rev:手持组盘入库

This commit is contained in:
zhangzq
2024-08-16 10:57:54 +08:00
parent a95eabf89a
commit c7f93fc11c

View File

@@ -0,0 +1,102 @@
package org.nl.wms.system_manage.service.quartz.task;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpStatus;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.TableDataInfo;
import org.nl.common.enums.StatusEnum;
import org.nl.common.utils.BaseCode;
import org.nl.common.utils.IdUtil;
import org.nl.config.lucene.LuceneAppender;
import org.nl.wms.dispatch_manage.task.service.ISchBaseTaskService;
import org.nl.wms.dispatch_manage.task.service.dao.SchBaseTask;
import org.nl.wms.external_system.acs.service.WmsToAcsService;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/*
* @author ZZQ
* @Date 2023/3/22 17:14
*/
@Service
@Slf4j
public class TaskScheduleService {
private ReentrantLock lock = new ReentrantLock();
@Autowired
private ISchBaseTaskService iSchBaseTaskService;
@Autowired
private WmsToAcsService wmsToAcsService;
public void run(){
try {
MDC.put("requestMethod","TaskScheduleService#run");
MDC.put("requestIp", "127.0.0.1");
MDC.put("requestTime", DateUtil.now());
LuceneAppender.traceIdTL.set(BaseCode.intToChars(IdUtil.getLongId()));
this.taskPublish();
}finally {
LuceneAppender.traceIdTL.remove();
}
}
public void taskPublish(){
boolean islock = lock.tryLock();
try {
Thread thread = new Thread(()->{
log.info("子线程任务------");
});
thread.start();
log.info("111---执行定时任务:-----taskPublish-----");
if (islock){
//查询所有自动下发的任务
List<SchBaseTask> list = iSchBaseTaskService.list(new QueryWrapper<SchBaseTask>().eq("is_send", true)
.eq("status", StatusEnum.FORM_STATUS.code("生成")));
if (!CollectionUtils.isEmpty(list)){
List<String> taskCodes = list.stream().map(SchBaseTask::getTask_code).collect(Collectors.toList());
log.info("222---执行定时任务:-----taskPublish-----"+ taskCodes);
TableDataInfo response = wmsToAcsService.interationToExt(list, "createTask");
if (!response.getCode().equals(String.valueOf(HttpStatus.HTTP_OK))){
JSONArray results = (JSONArray)JSON.toJSON(response.getData());
if (!CollectionUtils.isEmpty(results)){
for (Object result : results) {
Map resultM = (Map) result;
taskCodes.remove(resultM.get("task_code"));
iSchBaseTaskService.update(new UpdateWrapper<SchBaseTask>()
.eq("task_code",resultM.get("task_code"))
.set("status",StatusEnum.FORM_STATUS.code("暂停"))
.set("update_time", DateUtil.now()).set("remark",resultM.get("msg")));
}
}
}
if (!CollectionUtils.isEmpty(taskCodes)){
iSchBaseTaskService.update(new UpdateWrapper<SchBaseTask>()
.set("status",StatusEnum.FORM_STATUS.code("下发"))
.in("task_code",taskCodes));
}
}
}
}finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()){
lock.unlock();
}
}
}
}