|
@@ -1,12 +1,27 @@
|
|
|
package com.gzlh.utils;
|
|
|
|
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.gzlh.bus.EventConfig;
|
|
|
+import com.gzlh.config.ModuleEnum;
|
|
|
+import com.gzlh.config.SystemObject;
|
|
|
+import com.gzlh.config.dto.SerialSetting;
|
|
|
+import com.gzlh.device.capture.brand.CaptureBrandType;
|
|
|
+import com.gzlh.device.electron.brand.ElectronBrandType;
|
|
|
+import com.gzlh.device.led.brand.LedBrandType;
|
|
|
+import com.gzlh.device.weighbridge.brand.WeighbridgeBrandType;
|
|
|
+import com.gzlh.entity.DeviceStatus;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class DeviceCache {
|
|
|
- private static Map<String,Object> map = new ConcurrentHashMap<String,Object>();
|
|
|
+ private static DeviceStatus deviceStatus = new DeviceStatus();
|
|
|
private static Map<String, Date> plcTimeMap = new ConcurrentHashMap<String,Date>();
|
|
|
|
|
|
static boolean interrupt=false;
|
|
@@ -31,22 +46,53 @@ public class DeviceCache {
|
|
|
plcTimeMap=new ConcurrentHashMap<String,Date>();;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public static void put(String k, Object v){
|
|
|
- map.put(k,v);
|
|
|
+ public static String getDeviceStatusJson(){
|
|
|
+ if (StringUtils.isEmpty(deviceStatus.getChannelCode())){
|
|
|
+ deviceStatusInit();
|
|
|
+ }
|
|
|
+ return JSONUtil.toJsonStr(deviceStatus);
|
|
|
}
|
|
|
|
|
|
- public static Object get(String k){
|
|
|
- return map.get(k);
|
|
|
- }
|
|
|
+ public static void deviceStatusInit(){
|
|
|
+ SerialSetting serialSetting= EventConfig.serialSetting;
|
|
|
+ deviceStatus.setChannelCode(SystemObject.applicationConfig.getChannelCode());
|
|
|
+ deviceStatus.setChannelName(SystemObject.applicationConfig.getChannelName());
|
|
|
+
|
|
|
+ DeviceStatus.Device capture = new DeviceStatus.Device(SystemObject.capturePropertiesConfig.getHost(),
|
|
|
+ SystemObject.capturePropertiesConfig.getPort(),
|
|
|
+ LedBrandType.getBrandByCode(SystemObject.capturePropertiesConfig.getBrand()),
|
|
|
+ ModuleEnum.CAPTURE_MODULE.getModuleEn());
|
|
|
+ deviceStatus.getDeviceList().add(capture);
|
|
|
+
|
|
|
+ DeviceStatus.Device plc = new DeviceStatus.Device(serialSetting.getHost(),
|
|
|
+ serialSetting.getPlc().getPort(),
|
|
|
+ "",
|
|
|
+ ModuleEnum.PLC_MODULE.getModuleEn());
|
|
|
+ deviceStatus.getDeviceList().add(plc);
|
|
|
|
|
|
- public static void remove(String k){
|
|
|
- map.remove(k);
|
|
|
+ DeviceStatus.Device led = new DeviceStatus.Device(serialSetting.getHost(),
|
|
|
+ serialSetting.getLed().getPort(),
|
|
|
+ LedBrandType.getBrandByCode(serialSetting.getLed().getBrand()),
|
|
|
+ ModuleEnum.LED_MODULE.getModuleEn());
|
|
|
+ deviceStatus.getDeviceList().add(led);
|
|
|
+
|
|
|
+ DeviceStatus.Device weighbridge = new DeviceStatus.Device(serialSetting.getHost(),
|
|
|
+ serialSetting.getWeighbridge().getPort(),
|
|
|
+ WeighbridgeBrandType.getBrandByCode(serialSetting.getWeighbridge().getBrand()),
|
|
|
+ ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn());
|
|
|
+ deviceStatus.getDeviceList().add(weighbridge);
|
|
|
+
|
|
|
+ DeviceStatus.Device electron = new DeviceStatus.Device(serialSetting.getHost(),
|
|
|
+ serialSetting.getElectron().getPort(),
|
|
|
+ ElectronBrandType.getBrandByCode(serialSetting.getElectron().getBrand()),
|
|
|
+ ModuleEnum.ELECTRON_MODULE.getModuleEn());
|
|
|
+ deviceStatus.getDeviceList().add(electron);
|
|
|
}
|
|
|
|
|
|
- public static Map<String,Object> getCacheMap(){
|
|
|
- return map;
|
|
|
+ public static DeviceStatus getDeviceStatus(){
|
|
|
+ return deviceStatus;
|
|
|
}
|
|
|
+
|
|
|
public static Map<String, Date> getTimeMap(){
|
|
|
return plcTimeMap;
|
|
|
}
|
|
@@ -58,4 +104,12 @@ public class DeviceCache {
|
|
|
public static void setInterrupt(boolean interrupt) {
|
|
|
DeviceCache.interrupt = interrupt;
|
|
|
}
|
|
|
+
|
|
|
+ public static void changeDeviceStatus(String name,int status) {
|
|
|
+ List<DeviceStatus.Device> devices = DeviceCache.getDeviceStatus().getDeviceList();
|
|
|
+ if (devices.stream().anyMatch(device -> device.getName().equalsIgnoreCase(name))){
|
|
|
+ devices.stream().filter(device -> device.getName().equalsIgnoreCase(name))
|
|
|
+ .map(e -> e.setStatus(status)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|