| | |
| | | import cc.mrbird.febs.server.hr.entity.EmpBaseInfo; |
| | | import cc.mrbird.febs.server.hr.entity.EmpContractInfo; |
| | | import cc.mrbird.febs.server.hr.feign.IRemoteDeptService; |
| | | import cc.mrbird.febs.server.hr.mapper.EmpBaseInfoMapper; |
| | | import cc.mrbird.febs.server.hr.mapper.EmpContractInfoMapper; |
| | | import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService; |
| | | import cc.mrbird.febs.server.hr.service.IEmpContractInfoService; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | 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.google.common.collect.Lists; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final EmpContractInfoMapper empContractinfoMapper; |
| | | private final IRemoteDeptService remoteDeptService; |
| | | private final IEmpBaseInfoService empBaseInfoService; |
| | | private final EmpBaseInfoMapper empBaseInfoMapper; |
| | | private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser()) |
| | | .map(u -> u.getUserId().toString()) |
| | | .orElse("1"); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importEmpContractInfo(List<List<Object>> listObject, List<String> returnList, List<DicItem> dicItems) { |
| | | for (List<Object> list : listObject) { |
| | | for (List<Object> list : listObject) { |
| | | if (list.size() == 0 || StrUtil.isBlank(list.get(0).toString())) { |
| | | continue; |
| | | } |
| | |
| | | continue; |
| | | } |
| | | |
| | | // 计算合同结束日期与当前日期之间的间隔天数 |
| | | if (contractInfo.getEndDate() != null) { |
| | | contractInfo.setDiffDay((int) DateUtil.betweenDay(DateUtil.date(), contractInfo.getEndDate(), false)); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(list.get(8).toString())) { |
| | | contractInfo.setContractPeriod(list.get(8).toString()); |
| | | } |
| | |
| | | @Override |
| | | public IPage<EmpContractInfo> findRemindContractinfos(QueryRequest request, EmpContractInfo empContractinfo) { |
| | | int diffDay = Integer.parseInt(redisService.get("contract_remind").toString()); |
| | | List<String> contractStatus = Lists.newArrayList("1","2"); |
| | | QueryWrapper<EmpContractInfo> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("a.DelFlag", empContractinfo.getDelFlag()); |
| | | queryWrapper.eq("a.remindFlag", 0); |
| | | queryWrapper.in("a.contractStatus", contractStatus); |
| | | queryWrapper.le("a.diffDay", diffDay); |
| | | queryWrapper.ge("a.endDate", DateUtil.formatDate(new Date())); |
| | | String rightDepts = remoteDeptService.userRightDepts(); |
| | | |
| | | queryWrapper.in("c.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA)); |
| | | /* |
| | | * 原逻辑:仅查询即将到期的合同 |
| | | */ |
| | | // QueryWrapper<EmpContractInfo> queryWrapper = new QueryWrapper<>(); |
| | | // queryWrapper.eq("a.DelFlag", empContractinfo.getDelFlag()); |
| | | // queryWrapper.eq("a.remindFlag", 0); |
| | | // queryWrapper.in("a.contractStatus", Lists.newArrayList("1","2")); |
| | | // queryWrapper.in("a.empStatus", '0'); |
| | | // queryWrapper.le("a.diffDay", diffDay); |
| | | // queryWrapper.ge("a.endDate", DateUtil.formatDate(new Date())); |
| | | // queryWrapper.in("c.dept_Id", rightDepts.split(StringConstant.COMMA)); |
| | | // Page<EmpContractInfo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | // SortUtil.handlePageSort(request, page, "diffDay", FebsConstant.ORDER_ASC, true); |
| | | // IPage<EmpContractInfo> iPage = empContractinfoMapper.selectPageVo(page, queryWrapper); |
| | | |
| | | /* |
| | | * 新逻辑:查询在职人员的最后一份合同 |
| | | * 状态1或2:按原条件提醒(未到期、未提醒、在范围内) |
| | | * 状态4:已到期末,系统中无最新合同,直接提醒 |
| | | */ |
| | | // 处理部门ID,添加引号 |
| | | String[] deptIds = rightDepts.split(StringConstant.COMMA); |
| | | StringBuilder quotedDepts = new StringBuilder(); |
| | | for (int i = 0; i < deptIds.length; i++) { |
| | | if (i > 0) { |
| | | quotedDepts.append(","); |
| | | } |
| | | quotedDepts.append("'").append(deptIds[i]).append("'"); |
| | | } |
| | | |
| | | // 构建SQL:在职人员的最后一份合同 |
| | | // 使用INNER JOIN替代子查询,提高性能 |
| | | String today = DateUtil.formatDate(new Date()); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("b.empStatus = '0'"); // 员工当前在职 |
| | | sql.append(" AND a.DelFlag = ").append(empContractinfo.getDelFlag()); |
| | | // 关联子查询获取每个人的最后一份合同 |
| | | sql.append(" AND EXISTS ("); |
| | | sql.append("SELECT 1 FROM ("); |
| | | sql.append("SELECT empId, MAX(beginDate) as maxBeginDate "); |
| | | sql.append("FROM t_emp_contractinfo "); |
| | | sql.append("GROUP BY empId"); |
| | | sql.append(") latest "); |
| | | sql.append("WHERE latest.empId = a.empId AND latest.maxBeginDate = a.beginDate"); |
| | | sql.append(")"); |
| | | // 合同状态判断 |
| | | sql.append(" AND ((a.contractStatus IN ('1', '2')"); // 状态1或2 |
| | | sql.append(" AND a.remindFlag = 0"); |
| | | sql.append(" AND a.diffDay <= ").append(diffDay); |
| | | sql.append(" AND a.endDate >= '").append(today).append("'"); |
| | | sql.append(") OR (a.contractStatus = '4'"); // 状态4 |
| | | sql.append(" AND a.endDate < '").append(today).append("'"); |
| | | sql.append("))"); |
| | | sql.append(" AND c.dept_Id IN (").append(quotedDepts).append(")"); |
| | | |
| | | // 查询 |
| | | Page<EmpContractInfo> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | SortUtil.handlePageSort(request, page, "diffDay", FebsConstant.ORDER_ASC, true); |
| | | IPage<EmpContractInfo> iPage = empContractinfoMapper.selectPageVo(page, queryWrapper); |
| | | IPage<EmpContractInfo> iPage = empContractinfoMapper.selectLastContractPageVo(page, sql.toString()); |
| | | |
| | | List<EmpContractInfo> list = iPage.getRecords(); |
| | | //设置字典数据 |
| | | List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class); |
| | |
| | | //设置不再提醒 |
| | | empContractinfoMapper.updateEmpContractRemind(contractId); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void retireRehireEmpContract(EmpContractInfo empContractinfo) { |
| | | // 1.将原来合同状态为解除 |
| | | empContractinfoMapper.terminateContract(Collections.singletonList(String.valueOf(empContractinfo.getEmpId())), operatorId); |
| | | // 2.创建一份新合同信息 |
| | | empContractinfo.setDelFlag(0); |
| | | this.createEmpContractinfo(empContractinfo); |
| | | // 不再提醒 |
| | | empBaseInfoMapper.updateRetirementReminded(empContractinfo.getEmpId().toString(), "1", operatorId); |
| | | } |
| | | } |