项目初始化

This commit is contained in:
liuhanqing
2025-10-16 14:45:48 +08:00
commit 24df7ea115
791 changed files with 119486 additions and 0 deletions

View File

@@ -0,0 +1,189 @@
package com.ruoyi.schedule;
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.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;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Component
@Slf4j
public class ScheduleThread {
public CustomThread<PlcSsjRead> plcSsjReadCustomThread;
public CustomThread<PlcDdjRead> plcDdjReadCustomThread;
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;
@Autowired
private IDeviceSsjService deviceSsjService;
@Autowired
private IMsgDdjService msgDdjService;
private boolean isRun = false;
private boolean isRun2 = false;
/**
* 项目初始化启动
*/
@PostConstruct
public void init() {
log.info("初始化调度服务");
//读取信息初始化
plcReadInit();
//调度初始化
scheduleInit();
log.info("调度服务执行成功");
}
/**
* 调度初始化
*/
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);
}
/**
* plc读取初始化
*/
private void plcReadInit() {
ConcurrentHashMap<String, DeviceSsj> ssjList = new ConcurrentHashMap<>();
//获取要去取的输送机
List<DeviceSsj> deviceSsjs = deviceSsjService.selectDeviceSsjList(new DeviceSsj());
for (DeviceSsj deviceSsj : deviceSsjs) {
ssjList.put(deviceSsj.getDeviceCode(), deviceSsj);
}
//plc输送机读取线程
PlcSsjRead plcSsjRead = new PlcSsjRead(ssjList, new PlcConnectInfo("127.0.0.1", 102));
Thread plcSsjReadThread = new Thread(plcSsjRead);
plcSsjReadCustomThread = new CustomThread<PlcSsjRead>(plcSsjReadThread, plcSsjRead);
//plc堆垛机读取现场
ConcurrentHashMap<String, MsgDdj> ddjList = new ConcurrentHashMap<>();
List<MsgDdj> msgDdjs = msgDdjService.selectMsgDdjList(new MsgDdj());
for (MsgDdj msgDdj : msgDdjs) {
switch (msgDdj.getId()){
case 1:
msgDdj.setPlcDbReadAddress("DB41.0");
break;
case 2:
msgDdj.setPlcDbReadAddress("DB42.0");
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);
}
/**
* 开始线程
*/
public void startAllThread() {
plcSsjReadCustomThread.getThread().start();
plcDdjReadCustomThread.getThread().start();
isRun = true;
}
/**
* 开启线程2
*/
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();
isRun2 = true;
}
/**
* 停止线程
*/
public void stopAllThread() {
plcSsjReadCustomThread.runnable.isRun = false;
plcDdjReadCustomThread.runnable.isRun = false;
plcReadInit();
isRun = false;
}
/**
* 停止线程2
*/
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;
scheduleInit();
isRun2 = false;
}
/**
* 获取调度状态
*/
public HashMap<String,Boolean> getScheduleStatus() {
HashMap<String,Boolean> map = new HashMap<>();
map.put("isRun",isRun);
map.put("isRun2",isRun2);
return map;
}
}

View File

@@ -0,0 +1,72 @@
package com.ruoyi.schedule;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/device/operation")
public class ThreadOperationController {
@Resource
private ScheduleThread scheduleThread;
/**
* 开启plc读取线程
*
* @return
*/
@RequestMapping("/startAllThread")
//@PreAuthorize("@ss.hasPermi('device:operation:start')")
public AjaxResult startAllThread() {
scheduleThread.startAllThread();
return AjaxResult.success();
}
/**
* 开启调度线程
*
* @return
*/
@RequestMapping("/startAllThread2")
//@PreAuthorize("@ss.hasPermi('device:operation:start')")
public AjaxResult startAllThread2() {
scheduleThread.startAllThread2();
return AjaxResult.success();
}
/**
* 关闭线程
*
* @return
*/
@RequestMapping("/stopAllThread")
//@PreAuthorize("@ss.hasPermi('device:operation:stop')")
public AjaxResult stopAllThread() {
scheduleThread.stopAllThread();
return AjaxResult.success();
}
/**
* 关闭线程
*
* @return
*/
@RequestMapping("/stopAllThread2")
//@PreAuthorize("@ss.hasPermi('device:operation:stop')")
public AjaxResult stopAllThread2() {
scheduleThread.stopAllThread2();
return AjaxResult.success();
}
/**
* 获取调度状态
* @return
*/
@RequestMapping("/getScheduleStatus")
public AjaxResult getScheduleStatus() {
return AjaxResult.success(scheduleThread.getScheduleStatus());
}
}

View File

@@ -0,0 +1,143 @@
package com.ruoyi.schedule.plcRead.ddj;
import HslCommunication.BasicFramework.SoftBasic;
import HslCommunication.Core.Net.IReadWriteNet;
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import cn.hutool.core.convert.Convert;
import com.ruoyi.common.domain.HslRead;
import com.ruoyi.common.domain.PlcConnectInfo;
import com.ruoyi.device.ddj.domain.MsgDdj;
import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.schedule.plcRead.util.ParseUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class PlcDdjRead extends Thread {
public static ConcurrentHashMap<String, MsgDdj> deviceDdjMap;
public volatile boolean isRun = true;
public SiemensS7Net siemensS7Net = null;
public static IReadWriteNet readWriteNet = null;
private final String ip;
private final int port;
private boolean success = false;
public PlcDdjRead(ConcurrentHashMap<String, MsgDdj> deviceDdjMap, PlcConnectInfo plcConnectInfo) {
PlcDdjRead.deviceDdjMap = deviceDdjMap;
this.ip = plcConnectInfo.getIp();
this.port = plcConnectInfo.getPort();
}
public static int WriteToSSJ(String address, byte[] data) {
int a = 0;
if (readWriteNet != null) {
a = HslRead.WriteResultRender(readWriteNet.Write(address, data), address);
}
return a;
}
@Override
public void run() {
while (isRun) {
try {
if (IsConnect()) {
for (String key : deviceDdjMap.keySet()) {
MsgDdj msgDdj = deviceDdjMap.get(key);
if (msgDdj != null) {
readPlcDdj(msgDdj);
}
}
Thread.sleep(1000);
} else {
reConnect();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
log.info("********IP:" + this.ip + " port:" + this.port + "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣 " + e.getMessage());
}
}
}
private void readPlcDdj(MsgDdj msgDdj) {
OperateResultExOne<byte[]> read2 = readWriteNet.Read(msgDdj.getPlcDbReadAddress(), Convert.toShort("38"));
String ddsx = "0";
if (read2.IsSuccess) {
ddsx = SoftBasic.ByteToHexString(read2.Content);
msgDdj.setCzfs(ParseUtil.optInt(0, ddsx));
msgDdj.setSbzt(ParseUtil.optInt(2, ddsx));
msgDdj.setRwh(Convert.toLong(ParseUtil.optDInt(4, ddsx)));
msgDdj.setHczt(ParseUtil.optInt(8, ddsx));
msgDdj.setJdbz(ParseUtil.optInt(10, ddsx));
msgDdj.setYph(ParseUtil.optInt(12, ddsx));
msgDdj.setYlh(ParseUtil.optInt(14, ddsx));
msgDdj.setYch(ParseUtil.optInt(16, ddsx));
msgDdj.setMbph(ParseUtil.optInt(18, ddsx));
msgDdj.setMblh(ParseUtil.optInt(20, ddsx));
msgDdj.setMbch(ParseUtil.optInt(22, ddsx));
msgDdj.setYxxf(ParseUtil.optInt(24, ddsx));
msgDdj.setXtxh(ParseUtil.optInt(26, ddsx));
}
}
void ConnectServer() {
siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500);
try {
siemensS7Net.setIpAddress(this.ip);
siemensS7Net.setPort(this.port);
siemensS7Net.setRack((byte) 0);
siemensS7Net.setSlot((byte) 1);
OperateResult connect = siemensS7Net.ConnectServer();
if (connect.IsSuccess) {
setIsConnect(true);
readWriteNet = siemensS7Net;
}
} catch (Exception ex) {
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage());
}
}
public void setIsConnect(boolean bflag) {
if (!success) {
success = bflag;
}
}
public boolean IsConnect() {
if (success) {
return success;
}
return false;
}
void reConnect() {
closeServer();
ConnectServer();
log.info("重新连接 SSJ-PLC");
}
void closeServer() {
if (readWriteNet != null) {
readWriteNet.ConnectClose();
}
setIsConnect(false);
}
public static int WriteToDDJ(String address, byte[] data) {
int a = 0;
if (readWriteNet != null) {
a = HslRead.WriteResultRender(readWriteNet.Write(address, data), address);
}
return a;
}
}

View File

@@ -0,0 +1,236 @@
package com.ruoyi.schedule.plcRead.ssj;
import HslCommunication.BasicFramework.SoftBasic;
import HslCommunication.Core.Net.IReadWriteNet;
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.Profinet.Siemens.SiemensPLCS;
import HslCommunication.Profinet.Siemens.SiemensS7Net;
import com.ruoyi.common.domain.SendData;
import com.ruoyi.device.ddj.domain.MsgDdj;
import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.common.domain.HslRead;
import com.ruoyi.common.domain.PlcConnectInfo;
import com.ruoyi.schedule.plcRead.util.ParseUtil;
import com.ruoyi.schedule.plcRead.util.Tools;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
public class PlcSsjRead implements Runnable {
public static ConcurrentHashMap<String, DeviceSsj> deviceSsjMap;
public volatile boolean isRun = true;
public SiemensS7Net siemensS7Net = null;
public static IReadWriteNet readWriteNet = null;
private final String ip;
private final int port;
private boolean success = false;
public PlcSsjRead(ConcurrentHashMap<String, DeviceSsj> deviceSsjMap, PlcConnectInfo plcConnectInfo) {
PlcSsjRead.deviceSsjMap = deviceSsjMap;
this.ip = plcConnectInfo.getIp();
this.port = plcConnectInfo.getPort();
}
public static int WriteToSSJ(String address, byte[] data) {
int a = 0;
if (readWriteNet != null) {
a = HslRead.WriteResultRender(readWriteNet.Write(address, data), address);
}
return a;
}
@Override
public void run() {
while (isRun) {
try {
if (IsConnect()) {
int step = 20;
int baseOffset = 0;
for (String ssjCode : deviceSsjMap.keySet()) {
DeviceSsj ssjDevice = deviceSsjMap.get(ssjCode);
switch (ssjDevice.getType()) {
case "1":
readPlcLineSsj(ssjDevice);
break;
case "2":
readPlcInOutSsj(ssjDevice);
break;
case "3":
readPlcOtherSsj(ssjDevice);
break;
case "4":
readPlcRoadWaySsj(ssjDevice);
break;
}
}
Thread.sleep(1000);
} else {
reConnect();
}
} catch (InterruptedException e) {
// 捕获中断异常,退出循环
Thread.currentThread().interrupt(); // 重新设置中断标志
return;
} catch (Exception e) {
log.info("********IP:" + this.ip + " port:" + this.port + "读取数据异常 " + e.getMessage());
}
}
}
/**
* 其他输送机
*
* @param ssjDevice
*/
private void readPlcOtherSsj(DeviceSsj ssjDevice) {
OperateResultExOne<byte[]> read2 = readWriteNet.Read(ssjDevice.getPlcDbReadAddress(), Short.parseShort("20"));
String ddsx1 = "0";
if (read2.IsSuccess) {
ddsx1 = SoftBasic.ByteToHexString(read2.Content);
ssjDevice.setKx(ParseUtil.optInt(0, ddsx1));
ssjDevice.setDw(ParseUtil.optInt(2, ddsx1));
ssjDevice.setTaskNo(ParseUtil.optDInt(6, ddsx1));
}
}
/**
* 巷道输送机
*
* @param ssjDevice
*/
private void readPlcRoadWaySsj(DeviceSsj ssjDevice) {
OperateResultExOne<byte[]> read2 = readWriteNet.Read(ssjDevice.getPlcDbReadAddress(), Short.parseShort("20"));
String ddsx1 = "0";
if (read2.IsSuccess) {
ddsx1 = SoftBasic.ByteToHexString(read2.Content);
ssjDevice.setKx(ParseUtil.optInt(0, ddsx1));
ssjDevice.setDw(ParseUtil.optInt(2, ddsx1));
ssjDevice.setRkqq(ParseUtil.optInt(4, ddsx1));
ssjDevice.setTaskNo(ParseUtil.optDInt(6, ddsx1));
}
}
/**
* 入出库输送机
*
* @param ssjDevice
*/
private void readPlcInOutSsj(DeviceSsj ssjDevice) {
OperateResultExOne<byte[]> read2 = readWriteNet.Read(ssjDevice.getPlcDbReadAddress(), Short.parseShort("20"));
String ddsx1 = "0";
if (read2.IsSuccess) {
ddsx1 = SoftBasic.ByteToHexString(read2.Content);
ssjDevice.setKx(ParseUtil.optInt(0, ddsx1));
ssjDevice.setDw(ParseUtil.optInt(2, ddsx1));
ssjDevice.setException(ParseUtil.optInt(4, ddsx1));
ssjDevice.setAllowPut(ParseUtil.optInt(6, ddsx1));
ssjDevice.setTaskNo(ParseUtil.optDInt(8, ddsx1));
}
}
/**
* 产线输送机
*
* @param ssjDevice
*/
private void readPlcLineSsj(DeviceSsj ssjDevice) {
OperateResultExOne<byte[]> read2 = readWriteNet.Read(ssjDevice.getPlcDbReadAddress(), Short.parseShort("220"));
String ddsx1 = "0";
if (read2.IsSuccess) {
ddsx1 = SoftBasic.ByteToHexString(read2.Content);
ssjDevice.setKx(ParseUtil.optInt(0, ddsx1));
ssjDevice.setDw(ParseUtil.optInt(2, ddsx1));
ssjDevice.setRkqq(ParseUtil.optInt(4, ddsx1));
ssjDevice.setTraySize(ParseUtil.optInt(6, ddsx1));
ssjDevice.setTaskNo(ParseUtil.optDInt(8, ddsx1));
String trayCodeReadAddress="";
switch (ssjDevice.getDeviceCode()){
case "G1005":
trayCodeReadAddress = "DB502.0";
break;
case "L2012":
trayCodeReadAddress = "DB503.0";
break;
case "L2013":
trayCodeReadAddress = "DB504.0";
break;
}
OperateResultExOne<byte[]> trayCodeRead = readWriteNet.Read(trayCodeReadAddress, Short.parseShort("220"));
if (trayCodeRead.IsSuccess){
byte[] content = trayCodeRead.Content;
//去除bytes中
ssjDevice.setTrayCode(ParseUtil.filterAndConvert(trayCodeRead.Content));
}
}
}
void ConnectServer() {
siemensS7Net = new SiemensS7Net(SiemensPLCS.S1500);
try {
siemensS7Net.setIpAddress(this.ip);
siemensS7Net.setPort(this.port);
siemensS7Net.setRack((byte) 0);
siemensS7Net.setSlot((byte) 1);
OperateResult connect = siemensS7Net.ConnectServer();
if (connect.IsSuccess) {
setIsConnect(true);
readWriteNet = siemensS7Net;
}
} catch (Exception ex) {
log.info("********IP:" + this.ip + " port:" + this.port + "连接失败 " + ex.getMessage());
}
}
public void setIsConnect(boolean bflag) {
if (!success) {
success = bflag;
}
}
public boolean IsConnect() {
if (success) {
return success;
}
return false;
}
void reConnect() {
closeServer();
ConnectServer();
log.info("重新连接 SSJ-PLC");
}
void closeServer() {
if (readWriteNet != null) {
readWriteNet.ConnectClose();
}
setIsConnect(false);
}
public static int writeToSsj(String address, String taskNo, int qx , int completed) {
int jym = Tools.getJYM(Integer.parseInt(taskNo), qx, completed);
SendData taskNoSendData = new SendData(Tools.INT, taskNo);
SendData qxSendData = new SendData(Tools.INT, qx);
SendData completedSendData = new SendData(Tools.INT, completed);
SendData jymSendData = new SendData(Tools.INT, jym);
byte[] bytes = Tools.sendData(taskNoSendData, qxSendData, completedSendData, jymSendData);
return PlcSsjRead.WriteToSSJ(address, bytes);
}
}

View File

@@ -0,0 +1,80 @@
package com.ruoyi.schedule.plcRead.util;
import HslCommunication.BasicFramework.SoftBasic;
/**
* @author zn kai
* @create 2021-06-28 14:04
*/
public class ParseUtil {
/**
* short 16λתint
* @param start
* @param data
* @return
*/
public static int optInt(int start, String data) {
return Integer.parseInt(data.substring(start * 2, (start + 2) * 2), 16);
}
/**
* int 16λתint
* @param start
* @param data
* @return
*/
public static int optDInt(int start, String data) {
return Integer.parseInt(data.substring(start * 2, (start + 4) * 2), 16);
}
/**
* long 16λתlong
* @param start
* @param data
* @return
*/
public static Long optLong(int start, String data) {
return Long.parseLong(data.substring(start * 2, (start + 8) * 2), 16);
}
/**
* string 16λתstring
* @param start
* @param data
* @return
*/
public static String optString(int start, String data) {
byte[] bytes = SoftBasic.HexStringToBytes(data.substring(start * 2, (start + 7) * 2));
return Tools.bytetostringtool(bytes);
}
/**
* 过滤ASCII数组中的无效字符,只保留可打印字符(32-126)
* @param asciiArray 原始ASCII码数组
* @return 转换后的字符串
*/
public static String filterAndConvert(byte[] asciiArray) {
if (asciiArray == null) {
return "";
}
StringBuilder sb = new StringBuilder();
for (int code : asciiArray) {
// 只保留可打印ASCII字符(32-空格到126-~)
if (code >= 32 && code <= 126) {
sb.append((char) code);
}
}
return sb.toString();
}
}

View File

@@ -0,0 +1,403 @@
package com.ruoyi.schedule.plcRead.util;
import HslCommunication.BasicFramework.SoftBasic;
import com.ruoyi.common.domain.SendData;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
/**
* 描述:cyc16校验码
*
* @author zhu
*/
public class Tools implements Serializable {
public static int Debug = 0x20;
public final static int DEBUG_CONVERSIONS = 0x1000;
public static final int DINT = 4;
public static final int INT = 2;
public static void main(String[] arg) {
int jym = getJYM(1, 2, 3);
System.out.println(jym);
}
/*4、CRC-16校验码计算方法:
常用查表法和计算法。计算方法一般都是:
(1)、预置1个16位的寄存器为十六进制FFFF(即全为1),称此寄存器为CRC寄存器;
(2)、把第一个8位二进制数据(既通讯信息帧的第一个字节)与16位的CRC寄存器的低
8位相异或,把结果放于CRC寄存器,高八位数据不变;
(3)、把CRC寄存器的内容右移一位(朝低位)用0填补最高位,并检查右移后的移出位;
(4)、如果移出位为0:重复第3步(再次右移一位);如果移出位为1,CRC寄存器与多
项式A001(1010 0000 0000 0001)进行异或;
(5)、重复步骤3和4,直到右移8次,这样整个8位数据全部进行了处理;
(6)、重复步骤2到步骤5,进行通讯信息帧下一个字节的处理;
(7)、将该通讯信息帧所有字节按上述步骤计算完成后,得到的16位CRC寄存器的高、低
字节进行交换;
(8)、最后得到的CRC寄存器内容即为:CRC码。
以上计算步骤中的多项式A001是8005按位颠倒后的结果。
查表法是将移位异或的计算结果做成了一个表,就是将0~256放入一个长度为16位的寄存器中的低八位,高八位填充0,然后将该寄存器与多项式0XA001按照上述3、4步骤,直到八位全部移出,最后寄存器中的值就是表格中的数据,高八位、低八位分别单独一个表。*/
/**
* 全部校验码可用这个获取
*
* @param ints 传入的校验码
* @return 返回的int
*/
public static int getJYM(int... ints) {
//将整形任务号转为32位,能后转为四个字节,最后转为整形组4
int[] ints1 = new int[ints.length * 4];
for (int i = 0; i < ints.length; i++) {
int[] son;
son = binaryTints(printBits(ints[i]));
for (int j = 0; j < 4; j++) {
int s = j + i * 4;
ints1[s] = son[j];
System.out.println(Arrays.toString(ints1));
}
}
int a = 0;
for (int j : ints1) {
a = a + j;
}
return a;
}
/**
* @param hex 字符串
* @return a 整型
*/
public static int[] binaryTints(String hex) {
int[] a = new int[4];
String hexString = change32(hex);
a[0] = Integer.parseInt(hexString.substring(0, 8), 2);//将
a[1] = Integer.parseInt(hexString.substring(8, 16), 2);
a[2] = Integer.parseInt(hexString.substring(16, 24), 2);
a[3] = Integer.parseInt(hexString.substring(24, 32), 2);
return a;
}
public static int[] binaryTints16(String hex) {
int[] a = new int[2];
String hexString = change16(hex);
a[0] = Integer.parseInt(hexString.substring(0, 8), 2);//将二进制字符串转为整形
a[1] = Integer.parseInt(hexString.substring(8, 16), 2);
return a;
}
public static int binaryTints8(String hex) {
int a;
String hexString = change8(hex);
a = Integer.parseInt(hexString.substring(0, 8), 2);//将二进制字符串转为整形
return a;
}
public static int BytesToInt(int[] ss) {
if (ss != null) {
StringBuilder lString = new StringBuilder();
for (int s : ss) {
lString.append(change8(printBits(s)));
}
return Integer.parseInt(lString.toString(), 2);
} else {
return 0;
}
}
/**
* 将字符转为整形
**/
public static int showAscii(char x) {
return x;
}
/**
* 将整形转为字符
**/
public static char showChar(int x) {
return (char) x;
}
/**
* 托盘条码解析
**/
public static String byteToStringTool(byte[] aaa) {
StringBuilder builder = new StringBuilder();
for (byte b : aaa) {
String x = Character.toString(showChar(b));
builder.append(x);
}
return builder.toString();
}
/**
* 将整形转为二进制字符串
*/
public static String printBits(int n) {
return Integer.toBinaryString(n);
}
/**
* 将整形转为浮点型
*/
public static Float printFloat(int n) {
return Float.intBitsToFloat(n);
}
/**
* 不满8位加高位加0
**/
public static String change8(String value) {
if (value != null && !value.equals("")) {
StringBuilder ss = new StringBuilder(value);
for (int i = 0; i < 8 - value.length(); i++) {
ss.insert(0, "0");
}
return ss.toString();
} else {
return "00000000";
}
}
/**
* 不满32位加高位加0 4个字节
**/
public static String change32(String value) {
if (value != null && !value.equals("")) {
StringBuilder ss = new StringBuilder(value);
for (int i = 0; i < 32 - value.length(); i++) {
ss.insert(0, "0");
}
return ss.toString();
} else {
return "00000000000000000000000000000000";
}
}
/**
* 不满16位加高位加0 4个字节
**/
public static String change16(String value) {
if (value != null && !value.equals("")) {
StringBuilder ss = new StringBuilder(value);
for (int i = 0; i < 16 - value.length(); i++) {
ss.insert(0, "0");
}
return ss.toString();
} else {
return "0000000000000000";
}
}
///字节转整型
public static int get(byte a1, byte a2, byte a3, byte a4, byte a5, byte a6, byte a7, byte a8,
byte a9, byte a10, byte a11, byte a12, byte a13, byte a14, byte a15, byte a16,
byte a17, byte a18, byte a19, byte a20, byte a21, byte a22, byte a23, byte a24, byte a25) {
int[] ints = new int[25];
ints[0] = binaryTints8(printBits(a1));
ints[1] = binaryTints8(printBits(a2));
ints[2] = binaryTints8(printBits(a3));
ints[3] = binaryTints8(printBits(a4));
ints[4] = binaryTints8(printBits(a5));
ints[5] = binaryTints8(printBits(a6));
ints[6] = binaryTints8(printBits(a7));
ints[7] = binaryTints8(printBits(a8));
ints[8] = binaryTints8(printBits(a9));
ints[9] = binaryTints8(printBits(a10));
ints[10] = binaryTints8(printBits(a11));
ints[11] = binaryTints8(printBits(a12));
ints[12] = binaryTints8(printBits(a13));
ints[13] = binaryTints8(printBits(a14));
ints[14] = binaryTints8(printBits(a15));
ints[15] = binaryTints8(printBits(a16));
ints[16] = binaryTints8(printBits(a17));
ints[17] = binaryTints8(printBits(a18));
ints[18] = binaryTints8(printBits(a19));
ints[19] = binaryTints8(printBits(a20));
ints[20] = binaryTints8(printBits(a21));
ints[21] = binaryTints8(printBits(a22));
ints[22] = binaryTints8(printBits(a23));
ints[23] = binaryTints8(printBits(a24));
ints[24] = binaryTints8(printBits(a25));
for (int anInt : ints) {
System.out.print(anInt + " ");
}
System.out.println();
return BytesToInt(ints);
}
//
public static byte[] int2byte(int res) {///Java中10进制转byte[]
byte[] targets = new byte[4];
targets[3] = (byte) (res & 0xff);// 最低位
targets[2] = (byte) ((res >> 8) & 0xff);// 次低位
targets[1] = (byte) ((res >> 16) & 0xff);// 次高位
targets[0] = (byte) (res >>> 24);// 最高位,无符号右移。
return targets;
}
/**
* 多个byte 合并成一个byte
*/
public static byte[] byteMerge(byte[]... values) {
int length_byte = 0;
for (byte[] value : values) {
length_byte += value.length;
}
byte[] all_byte = new byte[length_byte];
int countLength = 0;
for (byte[] b : values) {
System.arraycopy(b, 0, all_byte, countLength, b.length);
countLength += b.length;
}
return all_byte;
}
/** ???????????**/
public static String bytetostringtool(byte[] aaa) {
String tptm = "";
for(int i=0;i<aaa.length;i++){
//System.out.println("??????:for:"+aaa[i]);
String x = Character.toString(showChar(aaa[i]));
char ddd=showChar(aaa[i]);
tptm=tptm+x;
//System.out.println(tptm);
}
if(tptm.length() == 0 || tptm.equals("")){
return "00000000";
}else {
return tptm;
}
}
/**
* int 转byte
*/
public static byte[] intToBytes(int value, int len) {
byte[] b = new byte[len];
for (int i = 0; i < len; i++) {
b[len - i - 1] = (byte) ((value >> 8 * i) & 0xff);
}
return b;
}
//下发字节数组
public static byte[] sendDataToDevice(long taskNo,String trayCode, int...ints){
int length = 0;
byte[] xfData = null;
if (trayCode == null){
length = 4 + (ints.length * 2);
xfData = new byte[length];
byte[] RWH = new byte[4];
RWH = Tools.int2byte((int) taskNo);
for (int i = 0; i < length; i++){
if (i < 4){
xfData[i] = RWH[i];
} else {
if (i % 2 == 0){
byte[] param = new byte[2];
param = intbyte(ints[(i - 4) / 2]);
xfData[i] = param[0];
xfData[i + 1] = param[1];
}
}
}
} else {
length = 12 + (ints.length * 2);
xfData = new byte[length];
byte[] RWH = new byte[4];
RWH = Tools.int2byte((int) taskNo);
byte[] tCode = new byte[8];
if ("".equals(trayCode)){
for (int i = 0;i < tCode.length;i++){
tCode[i] = 0;
}
}else {
byte[] code = trayCode.getBytes();
for (int i = 0; i < tCode.length; i++) {
tCode[i] = code[i];
}
}
for (int i = 0; i< length; i++){
if (i < 4){
xfData[i] = RWH[i];
} else if (i > 3 && i< 12) {
xfData[i] = tCode[i - 4];
} else {
if (i % 2 == 0){
byte[] param = new byte[2];
param = intbyte(ints[(i - 12) / 2]);
xfData[i] = param[0];
xfData[i + 1] = param[1];
}
}
}
}
return xfData;
}
/**
* 字节数组转字符船
*/
public static String byteToString(String substring) {
return new String(SoftBasic.HexStringToBytes(substring), StandardCharsets.UTF_8);
}
public static String getDate() {
Date t = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return df.format(t);
}
/**
* 下发到PLC的反馈字节
*/
public static byte[] sendData(SendData... list) {
byte[][] values = new byte[list.length][0];
for (int i = 0; i < list.length; i++) {
byte[] bytes = Tools.intToBytes(list[i].getNum2(), list[i].getNum());
//System.out.println(bytes.length);
values[i] = bytes;
}
int length_byte = 0;
for (byte[] value : values) {
length_byte += value.length;
}
byte[] all_byte = new byte[length_byte];
int countLength = 0;
for (byte[] b : values) {
System.arraycopy(b, 0, all_byte, countLength, b.length);
countLength += b.length;
}
return all_byte;
}
//int 转2字节
public static byte[] intbyte(int res) {///Java中10进制转byte[]
byte[] targets = new byte[2];
targets[1] = (byte) ((res >> 0) & 0xff);// 次高位
targets[0] = (byte) (res >>> 8);// 最高位,无符号右移。
return targets;
}
public static int[] binarysToints(String hex){
int[] a = new int[4];
String hexString = change32(hex);
a[0] = Integer.parseInt(hexString.substring(0,8),2);//将二进制字符串转为整形
a[1] = Integer.parseInt(hexString.substring(8,16),2);
a[2] = Integer.parseInt(hexString.substring(16,24),2);
a[3] = Integer.parseInt(hexString.substring(24,32),2);
return a;
}
}

View File

@@ -0,0 +1,150 @@
package com.ruoyi.schedule.scheduleTask.agv;
import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpUtil;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class AgvDispatch {
// 基础URL
private final String baseUrl;
// 客户端编号
private String clientCode;
// 令牌号
private String tokenCode;
public AgvDispatch(String ip, int port) {
this.baseUrl = String.format("http://%s:%d/rcms/services/rest", ip, port);
}
public AgvDispatch(String baseUrl) {
this.baseUrl = baseUrl;
}
/**
* 生成唯一请求编号
*/
private String generateReqCode() {
return IdUtil.fastSimpleUUID();
}
// ------------------------------ 常用接口 ------------------------------
/**
* 2.1.1 生成任务单
* @param taskTyp 任务类型
* @param wbCode 工作位
* @param positionCodePath 位置路径
* @param podCode 货架编号
* @return 接口返回结果
*/
public String genAgvSchedulingTask(String taskTyp, String wbCode,
Object[] positionCodePath, String podCode) throws IOException {
String url = baseUrl + "/hikRpcService/genAgvSchedulingTask";
Map<String, Object> params = new HashMap<>();
params.put("taskTyp", taskTyp);
params.put("wbCode", wbCode);
params.put("positionCodePath", positionCodePath);
params.put("podCode", podCode);
return HttpUtil.post(url, params);
}
/**
* 2.1.2 继续执行任务
* @param taskCode 任务单号
* @return 接口返回结果
*/
public String continueTask(String taskCode) throws IOException {
String url = baseUrl + "/hikRpcService/continueTask";
Map<String, Object> params = new HashMap<>();
params.put("taskCode", taskCode);
return HttpUtil.post(url, params);
}
/**
* 2.1.3 取消任务
* @param taskCode 任务单号
* @param forceCancel 取消类型(0-直接放地上,1-软取消)
* @return 接口返回结果
*/
public String cancelTask(String taskCode, String forceCancel) throws IOException {
String url = baseUrl + "/hikRpcService/cancelTask";
Map<String, Object> params = new HashMap<>();
params.put("taskCode", taskCode);
params.put("forceCancel", forceCancel);
return HttpUtil.post(url, params);
}
// ------------------------------ 可选接口 ------------------------------
/**
* 3.1.1 任务优先级设置
* @param priorities 优先级列表
* @return 接口返回结果
*/
public String setTaskPriority(Object[] priorities) throws IOException {
String url = baseUrl + "/hikRpcService/setTaskPriority";
Map<String, Object> params = new HashMap<>();
params.put("priorities", priorities);
return HttpUtil.post(url, params);
}
/**
* 3.1.2 货架与位置绑定、解绑
* @param podCode 货架编号
* @param positionCode 位置编号
* @param indBind 1-绑定,0-解绑
* @return 接口返回结果
*/
public String bindPodAndBerth(String podCode, String positionCode, String indBind) throws IOException {
String url = baseUrl + "/hikRpcService/bindPodAndBerth";
Map<String, Object> params = new HashMap<>();
params.put("podCode", podCode);
params.put("positionCode", positionCode);
params.put("indBind", indBind);
return HttpUtil.post(url, params);
}
/**
* 3.1.9 查询任务状态
* @param taskCodes 任务单编号数组
* @return 接口返回结果
*/
public String queryTaskStatus(String[] taskCodes) throws IOException {
String url = baseUrl + "/hikRpcService/queryTaskStatus";
Map<String, Object> params = new HashMap<>();
params.put("taskCodes", taskCodes);
return HttpUtil.post(url, params);
}
/**
* 3.1.10 查询AGV状态
* @param mapCode 地图编号
* @return 接口返回结果
*/
public String queryAgvStatus(String mapCode) throws IOException {
String url = "http://" + baseUrl.split("//")[1].split("/")[0] + "/rcms-dps/rest/queryAgvStatus";
Map<String, Object> params = new HashMap<>();
params.put("mapCode", mapCode);
return HttpUtil.post(url, params);
}
/**
* 3.1.16 料箱出库TPS(CTU+分拨墙)
* @param taskTyp 任务类型(传1)
* @param data 任务数据列表
* @return 接口返回结果
*/
public String getOutPod(String taskTyp, Object[] data) throws IOException {
String url = baseUrl + "/hikTpsService/getOutPod";
Map<String, Object> params = new HashMap<>();
params.put("taskTyp", taskTyp);
params.put("data", data);
return HttpUtil.post(url, params);
}
}

View File

@@ -0,0 +1,257 @@
package com.ruoyi.schedule.scheduleTask.ddj;
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 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.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.ArrayList;
import java.util.HashMap;
import java.util.List;
@Slf4j
public class Ddj1Thread implements Runnable {
public HashMap<String, List<String>> ddjCodeList;
private IApiService apiService;
private IDdjDeviceExecutionQueueService ddjDeviceExecutionQueueService;
private IDdjDeviceExecutionQueueFinishService ddjDeviceExecutionQueueFinishService;
private IMydoJobService mydoJobService;
public boolean isRun = true;
public void init() {
//todo 获取设备编码列表
ddjCodeList = new HashMap<>();
ArrayList<String> ddjCodes = new ArrayList<>();
ddjCodes.add("ddj1");
ddjCodes.add("ddj2");
ddjCodeList.put("ddj", ddjCodes);
apiService = SpringUtils.getBean(IApiService.class);
ddjDeviceExecutionQueueService = SpringUtils.getBean(IDdjDeviceExecutionQueueService.class);
ddjDeviceExecutionQueueFinishService = SpringUtils.getBean(IDdjDeviceExecutionQueueFinishService.class);
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService,mydoJobService);
}
@Override
public void run() {
init();
while (isRun) {
for (String type : ddjCodeList.keySet()) {
if ("ddj".equals(type)) {
for (String ddjCode : ddjCodeList.get(type)) {
try {
if (PlcDdjRead.deviceDdjMap.containsKey(ddjCode)) {
ddjTask(PlcDdjRead.deviceDdjMap.get(ddjCode));
} else {
log.error("设备不存在 ssjCode{}", ddjCode);
}
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
}
}
}
}
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
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());
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);
if ("0".equals(mydoJob.getFaultFlag())){
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);
}
}
}
/*
第四部分
取货无货,重新分配单据
*/
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 && ddj.getSbzt() == 0) {
Long rwh = ddj.getRwh();
//对堆垛机执行队列中无已下发队列
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
ddjDeviceExecutionQueueParam.setDdjxf("1");
ddjDeviceExecutionQueueParam.setDevId(ddj.getId());
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionQueueParam);
//取堆垛机队列中,生成时间最早的执行队列下发
if (CollUtil.isEmpty(ddjDeviceExecutionQueues)) {
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
if (ddjDeviceExecutionQueue == null) {
return;
}
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:{}", rwh);
} 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 = 5;
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);
}
}
}

View File

@@ -0,0 +1,48 @@
package com.ruoyi.schedule.scheduleTask.monit;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.device.ddj.service.IMsgDdjService;
import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.device.ssj.service.IDeviceSsjService;
import com.ruoyi.schedule.plcRead.ddj.PlcDdjRead;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
import lombok.extern.slf4j.Slf4j;
/**
* 监控线程
*/
@Slf4j
public class MonitoringThread implements Runnable {
public boolean isRun = true;
private IDeviceSsjService deviceSsjService;
private IMsgDdjService msgDdjService;
public void init() {
deviceSsjService = SpringUtils.getBean(IDeviceSsjService.class);
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
}
@Override
public void run() {
init();
while (isRun){
for (String ssjCode : PlcSsjRead.deviceSsjMap.keySet()) {
DeviceSsj deviceSsj = PlcSsjRead.deviceSsjMap.get(ssjCode);
deviceSsjService.updateDeviceSsj(deviceSsj);
}
for (String ddjCode : PlcDdjRead.deviceDdjMap.keySet()) {
msgDdjService.updateMsgDdj(PlcDdjRead.deviceDdjMap.get(ddjCode));
}
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}

View File

@@ -0,0 +1,230 @@
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()));
}
}
}
}
}
}
}

View File

@@ -0,0 +1,182 @@
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);
}
}
}
}
}

View File

@@ -0,0 +1,194 @@
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);
}
}
}
}
}
}

View File

@@ -0,0 +1,155 @@
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);
}
}
}
}

View File

@@ -0,0 +1,139 @@
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);
}
}
}
}
}

View File

@@ -0,0 +1,258 @@
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);
}
}
}
}
}
}
}
}