ServiceMemberMappingServiceImpl.java 5.56 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.dto.member.*;
import com.subsidy.mapper.CompanyMemberMappingMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.model.DepartmentDictDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.ServiceMemberMappingDO;
import com.subsidy.mapper.ServiceMemberMappingMapper;
import com.subsidy.service.ServiceMemberMappingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.member.ImportClassMembersVO;
import com.subsidy.vo.member.SelectMembersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务映射表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2024-04-08
 */
@Service
public class ServiceMemberMappingServiceImpl extends ServiceImpl<ServiceMemberMappingMapper, ServiceMemberMappingDO> implements ServiceMemberMappingService {

    @Autowired
    private CompanyMemberMappingMapper companyMemberMappingMapper;

    @Autowired
    private MemberMapper memberMapper;

    public String selectImport(SelectImportDTO selectImportDTO) {
        List<Long> members = selectImportDTO.getMemberIds();
        for (Long memberId : members) {
            int count = this.baseMapper.selectCount(new QueryWrapper<ServiceMemberMappingDO>()
            .lambda()
            .eq(ServiceMemberMappingDO::getMemberId,memberId)
            .eq(ServiceMemberMappingDO::getCompanyId,selectImportDTO.getCompanyId())
            .eq(ServiceMemberMappingDO::getServiceId,4L));

            if (count == 0){
                ServiceMemberMappingDO serviceMemberMappingDO = new ServiceMemberMappingDO();
                serviceMemberMappingDO.setCompanyId(selectImportDTO.getCompanyId());
                serviceMemberMappingDO.setMemberId(memberId);
                serviceMemberMappingDO.setServiceId(4L);
                this.baseMapper.insert(serviceMemberMappingDO);
            }

        }
        return ConstantUtils.ADD_SUCCESS;
    }

    public IPage<SelectMembersVO> selectMembers(SelectMembersDTO selectMembersDTO) {
        Page pager = new Page(selectMembersDTO.getPageNum(), selectMembersDTO.getPageSize());
        IPage<SelectMembersVO> selectMembersVOIPage = this.baseMapper.selectMembers(pager, selectMembersDTO.getCompanyId(), selectMembersDTO.getServiceId());

        List<SelectMembersVO> selectMembersVOS = selectMembersVOIPage.getRecords();

        for (SelectMembersVO smv : selectMembersVOS){
            //获取这个人所在的部门
            List<DepartmentDictDO> departmentDictDOS = memberMapper.getDepartments(smv.getId());
            smv.setDepartmentDictDOS(departmentDictDOS);
        }
        return selectMembersVOIPage;

    }

    public String removeMembers(RemoveMembersDTO removeMembersDTO) {
        this.baseMapper.delete(new QueryWrapper<ServiceMemberMappingDO>()
        .lambda()
        .in(ServiceMemberMappingDO::getId,removeMembersDTO.getMemberMappingIds()));
        return ConstantUtils.DELETE_SUCCESS;
    }

    public ImportClassMembersVO importClassMembers(MultipartFile multipartFile, Long companyId) {

        ImportClassMembersVO importClassMembersVO = new ImportClassMembersVO();

        List<ImportClassMemberDTO> importClassMemberDTOS = ExcelUtil.readExcel(null, ImportClassMemberDTO.class, multipartFile);

        //查找企业下所有的学员的手机号    手机 姓名 身份证
        List<String> companyMembers = companyMemberMappingMapper.companyMembers(companyId);

        List<ImportClassMemberDTO> successMembers = new ArrayList<ImportClassMemberDTO>();
        List<ImportClassMemberDTO> failMembers = new ArrayList<ImportClassMemberDTO>();

        //查看该学员是否该企业下的人,不是的话就要返回  是的话直接导入成功
        for (ImportClassMemberDTO imd : importClassMemberDTOS) {
            if (null == imd.getUserName() || null == imd.getTelephone() || null == imd.getIdCard()) {
                imd.setReason("人员信息不完整");
                failMembers.add(imd);
            } else if (!companyMembers.contains(imd.getUserName() + imd.getTelephone() + imd.getIdCard())) {
                imd.setReason("企业内未查询到该成员信息");
                failMembers.add(imd);
            } else if (successMembers.contains(imd.getUserName() + imd.getTelephone() + imd.getIdCard())) {
                imd.setReason("人员信息重复");
                failMembers.add(imd);
            } else {
                MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone,imd.getTelephone()));
                imd.setId(memberDO.getId());
                successMembers.add(imd);
            }
        }
        importClassMembersVO.setSuccessMembers(successMembers);
        importClassMembersVO.setFailureMembers(failMembers);
        return importClassMembersVO;
    }

    public void downloadFailClassMembers(DownloadFailClassMembers downloadFailClassMembers) {
        List<DownloadFailClassMembersDTO> downloadFailClassMembersDTOS = downloadFailClassMembers.getDownloadFailClassMembersDTOS();
        ExcelUtil.writeExcel(downloadFailClassMembersDTOS, DownloadFailClassMembersDTO.class);
    }


}