自动采购任务
parent
84a6d8c360
commit
912e1010d3
@ -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());
|
||||
}
|
||||
}
|
@ -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…
Reference in New Issue