♻️ 调整应收账单来源 ID 为 bigint
This commit is contained in:
@@ -17,7 +17,8 @@ public class ArBillDetail implements Serializable {
|
||||
|
||||
private Long detailId;
|
||||
private Long arBillId;
|
||||
private String prcOrderBillId;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
private Long prcOrderBillId;
|
||||
private Integer detailNo;
|
||||
private String orderNo;
|
||||
private String trackingNo;
|
||||
|
||||
@@ -16,7 +16,8 @@ public class ArBillDetailFee implements Serializable {
|
||||
|
||||
private Long detailFeeId;
|
||||
private Long detailId;
|
||||
private String prcIncomeBillFeeId;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
private Long prcIncomeBillFeeId;
|
||||
private Integer feeNo;
|
||||
private String feeType;
|
||||
private String feeName;
|
||||
|
||||
@@ -40,8 +40,9 @@ public class ArBillGenerateTask implements Serializable {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date snapshotCreateTime;
|
||||
/**
|
||||
* 按 bill_id 字典序处理的游标。
|
||||
* 按 bill_id 数值顺序处理的游标。
|
||||
*/
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
private Long lastSourceBillId;
|
||||
/**
|
||||
* 待处理总数;全选模式统计完成前使用 -1。
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.bms.receivable.domain.vo;
|
||||
|
||||
import com.bms.price.domain.PrcOrderBill;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
/** 应收生成预览中,订单 ID 以字符串传递,避免浏览器整数精度丢失。 */
|
||||
public class ArBillPreviewOrder extends PrcOrderBill {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static ArBillPreviewOrder from(PrcOrderBill source) {
|
||||
ArBillPreviewOrder result = new ArBillPreviewOrder();
|
||||
BeanUtils.copyProperties(source, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
||||
public Long getBillId() {
|
||||
return super.getBillId();
|
||||
}
|
||||
}
|
||||
+4
@@ -5,6 +5,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.bms.receivable.domain.ArBillGenerateTask;
|
||||
import com.bms.price.migration.domain.UuidToNewIdHolder;
|
||||
|
||||
/**
|
||||
* 应收账单异步生成任务 Mapper。
|
||||
@@ -21,6 +22,9 @@ public interface ArBillGenerateTaskMapper {
|
||||
|
||||
List<ArBillGenerateTask> selectWaiting(@Param("limit") int limit);
|
||||
|
||||
/** 历史失败任务重试时,将请求快照中的旧订单 UUID 转为新 ID。 */
|
||||
List<UuidToNewIdHolder> selectMigratedOrderIds(@Param("oldIds") List<String> oldIds);
|
||||
|
||||
int insert(ArBillGenerateTask task);
|
||||
|
||||
int markRunning(@Param("taskId") Long taskId, @Param("startedAt") Date startedAt);
|
||||
|
||||
+55
-5
@@ -19,6 +19,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -45,6 +46,8 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bms.receivable.domain.ArBill;
|
||||
import com.bms.receivable.domain.ArBankAccount;
|
||||
import com.bms.receivable.domain.ArBillDetail;
|
||||
@@ -105,6 +108,7 @@ import com.bms.price.enums.BillBillingFailStatus;
|
||||
import com.bms.price.mapper.PrcIncomeBillMapper;
|
||||
import com.bms.price.mapper.PrcIncomeBillFeeMapper;
|
||||
import com.bms.price.mapper.PrcOrderBillMapper;
|
||||
import com.bms.price.migration.domain.UuidToNewIdHolder;
|
||||
|
||||
/**
|
||||
* 应收账单核心业务实现。
|
||||
@@ -605,7 +609,7 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
if (!ArBillGenerateTaskStatus.FAILED.equals(task.getStatus())) {
|
||||
throw new ServiceException("只有失败的账单生成任务可以重试");
|
||||
}
|
||||
ArBillGenerateRequest request = JSON.parseObject(task.getRequestPayload(), ArBillGenerateRequest.class);
|
||||
ArBillGenerateRequest request = parseRetryRequest(task.getRequestPayload());
|
||||
request.setRequestId(requestId);
|
||||
ArBillGenerateTask retried = generateBill(request, operator, requestId);
|
||||
log.info("应收账单生成任务重试请求已处理,operator={}, requestId={}, sourceTaskId={}, newTaskId={}, status={}, costMs={}",
|
||||
@@ -614,6 +618,52 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
return retried;
|
||||
}
|
||||
|
||||
/** 旧失败任务的选择快照可能保留 UUID;新任务始终使用 bigint ID。 */
|
||||
private ArBillGenerateRequest parseRetryRequest(String payload) {
|
||||
JSONObject data = JSON.parseObject(payload);
|
||||
Set<String> oldIds = new LinkedHashSet<>();
|
||||
for (String field : List.of("sourceBillIds", "excludedSourceBillIds")) {
|
||||
JSONArray ids = data.getJSONArray(field);
|
||||
if (ids == null) continue;
|
||||
for (Object value : ids) {
|
||||
if (value instanceof String text && !isLongId(text)) oldIds.add(text.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
}
|
||||
if (!oldIds.isEmpty()) {
|
||||
List<String> ids = new ArrayList<>(oldIds);
|
||||
Map<String, Long> mapping = new HashMap<>();
|
||||
for (int start = 0; start < ids.size(); start += 500) {
|
||||
for (UuidToNewIdHolder row : generateTaskMapper.selectMigratedOrderIds(
|
||||
ids.subList(start, Math.min(start + 500, ids.size())))) {
|
||||
mapping.put(row.getOldBillId().toLowerCase(Locale.ROOT), row.getNewBillId());
|
||||
}
|
||||
}
|
||||
if (mapping.size() != oldIds.size()) {
|
||||
throw new ServiceException("历史任务的部分订单尚未完成 ID 映射,请重新选择订单生成账单");
|
||||
}
|
||||
for (String field : List.of("sourceBillIds", "excludedSourceBillIds")) {
|
||||
JSONArray values = data.getJSONArray(field);
|
||||
if (values == null) continue;
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
Object value = values.get(i);
|
||||
if (value instanceof String text && mapping.containsKey(text.toLowerCase(Locale.ROOT))) {
|
||||
values.set(i, mapping.get(text.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return JSON.parseObject(data.toJSONString(), ArBillGenerateRequest.class);
|
||||
}
|
||||
|
||||
private boolean isLongId(String value) {
|
||||
try {
|
||||
Long.parseLong(value);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行异步生成任务。每个批次使用短事务,事务内完成来源订单占用、明细落库、
|
||||
* 费用落库和任务游标更新;异常统一进入独立事务清理,避免任务永久卡在运行中。
|
||||
@@ -853,7 +903,7 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
// 失败订单先落快照,再汇总占用状态,避免无费用订单被错误恢复为 UNBILLED。
|
||||
sourceBillMapper.refreshArBillStatusByBillIds(currentSourceBillIds);
|
||||
|
||||
Map<String, ArBillDetail> detailsBySourceBill = new HashMap<>();
|
||||
Map<Long, ArBillDetail> detailsBySourceBill = new HashMap<>();
|
||||
for (ArBillDetail detail : detailMapper.selectByBillIdAndSourceIds(bill.getArBillId(), currentSourceBillIds)) {
|
||||
detailsBySourceBill.put(detail.getPrcOrderBillId(), detail);
|
||||
}
|
||||
@@ -865,7 +915,7 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
Map<Long, Integer> feeNumbers = new HashMap<>();
|
||||
if (sourceFees != null) {
|
||||
for (PrcIncomeBillFee sourceFee : sourceFees) {
|
||||
ArBillDetail detail = detailsBySourceBill.get(String.valueOf(sourceFee.getBillId()));
|
||||
ArBillDetail detail = detailsBySourceBill.get(sourceFee.getBillId());
|
||||
if (detail == null) {
|
||||
throw new ServiceException("来源费用找不到对应的账单明细:" + sourceFee.getBillId());
|
||||
}
|
||||
@@ -1268,7 +1318,7 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
int detailNo, String operator) {
|
||||
ArBillDetail detail = new ArBillDetail();
|
||||
detail.setArBillId(bill.getArBillId());
|
||||
detail.setPrcOrderBillId(String.valueOf(source.getBillId()));
|
||||
detail.setPrcOrderBillId(source.getBillId());
|
||||
detail.setDetailNo(detailNo);
|
||||
detail.setOrderNo(source.getOrderNo());
|
||||
detail.setTrackingNo(source.getTrackingNo());
|
||||
@@ -1304,7 +1354,7 @@ public class ArBillServiceImpl implements IArBillService {
|
||||
private ArBillDetailFee toDetailFee(ArBillDetail detail, PrcIncomeBillFee source, int feeNo, String operator) {
|
||||
ArBillDetailFee fee = new ArBillDetailFee();
|
||||
fee.setDetailId(detail.getDetailId());
|
||||
fee.setPrcIncomeBillFeeId(String.valueOf(source.getFeeId()));
|
||||
fee.setPrcIncomeBillFeeId(source.getFeeId());
|
||||
fee.setFeeNo(feeNo);
|
||||
fee.setFeeType(source.getFeeType());
|
||||
fee.setFeeName(source.getFeeName());
|
||||
|
||||
@@ -785,7 +785,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<select id="selectPrcOrderBillByCustomerPeriodCursor" resultMap="PrcOrderBillArSourceResult">
|
||||
<include refid="selectArBillSourceVo"/>
|
||||
<include refid="customerPeriodConditions"/>
|
||||
<if test="lastSourceBillId != null and lastSourceBillId != ''">
|
||||
<if test="lastSourceBillId != null">
|
||||
and p.bill_id > #{lastSourceBillId}
|
||||
</if>
|
||||
order by p.bill_id
|
||||
|
||||
@@ -56,6 +56,15 @@
|
||||
where task_id = #{taskId}
|
||||
</select>
|
||||
|
||||
<select id="selectMigratedOrderIds" resultType="com.bms.price.migration.domain.UuidToNewIdHolder">
|
||||
select old_bill_id as oldBillId, new_bill_id as newBillId
|
||||
from mig_bi_order_done
|
||||
where status = 'SUCCESS' and old_bill_id in
|
||||
<foreach collection="oldIds" item="oldId" open="(" separator="," close=")">
|
||||
#{oldId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectByRequestToken" parameterType="string" resultMap="ArBillGenerateTaskResult">
|
||||
<include refid="columns"/>
|
||||
where request_token = #{requestToken}
|
||||
|
||||
Reference in New Issue
Block a user