简化修改调度逻辑

This commit is contained in:
lsymicc
2026-04-09 14:06:31 +08:00
parent 715fd4a017
commit 1a93c78909
2 changed files with 197 additions and 144 deletions

View File

@@ -3,6 +3,7 @@ package com.ruoyi.schedule.scheduleTask.ssj;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.api.domain.wcs2wms.stockin.StockinReceive;
import com.ruoyi.api.service.IApiService;
@@ -20,9 +21,7 @@ import com.ruoyi.queue.agv.domain.AgvQueue;
import com.ruoyi.queue.agv.service.IAgvQueueService;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.*;
@@ -43,7 +42,7 @@ public class PortConvThread implements Runnable {
public HashMap<String, List<String>> ssjCodeList;
private IApiService apiService;
private IAgvQueueService agvQueueService;
// private IAgvQueueService agvQueueService;
private IMydoJobService mydoJobService;
private IJobCallBackService jobCallBackService;
private IBasCargoSpaceService basCargoSpaceService;
@@ -59,11 +58,11 @@ public class PortConvThread implements Runnable {
// ssjCodes.add("L1003");
ssjCodeList.put("portConv", ssjCodes);
apiService = SpringUtils.getBean(IApiService.class);
agvQueueService = SpringUtils.getBean(IAgvQueueService.class);
// agvQueueService = SpringUtils.getBean(IAgvQueueService.class);
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
jobCallBackService = SpringUtils.getBean(IJobCallBackService.class);
basCargoSpaceService = SpringUtils.getBean(IBasCargoSpaceService.class);
log.info("初始化服务 {},{}", apiService, agvQueueService);
// log.info("初始化服务 {},{}", apiService, agvQueueService);
}
@Override
@@ -101,153 +100,31 @@ public class PortConvThread implements Runnable {
public void inDispatch(DeviceSsj inSsjDevice) {
// 测试数据
// inSsjDevice.setInOrOut(1);
// inSsjDevice.setTrayCode("T888888");
// inSsjDevice.setKx(0);
// inSsjDevice.setDw(1);
inSsjDevice.setInOrOut(1);
inSsjDevice.setTrayCode("T888888");
inSsjDevice.setTaskNo(85012);
inSsjDevice.setKx(0);
inSsjDevice.setDw(1);
// inSsjDevice.setHeight("1");
// inSsjDevice.setWeight("100");
// inSsjDevice.setException(0);
inSsjDevice.setException(0);
// inSsjDevice.setRkqq(1);
switch (inSsjDevice.getInOrOut()) {
//---------------------------入库模式---------------------------
case 1:
//---------------------------入口取输送机(叉车取放货位置)---------------------------
//输送机【非空闲】、【输送到位】(【条码不为空】、有【入库请求】)
//输送机【非空闲】、【输送到位】、【入库请求】
if (inSsjDevice.getKx() != 1 && inSsjDevice.getDw() == 1) {
AjaxResult ajaxResult;
//更新入库任务阶段
updateMydoJob(inSsjDevice);
//请求参数
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("taskTypeCode", "inBound");//任务类型编号
paramMap.put("reqCode", UUID.randomUUID().toString());//请求码
paramMap.put("cntCode", inSsjDevice.getTrayCode());//容器编号
String height = inSsjDevice.getHeight();
String weight = inSsjDevice.getWeight();
paramMap.put("weight", weight);//重量
paramMap.put("altimetry", height);//高度
paramMap.put("adverseCauses", "");//异常信息
//请求wms获取入库任务
requestMydoJob(inSsjDevice);
//-----------------入库口异常校验-----------------
switch (inSsjDevice.getException()) {
//外形检测异常
case ConvException.CHECK_SIZE_EXCEPTION:
paramMap.put("adverseCauses", "外形检测异常-货物超高");
ajaxResult = apiService.createInMydoJobException(paramMap);
if (ajaxResult.isSuccess()) {
//向输送机下发退回
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "99", 99, 1);
}
return;
//超重检测
case ConvException.CHECK_OVERWEIGHT_EXCEPTION:
paramMap.put("adverseCauses", "外形检测异常-货物超重");
ajaxResult = apiService.createInMydoJobException(paramMap);
if (ajaxResult.isSuccess()) {
//向输送机下发退回
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "99", 99, 1);
}
return;
//扫码异常
case ConvException.CHECK_BARCODE_EXCEPTION:
if (inSsjDevice.getTrayCode() == "") {
paramMap.put("adverseCauses", "条码扫描失败:扫描结果为空");
ajaxResult = apiService.createInMydoJobException(paramMap);
}else{
//条码格式校验
paramMap.put("adverseCauses", "条码扫描异常:格式错误");
ajaxResult = apiService.createInMydoJobException(paramMap);
}
if (ajaxResult.isSuccess()) {
//向输送机下发退回
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "99", 99, 1);
}
return;
}
//-----------------校验:有【入库请求】再请求获取wcs任务-----------------
if (inSsjDevice.getRkqq() != 1) {
return;
}
//-----------------校验:当前条码任务已存在-----------------
MydoJob job = new MydoJob();
job.setTrayCode(inSsjDevice.getTrayCode());
if (!mydoJobService.selectMydoJobList(job).isEmpty()) {
log.warn("【生成wcs任务异常】该托盘号已有作业,托盘条码:{}",inSsjDevice.getTrayCode());
return;
}
//-----------------校验:当前条码已有库存-----------------
BasCargoSpace cargoSpace = new BasCargoSpace();
cargoSpace.setTrayCode(inSsjDevice.getTrayCode());
if (!basCargoSpaceService.selectBasCargoSpaceList(cargoSpace).isEmpty()) {
log.warn("【生成wcs任务异常】该托盘号已有库存,托盘条码:{}",inSsjDevice.getTrayCode());
return;
}
//-----------------请求生成wcs任务-----------------
ajaxResult = apiService.createMydoJobForStockin(paramMap);
if (ajaxResult.isSuccess()) {
//获取wms下发的任务号和分配货位
StockinReceive result = BeanUtil.toBean(ajaxResult.get("data"), StockinReceive.class);
MydoJob mydoJob = new MydoJob();
mydoJob.setTrayCode(result.getCntCode());
mydoJob.setCargoSpaceId(result.getSiteCode());
mydoJob.setWmsTaskNo(result.getTaskCode());
mydoJob.setJobId(mydoJobService.getJobId("RK"));
mydoJob.setTaskNo(mydoJobService.getTaskNo("1"));
// mydoJob.setTaskNo(result.getTaskCode());//todo 确定是否用获取的任务号作为wcs的任务号
//todo 校验wms分配的货位(排列层)是否合法
if (mydoJob.getCargoSpaceId() == null) {
log.info("【请求参数异常】分配货位:null,托盘条码:{}",inSsjDevice.getTrayCode());
return;
}else{
}
mydoJob.setStatus("1");
mydoJob.setInOrOut("1");
mydoJob.setEntranceId("G1004");
mydoJob.setExecutionPhase(TASK_EP_CREATE);
mydoJob.setCreateTime(new Date());
// mydoJob.setTraySize(Convert.toStr(inSsjDevice.getTraySize()));
mydoJob.setFaultFlag("0");
mydoJob.setPriority(Long.valueOf(10));
//如果还没有生成wcs任务 - 先生成一条任务记录
if (mydoJobService.selectInOrOutMydoJobList(mydoJob).isEmpty()) {
mydoJobService.insertMydoJob(mydoJob);
log.info("【入库请求】请求生成wcs作业成功,wms下发任务单号:{}, 任务号:{},托盘条码:{},分配货位:{}", mydoJob.getJobId(), mydoJob.getTaskNo(), mydoJob.getTrayCode(), mydoJob.getCargoSpaceId());
}else{
//如果已经生成入库任务 - 向输送机下发任务号
//todo 调整输送去向值
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), mydoJob.getTaskNo(), Integer.parseInt(mydoJob.getTraySize()), 1);
if (i == 1) {
//写入成功则更新执行阶段
mydoJob.setExecutionPhase(TASK_EP_LINE_SSJ);
mydoJobService.updateMydoJob(mydoJob);
log.info("【更新状态】G1004入口输送机下发任务号成功:{}", mydoJob.getTaskNo());
}
}
}else{
//请求生成wcs任务失败
//todo 向输送机下发退回
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "99", 99, 1);
//todo 接口调用失败处理
log.info("【入库请求】请求生成wcs作业失败退回,请重试,请求内容:{}");
}
}
break;
//---------------------------出库模式---------------------------
case 2:
@@ -330,7 +207,7 @@ public class PortConvThread implements Runnable {
mydoJob2.setExecutionPhase(TASK_EP_CREATE);
mydoJob2.setCreateTime(new Date());
mydoJob2.setFaultFlag("0");
mydoJob2.setPriority(Long.valueOf(10));
mydoJob2.setPriority(10L);
mydoJobService.insertMydoJob(mydoJob2);
int i = writeToSsj(ssjDevice.getPlcDbWriteAddress(),mydoJob2.getTaskNo(),1,1);
if (i == 1) {
@@ -373,4 +250,154 @@ public class PortConvThread implements Runnable {
Matcher m = pattern.matcher(input);
return m.find() ? m.group(1) : null;
}
/**
* 请求wms获取wcs任务参数
* @param inSsjDevice
*/
private void requestMydoJob(DeviceSsj inSsjDevice){
//校验:入库请求
if (inSsjDevice.getRkqq() != 1) {
return;
}
AjaxResult ajaxResult;
//请求参数
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("taskTypeCode", "inBound");//任务类型编号
paramMap.put("reqCode", UUID.randomUUID().toString());//请求码
paramMap.put("cntCode", inSsjDevice.getTrayCode());//容器编号
String height = inSsjDevice.getHeight();
String weight = inSsjDevice.getWeight();
paramMap.put("weight", weight);//重量
paramMap.put("altimetry", height);//高度
String errorMessage = "";
//-----------------校验:入库口异常上报-----------------
switch (inSsjDevice.getException()) {
//外形检测异常
case ConvException.CHECK_SIZE_EXCEPTION:
errorMessage = "外形检测异常-货物超高";
break;
//超重检测
case ConvException.CHECK_OVERWEIGHT_EXCEPTION:
errorMessage = "外形检测异常-货物超重";
break;
//扫码异常
case ConvException.CHECK_BARCODE_EXCEPTION:
if (inSsjDevice.getTrayCode() == "") {
errorMessage = "条码扫描失败:未扫到条码";
}else{
//todo 条码格式校验
errorMessage = "条码扫描异常:格式错误";
}
break;
}
if (inSsjDevice.getException() > 0){
paramMap.put("adverseCauses", errorMessage);
ajaxResult = apiService.createInMydoJobException(paramMap);
if (ajaxResult.isSuccess()) {
//向输送机下发退回
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "99", 99, 1);
if (i == 1) {
log.warn("【入库异常】{}",errorMessage);
}
}
}
//-----------------校验:条码已有库存-----------------
BasCargoSpace cargoSpace = new BasCargoSpace();
cargoSpace.setTrayCode(inSsjDevice.getTrayCode());
if (!basCargoSpaceService.selectBasCargoSpaceList(cargoSpace).isEmpty()) {
log.warn("【生成wcs任务异常】该托盘号已有库存,托盘条码:{}",inSsjDevice.getTrayCode());
return;
}
//-----------------请求生成wcs任务-----------------
ajaxResult = apiService.createMydoJobForStockin(paramMap);
if (ajaxResult.isSuccess()) {
//获取wms下发的任务号和分配货位
StockinReceive result = BeanUtil.toBean(ajaxResult.get("data"), StockinReceive.class);
MydoJob mydoJob = new MydoJob();
mydoJob.setTrayCode(result.getCntCode());
mydoJob.setCargoSpaceId(result.getSiteCode());
mydoJob.setWmsTaskNo(result.getTaskCode());
mydoJob.setJobId(mydoJobService.getJobId("RK"));
mydoJob.setTaskNo(mydoJobService.getTaskNo("1"));
// mydoJob.setTaskNo(result.getTaskCode());//todo 确定是否用获取的任务号作为wcs的任务号
//校验:wms分配的货位(排列层)是否合法
if (result.getSiteCode() == null || result.getSiteCode().isEmpty()) {
log.info("【请求参数异常】分配货位:null,无法生成作业,托盘条码:{}",inSsjDevice.getTrayCode());
return;
}else {
mydoJob.setRoadwayId(basCargoSpaceService.selectBasCargoSpaceByWmsCargoSpaceId(mydoJob.getCargoSpaceId()).getRoadwayId());
}
mydoJob.setStatus("1");
mydoJob.setInOrOut("1");
mydoJob.setRoadwayId("1");
mydoJob.setEntranceId("G1004");
mydoJob.setExecutionPhase(TASK_EP_CREATE);
mydoJob.setCreateTime(new Date());
// mydoJob.setTraySize(Convert.toStr(inSsjDevice.getTraySize()));
mydoJob.setFaultFlag("0");
mydoJob.setPriority(10L);
//如果还没有wcs任务 - 生成一条任务
if (mydoJobService.selectInOrOutMydoJobList(mydoJob).isEmpty()) {
mydoJobService.insertMydoJob(mydoJob);
log.info("【入库请求】请求生成wcs作业成功,wms下发任务单号:{}, 任务号:{},托盘条码:{},分配货位:{}", mydoJob.getJobId(), mydoJob.getTaskNo(), mydoJob.getTrayCode(), mydoJob.getCargoSpaceId());
}
}else{
//请求生成wcs任务失败
//todo 向输送机下发退回
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "99", 99, 1);
//todo 接口调用失败处理
log.info("【入库请求】请求生成wcs作业失败退回,请重试,响应内容:{}", ajaxResult.get("data").toString());
}
}
/**
* 更新入库任务阶段
* @param inSsjDevice
*/
private void updateMydoJob(DeviceSsj inSsjDevice){
//检查是否有已经创建成功的任务 - 更新到下一个执行阶段
MydoJob mydoJobStockin = new MydoJob();
mydoJobStockin.setTrayCode(inSsjDevice.getTrayCode());
mydoJobStockin.setExecutionPhase(TASK_EP_CREATE);
if(mydoJobService.selectMydoJobList(mydoJobStockin).isEmpty()){
//输送机扫描有条码但无任务
log.info("【异常任务】请检查条码扫描结果与托盘实际条码是否一致,扫描条码:{}", inSsjDevice.getTrayCode());
}else{
mydoJobStockin = mydoJobService.selectMydoJobList(mydoJobStockin).get(0);
//如果已经生成入库任务 - 向输送机下发任务号
//todo 调整输送去向值
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), mydoJobStockin.getTaskNo(), Integer.parseInt(mydoJobStockin.getTraySize()), 1);
// int i = 1;
if (i == 1) {
//写入成功则更新执行阶段
mydoJobStockin.setExecutionPhase(TASK_EP_SSJ);
mydoJobService.updateMydoJob(mydoJobStockin);
log.info("【更新状态】G1004入口输送机下发任务号成功:{}", mydoJobStockin.getTaskNo());
}
}
}
}

View File

@@ -93,6 +93,21 @@ public class RoadConvThread implements Runnable {
public void inDispatch(DeviceSsj roadSsjDevice) {
sendStackerIn(roadSsjDevice);
sendStackerOut(roadSsjDevice);
}
/**
* 向堆垛机发送【入库】任务
* @param roadSsjDevice
*/
private void sendStackerIn(DeviceSsj roadSsjDevice){
//模拟数据
roadSsjDevice.setDw(1);
roadSsjDevice.setTaskNo(85012);
//---------------------------入库任务---------------------------
//巷道口输送机到位,且任务号大于1000
if (roadSsjDevice.getDw()==1 && roadSsjDevice.getTaskNo()>1000) {
@@ -109,11 +124,16 @@ public class RoadConvThread implements Runnable {
// 检查任务属性:【任务已存在】、执行阶段-【巷道口输送机到位】、任务类型-【入库】
// 下发堆垛机执行队列
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)
if (ObjUtil.isNotNull(mydoJob)
&& mydoJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)
&& Convert.toInt(mydoJob.getInOrOut()) < 20) {
//检查堆垛机是否在正在执行中
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueListByRwlx(DDJ_RWLX_1, Convert.toInt(mydoJob.getRoadwayId()));
BasCargoSpace basCargoSpace = basCargoSpaceService.selectBasCargoSpaceByWmsCargoSpaceId(mydoJob.getCargoSpaceId());
List<Integer> pclList = roadwayMap.get(roadSsjDevice.getDeviceCode());
//生成堆垛机执行队列
if (CollUtil.isEmpty(ddjDeviceExecutionQueues) && ObjUtil.isNotNull(basCargoSpace) && CollUtil.isNotEmpty(pclList)) {
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
ddjDeviceExecutionQueue.setUuid(IdUtil.simpleUUID());
@@ -134,16 +154,22 @@ public class RoadConvThread implements Runnable {
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_1);
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
//生成堆垛机执行队列后更新任务阶段
//下发后更新任务阶段
mydoJob.setExecutionPhase(TASK_EP_DDJ);
mydoJobService.updateMydoJob(mydoJob);
}
}
}
}
}
//---------------------------出库任务---------------------------
/**
* 向堆垛机发送【出库】任务
* @param roadSsjDevice
*/
private void sendStackerOut(DeviceSsj roadSsjDevice){
//---------------------------出库任务---------------------------
//检查巷道口输送机是否空闲
if(roadSsjDevice.getKx()==1 && roadSsjDevice.getTaskNo() == 0){
//检查是否有入口是【G1004】的入库任务