refactor(schedule): 优化堆垛机任务调度逻辑

- 使用静态导入统一任务状态码常量
- 替换硬编码设备地址为动态获取PLC写入地址
- 修改任务号判断条件从0改为1000以上
- 更新设备映射关系适配新PLC点位配置
- 简化出入库作业下发逻辑减少冗余代码
- 重构读取PLC数据方法命名提高可读性
- 新增楼层2设备点位配置支持新硬件布局
This commit is contained in:
liuhanqing
2025-12-12 14:24:41 +08:00
parent 4cb4625992
commit 0ea3fdcd48
6 changed files with 35 additions and 45 deletions

View File

@@ -50,8 +50,8 @@ public class Floor1BothWayInSsjThread implements Runnable {
ssjCodeList = new HashMap<>();
ssjCodeList.put("roadway1", PlcSsjRead.deviceSsjMap.get("L2003"));
ssjCodeList.put("roadway2", PlcSsjRead.deviceSsjMap.get("L2005"));
ssjCodeList.put("in1", PlcSsjRead.deviceSsjMap.get("L2012"));
ssjCodeList.put("in2", PlcSsjRead.deviceSsjMap.get("L2013"));
ssjCodeList.put("in1", PlcSsjRead.deviceSsjMap.get("L2004"));
ssjCodeList.put("in2", PlcSsjRead.deviceSsjMap.get("L2006"));
apiService = SpringUtils.getBean(IApiService.class);
@@ -64,8 +64,8 @@ public class Floor1BothWayInSsjThread implements Runnable {
roadwayMap.put("L2003", Arrays.asList(1, 1, 1));
roadwayMap.put("L2005", Arrays.asList(1, 1, 1));
exitRoadwayMap.put("L2003", "L2012");
exitRoadwayMap.put("L2005", "L2013");
exitRoadwayMap.put("L2003", "L2004");
exitRoadwayMap.put("L2005", "L2006");
}
@@ -96,10 +96,10 @@ public class Floor1BothWayInSsjThread implements Runnable {
}
private void dispatch1(DeviceSsj ssj) {
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
if (ssj.getDw() == 1 && ssj.getTaskNo() > 1000) {
int taskNo = ssj.getTaskNo();
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(taskNo));
if (ObjUtil.isNotNull(mydoJob) && "1".equals(mydoJob.getStatus()) && TASK_EP_SSJ.equals(mydoJob.getExecutionPhase()) && Convert.toInt(mydoJob.getInOrOut())<20){
if (ObjUtil.isNotNull(mydoJob) && TASK_STATUS_CREATE.equals(mydoJob.getStatus()) && TASK_EP_SSJ.equals(mydoJob.getExecutionPhase()) && Convert.toInt(mydoJob.getInOrOut()) < 20) {
//修改作业执行状态
mydoJob.setStatus(TASK_STATUS_RUNNING);
mydoJob.setStartTime(DateUtil.formatDateTime(DateUtil.date()));
@@ -143,19 +143,9 @@ public class Floor1BothWayInSsjThread implements Runnable {
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0 && ssj.getTaskNo() < 1000 && ssj.getTraySize() != 0) {
//先检测有没有出库作业,有出库作业直接退回
MydoJob outMydoJob = mydoJobService.selectRunningMydoJobByExitList(Collections.singletonList(ssj.getDeviceCode()));
String l2012WriteAddress = "DB501.20";
String l2013WriteAddress = "DB501.30";
if (ObjUtil.isNotNull(outMydoJob) || StrUtil.isEmpty(ssj.getTrayCode())) {
int i = 0;
//下发去向 和任务号
switch (ssj.getDeviceCode()) {
case "L2012":
i = writeToSsj(l2012WriteAddress,"0",2,1);
break;
case "L2013":
i = writeToSsj(l2013WriteAddress,"0",2,1);
break;
}
int i = writeToSsj(ssj.getPlcDbWriteAddress(), "0", 2, 1);
if (i == 1) {
log.info("未检测到托盘码下发回退 rwh:{},qx:{},trayCode:{}", ssj.getTaskNo(), 1, ssj.getTrayCode());
}
@@ -178,22 +168,15 @@ public class Floor1BothWayInSsjThread implements Runnable {
if (result.isSuccess()) {
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
inJob.setStatus(TASK_STATUS_CREATE);
inJob.setExecutionPhase(TASK_EP_CREATE);
mydoJobService.insertMydoJob(inJob);
} else {
log.info("未检测到托盘码请求入库作业 rwh:{},trayCode:{}", ssj.getTaskNo(), ssj.getTrayCode());
}
}
if (inJob != null) {
int i = 0;
//下发去向 和任务号
switch (ssj.getDeviceCode()) {
case "L2012":
i = writeToSsj(l2012WriteAddress,inJob.getTaskNo(),1,1);
break;
case "L2013":
i = writeToSsj(l2013WriteAddress,inJob.getTaskNo(),1,1);
break;
}
int i = writeToSsj(ssj.getPlcDbWriteAddress(), inJob.getTaskNo(), 1, 1);
if (i == 1) {
inJob.setStatus(TASK_STATUS_RUNNING);
inJob.setExecutionPhase(TASK_EP_SSJ);

View File

@@ -40,6 +40,8 @@ public class Floor1BothWayOutSsjThread implements Runnable {
private final Map<String,List<Integer>> roadwayMap = new HashMap<>();
private IJobCallBackService jobCallBackService;
private final Map<String,DeviceSsj> roadwayOutMap = new HashMap<>();
public boolean isRun = true;
@@ -49,18 +51,18 @@ public class Floor1BothWayOutSsjThread implements Runnable {
ArrayList<DeviceSsj> roadway1 = new ArrayList<>();
roadway1.add(PlcSsjRead.deviceSsjMap.get("L2003"));
roadway1.add(PlcSsjRead.deviceSsjMap.get("L2004"));
roadway1.add(PlcSsjRead.deviceSsjMap.get("L2012"));
roadwayOutMap.put("L2003", PlcSsjRead.deviceSsjMap.get("L2004"));
ssjCodeList.put("roadway1", roadway1);
ArrayList<DeviceSsj> roadway2 = new ArrayList<>();
roadway2.add(PlcSsjRead.deviceSsjMap.get("L2005"));
roadway2.add(PlcSsjRead.deviceSsjMap.get("L2006"));
roadway2.add(PlcSsjRead.deviceSsjMap.get("L2013"));
roadwayOutMap.put("L2005", PlcSsjRead.deviceSsjMap.get("L2006"));
ssjCodeList.put("roadway2", roadway2);
ArrayList<DeviceSsj> ou1 = new ArrayList<>();
ou1.add(PlcSsjRead.deviceSsjMap.get("L2012"));
ou1.add(PlcSsjRead.deviceSsjMap.get("L2004"));
ssjCodeList.put("ou1", ou1);
ArrayList<DeviceSsj> out2 = new ArrayList<>();
out2.add(PlcSsjRead.deviceSsjMap.get("L2013"));
out2.add(PlcSsjRead.deviceSsjMap.get("L2006"));
ssjCodeList.put("out2", out2);
@@ -137,7 +139,7 @@ public class Floor1BothWayOutSsjThread implements Runnable {
* 出库堆垛机队列生成
*/
public void dispatch(List<DeviceSsj> ssjList) {
DeviceSsj deviceSsj = ssjList.get(ssjList.size() - 1);
DeviceSsj deviceSsj = roadwayOutMap.get(ssjList.get(0).getDeviceCode());
MydoJob pdOutJob = mydoJobService.selectMydoJobByExitList(Collections.singletonList(deviceSsj.getDeviceCode()));
MydoJob inJob = mydoJobService.selectMydoJobByEntranceList(Collections.singletonList(deviceSsj.getDeviceCode()));
boolean allKx = ssjList.stream().allMatch(ssj -> ssj.getKx() == 1);

View File

@@ -21,7 +21,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import static com.ruoyi.common.TaskStatusCode.TASK_EP_SSJ;
import static com.ruoyi.common.TaskStatusCode.*;
import static com.ruoyi.schedule.plcRead.ssj.PlcSsjRead.writeToSsj;
/**
@@ -43,8 +43,8 @@ public class Floor2InOutSsjThread implements Runnable {
public void init() {
ssjCodeList = new HashMap<>();
ArrayList<String> ssjCodes = new ArrayList<>();
ssjCodes.add("L1011");
ssjCodes.add("L1012");
ssjCodes.add("L1001");
ssjCodes.add("L1003");
ssjCodeList.put("inout", ssjCodes);
ssjCodes.add("L1001");
ssjCodes.add("L1003");
@@ -216,7 +216,7 @@ public class Floor2InOutSsjThread implements Runnable {
if(ajaxResult.isSuccess()){
MydoJob mydoJob2 = BeanUtil.toBean(ajaxResult.get("data"), MydoJob.class) ;
mydoJob2.setStatus("1");
mydoJob2.setExecutionPhase("0");
mydoJob2.setExecutionPhase(TASK_EP_CREATE);
mydoJob2.setCreateTime(new Date());
mydoJobService.insertMydoJob(mydoJob2);
int i = writeToSsj(ssjDevice.getPlcDbWriteAddress(),mydoJob2.getTaskNo(),1,1);

View File

@@ -23,8 +23,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import static com.ruoyi.common.TaskStatusCode.TASK_EP_AGV;
import static com.ruoyi.common.TaskStatusCode.TASK_EP_LINE_SSJ;
import static com.ruoyi.common.TaskStatusCode.*;
import static com.ruoyi.schedule.plcRead.ssj.PlcSsjRead.deviceSsjMap;
import static com.ruoyi.schedule.plcRead.ssj.PlcSsjRead.writeToSsj;
@@ -133,7 +132,7 @@ public class LineSsjThread implements Runnable {
//拿到正常作业,插到wcs作业表,下发给输送机任务号,覆盖任务号
MydoJob mydoJob2 = BeanUtil.toBean(ajaxResult.get("data"), MydoJob.class) ;
mydoJob2.setStatus("1");
mydoJob2.setExecutionPhase("0");
mydoJob2.setExecutionPhase(TASK_EP_CREATE);
mydoJob2.setCreateTime(new Date());
mydoJobService.insertMydoJob(mydoJob2);
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(),mydoJob2.getTaskNo(),1,1);