|
|
@ -99,6 +99,7 @@ import com.ms.dal.entity.OpOrderPhase;
|
|
|
|
import com.ms.dal.entity.OpOrderPriceProtection;
|
|
|
|
import com.ms.dal.entity.OpOrderPriceProtection;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncInfo;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncInfo;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncLog;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncLog;
|
|
|
|
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncPageBuffer;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncPageLog;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncPageLog;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncPageQueue;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncPageQueue;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncQueue;
|
|
|
|
import com.ms.dal.entity.OpOrderRsyncQueue;
|
|
|
@ -1987,11 +1988,79 @@ public class OpOrderServiceImpl implements OpOrderService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void moveOpPageBufferToQueue(Map<Long, Long> shopIdAndMoveCntMap) {
|
|
|
|
public void moveOpPageBufferToQueue(Map<Long, Long> shopIdAndMoveCntMap) {
|
|
|
|
log.info("start moveOpPageBufferToQueue");
|
|
|
|
log.info("start moveOpPageBufferToQueue");
|
|
|
|
int startBufferId = 0;
|
|
|
|
Long startBufferId = 0L;
|
|
|
|
int limit = 1000;
|
|
|
|
int limit = 1000;
|
|
|
|
for (Map.Entry<Long, Long> entry : shopIdAndMoveCntMap.entrySet()) {
|
|
|
|
while (shopIdAndMoveCntMap.size() > 0) {
|
|
|
|
|
|
|
|
List<OpOrderRsyncPageBuffer> chunkBufferList = opOrderRsyncPageBufferMapper.selectByBufferIdAndLimit(startBufferId, limit);
|
|
|
|
|
|
|
|
if (ObjectUtil.isEmpty(chunkBufferList)) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
startBufferId = chunkBufferList.stream().map(OpOrderRsyncPageBuffer::getOpOrderRsyncPageBufferId).max(Long::compare).orElse(0L);
|
|
|
|
|
|
|
|
startMoveOpPageBufferToQueue(chunkBufferList, shopIdAndMoveCntMap);
|
|
|
|
|
|
|
|
shopIdAndMoveCntMap = shopIdAndMoveCntMap.entrySet().stream().filter(r -> r.getValue() > 0)
|
|
|
|
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("end moveOpPageBufferToQueue");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApiResult startMoveOpPageBufferToQueue(List<OpOrderRsyncPageBuffer> bufferList, Map<Long, Long> shopIdAndMoveCntMap) {
|
|
|
|
|
|
|
|
List<Long> deleteBufferIds = new ArrayList<>();
|
|
|
|
|
|
|
|
List<OpOrderRsyncPageQueue> insertQueueList = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Long> deleteShopIds = new ArrayList<>();
|
|
|
|
|
|
|
|
for (OpOrderRsyncPageBuffer buffer : bufferList) {
|
|
|
|
|
|
|
|
Long shopId = buffer.getShopId();
|
|
|
|
|
|
|
|
if (!shopIdAndMoveCntMap.containsKey(shopId) || shopIdAndMoveCntMap.get(shopId) < 0) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Long cnt = shopIdAndMoveCntMap.get(shopId) - 1;
|
|
|
|
|
|
|
|
if (cnt < 0) {
|
|
|
|
|
|
|
|
deleteShopIds.add(shopId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OpOrderRsyncPageQueue queue = new OpOrderRsyncPageQueue();
|
|
|
|
|
|
|
|
queue.setOpOrderRsyncQueueId(buffer.getOpOrderRsyncQueueId());
|
|
|
|
|
|
|
|
queue.setShopId(shopId);
|
|
|
|
|
|
|
|
queue.setGmtStartModified(buffer.getGmtStartModified());
|
|
|
|
|
|
|
|
queue.setGmtEndModified(buffer.getGmtEndModified());
|
|
|
|
|
|
|
|
queue.setPageSize(buffer.getPageSize());
|
|
|
|
|
|
|
|
queue.setPage(buffer.getPage());
|
|
|
|
|
|
|
|
queue.setPageCount(buffer.getPageCount());
|
|
|
|
|
|
|
|
queue.setPreviewTotal(buffer.getPreviewTotal());
|
|
|
|
|
|
|
|
queue.setLocked(0L);
|
|
|
|
|
|
|
|
queue.setGmtCreate(new Date());
|
|
|
|
|
|
|
|
queue.setGmtModified(new Date());
|
|
|
|
|
|
|
|
insertQueueList.add(queue);
|
|
|
|
|
|
|
|
deleteBufferIds.add(buffer.getOpOrderRsyncPageBufferId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Long id : deleteShopIds) {
|
|
|
|
|
|
|
|
shopIdAndMoveCntMap.remove(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Long startQueueId = null;
|
|
|
|
|
|
|
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(insertQueueList)) {
|
|
|
|
|
|
|
|
opOrderRsyncPageQueueMapper.insertBatch(insertQueueList);
|
|
|
|
|
|
|
|
startQueueId = insertQueueList.get(insertQueueList.size() - 1).getOpOrderRsyncPageQueueId();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(deleteBufferIds)) {
|
|
|
|
|
|
|
|
opOrderRsyncPageBufferMapper.deleteByIdList(deleteBufferIds);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
dataSourceTransactionManager.rollback(transactionStatus); //事务回滚
|
|
|
|
|
|
|
|
return ApiResult.fail("数据处理失败,进行回滚。");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotNull(startQueueId)) {
|
|
|
|
|
|
|
|
int queueCount = insertQueueList.size();
|
|
|
|
|
|
|
|
int queueIdLoop = 0;
|
|
|
|
|
|
|
|
for (Long queueId = startQueueId; queueId < (queueCount + startQueueId); queueId++) {
|
|
|
|
|
|
|
|
OpOrderRsyncPageQueue queueData = insertQueueList.get(queueIdLoop);
|
|
|
|
|
|
|
|
String queueRedisKey = RedisKeyConst.getQueueRedisKey(TblConst.op_order_rsync_page_queue, false);
|
|
|
|
|
|
|
|
redisTemplate.opsForList().leftPush(queueRedisKey, queueId.toString());
|
|
|
|
|
|
|
|
queueIdLoop++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiResult.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void doCheckRsyncOpEnd(Long shopId, Long queueId) {
|
|
|
|
private void doCheckRsyncOpEnd(Long shopId, Long queueId) {
|
|
|
|