diff --git a/src/main/java/com/ydool/staff/service/impl/PersonnelServiceImpl.java b/src/main/java/com/ydool/staff/service/impl/PersonnelServiceImpl.java index a6df69f..42cf4c5 100644 --- a/src/main/java/com/ydool/staff/service/impl/PersonnelServiceImpl.java +++ b/src/main/java/com/ydool/staff/service/impl/PersonnelServiceImpl.java @@ -271,19 +271,38 @@ public class PersonnelServiceImpl extends BaseService asList = Arrays.asList(ids.getIds()); - for (String s : asList) { - Personnel personnel = personnelMapper.selectOne(new LambdaQueryWrapper().eq(Personnel::getId, s).eq(Personnel::getAlterationSign, "1") - .eq(Personnel::getChangeAlterationSign, "1").in(Personnel::getAuditState, 1, 2).in(Personnel::getChangeAuditState, 1, 2)); + List idList = Arrays.asList(ids.getIds()); + + for (String id : idList) { + Personnel personnel = personnelMapper.selectOne(new LambdaQueryWrapper() + .eq(Personnel::getId, id) + .eq(Personnel::getAlterationSign, "1") + .eq(Personnel::getChangeAlterationSign, "1") + .in(Personnel::getAuditState, 1, 2) + .in(Personnel::getChangeAuditState, 1, 2)); + if (ObjectUtil.isNotEmpty(personnel)) { return AjaxResult.fail().msg("该人员有变更中或待审批数据,不能删除!"); } } - if (CollectionUtil.isEmpty(asList)) { + + if (CollectionUtil.isEmpty(idList)) { return AjaxResult.fail().msg("Id不能为空!"); } else { - int i = personnelMapper.deleteBatchIds(asList); - return i > 0 ? AjaxResult.ok().msg("删除成功!") : AjaxResult.fail().msg("删除失败!"); + List personnels = personnelMapper.selectBatchIds(idList); + + for (Personnel personnel : personnels) { + if ("退休".equals(personnel.getWorkState()) || "离职".equals(personnel.getWorkState())) { + CompanyName companyName = companyNameMapper.selectById(personnel.getCompanyName()); + if (companyName != null) { + companyName.setResidualNumber(companyName.getResidualNumber() - 1); + companyNameMapper.updateById(companyName); + } + } + } + + int deleteCount = personnelMapper.deleteBatchIds(idList); + return deleteCount > 0 ? AjaxResult.ok().msg("删除成功!") : AjaxResult.fail().msg("删除失败!"); } }