From 253ccae45ca42e0abe08c70edc8e9942a687d5ac Mon Sep 17 00:00:00 2001 From: kerwincui <164770707@qq.com> Date: Sat, 29 May 2021 16:48:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/web/core/config/SwaggerConfig.java | 4 +- .../controller/IotCategoryController.java | 10 + .../controller/IotDeviceController.java | 28 +- .../controller/IotDeviceSetController.java | 38 ++- .../controller/IotDeviceStatusController.java | 43 ++- .../system/controller/IotGroupController.java | 113 ++++++++ .../system/controller/MqttController.java | 14 +- .../com/ruoyi/system/domain/IotDeviceSet.java | 58 +++- .../ruoyi/system/domain/IotDeviceStatus.java | 28 +- .../com/ruoyi/system/domain/IotGroup.java | 97 +++++++ .../system/domain/vo/IotDeviceListDto.java | 268 ++++++++++++++++++ .../ruoyi/system/mapper/IotDeviceMapper.java | 11 +- .../system/mapper/IotDeviceStatusMapper.java | 8 + .../ruoyi/system/mapper/IotGroupMapper.java | 61 ++++ .../system/mqtt/config/PushCallback.java | 55 +++- .../system/service/IIotDeviceService.java | 8 +- .../service/IIotDeviceStatusService.java | 8 + .../system/service/IIotGroupService.java | 61 ++++ .../service/impl/IotDeviceServiceImpl.java | 15 +- .../impl/IotDeviceStatusServiceImpl.java | 12 + .../service/impl/IotGroupServiceImpl.java | 96 +++++++ .../mapper/system/IotDeviceMapper.xml | 43 ++- .../mapper/system/IotDeviceSetMapper.xml | 19 +- .../mapper/system/IotDeviceStatusMapper.xml | 22 +- .../mapper/system/IotGroupMapper.xml | 90 ++++++ 25 files changed, 1159 insertions(+), 51 deletions(-) create mode 100644 spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotGroupController.java create mode 100644 spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotGroup.java create mode 100644 spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/IotDeviceListDto.java create mode 100644 spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotGroupMapper.java create mode 100644 spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotGroupService.java create mode 100644 spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotGroupServiceImpl.java create mode 100644 spring-boot/ruoyi-system/src/main/resources/mapper/system/IotGroupMapper.xml diff --git a/spring-boot/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java b/spring-boot/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java index 12737856..bf997cf7 100644 --- a/spring-boot/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java +++ b/spring-boot/ruoyi-admin/src/main/java/com/ruoyi/web/core/config/SwaggerConfig.java @@ -113,9 +113,9 @@ public class SwaggerConfig // 用ApiInfoBuilder进行定制 return new ApiInfoBuilder() // 设置标题 - .title("标题:若依管理系统_接口文档") + .title("标题:物美智能设备_接口文档") // 描述 - .description("描述:用于管理集团旗下公司的人员信息,具体包括XXX,XXX模块...") + .description("描述:物联网模块接口") // 作者信息 .contact(new Contact(ruoyiConfig.getName(), null, null)) // 版本 diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotCategoryController.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotCategoryController.java index 085f9fcb..c74d86f0 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotCategoryController.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotCategoryController.java @@ -1,6 +1,9 @@ package com.ruoyi.system.controller; import java.util.List; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -26,6 +29,7 @@ import com.ruoyi.common.core.page.TableDataInfo; * @author kerwincui * @date 2021-05-07 */ +@Api(value="设备分类",tags="设备分类") @RestController @RequestMapping("/system/category") public class IotCategoryController extends BaseController @@ -36,6 +40,7 @@ public class IotCategoryController extends BaseController /** * 查询设备分类列表 */ + @ApiOperation(value = "分类列表", notes = "分类列表") @PreAuthorize("@ss.hasPermi('system:category:list')") @GetMapping("/list") public TableDataInfo list(IotCategory iotCategory) @@ -48,6 +53,7 @@ public class IotCategoryController extends BaseController /** * 导出设备分类列表 */ + @ApiOperation(value = "导出分类列表", notes = "导出分类列表") @PreAuthorize("@ss.hasPermi('system:category:export')") @Log(title = "设备分类", businessType = BusinessType.EXPORT) @GetMapping("/export") @@ -61,6 +67,7 @@ public class IotCategoryController extends BaseController /** * 获取设备分类详细信息 */ + @ApiOperation(value = "获取分类详情", notes = "获取分类详情") @PreAuthorize("@ss.hasPermi('system:category:query')") @GetMapping(value = "/{categoryId}") public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId) @@ -71,6 +78,7 @@ public class IotCategoryController extends BaseController /** * 新增设备分类 */ + @ApiOperation(value = "新增分类", notes = "新增分类") @PreAuthorize("@ss.hasPermi('system:category:add')") @Log(title = "设备分类", businessType = BusinessType.INSERT) @PostMapping @@ -82,6 +90,7 @@ public class IotCategoryController extends BaseController /** * 修改设备分类 */ + @ApiOperation(value = "修改分类", notes = "修改分类") @PreAuthorize("@ss.hasPermi('system:category:edit')") @Log(title = "设备分类", businessType = BusinessType.UPDATE) @PutMapping @@ -93,6 +102,7 @@ public class IotCategoryController extends BaseController /** * 删除设备分类 */ + @ApiOperation(value = "删除分类", notes = "删除分类") @PreAuthorize("@ss.hasPermi('system:category:remove')") @Log(title = "设备分类", businessType = BusinessType.DELETE) @DeleteMapping("/{categoryIds}") diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceController.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceController.java index 972355a3..1008c59e 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceController.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceController.java @@ -1,6 +1,10 @@ package com.ruoyi.system.controller; import java.util.List; + +import com.ruoyi.system.domain.vo.IotDeviceListDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -26,6 +30,7 @@ import com.ruoyi.common.core.page.TableDataInfo; * @author kerwincui * @date 2021-05-06 */ +@Api(value="设备",tags="设备") @RestController @RequestMapping("/system/device") public class IotDeviceController extends BaseController @@ -36,31 +41,34 @@ public class IotDeviceController extends BaseController /** * 查询设备列表 */ + @ApiOperation(value = "设备列表", notes = "设备列表") @PreAuthorize("@ss.hasPermi('system:device:list')") @GetMapping("/list") public TableDataInfo list(IotDevice iotDevice) { startPage(); - List list = iotDeviceService.selectIotDeviceList(iotDevice); + List list = iotDeviceService.selectIotDeviceList(iotDevice); return getDataTable(list); } /** * 导出设备列表 */ + @ApiOperation(value = "导出设备列表", notes = "导出设备列表") @PreAuthorize("@ss.hasPermi('system:device:export')") @Log(title = "设备", businessType = BusinessType.EXPORT) @GetMapping("/export") public AjaxResult export(IotDevice iotDevice) { - List list = iotDeviceService.selectIotDeviceList(iotDevice); - ExcelUtil util = new ExcelUtil(IotDevice.class); + List list = iotDeviceService.selectIotDeviceList(iotDevice); + ExcelUtil util = new ExcelUtil(IotDeviceListDto.class); return util.exportExcel(list, "device"); } /** * 获取设备详细信息 */ + @ApiOperation(value = "获取设备详情", notes = "获取设备详情") @PreAuthorize("@ss.hasPermi('system:device:query')") @GetMapping(value = "/{deviceId}") public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId) @@ -68,9 +76,21 @@ public class IotDeviceController extends BaseController return AjaxResult.success(iotDeviceService.selectIotDeviceById(deviceId)); } + /** + * 根据设备编号获取设备详细信息 + */ + @ApiOperation(value = "根据设备编号获取设备详情", notes = "根据设备编号获取设备详情") + @PreAuthorize("@ss.hasPermi('system:device:query')") + @GetMapping(value = "/getByNum/{deviceNum}") + public AjaxResult getInfoByNum(@PathVariable("deviceNum") String deviceNum) + { + return AjaxResult.success(iotDeviceService.selectIotDeviceByNum(deviceNum)); + } + /** * 新增设备 */ + @ApiOperation(value = "新增设备", notes = "新增设备") @PreAuthorize("@ss.hasPermi('system:device:add')") @Log(title = "设备", businessType = BusinessType.INSERT) @PostMapping @@ -82,6 +102,7 @@ public class IotDeviceController extends BaseController /** * 修改设备 */ + @ApiOperation(value = "修改设备", notes = "修改设备") @PreAuthorize("@ss.hasPermi('system:device:edit')") @Log(title = "设备", businessType = BusinessType.UPDATE) @PutMapping @@ -93,6 +114,7 @@ public class IotDeviceController extends BaseController /** * 删除设备 */ + @ApiOperation(value = "删除设备", notes = "删除设备") @PreAuthorize("@ss.hasPermi('system:device:remove')") @Log(title = "设备", businessType = BusinessType.DELETE) @DeleteMapping("/{deviceIds}") diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceSetController.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceSetController.java index b397fe08..f8634670 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceSetController.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceSetController.java @@ -1,6 +1,11 @@ package com.ruoyi.system.controller; import java.util.List; + +import com.alibaba.fastjson.JSON; +import com.ruoyi.system.mqtt.config.MqttPushClient; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -26,6 +31,7 @@ import com.ruoyi.common.core.page.TableDataInfo; * @author kerwincui * @date 2021-05-06 */ +@Api(value="设备配置",tags="设备配置") @RestController @RequestMapping("/system/set") public class IotDeviceSetController extends BaseController @@ -33,9 +39,13 @@ public class IotDeviceSetController extends BaseController @Autowired private IIotDeviceSetService iotDeviceSetService; + @Autowired + private MqttPushClient mqttPushClient; + /** * 查询设备配置列表 */ + @ApiOperation(value = "查询设备配置列表", notes = "查询设备配置列表") @PreAuthorize("@ss.hasPermi('system:set:list')") @GetMapping("/list") public TableDataInfo list(IotDeviceSet iotDeviceSet) @@ -48,6 +58,7 @@ public class IotDeviceSetController extends BaseController /** * 导出设备配置列表 */ + @ApiOperation(value = "导出设备配置列表", notes = "导出设备配置列表") @PreAuthorize("@ss.hasPermi('system:set:export')") @Log(title = "设备配置", businessType = BusinessType.EXPORT) @GetMapping("/export") @@ -61,6 +72,7 @@ public class IotDeviceSetController extends BaseController /** * 获取设备配置详细信息 */ + @ApiOperation(value = "获取设备配置详情", notes = "获取设备配置详情") @PreAuthorize("@ss.hasPermi('system:set:query')") @GetMapping(value = "/{deviceSetId}") public AjaxResult getInfo(@PathVariable("deviceSetId") Long deviceSetId) @@ -71,6 +83,7 @@ public class IotDeviceSetController extends BaseController /** * 获取最新设备配置详细信息 */ + @ApiOperation(value = "获取最新设备配置详情", notes = "获取最新设备配置详情") @PreAuthorize("@ss.hasPermi('system:set:query')") @GetMapping(value = "/new/{deviceId}") public AjaxResult getNewInfo(@PathVariable("deviceId") Long deviceId) @@ -81,6 +94,7 @@ public class IotDeviceSetController extends BaseController /** * 新增设备配置 */ + @ApiOperation(value = "新增设备配置", notes = "新增设备配置") @PreAuthorize("@ss.hasPermi('system:set:add')") @Log(title = "设备配置", businessType = BusinessType.INSERT) @PostMapping @@ -92,22 +106,38 @@ public class IotDeviceSetController extends BaseController /** * 修改设备配置 */ + @ApiOperation(value = "修改设备配置", notes = "修改设备配置") @PreAuthorize("@ss.hasPermi('system:set:edit')") @Log(title = "设备配置", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody IotDeviceSet iotDeviceSet) { - return toAjax(iotDeviceSetService.updateIotDeviceSet(iotDeviceSet)); + // 存储 + iotDeviceSetService.updateIotDeviceSet(iotDeviceSet); + // mqtt发布 + String content = JSON.toJSONString(iotDeviceSet); + boolean isSuccess=mqttPushClient.publish(0,true,"setting/set/"+iotDeviceSet.getDeviceNum(),content); + if(isSuccess){return AjaxResult.success("mqtt 发布成功");} + return AjaxResult.error("mqtt 发布失败。"); + } + + @ApiOperation(value = "mqtt获取设备配置", notes = "mqtt获取设备配置") + @GetMapping(value = "/getSetting/{deviceNum}") + public AjaxResult getSetting(@PathVariable("deviceNum") String deviceNum){ + boolean isSuccess=mqttPushClient.publish(0,true,"setting/get/"+deviceNum,"wumei.live"); + if(isSuccess){return AjaxResult.success("mqtt 发布成功");} + return AjaxResult.error("mqtt 发布失败。"); } /** * 删除设备配置 */ + @ApiOperation(value = "删除设备配置", notes = "删除设备配置") @PreAuthorize("@ss.hasPermi('system:set:remove')") @Log(title = "设备配置", businessType = BusinessType.DELETE) - @DeleteMapping("/{deviceConfigIds}") - public AjaxResult remove(@PathVariable Long[] deviceConfigIds) + @DeleteMapping("/{deviceSetIds}") + public AjaxResult remove(@PathVariable Long[] deviceSetIds) { - return toAjax(iotDeviceSetService.deleteIotDeviceSetByIds(deviceConfigIds)); + return toAjax(iotDeviceSetService.deleteIotDeviceSetByIds(deviceSetIds)); } } diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceStatusController.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceStatusController.java index bd898fa2..bfe565dd 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceStatusController.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotDeviceStatusController.java @@ -1,6 +1,11 @@ package com.ruoyi.system.controller; import java.util.List; + +import com.alibaba.fastjson.JSON; +import com.ruoyi.system.mqtt.config.MqttPushClient; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -26,6 +31,7 @@ import com.ruoyi.common.core.page.TableDataInfo; * @author kerwincui * @date 2021-05-06 */ +@Api(value="设备状态",tags="设备状态") @RestController @RequestMapping("/system/status") public class IotDeviceStatusController extends BaseController @@ -33,9 +39,13 @@ public class IotDeviceStatusController extends BaseController @Autowired private IIotDeviceStatusService iotDeviceStatusService; + @Autowired + private MqttPushClient mqttPushClient; + /** * 查询设备状态列表 */ + @ApiOperation(value = "查询设备状态列表", notes = "查询设备状态列表") @PreAuthorize("@ss.hasPermi('system:status:list')") @GetMapping("/list") public TableDataInfo list(IotDeviceStatus iotDeviceStatus) @@ -48,6 +58,7 @@ public class IotDeviceStatusController extends BaseController /** * 导出设备状态列表 */ + @ApiOperation(value = "导出设备状态列表", notes = "导出设备状态列表") @PreAuthorize("@ss.hasPermi('system:status:export')") @Log(title = "设备状态", businessType = BusinessType.EXPORT) @GetMapping("/export") @@ -61,6 +72,7 @@ public class IotDeviceStatusController extends BaseController /** * 获取设备状态详细信息 */ + @ApiOperation(value = "获取设备状态详情", notes = "获取设备状态详情") @PreAuthorize("@ss.hasPermi('system:status:query')") @GetMapping(value = "/{deviceStatusId}") public AjaxResult getInfo(@PathVariable("deviceStatusId") Long deviceStatusId) @@ -68,9 +80,21 @@ public class IotDeviceStatusController extends BaseController return AjaxResult.success(iotDeviceStatusService.selectIotDeviceStatusById(deviceStatusId)); } + /** + * 根据设备编号获取设备状态 + */ + @ApiOperation(value = "根据设备编号获取最新设备状态", notes = "根据设备编号获取最新设备状态") + @PreAuthorize("@ss.hasPermi('system:status:query')") + @GetMapping(value = "/newByNum/{deviceNum}") + public AjaxResult getNewStatus(@PathVariable("deviceNum") String deviceNum) + { + return AjaxResult.success(iotDeviceStatusService.selectIotDeviceStatusByDeviceNum(deviceNum)); + } + /** * 获取最新设备状态详细信息 */ + @ApiOperation(value = "获取最新设备状态详情", notes = "获取最新设备状态详情") @PreAuthorize("@ss.hasPermi('system:status:query')") @GetMapping(value = "/new/{deviceId}") public AjaxResult getNewInfo(@PathVariable("deviceId") Long deviceId) @@ -81,6 +105,7 @@ public class IotDeviceStatusController extends BaseController /** * 新增设备状态 */ + @ApiOperation(value = "新增设备状态", notes = "新增设备状态") @PreAuthorize("@ss.hasPermi('system:status:add')") @Log(title = "设备状态", businessType = BusinessType.INSERT) @PostMapping @@ -92,17 +117,33 @@ public class IotDeviceStatusController extends BaseController /** * 修改设备状态 */ + @ApiOperation(value = "修改设备状态", notes = "修改设备状态") @PreAuthorize("@ss.hasPermi('system:status:edit')") @Log(title = "设备状态", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody IotDeviceStatus iotDeviceStatus) { - return toAjax(iotDeviceStatusService.updateIotDeviceStatus(iotDeviceStatus)); + // 存储 + iotDeviceStatusService.updateIotDeviceStatus(iotDeviceStatus); + // mqtt发布 + String content = JSON.toJSONString(iotDeviceStatus); + boolean isSuccess=mqttPushClient.publish(1,true,"status/set/"+iotDeviceStatus.getDeviceNum(),content); + if(isSuccess){return AjaxResult.success("mqtt 发布成功");} + return AjaxResult.error("mqtt 发布失败。"); + } + + @ApiOperation(value = "mqtt获取设备状态", notes = "mqtt获取设备状态") + @GetMapping(value = "/getStatus/{deviceNum}") + public AjaxResult getStatus(@PathVariable("deviceNum") String deviceNum){ + boolean isSuccess=mqttPushClient.publish(0,true,"status/get/"+deviceNum,"wumei.live"); + if(isSuccess){return AjaxResult.success("mqtt 发布成功");} + return AjaxResult.error("mqtt 发布失败。"); } /** * 删除设备状态 */ + @ApiOperation(value = "删除设备状态", notes = "删除设备状态") @PreAuthorize("@ss.hasPermi('system:status:remove')") @Log(title = "设备状态", businessType = BusinessType.DELETE) @DeleteMapping("/{deviceStatusIds}") diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotGroupController.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotGroupController.java new file mode 100644 index 00000000..57b642bf --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/IotGroupController.java @@ -0,0 +1,113 @@ +package com.ruoyi.system.controller; + +import java.util.List; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.IotGroup; +import com.ruoyi.system.service.IIotGroupService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 分组Controller + * + * @author kerwincui + * @date 2021-05-18 + */ +@Api(value="设备分组",tags="设备分组") +@RestController +@RequestMapping("/system/group") +public class IotGroupController extends BaseController +{ + @Autowired + private IIotGroupService iotGroupService; + + /** + * 查询分组列表 + */ + @ApiOperation(value = "分组列表", notes = "分组列表") + @PreAuthorize("@ss.hasPermi('system:group:list')") + @GetMapping("/list") + public TableDataInfo list(IotGroup iotGroup) + { + startPage(); + List list = iotGroupService.selectIotGroupList(iotGroup); + return getDataTable(list); + } + + /** + * 导出分组列表 + */ + @ApiOperation(value = "导出分组", notes = "导出分组") + @PreAuthorize("@ss.hasPermi('system:group:export')") + @Log(title = "分组", businessType = BusinessType.EXPORT) + @GetMapping("/export") + public AjaxResult export(IotGroup iotGroup) + { + List list = iotGroupService.selectIotGroupList(iotGroup); + ExcelUtil util = new ExcelUtil(IotGroup.class); + return util.exportExcel(list, "group"); + } + + /** + * 获取分组详细信息 + */ + @ApiOperation(value = "获取分组详情", notes = "获取分组详情") + @PreAuthorize("@ss.hasPermi('system:group:query')") + @GetMapping(value = "/{groupId}") + public AjaxResult getInfo(@PathVariable("groupId") Long groupId) + { + return AjaxResult.success(iotGroupService.selectIotGroupById(groupId)); + } + + /** + * 新增分组 + */ + @ApiOperation(value = "新增分组", notes = "新增分组") + @PreAuthorize("@ss.hasPermi('system:group:add')") + @Log(title = "分组", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody IotGroup iotGroup) + { + return toAjax(iotGroupService.insertIotGroup(iotGroup)); + } + + /** + * 修改分组 + */ + @ApiOperation(value = "修改分组", notes = "修改分组") + @PreAuthorize("@ss.hasPermi('system:group:edit')") + @Log(title = "分组", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody IotGroup iotGroup) + { + return toAjax(iotGroupService.updateIotGroup(iotGroup)); + } + + /** + * 删除分组 + */ + @ApiOperation(value = "删除分组", notes = "删除分组") + @PreAuthorize("@ss.hasPermi('system:group:remove')") + @Log(title = "分组", businessType = BusinessType.DELETE) + @DeleteMapping("/{groupIds}") + public AjaxResult remove(@PathVariable Long[] groupIds) + { + return toAjax(iotGroupService.deleteIotGroupByIds(groupIds)); + } +} diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/MqttController.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/MqttController.java index 31464256..26eb5202 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/MqttController.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/controller/MqttController.java @@ -14,12 +14,12 @@ import org.springframework.beans.factory.annotation.Autowired; /** - * swagger 用户测试方法 + * mqtt接口 * */ -@Api("mqtt测试") +@Api(value="mqtt消息发布",tags="mqtt消息发布") @RestController -@RequestMapping("/test/mqtt") +@RequestMapping("/system/mqtt") public class MqttController extends BaseController { @Autowired @@ -29,7 +29,7 @@ public class MqttController extends BaseController @PostMapping(value = "/updateStatus") public AjaxResult updateStatus(@RequestBody IotDeviceStatus iotDeviceStatus){ String content = JSON.toJSONString(iotDeviceStatus); - boolean isSuccess=mqttPushClient.publish(1,false,"status/"+iotDeviceStatus.getDeviceNum(),content); + boolean isSuccess=mqttPushClient.publish(1,false,"status/set/"+iotDeviceStatus.getDeviceNum(),content); if(isSuccess){return AjaxResult.success();} return AjaxResult.error("mqtt 发布失败。"); } @@ -37,7 +37,7 @@ public class MqttController extends BaseController @ApiOperation(value = "获取设备状态", notes = "获取设备状态") @GetMapping(value = "/getStatus/{deviceNum}") public AjaxResult getStatus(@PathVariable("deviceNum") String deviceNum){ - boolean isSuccess=mqttPushClient.publish(0,false,"status/new/"+deviceNum,""); + boolean isSuccess=mqttPushClient.publish(0,false,"status/get/"+deviceNum,"wumei.live"); if(isSuccess){return AjaxResult.success();} return AjaxResult.error("mqtt 发布失败。"); } @@ -46,7 +46,7 @@ public class MqttController extends BaseController @PostMapping(value = "/updateSetting") public AjaxResult updateSetting(@RequestBody IotDeviceSet iotDeviceSet){ String content = JSON.toJSONString(iotDeviceSet); - boolean isSuccess=mqttPushClient.publish(0,false,"setting/"+iotDeviceSet.getDeviceNum(),content); + boolean isSuccess=mqttPushClient.publish(0,false,"setting/set/"+iotDeviceSet.getDeviceNum(),content); if(isSuccess){return AjaxResult.success();} return AjaxResult.error("mqtt 发布失败。"); } @@ -54,7 +54,7 @@ public class MqttController extends BaseController @ApiOperation(value = "获取设备配置", notes = "获取设备配置") @GetMapping(value = "/getSetting/{deviceNum}") public AjaxResult getSetting(@PathVariable("deviceNum") String deviceNum){ - boolean isSuccess=mqttPushClient.publish(0,false,"Setting/new/"+deviceNum,""); + boolean isSuccess=mqttPushClient.publish(0,false,"setting/get/"+deviceNum,"wumei.lie"); if(isSuccess){return AjaxResult.success();} return AjaxResult.error("mqtt 发布失败。"); } diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceSet.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceSet.java index f8281995..98d215bf 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceSet.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceSet.java @@ -46,6 +46,18 @@ public class IotDeviceSet extends BaseEntity @Excel(name = "打开AP") private Integer isAp; + /** 是否离线使用 */ + @Excel(name = "是否离线使用") + private Integer isWifiOffline; + + /** 是否使用证书 */ + @Excel(name = "是否使用证书") + private Integer isOpenCertifi; + + /** 智能配网 */ + @Excel(name = "智能配网") + private Integer isSmartConfig; + /** 射频遥控 */ @Excel(name = "射频遥控") private Integer isRfControl; @@ -86,6 +98,10 @@ public class IotDeviceSet extends BaseEntity @Excel(name = "配网IP") private String networkIp; + /** 雷达感应间隔 */ + @Excel(name = "雷达感应间隔") + private Integer radarInterval; + /** 删除标志(0代表存在 2代表删除) */ private String delFlag; @@ -152,15 +168,43 @@ public class IotDeviceSet extends BaseEntity { return isReset; } + public void setIsAp(Integer isAp) { this.isAp = isAp; } - public Integer getIsAp() { return isAp; } + + public void setIsWifiOffline(Integer isWifiOffline) + { + this.isWifiOffline = isWifiOffline; + } + public Integer getIsWifiOffline() + { + return isWifiOffline; + } + + public void setIsOpenCertifi(Integer isOpenCertifi) + { + this.isOpenCertifi = isOpenCertifi; + } + public Integer getIsOpenCertifi() + { + return isOpenCertifi; + } + + public void setIsSmartConfig(Integer isSmartConfig) + { + this.isSmartConfig = isSmartConfig; + } + + public Integer getIsSmartConfig() + { + return isSmartConfig; + } public void setIsRfControl(Integer isRfControl) { this.isRfControl = isRfControl; @@ -256,6 +300,16 @@ public class IotDeviceSet extends BaseEntity this.delFlag = delFlag; } + public void setRadarInterval(Integer radarInterval) + { + this.radarInterval = radarInterval; + } + + public Integer getRadarInterval() + { + return radarInterval; + } + public String getDelFlag() { return delFlag; @@ -272,6 +326,7 @@ public class IotDeviceSet extends BaseEntity .append("isHost", getIsHost()) .append("isReset", getIsReset()) .append("isAp", getIsAp()) + .append("isSmartConfig", getIsSmartConfig()) .append("isRfControl", getIsRfControl()) .append("isRfLearn", getIsRfLearn()) .append("isRfClear", getIsRfClear()) @@ -282,6 +337,7 @@ public class IotDeviceSet extends BaseEntity .append("ownerId", getOwnerId()) .append("networkAddress", getNetworkAddress()) .append("networkIp", getNetworkIp()) + .append("radarInterval", getRadarInterval()) .append("delFlag", getDelFlag()) .append("createBy", getCreateBy()) .append("createTime", getCreateTime()) diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceStatus.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceStatus.java index cb0c08bf..27ec04ff 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceStatus.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotDeviceStatus.java @@ -44,8 +44,8 @@ public class IotDeviceStatus extends BaseEntity private BigDecimal deviceTemperature; /** 设备湿度 */ - @Excel(name = "设备湿度") - private BigDecimal deviceHumidity; + @Excel(name = "信号") + private Integer rssi; /** 空气温度 */ @Excel(name = "空气温度") @@ -71,6 +71,10 @@ public class IotDeviceStatus extends BaseEntity @Excel(name = "彩灯模式") private Integer lightMode; + /** 灯渐变时间 */ + @Excel(name = "渐变时间") + private Integer fadeTime; + /** 红灯 */ @Excel(name = "红灯") private Long red; @@ -149,14 +153,14 @@ public class IotDeviceStatus extends BaseEntity { return deviceTemperature; } - public void setDeviceHumidity(BigDecimal deviceHumidity) + public void setRssi(Integer rssi) { - this.deviceHumidity = deviceHumidity; + this.rssi = rssi; } - public BigDecimal getDeviceHumidity() + public Integer getRssi() { - return deviceHumidity; + return rssi; } public void setAirTemperature(BigDecimal airTemperature) { @@ -244,6 +248,15 @@ public class IotDeviceStatus extends BaseEntity this.delFlag = delFlag; } + public void setFadeTime(Integer fadeTime) + { + this.fadeTime = fadeTime; + } + public Integer getFadeTime() + { + return fadeTime; + } + public String getDelFlag() { return delFlag; @@ -259,13 +272,14 @@ public class IotDeviceStatus extends BaseEntity .append("lightStatus", getLightStatus()) .append("isOnline", getIsOnline()) .append("deviceTemperature", getDeviceTemperature()) - .append("deviceHumidity", getDeviceHumidity()) + .append("rssid", getRssi()) .append("airTemperature", getAirTemperature()) .append("airHumidity", getAirHumidity()) .append("triggerSource", getTriggerSource()) .append("brightness", getBrightness()) .append("lightInterval", getLightInterval()) .append("lightMode", getLightMode()) + .append("fadeTime", getFadeTime()) .append("red", getRed()) .append("green", getGreen()) .append("blue", getBlue()) diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotGroup.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotGroup.java new file mode 100644 index 00000000..5bcedfe1 --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/IotGroup.java @@ -0,0 +1,97 @@ +package com.ruoyi.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 分组对象 iot_group + * + * @author kerwincui + * @date 2021-05-18 + */ +public class IotGroup extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 设备分组 */ + private Long groupId; + + /** 用户 */ + @Excel(name = "用户") + private Long userId; + + /** 分组名称 */ + @Excel(name = "分组名称") + private String groupName; + + /** 排序 */ + @Excel(name = "排序") + private Integer groupOrder; + + /** 删除标志(0代表存在 2代表删除) */ + private String delFlag; + + public void setGroupId(Long groupId) + { + this.groupId = groupId; + } + + public Long getGroupId() + { + return groupId; + } + public void setUserId(Long userId) + { + this.userId = userId; + } + + public Long getUserId() + { + return userId; + } + public void setGroupName(String groupName) + { + this.groupName = groupName; + } + + public String getGroupName() + { + return groupName; + } + public void setGroupOrder(Integer groupOrder) + { + this.groupOrder = groupOrder; + } + + public Integer getGroupOrder() + { + return groupOrder; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + + public String getDelFlag() + { + return delFlag; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("groupId", getGroupId()) + .append("userId", getUserId()) + .append("groupName", getGroupName()) + .append("groupOrder", getGroupOrder()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/IotDeviceListDto.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/IotDeviceListDto.java new file mode 100644 index 00000000..c8940bce --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/IotDeviceListDto.java @@ -0,0 +1,268 @@ +package com.ruoyi.system.domain.vo; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 设备对象 iot_device + * + * @author kerwincui + * @date 2021-05-06 + */ +public class IotDeviceListDto extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 序号 */ + private Long deviceId; + + /** 编号 */ + @Excel(name = "编号") + private String deviceNum; + + /** 分类 */ + @Excel(name = "分类") + private Long categoryId; + + /** 名称 */ + @Excel(name = "名称") + private String deviceName; + + /** 固件版本 */ + @Excel(name = "固件版本") + private String firmwareVersion; + + /** 用户 */ + @Excel(name = "用户") + private String ownerId; + + @Excel(name="用户昵称") + private String nickName; + + /** 删除标志(0代表存在 2代表删除) */ + private String delFlag; + + + /** 报警 */ + @Excel(name = "报警") + private Integer isAlarm; + + /** 雷达感应 */ + @Excel(name = "雷达感应") + private Integer isRadar; + + /** 射频遥控 */ + @Excel(name = "射频遥控") + private Integer isRfControl; + + /** 配网地址 */ + @Excel(name = "配网地址") + private String networkAddress; + + /** 配网IP */ + @Excel(name = "配网IP") + private String networkIp; + + + /** 继电器 */ + @Excel(name = "继电器") + private Integer relayStatus; + + /** 灯状态 */ + @Excel(name = "灯状态") + private Integer lightStatus; + + /** 在线 */ + @Excel(name = "在线") + private Integer isOnline; + + /** 设备温度 */ + @Excel(name = "设备温度") + private BigDecimal deviceTemperature; + + /** 设备湿度 */ + @Excel(name = "信号") + private Integer rssi; + + + + public void setDeviceId(Long deviceId) + { + this.deviceId = deviceId; + } + public Long getDeviceId() + { + return deviceId; + } + public void setDeviceNum(String deviceNum) + { + this.deviceNum = deviceNum; + } + public String getDeviceNum() + { + return deviceNum; + } + public void setCategoryId(Long categoryId) + { + this.categoryId = categoryId; + } + public Long getCategoryId() + { + return categoryId; + } + public void setDeviceName(String deviceName) + { + this.deviceName = deviceName; + } + public String getDeviceName() + { + return deviceName; + } + public void setFirmwareVersion(String firmwareVersion) + { + this.firmwareVersion = firmwareVersion; + } + public String getFirmwareVersion() + { + return firmwareVersion; + } + public void setOwnerId(String ownerId) + { + this.ownerId = ownerId; + } + public String getOwnerId() + { + return ownerId; + } + public void setNickName(String nickName) + { + this.nickName = nickName; + } + public String getNickName() + { + return nickName; + } + public void setDelFlag(String delFlag) + { + this.delFlag = delFlag; + } + public String getDelFlag() + { + return delFlag; + } + + public void setIsAlarm(Integer isAlarm) + { + this.isAlarm = isAlarm; + } + public Integer getIsAlarm() + { + return isAlarm; + } + public void setIsRadar(Integer isRadar) + { + this.isRadar = isRadar; + } + public Integer getIsRadar() + { + return isRadar; + } + public void setIsRfControl(Integer isRfControl) + { + this.isRfControl = isRfControl; + } + public Integer getIsRfControl() + { + return isRfControl; + } + public void setNetworkAddress(String networkAddress) + { + this.networkAddress = networkAddress; + } + public String getNetworkAddress() + { + return networkAddress; + } + public void setNetworkIp(String networkIp) + { + this.networkIp = networkIp; + } + public String getNetworkIp() + { + return networkIp; + } + + public void setRelayStatus(Integer relayStatus) + { + this.relayStatus = relayStatus; + } + public Integer getRelayStatus() + { + return relayStatus; + } + public void setLightStatus(Integer lightStatus) + { + this.lightStatus = lightStatus; + } + public Integer getLightStatus() + { + return lightStatus; + } + public void setIsOnline(Integer isOnline) + { + this.isOnline = isOnline; + } + public Integer getIsOnline() + { + return isOnline; + } + public void setDeviceTemperature(BigDecimal deviceTemperature) + { + this.deviceTemperature = deviceTemperature; + } + public BigDecimal getDeviceTemperature() + { + return deviceTemperature; + } + public void setRssi(Integer rssi) + { + this.rssi = rssi; + } + public Integer getRssi() + { + return rssi; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("deviceId", getDeviceId()) + .append("deviceNum", getDeviceNum()) + .append("categoryId", getCategoryId()) + .append("deviceName", getDeviceName()) + .append("firmwareVersion", getFirmwareVersion()) + .append("ownerId", getOwnerId()) + .append("nickName", getNickName()) + .append("delFlag", getDelFlag()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("isAlarm", getIsAlarm()) + .append("isRadar", getIsRadar()) + .append("isRfControl", getIsRfControl()) + .append("networkAddress", getNetworkAddress()) + .append("networkIp", getNetworkIp()) + .append("relayStatus", getRelayStatus()) + .append("lightStatus", getLightStatus()) + .append("isOnline", getIsOnline()) + .append("deviceTemperature", getDeviceTemperature()) + .append("rssid", getRssi()) + .toString(); + } +} diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceMapper.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceMapper.java index 790b9459..84578dd8 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceMapper.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.system.mapper; import java.util.List; import com.ruoyi.system.domain.IotDevice; +import com.ruoyi.system.domain.vo.IotDeviceListDto; /** * 设备Mapper接口 @@ -19,13 +20,21 @@ public interface IotDeviceMapper */ public IotDevice selectIotDeviceById(Long deviceId); + /** + * 根据编号查询设备 + * + * @param deviceNum 设备编号 + * @return 设备 + */ + public IotDevice selectIotDeviceByNum(String deviceNum); + /** * 查询设备列表 * * @param iotDevice 设备 * @return 设备集合 */ - public List selectIotDeviceList(IotDevice iotDevice); + public List selectIotDeviceList(IotDevice iotDevice); /** * 新增设备 diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceStatusMapper.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceStatusMapper.java index 6624bcd1..e0a150df 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceStatusMapper.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotDeviceStatusMapper.java @@ -27,6 +27,14 @@ public interface IotDeviceStatusMapper */ public IotDeviceStatus selectIotDeviceStatusByDeviceId(Long deviceId); + /** + * 根据设备编号查询设备最新状态 + * + * @param deviceNum 设备编号 + * @return 设备状态 + */ + public IotDeviceStatus selectIotDeviceStatusByDeviceNum(String deviceNum); + /** * 查询设备状态列表 * diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotGroupMapper.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotGroupMapper.java new file mode 100644 index 00000000..8c333667 --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mapper/IotGroupMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.IotGroup; + +/** + * 分组Mapper接口 + * + * @author kerwincui + * @date 2021-05-18 + */ +public interface IotGroupMapper +{ + /** + * 查询分组 + * + * @param groupId 分组ID + * @return 分组 + */ + public IotGroup selectIotGroupById(Long groupId); + + /** + * 查询分组列表 + * + * @param iotGroup 分组 + * @return 分组集合 + */ + public List selectIotGroupList(IotGroup iotGroup); + + /** + * 新增分组 + * + * @param iotGroup 分组 + * @return 结果 + */ + public int insertIotGroup(IotGroup iotGroup); + + /** + * 修改分组 + * + * @param iotGroup 分组 + * @return 结果 + */ + public int updateIotGroup(IotGroup iotGroup); + + /** + * 删除分组 + * + * @param groupId 分组ID + * @return 结果 + */ + public int deleteIotGroupById(Long groupId); + + /** + * 批量删除分组 + * + * @param groupIds 需要删除的数据ID + * @return 结果 + */ + public int deleteIotGroupByIds(Long[] groupIds); +} diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mqtt/config/PushCallback.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mqtt/config/PushCallback.java index 6ed605ae..3e252b3e 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mqtt/config/PushCallback.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/mqtt/config/PushCallback.java @@ -3,9 +3,14 @@ package com.ruoyi.system.mqtt.config; import com.alibaba.fastjson.JSON; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.ip.AddressUtils; +import com.ruoyi.common.utils.ip.IpUtils; +import com.ruoyi.system.domain.IotCategory; import com.ruoyi.system.domain.IotDevice; import com.ruoyi.system.domain.IotDeviceSet; import com.ruoyi.system.domain.IotDeviceStatus; +import com.ruoyi.system.service.IIotCategoryService; import com.ruoyi.system.service.IIotDeviceService; import com.ruoyi.system.service.IIotDeviceSetService; import com.ruoyi.system.service.IIotDeviceStatusService; @@ -31,6 +36,8 @@ public class PushCallback implements MqttCallback { @Autowired private IIotDeviceService iotDeviceService; @Autowired + private IIotCategoryService iotCategoryService; + @Autowired private IIotDeviceStatusService iotDeviceStatusService; @Autowired private IIotDeviceSetService iotDeviceSetService; @@ -58,33 +65,53 @@ public class PushCallback implements MqttCallback { if(topic.equals("device_info")){ //添加设备信息 IotDevice device = JSON.parseObject(new String(mqttMessage.getPayload()), IotDevice.class); - iotDeviceService.insertIotDevice(device); - //获取设备状态 - mqttPushClient.publish(0,false,"status/new/"+device.getDeviceNum(),""); + IotDevice deviceEntity=iotDeviceService.selectIotDeviceByNum(device.getDeviceNum()); + if(deviceEntity!=null){ + device.setDeviceId(deviceEntity.getDeviceId()); + iotDeviceService.updateIotDevice(device); + }else { + IotCategory categoryEntity=iotCategoryService.selectIotCategoryById(device.getCategoryId()); + if(device.getDeviceName()==null || device.getDeviceNum().length()==0) { + device.setDeviceName(categoryEntity.getCategoryName()); + } + iotDeviceService.insertIotDevice(device); + } + //获取设备状态(消息内容不能为空,硬件获取不到数据报错) + mqttPushClient.publish(1,false,"status/get/"+device.getDeviceNum(),"wumei.live"); //获取设备配置 - mqttPushClient.publish(0,false,"setting/new/"+device.getDeviceNum(),""); + mqttPushClient.publish(1,false,"setting/get/"+device.getDeviceNum(),"wumei.live"); }else if(topic.equals("status")){ IotDeviceStatus deviceStatus = JSON.parseObject(new String(mqttMessage.getPayload()), IotDeviceStatus.class); - IotDevice device=iotDeviceService.selectIotDeviceById(deviceStatus.getDeviceId()); + IotDevice device=iotDeviceService.selectIotDeviceByNum(deviceStatus.getDeviceNum()); //添加设备状态 deviceStatus.setDeviceId(device.getDeviceId()); iotDeviceStatusService.insertIotDeviceStatus(deviceStatus); }else if(topic.equals("setting")){ IotDeviceSet deviceSet = JSON.parseObject(new String(mqttMessage.getPayload()), IotDeviceSet.class); - //更新设备用户 - IotDevice device=iotDeviceService.selectIotDeviceById(deviceSet.getDeviceId()); - device.setOwnerId(deviceSet.getOwnerId()); - iotDeviceService.updateIotDevice(device); + // 智能配网时需要获取IP、地址和设备用户 + IotDevice device=null; + if(deviceSet.getIsSmartConfig()==1){ + final String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); + deviceSet.setNetworkIp(ip); + deviceSet.setNetworkAddress( AddressUtils.getRealAddressByIP(ip)); + //更新设备用户 + device=iotDeviceService.selectIotDeviceByNum(deviceSet.getDeviceNum()); + device.setOwnerId(deviceSet.getOwnerId()); + iotDeviceService.updateIotDevice(device); + } //添加设备配置 deviceSet.setDeviceId(device.getDeviceId()); iotDeviceSetService.insertIotDeviceSet(deviceSet); }else if(topic.equals("offline")){ - //离线遗嘱 + //离线遗嘱 TODO:查询待优化 IotDeviceStatus deviceStatus = JSON.parseObject(new String(mqttMessage.getPayload()), IotDeviceStatus.class); - //添加设备状态 - IotDeviceStatus newDeviceStatus=iotDeviceStatusService.selectIotDeviceStatusById(deviceStatus.getDeviceStatusId()); - newDeviceStatus.setIsOnline(0); - iotDeviceStatusService.insertIotDeviceStatus(newDeviceStatus); + IotDevice device=iotDeviceService.selectIotDeviceByNum(deviceStatus.getDeviceNum()); + IotDeviceStatus deviceStatusEntity=iotDeviceStatusService.selectIotDeviceStatusByDeviceId(device.getDeviceId()); + //跟新最近一条设备状态为离线 + if(deviceStatusEntity!=null) { + deviceStatusEntity.setIsOnline(0); + iotDeviceStatusService.updateIotDeviceStatus(deviceStatusEntity); + } } } diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceService.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceService.java index 50abfbce..a6ee191a 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceService.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceService.java @@ -2,6 +2,7 @@ package com.ruoyi.system.service; import java.util.List; import com.ruoyi.system.domain.IotDevice; +import com.ruoyi.system.domain.vo.IotDeviceListDto; /** * 设备Service接口 @@ -19,13 +20,18 @@ public interface IIotDeviceService */ public IotDevice selectIotDeviceById(Long deviceId); + /** + * 根据编号查询设备 + */ + public IotDevice selectIotDeviceByNum(String deviceNum); + /** * 查询设备列表 * * @param iotDevice 设备 * @return 设备集合 */ - public List selectIotDeviceList(IotDevice iotDevice); + public List selectIotDeviceList(IotDevice iotDevice); /** * 新增设备 diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceStatusService.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceStatusService.java index a473321b..70169e8e 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceStatusService.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotDeviceStatusService.java @@ -27,6 +27,14 @@ public interface IIotDeviceStatusService */ public IotDeviceStatus selectIotDeviceStatusByDeviceId(Long deviceId); + /** + * 根据设备编号查询设备最新状态 + * + * @param deviceNum 设备编号 + * @return 设备状态 + */ + public IotDeviceStatus selectIotDeviceStatusByDeviceNum(String deviceNum); + /** * 查询设备状态列表 * diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotGroupService.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotGroupService.java new file mode 100644 index 00000000..6705b446 --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/IIotGroupService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.IotGroup; + +/** + * 分组Service接口 + * + * @author kerwincui + * @date 2021-05-18 + */ +public interface IIotGroupService +{ + /** + * 查询分组 + * + * @param groupId 分组ID + * @return 分组 + */ + public IotGroup selectIotGroupById(Long groupId); + + /** + * 查询分组列表 + * + * @param iotGroup 分组 + * @return 分组集合 + */ + public List selectIotGroupList(IotGroup iotGroup); + + /** + * 新增分组 + * + * @param iotGroup 分组 + * @return 结果 + */ + public int insertIotGroup(IotGroup iotGroup); + + /** + * 修改分组 + * + * @param iotGroup 分组 + * @return 结果 + */ + public int updateIotGroup(IotGroup iotGroup); + + /** + * 批量删除分组 + * + * @param groupIds 需要删除的分组ID + * @return 结果 + */ + public int deleteIotGroupByIds(Long[] groupIds); + + /** + * 删除分组信息 + * + * @param groupId 分组ID + * @return 结果 + */ + public int deleteIotGroupById(Long groupId); +} diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceServiceImpl.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceServiceImpl.java index eb1b4a33..d565daa1 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceServiceImpl.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl; import java.util.List; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.system.domain.vo.IotDeviceListDto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.IotDeviceMapper; @@ -32,6 +33,18 @@ public class IotDeviceServiceImpl implements IIotDeviceService return iotDeviceMapper.selectIotDeviceById(deviceId); } + /** + * 根据编号查询设备 + * + * @param deviceNum 设备编号 + * @return 设备 + */ + @Override + public IotDevice selectIotDeviceByNum(String deviceNum) + { + return iotDeviceMapper.selectIotDeviceByNum(deviceNum); + } + /** * 查询设备列表 * @@ -39,7 +52,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService * @return 设备 */ @Override - public List selectIotDeviceList(IotDevice iotDevice) + public List selectIotDeviceList(IotDevice iotDevice) { return iotDeviceMapper.selectIotDeviceList(iotDevice); } diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceStatusServiceImpl.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceStatusServiceImpl.java index eeeba668..1fb94517 100644 --- a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceStatusServiceImpl.java +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotDeviceStatusServiceImpl.java @@ -44,6 +44,18 @@ public class IotDeviceStatusServiceImpl implements IIotDeviceStatusService return iotDeviceStatusMapper.selectIotDeviceStatusByDeviceId(deviceId); } + /** + * 根据设备编号查询最新设备状态 + * + * @param deviceNum 设备编号 + * @return 设备状态 + */ + @Override + public IotDeviceStatus selectIotDeviceStatusByDeviceNum(String deviceNum) + { + return iotDeviceStatusMapper.selectIotDeviceStatusByDeviceNum(deviceNum); + } + /** * 查询设备状态列表 * diff --git a/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotGroupServiceImpl.java b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotGroupServiceImpl.java new file mode 100644 index 00000000..35c0cd93 --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/IotGroupServiceImpl.java @@ -0,0 +1,96 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import com.ruoyi.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.IotGroupMapper; +import com.ruoyi.system.domain.IotGroup; +import com.ruoyi.system.service.IIotGroupService; + +/** + * 分组Service业务层处理 + * + * @author kerwincui + * @date 2021-05-18 + */ +@Service +public class IotGroupServiceImpl implements IIotGroupService +{ + @Autowired + private IotGroupMapper iotGroupMapper; + + /** + * 查询分组 + * + * @param groupId 分组ID + * @return 分组 + */ + @Override + public IotGroup selectIotGroupById(Long groupId) + { + return iotGroupMapper.selectIotGroupById(groupId); + } + + /** + * 查询分组列表 + * + * @param iotGroup 分组 + * @return 分组 + */ + @Override + public List selectIotGroupList(IotGroup iotGroup) + { + return iotGroupMapper.selectIotGroupList(iotGroup); + } + + /** + * 新增分组 + * + * @param iotGroup 分组 + * @return 结果 + */ + @Override + public int insertIotGroup(IotGroup iotGroup) + { + iotGroup.setCreateTime(DateUtils.getNowDate()); + return iotGroupMapper.insertIotGroup(iotGroup); + } + + /** + * 修改分组 + * + * @param iotGroup 分组 + * @return 结果 + */ + @Override + public int updateIotGroup(IotGroup iotGroup) + { + iotGroup.setUpdateTime(DateUtils.getNowDate()); + return iotGroupMapper.updateIotGroup(iotGroup); + } + + /** + * 批量删除分组 + * + * @param groupIds 需要删除的分组ID + * @return 结果 + */ + @Override + public int deleteIotGroupByIds(Long[] groupIds) + { + return iotGroupMapper.deleteIotGroupByIds(groupIds); + } + + /** + * 删除分组信息 + * + * @param groupId 分组ID + * @return 结果 + */ + @Override + public int deleteIotGroupById(Long groupId) + { + return iotGroupMapper.deleteIotGroupById(groupId); + } +} diff --git a/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceMapper.xml b/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceMapper.xml index e157339f..48ecafb7 100644 --- a/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceMapper.xml +++ b/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceMapper.xml @@ -18,14 +18,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + + + + + + + select device_id, device_num, category_id, device_name, firmware_version, owner_id, create_by, create_time, update_by, update_time, remark from iot_device - + - del_flag= '0' + d.del_flag= '0' and device_num like concat('%', #{deviceNum}, '%') and category_id = #{categoryId} and device_name like concat('%', #{deviceName}, '%') @@ -39,6 +71,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where device_id = #{deviceId} + + insert into iot_device diff --git a/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceSetMapper.xml b/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceSetMapper.xml index ed41275b..285a1b15 100644 --- a/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceSetMapper.xml +++ b/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotDeviceSetMapper.xml @@ -13,6 +13,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + @@ -23,6 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -31,7 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select device_set_id, device_id, device_num, is_alarm, is_radar, is_host, is_reset, is_ap, is_rf_control, is_rf_learn, is_rf_clear, rf_one_func, rf_two_func, rf_three_func, rf_four_func, owner_id, network_address, network_ip, create_by, create_time, update_by, update_time, remark from iot_device_set + select device_set_id, device_id, device_num, is_alarm, is_radar, is_host, is_reset, is_ap, is_wifi_offline, is_open_certifi, is_smart_config, is_rf_control, is_rf_learn, is_rf_clear, rf_one_func, rf_two_func, rf_three_func, rf_four_func, owner_id, network_address, network_ip,radar_interval, create_by, create_time, update_by, update_time, remark from iot_device_set @@ -45,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and trigger_source = #{triggerSource} and create_time between #{params.beginCreateTime} and #{params.endCreateTime} + order by create_time desc + + insert into iot_device_status @@ -68,13 +77,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" light_status, is_online, device_temperature, - device_humidity, + rssi, air_temperature, air_humidity, trigger_source, brightness, light_interval, light_mode, + fade_time, red, green, blue, @@ -91,13 +101,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{lightStatus}, #{isOnline}, #{deviceTemperature}, - #{deviceHumidity}, + #{rssi}, #{airTemperature}, #{airHumidity}, #{triggerSource}, #{brightness}, #{lightInterval}, #{lightMode}, + #{fadeTime}, #{red}, #{green}, #{blue}, @@ -118,13 +129,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" light_status = #{lightStatus}, is_online = #{isOnline}, device_temperature = #{deviceTemperature}, - device_humidity = #{deviceHumidity}, + rssi = #{rssi}, air_temperature = #{airTemperature}, air_humidity = #{airHumidity}, trigger_source = #{triggerSource}, brightness = #{brightness}, light_interval = #{lightInterval}, light_mode = #{lightMode}, + fade_time = #{fadeTime}, red = #{red}, green = #{green}, blue = #{blue}, diff --git a/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotGroupMapper.xml b/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotGroupMapper.xml new file mode 100644 index 00000000..ec7a4b74 --- /dev/null +++ b/spring-boot/ruoyi-system/src/main/resources/mapper/system/IotGroupMapper.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + select group_id, user_id, group_name, group_order, del_flag, create_by, create_time, update_by, update_time, remark from iot_group + + + + + + + + insert into iot_group + + user_id, + group_name, + group_order, + del_flag, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{userId}, + #{groupName}, + #{groupOrder}, + #{delFlag}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update iot_group + + user_id = #{userId}, + group_name = #{groupName}, + group_order = #{groupOrder}, + del_flag = #{delFlag}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where group_id = #{groupId} + + + + delete from iot_group where group_id = #{groupId} + + + + delete from iot_group where group_id in + + #{groupId} + + + \ No newline at end of file