新增商品搬家的后台任务
parent
f1eae3ddb9
commit
e9001f0b58
@ -0,0 +1,28 @@
|
||||
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.MoveMaterialAuditBufferTaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ExtensionService("moveMaterialAuditBufferTimer")
|
||||
@Slf4j
|
||||
public class MoveMaterialAuditBufferTimerService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
|
||||
|
||||
@Autowired
|
||||
MoveMaterialAuditBufferTaskService moveMaterialAuditBufferTaskService;
|
||||
|
||||
@Override
|
||||
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
|
||||
moveMaterialAuditBufferTaskService.runTask();
|
||||
return R.ok(Ret.success());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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.MoveMaterialAuditProcessTaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ExtensionService("moveMaterialAuditProcessTimer")
|
||||
@Slf4j
|
||||
public class MoveMaterialAuditProcessTimerService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
|
||||
|
||||
@Autowired
|
||||
MoveMaterialAuditProcessTaskService moveMaterialAuditProcessTaskService;
|
||||
|
||||
@Override
|
||||
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
|
||||
moveMaterialAuditProcessTaskService.runTask();
|
||||
return R.ok(Ret.success());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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.MovePublishBufferTaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ExtensionService("movePublishBufferTimer")
|
||||
@Slf4j
|
||||
public class MovePublishBufferTimerService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
|
||||
|
||||
@Autowired
|
||||
MovePublishBufferTaskService movePublishBufferTaskService;
|
||||
|
||||
@Override
|
||||
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
|
||||
movePublishBufferTaskService.runTask();
|
||||
return R.ok(Ret.success());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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.ProcessProductPublishTaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@ExtensionService("proccessProductPublishTimer")
|
||||
@Slf4j
|
||||
public class ProccessProductPublishTimerService extends TimerBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
|
||||
|
||||
@Autowired
|
||||
ProcessProductPublishTaskService proccessProductPublishTaskService;
|
||||
|
||||
@Override
|
||||
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
|
||||
proccessProductPublishTaskService.runTask();
|
||||
return R.ok(Ret.success());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
package com.ms.api.task;
|
||||
|
||||
import com.ms.api.common.Ret;
|
||||
import com.ms.api.common.StrObjMap;
|
||||
import com.ms.api.common.TaskBaseService;
|
||||
import com.ms.api.tool.CommonTool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* 将move_product_publish_buffer中的数据
|
||||
* 移到move_product_publish_queue中的操作
|
||||
*/
|
||||
@Configuration
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MovePublishBufferTaskService extends TaskBaseService {
|
||||
|
||||
/**
|
||||
* 同时开启任务处理数量
|
||||
*/
|
||||
public int getCorePoolSiz() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务管理器名称
|
||||
*/
|
||||
public String getTaskExecutorName() {
|
||||
return "movePublishBufferTaskPool";
|
||||
}
|
||||
|
||||
@Bean(name = "movePublishBufferTaskPool")
|
||||
@Override
|
||||
public Executor getAsyncExecutor() {
|
||||
return super.getAsyncExecutor();
|
||||
}
|
||||
|
||||
@Resource(name = "movePublishBufferTaskPool")
|
||||
protected Executor taskPool;
|
||||
|
||||
@Override
|
||||
protected Executor getTaskPool() {
|
||||
return taskPool;
|
||||
}
|
||||
|
||||
//@Async("movePublishBufferTaskPool")
|
||||
@Override
|
||||
public void runTask() {
|
||||
super.runTask();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务
|
||||
*/
|
||||
@Override
|
||||
public Object getTask() {
|
||||
return getMoveProductPublishBufferShopMap(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理任务
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Object processTask(Object params) {
|
||||
StrObjMap selectedShopMap = (StrObjMap)params;
|
||||
log.info("start moveProductPublishBufferToQueue");
|
||||
Ret ret = moveProductPublishBufferToQueue(selectedShopMap);
|
||||
log.info("end moveProductPublishBufferToQueue ret: " + ret.toString());
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理任务
|
||||
*
|
||||
* @param params
|
||||
*/
|
||||
@Override
|
||||
public void clearTask(Object params) {
|
||||
}
|
||||
|
||||
private StrObjMap getMoveProductPublishBufferShopMap(int maxQueueCount) {
|
||||
log.info("handle getMoveProductPublishBufferShopMap");
|
||||
|
||||
int queueCount = 100; // TODO 查sql获取队列数量
|
||||
if (queueCount >= maxQueueCount) {
|
||||
log.info("queueCount " + queueCount + ", maxQueueCount " + maxQueueCount + ", end.");
|
||||
return null;
|
||||
}
|
||||
|
||||
int leftCount = maxQueueCount - queueCount;
|
||||
log.info("queueCount " + queueCount + ", maxQueueCount " + maxQueueCount + ", leftCount " + leftCount);
|
||||
StrObjMap selectedShopMap = countSelectedProductPublishBufferShopMap(leftCount);
|
||||
log.info("end getMoveProductPublishBufferSelectedShopMap");
|
||||
|
||||
return selectedShopMap;
|
||||
}
|
||||
|
||||
private StrObjMap countSelectedProductPublishBufferShopMap(int leftCount){
|
||||
log.info("handle countSelectedProductPublishBufferShopMap");
|
||||
StrObjMap ret = statProductPublishBuffer();
|
||||
StrObjMap priorityShopsMap = (StrObjMap)ret.get("priorityShopsMap");
|
||||
List<Long> shopIds = (List<Long>)ret.get("shopIds");
|
||||
log.info("end countSelectedProductPublishBufferShopMap");
|
||||
|
||||
// $stopMoveShopIds = $this->db->queryFirstColumn('select shop_id from move_shop_stop where is_limit_publish = 1');
|
||||
List<Long> stopMoveShopIds = new ArrayList<>(); // TODO 查上面sql获取
|
||||
shopIds = CommonTool.arrayDiff(shopIds, stopMoveShopIds);
|
||||
// foreach ($priorityShopsMap as $priority => $shopIdAndCountMap) {
|
||||
// foreach ($shopIdAndCountMap as $shopId => $count) {
|
||||
// if (in_array($shopId, $stopMoveShopIds)) {
|
||||
// unset($priorityShopsMap[$priority][$shopId]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
StrObjMap shopLimitQuotaArray = getShopLimitQuota(shopIds);
|
||||
log.info("start allocProductPublishQuota");
|
||||
StrObjMap selectedShopMap = allocProductPublishQuota(leftCount, priorityShopsMap, shopLimitQuotaArray);
|
||||
log.info("end allocProductPublishQuota");
|
||||
return selectedShopMap;
|
||||
}
|
||||
|
||||
private StrObjMap statProductPublishBuffer(){
|
||||
return null;
|
||||
}
|
||||
|
||||
private StrObjMap getShopLimitQuota(List<Long> shopIds){
|
||||
return null;
|
||||
}
|
||||
|
||||
private StrObjMap allocProductPublishQuota(int leftCount, StrObjMap priorityShopsMap, StrObjMap shopLimitQuotaArray) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Buffer移到Queue中
|
||||
private Ret moveProductPublishBufferToQueue(StrObjMap selectedShopMap) {
|
||||
StrObjMap bufferRowList = new StrObjMap();
|
||||
Ret addRet = addPublishQueueBatch(bufferRowList);
|
||||
//$bufferIds = ZcArrayHelper::getSub($bufferRowList, 'move_product_publish_buffer_id');
|
||||
List bufferIds = new ArrayList<>(); // TODO
|
||||
if (CommonTool.isSuccessRet(addRet)){
|
||||
log.info("start delete move_product_publish_buffer");
|
||||
//$delRet = $this->db->delete('move_product_publish_buffer', 'move_product_publish_buffer_id in %li', $bufferIds);
|
||||
Ret delRet = new Ret(); // TODO
|
||||
log.info("end delete move_product_publish_buffer delRet["+delRet+"] bufferIds total:" + bufferIds.size());
|
||||
}
|
||||
|
||||
// 加到redis队列
|
||||
// $redisTotal = 0;
|
||||
// foreach ($bufferRowList as $row) {
|
||||
// $redisTotal = $this->addPublishQueueToRedis($row['shop_id'], $row['priority'], $row['move_collect_task_detail_id']);
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Ret addPublishQueueBatch(StrObjMap bufferRowList) {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue