修改更新欠费状态功能

This commit is contained in:
wuweihua
2026-09-23 15:53:12 +08:00
parent 8522201248
commit c62433c09e
9 changed files with 253 additions and 18 deletions
@@ -50,5 +50,13 @@ public interface IPrcOrderBillService
*/
void clearCreditArrearsByAmount(String customerCode, BigDecimal amount);
/**
* 计费列表手动更新欠费状态:仅 ARREARS 可更为 NORMAL。
* 校验逻辑与计费同步额度一致(客户正常 + 有足够可用额度),不通过则拒绝。
*
* @param billId 订单计费ID
* @return 更新后的计费结果
*/
TmsPriceQuoteResult updateCreditArrearsStatus(String billId);
}
@@ -22,6 +22,7 @@ import com.ruoyi.ar.enums.ArIncomeBillFeeStatus;
import com.ruoyi.ar.enums.ArOrderBillStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.sign.Md5Utils;
import com.ruoyi.price.domain.PrcIncomeBill;
@@ -530,6 +531,76 @@ public class PrcOrderBillServiceImpl implements IPrcOrderBillService
}
}
/**
* 计费列表手动更新欠费状态:校验可用额度(与计费同步一致)后将 ARREARS 更为 NORMAL。
*/
@Override
@Transactional(rollbackFor = Exception.class)
public TmsPriceQuoteResult updateCreditArrearsStatus(String billId)
{
if (StringUtils.isEmpty(billId))
{
throw new ServiceException(MessageUtils.message("price.bill.billIdRequired"));
}
PrcOrderBill bill = orderBillMapper.selectPrcOrderBillById(billId.trim());
if (bill == null)
{
throw new ServiceException(MessageUtils.message("price.bill.notFound"));
}
if (!BillCreditArrearsStatus.ARREARS.getCode().equals(bill.getCreditArrearsStatus()))
{
throw new ServiceException("仅欠费订单可更新为正常");
}
String customerActive = normalizeCustomerActiveStatus(bill.getCustomerActiveStatus());
if (!BillCustomerActiveStatus.ACTIVE.getCode().equals(customerActive))
{
throw new ServiceException("客户状态非正常,不能更新欠费状态");
}
// 与计费同步一致:已欠费或可用额度不足则拒绝(本单额度已占用,按可用额度>=0 判定)
if (isCreditInsufficient(bill.getCustomerId(), bill.getCustomerCode(), BigDecimal.ZERO))
{
throw new ServiceException("可用额度不足,不能更新为正常");
}
String operator = SecurityUtils.getUsername();
if (StringUtils.isEmpty(operator))
{
operator = "system";
}
String normal = BillCreditArrearsStatus.NORMAL.getCode();
orderBillMapper.updateCreditArrearsStatus(bill.getBillId(), normal, operator);
bill.setCreditArrearsStatus(normal);
saveManualArrearsUpdateEsLog(bill, true, null);
return toResult(bill, incomeBillFeeMapper.selectByBillId(bill.getBillId()),
payBillFeeMapper.selectByBillId(bill.getBillId()));
}
private void saveManualArrearsUpdateEsLog(PrcOrderBill bill, boolean success, String errorMessage)
{
if (billSearchStore == null || bill == null || StringUtils.isEmpty(bill.getOrderNo()))
{
return;
}
JSONObject req = new JSONObject();
req.put("action", "MANUAL_CLEAR_ARREARS");
req.put("scope", "ORDER");
req.put("orderNo", bill.getOrderNo());
req.put("billId", bill.getBillId());
req.put("customerCode", bill.getCustomerCode());
req.put("incomeTotal", bill.getIncomeTotal());
req.put("fromStatus", BillCreditArrearsStatus.ARREARS.getCode());
req.put("toStatus", BillCreditArrearsStatus.NORMAL.getCode());
JSONObject resp = new JSONObject();
resp.put("success", Boolean.valueOf(success));
if (StringUtils.isNotEmpty(errorMessage))
{
resp.put("msg", errorMessage);
}
String status = success ? EsBizLogSupport.STATUS_SUCCESS : EsBizLogSupport.STATUS_FAIL;
String err = success ? null : EsBizLogSupport.cut(errorMessage);
billSearchStore.save(EsLogType.ARREARS, bill.getOrderNo(), req.toJSONString(), resp.toJSONString(), status, err);
}
private TmsOrderBillMatchType resolveTmsMatchType(String identifier, PrcOrderBill bill)
{
if (identifier.equalsIgnoreCase(StringUtils.trim(bill.getOrderNo())))