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

红外遥控

上级 2342f7dd
package tech.glinfo.enbao.modules.infrared.controller; package tech.glinfo.enbao.modules.infrared.controller;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -11,6 +12,7 @@ import org.springframework.web.bind.annotation.*;
import tech.glinfo.enbao.common.annotation.ApiLog; import tech.glinfo.enbao.common.annotation.ApiLog;
import tech.glinfo.enbao.common.annotation.Login; import tech.glinfo.enbao.common.annotation.Login;
import tech.glinfo.enbao.common.annotation.LoginUser; import tech.glinfo.enbao.common.annotation.LoginUser;
import tech.glinfo.enbao.common.utils.ByteUtils;
import tech.glinfo.enbao.common.utils.MapUtils; import tech.glinfo.enbao.common.utils.MapUtils;
import tech.glinfo.enbao.common.utils.R; import tech.glinfo.enbao.common.utils.R;
import tech.glinfo.enbao.common.utils.StringUtils; import tech.glinfo.enbao.common.utils.StringUtils;
...@@ -19,8 +21,15 @@ import tech.glinfo.enbao.modules.appuser.entity.AppUserEntity; ...@@ -19,8 +21,15 @@ import tech.glinfo.enbao.modules.appuser.entity.AppUserEntity;
import tech.glinfo.enbao.modules.infrared.entity.InfraredControlEntity; import tech.glinfo.enbao.modules.infrared.entity.InfraredControlEntity;
import tech.glinfo.enbao.modules.infrared.form.InfraredControlForm; import tech.glinfo.enbao.modules.infrared.form.InfraredControlForm;
import tech.glinfo.enbao.modules.infrared.service.OtherInfraredControlService; import tech.glinfo.enbao.modules.infrared.service.OtherInfraredControlService;
import tech.glinfo.enbao.modules.infrared.util.ProtocolUtil;
import tech.glinfo.enbao.modules.mq.MqProducer;
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.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -41,6 +50,48 @@ public class InfraredControlController { ...@@ -41,6 +50,48 @@ public class InfraredControlController {
@Autowired @Autowired
private OtherInfraredControlService otherInfraredControlService; private OtherInfraredControlService otherInfraredControlService;
@Autowired
private ShDeviceService shDeviceService;
@Autowired
private MqProducer mqProducer;
private static Map<String, String> temp = new HashMap<>();
static {
temp.put("17", "0000");
temp.put("18", "0001");
temp.put("19", "0011");
temp.put("20", "0010");
temp.put("21", "0110");
temp.put("22", "0111");
temp.put("23", "0101");
temp.put("24", "0100");
temp.put("25", "1100");
temp.put("26", "1101");
temp.put("27", "1001");
temp.put("28", "1000");
temp.put("29", "1010");
temp.put("30", "1011");
}
private static Map<String, String> model = new HashMap<>();
static {
model.put("自动", "10");
model.put("制冷", "00");
model.put("抽湿", "01");
model.put("制热", "11");
model.put("送风", "01");
}
private static Map<String, String> wind = new HashMap<>();
static {
wind.put("自动", "101");
wind.put("低风", "100");
wind.put("中风", "010");
wind.put("高风", "001");
wind.put("固定风", "000");
}
@Login @Login
@GetMapping("list") @GetMapping("list")
@ApiOperation("查询用户遥控器") @ApiOperation("查询用户遥控器")
...@@ -128,4 +179,62 @@ public class InfraredControlController { ...@@ -128,4 +179,62 @@ public class InfraredControlController {
return otherInfraredControlService.removeById(id)? R.ok() : R.error("删除失败"); return otherInfraredControlService.removeById(id)? R.ok() : R.error("删除失败");
} }
@Login
@PostMapping("controllerT")
public R controllerT(@RequestBody Map<String, Object> params) {
String frequency = (String) params.get("frequency");//频率
String datas = (String) params.get("datas");//数据
Integer deviceId = (Integer) params.get("deviceId");//设备Id
if(StringUtils.isBlank(frequency, datas, deviceId)) {
return R.error("缺少参数");
}
ShDeviceEntity device = shDeviceService.getById(deviceId);
if(device == null) {
return R.error("设备不存在,请核实!");
}
if(device.getOnlineStatus() != 2) {
return R.error("设备离线,无法发送!");
}
//转换
StringBuffer sb = new StringBuffer();
StringBuffer sb1 = new StringBuffer();
String[] codes = datas.split(",");
ProtocolContent protocol = new ProtocolContent();
protocol.setReceiveId(device.getNumbering());
protocol.setDeviceType("02");
logger.info("######数据长度:{}", codes.length);
if(codes.length > 300) { //大于300需要走压缩
String cmds = ProtocolUtil.getCmds(codes, frequency);
logger.info("压缩后的数据:{}", cmds);
protocol.setCmd("1B");
protocol.setContent(cmds);
} else {
protocol.setCmd("19");
for (String in : codes) {
sb1.append(in).append(",");
sb.append(ByteUtils.int2Hex(Integer.valueOf(in), 4));
}
logger.info(sb1.toString());
logger.info(sb.toString());
String content = StringUtils.appendString(sb.toString(), 1200, false, "0");
logger.info(content);
// InfraredControlCodeEntity controlCodeEntity = infraredControlCodeService.getOne(new QueryWrapper<InfraredControlCodeEntity>().eq("brand_id", controlUserEntity.getBrandId()).eq("remark", name).last("LIMIT 1"));
// if (controlCodeEntity != null) {
StringBuffer body = new StringBuffer();
body.append(StringUtils.appendString(ByteUtils.int2Hex(Integer.valueOf(frequency)), 4, true, "0"));
body.append(StringUtils.appendString(ByteUtils.int2Hex((sb.length()/2)),4, true, "0"));
body.append(content);
protocol.setContent(body.toString());
}
mqProducer.sendT(JSON.toJSONString(protocol));
return R.ok();
}
} }
...@@ -131,15 +131,16 @@ public class MqConsumer { ...@@ -131,15 +131,16 @@ public class MqConsumer {
logger.error("设备不存在 : {}", datas.get("receiveId")); logger.error("设备不存在 : {}", datas.get("receiveId"));
return; return;
} }
//更新设备状态为在线 if (device.getOnlineStatus() == 1 || device.getOnlineStatus() == 3) {
new Thread(() -> { //更新设备状态为在线
ShDeviceEntity deviceEntity = new ShDeviceEntity(); new Thread(() -> {
deviceEntity.setId(device.getId()); ShDeviceEntity deviceEntity = new ShDeviceEntity();
deviceEntity.setOnlineStatus(2); deviceEntity.setId(device.getId());
deviceEntity.setOnlineTime(new Date()); deviceEntity.setOnlineStatus(2);
otherShDeviceService.updateById(deviceEntity); deviceEntity.setOnlineTime(new Date());
}).start(); otherShDeviceService.updateById(deviceEntity);
}).start();
}
String sendMessage = null; String sendMessage = null;
Map<String, String> ws = null; Map<String, String> ws = null;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论