diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillAjustApplyServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillAjustApplyServiceImpl.java index 6efc9671f..5e5fc31ed 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillAjustApplyServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillAjustApplyServiceImpl.java @@ -62,7 +62,6 @@ public class EmisWaybillAjustApplyServiceImpl extends EmisBaseService implements @Autowired private SysPostMapper postMapper; - @Autowired private IEmisSettleSubBillService emisSettleSubBillService; @@ -584,19 +583,44 @@ public class EmisWaybillAjustApplyServiceImpl extends EmisBaseService implements } } - // 5. 查询去重后的emp_name对应的emp_code + // 5. 查询去重后的emp_name对应的emp_code,并构建empCode->empName映射,避免后续重复查询 Set notifyEmpCodes = new HashSet<>(); - for (String empName : empNames) { - List empCodes = getEmpCodesByEmpName(empName); - notifyEmpCodes.addAll(empCodes); + java.util.Map empCodeToName = new java.util.HashMap<>(); + for (String name : empNames) { + SysUser cond = new SysUser(); + cond.setEmpName(name); + List users = sysUserMapper.selectUserList(cond); + if (!CollectionUtils.isEmpty(users)) { + for (SysUser u : users) { + if (u != null && !StringUtils.isEmpty(u.getEmpCode())) { + notifyEmpCodes.add(u.getEmpCode()); + if (!StringUtils.isEmpty(u.getEmpName())) { + empCodeToName.put(u.getEmpCode(), u.getEmpName()); + } + } + } + } } - // 6. 分别调用sendNoticeToEmpUser发送通知 + // 6. 循环外预先计算申请人姓名与费用变更字符串,减少重复计算 + SysUser applyUser = getEmisStaffByCode(emisWaybillAjustApply.getApplyManCode()); + String applyManName = (applyUser != null && !StringUtils.isEmpty(applyUser.getEmpName())) + ? applyUser.getEmpName() + : emisWaybillAjustApply.getApplyManCode(); + BigDecimal oldFreight = emisWaybillOld != null ? emisWaybillOld.getFreight() : null; + BigDecimal newFreight = emisWaybillSave != null ? emisWaybillSave.getFreight() : null; + String oldFreightStr = oldFreight == null ? "-" : oldFreight.stripTrailingZeros().toPlainString(); + String newFreightStr = newFreight == null ? "-" : newFreight.stripTrailingZeros().toPlainString(); + + // 7. 分别调用sendNoticeToEmpUser发送通知 if (!notifyEmpCodes.isEmpty()) { for (String empCode : notifyEmpCodes) { if (!StringUtils.isEmpty(empCode)) { - String title = emisWaybillAjustApply.getApplyManCode() + "已对运单费用进行调整," + "请" + empCode + "仔细核对," - + "单号【" + emisWaybillAjustApply.getBillCode() + "】"; + String empName = !StringUtils.isEmpty(empCodeToName.get(empCode)) ? empCodeToName.get(empCode) + : empCode; + String title = applyManName + "已对运单费用进行调整," + "请" + empName + "仔细核对," + + "单号【" + emisWaybillAjustApply.getBillCode() + "】" + ",运费由" + oldFreightStr + "调整为" + + newFreightStr; sendNoticeToEmpUser(empCode, title, "", clickPath); }