删除 UUID 到 bigint 阴影同步相关的控制器、服务、映射器及配置文件

This commit is contained in:
wuweihua
2026-11-18 09:36:53 +08:00
parent ca45e15559
commit fb15b12275
21 changed files with 6 additions and 2109 deletions
@@ -1,95 +0,0 @@
package com.bms.price.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* UUID -> bigint 阴影同步配置(bms.mig.uuid-to-new)
* 运行开关/线程/批次由监控页控制,不走 cron。
*/
@Component
@ConfigurationProperties(prefix = "bms.mig.uuid-to-new")
public class UuidToNewProperties
{
/** Master switch; default false after Long PK cutover. */
private boolean enabled = false;
/** 每轮抓取订单数(1~1000) */
private int batchSize = 200;
/**
* 批内工作线程数(1~16)。
* 默认1;冲刺可上到与本地重计费相近的16,4核机器需盯CPU/连接池。
*/
private int threadCount = 1;
/** 无待处理订单时空转睡眠毫秒(开关仍为开时) */
private long idleSleepMs = 3000L;
public boolean isEnabled()
{
return enabled;
}
public void setEnabled(boolean enabled)
{
this.enabled = enabled;
}
public int getBatchSize()
{
return batchSize;
}
public void setBatchSize(int batchSize)
{
this.batchSize = batchSize;
}
/** 限定在 1~1000 */
public int resolvedBatchSize()
{
int n = batchSize;
if (n < 1)
{
return 1;
}
if (n > 1000)
{
return 1000;
}
return n;
}
public int getThreadCount()
{
return threadCount;
}
public void setThreadCount(int threadCount)
{
this.threadCount = threadCount;
}
/** 限定在1~16 */
public int resolvedThreadCount()
{
int n = threadCount;
if (n < 1)
{
return 1;
}
if (n > 16)
{
return 16;
}
return n;
}
public long getIdleSleepMs()
{
return idleSleepMs;
}
public void setIdleSleepMs(long idleSleepMs)
{
this.idleSleepMs = idleSleepMs;
}
}
@@ -1,49 +0,0 @@
package com.bms.price.migration.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* mig_bi_job_log 批次日志
*/
public class MigBiJobLog
{
private Long id;
private String batchNo;
private Integer fetched;
private Integer success;
private Integer fail;
private Integer skip;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date startedAt;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date finishedAt;
private String remark;
/** 查询:开始时间起 */
private String beginStartedAt;
/** 查询:开始时间止 */
private String endStartedAt;
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
public String getBatchNo() { return batchNo; }
public void setBatchNo(String batchNo) { this.batchNo = batchNo; }
public Integer getFetched() { return fetched; }
public void setFetched(Integer fetched) { this.fetched = fetched; }
public Integer getSuccess() { return success; }
public void setSuccess(Integer success) { this.success = success; }
public Integer getFail() { return fail; }
public void setFail(Integer fail) { this.fail = fail; }
public Integer getSkip() { return skip; }
public void setSkip(Integer skip) { this.skip = skip; }
public Date getStartedAt() { return startedAt; }
public void setStartedAt(Date startedAt) { this.startedAt = startedAt; }
public Date getFinishedAt() { return finishedAt; }
public void setFinishedAt(Date finishedAt) { this.finishedAt = finishedAt; }
public String getRemark() { return remark; }
public void setRemark(String remark) { this.remark = remark; }
public String getBeginStartedAt() { return beginStartedAt; }
public void setBeginStartedAt(String beginStartedAt) { this.beginStartedAt = beginStartedAt; }
public String getEndStartedAt() { return endStartedAt; }
public void setEndStartedAt(String endStartedAt) { this.endStartedAt = endStartedAt; }
}
@@ -1,25 +0,0 @@
package com.bms.price.migration.domain;
/**
* 一批阴影同步结果(供运行器做失败退避/自动停开)
*/
public class UuidToNewBatchResult
{
private int fetched;
private int success;
private int fail;
private int skip;
/** 本批首条失败原因(截断) */
private String sampleError;
public int getFetched() { return fetched; }
public void setFetched(int fetched) { this.fetched = fetched; }
public int getSuccess() { return success; }
public void setSuccess(int success) { this.success = success; }
public int getFail() { return fail; }
public void setFail(int fail) { this.fail = fail; }
public int getSkip() { return skip; }
public void setSkip(int skip) { this.skip = skip; }
public String getSampleError() { return sampleError; }
public void setSampleError(String sampleError) { this.sampleError = sampleError; }
}
@@ -1,15 +0,0 @@
package com.bms.price.migration.domain;
/**
* 旧收入费用行:逐行插入 income *_new 并建内存 Map
*/
public class UuidToNewFeeRow
{
private String feeId;
private String parentId;
public String getFeeId() { return feeId; }
public void setFeeId(String feeId) { this.feeId = feeId; }
public String getParentId() { return parentId; }
public void setParentId(String parentId) { this.parentId = parentId; }
}
@@ -1,54 +0,0 @@
package com.bms.price.migration.domain;
/**
* 阴影插入传参 / 接收自增主键、批次日志
*/
public class UuidToNewIdHolder
{
private String oldBillId;
private Long newBillId;
/** 旧 income_bill_id / fee_id(UUID) */
private String oldId;
/** 新 income_bill_id / fee_id(bigint) */
private Long newId;
/** 新 income_bill_id(费用行用) */
private Long newIncomeId;
private String orderNo;
private String status;
private String failReason;
private String batchNo;
private Integer fetched;
private Integer success;
private Integer fail;
private Integer skip;
private Long jobLogId;
public String getOldBillId() { return oldBillId; }
public void setOldBillId(String oldBillId) { this.oldBillId = oldBillId; }
public Long getNewBillId() { return newBillId; }
public void setNewBillId(Long newBillId) { this.newBillId = newBillId; }
public String getOldId() { return oldId; }
public void setOldId(String oldId) { this.oldId = oldId; }
public Long getNewId() { return newId; }
public void setNewId(Long newId) { this.newId = newId; }
public Long getNewIncomeId() { return newIncomeId; }
public void setNewIncomeId(Long newIncomeId) { this.newIncomeId = newIncomeId; }
public String getOrderNo() { return orderNo; }
public void setOrderNo(String orderNo) { this.orderNo = orderNo; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
public String getFailReason() { return failReason; }
public void setFailReason(String failReason) { this.failReason = failReason; }
public String getBatchNo() { return batchNo; }
public void setBatchNo(String batchNo) { this.batchNo = batchNo; }
public Integer getFetched() { return fetched; }
public void setFetched(Integer fetched) { this.fetched = fetched; }
public Integer getSuccess() { return success; }
public void setSuccess(Integer success) { this.success = success; }
public Integer getFail() { return fail; }
public void setFail(Integer fail) { this.fail = fail; }
public Integer getSkip() { return skip; }
public void setSkip(Integer skip) { this.skip = skip; }
public Long getJobLogId() { return jobLogId; }
public void setJobLogId(Long jobLogId) { this.jobLogId = jobLogId; }
}
@@ -1,17 +0,0 @@
package com.bms.price.migration.domain;
import java.util.Date;
/**
* 待同步订单(含游标 create_time)
*/
public class UuidToNewPendingRow
{
private String billId;
private Date createTime;
public String getBillId() { return billId; }
public void setBillId(String billId) { this.billId = billId; }
public Date getCreateTime() { return createTime; }
public void setCreateTime(Date createTime) { this.createTime = createTime; }
}
@@ -1,38 +0,0 @@
package com.bms.price.migration.domain;
/**
* UUID 阴影同步进度概览
*/
public class UuidToNewProgressVo
{
private long oldCnt;
private long doneCnt;
private long newCnt;
private long pendingCnt;
private double donePercent;
/** 监控页开关:是否要跑 */
private boolean enabled;
/** 循环是否正在执行中 */
private boolean running;
private int batchSize;
private int threadCount;
public long getOldCnt() { return oldCnt; }
public void setOldCnt(long oldCnt) { this.oldCnt = oldCnt; }
public long getDoneCnt() { return doneCnt; }
public void setDoneCnt(long doneCnt) { this.doneCnt = doneCnt; }
public long getNewCnt() { return newCnt; }
public void setNewCnt(long newCnt) { this.newCnt = newCnt; }
public long getPendingCnt() { return pendingCnt; }
public void setPendingCnt(long pendingCnt) { this.pendingCnt = pendingCnt; }
public double getDonePercent() { return donePercent; }
public void setDonePercent(double donePercent) { this.donePercent = donePercent; }
public boolean isEnabled() { return enabled; }
public void setEnabled(boolean enabled) { this.enabled = enabled; }
public boolean isRunning() { return running; }
public void setRunning(boolean running) { this.running = running; }
public int getBatchSize() { return batchSize; }
public void setBatchSize(int batchSize) { this.batchSize = batchSize; }
public int getThreadCount() { return threadCount; }
public void setThreadCount(int threadCount) { this.threadCount = threadCount; }
}
@@ -1,78 +0,0 @@
package com.bms.price.migration.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.price.migration.domain.MigBiJobLog;
import com.bms.price.migration.domain.UuidToNewFeeRow;
import com.bms.price.migration.domain.UuidToNewPendingRow;
import java.util.Date;
import com.bms.price.migration.domain.UuidToNewIdHolder;
import com.bms.price.migration.domain.UuidToNewProgressVo;
/**
* UUID -> bigint 阴影同步 Mapper(订单+income *_new + order_id / income_fee_id)
*/
public interface UuidToNewSyncMapper
{
/**
* 游标抓取未处理订单(避免每批从最早订单全量排序)
* @param lastCreateTime 上批最后 create_time;空=从头
* @param lastBillId 上批最后 bill_id;与 time 配对
*/
List<UuidToNewPendingRow> selectPendingBillIds(@Param("limit") int limit,
@Param("lastCreateTime") Date lastCreateTime,
@Param("lastBillId") String lastBillId);
/** done 已有进度且 Redis 无游标时:用最新 done 边界初始化 */
UuidToNewPendingRow selectPendingCursorBootstrap();
String selectOrderNo(@Param("oldBillId") String oldBillId);
int countOrderBill(@Param("oldBillId") String oldBillId);
int insertOrderBillNew(UuidToNewIdHolder holder);
int insertOrderDone(UuidToNewIdHolder holder);
/** INSERT IGNORE 占坑;返回 0 表示已被占用 */
int claimOrderDone(UuidToNewIdHolder holder);
int updateOrderDoneSuccess(UuidToNewIdHolder holder);
int updateOrderDoneFail(UuidToNewIdHolder holder);
int insertOrderExtNew(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
List<String> selectIncomeIds(@Param("oldBillId") String oldBillId);
int insertIncomeBillNew(UuidToNewIdHolder holder);
List<UuidToNewFeeRow> selectIncomeFees(@Param("oldBillId") String oldBillId);
int insertIncomeFeeNew(UuidToNewIdHolder holder);
/** 回写 ar_bill_detail_fee.income_fee_id(= prc_income_bill_fee_new.fee_id) */
int updateArDetailFeeIncomeFeeId(@Param("oldFeeId") String oldFeeId, @Param("newFeeId") Long newFeeId);
/** 回写现网关联表 order_id(= prc_order_bill_new.bill_id) */
int updatePayBillOrderId(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
int updatePayFeeOrderId(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
int updateArDetailOrderId(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
int updatePayBillLineOrderId(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
int updateBillingTaskOrderId(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
int updateArGenTaskOrderId(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
int insertJobLogStart(UuidToNewIdHolder holder);
int updateJobLogFinish(UuidToNewIdHolder holder);
UuidToNewProgressVo selectProgress();
List<MigBiJobLog> selectJobLogList(MigBiJobLog query);
}
@@ -1,23 +0,0 @@
package com.bms.price.migration.service;
import java.util.List;
import com.bms.price.migration.domain.MigBiJobLog;
import com.bms.price.migration.domain.UuidToNewProgressVo;
/**
* UUID 阴影同步监控
*/
public interface IUuidToNewMonitorService
{
UuidToNewProgressVo getProgress();
List<MigBiJobLog> selectJobLogList(MigBiJobLog query);
/** 打开/关闭连续同步;开启前可带线程/批次 */
void setEnabled(boolean enabled, Integer threadCount, Integer batchSize);
/**
* 仅开关关闭时可改线程与批次。
*/
void updateRuntimeConfig(Integer threadCount, Integer batchSize);
}
@@ -1,24 +0,0 @@
package com.bms.price.migration.service;
import com.bms.price.migration.domain.UuidToNewBatchResult;
/**
* UUID -> bigint 阴影同步服务
*/
public interface IUuidToNewSyncService
{
/**
* 执行一批。
* @return 本批统计(抓取/成功/失败/跳过)
*/
UuidToNewBatchResult syncBatch(int batchSize);
/** 一单一事务;返回 SUCCESS / FAIL / SKIP */
String syncOneOrder(String oldBillId);
/** 独立事务占坑;false=已被占用 */
boolean tryClaimOrder(String oldBillId);
/** 独立事务标记 FAIL,避免失败回滚后被无限重试 */
void markOrderFail(String oldBillId, String failReason);
}
@@ -1,124 +0,0 @@
package com.bms.price.migration.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bms.common.exception.ServiceException;
import com.bms.price.config.UuidToNewProperties;
import com.bms.price.migration.domain.MigBiJobLog;
import com.bms.price.migration.domain.UuidToNewProgressVo;
import com.bms.price.migration.mapper.UuidToNewSyncMapper;
import com.bms.price.migration.service.IUuidToNewMonitorService;
import com.bms.price.task.UuidToNewSyncRunner;
/**
* UUID 阴影同步监控
*/
@Service
public class UuidToNewMonitorServiceImpl implements IUuidToNewMonitorService
{
@Autowired
private UuidToNewSyncMapper syncMapper;
@Autowired
private UuidToNewProperties properties;
@Autowired
private UuidToNewSyncRunner syncRunner;
@Override
public UuidToNewProgressVo getProgress()
{
UuidToNewProgressVo vo = syncMapper.selectProgress();
if (vo == null)
{
vo = new UuidToNewProgressVo();
}
long pending = vo.getOldCnt() - vo.getDoneCnt();
if (pending < 0L)
{
pending = 0L;
}
vo.setPendingCnt(pending);
if (vo.getOldCnt() > 0L)
{
vo.setDonePercent(Math.round(vo.getDoneCnt() * 10000.0 / vo.getOldCnt()) / 100.0);
}
else
{
vo.setDonePercent(0.0);
}
vo.setEnabled(syncRunner.isEnabled());
vo.setRunning(syncRunner.isRunning());
if (properties != null)
{
vo.setBatchSize(properties.resolvedBatchSize());
vo.setThreadCount(properties.resolvedThreadCount());
}
return vo;
}
@Override
public List<MigBiJobLog> selectJobLogList(MigBiJobLog query)
{
return syncMapper.selectJobLogList(query);
}
@Override
public void setEnabled(boolean enabled, Integer threadCount, Integer batchSize)
{
if (enabled)
{
throw new ServiceException("切主后 UuidToNew 已停用,不允许开启连续同步");
}
syncRunner.setEnabled(false);
}
@Override
public void updateRuntimeConfig(Integer threadCount, Integer batchSize)
{
if (syncRunner.isEnabled() || syncRunner.isRunning())
{
throw new ServiceException("请先关闭连续同步再修改线程/批次");
}
applyConfig(threadCount, batchSize);
}
private void applyConfig(Integer threadCount, Integer batchSize)
{
if (properties == null)
{
return;
}
if (threadCount != null)
{
int n = threadCount.intValue();
if (n < 1)
{
n = 1;
}
if (n > 16)
{
n = 16;
}
properties.setThreadCount(n);
}
if (batchSize != null)
{
int n = batchSize.intValue();
if (n < 1)
{
n = 1;
}
if (n > 1000)
{
n = 1000;
}
properties.setBatchSize(n);
}
if (syncRunner != null)
{
syncRunner.persistRuntimeConfig();
}
}
}
@@ -1,493 +0,0 @@
package com.bms.price.migration.service.impl;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.bms.common.core.redis.RedisCache;
import com.bms.price.config.UuidToNewProperties;
import com.bms.price.migration.domain.UuidToNewBatchResult;
import com.bms.price.migration.domain.UuidToNewPendingRow;
import com.bms.price.migration.domain.UuidToNewFeeRow;
import com.bms.price.migration.domain.UuidToNewIdHolder;
import com.bms.price.migration.mapper.UuidToNewSyncMapper;
import com.bms.price.migration.service.IUuidToNewSyncService;
/**
* UUID -> bigint 阴影同步:订单+income *_new + 关联表回写 order_id。
* 占坑独立提交;一单一事务;批内可多线程;游标抓取避全表排序。
*/
@Service
public class UuidToNewSyncServiceImpl implements IUuidToNewSyncService
{
private static final Logger log = LoggerFactory.getLogger(UuidToNewSyncServiceImpl.class);
public static final String SUCCESS = "SUCCESS";
public static final String FAIL = "FAIL";
public static final String SKIP = "SKIP";
public static final String RUNNING = "RUNNING";
@Autowired
private UuidToNewSyncMapper syncMapper;
@Autowired
private UuidToNewProperties properties;
@Autowired
private RedisCache redisCache;
@Autowired
@Lazy
private IUuidToNewSyncService self;
/** Redis:抓取游标 create_time */
public static final String REDIS_KEY_CURSOR_TIME = "bms:mig:uuid-to-new:cursor-time";
/** Redis:抓取游标 bill_id */
public static final String REDIS_KEY_CURSOR_BILL_ID = "bms:mig:uuid-to-new:cursor-bill-id";
private static final String CURSOR_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
@Override
public UuidToNewBatchResult syncBatch(int batchSize)
{
int limit = Math.max(1, Math.min(batchSize, 1000));
int threads = properties == null ? 1 : properties.resolvedThreadCount();
String batchNo = UUID.randomUUID().toString().replace("-", "");
UuidToNewIdHolder job = new UuidToNewIdHolder();
job.setBatchNo(batchNo);
syncMapper.insertJobLogStart(job);
Date lastCreateTime = loadCursorTime();
String lastBillId = loadCursorBillId();
if (lastCreateTime == null || lastBillId == null || lastBillId.isEmpty())
{
// done 已有进度时用边界初始化,避免从最早订单重扫
UuidToNewPendingRow boot = syncMapper.selectPendingCursorBootstrap();
if (boot != null && boot.getCreateTime() != null && boot.getBillId() != null)
{
lastCreateTime = boot.getCreateTime();
lastBillId = boot.getBillId();
saveCursor(lastCreateTime, lastBillId);
log.info("uuid-to-new cursor bootstrap billId={} createTime={}", lastBillId, lastCreateTime);
}
}
List<UuidToNewPendingRow> pending = syncMapper.selectPendingBillIds(limit, lastCreateTime, lastBillId);
List<String> billIds = new ArrayList<String>();
for (UuidToNewPendingRow row : pending)
{
if (row != null && row.getBillId() != null)
{
billIds.add(row.getBillId());
}
}
AtomicInteger success = new AtomicInteger(0);
AtomicInteger fail = new AtomicInteger(0);
AtomicInteger skip = new AtomicInteger(0);
AtomicReference<String> sampleError = new AtomicReference<String>();
if (billIds.isEmpty())
{
// no-op
}
else if (threads <= 1)
{
for (String oldBillId : billIds)
{
applyResult(self, oldBillId, success, fail, skip, sampleError);
}
}
else
{
ExecutorService pool = Executors.newFixedThreadPool(threads);
try
{
List<Future<?>> futures = new ArrayList<Future<?>>();
for (String oldBillId : billIds)
{
final String id = oldBillId;
futures.add(pool.submit(new Runnable()
{
@Override
public void run()
{
applyResult(self, id, success, fail, skip, sampleError);
}
}));
}
for (Future<?> f : futures)
{
try
{
f.get();
}
catch (Exception e)
{
fail.incrementAndGet();
sampleError.compareAndSet(null, abbreviate(e));
log.warn("uuid-to-new worker future error: {}", e.toString());
}
}
}
finally
{
pool.shutdown();
try
{
if (!pool.awaitTermination(2, TimeUnit.HOURS))
{
pool.shutdownNow();
}
}
catch (InterruptedException ie)
{
pool.shutdownNow();
Thread.currentThread().interrupt();
}
}
}
job.setFetched(billIds.size());
job.setSuccess(success.get());
job.setFail(fail.get());
job.setSkip(skip.get());
String remark = "threads=" + threads;
if (sampleError.get() != null)
{
remark = remark + "; err=" + sampleError.get();
}
job.setFailReason(abbreviate(remark, 480));
syncMapper.updateJobLogFinish(job);
// 批次结束后推进游标(本批已尝试的最后一单)
if (!pending.isEmpty())
{
UuidToNewPendingRow last = pending.get(pending.size() - 1);
if (last.getCreateTime() != null && last.getBillId() != null)
{
saveCursor(last.getCreateTime(), last.getBillId());
}
}
UuidToNewBatchResult result = new UuidToNewBatchResult();
result.setFetched(billIds.size());
result.setSuccess(success.get());
result.setFail(fail.get());
result.setSkip(skip.get());
result.setSampleError(sampleError.get());
log.info("uuid-to-new batch={} threads={} fetched={} success={} fail={} skip={} err={}",
batchNo, threads, result.getFetched(), result.getSuccess(), result.getFail(),
result.getSkip(), result.getSampleError());
return result;
}
private void applyResult(IUuidToNewSyncService svc, String oldBillId,
AtomicInteger success, AtomicInteger fail, AtomicInteger skip,
AtomicReference<String> sampleError)
{
try
{
String r = svc.syncOneOrder(oldBillId);
if (SUCCESS.equals(r))
{
success.incrementAndGet();
}
else if (SKIP.equals(r))
{
skip.incrementAndGet();
}
else if (FAIL.equals(r))
{
fail.incrementAndGet();
}
else
{
fail.incrementAndGet();
}
}
catch (Exception e)
{
fail.incrementAndGet();
String msg = abbreviate(e);
sampleError.compareAndSet(null, msg);
try
{
svc.markOrderFail(oldBillId, msg);
}
catch (Exception markEx)
{
log.warn("uuid-to-new mark FAIL failed billId={}: {}", oldBillId, markEx.toString());
}
log.warn("uuid-to-new sync fail billId={}: {}", oldBillId, e.toString());
}
}
/**
* 占坑临时 new_bill_id:负数,避免与自增正数冲突。
*/
static long claimTempNewBillId(String oldBillId)
{
long h = UUID.nameUUIDFromBytes(oldBillId.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits();
if (h == 0L)
{
h = -1L;
}
else if (h > 0L)
{
h = -h;
}
return h;
}
private static String abbreviate(Throwable e)
{
if (e == null)
{
return null;
}
Throwable root = e;
while (root.getCause() != null && root.getCause() != root)
{
root = root.getCause();
}
String msg = root.getClass().getSimpleName() + ": " + root.getMessage();
return abbreviate(msg, 450);
}
private static String abbreviate(String s, int max)
{
if (s == null)
{
return null;
}
String t = s.replace('\r', ' ').replace('\n', ' ');
if (t.length() <= max)
{
return t;
}
return t.substring(0, max);
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public boolean tryClaimOrder(String oldBillId)
{
if (oldBillId == null || oldBillId.isEmpty())
{
return false;
}
if (syncMapper.countOrderBill(oldBillId) <= 0)
{
return false;
}
String orderNo = syncMapper.selectOrderNo(oldBillId);
UuidToNewIdHolder claim = new UuidToNewIdHolder();
claim.setOldBillId(oldBillId);
claim.setNewBillId(claimTempNewBillId(oldBillId));
claim.setOrderNo(orderNo);
claim.setStatus(RUNNING);
return syncMapper.claimOrderDone(claim) > 0;
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void markOrderFail(String oldBillId, String failReason)
{
if (oldBillId == null || oldBillId.isEmpty())
{
return;
}
UuidToNewIdHolder h = new UuidToNewIdHolder();
h.setOldBillId(oldBillId);
h.setFailReason(abbreviate(failReason, 480));
int n = syncMapper.updateOrderDoneFail(h);
if (n <= 0)
{
// 占坑未成功时补一条 FAIL,阻止再被抓取
h.setNewBillId(claimTempNewBillId(oldBillId));
h.setOrderNo(syncMapper.selectOrderNo(oldBillId));
h.setStatus(FAIL);
syncMapper.insertOrderDone(h);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public String syncOneOrder(String oldBillId)
{
if (oldBillId == null || oldBillId.isEmpty())
{
return SKIP;
}
if (!self.tryClaimOrder(oldBillId))
{
return SKIP;
}
UuidToNewIdHolder order = new UuidToNewIdHolder();
order.setOldBillId(oldBillId);
syncMapper.insertOrderBillNew(order);
Long newBillId = order.getNewBillId();
if (newBillId == null)
{
throw new IllegalStateException("insert prc_order_bill_new no generated bill_id");
}
String orderNo = syncMapper.selectOrderNo(oldBillId);
UuidToNewIdHolder done = new UuidToNewIdHolder();
done.setOldBillId(oldBillId);
done.setNewBillId(newBillId);
done.setOrderNo(orderNo);
syncMapper.updateOrderDoneSuccess(done);
syncMapper.insertOrderExtNew(oldBillId, newBillId);
copyIncomeShadow(oldBillId, newBillId);
fillRelatedOrderIds(oldBillId, newBillId);
return SUCCESS;
}
/**
* 拷贝收入主表/费用到 *_new:income_bill_id、fee_id UUID -> bigint AI
*/
private void copyIncomeShadow(String oldBillId, Long newBillId)
{
Map<String, Long> incomeMap = new HashMap<String, Long>();
for (String oldIncomeId : syncMapper.selectIncomeIds(oldBillId))
{
UuidToNewIdHolder h = new UuidToNewIdHolder();
h.setOldId(oldIncomeId);
h.setNewBillId(newBillId);
syncMapper.insertIncomeBillNew(h);
if (h.getNewId() == null)
{
throw new IllegalStateException("insert income_new no id for " + oldIncomeId);
}
incomeMap.put(oldIncomeId, h.getNewId());
}
for (UuidToNewFeeRow row : syncMapper.selectIncomeFees(oldBillId))
{
Long newIncomeId = null;
if (row.getParentId() != null && !row.getParentId().isEmpty())
{
newIncomeId = incomeMap.get(row.getParentId());
if (newIncomeId == null)
{
throw new IllegalStateException("incomeMap miss " + row.getParentId());
}
}
UuidToNewIdHolder h = new UuidToNewIdHolder();
h.setOldId(row.getFeeId());
h.setNewBillId(newBillId);
h.setNewIncomeId(newIncomeId);
syncMapper.insertIncomeFeeNew(h);
Long newFeeId = h.getNewId();
if (newFeeId == null)
{
throw new IllegalStateException("insert income_fee_new no id for " + row.getFeeId());
}
// 回写现网 AR 费用行:旧 UUID 列不动,income_fee_id=新 fee_id
syncMapper.updateArDetailFeeIncomeFeeId(row.getFeeId(), newFeeId);
}
}
/** 现网关联表回写 order_id;旧 UUID 列不动 */
private void fillRelatedOrderIds(String oldBillId, Long newBillId)
{
syncMapper.updatePayBillOrderId(oldBillId, newBillId);
syncMapper.updatePayFeeOrderId(oldBillId, newBillId);
syncMapper.updateArDetailOrderId(oldBillId, newBillId);
syncMapper.updatePayBillLineOrderId(oldBillId, newBillId);
syncMapper.updateBillingTaskOrderId(oldBillId, newBillId);
syncMapper.updateArGenTaskOrderId(oldBillId, newBillId);
}
private Date loadCursorTime()
{
if (redisCache == null)
{
return null;
}
try
{
Object v = redisCache.getCacheObject(REDIS_KEY_CURSOR_TIME);
if (v == null)
{
return null;
}
if (v instanceof Date)
{
return (Date) v;
}
String s = String.valueOf(v).trim();
if (s.isEmpty())
{
return null;
}
return new SimpleDateFormat(CURSOR_TIME_PATTERN).parse(s);
}
catch (ParseException pe)
{
log.warn("uuid-to-new parse cursor time failed: {}", pe.toString());
return null;
}
catch (Exception e)
{
log.warn("uuid-to-new load cursor time failed: {}", e.toString());
return null;
}
}
private String loadCursorBillId()
{
if (redisCache == null)
{
return null;
}
try
{
Object v = redisCache.getCacheObject(REDIS_KEY_CURSOR_BILL_ID);
return v == null ? null : String.valueOf(v).trim();
}
catch (Exception e)
{
log.warn("uuid-to-new load cursor billId failed: {}", e.toString());
return null;
}
}
private void saveCursor(Date createTime, String billId)
{
if (redisCache == null || createTime == null || billId == null || billId.isEmpty())
{
return;
}
try
{
String t = new SimpleDateFormat(CURSOR_TIME_PATTERN).format(createTime);
redisCache.setCacheObject(REDIS_KEY_CURSOR_TIME, t);
redisCache.setCacheObject(REDIS_KEY_CURSOR_BILL_ID, billId);
}
catch (Exception e)
{
log.warn("uuid-to-new save cursor failed: {}", e.toString());
}
}
}
@@ -1,203 +0,0 @@
package com.bms.price.task;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.bms.common.core.redis.RedisCache;
import com.bms.price.config.UuidToNewProperties;
import com.bms.price.migration.domain.UuidToNewBatchResult;
import com.bms.price.migration.service.IUuidToNewSyncService;
/**
* UUID 阴影同步运行器:已默认停用(bms.mig.uuid-to-new.enabled=false)。
* 不再实现 ApplicationRunner;setEnabled(true) 为 no-op,避免误开同步。
*/
@Component
@Order(100)
public class UuidToNewSyncRunner
{
private static final Logger log = LoggerFactory.getLogger(UuidToNewSyncRunner.class);
/** Redis:连续同步开关 */
public static final String REDIS_KEY_ENABLED = "bms:mig:uuid-to-new:enabled";
/** Redis:线程数 */
public static final String REDIS_KEY_THREAD_COUNT = "bms:mig:uuid-to-new:thread-count";
/** Redis:批次大小 */
public static final String REDIS_KEY_BATCH_SIZE = "bms:mig:uuid-to-new:batch-size";
/** 连续全失败批次达此值自动关闭 */
private static final int AUTO_OFF_AFTER_ALL_FAIL_BATCHES = 2;
/** 全失败退避基准(毫秒) */
private static final long ALL_FAIL_BACKOFF_MS = 30000L;
private final AtomicBoolean wantRun = new AtomicBoolean(false);
private final AtomicBoolean loopActive = new AtomicBoolean(false);
private final AtomicInteger consecutiveAllFail = new AtomicInteger(0);
@Autowired
private UuidToNewProperties properties;
@Autowired
private IUuidToNewSyncService syncService;
@Autowired
private RedisCache redisCache;
public boolean isEnabled()
{
return wantRun.get();
}
public boolean isRunning()
{
return loopActive.get();
}
/**
* Enabling is disabled after Long PK cutover; only OFF is accepted.
*/
public synchronized void setEnabled(boolean enabled)
{
if (enabled)
{
log.warn("uuid-to-new enable refused: migration runner disabled after Long PK cutover");
wantRun.set(false);
persistEnabled(false);
return;
}
wantRun.set(false);
persistEnabled(false);
log.info("uuid-to-new switch OFF, will stop after current batch");
}
/** 将当前线程/批次写入 Redis(无过期) */
public void persistRuntimeConfig()
{
if (redisCache == null || properties == null)
{
return;
}
try
{
redisCache.setCacheObject(REDIS_KEY_THREAD_COUNT, Integer.valueOf(properties.resolvedThreadCount()));
redisCache.setCacheObject(REDIS_KEY_BATCH_SIZE, Integer.valueOf(properties.resolvedBatchSize()));
}
catch (Exception e)
{
log.warn("uuid-to-new persist runtime config to redis failed: {}", e.getMessage());
}
}
private void persistEnabled(boolean enabled)
{
if (redisCache == null)
{
return;
}
try
{
redisCache.setCacheObject(REDIS_KEY_ENABLED, Boolean.valueOf(enabled));
}
catch (Exception e)
{
log.warn("uuid-to-new persist enabled={} to redis failed: {}", enabled, e.getMessage());
}
}
private void startLoopIfNeeded()
{
log.warn("uuid-to-new startLoop ignored: runner disabled after Long PK cutover");
}
private void runLoop()
{
try
{
while (wantRun.get())
{
int batchSize = properties == null ? 200 : properties.resolvedBatchSize();
UuidToNewBatchResult result = null;
try
{
result = syncService.syncBatch(batchSize);
}
catch (Exception e)
{
log.error("uuid-to-new batch error", e);
result = null;
}
if (!wantRun.get())
{
break;
}
long sleepMs = properties == null ? 3000L : Math.max(500L, properties.getIdleSleepMs());
if (result == null)
{
sleepMs = Math.max(sleepMs, ALL_FAIL_BACKOFF_MS);
bumpAllFailAndMaybeAutoOff("batch-exception");
}
else if (result.getFetched() <= 0)
{
consecutiveAllFail.set(0);
}
else if (result.getSuccess() <= 0 && result.getFail() > 0)
{
// 全失败:退避,避免立即重打
sleepMs = Math.max(sleepMs, ALL_FAIL_BACKOFF_MS);
bumpAllFailAndMaybeAutoOff(result.getSampleError());
}
else
{
consecutiveAllFail.set(0);
// 有成功:不强制睡眠,但若失败率过高仍稍停
if (result.getFail() > 0 && result.getFail() * 2 >= result.getFetched())
{
sleepMs = Math.max(sleepMs, 5000L);
}
else
{
sleepMs = 0L;
}
}
if (!wantRun.get())
{
break;
}
if (sleepMs > 0L)
{
try
{
Thread.sleep(sleepMs);
}
catch (InterruptedException ie)
{
Thread.currentThread().interrupt();
break;
}
}
}
}
finally
{
loopActive.set(false);
log.info("uuid-to-new loop stopped");
}
}
private void bumpAllFailAndMaybeAutoOff(String sampleError)
{
int n = consecutiveAllFail.incrementAndGet();
log.error("uuid-to-new all-fail batch #{}, sampleErr={}", n, sampleError);
if (n >= AUTO_OFF_AFTER_ALL_FAIL_BATCHES)
{
log.error("uuid-to-new auto switch OFF after {} consecutive all-fail batches", n);
setEnabled(false);
}
}
}
@@ -5,7 +5,6 @@ import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.bms.receivable.domain.ArBillGenerateTask;
import com.bms.price.migration.domain.UuidToNewIdHolder;
/**
* 应收账单异步生成任务 Mapper。
@@ -22,9 +21,6 @@ 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);
@@ -19,7 +19,6 @@ 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;
@@ -108,7 +107,6 @@ 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;
/**
* 应收账单核心业务实现。
@@ -620,37 +618,17 @@ public class ArBillServiceImpl implements IArBillService {
return retried;
}
/** 旧失败任务的选择快照可能保留 UUID;新任务始终使用 bigint ID。 */
/** 切主后仅支持 bigint 订单 ID;历史快照若仍含 UUID 则要求重新选单。 */
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;
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)));
}
if (value instanceof String text && !isLongId(text)) {
throw new ServiceException("历史任务含旧 UUID 订单ID,请重新选择订单生成账单");
}
}
}
@@ -1,341 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bms.price.migration.mapper.UuidToNewSyncMapper">
<select id="selectPendingBillIds" resultType="com.bms.price.migration.domain.UuidToNewPendingRow">
select o.bill_id as billId, o.create_time as createTime
from prc_order_bill o
where 1 = 1
<if test="lastCreateTime != null and lastBillId != null and lastBillId != ''">
and (
o.create_time &gt; #{lastCreateTime}
or (o.create_time = #{lastCreateTime} and o.bill_id &gt; #{lastBillId})
)
</if>
and not exists (
select 1 from mig_bi_order_done d
where d.old_bill_id = o.bill_id
)
order by o.create_time, o.bill_id
limit #{limit}
</select>
<select id="selectPendingCursorBootstrap" resultType="com.bms.price.migration.domain.UuidToNewPendingRow">
select o.bill_id as billId, o.create_time as createTime
from mig_bi_order_done d
inner join prc_order_bill o on o.bill_id = d.old_bill_id
order by o.create_time desc, o.bill_id desc
limit 1
</select>
<select id="selectOrderNo" resultType="String">
select order_no from prc_order_bill where bill_id = #{oldBillId} limit 1
</select>
<select id="countOrderBill" resultType="int">
select count(1) from prc_order_bill where bill_id = #{oldBillId}
</select>
<insert id="insertOrderBillNew" useGeneratedKeys="true" keyProperty="newBillId" keyColumn="bill_id">
insert into prc_order_bill_new (
bill_key, order_no, tracking_no, transfer_no,
belong_saler, belong_saler_code, settlement_man, settlement_man_code,
service_man, service_man_code, customer_id, customer_code,
customer_name, pieces, actual_weight, receive_weight,
volume, volume_weight, pkg_length, pkg_width,
pkg_height, shipper_name, consignee_name, dest_postcode,
warehouse_code, order_time, order_status, bl_pickup,
pickup_date, order_remark, product_code, product_name,
country_code, country_name, weight, biz_date,
tms_id, product_floor_code, product_floor, price_set_id,
price_set_code, price_set_name, set_type, bind_priority,
customer_priceset_id, psv_id, psd_id, weight_min,
weight_max, weight_label, effective_date, charge_weight,
freight_rate, base_freight_rate, discount_percent, registration_fee,
freight_amount, surcharge_amount, income_total, pay_total,
currency, ar_bill_status, customer_active_status, credit_arrears_status,
refund_status, billing_fail_status, error_message, round_mode,
created_by, create_time, updated_by, update_time
)
select
o.bill_key, o.order_no, o.tracking_no, o.transfer_no,
o.belong_saler, o.belong_saler_code, o.settlement_man, o.settlement_man_code,
o.service_man, o.service_man_code, o.customer_id, o.customer_code,
o.customer_name, o.pieces, o.actual_weight, o.receive_weight,
o.volume, o.volume_weight, o.pkg_length, o.pkg_width,
o.pkg_height, o.shipper_name, o.consignee_name, o.dest_postcode,
o.warehouse_code, o.order_time, o.order_status, o.bl_pickup,
o.pickup_date, o.order_remark, o.product_code, o.product_name,
o.country_code, o.country_name, o.weight, o.biz_date,
o.tms_id, o.product_floor_code, o.product_floor, o.price_set_id,
o.price_set_code, o.price_set_name, o.set_type, o.bind_priority,
o.customer_priceset_id, o.psv_id, o.psd_id, o.weight_min,
o.weight_max, o.weight_label, o.effective_date, o.charge_weight,
o.freight_rate, o.base_freight_rate, o.discount_percent, o.registration_fee,
o.freight_amount, o.surcharge_amount, o.income_total, o.pay_total,
o.currency, o.ar_bill_status, o.customer_active_status, o.credit_arrears_status,
o.refund_status, o.billing_fail_status, o.error_message, o.round_mode,
o.created_by, o.create_time, o.updated_by, o.update_time
from prc_order_bill o
where o.bill_id = #{oldBillId}
</insert>
<insert id="insertOrderDone">
insert into mig_bi_order_done (old_bill_id, new_bill_id, order_no, status, fail_reason, synced_at)
values (#{oldBillId}, #{newBillId}, #{orderNo}, #{status}, #{failReason}, now())
</insert>
<insert id="claimOrderDone">
insert ignore into mig_bi_order_done (old_bill_id, new_bill_id, order_no, status, fail_reason, synced_at)
values (#{oldBillId}, #{newBillId}, #{orderNo}, #{status}, #{failReason}, now())
</insert>
<update id="updateOrderDoneSuccess">
update mig_bi_order_done
set new_bill_id = #{newBillId},
order_no = #{orderNo},
status = 'SUCCESS',
fail_reason = null,
updated_at = now()
where old_bill_id = #{oldBillId}
</update>
<update id="updateOrderDoneFail">
update mig_bi_order_done
set status = 'FAIL',
fail_reason = #{failReason},
updated_at = now()
where old_bill_id = #{oldBillId}
</update>
<insert id="insertOrderExtNew">
insert into prc_order_bill_ext_new (
bill_id, order_no, create_time, update_time,
upstream_id, line_no, package_num, actual_volume,
cp_type, consignee_mobile, order_returnsign, trade_type,
duty_type, battery_type, consignee_companyname, consignee_address,
consignee_telephone, consignee_state, consignee_city, consignee_suburb,
consignee_passportno, consignee_email, consignee_taxno, consignee_taxnotype,
consignee_taxnocountry, consignee_streetno, consignee_doorno, shipper_taxnotype,
shipper_taxno, shipper_taxnocountry, customer_id, product_imagepath,
order_transactionurl, order_cargoamount, cargo_type, shipper_companyname,
shipper_address1, shipper_address2, shipper_address3, shipper_city,
shipper_state, shipper_postcode, shipper_country, shipper_telephone,
shipper_suburb, shipper_email, shipper_passportno, import_code,
import_name, import_companyname, import_address, import_address2,
import_address3, import_telephone, import_email, import_postcode,
import_city, import_state, import_country, buyerid,
create_at, pay_type, line_code, line_name,
product_code, product_name, product_type, line_type,
cargo_name, order_insurance, product_sum_price, product_sum,
shipper_doorno, tariff_payment_account, topayment, product_floor,
latest_trajectory, way_bill, bl_baging, bag_date,
org_order_status, status_description, zz_date, shipping_date,
order_type, receiving_photo, freight, is_receivable,
is_meet, bill_no_receivable, bill_no_meet, country_eingth_name,
is_receivable_fee, settlement_fee, product_id, service_freight,
is_pay_fee, has_added_surcharge, yf_fee, yf_totail_fee,
trajectory_status, cargo_type_name, service_code, three_code,
volume_height_old, volume_length_old, volume_width_old, register_man_old,
bag_no_old, air_no_old, lading_id, box_sizi_old,
baging_man_old, retrieval_man_old, invoice_amount_old, invoice_title_old,
invoice_weight_old, sku_old, hs_code_old, register_date_old,
invoice_currency_old, trajectory_sub_state, sign_in_time, warehouse_time,
declaration_time, release_time, station_time, takeoff_time,
landing_time, clearance_and_delivery_time, supplier_name, credit_code,
other_id, platform_code, sync_shipment_status, update_weight,
other_bag_no, bag_flag, online_time, outbound_time,
air_confirm_date, shipment_type, track_query_time, air_confirm_time,
package_type, confirm_weight, update_by, customer_pickup_site,
barcode_number, tracking_reflect_status, remote_postcode, clearance_time,
arrive_stock_time, departure_time, first_deliver_time, hs_code_tax_count,
hs_code_tax_amount, hs_code_tax_currency, invoice_url, clearance_no,
push_weight, internal_check_time, air_delay_time, first_landing_time,
second_takeoff_time, des_port_check_time, stay_remark, miss_box_remark,
product_channel_id, customer_track_id, register_site, package_type_financial,
mrn, product_floor_code, order_status, pickup_date,
bl_pickup, dimensional_weight_factor
)
select
#{newBillId}, e.order_no, e.create_time, e.update_time,
e.upstream_id, e.line_no, e.package_num, e.actual_volume,
e.cp_type, e.consignee_mobile, e.order_returnsign, e.trade_type,
e.duty_type, e.battery_type, e.consignee_companyname, e.consignee_address,
e.consignee_telephone, e.consignee_state, e.consignee_city, e.consignee_suburb,
e.consignee_passportno, e.consignee_email, e.consignee_taxno, e.consignee_taxnotype,
e.consignee_taxnocountry, e.consignee_streetno, e.consignee_doorno, e.shipper_taxnotype,
e.shipper_taxno, e.shipper_taxnocountry, e.customer_id, e.product_imagepath,
e.order_transactionurl, e.order_cargoamount, e.cargo_type, e.shipper_companyname,
e.shipper_address1, e.shipper_address2, e.shipper_address3, e.shipper_city,
e.shipper_state, e.shipper_postcode, e.shipper_country, e.shipper_telephone,
e.shipper_suburb, e.shipper_email, e.shipper_passportno, e.import_code,
e.import_name, e.import_companyname, e.import_address, e.import_address2,
e.import_address3, e.import_telephone, e.import_email, e.import_postcode,
e.import_city, e.import_state, e.import_country, e.buyerid,
e.create_at, e.pay_type, e.line_code, e.line_name,
e.product_code, e.product_name, e.product_type, e.line_type,
e.cargo_name, e.order_insurance, e.product_sum_price, e.product_sum,
e.shipper_doorno, e.tariff_payment_account, e.topayment, e.product_floor,
e.latest_trajectory, e.way_bill, e.bl_baging, e.bag_date,
e.org_order_status, e.status_description, e.zz_date, e.shipping_date,
e.order_type, e.receiving_photo, e.freight, e.is_receivable,
e.is_meet, e.bill_no_receivable, e.bill_no_meet, e.country_eingth_name,
e.is_receivable_fee, e.settlement_fee, e.product_id, e.service_freight,
e.is_pay_fee, e.has_added_surcharge, e.yf_fee, e.yf_totail_fee,
e.trajectory_status, e.cargo_type_name, e.service_code, e.three_code,
e.volume_height_old, e.volume_length_old, e.volume_width_old, e.register_man_old,
e.bag_no_old, e.air_no_old, e.lading_id, e.box_sizi_old,
e.baging_man_old, e.retrieval_man_old, e.invoice_amount_old, e.invoice_title_old,
e.invoice_weight_old, e.sku_old, e.hs_code_old, e.register_date_old,
e.invoice_currency_old, e.trajectory_sub_state, e.sign_in_time, e.warehouse_time,
e.declaration_time, e.release_time, e.station_time, e.takeoff_time,
e.landing_time, e.clearance_and_delivery_time, e.supplier_name, e.credit_code,
e.other_id, e.platform_code, e.sync_shipment_status, e.update_weight,
e.other_bag_no, e.bag_flag, e.online_time, e.outbound_time,
e.air_confirm_date, e.shipment_type, e.track_query_time, e.air_confirm_time,
e.package_type, e.confirm_weight, e.update_by, e.customer_pickup_site,
e.barcode_number, e.tracking_reflect_status, e.remote_postcode, e.clearance_time,
e.arrive_stock_time, e.departure_time, e.first_deliver_time, e.hs_code_tax_count,
e.hs_code_tax_amount, e.hs_code_tax_currency, e.invoice_url, e.clearance_no,
e.push_weight, e.internal_check_time, e.air_delay_time, e.first_landing_time,
e.second_takeoff_time, e.des_port_check_time, e.stay_remark, e.miss_box_remark,
e.product_channel_id, e.customer_track_id, e.register_site, e.package_type_financial,
e.mrn, e.product_floor_code, e.order_status, e.pickup_date,
e.bl_pickup, e.dimensional_weight_factor
from prc_order_bill_ext e
where e.bill_id = #{oldBillId}
</insert>
<select id="selectIncomeIds" resultType="String">
select income_bill_id from prc_income_bill where bill_id = #{oldBillId}
</select>
<insert id="insertIncomeBillNew" useGeneratedKeys="true" keyProperty="newId" keyColumn="income_bill_id">
insert into prc_income_bill_new (
bill_id, currency, product_amount, redline_amount,
sales_amount, income_total, refund_status, belong_saler,
belong_saler_code, settlement_man, settlement_man_code, create_by,
create_time, update_by, update_time
)
select
#{newBillId}, i.currency, i.product_amount, i.redline_amount,
i.sales_amount, i.income_total, i.refund_status, i.belong_saler,
i.belong_saler_code, i.settlement_man, i.settlement_man_code, i.create_by,
i.create_time, i.update_by, i.update_time
from prc_income_bill i
where i.income_bill_id = #{oldId}
</insert>
<select id="selectIncomeFees" resultType="com.bms.price.migration.domain.UuidToNewFeeRow">
select fee_id as feeId, income_bill_id as parentId
from prc_income_bill_fee
where bill_id = #{oldBillId}
order by fee_id
</select>
<insert id="insertIncomeFeeNew" useGeneratedKeys="true" keyProperty="newId" keyColumn="fee_id">
insert into prc_income_bill_fee_new (
bill_id, income_bill_id, fee_type, fee_name,
sc_id, amount, product_amount, redline_amount,
currency, round_mode, remark, ar_bill_status,
manual_flag, create_time
)
select
#{newBillId}, #{newIncomeId}, f.fee_type, f.fee_name,
f.sc_id, f.amount, f.product_amount, f.redline_amount,
f.currency, f.round_mode, f.remark, f.ar_bill_status,
f.manual_flag, f.create_time
from prc_income_bill_fee f
where f.fee_id = #{oldId}
</insert>
<update id="updateArDetailFeeIncomeFeeId">
update ar_bill_detail_fee
set income_fee_id = #{newFeeId}
where prc_income_bill_fee_id = #{oldFeeId}
</update>
<!-- 应付表旧 UUID 列已删;UuidToNew 回写空操作 -->
<update id="updatePayBillOrderId">
update prc_pay_bill
set bill_id = #{newBillId}
where 1 = 0
</update>
<update id="updatePayFeeOrderId">
update prc_pay_bill_fee
set bill_id = #{newBillId}
where 1 = 0
</update>
<update id="updateArDetailOrderId">
update ar_bill_detail
set order_id = #{newBillId}
where prc_order_bill_id = #{oldBillId}
</update>
<update id="updatePayBillLineOrderId">
update pay_bill_line
set order_bill_id = #{newBillId}
where 1 = 0
</update>
<!-- bill_id dropped; order_id is the live FK. No-op for legacy sync. -->
<update id="updateBillingTaskOrderId">
update prc_billing_task
set order_id = #{newBillId}
where 1 = 0
</update>
<update id="updateArGenTaskOrderId">
update ar_bill_generate_task
set order_id = #{newBillId}
where last_source_bill_id = #{oldBillId}
</update>
<insert id="insertJobLogStart" useGeneratedKeys="true" keyProperty="jobLogId" keyColumn="id">
insert into mig_bi_job_log (batch_no, fetched, success, fail, skip, started_at, remark)
values (#{batchNo}, 0, 0, 0, 0, now(), null)
</insert>
<update id="updateJobLogFinish">
update mig_bi_job_log
set fetched = #{fetched},
success = #{success},
fail = #{fail},
skip = #{skip},
finished_at = now(),
remark = #{failReason}
where id = #{jobLogId}
</update>
<select id="selectProgress" resultType="com.bms.price.migration.domain.UuidToNewProgressVo">
select
(select count(*) from prc_order_bill) as oldCnt,
(select count(*) from mig_bi_order_done where status = 'SUCCESS') as doneCnt,
(select count(*) from prc_order_bill_new) as newCnt
</select>
<select id="selectJobLogList" resultType="com.bms.price.migration.domain.MigBiJobLog">
select id, batch_no as batchNo, fetched, success, fail, skip,
started_at as startedAt, finished_at as finishedAt, remark
from mig_bi_job_log
<where>
<if test="batchNo != null and batchNo != ''">
and batch_no = #{batchNo}
</if>
<if test="beginStartedAt != null and beginStartedAt != ''">
and started_at &gt;= #{beginStartedAt}
</if>
<if test="endStartedAt != null and endStartedAt != ''">
and started_at &lt;= #{endStartedAt}
</if>
</where>
order by id desc
</select>
</mapper>
@@ -56,15 +56,6 @@
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}