| | |
| | | public void saveSalaryCalculationList(List<HrmSalaryCalculationDO> calculationList) { |
| | | for (HrmSalaryCalculationDO calculation : calculationList) { |
| | | if (calculation.getId() == null) { |
| | | // 新增记录,生成核算单号 |
| | | // 新增前先查重:同一员工(系统账号 ID)+ 同一周期 只允许存在一条记录。 |
| | | // 前端「预览数据 → 保存核算」走的就是这里,不查重会重复插入。 |
| | | List<HrmSalaryCalculationDO> existList = salaryCalculationMapper |
| | | .selectListByUserIdAndPeriod(calculation.getUserId(), calculation.getPeriod()); |
| | | if (CollUtil.isNotEmpty(existList)) { |
| | | HrmSalaryCalculationDO existing = existList.get(0); |
| | | // 已确认/已发放的记录不允许被覆盖,直接跳过 |
| | | if (existing.getStatus() != null && existing.getStatus() != 0) { |
| | | continue; |
| | | } |
| | | // 待确认的记录:覆盖重算结果,保留原单号 |
| | | calculation.setId(existing.getId()); |
| | | calculation.setNo(existing.getNo()); |
| | | calculation.setStatus(0); |
| | | salaryCalculationMapper.updateById(calculation); |
| | | continue; |
| | | } |
| | | // 确实是新增,生成核算单号 |
| | | String no = noRedisDAO.generateSalaryCalculationNo(); |
| | | while (salaryCalculationMapper.selectByNo(no) != null) { |
| | | no = noRedisDAO.generateSalaryCalculationNo(); |