MemberDictServiceImpl.java 15.9 KB
package com.laowu.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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laowu.common.exception.HttpException;
import com.laowu.dto.member.AddMemberDTO;
import com.laowu.dto.member.AllMembersDTO;
import com.laowu.dto.member.UpdateMemberDTO;
import com.laowu.mapper.*;
import com.laowu.model.*;
import com.laowu.service.MemberDictService;
import com.laowu.util.ConstantUtils;
import com.laowu.vo.member.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * <p>
 * 自然人表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2023-03-23
 */
@Service
public class MemberDictServiceImpl extends ServiceImpl<MemberDictMapper, MemberDictDO> implements MemberDictService {

    @Autowired
    private MemberJobInfoMapper memberJobInfoMapper;

    @Autowired
    private LibCollegeMapper libCollegeMapper;

    @Autowired
    private LibMajorMapper libMajorMapper;

    @Autowired
    private CompanyDictMapper companyDictMapper;

    @Autowired
    private MemberCollegeMappingMapper memberCollegeMappingMapper;

    @Autowired
    private WorkstationDictMapper workstationDictMapper;

    @Autowired
    private MemberUpdateHistoryMapper memberUpdateHistoryMapper;

    @Autowired
    private WorkstationMemberMappingMapper workstationMemberMappingMapper;

    @Autowired
    private MemberTeamMappingMapper memberTeamMappingMapper;

    @Autowired
    private TeamDictMapper teamDictMapper;

    @Autowired
    private MemberPositionsMapper memberPositionsMapper;

    @Autowired
    private MemberCertsMapper memberCertsMapper;

    @Autowired
    private MemberTrainInfoMapper memberTrainInfoMapper;

    @Autowired
    private MemberTrainPositionsMapper memberTrainPositionsMapper;

    public IPage<AllMembersVO> allMembers(AllMembersDTO allMembersDTO) {
        Page pager = new Page(allMembersDTO.getPageNum(), allMembersDTO.getPageSize());

        IPage<AllMembersVO> allMembersVOIPage = this.baseMapper.allMembers(pager, allMembersDTO.getProvince(), allMembersDTO.getCity(), allMembersDTO.getCounty(), allMembersDTO.getStatus(), allMembersDTO.getUserName());
        List<AllMembersVO> allMembersVOS = allMembersVOIPage.getRecords();
        for (AllMembersVO allMembersVO : allMembersVOS) {
            //专业技能信息
            List<PositionDictDO> memberPositions = memberPositionsMapper.memberPositions(allMembersVO.getId());
            allMembersVO.setPositionDictDOS(memberPositions);
        }

        return allMembersVOIPage;
    }

    @Transactional(rollbackFor = Exception.class)
    public String deleteMember(AddMemberDTO addMemberDTO) {
        this.baseMapper.deleteById(addMemberDTO.getId());

        memberTeamMappingMapper.delete(new QueryWrapper<MemberTeamMappingDO>()
                .lambda()
                .eq(MemberTeamMappingDO::getMemberId, addMemberDTO.getId()));

        workstationMemberMappingMapper.delete(new QueryWrapper<WorkstationMemberMappingDO>()
                .lambda()
                .eq(WorkstationMemberMappingDO::getMemberId, addMemberDTO.getId()));

        memberJobInfoMapper.delete(new QueryWrapper<MemberJobInfoDO>()
                .lambda()
                .eq(MemberJobInfoDO::getMemberId, addMemberDTO.getId()));

        //团队领导人为id的团队组长职位空
        List<TeamDictDO> teamDictDOS = teamDictMapper.selectList(new QueryWrapper<TeamDictDO>()
                .lambda()
                .eq(TeamDictDO::getMemberId, addMemberDTO.getId()));

        for (TeamDictDO teamDictDO : teamDictDOS) {
            teamDictMapper.noLeader(teamDictDO.getId());
        }

        //历史
        MemberUpdateHistoryDO memberUpdateHistoryDO = new MemberUpdateHistoryDO();
        memberUpdateHistoryDO.setAdministerId(addMemberDTO.getUserId());
        memberUpdateHistoryDO.setModule(addMemberDTO.getModule());
        memberUpdateHistoryDO.setMemberId(addMemberDTO.getId());
        memberUpdateHistoryDO.setOpr("删除了该成员");
        memberUpdateHistoryMapper.insert(memberUpdateHistoryDO);
        return ConstantUtils.DELETE_SUCCESS;
    }

    public String addMember(AddMemberDTO addMemberDTO) {

        int count = this.baseMapper.selectCount(new QueryWrapper<MemberDictDO>()
                .lambda()
                .isNotNull(MemberDictDO::getIdCard)
                .eq(MemberDictDO::getIdCard, addMemberDTO.getIdCard()));

        if (count > 0) {
            throw new HttpException(70001);
        }

        MemberDictDO memberDictDO = new MemberDictDO();
        BeanUtils.copyProperties(addMemberDTO, memberDictDO);

        //信息来源
        if (null != addMemberDTO.getStationId()) {
            WorkstationDictDO workstationDictDO = workstationDictMapper.selectById(addMemberDTO.getStationId());
            if (null != workstationDictDO) {
                memberDictDO.setInfoOrigin(workstationDictDO.getWorkstationName());
            }
        } else {
            memberDictDO.setInfoOrigin("自然人数据库");
        }

        List<Long> positionIds = addMemberDTO.getPositionIds();
        for (Long positionId : positionIds) {
            MemberPositionsDO memberPositionsDO = new MemberPositionsDO();
            memberPositionsDO.setMemberId(memberDictDO.getId());
            memberPositionsDO.setPositionId(positionId);
            memberPositionsMapper.insert(memberPositionsDO);
        }

        this.baseMapper.insert(memberDictDO);

        if (null != addMemberDTO.getStationId()) {
            WorkstationMemberMappingDO workstationMemberMappingDO = new WorkstationMemberMappingDO();
            workstationMemberMappingDO.setMemberId(memberDictDO.getId());
            workstationMemberMappingDO.setStationId(addMemberDTO.getStationId());
            workstationMemberMappingMapper.insert(workstationMemberMappingDO);
        }

        if (null != addMemberDTO.getTeamId()) {
            MemberTeamMappingDO memberTeamMappingDO = new MemberTeamMappingDO();
            memberTeamMappingDO.setMemberId(memberDictDO.getId());
            memberTeamMappingDO.setTeamId(addMemberDTO.getTeamId());
            memberTeamMappingMapper.insert(memberTeamMappingDO);
        }
        //历史
        MemberUpdateHistoryDO memberUpdateHistoryDO = new MemberUpdateHistoryDO();
        memberUpdateHistoryDO.setAdministerId(addMemberDTO.getUserId());
        memberUpdateHistoryDO.setModule(addMemberDTO.getModule());
        memberUpdateHistoryDO.setMemberId(memberDictDO.getId());
        memberUpdateHistoryDO.setOpr("创建了该成员");
        memberUpdateHistoryMapper.insert(memberUpdateHistoryDO);

        return ConstantUtils.ADD_SUCCESS;
    }

    public OneMemberVO oneMember(MemberDictDO memberDictDO) {

        OneMemberVO oneMemberVO = new OneMemberVO();
        MemberDictDO memberDictDO1 = this.baseMapper.selectById(memberDictDO.getId());
        BeanUtils.copyProperties(memberDictDO1, oneMemberVO);

        if (null != memberDictDO1.getCollegeId()) {
            LibCollegeDO libCollegeDO = libCollegeMapper.selectById(memberDictDO1.getCollegeId());
            oneMemberVO.setCollege(libCollegeDO.getCollege());
        }

        if (null != memberDictDO1.getMajorId()) {
            LibMajorDO libMajorDO = libMajorMapper.selectById(memberDictDO1.getMajorId());
            oneMemberVO.setMajor(libMajorDO.getMajor());
        }

        //院校信息
        List<MemberCollegeVO> memberCollegeVOS = new ArrayList<>();
        List<MemberCollegeMappingDO> memberCollegeMappingDOS = memberCollegeMappingMapper.selectList(new QueryWrapper<MemberCollegeMappingDO>()
                .lambda()
                .eq(MemberCollegeMappingDO::getMemberId, memberDictDO1.getId()));
        for (MemberCollegeMappingDO mcmd : memberCollegeMappingDOS) {
            MemberCollegeVO memberCollegeVO = new MemberCollegeVO();
            BeanUtils.copyProperties(mcmd, memberCollegeVO);
            LibCollegeDO libCollegeDO = libCollegeMapper.selectById(mcmd.getCollegeId());
            memberCollegeVO.setCollege(libCollegeDO.getCollege());

            LibMajorDO libMajorDO = libMajorMapper.selectById(mcmd.getMajorId());
            memberCollegeVO.setMajor(libMajorDO.getMajor());
            memberCollegeVOS.add(memberCollegeVO);
        }
        oneMemberVO.setMemberCollegeVOS(memberCollegeVOS);

        //就业信息
        List<MemberJobInfoVO> memberJobInfoVOS = new ArrayList<MemberJobInfoVO>();
        List<MemberJobInfoDO> memberJobInfoDOS = memberJobInfoMapper.selectList(new QueryWrapper<MemberJobInfoDO>()
                .lambda()
                .eq(MemberJobInfoDO::getMemberId, memberDictDO1.getId())
                .orderByDesc(MemberJobInfoDO::getStartDate));
        for (MemberJobInfoDO memberJobInfoDO : memberJobInfoDOS) {
            MemberJobInfoVO memberJobInfoVO = new MemberJobInfoVO();
            BeanUtils.copyProperties(memberJobInfoDO, memberJobInfoVO);

            CompanyDictDO companyDictDO = companyDictMapper.selectById(memberJobInfoDO.getCompanyId());
            memberJobInfoVO.setCompanyName(companyDictDO.getCompanyName());
            memberJobInfoVOS.add(memberJobInfoVO);
        }
        oneMemberVO.setMemberJobInfoVOS(memberJobInfoVOS);

        //专业技能信息
        List<PositionDictDO> memberPositions = memberPositionsMapper.memberPositions(memberDictDO.getId());
        oneMemberVO.setPositionDictDOS(memberPositions);

        //专业证书信息
        List<MemberCertsDO> memberCertsDOS = memberCertsMapper.selectList(new QueryWrapper<MemberCertsDO>()
                .lambda()
                .eq(MemberCertsDO::getMemberId, memberDictDO1.getId()));
        oneMemberVO.setMemberCertsDOS(memberCertsDOS);

        //培训信息
        List<MemberTrainInfoVO> memberTrainInfoVOS = new ArrayList<>();
        List<MemberTrainInfoDO> memberTrainInfoDOS = memberTrainInfoMapper.selectList(new QueryWrapper<MemberTrainInfoDO>()
                .lambda()
                .eq(MemberTrainInfoDO::getMemberId, memberDictDO1.getId()));

        for (MemberTrainInfoDO mtid : memberTrainInfoDOS) {
            MemberTrainInfoVO memberTrainInfoVO = new MemberTrainInfoVO();
            BeanUtils.copyProperties(mtid, memberTrainInfoVO);

            //技能
            List<PositionDictDO> positionDictDOS = memberTrainPositionsMapper.positions(mtid.getId());
            memberTrainInfoVO.setPositionDictDOS(positionDictDOS);
            memberTrainInfoVOS.add(memberTrainInfoVO);
        }
        oneMemberVO.setMemberTrainInfoVOS(memberTrainInfoVOS);


        return oneMemberVO;
    }

    public String updateMember(UpdateMemberDTO updateMemberDTO) {

        MemberDictDO memberDictDO1 = this.baseMapper.selectById(updateMemberDTO.getId());

        MemberDictDO memberDictDO = new MemberDictDO();
        BeanUtils.copyProperties(updateMemberDTO, memberDictDO);
        this.baseMapper.updateById(memberDictDO);

        List<MemberJobInfoVO> memberJobInfoVOS = updateMemberDTO.getMemberJobInfoVOS();

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("变更了“");

        if (null != memberJobInfoVOS) {
            memberJobInfoMapper.delete(new QueryWrapper<MemberJobInfoDO>()
                    .lambda()
                    .eq(MemberJobInfoDO::getMemberId, updateMemberDTO.getId()));
            for (MemberJobInfoVO memberJobInfoVO : memberJobInfoVOS) {
                MemberJobInfoDO memberJobInfoDO = new MemberJobInfoDO();
                BeanUtils.copyProperties(memberJobInfoVO, memberJobInfoDO);
                memberJobInfoMapper.insert(memberJobInfoDO);
            }
            stringBuffer.append("就业信息、");
        }

        if (null != updateMemberDTO.getPositionIds()) {
            List<Long> newIds = updateMemberDTO.getPositionIds();
            List<Long> oldIds = memberPositionsMapper.memberPositionIds(memberDictDO.getId());

            List<Long> newIds2 = new ArrayList<Long>();
            for (Long id : newIds) {
                newIds2.add(id);
            }

            newIds.removeAll(oldIds);  //新增的人在newIds里面

            if (newIds.size() > 0) {
                for (Long id : newIds) {
                    MemberPositionsDO memberPositionsDO = new MemberPositionsDO();
                    memberPositionsDO.setMemberId(memberDictDO.getId());
                    memberPositionsDO.setPositionId(id);
                    memberPositionsMapper.insert(memberPositionsDO);
                }
            }

            oldIds.removeAll(newIds2);//删掉以前的
            if (oldIds.size() > 0) {
                for (Long id : oldIds) {
                    memberPositionsMapper.delete(new QueryWrapper<MemberPositionsDO>()
                            .lambda()
                            .eq(MemberPositionsDO::getMemberId, memberDictDO.getId())
                            .eq(MemberPositionsDO::getPositionId, id));
                }
            }

        }


        //历史
        MemberUpdateHistoryDO memberUpdateHistoryDO = new MemberUpdateHistoryDO();
        memberUpdateHistoryDO.setAdministerId(updateMemberDTO.getUserId());
        memberUpdateHistoryDO.setModule(updateMemberDTO.getModule());
        memberUpdateHistoryDO.setMemberId(memberDictDO.getId());

        if (null != updateMemberDTO.getUserName() && !updateMemberDTO.getUserName().equals(memberDictDO1.getUserName())) {
            stringBuffer.append("姓名、");
        }
        if (null != updateMemberDTO.getTelephone() && !updateMemberDTO.getTelephone().equals(memberDictDO1.getProvince())) {
            stringBuffer.append("手机号码、");
        }
        if (null != updateMemberDTO.getProvince() && !updateMemberDTO.getProvince().equals(memberDictDO1.getProvince())) {
            stringBuffer.append("省、");
        }
        if (null != updateMemberDTO.getCity() && !updateMemberDTO.getCity().equals(memberDictDO1.getCity())) {
            stringBuffer.append("市、");
        }
        if (null != updateMemberDTO.getCounty() && !updateMemberDTO.getCounty().equals(memberDictDO1.getCounty())) {
            stringBuffer.append("县、");
        }
        if (null != updateMemberDTO.getAddress() && !updateMemberDTO.getAddress().equals(memberDictDO1.getAddress())) {
            stringBuffer.append("具体地址、");
        }
        if (null != updateMemberDTO.getEducation() && !updateMemberDTO.getEducation().equals(memberDictDO1.getEducation())) {
            stringBuffer.append("学历、");
        }
        if (null != updateMemberDTO.getEducationType() && !updateMemberDTO.getEducationType().equals(memberDictDO1.getEducationType())) {
            stringBuffer.append("学历类型、");
        }
        if (null != updateMemberDTO.getCollegeId() && !updateMemberDTO.getCollegeId().equals(memberDictDO1.getCollegeId())) {
            stringBuffer.append("院校、");
        }
        if (null != updateMemberDTO.getIsPoor() && !updateMemberDTO.getIsPoor().equals(memberDictDO1.getIsPoor())) {
            stringBuffer.append("是否为脱贫劳动力、");
        }
        if (null != updateMemberDTO.getIsMigration() && !updateMemberDTO.getIsMigration().equals(memberDictDO1.getIsMigration())) {
            stringBuffer.append("是否易迁户、");
        }
        if (null != updateMemberDTO.getIsParty() && !updateMemberDTO.getIsParty().equals(memberDictDO1.getIsParty())) {
            stringBuffer.append("是否党员、");
        }
        if (null != updateMemberDTO.getJobStatus() && !updateMemberDTO.getJobStatus().equals(memberDictDO1.getJobStatus())) {
            stringBuffer.append("就业状态、");
        }
        String opr = stringBuffer.substring(0, stringBuffer.length() - 1) + "”";
        memberUpdateHistoryDO.setOpr(opr);
        memberUpdateHistoryMapper.insert(memberUpdateHistoryDO);

        return ConstantUtils.SUCCESS_UPDATE;
    }

}