mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
后端V1.0
This commit is contained in:
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,9 +1,21 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.system.domain.IotDeviceStatus;
|
||||
import com.ruoyi.system.mqtt.config.MqttPushClient;
|
||||
import com.ruoyi.system.service.IIotDeviceStatusService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -38,6 +50,8 @@ public class IotDeviceSetController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IIotDeviceSetService iotDeviceSetService;
|
||||
@Autowired
|
||||
private IIotDeviceStatusService iotDeviceStatusService;
|
||||
|
||||
@Autowired
|
||||
private MqttPushClient mqttPushClient;
|
||||
@@ -112,11 +126,51 @@ public class IotDeviceSetController extends BaseController
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody IotDeviceSet iotDeviceSet)
|
||||
{
|
||||
IotDeviceStatus status=iotDeviceStatusService.selectIotDeviceStatusByDeviceId(iotDeviceSet.getDeviceId());
|
||||
if(status.getIsOnline()!=1){return AjaxResult.error("设备已离线,不能更新配置。");}
|
||||
// 存储
|
||||
iotDeviceSetService.updateIotDeviceSet(iotDeviceSet);
|
||||
// mqtt发布
|
||||
String content = JSON.toJSONString(iotDeviceSet);
|
||||
boolean isSuccess=mqttPushClient.publish(0,true,"setting/set/"+iotDeviceSet.getDeviceNum(),content);
|
||||
|
||||
//
|
||||
IotDeviceSet set=iotDeviceSetService.selectIotDeviceSetByDeviceId(iotDeviceSet.getDeviceId());
|
||||
if(iotDeviceSet.getIsRadar()!=null){
|
||||
set.setIsRadar(iotDeviceSet.getIsRadar());
|
||||
}
|
||||
if(iotDeviceSet.getIsAlarm()!=null){
|
||||
set.setIsAlarm(iotDeviceSet.getIsAlarm());
|
||||
}
|
||||
if(iotDeviceSet.getRadarInterval()!=null){
|
||||
set.setRadarInterval(iotDeviceSet.getRadarInterval());
|
||||
}
|
||||
if(iotDeviceSet.getIsRfControl()!=null){
|
||||
set.setIsRfControl(iotDeviceSet.getIsRfControl());
|
||||
}
|
||||
if(iotDeviceSet.getRfOneFunc()!=null){
|
||||
set.setRfOneFunc(iotDeviceSet.getRfOneFunc());
|
||||
}
|
||||
if(iotDeviceSet.getRfTwoFunc()!=null){
|
||||
set.setRfTwoFunc(iotDeviceSet.getRfTwoFunc());
|
||||
}
|
||||
if(iotDeviceSet.getRfThreeFunc()!=null){
|
||||
set.setRfThreeFunc(iotDeviceSet.getRfThreeFunc());
|
||||
}
|
||||
if(iotDeviceSet.getRfFourFunc()!=null){
|
||||
set.setRfFourFunc(iotDeviceSet.getRfFourFunc());
|
||||
}
|
||||
if(iotDeviceSet.getIsRfLearn()!=null){
|
||||
set.setIsRfLearn(iotDeviceSet.getIsRfLearn());
|
||||
}
|
||||
if(iotDeviceSet.getIsRfClear()!=null){
|
||||
set.setIsRfClear(iotDeviceSet.getIsRfClear());
|
||||
}
|
||||
if(iotDeviceSet.getIsAp()!=null){
|
||||
set.setIsAp(iotDeviceSet.getIsAp());
|
||||
}
|
||||
if(iotDeviceSet.getIsReset()!=null){
|
||||
set.setIsReset(iotDeviceSet.getIsReset());
|
||||
}
|
||||
String content = JSON.toJSONString(set);
|
||||
boolean isSuccess=mqttPushClient.publish(0,true,"setting/set/"+set.getDeviceNum(),content);
|
||||
if(isSuccess){return AjaxResult.success("mqtt 发布成功");}
|
||||
return AjaxResult.error("mqtt 发布失败。");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
@@ -123,12 +133,43 @@ public class IotDeviceStatusController extends BaseController
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody IotDeviceStatus iotDeviceStatus)
|
||||
{
|
||||
IotDeviceStatus status=iotDeviceStatusService.selectIotDeviceStatusByDeviceId(iotDeviceStatus.getDeviceId());
|
||||
if(status.getIsOnline()!=1){return AjaxResult.error("设备已离线,不能更新状态。");}
|
||||
// 存储
|
||||
iotDeviceStatusService.updateIotDeviceStatus(iotDeviceStatus);
|
||||
|
||||
// mqtt发布
|
||||
String content = JSON.toJSONString(iotDeviceStatus);
|
||||
boolean isSuccess=mqttPushClient.publish(1,true,"status/set/"+iotDeviceStatus.getDeviceNum(),content);
|
||||
if(iotDeviceStatus.getRelayStatus()!=null){
|
||||
status.setRelayStatus(iotDeviceStatus.getRelayStatus());
|
||||
}
|
||||
if(iotDeviceStatus.getLightStatus()!=null){
|
||||
status.setLightStatus(iotDeviceStatus.getLightStatus());
|
||||
}
|
||||
if(iotDeviceStatus.getLightMode()!=null){
|
||||
status.setLightMode(iotDeviceStatus.getLightMode());
|
||||
}
|
||||
if(iotDeviceStatus.getLightInterval()!=null){
|
||||
status.setLightInterval(iotDeviceStatus.getLightInterval());
|
||||
}
|
||||
if(iotDeviceStatus.getFadeTime()!=null){
|
||||
status.setFadeTime(iotDeviceStatus.getFadeTime());
|
||||
}
|
||||
if(iotDeviceStatus.getBrightness()!=null){
|
||||
status.setBrightness(iotDeviceStatus.getBrightness());
|
||||
}
|
||||
if(iotDeviceStatus.getRed()!=null){
|
||||
status.setRed(iotDeviceStatus.getRed());
|
||||
}
|
||||
if(iotDeviceStatus.getGreen()!=null){
|
||||
status.setGreen(iotDeviceStatus.getGreen());
|
||||
}
|
||||
if(iotDeviceStatus.getBlue()!=null){
|
||||
status.setBlue(iotDeviceStatus.getBlue());
|
||||
}
|
||||
String content = JSON.toJSONString(status);
|
||||
boolean isSuccess=mqttPushClient.publish(1,true,"status/set/"+status.getDeviceNum(),content);
|
||||
if(isSuccess){return AjaxResult.success("mqtt 发布成功");}
|
||||
|
||||
return AjaxResult.error("mqtt 发布失败。");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -22,41 +32,41 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
@RequestMapping("/system/mqtt")
|
||||
public class MqttController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private MqttPushClient mqttPushClient;
|
||||
|
||||
@ApiOperation(value = "更新设备状态", notes = "更新设备状态")
|
||||
@PostMapping(value = "/updateStatus")
|
||||
public AjaxResult updateStatus(@RequestBody IotDeviceStatus iotDeviceStatus){
|
||||
String content = JSON.toJSONString(iotDeviceStatus);
|
||||
boolean isSuccess=mqttPushClient.publish(1,false,"status/set/"+iotDeviceStatus.getDeviceNum(),content);
|
||||
if(isSuccess){return AjaxResult.success();}
|
||||
return AjaxResult.error("mqtt 发布失败。");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取设备状态", notes = "获取设备状态")
|
||||
@GetMapping(value = "/getStatus/{deviceNum}")
|
||||
public AjaxResult getStatus(@PathVariable("deviceNum") String deviceNum){
|
||||
boolean isSuccess=mqttPushClient.publish(0,false,"status/get/"+deviceNum,"wumei.live");
|
||||
if(isSuccess){return AjaxResult.success();}
|
||||
return AjaxResult.error("mqtt 发布失败。");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新设备配置", notes = "更新设备配置")
|
||||
@PostMapping(value = "/updateSetting")
|
||||
public AjaxResult updateSetting(@RequestBody IotDeviceSet iotDeviceSet){
|
||||
String content = JSON.toJSONString(iotDeviceSet);
|
||||
boolean isSuccess=mqttPushClient.publish(0,false,"setting/set/"+iotDeviceSet.getDeviceNum(),content);
|
||||
if(isSuccess){return AjaxResult.success();}
|
||||
return AjaxResult.error("mqtt 发布失败。");
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取设备配置", notes = "获取设备配置")
|
||||
@GetMapping(value = "/getSetting/{deviceNum}")
|
||||
public AjaxResult getSetting(@PathVariable("deviceNum") String deviceNum){
|
||||
boolean isSuccess=mqttPushClient.publish(0,false,"setting/get/"+deviceNum,"wumei.lie");
|
||||
if(isSuccess){return AjaxResult.success();}
|
||||
return AjaxResult.error("mqtt 发布失败。");
|
||||
}
|
||||
// @Autowired
|
||||
// private MqttPushClient mqttPushClient;
|
||||
//
|
||||
// @ApiOperation(value = "更新设备状态", notes = "更新设备状态")
|
||||
// @PostMapping(value = "/updateStatus")
|
||||
// public AjaxResult updateStatus(@RequestBody IotDeviceStatus iotDeviceStatus){
|
||||
// String content = JSON.toJSONString(iotDeviceStatus);
|
||||
// boolean isSuccess=mqttPushClient.publish(1,false,"status/set/"+iotDeviceStatus.getDeviceNum(),content);
|
||||
// if(isSuccess){return AjaxResult.success();}
|
||||
// return AjaxResult.error("mqtt 发布失败。");
|
||||
// }
|
||||
//
|
||||
// @ApiOperation(value = "获取设备状态", notes = "获取设备状态")
|
||||
// @GetMapping(value = "/getStatus/{deviceNum}")
|
||||
// public AjaxResult getStatus(@PathVariable("deviceNum") String deviceNum){
|
||||
// boolean isSuccess=mqttPushClient.publish(0,false,"status/get/"+deviceNum,"wumei.live");
|
||||
// if(isSuccess){return AjaxResult.success();}
|
||||
// return AjaxResult.error("mqtt 发布失败。");
|
||||
// }
|
||||
//
|
||||
// @ApiOperation(value = "更新设备配置", notes = "更新设备配置")
|
||||
// @PostMapping(value = "/updateSetting")
|
||||
// public AjaxResult updateSetting(@RequestBody IotDeviceSet iotDeviceSet){
|
||||
// String content = JSON.toJSONString(iotDeviceSet);
|
||||
// boolean isSuccess=mqttPushClient.publish(0,false,"setting/set/"+iotDeviceSet.getDeviceNum(),content);
|
||||
// if(isSuccess){return AjaxResult.success();}
|
||||
// return AjaxResult.error("mqtt 发布失败。");
|
||||
// }
|
||||
//
|
||||
// @ApiOperation(value = "获取设备配置", notes = "获取设备配置")
|
||||
// @GetMapping(value = "/getSetting/{deviceNum}")
|
||||
// public AjaxResult getSetting(@PathVariable("deviceNum") String deviceNum){
|
||||
// boolean isSuccess=mqttPushClient.publish(0,false,"setting/get/"+deviceNum,"wumei.lie");
|
||||
// if(isSuccess){return AjaxResult.success();}
|
||||
// return AjaxResult.error("mqtt 发布失败。");
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
@@ -5,6 +15,8 @@ import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 设备对象 iot_device
|
||||
*
|
||||
@@ -26,6 +38,14 @@ public class IotDevice extends BaseEntity
|
||||
@Excel(name = "分类")
|
||||
private Long categoryId;
|
||||
|
||||
/** 分类名称 */
|
||||
@Excel(name = "分类名称")
|
||||
private String categoryName;
|
||||
|
||||
/** 分类名称 */
|
||||
@Excel(name = "分类名称")
|
||||
private BigDecimal deviceTemp;
|
||||
|
||||
/** 名称 */
|
||||
@Excel(name = "名称")
|
||||
private String deviceName;
|
||||
@@ -38,6 +58,9 @@ public class IotDevice extends BaseEntity
|
||||
@Excel(name = "用户")
|
||||
private String ownerId;
|
||||
|
||||
/** 分组ID */
|
||||
private Long groupId;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
@@ -45,7 +68,6 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Long getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
@@ -54,7 +76,6 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.deviceNum = deviceNum;
|
||||
}
|
||||
|
||||
public String getDeviceNum()
|
||||
{
|
||||
return deviceNum;
|
||||
@@ -63,7 +84,6 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.categoryId = categoryId;
|
||||
}
|
||||
|
||||
public Long getCategoryId()
|
||||
{
|
||||
return categoryId;
|
||||
@@ -72,7 +92,6 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getDeviceName()
|
||||
{
|
||||
return deviceName;
|
||||
@@ -81,7 +100,6 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.firmwareVersion = firmwareVersion;
|
||||
}
|
||||
|
||||
public String getFirmwareVersion()
|
||||
{
|
||||
return firmwareVersion;
|
||||
@@ -90,7 +108,6 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public String getOwnerId()
|
||||
{
|
||||
return ownerId;
|
||||
@@ -99,18 +116,44 @@ public class IotDevice extends BaseEntity
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
public Long getGroupId()
|
||||
{
|
||||
return groupId;
|
||||
}
|
||||
public void setGroupId(Long groupId)
|
||||
{
|
||||
this.groupId = groupId;
|
||||
}
|
||||
public void setDeviceTemp(BigDecimal deviceTemp)
|
||||
{
|
||||
this.deviceTemp = deviceTemp;
|
||||
}
|
||||
public BigDecimal getDeviceTemp()
|
||||
{
|
||||
return deviceTemp;
|
||||
}
|
||||
public void setCategoryName(String categoryName)
|
||||
{
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
public String getCategoryName()
|
||||
{
|
||||
return categoryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("deviceId", getDeviceId())
|
||||
.append("deviceNum", getDeviceNum())
|
||||
.append("categoryName", getCategoryName())
|
||||
.append("deviceTemp", getDeviceTemp())
|
||||
.append("categoryId", getCategoryId())
|
||||
.append("groupId", getGroupId())
|
||||
.append("deviceName", getDeviceName())
|
||||
.append("firmwareVersion", getFirmwareVersion())
|
||||
.append("ownerId", getOwnerId())
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.domain.vo;
|
||||
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
@@ -28,6 +38,10 @@ public class IotDeviceListDto extends BaseEntity
|
||||
@Excel(name = "分类")
|
||||
private Long categoryId;
|
||||
|
||||
/** 分类名称 */
|
||||
@Excel(name = "分类名称")
|
||||
private String categoryName;
|
||||
|
||||
/** 名称 */
|
||||
@Excel(name = "名称")
|
||||
private String deviceName;
|
||||
@@ -114,6 +128,14 @@ public class IotDeviceListDto extends BaseEntity
|
||||
{
|
||||
return categoryId;
|
||||
}
|
||||
public void setCategoryName(String categoryName)
|
||||
{
|
||||
this.categoryName = categoryName;
|
||||
}
|
||||
public String getCategoryName()
|
||||
{
|
||||
return categoryName;
|
||||
}
|
||||
public void setDeviceName(String deviceName)
|
||||
{
|
||||
this.deviceName = deviceName;
|
||||
@@ -243,6 +265,7 @@ public class IotDeviceListDto extends BaseEntity
|
||||
.append("deviceId", getDeviceId())
|
||||
.append("deviceNum", getDeviceNum())
|
||||
.append("categoryId", getCategoryId())
|
||||
.append("categoryName", getCategoryName())
|
||||
.append("deviceName", getDeviceName())
|
||||
.append("firmwareVersion", getFirmwareVersion())
|
||||
.append("ownerId", getOwnerId())
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.mqtt.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.mqtt.config;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/******************************************************************************
|
||||
* 作者:kerwincui
|
||||
* 时间:2021-06-08
|
||||
* 邮箱:164770707@qq.com
|
||||
* 源码地址:https://gitee.com/kerwincui/wumei-smart
|
||||
* author: kerwincui
|
||||
* create: 2021-06-08
|
||||
* email:164770707@qq.com
|
||||
* source:https://github.com/kerwincui/wumei-smart
|
||||
******************************************************************************/
|
||||
package com.ruoyi.system.mqtt.config;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -22,6 +32,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @Classname PushCallback
|
||||
@@ -72,7 +83,8 @@ public class PushCallback implements MqttCallback {
|
||||
}else {
|
||||
IotCategory categoryEntity=iotCategoryService.selectIotCategoryById(device.getCategoryId());
|
||||
if(device.getDeviceName()==null || device.getDeviceNum().length()==0) {
|
||||
device.setDeviceName(categoryEntity.getCategoryName());
|
||||
Random rand = new Random(); //随机生成两位数
|
||||
device.setDeviceName(categoryEntity.getCategoryName()+(rand.nextInt(90) + 10));
|
||||
}
|
||||
iotDeviceService.insertIotDevice(device);
|
||||
}
|
||||
@@ -89,13 +101,12 @@ public class PushCallback implements MqttCallback {
|
||||
}else if(topic.equals("setting")){
|
||||
IotDeviceSet deviceSet = JSON.parseObject(new String(mqttMessage.getPayload()), IotDeviceSet.class);
|
||||
// 智能配网时需要获取IP、地址和设备用户
|
||||
IotDevice device=null;
|
||||
IotDevice device=iotDeviceService.selectIotDeviceByNum(deviceSet.getDeviceNum());
|
||||
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);
|
||||
}
|
||||
@@ -103,14 +114,13 @@ public class PushCallback implements MqttCallback {
|
||||
deviceSet.setDeviceId(device.getDeviceId());
|
||||
iotDeviceSetService.insertIotDeviceSet(deviceSet);
|
||||
}else if(topic.equals("offline")){
|
||||
//离线遗嘱 TODO:查询待优化
|
||||
//离线遗嘱
|
||||
IotDeviceStatus deviceStatus = JSON.parseObject(new String(mqttMessage.getPayload()), IotDeviceStatus.class);
|
||||
IotDevice device=iotDeviceService.selectIotDeviceByNum(deviceStatus.getDeviceNum());
|
||||
IotDeviceStatus deviceStatusEntity=iotDeviceStatusService.selectIotDeviceStatusByDeviceId(device.getDeviceId());
|
||||
//跟新最近一条设备状态为离线
|
||||
IotDeviceStatus deviceStatusEntity=iotDeviceStatusService.selectIotDeviceStatusByDeviceNum(deviceStatus.getDeviceNum());
|
||||
//设备状态为离线
|
||||
if(deviceStatusEntity!=null) {
|
||||
deviceStatusEntity.setIsOnline(0);
|
||||
iotDeviceStatusService.updateIotDeviceStatus(deviceStatusEntity);
|
||||
iotDeviceStatusService.insertIotDeviceStatus(deviceStatusEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="deviceNum" column="device_num" />
|
||||
<result property="categoryId" column="category_id" />
|
||||
<result property="categoryName" column="category_Name" />
|
||||
<result property="deviceTemp" column="device_temp" />
|
||||
<result property="deviceName" column="device_name" />
|
||||
<result property="firmwareVersion" column="firmware_version" />
|
||||
<result property="ownerId" column="owner_id" />
|
||||
@@ -22,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="deviceNum" column="device_num" />
|
||||
<result property="categoryId" column="category_id" />
|
||||
<result property="categoryName" column="category_Name" />
|
||||
<result property="deviceName" column="device_name" />
|
||||
<result property="firmwareVersion" column="firmware_version" />
|
||||
<result property="ownerId" column="owner_id" />
|
||||
@@ -40,41 +43,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectIotDeviceVo">
|
||||
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
|
||||
select d.device_id, d.device_num, d.category_id, d.device_name, d.firmware_version, d.owner_id, d.create_by, d.create_time, d.update_by, d.update_time, d.remark,
|
||||
c.category_name,
|
||||
s.device_temperature as device_temp
|
||||
from iot_device d
|
||||
left join iot_category c on d.category_id=c.category_id
|
||||
left join (select device_id,device_temperature from iot_device_status
|
||||
right join (select max(device_status_id) as status_id from iot_device_status group by device_id) mt
|
||||
on mt.status_id=device_status_id ) as s
|
||||
on d.device_id=s.device_id
|
||||
</sql>
|
||||
|
||||
<sql id="selectIotDeviceListVo">
|
||||
select d.device_id, d.device_num, d.category_id, d.device_name, d.firmware_version, d.owner_id, d.create_time,
|
||||
s.relay_status,s.light_status,s.is_online,s.rssi,s.device_temperature,
|
||||
t.network_address, t.network_ip,t.is_alarm, t.is_radar,t.is_rf_control,
|
||||
u.nick_name
|
||||
u.nick_name,
|
||||
c.category_name
|
||||
<if test="groupId != null and groupId!=0">,g.group_id </if>
|
||||
from iot_device d
|
||||
left join (select * from iot_device_set order by create_time desc limit 1) as t on d.device_id = t.device_id
|
||||
left join (select * from iot_device_status order by create_time desc limit 1 ) as s on d.device_id=s.device_id
|
||||
left join (select * from iot_device_set
|
||||
right join (select max(device_set_id) as set_id from iot_device_set group by device_id) ms on ms.set_id=device_set_id ) as t
|
||||
on d.device_id = t.device_id
|
||||
left join (select * from iot_device_status
|
||||
right join (select max(device_status_id) as status_id from iot_device_status group by device_id) mt on mt.status_id=device_status_id ) as s
|
||||
on d.device_id=s.device_id
|
||||
left join sys_user u on d.owner_id=u.user_id
|
||||
left join iot_category c on d.category_id=c.category_id
|
||||
<if test="groupId != null and groupId!=0"> left join iot_device_group g on d.device_id=g.device_id </if>
|
||||
|
||||
</sql>
|
||||
|
||||
<select id="selectIotDeviceList" parameterType="IotDevice" resultMap="IotDeviceListResult">
|
||||
<include refid="selectIotDeviceListVo"/>
|
||||
<where>
|
||||
d.del_flag= '0'
|
||||
<if test="deviceNum != null and deviceNum != ''"> and device_num like concat('%', #{deviceNum}, '%')</if>
|
||||
<if test="categoryId != null "> and category_id = #{categoryId}</if>
|
||||
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
|
||||
<if test="firmwareVersion != null and firmwareVersion != ''"> and firmware_version like concat('%', #{firmwareVersion}, '%')</if>
|
||||
<if test="ownerId != null and ownerId != ''"> and owner_id like concat('%', #{ownerId}, '%')</if>
|
||||
<if test="deviceNum != null and deviceNum != ''"> and d.device_num like concat('%', #{deviceNum}, '%')</if>
|
||||
<if test="categoryId != null "> and d.category_id = #{categoryId}</if>
|
||||
<if test="groupId != null and groupId!=0 "> and g.group_id = #{groupId}</if>
|
||||
<if test="deviceName != null and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
|
||||
<if test="firmwareVersion != null and firmwareVersion != ''"> and d.firmware_version like concat('%', #{firmwareVersion}, '%')</if>
|
||||
<if test="ownerId != null and ownerId != ''"> and d.owner_id like concat('%', #{ownerId}, '%')</if>
|
||||
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectIotDeviceById" parameterType="Long" resultMap="IotDeviceResult">
|
||||
<include refid="selectIotDeviceVo"/>
|
||||
where device_id = #{deviceId}
|
||||
where d.device_id = #{deviceId}
|
||||
</select>
|
||||
|
||||
<select id="selectIotDeviceByNum" parameterType="String" resultMap="IotDeviceResult">
|
||||
<include refid="selectIotDeviceVo"/>
|
||||
where device_num = #{deviceNum}
|
||||
where d.device_num = #{deviceNum}
|
||||
</select>
|
||||
|
||||
<insert id="insertIotDevice" parameterType="IotDevice" useGeneratedKeys="true" keyProperty="deviceId">
|
||||
|
||||
Reference in New Issue
Block a user