demand: TMS系统财务销账优化
committer: heyu
This commit is contained in:
parent
1b5f7b5730
commit
9173fc069b
@ -1134,15 +1134,17 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
String applyManName = StringUtils.hasText(apply.getApplyManName()) ? apply.getApplyManName()
|
||||
: apply.getApplyManCode();
|
||||
|
||||
// 获取操作人姓名
|
||||
// 获取操作人姓名 - 通过当前登录账号获取
|
||||
String operatorName = "";
|
||||
if ("centerPass".equals(actionType) || "centerReject".equals(actionType)) {
|
||||
operatorName = StringUtils.hasText(apply.getCenterConfirmManName()) ? apply.getCenterConfirmManName()
|
||||
: apply.getCenterConfirmManCode();
|
||||
} else if ("headquartersReject".equals(actionType)) {
|
||||
operatorName = StringUtils.hasText(apply.getHeadquartersConfirmManName())
|
||||
? apply.getHeadquartersConfirmManName()
|
||||
: apply.getHeadquartersConfirmManCode();
|
||||
try {
|
||||
SysUser currentUser = getCurrentUser();
|
||||
if (currentUser != null) {
|
||||
operatorName = StringUtils.hasText(currentUser.getEmpName()) ? currentUser.getEmpName()
|
||||
: currentUser.getEmpCode();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取当前登录用户信息失败,使用默认操作人", e);
|
||||
operatorName = "系统";
|
||||
}
|
||||
|
||||
// 构建通知内容
|
||||
@ -1214,57 +1216,56 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
continue;
|
||||
}
|
||||
|
||||
// 计算该运单的总申请金额
|
||||
BigDecimal totalApplyMoney = waybillDetails.stream()
|
||||
.map(detail -> detail.getApplyMoney() != null ? detail.getApplyMoney() : BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 计算该运单的总已收金额
|
||||
BigDecimal totalReceivedMoney = waybillDetails.stream()
|
||||
.map(detail -> detail.getEmisSettleSubBill() != null
|
||||
&& detail.getEmisSettleSubBill().getRecedMoney() != null
|
||||
? detail.getEmisSettleSubBill().getRecedMoney()
|
||||
: BigDecimal.ZERO)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 获取运单运费
|
||||
BigDecimal waybillFreight = firstDetail.getEmisWaybill().getFreight() != null
|
||||
? firstDetail.getEmisWaybill().getFreight()
|
||||
: BigDecimal.ZERO;
|
||||
|
||||
// 更新运单付款状态
|
||||
EmisWaybill updateWaybill = new EmisWaybill();
|
||||
updateWaybill.setBillCode(billCode);
|
||||
// 对每个运单明细单独计算并更新付款状态
|
||||
for (EmisWriteoffApplyDetail detail : waybillDetails) {
|
||||
// 计算该明细的申请金额
|
||||
BigDecimal applyMoney = detail.getApplyMoney() != null ? detail.getApplyMoney()
|
||||
: BigDecimal.ZERO;
|
||||
|
||||
if (isPass) {
|
||||
// 审核通过:申请金额 + 已收金额 与运单金额比较
|
||||
BigDecimal totalAmount = totalApplyMoney.add(totalReceivedMoney);
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
updateWaybill.setPaymentStatus("0"); // 未付款
|
||||
} else if (totalAmount.compareTo(waybillFreight) >= 0) {
|
||||
updateWaybill.setPaymentStatus("1"); // 已付款
|
||||
// 计算该明细的已收金额
|
||||
BigDecimal receivedMoney = detail.getEmisSettleSubBill() != null
|
||||
&& detail.getEmisSettleSubBill().getRecedMoney() != null
|
||||
? detail.getEmisSettleSubBill().getRecedMoney()
|
||||
: BigDecimal.ZERO;
|
||||
|
||||
// 更新运单付款状态
|
||||
EmisWaybill updateWaybill = new EmisWaybill();
|
||||
updateWaybill.setBillCode(billCode);
|
||||
|
||||
if (isPass) {
|
||||
// 审核通过:申请金额 + 已收金额 与运单金额比较
|
||||
BigDecimal totalAmount = applyMoney.add(receivedMoney);
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
updateWaybill.setPaymentStatus("0"); // 未付款
|
||||
} else if (totalAmount.compareTo(waybillFreight) >= 0) {
|
||||
updateWaybill.setPaymentStatus("1"); // 已付款
|
||||
} else {
|
||||
updateWaybill.setPaymentStatus("2"); // 部分付款
|
||||
}
|
||||
} else {
|
||||
updateWaybill.setPaymentStatus("2"); // 部分付款
|
||||
}
|
||||
} else {
|
||||
// 审核驳回:申请金额 + 已收金额 与运单金额比较
|
||||
BigDecimal totalAmount = totalReceivedMoney; // 驳回时只考虑已收金额
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
updateWaybill.setPaymentStatus("0"); // 未付款
|
||||
} else if (totalAmount.compareTo(waybillFreight) >= 0) {
|
||||
updateWaybill.setPaymentStatus("1"); // 已付款
|
||||
} else {
|
||||
updateWaybill.setPaymentStatus("2"); // 部分付款
|
||||
// 审核驳回:只考虑已收金额与运单金额比较
|
||||
if (receivedMoney.compareTo(BigDecimal.ZERO) == 0) {
|
||||
updateWaybill.setPaymentStatus("0"); // 未付款
|
||||
} else if (receivedMoney.compareTo(waybillFreight) >= 0) {
|
||||
updateWaybill.setPaymentStatus("1"); // 已付款
|
||||
} else {
|
||||
updateWaybill.setPaymentStatus("2"); // 部分付款
|
||||
}
|
||||
}
|
||||
|
||||
// 更新运单付款状态
|
||||
emisWaybillMapper.updatePayedStatus(updateWaybill);
|
||||
|
||||
log.info("运单付款状态更新成功,运单号: {}, 明细ID: {}, 付款状态: {}, 申请金额: {}, 已收金额: {}, 运单运费: {}",
|
||||
billCode, detail.getId(), updateWaybill.getPaymentStatus(), applyMoney, receivedMoney,
|
||||
waybillFreight);
|
||||
}
|
||||
|
||||
// 更新运单付款状态
|
||||
emisWaybillMapper.updatePayedStatus(updateWaybill);
|
||||
|
||||
log.info("运单付款状态更新成功,运单号: {}, 付款状态: {}, 申请金额: {}, 已收金额: {}, 运单运费: {}",
|
||||
billCode, updateWaybill.getPaymentStatus(), totalApplyMoney, totalReceivedMoney,
|
||||
waybillFreight);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新运单付款状态失败,运单号: {}", billCode, e);
|
||||
// 继续处理其他运单,不抛出异常
|
||||
|
||||
Loading…
Reference in New Issue
Block a user