package com.gkhy.exam.noncoalmine.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.exam.noncoalmine.entity.*; import com.gkhy.exam.noncoalmine.mapper.NcStaffMapper; import com.gkhy.exam.noncoalmine.model.addForm.NcExamineesAddForm; import com.gkhy.exam.noncoalmine.model.addForm.NcStaffAddForm; import com.gkhy.exam.noncoalmine.model.addForm.NcStaffResumeAddForm; import com.gkhy.exam.noncoalmine.model.addForm.NcStaffTrainAddForm; import com.gkhy.exam.noncoalmine.model.modForm.NcStaffModForm; import com.gkhy.exam.noncoalmine.model.query.NcStaffQuery; import com.gkhy.exam.noncoalmine.model.vo.NcStaffVO; import com.gkhy.exam.noncoalmine.model.vo.ViolationRegistrationVO; import com.gkhy.exam.noncoalmine.model.vo.WorkRegistrationVO; import com.gkhy.exam.noncoalmine.service.*; import com.ruoyi.common.exception.ServiceException; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.List; import java.util.stream.Collectors; /** * (NcStaff)表服务实现类 * * @author makejava * @since 2023-09-18 09:59:58 */ @Service("ncStaffService") public class NcStaffServiceImpl extends ServiceImpl implements NcStaffService { @Autowired private NcStaffMapper ncStaffMapper; @Autowired private NcStaffResumeService ncStaffResumeService; @Autowired private NcStaffTrainService ncStaffTrainService; @Autowired private NcExamineesService ncExamineesService; @Autowired private ViolationRegistrationService violationRegistrationService; @Autowired private WorkRegistrationService workRegistrationService; @Autowired private NcCertService ncCertService; @Override public List selectStaffList(NcStaffQuery query) { List staffVOList = ncStaffMapper.getList(query); for (NcStaffVO ncStaffVO : staffVOList) { List resumeList = ncStaffResumeService.getByStaffId(ncStaffVO.getId()); List trainList = ncStaffTrainService.getByStaffId(ncStaffVO.getId()); List examineesList = ncExamineesService.getByIdCard(ncStaffVO.getIdCardNum()); List violationList = violationRegistrationService.getByIdCard(ncStaffVO.getIdCardNum(), (byte) 0); List workList = workRegistrationService.getByIdCard(ncStaffVO.getIdCardNum(), (byte) 0); List certList = ncCertService.getByIdCard(ncStaffVO.getIdCardNum()); ncStaffVO.setResumeList(resumeList); ncStaffVO.setTrainList(trainList); ncStaffVO.setExamineeList(examineesList); ncStaffVO.setViolationList(violationList); ncStaffVO.setWorkList(workList); ncStaffVO.setCertList(certList); ncStaffVO.setCertCount(certList.size()); ncStaffVO.setViolationCount(violationList.size()); ncStaffVO.setWorkCount(workList.size()); } return staffVOList; } @Override public NcStaffVO getByIdCardNum(String idCardNum) { NcStaff ncStaff = ncStaffMapper.selectOne(new LambdaQueryWrapper() .eq(NcStaff::getDelFlag, (byte) 0) .eq(NcStaff::getIdCardNum, idCardNum)); NcStaffVO ncStaffVO = new NcStaffVO(); if(ncStaff != null){ BeanUtils.copyProperties(ncStaff,ncStaffVO); List resumeList = ncStaffResumeService.getByStaffId(ncStaff.getId()); List trainList = ncStaffTrainService.getByStaffId(ncStaff.getId()); List examineesList = ncExamineesService.getByIdCard(ncStaff.getIdCardNum()); List violationList = violationRegistrationService.getByIdCard(ncStaff.getIdCardNum(), (byte) 0); List workList = workRegistrationService.getByIdCard(ncStaff.getIdCardNum(), (byte) 0); List certList = ncCertService.getByIdCard(ncStaff.getIdCardNum()); ncStaffVO.setResumeList(resumeList); ncStaffVO.setTrainList(trainList); ncStaffVO.setExamineeList(examineesList); ncStaffVO.setViolationList(violationList); ncStaffVO.setWorkList(workList); ncStaffVO.setCertList(certList); ncStaffVO.setCertCount(certList.size()); ncStaffVO.setViolationCount(violationList.size()); ncStaffVO.setWorkCount(workList.size()); } return ncStaffVO; } /** * 新增 * @param addForm * @return */ @Transactional @Override public int add(NcStaffAddForm addForm) { if(isExist(addForm.getIdCardNum(),null)){ throw new ServiceException("人员已存在"); } NcStaff ncStaff = new NcStaff(); BeanUtils.copyProperties(addForm,ncStaff); ncStaff.setDelFlag((byte) 0); //插入人员 int i = ncStaffMapper.insert(ncStaff); //插入个人履历 saveBatchResume(addForm.getResumeList(),ncStaff.getId()); //插入培训经历 saveBatchTrain(addForm.getTrainList(),ncStaff); //考试经历 saveBatchExam(addForm.getExamineeList(),ncStaff); return i; } /** * 修改 * @param modForm */ @Transactional @Override public void mod(NcStaffModForm modForm) { if(isExist(modForm.getIdCardNum(),modForm.getId())){ throw new ServiceException("人员已存在"); } NcStaff ncStaff = new NcStaff(); BeanUtils.copyProperties(modForm,ncStaff); //修改人员 ncStaffMapper.updateById(ncStaff); //个人履历 updateBatchResume(modForm.getResumeList(),ncStaff); //插入培训经历 updateBatchTrain(modForm.getTrainList(),ncStaff); //考试经历 updateBatchExam(modForm.getExamineeList(),ncStaff); } private boolean isExist(String idCard,Long stuffId){ NcStaff ncStaff = baseMapper.selectOne(new LambdaQueryWrapper() .eq(NcStaff::getDelFlag, (byte) 0) .eq(NcStaff::getIdCardNum, idCard) .ne(stuffId != null,NcStaff::getId,stuffId)); if(ncStaff != null){ return true; } return false; } @Override public NcStaff getByIdCard(String idCard) { NcStaff ncStaff = baseMapper.selectOne(new LambdaQueryWrapper() .eq(NcStaff::getDelFlag, (byte) 0) .eq(NcStaff::getIdCardNum, idCard)); return ncStaff; } @Override public void delBatch(List staffIds) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.in("id",staffIds) .set("del_flag",(byte)2); this.update(updateWrapper); } //修改履历 public void updateBatchResume(List resumeFormList,NcStaff ncStaff){ if(!CollectionUtils.isEmpty(resumeFormList)){ //历史履历 List oldResumeList = ncStaffResumeService.list(new LambdaQueryWrapper() .eq(NcStaffResume::getDelFlag, (byte) 0) .eq(NcStaffResume::getStaffId, ncStaff.getId())); if(CollectionUtils.isEmpty(oldResumeList)){ //新增 saveBatchResume(resumeFormList, ncStaff.getId()); }else { //新增 List addResumeList = resumeFormList .stream() .filter(resume -> resume.getId() == null) .collect(Collectors.toList()); saveBatchResume(addResumeList, ncStaff.getId()); //修改 List modResumeList = resumeFormList .stream() .filter(resume -> resume.getId() != null) .collect(Collectors.toList()); if(!CollectionUtils.isEmpty(modResumeList)){ List collect = modResumeList.stream().map(modResume -> { NcStaffResume ncStaffResume = new NcStaffResume(); BeanUtils.copyProperties(modResume, ncStaffResume); return ncStaffResume; }).collect(Collectors.toList()); ncStaffResumeService.updateBatchById(collect); } //删除 for (NcStaffResume ncStaffResume : oldResumeList) { List selectList = resumeFormList .stream() .filter(resumeAddForm -> resumeAddForm.getId() != null && resumeAddForm.getId().equals(ncStaffResume.getId())) .collect(Collectors.toList()); if(selectList.size() == 0){ ncStaffResume.setDelFlag((byte) 2); ncStaffResumeService.updateById(ncStaffResume); } } } } } //插入履历 private void saveBatchResume(List resumeAddFormList, Long stuffId) { if(!CollectionUtils.isEmpty(resumeAddFormList)){ List resumeList = resumeAddFormList.stream().map(resume -> { NcStaffResume ncStaffResume = new NcStaffResume(); BeanUtils.copyProperties(resume, ncStaffResume); ncStaffResume.setStaffId(stuffId); ncStaffResume.setDelFlag((byte) 0); return ncStaffResume; }).collect(Collectors.toList()); ncStaffResumeService.saveBatch(resumeList); } } //修改考试经历 public void updateBatchTrain(List trainFormList,NcStaff ncStaff){ if(!CollectionUtils.isEmpty(trainFormList)){ //历史履历 List oldList = ncStaffTrainService.list(new LambdaQueryWrapper() .eq(NcStaffTrain::getDelFlag, (byte) 0) .eq(NcStaffTrain::getStaffId, ncStaff.getId())); if(CollectionUtils.isEmpty(oldList)){ //新增 saveBatchTrain(trainFormList, ncStaff); }else { //新增 List addList = trainFormList .stream() .filter(resume -> resume.getId() == null) .collect(Collectors.toList()); saveBatchTrain(addList, ncStaff); //修改 List modList = trainFormList .stream() .filter(resume -> resume.getId() != null) .collect(Collectors.toList()); if(!CollectionUtils.isEmpty(modList)){ List collect = modList.stream().map(modTrain -> { NcStaffTrain ncStaffTrain = new NcStaffTrain(); BeanUtils.copyProperties(modTrain, ncStaffTrain); ncStaffTrain.setIdCardNum(ncStaff.getIdCardNum()); ncStaffTrain.setName(ncStaff.getName()); return ncStaffTrain; }).collect(Collectors.toList()); ncStaffTrainService.updateBatchById(collect); } //删除 for (NcStaffTrain ncStaffTrain : oldList) { List selectList = trainFormList .stream() .filter(trainForm -> trainForm.getId() != null && trainForm.getId().equals(ncStaffTrain.getId())) .collect(Collectors.toList()); if(selectList.size() == 0){ ncStaffTrain.setDelFlag((byte) 2); ncStaffTrainService.updateById(ncStaffTrain); } } } } } //插入考试经历 private void saveBatchTrain(List trainAddFormList, NcStaff ncStaff) { if(!CollectionUtils.isEmpty(trainAddFormList)){ List trainList = trainAddFormList.stream().map(train -> { NcStaffTrain ncStaffTrain = new NcStaffTrain(); BeanUtils.copyProperties(train, ncStaffTrain); ncStaffTrain.setStaffId(ncStaff.getId()); ncStaffTrain.setIdCardNum(ncStaff.getIdCardNum()); ncStaffTrain.setName(ncStaff.getName()); ncStaffTrain.setDelFlag((byte) 0); return ncStaffTrain; }).collect(Collectors.toList()); ncStaffTrainService.saveBatch(trainList); } } //修改培训经历 public void updateBatchExam(List examFormList,NcStaff ncStaff){ if(!CollectionUtils.isEmpty(examFormList)){ //历史履历 List oldList = ncExamineesService.list(new LambdaQueryWrapper() .eq(NcExaminees::getDelFlag, (byte) 0) .eq(NcExaminees::getStaffId, ncStaff.getId())); if(CollectionUtils.isEmpty(oldList)){ //新增 saveBatchExam(examFormList, ncStaff); }else { //新增 List addList = examFormList .stream() .filter(resume -> resume.getId() == null) .collect(Collectors.toList()); saveBatchExam(addList, ncStaff); //修改 List modList = examFormList .stream() .filter(resume -> resume.getId() != null) .collect(Collectors.toList()); if(!CollectionUtils.isEmpty(modList)){ List collect = modList.stream().map(modExam -> { NcExaminees ncExaminees = new NcExaminees(); BeanUtils.copyProperties(modExam, ncExaminees); ncExaminees.setStaffId(ncStaff.getId()); ncExaminees.setDelFlag((byte) 0); ncExaminees.setCardNum(ncStaff.getIdCardNum()); ncExaminees.setCardName("身份证"); ncExaminees.setCardType("01"); return ncExaminees; }).collect(Collectors.toList()); ncExamineesService.updateBatchById(collect); } //删除 for (NcExaminees ncExaminees : oldList) { List selectList = examFormList .stream() .filter(examForm -> examForm.getId() != null && examForm.getId().equals(ncExaminees.getId())) .collect(Collectors.toList()); if(selectList.size() == 0){ ncExaminees.setDelFlag((byte) 2); ncExamineesService.updateById(ncExaminees); } } } } } //插入培训经历 private void saveBatchExam(List examineesAddFormList, NcStaff ncStaff) { if(!CollectionUtils.isEmpty(examineesAddFormList)){ List examineesList = examineesAddFormList.stream().map(examinees -> { NcExaminees ncExaminees = new NcExaminees(); BeanUtils.copyProperties(examinees, ncExaminees); ncExaminees.setStaffId(ncStaff.getId()); ncExaminees.setDelFlag((byte) 0); ncExaminees.setCardNum(ncStaff.getIdCardNum()); ncExaminees.setName(ncStaff.getName()); ncExaminees.setCardName("身份证"); ncExaminees.setCardType("01"); ncExaminees.setSex(ncStaff.getSex()); return ncExaminees; }).collect(Collectors.toList()); ncExamineesService.saveBatch(examineesList); } } }