From 593f3d3faa211ec9da62c922ac3e5b5fcc6711d5 Mon Sep 17 00:00:00 2001 From: mi9688 Date: Wed, 18 Dec 2024 14:55:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=93=8D=E4=BD=9C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C=E4=BB=A5=E5=8F=8A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=85=85=E5=80=BC=E5=8D=A1=E7=9B=B8=E5=85=B3=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/domain/AjaxResult.java | 2 +- .../consumer/DeviceOtherMsgConsumer.java | 9 ++- .../service/impl/DeviceOtherMsgHandler.java | 5 +- .../data/controller/DeviceController.java | 12 ++++ .../controller/DeviceOperationController.java | 59 +++++++++++++++++++ .../DeviceReportInfoController.java | 2 +- .../data/controller/gis/mqtt/MqttTest.java | 15 ++++- .../UserRechargeCardsController.java | 8 ++- .../iot/model/dto/DeviceOperationDTO.java | 15 +++++ .../impl/DeviceReportInfoServiceImpl.java | 27 ++++++++- .../service/impl/SysUserServiceImpl.java | 8 +-- 11 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceOperationController.java create mode 100644 fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/model/dto/DeviceOperationDTO.java diff --git a/fastbee-common/src/main/java/com/fastbee/common/core/domain/AjaxResult.java b/fastbee-common/src/main/java/com/fastbee/common/core/domain/AjaxResult.java index 646b6e3..9a553a8 100644 --- a/fastbee-common/src/main/java/com/fastbee/common/core/domain/AjaxResult.java +++ b/fastbee-common/src/main/java/com/fastbee/common/core/domain/AjaxResult.java @@ -85,7 +85,7 @@ public class AjaxResult extends HashMap */ public static AjaxResult success() { - return AjaxResult.success("操作成功"); + return AjaxResult.success("操作成功",null); } /** diff --git a/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/redischannel/consumer/DeviceOtherMsgConsumer.java b/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/redischannel/consumer/DeviceOtherMsgConsumer.java index d79bf79..86b6fcc 100644 --- a/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/redischannel/consumer/DeviceOtherMsgConsumer.java +++ b/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/redischannel/consumer/DeviceOtherMsgConsumer.java @@ -32,7 +32,7 @@ public class DeviceOtherMsgConsumer { public void consume(DeviceReportBo bo){ try { //处理emq订阅的非 property/post 属性上报的消息 ,因为其他消息量小,放在一起处理 - String serialNumber=bo.getSerialNumber();//设备序列号 + Long productId;//产品id Long packetId;//包号 @@ -40,8 +40,11 @@ public class DeviceOtherMsgConsumer { String topic=bo.getTopicName();//主题 //从主题中解析出产品id String[] split = topic.split("/"); - productId=Long.valueOf(split[1]); - System.err.println("主题:"+topic+"产品id:"+productId+"设备序列号:"+serialNumber); + productId= Long.valueOf(split[1]); + //从主题中解析出设备序列号 + String serialNumber= split[2];//设备序列号 + + System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber); //设备上报数据消息 if(topic.endsWith("/info/up")){ deviceDataReportHandler(new String(data)); diff --git a/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/service/impl/DeviceOtherMsgHandler.java b/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/service/impl/DeviceOtherMsgHandler.java index fbb8b88..f8d4ef5 100644 --- a/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/service/impl/DeviceOtherMsgHandler.java +++ b/fastbee-gateway/fastbee-mq/src/main/java/com/fastbee/mq/service/impl/DeviceOtherMsgHandler.java @@ -42,11 +42,12 @@ public class DeviceOtherMsgHandler { * @param bo */ public void messageHandler(DeviceReportBo bo) { - System.err.println("进入消息处理入口:"+bo); + String type = ""; String name = topicsUtils.parseTopicName(bo.getTopicName()); if (StringUtils.isEmpty(name) || name.endsWith(TopicType.FUNCTION_GET.getTopicSuffix())) return; ReportDataBo data = this.buildReportData(bo); + System.err.println("进入消息处理入口:"+data); TopicType topicType = TopicType.getType(name); switch (topicType) { case INFO_POST: @@ -77,7 +78,7 @@ public class DeviceOtherMsgHandler { String message = new String(bo.getData()); // log.info("收到设备信息[{}]", message); Long productId = topicsUtils.parseProductId(bo.getTopicName()); - System.err.println("主题路径解析出产品id:"+productId); +// System.err.println("主题路径解析出产品id:"+productId); String serialNumber = topicsUtils.parseSerialNumber(bo.getTopicName()); ReportDataBo dataBo = new ReportDataBo(); dataBo.setMessage(message); diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java index 58e4c9f..1042f11 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceController.java @@ -505,4 +505,16 @@ public class DeviceController extends BaseController { return AjaxResult.success(deviceService.getDeviceActivationList()); } + /** + * 根据设备编号判断设备是否激活 + */ + @GetMapping("/getDeviceIsActivation") + @ApiOperation("根据设备编号判断设备是否激活") + public AjaxResult getDeviceActivation(String serialNumber) { + Device device = deviceService.selectDeviceBySerialNumber(serialNumber); + if(device.getStatus().toString().equals("1")){ + return AjaxResult.success(false); + } + return AjaxResult.success(true); + } } diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceOperationController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceOperationController.java new file mode 100644 index 0000000..5e5c9f3 --- /dev/null +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceOperationController.java @@ -0,0 +1,59 @@ +package com.fastbee.data.controller; + +import cn.hutool.json.JSONUtil; +import com.dtflys.forest.annotation.Post; +import com.fastbee.common.core.domain.AjaxResult; +import com.fastbee.iot.model.dto.DeviceOperationDTO; +import com.fastbee.mqttclient.PubMqttCallBack; +import com.fastbee.mqttclient.PubMqttClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +/** + * 下发指令操作设备 + */ +@RestController +@RequestMapping("/device/operation") +public class DeviceOperationController { + + @Autowired + private PubMqttClient pubMqttClient; + + @Autowired + private PubMqttCallBack pubMqttCallBack; + + /** + * 下发指令控制设备 + */ + @PostMapping("/control") + public AjaxResult control(@RequestBody DeviceOperationDTO deviceOperationDTO){ + + //构建主题 + String topic ="/"+deviceOperationDTO.getProductId()+"/"+deviceOperationDTO.getDeviceNumber()+"/cmd/down"; + //构建消息 + Map param = new HashMap<>(); + //远程阀控 + if(deviceOperationDTO.getOperationType().equals("700")){ + param.put("cmd",700); + Map data = new HashMap<>(); + data.put("status",deviceOperationDTO.getOperationCode()); + param.put("data",data); + pubMqttClient.publish(1,true,topic, JSONUtil.toJsonStr(param)); + return AjaxResult.success(); + //设备重启 + } else if (deviceOperationDTO.getOperationType().equals("100")) { + param.put("cmd",100); + Map data = new HashMap<>(); + data.put("status",deviceOperationDTO.getOperationCode()); + param.put("data",data); + } + return AjaxResult.error("未知命令!"); + } + +} diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceReportInfoController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceReportInfoController.java index c9a4f8b..97d8c5c 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceReportInfoController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/DeviceReportInfoController.java @@ -41,7 +41,7 @@ public class DeviceReportInfoController extends BaseController /** * 查询设备上电审核前上报的基础信息列表 */ - @PreAuthorize("@ss.hasPermi('iot:info:list')") +// @PreAuthorize("@ss.hasPermi('iot:info:list')") @GetMapping("/list") @ApiOperation("查询设备上电审核前上报的基础信息列表") public TableDataInfo list(DeviceReportInfo deviceReportInfo) diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/gis/mqtt/MqttTest.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/gis/mqtt/MqttTest.java index 307f9cc..97d4657 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/controller/gis/mqtt/MqttTest.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/gis/mqtt/MqttTest.java @@ -1,5 +1,6 @@ package com.fastbee.data.controller.gis.mqtt; +import cn.hutool.json.JSONUtil; import com.fastbee.mqttclient.PubMqttCallBack; import com.fastbee.mqttclient.PubMqttClient; import org.springframework.beans.factory.annotation.Autowired; @@ -7,6 +8,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.HashMap; +import java.util.Map; + @RestController @RequestMapping("/mqtt") public class MqttTest { @@ -18,12 +22,17 @@ public class MqttTest { private PubMqttCallBack pubMqttCallBack; /** - * 测试平台mqtt发布消息 + * 测试平台mqtt下发指令 */ @GetMapping("/publish") public String test(){ - pubMqttClient.publish(1,true,"/10086/155/cmd/down","mqtt测试主题发布消息!"); - return "test"; + Map param = new HashMap<>(); + param.put("cmd",700); + Map data = new HashMap<>(); + data.put("status",0); + param.put("data",data); + pubMqttClient.publish(1,true,"/10086/155/cmd/down", JSONUtil.toJsonStr(param)); + return "ok"; } /** diff --git a/fastbee-open-api/src/main/java/com/fastbee/data/controller/userRecharge/UserRechargeCardsController.java b/fastbee-open-api/src/main/java/com/fastbee/data/controller/userRecharge/UserRechargeCardsController.java index e8175dd..0f2d529 100644 --- a/fastbee-open-api/src/main/java/com/fastbee/data/controller/userRecharge/UserRechargeCardsController.java +++ b/fastbee-open-api/src/main/java/com/fastbee/data/controller/userRecharge/UserRechargeCardsController.java @@ -1,5 +1,7 @@ package com.fastbee.data.controller.userRecharge; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -112,10 +114,10 @@ public class UserRechargeCardsController extends BaseController * 删除用户充值卡 */ @PreAuthorize("@ss.hasPermi('rechargecard:cards:remove')") - @DeleteMapping("/{ids}") + @DeleteMapping("/{id}") @ApiOperation("删除用户充值卡") - public AjaxResult remove(@PathVariable Long[] ids) + public AjaxResult remove(@PathVariable Long id) { - return toAjax(userRechargeCardsService.deleteUserRechargeCardsByIds(ids)); + return toAjax(userRechargeCardsService.deleteUserRechargeCardsByIds(Collections.singletonList(id).toArray(new Long[0]))); } } diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/model/dto/DeviceOperationDTO.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/model/dto/DeviceOperationDTO.java new file mode 100644 index 0000000..4286b6d --- /dev/null +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/model/dto/DeviceOperationDTO.java @@ -0,0 +1,15 @@ +package com.fastbee.iot.model.dto; + +import lombok.Data; + +@Data +public class DeviceOperationDTO { + + private Long productId; + + private String deviceNumber; + + private String operationType; + + private String operationCode; +} diff --git a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceReportInfoServiceImpl.java b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceReportInfoServiceImpl.java index c249b0d..c659048 100644 --- a/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceReportInfoServiceImpl.java +++ b/fastbee-service/fastbee-iot-service/src/main/java/com/fastbee/iot/service/impl/DeviceReportInfoServiceImpl.java @@ -5,6 +5,8 @@ import java.util.List; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.fastbee.common.exception.ServiceException; +import com.fastbee.iot.domain.Device; +import com.fastbee.iot.mapper.DeviceMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.fastbee.iot.mapper.DeviceReportInfoMapper; @@ -24,6 +26,10 @@ public class DeviceReportInfoServiceImpl implements IDeviceReportInfoService private DeviceReportInfoMapper deviceReportInfoMapper; + @Autowired + private DeviceMapper deviceMapper; + + /** * 查询设备上电审核前上报的基础信息 * @@ -81,7 +87,26 @@ public class DeviceReportInfoServiceImpl implements IDeviceReportInfoService if(deviceReportInfo.getAutoReview()!=null&&deviceReportInfo.getAutoReview()){ deviceReportInfo.setStatus(2);//修改状态为已审核 } - return deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo); + int inserted = deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo); + + if(inserted<1){ + throw new ServiceException("插入设备上报信息失败!"); + } +// //插入成功后,插入设备信息 +// Device device= new Device(); +// device.setDeviceName(deviceReportInfo.getName()); +// device.setSerialNumber(deviceReportInfo.getSerialNumber()); +// //TODO 弄成活的 +// device.setProductId(146L); +// device.setStatus(1);//未激活 +// device.setCreateTime(deviceReportInfo.getPowersTime()); +// device.setTenantId(1L);//默认总管理员 +// int inserted1 = deviceMapper.insert(device); +// if(inserted1<1){ +// throw new ServiceException("插入设备信息失败!"); +// } + + return 1; } /** diff --git a/fastbee-service/fastbee-system-service/src/main/java/com/fastbee/system/service/impl/SysUserServiceImpl.java b/fastbee-service/fastbee-system-service/src/main/java/com/fastbee/system/service/impl/SysUserServiceImpl.java index d1a5584..fd8b307 100644 --- a/fastbee-service/fastbee-system-service/src/main/java/com/fastbee/system/service/impl/SysUserServiceImpl.java +++ b/fastbee-service/fastbee-system-service/src/main/java/com/fastbee/system/service/impl/SysUserServiceImpl.java @@ -123,7 +123,7 @@ public class SysUserServiceImpl implements ISysUserService * @param userName 用户名 * @return 用户对象信息 */ - @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userName", unless = "#result == null") +// @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userName", unless = "#result == null") @Override public SysUser selectUserByUserName(String userName) { @@ -136,7 +136,7 @@ public class SysUserServiceImpl implements ISysUserService * @param userId 用户ID * @return 用户对象信息 */ - @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userId", unless = "#result == null") +// @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userId", unless = "#result == null") @Override public SysUser selectUserById(Long userId) { @@ -149,7 +149,7 @@ public class SysUserServiceImpl implements ISysUserService * @param userName 用户名 * @return 结果 */ - @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userName", unless = "#result == null") +// @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userName", unless = "#result == null") @Override public String selectUserRoleGroup(String userName) { @@ -167,7 +167,7 @@ public class SysUserServiceImpl implements ISysUserService * @param userName 用户名 * @return 结果 */ - @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userName", unless = "#result == null") +// @Cacheable(value = "sysUser", key = "#root.methodName + '_' + #userName", unless = "#result == null") @Override public String selectUserPostGroup(String userName) {