| | |
| | | package cc.mrbird.febs.server.hr.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.core.constant.GlobalStatic; |
| | | import java.util.*; |
| | | |
| | | import cc.mrbird.febs.server.hr.entity.EmpDimissionLog; |
| | | import cc.mrbird.febs.server.hr.entity.EmpJobChange; |
| | | import cc.mrbird.febs.server.hr.service.IEmpDimissionLogService; |
| | | import cc.mrbird.febs.server.hr.service.IEmpJobChangeService; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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 cc.mrbird.febs.common.core.constant.DicCode; |
| | | import cc.mrbird.febs.common.core.constant.ModuleCode; |
| | | import cc.mrbird.febs.common.core.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.core.entity.system.Dept; |
| | | import cc.mrbird.febs.common.core.entity.system.DicItem; |
| | | import cc.mrbird.febs.common.core.utils.CastUtil; |
| | | import cc.mrbird.febs.common.core.utils.FebsUtil; |
| | | import cc.mrbird.febs.common.core.utils.SequenceUtil; |
| | | import cc.mrbird.febs.common.redis.service.RedisService; |
| | | import cc.mrbird.febs.server.hr.entity.EmpBaseInfo; |
| | | import cc.mrbird.febs.server.hr.feign.IRemoteDeptService; |
| | | import cc.mrbird.febs.server.hr.mapper.EmpBaseInfoMapper; |
| | | import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * name:EmpBaseinfo |
| | |
| | | @Transactional(propagation = Propagation.SUPPORTS, readOnly = true) |
| | | class EmpBaseInfoServiceImpl extends ServiceImpl<EmpBaseInfoMapper, EmpBaseInfo> implements IEmpBaseInfoService { |
| | | private final RedisService redisService; |
| | | private final IRemoteDeptService remoteDeptService; |
| | | private final EmpBaseInfoMapper empBaseInfoMapper; |
| | | private final IEmpDimissionLogService dimissionLogService; |
| | | private final IEmpJobChangeService jobChangeService; |
| | | private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser()) |
| | | .map(u -> u.getUserId().toString()) |
| | | .orElse("1"); |
| | |
| | | @Override |
| | | public IPage<EmpBaseInfo> findEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) { |
| | | LambdaQueryWrapper<EmpBaseInfo> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EmpBaseInfo::getDelFlag, 0); |
| | | queryWrapper.eq(EmpBaseInfo::getDelFlag, empBaseInfo.getDelFlag()); |
| | | if (StringUtils.isNotBlank(empBaseInfo.getEmpNumb())) { |
| | | queryWrapper.like(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getEmpName())) { |
| | | queryWrapper.like(EmpBaseInfo::getEmpName, empBaseInfo.getEmpName()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getCertificateNumb())) { |
| | | queryWrapper.like(EmpBaseInfo::getCertificateNumb, empBaseInfo.getCertificateNumb()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getDeptName())) { |
| | | queryWrapper.like(EmpBaseInfo::getDeptName, empBaseInfo.getDeptName()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getEntryDateStr())) { |
| | | queryWrapper.between(EmpBaseInfo::getEntryDate, empBaseInfo.getEntryDateStr().split(",")[0], empBaseInfo.getEntryDateStr().split(",")[1]); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getDimissionDateStr())) { |
| | | queryWrapper.between(EmpBaseInfo::getDimissionDate, empBaseInfo.getDimissionDateStr().split(",")[0], empBaseInfo.getDimissionDateStr().split(",")[1]); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getSex())) { |
| | | queryWrapper.eq(EmpBaseInfo::getSex, empBaseInfo.getSex()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getEducation())) { |
| | | queryWrapper.like(EmpBaseInfo::getEducation, empBaseInfo.getEducation()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getPolitics())) { |
| | | queryWrapper.like(EmpBaseInfo::getPolitics, empBaseInfo.getPolitics()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getAgeStr())) { |
| | | queryWrapper.between(EmpBaseInfo::getAge, empBaseInfo.getAgeStr().split(",")[0], empBaseInfo.getAgeStr().split(",")[1]); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getArchivesStatus())) { |
| | | queryWrapper.eq(EmpBaseInfo::getArchivesStatus, empBaseInfo.getArchivesStatus()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getInsuranceType())) { |
| | | queryWrapper.eq(EmpBaseInfo::getInsuranceType, empBaseInfo.getInsuranceType()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getEmpStatus())) { |
| | | queryWrapper.eq(EmpBaseInfo::getEmpStatus, empBaseInfo.getEmpStatus()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getHandbookStatus())) { |
| | | queryWrapper.eq(EmpBaseInfo::getHandbookStatus, empBaseInfo.getHandbookStatus()); |
| | | } |
| | | if (StringUtils.isNotBlank(empBaseInfo.getEmpCardStatus())) { |
| | | queryWrapper.eq(EmpBaseInfo::getEmpCardStatus, empBaseInfo.getEmpCardStatus()); |
| | | } |
| | | Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | IPage<EmpBaseInfo> iPage = this.page(page, queryWrapper);; |
| | | List<EmpBaseInfo> list = iPage.getRecords(); |
| | | List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"),DicItem.class); |
| | | IPage<EmpBaseInfo> iPage = this.page(page, queryWrapper); |
| | | //设置部门 |
| | | List<EmpBaseInfo> list = setDeptName(iPage.getRecords()); |
| | | List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class); |
| | | list.forEach(p -> { |
| | | p.setJobName("测试岗位"); |
| | | p.setMarriage("未婚"); |
| | | p.setSexName("1".equals(p.getSex()) ? "男" : "女"); |
| | | p.setEmpTypeName("1".equals(p.getEmpType()) ? "正式工" : "临时工"); |
| | | p.setInsuranceTypeName("1".equals(p.getInsuranceType()) ? "(深户)五险一档" : "(非深户)五险一档"); |
| | | p.setArchivesStatusName("0".equals(p.getArchivesStatus()) ? "未移交" : "已移交"); |
| | | // 设置民族 |
| | | p.setNation(dicItems.stream() |
| | | .filter(k -> "nation".equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNation())) |
| | | p.setNationName(dicItems.stream() |
| | | .filter(k -> DicCode.NATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNation())) |
| | | .findFirst() |
| | | .map(DicItem::getDicItemName) |
| | | .orElse("汉族")); |
| | | // 设置政治面貌 |
| | | p.setPoliticsName(dicItems.stream() |
| | | .filter(k -> DicCode.PLITICAL.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getPolitics())) |
| | | .findFirst() |
| | | .map(DicItem::getDicItemName) |
| | | .orElse("群众")); |
| | | // 设置婚姻状况 |
| | | p.setMarriageName(dicItems.stream() |
| | | .filter(k -> DicCode.MARRIAGE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getMarriage())) |
| | | .findFirst() |
| | | .map(DicItem::getDicItemName) |
| | | .orElse("未婚")); |
| | | // 设置学历 |
| | | p.setEducationName(dicItems.stream() |
| | | .filter(k -> DicCode.EDUCATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEducation())) |
| | | .findFirst() |
| | | .map(DicItem::getDicItemName) |
| | | .orElse("无学历")); |
| | | // 设置籍贯 |
| | | p.setNativePlaceName(dicItems.stream() |
| | | .filter(k -> DicCode.NATIVEPLACE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNativePlace())) |
| | | .findFirst() |
| | | .map(DicItem::getDicItemName) |
| | | .orElse("未知")); |
| | | }); |
| | | iPage.setRecords(list); |
| | | return iPage; |
| | |
| | | @Override |
| | | public List<EmpBaseInfo> findEmpBaseInfos(EmpBaseInfo empBaseInfo) { |
| | | LambdaQueryWrapper<EmpBaseInfo> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(EmpBaseInfo::getDelFlag, 0); |
| | | queryWrapper.eq(EmpBaseInfo::getDelFlag, empBaseInfo.getDelFlag()); |
| | | return this.baseMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void createEmpBaseInfo(EmpBaseInfo empBaseInfo) { |
| | | empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE)); |
| | | empBaseInfo.setDeptId(1L); |
| | | empBaseInfo.setJobId(1L); |
| | | EmpBaseInfo dbInfo = this.getEmpBaseInfo(empBaseInfo); |
| | | if(dbInfo==null) { |
| | | empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE)); |
| | | } else{ |
| | | empBaseInfo.setEmpId(dbInfo.getEmpId()); |
| | | } |
| | | empBaseInfo.setCreator(operatorId); |
| | | empBaseInfo.setModifier(operatorId); |
| | | this.save(empBaseInfo); |
| | | this.saveOrUpdate(empBaseInfo); |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<String> list = new ArrayList<>(Arrays.asList(str)); |
| | | empBaseInfoMapper.logicDeleteByIds(list, operatorId); |
| | | } |
| | | |
| | | /** |
| | | * 设置员工部门名称 |
| | | * <p> |
| | | * date 2021-02-02 21:43 |
| | | * |
| | | * @param empBaseInfoList 人员信息列表 |
| | | * @return java.util.List<cc.mrbird.febs.server.hr.entity.EmpBaseInfo> |
| | | * @author: luoyibo |
| | | */ |
| | | private List<EmpBaseInfo> setDeptName(List<EmpBaseInfo> empBaseInfoList) { |
| | | List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class); |
| | | for (EmpBaseInfo empBaseInfo : empBaseInfoList) { |
| | | // 设置部门 |
| | | empBaseInfo.setDeptName(depts.stream() |
| | | .filter(k -> k.getDeptId().equals(empBaseInfo.getDeptId())) |
| | | .findFirst() |
| | | .map(Dept::getDeptName) |
| | | .orElse("")); |
| | | } |
| | | return empBaseInfoList; |
| | | } |
| | | |
| | | @Override |
| | | public boolean verifyEmpNumb(EmpBaseInfo empBaseInfo) { |
| | | QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.lambda().eq(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb()); |
| | | EmpBaseInfo tempEmpBaseInfo = this.getOne(queryWrapper); |
| | | if (tempEmpBaseInfo == null) { |
| | | return false; |
| | | } |
| | | return !empBaseInfo.getEmpId().equals(tempEmpBaseInfo.getEmpId()); |
| | | } |
| | | |
| | | @Override |
| | | public boolean momentToNormal(String ids) { |
| | | String[] str = ids.split(","); |
| | | List<String> list = new ArrayList<>(Arrays.asList(str)); |
| | | return empBaseInfoMapper.momentToNormal(list, operatorId) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public EmpBaseInfo getEmpBaseInfo(EmpBaseInfo empBaseInfo) { |
| | | QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>(); |
| | | if(StringUtils.isEmpty(empBaseInfo.getCertificateNumb())){ |
| | | queryWrapper.lambda().eq(EmpBaseInfo::getCertificateNumb, empBaseInfo.getCertificateNumb()); |
| | | } |
| | | |
| | | return this.getOne(queryWrapper); |
| | | } |
| | | /** |
| | | * |
| | | * 关闭员工档案 |
| | | * |
| | | * date 2021-02-18 12:54 |
| | | * @author: luoyibo |
| | | * @param empDimissionLog |
| | | * @return boolean |
| | | */ |
| | | @Override |
| | | public boolean closeEmpArchives(EmpDimissionLog empDimissionLog) { |
| | | String[] str = empDimissionLog.getEmpIds().split(","); |
| | | List<String> list = new ArrayList<>(Arrays.asList(str)); |
| | | String[] strDate = empDimissionLog.getEntryDates().split(","); |
| | | EmpDimissionLog dimissionLog = null; |
| | | for (int i = 0,k=str.length; i < k; i++) { |
| | | dimissionLog = new EmpDimissionLog(); |
| | | dimissionLog.setCloseId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE)); |
| | | dimissionLog.setEmpId(Long.parseLong(str[i])); |
| | | dimissionLog.setEntryDate(DateUtil.parse(strDate[i],"yyyy-MM-dd")); |
| | | dimissionLog.setDimissionDate(empDimissionLog.getDimissionDate()); |
| | | dimissionLog.setDimissionType(empDimissionLog.getDimissionType()); |
| | | dimissionLog.setRemark(empDimissionLog.getRemark()); |
| | | dimissionLog.setSelfLeaveDay(empDimissionLog.getSelfLeaveDay()); |
| | | dimissionLog.setReporter(empDimissionLog.getReporter()); |
| | | dimissionLog.setCreator(operatorId); |
| | | dimissionLog.setModifier(operatorId); |
| | | |
| | | dimissionLogService.save(dimissionLog); |
| | | } |
| | | return empBaseInfoMapper.closeEmpArchives(list, empDimissionLog.getDimissionType(), empDimissionLog.getDimissionDate(), empDimissionLog.getRemark(), operatorId)>0; |
| | | } |
| | | /** |
| | | * |
| | | * 员工岗位变更 |
| | | * |
| | | * date 2021-02-18 20:32 |
| | | * @author: luoyibo |
| | | * @param empJobChange 1 |
| | | * @return boolean |
| | | */ |
| | | @Override |
| | | public boolean changeEmpJob(EmpJobChange empJobChange) { |
| | | String[] str = empJobChange.getEmpIds().split(","); |
| | | List<String> list = new ArrayList<>(Arrays.asList(str)); |
| | | String[] strName = empJobChange.getEmpNames().split(","); |
| | | String[] strDeptName = empJobChange.getOldDeptNames().split(","); |
| | | String[] strJobName = empJobChange.getOldJobNames().split(","); |
| | | |
| | | EmpJobChange saveChange = null; |
| | | |
| | | for (int i = 0,k=str.length; i <k ; i++) { |
| | | saveChange = new EmpJobChange(); |
| | | saveChange.setJobChangeId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE)); |
| | | saveChange.setEmpId(Long.parseLong(str[i])); |
| | | saveChange.setEmpName(strName[i]); |
| | | saveChange.setOldDeptName(strDeptName[i]); |
| | | saveChange.setOldJobName(strJobName[i]); |
| | | saveChange.setNewDeptName(empJobChange.getNewDeptName()); |
| | | saveChange.setNewJobName(empJobChange.getNewJobName()); |
| | | saveChange.setChangeType(empJobChange.getChangeType()); |
| | | saveChange.setChangeDate(empJobChange.getChangeDate()); |
| | | saveChange.setChangeReason(empJobChange.getChangeReason()); |
| | | saveChange.setCreator(operatorId); |
| | | saveChange.setModifier(operatorId); |
| | | |
| | | jobChangeService.save(saveChange); |
| | | |
| | | } |
| | | |
| | | Map<String, Object> mapParams = new HashMap<>(); |
| | | mapParams.put("deptId", empJobChange.getDeptId()); |
| | | mapParams.put("deptName", empJobChange.getNewDeptName()); |
| | | mapParams.put("jobId", empJobChange.getJobId()); |
| | | mapParams.put("jobName", empJobChange.getNewJobName()); |
| | | mapParams.put("operatorId", operatorId); |
| | | return empBaseInfoMapper.changeEmpJob(list,mapParams)>0; |
| | | } |
| | | |
| | | /** |
| | | * 导入员工 |
| | | * @param listObject |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importEmpBaseInfo(List<List<Object>> listObject) { |
| | | for (List<Object> list : listObject) { |
| | | EmpBaseInfo empBaseInfo = new EmpBaseInfo(); |
| | | empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE)); |
| | | empBaseInfo.setEmpNumb(list.get(0).toString()); |
| | | List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class); |
| | | empBaseInfo.setDeptName(list.get(1).toString()); |
| | | Long deptId=depts.stream().filter(d -> d.getDeptName().equals(list.get(1).toString())).findFirst().get().getDeptId(); |
| | | empBaseInfo.setDeptId(deptId); |
| | | empBaseInfo.setJobName(list.get(2).toString()); |
| | | empBaseInfo.setEmpName(list.get(3).toString()); |
| | | empBaseInfo.setCertificateNumb(list.get(4).toString()); |
| | | empBaseInfo.setSex("男".equals(list.get(5).toString())?"1":"0"); |
| | | if (StringUtils.isNotBlank(list.get(6).toString())) { |
| | | empBaseInfo.setAge(Integer.valueOf(list.get(6).toString())); |
| | | } |
| | | empBaseInfo.setEducation(list.get(7).toString()); |
| | | empBaseInfo.setNativePlace(list.get(8).toString()); |
| | | empBaseInfo.setTelePhone(list.get(9).toString()); |
| | | if (StringUtils.isNotBlank(list.get(10).toString())) { |
| | | empBaseInfo.setEntryDate(DateUtil.parseDate(list.get(10).toString())); |
| | | } |
| | | empBaseInfo.setEmpStatus("0"); |
| | | this.save(empBaseInfo); |
| | | } |
| | | |
| | | } |
| | | } |