package io.hmit.modules.meeting.service.impl;

import cn.hutool.system.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.hmit.common.service.impl.CrudServiceImpl;
import io.hmit.modules.meeting.dao.WlMeetingStaffDao;
import io.hmit.modules.meeting.dto.WlMeetingStaffDTO;
import io.hmit.modules.meeting.entity.WlMeetingStaffEntity;
import io.hmit.modules.meeting.service.WlMeetingStaffService;
import io.hmit.modules.user.dto.UserDTO;
import io.hmit.modules.user.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 参会人员
 *
 * @author zsh 408538940@qq.com
 * @since 1.0.0 2020-12-29
 */
@Service
public class WlMeetingStaffServiceImpl extends CrudServiceImpl<WlMeetingStaffDao, WlMeetingStaffEntity, WlMeetingStaffDTO> implements WlMeetingStaffService {

    @Autowired
    private UserService userService;

    @Override
    public QueryWrapper<WlMeetingStaffEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        String userId = "";
        if(params.get("userId") !=null){
            userId = params.get("userId").toString();
        }
        String meetingId = "";
        if(params.get("meetingId") != null){
            meetingId = params.get("meetingId").toString();
        }
        String registrationState = (String)params.get("registrationState");

        QueryWrapper<WlMeetingStaffEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id)
            .eq(StringUtils.isNotBlank(registrationState), "registration_state", registrationState)
            .eq(StringUtils.isNotBlank(userId), "user_id", userId)
            .eq(StringUtils.isNotBlank(meetingId), "meeting_id", meetingId);

        return wrapper;
    }


    @Override
    public List<UserDTO> getInvitedNames(Long meetingId) {
        Map<String, Object> params = new HashMap<>();
        params.put("meetingId",meetingId);
        List<UserDTO> userList=new ArrayList<>();
        baseDao.selectList(getWrapper(params)).stream().forEach(meetingStaff->{
            userList.add(userService.get(meetingStaff.getUserId()));
        });
        return userList;
    }
}
