package com.zy.asrs.wcs.core.timer;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.zy.asrs.common.utils.HttpHandler;
|
import com.zy.asrs.wcs.core.entity.*;
|
import com.zy.asrs.wcs.core.model.enums.LocStsType;
|
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
|
import com.zy.asrs.wcs.core.service.*;
|
import com.zy.asrs.wcs.rcs.News;
|
import com.zy.asrs.wcs.system.entity.Dict;
|
import com.zy.asrs.wcs.system.service.DictService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.*;
|
|
@Slf4j
|
@Component
|
public class TaskTimer {
|
|
@Autowired
|
private TaskService taskService;
|
@Autowired
|
private TaskLogService taskLogService;
|
@Autowired
|
private MotionService motionService;
|
@Autowired
|
private MotionLogService motionLogService;
|
@Autowired
|
private LocService locService;
|
@Autowired
|
private DictService dictService;
|
@Autowired
|
private BasConveyorStaService basConveyorStaService;
|
|
@Scheduled(cron = "0/1 * * * * ? ")
|
@Transactional
|
public synchronized void clearCompletedTask2() {
|
ArrayList<Long> taskSts = new ArrayList<>();
|
// taskSts.add(TaskStsType.COMPLETE_INBOUND.sts);
|
// taskSts.add(TaskStsType.COMPLETE_OUTBOUND.sts);
|
taskSts.add(TaskStsType.COMPLETE_CHARGE.sts);
|
taskSts.add(TaskStsType.COMPLETE_MOVE.sts);
|
taskSts.add(TaskStsType.COMPLETE_MANUAL.sts);
|
|
List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
|
.eq(Task::getStatus, 1)
|
.in(Task::getTaskSts, taskSts));
|
for (Task task : tasks) {
|
|
// boolean httpRequest = doHttpRequest(task, "127.0.0.1:8080", "/wms/open/asrs//wrkMast/finish/v1");
|
// if (!httpRequest) {
|
// return;
|
// }
|
|
//记录库存信息
|
updateRecordLoc(task);
|
//任务转历史档
|
saveTaskLog(task);
|
}
|
}
|
|
@Scheduled(cron = "0/1 * * * * ? ")
|
@Transactional
|
public synchronized void clearCompletedTask() {
|
ArrayList<Long> taskSts = new ArrayList<>();
|
taskSts.add(TaskStsType.COMPLETE_INBOUND.sts);
|
taskSts.add(TaskStsType.COMPLETE_OUTBOUND.sts);
|
// taskSts.add(TaskStsType.COMPLETE_CHARGE.sts);
|
// taskSts.add(TaskStsType.COMPLETE_MOVE.sts);
|
// taskSts.add(TaskStsType.COMPLETE_MANUAL.sts);
|
|
Dict reportWms = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "reportWms"));
|
|
List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
|
.eq(Task::getStatus, 1)
|
.in(Task::getTaskSts, taskSts));
|
for (Task task : tasks) {
|
Motion motion = motionService.getOne(new LambdaQueryWrapper<Motion>().eq(Motion::getMotionCtg, 9).eq(Motion::getTaskNo, task.getTaskNo()));
|
List<BasConveyorSta> conveyorStas = basConveyorStaService.list(new LambdaQueryWrapper<BasConveyorSta>().in(BasConveyorSta::getTaskNo, motion.getTemp()));
|
if (!conveyorStas.isEmpty()) {
|
continue;
|
}
|
if (reportWms != null && reportWms.getValue().equals("true")) {
|
//获取WMS地址
|
Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "WMS_URL").eq(Dict::getStatus, 1));
|
if (dict == null) {
|
News.error("WMS地址未配置");
|
return;
|
}
|
String wmsUrl = dict.getValue();
|
|
if(task.getTaskSts().equals(TaskStsType.COMPLETE_INBOUND.sts) || task.getTaskSts().equals(TaskStsType.COMPLETE_OUTBOUND.sts)){
|
boolean httpRequest = doHttpRequest(task, wmsUrl, "/open/asrs//wrkMast/finish/v1");
|
if (!httpRequest) {
|
continue;
|
}
|
}
|
}
|
|
//记录库存信息
|
updateRecordLoc(task);
|
//任务转历史档
|
saveTaskLog(task);
|
}
|
}
|
|
private boolean doHttpRequest(Task requestParam, String url, String path){
|
String response = "";
|
boolean success = false;
|
try {
|
Map<String, Object> map = new HashMap<>();
|
map.put("appkey", "ea1f0459efc02a79f046f982767939ae");
|
Map<String, Object> map2 = new HashMap<>();
|
map2.put("taskNo", requestParam.getWmsTaskNo());
|
log.info("请求报文:"+ JSONObject.toJSONString(requestParam));
|
|
response = new HttpHandler.Builder()
|
.setHeaders(map)
|
.setUri(url)
|
.setPath(path)
|
.setJson(JSONObject.toJSONString(map2))
|
.build()
|
.doPost();
|
JSONObject jsonObject = JSON.parseObject(response);
|
log.info("请求返回:"+response);
|
String code = jsonObject.get("code").toString();
|
if(code.equals("200")){
|
success = true;
|
}
|
|
}catch (Exception e){
|
log.info("请求报错"+e.getMessage());
|
}
|
return success;
|
}
|
|
//更新库存信息
|
@Transactional
|
public void updateRecordLoc(Task task) {
|
if (task.getRecordLoc() == null) {
|
return;
|
}
|
|
if (task.getRecordLoc().equals("Y")) {//记录库存信息
|
//源库位 => 空库
|
//目标库位 => 在库
|
Loc originLoc = locService.selectByLocNo(task.getOriginLoc());
|
if (originLoc != null) {
|
originLoc.setLocSts(LocStsType.O.val());
|
locService.updateById(originLoc);
|
}
|
|
Loc destLoc = locService.selectByLocNo(task.getDestLoc());
|
if (destLoc != null) {
|
destLoc.setLocSts(LocStsType.F.val());
|
locService.updateById(destLoc);
|
}
|
} else if (task.getRecordLoc().equals("record-dest")) {//只记录目标库位信息
|
//目标库位 => 在库
|
Loc destLoc = locService.selectByLocNo(task.getDestLoc());
|
if (destLoc != null) {
|
destLoc.setLocSts(LocStsType.F.val());
|
locService.updateById(destLoc);
|
}
|
}
|
}
|
|
//更新历史档
|
@Transactional
|
public void saveTaskLog(Task task) {
|
//创建历史档
|
TaskLog taskLog = new TaskLog();
|
taskLog.sync(task);
|
taskLog.setUpdateTime(new Date());
|
taskLogService.save(taskLog);
|
|
List<Motion> motions = motionService.list(new LambdaQueryWrapper<Motion>().eq(Motion::getTaskNo, task.getTaskNo()).eq(Motion::getHostId, task.getHostId()));
|
for (Motion motion : motions) {
|
//创建动作历史档
|
MotionLog motionLog = new MotionLog();
|
motionLog.sync(motion);
|
motionLog.setUpdateTime(new Date());
|
motionLogService.save(motionLog);
|
}
|
|
//删除源任务
|
taskService.removeById(task.getId());
|
//删除动作
|
motionService.remove(new LambdaQueryWrapper<Motion>().eq(Motion::getTaskNo, task.getTaskNo()).eq(Motion::getHostId, task.getHostId()));
|
}
|
|
}
|