作者 钟来

plc004支持定时功能

package com.zhonglai.luhui.lsy.plc.service.service.topic;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.ruoyi.common.utils.DateUtils;
... ... @@ -14,8 +15,12 @@ import com.zhonglai.luhui.device.analysis.comm.dto.business.BusinessDto;
import com.zhonglai.luhui.device.analysis.comm.factory.BusinessAgreement;
import com.zhonglai.luhui.device.analysis.comm.factory.Topic;
import com.zhonglai.luhui.device.analysis.comm.util.ByteUtil;
import com.zhonglai.luhui.device.analysis.dto.Message;
import com.zhonglai.luhui.lsy.plc.service.comm.service.DeviceService;
import com.zhonglai.luhui.lsy.plc.service.dto.*;
import com.zhonglai.luhui.lsy.plc.service.service.ClienNoticeService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -23,7 +28,8 @@ import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
... ... @@ -37,6 +43,8 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> {
@Autowired
private DeviceService deviceService;
@Autowired
private ClienNoticeService clienNoticeService;
@Override
public ServerDto analysis(Topic topic, AllPostDto data) throws Exception {
... ... @@ -65,6 +73,7 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> {
Map<String, DeviceDataConfig> deviceDataConfigMap = DeviceProductProtocol.deviceDataConfigReadMap; //获取点位表配置
if(null != deviceDataConfigMap && deviceDataConfigMap.size() !=0)
{
analysisTimePWZX(object,topic);
analysisTime(object,deviceDataConfigMap,topic,deviceInfoList);
for (String key : object.keySet())
... ... @@ -137,6 +146,49 @@ public class AllPostTopic implements BusinessAgreement<AllPostDto> {
// log.info("设备信息{}",deviceInfo);
}
}
private void analysisTimePWZX( JSONObject jsonObject,Topic topic)
{
if(null != jsonObject && jsonObject.size() != 0)
{
JSONObject object = new JSONObject();
for (String key:jsonObject.keySet())
{
if(key.startsWith("PW") && key.endsWith("ZX"))
{
if(jsonObject.getInteger(key)==1)
{
Integer number = extractNumberIfMatch(key);
if (number != null) {
String fjbh = String.valueOf((char) ('A' + number - 1));
object.put("YC_STP_C001"+fjbh,0);
}
}
}
}
log.info("定时推水状态{}",object);
if (!object.isEmpty())
{
MqttMessage mqttMessage = new MqttMessage();
mqttMessage.setPayload(object.toJSONString().trim().getBytes());
try {
Topic sentopic = new Topic("2",topic.getUsername(),topic.getClientid(),"PUT",null);
clienNoticeService.sendMessage(sentopic,mqttMessage);
} catch (Exception e) {
log.error("传回定时推水状态消息失败",e);
}
}
}
}
public static Integer extractNumberIfMatch(String key) {
Pattern pattern = Pattern.compile("^PW(\\d+)_ZX$");
Matcher matcher = pattern.matcher(key);
if (matcher.matches()) {
return Integer.parseInt(matcher.group(1));
}
return null;
}
private void analysisTime( JSONObject jsonObject,Map<String, DeviceDataConfig> deviceDataConfigMap,Topic topic,List<DeviceInfo> deviceInfoList)
{
if(null != jsonObject && jsonObject.size() != 0)
... ...