提交 ab884fc5 authored 作者: 林业通's avatar 林业通

开关修改

上级 10bd1004
......@@ -137,16 +137,17 @@ public class MqConsumer {
map1.put("status", "2");
mapList.add(map1);
jmsTemplate.convertAndSend(socketioTopic, JSON.toJSONString(new MapUtils().put("deviceId", "onlineStatus").put("list", JSON.toJSONString(mapList))));
//更新设备状态为在线
new Thread(() -> {
ShDeviceEntity deviceEntity = new ShDeviceEntity();
deviceEntity.setId(device.getId());
deviceEntity.setOnlineStatus(2);
deviceEntity.setOnlineTime(new Date());
otherShDeviceService.updateById(deviceEntity);
}).start();
}
//更新设备状态为在线
new Thread(() -> {
ShDeviceEntity deviceEntity = new ShDeviceEntity();
deviceEntity.setId(device.getId());
deviceEntity.setOnlineStatus(2);
deviceEntity.setOnlineTime(new Date());
otherShDeviceService.updateById(deviceEntity);
}).start();
String sendMessage = null;
Map<String, String> ws = null;
// redisUtils.get(Constants.PARSE_CLASS + datas.get("deviceType"));
......
......@@ -2,25 +2,23 @@ package tech.glinfo.enbao.modules.mq;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.glinfo.enbao.common.utils.ByteUtils;
import tech.glinfo.enbao.common.utils.DateUtils;
import tech.glinfo.enbao.common.utils.RedisUtils;
import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.modules.sh.entity.ShDeviceDataEntity;
import tech.glinfo.enbao.modules.sh.entity.ShDeviceEntity;
import tech.glinfo.enbao.modules.sh.entity.ShDeviceRecordEntity;
import tech.glinfo.enbao.modules.sh.entity.ShDlinkEntity;
import tech.glinfo.enbao.modules.sh.entity.ShInstructionParsingEntity;
import tech.glinfo.enbao.modules.sh.service.*;
import tech.glinfo.enbao.modules.sh.service.OtherShDeviceService;
import tech.glinfo.enbao.modules.sh.service.OtherShDlinkService;
import tech.glinfo.enbao.modules.sh.service.ShDeviceRecordService;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
//智能开关
@Component("switchParse")
......@@ -34,9 +32,6 @@ public class SwitchParse implements IParse {
@Autowired
private ShDeviceRecordService shDeviceRecordService;
@Autowired
private ShDeviceDataService shDeviceDataService;
@Autowired
private RedisUtils redisUtils;
......@@ -46,6 +41,9 @@ public class SwitchParse implements IParse {
@Autowired
private MqProducer mqProducer;
@Autowired
private OtherShDlinkService otherShDlinkService;
@Override
public Map<String, String> run(Object o, Map<String, String> datas) {
ShDeviceEntity device = (ShDeviceEntity) o;
......@@ -107,75 +105,70 @@ public class SwitchParse implements IParse {
}else if("18".equals(datas.get("cmd"))) {//开关响应
String content = datas.get("content");
logger.info("开关响应 : {}", content);
//开关状态
/*if (content.equals("00")) {
//保存开关记录
logger.info("receiveId : {}", datas.get("receiveId"));
String action = redisUtils.get(datas.get("receiveId") + "action1");
String action2 = redisUtils.get(datas.get("receiveId") + "action2");
if (StringUtils.isNotBlank(action)) {
ws.put("action", content);
}else if("20".equals(datas.get("cmd"))) {//事件上报
//保存开关记录
String content = datas.get("content");
String type = content.substring(2, 4);
String action1 = content.substring(6, 8);
String action2 = content.substring(8, 10);
switch (type) {
case "01": {
ShDeviceRecordEntity recordEntity = new ShDeviceRecordEntity();
recordEntity.setDeviceId(device.getId());
recordEntity.setAction(Integer.parseInt(action));
//开关1 1:开 2:关
recordEntity.setAction(action1.equals("01") ? 1 : 2);
shDeviceRecordService.save(recordEntity);
redisUtils.delete(datas.get("receiveId") + "action1");
break;
}
if (StringUtils.isNotBlank(action2)) {
case "02": {
ShDeviceRecordEntity recordEntity = new ShDeviceRecordEntity();
recordEntity.setDeviceId(device.getId());
recordEntity.setAction(Integer.parseInt(action2));
//开关2 3:开 4:关
recordEntity.setAction(action2.equals("01") ? 3 : 4);
shDeviceRecordService.save(recordEntity);
redisUtils.delete(datas.get("receiveId") + "action2");
break;
}
case "03": {
Date date = new Date();
ShDeviceRecordEntity recordEntity = new ShDeviceRecordEntity();
recordEntity.setDeviceId(device.getId());
//开关1 1:开 2:关
recordEntity.setAction(action1.equals("01") ? 1 : 2);
recordEntity.setCreateTime(date);
shDeviceRecordService.save(recordEntity);
}*/
ws.put("action", content);
}else if("1A".equals(datas.get("cmd"))) {//温控响应
String content = datas.get("content");
logger.info("设置温控响应 : {}", content);
/* String content1 = redisUtils.get(device.getNumbering() + "temp");
//设备响应成功之后修改数据,不用等30秒,页面体验好些
if ("00".equals(content)) {
if (content1 != null) {
ShDeviceDataEntity entity = shDeviceDataService.getOne(new QueryWrapper<ShDeviceDataEntity>().eq("device_id", device.getId()));
if (entity != null) {
JSONObject jsonObj = new JSONObject(entity.getValue());
jsonObj.put("highTemp1", ByteUtils.signHex2IntString(content1.substring(0, 2)));
jsonObj.put("highTempStatus1", ByteUtils.signHex2IntString(content1.substring(2, 4)));
jsonObj.put("lowTemp1", ByteUtils.signHex2IntString(content1.substring(4, 6)));
jsonObj.put("lowTempStatus1", ByteUtils.signHex2IntString(content1.substring(6, 8)));
jsonObj.put("highTemp2", ByteUtils.signHex2IntString(content1.substring(8, 10)));
jsonObj.put("highTempStatus2", ByteUtils.signHex2IntString(content1.substring(10, 12)));
jsonObj.put("lowTemp2", ByteUtils.signHex2IntString(content1.substring(12, 14)));
jsonObj.put("lowTempStatus2", ByteUtils.signHex2IntString(content1.substring(14, 16)));
entity.setValue(jsonObj.toString());
shDeviceDataService.updateById(entity);
}
ShDeviceRecordEntity recordEntity1 = new ShDeviceRecordEntity();
recordEntity1.setDeviceId(device.getId());
//开关2 3:开 4:关
recordEntity1.setAction(action2.equals("01") ? 3 : 4);
recordEntity1.setCreateTime(date);
shDeviceRecordService.save(recordEntity1);
break;
}
}
redisUtils.delete(device.getNumbering() + "temp");*/
}else if("20".equals(datas.get("cmd"))) {//事件上报
//保存开关记录
String content = datas.get("content");
String type = content.substring(2, 4);
String action = content.substring(6, 8);
ShDeviceRecordEntity recordEntity = new ShDeviceRecordEntity();
recordEntity.setDeviceId(device.getId());
if (type.equals("01")) {
//开关1 1:开 2:关
recordEntity.setAction(action.equals("01") ? 1 : 2);
}else {
//开关2 3:开 4:关
recordEntity.setAction(action.equals("01") ? 3 : 4);
}
shDeviceRecordService.save(recordEntity);
sendCmd(device.getId(), action1.equals("01") ? "1" : "2", action2.equals("01") ? "1" : "2");
}
return ws;
}
private void sendCmd(Integer id, String statusO, String statusT) {
String sss = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm");
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id, statusO, statusT);
if (dlinkEntity != null) {
String key = "device:dlink:" + dlinkEntity.getStart() + "-" + dlinkEntity.getEnd() + ":" + dlinkEntity.getDeviceId();
String json = redisUtils.get(key);
logger.info("场景找到1" + json);
if (StringUtils.isNotBlank(json)) {
for (String s : json.split("-")) {
logger.info("场景找到2" + s);
mqProducer.sendT(s);
}
}
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论