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<NcStaffMapper, NcStaff> 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<NcStaffVO> selectStaffList(NcStaffQuery query) {
|
List<NcStaffVO> staffVOList = ncStaffMapper.getList(query);
|
for (NcStaffVO ncStaffVO : staffVOList) {
|
List<NcStaffResume> resumeList = ncStaffResumeService.getByStaffId(ncStaffVO.getId());
|
List<NcStaffTrain> trainList = ncStaffTrainService.getByStaffId(ncStaffVO.getId());
|
List<NcExaminees> examineesList = ncExamineesService.getByIdCard(ncStaffVO.getIdCardNum());
|
List<ViolationRegistrationVO> violationList = violationRegistrationService.getByIdCard(ncStaffVO.getIdCardNum(), (byte) 0);
|
List<WorkRegistrationVO> workList = workRegistrationService.getByIdCard(ncStaffVO.getIdCardNum(), (byte) 0);
|
List<NcCert> 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;
|
}
|
|
/**
|
* 新增
|
* @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<NcStaff>()
|
.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<NcStaff>()
|
.eq(NcStaff::getDelFlag, (byte) 0)
|
.eq(NcStaff::getIdCardNum, idCard));
|
return ncStaff;
|
}
|
|
@Override
|
public void delBatch(List<Long> staffIds) {
|
UpdateWrapper<NcStaff> updateWrapper = new UpdateWrapper<>();
|
updateWrapper.in("id",staffIds)
|
.set("del_flag",(byte)2);
|
this.update(updateWrapper);
|
}
|
|
//修改履历
|
public void updateBatchResume(List<NcStaffResumeAddForm> resumeFormList,NcStaff ncStaff){
|
if(!CollectionUtils.isEmpty(resumeFormList)){
|
//历史履历
|
List<NcStaffResume> oldResumeList = ncStaffResumeService.list(new LambdaQueryWrapper<NcStaffResume>()
|
.eq(NcStaffResume::getDelFlag, (byte) 0)
|
.eq(NcStaffResume::getStaffId, ncStaff.getId()));
|
if(CollectionUtils.isEmpty(oldResumeList)){
|
//新增
|
saveBatchResume(resumeFormList, ncStaff.getId());
|
}else {
|
|
//新增
|
List<NcStaffResumeAddForm> addResumeList = resumeFormList
|
.stream()
|
.filter(resume -> resume.getId() == null)
|
.collect(Collectors.toList());
|
saveBatchResume(addResumeList, ncStaff.getId());
|
//修改
|
List<NcStaffResumeAddForm> modResumeList = resumeFormList
|
.stream()
|
.filter(resume -> resume.getId() != null)
|
.collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(modResumeList)){
|
List<NcStaffResume> 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<NcStaffResumeAddForm> 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<NcStaffResumeAddForm> resumeAddFormList, Long stuffId) {
|
if(!CollectionUtils.isEmpty(resumeAddFormList)){
|
List<NcStaffResume> 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<NcStaffTrainAddForm> trainFormList,NcStaff ncStaff){
|
if(!CollectionUtils.isEmpty(trainFormList)){
|
//历史履历
|
List<NcStaffTrain> oldList = ncStaffTrainService.list(new LambdaQueryWrapper<NcStaffTrain>()
|
.eq(NcStaffTrain::getDelFlag, (byte) 0)
|
.eq(NcStaffTrain::getStaffId, ncStaff.getId()));
|
if(CollectionUtils.isEmpty(oldList)){
|
//新增
|
saveBatchTrain(trainFormList, ncStaff);
|
}else {
|
//新增
|
List<NcStaffTrainAddForm> addList = trainFormList
|
.stream()
|
.filter(resume -> resume.getId() == null)
|
.collect(Collectors.toList());
|
saveBatchTrain(addList, ncStaff);
|
//修改
|
List<NcStaffTrainAddForm> modList = trainFormList
|
.stream()
|
.filter(resume -> resume.getId() != null)
|
.collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(modList)){
|
List<NcStaffTrain> 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<NcStaffTrainAddForm> 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<NcStaffTrainAddForm> trainAddFormList, NcStaff ncStaff) {
|
if(!CollectionUtils.isEmpty(trainAddFormList)){
|
List<NcStaffTrain> 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<NcExamineesAddForm> examFormList,NcStaff ncStaff){
|
if(!CollectionUtils.isEmpty(examFormList)){
|
//历史履历
|
List<NcExaminees> oldList = ncExamineesService.list(new LambdaQueryWrapper<NcExaminees>()
|
.eq(NcExaminees::getDelFlag, (byte) 0)
|
.eq(NcExaminees::getStaffId, ncStaff.getId()));
|
if(CollectionUtils.isEmpty(oldList)){
|
//新增
|
saveBatchExam(examFormList, ncStaff);
|
}else {
|
//新增
|
List<NcExamineesAddForm> addList = examFormList
|
.stream()
|
.filter(resume -> resume.getId() == null)
|
.collect(Collectors.toList());
|
saveBatchExam(addList, ncStaff);
|
//修改
|
List<NcExamineesAddForm> modList = examFormList
|
.stream()
|
.filter(resume -> resume.getId() != null)
|
.collect(Collectors.toList());
|
if(!CollectionUtils.isEmpty(modList)){
|
List<NcExaminees> 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<NcExamineesAddForm> 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<NcExamineesAddForm> examineesAddFormList, NcStaff ncStaff) {
|
if(!CollectionUtils.isEmpty(examineesAddFormList)){
|
List<NcExaminees> 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);
|
}
|
}
|
|
}
|