diff --git a/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java b/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java index 2ca312be7..3031ffeae 100644 --- a/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryItemServiceImpl.java @@ -148,13 +148,13 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService .sorted(new Comparator() { @Override public int compare(SalaryItemPO o1, SalaryItemPO o2) { - if(o1.getSortedIndex() == null && o2.getSortedIndex() == null){ - Integer systemType1=o1.getSystemType() == null ? 0 : o1.getSystemType(); - Integer systemType2=o2.getSystemType() == null ? 0 : o2.getSystemType(); + if (o1.getSortedIndex() == null && o2.getSortedIndex() == null) { + Integer systemType1 = o1.getSystemType() == null ? 0 : o1.getSystemType(); + Integer systemType2 = o2.getSystemType() == null ? 0 : o2.getSystemType(); return systemType1.compareTo(systemType2); - }else{ - Integer sortedIndex1=o1.getSortedIndex() == null ? 0 : o1.getSortedIndex(); - Integer sortedIndex2=o2.getSortedIndex() == null ? 0 : o2.getSortedIndex(); + } else { + Integer sortedIndex1 = o1.getSortedIndex() == null ? 0 : o1.getSortedIndex(); + Integer sortedIndex2 = o2.getSortedIndex() == null ? 0 : o2.getSortedIndex(); return sortedIndex2.compareTo(sortedIndex1); } } @@ -263,35 +263,24 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService if (!StringUtils.equals(oldName, newName)) { //薪资项目 - String itemPrefix = newSalaryItemPO.getUseInEmployeeSalary() == 0 ? "salaryItem_" : "salaryArchives_"; - String fieldNamePrefix = newSalaryItemPO.getUseInEmployeeSalary() == 0 ? "{薪资项目.%s}" : "{薪资档案.%s}"; - String code = itemPrefix + salaryItemPO.getCode(); - Date now = new Date(); - List formulaVars = getSalaryFormulaService(user).listByCode(code); - formulaVars.forEach(v -> { - FormulaVar formulaVar = FormulaVar.builder() - .id(v.getId()) - .name(newName) - .fieldName(String.format(fieldNamePrefix, newName)) - .updateTime(now) - .build(); - getSalaryFormulaService(user).updateVar(formulaVar); - }); + if (newSalaryItemPO.getUseInEmployeeSalary() == 0) { + String itemPrefix = "salaryItem_"; + String fieldNamePrefix = "{薪资项目.%s}"; + changeName(salaryItemPO, oldName, newName, itemPrefix, fieldNamePrefix); + } - List formulaIds = SalaryEntityUtil.properties(formulaVars, FormulaVar::getFormulaId, Collectors.toList()); - List formulaPOS = getSalaryFormulaService(user).listByIds(formulaIds); - formulaPOS.forEach(f -> { - String formula = f.getFormula(); - formula = formula.replace(String.format(fieldNamePrefix, oldName), String.format(fieldNamePrefix, newName)); - FormulaPO formulaPO = FormulaPO.builder() - .id(f.getId()) - .formula(formula) - .updateTime(now) - .build(); - getSalaryFormulaService(user).update(formulaPO); - }); + if (newSalaryItemPO.getUseInEmployeeSalary() == 1) { + //引用档案 + String itemPrefix = "salaryArchives_"; + String fieldNamePrefix = "{薪资档案.%s}"; + changeName(salaryItemPO, oldName, newName, itemPrefix, fieldNamePrefix); + //引用项目 + itemPrefix = "salaryItem_"; + fieldNamePrefix = "{薪资项目.%s}"; + changeName(salaryItemPO, oldName, newName, itemPrefix, fieldNamePrefix); + } } @@ -307,6 +296,34 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService // salaryItemLoggerTemplate.write(loggerContext); } + private void changeName(SalaryItemPO salaryItemPO, String oldName, String newName, String itemPrefix, String fieldNamePrefix) { + String code = itemPrefix + salaryItemPO.getCode(); + Date now = new Date(); + List formulaVars = getSalaryFormulaService(user).listByCode(code); + formulaVars.forEach(v -> { + FormulaVar formulaVar = FormulaVar.builder() + .id(v.getId()) + .name(newName) + .fieldName(String.format(fieldNamePrefix, newName)) + .updateTime(now) + .build(); + getSalaryFormulaService(user).updateVar(formulaVar); + }); + + List formulaIds = SalaryEntityUtil.properties(formulaVars, FormulaVar::getFormulaId, Collectors.toList()); + List formulaPOS = getSalaryFormulaService(user).listByIds(formulaIds); + formulaPOS.forEach(f -> { + String formula = f.getFormula(); + formula = formula.replace(String.format(fieldNamePrefix, oldName), String.format(fieldNamePrefix, newName)); + FormulaPO formulaPO = FormulaPO.builder() + .id(f.getId()) + .formula(formula) + .updateTime(now) + .build(); + getSalaryFormulaService(user).update(formulaPO); + }); + } + @Override public void deleteByIds(Collection ids) { SalaryItemServiceImpl.UsingItem usingItem = getUsingItem(); @@ -423,7 +440,7 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService } // 获取薪资账套中薪资项目信息 List salarySobItemPOS = getSalarySobItemService(user).listBySalaryItemIds(Collections.singleton(param.getSalaryItemId())); - salarySobItemPOS = salarySobItemPOS.stream().filter( po -> param.getSalarySobIds().contains(po.getSalarySobId())).collect(Collectors.toList()); + salarySobItemPOS = salarySobItemPOS.stream().filter(po -> param.getSalarySobIds().contains(po.getSalarySobId())).collect(Collectors.toList()); // 更新薪资账套中的薪资项目信息 Date now = new Date(); for (SalarySobItemPO sobItem : salarySobItemPOS) {