This commit is contained in:
USER-20220102CG\noblelift
2023-03-01 19:48:55 +08:00
parent d3662bb58b
commit 89a0226c57
50 changed files with 843 additions and 202 deletions

View File

@@ -46,14 +46,14 @@ public class ConveyorDevice {
public void run() { public void run() {
System.out.println("test"); System.out.println("test");
String MODE = "RD1.RD1." + id + ".mode"; String MODE = "RD1.RD1." + id + ".mode";
String code = OpcUtl.read(MODE); // String code = OpcUtl.read(MODE);
if ("2".equals(code)) { // if ("2".equals(code)) {
TaskService taskserver = SpringContextHolder.getBean(TaskServiceImpl.class); // TaskService taskserver = SpringContextHolder.getBean(TaskServiceImpl.class);
TaskDto dto = new TaskDto(); // TaskDto dto = new TaskDto();
dto.setStart_point_code(id); // dto.setStart_point_code(id);
dto.setNext_point_code("1002"); // dto.setNext_point_code("1002");
taskserver.create(dto); // taskserver.create(dto);
} // }
} }
} }
} }

View File

@@ -0,0 +1,36 @@
package org.nl.acs.device_driver.driver;
/**
* @author ldjun
* @version 1.0
* @date 2023年02月01日 11:21
* @desc desc
*/
public class ItemValue {
private String item_code;
private Object item_value;
public ItemValue() {
}
public ItemValue(String item_code, Object item_value) {
this.item_code = item_code;
this.item_value = item_value;
}
public String getItem_code() {
return this.item_code;
}
public void setItem_code(String item_code) {
this.item_code = item_code;
}
public Object getItem_value() {
return this.item_value;
}
public void setItem_value(Object item_value) {
this.item_value = item_value;
}
}

View File

@@ -64,27 +64,27 @@ public interface OpcDeviceDriver extends DeviceDriver {
} }
default Float getFloatValue(String protocol) { default Float getFloatValue(String protocol) {
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); // RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
return (Float)redisUtils.get(this.getItem(protocol)); // return (Float)redisUtils.get(this.getItem(protocol));
// return (Float) this.getOpcValueAccessor().getValue(this.getItem(protocol)); return (Float) this.getOpcValueAccessor().getValue(this.getItem(protocol));
} }
default int[] getIntegeregerArrayValue(String protocol) { default int[] getIntegeregerArrayValue(String protocol) {
// return (int[]) this.getOpcValueAccessor().getValue(this.getItem(protocol)); return (int[]) this.getOpcValueAccessor().getValue(this.getItem(protocol));
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); // RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
return (int[])redisUtils.get(this.getItem(protocol)); // return (int[])redisUtils.get(this.getItem(protocol));
} }
default String getStringValue(String protocol) { default String getStringValue(String protocol) {
// return (String) this.getOpcValueAccessor().getValue(this.getItem(protocol)); return (String) this.getOpcValueAccessor().getValue(this.getItem(protocol));
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); // RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
return (String)redisUtils.get(this.getItem(protocol)); // return (String)redisUtils.get(this.getItem(protocol));
} }
default Object getValue(String protocol) { default Object getValue(String protocol) {
// return this.getOpcValueAccessor().getValue(this.getItem(protocol)); return this.getOpcValueAccessor().getValue(this.getItem(protocol));
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); // RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
return redisUtils.get(this.getItem(protocol)); // return redisUtils.get(this.getItem(protocol));
} }
default String getItem(String item) { default String getItem(String item) {

View File

@@ -84,7 +84,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -161,12 +161,7 @@ public class LnshLaminatingMachineDeviceDriver extends AbstractOpcDeviceDriver i
return; return;
} }
if (!this.itemProtocol.getIsonline()) { if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);
message = "未联机"; message = "未联机";

View File

@@ -153,7 +153,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -258,11 +258,7 @@ public class LnshKilnLaneDeviceDriver extends AbstractOpcDeviceDriver implements
if (this.isStop()) { if (this.isStop()) {
//未在线无心跳 //未在线无心跳
} else if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) { } else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);

View File

@@ -82,7 +82,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -142,11 +142,6 @@ public class LnshLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver imp
if (this.isStop()) { if (this.isStop()) {
//未在线无心跳 //未在线无心跳
} else if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) { } else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);

View File

@@ -114,7 +114,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -204,12 +204,7 @@ public class LnshOneRGVDeviceDriver extends AbstractOpcDeviceDriver implements D
return; return;
} }
if (!this.itemProtocol.getIsonline()) { if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);
message = "未联机"; message = "未联机";

View File

@@ -789,7 +789,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -664,12 +664,7 @@ public class LnshPackagePalletManipulatorDeviceDriver extends AbstractOpcDeviceD
return; return;
} }
if (!this.itemProtocol.getIsonline()) { if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);
message = "未联机"; message = "未联机";

View File

@@ -193,7 +193,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); // //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -258,11 +258,6 @@ public class LnshPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDri
if (this.isStop()) { if (this.isStop()) {
//未在线无心跳 //未在线无心跳
} else if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) { } else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);

View File

@@ -192,7 +192,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -174,7 +174,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -723,7 +723,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -117,7 +117,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -210,11 +210,6 @@ public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements
if (this.isStop()) { if (this.isStop()) {
//未在线无心跳 //未在线无心跳
} else if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) { } else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);

View File

@@ -799,7 +799,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -84,7 +84,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -180,12 +180,8 @@ public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver
return; return;
} }
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false); if (mode == 0) {
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);
message = "未联机"; message = "未联机";

View File

@@ -101,7 +101,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -96,7 +96,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -79,7 +79,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -72,7 +72,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -146,13 +146,6 @@ public class StandardEmptyPalletSiteDeviceDriver extends AbstractOpcDeviceDriver
if (this.isStop()) { if (this.isStop()) {
//未在线无心跳
} else if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) { } else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);

View File

@@ -74,7 +74,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -209,12 +209,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
return; return;
} }
if (!this.itemProtocol.getIsonline()) { if (mode == 0) {
this.setIsonline(false);
this.setIserror(true);
message = "信号量同步异常";
//未联机
} else if (mode == 0) {
this.setIsonline(false); this.setIsonline(false);
this.setIserror(true); this.setIserror(true);
message = "未联机"; message = "未联机";

View File

@@ -94,7 +94,7 @@ public class ItemProtocol {
public int getOpcIntegerValue(String protocol) { public int getOpcIntegerValue(String protocol) {
Integer value = this.driver.getIntegeregerValue(protocol); Integer value = this.driver.getIntegeregerValue(protocol);
if (value == null) { if (value == null) {
log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); //log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!");
setIsonline(false); setIsonline(false);
} else { } else {
setIsonline(true); setIsonline(true);

View File

@@ -309,12 +309,12 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) { if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorSiteDeviceDriver) {
lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver(); lnshPalletizingManipulatorSiteDeviceDriver = (LnshPalletizingManipulatorSiteDeviceDriver) device.getDeviceDriver();
if (lnshPalletizingManipulatorSiteDeviceDriver.getIserror() // if (lnshPalletizingManipulatorSiteDeviceDriver.getIserror()
&& !device_code.equals("MDJXS601") // && !device_code.equals("MDJXS601")
&& !device_code.equals("MDJXS201") // && !device_code.equals("MDJXS201")
&& !device_code.equals("MDJXS301")) { // && !device_code.equals("MDJXS301")) {
throw new BadRequestException("设备状态异常,下发失败!"); // throw new BadRequestException("设备状态异常,下发失败!");
} // }
if (StrUtil.isEmpty(qty)) { if (StrUtil.isEmpty(qty)) {
throw new WDKException("数量不能为空"); throw new WDKException("数量不能为空");
} }
@@ -329,10 +329,10 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
} }
if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorDeviceDriver) { if (device.getDeviceDriver() instanceof LnshPalletizingManipulatorDeviceDriver) {
lnshPalletizingManipulatorDeviceDriver = (LnshPalletizingManipulatorDeviceDriver) device.getDeviceDriver(); lnshPalletizingManipulatorDeviceDriver = (LnshPalletizingManipulatorDeviceDriver) device.getDeviceDriver();
if (lnshPalletizingManipulatorDeviceDriver.getIserror() // if (lnshPalletizingManipulatorDeviceDriver.getIserror()
&& !device_code.equals("MDJXS601")) { // && !device_code.equals("MDJXS601")) {
throw new BadRequestException("设备状态异常,下发失败!"); // throw new BadRequestException("设备状态异常,下发失败!");
} // }
if (StrUtil.isEmpty(qty)) { if (StrUtil.isEmpty(qty)) {
throw new WDKException("数量不能为空"); throw new WDKException("数量不能为空");
} }
@@ -347,9 +347,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
} }
if (device.getDeviceDriver() instanceof LnshSplitManipulatorDeviceDriver) { if (device.getDeviceDriver() instanceof LnshSplitManipulatorDeviceDriver) {
lnshSplitManipulatorDeviceDriver = (LnshSplitManipulatorDeviceDriver) device.getDeviceDriver(); lnshSplitManipulatorDeviceDriver = (LnshSplitManipulatorDeviceDriver) device.getDeviceDriver();
if (lnshSplitManipulatorDeviceDriver.getIserror()) { // if (lnshSplitManipulatorDeviceDriver.getIserror()) {
throw new BadRequestException("设备状态异常,下发失败!"); // throw new BadRequestException("设备状态异常,下发失败!");
} // }
if (StrUtil.isEmpty(qty)) { if (StrUtil.isEmpty(qty)) {
throw new WDKException("数量不能为空"); throw new WDKException("数量不能为空");
} }
@@ -378,9 +378,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
} }
if (device.getDeviceDriver() instanceof LnshPackagePalletManipulatorDeviceDriver) { if (device.getDeviceDriver() instanceof LnshPackagePalletManipulatorDeviceDriver) {
lnshPackagePalletManipulatorDeviceDriver = (LnshPackagePalletManipulatorDeviceDriver) device.getDeviceDriver(); lnshPackagePalletManipulatorDeviceDriver = (LnshPackagePalletManipulatorDeviceDriver) device.getDeviceDriver();
if (lnshPackagePalletManipulatorDeviceDriver.getIserror()) { // if (lnshPackagePalletManipulatorDeviceDriver.getIserror()) {
throw new BadRequestException("设备状态异常,下发失败!"); // throw new BadRequestException("设备状态异常,下发失败!");
} // }
if (StrUtil.isEmpty(qty)) { if (StrUtil.isEmpty(qty)) {
throw new WDKException("数量不能为空"); throw new WDKException("数量不能为空");
} }
@@ -397,9 +397,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
if (device.getDeviceDriver() instanceof RljnPackagePalletSplitManipulatorDeviceDriver) { if (device.getDeviceDriver() instanceof RljnPackagePalletSplitManipulatorDeviceDriver) {
rljnPackagePalletSplitManipulatorDeviceDriver = (RljnPackagePalletSplitManipulatorDeviceDriver) device.getDeviceDriver(); rljnPackagePalletSplitManipulatorDeviceDriver = (RljnPackagePalletSplitManipulatorDeviceDriver) device.getDeviceDriver();
if (rljnPackagePalletSplitManipulatorDeviceDriver.getIserror()) { // if (rljnPackagePalletSplitManipulatorDeviceDriver.getIserror()) {
throw new BadRequestException("设备状态异常,下发失败!"); // throw new BadRequestException("设备状态异常,下发失败!");
} // }
if (StrUtil.isEmpty(qty)) { if (StrUtil.isEmpty(qty)) {
throw new WDKException("数量不能为空"); throw new WDKException("数量不能为空");
} }

View File

@@ -0,0 +1,107 @@
package org.nl.acs.opc;
import lombok.extern.slf4j.Slf4j;
import org.nl.start.auto.run.ThreadStatusEnum;
import org.nl.start.auto.run.ThreadUsedStatusEnum;
import java.util.Date;
@Slf4j
public abstract class AbstractAutoRunnable implements Runnable {
private ThreadStatusEnum status;
private Date startTime;
private Date stopTime;
private String stopMessage;
private ThreadUsedStatusEnum usedStatus;
@Override
public void run() {
this.setStatus(ThreadStatusEnum.run);
this.setStartTime(new Date());
this.setStopMessage("");
String true_clear = "执行完毕";
try {
this.before();
//子类该方法是个死循环
this.autoRun();
this.setStopMessage(true_clear);
} catch (Throwable arg5) {
log.warn("", arg5);
System.out.println(arg5.getMessage());
// this.setStopMessage(ExceptionUtlEx.getSimpleTrace(arg5));
} finally {
this.setStopTime(new Date());
this.setStatus(ThreadStatusEnum.stop);
this.after();
}
}
public void before() throws Exception {
}
public void after() {
}
public void stop() {
this.after();
}
public Boolean getForbidStop() {
return Boolean.valueOf(false);
}
public Boolean getForbidDisable() {
return Boolean.valueOf(false);
}
public abstract String getCode();
public abstract String getName();
public String getDescription() {
return this.getName();
}
public abstract void autoRun() throws Exception;
public ThreadStatusEnum getStatus() {
return this.status;
}
public void setStatus(ThreadStatusEnum status) {
this.status = status;
}
public Date getStartTime() {
return this.startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getStopTime() {
return this.stopTime;
}
public void setStopTime(Date stopTime) {
this.stopTime = stopTime;
}
public String getStopMessage() {
return this.stopMessage;
}
public void setStopMessage(String stopMessage) {
this.stopMessage = stopMessage;
}
public ThreadUsedStatusEnum getUsedStatus() {
return this.usedStatus;
}
public void setUsedStatus(ThreadUsedStatusEnum usedStatus) {
this.usedStatus = usedStatus;
}
}

View File

@@ -6,8 +6,6 @@ import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.modules.udw.UnifiedDataAccessor; import org.nl.modules.udw.UnifiedDataAccessor;
import org.nl.modules.udw.UnifiedDataAccessorFactory; import org.nl.modules.udw.UnifiedDataAccessorFactory;
import org.nl.utils.RedisUtils;
import org.nl.utils.SpringContextHolder;
import org.openscada.opc.lib.da.Group; import org.openscada.opc.lib.da.Group;
import org.openscada.opc.lib.da.Item; import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState; import org.openscada.opc.lib.da.ItemState;
@@ -21,10 +19,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
OpcServerManageDto OpcServer; OpcServerManageDto OpcServer;
int error_num; int error_num;
String message; String message;
private Server server;
public DeviceOpcProtocolRunable() { public DeviceOpcProtocolRunable() {
this.error_num = 0; this.error_num = 0;
this.message = null; this.message = null;
this.server = null;
} }
public List<OpcItemDto> getProtocols() { public List<OpcItemDto> getProtocols() {
@@ -62,8 +62,12 @@ public class DeviceOpcProtocolRunable implements Runnable {
public void run() { public void run() {
while (true) { while (true) {
try { try {
Server server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
Group group = server.addGroup(); // Group group = server.addGroup(this.OpcServer.getOpc_host());
Group group = server.addGroup(this.OpcServer.getOpc_code());
if(ObjectUtil.isEmpty(group)){
log.info("group is null ");
}
List<String> itemsString = new ArrayList(); List<String> itemsString = new ArrayList();
Iterator it = this.protocols.iterator(); Iterator it = this.protocols.iterator();
@@ -112,11 +116,18 @@ public class DeviceOpcProtocolRunable implements Runnable {
label97: label97:
while (true) { while (true) {
long begin = System.currentTimeMillis(); long begin = System.currentTimeMillis();
Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); Map<Item, ItemState> itemStatus = null;
try {
itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
} catch (Exception e){
System.out.println("数据同步异常:"+ this.getOpcServer().getOpc_code());
//e.printStackTrace();
}
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
log.trace("{} 开始记时{}", tag, DateUtil.now()); log.trace("{} 开始记时{}", tag, DateUtil.now());
long duration = end - begin; long duration = end - begin;
log.trace("{} 读取耗时:{}", tag, duration); log.trace("{} 读取耗时:{}", tag, duration);
System.out.println("线程:"+tag + " 读取耗时:"+ duration);
if (duration > 1000L) { if (duration > 1000L) {
if (!time_out) { if (!time_out) {
log.warn("{} 读取超时 : {}", tag, duration); log.warn("{} 读取超时 : {}", tag, duration);
@@ -127,6 +138,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
time_out = false; time_out = false;
} }
// if(ObjectUtil.isEmpty(itemStatus)) continue label97;
Set<Item> items = itemStatus.keySet(); Set<Item> items = itemStatus.keySet();
Iterator var18 = items.iterator(); Iterator var18 = items.iterator();
@@ -152,11 +165,8 @@ public class DeviceOpcProtocolRunable implements Runnable {
item = (Item) var18.next(); item = (Item) var18.next();
ItemState itemState = (ItemState) itemStatus.get(item); ItemState itemState = (ItemState) itemStatus.get(item);
value = OpcUtl.getValue(item, itemState); value = OpcUtl.getValue(item, itemState);
// his = accessor_value.getValue(item.getId()); his = accessor_value.getValue(item.getId());
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
his=redisUtils.get(item.getId());
if (!ObjectUtil.equal(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality()); log.warn("opc 值不健康 item: {}, 状态: {}", item.getId(), itemState.getQuality());
} }
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码 } while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
@@ -177,16 +187,24 @@ public class DeviceOpcProtocolRunable implements Runnable {
log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb}); log.info("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb});
} }
// accessor_value.setValueWithPersistence(item.getId(),accessor_value.getValue(item.getId()));
// accessor_value.getHistoryUnifiedData(item.getId());
//设置值 //设置值
// accessor_value.setValue(item.getId(), value); accessor_value.setValue(item.getId(), value);
RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class);
redisUtils.set(item.getId(), value);
} }
} }
} catch (Exception var30) { } catch (Exception var30) {
String error_message = "设备信息同步异常"; if (this.server != null) {
try {
this.server.disconnect();
} catch (Exception var25) {
}
}
this.server = null;
String error_message = "设备信息同步异常,"+var30;
if (!StrUtil.equals(this.message, error_message)) { if (!StrUtil.equals(this.message, error_message)) {
log.warn("", var30); log.warn("", var30);
} }
@@ -195,6 +213,7 @@ public class DeviceOpcProtocolRunable implements Runnable {
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000)); Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
// Thread.currentThread().interrupt();不会真正停止线程
} }
++this.error_num; ++this.error_num;
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) { if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {

View File

@@ -0,0 +1,72 @@
package org.nl.acs.opc;
import org.nl.exception.WDKException;
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);
}
}
}

View File

@@ -0,0 +1,21 @@
package org.nl.acs.opc;
import org.nl.acs.device_driver.driver.ItemValue;
import org.openscada.opc.lib.da.Group;
/**
* @author ldjun
* @version 1.0
* @date 2023年02月01日 11:26
* @desc desc
*/
public interface OpcServerService {
void reload();
Group getServer(String var1);
void writeInteger(String var1, ItemValue... var2);
void clearServer(String var1);
}

View File

@@ -0,0 +1,154 @@
package org.nl.acs.opc;
import org.jinterop.dcom.common.JIException;
import org.nl.acs.device_driver.driver.ItemValue;
import org.nl.exception.WDKException;
import org.nl.start.auto.initial.ApplicationAutoInitial;
import org.openscada.opc.lib.common.NotConnectedException;
import org.openscada.opc.lib.da.Group;
import org.openscada.opc.lib.da.Server;
import org.openscada.opc.lib.da.UnknownGroupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.UnknownHostException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @author ldjun
* @version 1.0
* @date 2023年02月01日 11:27
* @desc desc
*/
@Service
public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial {
private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class);
@Autowired OpcServerManageService opcServerManageService;
Map<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
Map<String, Group> groups = Collections.synchronizedMap(new HashMap());
public OpcServerServiceImpl() {}
public void autoInitial() throws Exception {
this.reload();
if (OpcConfig.auto_start_opc) {
Thread t =
new Thread() {
public void run() {
Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator();
while (var1.hasNext()) {
OpcServerManageDto dto = (OpcServerManageDto) var1.next();
try {
OpcServerServiceImpl.this.getServer(dto.getOpc_code());
OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code());
} catch (Exception var4) {
OpcServerServiceImpl.log.warn("启动无法载入servers", var4);
}
}
}
};
t.start();
}
}
public synchronized void reload() {
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
}
public synchronized Group getServer(String code) {
Group group = null;
group = (Group) this.groups.get(code);
if (group != null) {
try {
if (group.isActive()) {
return group;
}
} catch (JIException var9) {
var9.printStackTrace();
}
}
Server server = (Server) this.servers.get(code);
boolean needcreate = false;
if (server == null) {
needcreate = true;
} else {
try {
group = server.findGroup(OpcConfig.opc_server_default_group);
} catch (UnknownHostException
| JIException
| UnknownGroupException
| NotConnectedException
| IllegalArgumentException var8) {
var8.printStackTrace();
needcreate = true;
}
}
if (needcreate) {
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
if (dto == null) {
throw new WDKException("code 不存在");
}
server = OpcServerUtl.getServerWithOutException(
dto.getOpc_host(),
dto.getCls_id(),
dto.getUser(),
dto.getPassword(),
dto.getDomain());
// server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
try {
group = server.addGroup(OpcConfig.opc_server_default_group);
} catch (Exception var7) {
throw new WDKException(var7);
}
this.servers.put(code, server);
this.groups.put(code, group);
}
return group;
}
public synchronized void clearServer(String code) {
try {
Server server = (Server) this.servers.get(code);
if (server!=null){
server.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
log.error("清理server异常,",e.getMessage());
}
this.servers.remove(code);
this.groups.remove(code);
}
public void writeInteger(String code, ItemValue... values) {
try {
Group group = this.getServer(code);
OpcUtl.writeValue(group, values);
} catch (Exception var4) {
this.clearServer(code);
log.warn("写入出错opc server {} 重新加载", code, var4);
ThreadUtl.sleep(5000L);
throw var4;
}
}
}

View File

@@ -4,19 +4,28 @@ import cn.hutool.core.util.NumberUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jinterop.dcom.common.JIException; import org.jinterop.dcom.common.JIException;
import org.jinterop.dcom.core.*; import org.jinterop.dcom.core.*;
import org.nl.acs.device_driver.driver.ItemValue;
import org.nl.exception.BadRequestException; import org.nl.exception.BadRequestException;
import org.nl.exception.WDKException; import org.nl.exception.WDKException;
import org.openscada.opc.lib.common.ConnectionInformation; import org.openscada.opc.lib.common.ConnectionInformation;
import org.openscada.opc.lib.da.*; import org.openscada.opc.lib.da.*;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@Slf4j @Slf4j
public class OpcUtl { public class OpcUtl {
private static int timeout = 180000; private static int timeout = 1*60*1000;
private static String key = "rpc.socketTimeout"; private static String key = "rpc.socketTimeout";
public static int successNum=0;
public static int errNum=0;
static {
checkTimeout();
}
public static void checkTimeout() { public static void checkTimeout() {
if (Integer.getInteger(key, 0).intValue() != timeout) { if (Integer.getInteger(key, 0).intValue() != timeout) {
@@ -26,9 +35,20 @@ public class OpcUtl {
} }
public static void writeValue(Group group, WriteRequest... requests) { public static void writeValue(Group group, WriteRequest... requests) throws WDKException {
try { try {
Map e = group.write(requests); Map<Item, Integer> e=null;
try{
e=group.write(requests);
group.write(requests);
}catch (Exception e1){
try{
e= group.write(requests);
}catch (Exception e2){
e= group.write(requests);
}
}
boolean is_success = true; boolean is_success = true;
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
Iterator arg4 = e.keySet().iterator(); Iterator arg4 = e.keySet().iterator();
@@ -50,9 +70,60 @@ public class OpcUtl {
if (!is_success) { if (!is_success) {
// throw new BusinessException(message.toString()); // throw new BusinessException(message.toString());
System.out.println("下发信号失败:"+message.toString());
System.out.println("下发信号失败原因:"+message.toString());
log.info("下发信号失败:"+message.toString());
throw new WDKException(message.toString());
} }
} catch (JIException arg7) { } catch (JIException arg7) {
// throw new BusinessException(arg7); log.info("下发信号失败:"+arg7.getMessage());
System.out.println("下发信号失败原因:"+arg7.getMessage());
throw new WDKException(arg7);
}
}
public static void writeValue(Group group, ItemValue... values) throws WDKException {
try {
if (values != null && values.length > 0) {
List<WriteRequest> ws = new ArrayList();
ItemValue[] var3 = values;
int var4 = values.length;
for(int var5 = 0; var5 < var4; ++var5) {
ItemValue value = var3[var5];
Item item = group.addItem(value.getItem_code());
ws.add(new WriteRequest(item, getVariant(value.getItem_value())));
}
writeValue(group, (WriteRequest[])ws.toArray(new WriteRequest[0]));
}
} catch (AddFailedException | JIException var8) {
throw new WDKException(var8);
}
}
public static JIVariant getVariant(Object object) {
if (object instanceof Integer) {
return getIntegerVariant((Integer)object);
} else if (object instanceof String) {
return getStringVariant((String)object);
} else if (object instanceof byte[]) {
return getByteArrayVariant((byte[])((byte[])object));
} else if (object instanceof Byte[]) {
return getByteArrayVariant((Byte[])((Byte[])object));
} else if (object instanceof Boolean) {
return new JIVariant((Boolean)object);
} else if (object instanceof int[]) {
return getByteArrayVariantxx((int[])((int[])object));
} else if (object instanceof Integer[]) {
JIArray array = new JIArray((Integer)object, false);
JIVariant value = new JIVariant(array);
return value;
} else if (object instanceof JIVariant) {
return (JIVariant)object;
} else {
throw new WDKException("未实现目前支持是int,string,byte[]");
} }
} }
@@ -60,6 +131,7 @@ public class OpcUtl {
if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) { if (NumberUtil.compare(itemState.getQuality(), Short.valueOf(QualityTypeValue.OPC_QUALITY_GOOD)) != 0) {
if (item != null) { if (item != null) {
log.debug("value is not good {} : {}", item.getId(), itemState.getQuality()); log.debug("value is not good {} : {}", item.getId(), itemState.getQuality());
// throw new WDKException("值不健康进行重连!");
} else { } else {
log.debug("value is not good {}", itemState.getQuality()); log.debug("value is not good {}", itemState.getQuality());
} }
@@ -150,12 +222,28 @@ public class OpcUtl {
server = new Server(getConnection(host, clsid, user, password, domain), server = new Server(getConnection(host, clsid, user, password, domain),
Executors.newSingleThreadScheduledExecutor()); Executors.newSingleThreadScheduledExecutor());
server.connect(); server.connect();
successNum++;
return server; return server;
} catch (Exception e) { } catch (Exception e) {
throw new WDKException(e); errNum++;
// e.printStackTrace();
System.out.println("server error:"+e.getMessage());
throw new WDKException(e.getMessage());
}finally{
System.out.println("successNum:"+successNum);
System.out.println("errNum:"+errNum);
} }
} }
public static Server getAutoServer(String host, String clsid, String user, String password, String domain) throws WDKException {
checkTimeout();
Server server = null;
server = new Server(getConnection(host, clsid, user, password, domain), Executors.newSingleThreadScheduledExecutor());
AutoReconnectController autoReconnectController = new AutoReconnectController(server);
autoReconnectController.connect();
return server;
}
public static ConnectionInformation getConnection(String host, String clsid, String user, String password, public static ConnectionInformation getConnection(String host, String clsid, String user, String password,
String domain) { String domain) {
ConnectionInformation connection = new ConnectionInformation(); ConnectionInformation connection = new ConnectionInformation();
@@ -167,31 +255,44 @@ public class OpcUtl {
return connection; return connection;
} }
public static String read(String item) throws Exception { public static JIVariant getByteArrayVariantxx(int[] bytes) {
System.out.println(item); Integer[] byte_Data = new Integer[bytes.length];
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", "");
// String byteItemString = "RD1.RD1.1001.mode"; for(int i = 0; i < bytes.length; ++i) {
Group group = server.addGroup(); byte_Data[i] = bytes[i];
Item byteItem = group.addItem(item); }
ItemState itemState = null;
JIVariant value = null; JIArray array = new JIArray(byte_Data, false);
itemState = byteItem.read(true); JIVariant value = new JIVariant(array);
value = itemState.getValue(); return value;
String data = OpcUtl.getValue(byteItem, itemState) + "";
return data;
} }
public static void main(String[] args) throws Exception { public static JIVariant getIntegerVariant(Integer integer) {
Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", ""); return new JIVariant(integer);
String byteItemString = "RD1.RD1.1001.mode";
Group group = server.addGroup();
Item byteItem = group.addItem(byteItemString);
ItemState itemState = null;
JIVariant value = null;
System.out.println(byteItem.getId());
itemState = byteItem.read(true);
System.out.println(itemState.getQuality());
System.out.println(getValue(byteItem, itemState));
} }
public static JIVariant getStringVariant(String string) {
return new JIVariant(string);
}
public static JIVariant getByteArrayVariant(byte[] bytes) {
Byte[] byte_Data = new Byte[bytes.length];
for(int i = 0; i < bytes.length; ++i) {
byte_Data[i] = bytes[i];
}
JIArray array = new JIArray(byte_Data, false);
JIVariant value = new JIVariant(array);
return value;
}
public static JIVariant getByteArrayVariant(Byte[] bytes) {
JIArray array = new JIArray(bytes, false);
JIVariant value = new JIVariant(array);
return value;
}
} }

View File

@@ -0,0 +1,21 @@
package org.nl.acs.opc;
/**
* @author ldjun
* @version 1.0
* @date 2023年02月01日 11:28
* @desc desc
*/
public class ThreadUtl {
private ThreadUtl() {
}
public static void sleep(long times) throws RuntimeException {
try {
Thread.sleep(times);
} catch (InterruptedException var3) {
throw new RuntimeException(var3);
}
}
}

View File

@@ -29,7 +29,7 @@ public class opcServerManageServiceImpl implements OpcServerManageService {
public List<OpcServerManageDto> queryAll() { public List<OpcServerManageDto> queryAll() {
//return this.opcServerRepository.queryAll(OpcServerManageDto.class); //return this.opcServerRepository.queryAll(OpcServerManageDto.class);
//OPC表【acs_opc】 //OPC表【acs_opc】
JSONArray arr = WQLObject.getWQLObject("acs_opc").query().getResultJSONArray(0); JSONArray arr = WQLObject.getWQLObject("acs_opc").query("is_active='1' and is_delete='0'").getResultJSONArray(0);
return arr.toJavaList(OpcServerManageDto.class); return arr.toJavaList(OpcServerManageDto.class);
} }

View File

@@ -1,5 +1,6 @@
package org.nl.modules.udw; package org.nl.modules.udw;
import org.nl.modules.udw.UnifiedDataAppService;
import org.nl.modules.udw.service.impl.UnifiedDataAccessorImpl; import org.nl.modules.udw.service.impl.UnifiedDataAccessorImpl;
import org.nl.modules.udw.service.impl.UnifiedDataAppServiceImpl; import org.nl.modules.udw.service.impl.UnifiedDataAppServiceImpl;

View File

@@ -0,0 +1,43 @@
package org.nl.modules.udw.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.udw.service.UdwManageService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequiredArgsConstructor
@Api(tags = "内存点位管理")
@RequestMapping("/api/udw")
@Slf4j
public class UdwManagerController {
private final UdwManageService udwManageService;
// @GetMapping
// @Log("查询内存点位")
// @ApiOperation("查询内存点位")
// @SaIgnore
// public ResponseEntity<Object> query(@RequestParam JSONObject whereJson) {
// return new ResponseEntity<>(udwManageService.queryByConditions(whereJson), HttpStatus.OK);
// }
@GetMapping
@ApiOperation("查询内存点位")
//@PreAuthorize("@el.check('device:list')")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(udwManageService.queryAll(whereJson, page), HttpStatus.OK);
}
}

View File

@@ -2,8 +2,10 @@ package org.nl.modules.udw.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.nl.modules.udw.dto.UdwDto; import org.nl.modules.udw.dto.UdwDto;
import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
import java.util.Map;
public interface UdwManageService { public interface UdwManageService {
/** /**
@@ -13,4 +15,13 @@ public interface UdwManageService {
* @return * @return
*/ */
List<UdwDto> queryByConditions(JSONObject where); List<UdwDto> queryByConditions(JSONObject where);
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> queryAll(Map whereJson, Pageable page);
} }

View File

@@ -1,11 +1,19 @@
package org.nl.modules.udw.service.impl; package org.nl.modules.udw.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.nl.modules.udw.UnifiedData;
import org.nl.modules.udw.UnifiedDataAccessorFactory;
import org.nl.modules.udw.dto.UdwDto; import org.nl.modules.udw.dto.UdwDto;
import org.nl.modules.udw.service.UdwManageService; import org.nl.modules.udw.service.UdwManageService;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
public class UdwManagerServiceImpl implements UdwManageService { public class UdwManagerServiceImpl implements UdwManageService {
@@ -13,4 +21,89 @@ public class UdwManagerServiceImpl implements UdwManageService {
public List<UdwDto> queryByConditions(JSONObject where) { public List<UdwDto> queryByConditions(JSONObject where) {
return null; return null;
} }
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
String unified_key = (String) whereJson.get("unified_key");
String keys = (String) whereJson.get("code");
if(StrUtil.isEmpty(unified_key))
{
unified_key = "opc_value";
}
// String unified_key = (String) whereJson.get("unified_key");
// String code = (String) whereJson.get("code");
// unified_key = whereJson.get("key").toString();
// keys = whereJson.get("value").toString();
//[[{"column":"unified_key","value":"cached","compareType":"equals","columnType":"object"}]]
UnifiedDataUnit unifiedDataUnit = UnifiedDataAccessorFactory.getUnifiedDataAppService().getUnifiedDataUnit(unified_key);
if (unifiedDataUnit == null) {
return null;
} else {
String key;
UdwDto udwDto;
Map storage;
ArrayList udwDtos;
Iterator var14;
if (keys != null) {
storage = unifiedDataUnit.getStorage();
udwDtos = new ArrayList();
var14 = storage.keySet().iterator();
while(var14.hasNext()) {
key = (String)var14.next();
if (key.indexOf(keys) != -1) {
udwDto = new UdwDto();
udwDto.setUnified_key(unified_key);
udwDto.setKey(key);
udwDto.setValue(((UnifiedData)storage.get(key)).getValue());
udwDtos.add(udwDto);
}
}
Integer currentPageNumber = page.getPageNumber() + 1;
Integer pageMaxSize = page.getPageSize();
List orderbyDtoList = (List) udwDtos.stream().skip((currentPageNumber - 1) * pageMaxSize)
.limit(pageMaxSize)
.collect(Collectors.toList());
JSONObject jo = new JSONObject();
jo.put("content", orderbyDtoList);
jo.put("totalElements", udwDtos.size());
return jo;
} else {
storage = unifiedDataUnit.getStorage();
udwDtos = new ArrayList();
var14 = storage.keySet().iterator();
while(var14.hasNext()) {
key = (String)var14.next();
udwDto = new UdwDto();
udwDto.setUnified_key(unified_key);
udwDto.setKey(key);
udwDto.setValue(((UnifiedData)storage.get(key)).getValue());
udwDtos.add(udwDto);
}
Integer currentPageNumber = page.getPageNumber() + 1;
Integer pageMaxSize = page.getPageSize();
List orderbyDtoList = (List) udwDtos.stream().skip((currentPageNumber - 1) * pageMaxSize)
.limit(pageMaxSize)
.collect(Collectors.toList());
JSONObject jo = new JSONObject();
jo.put("content", orderbyDtoList);
jo.put("totalElements", udwDtos.size());
return jo;
}
}
}
} }

View File

@@ -1,7 +1,7 @@
package org.nl.acs.opc; package org.nl.start.auto.run;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import org.nl.start.auto.run.AbstractAutoRunnable; import org.nl.acs.opc.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -17,6 +17,8 @@ import java.util.concurrent.Executors;
*/ */
@Component @Component
public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable { public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
public static boolean isRun = false;
ExecutorService executorService = Executors.newCachedThreadPool(); ExecutorService executorService = Executors.newCachedThreadPool();
@Autowired @Autowired
private DeviceAppService deviceAppService; private DeviceAppService deviceAppService;
@@ -36,24 +38,22 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
@Override @Override
public void autoRun() throws Exception { public void autoRun() throws Exception {
{ {
isRun = true;
Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap(); Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap();
Map<String, List<List<OpcItemDto>>> pros; Map<String, List<List<OpcItemDto>>> pros;
do{ do{
Thread.sleep(1000L); Thread.sleep(1000L);
pros = this.deviceAppService.findAllFormatProtocolFromDriver(); pros = this.deviceAppService.findAllFormatProtocolFromDriver();
}while (ObjectUtil.isEmpty(pros)); }while (ObjectUtil.isEmpty(pros));
Set<String> keys = pros.keySet(); Set<String> keys = pros.keySet();
Iterator var4 = keys.iterator(); Iterator var4 = keys.iterator();
System.out.println("test:" + var4.hasNext());
//代码执行一次 //代码执行一次
while (var4.hasNext()) { while (var4.hasNext()) {
String key = (String) var4.next(); String key = (String) var4.next();
List<List<OpcItemDto>> list = (List) pros.get(key); List<List<OpcItemDto>> list = (List) pros.get(key);
OpcServerManageDto opcServer = (OpcServerManageDto) servers.get(key); OpcServerManageDto opcServer = (OpcServerManageDto) servers.get(key);
Iterator var8 = list.iterator(); Iterator var8 = list.iterator();
System.out.println("test2:" + var8.hasNext());
while (var8.hasNext()) { while (var8.hasNext()) {
List<OpcItemDto> groupProtols = (List) var8.next(); List<OpcItemDto> groupProtols = (List) var8.next();
DeviceOpcProtocolRunable runable = new DeviceOpcProtocolRunable(); DeviceOpcProtocolRunable runable = new DeviceOpcProtocolRunable();
@@ -75,6 +75,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
@Override @Override
public void after() { public void after() {
isRun = false;
this.executorService.shutdownNow(); this.executorService.shutdownNow();
this.executorService = Executors.newCachedThreadPool(); this.executorService = Executors.newCachedThreadPool();
} }

View File

@@ -1,5 +1,10 @@
server: server:
port: 8010 port: 8010
tomcat:
accept-count: 1000
max-connections: 10000
max-threads: 800
min-spare-threads: 100
#配置数据源 #配置数据源
spring: spring:
profiles: profiles:
@@ -8,12 +13,12 @@ spring:
druid: druid:
db-type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:rljn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:jn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
# url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rljn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true # url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rljn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
username: ${DB_USER:root} username: ${DB_USER:root}
# password: ${DB_PWD:P@ssw0rd} # password: ${DB_PWD:P@ssw0rd}
password: ${DB_PWD:Root.123456} # password: ${DB_PWD:Root.123456}
# password: ${DB_PWD:123456} password: ${DB_PWD:123456}
# 初始连接数 # 初始连接数
initial-size: 5 initial-size: 5
# 最小连接数 # 最小连接数

View File

@@ -1,5 +1,10 @@
server: server:
port: 8010 port: 8010
tomcat:
accept-count: 1000
max-connections: 10000
max-threads: 800
min-spare-threads: 100
#配置数据源 #配置数据源
spring: spring:
profiles: profiles:

View File

@@ -2,7 +2,7 @@ spring:
freemarker: freemarker:
check-template-location: false check-template-location: false
profiles: profiles:
active: dev active: prod
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8
data: data:

View File

@@ -1,30 +1,30 @@
<!--<?xml version="1.0" encoding="UTF-8"?>--> <?xml version="1.0" encoding="UTF-8"?>
<!--<included>--> <included>
<!-- <springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>--> <springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
<!-- <springProperty scope="context" name="lokiUrl" source="loki.url"/>--> <springProperty scope="context" name="lokiUrl" source="loki.url"/>
<!-- <property name="LOKI_URL" value="${lokiUrl}"/>--> <property name="LOKI_URL" value="${lokiUrl}"/>
<!-- <property name="log.pattern"--> <property name="log.pattern"
<!-- value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>--> value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>
<!-- &lt;!&ndash;添加loki&ndash;&gt;--> <!--添加loki-->
<!-- <appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">--> <appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
<!-- <batchTimeoutMs>1000</batchTimeoutMs>--> <batchTimeoutMs>1000</batchTimeoutMs>
<!-- <http class="com.github.loki4j.logback.ApacheHttpSender">--> <http class="com.github.loki4j.logback.ApacheHttpSender">
<!-- <url>${LOKI_URL}</url>--> <url>${LOKI_URL}</url>
<!-- </http>--> </http>
<!-- <format>--> <format>
<!-- <label>--> <label>
<!-- <pattern>logType=wms_to_acs</pattern>--> <pattern>logType=wms_to_acs</pattern>
<!-- </label>--> </label>
<!-- <message>--> <message>
<!-- <pattern>${log.pattern}</pattern>--> <pattern>${log.pattern}</pattern>
<!-- </message>--> </message>
<!-- <sortByTime>true</sortByTime>--> <sortByTime>true</sortByTime>
<!-- </format>--> </format>
<!-- </appender>--> </appender>
<!-- &lt;!&ndash; 打印sql &ndash;&gt;--> <!-- 打印sql -->
<!-- <logger name="org.nl.acs.ext.wms.service.impl.WmsToAcsServiceImpl" level="info" additivity="false">--> <logger name="org.nl.acs.ext.wms.service.impl.WmsToAcsServiceImpl" level="info" additivity="false">
<!-- <appender-ref ref="lokiAppender" />--> <appender-ref ref="lokiAppender" />
<!-- </logger>--> </logger>
<!--</included>--> </included>

View File

@@ -21,7 +21,7 @@ https://juejin.cn/post/6844903775631572999
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${logPath}"/> <property name="LOG_HOME" value="${logPath}"/>
<!--引入默认的一些设置--> <!--引入默认的一些设置-->
<!-- <include resource="log/AutoCreateInst.xml"/> <include resource="log/AutoCreateInst.xml"/>
<include resource="log/QueryAgvTaskStatus.xml"/> <include resource="log/QueryAgvTaskStatus.xml"/>
<include resource="log/AgvFeedbackServiceImpl.xml"/> <include resource="log/AgvFeedbackServiceImpl.xml"/>
<include resource="log/AgvLeaveServlet.xml"/> <include resource="log/AgvLeaveServlet.xml"/>
@@ -29,7 +29,7 @@ https://juejin.cn/post/6844903775631572999
<include resource="log/AcsToWms.xml"/> <include resource="log/AcsToWms.xml"/>
<include resource="log/WmsToAcs.xml"/> <include resource="log/WmsToAcs.xml"/>
<include resource="log/QueryXZAgvTaskStatus.xml"/> <include resource="log/QueryXZAgvTaskStatus.xml"/>
<include resource="log/NDCSocketConnectionAutoRun.xml"/>--> <include resource="log/NDCSocketConnectionAutoRun.xml"/>
<!-- <include resource="log/QueryMagicAgvDeviceStatus.xml"/>--> <!-- <include resource="log/QueryMagicAgvDeviceStatus.xml"/>-->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
@@ -85,8 +85,9 @@ https://juejin.cn/post/6844903775631572999
<!--开发环境:打印控制台--> <!--开发环境:打印控制台-->
<springProfile name="dev"> <springProfile name="dev">
<root level="info"> <root level="info">
<!-- <appender-ref ref="CONSOLE"/>--> <appender-ref ref="CONSOLE"/>
<appender-ref ref="lokiAppender" /> <appender-ref ref="lokiAppender" />
<appender-ref ref="asyncFileAppender"/>
</root> </root>
<!--logmanage --> <!--logmanage -->
<logger name="org.nl.acs.log.service.impl.DeviceExecuteLogServiceImpl" level="info" additivity="false"> <logger name="org.nl.acs.log.service.impl.DeviceExecuteLogServiceImpl" level="info" additivity="false">