From 912e1010d32f0c29df31d0988c0450217073d9e1 Mon Sep 17 00:00:00 2001 From: wangchaoxu Date: Fri, 8 Sep 2023 13:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=87=87=E8=B4=AD=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ms/api/service/PurchaseOrderService.java | 2 + .../service/impl/DoudianMsgServiceImpl.java | 11 -- .../impl/PurchaseOrderServiceImpl.java | 83 +++++++------- ...AutoPurchaseBufferToQueueTimerService.java | 27 +++++ ...nAftersaleMsgBufferToQueueTaskService.java | 1 - ...udianTradeMsgBufferToQueueTaskService.java | 1 - ...sAutoPurchaseBufferToQueueTaskService.java | 107 ++++++++++++++++++ 7 files changed, 175 insertions(+), 57 deletions(-) create mode 100644 ms-biz/src/main/java/com/ms/api/spi/timer/MoveDsAutoPurchaseBufferToQueueTimerService.java create mode 100644 ms-biz/src/main/java/com/ms/api/task/MoveDsAutoPurchaseBufferToQueueTaskService.java diff --git a/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java b/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java index 637309a2..b6848648 100644 --- a/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java +++ b/ms-biz/src/main/java/com/ms/api/service/PurchaseOrderService.java @@ -82,4 +82,6 @@ public interface PurchaseOrderService { boolean needPurchaseSetting); int updateStatusByOrderId(Long shopId, String orderId, String status); + + boolean doMoveDsAutoPurchaseBufferToQueue(Map shopIdAndMoveCntMap); } diff --git a/ms-biz/src/main/java/com/ms/api/service/impl/DoudianMsgServiceImpl.java b/ms-biz/src/main/java/com/ms/api/service/impl/DoudianMsgServiceImpl.java index da9b609b..bf9defe1 100644 --- a/ms-biz/src/main/java/com/ms/api/service/impl/DoudianMsgServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/api/service/impl/DoudianMsgServiceImpl.java @@ -531,19 +531,8 @@ public class DoudianMsgServiceImpl implements DoudianMsgService { @Override public boolean deleteDoudianAftersaleMsgQueue(Long queueId) { -// DoudianAftersaleMsgQueue queueMsg = (DoudianAftersaleMsgQueue) params.get("queueMsg"); -// int affRow = doudianTradeMsgQueueMapper.deleteByPrimaryKey(queueMsg.getDoudianAftersaleMsgQueueId()); int affRow = doudianTradeMsgQueueMapper.deleteByPrimaryKey(queueId); return affRow > 0 ? true : false; -// if (!StringUtils.isEmpty(queueMsg.getMsgId())) { -// DdAftersaleMsg obj = new DdAftersaleMsg(); -// obj.setMsgId(queueMsg.getMsgId()); -// obj.setStatus(); -// obj.setReason(); -// obj.setGmtModified(new Date()); -// ddAftersaleMsgMapper.updateByMsgIdSelective(obj); -// } -// return true; } } diff --git a/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java b/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java index cc97813f..eb890aec 100644 --- a/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/api/service/impl/PurchaseOrderServiceImpl.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.stream.Collector; import java.util.stream.Collectors; import cn.hutool.core.collection.CollectionUtil; @@ -74,50 +75,8 @@ import com.ms.dal.bo.OpLogisticsPlatformBO; import com.ms.dal.bo.OpOrderAddressHistoryBO; import com.ms.dal.bo.OpOrderChildBO; import com.ms.dal.bo.PurchaseOrderBO; -import com.ms.dal.entity.AfterSale; -import com.ms.dal.entity.DsAllowAutoPurchaseProduct; -import com.ms.dal.entity.DsAutoPurchaseAgreement; -import com.ms.dal.entity.DsAutoPurchaseLog; -import com.ms.dal.entity.DsAutoPurchaseSwitchLog; -import com.ms.dal.entity.DsFilterAutoPurchaseProduct; -import com.ms.dal.entity.DsPurchaseSetting; -import com.ms.dal.entity.DsPurchaseSettingLog; -import com.ms.dal.entity.OpOrder; -import com.ms.dal.entity.OpOrderAmountDetail; -import com.ms.dal.entity.OpOrderChildLogistics; -import com.ms.dal.entity.OpOrderEncryptIndex; -import com.ms.dal.entity.OpOrderExt; -import com.ms.dal.entity.OpOrderGivenProduct; -import com.ms.dal.entity.OpOrderOutstorageHistory; -import com.ms.dal.entity.OpOrderPhase; -import com.ms.dal.entity.OpOrderPriceProtection; -import com.ms.dal.entity.OpOrderRedpackInfo; -import com.ms.dal.entity.OpOrderSensitive; -import com.ms.dal.entity.ProductToDsItem; -import com.ms.dal.entity.PurchaseOrder; -import com.ms.dal.entity.PurchaseOrderItem; -import com.ms.dal.entity.PurchaseOrderSetting; -import com.ms.dal.entity.PurchaseSetting; -import com.ms.dal.entity.PurchaseSettingLog; -import com.ms.dal.entity.Shop; -import com.ms.dal.entity.ShopTo1688DsMember; -import com.ms.dal.mapper.DsAllowAutoPurchaseProductMapper; -import com.ms.dal.mapper.DsAutoPurchaseAgreementMapper; -import com.ms.dal.mapper.DsAutoPurchaseLogMapper; -import com.ms.dal.mapper.DsAutoPurchaseSwitchLogMapper; -import com.ms.dal.mapper.DsFilterAutoPurchaseProductMapper; -import com.ms.dal.mapper.DsPurchaseSettingLogMapper; -import com.ms.dal.mapper.DsPurchaseSettingMapper; -import com.ms.dal.mapper.OpOrderChildMapper; -import com.ms.dal.mapper.OpOrderEncryptIndexMapper; -import com.ms.dal.mapper.OpOrderMapper; -import com.ms.dal.mapper.ProductToDsItemMapper; -import com.ms.dal.mapper.PurchaseOrderItemMapper; -import com.ms.dal.mapper.PurchaseOrderMapper; -import com.ms.dal.mapper.PurchaseOrderSettingMapper; -import com.ms.dal.mapper.PurchaseSettingLogMapper; -import com.ms.dal.mapper.PurchaseSettingMapper; -import com.ms.dal.mapper.ShopTo1688DsMemberMapper; +import com.ms.dal.entity.*; +import com.ms.dal.mapper.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -233,6 +192,9 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { @Autowired private DsAutoPurchaseLogMapper dsAutoPurchaseLogMapper; + @Autowired + private DsAutoPurchaseOrderBufferMapper dsAutoPurchaseOrderBufferMapper; + @Override public int deleteByPrimaryKey(Long id) { return purchaseOrderMapper.deleteByPrimaryKey(id); @@ -1876,6 +1838,39 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService { log.info("===========dsDebugCount:{}==========", total); return total; } + + @Override + @Transactional(rollbackFor = Exception.class) + public boolean doMoveDsAutoPurchaseBufferToQueue(Map shopIdAndMoveCntMap) { + final int pageSize = 100; + + List allOrderIds = new ArrayList<>(); + Map allBufferMap = new HashMap<>(); + + for (Long shopId : shopIdAndMoveCntMap.keySet()) { + if (!shopIdAndMoveCntMap.containsKey(shopId) && shopIdAndMoveCntMap.get(shopId) == null || shopIdAndMoveCntMap.get(shopId) <= 0) { + continue; + } + Long moveBufferCount = shopIdAndMoveCntMap.get(shopId); + + List bufferRows = dsAutoPurchaseOrderBufferMapper.selectXXXX(); + if (bufferRows.size() == 0) { + continue; + } + + allOrderIds.addAll(bufferRows.stream().map(DsAutoPurchaseOrderBuffer::getOrderId).collect(Collectors.toList())); + Map bufferRowsMap = CommonTool.convertListToMap(bufferRows, DsAutoPurchaseOrderBuffer::getDsAutoPurchaseOrderBufferId); + allBufferMap.putAll(bufferRowsMap); + } + + if (allBufferMap.isEmpty()) { + return false; + } + + // todo: 未完待续 + + return true; + } } diff --git a/ms-biz/src/main/java/com/ms/api/spi/timer/MoveDsAutoPurchaseBufferToQueueTimerService.java b/ms-biz/src/main/java/com/ms/api/spi/timer/MoveDsAutoPurchaseBufferToQueueTimerService.java new file mode 100644 index 00000000..794b1ca7 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/spi/timer/MoveDsAutoPurchaseBufferToQueueTimerService.java @@ -0,0 +1,27 @@ +package com.ms.api.spi.timer; + +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.common.R; +import com.ms.api.common.Ret; +import com.ms.api.common.TimerBaseService; +import com.ms.api.dto.ItemDTO; +import com.ms.api.task.MoveDsAutoPurchaseBufferToQueueTaskService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +@ExtensionService("moveDsAutoPurchaseBufferToQueueTimer") +@Slf4j +public class MoveDsAutoPurchaseBufferToQueueTimerService extends TimerBaseService implements ExtensionServiceHandler { + + @Autowired + private MoveDsAutoPurchaseBufferToQueueTaskService moveDsAutoPurchaseBufferToQueueTaskService; + + @Override + public BaseResponse handle(BaseRequest req) { + moveDsAutoPurchaseBufferToQueueTaskService.runTask(); + return R.ok(Ret.success()); + } +} diff --git a/ms-biz/src/main/java/com/ms/api/task/MoveDoudianAftersaleMsgBufferToQueueTaskService.java b/ms-biz/src/main/java/com/ms/api/task/MoveDoudianAftersaleMsgBufferToQueueTaskService.java index 0a24b051..31ec6b55 100644 --- a/ms-biz/src/main/java/com/ms/api/task/MoveDoudianAftersaleMsgBufferToQueueTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/MoveDoudianAftersaleMsgBufferToQueueTaskService.java @@ -10,7 +10,6 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.util.Map; import java.util.concurrent.Executor; @Configuration diff --git a/ms-biz/src/main/java/com/ms/api/task/MoveDoudianTradeMsgBufferToQueueTaskService.java b/ms-biz/src/main/java/com/ms/api/task/MoveDoudianTradeMsgBufferToQueueTaskService.java index 5fbb567e..a6990498 100644 --- a/ms-biz/src/main/java/com/ms/api/task/MoveDoudianTradeMsgBufferToQueueTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/MoveDoudianTradeMsgBufferToQueueTaskService.java @@ -2,7 +2,6 @@ package com.ms.api.task; import com.ms.api.common.TaskBaseService; import com.ms.api.service.DoudianMsgService; -import com.ms.dal.entity.DoudianMsgParseQueue; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/ms-biz/src/main/java/com/ms/api/task/MoveDsAutoPurchaseBufferToQueueTaskService.java b/ms-biz/src/main/java/com/ms/api/task/MoveDsAutoPurchaseBufferToQueueTaskService.java new file mode 100644 index 00000000..8554d8e4 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/task/MoveDsAutoPurchaseBufferToQueueTaskService.java @@ -0,0 +1,107 @@ +package com.ms.api.task; + +import com.alibaba.fastjson.JSONObject; +import com.ms.api.common.TaskBaseService; +import com.ms.api.consts.TblConst; +import com.ms.api.service.PurchaseOrderService; +import com.ms.api.service.QueueService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.Executor; + +@Configuration +@Component +@Slf4j +public class MoveDsAutoPurchaseBufferToQueueTaskService extends TaskBaseService { + + @Autowired + private QueueService queueService; + + @Autowired + private PurchaseOrderService purchaseOrderService; + + /** + * 同时开启任务处理数量 + */ + public int getCorePoolSiz() { + return 3; + } + + /** + * 任务管理器名称 + */ + public String getTaskExecutorName() { + return "moveDsAutoPurchaseBufferToQueueTaskPool"; + } + + @Bean(name = "moveDsAutoPurchaseBufferToQueueTaskPool") + @Override + public Executor getAsyncExecutor() { + return super.getAsyncExecutor(); + } + + @Resource(name = "moveDsAutoPurchaseBufferToQueueTaskPool") + protected Executor taskPool; + + @Override + protected Executor getTaskPool() { + return taskPool; + } + + @Async("moveDsAutoPurchaseBufferToQueueTaskPool") + @Override + public void runTask() { + super.runTask(); + } + + @Override + public Object getTask() { + int maxQueueCount = 5000; + int shopLimit = 100; + JSONObject filter = new JSONObject(); + log.info("start allocDoudianTradeBufferToQueueByShopAvg"); + Map shopIdAndMoveCntMap = queueService.allocBufferToQueueByShopAvg(TblConst.ds_auto_purchase_order_buffer, TblConst.ds_auto_purchase_order_queue, filter, maxQueueCount, shopLimit); + log.info("end allocDoudianTradeBufferToQueueByShopAvg"); + return shopIdAndMoveCntMap; + } + + /** + * 处理任务 + * + * @param params + * @return + */ + @Override + public Object processTask(Object params) { + if (params == null) { + return null; + } + Map shopIdAndMoveCntMap = (Map) params; + log.info("start doMoveDsAutoPurchaseBufferToQueue"); + boolean ret = purchaseOrderService.doMoveDsAutoPurchaseBufferToQueue(shopIdAndMoveCntMap); + log.info("end doMoveDsAutoPurchaseBufferToQueue"); + return ret; + } + + /** + * 清理任务 + * + * @param params + */ + @Override + public void clearTask(Object params) { + if (params == null) { + return; + } + if ((Boolean) params == true) { + log.info("MoveDsAutoPurchaseBufferToQueueTask finish"); + } + } +}