正在显示
11 个修改的文件
包含
493 行增加
和
154 行删除
| 1 | package com.zhonglai.luhui.lsy.plc.service; | 1 | package com.zhonglai.luhui.lsy.plc.service; |
| 2 | 2 | ||
| 3 | +import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService; | ||
| 3 | import com.zhonglai.luhui.lsy.plc.service.dto.DeviceProductProtocol; | 4 | import com.zhonglai.luhui.lsy.plc.service.dto.DeviceProductProtocol; |
| 4 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; |
| 5 | import org.slf4j.LoggerFactory; | 6 | import org.slf4j.LoggerFactory; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 7 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | 9 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| 8 | import org.springframework.boot.builder.SpringApplicationBuilder; | 10 | import org.springframework.boot.builder.SpringApplicationBuilder; |
| 9 | import org.springframework.context.annotation.ComponentScan; | 11 | import org.springframework.context.annotation.ComponentScan; |
| 10 | 12 | ||
| 13 | +import javax.annotation.PostConstruct; | ||
| 14 | + | ||
| 11 | @ComponentScan(basePackages = { | 15 | @ComponentScan(basePackages = { |
| 12 | "com.zhonglai.luhui.device.analysis.comm.agreement", | 16 | "com.zhonglai.luhui.device.analysis.comm.agreement", |
| 13 | "com.zhonglai.luhui.device.analysis.comm.config", | 17 | "com.zhonglai.luhui.device.analysis.comm.config", |
| @@ -17,13 +21,20 @@ import org.springframework.context.annotation.ComponentScan; | @@ -17,13 +21,20 @@ import org.springframework.context.annotation.ComponentScan; | ||
| 17 | public class Main { | 21 | public class Main { |
| 18 | 22 | ||
| 19 | private static Logger log = LoggerFactory.getLogger(Main.class); | 23 | private static Logger log = LoggerFactory.getLogger(Main.class); |
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + private DeviceService deviceService; | ||
| 20 | public static void main(String[] args) { | 27 | public static void main(String[] args) { |
| 21 | log.info("启动服务"); | 28 | log.info("启动服务"); |
| 22 | // System.setProperty("dbPath",Main.class.getClassLoader().getResource("").getPath()); | 29 | // System.setProperty("dbPath",Main.class.getClassLoader().getResource("").getPath()); |
| 23 | - DeviceProductProtocol.init(); | ||
| 24 | SpringApplicationBuilder builder = new SpringApplicationBuilder(Main.class); | 30 | SpringApplicationBuilder builder = new SpringApplicationBuilder(Main.class); |
| 25 | builder.run( args); | 31 | builder.run( args); |
| 26 | 32 | ||
| 27 | } | 33 | } |
| 28 | 34 | ||
| 35 | + @PostConstruct | ||
| 36 | + public void init() { | ||
| 37 | + DeviceProductProtocol.init(deviceService); | ||
| 38 | + } | ||
| 39 | + | ||
| 29 | } | 40 | } |
| @@ -44,7 +44,7 @@ public class DeviceService { | @@ -44,7 +44,7 @@ public class DeviceService { | ||
| 44 | */ | 44 | */ |
| 45 | public List<DeviceInfo> getDeviceInfoList(String imei) | 45 | public List<DeviceInfo> getDeviceInfoList(String imei) |
| 46 | { | 46 | { |
| 47 | - return baseDao.findBysql("SELECT `id`,alarm_code,data_value,device_service_ip FROM `device_info` WHERE `id` LIKE '%"+imei+"%'", DeviceInfo.class); | 47 | + return baseDao.findBysql("SELECT `id`,alarm_code,data_value,device_service_ip,device_type,base_id,user_id,user_login_name,base_name,device_name FROM `device_info` WHERE `id` LIKE '%"+imei+"%'", DeviceInfo.class); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | 50 | ||
| @@ -65,4 +65,14 @@ public class DeviceService { | @@ -65,4 +65,14 @@ public class DeviceService { | ||
| 65 | { | 65 | { |
| 66 | baseDao.insertList(logDeviceOperationList, tableName); | 66 | baseDao.insertList(logDeviceOperationList, tableName); |
| 67 | } | 67 | } |
| 68 | + | ||
| 69 | + public Long getTol(Object object) | ||
| 70 | + { | ||
| 71 | + return baseDao.getTotle(object); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public BaseDao getBaseDao() | ||
| 75 | + { | ||
| 76 | + return baseDao; | ||
| 77 | + } | ||
| 68 | } | 78 | } |
| @@ -23,10 +23,8 @@ import org.slf4j.LoggerFactory; | @@ -23,10 +23,8 @@ import org.slf4j.LoggerFactory; | ||
| 23 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
| 24 | import org.springframework.web.bind.annotation.*; | 24 | import org.springframework.web.bind.annotation.*; |
| 25 | 25 | ||
| 26 | -import java.util.ArrayList; | ||
| 27 | -import java.util.HashMap; | ||
| 28 | -import java.util.List; | ||
| 29 | -import java.util.Map; | 26 | +import java.math.BigDecimal; |
| 27 | +import java.util.*; | ||
| 30 | 28 | ||
| 31 | @Api(tags = "设备操作") | 29 | @Api(tags = "设备操作") |
| 32 | @RestController | 30 | @RestController |
| @@ -42,9 +40,6 @@ public class DeviceController { | @@ -42,9 +40,6 @@ public class DeviceController { | ||
| 42 | 40 | ||
| 43 | @ApiOperation("设备控制") | 41 | @ApiOperation("设备控制") |
| 44 | @ApiImplicitParams({ | 42 | @ApiImplicitParams({ |
| 45 | - @ApiImplicitParam(value = "设备号",name = "deviceId"), | ||
| 46 | - @ApiImplicitParam(value = "数据",name = "dataObject"), | ||
| 47 | - @ApiImplicitParam(value = "地址位",name = "addressBits"), | ||
| 48 | @ApiImplicitParam(value = "设备表id",name = "deviceInfoId") | 43 | @ApiImplicitParam(value = "设备表id",name = "deviceInfoId") |
| 49 | }) | 44 | }) |
| 50 | @RequestMapping(value = "write/{deviceInfoId}",method = RequestMethod.POST) | 45 | @RequestMapping(value = "write/{deviceInfoId}",method = RequestMethod.POST) |
| @@ -61,6 +56,109 @@ public class DeviceController { | @@ -61,6 +56,109 @@ public class DeviceController { | ||
| 61 | { | 56 | { |
| 62 | data.put("type","3"); | 57 | data.put("type","3"); |
| 63 | } | 58 | } |
| 59 | + if ( data.containsKey("type") && data.get("type").toString().equals("getTimer")) | ||
| 60 | + { | ||
| 61 | + return new Message(MessageCode.DEFAULT_SUCCESS_CODE,DateUtils.getNowTimeMilly()); | ||
| 62 | + } | ||
| 63 | + if ( data.containsKey("type") && data.get("type").toString().equals("times")) | ||
| 64 | + { | ||
| 65 | + Integer time = (Integer) data.get("value"); | ||
| 66 | + OrderDtu orderDtu = deviceService.getOrderDtu(deviceControlMessage.getDeviceId()); | ||
| 67 | + MqttMessage mqttMessage = new MqttMessage(); | ||
| 68 | + Map<String,Object> map = new HashMap<>(); | ||
| 69 | + Calendar calendar = Calendar.getInstance(); | ||
| 70 | + calendar.setTime(new Date(time*1000l)); | ||
| 71 | + map.put("SYS_Y_SET",calendar.get(Calendar.YEAR)); | ||
| 72 | + map.put("SYS_M_SET",calendar.get(Calendar.MONTH)+1); | ||
| 73 | + map.put("SYS_D_SET",calendar.get(Calendar.DATE)); | ||
| 74 | + map.put("SYS_h_SET",calendar.get(Calendar.HOUR_OF_DAY)); | ||
| 75 | + map.put("SYS_m_SET",calendar.get(Calendar.MINUTE)); | ||
| 76 | + Topic topic = new Topic("2",orderDtu.getDeviceType(),deviceControlMessage.getDeviceId(),"PUT",null); | ||
| 77 | + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); | ||
| 78 | + try { | ||
| 79 | + Message message = clienNoticeService.sendMessage(topic,mqttMessage); | ||
| 80 | + return message; | ||
| 81 | + } catch (MqttException e) { | ||
| 82 | + throw new RuntimeException(e); | ||
| 83 | + } catch (InterruptedException e) { | ||
| 84 | + throw new RuntimeException(e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + if ( data.containsKey("type") && data.get("type").toString().equals("shijianfuzhu")) | ||
| 88 | + { | ||
| 89 | + Integer time = DateUtils.getNowTimeMilly(); | ||
| 90 | + OrderDtu orderDtu = deviceService.getOrderDtu(deviceControlMessage.getDeviceId()); | ||
| 91 | + MqttMessage mqttMessage = new MqttMessage(); | ||
| 92 | + Map<String,Object> map = new HashMap<>(); | ||
| 93 | + Calendar calendar = Calendar.getInstance(); | ||
| 94 | + calendar.setTime(new Date(time*1000l)); | ||
| 95 | + map.put("SYS_Y_SET",calendar.get(Calendar.YEAR)); | ||
| 96 | + map.put("SYS_M_SET",calendar.get(Calendar.MONTH)+1); | ||
| 97 | + map.put("SYS_D_SET",calendar.get(Calendar.DATE)); | ||
| 98 | + map.put("SYS_h_SET",calendar.get(Calendar.HOUR_OF_DAY)); | ||
| 99 | + map.put("SYS_m_SET",calendar.get(Calendar.MINUTE)); | ||
| 100 | + Topic topic = new Topic("2",orderDtu.getDeviceType(),deviceControlMessage.getDeviceId(),"PUT",null); | ||
| 101 | + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); | ||
| 102 | + try { | ||
| 103 | + Message message = clienNoticeService.sendMessage(topic,mqttMessage); | ||
| 104 | + if(message.getCode()==1) | ||
| 105 | + { | ||
| 106 | + map = new HashMap<>(); | ||
| 107 | + map.put("T_JZ",1); | ||
| 108 | + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); | ||
| 109 | + clienNoticeService.sendMessage(topic,mqttMessage); | ||
| 110 | + | ||
| 111 | + map = new HashMap<>(); | ||
| 112 | + map.put("T_JZ",0); | ||
| 113 | + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); | ||
| 114 | + clienNoticeService.sendMessage(topic,mqttMessage); | ||
| 115 | + } | ||
| 116 | + return message; | ||
| 117 | + } catch (MqttException e) { | ||
| 118 | + throw new RuntimeException(e); | ||
| 119 | + } catch (InterruptedException e) { | ||
| 120 | + throw new RuntimeException(e); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + if ( data.containsKey("type") && data.get("type").toString().equals("timer")) | ||
| 124 | + { | ||
| 125 | +// {"shi":"14","feng":"53","miao":"00","shi1":"16","feng1":"53","miao1":"00","number":2,"type":"timer"} | ||
| 126 | + Integer number = (Integer) data.get("number"); | ||
| 127 | + Map<String, DeviceDataConfig> deviceDataConfigWriteMap = DeviceProductProtocol.deviceDataConfigWriteMap; | ||
| 128 | + | ||
| 129 | + String pw ="PW1"; | ||
| 130 | + int j=number; | ||
| 131 | + for (String key : deviceDataConfigWriteMap.keySet()) | ||
| 132 | + { | ||
| 133 | + DeviceDataConfig deviceDataConfig = deviceDataConfigWriteMap.get(key); | ||
| 134 | + if(deviceDataConfig.getSensor_numer().equals(deviceControlMessage.getAddressBits()) && deviceDataConfig.getAttribute_describe().equals("开始时间")) | ||
| 135 | + { | ||
| 136 | + pw = deviceDataConfig.getAttribute_name().split("_")[0]; | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + String skey = pw+"_TS"+j; | ||
| 140 | + String ekey = pw+"_TE"+j; | ||
| 141 | + if(!"".equals(skey) && !"".equals(ekey)) | ||
| 142 | + { | ||
| 143 | + MqttMessage mqttMessage = new MqttMessage(); | ||
| 144 | + Map<String,Object> map = new HashMap<>(); | ||
| 145 | + map.put(skey,Integer.parseInt(data.get("shi")+""+data.get("feng"))); | ||
| 146 | + map.put(ekey,Integer.parseInt(data.get("shi1")+""+data.get("feng1"))); | ||
| 147 | + OrderDtu orderDtu = deviceService.getOrderDtu(deviceControlMessage.getDeviceId()); | ||
| 148 | + Topic topic = new Topic("2",orderDtu.getDeviceType(),deviceControlMessage.getDeviceId(),"PUT",null); | ||
| 149 | + mqttMessage.setPayload(JSON.toJSONString(map).trim().getBytes()); | ||
| 150 | + try { | ||
| 151 | + Message message = clienNoticeService.sendMessage(topic,mqttMessage); | ||
| 152 | + return message; | ||
| 153 | + } catch (MqttException e) { | ||
| 154 | + throw new RuntimeException(e); | ||
| 155 | + } catch (InterruptedException e) { | ||
| 156 | + throw new RuntimeException(e); | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + return new Message(MessageCode.DEFAULT_FAIL_CODE,"设备不支持该操作!"); | ||
| 160 | + | ||
| 161 | + } | ||
| 64 | DeviceInfo deviceInfo = deviceService.getDeviceInfo(deviceInfoId); | 162 | DeviceInfo deviceInfo = deviceService.getDeviceInfo(deviceInfoId); |
| 65 | 163 | ||
| 66 | String[] ss = deviceInfoId.split("_"); | 164 | String[] ss = deviceInfoId.split("_"); |
| @@ -76,18 +174,22 @@ public class DeviceController { | @@ -76,18 +174,22 @@ public class DeviceController { | ||
| 76 | } | 174 | } |
| 77 | } | 175 | } |
| 78 | } | 176 | } |
| 79 | - Topic topic = new Topic("2",deviceInfo.getDevice_type(),deviceControlMessage.getDeviceId(),"PUT",null); | 177 | + Topic topic = new Topic("2",deviceInfo.getDeviceType(),deviceControlMessage.getDeviceId(),"PUT",null); |
| 80 | 178 | ||
| 81 | - List<DeviceDataConfig> list = DeviceProductProtocol.deviceDataWriteConfigList; | ||
| 82 | - if(null == list) | 179 | + Map<String, DeviceDataConfig> deviceDataConfigWriteMap = DeviceProductProtocol.deviceDataConfigWriteMap; |
| 180 | + if(deviceControlMessage.getDeviceId().equals("004112100018632")) //临时的 | ||
| 181 | + { | ||
| 182 | + deviceDataConfigWriteMap = DeviceProductProtocol.get004112100019727Map(); | ||
| 183 | + } | ||
| 184 | + if(null == deviceDataConfigWriteMap) | ||
| 83 | { | 185 | { |
| 84 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"该设备未配置请联系管理员"); | 186 | return new Message(MessageCode.DEFAULT_FAIL_CODE,"该设备未配置请联系管理员"); |
| 85 | } | 187 | } |
| 86 | Map<String,Object> map = new HashMap<>(); | 188 | Map<String,Object> map = new HashMap<>(); |
| 87 | - //记录日志 | ||
| 88 | - for (DeviceDataConfig deviceDataConfig:list) | 189 | + for (String key:deviceDataConfigWriteMap.keySet()) |
| 89 | { | 190 | { |
| 90 | - if(deviceDataConfig.getSensor_numer().equals(deviceControlMessage.getAddressBits()) && deviceDataConfig.getPlc_data_type().sensorDataType.equals(data.get("type")) ) | 191 | + DeviceDataConfig deviceDataConfig = deviceDataConfigWriteMap.get(key); |
| 192 | + if(deviceDataConfig.getSensor_numer().equals(deviceControlMessage.getAddressBits()) && PLCDataType.valueOf(deviceDataConfig.getPlc_data_type()).sensorDataType.equals(data.get("type")) ) | ||
| 91 | { | 193 | { |
| 92 | //记录日志 | 194 | //记录日志 |
| 93 | map.put(deviceDataConfig.getAttribute_name(), data.get("value").toString().equals(deviceDataConfig.getAlarmValue())?1:0); | 195 | map.put(deviceDataConfig.getAttribute_name(), data.get("value").toString().equals(deviceDataConfig.getAlarmValue())?1:0); |
| @@ -117,10 +219,10 @@ public class DeviceController { | @@ -117,10 +219,10 @@ public class DeviceController { | ||
| 117 | object = GsonConstructor.get().fromJson(deviceInfo.getDataValue(),JsonObject.class); | 219 | object = GsonConstructor.get().fromJson(deviceInfo.getDataValue(),JsonObject.class); |
| 118 | } | 220 | } |
| 119 | 221 | ||
| 120 | - List<DeviceDataConfig> deviceDataConfigList = DeviceProductProtocol.deviceDataConfigList; | ||
| 121 | - for (DeviceDataConfig deviceDataConfig:deviceDataConfigList) | 222 | + if(deviceDataConfigWriteMap.containsKey(deviceControlMessage.getAddressBits())) |
| 122 | { | 223 | { |
| 123 | - if(deviceDataConfig.getSensor_numer().equals(deviceControlMessage.getAddressBits()) && deviceDataConfig.getPlc_data_type().sensorDataType.equals(data.get("type")) ) | 224 | + DeviceDataConfig deviceDataConfig = deviceDataConfigWriteMap.get(deviceControlMessage.getAddressBits()); |
| 225 | + if(PLCDataType.valueOf(deviceDataConfig.getPlc_data_type()).sensorDataType.equals(data.get("type"))) | ||
| 124 | { | 226 | { |
| 125 | object.addProperty(data.get("type")+"",data.get("value").toString()); | 227 | object.addProperty(data.get("type")+"",data.get("value").toString()); |
| 126 | } | 228 | } |
| @@ -147,9 +249,9 @@ public class DeviceController { | @@ -147,9 +249,9 @@ public class DeviceController { | ||
| 147 | } | 249 | } |
| 148 | 250 | ||
| 149 | public static void main(String[] args) { | 251 | public static void main(String[] args) { |
| 150 | - DeviceService deviceService = new DeviceService(); | ||
| 151 | - DeviceInfo deviceInfo = deviceService.getDeviceInfo("deviceInfoId"); | ||
| 152 | - System.out.println(); | 252 | + BigDecimal bd = new BigDecimal(DateUtils.getNowTimeMilly()); |
| 253 | + String time = DateUtils.parseDateToStr("HH:mm:ss",new Date(Integer.parseInt(bd.toPlainString())*1000l)); | ||
| 254 | + System.out.println(time); | ||
| 153 | } | 255 | } |
| 154 | 256 | ||
| 155 | /** | 257 | /** |
| 1 | package com.zhonglai.luhui.lsy.plc.service.dto; | 1 | package com.zhonglai.luhui.lsy.plc.service.dto; |
| 2 | 2 | ||
| 3 | import com.google.gson.JsonObject; | 3 | import com.google.gson.JsonObject; |
| 4 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 5 | +import io.swagger.annotations.ApiModel; | ||
| 6 | +import io.swagger.annotations.ApiModelProperty; | ||
| 4 | 7 | ||
| 5 | import java.util.Map; | 8 | import java.util.Map; |
| 6 | 9 | ||
| @@ -8,12 +11,17 @@ import java.util.Map; | @@ -8,12 +11,17 @@ import java.util.Map; | ||
| 8 | * plc控制请求消息体 | 11 | * plc控制请求消息体 |
| 9 | * Created by zhonglai on 2016/12/30. | 12 | * Created by zhonglai on 2016/12/30. |
| 10 | */ | 13 | */ |
| 14 | +@ApiModel | ||
| 11 | public class DeviceControlMessage { | 15 | public class DeviceControlMessage { |
| 12 | - | 16 | + @ApiModelProperty("设备号") |
| 13 | private String deviceId; //设备号 | 17 | private String deviceId; //设备号 |
| 18 | + @ApiModelProperty("地址位") | ||
| 14 | private String addressBits; //地址位 | 19 | private String addressBits; //地址位 |
| 20 | + @ApiModelProperty("命令字") | ||
| 15 | private String commandWord; //命令字 | 21 | private String commandWord; //命令字 |
| 22 | + @ApiModelProperty("数据") | ||
| 16 | private Map<String,Object> dataObject; //数据 | 23 | private Map<String,Object> dataObject; //数据 |
| 24 | + @ApiModelProperty("指令类型") | ||
| 17 | private String commandTye ; //指令类型 | 25 | private String commandTye ; //指令类型 |
| 18 | 26 | ||
| 19 | public String getDeviceId() { | 27 | public String getDeviceId() { |
| @@ -4,12 +4,11 @@ import lombok.Data; | @@ -4,12 +4,11 @@ import lombok.Data; | ||
| 4 | 4 | ||
| 5 | @Data | 5 | @Data |
| 6 | public class DeviceDataConfig { | 6 | public class DeviceDataConfig { |
| 7 | - private Integer number; | ||
| 8 | private String attribute_name; | 7 | private String attribute_name; |
| 9 | - private PLCType device_type; | 8 | + private String device_type; |
| 10 | private String sensor_numer; | 9 | private String sensor_numer; |
| 11 | private String attribute_describe; | 10 | private String attribute_describe; |
| 12 | - private PLCDataType plc_data_type; | 11 | + private String plc_data_type; |
| 13 | 12 | ||
| 14 | private String alarmCode; | 13 | private String alarmCode; |
| 15 | private String alarmValue; | 14 | private String alarmValue; |
| @@ -18,20 +17,30 @@ public class DeviceDataConfig { | @@ -18,20 +17,30 @@ public class DeviceDataConfig { | ||
| 18 | 17 | ||
| 19 | } | 18 | } |
| 20 | 19 | ||
| 21 | - public DeviceDataConfig(Integer number, String attribute_name, PLCType device_type, PLCDataType plc_data_type,String sensor_numer,String attribute_describe) { | ||
| 22 | - this.number = number; | 20 | + public DeviceDataConfig(String attribute_name, PLCType device_type, PLCDataType plc_data_type,String sensor_numer,String attribute_describe) { |
| 23 | this.attribute_name = attribute_name; | 21 | this.attribute_name = attribute_name; |
| 24 | - this.device_type = device_type; | ||
| 25 | - this.plc_data_type = plc_data_type; | 22 | + if(null != device_type) |
| 23 | + { | ||
| 24 | + this.device_type = device_type.name(); | ||
| 25 | + } | ||
| 26 | + if(null != plc_data_type) | ||
| 27 | + { | ||
| 28 | + this.plc_data_type = plc_data_type.name(); | ||
| 29 | + } | ||
| 26 | this.sensor_numer = sensor_numer; | 30 | this.sensor_numer = sensor_numer; |
| 27 | this.attribute_describe = attribute_describe; | 31 | this.attribute_describe = attribute_describe; |
| 28 | } | 32 | } |
| 29 | 33 | ||
| 30 | public DeviceDataConfig(Integer number, String attribute_name,PLCType device_type, PLCDataType plc_data_type,String sensor_numer,String attribute_describe,String alarmCode,String alarmValue) { | 34 | public DeviceDataConfig(Integer number, String attribute_name,PLCType device_type, PLCDataType plc_data_type,String sensor_numer,String attribute_describe,String alarmCode,String alarmValue) { |
| 31 | - this.number = number; | ||
| 32 | this.attribute_name = attribute_name; | 35 | this.attribute_name = attribute_name; |
| 33 | - this.device_type = device_type; | ||
| 34 | - this.plc_data_type = plc_data_type; | 36 | + if(null != device_type) |
| 37 | + { | ||
| 38 | + this.device_type = device_type.name(); | ||
| 39 | + } | ||
| 40 | + if(null != plc_data_type) | ||
| 41 | + { | ||
| 42 | + this.plc_data_type = plc_data_type.name(); | ||
| 43 | + } | ||
| 35 | this.sensor_numer = sensor_numer; | 44 | this.sensor_numer = sensor_numer; |
| 36 | this.attribute_describe = attribute_describe; | 45 | this.attribute_describe = attribute_describe; |
| 37 | this.alarmCode = alarmCode; | 46 | this.alarmCode = alarmCode; |
| @@ -17,5 +17,11 @@ public class DeviceInfo { | @@ -17,5 +17,11 @@ public class DeviceInfo { | ||
| 17 | private String online; //设备在线状态(00-不在线,01-在线) | 17 | private String online; //设备在线状态(00-不在线,01-在线) |
| 18 | private Integer dataUpdateTime; //更新时间 | 18 | private Integer dataUpdateTime; //更新时间 |
| 19 | private String deviceServiceIp; //设备服务器IP | 19 | private String deviceServiceIp; //设备服务器IP |
| 20 | - private String device_type; //设备类型 | 20 | + private String deviceType; //设备类型 |
| 21 | + private Integer baseId; | ||
| 22 | + private Integer userId; | ||
| 23 | + private String userLoginName; | ||
| 24 | + private String baseName; | ||
| 25 | + private String deviceName; | ||
| 26 | + | ||
| 21 | } | 27 | } |
| 1 | package com.zhonglai.luhui.lsy.plc.service.dto; | 1 | package com.zhonglai.luhui.lsy.plc.service.dto; |
| 2 | 2 | ||
| 3 | -import lombok.Data; | 3 | +import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService; |
| 4 | 4 | ||
| 5 | -import java.util.ArrayList; | ||
| 6 | import java.util.HashMap; | 5 | import java.util.HashMap; |
| 7 | import java.util.List; | 6 | import java.util.List; |
| 8 | import java.util.Map; | 7 | import java.util.Map; |
| 9 | 8 | ||
| 9 | + | ||
| 10 | /** | 10 | /** |
| 11 | * 产品协议 | 11 | * 产品协议 |
| 12 | */ | 12 | */ |
| 13 | public class DeviceProductProtocol { | 13 | public class DeviceProductProtocol { |
| 14 | public static String payloadtype = "Json"; | 14 | public static String payloadtype = "Json"; |
| 15 | - public static List<DeviceDataConfig> deviceDataConfigList = new ArrayList<>(); | 15 | + public static Map<String, DeviceDataConfig> deviceDataConfigReadMap = new HashMap<>(); |
| 16 | 16 | ||
| 17 | - public static List<DeviceDataConfig> deviceDataWriteConfigList = new ArrayList<>(); | 17 | + public static Map<String, DeviceDataConfig> deviceDataConfigWriteMap = new HashMap<>(); |
| 18 | 18 | ||
| 19 | - public static void init() | 19 | + public static void init(DeviceService deviceService) |
| 20 | { | 20 | { |
| 21 | - deviceDataConfigList.add(new DeviceDataConfig(1,"C001A_RUN",PLCType.推水机,PLCDataType.控制器状态码,"01","运行信号")); | ||
| 22 | - deviceDataConfigList.add(new DeviceDataConfig(2,"C001A_ALARM",PLCType.推水机,PLCDataType.故障代码,"01","故障信号","11","01")); | ||
| 23 | - deviceDataConfigList.add(new DeviceDataConfig(3,"C001B_RUN",PLCType.推水机,PLCDataType.控制器状态码,"02","运行信号")); | ||
| 24 | - deviceDataConfigList.add(new DeviceDataConfig(4,"C001B_ALARM",PLCType.推水机,PLCDataType.故障代码,"02","故障信号","11","01")); | ||
| 25 | - deviceDataConfigList.add(new DeviceDataConfig(5,"C001C_RUN",PLCType.推水机,PLCDataType.控制器状态码,"03","运行信号")); | ||
| 26 | - deviceDataConfigList.add(new DeviceDataConfig(6,"C001C_ALARM",PLCType.推水机,PLCDataType.故障代码,"03","故障信号","11","01")); | ||
| 27 | - deviceDataConfigList.add(new DeviceDataConfig(48,"C001D_RUN",PLCType.推水机,PLCDataType.控制器状态码,"04","运行信号")); | ||
| 28 | - deviceDataConfigList.add(new DeviceDataConfig(49,"C001D_ALARM",PLCType.推水机,PLCDataType.故障代码,"04","故障信号","11","01")); | ||
| 29 | - deviceDataConfigList.add(new DeviceDataConfig(50,"C001E_RUN",PLCType.推水机,PLCDataType.控制器状态码,"05","运行信号")); | ||
| 30 | - deviceDataConfigList.add(new DeviceDataConfig(51,"C001E_ALARM",PLCType.推水机,PLCDataType.故障代码,"05","故障信号","11","01")); | ||
| 31 | - deviceDataConfigList.add(new DeviceDataConfig(52,"C001F_RUN",PLCType.推水机,PLCDataType.控制器状态码,"06","运行信号")); | ||
| 32 | - deviceDataConfigList.add(new DeviceDataConfig(53,"C001F_ALARM",PLCType.推水机,PLCDataType.故障代码,"06","故障信号","11","01")); | ||
| 33 | - deviceDataConfigList.add(new DeviceDataConfig(7,"C002_RUN",PLCType.增氧机,PLCDataType.控制器状态码,"34","运行信号")); | ||
| 34 | - deviceDataConfigList.add(new DeviceDataConfig(8,"C002_ALARM",PLCType.增氧机,PLCDataType.故障代码,"34","故障信号","11","01")); | ||
| 35 | - deviceDataConfigList.add(new DeviceDataConfig(9,"P001A_RUN",PLCType.排污,PLCDataType.控制器状态码,"21","运行信号")); | ||
| 36 | - deviceDataConfigList.add(new DeviceDataConfig(10,"P001A_ALARM",PLCType.排污,PLCDataType.故障代码,"21","故障信号","11","01")); | ||
| 37 | - deviceDataConfigList.add(new DeviceDataConfig(11,"P001B_RUN",PLCType.排污,PLCDataType.控制器状态码,"22","运行信号")); | ||
| 38 | - deviceDataConfigList.add(new DeviceDataConfig(12,"P001B_ALARM",PLCType.排污,PLCDataType.故障代码,"22","故障信号","11","01")); | ||
| 39 | - deviceDataConfigList.add(new DeviceDataConfig(13,"P001C_RUN",PLCType.排污,PLCDataType.控制器状态码,"23","运行信号")); | ||
| 40 | - deviceDataConfigList.add(new DeviceDataConfig(14,"P001C_ALARM",PLCType.排污,PLCDataType.故障代码,"23","故障信号","11","01")); | ||
| 41 | - deviceDataConfigList.add(new DeviceDataConfig(54,"P001D_RUN",PLCType.排污,PLCDataType.控制器状态码,"24","运行信号")); | ||
| 42 | - deviceDataConfigList.add(new DeviceDataConfig(55,"P001D_ALARM",PLCType.排污,PLCDataType.故障代码,"24","故障信号","11","01")); | ||
| 43 | - deviceDataConfigList.add(new DeviceDataConfig(56,"P001E_RUN",PLCType.排污,PLCDataType.控制器状态码,"25","运行信号")); | ||
| 44 | - deviceDataConfigList.add(new DeviceDataConfig(57,"P001E_ALARM",PLCType.排污,PLCDataType.故障代码,"25","故障信号","11","01")); | ||
| 45 | - deviceDataConfigList.add(new DeviceDataConfig(58,"P001F_RUN",PLCType.排污,PLCDataType.控制器状态码,"26","运行信号")); | ||
| 46 | - deviceDataConfigList.add(new DeviceDataConfig(59,"P001F_ALARM",PLCType.排污,PLCDataType.故障代码,"26","故障信号","11","01")); | ||
| 47 | - deviceDataConfigList.add(new DeviceDataConfig(60,"P002_RUN",PLCType.排污,PLCDataType.控制器状态码,"40","运行信号")); | ||
| 48 | - deviceDataConfigList.add(new DeviceDataConfig(61,"P002_ALARM",PLCType.排污,PLCDataType.故障代码,"40","故障信号","11","01")); | ||
| 49 | - deviceDataConfigList.add(new DeviceDataConfig(62,"ZZC_L_YW",PLCType.排污,PLCDataType.液位高低,"41","低液位信号",null,"00")); | ||
| 50 | - deviceDataConfigList.add(new DeviceDataConfig(63,"ZZC_H_YW",PLCType.排污,PLCDataType.液位高低,"41","高液位信号",null,"01")); | ||
| 51 | - deviceDataConfigList.add(new DeviceDataConfig(15,"SD_RUN",null,PLCDataType.故障代码,"00","市电供电信号","12","00")); | ||
| 52 | - deviceDataConfigList.add(new DeviceDataConfig(16,"FD_RUN",null,PLCDataType.故障代码,"00","发电供电信号","13","01")); | ||
| 53 | - deviceDataConfigList.add(new DeviceDataConfig(17,"DY_ALARM",null,PLCDataType.故障代码,"00","电源故障信号","51","01")); | ||
| 54 | - deviceDataConfigList.add(new DeviceDataConfig(18,"SYS_AUTO",null,PLCDataType.控制柜状态,"00","系统自动允许")); | ||
| 55 | - deviceDataConfigList.add(new DeviceDataConfig(26,"TX_RUN",null,PLCDataType.故障代码,"00","远程通讯正常","01","00")); | ||
| 56 | - deviceDataConfigList.add(new DeviceDataConfig(41,"SYS_ALARM",null,PLCDataType.故障代码,"00","设备故障报警","01","01")); | ||
| 57 | - deviceDataConfigList.add(new DeviceDataConfig(73,"YC_AUTO_P002",PLCType.排污,PLCDataType.控制器状态码,"41","远程自动按钮",null,"01")); | ||
| 58 | - | ||
| 59 | - deviceDataConfigList.add(new DeviceDataConfig(1,"C001_RUN",PLCType.曝气,PLCDataType.控制器状态码,"42","运行信号")); | ||
| 60 | - deviceDataConfigList.add(new DeviceDataConfig(2,"C001_ALARM",PLCType.曝气,PLCDataType.故障代码,"42","故障信号","11","01")); | ||
| 61 | - deviceDataConfigList.add(new DeviceDataConfig(1,"P003_RUN",PLCType.微滤机,PLCDataType.控制器状态码,"43","微滤反洗水泵运行信号")); | ||
| 62 | - deviceDataConfigList.add(new DeviceDataConfig(2,"P003_ALARM",PLCType.微滤机,PLCDataType.故障代码,"43","微滤反洗水泵故障信号","11","01")); | ||
| 63 | - deviceDataConfigList.add(new DeviceDataConfig(1,"M001_RUN",PLCType.微滤机,PLCDataType.控制器状态码,"44","微滤驱动电机运行信号")); | ||
| 64 | - deviceDataConfigList.add(new DeviceDataConfig(2,"M001_ALARM",PLCType.微滤机,PLCDataType.故障代码,"44","微滤驱动电机故障信号","11","01")); | ||
| 65 | - deviceDataConfigList.add(new DeviceDataConfig(1,"DV01_RUN",PLCType.蛋分,PLCDataType.控制器状态码,"45","蛋分电磁阀运行信号")); | ||
| 66 | - deviceDataConfigList.add(new DeviceDataConfig(1,"DF_YW",PLCType.蛋分,PLCDataType.液位高低,"45","蛋分低液位")); | ||
| 67 | - deviceDataConfigList.add(new DeviceDataConfig(1,"ZWX_RUN",PLCType.杀菌,PLCDataType.控制器状态码,"46","紫外线运行信号")); | ||
| 68 | - deviceDataConfigList.add(new DeviceDataConfig(1,"JCY_RUN",PLCType.鱼儿乐,PLCDataType.控制器状态码,"47","水质监测仪运行信号")); | ||
| 69 | - deviceDataConfigList.add(new DeviceDataConfig(1,"ZM_RUN",null,PLCDataType.控制器状态码,"00","照明运行信号")); | ||
| 70 | - deviceDataConfigList.add(new DeviceDataConfig(1,"XHSC_YW_L",PLCType.循环水池,PLCDataType.低液位,"48","循环水池低液位")); | ||
| 71 | - deviceDataConfigList.add(new DeviceDataConfig(1,"XHSC_YW_H",PLCType.循环水池,PLCDataType.高液位,"49","循环水池高液位")); | ||
| 72 | - deviceDataConfigList.add(new DeviceDataConfig(1,"SWLT_YW_1",PLCType.生物滤筒,PLCDataType.液位高低,"50","生物滤筒液位1")); | ||
| 73 | - deviceDataConfigList.add(new DeviceDataConfig(1,"SWLT_YW_2",PLCType.生物滤筒,PLCDataType.液位高低,"51","生物滤筒液位2")); | ||
| 74 | - deviceDataConfigList.add(new DeviceDataConfig(1,"ZWX_YW",PLCType.杀菌,PLCDataType.液位高低,"52","紫外线液位")); | ||
| 75 | - deviceDataConfigList.add(new DeviceDataConfig(1,"WL_YW",PLCType.微滤机,PLCDataType.高液位,"53","微滤机池高液位")); | ||
| 76 | - | ||
| 77 | - deviceDataWriteConfigList.add(new DeviceDataConfig(27,"YC_ST_C001A",PLCType.推水机,PLCDataType.控制器状态码,"01","远程启动按钮",null,"01")); | ||
| 78 | - deviceDataWriteConfigList.add(new DeviceDataConfig(28,"YC_STP_C001A",PLCType.推水机,PLCDataType.控制器状态码,"01","远程停止按钮",null,"00")); | ||
| 79 | - deviceDataWriteConfigList.add(new DeviceDataConfig(29,"YC_ST_C001B",PLCType.推水机,PLCDataType.控制器状态码,"02","远程启动按钮",null,"01")); | ||
| 80 | - deviceDataWriteConfigList.add(new DeviceDataConfig(30,"YC_STP_C001B",PLCType.推水机,PLCDataType.控制器状态码,"02","远程停止按钮",null,"00")); | ||
| 81 | - deviceDataWriteConfigList.add(new DeviceDataConfig(31,"YC_ST_C001C",PLCType.推水机,PLCDataType.控制器状态码,"03","远程启动按钮",null,"01")); | ||
| 82 | - deviceDataWriteConfigList.add(new DeviceDataConfig(32,"YC_STP_C001C",PLCType.推水机,PLCDataType.控制器状态码,"03","远程停止按钮",null,"00")); | ||
| 83 | - deviceDataWriteConfigList.add(new DeviceDataConfig(42,"YC_ST_C001D",PLCType.推水机,PLCDataType.控制器状态码,"04","远程启动按钮",null,"01")); | ||
| 84 | - deviceDataWriteConfigList.add(new DeviceDataConfig(43,"YC_STP_C001D",PLCType.推水机,PLCDataType.控制器状态码,"04","远程停止按钮",null,"00")); | ||
| 85 | - deviceDataWriteConfigList.add(new DeviceDataConfig(44,"YC_ST_C001E",PLCType.推水机,PLCDataType.控制器状态码,"05","远程启动按钮",null,"01")); | ||
| 86 | - deviceDataWriteConfigList.add(new DeviceDataConfig(45,"YC_STP_C001E",PLCType.推水机,PLCDataType.控制器状态码,"05","远程停止按钮",null,"00")); | ||
| 87 | - deviceDataWriteConfigList.add(new DeviceDataConfig(46,"YC_ST_C001F",PLCType.推水机,PLCDataType.控制器状态码,"06","远程启动按钮",null,"01")); | ||
| 88 | - deviceDataWriteConfigList.add(new DeviceDataConfig(47,"YC_STP_C001F",PLCType.推水机,PLCDataType.控制器状态码,"06","远程停止按钮",null,"00")); | ||
| 89 | - deviceDataWriteConfigList.add(new DeviceDataConfig(33,"YC_ST_C002",PLCType.增氧机,PLCDataType.控制器状态码,"34","远程启动按钮",null,"01")); | ||
| 90 | - deviceDataWriteConfigList.add(new DeviceDataConfig(34,"YC_STP_C002",PLCType.增氧机,PLCDataType.控制器状态码,"34","远程停止按钮",null,"00")); | ||
| 91 | - deviceDataWriteConfigList.add(new DeviceDataConfig(35,"YC_ST_P001A",PLCType.排污,PLCDataType.控制器状态码,"21","远程启动按钮",null,"01")); | ||
| 92 | - deviceDataWriteConfigList.add(new DeviceDataConfig(36,"YC_STP_P001A",PLCType.排污,PLCDataType.控制器状态码,"21","远程停止按钮",null,"00")); | ||
| 93 | - deviceDataWriteConfigList.add(new DeviceDataConfig(37,"YC_ST_P001B",PLCType.排污,PLCDataType.控制器状态码,"22","远程启动按钮",null,"01")); | ||
| 94 | - deviceDataWriteConfigList.add(new DeviceDataConfig(38,"YC_STP_P001B",PLCType.排污,PLCDataType.控制器状态码,"22","远程停止按钮",null,"00")); | ||
| 95 | - deviceDataWriteConfigList.add(new DeviceDataConfig(39,"YC_ST_P001C",PLCType.排污,PLCDataType.控制器状态码,"23","远程启动按钮",null,"01")); | ||
| 96 | - deviceDataWriteConfigList.add(new DeviceDataConfig(40,"YC_STP_P001C",PLCType.排污,PLCDataType.控制器状态码,"23","远程停止按钮",null,"00")); | ||
| 97 | - deviceDataWriteConfigList.add(new DeviceDataConfig(64,"YC_ST_P001D",PLCType.排污,PLCDataType.控制器状态码,"24","远程启动按钮",null,"01")); | ||
| 98 | - deviceDataWriteConfigList.add(new DeviceDataConfig(65,"YC_STP_P001D",PLCType.排污,PLCDataType.控制器状态码,"24","远程停止按钮",null,"00")); | ||
| 99 | - deviceDataWriteConfigList.add(new DeviceDataConfig(66,"YC_ST_P001E",PLCType.排污,PLCDataType.控制器状态码,"25","远程启动按钮",null,"01")); | ||
| 100 | - deviceDataWriteConfigList.add(new DeviceDataConfig(67,"YC_STP_P001E",PLCType.排污,PLCDataType.控制器状态码,"25","远程停止按钮",null,"00")); | ||
| 101 | - deviceDataWriteConfigList.add(new DeviceDataConfig(68,"YC_ST_P001F",PLCType.排污,PLCDataType.控制器状态码,"26","远程启动按钮",null,"01")); | ||
| 102 | - deviceDataWriteConfigList.add(new DeviceDataConfig(69,"YC_STP_P001F",PLCType.排污,PLCDataType.控制器状态码,"26","远程停止按钮",null,"00")); | ||
| 103 | - deviceDataWriteConfigList.add(new DeviceDataConfig(70,"YC_ST_P002",PLCType.排污,PLCDataType.控制器状态码,"40","远程启动按钮",null,"01")); | ||
| 104 | - deviceDataWriteConfigList.add(new DeviceDataConfig(71,"YC_STP_P002",PLCType.排污,PLCDataType.控制器状态码,"40","远程停止按钮",null,"00")); | ||
| 105 | - deviceDataWriteConfigList.add(new DeviceDataConfig(72,"YC_AUTO_P002",PLCType.排污,PLCDataType.控制器状态码,"41","远程自动按钮",null,"01")); | ||
| 106 | - deviceDataWriteConfigList.add(new DeviceDataConfig(74,"SYS_REST",PLCType.推水机,PLCDataType.复位,"01","设备故障复位",null,"1")); | ||
| 107 | - | 21 | + List<DeviceDataConfig> deviceDataConfigList = deviceService.getBaseDao().findBysql("SELECT * FROM `device_data_config` WHERE read_write_type=1 OR read_write_type=3",DeviceDataConfig.class); |
| 22 | + if(null != deviceDataConfigList && deviceDataConfigList.size() > 0) | ||
| 23 | + { | ||
| 24 | + for (DeviceDataConfig deviceDataConfig : deviceDataConfigList) | ||
| 25 | + { | ||
| 26 | + deviceDataConfigReadMap.put(deviceDataConfig.getAttribute_name(),deviceDataConfig); | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + List<DeviceDataConfig> deviceDataConfigs = deviceService.getBaseDao().findBysql("SELECT * FROM `device_data_config` WHERE read_write_type=2 OR read_write_type=3",DeviceDataConfig.class); | ||
| 30 | + if(null != deviceDataConfigs && deviceDataConfigs.size() > 0) | ||
| 31 | + { | ||
| 32 | + for (DeviceDataConfig deviceDataConfig : deviceDataConfigs) | ||
| 33 | + { | ||
| 34 | + deviceDataConfigWriteMap.put(deviceDataConfig.getAttribute_name(),deviceDataConfig); | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + } | ||
| 108 | 38 | ||
| 39 | + public static Map<String, DeviceDataConfig> get004112100019727Map() | ||
| 40 | + { | ||
| 41 | +// String attribute_name, PLCType device_type, PLCDataType plc_data_type,String sensor_numer,String attribute_describe | ||
| 42 | + Map<String, DeviceDataConfig> deviceDataConfigReadMap = new HashMap<>(); | ||
| 43 | + deviceDataConfigReadMap.put("YC_QT_C001A",new DeviceDataConfig("YC_QT_C001A",PLCType.推水机,PLCDataType.控制器状态码,"01","远程启停按钮")); | ||
| 44 | + deviceDataConfigReadMap.put("YC_QT_C001B",new DeviceDataConfig("YC_QT_C001B",PLCType.推水机,PLCDataType.控制器状态码,"02","远程启停按钮")); | ||
| 45 | + deviceDataConfigReadMap.put("YC_QT_C001C",new DeviceDataConfig("YC_QT_C001C",PLCType.推水机,PLCDataType.控制器状态码,"03","远程启停按钮")); | ||
| 46 | + deviceDataConfigReadMap.put("YC_QT_C001D",new DeviceDataConfig("YC_QT_C001D",PLCType.推水机,PLCDataType.控制器状态码,"04","远程启停按钮")); | ||
| 47 | + deviceDataConfigReadMap.put("YC_QT_C002",new DeviceDataConfig("YC_QT_C002",PLCType.增氧机,PLCDataType.控制器状态码,"34","远程启停按钮")); | ||
| 48 | + deviceDataConfigReadMap.put("YC_QT_P001A",new DeviceDataConfig("YC_QT_P001A",PLCType.排污,PLCDataType.控制器状态码,"21","远程启停按钮")); | ||
| 49 | + deviceDataConfigReadMap.put("YC_QT_P001B",new DeviceDataConfig("YC_QT_P001B",PLCType.排污,PLCDataType.控制器状态码,"22","远程启停按钮")); | ||
| 50 | + deviceDataConfigReadMap.put("YC_QT_P001C",new DeviceDataConfig("YC_QT_P001C",PLCType.排污,PLCDataType.控制器状态码,"23","远程启停按钮")); | ||
| 51 | + deviceDataConfigReadMap.put("YC_QT_P001D",new DeviceDataConfig("YC_QT_P001D",PLCType.排污,PLCDataType.控制器状态码,"24","远程启停按钮")); | ||
| 52 | + return deviceDataConfigReadMap; | ||
| 109 | } | 53 | } |
| 110 | } | 54 | } |
lh-modules/lh-lsy-plc-service/src/main/java/com/zhonglai/luhui/lsy/plc/service/dto/DeviceTimer.java
0 → 100644
| 1 | +package com.zhonglai.luhui.lsy.plc.service.dto; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * PLC 开关定时器 | ||
| 6 | + * Created by Administrator on 2017/2/6. | ||
| 7 | + */ | ||
| 8 | +public class DeviceTimer { | ||
| 9 | + | ||
| 10 | + private Integer id; //主键id | ||
| 11 | + private String imei; //IMEI号 | ||
| 12 | + private String number; //编号(多个用|分开) | ||
| 13 | + private String deviceName; //设备名称(多个用|分开) | ||
| 14 | + private Integer serialNumber; //控制序号 | ||
| 15 | + private Integer baseId; //基地id | ||
| 16 | + private String baseName; //基地名称 | ||
| 17 | + private Integer userId; //用户id | ||
| 18 | + private String userLogin; //用户登录名 | ||
| 19 | + private Integer startTime; //开始时间 | ||
| 20 | + private Integer endTime; //结束时间 | ||
| 21 | + private Integer createTime; //创建时间 | ||
| 22 | + | ||
| 23 | + public Integer getId() { | ||
| 24 | + return id; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public void setId(Integer id) { | ||
| 28 | + this.id = id; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public String getImei() { | ||
| 32 | + return imei; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public void setImei(String imei) { | ||
| 36 | + this.imei = imei; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public String getNumber() { | ||
| 40 | + return number; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + public void setNumber(String number) { | ||
| 44 | + this.number = number; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public String getDeviceName() { | ||
| 48 | + return deviceName; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public void setDeviceName(String deviceName) { | ||
| 52 | + this.deviceName = deviceName; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + public Integer getStartTime() { | ||
| 56 | + return startTime; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public void setStartTime(Integer startTime) { | ||
| 60 | + this.startTime = startTime; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public Integer getEndTime() { | ||
| 64 | + return endTime; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + public void setEndTime(Integer endTime) { | ||
| 68 | + this.endTime = endTime; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public Integer getCreateTime() { | ||
| 72 | + return createTime; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + public void setCreateTime(Integer createTime) { | ||
| 76 | + this.createTime = createTime; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public Integer getUserId() { | ||
| 80 | + return userId; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void setUserId(Integer userId) { | ||
| 84 | + this.userId = userId; | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + public String getUserLogin() { | ||
| 88 | + return userLogin; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setUserLogin(String userLogin) { | ||
| 92 | + this.userLogin = userLogin; | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + public Integer getBaseId() { | ||
| 96 | + return baseId; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public void setBaseId(Integer baseId) { | ||
| 100 | + this.baseId = baseId; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public String getBaseName() { | ||
| 104 | + return baseName; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + public void setBaseName(String baseName) { | ||
| 108 | + this.baseName = baseName; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public Integer getSerialNumber() { | ||
| 112 | + return serialNumber; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + public void setSerialNumber(Integer serialNumber) { | ||
| 116 | + this.serialNumber = serialNumber; | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | + |
| @@ -17,6 +17,8 @@ public enum PLCDataType { | @@ -17,6 +17,8 @@ public enum PLCDataType { | ||
| 17 | 复位("101"), | 17 | 复位("101"), |
| 18 | 低液位("102"), | 18 | 低液位("102"), |
| 19 | 高液位("103"), | 19 | 高液位("103"), |
| 20 | + 定时("105"), | ||
| 21 | + 校准时间("106"), | ||
| 20 | 控制柜状态("104"); | 22 | 控制柜状态("104"); |
| 21 | public String sensorDataType; | 23 | public String sensorDataType; |
| 22 | 24 |
| 1 | package com.zhonglai.luhui.lsy.plc.service.service.topic; | 1 | package com.zhonglai.luhui.lsy.plc.service.service.topic; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | +import com.google.gson.JsonObject; | ||
| 4 | import com.ruoyi.common.utils.DateUtils; | 5 | import com.ruoyi.common.utils.DateUtils; |
| 5 | import com.ruoyi.common.utils.GsonConstructor; | 6 | import com.ruoyi.common.utils.GsonConstructor; |
| 6 | import com.ruoyi.common.utils.StringUtils; | 7 | import com.ruoyi.common.utils.StringUtils; |
| 7 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; | 8 | import com.zhonglai.luhui.device.analysis.comm.config.SysParameter; |
| 9 | +import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao; | ||
| 8 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceOperationTypeEnum; | 10 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceOperationTypeEnum; |
| 9 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; | 11 | import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData; |
| 10 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; | 12 | import com.zhonglai.luhui.device.analysis.comm.dto.ServerDto; |
| @@ -19,15 +21,20 @@ import org.slf4j.LoggerFactory; | @@ -19,15 +21,20 @@ import org.slf4j.LoggerFactory; | ||
| 19 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
| 20 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
| 21 | 23 | ||
| 24 | +import java.text.ParseException; | ||
| 22 | import java.util.*; | 25 | import java.util.*; |
| 23 | 26 | ||
| 24 | 27 | ||
| 28 | + | ||
| 25 | /** | 29 | /** |
| 26 | * 全量上报数据,不需要返回 | 30 | * 全量上报数据,不需要返回 |
| 27 | */ | 31 | */ |
| 28 | @Service("ALL_POST") | 32 | @Service("ALL_POST") |
| 29 | public class AllPostTopic implements BusinessAgreement<AllPostDto> { | 33 | public class AllPostTopic implements BusinessAgreement<AllPostDto> { |
| 30 | private static final Logger log = LoggerFactory.getLogger(AllPostTopic.class); | 34 | private static final Logger log = LoggerFactory.getLogger(AllPostTopic.class); |
| 35 | + | ||
| 36 | + private static Map<String, JSONObject> deviceTime = new HashMap<>(); | ||
| 37 | + | ||
| 31 | @Autowired | 38 | @Autowired |
| 32 | private DeviceService deviceService; | 39 | private DeviceService deviceService; |
| 33 | @Override | 40 | @Override |
| @@ -55,24 +62,25 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -55,24 +62,25 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 55 | JSONObject object = data.getData(); | 62 | JSONObject object = data.getData(); |
| 56 | if(null != object && object.size() !=0) | 63 | if(null != object && object.size() !=0) |
| 57 | { | 64 | { |
| 58 | - List<DeviceDataConfig> deviceDataConfigList = DeviceProductProtocol.deviceDataConfigList; //获取点位表配置 | ||
| 59 | - if(null != deviceDataConfigList && deviceDataConfigList.size() !=0) | 65 | + Map<String, DeviceDataConfig> deviceDataConfigMap = DeviceProductProtocol.deviceDataConfigReadMap; //获取点位表配置 |
| 66 | + if(null != deviceDataConfigMap && deviceDataConfigMap.size() !=0) | ||
| 60 | { | 67 | { |
| 61 | - for (DeviceInfo deviceInfo:deviceInfoList) | ||
| 62 | - { | ||
| 63 | - String newAlrmCode = "00"; | ||
| 64 | - for (DeviceDataConfig deviceDataConfig:deviceDataConfigList) | 68 | + analysisTime(object,deviceDataConfigMap,topic,deviceInfoList); |
| 69 | + | ||
| 70 | + for (String key : object.keySet()) | ||
| 65 | { | 71 | { |
| 66 | - String dttribute_name = deviceDataConfig.getAttribute_name(); | ||
| 67 | - if(object.containsKey(dttribute_name) && null != object.get(dttribute_name)) //点位值存在 | 72 | + if(deviceDataConfigMap.containsKey(key)) |
| 68 | { | 73 | { |
| 69 | - String dttribute_value = object.get(dttribute_name).toString(); | 74 | + String dttribute_value = object.get(key).toString(); |
| 70 | String newDataValue= ByteUtil.changerTwoStr(dttribute_value); | 75 | String newDataValue= ByteUtil.changerTwoStr(dttribute_value); |
| 71 | 76 | ||
| 77 | + DeviceDataConfig deviceDataConfig = deviceDataConfigMap.get(key); | ||
| 78 | + String newAlrmCode = "00"; | ||
| 72 | String deviceInfoId = deviceDataConfig.getDeviceInfoId(topic.getClientid()); //根据点位协议解析到设备id | 79 | String deviceInfoId = deviceDataConfig.getDeviceInfoId(topic.getClientid()); //根据点位协议解析到设备id |
| 73 | - if(deviceInfoId.equals(deviceInfo.getId()) || deviceInfoId.equals(topic.getClientid())) //点位匹配 | 80 | + DeviceInfo deviceInfo = getDeviceInfo(deviceInfoList,deviceInfoId); |
| 81 | + if(null != deviceInfo) | ||
| 74 | { | 82 | { |
| 75 | - switch (deviceDataConfig.getPlc_data_type()) | 83 | + switch (PLCDataType.valueOf(deviceDataConfig.getPlc_data_type())) |
| 76 | { | 84 | { |
| 77 | case 故障代码: | 85 | case 故障代码: |
| 78 | if(newDataValue.equals(deviceDataConfig.getAlarmValue())) | 86 | if(newDataValue.equals(deviceDataConfig.getAlarmValue())) |
| @@ -80,7 +88,137 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -80,7 +88,137 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 80 | newAlrmCode = deviceDataConfig.getAlarmCode(); | 88 | newAlrmCode = deviceDataConfig.getAlarmCode(); |
| 81 | } | 89 | } |
| 82 | break; | 90 | break; |
| 91 | + case 控制柜状态: | ||
| 92 | + analysisData(data,deviceInfo,deviceDataConfig,newDataValue,topic); | ||
| 93 | + break; | ||
| 94 | + case 校准时间: | ||
| 95 | + analysisData(data,deviceInfo,deviceDataConfig,newDataValue,topic); | ||
| 96 | + break; | ||
| 83 | default: | 97 | default: |
| 98 | + analysisData(data,deviceInfo,deviceDataConfig,newDataValue,topic); | ||
| 99 | + break; | ||
| 100 | + } | ||
| 101 | + deviceInfo.setAlarmCode(newAlrmCode); | ||
| 102 | + deviceInfo.setDataUpdateTime(DateUtils.getNowTimeMilly()); | ||
| 103 | + deviceInfo.setDeviceServiceIp(SysParameter.service_ip); | ||
| 104 | + deviceInfo.setOnline("01"); | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + return data; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + private void analysisTime( JSONObject jsonObject,Map<String, DeviceDataConfig> deviceDataConfigMap,Topic topic,List<DeviceInfo> deviceInfoList) | ||
| 116 | + { | ||
| 117 | + if(null != jsonObject && jsonObject.size() != 0) | ||
| 118 | + { | ||
| 119 | + JSONObject oldTime = deviceTime.get(topic.getClientid()); | ||
| 120 | + String imei = topic.getClientid(); | ||
| 121 | + for (int i=1;i<=4;i++) //支持定时器的排污数 | ||
| 122 | + { | ||
| 123 | + for (int j=1;j<=3;j++) //每个排污支持的定时器数据 | ||
| 124 | + { | ||
| 125 | + String start_time_attribute_name = "PW"+i+"_TS"+j; | ||
| 126 | + String end_time_attribute_name = "PW"+i+"_TE"+j; | ||
| 127 | + if(jsonObject.containsKey(start_time_attribute_name) && jsonObject.get(start_time_attribute_name) != null && jsonObject.containsKey(end_time_attribute_name) && jsonObject.get(end_time_attribute_name) != null | ||
| 128 | + &&(null == oldTime || !jsonObject.getString(start_time_attribute_name).equals(oldTime.getString(start_time_attribute_name)) || !jsonObject.getString(end_time_attribute_name).equals(oldTime.getString(end_time_attribute_name)))) //值存在并且有数据更新 | ||
| 129 | + { | ||
| 130 | + //开始时间段 | ||
| 131 | + DeviceDataConfig deviceDataConfig = deviceDataConfigMap.get(start_time_attribute_name); | ||
| 132 | + DeviceInfo deviceInfo = getDeviceInfo(deviceInfoList,imei+"_"+deviceDataConfig.getSensor_numer()); | ||
| 133 | + if(null != deviceInfo) | ||
| 134 | + { | ||
| 135 | + Integer statTime = jsonObject.getInteger(start_time_attribute_name); | ||
| 136 | + Integer endTime = jsonObject.getInteger(end_time_attribute_name); | ||
| 137 | + try { | ||
| 138 | + upDeviceTimer(topic.getClientid(),j,deviceDataConfig,deviceInfo,statTime,endTime ); | ||
| 139 | + } catch (ParseException e) { | ||
| 140 | + log.error("定时器解析错误",e); | ||
| 141 | + } | ||
| 142 | +// if(null != statTime && 0!= statTime && null != endTime && 0!= endTime) | ||
| 143 | +// { | ||
| 144 | +// | ||
| 145 | +// } | ||
| 146 | + } | ||
| 147 | + } | ||
| 148 | + jsonObject.remove(start_time_attribute_name); | ||
| 149 | + jsonObject.remove(end_time_attribute_name); | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public static String formatToTime(String timeStr) { | ||
| 157 | + | ||
| 158 | + if (timeStr.length() > 4) { | ||
| 159 | + log.error("时间格式错误"+timeStr); | ||
| 160 | + return null; | ||
| 161 | + } | ||
| 162 | + if (timeStr.length() < 4) { | ||
| 163 | + // 补零到4位,例如 "612" → "0612" | ||
| 164 | + timeStr = String.format("%04d", Integer.parseInt(timeStr)); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + String hour = timeStr.substring(0, 2); | ||
| 168 | + String minute = timeStr.substring(2, 4); | ||
| 169 | + return hour + ":" + minute; | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + private DeviceInfo getDeviceInfo(List<DeviceInfo> list,String id) | ||
| 173 | + { | ||
| 174 | + if(null != list && StringUtils.isNotEmpty(id)) | ||
| 175 | + { | ||
| 176 | + for (DeviceInfo deviceInfo:list) | ||
| 177 | + { | ||
| 178 | + if (id.equals(deviceInfo.getId())) | ||
| 179 | + { | ||
| 180 | + return deviceInfo; | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + return null; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + private void upDeviceTimer(String deviceId,Integer serialNumber,DeviceDataConfig deviceDataConfig,DeviceInfo deviceInfo,Integer statTime,Integer endTime) throws ParseException { | ||
| 188 | + String sShi = formatToTime(statTime+""); | ||
| 189 | + String eShi = formatToTime(endTime+""); | ||
| 190 | + | ||
| 191 | + DeviceTimer deviceTimer = new DeviceTimer(); | ||
| 192 | + deviceTimer.setImei(deviceId); | ||
| 193 | + deviceTimer.setNumber(deviceDataConfig.getSensor_numer()); | ||
| 194 | + deviceTimer.setSerialNumber(serialNumber); | ||
| 195 | + long totle = deviceService.getTol(deviceTimer); | ||
| 196 | + | ||
| 197 | + deviceTimer.setBaseId(deviceInfo.getBaseId()); | ||
| 198 | + deviceTimer.setCreateTime(DateUtils.getNowTimeMilly()); | ||
| 199 | + deviceTimer.setUserId(deviceInfo.getUserId()); | ||
| 200 | + deviceTimer.setUserLogin(deviceInfo.getUserLoginName()); | ||
| 201 | + deviceTimer.setBaseName(deviceInfo.getBaseName()); | ||
| 202 | + deviceTimer.setDeviceName(deviceInfo.getDeviceName()); | ||
| 203 | + | ||
| 204 | + deviceTimer.setStartTime((int) ((DateUtils.parseDate(DateUtils.dateTimeNow("yyyy-MM-dd")+" "+sShi+":00", DateUtils.YYYY_MM_DD_HH_MM_SS).getTime())/1000)); | ||
| 205 | + deviceTimer.setEndTime((int) ((DateUtils.parseDate(DateUtils.dateTimeNow("yyyy-MM-dd")+" "+eShi+":00", DateUtils.YYYY_MM_DD_HH_MM_SS).getTime())/1000)); | ||
| 206 | + | ||
| 207 | + | ||
| 208 | + if(totle>0) | ||
| 209 | + { | ||
| 210 | + deviceService.getBaseDao().updateBySql("update `runing_fish`.`device_timer` set base_id="+deviceTimer.getBaseId()+ | ||
| 211 | + ",user_id="+deviceTimer.getUserId()+",user_login='"+deviceTimer.getUserLogin()+ | ||
| 212 | + "',base_name='"+deviceTimer.getBaseName()+"',device_name='"+deviceTimer.getDeviceName()+ | ||
| 213 | + "' where imei='"+deviceTimer.getImei()+"' and number='"+deviceTimer.getNumber()+"' and serial_number="+deviceTimer.getSerialNumber() | ||
| 214 | + ); | ||
| 215 | + }else{ | ||
| 216 | + deviceService.getBaseDao().insert(deviceTimer); | ||
| 217 | + } | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + private void analysisData(AllPostDto data,DeviceInfo deviceInfo,DeviceDataConfig deviceDataConfig,String newDataValue,Topic topic) | ||
| 221 | + { | ||
| 84 | String dataValue = deviceInfo.getDataValue(); | 222 | String dataValue = deviceInfo.getDataValue(); |
| 85 | JSONObject jsonObject = new JSONObject(); | 223 | JSONObject jsonObject = new JSONObject(); |
| 86 | 224 | ||
| @@ -88,11 +226,11 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -88,11 +226,11 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 88 | { | 226 | { |
| 89 | jsonObject = GsonConstructor.get().fromJson(dataValue,JSONObject.class); | 227 | jsonObject = GsonConstructor.get().fromJson(dataValue,JSONObject.class); |
| 90 | } | 228 | } |
| 91 | - String odlDataValue = (String) jsonObject.get(deviceDataConfig.getPlc_data_type().sensorDataType); | 229 | + String odlDataValue = (String) jsonObject.get(PLCDataType.valueOf(deviceDataConfig.getPlc_data_type()).sensorDataType); |
| 92 | if(!newDataValue.equals(odlDataValue)) | 230 | if(!newDataValue.equals(odlDataValue)) |
| 93 | { | 231 | { |
| 94 | - jsonObject.put(deviceDataConfig.getPlc_data_type().sensorDataType,newDataValue); //更新数据 | ||
| 95 | - if(deviceDataConfig.getPlc_data_type().sensorDataType.equals("104")) | 232 | + jsonObject.put(PLCDataType.valueOf(deviceDataConfig.getPlc_data_type()).sensorDataType,newDataValue); //更新数据 |
| 233 | + if(PLCDataType.valueOf(deviceDataConfig.getPlc_data_type()).sensorDataType.equals("104")) | ||
| 96 | { | 234 | { |
| 97 | jsonObject.put("9",newDataValue); //更新数据 | 235 | jsonObject.put("9",newDataValue); //更新数据 |
| 98 | } | 236 | } |
| @@ -102,25 +240,12 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -102,25 +240,12 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 102 | //记录日志 | 240 | //记录日志 |
| 103 | if(null != deviceDataConfig.getDevice_type()) | 241 | if(null != deviceDataConfig.getDevice_type()) |
| 104 | { | 242 | { |
| 105 | - describe = deviceDataConfig.getSensor_numer()+deviceDataConfig.getDevice_type().name()+describe; | 243 | + describe = deviceDataConfig.getSensor_numer()+deviceDataConfig.getDevice_type()+describe; |
| 106 | } | 244 | } |
| 107 | data.getLogDeviceOperationList().add(addLogDeviceOperation(topic.getClientid(),deviceDataConfig.getSensor_numer(),null,describe,newDataValue,odlDataValue,1)); | 245 | data.getLogDeviceOperationList().add(addLogDeviceOperation(topic.getClientid(),deviceDataConfig.getSensor_numer(),null,describe,newDataValue,odlDataValue,1)); |
| 108 | } | 246 | } |
| 109 | - break; | ||
| 110 | - } | ||
| 111 | - } | ||
| 112 | - } | ||
| 113 | - } | ||
| 114 | - deviceInfo.setAlarmCode(newAlrmCode); | ||
| 115 | - deviceInfo.setDataUpdateTime(DateUtils.getNowTimeMilly()); | ||
| 116 | - deviceInfo.setDeviceServiceIp(SysParameter.service_ip); | ||
| 117 | - deviceInfo.setOnline("01"); | ||
| 118 | - } | ||
| 119 | - } | ||
| 120 | - } | ||
| 121 | - return data; | ||
| 122 | - } | ||
| 123 | 247 | ||
| 248 | + } | ||
| 124 | @Override | 249 | @Override |
| 125 | public AllPostDto toData(BusinessDto data) { | 250 | public AllPostDto toData(BusinessDto data) { |
| 126 | AllPostDto serverDto = new AllPostDto(); | 251 | AllPostDto serverDto = new AllPostDto(); |
| @@ -141,6 +266,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -141,6 +266,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 141 | } | 266 | } |
| 142 | 267 | ||
| 143 | 268 | ||
| 269 | + | ||
| 144 | /** | 270 | /** |
| 145 | * 添加设备操作日志记录 | 271 | * 添加设备操作日志记录 |
| 146 | * @param deviceId 设备imei | 272 | * @param deviceId 设备imei |
-
请 注册 或 登录 后发表评论