OCP相关同步兰州
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @author ls
|
||||
* @date 2023/12/6 16:04
|
||||
*/
|
||||
package org.nl.acs.common.base;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CommonFinalParam {
|
||||
|
||||
public static final String DELETE = "0";
|
||||
/**
|
||||
* 分隔符
|
||||
*/
|
||||
private final String BARRE = "-";
|
||||
private final String POINT = ".";
|
||||
|
||||
public static final String ZERO = "0";
|
||||
public static final String ONE = "1";
|
||||
|
||||
public static final String TWO = "2";
|
||||
|
||||
public static final String THREE = "3";
|
||||
public static final String FOUR = "4";
|
||||
public static final String FIVE = "5";
|
||||
public static final String SIX = "6";
|
||||
public static final String SEVEN = "7";
|
||||
public static final String EIGHT = "8";
|
||||
public static final String NINE = "9";
|
||||
public static final String TEN = "10";
|
||||
public static final String ELEVEN = "11";
|
||||
|
||||
|
||||
/**
|
||||
* 无货
|
||||
*/
|
||||
public static final int DEVICE_MOVE_ZERO = 0;
|
||||
/**
|
||||
* 设备联机等待
|
||||
*/
|
||||
public static final int DEVICE_MODE_TWO = 2;
|
||||
/**
|
||||
* 成功状态
|
||||
*/
|
||||
public static final int STATUS_OPEN = 200;
|
||||
|
||||
/**
|
||||
* 动作信号
|
||||
*/
|
||||
public static final int ACTION_ONE = 1;
|
||||
public static final int ACTION_TWO = 2;
|
||||
public static final int ACTION_THREE = 3;
|
||||
|
||||
/**
|
||||
* 申请任务type类型
|
||||
*/
|
||||
public static final String TYPE_ONE = "1";
|
||||
public static final String TYPE_TWO = "2";
|
||||
public static final String TYPE_THREE = "3";
|
||||
public static final String TYPE_FOUR = "4";
|
||||
public static final String TYPE_FIVE = "5";
|
||||
public static final String TYPE_SIX = "6";
|
||||
public static final String TYPE_SEVEN = "7";
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 切割点符号
|
||||
*/
|
||||
public static final String DOT = ".";
|
||||
/**
|
||||
* 切割横杠符号
|
||||
*/
|
||||
public static final String HYPHEN_ = "-";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 自动门
|
||||
*/
|
||||
public static final String DOORS = "doors";
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import org.nl.acs.device_driver.basedriver.standard_storage.StandardStorageDevic
|
||||
import org.nl.acs.device_driver.driver.AbstractDeviceDriver;
|
||||
import org.nl.acs.device_driver.tianneng.site.SiteDeviceDriver;
|
||||
import org.nl.acs.ext.wms.data.BaseRequest;
|
||||
import org.nl.acs.ext.wms.data.feedBackTaskStatus.FeedBackTaskStatusRequest;
|
||||
import org.nl.acs.ext.wms.service.AcsToWmsService;
|
||||
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
|
||||
import org.nl.acs.instruction.domain.Instruction;
|
||||
@@ -117,6 +118,10 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
if (arr[18] * 256 + arr[19] == 0) {
|
||||
|
||||
}
|
||||
FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest();
|
||||
request.setDevice_code(this.device_code);
|
||||
request.setState("故障");
|
||||
acsToWmsService.notify(request);
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.common.utils.CodeUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -47,6 +48,9 @@ import java.util.Map;
|
||||
public class GuhuashiSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor {
|
||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||
|
||||
@Autowired
|
||||
private AcsToWmsService acsToWmsService;
|
||||
|
||||
String devicecode;
|
||||
|
||||
|
||||
@@ -85,16 +89,130 @@ public class GuhuashiSiteDeviceDriver extends AbstractOpcDeviceDriver implements
|
||||
int VW70006 = 0;
|
||||
int VW70007 = 0;
|
||||
|
||||
int last_VW7010 = 0;
|
||||
int last_VW7012 = 0;
|
||||
int last_VW7014 = 0;
|
||||
int last_VW7016 = 0;
|
||||
int last_VW7018 = 0;
|
||||
int last_VW7020 = 0;
|
||||
int last_VW7022 = 0;
|
||||
int last_VW7024 = 0;
|
||||
int last_VW7026 = 0;
|
||||
int last_VW7028 = 0;
|
||||
int last_VW7030 = 0;
|
||||
int last_VW7032 = 0;
|
||||
int last_VW7034 = 0;
|
||||
int last_VW7036 = 0;
|
||||
int last_VW7038 = 0;
|
||||
int last_VW7040 = 0;
|
||||
int last_VW7042 = 0;
|
||||
int last_VW7044 = 0;
|
||||
int last_VW7046 = 0;
|
||||
int last_VW7056 = 0;
|
||||
int last_VW7058 = 0;
|
||||
int last_VW7076 = 0;
|
||||
int last_VW70001 = 0;
|
||||
int last_VW70002 = 0;
|
||||
int last_VW70003 = 0;
|
||||
int last_VW70004 = 0;
|
||||
int last_VW70005 = 0;
|
||||
int last_VW70006 = 0;
|
||||
int last_VW70007 = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
String message = null;
|
||||
try {
|
||||
devicecode = this.getDeviceCode();
|
||||
VW7010 = this.itemProtocol.getVW7010();
|
||||
VW7012 = this.itemProtocol.getVW7012();
|
||||
VW7014 = this.itemProtocol.getVW7014();
|
||||
VW7016 = this.itemProtocol.getVW7016();
|
||||
VW7018 = this.itemProtocol.getVW7018();
|
||||
VW7020 = this.itemProtocol.getVW7020();
|
||||
VW7022 = this.itemProtocol.getVW7022();
|
||||
VW7024 = this.itemProtocol.getVW7024();
|
||||
VW7026 = this.itemProtocol.getVW7026();
|
||||
VW7028 = this.itemProtocol.getVW7028();
|
||||
VW7030 = this.itemProtocol.getVW7030();
|
||||
VW7032 = this.itemProtocol.getVW7032();
|
||||
VW7034 = this.itemProtocol.getVW7034();
|
||||
VW7036 = this.itemProtocol.getVW7036();
|
||||
VW7038 = this.itemProtocol.getVW7038();
|
||||
VW7040 = this.itemProtocol.getVW7040();
|
||||
VW7042 = this.itemProtocol.getVW7042();
|
||||
VW7044 = this.itemProtocol.getVW7044();
|
||||
VW7046 = this.itemProtocol.getVW7046();
|
||||
VW7056 = this.itemProtocol.getVW7056();
|
||||
VW7058 = this.itemProtocol.getVW7058();
|
||||
VW7076 = this.itemProtocol.getVW7076();
|
||||
VW70001 = this.itemProtocol.getVW70001();
|
||||
VW70002 = this.itemProtocol.getVW70002();
|
||||
VW70003 = this.itemProtocol.getVW70003();
|
||||
VW70004 = this.itemProtocol.getVW70004();
|
||||
VW70005 = this.itemProtocol.getVW70005();
|
||||
VW70006 = this.itemProtocol.getVW70006();
|
||||
VW70007 = this.itemProtocol.getVW70007();
|
||||
|
||||
if(VW7058!=last_VW7058){
|
||||
//固化室状态变更后通知lms更新固化室状态
|
||||
FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest();
|
||||
request.setDevice_code(this.devicecode);
|
||||
request.setType("1");
|
||||
switch(VW7058) {
|
||||
case 2:
|
||||
request.setState("4");
|
||||
acsToWmsService.notify(request);
|
||||
break;
|
||||
case 3:
|
||||
request.setState("3");
|
||||
acsToWmsService.notify(request);
|
||||
break;
|
||||
case 4:
|
||||
request.setState("5");
|
||||
acsToWmsService.notify(request);
|
||||
break;
|
||||
case 5:
|
||||
request.setType("3");
|
||||
request.setState("故障");
|
||||
acsToWmsService.notify(request);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception var17) {
|
||||
return;
|
||||
}
|
||||
last_VW7010 = VW7010;
|
||||
last_VW7012 = VW7012;
|
||||
last_VW7014 = VW7014;
|
||||
last_VW7016 = VW7016;
|
||||
last_VW7018 = VW7018;
|
||||
last_VW7020 = VW7020;
|
||||
last_VW7022 = VW7022;
|
||||
last_VW7024 = VW7024;
|
||||
last_VW7026 = VW7026;
|
||||
last_VW7028 = VW7028;
|
||||
last_VW7030 = VW7030;
|
||||
last_VW7032 = VW7032;
|
||||
last_VW7034 = VW7034;
|
||||
last_VW7036 = VW7036;
|
||||
last_VW7038 = VW7038;
|
||||
last_VW7040 = VW7040;
|
||||
last_VW7042 = VW7042;
|
||||
last_VW7044 = VW7044;
|
||||
last_VW7046 = VW7046;
|
||||
last_VW7056 = VW7056;
|
||||
last_VW7058 = VW7058;
|
||||
last_VW7076 = VW7076;
|
||||
last_VW70001 = VW70001;
|
||||
last_VW70002 = VW70002;
|
||||
last_VW70003 = VW70003;
|
||||
last_VW70004 = VW70004;
|
||||
last_VW70005 = VW70005;
|
||||
last_VW70006 = VW70006;
|
||||
last_VW70007 = VW70007;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -163,7 +163,11 @@ public class SiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceD
|
||||
acsToWmsService.notify(request);
|
||||
}
|
||||
}
|
||||
if (error != last_error) {
|
||||
if (error != last_error &&error!=0) {
|
||||
FeedBackTaskStatusRequest request = new FeedBackTaskStatusRequest();
|
||||
request.setDevice_code(this.device_code);
|
||||
request.setState("故障");
|
||||
acsToWmsService.notify(request);
|
||||
}
|
||||
} catch (Exception var17) {
|
||||
return;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService {
|
||||
|
||||
@Override
|
||||
public void deviceExecuteLog(
|
||||
String device_code, String vehicle_code, String inst_code, String message) {
|
||||
String device_code, String vehicle_code, String inst_code, String message) {
|
||||
try {
|
||||
MDC.put("device_code_log", device_code);
|
||||
log.info("{},{}", device_code, message);
|
||||
@@ -33,8 +33,6 @@ public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
MDC.remove("device_code_log");
|
||||
System.out.println("successNum:" + OpcUtl.successNum);
|
||||
System.out.println("errNum:" + OpcUtl.errNum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author LENOVO
|
||||
*/
|
||||
public abstract class BlockedRunable implements Runnable {
|
||||
private String threadName;
|
||||
private Date startTime;
|
||||
@@ -16,10 +19,19 @@ public abstract class BlockedRunable implements Runnable {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取code
|
||||
* @return
|
||||
*/
|
||||
public abstract String getCode();
|
||||
|
||||
/**
|
||||
* subRun
|
||||
* @throws Exception
|
||||
*/
|
||||
public abstract void subRun() throws Exception;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
this.setStartTime(new Date());
|
||||
@@ -60,6 +72,7 @@ public abstract class BlockedRunable implements Runnable {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int prime = 1;
|
||||
int result = 1;
|
||||
@@ -67,6 +80,7 @@ public abstract class BlockedRunable implements Runnable {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
|
||||
@@ -7,7 +7,11 @@ import org.nl.acs.device_driver.LinewayDeviceDriver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public interface DeviceAppService {
|
||||
/**
|
||||
* 查找所有设备
|
||||
@@ -32,6 +36,11 @@ public interface DeviceAppService {
|
||||
*/
|
||||
Device findDeviceByAddress(String address);
|
||||
|
||||
/**
|
||||
* 设备总数
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int deviceSize();
|
||||
|
||||
/**
|
||||
@@ -39,8 +48,12 @@ public interface DeviceAppService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, List<List<org.nl.acs.opc.OpcItemDto>>> findAllFormatProtocolFromDriver();
|
||||
Map<String, List<List<OpcItemDto>>> findAllFormatProtocolFromDriver();
|
||||
|
||||
/**
|
||||
* key:opcServer编码,List 每个opcServe下面挂了多少Plc
|
||||
* @return
|
||||
*/
|
||||
Map<String, List<List<OpcItemDto>>> findAllFormatProtocolFromDriverByPlc();
|
||||
|
||||
|
||||
@@ -61,6 +74,12 @@ public interface DeviceAppService {
|
||||
*/
|
||||
Map<String, String> findDeviceOptions(DeviceType deviceType);
|
||||
|
||||
/**
|
||||
* 根据设备类型查找设备
|
||||
*
|
||||
* @param deviceType
|
||||
* @return
|
||||
*/
|
||||
List findDeviceByType(DeviceType deviceType);
|
||||
|
||||
/**
|
||||
@@ -71,8 +90,16 @@ public interface DeviceAppService {
|
||||
*/
|
||||
List<Device> findDevice(DeviceType deviceType);
|
||||
|
||||
/**
|
||||
* 重新加载设备驱动
|
||||
*/
|
||||
void reload();
|
||||
|
||||
/**
|
||||
* 找线网设备
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<LinewayDeviceDriver> findLaneway();
|
||||
|
||||
/**
|
||||
@@ -83,8 +110,22 @@ public interface DeviceAppService {
|
||||
*/
|
||||
String findDeviceTypeByCode(String deviceCode);
|
||||
|
||||
/**
|
||||
* 移除设备
|
||||
*
|
||||
* @param deviceCode
|
||||
*/
|
||||
void removeDevice(String deviceCode);
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
*
|
||||
* @param deviceCode
|
||||
*/
|
||||
void addDevice(String deviceCode);
|
||||
|
||||
/**
|
||||
* 查找设备区域
|
||||
*/
|
||||
TreeSet<Integer> selectRegion();
|
||||
}
|
||||
|
||||
@@ -17,11 +17,20 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoInitial {
|
||||
private List<Device> devices = new ArrayList(); // 所有设备链表
|
||||
private List<String> code_indexs = new ArrayList(); // 设备对应的下表
|
||||
/**
|
||||
* 所有设备链表
|
||||
*/
|
||||
private List<Device> devices = new ArrayList();
|
||||
/**
|
||||
* 设备对应的下表
|
||||
*/
|
||||
private List<String> code_indexs = new ArrayList();
|
||||
@Autowired
|
||||
private DeviceManageService deviceManageService;
|
||||
@Autowired
|
||||
@@ -48,6 +57,7 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device findDeviceByAddress(String address) {
|
||||
Iterator var2 = this.findAllDevice().iterator();
|
||||
|
||||
@@ -128,7 +138,7 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
while (var21.hasNext()) {
|
||||
String string = (String) var21.next();
|
||||
List<OpcItemDto> device = (List) deviceMap.get(string);
|
||||
if (temp.size() + device.size() > org.nl.acs.opc.WcsConfig.opc_group_sync_max_item) {
|
||||
if (temp.size() + device.size() > WcsConfig.opc_group_sync_max_item) {
|
||||
if (temp.size() > 0) {
|
||||
serverResult.add(temp);
|
||||
temp = new ArrayList();
|
||||
@@ -297,13 +307,14 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
|
||||
while (var3.hasNext()) {
|
||||
Device device = (Device) var3.next();
|
||||
if (ObjectUtil.equal(device.getDevice_code(), deviceCode)) {
|
||||
if (ObjectUtil.equal(device.getDevice_code(), deviceCode) && ObjectUtil.isNotEmpty(device.getDeviceDriverDefination())) {
|
||||
return device.getDeviceDriverDefination().getFitDeviceTypes().get(0).name();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LinewayDeviceDriver> findLaneway() {
|
||||
return this.findDeviceDriver(LinewayDeviceDriver.class);
|
||||
}
|
||||
@@ -314,6 +325,7 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
List<DeviceManageDto> deviceManageDtos = deviceManageService.queryAllWithExtra();
|
||||
this.devices = new ArrayList();
|
||||
@@ -388,4 +400,13 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeSet<Integer> selectRegion() {
|
||||
TreeSet<Integer> set = new TreeSet<>();
|
||||
for (Device device : devices) {
|
||||
set.add(Integer.parseInt(StrUtil.isEmpty(device.getRegion()) ? "0" : device.getRegion()));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceDriverDefinationAppServiceImpl implements DeviceDriverDefinationAppService, InitializingBean, ApplicationContextAware {
|
||||
|
||||
@@ -10,6 +10,9 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
||||
@@ -83,7 +86,6 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
// Thread.sleep(10000L);
|
||||
log.info("设备执行线程开始...");
|
||||
|
||||
while (true) {
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.nl.acs.opc;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Data
|
||||
public class DeviceExtraManageDto {
|
||||
private String device_id;
|
||||
@@ -17,7 +20,6 @@ public class DeviceExtraManageDto {
|
||||
|
||||
|
||||
public Object parseName() {
|
||||
//return DictionaryUtl.parseValue(this.getCollection_type(), this.getValue_type(), this.getName());
|
||||
return extra_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Data
|
||||
public class DeviceManageDto {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -53,16 +56,24 @@ public class DeviceManageDto {
|
||||
private Boolean is_configed;
|
||||
private Boolean is_exist;
|
||||
private Boolean is_entrance;
|
||||
/* 粉桶号 */
|
||||
/**
|
||||
* 粉桶号
|
||||
*/
|
||||
private String barrels_code;
|
||||
|
||||
/* 配合批号 */
|
||||
/**
|
||||
* 配合批号
|
||||
*/
|
||||
private String cooperate_code;
|
||||
|
||||
/* 粉种名称 */
|
||||
/**
|
||||
* 粉种名称
|
||||
*/
|
||||
private String powder_name;
|
||||
|
||||
/* 粉桶状态 */
|
||||
/**
|
||||
* 粉桶状态
|
||||
*/
|
||||
private String barrels_status;
|
||||
|
||||
private List<DeviceExtraManageDto> extra = new LinkedList();
|
||||
|
||||
@@ -2,8 +2,20 @@ package org.nl.acs.opc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public interface DeviceManageService {
|
||||
List<org.nl.acs.opc.DeviceManageDto> queryAllWithExtra();
|
||||
/**
|
||||
* 查询所有设备
|
||||
* @return
|
||||
*/
|
||||
List<DeviceManageDto> queryAllWithExtra();
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备
|
||||
* @param device_code
|
||||
* @return
|
||||
*/
|
||||
List<DeviceManageDto> queryAllWithExtra(String device_code);
|
||||
}
|
||||
|
||||
@@ -5,13 +5,16 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
import org.nl.acs.device.domain.DeviceExtra;
|
||||
import org.nl.acs.device.service.mapper.DeviceExtraMapper;
|
||||
import org.nl.acs.device.service.mapper.DeviceMapper;
|
||||
import org.nl.acs.device.service.mapper.DeviceRunpointMapper;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.domain.OpcPlc;
|
||||
import org.nl.acs.opc.service.mapper.OpcMapper;
|
||||
import org.nl.acs.opc.service.mapper.OpcPlcMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,7 +24,11 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
|
||||
@Autowired
|
||||
@@ -41,24 +48,19 @@ public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
|
||||
@Override
|
||||
public List<DeviceManageDto> queryAllWithExtra() {
|
||||
// JSONArray arr = WQLObject.getWQLObject("acs_device").query().getResultJSONArray(0);
|
||||
// 获取所有的设备
|
||||
List<Device> deviceList= new LambdaQueryChainWrapper<>(deviceMapper).list();
|
||||
List<Device> deviceList = new LambdaQueryChainWrapper<>(deviceMapper).list();
|
||||
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(deviceList));
|
||||
|
||||
// 获取列表扩展
|
||||
// JSONArray extArr = WQLObject.getWQLObject("acs_device_extra").query().getResultJSONArray(0);
|
||||
List<DeviceExtra> deviceExtraList= new LambdaQueryChainWrapper<>(deviceExtraMapper).list();
|
||||
List<DeviceExtra> deviceExtraList = new LambdaQueryChainWrapper<>(deviceExtraMapper).list();
|
||||
JSONArray extArr = JSONArray.parseArray(JSON.toJSONString(deviceExtraList));
|
||||
|
||||
// 设备+扩展DTO
|
||||
List<DeviceExtraManageDto> extras = extArr.toJavaList(DeviceExtraManageDto.class);
|
||||
|
||||
// WQLObject runpointTab = WQLObject.getWQLObject("acs_device_runpoint");
|
||||
|
||||
// WQLObject opcTab = WQLObject.getWQLObject("acs_opc");
|
||||
//OPC_PLC表【acs_opc_plc】
|
||||
// WQLObject plcTab = WQLObject.getWQLObject("acs_opc_plc");
|
||||
List<DeviceManageDto> devices = new ArrayList<>();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
JSONObject json = arr.getJSONObject(i);
|
||||
@@ -67,18 +69,23 @@ public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
String opc_plc_id = json.getString("opc_plc_id");
|
||||
if (StrUtil.isNotEmpty(opc_plc_id) && StrUtil.isNotEmpty(opc_server_id)) {
|
||||
//OPC表【acs_opc】
|
||||
// String opc_code = opcTab.query("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").uniqueResult(0).getString("opc_code");
|
||||
String opc_code = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").one().getOpc_code();
|
||||
device.setOpc_server_code(opc_code);
|
||||
// if(ObjectUtil.isEmpty(plcTab.query("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").uniqueResult(0)))
|
||||
if(ObjectUtil.isEmpty(new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one()))
|
||||
{
|
||||
Opc opc = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'")
|
||||
.one();
|
||||
if (opc == null) {
|
||||
log.info("设备:{},配置的OPC数据源不存在,opc_id:{}", json.getString("device_code"), opc_server_id);
|
||||
continue;
|
||||
}
|
||||
device.setOpc_server_code(opc.getOpc_code());
|
||||
if (ObjectUtil.isEmpty(new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one())) {
|
||||
System.out.println(device.getDevice_code());
|
||||
continue;
|
||||
}
|
||||
// String plc_code = plcTab.query("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").uniqueResult(0).getString("plc_code");
|
||||
String plc_code = new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one().getPlc_code();
|
||||
device.setOpc_plc_code(plc_code);
|
||||
OpcPlc opcPlc = new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one();
|
||||
if (opcPlc == null) {
|
||||
log.info("设备:{},配置的PLC数据源不存在,plc_id:{}", json.getString("device_code"), opc_plc_id);
|
||||
continue;
|
||||
}
|
||||
device.setOpc_plc_code(opcPlc.getPlc_code());
|
||||
}
|
||||
devices.add(device);
|
||||
}
|
||||
@@ -93,10 +100,6 @@ public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
if (extra.getDevice_id().equals(device.getDevice_id())) {
|
||||
device.getExtra().add(extra);
|
||||
if (StrUtil.equals(extra.getExtra_code(), "station_manager") && StrUtil.equals(extra.getExtra_value().toString(), "true")) {
|
||||
// String has_goods = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("hasgoods");
|
||||
// String material_type = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("material_type");
|
||||
// String batch = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("batch");
|
||||
// String islock = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("islock");
|
||||
String has_goods = new LambdaQueryChainWrapper<>(deviceRunpointMapper).apply("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").one().getHasgoods();
|
||||
String material_type = new LambdaQueryChainWrapper<>(deviceRunpointMapper).apply("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").one().getMaterial_type();
|
||||
String batch = new LambdaQueryChainWrapper<>(deviceRunpointMapper).apply("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").one().getBatch();
|
||||
@@ -115,21 +118,15 @@ public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
|
||||
@Override
|
||||
public List<DeviceManageDto> queryAllWithExtra(String device_code) {
|
||||
// JSONArray arr = WQLObject.getWQLObject("acs_device").query("device_code = '" + device_code + " '").getResultJSONArray(0);
|
||||
List<Device> deviceList= new LambdaQueryChainWrapper<>(deviceMapper).eq(Device::getDevice_code,device_code).list();
|
||||
List<Device> deviceList = new LambdaQueryChainWrapper<>(deviceMapper).eq(Device::getDevice_code, device_code).list();
|
||||
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(deviceList));
|
||||
|
||||
// JSONArray extArr = WQLObject.getWQLObject("acs_device_extra").query("device_code = '" + device_code + " '").getResultJSONArray(0);
|
||||
List<DeviceExtra> deviceExtraList= new LambdaQueryChainWrapper<>(deviceExtraMapper).eq(DeviceExtra::getDevice_code,device_code).list();
|
||||
List<DeviceExtra> deviceExtraList = new LambdaQueryChainWrapper<>(deviceExtraMapper).eq(DeviceExtra::getDevice_code, device_code).list();
|
||||
JSONArray extArr = JSONArray.parseArray(JSON.toJSONString(deviceExtraList));
|
||||
|
||||
List<DeviceExtraManageDto> extras = extArr.toJavaList(DeviceExtraManageDto.class);
|
||||
|
||||
// WQLObject runpointTab = WQLObject.getWQLObject("acs_device_runpoint");
|
||||
|
||||
// WQLObject opcTab = WQLObject.getWQLObject("acs_opc");
|
||||
//OPC_PLC表【acs_opc_plc】
|
||||
// WQLObject plcTab = WQLObject.getWQLObject("acs_opc_plc");
|
||||
List<DeviceManageDto> devices = new ArrayList<>();
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
JSONObject json = arr.getJSONObject(i);
|
||||
@@ -137,22 +134,17 @@ public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
String opc_server_id = json.getString("opc_server_id");
|
||||
String opc_plc_id = json.getString("opc_plc_id");
|
||||
if (StrUtil.isNotEmpty(opc_plc_id) && StrUtil.isNotEmpty(opc_server_id)) {
|
||||
//OPC表【acs_opc】
|
||||
// JSONObject rb = opcTab.query("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").uniqueResult(0);
|
||||
Opc opc = new LambdaQueryChainWrapper<>(opcMapper).apply("is_delete= '0' AND is_active= '1' AND opc_id = '" + opc_server_id + "'").one();
|
||||
if(ObjectUtil.isEmpty(opc)){
|
||||
if (ObjectUtil.isEmpty(opc)) {
|
||||
System.out.println(device.getDevice_code());
|
||||
continue;
|
||||
}
|
||||
String opc_code=opc.getOpc_code();
|
||||
String opc_code = opc.getOpc_code();
|
||||
device.setOpc_server_code(opc_code);
|
||||
// if(ObjectUtil.isEmpty(plcTab.query("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").uniqueResult(0)))
|
||||
if(ObjectUtil.isEmpty(new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one()))
|
||||
{
|
||||
if (ObjectUtil.isEmpty(new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one())) {
|
||||
System.out.println(device.getDevice_code());
|
||||
continue;
|
||||
}
|
||||
// String plc_code = plcTab.query("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").uniqueResult(0).getString("plc_code");
|
||||
String plc_code = new LambdaQueryChainWrapper<>(opcPlcMapper).apply("is_delete= '0' AND is_active= '1' AND plc_id = '" + opc_plc_id + "'").one().getPlc_code();
|
||||
device.setOpc_plc_code(plc_code);
|
||||
}
|
||||
@@ -169,10 +161,6 @@ public class DeviceManageServiceImpl implements DeviceManageService {
|
||||
if (extra.getDevice_id().equals(device.getDevice_id())) {
|
||||
device.getExtra().add(extra);
|
||||
if (StrUtil.equals(extra.getExtra_code(), "station_manager") && StrUtil.equals(extra.getExtra_value().toString(), "true")) {
|
||||
// String has_goods = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("hasgoods");
|
||||
// String material_type = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("material_type");
|
||||
// String batch = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("batch");
|
||||
// String islock = runpointTab.query("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").uniqueResult(0).getString("islock");
|
||||
String has_goods = new LambdaQueryChainWrapper<>(deviceRunpointMapper).apply("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").one().getHasgoods();
|
||||
String material_type = new LambdaQueryChainWrapper<>(deviceRunpointMapper).apply("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").one().getMaterial_type();
|
||||
String batch = new LambdaQueryChainWrapper<>(deviceRunpointMapper).apply("is_delete= '0' AND is_active= '1' AND device_id = '" + extra.getDevice_id() + "'").one().getBatch();
|
||||
|
||||
@@ -1,17 +1,29 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.util.NamedThreadFactory;
|
||||
import org.nl.acs.AcsConfig;
|
||||
import org.nl.acs.auto.run.AbstractAutoRunnable;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.nl.common.enums.LogTypeEnum;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* OPC设备同步启动
|
||||
@@ -19,66 +31,286 @@ import java.util.concurrent.*;
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
|
||||
public static boolean isRun = false;
|
||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
static boolean isRun = true;
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
@Autowired
|
||||
private OpcServerManageService opcServerManageService;
|
||||
// @Autowired
|
||||
// LuceneExecuteLogService lucene;
|
||||
|
||||
static ExecutorService executorService;
|
||||
public static Map<String, OpcServerManageDto> opcServersConfig;
|
||||
public static Map<String, OpcItemDto> itemCodeOpcItemDtoMapping = new ConcurrentHashMap();
|
||||
|
||||
static boolean canRefreshOpcEntity = true;
|
||||
private long lastRefreshOpcEntityTime;
|
||||
static UnifiedDataAccessor udw;
|
||||
private static Map<String, Boolean> canReadOpcValues;
|
||||
private static volatile Map<String, OpcEntity> opcCodeOpcEntityMapping;
|
||||
|
||||
public DeviceOpcSynchronizeAutoRun() {
|
||||
this.lastRefreshOpcEntityTime = 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return DeviceOpcSynchronizeAutoRun.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "opc设备同步器";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void autoRun() throws Exception {
|
||||
{
|
||||
isRun = true;
|
||||
static Group getGroup(String opcCode) throws Exception {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
return opcServerService.getServer(opcCode);
|
||||
}
|
||||
|
||||
Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap();
|
||||
Map<String, List<List<OpcItemDto>>> pros;
|
||||
do{
|
||||
Thread.sleep(1000L);
|
||||
pros = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
}while (ObjectUtil.isEmpty(pros));
|
||||
Set<String> keys = pros.keySet();
|
||||
Iterator var4 = keys.iterator();
|
||||
//代码执行一次
|
||||
while (var4.hasNext()) {
|
||||
String key = (String) var4.next();
|
||||
List<List<OpcItemDto>> list = (List) pros.get(key);
|
||||
OpcServerManageDto opcServer = (OpcServerManageDto) servers.get(key);
|
||||
Iterator var8 = list.iterator();
|
||||
while (var8.hasNext()) {
|
||||
List<OpcItemDto> groupProtols = (List) var8.next();
|
||||
DeviceOpcProtocolRunable runable = new DeviceOpcProtocolRunable();
|
||||
runable.setProtocols(groupProtols);
|
||||
runable.setOpcServer(opcServer);
|
||||
this.executorService.submit(runable);
|
||||
}
|
||||
static void submitTimeLimitTask(Runnable runnable, String opcCode) {
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, executorService);
|
||||
|
||||
// try {
|
||||
// future.get(10L, TimeUnit.SECONDS);
|
||||
// } catch (InterruptedException var9) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// } catch (ExecutionException var10) {
|
||||
// var10.printStackTrace();
|
||||
// } catch (TimeoutException var11) {
|
||||
// itemCodeOpcItemDtoMapping.keySet().forEach((key) -> {
|
||||
// udw.setValue(key, (Object) null);
|
||||
// });
|
||||
// canReadOpcValues = new ConcurrentHashMap<>();
|
||||
// System.out.println("opc设备同步器 任务执行超时,取消任务...");
|
||||
// future.cancel(true);
|
||||
// } finally {
|
||||
// canRefreshOpcEntity = true;
|
||||
// if (opcCode != null) {
|
||||
// canReadOpcValues.put(opcCode, true);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
private ExecutorService createThreadPool() {
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(32, 32, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("opc-sync"));
|
||||
executor.allowCoreThreadTimeOut(true);
|
||||
return executor;
|
||||
}
|
||||
|
||||
public void autoRun() {
|
||||
OpcStartTag.is_run = true;
|
||||
opcServersConfig = this.opcServerManageService.queryAllServerMap();
|
||||
executorService = this.createThreadPool();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
itemCodeOpcItemDtoMapping.keySet().forEach((key) -> {
|
||||
udw.setValue(key, (Object) null);
|
||||
});
|
||||
canRefreshOpcEntity = true;
|
||||
canReadOpcValues.clear();
|
||||
|
||||
while (true) {
|
||||
this.refreshOpcEntity();
|
||||
Iterator var1 = opcServersConfig.keySet().iterator();
|
||||
|
||||
while (var1.hasNext()) {
|
||||
String opcCode = (String) var1.next();
|
||||
submitTimeLimitTask(() -> {
|
||||
boolean in = false;
|
||||
try {
|
||||
if (canReadOpcValues.computeIfAbsent(opcCode, (key) -> true)) {
|
||||
in = true;
|
||||
canReadOpcValues.put(opcCode, false);
|
||||
this.readOpcValues(opcCode);
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
var3.printStackTrace();
|
||||
} finally {
|
||||
canRefreshOpcEntity = true;
|
||||
if (opcCode != null && in) {
|
||||
canReadOpcValues.put(opcCode, true);
|
||||
}
|
||||
}
|
||||
}, opcCode);
|
||||
}
|
||||
|
||||
// 同步无光电设备信号
|
||||
//Map<String, List<List<OpcItemDto>>> pros1 = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
//List<DeviceDriver> opcDrivers = this.deviceAppService.findDeviceDriver(DeviceDriver.class);
|
||||
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond);
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
Thread.sleep(3000L);
|
||||
private void readOpcValues(String opcCode) throws Exception {
|
||||
synchronized (opcCode.intern()) {
|
||||
OpcEntity opcEntity = (OpcEntity) opcCodeOpcEntityMapping.get(opcCode);
|
||||
if (opcEntity != null) {
|
||||
if (opcEntity.getItems().size() != 0) {
|
||||
long begin = System.currentTimeMillis();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("opc {} 开始计时{}", opcCode, begin);
|
||||
}
|
||||
|
||||
new HashMap();
|
||||
|
||||
Map<Item, ItemState> itemStatus;
|
||||
try {
|
||||
itemStatus = opcEntity.readAll();
|
||||
} catch (Exception var15) {
|
||||
itemStatus = opcEntity.readDividually();
|
||||
}
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
long duration = end - begin;
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("opc {} 读取耗时:{}", opcCode, duration);
|
||||
}
|
||||
|
||||
if (duration > 1000L) {
|
||||
log.warn("opc {} 读取超时 : {}", opcCode, duration);
|
||||
}
|
||||
|
||||
// boolean allNull = itemStatus.entrySet().stream().map((map) -> {
|
||||
// return OpcUtl.getValue((Item)map.getKey(), (ItemState)map.getValue());
|
||||
// }).allMatch(Objects::isNull);
|
||||
// if (allNull) {
|
||||
// opcEntity.getItems().clear();
|
||||
// }
|
||||
|
||||
UnifiedDataAccessor udw = opcEntity.getUdw();
|
||||
|
||||
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var18 = items.iterator();
|
||||
|
||||
while (var18.hasNext()) {
|
||||
Item item = (Item) var18.next();
|
||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
||||
Object nowValue = OpcUtl.getValue(item, itemState);
|
||||
String itemId = item.getId();
|
||||
Object historyValue = udw.getValue(itemId);
|
||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && historyValue != null) {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
}
|
||||
if (!UnifiedDataAppService.isEquals(nowValue, historyValue)) {
|
||||
OpcItemDto itemDto = (OpcItemDto) itemCodeOpcItemDtoMapping.get(itemId);
|
||||
if (true) {
|
||||
this.logItemChanged(itemId, udw, nowValue, itemDto);
|
||||
}
|
||||
udw.setValue(itemId, nowValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
private void refreshOpcEntity() {
|
||||
if (canRefreshOpcEntity) {
|
||||
canRefreshOpcEntity = false;
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - this.lastRefreshOpcEntityTime >= 20000L) {
|
||||
this.lastRefreshOpcEntityTime = now;
|
||||
submitTimeLimitTask(() -> {
|
||||
try {
|
||||
Map<String, List<List<OpcItemDto>>> protocol = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
Iterator var2 = protocol.entrySet().iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
Entry<String, List<List<OpcItemDto>>> stringListEntry = (Entry) var2.next();
|
||||
String opcCode = (String) stringListEntry.getKey();
|
||||
List<List<OpcItemDto>> opcItemDtos = (List) stringListEntry.getValue();
|
||||
((OpcEntity) opcCodeOpcEntityMapping.computeIfAbsent(opcCode, OpcEntity::new)).reload(opcItemDtos);
|
||||
}
|
||||
} catch (Exception var6) {
|
||||
var6.printStackTrace();
|
||||
} finally {
|
||||
canRefreshOpcEntity = true;
|
||||
}
|
||||
|
||||
}, (String) null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logMessage(String errorMessage) {
|
||||
try {
|
||||
// issueLogger.setResource(OpcConfig.resource_code, OpcConfig.resource_name).setError(StringUtl.getString(100), "设备同步通信异常").log(errorMessage, new Object[0]);
|
||||
// businessLogger.setResource(OpcConfig.resource_code, OpcConfig.resource_name).setError(StringUtl.getString(100), "设备同步通信异常").log(errorMessage, new Object[0]);
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void after() {
|
||||
isRun = false;
|
||||
this.executorService.shutdownNow();
|
||||
this.executorService = Executors.newCachedThreadPool();
|
||||
OpcStartTag.is_run = false;
|
||||
opcCodeOpcEntityMapping.values().forEach((opcEntity) -> {
|
||||
opcEntity.cleanUdwCache();
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
opcServerService.cleanGroups(opcEntity.getOpcCode());
|
||||
});
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
itemCodeOpcItemDtoMapping = new ConcurrentHashMap();
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
|
||||
private void logItemChanged(String itemId, UnifiedDataAccessor accessor_value, Object value, OpcItemDto itemDto) {
|
||||
ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class);
|
||||
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 + ";");
|
||||
}
|
||||
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
|
||||
// 存在上次点位值为null情况 则不记录日志
|
||||
if(!(his instanceof Float) && !(value instanceof Float)){
|
||||
LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(),4, itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
|
||||
String.valueOf(his), String.valueOf(value));
|
||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
String logLevel = paramService.findByCode(AcsConfig.LOGLEVEL).getValue();
|
||||
if(StrUtil.isNotEmpty(logLevel) && isNumeric(logLevel) && (luceneLogDto.getLog_level() >= Integer.parseInt(logLevel))){
|
||||
log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
|
||||
// if(!(his instanceof Float) && !(value instanceof Float)){
|
||||
// LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
|
||||
// String.valueOf(his), String.valueOf(value));
|
||||
// luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
// log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
|
||||
if(!(his instanceof Float) && !(value instanceof Float)){
|
||||
LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(),4, itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
|
||||
String.valueOf(his), String.valueOf(value));
|
||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
String logLevel = paramService.findByCode(AcsConfig.LOGLEVEL).getValue();
|
||||
if(StrUtil.isNotEmpty(logLevel) && isNumeric(logLevel) && (luceneLogDto.getLog_level() >= Integer.parseInt(logLevel))){
|
||||
log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
canReadOpcValues = new ConcurrentHashMap();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str) {
|
||||
return Pattern.compile("^[0-9]+$").matcher(str).matches();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class JsonUtl {
|
||||
private static ObjectMapper objectMapper = null;
|
||||
private static ObjectMapper objectMapperLog = null;
|
||||
@@ -34,7 +37,7 @@ public class JsonUtl {
|
||||
public static ObjectMapper getInstance() {
|
||||
if (objectMapper == null) {
|
||||
Class var0 = JsonUtl.class;
|
||||
synchronized(JsonUtl.class) {
|
||||
synchronized (JsonUtl.class) {
|
||||
if (objectMapper == null) {
|
||||
objectMapper = init();
|
||||
}
|
||||
@@ -47,7 +50,7 @@ public class JsonUtl {
|
||||
public static ObjectMapper getInstanceLog() {
|
||||
if (objectMapperLog == null) {
|
||||
Class var0 = JsonUtl.class;
|
||||
synchronized(JsonUtl.class) {
|
||||
synchronized (JsonUtl.class) {
|
||||
if (objectMapperLog == null) {
|
||||
objectMapperLog = init();
|
||||
objectMapperLog.setSerializationInclusion(Include.NON_NULL);
|
||||
@@ -97,7 +100,7 @@ public class JsonUtl {
|
||||
public static <T> List<T> formatList(String json, Class<T> clazz) throws RuntimeException {
|
||||
try {
|
||||
JavaType type = getObjectMapper().getTypeFactory().constructParametricType(List.class, new Class[]{clazz});
|
||||
return (List)getObjectMapper().readValue(json, type);
|
||||
return (List) getObjectMapper().readValue(json, type);
|
||||
} catch (IOException var3) {
|
||||
throw new RuntimeException(var3);
|
||||
}
|
||||
@@ -106,7 +109,7 @@ public class JsonUtl {
|
||||
public static <T, U> Map<T, U> formatMap(String json, Class<T> clazzKey, Class<U> clazzValue) throws RuntimeException {
|
||||
try {
|
||||
JavaType type = getObjectMapper().getTypeFactory().constructParametricType(Map.class, new Class[]{clazzKey, clazzValue});
|
||||
return (Map)getObjectMapper().readValue(json, type);
|
||||
return (Map) getObjectMapper().readValue(json, type);
|
||||
} catch (IOException var4) {
|
||||
throw new RuntimeException(var4);
|
||||
}
|
||||
@@ -117,7 +120,7 @@ public class JsonUtl {
|
||||
TypeFactory typeFactory = getObjectMapper().getTypeFactory();
|
||||
JavaType type = typeFactory.constructParametrizedType(List.class, List.class, new Class[]{clazz});
|
||||
type = typeFactory.constructParametrizedType(List.class, List.class, new JavaType[]{type});
|
||||
return (List)getObjectMapper().readValue(json, type);
|
||||
return (List) getObjectMapper().readValue(json, type);
|
||||
} catch (IOException var4) {
|
||||
throw new RuntimeException(var4);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
|
||||
public class LangProcess {
|
||||
|
||||
public static String msg(String code,String...args){
|
||||
MessageSource bean = SpringContextHolder.getBean(MessageSource.class);
|
||||
if (StringUtils.isEmpty(code)){
|
||||
return " ";
|
||||
}
|
||||
String message = bean.getMessage(code, args, LocaleContextHolder.getLocale());
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ package org.nl.acs.opc;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class ObjectUtl {
|
||||
private ObjectUtl() {
|
||||
}
|
||||
@@ -55,9 +58,6 @@ public class ObjectUtl {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean isObject(Class<?> clazz) {
|
||||
if (clazz == null) {
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class OpcConfig {
|
||||
public static Boolean auto_start_opc = Boolean.valueOf(true);
|
||||
public static String udw_opc_value_key = "opc_value";
|
||||
@@ -11,6 +14,8 @@ public class OpcConfig {
|
||||
public static String resource_code = "opc_sync";
|
||||
public static String resource_name = "opc同步";
|
||||
|
||||
//OPC 数据同步是否采用回调机制实现。之前是线程定期全部读,效率低。
|
||||
/**
|
||||
* OPC 数据同步是否采用回调机制实现。之前是线程定期全部读,效率低。
|
||||
*/
|
||||
public static Boolean opc_item_read_using_callback = false;
|
||||
}
|
||||
|
||||
@@ -1,174 +1,180 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import org.nl.acs.opc.DeviceOpcSynchronizeAutoRun;
|
||||
import org.nl.acs.opc.OpcConfig;
|
||||
import org.nl.acs.opc.OpcItemDto;
|
||||
import org.nl.acs.opc.OpcServerService;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
public class OpcEntity {
|
||||
|
||||
// OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
// private final UnifiedDataAccessor udw;
|
||||
// private Map<String, List<Item>> items;
|
||||
// private Map<String, List<String>> someFailDevices;
|
||||
// private String opcCode;
|
||||
//
|
||||
// public OpcEntity(String opcCode) {
|
||||
// this.udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
// this.items = new ConcurrentHashMap();
|
||||
// this.someFailDevices = new ConcurrentHashMap();
|
||||
// this.opcCode = opcCode;
|
||||
// }
|
||||
//
|
||||
// public void reload(List<List<OpcItemDto>> opcItemDtos) {
|
||||
// Map<String, List<String>> itemCodes = new ConcurrentHashMap();
|
||||
// (opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.groupingBy(OpcItemDto::getDevice_code))).forEach((deviceCodes, opcItemDtoList) -> {
|
||||
// itemCodes.put(deviceCodes, opcItemDtoList.stream().map(OpcItemDto::getItem_code).collect(Collectors.toList()));
|
||||
// });
|
||||
// DeviceOpcSynchronizeAutoRun.itemCodeOpcItemDtoMapping.putAll((Map)opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.toMap(OpcItemDto::getItem_code, (obj) -> {
|
||||
// return obj;
|
||||
// },(k, v) -> k)));
|
||||
// if (this.items.size() == 0) {
|
||||
// itemCodes.values().stream().flatMap(Collection::stream).forEach((key) -> {
|
||||
// this.udw.setValue(key, (Object)null);
|
||||
// });
|
||||
// this.addItemsIntoGroup(itemCodes);
|
||||
// } else {
|
||||
// if (this.someFailDevices.size() > 0) {
|
||||
// this.reAddDevices();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void reAddDevices() {
|
||||
// Map<String, List<Item>> addItems = new ConcurrentHashMap();
|
||||
// StringBuilder err_message = new StringBuilder();
|
||||
// this.someFailDevices.forEach((deviceCode, itemCodesList) -> {
|
||||
// itemCodesList.forEach((itemCode) -> {
|
||||
// try {
|
||||
// Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
// ((List)addItems.computeIfAbsent(deviceCode, (key) -> {
|
||||
// return new ArrayList();
|
||||
// })).add(group.addItem(itemCode));
|
||||
// } catch (Exception var6) {
|
||||
// err_message.append(itemCode).append(" 添加失败; ");
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// List<Item> deviceItems = (List)addItems.get(deviceCode);
|
||||
// if (deviceItems != null && deviceItems.size() == itemCodesList.size()) {
|
||||
// this.someFailDevices.remove(deviceCode);
|
||||
// } else if (itemCodesList.size() == 0) {
|
||||
// addItems.remove(deviceCode);
|
||||
// } else {
|
||||
// assert deviceItems != null;
|
||||
//
|
||||
// ((List)this.someFailDevices.get(deviceCode)).removeAll(deviceItems);
|
||||
// }
|
||||
//
|
||||
// synchronized(this.opcCode.intern()) {
|
||||
// this.items.putAll(addItems);
|
||||
// }
|
||||
//
|
||||
// if (err_message.length() > 0) {
|
||||
// String errMsg = err_message.toString();
|
||||
// //this.log.warn("{}:{}", com.wxzd.wcs.opc.OpcConfig.resource_code, errMsg);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void addItemsIntoGroup(Map<String, List<String>> itemCodes) {
|
||||
// try {
|
||||
// Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
// StringBuilder err_message = new StringBuilder();
|
||||
// Map<String, List<Item>> items = new ConcurrentHashMap();
|
||||
// itemCodes.forEach((deviceCode, itemCodesList) -> {
|
||||
// itemCodesList.forEach((itemCode) -> {
|
||||
// try {
|
||||
// ((List)items.computeIfAbsent(deviceCode, (key) -> {
|
||||
// return new ArrayList();
|
||||
// })).add(group.addItem(itemCode));
|
||||
// } catch (Exception var7) {
|
||||
// ((List)this.someFailDevices.computeIfAbsent(deviceCode, (key) -> {
|
||||
// return new ArrayList();
|
||||
// })).add(itemCode);
|
||||
// this.udw.setValue(itemCode, (Object)null);
|
||||
// err_message.append(itemCode).append(" 添加失败; ");
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// List<Item> deviceItems = (List)items.get(deviceCode);
|
||||
// if (deviceItems != null && deviceItems.size() != itemCodesList.size()) {
|
||||
// items.remove(deviceCode);
|
||||
// this.someFailDevices.put(deviceCode, itemCodesList);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// synchronized(this.opcCode.intern()) {
|
||||
// this.items = items;
|
||||
// }
|
||||
//
|
||||
// if (err_message.length() > 0) {
|
||||
// String errMsg = err_message.toString();
|
||||
//// this.log.warn("{}:{}", OpcConfig.resource_code, errMsg);
|
||||
// }
|
||||
// } catch (Exception var8) {
|
||||
// var8.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void cleanUdwCache() {
|
||||
// this.items.values().stream().flatMap(Collection::stream).map(Item::getId).forEach((key) -> {
|
||||
// this.udw.setValue(key, (Object)null);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public Map<Item, ItemState> readAll() throws Exception {
|
||||
// return opcServerService.getServer(this.opcCode).read(true, (Item[])this.items.values().stream().flatMap(Collection::stream).toArray((x$0) -> {
|
||||
// return new Item[x$0];
|
||||
// }));
|
||||
// }
|
||||
//
|
||||
// public Map<Item, ItemState> readDividually() {
|
||||
// Map<Item, ItemState> result = new HashMap();
|
||||
// CompletableFuture[] futures = (CompletableFuture[])this.items.entrySet().stream().map((entry) -> {
|
||||
// return CompletableFuture.runAsync(() -> {
|
||||
// try {
|
||||
// Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
// result.putAll(group.read(true, (Item[])((List)entry.getValue()).toArray(new Item[0])));
|
||||
// } catch (Exception var5) {
|
||||
// String deviceCode = (String)entry.getKey();
|
||||
// // to do
|
||||
//// this.someFailDevices.put(deviceCode, ((List)entry.getValue()).stream().map(Item::getId).collect(Collectors.toList()));
|
||||
// this.items.remove(deviceCode);
|
||||
// }
|
||||
//
|
||||
// }, DeviceOpcSynchronizeAutoRun.executorService);
|
||||
// }).toArray((x$0) -> {
|
||||
// return new CompletableFuture[x$0];
|
||||
// });
|
||||
// CompletableFuture.allOf(futures).join();
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public UnifiedDataAccessor getUdw() {
|
||||
// return this.udw;
|
||||
// }
|
||||
//
|
||||
// public Map<String, List<Item>> getItems() {
|
||||
// return this.items;
|
||||
// }
|
||||
//
|
||||
// public String getOpcCode() {
|
||||
// return this.opcCode;
|
||||
// }
|
||||
public class OpcEntity {
|
||||
@Autowired
|
||||
OpcServerService opcServerService;
|
||||
private final UnifiedDataAccessor udw;
|
||||
private Map<String, List<Item>> items;
|
||||
private Map<String, List<String>> someFailDevices;
|
||||
private String opcCode;
|
||||
|
||||
public OpcEntity(String opcCode) {
|
||||
this.udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
this.items = new ConcurrentHashMap();
|
||||
this.someFailDevices = new ConcurrentHashMap();
|
||||
this.opcCode = opcCode;
|
||||
}
|
||||
|
||||
public void reload(List<List<OpcItemDto>> opcItemDtos) {
|
||||
Map<String, List<String>> itemCodes = new ConcurrentHashMap();
|
||||
(opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.groupingBy(OpcItemDto::getDevice_code))).forEach((deviceCodes, opcItemDtoList) -> {
|
||||
itemCodes.put(deviceCodes, opcItemDtoList.stream().map(OpcItemDto::getItem_code).collect(Collectors.toList()));
|
||||
});
|
||||
DeviceOpcSynchronizeAutoRun.itemCodeOpcItemDtoMapping.putAll((Map)opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.toMap(OpcItemDto::getItem_code, (obj) -> {
|
||||
return obj;
|
||||
},(k, v) -> k)));
|
||||
if (this.items.size() == 0) {
|
||||
itemCodes.values().stream().flatMap(Collection::stream).forEach((key) -> {
|
||||
this.udw.setValue(key, (Object)null);
|
||||
});
|
||||
this.addItemsIntoGroup(itemCodes);
|
||||
} else {
|
||||
if (this.someFailDevices.size() > 0) {
|
||||
this.reAddDevices();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void reAddDevices() {
|
||||
Map<String, List<Item>> addItems = new ConcurrentHashMap();
|
||||
StringBuilder err_message = new StringBuilder();
|
||||
this.someFailDevices.forEach((deviceCode, itemCodesList) -> {
|
||||
itemCodesList.forEach((itemCode) -> {
|
||||
try {
|
||||
Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
((List)addItems.computeIfAbsent(deviceCode, (key) -> {
|
||||
return new ArrayList();
|
||||
})).add(group.addItem(itemCode));
|
||||
} catch (Exception var6) {
|
||||
err_message.append(itemCode).append(" 添加失败; ");
|
||||
}
|
||||
|
||||
});
|
||||
List<Item> deviceItems = (List)addItems.get(deviceCode);
|
||||
if (deviceItems != null && deviceItems.size() == itemCodesList.size()) {
|
||||
this.someFailDevices.remove(deviceCode);
|
||||
} else if (itemCodesList.size() == 0) {
|
||||
addItems.remove(deviceCode);
|
||||
} else {
|
||||
assert deviceItems != null;
|
||||
|
||||
((List)this.someFailDevices.get(deviceCode)).removeAll(deviceItems);
|
||||
}
|
||||
|
||||
synchronized(this.opcCode.intern()) {
|
||||
this.items.putAll(addItems);
|
||||
}
|
||||
|
||||
if (err_message.length() > 0) {
|
||||
String errMsg = err_message.toString();
|
||||
//this.log.warn("{}:{}", com.wxzd.wcs.opc.OpcConfig.resource_code, errMsg);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void addItemsIntoGroup(Map<String, List<String>> itemCodes) {
|
||||
try {
|
||||
Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
StringBuilder err_message = new StringBuilder();
|
||||
Map<String, List<Item>> items = new ConcurrentHashMap();
|
||||
itemCodes.forEach((deviceCode, itemCodesList) -> {
|
||||
itemCodesList.forEach((itemCode) -> {
|
||||
try {
|
||||
((List)items.computeIfAbsent(deviceCode, (key) -> {
|
||||
return new ArrayList();
|
||||
})).add(group.addItem(itemCode));
|
||||
} catch (Exception var7) {
|
||||
((List)this.someFailDevices.computeIfAbsent(deviceCode, (key) -> {
|
||||
return new ArrayList();
|
||||
})).add(itemCode);
|
||||
this.udw.setValue(itemCode, (Object)null);
|
||||
err_message.append(itemCode).append(" 添加失败; ");
|
||||
}
|
||||
|
||||
});
|
||||
List<Item> deviceItems = (List)items.get(deviceCode);
|
||||
if (deviceItems != null && deviceItems.size() != itemCodesList.size()) {
|
||||
items.remove(deviceCode);
|
||||
this.someFailDevices.put(deviceCode, itemCodesList);
|
||||
}
|
||||
|
||||
});
|
||||
synchronized(this.opcCode.intern()) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
if (err_message.length() > 0) {
|
||||
String errMsg = err_message.toString();
|
||||
// this.log.warn("{}:{}", OpcConfig.resource_code, errMsg);
|
||||
}
|
||||
} catch (Exception var8) {
|
||||
var8.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void cleanUdwCache() {
|
||||
this.items.values().stream().flatMap(Collection::stream).map(Item::getId).forEach((key) -> {
|
||||
this.udw.setValue(key, (Object)null);
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Item, ItemState> readAll() throws Exception {
|
||||
return opcServerService.getServer(this.opcCode).read(true, (Item[])this.items.values().stream().flatMap(Collection::stream).toArray((x$0) -> {
|
||||
return new Item[x$0];
|
||||
}));
|
||||
}
|
||||
|
||||
public Map<Item, ItemState> readDividually() {
|
||||
Map<Item, ItemState> result = new HashMap();
|
||||
CompletableFuture[] futures = (CompletableFuture[])this.items.entrySet().stream().map((entry) -> {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
result.putAll(group.read(true, (Item[])((List)entry.getValue()).toArray(new Item[0])));
|
||||
} catch (Exception var5) {
|
||||
String deviceCode = (String)entry.getKey();
|
||||
// to do
|
||||
// this.someFailDevices.put(deviceCode, ((List)entry.getValue()).stream().map(Item::getId).collect(Collectors.toList()));
|
||||
this.items.remove(deviceCode);
|
||||
}
|
||||
|
||||
}, DeviceOpcSynchronizeAutoRun.executorService);
|
||||
}).toArray((x$0) -> {
|
||||
return new CompletableFuture[x$0];
|
||||
});
|
||||
CompletableFuture.allOf(futures).join();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public UnifiedDataAccessor getUdw() {
|
||||
return this.udw;
|
||||
}
|
||||
|
||||
public Map<String, List<Item>> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public String getOpcCode() {
|
||||
return this.opcCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import lombok.Data;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Data
|
||||
public class OpcItemDto {
|
||||
private String device_code;
|
||||
@@ -14,7 +17,9 @@ public class OpcItemDto {
|
||||
private String opc_plc_code;
|
||||
private String item_code;
|
||||
private Object item_value;
|
||||
|
||||
private Object his_item_value;
|
||||
|
||||
private Boolean need_log = Boolean.valueOf(false);
|
||||
private List<String> relate_items = new ArrayList();
|
||||
|
||||
|
||||
@@ -4,6 +4,14 @@ import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public interface OpcServerManageService {
|
||||
/**
|
||||
* 查询所有opc服务器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, OpcServerManageDto> queryAllServerMap();
|
||||
}
|
||||
|
||||
@@ -11,13 +11,45 @@ import org.openscada.opc.lib.da.Group;
|
||||
*/
|
||||
public interface OpcServerService {
|
||||
|
||||
/**
|
||||
* 重新加载
|
||||
*/
|
||||
void reload();
|
||||
|
||||
/**
|
||||
* 获取服务器
|
||||
* @param var1
|
||||
* @return
|
||||
*/
|
||||
Group getServer(String var1);
|
||||
|
||||
/**
|
||||
* 获取服务器
|
||||
* @param var1
|
||||
* @return
|
||||
*/
|
||||
Group getServerByNewConn(String var1);
|
||||
|
||||
/**
|
||||
* 写入整数
|
||||
* @param var1
|
||||
* @param var2
|
||||
*/
|
||||
void writeInteger(String var1, ItemValue... var2);
|
||||
|
||||
/**
|
||||
* 写入整数
|
||||
* @param var1
|
||||
* @param var2
|
||||
*/
|
||||
void writeIntegerByNewConn(String var1, ItemValue... var2);
|
||||
|
||||
/**
|
||||
* 清除服务器
|
||||
* @param var1
|
||||
*/
|
||||
void clearServer(String var1);
|
||||
|
||||
void cleanGroups(String var1);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.jinterop.dcom.common.JIException;
|
||||
import org.nl.acs.auto.initial.ApplicationAutoInitial;
|
||||
import org.nl.acs.device_driver.driver.ItemValue;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.openscada.opc.lib.common.NotConnectedException;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
@@ -41,8 +41,10 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
|
||||
/**
|
||||
* 加载opc服务,启动opc线程
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void autoInitial() throws Exception {
|
||||
this.reload(); // 加载opc服务
|
||||
if (OpcConfig.auto_start_opc) {
|
||||
@@ -65,70 +67,129 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap();
|
||||
this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Group getServer(String code) {
|
||||
Group group = null;
|
||||
group = (Group) this.groups.get(code);
|
||||
if (group != null) {
|
||||
try {
|
||||
if (group.isActive()) {
|
||||
return group;
|
||||
synchronized (this.buildLock(code)) {
|
||||
Group group = null;
|
||||
group = (Group) this.groups.get(code);
|
||||
if (group != null) {
|
||||
label68:
|
||||
{
|
||||
Group var10000;
|
||||
try {
|
||||
if (!group.isActive()) {
|
||||
break label68;
|
||||
}
|
||||
|
||||
var10000 = group;
|
||||
} catch (JIException var14) {
|
||||
log.error(code, var14);
|
||||
break label68;
|
||||
}
|
||||
|
||||
return var10000;
|
||||
}
|
||||
} 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();
|
||||
Server server = (Server) this.servers.get(code);
|
||||
boolean needcreate = false;
|
||||
String groupName = code;
|
||||
if (server == null) {
|
||||
needcreate = true;
|
||||
} else {
|
||||
try {
|
||||
group = server.findGroup(groupName);
|
||||
} catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException |
|
||||
IllegalArgumentException var13) {
|
||||
log.error(code, var13);
|
||||
needcreate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needcreate) {
|
||||
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
|
||||
if (dto == null) {
|
||||
throw new RuntimeException(code + "不存在");
|
||||
}
|
||||
|
||||
// if (server!=null){
|
||||
// server.disconnect();
|
||||
// server=null;
|
||||
// }
|
||||
|
||||
if (server == null) {
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
}
|
||||
|
||||
try {
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var12) {
|
||||
this.clearServer(code);
|
||||
ThreadUtl.sleep(5000L);
|
||||
log.warn("获取opc出错重新获取", code, var12);
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
try {
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var11) {
|
||||
throw new RuntimeException(var12);
|
||||
}
|
||||
}
|
||||
|
||||
this.servers.put(code, server);
|
||||
this.groups.put(code, group);
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Group getServerByNewConn(String code) {
|
||||
synchronized (this.buildLock(code)) {
|
||||
|
||||
Server server = (Server) this.servers.get(code);
|
||||
if (server != null) {
|
||||
this.clearServer(code);
|
||||
}
|
||||
}
|
||||
|
||||
if (needcreate) {
|
||||
OpcServerManageDto dto = (OpcServerManageDto) this.opcServerManageDtos.get(code);
|
||||
if (dto == null) {
|
||||
throw new BadRequestException("code 不存在");
|
||||
throw new RuntimeException(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());
|
||||
|
||||
// if (server == null) {
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
// }
|
||||
String groupName = code;
|
||||
Group group = null;
|
||||
|
||||
try {
|
||||
group = server.addGroup(OpcConfig.opc_server_default_group);
|
||||
} catch (Exception var7) {
|
||||
throw new BadRequestException(var7.toString());
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var12) {
|
||||
this.clearServer(code);
|
||||
ThreadUtl.sleep(2000L);
|
||||
log.warn("获取opc出错重新获取", code, var12);
|
||||
server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain()));
|
||||
try {
|
||||
group = server.addGroup(groupName);
|
||||
} catch (Exception var11) {
|
||||
throw new RuntimeException(var12);
|
||||
}
|
||||
}
|
||||
|
||||
this.servers.put(code, server);
|
||||
this.groups.put(code, group);
|
||||
return group;
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void clearServer(String code) {
|
||||
try {
|
||||
Server server = (Server) this.servers.get(code);
|
||||
@@ -163,6 +224,7 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeInteger(String code, ItemValue... values) {
|
||||
try {
|
||||
Group group = this.getServer(code);
|
||||
@@ -174,4 +236,28 @@ public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoIn
|
||||
throw var4;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeIntegerByNewConn(String code, ItemValue... values) {
|
||||
try {
|
||||
Group group = this.getServerByNewConn(code);
|
||||
OpcUtl.writeValue(group, values);
|
||||
} catch (Exception var4) {
|
||||
this.clearServer(code);
|
||||
log.info("写入出错opc server {} 重新加载", code, var4);
|
||||
ThreadUtl.sleep(1000L);
|
||||
throw var4;
|
||||
}
|
||||
}
|
||||
|
||||
private String buildLock(String key) {
|
||||
if (StrUtil.isEmpty(key)) {
|
||||
key = "";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("OpcServerService.");
|
||||
builder.append(key);
|
||||
String lock = builder.toString().intern();
|
||||
return lock;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ package org.nl.acs.opc;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.openscada.opc.lib.da.Server;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class OpcServerUtl {
|
||||
|
||||
public static synchronized Server getServerWithOutException(String host, String clsid, String user, String password,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class OpcStartTag {
|
||||
public static boolean is_run = false;
|
||||
}
|
||||
|
||||
@@ -15,12 +15,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Slf4j
|
||||
public class OpcUtl {
|
||||
private static int timeout = 1*60*1000;
|
||||
private static int timeout = 1 * 60 * 1000;
|
||||
private static String key = "rpc.socketTimeout";
|
||||
public static int successNum=0;
|
||||
public static int errNum=0;
|
||||
|
||||
static {
|
||||
checkTimeout();
|
||||
@@ -36,16 +37,16 @@ public class OpcUtl {
|
||||
|
||||
public static void writeValue(Group group, WriteRequest... requests) throws BadRequestException {
|
||||
try {
|
||||
Map<Item, Integer> e=null;
|
||||
try{
|
||||
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);
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
try {
|
||||
e = group.write(requests);
|
||||
} catch (Exception e2) {
|
||||
e = group.write(requests);
|
||||
}
|
||||
}
|
||||
|
||||
boolean is_success = true;
|
||||
@@ -69,15 +70,15 @@ public class OpcUtl {
|
||||
|
||||
if (!is_success) {
|
||||
// throw new BusinessException(message.toString());
|
||||
System.out.println("下发信号失败:"+message.toString());
|
||||
System.out.println("下发信号失败原因:"+message.toString());
|
||||
log.info("下发信号失败:"+message.toString());
|
||||
System.out.println("下发信号失败:" + message.toString());
|
||||
System.out.println("下发信号失败原因:" + message.toString());
|
||||
log.info("下发信号失败:" + message.toString());
|
||||
throw new BadRequestException(message.toString());
|
||||
}
|
||||
} catch (JIException arg7) {
|
||||
log.info("下发信号失败:"+arg7.getMessage());
|
||||
System.out.println("下发信号失败原因:"+arg7.getMessage());
|
||||
throw new BadRequestException(arg7.toString());
|
||||
log.info("下发信号失败:" + arg7.getMessage());
|
||||
System.out.println("下发信号失败原因:" + arg7.getMessage());
|
||||
throw new BadRequestException(arg7.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,13 +89,13 @@ public class OpcUtl {
|
||||
ItemValue[] var3 = values;
|
||||
int var4 = values.length;
|
||||
|
||||
for(int var5 = 0; var5 < var4; ++var5) {
|
||||
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]));
|
||||
writeValue(group, (WriteRequest[]) ws.toArray(new WriteRequest[0]));
|
||||
}
|
||||
|
||||
} catch (AddFailedException | JIException var8) {
|
||||
@@ -104,25 +105,25 @@ public class OpcUtl {
|
||||
|
||||
public static JIVariant getVariant(Object object) {
|
||||
if (object instanceof Integer) {
|
||||
return getIntegerVariant((Integer)object);
|
||||
return getIntegerVariant((Integer) object);
|
||||
} else if (object instanceof String) {
|
||||
return getStringVariant((String)object);
|
||||
return getStringVariant((String) object);
|
||||
} else if (object instanceof byte[]) {
|
||||
return getByteArrayVariant((byte[])((byte[])object));
|
||||
return getByteArrayVariant((byte[]) ((byte[]) object));
|
||||
} else if (object instanceof Byte[]) {
|
||||
return getByteArrayVariant((Byte[])((Byte[])object));
|
||||
return getByteArrayVariant((Byte[]) ((Byte[]) object));
|
||||
} else if (object instanceof Boolean) {
|
||||
return new JIVariant((Boolean)object);
|
||||
return new JIVariant((Boolean) object);
|
||||
} else if (object instanceof int[]) {
|
||||
return getByteArrayVariantxx((int[])((int[])object));
|
||||
return getByteArrayVariantxx((int[]) ((int[]) object));
|
||||
} else if (object instanceof Integer[]) {
|
||||
JIArray array = new JIArray((Integer)object, false);
|
||||
JIArray array = new JIArray((Integer) object, false);
|
||||
JIVariant value = new JIVariant(array);
|
||||
return value;
|
||||
} else if (object instanceof JIVariant) {
|
||||
return (JIVariant)object;
|
||||
return (JIVariant) object;
|
||||
} else {
|
||||
throw new BadRequestException("未实现目前支持是int,string,byte[]");
|
||||
throw new BadRequestException(LangProcess.msg("error_checkTypes", "int,string,byte[]"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +159,8 @@ public class OpcUtl {
|
||||
return jiVariant.getObject();
|
||||
} else if (e instanceof Float) {
|
||||
return jiVariant.getObject();
|
||||
} else if (e instanceof Double) {
|
||||
return jiVariant.getObject();
|
||||
} else {
|
||||
System.err.println(id + "不明类型" + e.getClass());
|
||||
if (jiVariant.getType() == 0) {
|
||||
@@ -221,15 +224,9 @@ public class OpcUtl {
|
||||
server = new Server(getConnection(host, clsid, user, password, domain),
|
||||
Executors.newSingleThreadScheduledExecutor());
|
||||
server.connect();
|
||||
successNum++;
|
||||
return server;
|
||||
} catch (Exception e) {
|
||||
errNum++;
|
||||
throw new BadRequestException(e.getMessage());
|
||||
}finally{
|
||||
System.out.println("successNum:"+successNum);
|
||||
System.out.println("errNum:"+errNum);
|
||||
System.out.println(11);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +253,7 @@ public class OpcUtl {
|
||||
public static JIVariant getByteArrayVariantxx(int[] bytes) {
|
||||
Integer[] byte_Data = new Integer[bytes.length];
|
||||
|
||||
for(int i = 0; i < bytes.length; ++i) {
|
||||
for (int i = 0; i < bytes.length; ++i) {
|
||||
byte_Data[i] = bytes[i];
|
||||
}
|
||||
|
||||
@@ -276,7 +273,7 @@ public class OpcUtl {
|
||||
public static JIVariant getByteArrayVariant(byte[] bytes) {
|
||||
Byte[] byte_Data = new Byte[bytes.length];
|
||||
|
||||
for(int i = 0; i < bytes.length; ++i) {
|
||||
for (int i = 0; i < bytes.length; ++i) {
|
||||
byte_Data[i] = bytes[i];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class QualityTypeValue {
|
||||
public static short OPC_QUALITY_GOOD = 192;
|
||||
public static short OPC_QUALITY_LOCAL_OVERRIDE = 216;
|
||||
|
||||
@@ -1,16 +1,31 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class WcsConfig {
|
||||
|
||||
public static Integer opc_group_sync_max_item = 700;
|
||||
|
||||
//设备是否需要校验在线
|
||||
/**
|
||||
* 设备是否需要校验在线
|
||||
*/
|
||||
public static Boolean fake_online;
|
||||
|
||||
//物料默认类型描述
|
||||
/**
|
||||
* 物料默认类型描述
|
||||
*/
|
||||
public static String task_container_type_default_desc;
|
||||
|
||||
//重复的指令下发超时 ms
|
||||
/**
|
||||
* 堆垛机异常入库次数限制
|
||||
*/
|
||||
public static Integer stacker_error_in_count ;
|
||||
|
||||
|
||||
/**
|
||||
* 重复的指令下发超时 ms
|
||||
*/
|
||||
public static Integer opc_write_repeat_check = 1000;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
package org.nl.acs.opc.domain;
|
||||
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@@ -25,70 +33,70 @@ import java.io.Serializable;
|
||||
public class Opc extends CommonModel<Opc> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "OPC标识")
|
||||
@TableId(type= IdType.ASSIGN_ID)
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String opc_id;
|
||||
|
||||
@ApiModelProperty(value = "OPC编码")
|
||||
|
||||
@NotBlank
|
||||
private String opc_code;
|
||||
|
||||
@ApiModelProperty(value = "OPC名称")
|
||||
|
||||
@NotBlank
|
||||
private String opc_name;
|
||||
|
||||
@ApiModelProperty(value = "OPC地址")
|
||||
|
||||
private String opc_host;
|
||||
|
||||
@ApiModelProperty(value = "用户名")
|
||||
|
||||
private String user;
|
||||
|
||||
@ApiModelProperty(value = "密码")
|
||||
|
||||
@NotBlank
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "程序ID")
|
||||
|
||||
private String prog_id;
|
||||
|
||||
@ApiModelProperty(value = "注册表ID")
|
||||
|
||||
private String cls_id;
|
||||
|
||||
@ApiModelProperty(value = "domain")
|
||||
|
||||
private String domain;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
|
||||
@NotBlank
|
||||
private String is_active;
|
||||
|
||||
@ApiModelProperty(value = "是否删除")
|
||||
|
||||
@NotBlank
|
||||
private String is_delete;
|
||||
|
||||
@ApiModelProperty(value = "创建者")
|
||||
|
||||
@NotBlank
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String create_by;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
|
||||
@NotBlank
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String create_time;
|
||||
|
||||
@ApiModelProperty(value = "修改者")
|
||||
@TableField(fill= FieldFill.INSERT_UPDATE)
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String update_by;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
@TableField(fill= FieldFill.INSERT_UPDATE)
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String update_time;
|
||||
|
||||
@NotBlank
|
||||
private String has_children;
|
||||
|
||||
public void copyFrom(Opc source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
public void copyFrom(Opc source) {
|
||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,28 @@
|
||||
package org.nl.acs.opc.domain;
|
||||
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.nl.acs.common.base.CommonModel;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@@ -25,54 +33,54 @@ import java.io.Serializable;
|
||||
public class OpcPlc extends CommonModel<OpcPlc> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "plc标识")
|
||||
@TableId(type= IdType.ASSIGN_ID)
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String plc_id;
|
||||
|
||||
@ApiModelProperty(value = "plc编码")
|
||||
|
||||
@NotBlank
|
||||
private String plc_code;
|
||||
|
||||
@ApiModelProperty(value = "plc名字")
|
||||
|
||||
@NotBlank
|
||||
private String plc_name;
|
||||
|
||||
@ApiModelProperty(value = "plc地址")
|
||||
|
||||
private String plc_host;
|
||||
|
||||
@ApiModelProperty(value = "opcServer标识")
|
||||
|
||||
private String opc_server_id;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
|
||||
@NotBlank
|
||||
private String is_active;
|
||||
|
||||
@ApiModelProperty(value = "是否删除")
|
||||
|
||||
@NotBlank
|
||||
private String is_delete;
|
||||
|
||||
@ApiModelProperty(value = "创建者")
|
||||
|
||||
@NotBlank
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String create_by;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
|
||||
@NotBlank
|
||||
@TableField(fill= FieldFill.INSERT)
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String create_time;
|
||||
|
||||
@ApiModelProperty(value = "修改者")
|
||||
@TableField(fill= FieldFill.INSERT_UPDATE)
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String update_by;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
@TableField(fill= FieldFill.INSERT_UPDATE)
|
||||
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private String update_time;
|
||||
|
||||
public void copyFrom(OpcPlc source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
public void copyFrom(OpcPlc source) {
|
||||
BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.acs.opc.service.mapper.OpcMapper;
|
||||
import org.nl.acs.utils.ConvertUtil;
|
||||
@@ -14,6 +16,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Service
|
||||
public class opcServerManageServiceImpl implements OpcServerManageService {
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.nl.acs.opc.rest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.acs.opc.service.OpcService;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
@@ -18,12 +16,11 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
**/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "opc服务管理")
|
||||
@RequestMapping("/api/opc")
|
||||
public class OpcController {
|
||||
|
||||
@@ -31,15 +28,12 @@ public class OpcController {
|
||||
|
||||
@GetMapping
|
||||
@Log("查询opc")
|
||||
@ApiOperation("查询opc")
|
||||
//@PreAuthorize("@el.check('opc:list')")
|
||||
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
|
||||
return new ResponseEntity<>(opcService.queryAll(whereJson, page), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@Log("新增opc")
|
||||
@ApiOperation("新增opc")
|
||||
//@PreAuthorize("@el.check('opc:add')")
|
||||
public ResponseEntity<Object> create(@Validated @RequestBody OpcDto dto) {
|
||||
opcService.insert(dto);
|
||||
@@ -48,7 +42,6 @@ public class OpcController {
|
||||
|
||||
@PutMapping
|
||||
@Log("修改opc")
|
||||
@ApiOperation("修改opc")
|
||||
//@PreAuthorize("@el.check('opc:edit')")
|
||||
public ResponseEntity<Object> update(@Validated @RequestBody OpcDto dto) {
|
||||
opcService.update(dto);
|
||||
@@ -56,7 +49,6 @@ public class OpcController {
|
||||
}
|
||||
|
||||
@Log("删除opc")
|
||||
@ApiOperation("删除opc")
|
||||
//@PreAuthorize("@el.check('opc:del')")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Object> delete(@RequestBody String[] ids) {
|
||||
@@ -65,7 +57,6 @@ public class OpcController {
|
||||
}
|
||||
|
||||
@Log("导出opc")
|
||||
@ApiOperation("导出opc")
|
||||
@GetMapping(value = "/download")
|
||||
//@PreAuthorize("@el.check('opc:list')")
|
||||
public void download(HttpServletResponse response, Map whereJson) throws IOException {
|
||||
@@ -74,14 +65,12 @@ public class OpcController {
|
||||
|
||||
@GetMapping("/selectList")
|
||||
@Log("下拉选OPC")
|
||||
@ApiOperation("下拉选OPC")
|
||||
//@PreAuthorize("@el.check('routePlan:list')")
|
||||
public ResponseEntity<Object> selectList() {
|
||||
return new ResponseEntity<>(opcService.selectList(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出opc")
|
||||
@ApiOperation("导出opc")
|
||||
@PostMapping(value = "/getmeteal")
|
||||
//@PreAuthorize("@el.check('opc:list')")
|
||||
public ResponseEntity<Object> getmeteal(@RequestBody Map whereJson) throws IOException {
|
||||
@@ -89,7 +78,6 @@ public class OpcController {
|
||||
}
|
||||
|
||||
@Log("新增PLC")
|
||||
@ApiOperation("新增PLC")
|
||||
@PostMapping(value = "/addPLC")
|
||||
//@PreAuthorize("@el.check('opc:list')")
|
||||
public ResponseEntity<Object> createPlc(@RequestBody Map whereJson) throws IOException {
|
||||
@@ -97,7 +85,7 @@ public class OpcController {
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ApiOperation("查询plc")
|
||||
|
||||
@GetMapping(value = "/queryServerPlc")
|
||||
//@PreAuthorize("@el.ceck('menu:list','roles:list')")
|
||||
public ResponseEntity<Object> query(@RequestParam String id) {
|
||||
@@ -105,7 +93,6 @@ public class OpcController {
|
||||
}
|
||||
|
||||
@Log("删除PLC")
|
||||
@ApiOperation("删除PLC")
|
||||
@PostMapping(value = "/delPLC")
|
||||
//@PreAuthorize("@el.check('opc:list')")
|
||||
public ResponseEntity<Object> delPLC(@RequestBody Map whereJson) throws IOException {
|
||||
@@ -114,7 +101,6 @@ public class OpcController {
|
||||
}
|
||||
|
||||
@Log("编辑PLC")
|
||||
@ApiOperation("编辑PLC")
|
||||
@PostMapping(value = "/editPLC")
|
||||
//@PreAuthorize("@el.check('opc:list')")
|
||||
public ResponseEntity<Object> editPLC(@RequestBody JSONObject json) throws IOException {
|
||||
|
||||
@@ -2,9 +2,9 @@ package org.nl.acs.opc.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.nl.acs.common.base.CommonService;
|
||||
import org.nl.acs.common.base.PageInfo;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.common.base.PageInfo;
|
||||
import org.nl.acs.common.base.CommonService;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcQueryParam;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -17,45 +17,80 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
public interface OpcService extends CommonService<Opc> {
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
public interface OpcService extends CommonService<Opc> {
|
||||
|
||||
static final String CACHE_KEY = "opc";
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param query 条件
|
||||
* @param pageable 分页参数
|
||||
* @return PageInfo<OpcDto>
|
||||
*/
|
||||
* 查询数据分页
|
||||
*
|
||||
* @param query 条件
|
||||
* @param pageable 分页参数
|
||||
* @return PageInfo<OpcDto>
|
||||
*/
|
||||
PageInfo<OpcDto> queryAll(OpcQueryParam query, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param query 条件参数
|
||||
* @return List<OpcDto>
|
||||
*/
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
* @param query 条件参数
|
||||
* @return List<OpcDto>
|
||||
*/
|
||||
List<OpcDto> queryAll(OpcQueryParam query);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return Opc
|
||||
*/
|
||||
Opc getById(String id);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return OpcDto
|
||||
*/
|
||||
OpcDto findById(String id);
|
||||
|
||||
/**
|
||||
* 插入一条新数据。
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
int insert(OpcDto resources);
|
||||
|
||||
/**
|
||||
* 编辑一条数据
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
int updateById(OpcDto resources);
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
int removeById(String id);
|
||||
|
||||
/**
|
||||
* 根据多个id删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
int removeByIds(Set<String> ids);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
// void download(List<OpcDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
@@ -130,11 +165,30 @@ public interface OpcService extends CommonService<Opc> {
|
||||
*/
|
||||
OpcDto queryServerPlc(String opc_id);
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*
|
||||
* @param whereJson 条件
|
||||
* @return Map<String, String>
|
||||
*/
|
||||
HashMap<String, String> getmeteal(Map whereJson);
|
||||
|
||||
/**
|
||||
* 创建PLC
|
||||
*
|
||||
* @param map map
|
||||
*/
|
||||
void createPLC(Map map);
|
||||
|
||||
/**
|
||||
* 删除plc
|
||||
* @param map
|
||||
*/
|
||||
void delPLC(Map map);
|
||||
|
||||
/**
|
||||
* 编辑plc
|
||||
* @param json
|
||||
*/
|
||||
void editPLC(JSONObject json);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package org.nl.acs.opc.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@@ -19,52 +26,52 @@ import java.io.Serializable;
|
||||
public class OpcDto implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "OPC标识")
|
||||
|
||||
private String opc_id;
|
||||
|
||||
@ApiModelProperty(value = "OPC编码")
|
||||
|
||||
private String opc_code;
|
||||
|
||||
@ApiModelProperty(value = "OPC名称")
|
||||
|
||||
private String opc_name;
|
||||
|
||||
@ApiModelProperty(value = "OPC地址")
|
||||
|
||||
private String opc_host;
|
||||
|
||||
@ApiModelProperty(value = "用户名")
|
||||
|
||||
private String user;
|
||||
|
||||
@ApiModelProperty(value = "密码")
|
||||
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "程序ID")
|
||||
|
||||
private String prog_id;
|
||||
|
||||
@ApiModelProperty(value = "注册表ID")
|
||||
|
||||
private String cls_id;
|
||||
|
||||
@ApiModelProperty(value = "domain")
|
||||
|
||||
private String domain;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
|
||||
private String is_active;
|
||||
|
||||
@ApiModelProperty(value = "是否删除")
|
||||
|
||||
private String is_delete;
|
||||
|
||||
@ApiModelProperty(value = "创建者")
|
||||
|
||||
private String create_by;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
|
||||
private String create_time;
|
||||
|
||||
@ApiModelProperty(value = "修改者")
|
||||
|
||||
private String update_by;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
|
||||
private String update_time;
|
||||
|
||||
private String hasChildren;
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package org.nl.acs.opc.service.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@@ -19,39 +26,39 @@ import java.io.Serializable;
|
||||
public class OpcPlcDto implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "plc标识")
|
||||
|
||||
private String plc_id;
|
||||
|
||||
@ApiModelProperty(value = "plc编码")
|
||||
|
||||
private String plc_code;
|
||||
|
||||
@ApiModelProperty(value = "plc名字")
|
||||
|
||||
private String plc_name;
|
||||
|
||||
@ApiModelProperty(value = "plc地址")
|
||||
|
||||
private String plc_host;
|
||||
|
||||
@ApiModelProperty(value = "opcServer标识")
|
||||
|
||||
private String opc_server_id;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
|
||||
private String is_active;
|
||||
|
||||
@ApiModelProperty(value = "是否删除")
|
||||
|
||||
private String is_delete;
|
||||
|
||||
@ApiModelProperty(value = "创建者")
|
||||
|
||||
private String create_by;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
|
||||
private String create_time;
|
||||
|
||||
@ApiModelProperty(value = "修改者")
|
||||
|
||||
private String update_by;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
|
||||
private String update_time;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,18 @@ package org.nl.acs.opc.service.dto;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nl.common.annotation.Query;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class OpcPlcQueryParam{
|
||||
public class OpcPlcQueryParam {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,18 @@ package org.nl.acs.opc.service.dto;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Date;
|
||||
|
||||
import org.nl.common.annotation.Query;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class OpcQueryParam{
|
||||
public class OpcQueryParam {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.nl.acs.opc.service.dto;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
public class OpcServerManageDto {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -10,7 +13,7 @@ public class OpcServerManageDto {
|
||||
private String password;
|
||||
private String prog_id;
|
||||
private String cls_id;
|
||||
private String domain;
|
||||
private String domain = "";
|
||||
|
||||
public String getOpc_code() {
|
||||
return this.opc_code;
|
||||
|
||||
@@ -10,35 +10,37 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.common.base.CommonFinalParam;
|
||||
import org.nl.acs.opc.LangProcess;
|
||||
import org.nl.acs.opc.domain.OpcPlc;
|
||||
import org.nl.acs.opc.service.mapper.OpcPlcMapper;
|
||||
import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.acs.common.base.PageInfo;
|
||||
import org.nl.acs.common.base.QueryHelpMybatisPlus;
|
||||
import org.nl.acs.common.base.impl.CommonServiceImpl;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.acs.utils.ConvertUtil;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.acs.utils.PageUtil;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.opc.domain.OpcPlc;
|
||||
import org.nl.acs.opc.service.OpcService;
|
||||
import org.nl.acs.opc.service.dto.OpcDto;
|
||||
import org.nl.acs.opc.service.dto.OpcQueryParam;
|
||||
import org.nl.acs.opc.service.mapper.OpcMapper;
|
||||
import org.nl.acs.opc.service.mapper.OpcPlcMapper;
|
||||
import org.nl.acs.utils.ConvertUtil;
|
||||
import org.nl.acs.utils.PageUtil;
|
||||
import org.nl.acs.utils.ReadUtil;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.utils.FileUtil;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
@@ -46,9 +48,11 @@ import java.util.*;
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements OpcService {
|
||||
|
||||
// private final RedisUtils redisUtils;
|
||||
private final OpcMapper opcMapper;
|
||||
private final OpcPlcMapper opcPlcMapper;
|
||||
|
||||
private static final String BLURRY = "blurry";
|
||||
|
||||
@Override
|
||||
public PageInfo<OpcDto> queryAll(OpcQueryParam query, Pageable pageable) {
|
||||
IPage<Opc> queryPage = PageUtil.toMybatisPage(pageable);
|
||||
@@ -57,7 +61,7 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OpcDto> queryAll(OpcQueryParam query){
|
||||
public List<OpcDto> queryAll(OpcQueryParam query) {
|
||||
return ConvertUtil.convertList(opcMapper.selectList(QueryHelpMybatisPlus.getPredicate(query)), OpcDto.class);
|
||||
}
|
||||
|
||||
@@ -67,7 +71,7 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Cacheable(key = "'id:' + #p0")
|
||||
|
||||
public OpcDto findById(String id) {
|
||||
return ConvertUtil.convert(getById(id), OpcDto.class);
|
||||
}
|
||||
@@ -75,7 +79,7 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insert(OpcDto dto) {
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
String currentUsername = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
dto.setOpc_id(IdUtil.simpleUUID());
|
||||
dto.setCreate_by(currentUsername);
|
||||
@@ -88,7 +92,7 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateById(OpcDto resources){
|
||||
public int updateById(OpcDto resources) {
|
||||
Opc entity = ConvertUtil.convert(resources, Opc.class);
|
||||
int ret = opcMapper.updateById(entity);
|
||||
// delCaches(resources.id);
|
||||
@@ -97,14 +101,14 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeByIds(Set<String> ids){
|
||||
public int removeByIds(Set<String> ids) {
|
||||
// delCaches(ids);
|
||||
return opcMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int removeById(String id){
|
||||
public int removeById(String id) {
|
||||
Set<String> set = new HashSet<>(1);
|
||||
set.add(id);
|
||||
return this.removeByIds(set);
|
||||
@@ -126,20 +130,21 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
|
||||
IPage<Opc> queryPage = PageUtil.toMybatisPage(page);
|
||||
LambdaQueryWrapper<Opc> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Opc::getIs_delete,"0").eq(Opc::getIs_active,"1");
|
||||
if (whereJson.get("blurry") != null) {
|
||||
wrapper.eq(Opc::getIs_delete, "0").eq(Opc::getIs_active, CommonFinalParam.ONE);
|
||||
if (whereJson.get(BLURRY) != null) {
|
||||
wrapper.like(Opc::getOpc_code, whereJson.get("blurry")).or().like(Opc::getOpc_name, whereJson.get("blurry")).or().like(Opc::getOpc_host, whereJson.get("blurry"));
|
||||
}
|
||||
IPage<Opc> opcPage = opcMapper.selectPage(queryPage,wrapper);
|
||||
wrapper.orderByDesc(Opc::getCreate_time);
|
||||
IPage<Opc> opcPage = opcMapper.selectPage(queryPage, wrapper);
|
||||
final JSONObject json = (JSONObject) JSON.toJSON(ConvertUtil.convertPage(opcPage, OpcDto.class));
|
||||
JSONArray newja = new JSONArray();
|
||||
JSONArray ja = json.getJSONArray("content");
|
||||
for (int i = 0; i < ja.size(); i++) {
|
||||
JSONObject jo = (JSONObject) ja.get(i);
|
||||
List<OpcPlc> plcList = new LambdaQueryChainWrapper<OpcPlc>(opcPlcMapper)
|
||||
.eq(OpcPlc::getIs_active, "1")
|
||||
.eq(OpcPlc::getIs_active, CommonFinalParam.ONE)
|
||||
.eq(OpcPlc::getIs_delete, "0")
|
||||
.eq(OpcPlc::getOpc_server_id,jo.getString("opc_id"))
|
||||
.eq(OpcPlc::getOpc_server_id, jo.getString("opc_id"))
|
||||
.list();
|
||||
if (plcList.size() > 0) {
|
||||
JSONArray children = new JSONArray();
|
||||
@@ -164,7 +169,7 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
}
|
||||
jo.put("children", children);
|
||||
}
|
||||
jo.put("opc_flag", "1");
|
||||
jo.put("opc_flag", CommonFinalParam.ONE);
|
||||
jo.put("type", "server");
|
||||
newja.add(jo);
|
||||
}
|
||||
@@ -176,7 +181,7 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
@Override
|
||||
public List<OpcDto> queryAll(Map whereJson) {
|
||||
LambdaQueryWrapper<Opc> wrapper = new LambdaQueryWrapper<>();
|
||||
if (whereJson.get("blurry") != null) {
|
||||
if (whereJson.get(BLURRY) != null) {
|
||||
wrapper.like(Opc::getOpc_code, whereJson.get("blurry")).or().like(Opc::getOpc_name, whereJson.get("blurry")).or().like(Opc::getOpc_host, whereJson.get("blurry"));
|
||||
}
|
||||
return ConvertUtil.convertList(opcMapper.selectList(wrapper), OpcDto.class);
|
||||
@@ -195,8 +200,10 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(OpcDto dto) {
|
||||
OpcDto entity = this.findById(dto.getOpc_id());
|
||||
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
|
||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||
if (entity == null) {
|
||||
throw new BadRequestException(LangProcess.msg("error_sysAuth"));
|
||||
}
|
||||
String currentUsername = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_by(currentUsername);
|
||||
@@ -242,9 +249,9 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
|
||||
@Override
|
||||
public JSONArray selectList() {
|
||||
List<Opc> opcList= new LambdaQueryChainWrapper<>(opcMapper)
|
||||
List<Opc> opcList = new LambdaQueryChainWrapper<>(opcMapper)
|
||||
.eq(Opc::getIs_delete, "0")
|
||||
.eq(Opc::getIs_active,"1")
|
||||
.eq(Opc::getIs_active, CommonFinalParam.ONE)
|
||||
.list();
|
||||
JSONArray result = new JSONArray();
|
||||
for (int i = 0; i < opcList.size(); i++) {
|
||||
@@ -296,9 +303,9 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
plc_map.put("plc_host", (String) map.get("plc_host"));
|
||||
plc_map.put("opc_server_id", (String) map.get("opc_server_id"));
|
||||
plc_map.put("remark", (String) map.get("remark"));
|
||||
plc_map.put("is_active", "1");
|
||||
plc_map.put("is_active", CommonFinalParam.ONE);
|
||||
plc_map.put("is_delete", "0");
|
||||
plc_map.put("create_by", SecurityUtils.getCurrentUsername());
|
||||
plc_map.put("create_by", SecurityUtils.getCurrentNickName());
|
||||
plc_map.put("create_time", now);
|
||||
OpcPlc entity = ConvertUtil.convert(plc_map, OpcPlc.class);
|
||||
opcPlcMapper.insert(entity);
|
||||
@@ -315,8 +322,8 @@ public class OpcServiceImpl extends CommonServiceImpl<OpcMapper, Opc> implements
|
||||
public void editPLC(JSONObject json) {
|
||||
String now = DateUtil.now();
|
||||
json.put("update_time", now);
|
||||
json.put("update_by", SecurityUtils.getCurrentUsername());
|
||||
OpcPlc opcPlc = JSON.toJavaObject(json,OpcPlc.class);
|
||||
json.put("update_by", SecurityUtils.getCurrentNickName());
|
||||
OpcPlc opcPlc = JSON.toJavaObject(json, OpcPlc.class);
|
||||
opcPlcMapper.updateById(opcPlc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.nl.acs.opc.service.mapper;
|
||||
|
||||
import org.nl.acs.common.base.CommonMapper;
|
||||
import org.nl.acs.opc.domain.Opc;
|
||||
import org.nl.acs.common.base.CommonMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Repository
|
||||
public interface OpcMapper extends CommonMapper<Opc> {
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import org.nl.acs.opc.domain.OpcPlc;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
* @author jiaolm
|
||||
* @date 2023-05-09
|
||||
*/
|
||||
@Repository
|
||||
public interface OpcPlcMapper extends CommonMapper<OpcPlc> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user