Commit 95cfbcd7 by YG8999

设备网关代码

parent 32e8377d
package share.common.constant;
import cn.hutool.core.collection.CollUtil;
import java.util.ArrayList;
import java.util.List;
/**
* @className: share.common.constant.MqttConstants
* @description: MQTT 服务变量
* @author: lwj
* @create: 2023-11-03 15:51
*/
public class MqttConstants {
/**
* 动作: 请求端为req
*/
public static final String MQTT_AC_REQ = "req";
/**
* 动作: 回复端为resp
*/
public static final String MQTT_AC_RESP = "resp";
/**
* 操作命令: locklist, 网关设备列表操作
*/
public static final String MQTT_OP_LOCKLIST = "locklist";
/**
* 操作命令: opencloselock, 锁开门操作
*/
public static final String MQTT_OP_OPENCLOSELOCK = "opencloselock";
/**
* 数据流转方式,s2d:服务向设备请求
*/
public static final String MQTT_MODE_S2D = "s2d";
/**
* 数据流转方式, d2s:设备向服务请求
*/
public static final String MQTT_MODE_D2S = "d2s";
/**
* 消息方式: 下发
*/
public static final String MQTT_TYPE_1 = "1";
/**
* 消息方式: 上报
*/
public static final String MQTT_TYPE_2 = "2";
/**
* mqtt消息描述: 清除网关锁id列表
*/
public static final String MQTT_DESCRIBE_GATEWAY_CLEAR = "清除网关锁id列表";
/**
* mqtt消息描述: 清除网关锁id列表
*/
public static final String MQTT_DESCRIBE_GATEWAY_ADD = "下发组号、设备id列表";
/**
* mqtt消息描述: 清除网关锁开门
*/
public static final String MQTT_DESCRIBE_DEVICE_OPEN = "开门";
/**
* mqtt消息描述: 清除网关锁开门
*/
public static final String MQTT_DESCRIBE_DEVICE_ELECTRICITY_INTAKE = "取电";
/**
* topic: 清除网关锁id列表
*/
public static final String MQTT_GATEWAY_CLEAR = "ydlink/{}/thing/property/set";
/**
* topic: 下发组号、锁id/取电开关id列表
*/
public static final String MQTT_GATEWAY_ADD = "ydlink/{}/thing/property/set";
/**
* topic: 下发组号、锁id/取电开关id列表
*/
public static final String MQTT_DEVICE_OPEN = "ydlink/{}/thing/action/execute";
/**
* topic: 解析网关下属锁id信息: 锁id、信号值、电量、锁状态
*/
public static final String MQTT_GATEWAY_BATCH_REPORT = "/thing/data/batch_report";
/**
* 设备上报订阅主题后缀集合
*/
public static final List<String> MQTT_TOPIC_REPORT_LIST = CollUtil.newArrayList(
"/thing/data/batch_report");
}
package share.common.enums;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @className: share.common.enums.MqttOpenType
* @description: 开/关类型
* @author: lwj
* @create: 2023-11-04 15:35
*/
public enum MqttOpenType {
//1:开锁/取电 2:关锁/关电 3:常开锁/强制取电 4:常闭锁/强制断电
OPEN("1", "开锁/取电"),
CLOSE("2", "关锁/关电"),
OFTEN_OPEN("3", "常开锁/强制取电"),
OFTEN_CLOSE("4", "常闭锁/强制断电")
;
private String code;
private String name;
MqttOpenType(String code, String name) {
this.code = code;
this.name = name;
}
//code转字符串1,2,3,4
public static String getCodeList() {
List<String> list = Arrays.stream(StoreType.values()).map(StoreType::getCode).collect(Collectors.toList());
return String.join(",", list);
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
......@@ -11,7 +11,7 @@ import lombok.Data;
* 设备信息对象 s_device
*
* @author wuwenlong
* @date 2023-11-03
* @date 2023-11-04
*/
@Data
public class Device extends BaseEntity
......@@ -42,7 +42,7 @@ public class Device extends BaseEntity
private String devVer;
/** 设备类型 */
@Excel(name = "设备类型 ")
@Excel(name = "设备类型")
private String devType;
/** 项目ID */
......@@ -57,7 +57,7 @@ public class Device extends BaseEntity
@Excel(name = "分组")
private String group;
/** 设备状态 */
/** 设备状态: 0 在线、1 开门状态、2 反锁、3 门磁 */
@Excel(name = "设备状态")
private String status;
......@@ -69,6 +69,14 @@ public class Device extends BaseEntity
@Excel(name = "设备网关dev_id")
private String gatewayId;
/** 电量、电压 */
@Excel(name = "电量、电压")
private String voltage;
/** 信号值 */
@Excel(name = "信号值")
private String signalValue;
@Override
public String toString() {
......@@ -91,6 +99,8 @@ public class Device extends BaseEntity
.append("remark", getRemark())
.append("devPosition", getDevPosition())
.append("gatewayId", getGatewayId())
.append("voltage", getVoltage())
.append("signalValue", getSignalValue())
.toString();
}
}
package share.system.domain.vo;
import lombok.Data;
import share.common.core.domain.BaseEntity;
import java.io.Serializable;
/**
* @className: share.system.domain.vo.MqttxVo
* @description: mqtt消息内容
* @author: lwj
* @create: 2023-11-03 15:32
*/
@Data
public class MqttxVo extends BaseEntity {
/** mqtt主题 */
private String topic;
/** mqtt消息主体 */
private String payload;
/** 设备mac */
private String devMac;
/** 设备id */
private String devId;
/** 请求的序列号 */
private String seq;
/** 消息类型:1-下发,2-上报 */
private String mqttType;
/** 消息描述:开门、开灯、网关设备绑定等 */
private String mqttDescribe;
}
......@@ -59,4 +59,12 @@ public interface DeviceGatewayMapper extends BaseMapper<DeviceGateway>
* @return 结果
*/
public int deleteDeviceGatewayByIds(Long[] ids);
/**
* 查询设备网关信息
*
* @param devId 设备网关devid
* @return 设备网关信息
*/
DeviceGateway selectDeviceGatewayByDevId(String devId);
}
......@@ -8,7 +8,7 @@ import share.system.domain.Device;
* 设备信息Mapper接口
*
* @author wuwenlong
* @date 2023-11-03
* @date 2023-11-04
*/
public interface DeviceMapper extends BaseMapper<Device>
{
......@@ -59,4 +59,22 @@ public interface DeviceMapper extends BaseMapper<Device>
* @return 结果
*/
public int deleteDeviceByIds(Long[] ids);
/**
* 修改设备信息
*
* @param device 设备信息
* @return 结果
*/
public int updateDeviceByDevId(Device device);
/**
* 批量修改
* @param list 设备数据集合
* @return
*/
int updateBatch(List<Device> list);
Device selectDeviceByDevId(String devId);
}
......@@ -8,7 +8,7 @@ import share.system.domain.Device;
* 设备信息Service接口
*
* @author wuwenlong
* @date 2023-11-03
* @date 2023-11-04
*/
public interface DeviceService extends IService<Device>
{
......@@ -59,4 +59,13 @@ public interface DeviceService extends IService<Device>
* @return 结果
*/
public int deleteDeviceById(Long id);
/**
* 修改设备信息
* 根据devid
* @param device 设备信息
* @return 结果
*/
int updateDeviceByDevId(Device device);
}
package share.system.service;
import share.system.domain.vo.MqttxVo;
/**
* @className: share.system.service.MqttxService
* @description: MQTT 通讯服务接口
* @author: lwj
* @create: 2023-11-03 15:29
*/
public interface MqttxService {
/**
* 清除网关锁id列表
* @param devId 网关设备dev_id
* @return
*/
MqttxVo clearGatewayDevice(String devId);
/**
* 下发组号、锁id/取电开关id列表
* @param devId 网关设备dev_id
* @return
*/
MqttxVo addGatewayDevice(String devId);
/**
* mqtt 上报接口
* @param mqttx 上报数据对象
* @return
*/
boolean mqttReport(MqttxVo mqttx);
/**
* 开锁/关锁、取电/断电
* @param devId 门锁设备dev_id
* @param phone 开锁用户
* @param opType 操作类型:10:开门,20:取电,30:锁门,40:断电
* @return
*/
MqttxVo openOrCloseDevice(String devId, String phone, String opType);
}
......@@ -13,7 +13,7 @@ import share.system.service.DeviceService;
* 设备信息Service业务层处理
*
* @author wuwenlong
* @date 2023-11-03
* @date 2023-11-04
*/
@Service
public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> implements DeviceService
......@@ -94,4 +94,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
{
return deviceMapper.deleteDeviceById(id);
}
/**
* 修改设备信息
* 根据devid
* @param device 设备信息
* @return 结果
*/
@Override
public int updateDeviceByDevId(Device device)
{
device.setUpdateTime(DateUtils.getNowDate());
return deviceMapper.updateDeviceByDevId(device);
}
}
......@@ -53,7 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeviceGatewayVo"/>
where id = #{id}
</select>
<select id="selectDeviceGatewayByDevId" parameterType="String" resultMap="DeviceGatewayResult">
<include refid="selectDeviceGatewayVo"/>
where dev_id = #{devId}
</select>
<insert id="insertDeviceGateway" parameterType="DeviceGateway" useGeneratedKeys="true" keyProperty="id">
insert into s_device_gateway
<trim prefix="(" suffix=")" suffixOverrides=",">
......
......@@ -23,10 +23,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="devPosition" column="dev_position" />
<result property="gatewayId" column="gateway_id" />
<result property="voltage" column="voltage" />
<result property="signalValue" column="signal_value" />
</resultMap>
<sql id="selectDeviceVo">
select id, dev_name, dev_mac, dev_id, dev_psw, dev_ver, dev_type, projt_id, projt_psw, group, status, create_by, create_time, update_by, update_time, remark, dev_position, gateway_id from s_device
select id, dev_name, dev_mac, dev_id, dev_psw, dev_ver, dev_type, projt_id, projt_psw, group, status, create_by, create_time, update_by, update_time, remark, dev_position, gateway_id, voltage, signal_value from s_device
</sql>
<select id="selectDeviceList" parameterType="Device" resultMap="DeviceResult">
......@@ -44,6 +46,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="devPosition != null and devPosition != ''"> and dev_position = #{devPosition}</if>
<if test="gatewayId != null and gatewayId != ''"> and gateway_id = #{gatewayId}</if>
<if test="voltage != null and voltage != ''"> and voltage = #{voltage}</if>
<if test="signalValue != null and signalValue != ''"> and signal_value = #{signalValue}</if>
</where>
</select>
......@@ -51,7 +55,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeviceVo"/>
where id = #{id}
</select>
<select id="selectDeviceByDevId" parameterType="String" resultMap="DeviceResult">
<include refid="selectDeviceVo"/>
where dev_id = #{devId}
</select>
<insert id="insertDevice" parameterType="Device" useGeneratedKeys="true" keyProperty="id">
insert into s_device
<trim prefix="(" suffix=")" suffixOverrides=",">
......@@ -72,6 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark,</if>
<if test="devPosition != null">dev_position,</if>
<if test="gatewayId != null">gateway_id,</if>
<if test="voltage != null">voltage,</if>
<if test="signalValue != null">signal_value,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="devName != null">#{devName},</if>
......@@ -91,6 +101,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">#{remark},</if>
<if test="devPosition != null">#{devPosition},</if>
<if test="gatewayId != null">#{gatewayId},</if>
<if test="voltage != null">#{voltage},</if>
<if test="signalValue != null">#{signalValue},</if>
</trim>
</insert>
......@@ -114,10 +126,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="remark != null">remark = #{remark},</if>
<if test="devPosition != null">dev_position = #{devPosition},</if>
<if test="gatewayId != null">gateway_id = #{gatewayId},</if>
<if test="voltage != null">voltage = #{voltage},</if>
<if test="signalValue != null">signal_value = #{signalValue},</if>
</trim>
where id = #{id}
</update>
<update id="updateDeviceByDevId" parameterType="Device">
update s_device
<trim prefix="SET" suffixOverrides=",">
<if test="devName != null">dev_name = #{devName},</if>
<if test="devMac != null and devMac != ''">dev_mac = #{devMac},</if>
<if test="devId != null and devId != ''">dev_id = #{devId},</if>
<if test="devPsw != null">dev_psw = #{devPsw},</if>
<if test="devVer != null">dev_ver = #{devVer},</if>
<if test="devType != null">dev_type = #{devType},</if>
<if test="projtId != null">projt_id = #{projtId},</if>
<if test="projtPsw != null">projt_psw = #{projtPsw},</if>
<if test="group != null">group = #{group},</if>
<if test="status != null">status = #{status},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="devPosition != null">dev_position = #{devPosition},</if>
<if test="gatewayId != null">gateway_id = #{gatewayId},</if>
<if test="voltage != null">voltage = #{voltage},</if>
<if test="signalValue != null">signal_value = #{signalValue},</if>
</trim>
where dev_id = #{devId}
</update>
<update id="updateBatch" parameterType="list">
update s_device
<trim prefix="set" suffixOverrides=",">
<trim prefix=" signal_value =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.signalValue!=null">
when dev_id=#{i.devId} then #{i.signalValue}
</if>
</foreach>
</trim>
<trim prefix=" voltage =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.voltage!=null">
when dev_id=#{i.devId} then #{i.voltage}
</if>
</foreach>
</trim>
<trim prefix=" status =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.status!=null">
when dev_id=#{i.devId} then #{i.status}
</if>
</foreach>
</trim>
<trim prefix=" update_time =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.updateTime!=null">
when dev_id=#{i.devId} then #{i.updateTime}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index" >
dev_id=#{i.devId}
</foreach>
</update>
<delete id="deleteDeviceById" parameterType="Long">
delete from s_device where id = #{id}
</delete>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment