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

红外、联动修改

上级 7e367888
package tech.glinfo.enbao.modules.infrared.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
......@@ -29,7 +28,6 @@ import tech.glinfo.enbao.modules.sh.service.ShDeviceService;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -98,12 +96,11 @@ public class InfraredControlController {
@ApiLog("查询用户遥控器")
public R list(@RequestParam Map<String, Object> params, @LoginUser AppUserEntity user) {
String deviceId = (String) params.get("deviceId");
if (StringUtils.isNotBlank(deviceId)) {
return R.ok().put("list", otherInfraredControlService.list(new QueryWrapper<InfraredControlEntity>().eq("device_id", deviceId)));
if (StringUtils.isNotBlank(deviceId)) {
return otherInfraredControlService.list(Integer.valueOf(deviceId), user.getId());
}else {
return R.ok().put("list", otherInfraredControlService.list(new QueryWrapper<InfraredControlEntity>().eq("user_id", user.getId())));
return otherInfraredControlService.list(null, user.getId());
}
}
......
package tech.glinfo.enbao.modules.infrared.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import tech.glinfo.enbao.modules.infrared.entity.InfraredControlEntity;
import java.util.List;
import java.util.Map;
/**
* 用户遥控器
*
* @author linyetong
* @email linyetong@glinfo.com
* @date 2022-02-23 10:03:36
*/
@Mapper
public interface OtherInfraredControlDao extends BaseMapper<InfraredControlEntity> {
@Select("<script>" +
"SELECT a.id, a.device_id deviceId, a.user_id userId, a.device_type deviceType," +
" a.rtype, a.brand, a.model, a.remark, c.name roomName FROM infrared_control a, sh_device b LEFT JOIN sh_family_room c ON b.room_id = c.id WHERE a.device_id = b.id AND" +
"<choose>" +
" <when test='deviceId != null'>" +
" a.device_id = ${deviceId}" +
" </when>" +
" <otherwise>" +
" a.user_id = ${userId}" +
" </otherwise>" +
" </choose>" +
" </script>")
List<Map<String, Object>> list(Integer deviceId, Integer userId);
}
package tech.glinfo.enbao.modules.infrared.service;
import com.baomidou.mybatisplus.extension.service.IService;
import tech.glinfo.enbao.common.utils.R;
import tech.glinfo.enbao.modules.infrared.entity.InfraredControlEntity;
/**
......@@ -12,6 +13,8 @@ import tech.glinfo.enbao.modules.infrared.entity.InfraredControlEntity;
*/
public interface OtherInfraredControlService extends IService<InfraredControlEntity> {
R list(Integer deviceId, Integer userId);
void saveInfraredCode(String deviceType, String model, Integer deviceId, String rtype);
void deleteInfraredCode(Integer deviceId, String deviceType);
......
......@@ -9,11 +9,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.glinfo.enbao.common.contants.AppContants;
import tech.glinfo.enbao.common.utils.ByteUtils;
import tech.glinfo.enbao.common.utils.HttpUtil;
import tech.glinfo.enbao.common.utils.RedisUtils;
import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.common.utils.*;
import tech.glinfo.enbao.modules.infrared.dao.InfraredControlDao;
import tech.glinfo.enbao.modules.infrared.dao.OtherInfraredControlDao;
import tech.glinfo.enbao.modules.infrared.entity.InfraredControlEntity;
import tech.glinfo.enbao.modules.infrared.service.OtherInfraredControlService;
import tech.glinfo.enbao.modules.infrared.util.ProtocolUtil;
......@@ -21,9 +19,12 @@ import tech.glinfo.enbao.modules.sh.entity.ShDeviceEntity;
import tech.glinfo.enbao.modules.sh.form.ProtocolContent;
import tech.glinfo.enbao.modules.sh.service.ShDeviceService;
import java.util.List;
import java.util.Map;
@Service("otherInfraredControlService")
public class OtherInfraredControlServiceImpl extends ServiceImpl<InfraredControlDao, InfraredControlEntity> implements OtherInfraredControlService {
public class OtherInfraredControlServiceImpl extends ServiceImpl<OtherInfraredControlDao, InfraredControlEntity> implements OtherInfraredControlService {
private final static Logger logger = LoggerFactory.getLogger(OtherInfraredControlServiceImpl.class);
......@@ -36,6 +37,12 @@ public class OtherInfraredControlServiceImpl extends ServiceImpl<InfraredControl
private RedisUtils redisUtils;
@Override
public R list(Integer deviceId, Integer userId) {
List<Map<String, Object>> list = this.baseMapper.list(deviceId, userId);
return R.ok().put("list", list);
}
@Override
public void saveInfraredCode(String deviceType, String model, Integer deviceId, String rtype) {
//电视==电视是根据按键索引来获取红外数据
......
......@@ -308,7 +308,7 @@ public class FaceLockParse implements IParse {
private void sendCmd(Integer id) {
String sss = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm");
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id);
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id, null, null);
if (dlinkEntity != null) {
String key = "device:dlink:" + dlinkEntity.getStart() + "-" + dlinkEntity.getEnd() + ":" + dlinkEntity.getDeviceId();
String json = redisUtils.get(key);
......
......@@ -323,7 +323,7 @@ public class LockParse implements IParse {
private void sendCmd(Integer id) {
String sss = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm");
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id);
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id, null, null);
if (dlinkEntity != null) {
String key = "device:dlink:" + dlinkEntity.getStart() + "-" + dlinkEntity.getEnd() + ":" + dlinkEntity.getDeviceId();
String json = redisUtils.get(key);
......
......@@ -11,14 +11,9 @@ 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.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.ShInstructionParsingEntity;
import tech.glinfo.enbao.modules.sh.service.OtherShDevicePowerService;
import tech.glinfo.enbao.modules.sh.service.OtherShDeviceService;
import tech.glinfo.enbao.modules.sh.service.ShDeviceDataService;
import tech.glinfo.enbao.modules.sh.service.ShDeviceRecordService;
import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.modules.sh.entity.*;
import tech.glinfo.enbao.modules.sh.service.*;
import java.util.Date;
import java.util.HashMap;
......@@ -53,6 +48,9 @@ public class OutletParse 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;
......@@ -120,43 +118,12 @@ public class OutletParse implements IParse {
ws.put("power", power);*/
}else if("18".equals(datas.get("cmd"))) {//开关响应
redisUtils.delete(device.getNumbering() + "cf");
logger.info("已删除重复 : {}", redisUtils.hasKey(device.getNumbering() + "cf"));
String content = datas.get("content");
//开关状态
/* if (content.equals("00")) {
//保存开关记录
String action = redisUtils.get(datas.get("receiveId") + "action");
if (action != null) {
ShDeviceRecordEntity recordEntity = new ShDeviceRecordEntity();
recordEntity.setDeviceId(device.getId());
recordEntity.setAction(action.equals("01") ? 1 : 2);
shDeviceRecordService.save(recordEntity);
redisUtils.delete(datas.get("receiveId") + "action");
}
}*/
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("highTemp", ByteUtils.signHex2IntString(content1.substring(0, 2)));
jsonObj.put("highTempStatus", ByteUtils.signHex2IntString(content1.substring(2, 4)));
jsonObj.put("lowTemp", ByteUtils.signHex2IntString(content1.substring(4, 6)));
jsonObj.put("lowTempStatus", ByteUtils.signHex2IntString(content1.substring(6, 8)));
entity.setValue(jsonObj.toString());
shDeviceDataService.updateById(entity);
}
}
}
redisUtils.delete(device.getNumbering() + "temp");*/
}else if("20".equals(datas.get("cmd"))) {//事件上报
//保存开关记录
String content = datas.get("content");
......@@ -165,7 +132,7 @@ public class OutletParse implements IParse {
recordEntity.setDeviceId(device.getId());
recordEntity.setAction(action.equals("01") ? 1 : 2);
shDeviceRecordService.save(recordEntity);
sendCmd(device.getId(), action.equals("01") ? "1" : "2");
}
new Thread(() -> {
//检测有没待下发指令
......@@ -195,5 +162,19 @@ public class OutletParse implements IParse {
return ws;
}
private void sendCmd(Integer id, String statusO) {
String sss = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm");
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id, statusO, null);
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);
}
}
}
}
}
......@@ -181,7 +181,7 @@ public class SmartLockParse implements IParse {
private void sendCmd(Integer id) {
String sss = DateUtils.format(new Date(), "yyyy-MM-dd HH:mm");
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id);
ShDlinkEntity dlinkEntity = otherShDlinkService.checkTime(sss.substring(sss.length()-5), id, null, null);
if (dlinkEntity != null) {
String key = "device:dlink:" + dlinkEntity.getStart() + "-" + dlinkEntity.getEnd() + ":" + dlinkEntity.getDeviceId();
String json = redisUtils.get(key);
......
......@@ -18,10 +18,16 @@ public interface OtherShDlinkDao extends BaseMapper<ShDlinkEntity> {
@Select("<script>" +
" SELECT * FROM sh_dlink a WHERE a.device_id = ${deviceId} AND #{time} between a.`start` and a.`end` AND a.status = 1 LIMIT 1"
+
" SELECT * FROM sh_dlink a WHERE a.device_id = ${deviceId} AND #{time} between a.`start` and a.`end` AND a.status = 1"
+ " <if test='statusO != null and statusO != \"\"' > "
+ " and a.status_o = #{statusO}"
+ " </if>"
+ " <if test='statusT != null and statusT != \"\"' > "
+ " and a.status_t = #{statusT}"
+ " </if>" +
" LIMIT 1" +
" </script>")
ShDlinkEntity checkTime(String time, Integer deviceId);
ShDlinkEntity checkTime(String time, Integer deviceId, String statusO, String statusT);
@Select("<script>" +
" SELECT b.id, b.name, b.numbering, b.numbering_flag numberingFlag FROM sh_dlink_device a, sh_device b WHERE a.device_id = b.id AND a.dlink_id = ${id}"
......
......@@ -17,7 +17,7 @@ public interface OtherShDlinkService extends IService<ShDlinkEntity> {
R info(Integer id);
ShDlinkEntity checkTime(String time, Integer deviceId);
ShDlinkEntity checkTime(String time, Integer deviceId, String statusO, String statusT);
R list(Integer userId);
......
......@@ -119,8 +119,8 @@ public class OtherShDlinkServiceImpl extends ServiceImpl<OtherShDlinkDao, ShDlin
}
@Override
public ShDlinkEntity checkTime(String time, Integer deviceId) {
return this.baseMapper.checkTime(time, deviceId);
public ShDlinkEntity checkTime(String time, Integer deviceId, String statusO, String statusT) {
return this.baseMapper.checkTime(time, deviceId, statusO, statusT);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论