自动采购任务

20230922-ljl-fixBug
wangchaoxu 1 year ago
parent 84a6d8c360
commit 912e1010d3

@ -82,4 +82,6 @@ public interface PurchaseOrderService {
boolean needPurchaseSetting);
int updateStatusByOrderId(Long shopId, String orderId, String status);
boolean doMoveDsAutoPurchaseBufferToQueue(Map<Long, Long> shopIdAndMoveCntMap);
}

@ -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;
}
}

@ -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<Long, Long> shopIdAndMoveCntMap) {
final int pageSize = 100;
List<String> allOrderIds = new ArrayList<>();
Map<Long, DsAutoPurchaseOrderBuffer> 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<DsAutoPurchaseOrderBuffer> bufferRows = dsAutoPurchaseOrderBufferMapper.selectXXXX();
if (bufferRows.size() == 0) {
continue;
}
allOrderIds.addAll(bufferRows.stream().map(DsAutoPurchaseOrderBuffer::getOrderId).collect(Collectors.toList()));
Map<Long, DsAutoPurchaseOrderBuffer> bufferRowsMap = CommonTool.convertListToMap(bufferRows, DsAutoPurchaseOrderBuffer::getDsAutoPurchaseOrderBufferId);
allBufferMap.putAll(bufferRowsMap);
}
if (allBufferMap.isEmpty()) {
return false;
}
// todo: 未完待续
return true;
}
}

@ -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<ItemDTO, Ret> {
@Autowired
private MoveDsAutoPurchaseBufferToQueueTaskService moveDsAutoPurchaseBufferToQueueTaskService;
@Override
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
moveDsAutoPurchaseBufferToQueueTaskService.runTask();
return R.ok(Ret.success());
}
}

@ -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

@ -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;

@ -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<Long, Long> 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<Long, Long> shopIdAndMoveCntMap = (Map<Long, Long>) 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");
}
}
}
Loading…
Cancel
Save