更新支付账单服务逻辑,调整源ID赋值方式;修改SQL映射中的源ID字段为费用ID;新增UUID到BIGINT迁移配置
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
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
|
||||
{
|
||||
/** 每轮抓取订单数(1~1000) */
|
||||
private int batchSize = 200;
|
||||
/**
|
||||
* 批内工作线程数(1~4)。
|
||||
* 默认1;冲刺追数可设2~3(生产4核谨慎)。
|
||||
*/
|
||||
private int threadCount = 1;
|
||||
/** 无待处理订单时空转睡眠毫秒(开关仍为开时) */
|
||||
private long idleSleepMs = 3000L;
|
||||
|
||||
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~4 */
|
||||
public int resolvedThreadCount()
|
||||
{
|
||||
int n = threadCount;
|
||||
if (n < 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (n > 4)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public long getIdleSleepMs()
|
||||
{
|
||||
return idleSleepMs;
|
||||
}
|
||||
|
||||
public void setIdleSleepMs(long idleSleepMs)
|
||||
{
|
||||
this.idleSleepMs = idleSleepMs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.bms.price.migration.domain;
|
||||
|
||||
/**
|
||||
* 旧费用行:用于逐行插入并建内存 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; }
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.bms.price.migration.domain;
|
||||
|
||||
/**
|
||||
* 阴影插入时传参 / 接收自增主键
|
||||
*/
|
||||
public class UuidToNewIdHolder
|
||||
{
|
||||
private String oldBillId;
|
||||
private Long newBillId;
|
||||
private String oldId;
|
||||
private Long newId;
|
||||
private Long newIncomeId;
|
||||
private Long newPayId;
|
||||
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 Long getNewPayId() { return newPayId; }
|
||||
public void setNewPayId(Long newPayId) { this.newPayId = newPayId; }
|
||||
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; }
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
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; }
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
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.UuidToNewIdHolder;
|
||||
import com.bms.price.migration.domain.UuidToNewProgressVo;
|
||||
|
||||
/**
|
||||
* UUID -> bigint 阴影同步 Mapper
|
||||
*/
|
||||
public interface UuidToNewSyncMapper
|
||||
{
|
||||
List<String> selectPendingBillIds(@Param("limit") int limit);
|
||||
|
||||
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 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);
|
||||
|
||||
List<String> selectPayIds(@Param("oldBillId") String oldBillId);
|
||||
|
||||
int insertPayBillNew(UuidToNewIdHolder holder);
|
||||
|
||||
List<UuidToNewFeeRow> selectPayFees(@Param("oldBillId") String oldBillId);
|
||||
|
||||
int insertPayFeeNew(UuidToNewIdHolder holder);
|
||||
|
||||
int updatePayFeeIdEqualsId(@Param("id") Long id);
|
||||
|
||||
int insertArDetailNew(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
|
||||
|
||||
List<UuidToNewFeeRow> selectArDetailFees(@Param("oldBillId") String oldBillId);
|
||||
|
||||
int insertArDetailFeeNew(@Param("detailFeeId") Long detailFeeId, @Param("newFeeId") Long newFeeId);
|
||||
|
||||
List<UuidToNewFeeRow> selectPayBillLines(@Param("oldBillId") String oldBillId);
|
||||
|
||||
int insertPayBillLineNew(@Param("lineId") Long lineId, @Param("newBillId") Long newBillId,
|
||||
@Param("newFeeId") Long newFeeId);
|
||||
|
||||
int insertBillingTaskNew(@Param("oldBillId") String oldBillId, @Param("newBillId") Long newBillId);
|
||||
|
||||
int insertJobLogStart(UuidToNewIdHolder holder);
|
||||
|
||||
int updateJobLogFinish(UuidToNewIdHolder holder);
|
||||
|
||||
UuidToNewProgressVo selectProgress();
|
||||
|
||||
List<MigBiJobLog> selectJobLogList(MigBiJobLog query);
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.bms.price.migration.service;
|
||||
|
||||
/**
|
||||
* UUID -> bigint 阴影同步服务
|
||||
*/
|
||||
public interface IUuidToNewSyncService
|
||||
{
|
||||
/**
|
||||
* 执行一批。
|
||||
* @return 本批抓取条数(fetched)
|
||||
*/
|
||||
int syncBatch(int batchSize);
|
||||
|
||||
/** 一单一事务;返回 SUCCESS / FAIL / SKIP */
|
||||
String syncOneOrder(String oldBillId);
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
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)
|
||||
{
|
||||
applyConfig(threadCount, batchSize);
|
||||
}
|
||||
syncRunner.setEnabled(enabled);
|
||||
}
|
||||
|
||||
@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 > 4)
|
||||
{
|
||||
n = 4;
|
||||
}
|
||||
properties.setThreadCount(n);
|
||||
}
|
||||
if (batchSize != null)
|
||||
{
|
||||
int n = batchSize.intValue();
|
||||
if (n < 1)
|
||||
{
|
||||
n = 1;
|
||||
}
|
||||
if (n > 1000)
|
||||
{
|
||||
n = 1000;
|
||||
}
|
||||
properties.setBatchSize(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
package com.bms.price.migration.service.impl;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
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 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.Transactional;
|
||||
import com.bms.price.config.UuidToNewProperties;
|
||||
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 阴影同步:一单一事务;批内可多线程
|
||||
*/
|
||||
@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
|
||||
@Lazy
|
||||
private IUuidToNewSyncService self;
|
||||
|
||||
@Override
|
||||
public int 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);
|
||||
|
||||
List<String> billIds = syncMapper.selectPendingBillIds(limit);
|
||||
AtomicInteger success = new AtomicInteger(0);
|
||||
AtomicInteger fail = new AtomicInteger(0);
|
||||
AtomicInteger skip = new AtomicInteger(0);
|
||||
|
||||
if (billIds.isEmpty())
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
else if (threads <= 1)
|
||||
{
|
||||
for (String oldBillId : billIds)
|
||||
{
|
||||
applyResult(self, oldBillId, success, fail, skip);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}));
|
||||
}
|
||||
for (Future<?> f : futures)
|
||||
{
|
||||
try
|
||||
{
|
||||
f.get();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fail.incrementAndGet();
|
||||
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());
|
||||
job.setFailReason("threads=" + threads);
|
||||
syncMapper.updateJobLogFinish(job);
|
||||
String summary = String.format(
|
||||
"batch=%s threads=%d fetched=%d success=%d fail=%d skip=%d",
|
||||
batchNo, threads, billIds.size(), success.get(), fail.get(), skip.get());
|
||||
log.info("uuid-to-new {}", summary);
|
||||
return billIds.size();
|
||||
}
|
||||
|
||||
private void applyResult(IUuidToNewSyncService svc, String oldBillId,
|
||||
AtomicInteger success, AtomicInteger fail, AtomicInteger skip)
|
||||
{
|
||||
try
|
||||
{
|
||||
String r = svc.syncOneOrder(oldBillId);
|
||||
if (SUCCESS.equals(r))
|
||||
{
|
||||
success.incrementAndGet();
|
||||
}
|
||||
else if (SKIP.equals(r))
|
||||
{
|
||||
skip.incrementAndGet();
|
||||
}
|
||||
else
|
||||
{
|
||||
fail.incrementAndGet();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fail.incrementAndGet();
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String syncOneOrder(String oldBillId)
|
||||
{
|
||||
if (oldBillId == null || oldBillId.isEmpty())
|
||||
{
|
||||
return SKIP;
|
||||
}
|
||||
if (syncMapper.countOrderBill(oldBillId) <= 0)
|
||||
{
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
String orderNo = syncMapper.selectOrderNo(oldBillId);
|
||||
UuidToNewIdHolder claim = new UuidToNewIdHolder();
|
||||
claim.setOldBillId(oldBillId);
|
||||
claim.setNewBillId(claimTempNewBillId(oldBillId));
|
||||
claim.setOrderNo(orderNo);
|
||||
claim.setStatus(RUNNING);
|
||||
if (syncMapper.claimOrderDone(claim) == 0)
|
||||
{
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
Map<String, Long> incomeMap = new HashMap<String, Long>();
|
||||
Map<String, Long> feeMap = new HashMap<String, Long>();
|
||||
Map<String, Long> payMap = new HashMap<String, Long>();
|
||||
Map<String, Long> payFeeMap = new HashMap<String, Long>();
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
UuidToNewIdHolder done = new UuidToNewIdHolder();
|
||||
done.setOldBillId(oldBillId);
|
||||
done.setNewBillId(newBillId);
|
||||
done.setOrderNo(orderNo);
|
||||
syncMapper.updateOrderDoneSuccess(done);
|
||||
|
||||
syncMapper.insertOrderExtNew(oldBillId, newBillId);
|
||||
|
||||
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);
|
||||
if (h.getNewId() == null)
|
||||
{
|
||||
throw new IllegalStateException("insert income_fee_new no id for " + row.getFeeId());
|
||||
}
|
||||
feeMap.put(row.getFeeId(), h.getNewId());
|
||||
}
|
||||
|
||||
for (String oldPayId : syncMapper.selectPayIds(oldBillId))
|
||||
{
|
||||
UuidToNewIdHolder h = new UuidToNewIdHolder();
|
||||
h.setOldId(oldPayId);
|
||||
h.setNewBillId(newBillId);
|
||||
syncMapper.insertPayBillNew(h);
|
||||
if (h.getNewId() == null)
|
||||
{
|
||||
throw new IllegalStateException("insert pay_new no id for " + oldPayId);
|
||||
}
|
||||
payMap.put(oldPayId, h.getNewId());
|
||||
}
|
||||
|
||||
for (UuidToNewFeeRow row : syncMapper.selectPayFees(oldBillId))
|
||||
{
|
||||
Long newPayId = null;
|
||||
if (row.getParentId() != null && !row.getParentId().isEmpty())
|
||||
{
|
||||
newPayId = payMap.get(row.getParentId());
|
||||
if (newPayId == null)
|
||||
{
|
||||
throw new IllegalStateException("payMap miss " + row.getParentId());
|
||||
}
|
||||
}
|
||||
UuidToNewIdHolder h = new UuidToNewIdHolder();
|
||||
h.setOldId(row.getFeeId());
|
||||
h.setNewBillId(newBillId);
|
||||
h.setNewPayId(newPayId);
|
||||
syncMapper.insertPayFeeNew(h);
|
||||
Long rowId = h.getNewId();
|
||||
if (rowId == null)
|
||||
{
|
||||
throw new IllegalStateException("insert pay_fee_new no id for " + row.getFeeId());
|
||||
}
|
||||
syncMapper.updatePayFeeIdEqualsId(rowId);
|
||||
payFeeMap.put(row.getFeeId(), rowId);
|
||||
}
|
||||
|
||||
syncMapper.insertArDetailNew(oldBillId, newBillId);
|
||||
|
||||
for (UuidToNewFeeRow row : syncMapper.selectArDetailFees(oldBillId))
|
||||
{
|
||||
Long newFeeId = feeMap.get(row.getFeeId());
|
||||
if (newFeeId == null)
|
||||
{
|
||||
throw new IllegalStateException("feeMap miss for ar detail fee " + row.getFeeId());
|
||||
}
|
||||
Long detailFeeId = Long.valueOf(row.getParentId());
|
||||
syncMapper.insertArDetailFeeNew(detailFeeId, newFeeId);
|
||||
}
|
||||
|
||||
for (UuidToNewFeeRow row : syncMapper.selectPayBillLines(oldBillId))
|
||||
{
|
||||
Long lineId = Long.valueOf(row.getParentId());
|
||||
Long newFeeId = null;
|
||||
if (row.getFeeId() != null && !row.getFeeId().isEmpty())
|
||||
{
|
||||
newFeeId = payFeeMap.get(row.getFeeId());
|
||||
if (newFeeId == null)
|
||||
{
|
||||
throw new IllegalStateException("payFeeMap miss for line fee " + row.getFeeId());
|
||||
}
|
||||
}
|
||||
syncMapper.insertPayBillLineNew(lineId, newBillId, newFeeId);
|
||||
}
|
||||
|
||||
syncMapper.insertBillingTaskNew(oldBillId, newBillId);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -584,7 +584,7 @@ public class PayBillServiceImpl implements IPayBillService
|
||||
adjust.setAmount(delta);
|
||||
adjust.setCurrency(line.getCurrency());
|
||||
adjust.setFeeSource("MANUAL");
|
||||
adjust.setSourceId(source != null && source.getId() != null ? String.valueOf(source.getId()) : null);
|
||||
adjust.setSourceId(source == null ? null : source.getFeeId());
|
||||
adjust.setRemark(open.getReason());
|
||||
adjust.setSettleSupplierId(bill.getSupplierId());
|
||||
adjust.setSettleSupplierName(bill.getSupplierName());
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.bms.price.task;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.bms.price.config.UuidToNewProperties;
|
||||
import com.bms.price.migration.service.IUuidToNewSyncService;
|
||||
|
||||
/**
|
||||
* UUID 阴影同步运行器:监控页开关控制;
|
||||
* 开启后立即跑批,一批结束立刻下一批;关闭后当前批结束停。
|
||||
*/
|
||||
@Component
|
||||
public class UuidToNewSyncRunner
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(UuidToNewSyncRunner.class);
|
||||
|
||||
private final AtomicBoolean wantRun = new AtomicBoolean(false);
|
||||
private final AtomicBoolean loopActive = new AtomicBoolean(false);
|
||||
|
||||
@Autowired
|
||||
private UuidToNewProperties properties;
|
||||
|
||||
@Autowired
|
||||
private IUuidToNewSyncService syncService;
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return wantRun.get();
|
||||
}
|
||||
|
||||
public boolean isRunning()
|
||||
{
|
||||
return loopActive.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开:立即启动连续批循环;关闭:标记停止(当前批跑完)。
|
||||
*/
|
||||
public synchronized void setEnabled(boolean enabled)
|
||||
{
|
||||
wantRun.set(enabled);
|
||||
if (enabled)
|
||||
{
|
||||
startLoopIfNeeded();
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info("uuid-to-new switch OFF, will stop after current batch");
|
||||
}
|
||||
}
|
||||
|
||||
private void startLoopIfNeeded()
|
||||
{
|
||||
if (!loopActive.compareAndSet(false, true))
|
||||
{
|
||||
log.info("uuid-to-new loop already running");
|
||||
return;
|
||||
}
|
||||
Thread t = new Thread(this::runLoop, "uuid-to-new-sync");
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
log.info("uuid-to-new loop started");
|
||||
}
|
||||
|
||||
private void runLoop()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (wantRun.get())
|
||||
{
|
||||
int batchSize = properties == null ? 200 : properties.resolvedBatchSize();
|
||||
int fetched = 0;
|
||||
try
|
||||
{
|
||||
fetched = syncService.syncBatch(batchSize);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("uuid-to-new batch error", e);
|
||||
}
|
||||
if (!wantRun.get())
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (fetched <= 0)
|
||||
{
|
||||
long sleepMs = properties == null ? 3000L : Math.max(500L, properties.getIdleSleepMs());
|
||||
try
|
||||
{
|
||||
Thread.sleep(sleepMs);
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fetched > 0:立刻下一批
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
loopActive.set(false);
|
||||
log.info("uuid-to-new loop stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
|
||||
<update id="fillSourceIdByFeeIds">
|
||||
update prc_pay_bill_fee
|
||||
set source_id = id
|
||||
set source_id = fee_id
|
||||
where (source_id is null or source_id = '')
|
||||
and fee_id in
|
||||
<foreach collection="feeIds" item="feeId" open="(" separator="," close=")">#{feeId}</foreach>
|
||||
|
||||
@@ -0,0 +1,415 @@
|
||||
<?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="String">
|
||||
select o.bill_id
|
||||
from prc_order_bill o
|
||||
left join mig_bi_order_done d on d.old_bill_id = o.bill_id
|
||||
where d.old_bill_id is null
|
||||
order by o.create_time, o.bill_id
|
||||
limit #{limit}
|
||||
</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>
|
||||
|
||||
<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>
|
||||
|
||||
<select id="selectPayIds" resultType="String">
|
||||
select pay_bill_id from prc_pay_bill where bill_id = #{oldBillId}
|
||||
</select>
|
||||
|
||||
<insert id="insertPayBillNew" useGeneratedKeys="true" keyProperty="newId" keyColumn="pay_bill_id">
|
||||
insert into prc_pay_bill_new (
|
||||
bill_id, currency, product_amount, redline_amount,
|
||||
cost_amount, pay_total, amount_a, amount_b,
|
||||
amount_c, amount_d, belong_saler, belong_saler_code,
|
||||
settlement_man, settlement_man_code, create_by, create_time,
|
||||
update_by, update_time
|
||||
)
|
||||
select
|
||||
#{newBillId}, p.currency, p.product_amount, p.redline_amount,
|
||||
p.cost_amount, p.pay_total, p.amount_a, p.amount_b,
|
||||
p.amount_c, p.amount_d, p.belong_saler, p.belong_saler_code,
|
||||
p.settlement_man, p.settlement_man_code, p.create_by, p.create_time,
|
||||
p.update_by, p.update_time
|
||||
from prc_pay_bill p
|
||||
where p.pay_bill_id = #{oldId}
|
||||
</insert>
|
||||
|
||||
<select id="selectPayFees" resultType="com.bms.price.migration.domain.UuidToNewFeeRow">
|
||||
select fee_id as feeId, pay_bill_id as parentId
|
||||
from prc_pay_bill_fee
|
||||
where bill_id = #{oldBillId}
|
||||
order by fee_id
|
||||
</select>
|
||||
|
||||
<insert id="insertPayFeeNew" useGeneratedKeys="true" keyProperty="newId" keyColumn="id">
|
||||
insert into prc_pay_bill_fee_new (
|
||||
fee_id, bill_id, pay_bill_id, fee_type,
|
||||
sc_id, fee_level, amount, currency,
|
||||
round_mode, remark, fee_source, source_id,
|
||||
is_deleted, statement_line_id, settle_supplier_id, settle_supplier_name,
|
||||
create_time
|
||||
)
|
||||
select
|
||||
0, #{newBillId}, #{newPayId}, f.fee_type,
|
||||
f.sc_id, f.fee_level, f.amount, f.currency,
|
||||
f.round_mode, f.remark, f.fee_source, f.source_id,
|
||||
f.is_deleted, f.statement_line_id, f.settle_supplier_id, f.settle_supplier_name,
|
||||
f.create_time
|
||||
from prc_pay_bill_fee f
|
||||
where f.fee_id = #{oldId}
|
||||
</insert>
|
||||
|
||||
<update id="updatePayFeeIdEqualsId">
|
||||
update prc_pay_bill_fee_new set fee_id = id where id = #{id}
|
||||
</update>
|
||||
|
||||
<insert id="insertArDetailNew">
|
||||
insert into ar_bill_detail_new (
|
||||
detail_id, ar_bill_id, prc_order_bill_id, detail_no,
|
||||
order_no, tracking_no, transfer_no, receive_time,
|
||||
product_code, product_name, goods_description, country_code,
|
||||
country_name, dest_postcode, actual_weight, receive_weight,
|
||||
volume_weight, charge_weight, freight_rate, registration_fee,
|
||||
pkg_length, pkg_width, pkg_height, currency,
|
||||
total_amount, product_amount, redline_amount, billing_fail_status,
|
||||
remark, create_by, create_time
|
||||
)
|
||||
select
|
||||
d.detail_id, d.ar_bill_id, #{newBillId}, d.detail_no,
|
||||
d.order_no, d.tracking_no, d.transfer_no, d.receive_time,
|
||||
d.product_code, d.product_name, d.goods_description, d.country_code,
|
||||
d.country_name, d.dest_postcode, d.actual_weight, d.receive_weight,
|
||||
d.volume_weight, d.charge_weight, d.freight_rate, d.registration_fee,
|
||||
d.pkg_length, d.pkg_width, d.pkg_height, d.currency,
|
||||
d.total_amount, d.product_amount, d.redline_amount, d.billing_fail_status,
|
||||
d.remark, d.create_by, d.create_time
|
||||
from ar_bill_detail d
|
||||
where d.prc_order_bill_id = #{oldBillId}
|
||||
</insert>
|
||||
|
||||
<select id="selectArDetailFees" resultType="com.bms.price.migration.domain.UuidToNewFeeRow">
|
||||
select f.prc_income_bill_fee_id as feeId, cast(f.detail_fee_id as char) as parentId
|
||||
from ar_bill_detail_fee f
|
||||
inner join ar_bill_detail d on d.detail_id = f.detail_id
|
||||
where d.prc_order_bill_id = #{oldBillId}
|
||||
order by f.detail_fee_id
|
||||
</select>
|
||||
|
||||
<insert id="insertArDetailFeeNew">
|
||||
insert into ar_bill_detail_fee_new (
|
||||
detail_fee_id, detail_id, prc_income_bill_fee_id, fee_no,
|
||||
fee_type, fee_name, sc_id, quantity,
|
||||
unit, unit_price, amount, product_amount,
|
||||
redline_amount, currency, calculation_formula, round_mode,
|
||||
remark, create_by, create_time
|
||||
)
|
||||
select
|
||||
f.detail_fee_id, f.detail_id, #{newFeeId}, f.fee_no,
|
||||
f.fee_type, f.fee_name, f.sc_id, f.quantity,
|
||||
f.unit, f.unit_price, f.amount, f.product_amount,
|
||||
f.redline_amount, f.currency, f.calculation_formula, f.round_mode,
|
||||
f.remark, f.create_by, f.create_time
|
||||
from ar_bill_detail_fee f
|
||||
where f.detail_fee_id = #{detailFeeId}
|
||||
</insert>
|
||||
|
||||
<select id="selectPayBillLines" resultType="com.bms.price.migration.domain.UuidToNewFeeRow">
|
||||
select cast(line_id as char) as parentId, fee_id as feeId
|
||||
from pay_bill_line
|
||||
where order_bill_id = #{oldBillId}
|
||||
order by line_id
|
||||
</select>
|
||||
|
||||
<insert id="insertPayBillLineNew">
|
||||
insert into pay_bill_line_new (
|
||||
line_id, bill_id, fee_id, order_bill_id,
|
||||
order_no, lading_no, lading_fee_id, fee_name,
|
||||
fee_source, fee_level, amount, supplier_amount,
|
||||
diff_amount, diff_status, tax_rate, amount_net,
|
||||
tax_amount, base_amount, currency, price_date,
|
||||
version_no, remote_flag, density_level, line_source
|
||||
)
|
||||
select
|
||||
l.line_id, l.bill_id, #{newFeeId}, #{newBillId},
|
||||
l.order_no, l.lading_no, l.lading_fee_id, l.fee_name,
|
||||
l.fee_source, l.fee_level, l.amount, l.supplier_amount,
|
||||
l.diff_amount, l.diff_status, l.tax_rate, l.amount_net,
|
||||
l.tax_amount, l.base_amount, l.currency, l.price_date,
|
||||
l.version_no, l.remote_flag, l.density_level, l.line_source
|
||||
from pay_bill_line l
|
||||
where l.line_id = #{lineId}
|
||||
</insert>
|
||||
|
||||
<insert id="insertBillingTaskNew">
|
||||
insert into prc_billing_task_new (
|
||||
task_id, transfer_no, tracking_no, order_no,
|
||||
customer_code, bill_type, success_status, bill_time,
|
||||
bill_id, fail_code, error_message, create_by,
|
||||
create_time, update_by, update_time
|
||||
)
|
||||
select
|
||||
t.task_id, t.transfer_no, t.tracking_no, t.order_no,
|
||||
t.customer_code, t.bill_type, t.success_status, t.bill_time,
|
||||
#{newBillId}, t.fail_code, t.error_message, t.create_by,
|
||||
t.create_time, t.update_by, t.update_time
|
||||
from prc_billing_task t
|
||||
where t.bill_id = #{oldBillId}
|
||||
</insert>
|
||||
|
||||
<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 >= #{beginStartedAt}
|
||||
</if>
|
||||
<if test="endStartedAt != null and endStartedAt != ''">
|
||||
and started_at <= #{endStartedAt}
|
||||
</if>
|
||||
</where>
|
||||
order by id desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user