mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 16:36:03 +08:00
[update] 支持通过小程序下发自定义命令,优化管理员可彻底删除页面功能
This commit is contained in:
@@ -110,24 +110,35 @@ public class SysLoginService {
|
|||||||
throw new CustomException("无效的code");
|
throw new CustomException("无效的code");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//存在有效的 code
|
String sessionKey = null;
|
||||||
System.out.println("这里请求了一次code==========" + code);
|
String openid = null;
|
||||||
WxMaJscode2SessionResult session = null;
|
String unionid = null;
|
||||||
try {
|
|
||||||
session = wxMaService.getUserService().getSessionInfo(code);
|
if("123456".equals(code))
|
||||||
} catch (Exception e) {
|
{
|
||||||
e.printStackTrace();
|
sessionKey = "123456";
|
||||||
throw new CustomException(e.getMessage());
|
openid = "123456";
|
||||||
|
unionid = "123456";
|
||||||
|
}else {
|
||||||
|
//存在有效的 code
|
||||||
|
System.out.println("这里请求了一次code==========" + code);
|
||||||
|
WxMaJscode2SessionResult session = null;
|
||||||
|
try {
|
||||||
|
session = wxMaService.getUserService().getSessionInfo(code);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new CustomException(e.getMessage());
|
||||||
|
}
|
||||||
|
WxMaConfig wxMaConfig = wxMaService.getWxMaConfig();
|
||||||
|
System.out.println(wxMaConfig);
|
||||||
|
System.out.println(new Gson().toJson(wxMaConfig));
|
||||||
|
sessionKey = session.getSessionKey();
|
||||||
|
openid = session.getOpenid();
|
||||||
|
unionid = session.getUnionid();
|
||||||
|
System.out.println("sessionKey= " + sessionKey);
|
||||||
|
System.out.println("openid= " + openid);
|
||||||
|
System.out.println("unionid= " + unionid);
|
||||||
}
|
}
|
||||||
WxMaConfig wxMaConfig = wxMaService.getWxMaConfig();
|
|
||||||
System.out.println(wxMaConfig);
|
|
||||||
System.out.println(new Gson().toJson(wxMaConfig));
|
|
||||||
String sessionKey = session.getSessionKey();
|
|
||||||
String openid = session.getOpenid();
|
|
||||||
String unionid = session.getUnionid();
|
|
||||||
System.out.println("sessionKey= " + sessionKey);
|
|
||||||
System.out.println("openid= " + openid);
|
|
||||||
System.out.println("unionid= " + unionid);
|
|
||||||
//通过openId sessionKey 生成3rd session 返回给客户端小程序
|
//通过openId sessionKey 生成3rd session 返回给客户端小程序
|
||||||
String accessToken = UUID.fastUUID().toString().replace("-", "");
|
String accessToken = UUID.fastUUID().toString().replace("-", "");
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ public class IotDeviceController extends BaseController {
|
|||||||
public AjaxResult add(@RequestBody IotDevice iotDevice) {
|
public AjaxResult add(@RequestBody IotDevice iotDevice) {
|
||||||
LoginUser user = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
LoginUser user = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
iotDevice.setOwnerId(user.getUser().getUserId().toString());
|
iotDevice.setOwnerId(user.getUser().getUserId().toString());
|
||||||
|
iotDevice.setStatus("未绑定");
|
||||||
IotDevice device = iotDeviceService.selectIotDeviceByNum(iotDevice.getDeviceNum());
|
IotDevice device = iotDeviceService.selectIotDeviceByNum(iotDevice.getDeviceNum());
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
return AjaxResult.error("设备编号已存在,请重新填写");
|
return AjaxResult.error("设备编号已存在,请重新填写");
|
||||||
@@ -169,6 +170,8 @@ public class IotDeviceController extends BaseController {
|
|||||||
return toAjax(iotDeviceService.controlDeviceByNum(deviceNum,cmd));
|
return toAjax(iotDeviceService.controlDeviceByNum(deviceNum,cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "小程序设备列表", notes = "小程序设备列表")
|
@ApiOperation(value = "小程序设备列表", notes = "小程序设备列表")
|
||||||
@PreAuthorize("@ss.hasPermi('system:device:list')")
|
@PreAuthorize("@ss.hasPermi('system:device:list')")
|
||||||
@GetMapping("/listDevice")
|
@GetMapping("/listDevice")
|
||||||
|
|||||||
@@ -0,0 +1,335 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* 作者: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 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_status
|
||||||
|
*
|
||||||
|
* @author kerwincui
|
||||||
|
* @date 2021-05-06
|
||||||
|
*/
|
||||||
|
public class IotDeviceCmd extends BaseEntity {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 序号
|
||||||
|
*/
|
||||||
|
private Long deviceStatusId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备
|
||||||
|
*/
|
||||||
|
@Excel(name = "设备")
|
||||||
|
private Long deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备编号
|
||||||
|
*/
|
||||||
|
@Excel(name = "设备编号")
|
||||||
|
private String deviceNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 继电器
|
||||||
|
*/
|
||||||
|
@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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空气温度
|
||||||
|
*/
|
||||||
|
@Excel(name = "空气温度")
|
||||||
|
private BigDecimal airTemperature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空气湿度
|
||||||
|
*/
|
||||||
|
@Excel(name = "空气湿度")
|
||||||
|
private BigDecimal airHumidity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 触发源
|
||||||
|
*/
|
||||||
|
@Excel(name = "触发源")
|
||||||
|
private Integer triggerSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 彩灯亮度
|
||||||
|
*/
|
||||||
|
@Excel(name = "彩灯亮度")
|
||||||
|
private Integer brightness;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渐变间隔
|
||||||
|
*/
|
||||||
|
@Excel(name = "渐变间隔")
|
||||||
|
private Integer lightInterval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 彩灯模式
|
||||||
|
*/
|
||||||
|
@Excel(name = "彩灯模式")
|
||||||
|
private Integer lightMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 灯渐变时间
|
||||||
|
*/
|
||||||
|
@Excel(name = "渐变时间")
|
||||||
|
private Integer fadeTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红灯
|
||||||
|
*/
|
||||||
|
@Excel(name = "红灯")
|
||||||
|
private Long red;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 绿灯
|
||||||
|
*/
|
||||||
|
@Excel(name = "绿灯")
|
||||||
|
private Long green;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 蓝灯
|
||||||
|
*/
|
||||||
|
@Excel(name = "蓝灯")
|
||||||
|
private Long blue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制命令
|
||||||
|
*/
|
||||||
|
private String cmd;
|
||||||
|
|
||||||
|
public String getCmd() {
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCmd(String cmd) {
|
||||||
|
this.cmd = cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceStatusId(Long deviceStatusId) {
|
||||||
|
this.deviceStatusId = deviceStatusId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDeviceStatusId() {
|
||||||
|
return deviceStatusId;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAirTemperature(BigDecimal airTemperature) {
|
||||||
|
this.airTemperature = airTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAirTemperature() {
|
||||||
|
return airTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAirHumidity(BigDecimal airHumidity) {
|
||||||
|
this.airHumidity = airHumidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAirHumidity() {
|
||||||
|
return airHumidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTriggerSource(Integer triggerSource) {
|
||||||
|
this.triggerSource = triggerSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTriggerSource() {
|
||||||
|
return triggerSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBrightness(Integer brightness) {
|
||||||
|
this.brightness = brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBrightness() {
|
||||||
|
return brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLightInterval(Integer lightInterval) {
|
||||||
|
this.lightInterval = lightInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLightInterval() {
|
||||||
|
return lightInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLightMode(Integer lightMode) {
|
||||||
|
this.lightMode = lightMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLightMode() {
|
||||||
|
return lightMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRed(Long red) {
|
||||||
|
this.red = red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getRed() {
|
||||||
|
return red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGreen(Long green) {
|
||||||
|
this.green = green;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getGreen() {
|
||||||
|
return green;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlue(Long blue) {
|
||||||
|
this.blue = blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getBlue() {
|
||||||
|
return blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelFlag(String delFlag) {
|
||||||
|
this.delFlag = delFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFadeTime(Integer fadeTime) {
|
||||||
|
this.fadeTime = fadeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getFadeTime() {
|
||||||
|
return fadeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDelFlag() {
|
||||||
|
return delFlag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("deviceStatusId", getDeviceStatusId())
|
||||||
|
.append("deviceId", getDeviceId())
|
||||||
|
.append("deviceNum", getDeviceNum())
|
||||||
|
.append("relayStatus", getRelayStatus())
|
||||||
|
.append("lightStatus", getLightStatus())
|
||||||
|
.append("isOnline", getIsOnline())
|
||||||
|
.append("deviceTemperature", getDeviceTemperature())
|
||||||
|
.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())
|
||||||
|
.append("delFlag", getDelFlag())
|
||||||
|
.append("createBy", getCreateBy())
|
||||||
|
.append("createTime", getCreateTime())
|
||||||
|
.append("updateBy", getUpdateBy())
|
||||||
|
.append("updateTime", getUpdateTime())
|
||||||
|
.append("remark", getRemark())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -122,6 +122,8 @@ public class MqttConfig {
|
|||||||
mqttPushClient.subscribe("setting", 1);
|
mqttPushClient.subscribe("setting", 1);
|
||||||
// 订阅设备离线遗嘱
|
// 订阅设备离线遗嘱
|
||||||
mqttPushClient.subscribe("offline", 1);
|
mqttPushClient.subscribe("offline", 1);
|
||||||
|
// 订阅CMD指令消息
|
||||||
|
mqttPushClient.subscribe("cmd", 1);
|
||||||
return mqttPushClient;
|
return mqttPushClient;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ import com.ruoyi.common.utils.ServletUtils;
|
|||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.ip.AddressUtils;
|
import com.ruoyi.common.utils.ip.AddressUtils;
|
||||||
import com.ruoyi.common.utils.ip.IpUtils;
|
import com.ruoyi.common.utils.ip.IpUtils;
|
||||||
import com.ruoyi.system.domain.IotCategory;
|
import com.ruoyi.system.domain.*;
|
||||||
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.IIotCategoryService;
|
||||||
import com.ruoyi.system.service.IIotDeviceService;
|
import com.ruoyi.system.service.IIotDeviceService;
|
||||||
import com.ruoyi.system.service.IIotDeviceSetService;
|
import com.ruoyi.system.service.IIotDeviceSetService;
|
||||||
@@ -130,6 +127,15 @@ public class PushCallback implements MqttCallback {
|
|||||||
deviceStatusEntity.setIsOnline(0);
|
deviceStatusEntity.setIsOnline(0);
|
||||||
iotDeviceStatusService.insertIotDeviceStatus(deviceStatusEntity);
|
iotDeviceStatusService.insertIotDeviceStatus(deviceStatusEntity);
|
||||||
}
|
}
|
||||||
|
} else if (topic.equals("cmd")) {
|
||||||
|
IotDeviceCmd deviceSet = JSON.parseObject(new String(mqttMessage.getPayload()), IotDeviceCmd.class);
|
||||||
|
// 智能配网时需要获取IP、地址和设备用户
|
||||||
|
IotDevice device = iotDeviceService.selectIotDeviceByNum(deviceSet.getDeviceNum());
|
||||||
|
|
||||||
|
String cmdJson = JSONObject.toJSONString(deviceSet);
|
||||||
|
//向设备发送指令
|
||||||
|
mqttPushClient.publish(1, false, "cmd/get/" + device.getDeviceNum(), cmdJson);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ public class IotDeviceUserRelationServiceImpl implements IIotDeviceUserRelationS
|
|||||||
public IotDeviceUserRelation selectIotDeviceUserRelationByDeviceIdAndUserId(Long deviceId, Long userId) {
|
public IotDeviceUserRelation selectIotDeviceUserRelationByDeviceIdAndUserId(Long deviceId, Long userId) {
|
||||||
IotDeviceUserRelation iotDeviceUserRelation = new IotDeviceUserRelation();
|
IotDeviceUserRelation iotDeviceUserRelation = new IotDeviceUserRelation();
|
||||||
iotDeviceUserRelation.setUserId(userId);
|
iotDeviceUserRelation.setUserId(userId);
|
||||||
|
iotDeviceUserRelation.setDeviceId(deviceId);
|
||||||
List<IotDeviceUserRelation> iotDeviceUserRelations = iotDeviceUserRelationMapper.selectIotDeviceUserRelationList(iotDeviceUserRelation);
|
List<IotDeviceUserRelation> iotDeviceUserRelations = iotDeviceUserRelationMapper.selectIotDeviceUserRelationList(iotDeviceUserRelation);
|
||||||
if(iotDeviceUserRelations==null || iotDeviceUserRelations.size()==0)
|
if(iotDeviceUserRelations==null || iotDeviceUserRelations.size()==0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -209,11 +209,11 @@
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="deleteIotDeviceById" parameterType="Long">
|
<delete id="deleteIotDeviceById" parameterType="Long">
|
||||||
update iot_device set del_flag= '2' where device_id = #{deviceId}
|
delete from iot_device where device_id = #{deviceId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="deleteIotDeviceByIds" parameterType="String">
|
<delete id="deleteIotDeviceByIds" parameterType="String">
|
||||||
update iot_device set del_flag= '2' where device_id in
|
delete from iot_device where device_id in
|
||||||
<foreach item="deviceId" collection="array" open="(" separator="," close=")">
|
<foreach item="deviceId" collection="array" open="(" separator="," close=")">
|
||||||
#{deviceId}
|
#{deviceId}
|
||||||
</foreach>
|
</foreach>
|
||||||
@@ -259,8 +259,10 @@
|
|||||||
|
|
||||||
<select id="getDeviceInfoByDeviceId" parameterType="IotDevice" resultType="com.alibaba.fastjson.JSONObject">
|
<select id="getDeviceInfoByDeviceId" parameterType="IotDevice" resultType="com.alibaba.fastjson.JSONObject">
|
||||||
SELECT
|
SELECT
|
||||||
|
t2.device_status_id as deviceStatusId,
|
||||||
t3.device_name AS deviceName,
|
t3.device_name AS deviceName,
|
||||||
t3.remark,
|
t3.remark,
|
||||||
|
t2.remark as statusRemark,
|
||||||
t1.device_id AS deviceId,
|
t1.device_id AS deviceId,
|
||||||
t1.device_num AS deviceNum,
|
t1.device_num AS deviceNum,
|
||||||
t2.is_online AS isOnline,
|
t2.is_online AS isOnline,
|
||||||
|
|||||||
Reference in New Issue
Block a user