正在显示
1 个修改的文件
包含
53 行增加
和
1 行删除
| 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.JSON; | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 4 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.google.gson.JsonObject; | 5 | import com.google.gson.JsonObject; |
| 5 | import com.ruoyi.common.utils.DateUtils; | 6 | import com.ruoyi.common.utils.DateUtils; |
| @@ -14,8 +15,12 @@ import com.zhonglai.luhui.device.analysis.comm.dto.business.BusinessDto; | @@ -14,8 +15,12 @@ import com.zhonglai.luhui.device.analysis.comm.dto.business.BusinessDto; | ||
| 14 | import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreement; | 15 | import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreement; |
| 15 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; | 16 | import com.zhonglai.luhui.device.analysis.comm.factory.Topic; |
| 16 | import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; | 17 | import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil; |
| 18 | +import com.zhonglai.luhui.device.analysis.dto.Message; | ||
| 17 | import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService; | 19 | import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService; |
| 18 | import com.zhonglai.luhui.lsy.plc.service.dto.*; | 20 | import com.zhonglai.luhui.lsy.plc.service.dto.*; |
| 21 | +import com.zhonglai.luhui.lsy.plc.service.service.ClienNoticeService; | ||
| 22 | +import org.eclipse.paho.client.mqttv3.MqttException; | ||
| 23 | +import org.eclipse.paho.client.mqttv3.MqttMessage; | ||
| 19 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
| 20 | import org.slf4j.LoggerFactory; | 25 | import org.slf4j.LoggerFactory; |
| 21 | import org.springframework.beans.factory.annotation.Autowired; | 26 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -23,7 +28,8 @@ import org.springframework.stereotype.Service; | @@ -23,7 +28,8 @@ import org.springframework.stereotype.Service; | ||
| 23 | 28 | ||
| 24 | import java.text.ParseException; | 29 | import java.text.ParseException; |
| 25 | import java.util.*; | 30 | import java.util.*; |
| 26 | - | 31 | +import java.util.regex.Matcher; |
| 32 | +import java.util.regex.Pattern; | ||
| 27 | 33 | ||
| 28 | 34 | ||
| 29 | /** | 35 | /** |
| @@ -37,6 +43,8 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -37,6 +43,8 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 37 | 43 | ||
| 38 | @Autowired | 44 | @Autowired |
| 39 | private DeviceService deviceService; | 45 | private DeviceService deviceService; |
| 46 | + @Autowired | ||
| 47 | + private ClienNoticeService clienNoticeService; | ||
| 40 | @Override | 48 | @Override |
| 41 | public ServerDto analysis(Topic topic, AllPostDto data) throws Exception { | 49 | public ServerDto analysis(Topic topic, AllPostDto data) throws Exception { |
| 42 | 50 | ||
| @@ -65,6 +73,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -65,6 +73,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 65 | Map<String, DeviceDataConfig> deviceDataConfigMap = DeviceProductProtocol.deviceDataConfigReadMap; //获取点位表配置 | 73 | Map<String, DeviceDataConfig> deviceDataConfigMap = DeviceProductProtocol.deviceDataConfigReadMap; //获取点位表配置 |
| 66 | if(null != deviceDataConfigMap && deviceDataConfigMap.size() !=0) | 74 | if(null != deviceDataConfigMap && deviceDataConfigMap.size() !=0) |
| 67 | { | 75 | { |
| 76 | + analysisTimePWZX(object,topic); | ||
| 68 | analysisTime(object,deviceDataConfigMap,topic,deviceInfoList); | 77 | analysisTime(object,deviceDataConfigMap,topic,deviceInfoList); |
| 69 | 78 | ||
| 70 | for (String key : object.keySet()) | 79 | for (String key : object.keySet()) |
| @@ -137,6 +146,49 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | @@ -137,6 +146,49 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> { | ||
| 137 | // log.info("设备信息{}",deviceInfo); | 146 | // log.info("设备信息{}",deviceInfo); |
| 138 | } | 147 | } |
| 139 | } | 148 | } |
| 149 | + private void analysisTimePWZX( JSONObject jsonObject,Topic topic) | ||
| 150 | + { | ||
| 151 | + if(null != jsonObject && jsonObject.size() != 0) | ||
| 152 | + { | ||
| 153 | + JSONObject object = new JSONObject(); | ||
| 154 | + for (String key:jsonObject.keySet()) | ||
| 155 | + { | ||
| 156 | + if(key.startsWith("PW") && key.endsWith("ZX")) | ||
| 157 | + { | ||
| 158 | + if(jsonObject.getInteger(key)==1) | ||
| 159 | + { | ||
| 160 | + Integer number = extractNumberIfMatch(key); | ||
| 161 | + if (number != null) { | ||
| 162 | + String fjbh = String.valueOf((char) ('A' + number - 1)); | ||
| 163 | + object.put("YC_STP_C001"+fjbh,0); | ||
| 164 | + } | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + log.info("定时推水状态{}",object); | ||
| 170 | + if (!object.isEmpty()) | ||
| 171 | + { | ||
| 172 | + MqttMessage mqttMessage = new MqttMessage(); | ||
| 173 | + mqttMessage.setPayload(object.toJSONString().trim().getBytes()); | ||
| 174 | + try { | ||
| 175 | + Topic sentopic = new Topic("2",topic.getUsername(),topic.getClientid(),"PUT",null); | ||
| 176 | + clienNoticeService.sendMessage(sentopic,mqttMessage); | ||
| 177 | + } catch (Exception e) { | ||
| 178 | + log.error("传回定时推水状态消息失败",e); | ||
| 179 | + } | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + public static Integer extractNumberIfMatch(String key) { | ||
| 185 | + Pattern pattern = Pattern.compile("^PW(\\d+)_ZX$"); | ||
| 186 | + Matcher matcher = pattern.matcher(key); | ||
| 187 | + if (matcher.matches()) { | ||
| 188 | + return Integer.parseInt(matcher.group(1)); | ||
| 189 | + } | ||
| 190 | + return null; | ||
| 191 | + } | ||
| 140 | private void analysisTime( JSONObject jsonObject,Map<String, DeviceDataConfig> deviceDataConfigMap,Topic topic,List<DeviceInfo> deviceInfoList) | 192 | private void analysisTime( JSONObject jsonObject,Map<String, DeviceDataConfig> deviceDataConfigMap,Topic topic,List<DeviceInfo> deviceInfoList) |
| 141 | { | 193 | { |
| 142 | if(null != jsonObject && jsonObject.size() != 0) | 194 | if(null != jsonObject && jsonObject.size() != 0) |
-
请 注册 或 登录 后发表评论