Blame view

ServiceMemberMappingServiceImpl.java 5.56 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
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);
    }


}