修改wcs首页,修改堆垛机调度 堆垛机读取线程
This commit is contained in:
@@ -18,4 +18,8 @@ public class Constant {
|
||||
public static final String REQUEST_ENTER_URL = WMS_BASE_URL+"requestEnterByTrayCodeAndEntranceId";
|
||||
|
||||
|
||||
public static final String WAREHOUSE_01 = "01";
|
||||
public static final String WAREHOUSE_02 = "02";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -27,8 +32,7 @@ import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/index")
|
||||
public class IndexController extends BaseController
|
||||
{
|
||||
public class IndexController extends BaseController {
|
||||
@Autowired
|
||||
private IDeviceCarService deviceCarService;
|
||||
|
||||
@@ -41,38 +45,33 @@ public class IndexController extends BaseController
|
||||
@Autowired
|
||||
private IDeviceSsjService deviceSsjService;
|
||||
|
||||
@Autowired
|
||||
private IMsgDdjService msgDdjService;
|
||||
|
||||
@Autowired
|
||||
private IMydoJobService mydoJobService;
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备统计数据
|
||||
*/
|
||||
@GetMapping("/deviceStats")
|
||||
public AjaxResult getDeviceStats()
|
||||
{
|
||||
public AjaxResult getDeviceStats() {
|
||||
try {
|
||||
DeviceCar deviceCar = new DeviceCar();
|
||||
MsgDdj msgDdj = new MsgDdj();
|
||||
DeviceSsj deviceSsj = new DeviceSsj();
|
||||
List<DeviceCar> deviceList = deviceCarService.selectDeviceCarList(deviceCar);
|
||||
List<MsgDdj> msgDdjList = msgDdjService.selectMsgDdjList(msgDdj);
|
||||
List<DeviceSsj> deviceSsjList = deviceSsjService.selectDeviceSsjList(deviceSsj);
|
||||
|
||||
Map<String, Object> stats = new HashMap<>();
|
||||
int agvCount = 0;
|
||||
int ctuCount = 0;
|
||||
int ssjCount = 0;
|
||||
Map<String, Object> count = new HashMap<>();
|
||||
|
||||
for (DeviceCar device : deviceList) {
|
||||
String type = device.getType();
|
||||
if ("1".equals(type)) {
|
||||
agvCount++;
|
||||
} else if ("2".equals(type)) {
|
||||
ctuCount++;
|
||||
} else if ("3".equals(type)) {
|
||||
ssjCount++;
|
||||
}
|
||||
}
|
||||
count.put("agvCount", deviceList.size());
|
||||
count.put("ddjCount", msgDdjList.size());
|
||||
count.put("ssjCount", deviceSsjList.size());
|
||||
|
||||
stats.put("agvCount", agvCount);
|
||||
stats.put("ctuCount", ctuCount);
|
||||
stats.put("ssjCount", ssjCount);
|
||||
stats.put("totalCount", deviceList.size());
|
||||
|
||||
return AjaxResult.success(stats);
|
||||
return AjaxResult.success(count);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("获取设备统计数据失败");
|
||||
}
|
||||
@@ -82,34 +81,39 @@ public class IndexController extends BaseController
|
||||
* 获取任务统计数据
|
||||
*/
|
||||
@GetMapping("/taskStats")
|
||||
public AjaxResult getTaskStats()
|
||||
{
|
||||
public AjaxResult getTaskStats() {
|
||||
try {
|
||||
MydoJob mydoJob = new MydoJob();
|
||||
AgvQueue agvQueue = new AgvQueue();
|
||||
List<AgvQueue> queueList = agvQueueService.selectAgvQueueList(agvQueue);
|
||||
List<MydoJob> mydoJobList = mydoJobService.selectMydoJobList(mydoJob);
|
||||
List<MydoJob> mydoJobFinishList = mydoJobService.selectMydoJobFinishList(mydoJob);
|
||||
|
||||
int pendingCount = 0;
|
||||
int runningCount = 0;
|
||||
int finishedCount = 0;
|
||||
|
||||
for (AgvQueue queue : queueList) {
|
||||
String status = queue.getStatus();
|
||||
if ("0".equals(status)||"1".equals(status)) {
|
||||
for (MydoJob job : mydoJobList) {
|
||||
String status = job.getStatus();
|
||||
if ("2".equals(status)) {
|
||||
pendingCount++;
|
||||
} else if ("2".equals(status)||"3".equals(status)) {
|
||||
} else if ("3".equals(status)) {
|
||||
runningCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取今日完成任务数
|
||||
AgvQueueFinish finishQuery = new AgvQueueFinish();
|
||||
List<AgvQueueFinish> finishList = agvQueueFinishService.selectAgvQueueFinishList(finishQuery);
|
||||
int finishedCount = finishList.size();
|
||||
for (MydoJob Fjob : mydoJobFinishList) {
|
||||
String status = Fjob.getStatus();
|
||||
if ("4".equals(status)) {
|
||||
finishedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Map<String, Object> stats = new HashMap<>();
|
||||
stats.put("pendingCount", pendingCount);
|
||||
stats.put("runningCount", runningCount);
|
||||
stats.put("finishedCount", finishedCount);
|
||||
stats.put("totalCount", pendingCount + runningCount + finishedCount);
|
||||
|
||||
return AjaxResult.success(stats);
|
||||
} catch (Exception e) {
|
||||
@@ -121,13 +125,12 @@ public class IndexController extends BaseController
|
||||
* 获取当前任务队列
|
||||
*/
|
||||
@GetMapping("/currentTasks")
|
||||
public AjaxResult getCurrentTasks()
|
||||
{
|
||||
public AjaxResult getCurrentTasks() {
|
||||
try {
|
||||
AgvQueue agvQueue = new AgvQueue();
|
||||
List<AgvQueue> taskList = agvQueueService.selectAgvQueueList(agvQueue);
|
||||
|
||||
return AjaxResult.success(taskList);
|
||||
MydoJob mydoJobParam = new MydoJob();
|
||||
mydoJobParam.setStatus("3");
|
||||
List<MydoJob> mydoJobList = mydoJobService.selectMydoJobList(mydoJobParam);
|
||||
return AjaxResult.success(mydoJobList);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("获取当前任务队列失败");
|
||||
}
|
||||
@@ -137,13 +140,12 @@ public class IndexController extends BaseController
|
||||
* 获取运行中的设备列表
|
||||
*/
|
||||
@GetMapping("/deviceList")
|
||||
public AjaxResult getDeviceList()
|
||||
{
|
||||
public AjaxResult getDeviceList() {
|
||||
try {
|
||||
List<Map<String, Object>> runningDevices = new ArrayList<>();
|
||||
|
||||
// 查询运行中的AGV和CTU设备
|
||||
DeviceCar deviceCar = new DeviceCar();
|
||||
/*DeviceCar deviceCar = new DeviceCar();
|
||||
List<DeviceCar> deviceList = deviceCarService.selectDeviceCarList(deviceCar);
|
||||
|
||||
for (DeviceCar device : deviceList) {
|
||||
@@ -153,11 +155,11 @@ public class IndexController extends BaseController
|
||||
Map<String, Object> deviceInfo = new HashMap<>();
|
||||
deviceInfo.put("deviceCode", device.getDeviceCode());
|
||||
deviceInfo.put("deviceName", device.getName());
|
||||
deviceInfo.put("deviceType", "1".equals(device.getType()) ? "AGV" : "CTU");
|
||||
deviceInfo.put("deviceType", "AGV");
|
||||
deviceInfo.put("taskNo", device.getTaskNo());
|
||||
runningDevices.add(deviceInfo);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// 查询运行中的SSJ设备
|
||||
DeviceSsj deviceSsj = new DeviceSsj();
|
||||
@@ -176,6 +178,21 @@ public class IndexController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
MsgDdj msgDdj = new MsgDdj();
|
||||
List<MsgDdj> msgDdjList = msgDdjService.selectMsgDdjList(msgDdj);
|
||||
|
||||
for (MsgDdj ddj : msgDdjList){
|
||||
Long taskNo = ddj.getRwh();
|
||||
if (taskNo != 0){
|
||||
HashMap<String, Object> deviceInfo = new HashMap<>();
|
||||
deviceInfo.put("deviceCode",ddj.getId());
|
||||
deviceInfo.put("deviceName", ddj.getName());
|
||||
deviceInfo.put("deviceType", "DDJ");
|
||||
deviceInfo.put("taskNo", ddj.getRwh());
|
||||
runningDevices.add(deviceInfo);
|
||||
}
|
||||
}
|
||||
|
||||
return AjaxResult.success(runningDevices);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("获取运行中设备列表失败");
|
||||
@@ -186,37 +203,28 @@ public class IndexController extends BaseController
|
||||
* 获取任务类型分布数据
|
||||
*/
|
||||
@GetMapping("/taskTypeChart")
|
||||
public AjaxResult getTaskTypeChart()
|
||||
{
|
||||
public AjaxResult getTaskTypeChart() {
|
||||
try {
|
||||
AgvQueue agvQueue = new AgvQueue();
|
||||
List<AgvQueue> queueList = agvQueueService.selectAgvQueueList(agvQueue);
|
||||
MydoJob mydoJob = new MydoJob();
|
||||
List<MydoJob> mydoJobFinishList = mydoJobService.selectMydoJobFinishList(mydoJob);
|
||||
|
||||
AgvQueueFinish finishQuery = new AgvQueueFinish();
|
||||
List<AgvQueueFinish> finishList = agvQueueFinishService.selectAgvQueueFinishList(finishQuery);
|
||||
Map<String, Integer> inOrOutCount = new HashMap<>();
|
||||
|
||||
Map<String, Integer> taskTypeCount = new HashMap<>();
|
||||
|
||||
// 统计队列中的任务类型
|
||||
for (AgvQueue queue : queueList) {
|
||||
String wmsTaskType = queue.getWmsTaskType();
|
||||
if (wmsTaskType != null && !wmsTaskType.isEmpty()) {
|
||||
taskTypeCount.put(wmsTaskType, taskTypeCount.getOrDefault(wmsTaskType, 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 统计完成任务的类型
|
||||
for (AgvQueueFinish finish : finishList) {
|
||||
String wmsTaskType = finish.getWmsTaskType();
|
||||
if (wmsTaskType != null && !wmsTaskType.isEmpty()) {
|
||||
taskTypeCount.put(wmsTaskType, taskTypeCount.getOrDefault(wmsTaskType, 0) + 1);
|
||||
// 统计完成任务的 inOrOut 类型
|
||||
for (MydoJob job : mydoJobFinishList) {
|
||||
String inOrOut = job.getInOrOut();
|
||||
if (inOrOut != null && !inOrOut.isEmpty()) {
|
||||
inOrOutCount.put(inOrOut, inOrOutCount.getOrDefault(inOrOut, 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, Object>> chartData = new ArrayList<>();
|
||||
for (Map.Entry<String, Integer> entry : taskTypeCount.entrySet()) {
|
||||
for (Map.Entry<String, Integer> entry : inOrOutCount.entrySet()) {
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("name", entry.getKey());
|
||||
// 使用字典工具类获取字典标签
|
||||
String dictLabel = com.ruoyi.common.utils.DictUtils.getDictLabel("in_or_out", entry.getKey());
|
||||
// 如果没有找到对应的字典标签,则使用原始值
|
||||
item.put("name", dictLabel != null && !dictLabel.isEmpty() ? dictLabel : entry.getKey());
|
||||
item.put("value", entry.getValue());
|
||||
chartData.add(item);
|
||||
}
|
||||
@@ -231,39 +239,27 @@ public class IndexController extends BaseController
|
||||
* 获取设备状态分布数据
|
||||
*/
|
||||
@GetMapping("/deviceStatusChart")
|
||||
public AjaxResult getDeviceStatusChart()
|
||||
{
|
||||
public AjaxResult getDeviceStatusChart() {
|
||||
try {
|
||||
Map<String, Map<String, Integer>> statusCount = new HashMap<>();
|
||||
statusCount.put("AGV", new HashMap<>());
|
||||
statusCount.put("CTU", new HashMap<>());
|
||||
// statusCount.put("AGV", new HashMap<>());
|
||||
statusCount.put("DDJ", new HashMap<>());
|
||||
statusCount.put("SSJ", new HashMap<>());
|
||||
|
||||
// 查询DeviceCar数据(AGV和CTU)
|
||||
// 查询DeviceCar数据(AGV)
|
||||
DeviceCar deviceCar = new DeviceCar();
|
||||
List<DeviceCar> deviceList = deviceCarService.selectDeviceCarList(deviceCar);
|
||||
|
||||
for (DeviceCar device : deviceList) {
|
||||
String type = device.getType();
|
||||
String taskNo = device.getTaskNo();
|
||||
String deviceType = "";
|
||||
String status = "其他";
|
||||
|
||||
if ("1".equals(type)) {
|
||||
deviceType = "AGV";
|
||||
} else if ("2".equals(type)) {
|
||||
deviceType = "CTU";
|
||||
}
|
||||
|
||||
// 根据taskNo判断状态:不等于空或0时为运行状态
|
||||
if (taskNo != null && !taskNo.trim().isEmpty() && !"0".equals(taskNo.trim())) {
|
||||
status = "运行";
|
||||
}
|
||||
Map<String, Integer> typeStatusCount = statusCount.get("AGV");
|
||||
typeStatusCount.put(status, typeStatusCount.getOrDefault(status, 0) + 1);
|
||||
|
||||
if (!deviceType.isEmpty()) {
|
||||
Map<String, Integer> typeStatusCount = statusCount.get(deviceType);
|
||||
typeStatusCount.put(status, typeStatusCount.getOrDefault(status, 0) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// 查询DeviceSsj数据(SSJ)
|
||||
@@ -283,6 +279,19 @@ public class IndexController extends BaseController
|
||||
typeStatusCount.put(status, typeStatusCount.getOrDefault(status, 0) + 1);
|
||||
}
|
||||
|
||||
MsgDdj msgDdj = new MsgDdj();
|
||||
List<MsgDdj> msgDdjList = msgDdjService.selectMsgDdjList(msgDdj);
|
||||
|
||||
for (MsgDdj ddj : msgDdjList){
|
||||
Long taskNo = ddj.getRwh();
|
||||
String status = "其他";
|
||||
if (taskNo!=0){
|
||||
status = "运行";
|
||||
}
|
||||
Map<String,Integer> typeStatusCount = statusCount.get("DDJ");
|
||||
typeStatusCount.put(status,typeStatusCount.getOrDefault(status,0) + 1);
|
||||
}
|
||||
|
||||
return AjaxResult.success(statusCount);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("获取设备状态分布数据失败");
|
||||
@@ -293,8 +302,7 @@ public class IndexController extends BaseController
|
||||
* 获取首页综合数据
|
||||
*/
|
||||
@GetMapping("/dashboard")
|
||||
public AjaxResult getDashboardData()
|
||||
{
|
||||
public AjaxResult getDashboardData() {
|
||||
try {
|
||||
Map<String, Object> dashboardData = new HashMap<>();
|
||||
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
package com.ruoyi.schedule;
|
||||
|
||||
import com.ruoyi.common.domain.CustomThread;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.device.ssj.service.IDeviceSsjService;
|
||||
import com.ruoyi.common.domain.PlcConnectInfo;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.common.domain.CustomThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ddj.Ddj1Thread;
|
||||
import com.ruoyi.schedule.scheduleTask.ddj.*;
|
||||
import com.ruoyi.schedule.scheduleTask.monit.MonitoringThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ssj.floor1.Floor1BothWayInSsjThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ssj.floor1.Floor1BothWayOutSsjThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ssj.floor1.Floor1SingleSsjThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ssj.floor2.Floor2InOutSsjThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ssj.floor2.Floor2RoadWaySsjThread;
|
||||
import com.ruoyi.schedule.scheduleTask.ssj.floor2.LineSsjThread;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -30,16 +24,20 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class ScheduleThread {
|
||||
|
||||
public CustomThread<PlcSsjRead> plcSsjReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdjReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj1ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj2ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj3ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj4ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj5ReadCustomThread;
|
||||
public CustomThread<PlcDdjRead> plcDdj6ReadCustomThread;
|
||||
|
||||
public CustomThread<Floor1BothWayInSsjThread> floor1BothWayInSsjCustomThread;
|
||||
public CustomThread<Floor1BothWayOutSsjThread> floor1BothWayOutSsjCustomThread;
|
||||
public CustomThread<Floor1SingleSsjThread> floor1SingleSsjCustomThread;
|
||||
public CustomThread<Floor2InOutSsjThread> floor2InSsjCustomThread;
|
||||
public CustomThread<Floor2RoadWaySsjThread> floor2OutSsjCustomThread;
|
||||
public CustomThread<LineSsjThread> lineSsjCustomThread;
|
||||
public CustomThread<MonitoringThread> monitoringCustomThread;
|
||||
public CustomThread<Ddj1Thread> ddj1CustomThread;
|
||||
public CustomThread<Ddj2Thread> ddj2CustomThread;
|
||||
public CustomThread<Ddj3Thread> ddj3CustomThread;
|
||||
public CustomThread<Ddj4Thread> ddj4CustomThread;
|
||||
public CustomThread<Ddj5Thread> ddj5CustomThread;
|
||||
public CustomThread<Ddj6Thread> ddj6CustomThread;
|
||||
@Autowired
|
||||
private IDeviceSsjService deviceSsjService;
|
||||
@Autowired
|
||||
@@ -67,27 +65,18 @@ public class ScheduleThread {
|
||||
private void scheduleInit() {
|
||||
MonitoringThread monitoringThread = new MonitoringThread();
|
||||
monitoringCustomThread = new CustomThread<MonitoringThread>(new Thread(monitoringThread), monitoringThread);
|
||||
|
||||
Floor1BothWayInSsjThread floor1BothWayInSsjThread = new Floor1BothWayInSsjThread();
|
||||
floor1BothWayInSsjCustomThread = new CustomThread<Floor1BothWayInSsjThread>(new Thread(floor1BothWayInSsjThread), floor1BothWayInSsjThread);
|
||||
|
||||
Floor1BothWayOutSsjThread floor1BothWayOutSsjThread = new Floor1BothWayOutSsjThread();
|
||||
floor1BothWayOutSsjCustomThread = new CustomThread<Floor1BothWayOutSsjThread>(new Thread(floor1BothWayOutSsjThread), floor1BothWayOutSsjThread);
|
||||
|
||||
Floor1SingleSsjThread floor1SingleSsjThread = new Floor1SingleSsjThread();
|
||||
floor1SingleSsjCustomThread = new CustomThread<Floor1SingleSsjThread>(new Thread(floor1SingleSsjThread), floor1SingleSsjThread);
|
||||
|
||||
Floor2InOutSsjThread floor2InSsjThread = new Floor2InOutSsjThread();
|
||||
floor2InSsjCustomThread = new CustomThread<Floor2InOutSsjThread>(new Thread(floor2InSsjThread), floor2InSsjThread);
|
||||
|
||||
LineSsjThread lineSsjThread = new LineSsjThread();
|
||||
lineSsjCustomThread = new CustomThread<LineSsjThread>(new Thread(lineSsjThread), lineSsjThread);
|
||||
|
||||
Floor2RoadWaySsjThread floor2OutSsjThread = new Floor2RoadWaySsjThread();
|
||||
floor2OutSsjCustomThread = new CustomThread<Floor2RoadWaySsjThread>(new Thread(floor2OutSsjThread), floor2OutSsjThread);
|
||||
|
||||
Ddj1Thread ddj1Thread = new Ddj1Thread();
|
||||
ddj1CustomThread = new CustomThread<Ddj1Thread>(new Thread(ddj1Thread), ddj1Thread);
|
||||
ddj1CustomThread = new CustomThread<>(new Thread(ddj1Thread), ddj1Thread);
|
||||
Ddj2Thread ddj2Thread = new Ddj2Thread();
|
||||
ddj2CustomThread = new CustomThread<>(new Thread(ddj2Thread), ddj2Thread);
|
||||
Ddj3Thread ddj3Thread = new Ddj3Thread();
|
||||
ddj3CustomThread = new CustomThread<>(new Thread(ddj3Thread), ddj3Thread);
|
||||
Ddj4Thread ddj4Thread = new Ddj4Thread();
|
||||
ddj4CustomThread = new CustomThread<>(new Thread(ddj4Thread), ddj4Thread);
|
||||
Ddj5Thread ddj5Thread = new Ddj5Thread();
|
||||
ddj5CustomThread = new CustomThread<>(new Thread(ddj5Thread), ddj5Thread);
|
||||
Ddj6Thread ddj6Thread = new Ddj6Thread();
|
||||
ddj6CustomThread = new CustomThread<>(new Thread(ddj6Thread), ddj6Thread);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,17 +103,43 @@ public class ScheduleThread {
|
||||
switch (msgDdj.getId()){
|
||||
case 1:
|
||||
msgDdj.setPlcDbReadAddress("DB41.0");
|
||||
PlcDdjRead plcDdjRead1 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread1 = new Thread(plcDdjRead1);
|
||||
plcDdj1ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread1, plcDdjRead1);
|
||||
break;
|
||||
case 2:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead2 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread2 = new Thread(plcDdjRead2);
|
||||
plcDdj2ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread2, plcDdjRead2);
|
||||
break;
|
||||
case 3:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead3 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread3 = new Thread(plcDdjRead3);
|
||||
plcDdj3ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread3, plcDdjRead3);
|
||||
break;
|
||||
case 4:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead4 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread4 = new Thread(plcDdjRead4);
|
||||
plcDdj4ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread4, plcDdjRead4);
|
||||
break;
|
||||
case 5:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead5 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread5 = new Thread(plcDdjRead5);
|
||||
plcDdj5ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread5, plcDdjRead5);
|
||||
break;
|
||||
case 6:
|
||||
msgDdj.setPlcDbReadAddress("DB42.0");
|
||||
PlcDdjRead plcDdjRead6 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread6 = new Thread(plcDdjRead6);
|
||||
plcDdj6ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread6, plcDdjRead6);
|
||||
break;
|
||||
}
|
||||
ddjList.put("ddj" + msgDdj.getId(), msgDdj);
|
||||
}
|
||||
PlcDdjRead plcDdjRead = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
|
||||
Thread plcDdjReadThread = new Thread(plcDdjRead);
|
||||
plcDdjReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread, plcDdjRead);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +147,12 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void startAllThread() {
|
||||
plcSsjReadCustomThread.getThread().start();
|
||||
plcDdjReadCustomThread.getThread().start();
|
||||
plcDdj1ReadCustomThread.getThread().start();
|
||||
plcDdj2ReadCustomThread.getThread().start();
|
||||
plcDdj3ReadCustomThread.getThread().start();
|
||||
plcDdj4ReadCustomThread.getThread().start();
|
||||
plcDdj5ReadCustomThread.getThread().start();
|
||||
plcDdj6ReadCustomThread.getThread().start();
|
||||
isRun = true;
|
||||
}
|
||||
|
||||
@@ -141,13 +161,12 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void startAllThread2() {
|
||||
monitoringCustomThread.thread.start();
|
||||
floor1BothWayInSsjCustomThread.thread.start();
|
||||
floor1BothWayOutSsjCustomThread.thread.start();
|
||||
floor1SingleSsjCustomThread.thread.start();
|
||||
floor2InSsjCustomThread.thread.start();
|
||||
lineSsjCustomThread.thread.start();
|
||||
floor2OutSsjCustomThread.thread.start();
|
||||
ddj1CustomThread.thread.start();
|
||||
ddj2CustomThread.thread.start();
|
||||
ddj3CustomThread.thread.start();
|
||||
ddj4CustomThread.thread.start();
|
||||
ddj5CustomThread.thread.start();
|
||||
ddj6CustomThread.thread.start();
|
||||
isRun2 = true;
|
||||
}
|
||||
|
||||
@@ -156,7 +175,12 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void stopAllThread() {
|
||||
plcSsjReadCustomThread.runnable.isRun = false;
|
||||
plcDdjReadCustomThread.runnable.isRun = false;
|
||||
plcDdj1ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj2ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj3ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj4ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj5ReadCustomThread.runnable.isRun = false;
|
||||
plcDdj6ReadCustomThread.runnable.isRun = false;
|
||||
plcReadInit();
|
||||
isRun = false;
|
||||
}
|
||||
@@ -166,13 +190,12 @@ public class ScheduleThread {
|
||||
*/
|
||||
public void stopAllThread2() {
|
||||
monitoringCustomThread.runnable.isRun = false;
|
||||
floor1BothWayInSsjCustomThread.runnable.isRun = false;
|
||||
floor1BothWayOutSsjCustomThread.runnable.isRun = false;
|
||||
floor1SingleSsjCustomThread.runnable.isRun = false;
|
||||
floor2InSsjCustomThread.runnable.isRun = false;
|
||||
lineSsjCustomThread.runnable.isRun = false;
|
||||
floor2OutSsjCustomThread.runnable.isRun = false;
|
||||
ddj1CustomThread.runnable.isRun = false;
|
||||
ddj2CustomThread.runnable.isRun = false;
|
||||
ddj3CustomThread.runnable.isRun = false;
|
||||
ddj4CustomThread.runnable.isRun = false;
|
||||
ddj5CustomThread.runnable.isRun = false;
|
||||
ddj6CustomThread.runnable.isRun = false;
|
||||
scheduleInit();
|
||||
isRun2 = false;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.Constant.WAREHOUSE_01;
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
|
||||
|
||||
@@ -51,33 +52,29 @@ public class Ddj1Thread implements Runnable {
|
||||
ddjCodes.add(PlcDdjRead.deviceDdjMap.get("ddj1"));
|
||||
ddjCodeList.put("ddj", ddjCodes);
|
||||
ArrayList<DeviceSsj> roadSsjList = new ArrayList<>();
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1001"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1002"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2001"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2002"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2007"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2008"));
|
||||
ssjList.put("roadSsjList", roadSsjList);
|
||||
ArrayList<DeviceSsj> outSsj1 = new ArrayList<>();
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L2001"));
|
||||
ssjList.put("outSsj1", outSsj1);
|
||||
ArrayList<DeviceSsj> outSsj2 = new ArrayList<>();
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L2002"));
|
||||
ssjList.put("outSsj2", outSsj2);
|
||||
ArrayList<DeviceSsj> outSsj3 = new ArrayList<>();
|
||||
outSsj3.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
outSsj3.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
outSsj3.add(PlcSsjRead.deviceSsjMap.get("L2007"));
|
||||
ssjList.put("outSsj3", outSsj3);
|
||||
ArrayList<DeviceSsj> outSsj4 = new ArrayList<>();
|
||||
outSsj4.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
outSsj4.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
outSsj4.add(PlcSsjRead.deviceSsjMap.get("L2008"));
|
||||
ssjList.put("outSsj4", outSsj4);
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L1001", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L1002", Arrays.asList(2, 1, 1));
|
||||
roadwayMap.put("L1003", Arrays.asList(1, 58, 1));
|
||||
roadwayMap.put("L1004", Arrays.asList(2, 58, 1));
|
||||
roadwayMap.put("L2001", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L2002", Arrays.asList(2, 1, 1));
|
||||
roadwayMap.put("L2007", Arrays.asList(1, 22, 1));
|
||||
roadwayMap.put("L2008", Arrays.asList(2, 22, 1));
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
@@ -126,7 +123,7 @@ public class Ddj1Thread implements Runnable {
|
||||
private void generateOutBoundQueue(MsgDdj ddj) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setInOut("2");
|
||||
param.setWarehouseId("01");
|
||||
param.setWarehouseId(WAREHOUSE_01);
|
||||
param.setRoadwayId(Convert.toStr(ddj.getId()));
|
||||
List<MydoJob> outJobList = mydoJobService.selectMydoJobList(param);
|
||||
if (CollUtil.isNotEmpty(outJobList)) {
|
||||
@@ -197,6 +194,8 @@ public class Ddj1Thread implements Runnable {
|
||||
//请求wms获取任务 并生成队列
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ddj.getTrayCode());
|
||||
paramMap.put("warehouseId",WAREHOUSE_01);
|
||||
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
|
||||
@@ -0,0 +1,462 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ddj;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.domain.wcs2wms.JobParam;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueFinishService;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.Constant.WAREHOUSE_01;
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class Ddj2Thread implements Runnable {
|
||||
|
||||
public HashMap<String, List<MsgDdj>> ddjCodeList;
|
||||
public HashMap<String, List<DeviceSsj>> ssjList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private IDdjDeviceExecutionQueueFinishService ddjDeviceExecutionQueueFinishService;
|
||||
private IMsgDdjService msgDdjService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
//todo 获取设备编码列表
|
||||
ddjCodeList = new HashMap<>();
|
||||
ArrayList<MsgDdj> ddjCodes = new ArrayList<>();
|
||||
ddjCodes.add(PlcDdjRead.deviceDdjMap.get("ddj2"));
|
||||
ddjCodeList.put("ddj", ddjCodes);
|
||||
ArrayList<DeviceSsj> roadSsjList = new ArrayList<>();
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2003"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2004"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2009"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2010"));
|
||||
ssjList.put("roadSsjList", roadSsjList);
|
||||
ArrayList<DeviceSsj> outSsj1 = new ArrayList<>();
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L2003"));
|
||||
ssjList.put("outSsj1", outSsj1);
|
||||
ArrayList<DeviceSsj> outSsj2 = new ArrayList<>();
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L2004"));
|
||||
ssjList.put("outSsj2", outSsj2);
|
||||
ArrayList<DeviceSsj> outSsj3 = new ArrayList<>();
|
||||
outSsj3.add(PlcSsjRead.deviceSsjMap.get("L2009"));
|
||||
ssjList.put("outSsj3", outSsj3);
|
||||
ArrayList<DeviceSsj> outSsj4 = new ArrayList<>();
|
||||
outSsj4.add(PlcSsjRead.deviceSsjMap.get("L2010"));
|
||||
ssjList.put("outSsj4", outSsj4);
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L2001", Arrays.asList(3, 1, 1));
|
||||
roadwayMap.put("L2002", Arrays.asList(4, 1, 1));
|
||||
roadwayMap.put("L2007", Arrays.asList(3, 22, 1));
|
||||
roadwayMap.put("L2008", Arrays.asList(4, 22, 1));
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
ddjDeviceExecutionQueueFinishService = SpringUtils.getBean(IDdjDeviceExecutionQueueFinishService.class);
|
||||
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService, mydoJobService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ddjCodeList.keySet()) {
|
||||
|
||||
for (MsgDdj msgDdj : ddjCodeList.get(type)) {
|
||||
try {
|
||||
if (ObjUtil.isNotNull(msgDdj)) {
|
||||
if (0 == msgDdj.getSpare1()) {
|
||||
generateInBoundPickQueue(msgDdj);
|
||||
generateInBoundLoadQueue(msgDdj);
|
||||
generateOutBoundQueue(msgDdj);
|
||||
ddjTask(msgDdj);
|
||||
}
|
||||
} else {
|
||||
log.error("堆垛机设备为空");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出库队列
|
||||
*/
|
||||
private void generateOutBoundQueue(MsgDdj ddj) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setInOut("2");
|
||||
param.setWarehouseId(WAREHOUSE_01);
|
||||
param.setRoadwayId(Convert.toStr(ddj.getId()));
|
||||
List<MydoJob> outJobList = mydoJobService.selectMydoJobList(param);
|
||||
if (CollUtil.isNotEmpty(outJobList)) {
|
||||
for (MydoJob outJob : outJobList) {
|
||||
String exitId = outJob.getExitId();
|
||||
|
||||
String outSsj = "";
|
||||
switch (exitId) {
|
||||
case "1":
|
||||
List<DeviceSsj> outSsj1 = ssjList.get("outSsj1");
|
||||
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj1.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj2 = ssjList.get("outSsj2");
|
||||
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj2.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
List<DeviceSsj> outSsj3 = ssjList.get("outSsj3");
|
||||
if (outSsj3.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj3.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj4 = ssjList.get("outSsj4");
|
||||
if (outSsj4.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj4.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log.error("出库任务出口错误");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("0".equals(outJob.getExecutionPhase()) && StrUtil.isNotEmpty(outSsj)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(outJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
outJob.setStatus("3");
|
||||
outJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
outJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(outJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", outJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库放货队列
|
||||
*/
|
||||
private void generateInBoundLoadQueue(MsgDdj ddj) {
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 3) {
|
||||
//允许下发 联机 有货待机
|
||||
if (StrUtil.isNotEmpty(ddj.getTrayCode())) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setTrayCode(ddj.getTrayCode());
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectMydoJobList(param);
|
||||
MydoJob inJob = null;
|
||||
if (CollUtil.isEmpty(mydoJobs)) {
|
||||
//请求wms获取任务 并生成队列
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ddj.getTrayCode());
|
||||
paramMap.put("warehouseId",WAREHOUSE_01);
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
inJob.setStatus(TASK_STATUS_CREATE);
|
||||
inJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.insertMydoJob(inJob);
|
||||
} else {
|
||||
log.error(result.get("msg").toString());
|
||||
}
|
||||
} else {
|
||||
inJob = mydoJobs.get(0);
|
||||
}
|
||||
|
||||
if (ObjUtil.isNotNull(inJob) && inJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(inJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
inJob.setStatus("3");
|
||||
inJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
inJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(inJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", inJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Integer mbph = ddj.getMbph();
|
||||
Integer mblh = ddj.getMblh();
|
||||
Integer mbch = ddj.getMbch();
|
||||
long rwh = ddj.getRwh() + 100;
|
||||
log.error("扫码失败,放回原位 排:{} 列:{} 层:{} 任务号:{}", mbph, mblh, mbch, rwh);
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库取货队列
|
||||
*/
|
||||
private void generateInBoundPickQueue(MsgDdj ddj) {
|
||||
List<DeviceSsj> roadSsjList = ssjList.get("roadSsjList");
|
||||
for (DeviceSsj ssj : roadSsjList) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(ssj.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", ssj.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ddjTask(MsgDdj ddj) {
|
||||
/*
|
||||
第一部分
|
||||
堆垛机线程进来后第一件事先进行堆垛机正执行任务的账务处理
|
||||
以防存在漏处理,没处理的情况发生
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 0 && ddj.getJdbz() == 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//完成作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (mydoJob != null && ddjDeviceExecutionQueue != null) {
|
||||
//回传完成信号
|
||||
ddjTaskFinish(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第二部分
|
||||
跟踪队列执行阶段
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1 && (ddj.getJdbz() == 2 || ddj.getJdbz() == 3 || ddj.getJdbz() == 4)) {
|
||||
//根据堆垛机上任务号,修改任务执行阶段
|
||||
Long rwh = ddj.getRwh();
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ddjDeviceExecutionQueue != null) {
|
||||
//修改队列执行阶段
|
||||
ddjDeviceExecutionQueue.setRwzt(ddj.getJdbz());
|
||||
ddjDeviceExecutionQueue.setSpare1("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第三部分
|
||||
放货有货,重新分配货位
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1052 && ddj.getJdbz() < 5 && ddj.getYxxf() == 1) {
|
||||
//判断堆垛机上任务是否已重分,若未重分,则调用接口,请求重分货位
|
||||
Long rwh = ddj.getRwh();
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if ("0".equals(mydoJob.getFaultFlag()) && "1".equals(ddjDeviceExecutionQueue.getSpare1())) {
|
||||
mydoJob.setStatus("1");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
AjaxResult ajaxResult = apiService.reAssign(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
mydoJob.setFaultFlag("2");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
ddjDeviceExecutionQueue.setSpare1("0");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第四部分
|
||||
取货无货,重新分配单据
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1053 && ddj.getJdbz() < 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//无货异常处理
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
//找到对应任务 调用api接口 取货无货,重新分配单据
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
//作废作业
|
||||
InvalidMydoJob(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第五部分
|
||||
堆垛机任务下发
|
||||
*/
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5 && ddj.getSbzt() == 1052) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//查询作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
if (ObjUtil.isNotNull(mydoJob) && "2".equals(mydoJob.getFaultFlag())) {
|
||||
//判断任务是否重分完成
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
//重新下发堆垛机任务
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
mydoJob.setFaultFlag("0");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("托盘堆垛机重新下发任务成功 rwh:{}", rwh);
|
||||
} else {
|
||||
log.error("托盘堆垛机重新下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//正常下发
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5) {
|
||||
if (ddj.getSbzt() == 0) {
|
||||
//无货待机 只查询入库取货扫码或者出库队列
|
||||
ArrayList<Integer> rwlxList = new ArrayList<>();
|
||||
rwlxList.add(1);
|
||||
rwlxList.add(3);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlxList(rwlxList);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
} else if (ddj.getSbzt() == 3) {
|
||||
//有货待机 只查询入库放货队列
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlx(2);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废作业
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void InvalidMydoJob(Long rwh, Integer id) {
|
||||
mydoJobService.InvalidMydoJob(rwh, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 堆垛机任务完成
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void ddjTaskFinish(Long rwh, Integer id) {
|
||||
mydoJobService.ddjTaskFinish(rwh, id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给堆垛机下发任务
|
||||
*
|
||||
* @param queue 堆垛机执行的队列
|
||||
*/
|
||||
private int issuedDDJTask(Integer devId, DdjDeviceExecutionQueue queue) {
|
||||
int taskNo = Convert.toInt(queue.getRwh());
|
||||
int yph = Convert.toInt(queue.getYph());
|
||||
int ylh = Convert.toInt(queue.getYlh());
|
||||
int ych = Convert.toInt(queue.getYch());
|
||||
int mbph = Convert.toInt(queue.getMbph());
|
||||
int mblh = Convert.toInt(queue.getMblh());
|
||||
int mbch = Convert.toInt(queue.getMbch());
|
||||
int mlfs;
|
||||
if (queue.getRwlx() == 1 || queue.getRwlx() == 3) {
|
||||
mlfs = 5;
|
||||
} else if (queue.getRwlx() == 2) {
|
||||
mlfs = 4;
|
||||
} else {
|
||||
throw new RuntimeException("任务类型错误");
|
||||
}
|
||||
int xfwc = 1;
|
||||
int jym = Tools.getJYM(taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc);
|
||||
byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc, jym);
|
||||
if (devId == 1) {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
} else {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ddj;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.domain.wcs2wms.JobParam;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueFinishService;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.Constant.WAREHOUSE_01;
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class Ddj3Thread implements Runnable {
|
||||
|
||||
public HashMap<String, List<MsgDdj>> ddjCodeList;
|
||||
public HashMap<String, List<DeviceSsj>> ssjList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private IDdjDeviceExecutionQueueFinishService ddjDeviceExecutionQueueFinishService;
|
||||
private IMsgDdjService msgDdjService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
//todo 获取设备编码列表
|
||||
ddjCodeList = new HashMap<>();
|
||||
ArrayList<MsgDdj> ddjCodes = new ArrayList<>();
|
||||
ddjCodes.add(PlcDdjRead.deviceDdjMap.get("ddj3"));
|
||||
ddjCodeList.put("ddj", ddjCodes);
|
||||
ArrayList<DeviceSsj> roadSsjList = new ArrayList<>();
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2005"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2006"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2011"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L2012"));
|
||||
ssjList.put("roadSsjList", roadSsjList);
|
||||
ArrayList<DeviceSsj> outSsj1 = new ArrayList<>();
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L2005"));
|
||||
ssjList.put("outSsj1", outSsj1);
|
||||
ArrayList<DeviceSsj> outSsj2 = new ArrayList<>();
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L2006"));
|
||||
ssjList.put("outSsj2", outSsj2);
|
||||
ArrayList<DeviceSsj> outSsj3 = new ArrayList<>();
|
||||
outSsj3.add(PlcSsjRead.deviceSsjMap.get("L2011"));
|
||||
ssjList.put("outSsj3", outSsj3);
|
||||
ArrayList<DeviceSsj> outSsj4 = new ArrayList<>();
|
||||
outSsj4.add(PlcSsjRead.deviceSsjMap.get("L2012"));
|
||||
ssjList.put("outSsj4", outSsj4);
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L2005", Arrays.asList(5, 1, 1));
|
||||
roadwayMap.put("L2006", Arrays.asList(6, 1, 1));
|
||||
roadwayMap.put("L2011", Arrays.asList(5, 22, 1));
|
||||
roadwayMap.put("L2012", Arrays.asList(6, 22, 1));
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
ddjDeviceExecutionQueueFinishService = SpringUtils.getBean(IDdjDeviceExecutionQueueFinishService.class);
|
||||
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService, mydoJobService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ddjCodeList.keySet()) {
|
||||
|
||||
for (MsgDdj msgDdj : ddjCodeList.get(type)) {
|
||||
try {
|
||||
if (ObjUtil.isNotNull(msgDdj)) {
|
||||
if (0 == msgDdj.getSpare1()) {
|
||||
generateInBoundPickQueue(msgDdj);
|
||||
generateInBoundLoadQueue(msgDdj);
|
||||
generateOutBoundQueue(msgDdj);
|
||||
ddjTask(msgDdj);
|
||||
}
|
||||
} else {
|
||||
log.error("堆垛机设备为空");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出库队列
|
||||
*/
|
||||
private void generateOutBoundQueue(MsgDdj ddj) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setInOut("2");
|
||||
param.setWarehouseId(WAREHOUSE_01);
|
||||
param.setRoadwayId(Convert.toStr(ddj.getId()));
|
||||
List<MydoJob> outJobList = mydoJobService.selectMydoJobList(param);
|
||||
if (CollUtil.isNotEmpty(outJobList)) {
|
||||
for (MydoJob outJob : outJobList) {
|
||||
String exitId = outJob.getExitId();
|
||||
|
||||
String outSsj = "";
|
||||
switch (exitId) {
|
||||
case "1":
|
||||
List<DeviceSsj> outSsj1 = ssjList.get("outSsj1");
|
||||
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj1.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj2 = ssjList.get("outSsj2");
|
||||
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj2.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
List<DeviceSsj> outSsj3 = ssjList.get("outSsj3");
|
||||
if (outSsj3.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj3.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj4 = ssjList.get("outSsj4");
|
||||
if (outSsj4.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj4.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log.error("出库任务出口错误");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("0".equals(outJob.getExecutionPhase()) && StrUtil.isNotEmpty(outSsj)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(outJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
outJob.setStatus("3");
|
||||
outJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
outJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(outJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", outJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库放货队列
|
||||
*/
|
||||
private void generateInBoundLoadQueue(MsgDdj ddj) {
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 3) {
|
||||
//允许下发 联机 有货待机
|
||||
if (StrUtil.isNotEmpty(ddj.getTrayCode())) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setTrayCode(ddj.getTrayCode());
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectMydoJobList(param);
|
||||
MydoJob inJob = null;
|
||||
if (CollUtil.isEmpty(mydoJobs)) {
|
||||
//请求wms获取任务 并生成队列
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ddj.getTrayCode());
|
||||
paramMap.put("warehouseId",WAREHOUSE_01);
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
inJob.setStatus(TASK_STATUS_CREATE);
|
||||
inJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.insertMydoJob(inJob);
|
||||
} else {
|
||||
log.error(result.get("msg").toString());
|
||||
}
|
||||
} else {
|
||||
inJob = mydoJobs.get(0);
|
||||
}
|
||||
|
||||
if (ObjUtil.isNotNull(inJob) && inJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(inJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
inJob.setStatus("3");
|
||||
inJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
inJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(inJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", inJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Integer mbph = ddj.getMbph();
|
||||
Integer mblh = ddj.getMblh();
|
||||
Integer mbch = ddj.getMbch();
|
||||
long rwh = ddj.getRwh() + 100;
|
||||
log.error("扫码失败,放回原位 排:{} 列:{} 层:{} 任务号:{}", mbph, mblh, mbch, rwh);
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库取货队列
|
||||
*/
|
||||
private void generateInBoundPickQueue(MsgDdj ddj) {
|
||||
List<DeviceSsj> roadSsjList = ssjList.get("roadSsjList");
|
||||
for (DeviceSsj ssj : roadSsjList) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(ssj.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", ssj.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ddjTask(MsgDdj ddj) {
|
||||
/*
|
||||
第一部分
|
||||
堆垛机线程进来后第一件事先进行堆垛机正执行任务的账务处理
|
||||
以防存在漏处理,没处理的情况发生
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 0 && ddj.getJdbz() == 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//完成作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (mydoJob != null && ddjDeviceExecutionQueue != null) {
|
||||
//回传完成信号
|
||||
ddjTaskFinish(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第二部分
|
||||
跟踪队列执行阶段
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1 && (ddj.getJdbz() == 2 || ddj.getJdbz() == 3 || ddj.getJdbz() == 4)) {
|
||||
//根据堆垛机上任务号,修改任务执行阶段
|
||||
Long rwh = ddj.getRwh();
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ddjDeviceExecutionQueue != null) {
|
||||
//修改队列执行阶段
|
||||
ddjDeviceExecutionQueue.setRwzt(ddj.getJdbz());
|
||||
ddjDeviceExecutionQueue.setSpare1("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第三部分
|
||||
放货有货,重新分配货位
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1052 && ddj.getJdbz() < 5 && ddj.getYxxf() == 1) {
|
||||
//判断堆垛机上任务是否已重分,若未重分,则调用接口,请求重分货位
|
||||
Long rwh = ddj.getRwh();
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if ("0".equals(mydoJob.getFaultFlag()) && "1".equals(ddjDeviceExecutionQueue.getSpare1())) {
|
||||
mydoJob.setStatus("1");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
AjaxResult ajaxResult = apiService.reAssign(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
mydoJob.setFaultFlag("2");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
ddjDeviceExecutionQueue.setSpare1("0");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第四部分
|
||||
取货无货,重新分配单据
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1053 && ddj.getJdbz() < 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//无货异常处理
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
//找到对应任务 调用api接口 取货无货,重新分配单据
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
//作废作业
|
||||
InvalidMydoJob(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第五部分
|
||||
堆垛机任务下发
|
||||
*/
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5 && ddj.getSbzt() == 1052) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//查询作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
if (ObjUtil.isNotNull(mydoJob) && "2".equals(mydoJob.getFaultFlag())) {
|
||||
//判断任务是否重分完成
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
//重新下发堆垛机任务
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
mydoJob.setFaultFlag("0");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("托盘堆垛机重新下发任务成功 rwh:{}", rwh);
|
||||
} else {
|
||||
log.error("托盘堆垛机重新下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//正常下发
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5) {
|
||||
if (ddj.getSbzt() == 0) {
|
||||
//无货待机 只查询入库取货扫码或者出库队列
|
||||
ArrayList<Integer> rwlxList = new ArrayList<>();
|
||||
rwlxList.add(1);
|
||||
rwlxList.add(3);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlxList(rwlxList);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
} else if (ddj.getSbzt() == 3) {
|
||||
//有货待机 只查询入库放货队列
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlx(2);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废作业
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void InvalidMydoJob(Long rwh, Integer id) {
|
||||
mydoJobService.InvalidMydoJob(rwh, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 堆垛机任务完成
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void ddjTaskFinish(Long rwh, Integer id) {
|
||||
mydoJobService.ddjTaskFinish(rwh, id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给堆垛机下发任务
|
||||
*
|
||||
* @param queue 堆垛机执行的队列
|
||||
*/
|
||||
private int issuedDDJTask(Integer devId, DdjDeviceExecutionQueue queue) {
|
||||
int taskNo = Convert.toInt(queue.getRwh());
|
||||
int yph = Convert.toInt(queue.getYph());
|
||||
int ylh = Convert.toInt(queue.getYlh());
|
||||
int ych = Convert.toInt(queue.getYch());
|
||||
int mbph = Convert.toInt(queue.getMbph());
|
||||
int mblh = Convert.toInt(queue.getMblh());
|
||||
int mbch = Convert.toInt(queue.getMbch());
|
||||
int mlfs;
|
||||
if (queue.getRwlx() == 1 || queue.getRwlx() == 3) {
|
||||
mlfs = 5;
|
||||
} else if (queue.getRwlx() == 2) {
|
||||
mlfs = 4;
|
||||
} else {
|
||||
throw new RuntimeException("任务类型错误");
|
||||
}
|
||||
int xfwc = 1;
|
||||
int jym = Tools.getJYM(taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc);
|
||||
byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc, jym);
|
||||
if (devId == 1) {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
} else {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,441 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ddj;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.domain.wcs2wms.JobParam;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueFinishService;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.Constant.WAREHOUSE_02;
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class Ddj4Thread implements Runnable {
|
||||
|
||||
public HashMap<String, List<MsgDdj>> ddjCodeList;
|
||||
public HashMap<String, List<DeviceSsj>> ssjList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private IDdjDeviceExecutionQueueFinishService ddjDeviceExecutionQueueFinishService;
|
||||
private IMsgDdjService msgDdjService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
//todo 获取设备编码列表
|
||||
ddjCodeList = new HashMap<>();
|
||||
ArrayList<MsgDdj> ddjCodes = new ArrayList<>();
|
||||
ddjCodes.add(PlcDdjRead.deviceDdjMap.get("ddj4"));
|
||||
ddjCodeList.put("ddj", ddjCodes);
|
||||
ArrayList<DeviceSsj> roadSsjList = new ArrayList<>();
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1001"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1002"));
|
||||
ssjList.put("roadSsjList", roadSsjList);
|
||||
ArrayList<DeviceSsj> outSsj1 = new ArrayList<>();
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L1001"));
|
||||
ssjList.put("outSsj1", outSsj1);
|
||||
ArrayList<DeviceSsj> outSsj2 = new ArrayList<>();
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L1002"));
|
||||
ssjList.put("outSsj2", outSsj2);
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L1001", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L1002", Arrays.asList(2, 1, 1));
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
ddjDeviceExecutionQueueFinishService = SpringUtils.getBean(IDdjDeviceExecutionQueueFinishService.class);
|
||||
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService, mydoJobService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ddjCodeList.keySet()) {
|
||||
|
||||
for (MsgDdj msgDdj : ddjCodeList.get(type)) {
|
||||
try {
|
||||
if (ObjUtil.isNotNull(msgDdj)) {
|
||||
if (0 == msgDdj.getSpare1()) {
|
||||
generateInBoundPickQueue(msgDdj);
|
||||
generateInBoundLoadQueue(msgDdj);
|
||||
generateOutBoundQueue(msgDdj);
|
||||
ddjTask(msgDdj);
|
||||
}
|
||||
} else {
|
||||
log.error("堆垛机设备为空");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出库队列
|
||||
*/
|
||||
private void generateOutBoundQueue(MsgDdj ddj) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setInOut("2");
|
||||
param.setWarehouseId(WAREHOUSE_02);
|
||||
param.setRoadwayId(Convert.toStr(ddj.getId()));
|
||||
List<MydoJob> outJobList = mydoJobService.selectMydoJobList(param);
|
||||
if (CollUtil.isNotEmpty(outJobList)) {
|
||||
for (MydoJob outJob : outJobList) {
|
||||
String exitId = outJob.getExitId();
|
||||
|
||||
String outSsj = "";
|
||||
switch (exitId) {
|
||||
case "1":
|
||||
List<DeviceSsj> outSsj1 = ssjList.get("outSsj1");
|
||||
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj1.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj2 = ssjList.get("outSsj2");
|
||||
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj2.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log.error("出库任务出口错误");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("0".equals(outJob.getExecutionPhase()) && StrUtil.isNotEmpty(outSsj)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(outJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
outJob.setStatus("3");
|
||||
outJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
outJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(outJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", outJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库放货队列
|
||||
*/
|
||||
private void generateInBoundLoadQueue(MsgDdj ddj) {
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 3) {
|
||||
//允许下发 联机 有货待机
|
||||
if (StrUtil.isNotEmpty(ddj.getTrayCode())) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setTrayCode(ddj.getTrayCode());
|
||||
param.setWarehouseId(WAREHOUSE_02);
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectMydoJobList(param);
|
||||
MydoJob inJob = null;
|
||||
if (CollUtil.isEmpty(mydoJobs)) {
|
||||
//请求wms获取任务 并生成队列
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ddj.getTrayCode());
|
||||
paramMap.put("warehouseId", WAREHOUSE_02);
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
inJob.setStatus(TASK_STATUS_CREATE);
|
||||
inJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.insertMydoJob(inJob);
|
||||
} else {
|
||||
log.error(result.get("msg").toString());
|
||||
}
|
||||
} else {
|
||||
inJob = mydoJobs.get(0);
|
||||
}
|
||||
|
||||
if (ObjUtil.isNotNull(inJob) && inJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(inJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
inJob.setStatus("3");
|
||||
inJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
inJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(inJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", inJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Integer mbph = ddj.getMbph();
|
||||
Integer mblh = ddj.getMblh();
|
||||
Integer mbch = ddj.getMbch();
|
||||
long rwh = ddj.getRwh() + 100;
|
||||
log.error("扫码失败,放回原位 排:{} 列:{} 层:{} 任务号:{}", mbph, mblh, mbch, rwh);
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库取货队列
|
||||
*/
|
||||
private void generateInBoundPickQueue(MsgDdj ddj) {
|
||||
List<DeviceSsj> roadSsjList = ssjList.get("roadSsjList");
|
||||
for (DeviceSsj ssj : roadSsjList) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(ssj.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", ssj.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ddjTask(MsgDdj ddj) {
|
||||
/*
|
||||
第一部分
|
||||
堆垛机线程进来后第一件事先进行堆垛机正执行任务的账务处理
|
||||
以防存在漏处理,没处理的情况发生
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 0 && ddj.getJdbz() == 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//完成作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (mydoJob != null && ddjDeviceExecutionQueue != null) {
|
||||
//回传完成信号
|
||||
ddjTaskFinish(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第二部分
|
||||
跟踪队列执行阶段
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1 && (ddj.getJdbz() == 2 || ddj.getJdbz() == 3 || ddj.getJdbz() == 4)) {
|
||||
//根据堆垛机上任务号,修改任务执行阶段
|
||||
Long rwh = ddj.getRwh();
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ddjDeviceExecutionQueue != null) {
|
||||
//修改队列执行阶段
|
||||
ddjDeviceExecutionQueue.setRwzt(ddj.getJdbz());
|
||||
ddjDeviceExecutionQueue.setSpare1("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第三部分
|
||||
放货有货,重新分配货位
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1052 && ddj.getJdbz() < 5 && ddj.getYxxf() == 1) {
|
||||
//判断堆垛机上任务是否已重分,若未重分,则调用接口,请求重分货位
|
||||
Long rwh = ddj.getRwh();
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if ("0".equals(mydoJob.getFaultFlag()) && "1".equals(ddjDeviceExecutionQueue.getSpare1())) {
|
||||
mydoJob.setStatus("1");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
AjaxResult ajaxResult = apiService.reAssign(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
mydoJob.setFaultFlag("2");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
ddjDeviceExecutionQueue.setSpare1("0");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第四部分
|
||||
取货无货,重新分配单据
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1053 && ddj.getJdbz() < 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//无货异常处理
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
//找到对应任务 调用api接口 取货无货,重新分配单据
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
//作废作业
|
||||
InvalidMydoJob(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第五部分
|
||||
堆垛机任务下发
|
||||
*/
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5 && ddj.getSbzt() == 1052) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//查询作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
if (ObjUtil.isNotNull(mydoJob) && "2".equals(mydoJob.getFaultFlag())) {
|
||||
//判断任务是否重分完成
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
//重新下发堆垛机任务
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
mydoJob.setFaultFlag("0");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("托盘堆垛机重新下发任务成功 rwh:{}", rwh);
|
||||
} else {
|
||||
log.error("托盘堆垛机重新下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//正常下发
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5) {
|
||||
if (ddj.getSbzt() == 0) {
|
||||
//无货待机 只查询入库取货扫码或者出库队列
|
||||
ArrayList<Integer> rwlxList = new ArrayList<>();
|
||||
rwlxList.add(1);
|
||||
rwlxList.add(3);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlxList(rwlxList);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
} else if (ddj.getSbzt() == 3) {
|
||||
//有货待机 只查询入库放货队列
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlx(2);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废作业
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void InvalidMydoJob(Long rwh, Integer id) {
|
||||
mydoJobService.InvalidMydoJob(rwh, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 堆垛机任务完成
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void ddjTaskFinish(Long rwh, Integer id) {
|
||||
mydoJobService.ddjTaskFinish(rwh, id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给堆垛机下发任务
|
||||
*
|
||||
* @param queue 堆垛机执行的队列
|
||||
*/
|
||||
private int issuedDDJTask(Integer devId, DdjDeviceExecutionQueue queue) {
|
||||
int taskNo = Convert.toInt(queue.getRwh());
|
||||
int yph = Convert.toInt(queue.getYph());
|
||||
int ylh = Convert.toInt(queue.getYlh());
|
||||
int ych = Convert.toInt(queue.getYch());
|
||||
int mbph = Convert.toInt(queue.getMbph());
|
||||
int mblh = Convert.toInt(queue.getMblh());
|
||||
int mbch = Convert.toInt(queue.getMbch());
|
||||
int mlfs;
|
||||
if (queue.getRwlx() == 1 || queue.getRwlx() == 3) {
|
||||
mlfs = 5;
|
||||
} else if (queue.getRwlx() == 2) {
|
||||
mlfs = 4;
|
||||
} else {
|
||||
throw new RuntimeException("任务类型错误");
|
||||
}
|
||||
int xfwc = 1;
|
||||
int jym = Tools.getJYM(taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc);
|
||||
byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc, jym);
|
||||
if (devId == 1) {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
} else {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,441 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ddj;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.domain.wcs2wms.JobParam;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueFinishService;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.Constant.WAREHOUSE_02;
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class Ddj5Thread implements Runnable {
|
||||
|
||||
public HashMap<String, List<MsgDdj>> ddjCodeList;
|
||||
public HashMap<String, List<DeviceSsj>> ssjList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private IDdjDeviceExecutionQueueFinishService ddjDeviceExecutionQueueFinishService;
|
||||
private IMsgDdjService msgDdjService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
//todo 获取设备编码列表
|
||||
ddjCodeList = new HashMap<>();
|
||||
ArrayList<MsgDdj> ddjCodes = new ArrayList<>();
|
||||
ddjCodes.add(PlcDdjRead.deviceDdjMap.get("ddj5"));
|
||||
ddjCodeList.put("ddj", ddjCodes);
|
||||
ArrayList<DeviceSsj> roadSsjList = new ArrayList<>();
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
ssjList.put("roadSsjList", roadSsjList);
|
||||
ArrayList<DeviceSsj> outSsj1 = new ArrayList<>();
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L1003"));
|
||||
ssjList.put("outSsj1", outSsj1);
|
||||
ArrayList<DeviceSsj> outSsj2 = new ArrayList<>();
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L1004"));
|
||||
ssjList.put("outSsj2", outSsj2);
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L1003", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L1004", Arrays.asList(2, 1, 1));
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
ddjDeviceExecutionQueueFinishService = SpringUtils.getBean(IDdjDeviceExecutionQueueFinishService.class);
|
||||
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService, mydoJobService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ddjCodeList.keySet()) {
|
||||
|
||||
for (MsgDdj msgDdj : ddjCodeList.get(type)) {
|
||||
try {
|
||||
if (ObjUtil.isNotNull(msgDdj)) {
|
||||
if (0 == msgDdj.getSpare1()) {
|
||||
generateInBoundPickQueue(msgDdj);
|
||||
generateInBoundLoadQueue(msgDdj);
|
||||
generateOutBoundQueue(msgDdj);
|
||||
ddjTask(msgDdj);
|
||||
}
|
||||
} else {
|
||||
log.error("堆垛机设备为空");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出库队列
|
||||
*/
|
||||
private void generateOutBoundQueue(MsgDdj ddj) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setInOut("2");
|
||||
param.setWarehouseId(WAREHOUSE_02);
|
||||
param.setRoadwayId(Convert.toStr(ddj.getId()));
|
||||
List<MydoJob> outJobList = mydoJobService.selectMydoJobList(param);
|
||||
if (CollUtil.isNotEmpty(outJobList)) {
|
||||
for (MydoJob outJob : outJobList) {
|
||||
String exitId = outJob.getExitId();
|
||||
|
||||
String outSsj = "";
|
||||
switch (exitId) {
|
||||
case "1":
|
||||
List<DeviceSsj> outSsj1 = ssjList.get("outSsj1");
|
||||
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj1.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj2 = ssjList.get("outSsj2");
|
||||
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj2.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log.error("出库任务出口错误");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("0".equals(outJob.getExecutionPhase()) && StrUtil.isNotEmpty(outSsj)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(outJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
outJob.setStatus("3");
|
||||
outJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
outJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(outJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", outJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库放货队列
|
||||
*/
|
||||
private void generateInBoundLoadQueue(MsgDdj ddj) {
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 3) {
|
||||
//允许下发 联机 有货待机
|
||||
if (StrUtil.isNotEmpty(ddj.getTrayCode())) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setTrayCode(ddj.getTrayCode());
|
||||
param.setWarehouseId(WAREHOUSE_02);
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectMydoJobList(param);
|
||||
MydoJob inJob = null;
|
||||
if (CollUtil.isEmpty(mydoJobs)) {
|
||||
//请求wms获取任务 并生成队列
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ddj.getTrayCode());
|
||||
paramMap.put("warehouseId", WAREHOUSE_02);
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
inJob.setStatus(TASK_STATUS_CREATE);
|
||||
inJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.insertMydoJob(inJob);
|
||||
} else {
|
||||
log.error(result.get("msg").toString());
|
||||
}
|
||||
} else {
|
||||
inJob = mydoJobs.get(0);
|
||||
}
|
||||
|
||||
if (ObjUtil.isNotNull(inJob) && inJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(inJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
inJob.setStatus("3");
|
||||
inJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
inJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(inJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", inJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Integer mbph = ddj.getMbph();
|
||||
Integer mblh = ddj.getMblh();
|
||||
Integer mbch = ddj.getMbch();
|
||||
long rwh = ddj.getRwh() + 100;
|
||||
log.error("扫码失败,放回原位 排:{} 列:{} 层:{} 任务号:{}", mbph, mblh, mbch, rwh);
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库取货队列
|
||||
*/
|
||||
private void generateInBoundPickQueue(MsgDdj ddj) {
|
||||
List<DeviceSsj> roadSsjList = ssjList.get("roadSsjList");
|
||||
for (DeviceSsj ssj : roadSsjList) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(ssj.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", ssj.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ddjTask(MsgDdj ddj) {
|
||||
/*
|
||||
第一部分
|
||||
堆垛机线程进来后第一件事先进行堆垛机正执行任务的账务处理
|
||||
以防存在漏处理,没处理的情况发生
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 0 && ddj.getJdbz() == 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//完成作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (mydoJob != null && ddjDeviceExecutionQueue != null) {
|
||||
//回传完成信号
|
||||
ddjTaskFinish(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第二部分
|
||||
跟踪队列执行阶段
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1 && (ddj.getJdbz() == 2 || ddj.getJdbz() == 3 || ddj.getJdbz() == 4)) {
|
||||
//根据堆垛机上任务号,修改任务执行阶段
|
||||
Long rwh = ddj.getRwh();
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ddjDeviceExecutionQueue != null) {
|
||||
//修改队列执行阶段
|
||||
ddjDeviceExecutionQueue.setRwzt(ddj.getJdbz());
|
||||
ddjDeviceExecutionQueue.setSpare1("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第三部分
|
||||
放货有货,重新分配货位
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1052 && ddj.getJdbz() < 5 && ddj.getYxxf() == 1) {
|
||||
//判断堆垛机上任务是否已重分,若未重分,则调用接口,请求重分货位
|
||||
Long rwh = ddj.getRwh();
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if ("0".equals(mydoJob.getFaultFlag()) && "1".equals(ddjDeviceExecutionQueue.getSpare1())) {
|
||||
mydoJob.setStatus("1");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
AjaxResult ajaxResult = apiService.reAssign(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
mydoJob.setFaultFlag("2");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
ddjDeviceExecutionQueue.setSpare1("0");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第四部分
|
||||
取货无货,重新分配单据
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1053 && ddj.getJdbz() < 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//无货异常处理
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
//找到对应任务 调用api接口 取货无货,重新分配单据
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
//作废作业
|
||||
InvalidMydoJob(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第五部分
|
||||
堆垛机任务下发
|
||||
*/
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5 && ddj.getSbzt() == 1052) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//查询作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
if (ObjUtil.isNotNull(mydoJob) && "2".equals(mydoJob.getFaultFlag())) {
|
||||
//判断任务是否重分完成
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
//重新下发堆垛机任务
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
mydoJob.setFaultFlag("0");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("托盘堆垛机重新下发任务成功 rwh:{}", rwh);
|
||||
} else {
|
||||
log.error("托盘堆垛机重新下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//正常下发
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5) {
|
||||
if (ddj.getSbzt() == 0) {
|
||||
//无货待机 只查询入库取货扫码或者出库队列
|
||||
ArrayList<Integer> rwlxList = new ArrayList<>();
|
||||
rwlxList.add(1);
|
||||
rwlxList.add(3);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlxList(rwlxList);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
} else if (ddj.getSbzt() == 3) {
|
||||
//有货待机 只查询入库放货队列
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlx(2);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废作业
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void InvalidMydoJob(Long rwh, Integer id) {
|
||||
mydoJobService.InvalidMydoJob(rwh, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 堆垛机任务完成
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void ddjTaskFinish(Long rwh, Integer id) {
|
||||
mydoJobService.ddjTaskFinish(rwh, id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给堆垛机下发任务
|
||||
*
|
||||
* @param queue 堆垛机执行的队列
|
||||
*/
|
||||
private int issuedDDJTask(Integer devId, DdjDeviceExecutionQueue queue) {
|
||||
int taskNo = Convert.toInt(queue.getRwh());
|
||||
int yph = Convert.toInt(queue.getYph());
|
||||
int ylh = Convert.toInt(queue.getYlh());
|
||||
int ych = Convert.toInt(queue.getYch());
|
||||
int mbph = Convert.toInt(queue.getMbph());
|
||||
int mblh = Convert.toInt(queue.getMblh());
|
||||
int mbch = Convert.toInt(queue.getMbch());
|
||||
int mlfs;
|
||||
if (queue.getRwlx() == 1 || queue.getRwlx() == 3) {
|
||||
mlfs = 5;
|
||||
} else if (queue.getRwlx() == 2) {
|
||||
mlfs = 4;
|
||||
} else {
|
||||
throw new RuntimeException("任务类型错误");
|
||||
}
|
||||
int xfwc = 1;
|
||||
int jym = Tools.getJYM(taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc);
|
||||
byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc, jym);
|
||||
if (devId == 1) {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
} else {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,441 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ddj;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.domain.wcs2wms.JobParam;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ddj.domain.MsgDdj;
|
||||
import com.ruoyi.device.ddj.service.IMsgDdjService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueFinishService;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.Constant.WAREHOUSE_02;
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class Ddj6Thread implements Runnable {
|
||||
|
||||
public HashMap<String, List<MsgDdj>> ddjCodeList;
|
||||
public HashMap<String, List<DeviceSsj>> ssjList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private IDdjDeviceExecutionQueueFinishService ddjDeviceExecutionQueueFinishService;
|
||||
private IMsgDdjService msgDdjService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
//todo 获取设备编码列表
|
||||
ddjCodeList = new HashMap<>();
|
||||
ArrayList<MsgDdj> ddjCodes = new ArrayList<>();
|
||||
ddjCodes.add(PlcDdjRead.deviceDdjMap.get("ddj6"));
|
||||
ddjCodeList.put("ddj", ddjCodes);
|
||||
ArrayList<DeviceSsj> roadSsjList = new ArrayList<>();
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1005"));
|
||||
roadSsjList.add(PlcSsjRead.deviceSsjMap.get("L1006"));
|
||||
ssjList.put("roadSsjList", roadSsjList);
|
||||
ArrayList<DeviceSsj> outSsj1 = new ArrayList<>();
|
||||
outSsj1.add(PlcSsjRead.deviceSsjMap.get("L1005"));
|
||||
ssjList.put("outSsj1", outSsj1);
|
||||
ArrayList<DeviceSsj> outSsj2 = new ArrayList<>();
|
||||
outSsj2.add(PlcSsjRead.deviceSsjMap.get("L1006"));
|
||||
ssjList.put("outSsj2", outSsj2);
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L1005", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L1006", Arrays.asList(2, 1, 1));
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
ddjDeviceExecutionQueueFinishService = SpringUtils.getBean(IDdjDeviceExecutionQueueFinishService.class);
|
||||
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService, mydoJobService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ddjCodeList.keySet()) {
|
||||
|
||||
for (MsgDdj msgDdj : ddjCodeList.get(type)) {
|
||||
try {
|
||||
if (ObjUtil.isNotNull(msgDdj)) {
|
||||
if (0 == msgDdj.getSpare1()) {
|
||||
generateInBoundPickQueue(msgDdj);
|
||||
generateInBoundLoadQueue(msgDdj);
|
||||
generateOutBoundQueue(msgDdj);
|
||||
ddjTask(msgDdj);
|
||||
}
|
||||
} else {
|
||||
log.error("堆垛机设备为空");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建出库队列
|
||||
*/
|
||||
private void generateOutBoundQueue(MsgDdj ddj) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setInOut("2");
|
||||
param.setWarehouseId(WAREHOUSE_02);
|
||||
param.setRoadwayId(Convert.toStr(ddj.getId()));
|
||||
List<MydoJob> outJobList = mydoJobService.selectMydoJobList(param);
|
||||
if (CollUtil.isNotEmpty(outJobList)) {
|
||||
for (MydoJob outJob : outJobList) {
|
||||
String exitId = outJob.getExitId();
|
||||
|
||||
String outSsj = "";
|
||||
switch (exitId) {
|
||||
case "1":
|
||||
List<DeviceSsj> outSsj1 = ssjList.get("outSsj1");
|
||||
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj1.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
List<DeviceSsj> outSsj2 = ssjList.get("outSsj2");
|
||||
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getModel() == 2)) {
|
||||
outSsj = outSsj2.get(0).getDeviceCode();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log.error("出库任务出口错误");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("0".equals(outJob.getExecutionPhase()) && StrUtil.isNotEmpty(outSsj)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(outJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
outJob.setStatus("3");
|
||||
outJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
outJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(outJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", outJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库放货队列
|
||||
*/
|
||||
private void generateInBoundLoadQueue(MsgDdj ddj) {
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 3) {
|
||||
//允许下发 联机 有货待机
|
||||
if (StrUtil.isNotEmpty(ddj.getTrayCode())) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setTrayCode(ddj.getTrayCode());
|
||||
param.setWarehouseId(WAREHOUSE_02);
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectMydoJobList(param);
|
||||
MydoJob inJob = null;
|
||||
if (CollUtil.isEmpty(mydoJobs)) {
|
||||
//请求wms获取任务 并生成队列
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ddj.getTrayCode());
|
||||
paramMap.put("warehouseId", WAREHOUSE_02);
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
inJob.setStatus(TASK_STATUS_CREATE);
|
||||
inJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.insertMydoJob(inJob);
|
||||
} else {
|
||||
log.error(result.get("msg").toString());
|
||||
}
|
||||
} else {
|
||||
inJob = mydoJobs.get(0);
|
||||
}
|
||||
|
||||
if (ObjUtil.isNotNull(inJob) && inJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(inJob.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
inJob.setStatus("3");
|
||||
inJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
||||
inJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(inJob);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", inJob.getTaskNo());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Integer mbph = ddj.getMbph();
|
||||
Integer mblh = ddj.getMblh();
|
||||
Integer mbch = ddj.getMbch();
|
||||
long rwh = ddj.getRwh() + 100;
|
||||
log.error("扫码失败,放回原位 排:{} 列:{} 层:{} 任务号:{}", mbph, mblh, mbch, rwh);
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建入库取货队列
|
||||
*/
|
||||
private void generateInBoundPickQueue(MsgDdj ddj) {
|
||||
List<DeviceSsj> roadSsjList = ssjList.get("roadSsjList");
|
||||
for (DeviceSsj ssj : roadSsjList) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(ssj.getTaskNo()), ddj.getId());
|
||||
if (ObjUtil.isNull(ddjQueue)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
} else {
|
||||
log.info("任务已存在 rwh{}", ssj.getTaskNo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ddjTask(MsgDdj ddj) {
|
||||
/*
|
||||
第一部分
|
||||
堆垛机线程进来后第一件事先进行堆垛机正执行任务的账务处理
|
||||
以防存在漏处理,没处理的情况发生
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 0 && ddj.getJdbz() == 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//完成作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (mydoJob != null && ddjDeviceExecutionQueue != null) {
|
||||
//回传完成信号
|
||||
ddjTaskFinish(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第二部分
|
||||
跟踪队列执行阶段
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1 && (ddj.getJdbz() == 2 || ddj.getJdbz() == 3 || ddj.getJdbz() == 4)) {
|
||||
//根据堆垛机上任务号,修改任务执行阶段
|
||||
Long rwh = ddj.getRwh();
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ddjDeviceExecutionQueue != null) {
|
||||
//修改队列执行阶段
|
||||
ddjDeviceExecutionQueue.setRwzt(ddj.getJdbz());
|
||||
ddjDeviceExecutionQueue.setSpare1("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第三部分
|
||||
放货有货,重新分配货位
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1052 && ddj.getJdbz() < 5 && ddj.getYxxf() == 1) {
|
||||
//判断堆垛机上任务是否已重分,若未重分,则调用接口,请求重分货位
|
||||
Long rwh = ddj.getRwh();
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if ("0".equals(mydoJob.getFaultFlag()) && "1".equals(ddjDeviceExecutionQueue.getSpare1())) {
|
||||
mydoJob.setStatus("1");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
AjaxResult ajaxResult = apiService.reAssign(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
mydoJob.setFaultFlag("2");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
ddjDeviceExecutionQueue.setSpare1("0");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第四部分
|
||||
取货无货,重新分配单据
|
||||
*/
|
||||
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 1053 && ddj.getJdbz() < 5) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//无货异常处理
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
//找到对应任务 调用api接口 取货无货,重新分配单据
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(rwh.toString(), null, null));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
//作废作业
|
||||
InvalidMydoJob(rwh, ddj.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
第五部分
|
||||
堆垛机任务下发
|
||||
*/
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5 && ddj.getSbzt() == 1052) {
|
||||
Long rwh = ddj.getRwh();
|
||||
//查询作业
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
|
||||
if (ObjUtil.isNotNull(mydoJob) && "2".equals(mydoJob.getFaultFlag())) {
|
||||
//判断任务是否重分完成
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
|
||||
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
|
||||
//重新下发堆垛机任务
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
mydoJob.setFaultFlag("0");
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("托盘堆垛机重新下发任务成功 rwh:{}", rwh);
|
||||
} else {
|
||||
log.error("托盘堆垛机重新下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//正常下发
|
||||
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5) {
|
||||
if (ddj.getSbzt() == 0) {
|
||||
//无货待机 只查询入库取货扫码或者出库队列
|
||||
ArrayList<Integer> rwlxList = new ArrayList<>();
|
||||
rwlxList.add(1);
|
||||
rwlxList.add(3);
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlxList(rwlxList);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
} else if (ddj.getSbzt() == 3) {
|
||||
//有货待机 只查询入库放货队列
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueueParam.setDdjxf("0");
|
||||
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
|
||||
ddjDeviceExecutionQueueParam.setRwlx(2);
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
|
||||
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
|
||||
int i = issuedDDJTask(ddj.getId(), ddjDeviceExecutionQueue);
|
||||
if (i == 1) {
|
||||
//更新开始时间,修改ddjxf为已下发1
|
||||
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("1");
|
||||
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
|
||||
} else {
|
||||
log.error("托盘堆垛机下发任务失败!!!!!!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 作废作业
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void InvalidMydoJob(Long rwh, Integer id) {
|
||||
mydoJobService.InvalidMydoJob(rwh, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 堆垛机任务完成
|
||||
*
|
||||
* @param rwh 作业单号
|
||||
* @param id 作业单id
|
||||
*/
|
||||
private void ddjTaskFinish(Long rwh, Integer id) {
|
||||
mydoJobService.ddjTaskFinish(rwh, id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给堆垛机下发任务
|
||||
*
|
||||
* @param queue 堆垛机执行的队列
|
||||
*/
|
||||
private int issuedDDJTask(Integer devId, DdjDeviceExecutionQueue queue) {
|
||||
int taskNo = Convert.toInt(queue.getRwh());
|
||||
int yph = Convert.toInt(queue.getYph());
|
||||
int ylh = Convert.toInt(queue.getYlh());
|
||||
int ych = Convert.toInt(queue.getYch());
|
||||
int mbph = Convert.toInt(queue.getMbph());
|
||||
int mblh = Convert.toInt(queue.getMblh());
|
||||
int mbch = Convert.toInt(queue.getMbch());
|
||||
int mlfs;
|
||||
if (queue.getRwlx() == 1 || queue.getRwlx() == 3) {
|
||||
mlfs = 5;
|
||||
} else if (queue.getRwlx() == 2) {
|
||||
mlfs = 4;
|
||||
} else {
|
||||
throw new RuntimeException("任务类型错误");
|
||||
}
|
||||
int xfwc = 1;
|
||||
int jym = Tools.getJYM(taskNo, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc);
|
||||
byte[] sendData = Tools.sendDataToDevice(taskNo, null, yph, ylh, ych, mbph, mblh, mbch, mlfs, xfwc, jym);
|
||||
if (devId == 1) {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
} else {
|
||||
return PlcDdjRead.WriteToDDJ("DB61.0", sendData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ssj.floor1;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.bas.cargospace.domain.BasCargoSpace;
|
||||
import com.ruoyi.bas.cargospace.service.IBasCargoSpaceService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
import static com.ruoyi.common.TaskType.DDJ_RWLX_3;
|
||||
import static com.ruoyi.schedule.plcRead.ssj.PlcSsjRead.writeToSsj;
|
||||
|
||||
/**
|
||||
* 一楼双向线体入库线程 条码+到位+无出库作业 下发去向+任务号 有出库作业就下发退回
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class Floor1BothWayInSsjThread implements Runnable {
|
||||
|
||||
public HashMap<String, DeviceSsj> ssjCodeList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private IBasCargoSpaceService basCargoSpaceService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
private final Map<String, String> exitRoadwayMap = new HashMap<>();
|
||||
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
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"));
|
||||
|
||||
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
basCargoSpaceService = SpringUtils.getBean(IBasCargoSpaceService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L2003", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L2005", Arrays.asList(1, 1, 1));
|
||||
|
||||
exitRoadwayMap.put("L2003", "L2012");
|
||||
exitRoadwayMap.put("L2005", "L2013");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
|
||||
for (String type : ssjCodeList.keySet()) {
|
||||
switch (type) {
|
||||
case "roadway1":
|
||||
case "roadway2":
|
||||
dispatch1(ssjCodeList.get(type));
|
||||
break;
|
||||
case "in1":
|
||||
case "in2":
|
||||
dispatch2(ssjCodeList.get(type));
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dispatch1(DeviceSsj ssj) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
int taskNo = ssj.getTaskNo();
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(taskNo));
|
||||
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_SSJ)) {
|
||||
mydoJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
}
|
||||
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueListByRwlx(DDJ_RWLX_3, Convert.toInt(mydoJob.getRoadwayId()));
|
||||
BasCargoSpace basCargoSpace = basCargoSpaceService.selectBasCargoSpaceByWmsCargoSpaceId(mydoJob.getCargoSpaceId());
|
||||
List<Integer> pclList = roadwayMap.get(ssj.getDeviceCode());
|
||||
if (CollUtil.isEmpty(ddjDeviceExecutionQueues) && ObjUtil.isNotNull(basCargoSpace) && CollUtil.isNotEmpty(pclList)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueue.setUuid(IdUtil.simpleUUID());
|
||||
ddjDeviceExecutionQueue.setRwh(Convert.toLong(mydoJob.getTaskNo()));
|
||||
ddjDeviceExecutionQueue.setDevName(mydoJob.getRoadwayId());
|
||||
ddjDeviceExecutionQueue.setDevId(Convert.toInt(mydoJob.getRoadwayId()));
|
||||
ddjDeviceExecutionQueue.setRwzt(0);
|
||||
ddjDeviceExecutionQueue.setYph(pclList.get(0));
|
||||
ddjDeviceExecutionQueue.setYlh(pclList.get(1));
|
||||
ddjDeviceExecutionQueue.setYch(pclList.get(2));
|
||||
ddjDeviceExecutionQueue.setMbph(Convert.toInt(basCargoSpace.getThePlatoon()));
|
||||
ddjDeviceExecutionQueue.setMblh(Convert.toInt(basCargoSpace.getTheColumn()));
|
||||
ddjDeviceExecutionQueue.setMbch(Convert.toInt(basCargoSpace.getTheFloor()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("0");
|
||||
ddjDeviceExecutionQueue.setMlfs(5);
|
||||
ddjDeviceExecutionQueue.setScsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_3);
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
|
||||
mydoJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatch2(DeviceSsj ssj) {
|
||||
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;
|
||||
}
|
||||
if (i == 1) {
|
||||
log.info("未检测到托盘码下发回退 rwh:{},qx:{},trayCode:{}", ssj.getTaskNo(), 1, ssj.getTrayCode());
|
||||
}
|
||||
} else {
|
||||
if (StrUtil.isNotBlank(ssj.getTrayCode())) {
|
||||
MydoJob param = new MydoJob();
|
||||
param.setEntranceId(ssj.getDeviceCode());
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectMydoJobList(param);
|
||||
MydoJob inJob = null;
|
||||
if (CollUtil.isNotEmpty(mydoJobs)) {
|
||||
inJob = mydoJobs.get(0);
|
||||
} else {
|
||||
//根据托盘码请求入库作业
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", ssj.getTrayCode());
|
||||
paramMap.put("size", ssj.getTraySize());
|
||||
paramMap.put("floor", "1");
|
||||
paramMap.put("entranceId",ssj.getDeviceCode());
|
||||
AjaxResult result = apiService.selectMydoJobByTrayCodeAndEntranceId(paramMap);
|
||||
if (result.isSuccess()) {
|
||||
inJob = BeanUtil.toBean(result.get("data"), MydoJob.class);
|
||||
inJob.setStatus(TASK_STATUS_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;
|
||||
}
|
||||
if (i == 1) {
|
||||
inJob.setStatus(TASK_STATUS_RUNNING);
|
||||
inJob.setExecutionPhase(TASK_EP_SSJ);
|
||||
inJob.setStartTime(DateUtil.formatDateTime(DateUtil.date()));
|
||||
inJob.setTargetRoadwayId(Convert.toStr(1));
|
||||
mydoJobService.updateMydoJob(inJob);
|
||||
log.info("入库请求下发任务号加去向 rwh:{},qx:{},trayCode:{}", ssj.getTaskNo(), 1, ssj.getTrayCode());
|
||||
}
|
||||
}
|
||||
}else {
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("size", ssj.getTraySize());
|
||||
AjaxResult ajaxResult = apiService.selectMydoJobByNoTrayCode(paramMap);
|
||||
if (ajaxResult.isSuccess()) {
|
||||
MydoJob mydoJob2 = BeanUtil.toBean(ajaxResult.get("data"), MydoJob.class);
|
||||
mydoJobService.insertMydoJob(mydoJob2);
|
||||
int i = writeToSsj(ssj.getPlcDbWriteAddress(),mydoJob2.getTaskNo(),1,1);
|
||||
if (i == 1) {
|
||||
mydoJob2.setExecutionPhase("1");
|
||||
mydoJobService.updateMydoJob(mydoJob2);
|
||||
log.info("{}下发任务号{}成功:",ssj.getDeviceCode(),mydoJob2.getTaskNo());
|
||||
}
|
||||
} else if (ajaxResult.isError()) {
|
||||
//超大,给plc下发错误信息,等待人工处理
|
||||
//托盘大小对不上,给plc下发错误信息,等待人工处理
|
||||
//码不对,给plc下发错误信息,等待人工处理
|
||||
int i = writeToSsj(ssj.getPlcDbWriteAddress(), "0", Integer.parseInt(ajaxResult.get("code").toString()), 2);
|
||||
if (i == 1) {
|
||||
log.info("{}下发错误信号{}成功:",ssj.getDeviceCode(),Integer.parseInt(ajaxResult.get("code").toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,182 +0,0 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ssj.floor1;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.bas.cargospace.domain.BasCargoSpace;
|
||||
import com.ruoyi.bas.cargospace.service.IBasCargoSpaceService;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.JobCallBack;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IJobCallBackService;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.agv.service.IAgvQueueService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
import static com.ruoyi.common.TaskType.DDJ_RWLX_3;
|
||||
|
||||
/**
|
||||
* 一楼双向线体出库线程 循环盘点出库作业+巷道口空闲+出库线体全部空闲+无入库作业 生成堆垛机出库队列
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class Floor1BothWayOutSsjThread implements Runnable {
|
||||
|
||||
public HashMap<String, List<DeviceSsj>> ssjCodeList;
|
||||
|
||||
private IMydoJobService mydoJobService;
|
||||
private IBasCargoSpaceService basCargoSpaceService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private final Map<String,List<Integer>> roadwayMap = new HashMap<>();
|
||||
private IJobCallBackService jobCallBackService;
|
||||
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
ssjCodeList = new HashMap<>();
|
||||
ArrayList<DeviceSsj> roadway1 = new ArrayList<>();
|
||||
roadway1.add(PlcSsjRead.deviceSsjMap.get("L2003"));
|
||||
roadway1.add(PlcSsjRead.deviceSsjMap.get("L2004"));
|
||||
roadway1.add(PlcSsjRead.deviceSsjMap.get("L2012"));
|
||||
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"));
|
||||
ssjCodeList.put("roadway2", roadway2);
|
||||
ArrayList<DeviceSsj> ou1 = new ArrayList<>();
|
||||
ou1.add(PlcSsjRead.deviceSsjMap.get("L2012"));
|
||||
ssjCodeList.put("ou1", ou1);
|
||||
ArrayList<DeviceSsj> out2 = new ArrayList<>();
|
||||
out2.add(PlcSsjRead.deviceSsjMap.get("L2013"));
|
||||
ssjCodeList.put("out2", out2);
|
||||
|
||||
|
||||
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
basCargoSpaceService = SpringUtils.getBean(IBasCargoSpaceService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
jobCallBackService = SpringUtils.getBean(IJobCallBackService.class);
|
||||
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L2003",Arrays.asList(1,1,1));
|
||||
roadwayMap.put("L2005",Arrays.asList(1,1,1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun){
|
||||
for (String type : ssjCodeList.keySet()) {
|
||||
|
||||
switch (type){
|
||||
case "roadway1":
|
||||
case "roadway2":
|
||||
dispatch(ssjCodeList.get(type));
|
||||
break;
|
||||
case "out1":
|
||||
case "out2":
|
||||
dispatch1(ssjCodeList.get(type));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void dispatch1(List<DeviceSsj> ssjList) {
|
||||
for (DeviceSsj ssj : ssjList) {
|
||||
if (ssj.getDw()==1 && ssj.getTaskNo()>0){
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(ssj.getTaskNo()));
|
||||
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
mydoJob.setExecutionPhase(TASK_EP_SSJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
}
|
||||
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_SSJ)) {
|
||||
JobCallBack jobCallBack = new JobCallBack();
|
||||
jobCallBack.setType("2");
|
||||
jobCallBack.setMydojobId(mydoJob.getJobId());
|
||||
jobCallBack.setStatus("0");
|
||||
jobCallBack.setTaskNo(Convert.toLong(mydoJob.getTaskNo()));
|
||||
jobCallBack.setCreateTime(new Date());
|
||||
jobCallBackService.insertJobCallBack(jobCallBack);
|
||||
|
||||
log.info("完成任务 taskNo{} ", mydoJob.getTaskNo());
|
||||
mydoJob.setStatus(TASK_STATUS_FINISH);
|
||||
mydoJob.setExecutionPhase(TASK_EP_WMS_FINISH);
|
||||
mydoJob.setFinishTime(DateUtil.formatDateTime(new Date()));
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
mydoJobService.insertHistory(mydoJob.getJobId());
|
||||
mydoJobService.deleteMydoJobByJobId(mydoJob.getJobId());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 出库堆垛机队列生成
|
||||
*/
|
||||
public void dispatch(List<DeviceSsj> ssjList) {
|
||||
DeviceSsj deviceSsj = ssjList.get(ssjList.size() - 1);
|
||||
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);
|
||||
if (ObjUtil.isNotNull(pdOutJob) && allKx && ObjUtil.isNull(inJob)) {
|
||||
//所有线体为空闲 并且存在出库作业 并且不存在入库作业
|
||||
BasCargoSpace basCargoSpace = basCargoSpaceService.selectBasCargoSpaceByWmsCargoSpaceId(pdOutJob.getCargoSpaceId());
|
||||
if (ObjUtil.isNull(basCargoSpace)){
|
||||
log.error("货位不存在 cargoSpaceId{}",pdOutJob.getCargoSpaceId());
|
||||
}else {
|
||||
//生成队列
|
||||
List<DdjDeviceExecutionQueue> list = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueListByRwlx(DDJ_RWLX_3,Convert.toInt(pdOutJob.getRoadwayId()));
|
||||
List<Integer> pclList = roadwayMap.get(ssjList.get(0).getDeviceCode());
|
||||
if (CollUtil.isEmpty(list) && CollUtil.isNotEmpty(pclList)){
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueue.setUuid(IdUtil.simpleUUID());
|
||||
ddjDeviceExecutionQueue.setRwh(Convert.toLong(pdOutJob.getTaskNo()));
|
||||
ddjDeviceExecutionQueue.setDevName(pdOutJob.getRoadwayId());
|
||||
ddjDeviceExecutionQueue.setDevId(Convert.toInt(pdOutJob.getRoadwayId()));
|
||||
ddjDeviceExecutionQueue.setRwzt(0);
|
||||
ddjDeviceExecutionQueue.setYph(Convert.toInt(basCargoSpace.getThePlatoon()));
|
||||
ddjDeviceExecutionQueue.setYlh(Convert.toInt(basCargoSpace.getTheColumn()));
|
||||
ddjDeviceExecutionQueue.setYch(Convert.toInt(basCargoSpace.getTheFloor()));
|
||||
ddjDeviceExecutionQueue.setMbph(pclList.get(0));
|
||||
ddjDeviceExecutionQueue.setMblh(pclList.get(1));
|
||||
ddjDeviceExecutionQueue.setMbch(pclList.get(2));
|
||||
ddjDeviceExecutionQueue.setDdjxf("0");
|
||||
ddjDeviceExecutionQueue.setMlfs(5);
|
||||
ddjDeviceExecutionQueue.setScsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_3);
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
|
||||
pdOutJob.setStatus(TASK_STATUS_RUNNING);
|
||||
pdOutJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
pdOutJob.setStartTime(DateUtil.formatDateTime(DateUtil.date()));
|
||||
mydoJobService.updateMydoJob(pdOutJob);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ssj.floor1;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.bas.cargospace.domain.BasCargoSpace;
|
||||
import com.ruoyi.bas.cargospace.service.IBasCargoSpaceService;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.JobCallBack;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IJobCallBackService;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
import static com.ruoyi.common.TaskType.DDJ_RWLX_2;
|
||||
|
||||
/**
|
||||
* 一楼单向出库线程 循环出库作业+巷道口空闲 生成堆垛机出库队列
|
||||
*/
|
||||
@Slf4j
|
||||
public class Floor1SingleSsjThread implements Runnable {
|
||||
|
||||
public HashMap<String, List<String>> ssjCodeList;
|
||||
private IMydoJobService mydoJobService;
|
||||
public boolean isRun = true;
|
||||
private final Map<String, String> exitRoadwayMap = new HashMap<>();
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
private IBasCargoSpaceService basCargoSpaceService;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
private IJobCallBackService jobCallBackService;
|
||||
|
||||
|
||||
public void init() {
|
||||
//设置要循环的输送机
|
||||
ssjCodeList = new HashMap<>();
|
||||
ArrayList<String> outRoadwaySsjList = new ArrayList<>();
|
||||
outRoadwaySsjList.add("L2001");
|
||||
outRoadwaySsjList.add("L2007");
|
||||
ssjCodeList.put("outRoadwaySsj", outRoadwaySsjList);
|
||||
ArrayList<String> outSsjList = new ArrayList<>();
|
||||
outSsjList.add("L2002");
|
||||
outSsjList.add("L2008");
|
||||
ssjCodeList.put("outSsj", outSsjList);
|
||||
|
||||
|
||||
//初始化服务
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
basCargoSpaceService = SpringUtils.getBean(IBasCargoSpaceService.class);
|
||||
jobCallBackService = SpringUtils.getBean(IJobCallBackService.class);
|
||||
|
||||
|
||||
//初始化出口和巷道口映射关系
|
||||
exitRoadwayMap.put("L2001", "L2002");
|
||||
exitRoadwayMap.put("L2007", "L2008");
|
||||
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L2001", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L2007", Arrays.asList(1, 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ssjCodeList.keySet()) {
|
||||
//一楼单向巷道口
|
||||
if ("outRoadwaySsj".equals(type)) {
|
||||
for (String ssjCode : ssjCodeList.get(type)) {
|
||||
try {
|
||||
if (PlcSsjRead.deviceSsjMap.containsKey(ssjCode)) {
|
||||
dispatch(PlcSsjRead.deviceSsjMap.get(ssjCode));
|
||||
} else {
|
||||
log.error("设备不存在 ssjCode{}", ssjCode);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if ("outSsj".equals(type)) {
|
||||
for (String ssjCode : ssjCodeList.get(type)) {
|
||||
try {
|
||||
if (PlcSsjRead.deviceSsjMap.containsKey(ssjCode)) {
|
||||
dispatch2(PlcSsjRead.deviceSsjMap.get(ssjCode));
|
||||
} else {
|
||||
log.error("设备不存在 ssjCode{}", ssjCode);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 一楼单向出库口调度
|
||||
*
|
||||
* @param ssj 输送机
|
||||
*/
|
||||
private void dispatch2(DeviceSsj ssj) {
|
||||
if (ssj.getDw() == 1 && ssj.getTaskNo() > 0) {
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(ssj.getTaskNo()));
|
||||
if (ObjUtil.isNotNull(mydoJob)) {
|
||||
mydoJob.setExecutionPhase(TASK_EP_SSJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
JobCallBack jobCallBack = new JobCallBack();
|
||||
jobCallBack.setType("2");
|
||||
jobCallBack.setMydojobId(mydoJob.getJobId());
|
||||
jobCallBack.setStatus("0");
|
||||
jobCallBack.setTaskNo(Convert.toLong(mydoJob.getTaskNo()));
|
||||
jobCallBack.setCreateTime(new Date());
|
||||
jobCallBackService.insertJobCallBack(jobCallBack);
|
||||
log.info("完成任务 taskNo{} ", mydoJob.getTaskNo());
|
||||
mydoJob.setStatus(TASK_STATUS_FINISH);
|
||||
mydoJob.setFinishTime(DateUtil.formatDateTime(new Date()));
|
||||
mydoJob.setExecutionPhase(TASK_EP_WMS_FINISH);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
mydoJobService.insertHistory(mydoJob.getJobId());
|
||||
mydoJobService.deleteMydoJobByJobId(mydoJob.getJobId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 一楼单向巷道口调度
|
||||
*
|
||||
* @param ssj 输送机
|
||||
*/
|
||||
public void dispatch(DeviceSsj ssj) {
|
||||
//如果入库请求1 并且 托盘码不为空
|
||||
if (ssj.getKx() == 1) {
|
||||
String exitId = exitRoadwayMap.get(ssj.getDeviceCode());
|
||||
List<String> exitList = new ArrayList<>();
|
||||
exitList.add(exitId);
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByExitList(exitList);
|
||||
if (ObjUtil.isNotNull(mydoJob)) {
|
||||
BasCargoSpace basCargoSpace = basCargoSpaceService.selectBasCargoSpaceByWmsCargoSpaceId(mydoJob.getCargoSpaceId());
|
||||
if (ObjUtil.isNull(basCargoSpace)) {
|
||||
log.error("货位不存在 cargoSpaceId{}", mydoJob.getCargoSpaceId());
|
||||
} else {
|
||||
//生成队列
|
||||
List<DdjDeviceExecutionQueue> list = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueListByRwlx(DDJ_RWLX_2, Convert.toInt(mydoJob.getRoadwayId()));
|
||||
List<Integer> pclList = roadwayMap.get(ssj.getDeviceCode());
|
||||
if (CollUtil.isEmpty(list) && CollUtil.isNotEmpty(pclList)) {
|
||||
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
|
||||
ddjDeviceExecutionQueue.setUuid(IdUtil.simpleUUID());
|
||||
ddjDeviceExecutionQueue.setRwh(Convert.toLong(mydoJob.getTaskNo()));
|
||||
ddjDeviceExecutionQueue.setDevName(mydoJob.getRoadwayId());
|
||||
ddjDeviceExecutionQueue.setDevId(Convert.toInt(mydoJob.getRoadwayId()));
|
||||
ddjDeviceExecutionQueue.setRwzt(0);
|
||||
ddjDeviceExecutionQueue.setYph(Convert.toInt(basCargoSpace.getThePlatoon()));
|
||||
ddjDeviceExecutionQueue.setYlh(Convert.toInt(basCargoSpace.getTheColumn()));
|
||||
ddjDeviceExecutionQueue.setYch(Convert.toInt(basCargoSpace.getTheFloor()));
|
||||
ddjDeviceExecutionQueue.setMbph(pclList.get(0));
|
||||
ddjDeviceExecutionQueue.setMblh(pclList.get(1));
|
||||
ddjDeviceExecutionQueue.setMbch(pclList.get(2));
|
||||
ddjDeviceExecutionQueue.setDdjxf("0");
|
||||
ddjDeviceExecutionQueue.setMlfs(5);
|
||||
ddjDeviceExecutionQueue.setScsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_2);
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
|
||||
//修改作业状态
|
||||
mydoJob.setStatus(TASK_STATUS_RUNNING);
|
||||
mydoJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJob.setStartTime(DateUtil.formatDateTime(DateUtil.date()));
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ssj.floor2;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.JobCallBack;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IJobCallBackService;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
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 java.util.ArrayList;
|
||||
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.schedule.plcRead.ssj.PlcSsjRead.writeToSsj;
|
||||
|
||||
/**
|
||||
* 二楼出入口输送线线程
|
||||
*/
|
||||
@Slf4j
|
||||
public class Floor2InOutSsjThread implements Runnable {
|
||||
|
||||
public HashMap<String, List<String>> ssjCodeList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IAgvQueueService agvQueueService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private IJobCallBackService jobCallBackService;
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
ssjCodeList = new HashMap<>();
|
||||
ArrayList<String> ssjCodes = new ArrayList<>();
|
||||
ssjCodes.add("L1011");
|
||||
ssjCodes.add("L1012");
|
||||
ssjCodeList.put("inout", ssjCodes);
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
agvQueueService = SpringUtils.getBean(IAgvQueueService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
jobCallBackService = SpringUtils.getBean(IJobCallBackService.class);
|
||||
log.info("初始化服务 {},{}", apiService, agvQueueService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ssjCodeList.keySet()) {
|
||||
|
||||
switch (type) {
|
||||
case "inout":
|
||||
//生产线入库
|
||||
for (String ssjCode : ssjCodeList.get(type)) {
|
||||
try {
|
||||
if (PlcSsjRead.deviceSsjMap.containsKey(ssjCode)) {
|
||||
inDispatch(PlcSsjRead.deviceSsjMap.get(ssjCode));
|
||||
} else {
|
||||
log.error("设备不存在 ssjCode{}", ssjCode);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void inDispatch(DeviceSsj inSsjDevice) {
|
||||
//如果输送机空闲
|
||||
if (inSsjDevice.getKx() == 1) {
|
||||
AgvQueue agvQueue = new AgvQueue();
|
||||
agvQueue.setStatus("5");//请求放货
|
||||
agvQueue.setPositionCode2(inSsjDevice.getDeviceCode());
|
||||
List<AgvQueue> agvQueues = agvQueueService.selectAgvQueueList(agvQueue);
|
||||
//不允许放货
|
||||
if (!agvQueues.isEmpty() && inSsjDevice.getAllowPut() == 0) {
|
||||
//如果有这个输送机口的agv队列并请求放货(状态为6)
|
||||
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), "0", Integer.parseInt(agvQueues.get(0).getCtnrType()),1);
|
||||
if (i == 1) {
|
||||
log.info(inSsjDevice.getDeviceCode() + "输送机下发请求放货成功");
|
||||
}
|
||||
}
|
||||
//允许放货
|
||||
if (!agvQueues.isEmpty() && inSsjDevice.getAllowPut() == 1) {
|
||||
log.info("设备:{} 位置:{} 任务号:{} 请求放货成功", inSsjDevice.getDeviceCode(), "输送线", agvQueues.get(0).getTaskCode());
|
||||
AjaxResult ajaxResult = apiService.continueTask(agvQueues.get(0));
|
||||
if (ajaxResult.isSuccess()) {
|
||||
log.info("下发agv允许放货成功" + agvQueues.get(0).getWmsTaskNo());
|
||||
agvQueues.get(0).setStatus("6");
|
||||
agvQueueService.updateAgvQueue(agvQueues.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//入库下发输送线
|
||||
if (inSsjDevice.getKx() == 0 && inSsjDevice.getTaskNo() == 0) {
|
||||
AgvQueue agvQueue = new AgvQueue();
|
||||
agvQueue.setStatus("7"); //end
|
||||
agvQueue.setPositionCode2(inSsjDevice.getDeviceCode());
|
||||
List<AgvQueue> agvQueues = agvQueueService.selectAgvQueueList(agvQueue);
|
||||
if (!agvQueues.isEmpty()) {
|
||||
int i = writeToSsj(inSsjDevice.getPlcDbWriteAddress(), agvQueues.get(0).getWmsTaskNo(), 1,1);
|
||||
if (i == 1) {
|
||||
log.info("输送机{}下发任务号{}成功", inSsjDevice.getDeviceCode(), agvQueues.get(0).getWmsTaskNo());
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByJobId(agvQueues.get(0).getTaskCode());
|
||||
mydoJob.setExecutionPhase(TASK_EP_SSJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
agvQueueService.insertHistory(agvQueues.get(0).getReqCode());
|
||||
agvQueueService.deleteAgvQueueByReqCode(agvQueues.get(0).getReqCode());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//出库到位
|
||||
if (inSsjDevice.getDw() == 1 && inSsjDevice.getTaskNo() > 0) {
|
||||
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(inSsjDevice.getTaskNo()));
|
||||
if (mydoJob != null) {
|
||||
log.info("设备:{} 位置:{} 任务号:{} 出库到位", "输送线", inSsjDevice.getDeviceCode(), mydoJob.getTaskNo());
|
||||
mydoJobService.insertHistory(mydoJob.getJobId());
|
||||
mydoJobService.deleteMydoJobByJobId(mydoJob.getJobId());
|
||||
JobCallBack jobCallBack = new JobCallBack();
|
||||
jobCallBack.setType("2");
|
||||
jobCallBack.setMydojobId(mydoJob.getJobId());
|
||||
jobCallBack.setStatus("0");
|
||||
jobCallBack.setTaskNo(Convert.toLong(mydoJob.getTaskNo()));
|
||||
jobCallBack.setCreateTime(new Date());
|
||||
jobCallBackService.insertJobCallBack(jobCallBack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ssj.floor2;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.bas.cargospace.domain.BasCargoSpace;
|
||||
import com.ruoyi.bas.cargospace.service.IBasCargoSpaceService;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.job.domain.JobCallBack;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.agv.service.IAgvQueueService;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.queue.ddj.domain.DdjDeviceExecutionQueue;
|
||||
import com.ruoyi.queue.ddj.service.IDdjDeviceExecutionQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.ruoyi.common.TaskStatusCode.*;
|
||||
import static com.ruoyi.common.TaskType.DDJ_RWLX_1;
|
||||
import static com.ruoyi.common.TaskType.DDJ_RWLX_3;
|
||||
|
||||
/**
|
||||
* 二楼出库线程 检测当前巷道有没有入库作业,没有作业,生成堆垛机出库队列
|
||||
*/
|
||||
@Slf4j
|
||||
public class Floor2RoadWaySsjThread implements Runnable {
|
||||
|
||||
public HashMap<String, List<String>> ssjCodeList;
|
||||
private final Map<String, List<Integer>> roadwayMap = new HashMap<>();
|
||||
private IApiService apiService;
|
||||
private IAgvQueueService agvQueueService;
|
||||
private IMydoJobService mydoJobService;
|
||||
private IBasCargoSpaceService basCargoSpaceService;
|
||||
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
ssjCodeList = new HashMap<>();
|
||||
ArrayList<String> ssjCodes = new ArrayList<>();
|
||||
ssjCodes.add("L1002");
|
||||
ssjCodes.add("L1004");
|
||||
ssjCodeList.put("roadwaySsj", ssjCodes);
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
agvQueueService = SpringUtils.getBean(IAgvQueueService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
basCargoSpaceService = SpringUtils.getBean(IBasCargoSpaceService.class);
|
||||
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
|
||||
//初始化巷道口 排 列 层
|
||||
roadwayMap.put("L1002", Arrays.asList(1, 1, 1));
|
||||
roadwayMap.put("L1004", Arrays.asList(1, 1, 1));
|
||||
log.info("初始化服务 {},{}", apiService, agvQueueService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun){
|
||||
for (String type : ssjCodeList.keySet()) {
|
||||
|
||||
switch ( type){
|
||||
case "roadwaySsj":
|
||||
//生产线入库
|
||||
for (String ssjCode : ssjCodeList.get(type)) {
|
||||
try {
|
||||
if (PlcSsjRead.deviceSsjMap.containsKey(ssjCode)) {
|
||||
inDispatch(PlcSsjRead.deviceSsjMap.get(ssjCode));
|
||||
} else {
|
||||
log.error("设备不存在 ssjCode{}", ssjCode);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void inDispatch(DeviceSsj roadSsjDevice) {
|
||||
//如果到位,且任务号大于0
|
||||
if (roadSsjDevice.getDw()==1 && roadSsjDevice.getTaskNo()>0) {
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(roadSsjDevice.getTaskNo()));
|
||||
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_SSJ)) {
|
||||
mydoJob.setExecutionPhase(TASK_EP_ROADWAY_SSJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
}
|
||||
if (ObjUtil.isNotNull(mydoJob) && mydoJob.getExecutionPhase().equals(TASK_EP_ROADWAY_SSJ)) {
|
||||
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());
|
||||
ddjDeviceExecutionQueue.setRwh(Convert.toLong(mydoJob.getTaskNo()));
|
||||
ddjDeviceExecutionQueue.setDevName(mydoJob.getRoadwayId());
|
||||
ddjDeviceExecutionQueue.setDevId(Convert.toInt(mydoJob.getRoadwayId()));
|
||||
ddjDeviceExecutionQueue.setRwzt(0);
|
||||
ddjDeviceExecutionQueue.setYph(pclList.get(0));
|
||||
ddjDeviceExecutionQueue.setYlh(pclList.get(1));
|
||||
ddjDeviceExecutionQueue.setYch(pclList.get(2));
|
||||
ddjDeviceExecutionQueue.setMbph(Convert.toInt(basCargoSpace.getThePlatoon()));
|
||||
ddjDeviceExecutionQueue.setMblh(Convert.toInt(basCargoSpace.getTheColumn()));
|
||||
ddjDeviceExecutionQueue.setMbch(Convert.toInt(basCargoSpace.getTheFloor()));
|
||||
ddjDeviceExecutionQueue.setDdjxf("0");
|
||||
ddjDeviceExecutionQueue.setMlfs(5);
|
||||
ddjDeviceExecutionQueue.setScsj(DateUtil.formatDateTime(DateUtil.date()));
|
||||
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_1);
|
||||
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
|
||||
|
||||
mydoJob.setExecutionPhase(TASK_EP_DDJ);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,258 +0,0 @@
|
||||
package com.ruoyi.schedule.scheduleTask.ssj.floor2;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.api.service.IApiService;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.domain.SendData;
|
||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||
import com.ruoyi.device.ssj.domain.DeviceSsj;
|
||||
import com.ruoyi.job.domain.MydoJob;
|
||||
import com.ruoyi.job.service.IMydoJobService;
|
||||
import com.ruoyi.queue.agv.domain.AgvQueue;
|
||||
import com.ruoyi.queue.agv.service.IAgvQueueService;
|
||||
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
|
||||
import com.ruoyi.schedule.plcRead.util.Tools;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.schedule.plcRead.ssj.PlcSsjRead.deviceSsjMap;
|
||||
import static com.ruoyi.schedule.plcRead.ssj.PlcSsjRead.writeToSsj;
|
||||
|
||||
/**
|
||||
* 生产线输送机
|
||||
* 生产线线程 检测到位+托盘条码+托盘大小 请求wms生成入库作业 。 循环作业表,检测有没有出库作业 ,生成agv搬运作业。
|
||||
*/
|
||||
@Slf4j
|
||||
public class LineSsjThread implements Runnable {
|
||||
public HashMap<String, List<String>> ssjCodeList;
|
||||
|
||||
private IApiService apiService;
|
||||
private IAgvQueueService agvQueueService;
|
||||
private IMydoJobService mydoJobService;
|
||||
|
||||
public boolean isRun = true;
|
||||
|
||||
|
||||
public void init() {
|
||||
ssjCodeList = new HashMap<>();
|
||||
ArrayList<String> ssjCodes = new ArrayList<>();
|
||||
ssjCodes.add("G1005");
|
||||
ssjCodeList.put("line", ssjCodes);
|
||||
apiService = SpringUtils.getBean(IApiService.class);
|
||||
agvQueueService = SpringUtils.getBean(IAgvQueueService.class);
|
||||
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
|
||||
log.info("初始化服务 {},{}", apiService, agvQueueService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
init();
|
||||
while (isRun) {
|
||||
for (String type : ssjCodeList.keySet()) {
|
||||
|
||||
switch (type) {
|
||||
case "line":
|
||||
//生产线入库
|
||||
for (String ssjCode : ssjCodeList.get(type)) {
|
||||
try {
|
||||
if (deviceSsjMap.containsKey(ssjCode)) {
|
||||
inDispatch(deviceSsjMap.get(ssjCode));
|
||||
} else {
|
||||
log.error("设备不存在 ssjCode{}", ssjCode);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void inDispatch(DeviceSsj SsjDevice) {
|
||||
//如果到位,扫到条码,托盘大小,执行阶段卡控一下(下发输送机后改执行阶段)
|
||||
if (SsjDevice.getDw() == 1 && StrUtil.isNotBlank(SsjDevice.getTrayCode()) && SsjDevice.getTraySize() != 0 && SsjDevice.getTaskNo() < 1000) {
|
||||
log.info("设备:{} 位置:{} 条码:{} 托盘大小:{}", SsjDevice.getDeviceCode(), "产线到位", SsjDevice.getTrayCode(), SsjDevice.getTraySize());
|
||||
|
||||
//查作业,入如果已经有了,直接下发输送线
|
||||
MydoJob mydoJob = new MydoJob();
|
||||
mydoJob.setInOrOut("1");
|
||||
mydoJob.setStatus("1");
|
||||
mydoJob.setEntranceId("G1005");
|
||||
mydoJob.setExecutionPhase("0");
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectInOrOutMydoJobList(mydoJob);
|
||||
//有作业,下发输送机任务号,覆盖任务号
|
||||
if (!mydoJobs.isEmpty()) {
|
||||
|
||||
mydoJob = mydoJobs.get(0);
|
||||
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(),mydoJob.getTaskNo(),1,1);
|
||||
if (i == 1) {
|
||||
//mydoJob.setExecutionPhase(TASK_EP_AGV);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("G1005产线输送机下发任务号成功:" + mydoJob.getTaskNo());
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
//请求wms生成入库作业
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", SsjDevice.getTrayCode());
|
||||
paramMap.put("size", SsjDevice.getTraySize());
|
||||
paramMap.put("floor", "2");
|
||||
paramMap.put("entranceId", "G1005");
|
||||
AjaxResult ajaxResult = apiService.createInMydoJob(paramMap);
|
||||
if (ajaxResult.isSuccess()) {
|
||||
//拿到正常作业,插到wcs作业表,下发给输送机任务号,覆盖任务号
|
||||
MydoJob mydoJob2 = BeanUtil.toBean(ajaxResult.get("data"), MydoJob.class) ;
|
||||
mydoJob2.setStatus("1");
|
||||
mydoJob2.setExecutionPhase("0");
|
||||
mydoJob2.setCreateTime(new Date());
|
||||
|
||||
mydoJobService.insertMydoJob(mydoJob2);
|
||||
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(),mydoJob2.getTaskNo(),1,1);
|
||||
if (i == 1) {
|
||||
//mydoJob2.setExecutionPhase("1");
|
||||
mydoJobService.updateMydoJob(mydoJob2);
|
||||
log.info("G1005产线输送机下发任务号成功:{}" , mydoJob2.getTaskNo());
|
||||
}
|
||||
} else {
|
||||
//超大,给plc下发错误信息,等待人工处理
|
||||
//托盘大小对不上,给plc下发错误信息,等待人工处理
|
||||
//码不对,给plc下发错误信息,等待人工处理
|
||||
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(), "0", Integer.parseInt(ajaxResult.get("code").toString()), 2);
|
||||
if (i == 1) {
|
||||
log.info("G1005产线输送机下发错误信息成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (SsjDevice.getDw() == 1 && StrUtil.isBlank(SsjDevice.getTrayCode()) && SsjDevice.getTraySize() != 0 && SsjDevice.getTaskNo() < 1000) {
|
||||
|
||||
log.info("设备:{} 位置:{} 条码:{} 托盘大小:{}", SsjDevice.getDeviceCode(), "产线", SsjDevice.getTrayCode(), SsjDevice.getTraySize());
|
||||
//查wcs有没作业,有下发给输送机任务号,覆盖任务号
|
||||
MydoJob mydoJob = new MydoJob();
|
||||
mydoJob.setInOrOut("1");
|
||||
mydoJob.setStatus("1");
|
||||
mydoJob.setEntranceId("G1005");
|
||||
mydoJob.setExecutionPhase("0");
|
||||
List<MydoJob> mydoJobs = mydoJobService.selectInOrOutMydoJobList(mydoJob);
|
||||
if (!mydoJobs.isEmpty()) {
|
||||
mydoJob = mydoJobs.get(0);
|
||||
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(),mydoJob.getTaskNo(),1,1);
|
||||
if (i == 1) {
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
log.info("G1005产线输送机下发任务号成功:" + mydoJob.getTaskNo());
|
||||
}
|
||||
} else {
|
||||
//没有,请求错误接口,找作业,返回成功,//拿到正常作业,插到wcs作业表,下发给输送机任务号,覆盖任务号,shibai...
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("size", SsjDevice.getTraySize());
|
||||
AjaxResult ajaxResult = apiService.selectMydoJobByNoTrayCode(paramMap);
|
||||
if (ajaxResult.isSuccess()) {
|
||||
MydoJob mydoJob2 = BeanUtil.toBean(ajaxResult.get("data"), MydoJob.class);
|
||||
mydoJobService.insertMydoJob(mydoJob2);
|
||||
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(),mydoJob2.getTaskNo(),1,1);
|
||||
if (i == 1) {
|
||||
mydoJob2.setExecutionPhase("1");
|
||||
mydoJobService.updateMydoJob(mydoJob2);
|
||||
log.info("G1005产线输送机下发任务号成功:" + mydoJob2.getTaskNo());
|
||||
}
|
||||
} else if (ajaxResult.isError()) {
|
||||
//超大,给plc下发错误信息,等待人工处理
|
||||
//托盘大小对不上,给plc下发错误信息,等待人工处理
|
||||
//码不对,给plc下发错误信息,等待人工处理
|
||||
int i = writeToSsj(SsjDevice.getPlcDbWriteAddress(), "0", Integer.parseInt(ajaxResult.get("code").toString()), 2);
|
||||
if (i == 1) {
|
||||
log.info("G1005产线输送机下发错误信息成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (SsjDevice.getDw() == 1 && SsjDevice.getTaskNo() > 1000) {
|
||||
|
||||
log.info("设备:{} 位置:{} 条码:{} 托盘大小:{}", SsjDevice.getDeviceCode(), "产线收到wcs任务号", SsjDevice.getTrayCode(), SsjDevice.getTraySize());
|
||||
//任务号查wcs作业,查巷道,看目标输送线是否空闲,查是否有出库作业,生成agv队列
|
||||
|
||||
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(Convert.toLong(SsjDevice.getTaskNo()));
|
||||
String deviceCode = "";
|
||||
if (mydoJob != null) {
|
||||
if ("1".equals(mydoJob.getRoadwayId())) {
|
||||
deviceCode = "L1011";
|
||||
} else {
|
||||
deviceCode = "L1012";
|
||||
}
|
||||
int kx = deviceSsjMap.get(deviceCode).getKx();
|
||||
MydoJob mydoJobParam = new MydoJob();
|
||||
mydoJobParam.setInOut("2");
|
||||
mydoJobParam.setStatus("3");
|
||||
mydoJobParam.setExitId(deviceCode);
|
||||
List<MydoJob> outMydoJobList = mydoJobService.selectInOrOutMydoJobList(mydoJobParam);
|
||||
|
||||
|
||||
if (outMydoJobList.isEmpty() && kx == 1) {
|
||||
//查是否有队列,如果有了请求放货修改为允许放货
|
||||
AgvQueue agvQueue = agvQueueService.selectAgvQueueByTaskCode(mydoJob.getJobId());
|
||||
if (agvQueue != null){
|
||||
if ("3".equals(mydoJob.getStatus()) && "1".equals(agvQueue.getStatus())){
|
||||
AjaxResult ajaxResult = apiService.continueTask(agvQueue);
|
||||
if (ajaxResult.isSuccess()) {
|
||||
log.info("给agv下发允许取货继续任务成功"+agvQueue.getWmsTaskNo());
|
||||
agvQueue.setStatus("2");
|
||||
agvQueueService.updateAgvQueue(agvQueue);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if ("1".equals(mydoJob.getStatus())){
|
||||
HashMap<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("trayCode", mydoJob.getTrayCode());
|
||||
paramMap.put("taskNo", mydoJob.getJobId());
|
||||
paramMap.put("startPoint", "G1005");
|
||||
paramMap.put("endPoint", deviceCode);
|
||||
paramMap.put("traySize",String.valueOf(SsjDevice.getTraySize()));
|
||||
paramMap.put("wmsTaskNo", mydoJob.getTaskNo());
|
||||
AjaxResult ajaxResult = apiService.receiveAgvMoveJob(paramMap);
|
||||
if (ajaxResult.isSuccess()) {
|
||||
mydoJob.setStatus("3");
|
||||
mydoJob.setExecutionPhase(TASK_EP_AGV);
|
||||
mydoJobService.updateMydoJob(mydoJob);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user