fix:修复联调测试出现的问题
This commit is contained in:
@@ -34,7 +34,8 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
DeviceAppService deviceAppService;
|
||||
@Autowired
|
||||
ParamService paramService;
|
||||
private final AcsToWmsService acsToWmsService;
|
||||
@Autowired
|
||||
AcsToWmsService acsToWmsService;
|
||||
|
||||
private final DeviceExecuteLogService logServer;
|
||||
|
||||
|
||||
@@ -191,8 +191,8 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
} else {
|
||||
//上报异常信息
|
||||
//(不需要WCS反馈)
|
||||
if (phase == 0x67) {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[27]));
|
||||
if (phase == 0x67 || phase == 0x70 || phase == 0x71 || phase == 0x72 || phase == 0x73 || phase == 0x74 || phase == 0x50 || phase == 0x51 ) {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[18] * 256 + arr[19]));
|
||||
} else {
|
||||
device = deviceAppService.findDeviceByCode(Integer.toString(arr[20]));
|
||||
}
|
||||
|
||||
@@ -3,16 +3,21 @@ package org.nl.acs.device_driver.basedriver.agv.ndcone;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.AcsConfig;
|
||||
import org.nl.acs.agv.server.NDCAgvService;
|
||||
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
|
||||
import org.nl.acs.device.service.DeviceService;
|
||||
import org.nl.acs.device_driver.DeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.agv.utils.ErrorUtil;
|
||||
import org.nl.acs.device_driver.basedriver.agv.utils.OneAgvPhase;
|
||||
import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.standard_inspect_site.StandardInspectSiteDeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDeviceDriver;
|
||||
import org.nl.acs.device_driver.driver.AbstractDeviceDriver;
|
||||
@@ -24,6 +29,7 @@ import org.nl.acs.instruction.service.impl.InstructionServiceImpl;
|
||||
import org.nl.acs.log.LokiLog;
|
||||
import org.nl.acs.log.LokiLogType;
|
||||
import org.nl.acs.log.service.DeviceExecuteLogService;
|
||||
import org.nl.acs.monitor.DeviceStageMonitor;
|
||||
import org.nl.acs.opc.Device;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
@@ -43,7 +49,7 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements DeviceDriver {
|
||||
public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements DeviceDriver, DeviceStageMonitor {
|
||||
|
||||
ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class);
|
||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class);
|
||||
@@ -53,6 +59,9 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
|
||||
DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class);
|
||||
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
|
||||
|
||||
OneAgvPhase oneAgvPhase = new OneAgvPhase();
|
||||
|
||||
int agvaddr = 0;
|
||||
int agvaddr_copy = 0;
|
||||
int weight = 0;
|
||||
@@ -73,6 +82,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
int last_status = 0;
|
||||
int last_error = 0;
|
||||
|
||||
String error_code = "0";
|
||||
String error_message = "";
|
||||
String message = "";
|
||||
private Instruction instruction;
|
||||
String order = "";
|
||||
|
||||
int mode = 2;
|
||||
|
||||
@LokiLog(type = LokiLogType.ACS_TO_LMS)
|
||||
public synchronized void processSocket(int[] arr) throws Exception {
|
||||
device_code = this.getDeviceCode();
|
||||
@@ -89,15 +106,16 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
Instruction link_inst = null;
|
||||
List<Instruction> insts = null;
|
||||
Instruction inst = null;
|
||||
boolean wcsFlag = false;
|
||||
boolean wmsFlag = false;
|
||||
boolean link_flag = false;
|
||||
Device agv_device = null;
|
||||
if (carno != 0) {
|
||||
agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno));
|
||||
}
|
||||
if (ikey != 0) {
|
||||
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
|
||||
if (ObjectUtil.isEmpty(inst)) {
|
||||
inst = instructionService.findByCode(String.valueOf(ikey));
|
||||
if (phase != 0x67 && phase != 0x71 && phase != 0x72 && phase != 0x73 && phase != 0x74 && phase != 0x75) {
|
||||
inst = instructionService.findByCodeFromCache(String.valueOf(ikey));
|
||||
this.instruction = inst;
|
||||
}
|
||||
if(ObjectUtil.isNotEmpty(inst)) {
|
||||
order = inst.getTask_code();
|
||||
}
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(link_inst)) {
|
||||
@@ -109,24 +127,14 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
String emptyNum = null;
|
||||
String device_code = null;
|
||||
|
||||
if (phase == 0x67) {
|
||||
//故障信息
|
||||
if (arr[18] * 256 + arr[19] == 0) {
|
||||
|
||||
}
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
|
||||
//普通站点
|
||||
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
|
||||
//货架
|
||||
StandardStorageDeviceDriver standardStorageDeviceDriver;
|
||||
//
|
||||
SiemensConveyorDeviceDriver siemensConveyorDeviceDriver;
|
||||
|
||||
//分配 车id
|
||||
//(不需要WCS反馈)
|
||||
if (phase == 0x02) {
|
||||
if (ObjectUtil.isEmpty(inst)) {
|
||||
log.info("未找到编号{}对应的指令", ikey);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "未找到关联编号对应的指令" + ikey);
|
||||
return;
|
||||
}
|
||||
inst.setCarno(String.valueOf(carno));
|
||||
instructionService.update(inst);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + "反馈:" + data);
|
||||
@@ -150,7 +158,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
} else if (StrUtil.contains(old_device_code, ".")) {
|
||||
String[] point = old_device_code.split("\\.");
|
||||
device_code = point[0];
|
||||
emptyNum = point[1];
|
||||
} else {
|
||||
device_code = old_device_code;
|
||||
}
|
||||
@@ -158,8 +165,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
|
||||
device = deviceAppService.findDeviceByCode(device_code);
|
||||
if (ObjectUtil.isEmpty(device_code)) {
|
||||
log.info(agvaddr + "对应设备号为空!");
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空");
|
||||
log.info(agvaddr + "对应设备号为空!");
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空!");
|
||||
return;
|
||||
}
|
||||
//校验agv上报站点编号与指令起始点相同
|
||||
@@ -193,32 +200,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
} else {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(inst)){
|
||||
JSONArray req = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("device_code", inst.getStart_point_code());
|
||||
map.put("device_status",inst.getExecute_status());
|
||||
map.put("energyLevel",electric_qty);
|
||||
map.put("transportOrder",inst.getTask_code());
|
||||
map.put("positionX",x);
|
||||
map.put("positionY",y);
|
||||
map.put("positionAngle",angle);
|
||||
HttpResponse httpResponse = acsToWmsService.feedbackAgv(req);
|
||||
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
||||
JSONObject resp = JSONObject.parseObject(httpResponse.body());
|
||||
if (resp.getInteger("status") == 200) {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
log.info("指令号:{},acs向wms反馈AGV设备信息,已反馈AGV设备信息", inst.getInstruction_code());
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息,未反馈AGV设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息失败,连接被拒绝,未反馈agv设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
|
||||
//取货完毕
|
||||
//(需要WCS反馈)
|
||||
} else if (phase == 0x05) {
|
||||
@@ -237,7 +218,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
} else if (StrUtil.contains(old_device_code, ".")) {
|
||||
String[] point = old_device_code.split("\\.");
|
||||
device_code = point[0];
|
||||
emptyNum = point[1];
|
||||
} else {
|
||||
device_code = old_device_code;
|
||||
}
|
||||
@@ -281,31 +261,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(inst)){
|
||||
JSONArray req = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("device_code", inst.getStart_point_code());
|
||||
map.put("device_status",inst.getExecute_status());
|
||||
map.put("energyLevel",electric_qty);
|
||||
map.put("transportOrder",inst.getTask_code());
|
||||
map.put("positionX",x);
|
||||
map.put("positionY",y);
|
||||
map.put("positionAngle",angle);
|
||||
HttpResponse httpResponse = acsToWmsService.feedbackAgv(req);
|
||||
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
||||
JSONObject resp = JSONObject.parseObject(httpResponse.body());
|
||||
if (resp.getInteger("status") == 200) {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
log.info("指令号:{},acs向wms反馈AGV设备信息,已反馈AGV设备信息", inst.getInstruction_code());
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息,未反馈AGV设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息失败,连接被拒绝,未反馈agv设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
//到达放货点
|
||||
//(需要WCS反馈)
|
||||
} else if (phase == 0x07) {
|
||||
@@ -324,7 +279,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
} else if (StrUtil.contains(old_device_code, ".")) {
|
||||
String[] point = old_device_code.split("\\.");
|
||||
device_code = point[0];
|
||||
emptyNum = point[1];
|
||||
} else {
|
||||
device_code = old_device_code;
|
||||
}
|
||||
@@ -339,6 +293,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
log.info("未找到关联编号{}对应的指令", ikey);
|
||||
return;
|
||||
}
|
||||
|
||||
Object reqWms = device.getExtraValue().get("reqWms");
|
||||
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
|
||||
JSONArray req = new JSONArray();
|
||||
@@ -364,31 +319,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isNotEmpty(inst)){
|
||||
JSONArray req = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("device_code", inst.getStart_point_code());
|
||||
map.put("device_status",inst.getExecute_status());
|
||||
map.put("energyLevel",electric_qty);
|
||||
map.put("transportOrder",inst.getTask_code());
|
||||
map.put("positionX",x);
|
||||
map.put("positionY",y);
|
||||
map.put("positionAngle",angle);
|
||||
HttpResponse httpResponse = acsToWmsService.feedbackAgv(req);
|
||||
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
||||
JSONObject resp = JSONObject.parseObject(httpResponse.body());
|
||||
if (resp.getInteger("status") == 200) {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
log.info("指令号:{},acs向wms反馈AGV设备信息,已反馈AGV设备信息", inst.getInstruction_code());
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息,未反馈AGV设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息失败,连接被拒绝,未反馈agv设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
//放货完毕
|
||||
//(需要WCS反馈)
|
||||
} else if (phase == 0x09) {
|
||||
@@ -407,7 +337,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
} else if (StrUtil.contains(old_device_code, ".")) {
|
||||
String[] point = old_device_code.split("\\.");
|
||||
device_code = point[0];
|
||||
emptyNum = point[1];
|
||||
} else {
|
||||
device_code = old_device_code;
|
||||
}
|
||||
@@ -423,6 +352,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
log.info("未找到编号{}对应的指令", ikey);
|
||||
return;
|
||||
}
|
||||
|
||||
Object reqWms = device.getExtraValue().get("reqWms");
|
||||
if (ObjectUtil.isNotEmpty(reqWms) && reqWms.toString().equals("true")) {
|
||||
JSONArray req = new JSONArray();
|
||||
@@ -442,31 +372,6 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
} else {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(inst)){
|
||||
JSONArray req = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("device_code", inst.getStart_point_code());
|
||||
map.put("device_status",inst.getExecute_status());
|
||||
map.put("energyLevel",electric_qty);
|
||||
map.put("transportOrder",inst.getTask_code());
|
||||
map.put("positionX",x);
|
||||
map.put("positionY",y);
|
||||
map.put("positionAngle",angle);
|
||||
HttpResponse httpResponse = acsToWmsService.feedbackAgv(req);
|
||||
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
||||
JSONObject resp = JSONObject.parseObject(httpResponse.body());
|
||||
if (resp.getInteger("status") == 200) {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
log.info("指令号:{},acs向wms反馈AGV设备信息,已反馈AGV设备信息", inst.getInstruction_code());
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息,未反馈AGV设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
log.warn("指令号:{},acs向wms反馈AGV设备信息失败,连接被拒绝,未反馈agv设备信息", inst.getInstruction_code());
|
||||
}
|
||||
} else {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
}
|
||||
//到达位置点
|
||||
//(需要WCS反馈)
|
||||
@@ -476,32 +381,142 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
agvaddr_copy = agvaddr;
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
} else if (phase == 0x50) {//进入交通灯区域
|
||||
} else if (phase == 0x50) {//进入区域
|
||||
agvaddr = arr[18] * 256 + arr[19];
|
||||
String device_code1 = deviceService.queryDeviceCodeByAddress(agvaddr);
|
||||
if (ObjectUtil.isEmpty(device_code1)) {
|
||||
log.info(agvaddr + "对应设备号为空!");
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空");
|
||||
return;
|
||||
}
|
||||
JSONArray req = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("status", "5");
|
||||
map.put("device_code", device_code1);
|
||||
map.put("vehicle_code", "");
|
||||
map.put("task_code", "");
|
||||
req.add(map);
|
||||
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
|
||||
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
} else {
|
||||
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
|
||||
}
|
||||
} else if (phase == 0x51) {//离开区域
|
||||
agvaddr = arr[18] * 256 + arr[19];
|
||||
String device_code2 = deviceService.queryDeviceCodeByAddress(agvaddr);
|
||||
if (ObjectUtil.isEmpty(device_code2)) {
|
||||
log.info(agvaddr + "对应设备号为空!");
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", agvaddr + "对应设备号为空");
|
||||
return;
|
||||
}
|
||||
JSONArray req = new JSONArray();
|
||||
JSONObject map = new JSONObject();
|
||||
map.put("status", "6");
|
||||
map.put("device_code", device_code2);
|
||||
map.put("vehicle_code", "");
|
||||
map.put("task_code", "");
|
||||
req.add(map);
|
||||
HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req);
|
||||
if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) {
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
} else {
|
||||
log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code());
|
||||
}
|
||||
} else if (phase == 0x67) {//agv异常
|
||||
if (ikey == 0) {
|
||||
this.setErrorInfo(ikey, "0", "正常");
|
||||
} else {
|
||||
Map<String, String> error = ErrorUtil.getAgvErrorMsg(ikey);
|
||||
String code = error.get("code");
|
||||
String info = error.get("info");
|
||||
this.setErrorInfo(ikey, code, info);
|
||||
}
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
} else if (phase == 0x51) {//离开交通灯区域
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
last_error = error;
|
||||
} else if (phase == 0x70) {
|
||||
//x坐标
|
||||
//x坐标
|
||||
x = ikey;
|
||||
} else if (phase == 0x71) {
|
||||
//y坐标
|
||||
y = ikey;
|
||||
} else if (phase == 0x72) {
|
||||
//车辆角度
|
||||
//车辆角度
|
||||
angle = ikey;
|
||||
} else if (phase == 0x73) {
|
||||
//agv电量
|
||||
electric_qty = ikey;
|
||||
//agv电量
|
||||
electric_qty = ikey;
|
||||
} else if (phase == 0x74) {
|
||||
//三色灯状态
|
||||
status = ikey;
|
||||
}
|
||||
//三色灯状态
|
||||
status = ikey;
|
||||
if(status==4) {
|
||||
order = "";
|
||||
}
|
||||
last_status = status;
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(data)) {
|
||||
phase = 0;
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
OneNDCSocketConnectionAutoRun.write(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private synchronized void setErrorInfo(int error, String error_code, String error_message) {
|
||||
this.error = error;
|
||||
this.error_code = error_code;
|
||||
this.error_message = error_message;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public JSONObject getDeviceStatusName() throws Exception {
|
||||
// JSONObject jo = new JSONObject();
|
||||
// jo.put("device_name", this.getDevice().getDevice_name());
|
||||
// jo.put("x", this.x);
|
||||
// jo.put("y", this.y);
|
||||
// jo.put("angle", this.angle);
|
||||
// jo.put("electric_qty", this.electric_qty);
|
||||
// jo.put("status", this.status);
|
||||
// jo.put("error", this.error);
|
||||
// jo.put("error_message", this.error_message);
|
||||
// jo.put("device_status", this.device_status);
|
||||
// jo.put("message", this.message);
|
||||
// return jo;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public JSONObject getDeviceStatusName() {
|
||||
JSONObject jo = new JSONObject();
|
||||
//agv编码
|
||||
jo.put("car_no", this.getDevice().getDevice_code());
|
||||
//agv名称
|
||||
jo.put("device_name", this.getDevice().getDevice_name());
|
||||
//x坐标
|
||||
jo.put("x", this.getX());
|
||||
//y坐标
|
||||
jo.put("y", this.getY());
|
||||
//角度
|
||||
jo.put("angle", this.getAngle());
|
||||
jo.put("phase", phase);
|
||||
jo.put("phase_name", oneAgvPhase.getPhaseName(phase));
|
||||
//电量
|
||||
jo.put("electricity", this.getElectric_qty());
|
||||
String status_name = this.status == 1 ? "关机" : this.status == 2 ? "工作中" : this.status == 3 ? "交通管制" : this.status == 4 ? "任务等待" : this.status == 5 ? "充电中" : this.status == 6 ? "故障中" : this.status == 7 ? "电量低" : "正常";
|
||||
//agv状态
|
||||
jo.put("status_name", status_name);
|
||||
//任务号
|
||||
jo.put("task_code", ObjectUtil.isEmpty(instruction) ? "0" : instruction.getTask_code());
|
||||
//异常
|
||||
jo.put("fault", this.getError_message());
|
||||
jo.put("message", this.getMessage());
|
||||
return jo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceStatus(JSONObject data) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package org.nl.acs.device_driver.basedriver.agv.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.nl.modules.system.domain.Dict;
|
||||
import org.nl.modules.system.service.DictDetailService;
|
||||
import org.nl.modules.system.service.DictService;
|
||||
import org.nl.modules.system.service.dto.DictDetailDto;
|
||||
import org.nl.modules.system.service.impl.DictDetailServiceImpl;
|
||||
import org.nl.modules.system.service.impl.DictServiceImpl;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author: tu qiang
|
||||
* @createDate: 2024/1/12
|
||||
*/
|
||||
public class ErrorUtil {
|
||||
|
||||
public static ConcurrentHashMap<String, List<DictDetailDto>> dictMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
public static String getDictDetail(String type, String error_code) {
|
||||
getDict();
|
||||
List<DictDetailDto> dictDetailDtos = dictMap.get(type);
|
||||
String detail = null;
|
||||
if (ObjectUtil.isNotEmpty(dictDetailDtos)) {
|
||||
for (int i = 0; i < dictDetailDtos.size(); i++) {
|
||||
DictDetailDto dictDetailDto = dictDetailDtos.get(i);
|
||||
String value = dictDetailDto.getValue();
|
||||
String label = dictDetailDto.getLabel();
|
||||
if (StrUtil.equals(value, error_code)) {
|
||||
detail = label;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return detail == null ? "字典表未配置对应的报警信息" : detail;
|
||||
}
|
||||
|
||||
public static Map<Integer, String> getDictDetailByName(String type) {
|
||||
getDict();
|
||||
List<DictDetailDto> dictDetailDtos = dictMap.get(type);
|
||||
Map<Integer, String> map = new HashMap<>();
|
||||
if (ObjectUtil.isNotEmpty(dictDetailDtos)) {
|
||||
List<DictDetailDto> dtos = dictDetailDtos
|
||||
.stream()
|
||||
.filter(dictDetailDto -> !dictDetailDto.getValue().equals("0"))
|
||||
.filter(dictDetailDto -> !dictDetailDto.getValue().equals("-1"))
|
||||
.collect(Collectors.toList());
|
||||
dtos.forEach(dictDetailDto -> map.put(Integer.parseInt(dictDetailDto.getValue()), dictDetailDto.getLabel()));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public static void getDict() {
|
||||
if (ObjectUtil.isEmpty(dictMap)) {
|
||||
DictDetailService dictDetailService = SpringContextHolder.getBean(DictDetailServiceImpl.class);
|
||||
DictService dictService = SpringContextHolder.getBean(DictServiceImpl.class);
|
||||
List<Dict> dictDtos = dictService.queryAll();
|
||||
for (int i = 0; i < dictDtos.size(); i++) {
|
||||
Dict dictDto = dictDtos.get(i);
|
||||
dictMap.put(dictDto.getName(), getDict(dictDto.getName(), t -> {
|
||||
return dictDetailService.getDictByName(t);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<DictDetailDto> getDict(String name, Function<String, List<DictDetailDto>> f) {
|
||||
return f.apply(name);
|
||||
}
|
||||
|
||||
public static Map<String, String> getAgvErrorMsg(Integer ageErrorNum) {
|
||||
Map<Integer, String> agvMap = getDictDetailByName("agv_error_type");
|
||||
Integer[] keys = agvMap.keySet().toArray(new Integer[0]);
|
||||
String message = "";
|
||||
String code = "";
|
||||
out:
|
||||
for (int i = 1; i < 1 << keys.length; i++) {
|
||||
int sum = 0;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuffer sbCode = new StringBuffer();
|
||||
inner:
|
||||
for (int j = 0; j < keys.length; j++) {
|
||||
if ((i & 1 << j) != 0) {
|
||||
sum += keys[j];
|
||||
sb.append(agvMap.get(keys[j])).append(",");
|
||||
sbCode.append(keys[j]).append(",");
|
||||
}
|
||||
}
|
||||
if (sum == ageErrorNum) {
|
||||
code = sbCode.toString();
|
||||
message = sb.toString();
|
||||
break out;
|
||||
}
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
String info = replace(message);
|
||||
code = replace(code);
|
||||
map.put("code", StrUtil.isEmpty(code) ? "-1" : code);
|
||||
map.put("info", StrUtil.isEmpty(info) ? "AGV上报报警代码有误" : info);
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String replace(String message) {
|
||||
if (StrUtil.isEmpty(message)) {
|
||||
return null;
|
||||
}
|
||||
if (message.endsWith(",")) {
|
||||
return message.substring(0, message.length() - 1);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,20 @@ public class OneAgvPhase implements IAgv{
|
||||
return "到达位置点";
|
||||
} else if (phase == 0x65){
|
||||
return "称重就绪";
|
||||
}else if (phase == 0x50){
|
||||
return "请求开门";
|
||||
} else if (phase == 0x51){
|
||||
return "请求关门";
|
||||
} else if (phase == 0x70){
|
||||
return "上报X坐标";
|
||||
} else if (phase == 0x71){
|
||||
return "上报Y坐标";
|
||||
} else if (phase == 0x72){
|
||||
return "上报角度";
|
||||
} else if (phase == 0x73){
|
||||
return "上报电量";
|
||||
} else if (phase == 0x74){
|
||||
return "上报状态";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public class ItemProtocol {
|
||||
public static String DO0 = "DO0";
|
||||
public static String DO1 = "DO1";
|
||||
public static String DO2 = "DO2";
|
||||
public static String DO8 = "DO8";
|
||||
public static String x = "x";
|
||||
public static String y = "y";
|
||||
public static String angle = "angle";
|
||||
@@ -53,6 +54,7 @@ public class ItemProtocol {
|
||||
public static String to_pause_navigation = "to_pause_navigation";
|
||||
public static String to_continue_navigation = "to_continue_navigation";
|
||||
public static String to_cancle_navigation = "to_cancle_navigation";
|
||||
public static String to_reclaim_control = "to_reclaim_control";
|
||||
public static String to_DO0_height = "to_DO0_height";
|
||||
public static String to_DO0_low = "to_DO0_low";
|
||||
public static String to_DO1_height = "to_DO1_height";
|
||||
@@ -124,6 +126,11 @@ public class ItemProtocol {
|
||||
|
||||
}
|
||||
|
||||
public int getDO8() {
|
||||
return this.getOpcIntegerValue(DO8);
|
||||
|
||||
}
|
||||
|
||||
public Float getX() {
|
||||
return this.getOpcFloatValue(x);
|
||||
|
||||
@@ -219,6 +226,11 @@ public class ItemProtocol {
|
||||
ItemProtocol.to_cancle_navigation = to_cancle_navigation;
|
||||
}
|
||||
|
||||
public static void setTo_reclaim_control(String to_reclaim_control) {
|
||||
ItemProtocol.to_reclaim_control = to_reclaim_control;
|
||||
}
|
||||
|
||||
|
||||
public static void setTo_DO0_height(String to_DO0_height) {
|
||||
ItemProtocol.to_DO0_height = to_DO0_height;
|
||||
}
|
||||
@@ -313,6 +325,7 @@ public class ItemProtocol {
|
||||
list.add(new ItemDto(DI4, "DI4", "10024"));
|
||||
list.add(new ItemDto(DO1, "DO1", "10061"));
|
||||
list.add(new ItemDto(DO2, "DO2", "10062"));
|
||||
list.add(new ItemDto(DO8, "DO8", "10068"));
|
||||
list.add(new ItemDto(DI11, "DI11", "10031"));
|
||||
list.add(new ItemDto(DI12, "DI12", "10032"));
|
||||
list.add(new ItemDto(x, "x", "30001"));
|
||||
@@ -344,6 +357,7 @@ public class ItemProtocol {
|
||||
list.add(new ItemDto(to_pause_navigation, "to_暂停导航", "00004"));
|
||||
list.add(new ItemDto(to_continue_navigation, "to_继续导航", "00005"));
|
||||
list.add(new ItemDto(to_cancle_navigation, "to_取消导航", "00006"));
|
||||
list.add(new ItemDto(to_reclaim_control, "to_回收控制权", "00010"));
|
||||
list.add(new ItemDto(to_DO0_height, "to_DO0置为高电平", "00061"));
|
||||
list.add(new ItemDto(to_DO0_low, "to_DO0置为低电平", "00020"));
|
||||
list.add(new ItemDto(to_DO1_height, "to_DO1置为高电平", "00062"));
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.route.service.RouteLineService;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.acs.task.service.dto.TaskDto;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.logging.DeviceCodeDir;
|
||||
import org.nl.modules.lucence.service.LuceneExecuteLogService;
|
||||
import org.nl.modules.lucence.service.dto.LuceneLogDto;
|
||||
@@ -30,10 +31,7 @@ import org.openscada.opc.lib.da.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,6 +72,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
int DO0 = 0;
|
||||
int DO1 = 0;
|
||||
int DO2 = 0;
|
||||
int DO8 = 0;
|
||||
Float x = 0f;
|
||||
Float y = 0f;
|
||||
Float angle = 0f;
|
||||
@@ -103,6 +102,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
int last_DO0 = 0;
|
||||
int last_DO1 = 0;
|
||||
int last_DO2 = 0;
|
||||
int last_DO8 = 0;
|
||||
Float last_x = 0f;
|
||||
Float last_y = 0f;
|
||||
Float last_angle = 0f;
|
||||
@@ -133,7 +133,12 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
//休息点
|
||||
int relax_point = 0;
|
||||
//充电点
|
||||
int charge_point =0;
|
||||
int charge_point = 0;
|
||||
//0.关机 1.有任务 2.空闲 3.充电
|
||||
int flag = 0;
|
||||
//任务号
|
||||
String order = "";
|
||||
|
||||
@Override
|
||||
public Device getDevice() {
|
||||
return this.device;
|
||||
@@ -154,6 +159,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
DO0 = this.itemProtocol.getDO0();
|
||||
DO1 = this.itemProtocol.getDO1();
|
||||
DO2 = this.itemProtocol.getDO2();
|
||||
DO8 = this.itemProtocol.getDO8();
|
||||
x = this.itemProtocol.getX();
|
||||
y = this.itemProtocol.getY();
|
||||
navigation_address = this.itemProtocol.getNavigation_address();
|
||||
@@ -170,6 +176,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
cancle_navigation = this.itemProtocol.getCancle_navigation();
|
||||
drum_run_status = this.itemProtocol.getDrum_run_status();
|
||||
stop = this.itemProtocol.getStop();
|
||||
angle = this.itemProtocol.getAngle();
|
||||
|
||||
if (home_relocation != last_home_relocation) {
|
||||
// LuceneLogDto logDto = LuceneLogDto.builder()
|
||||
@@ -178,7 +185,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
// .build();
|
||||
// luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
luceneExecuteLogService.deviceExecuteLog(
|
||||
new LuceneLogDto(this.getDevice().getOpc_server_code(),this.getDevice().getOpc_plc_code(),this.device_code,ItemProtocol.to_home_relocation,this.last_home_relocation,this.home_relocation));
|
||||
new LuceneLogDto(this.getDevice().getOpc_server_code(), this.getDevice().getOpc_plc_code(), this.device_code, ItemProtocol.to_home_relocation, this.last_home_relocation, this.home_relocation));
|
||||
}
|
||||
|
||||
if (stop != last_stop) {
|
||||
@@ -192,7 +199,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
if (address != last_address) {
|
||||
LuceneLogDto logDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("信号" + this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.device_code + "." + ItemProtocol.address + this.last_address + "->" + this.address)
|
||||
.content("信号" + this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.device_code + "." + ItemProtocol.address + this.last_address + "->" + this.address)
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
}
|
||||
@@ -200,7 +207,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
if (electricity != last_electricity) {
|
||||
LuceneLogDto logDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("信号" + this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.device_code + "." + ItemProtocol.electricity + this.last_electricity + "->" + this.electricity)
|
||||
.content("信号" + this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.device_code + "." + ItemProtocol.electricity + this.last_electricity + "->" + this.electricity)
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
}
|
||||
@@ -238,83 +245,114 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
Device charge_point_device = deviceAppService.findDeviceByCode((String) this.getDevice().getExtraValue().get("charge_point"));
|
||||
charge_point = Integer.parseInt(charge_point_device.getAddress());
|
||||
List<Instruction> instList = instructionService.findAllInstFromCache();
|
||||
|
||||
if (instList.size() > 0) {
|
||||
if (ObjectUtil.isNotEmpty(instList)) {
|
||||
for (int i = 0; i < instList.size(); i++) {
|
||||
instList = this.sortTask(instList);
|
||||
inst = instList.get(i);
|
||||
if (ObjectUtil.equal(inst.getInstruction_type(), "1")) {
|
||||
if (!ObjectUtil.equal(inst.getInstruction_type(), "1")) {
|
||||
inst = null;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isEmpty(inst)) {
|
||||
message = "未找到对应指令";
|
||||
return;
|
||||
if (ObjectUtil.isNotEmpty(inst)) break;
|
||||
}
|
||||
}
|
||||
//先判断当前有无指令
|
||||
if (ObjectUtil.isEmpty(inst)) {
|
||||
this.flag = 2;
|
||||
if (electricity != 0 && electricity < min_electric && address != charge_point && (navigation_status == 0 || navigation_status == 4)) {
|
||||
log.info("下发充电:{}", charge_point);
|
||||
feedAgvTaskStatus(inst, "5");
|
||||
feedAgvTaskStatus(inst, "7");
|
||||
}
|
||||
if (electricity != 0 && electricity > cancle_electric && address == charge_point && (navigation_status == 0 || navigation_status == 4)) {
|
||||
log.info("下发回休息点:{}", relax_point);
|
||||
|
||||
writing("to_address", 1);
|
||||
}
|
||||
} else {
|
||||
order = inst.getTask_code();
|
||||
TaskDto task = taskserver.findByCodeFromCache(inst.getTask_code());
|
||||
Device start_device = deviceAppService.findDeviceByCode(inst.getStart_device_code());
|
||||
Device next_device = deviceAppService.findDeviceByCode(inst.getNext_device_code());
|
||||
int start_device_code = Integer.parseInt(start_device.getAddress());
|
||||
int next_device_code = Integer.parseInt(next_device.getAddress());
|
||||
|
||||
|
||||
StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver;
|
||||
//指令状态就绪
|
||||
if (StrUtil.equals("0", inst.getInstruction_status())) {
|
||||
this.flag = 1;
|
||||
log.info("下发指令号{},起点{}", inst.getInstruction_code(), start_device);
|
||||
//判断指令起点与任务起点是否相同
|
||||
String start_addr = start_device.getExtraValue().get("address").toString();
|
||||
String next_addr = next_device.getExtraValue().get("address").toString();
|
||||
String line_code = start_addr + next_addr;
|
||||
int to_line_code = Integer.parseInt(line_code);
|
||||
inst.setInstruction_status("1");
|
||||
if ("A4".equals(inst.getStart_device_code())) {
|
||||
inst.setExecute_status("1");
|
||||
} else {
|
||||
inst.setExecute_status("3");
|
||||
}
|
||||
instructionService.update(inst);
|
||||
writing("to_locate_correct", 1);
|
||||
writing("to_reclaim_control", 1);
|
||||
writing("to_line", to_line_code);
|
||||
}
|
||||
//判断起点终点是否配置电气值
|
||||
Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code());
|
||||
Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code());
|
||||
if (ObjectUtil.isEmpty(startDevice.getExtraValue().get("address"))) {
|
||||
throw new BadRequestException("设备:" + startDevice.getDevice_code() + "未设置电气调度号!");
|
||||
}
|
||||
if (ObjectUtil.isEmpty(nextDevice.getExtraValue().get("address"))) {
|
||||
throw new BadRequestException("设备:" + nextDevice.getDevice_code() + "未设置电气调度号!");
|
||||
}
|
||||
String start_addr = startDevice.getExtraValue().get("address").toString();
|
||||
String next_addr = nextDevice.getExtraValue().get("address").toString();
|
||||
|
||||
//申请取货
|
||||
if (StrUtil.equals("1", inst.getInstruction_status()) && next_addr.equals(String.valueOf(address)) && stop == 1 && StrUtil.equals(inst.getExecute_status(), "1")) {
|
||||
//请求wms是否允许取货
|
||||
feedAgvTaskStatus(inst, "1");
|
||||
}
|
||||
|
||||
|
||||
//取货完成请求离开
|
||||
if (StrUtil.equals("1", inst.getInstruction_status()) && address == 5 && stop == 1 && StrUtil.equals(inst.getExecute_status(),"1")) {
|
||||
//请求wms是否允许从取货点离开
|
||||
feedAgvTaskStatus(inst, "2");
|
||||
}
|
||||
// if (StrUtil.equals("1", inst.getInstruction_status()) && start_addr.equals(String.valueOf(address)) && stop == 1 && StrUtil.equals(inst.getExecute_status(), "1")) {
|
||||
// //请求wms是否允许从取货点离开
|
||||
// feedAgvTaskStatus(inst, "2");
|
||||
// }
|
||||
|
||||
//请求放货
|
||||
if (StrUtil.equals("1", inst.getInstruction_status()) && address == 2 && stop == 1 && StrUtil.equals(inst.getExecute_status(),"2")) {
|
||||
if (StrUtil.equals("1", inst.getInstruction_status()) && next_addr.equals(String.valueOf(address)) && stop == 1 && StrUtil.equals(inst.getExecute_status(), "3")) {
|
||||
//请求wms是否允许进入放货
|
||||
feedAgvTaskStatus(inst, "3");
|
||||
|
||||
}
|
||||
//放货完成 完成任务回休息点
|
||||
if (StrUtil.equals("1", inst.getInstruction_status()) && address == 1 && stop == 1 && StrUtil.equals(inst.getExecute_status(),"3")) {
|
||||
feedAgvTaskStatus(inst, "4");
|
||||
}
|
||||
// if (StrUtil.equals("1", inst.getInstruction_status()) && next_addr.equals(String.valueOf(address)) && stop == 1 && StrUtil.equals(inst.getExecute_status(), "3")) {
|
||||
// feedAgvTaskStatus(inst, "4");
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
//请求开门
|
||||
if ( (address == 3 || address == 11 ) && stop == 1 ) {
|
||||
if ((address == 6 || address == 2) && stop == 1 && DO8 == 1) {
|
||||
feedAgvAction("5");
|
||||
}
|
||||
|
||||
//请求关门
|
||||
if ( (address == 9 || address == 10 ) && stop == 1 ) {
|
||||
if ((address == 6 || address == 2) && stop == 1 && DO8 == 0) {
|
||||
feedAgvAction("6");
|
||||
}
|
||||
|
||||
//请求充电
|
||||
if ( address == 4 && stop == 1 ) {
|
||||
feedAgvAction( "7");
|
||||
}
|
||||
|
||||
last_home_relocation = home_relocation;
|
||||
last_address = address;
|
||||
last_next_address = next_address;
|
||||
last_electricity = electricity;
|
||||
last_stop = stop;
|
||||
last_angle = angle;
|
||||
last_x = x;
|
||||
last_y = y;
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +365,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
itemMap.put(to_command, value);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("下发信号"+ this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.device_code + "." + key + "value:"+ value )
|
||||
.content("下发信号" + this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.device_code + "." + key + "value:" + value)
|
||||
.build();
|
||||
|
||||
ReadUtil.write(itemMap, server);
|
||||
@@ -354,6 +392,23 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
|
||||
}
|
||||
|
||||
public List<Instruction> sortTask(List<Instruction> instructions) {
|
||||
Collections.sort(instructions, new Comparator<Instruction>() {
|
||||
@Override
|
||||
public int compare(Instruction t1, Instruction t2) {
|
||||
//优先级从大到小
|
||||
int i = t2.getPriority().compareTo(t1.getPriority());
|
||||
//如果优先级相等
|
||||
if (i == 0) {
|
||||
//时间从早到晚
|
||||
i = t1.getCreate_time().compareTo(t2.getCreate_time());
|
||||
}
|
||||
return i;
|
||||
}
|
||||
});
|
||||
return instructions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 反馈wms动作状态
|
||||
*
|
||||
@@ -369,43 +424,38 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
|
||||
//请求WMS允许取货
|
||||
if (StrUtil.equals(type, "1")) {
|
||||
Device start_device = deviceAppService.findDeviceByCode(inst.getStart_device_code());
|
||||
Device next_device = deviceAppService.findDeviceByCode(inst.getNext_device_code());
|
||||
int start_device_code = Integer.parseInt(start_device.getAddress());
|
||||
int next_device_code = Integer.parseInt(next_device.getAddress());
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("vehicle_code", inst.getVehicle_code());
|
||||
jo.put("status", "1");
|
||||
jo.put("device_code", this.device_code);
|
||||
jo.put("status", "4");
|
||||
jo.put("device_code", inst.getNext_device_code());
|
||||
jo.put("task_code", inst.getTask_code());
|
||||
ja.add(jo);
|
||||
LuceneLogDto reqlogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("请求参数:"+jo)
|
||||
.requestparam("请求参数:"+jo)
|
||||
.content("请求参数:" + jo)
|
||||
.requestparam("请求参数:" + jo)
|
||||
.method("feedAgvTaskStatus")
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(reqlogDto);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("返回参数:"+resp.body())
|
||||
.responseparam("返回参数:"+resp.body())
|
||||
.content("返回参数:" + resp.body())
|
||||
.responseparam("返回参数:" + resp.body())
|
||||
.method("feedAgvTaskStatus")
|
||||
.status_code(String.valueOf(resp.getStatus()))
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto);
|
||||
|
||||
if (resp.getStatus() ==200) {
|
||||
|
||||
if (resp.getStatus() == 200) {
|
||||
inst.setInstruction_status("1");
|
||||
inst.setExecute_status("1");
|
||||
inst.setExecute_status("2");
|
||||
instructionService.update(inst);
|
||||
writing("to_line", 1);
|
||||
|
||||
//结束任务
|
||||
finish_instruction(inst);
|
||||
} else {
|
||||
writing("to_line", 1);
|
||||
|
||||
|
||||
}
|
||||
//取货完成请求离开
|
||||
@@ -423,21 +473,21 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
ja.add(jo);
|
||||
LuceneLogDto reqlogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("请求参数:"+jo)
|
||||
.requestparam("请求参数:"+jo)
|
||||
.content("请求参数:" + jo)
|
||||
.requestparam("请求参数:" + jo)
|
||||
.method("feedAgvTaskStatus")
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(reqlogDto);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("返回参数:"+resp.body())
|
||||
.responseparam("返回参数:"+resp.body())
|
||||
.content("返回参数:" + resp.body())
|
||||
.responseparam("返回参数:" + resp.body())
|
||||
.method("feedAgvTaskStatus")
|
||||
.status_code(String.valueOf(resp.getStatus()))
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto);
|
||||
if (resp.getStatus() ==200) {
|
||||
if (resp.getStatus() == 200) {
|
||||
|
||||
inst.setInstruction_status("1");
|
||||
inst.setExecute_status("2");
|
||||
@@ -446,7 +496,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
|
||||
}
|
||||
//请求放货
|
||||
} else if (StrUtil.equals(type, "3")) {
|
||||
} else if (StrUtil.equals(type, "3")) {
|
||||
Device start_device = deviceAppService.findDeviceByCode(inst.getStart_device_code());
|
||||
Device next_device = deviceAppService.findDeviceByCode(inst.getNext_device_code());
|
||||
int start_device_code = Integer.parseInt(start_device.getAddress());
|
||||
@@ -454,38 +504,45 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("vehicle_code", inst.getVehicle_code());
|
||||
jo.put("status", "3");
|
||||
jo.put("device_code", this.device_code);
|
||||
jo.put("status", "4");
|
||||
jo.put("device_code", inst.getNext_device_code());
|
||||
jo.put("task_code", inst.getTask_code());
|
||||
ja.add(jo);
|
||||
LuceneLogDto reqlogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("请求参数:"+jo)
|
||||
.requestparam("请求参数:"+jo)
|
||||
.content("请求参数:" + jo)
|
||||
.requestparam("请求参数:" + jo)
|
||||
.method("feedAgvTaskStatus")
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(reqlogDto);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("返回参数:"+resp.body())
|
||||
.responseparam("返回参数:"+resp.body())
|
||||
.content("返回参数:" + resp.body())
|
||||
.responseparam("返回参数:" + resp.body())
|
||||
.method("feedAgvTaskStatus")
|
||||
.status_code(String.valueOf(resp.getStatus()))
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto);
|
||||
if (resp.getStatus() ==200) {
|
||||
if (resp.getStatus() == 200) {
|
||||
// inst.setInstruction_status("1");
|
||||
// inst.setExecute_status("4");
|
||||
// instructionService.update(inst);
|
||||
inst.setInstruction_status("1");
|
||||
inst.setExecute_status("3");
|
||||
inst.setExecute_status("4");
|
||||
instructionService.update(inst);
|
||||
//结束任务
|
||||
finish_instruction(inst);
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (StrUtil.equals(type, "4")) {
|
||||
Device start_device = deviceAppService.findDeviceByCode(inst.getStart_device_code());
|
||||
Device next_device = deviceAppService.findDeviceByCode(inst.getNext_device_code());
|
||||
int start_device_code = Integer.parseInt(start_device.getAddress());
|
||||
int next_device_code = Integer.parseInt(next_device.getAddress());
|
||||
String start_addr = start_device.getExtraValue().get("address").toString();
|
||||
String next_addr = next_device.getExtraValue().get("address").toString();
|
||||
String line_code = next_addr + start_addr;
|
||||
int to_line_code = Integer.parseInt(line_code);
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("vehicle_code", inst.getVehicle_code());
|
||||
@@ -495,22 +552,23 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
ja.add(jo);
|
||||
LuceneLogDto reqlogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("请求参数:"+jo)
|
||||
.requestparam("请求参数:"+jo)
|
||||
.content("请求参数:" + jo)
|
||||
.requestparam("请求参数:" + jo)
|
||||
.method("feedAgvTaskStatus")
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(reqlogDto);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("返回参数:"+resp.body())
|
||||
.responseparam("返回参数:"+resp.body())
|
||||
.content("返回参数:" + resp.body())
|
||||
.responseparam("返回参数:" + resp.body())
|
||||
.method("feedAgvTaskStatus")
|
||||
.status_code(String.valueOf(resp.getStatus()))
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto);
|
||||
if (resp.getStatus() ==200) {
|
||||
writing("to_line", 2);
|
||||
if (resp.getStatus() == 200) {
|
||||
writing("to_locate_correct", 1);
|
||||
writing("to_line", to_line_code);
|
||||
inst.setInstruction_status("2");
|
||||
inst.setExecute_status("4");
|
||||
instructionService.finish(inst);
|
||||
@@ -525,27 +583,26 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
ja.add(jo);
|
||||
LuceneLogDto reqlogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("请求参数:"+jo)
|
||||
.requestparam("请求参数:"+jo)
|
||||
.content("请求参数:" + jo)
|
||||
.requestparam("请求参数:" + jo)
|
||||
.method("feedAgvTaskStatus")
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(reqlogDto);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("返回参数:"+resp.body())
|
||||
.responseparam("返回参数:"+resp.body())
|
||||
.content("返回参数:" + resp.body())
|
||||
.responseparam("返回参数:" + resp.body())
|
||||
.method("feedAgvTaskStatus")
|
||||
.status_code(String.valueOf(resp.getStatus()))
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto);
|
||||
if (resp.getStatus() == 200) {
|
||||
writing("to_di_low", 0);
|
||||
writing("to_di_height", 0);
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (StrUtil.equals(type, "6")) {
|
||||
} else if (StrUtil.equals(type, "6")) {
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("status", "6");
|
||||
@@ -558,15 +615,18 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (StrUtil.equals(type, "7")) {
|
||||
} else if (StrUtil.equals(type, "7")) {
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("status", "7");
|
||||
jo.put("device_code", this.device_code);
|
||||
jo.put("device_code", "CP5");
|
||||
jo.put("vehicle_code", "");
|
||||
jo.put("task_code", "");
|
||||
ja.add(jo);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
if (resp.getStatus() == 200) {
|
||||
writing("to_di_low", 0);
|
||||
writing("to_address", 5);
|
||||
this.flag = 3;
|
||||
} else {
|
||||
|
||||
}
|
||||
@@ -575,6 +635,11 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean finish_instruction(Instruction inst) throws Exception {
|
||||
instructionService.finish(inst);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean feedAgvAction(String type) throws Exception {
|
||||
Date date = new Date();
|
||||
if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) {
|
||||
@@ -585,55 +650,58 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("status", "5");
|
||||
jo.put("device_code", "A4");
|
||||
jo.put("device_code", "AD4");
|
||||
jo.put("vehicle_code", "");
|
||||
jo.put("task_code", "");
|
||||
ja.add(jo);
|
||||
LuceneLogDto reqlogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("请求参数:"+jo)
|
||||
.requestparam("请求参数:"+jo)
|
||||
.content("请求参数:" + jo)
|
||||
.requestparam("请求参数:" + jo)
|
||||
.method("feedAgvTaskStatus")
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(reqlogDto);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
LuceneLogDto resplogDto = LuceneLogDto.builder()
|
||||
.device_code(device_code)
|
||||
.content("返回参数:"+resp.body())
|
||||
.responseparam("返回参数:"+resp.body())
|
||||
.content("返回参数:" + resp.body())
|
||||
.responseparam("返回参数:" + resp.body())
|
||||
.method("feedAgvTaskStatus")
|
||||
.status_code(String.valueOf(resp.getStatus()))
|
||||
.build();
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto); if (resp.getStatus() == 200) {
|
||||
writing("to_di_low", 0);
|
||||
luceneExecuteLogService.deviceExecuteLog(resplogDto);
|
||||
if (resp.getStatus() == 200) {
|
||||
writing("to_di_height", 0);
|
||||
} else {
|
||||
writing("to_di_low", 0);
|
||||
writing("to_di_height", 0);
|
||||
|
||||
}
|
||||
} else if (StrUtil.equals(type, "6")) {
|
||||
} else if (StrUtil.equals(type, "6")) {
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("status", "6");
|
||||
jo.put("device_code", "A4");
|
||||
jo.put("device_code", "AD4");
|
||||
jo.put("vehicle_code", "");
|
||||
jo.put("task_code", "");
|
||||
ja.add(jo);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
if (resp.getStatus() == 200) {
|
||||
writing("to_di_height", 0);
|
||||
writing("to_di_low", 0);
|
||||
} else {
|
||||
writing("to_di_height", 0);
|
||||
writing("to_di_low", 0);
|
||||
|
||||
}
|
||||
} else if (StrUtil.equals(type, "7")) {
|
||||
} else if (StrUtil.equals(type, "7")) {
|
||||
JSONArray ja = new JSONArray();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("status", "7");
|
||||
jo.put("device_code", "A4");
|
||||
jo.put("vehicle_code", "");
|
||||
jo.put("task_code", "");
|
||||
ja.add(jo);
|
||||
HttpResponse resp = acsToWmsService.feedAgvTaskStatus(ja);
|
||||
if (resp.getStatus() == 200) {
|
||||
writing("to_di_height", 0);
|
||||
} else {
|
||||
writing("to_di_height", 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,4 +112,6 @@ public interface AcsToWmsService {
|
||||
* @return
|
||||
*/
|
||||
HttpResponse feedAgvTaskStatus(JSONArray from);
|
||||
|
||||
void sendDeviceStatus(JSONObject param);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.nl.acs.task.service.dto.TaskDto;
|
||||
import org.nl.modules.system.service.ParamService;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -552,4 +553,28 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendDeviceStatus(JSONObject param) {
|
||||
try {
|
||||
MDC.put(log_file_type, log_type);
|
||||
|
||||
if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) {
|
||||
String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue();
|
||||
AddressDto addressDto = addressService.findByCode("sendDeviceStatus");
|
||||
String methods_url = addressDto.getMethods_url();
|
||||
String url = wmsUrl + methods_url;
|
||||
log.info("sendDeviceStatus - 请求参数 {}", param);
|
||||
HttpResponse response = HttpRequest
|
||||
.post(url)
|
||||
.body(param.toString())
|
||||
.execute();
|
||||
log.info("sendDeviceStatus - 返回参数 {}", response.body());
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
} finally {
|
||||
MDC.remove(log_file_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Map<String, Object> getByTaskId(String id) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject jsonObject = wo.query("task_id='" + id + "'").pageResult();
|
||||
JSONObject jsonObject = wo.query("task_id='" + id + "'","create_time desc").pageResult();
|
||||
JSONArray content = jsonObject.getJSONArray("content");
|
||||
JSONArray array = new JSONArray();
|
||||
for (int i = 0; i < content.size(); i++) {
|
||||
@@ -222,7 +222,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Instruction findById(String instruction_id) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0);
|
||||
JSONObject json = wo.query("instruction_id ='" + instruction_id + "'","create_time desc").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)) {
|
||||
final Instruction obj = json.toJavaObject(Instruction.class);
|
||||
return obj;
|
||||
@@ -233,7 +233,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Instruction findByCode(String code) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0);
|
||||
JSONObject json = wo.query("instruction_code ='" + code + "'","create_time desc").uniqueResult(0);
|
||||
if (ObjectUtil.isEmpty(json)) {
|
||||
return null;
|
||||
}
|
||||
@@ -244,7 +244,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
@Override
|
||||
public Instruction findByTaskcode(String code) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0);
|
||||
JSONObject json = wo.query("task_code ='" + code + "'","create_time desc").uniqueResult(0);
|
||||
final Instruction obj = json.toJavaObject(Instruction.class);
|
||||
return obj;
|
||||
}
|
||||
@@ -268,7 +268,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
wherecaluse = " and " + wherecaluse;
|
||||
}
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_instruction");
|
||||
JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse).uniqueResult(0);
|
||||
JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse,"create_time desc").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)) {
|
||||
return json.toJavaObject(Instruction.class);
|
||||
}
|
||||
@@ -363,7 +363,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
if (ObjectUtil.isEmpty(route)) {
|
||||
throw new BadRequestException("未查询到相关路由!");
|
||||
}
|
||||
if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) {
|
||||
if (StrUtil.equals(shortPathsList.get(0).getType(), "2")) {
|
||||
NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class);
|
||||
ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto);
|
||||
}
|
||||
@@ -518,7 +518,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
+ "'"
|
||||
+ " and task_id = '"
|
||||
+ dto.getTask_id()
|
||||
+ "'")
|
||||
+ "'","create_time desc")
|
||||
.uniqueResult(0);
|
||||
if (instcheckjson != null) {
|
||||
throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!");
|
||||
@@ -702,7 +702,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(entity);
|
||||
wo.update(json);
|
||||
JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0);
|
||||
JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'","create_time desc").uniqueResult(0);
|
||||
TaskDto obj = taskjson.toJavaObject(TaskDto.class);
|
||||
// =0 则不用再次请求
|
||||
if (StrUtil.equals(obj.getRequest_again(), "0")) {
|
||||
@@ -780,7 +780,7 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
||||
dto = foramte(dto);
|
||||
String device_code = dto.getNext_device_code();
|
||||
WQLObject taskwo = WQLObject.getWQLObject("acs_task");
|
||||
JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0);
|
||||
JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'","create_time desc").uniqueResult(0);
|
||||
TaskDto acsTask = taskjson.toJavaObject(TaskDto.class);
|
||||
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class);
|
||||
List<RouteLineDto> list =
|
||||
|
||||
@@ -264,13 +264,13 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
@Override
|
||||
public List<Device> findDeviceByType(DeviceType deviceType) {
|
||||
List<Device> list = this.findDevice(deviceType);
|
||||
Map<String, String> map = new HashMap();
|
||||
Iterator var4 = list.iterator();
|
||||
|
||||
while (var4.hasNext()) {
|
||||
Device device = (Device) var4.next();
|
||||
list.add(device);
|
||||
}
|
||||
// Map<String, String> map = new HashMap();
|
||||
// Iterator var4 = list.iterator();
|
||||
//
|
||||
// while (var4.hasNext()) {
|
||||
// Device device = (Device) var4.next();
|
||||
// list.add(device);
|
||||
// }
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,31 +4,36 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.instruction.service.InstructionService;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.openscada.opc.lib.da.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class DeviceOpcProtocolRunable implements Runnable {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class);
|
||||
|
||||
|
||||
public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener {
|
||||
List<OpcItemDto> protocols;
|
||||
OpcServerManageDto OpcServer;
|
||||
int error_num;
|
||||
String message;
|
||||
int maxResartNum;
|
||||
private Server server;
|
||||
private Group group;
|
||||
boolean flag = false;
|
||||
private int all_null;
|
||||
private Map<String, OpcItemDto> itemSearchCache;
|
||||
|
||||
Group group;
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
this.error_num = 0;
|
||||
this.all_null = 0;
|
||||
this.message = null;
|
||||
this.itemSearchCache = new HashMap();
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
public List<OpcItemDto> getProtocols() {
|
||||
@@ -47,32 +52,60 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
this.OpcServer = opcServer;
|
||||
}
|
||||
|
||||
OpcItemDto getItem(String item) {
|
||||
Iterator var2 = this.protocols.iterator();
|
||||
|
||||
OpcItemDto dto;
|
||||
do {
|
||||
if (!var2.hasNext()) {
|
||||
return null;
|
||||
private OpcItemDto getItem(String item) {
|
||||
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item);
|
||||
if (x == null) {
|
||||
Iterator var3 = this.protocols.iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
OpcItemDto dto = (OpcItemDto) var3.next();
|
||||
if (StrUtil.equals(item, dto.getItem_code())) {
|
||||
x = dto;
|
||||
this.itemSearchCache.put(item, dto);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dto = (OpcItemDto) var2.next();
|
||||
} while (!StrUtil.equals(item, dto.getItem_code()));
|
||||
|
||||
return dto;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (OpcConfig.opc_item_read_using_callback) {
|
||||
this.runNew();
|
||||
} else {
|
||||
this.runOld();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void runOld() {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class);
|
||||
while (true) {
|
||||
start:
|
||||
try {
|
||||
group= opcServerService.getServer(this.OpcServer.getOpc_code());
|
||||
if (this.group != null) {
|
||||
group.clear();
|
||||
group.remove();
|
||||
log.trace("清理group...");
|
||||
}
|
||||
if (this.server != null) {
|
||||
server.disconnect();
|
||||
log.trace("清理server...");
|
||||
}
|
||||
|
||||
// group =opcServerService.getServer(this.getOpcServer().getOpc_code());
|
||||
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
||||
this.server.addStateListener(this);
|
||||
group = this.server.addGroup();
|
||||
List<String> itemsString = new ArrayList();
|
||||
Iterator it = this.protocols.iterator();
|
||||
Iterator var3 = this.protocols.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
OpcItemDto protocol = (OpcItemDto) it.next();
|
||||
while (var3.hasNext()) {
|
||||
OpcItemDto protocol = (OpcItemDto) var3.next();
|
||||
String item = protocol.getItem_code();
|
||||
itemsString.add(item);
|
||||
}
|
||||
@@ -80,66 +113,60 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
Map<String, Item> itemsMap = new LinkedHashMap();
|
||||
boolean is_error = false;
|
||||
StringBuilder err_message = new StringBuilder();
|
||||
Iterator var7 = itemsString.iterator();
|
||||
Iterator var6 = itemsString.iterator();
|
||||
|
||||
while (var7.hasNext()) {
|
||||
String string = (String) var7.next();
|
||||
while (var6.hasNext()) {
|
||||
String string = (String) var6.next();
|
||||
|
||||
try {
|
||||
itemsMap.put(string, group.addItem(string));
|
||||
Item item = group.addItem(string);
|
||||
itemsMap.put(string, item);
|
||||
log.trace("添加成功 {}", string);
|
||||
} catch (Exception var29) {
|
||||
err_message.append(string + ":" + var29.getMessage());
|
||||
} catch (Exception var26) {
|
||||
err_message.append(string + ":" + var26.getMessage());
|
||||
if (!is_error) {
|
||||
is_error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String tag;
|
||||
if (is_error) {
|
||||
log.info("设备OPC数据同步配置异常," + err_message);
|
||||
tag = err_message.toString();
|
||||
log.warn("{}:{}", OpcConfig.resource_code, tag);
|
||||
}
|
||||
|
||||
if (!OpcStartTag.is_run) {
|
||||
OpcStartTag.is_run = true;
|
||||
}
|
||||
|
||||
// 线程名
|
||||
String tag = Thread.currentThread().getName();
|
||||
if (this.OpcServer != null) {
|
||||
tag = tag + this.OpcServer.getOpc_code();
|
||||
tag = "";
|
||||
if (log.isWarnEnabled()) {
|
||||
tag = Thread.currentThread().getName();
|
||||
if (this.OpcServer != null) {
|
||||
tag = tag + this.getOpcGroupID();
|
||||
}
|
||||
}
|
||||
UnifiedDataAccessor accessor_value =
|
||||
UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
|
||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
boolean time_out = false;
|
||||
|
||||
label97:
|
||||
while (true) {
|
||||
// System.out.println("label97");
|
||||
while (DeviceOpcSynchronizeAutoRun.isRun) {
|
||||
long begin = System.currentTimeMillis();
|
||||
Map<Item, ItemState> itemStatus =null;
|
||||
|
||||
try{
|
||||
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
}catch (Exception e){
|
||||
try{
|
||||
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
}catch (Exception e2){
|
||||
itemStatus=group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//TODO 读完释放server可行否?
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||
}
|
||||
|
||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
long end = System.currentTimeMillis();
|
||||
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||
long duration = end - begin;
|
||||
log.trace("{} 读取耗时:{}", tag, duration);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("{} 读取耗时:{}", tag, duration);
|
||||
}
|
||||
|
||||
if (duration > 1000L) {
|
||||
if (!time_out) {
|
||||
log.warn(" {} 读取超时 : {} ", tag, duration);
|
||||
log.warn("{} 读取超时 : {}", tag, duration);
|
||||
}
|
||||
|
||||
time_out = true;
|
||||
@@ -147,89 +174,265 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
||||
time_out = false;
|
||||
}
|
||||
|
||||
// A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表
|
||||
boolean valueAllNotNull = false;
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var18 = items.iterator();
|
||||
|
||||
while (true) {
|
||||
Item item;
|
||||
// A1_HK_04.A1_HK_04.A1_HK_04_3.door
|
||||
// 当前值
|
||||
Object value;
|
||||
// 旧的值
|
||||
Object his;
|
||||
do {
|
||||
if (!var18.hasNext()) {
|
||||
end = System.currentTimeMillis();
|
||||
log.trace("{}", itemsString);
|
||||
log.trace("{} 计算完成耗时{}", tag, end - begin);
|
||||
Thread.sleep((long) OpcConfig.synchronized_millisecond);
|
||||
if (this.error_num != 0) {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
}
|
||||
// 所有信号读完并且没有变化的值
|
||||
continue label97;
|
||||
}
|
||||
|
||||
item = (Item) var18.next();
|
||||
ItemState itemState = itemStatus.get(item);
|
||||
value = OpcUtl.getValue(item, itemState);
|
||||
his = accessor_value.getValue(item.getId());
|
||||
if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD)
|
||||
&& his != null) {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality());
|
||||
}
|
||||
} while (ObjectUtil.equal(value, his)); // 如果两次的值相等,不走下面的代码
|
||||
|
||||
OpcItemDto itemDto = this.getItem(item.getId());
|
||||
if (itemDto.getNeed_log() != null && itemDto.getNeed_log()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
// 设备的ITEM项
|
||||
List<String> relate_items = itemDto.getRelate_items();
|
||||
Iterator var26 = relate_items.iterator();
|
||||
|
||||
while (var26.hasNext()) {
|
||||
String relate = (String) var26.next();
|
||||
Object obj = accessor_value.getValue(relate);
|
||||
sb.append("key:" + relate + "value:" + obj + ";");
|
||||
}
|
||||
|
||||
log.info("信号{}变更从{}->{};信号快照:{}", new Object[] {item.getId(), his, value, sb});
|
||||
while (var18.hasNext()) {
|
||||
Item item = (Item) var18.next();
|
||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
||||
Object value = OpcUtl.getValue(item, itemState);
|
||||
if (value != null) {
|
||||
valueAllNotNull = true;
|
||||
}
|
||||
// 设置值
|
||||
accessor_value.setValue(item.getId(), value);
|
||||
}
|
||||
}
|
||||
} catch (Exception var30) {
|
||||
|
||||
if (group != null) {
|
||||
String itemId = item.getId();
|
||||
Object his = accessor_value.getValue(itemId);
|
||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
valueAllNotNull = false;
|
||||
}
|
||||
|
||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
||||
OpcItemDto itemDto = this.getItem(itemId);
|
||||
if (true) {
|
||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
}
|
||||
if(!ObjectUtil.isEmpty(value)){
|
||||
accessor_value.setValue(itemId, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end = System.currentTimeMillis();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("{}", itemsString);
|
||||
log.trace("{} 计算完成耗时{}", tag, end - begin);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond);
|
||||
if (this.error_num != 0) {
|
||||
this.error_num = 0;
|
||||
this.message = null;
|
||||
}
|
||||
|
||||
if (!valueAllNotNull) {
|
||||
int random = (new Random()).nextInt(10) + 1;
|
||||
random *= 1000;
|
||||
if (this.all_null < 3) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,3);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep( 3000);
|
||||
break start;
|
||||
} else if (this.all_null < 6) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(tag + "重新创建server");
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,3);
|
||||
}
|
||||
ThreadUtl.sleep(3000);
|
||||
break start;
|
||||
} else if (this.all_null < 12) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(tag + "重新创建server");
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,3);
|
||||
}
|
||||
ThreadUtl.sleep(3000);
|
||||
break start;
|
||||
} else {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 5000);
|
||||
}
|
||||
ThreadUtl.sleep((long) (5000));
|
||||
}
|
||||
|
||||
++this.all_null;
|
||||
} else {
|
||||
this.all_null = 0;
|
||||
}
|
||||
// break start;
|
||||
|
||||
}
|
||||
|
||||
log.warn("opc线程停止。。。");
|
||||
return;
|
||||
} catch (Exception var27) {
|
||||
if (this.server != null) {
|
||||
try {
|
||||
group.getServer().dispose();
|
||||
group.clear();
|
||||
group.remove();
|
||||
} catch (Exception var6) {
|
||||
this.server.disconnect();
|
||||
} catch (Exception var25) {
|
||||
}
|
||||
this.group = null;
|
||||
}
|
||||
|
||||
this.server = null;
|
||||
if (!DeviceOpcSynchronizeAutoRun.isRun) {
|
||||
log.warn("opc线程停止2。。。");
|
||||
return;
|
||||
}
|
||||
|
||||
String error_message = "设备信息同步异常";
|
||||
if (!StrUtil.equals(this.message, error_message)) {
|
||||
log.warn("", var30);
|
||||
log.warn(error_message, var27);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ThreadUtl.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||
++this.error_num;
|
||||
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
||||
log.info("设备同步通信异常");
|
||||
this.message = error_message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void runNew() {
|
||||
Async20Access accessor = null;
|
||||
|
||||
while (true) {
|
||||
String opcGroupId = this.getOpcGroupID();
|
||||
|
||||
try {
|
||||
if (this.server == null) {
|
||||
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
||||
this.server.addStateListener(this);
|
||||
accessor = new Async20Access(this.server, OpcConfig.synchronized_millisecond, true);
|
||||
Iterator var9 = this.protocols.iterator();
|
||||
|
||||
while (var9.hasNext()) {
|
||||
OpcItemDto protocol = (OpcItemDto) var9.next();
|
||||
String itemId = protocol.getItem_code();
|
||||
accessor.addItem(itemId, this);
|
||||
}
|
||||
|
||||
accessor.bind();
|
||||
log.info("Async20Access bind {}", opcGroupId);
|
||||
}
|
||||
|
||||
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||
} catch (Exception var8) {
|
||||
if (accessor != null) {
|
||||
try {
|
||||
log.warn("Async20Access unbind {}", opcGroupId);
|
||||
accessor.unbind();
|
||||
} catch (Exception var7) {
|
||||
var7.printStackTrace();
|
||||
}
|
||||
|
||||
accessor = null;
|
||||
}
|
||||
|
||||
if (this.server != null) {
|
||||
try {
|
||||
this.server.disconnect();
|
||||
} catch (Exception var6) {
|
||||
}
|
||||
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
if (var8 instanceof InterruptedException) {
|
||||
log.warn("OPC 同步线程(%s)被中断", opcGroupId);
|
||||
return;
|
||||
}
|
||||
|
||||
log.warn("设备信息同步异常", var8);
|
||||
ThreadUtl.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||
String error_message = var8.getMessage();
|
||||
if (error_message == null) {
|
||||
error_message = var8.toString();
|
||||
}
|
||||
|
||||
++this.error_num;
|
||||
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
||||
this.message = error_message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void connectionStateChanged(boolean connected) {
|
||||
if (!connected) {
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
|
||||
}
|
||||
|
||||
private String getOpcGroupID() {
|
||||
String var10000 = this.OpcServer.getOpc_code();
|
||||
return var10000 + "(" + this.protocols.size() + " items)";
|
||||
}
|
||||
|
||||
public static String formatDuring(long mss) {
|
||||
long days = mss / 86400000L;
|
||||
long hours = mss % 86400000L / 3600000L;
|
||||
long minutes = mss % 3600000L / 60000L;
|
||||
long seconds = mss % 60000L / 1000L;
|
||||
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
|
||||
}
|
||||
|
||||
|
||||
public void changed(Item item, ItemState itemState) {
|
||||
String itemId = item.getId();
|
||||
|
||||
try {
|
||||
Object value = OpcUtl.getValue(item, itemState);
|
||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
accessor_value.setValue(itemId, value);
|
||||
|
||||
// if (value != null) {
|
||||
// if (log.isTraceEnabled()) {
|
||||
// log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||
// }
|
||||
// } else if (log.isInfoEnabled()) {
|
||||
// log.info("Item {} new value: {}, Timestamp: {}, Quality: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime(), itemState.getQuality()});
|
||||
// }
|
||||
log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||
|
||||
OpcItemDto itemDto = this.getItem(itemId);
|
||||
// if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
||||
// this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
// }
|
||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
|
||||
} catch (Exception var7) {
|
||||
log.error(itemId, var7);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void logItemChanged(String itemId, UnifiedDataAccessor accessor_value, Object value, OpcItemDto itemDto) {
|
||||
Object his = accessor_value.getValue(itemId);
|
||||
List<String> relate_items = itemDto.getRelate_items();
|
||||
if (relate_items != null && !relate_items.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Iterator var8 = relate_items.iterator();
|
||||
|
||||
while (var8.hasNext()) {
|
||||
String relate = (String) var8.next();
|
||||
Object obj = accessor_value.getValue(relate);
|
||||
sb.append("key:" + relate + "value:" + obj + ";");
|
||||
}
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
|
||||
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{};信号快照:{}", new Object[]{itemId, his, value, sb});
|
||||
} else {
|
||||
// if(his instanceof int[]){
|
||||
// if(!Arrays.equals((long[]) his, (long[]) value)){
|
||||
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// }
|
||||
// } else if(his instanceof String){
|
||||
// if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
|
||||
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// }
|
||||
// } else {
|
||||
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// }
|
||||
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
package org.nl.acs.opc;
|
||||
|
||||
|
||||
import org.nl.modules.wql.exception.WDKException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ObjectUtl {
|
||||
private ObjectUtl() {
|
||||
}
|
||||
|
||||
public static boolean isEquals(Object a, Object b) {
|
||||
if (a == null && b == null) {
|
||||
return true;
|
||||
} else if (a != null && b != null) {
|
||||
if (a.getClass().isArray()) {
|
||||
if (a instanceof boolean[]) {
|
||||
return Arrays.equals((boolean[]) ((boolean[]) a), (boolean[]) ((boolean[]) b));
|
||||
} else if (a instanceof byte[]) {
|
||||
return Arrays.equals((byte[]) ((byte[]) a), (byte[]) ((byte[]) b));
|
||||
} else if (a instanceof int[]) {
|
||||
return Arrays.equals((int[]) ((int[]) a), (int[]) ((int[]) b));
|
||||
} else if (a instanceof long[]) {
|
||||
return Arrays.equals((long[]) ((long[]) a), (long[]) ((long[]) b));
|
||||
} else if (a instanceof double[]) {
|
||||
return Arrays.equals((double[]) ((double[]) a), (double[]) ((double[]) b));
|
||||
} else if (a instanceof short[]) {
|
||||
return Arrays.equals((short[]) ((short[]) a), (short[]) ((short[]) b));
|
||||
} else if (a instanceof char[]) {
|
||||
return Arrays.equals((char[]) ((char[]) a), (char[]) ((char[]) b));
|
||||
} else if (a instanceof float[]) {
|
||||
return Arrays.equals((float[]) ((float[]) a), (float[]) ((float[]) b));
|
||||
} else if (a instanceof Object[]) {
|
||||
return Arrays.equals((Object[]) ((Object[]) a), (Object[]) ((Object[]) b));
|
||||
} else {
|
||||
throw new WDKException("未实现");
|
||||
}
|
||||
} else {
|
||||
return Objects.equals(a, b);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isTrue(Boolean boolean_) {
|
||||
return boolean_ != null && isEquals(boolean_, true);
|
||||
}
|
||||
|
||||
public static boolean isTrue(Boolean targetBoolean, boolean defaultBoolean) {
|
||||
return targetBoolean == null ? defaultBoolean : targetBoolean;
|
||||
}
|
||||
|
||||
public static boolean isFalse(Boolean boolean_) {
|
||||
return boolean_ != null && isEquals(boolean_, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean isObject(Class<?> clazz) {
|
||||
if (clazz == null) {
|
||||
return false;
|
||||
} else if (clazz.getClass().isArray()) {
|
||||
return false;
|
||||
} else {
|
||||
return Object.class.isAssignableFrom(clazz);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +290,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
@Override
|
||||
public TaskDto findById(String task_id) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_task");
|
||||
JSONObject json = wo.query("task_id ='" + task_id + "'").uniqueResult(0);
|
||||
JSONObject json = wo.query("task_id ='" + task_id + "'","create_time desc").uniqueResult(0);
|
||||
final TaskDto obj = json.toJavaObject(TaskDto.class);
|
||||
return obj;
|
||||
}
|
||||
@@ -306,7 +306,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
||||
@Override
|
||||
public TaskDto findByCode(String code) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_task");
|
||||
JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0);
|
||||
JSONObject json = wo.query("task_code ='" + code + "'","create_time desc").uniqueResult(0);
|
||||
final TaskDto obj = json.toJavaObject(TaskDto.class);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -5,13 +5,19 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.agv.server.AgvService;
|
||||
import org.nl.acs.agv.server.dto.AgvDto;
|
||||
import org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver;
|
||||
import org.nl.acs.device_driver.basedriver.agv.xg_agv.XgagvDeviceDriver;
|
||||
import org.nl.acs.ext.wms.service.AcsToWmsService;
|
||||
import org.nl.acs.opc.Device;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.opc.DeviceType;
|
||||
import org.nl.modules.mnt.websocket.MsgType;
|
||||
import org.nl.modules.mnt.websocket.SocketMsg;
|
||||
import org.nl.modules.mnt.websocket.WebSocketServer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -25,52 +31,97 @@ public class ToAgvDevice {
|
||||
AcsToWmsService acsToWmsService;
|
||||
@Autowired
|
||||
AgvService agvService;
|
||||
@Autowired
|
||||
DeviceAppService deviceAppService;
|
||||
|
||||
public void run() throws Exception {
|
||||
JSONObject json = new JSONObject();
|
||||
Map<String, AgvDto> agv_map = agvService.findAllAgvFromCache();
|
||||
|
||||
JSONArray agv_rows = new JSONArray();
|
||||
JSONObject row = new JSONObject();
|
||||
|
||||
for (AgvDto agvDto : agv_map.values()) {
|
||||
row.put("device_code", agvDto.getName());
|
||||
row.put("energyLevel", agvDto.getEnergyLevel());
|
||||
if (agvDto.getState().equals("UNKNOWN")) {
|
||||
row.put("status_name", "有任务");
|
||||
row.put("flag", "1");
|
||||
AgvNdcOneDeviceDriver agvNdcOneDeviceDriver;
|
||||
XgagvDeviceDriver xgagvDeviceDriver;
|
||||
try {
|
||||
List<Device> deviceList = deviceAppService.findDeviceByType(DeviceType.agv);
|
||||
for(Device device:deviceList) {
|
||||
if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) {
|
||||
JSONObject row = new JSONObject();
|
||||
agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver();
|
||||
row.put("device_code", String.valueOf(device.getDevice_code()));
|
||||
row.put("energyLevel", String.valueOf(agvNdcOneDeviceDriver.getElectric_qty()));
|
||||
// 车状态:
|
||||
// 1:关机
|
||||
// 2:运行中
|
||||
// 3:交通管制
|
||||
// 4:任务等待
|
||||
// 5:充电中
|
||||
// 6:故障中
|
||||
// 7:低电量
|
||||
if (agvNdcOneDeviceDriver.getStatus()==1) {
|
||||
row.put("device_status", "UNKNOWN");
|
||||
row.put("status_name", "关机");
|
||||
} else if (agvNdcOneDeviceDriver.getStatus()==2) {
|
||||
row.put("device_status", "EXECUTING");
|
||||
row.put("status_name", "有任务");
|
||||
} else if (agvNdcOneDeviceDriver.getStatus()==3) {
|
||||
row.put("device_status", "UNAVAILABLE");
|
||||
row.put("status_name", "交通管制");
|
||||
} else if (agvNdcOneDeviceDriver.getStatus()==4) {
|
||||
row.put("device_status", "IDLE");
|
||||
row.put("status_name", "空闲");
|
||||
} else if (agvNdcOneDeviceDriver.getStatus()==5) {
|
||||
row.put("device_status", "CHARGING");
|
||||
row.put("status_name", "充电");
|
||||
} else if (agvNdcOneDeviceDriver.getStatus()==6) {
|
||||
row.put("device_status", "ERROR");
|
||||
row.put("status_name", "故障");
|
||||
} else if (agvNdcOneDeviceDriver.getStatus()==7) {
|
||||
row.put("device_status", "ERROR");
|
||||
row.put("status_name", "低电量");
|
||||
}
|
||||
|
||||
row.put("transportOrder", String.valueOf(agvNdcOneDeviceDriver.getOrder()));
|
||||
row.put("positionX", String.valueOf(agvNdcOneDeviceDriver.getX()));
|
||||
row.put("positionY", String.valueOf(agvNdcOneDeviceDriver.getY()));
|
||||
row.put("positionAngle", String.valueOf(agvNdcOneDeviceDriver.getAngle()));
|
||||
agv_rows.add(row);
|
||||
|
||||
}else if (device.getDeviceDriver() instanceof XgagvDeviceDriver){
|
||||
JSONObject row = new JSONObject();
|
||||
xgagvDeviceDriver = (XgagvDeviceDriver) device.getDeviceDriver();
|
||||
row.put("device_code", String.valueOf(device.getDevice_code()));
|
||||
row.put("energyLevel", String.valueOf(xgagvDeviceDriver.getElectricity()));
|
||||
// 车状态:
|
||||
// 1:关机
|
||||
// 2:运行中
|
||||
// 3:交通管制
|
||||
// 4:任务等待
|
||||
// 5:充电中
|
||||
// 6:故障中
|
||||
// 7:低电量
|
||||
if (xgagvDeviceDriver.getFlag()==0) {
|
||||
row.put("device_status", "UNKNOWN");
|
||||
row.put("status_name", "关机");
|
||||
} else if (xgagvDeviceDriver.getFlag()==1) {
|
||||
row.put("device_status", "EXECUTING");
|
||||
row.put("status_name", "有任务");
|
||||
} else if (xgagvDeviceDriver.getFlag()==2) {
|
||||
row.put("device_status", "IDLE");
|
||||
row.put("status_name", "空闲");
|
||||
} else if (xgagvDeviceDriver.getFlag()==3) {
|
||||
row.put("device_status", "CHARGING");
|
||||
row.put("status_name", "充电");
|
||||
}
|
||||
row.put("transportOrder", String.valueOf(xgagvDeviceDriver.getOrder()));
|
||||
row.put("positionX", String.valueOf(xgagvDeviceDriver.getX()));
|
||||
row.put("positionY", String.valueOf(xgagvDeviceDriver.getY()));
|
||||
row.put("positionAngle", String.valueOf(xgagvDeviceDriver.getAngle()));
|
||||
agv_rows.add(row);
|
||||
}
|
||||
}
|
||||
if (agvDto.getState().equals("UNAVAILABLE")) {
|
||||
row.put("status_name", "网络异常");
|
||||
row.put("flag", "1");
|
||||
}
|
||||
if (agvDto.getState().equals("ERROR")) {
|
||||
row.put("status_name", "机器错误");
|
||||
row.put("flag", "1");
|
||||
}
|
||||
if (agvDto.getState().equals("IDLE")) {
|
||||
row.put("status_name", "空闲");
|
||||
row.put("flag", "0");
|
||||
}
|
||||
if (agvDto.getState().equals("EXECUTING")) {
|
||||
row.put("status_name", "运行中");
|
||||
row.put("flag", "0");
|
||||
}
|
||||
if (agvDto.getState().equals("CHARGING")) {
|
||||
row.put("status_name", "充电中");
|
||||
row.put("flag", "0");
|
||||
}
|
||||
row.put("transportOrder", agvDto.getTransportOrder());
|
||||
row.put("positionX", agvDto.getPositionX());
|
||||
row.put("positionY", agvDto.getPositionY());
|
||||
row.put("positionAngle", agvDto.getPositionAngle());
|
||||
agv_rows.add(row);
|
||||
|
||||
}catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
json.put("agv_rows", agv_rows);
|
||||
SocketMsg deviceInfo = new SocketMsg(json, MsgType.INFO);
|
||||
WebSocketServer.sendInfo(deviceInfo, "toAgvDevice_data");
|
||||
|
||||
// acsToWmsService.feedbackAgv(row);
|
||||
acsToWmsService.feedbackAgv(agv_rows);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,4 +73,6 @@ public interface DictService {
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<DictDto> queryAll, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
|
||||
List<Dict> queryAll();
|
||||
}
|
||||
|
||||
@@ -119,4 +119,9 @@ public class DictServiceImpl implements DictService {
|
||||
public void delCaches(Dict dict){
|
||||
redisUtils.del("dict::name:" + dict.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Dict> queryAll() {
|
||||
return dictRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user