Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pseer
gxpt_ht
Commits
95cfbcd7
Commit
95cfbcd7
authored
Nov 06, 2023
by
YG8999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备网关代码
parent
32e8377d
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
615 additions
and
9 deletions
+615
-9
MqttConstants.java
...on/src/main/java/share/common/constant/MqttConstants.java
+100
-0
MqttOpenType.java
...common/src/main/java/share/common/enums/MqttOpenType.java
+40
-0
Device.java
share-system/src/main/java/share/system/domain/Device.java
+13
-3
MqttxVo.java
...-system/src/main/java/share/system/domain/vo/MqttxVo.java
+38
-0
DeviceGatewayMapper.java
...rc/main/java/share/system/mapper/DeviceGatewayMapper.java
+8
-0
DeviceMapper.java
...ystem/src/main/java/share/system/mapper/DeviceMapper.java
+19
-1
DeviceService.java
...tem/src/main/java/share/system/service/DeviceService.java
+10
-1
MqttxService.java
...stem/src/main/java/share/system/service/MqttxService.java
+43
-0
DeviceServiceImpl.java
...ain/java/share/system/service/impl/DeviceServiceImpl.java
+15
-1
MqttxServiceImpl.java
...main/java/share/system/service/impl/MqttxServiceImpl.java
+243
-0
DeviceGatewayMapper.xml
.../src/main/resources/mapper/system/DeviceGatewayMapper.xml
+5
-1
DeviceMapper.xml
...-system/src/main/resources/mapper/system/DeviceMapper.xml
+81
-2
No files found.
share-common/src/main/java/share/common/constant/MqttConstants.java
0 → 100644
View file @
95cfbcd7
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"
);
}
share-common/src/main/java/share/common/enums/MqttOpenType.java
0 → 100644
View file @
95cfbcd7
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
;
}
}
share-system/src/main/java/share/system/domain/Device.java
View file @
95cfbcd7
...
@@ -11,7 +11,7 @@ import lombok.Data;
...
@@ -11,7 +11,7 @@ import lombok.Data;
* 设备信息对象 s_device
* 设备信息对象 s_device
*
*
* @author wuwenlong
* @author wuwenlong
* @date 2023-11-0
3
* @date 2023-11-0
4
*/
*/
@Data
@Data
public
class
Device
extends
BaseEntity
public
class
Device
extends
BaseEntity
...
@@ -42,7 +42,7 @@ public class Device extends BaseEntity
...
@@ -42,7 +42,7 @@ public class Device extends BaseEntity
private
String
devVer
;
private
String
devVer
;
/** 设备类型 */
/** 设备类型 */
@Excel
(
name
=
"设备类型
"
)
@Excel
(
name
=
"设备类型"
)
private
String
devType
;
private
String
devType
;
/** 项目ID */
/** 项目ID */
...
@@ -57,7 +57,7 @@ public class Device extends BaseEntity
...
@@ -57,7 +57,7 @@ public class Device extends BaseEntity
@Excel
(
name
=
"分组"
)
@Excel
(
name
=
"分组"
)
private
String
group
;
private
String
group
;
/** 设备状态 */
/** 设备状态
: 0 在线、1 开门状态、2 反锁、3 门磁
*/
@Excel
(
name
=
"设备状态"
)
@Excel
(
name
=
"设备状态"
)
private
String
status
;
private
String
status
;
...
@@ -69,6 +69,14 @@ public class Device extends BaseEntity
...
@@ -69,6 +69,14 @@ public class Device extends BaseEntity
@Excel
(
name
=
"设备网关dev_id"
)
@Excel
(
name
=
"设备网关dev_id"
)
private
String
gatewayId
;
private
String
gatewayId
;
/** 电量、电压 */
@Excel
(
name
=
"电量、电压"
)
private
String
voltage
;
/** 信号值 */
@Excel
(
name
=
"信号值"
)
private
String
signalValue
;
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
@@ -91,6 +99,8 @@ public class Device extends BaseEntity
...
@@ -91,6 +99,8 @@ public class Device extends BaseEntity
.
append
(
"remark"
,
getRemark
())
.
append
(
"remark"
,
getRemark
())
.
append
(
"devPosition"
,
getDevPosition
())
.
append
(
"devPosition"
,
getDevPosition
())
.
append
(
"gatewayId"
,
getGatewayId
())
.
append
(
"gatewayId"
,
getGatewayId
())
.
append
(
"voltage"
,
getVoltage
())
.
append
(
"signalValue"
,
getSignalValue
())
.
toString
();
.
toString
();
}
}
}
}
share-system/src/main/java/share/system/domain/vo/MqttxVo.java
0 → 100644
View file @
95cfbcd7
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
;
}
share-system/src/main/java/share/system/mapper/DeviceGatewayMapper.java
View file @
95cfbcd7
...
@@ -59,4 +59,12 @@ public interface DeviceGatewayMapper extends BaseMapper<DeviceGateway>
...
@@ -59,4 +59,12 @@ public interface DeviceGatewayMapper extends BaseMapper<DeviceGateway>
* @return 结果
* @return 结果
*/
*/
public
int
deleteDeviceGatewayByIds
(
Long
[]
ids
);
public
int
deleteDeviceGatewayByIds
(
Long
[]
ids
);
/**
* 查询设备网关信息
*
* @param devId 设备网关devid
* @return 设备网关信息
*/
DeviceGateway
selectDeviceGatewayByDevId
(
String
devId
);
}
}
share-system/src/main/java/share/system/mapper/DeviceMapper.java
View file @
95cfbcd7
...
@@ -8,7 +8,7 @@ import share.system.domain.Device;
...
@@ -8,7 +8,7 @@ import share.system.domain.Device;
* 设备信息Mapper接口
* 设备信息Mapper接口
*
*
* @author wuwenlong
* @author wuwenlong
* @date 2023-11-0
3
* @date 2023-11-0
4
*/
*/
public
interface
DeviceMapper
extends
BaseMapper
<
Device
>
public
interface
DeviceMapper
extends
BaseMapper
<
Device
>
{
{
...
@@ -59,4 +59,22 @@ public interface DeviceMapper extends BaseMapper<Device>
...
@@ -59,4 +59,22 @@ public interface DeviceMapper extends BaseMapper<Device>
* @return 结果
* @return 结果
*/
*/
public
int
deleteDeviceByIds
(
Long
[]
ids
);
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
);
}
}
share-system/src/main/java/share/system/service/DeviceService.java
View file @
95cfbcd7
...
@@ -8,7 +8,7 @@ import share.system.domain.Device;
...
@@ -8,7 +8,7 @@ import share.system.domain.Device;
* 设备信息Service接口
* 设备信息Service接口
*
*
* @author wuwenlong
* @author wuwenlong
* @date 2023-11-0
3
* @date 2023-11-0
4
*/
*/
public
interface
DeviceService
extends
IService
<
Device
>
public
interface
DeviceService
extends
IService
<
Device
>
{
{
...
@@ -59,4 +59,13 @@ public interface DeviceService extends IService<Device>
...
@@ -59,4 +59,13 @@ public interface DeviceService extends IService<Device>
* @return 结果
* @return 结果
*/
*/
public
int
deleteDeviceById
(
Long
id
);
public
int
deleteDeviceById
(
Long
id
);
/**
* 修改设备信息
* 根据devid
* @param device 设备信息
* @return 结果
*/
int
updateDeviceByDevId
(
Device
device
);
}
}
share-system/src/main/java/share/system/service/MqttxService.java
0 → 100644
View file @
95cfbcd7
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
);
}
share-system/src/main/java/share/system/service/impl/DeviceServiceImpl.java
View file @
95cfbcd7
...
@@ -13,7 +13,7 @@ import share.system.service.DeviceService;
...
@@ -13,7 +13,7 @@ import share.system.service.DeviceService;
* 设备信息Service业务层处理
* 设备信息Service业务层处理
*
*
* @author wuwenlong
* @author wuwenlong
* @date 2023-11-0
3
* @date 2023-11-0
4
*/
*/
@Service
@Service
public
class
DeviceServiceImpl
extends
ServiceImpl
<
DeviceMapper
,
Device
>
implements
DeviceService
public
class
DeviceServiceImpl
extends
ServiceImpl
<
DeviceMapper
,
Device
>
implements
DeviceService
...
@@ -94,4 +94,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
...
@@ -94,4 +94,18 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
{
{
return
deviceMapper
.
deleteDeviceById
(
id
);
return
deviceMapper
.
deleteDeviceById
(
id
);
}
}
/**
* 修改设备信息
* 根据devid
* @param device 设备信息
* @return 结果
*/
@Override
public
int
updateDeviceByDevId
(
Device
device
)
{
device
.
setUpdateTime
(
DateUtils
.
getNowDate
());
return
deviceMapper
.
updateDeviceByDevId
(
device
);
}
}
}
share-system/src/main/java/share/system/service/impl/MqttxServiceImpl.java
0 → 100644
View file @
95cfbcd7
package
share
.
system
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
share.common.constant.MqttConstants
;
import
share.common.enums.MqttOpenType
;
import
share.common.utils.DateUtils
;
import
share.system.domain.Device
;
import
share.system.domain.DeviceGateway
;
import
share.system.domain.vo.MqttxVo
;
import
share.system.mapper.DeviceGatewayMapper
;
import
share.system.mapper.DeviceMapper
;
import
share.system.service.MqttxService
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @className: share.system.service.impl.MqttxServiceImpl
* @description: MQTT 通讯服务
* @author: lwj
* @create: 2023-11-03 15:30
*/
@Service
public
class
MqttxServiceImpl
implements
MqttxService
{
@Autowired
private
DeviceGatewayMapper
deviceGatewayMapper
;
@Autowired
private
DeviceMapper
deviceMapper
;
/**
* 清除网关锁id列表
* @param devId 网关设备dev_id
* @return
*/
@Override
public
MqttxVo
clearGatewayDevice
(
String
devId
)
{
DeviceGateway
deviceGateway
=
deviceGatewayMapper
.
selectDeviceGatewayByDevId
(
devId
);
if
(
deviceGateway
!=
null
)
{
String
topic
=
StrUtil
.
format
(
MqttConstants
.
MQTT_GATEWAY_CLEAR
,
deviceGateway
.
getDevId
());
String
seq
=
IdUtil
.
simpleUUID
().
toUpperCase
();
JSONArray
params
=
JSONUtil
.
createArray
();
params
.
add
(
"clear"
);
JSONObject
payload
=
JSONUtil
.
createObj
()
.
put
(
"devId"
,
deviceGateway
.
getDevId
())
.
put
(
"devPsw"
,
deviceGateway
.
getDevPsw
())
.
put
(
"devVer"
,
deviceGateway
.
getDevVer
())
.
put
(
"devType"
,
deviceGateway
.
getDevType
()).
put
(
"ac"
,
MqttConstants
.
MQTT_AC_REQ
)
.
put
(
"at"
,
DateUtil
.
date
().
getTime
())
.
put
(
"seq"
,
seq
).
put
(
"op"
,
MqttConstants
.
MQTT_OP_LOCKLIST
)
.
put
(
"mode"
,
MqttConstants
.
MQTT_MODE_S2D
)
.
put
(
"chksum"
,
"xx"
)
.
put
(
"params"
,
params
);
MqttxVo
mqttxVo
=
new
MqttxVo
();
mqttxVo
.
setTopic
(
topic
);
mqttxVo
.
setPayload
(
JSONUtil
.
toJsonStr
(
payload
));
mqttxVo
.
setDevMac
(
deviceGateway
.
getDevMac
());
mqttxVo
.
setDevId
(
deviceGateway
.
getDevId
());
mqttxVo
.
setSeq
(
seq
);
mqttxVo
.
setMqttType
(
MqttConstants
.
MQTT_TYPE_1
);
mqttxVo
.
setMqttDescribe
(
MqttConstants
.
MQTT_DESCRIBE_GATEWAY_CLEAR
);
return
mqttxVo
;
}
return
null
;
}
/**
* 下发组号、锁id/取电开关id列表
* @param devId 网关设备dev_id
* @return
*/
@Override
public
MqttxVo
addGatewayDevice
(
String
devId
)
{
DeviceGateway
deviceGateway
=
deviceGatewayMapper
.
selectDeviceGatewayByDevId
(
devId
);
if
(
deviceGateway
!=
null
)
{
Device
device
=
new
Device
();
device
.
setGroup
(
deviceGateway
.
getGroup
());
List
<
Device
>
deviceList
=
deviceMapper
.
selectDeviceList
(
device
);
if
(
deviceList
.
size
()
>
0
)
{
String
topic
=
StrUtil
.
format
(
MqttConstants
.
MQTT_GATEWAY_ADD
,
deviceGateway
.
getDevId
());
String
seq
=
IdUtil
.
simpleUUID
().
toUpperCase
();
JSONArray
params
=
JSONUtil
.
createArray
();
params
.
add
(
"add"
);
params
.
add
(
deviceGateway
.
getGroup
());
params
.
add
(
String
.
valueOf
(
deviceList
.
size
()));
for
(
Device
dev
:
deviceList
)
{
params
.
add
(
StrUtil
.
concat
(
true
,
dev
.
getDevType
(),
dev
.
getDevId
()));
}
JSONObject
payload
=
JSONUtil
.
createObj
()
.
put
(
"devId"
,
deviceGateway
.
getDevId
())
.
put
(
"devPsw"
,
deviceGateway
.
getDevPsw
())
.
put
(
"devVer"
,
deviceGateway
.
getDevVer
())
.
put
(
"devType"
,
deviceGateway
.
getDevType
()).
put
(
"ac"
,
MqttConstants
.
MQTT_AC_REQ
)
.
put
(
"at"
,
DateUtil
.
date
().
getTime
())
.
put
(
"seq"
,
seq
).
put
(
"op"
,
MqttConstants
.
MQTT_OP_LOCKLIST
)
.
put
(
"mode"
,
MqttConstants
.
MQTT_MODE_S2D
)
.
put
(
"chksum"
,
"xx"
)
.
put
(
"params"
,
params
);
MqttxVo
mqttxVo
=
new
MqttxVo
();
mqttxVo
.
setTopic
(
topic
);
mqttxVo
.
setPayload
(
JSONUtil
.
toJsonStr
(
payload
));
mqttxVo
.
setDevMac
(
deviceGateway
.
getDevMac
());
mqttxVo
.
setDevId
(
deviceGateway
.
getDevId
());
mqttxVo
.
setSeq
(
seq
);
mqttxVo
.
setMqttType
(
MqttConstants
.
MQTT_TYPE_1
);
mqttxVo
.
setMqttDescribe
(
MqttConstants
.
MQTT_DESCRIBE_GATEWAY_ADD
);
return
mqttxVo
;
}
}
return
null
;
}
@Override
public
boolean
mqttReport
(
MqttxVo
mqttx
)
{
boolean
isSuccess
=
false
;
String
topic
=
mqttx
.
getTopic
();
for
(
String
top
:
MqttConstants
.
MQTT_TOPIC_REPORT_LIST
)
{
if
(
topic
.
endsWith
(
top
))
{
switch
(
top
)
{
case
MqttConstants
.
MQTT_GATEWAY_BATCH_REPORT
:
// 修改设备状态、电量
isSuccess
=
this
.
updateDevice
(
mqttx
);
break
;
default
:
//执行默认代码
break
;
}
}
}
return
isSuccess
;
}
/**
* 开锁/关锁、取电/断电
* @param devId 门锁设备dev_id
* @param phone 开锁用户
* @param opType 操作类型:10:开门,20:取电,30:锁门,40:断电
* @return
*/
@Override
public
MqttxVo
openOrCloseDevice
(
String
devId
,
String
phone
,
String
opType
)
{
MqttxVo
mqttxVo
=
null
;
switch
(
opType
)
{
case
"10"
:
// 开锁
mqttxVo
=
this
.
openOrCloseDeviceInit
(
devId
,
phone
,
MqttOpenType
.
OPEN
.
getCode
(),
MqttConstants
.
MQTT_DESCRIBE_DEVICE_OPEN
);
break
;
case
"20"
:
// 取电
mqttxVo
=
this
.
openOrCloseDeviceInit
(
devId
,
phone
,
MqttOpenType
.
OPEN
.
getCode
(),
MqttConstants
.
MQTT_DESCRIBE_DEVICE_ELECTRICITY_INTAKE
);
break
;
default
:
break
;
}
return
mqttxVo
;
}
/**
*
* @param devId 门锁设备dev_id
* @param phone 开锁用户
* @param openType
* @return
*/
private
MqttxVo
openOrCloseDeviceInit
(
String
devId
,
String
phone
,
String
openType
,
String
mqttDescribe
)
{
Device
device
=
deviceMapper
.
selectDeviceByDevId
(
devId
);
if
(
device
!=
null
)
{
DeviceGateway
deviceGateway
=
new
DeviceGateway
();
deviceGateway
.
setGroup
(
device
.
getGroup
());
List
<
DeviceGateway
>
deviceGateways
=
deviceGatewayMapper
.
selectDeviceGatewayList
(
deviceGateway
);
if
(
deviceGateways
.
size
()
>
0
)
{
String
topic
=
StrUtil
.
format
(
MqttConstants
.
MQTT_DEVICE_OPEN
,
deviceGateway
.
getGroup
());
String
seq
=
IdUtil
.
simpleUUID
().
toUpperCase
();
JSONArray
params
=
JSONUtil
.
createArray
();
params
.
add
(
"open"
);
params
.
add
(
phone
);
params
.
add
(
openType
);
params
.
add
(
device
.
getDevId
());
params
.
add
(
StrUtil
.
concat
(
true
,
device
.
getDevType
(),
device
.
getDevId
()));
params
.
add
(
device
.
getDevPsw
());
JSONObject
payload
=
JSONUtil
.
createObj
()
.
put
(
"devId"
,
deviceGateway
.
getGroup
())
.
put
(
"devPsw"
,
deviceGateway
.
getDevPsw
())
.
put
(
"devVer"
,
deviceGateway
.
getDevVer
())
.
put
(
"devType"
,
deviceGateway
.
getDevType
()).
put
(
"ac"
,
MqttConstants
.
MQTT_AC_REQ
)
.
put
(
"at"
,
DateUtil
.
date
().
getTime
())
.
put
(
"seq"
,
seq
).
put
(
"op"
,
MqttConstants
.
MQTT_OP_OPENCLOSELOCK
)
.
put
(
"mode"
,
MqttConstants
.
MQTT_MODE_S2D
)
.
put
(
"chksum"
,
"xx"
)
.
put
(
"params"
,
params
);
MqttxVo
mqttxVo
=
new
MqttxVo
();
mqttxVo
.
setTopic
(
topic
);
mqttxVo
.
setPayload
(
JSONUtil
.
toJsonStr
(
payload
));
mqttxVo
.
setDevMac
(
deviceGateway
.
getDevMac
());
mqttxVo
.
setDevId
(
deviceGateway
.
getDevId
());
mqttxVo
.
setSeq
(
seq
);
mqttxVo
.
setMqttType
(
MqttConstants
.
MQTT_TYPE_1
);
mqttxVo
.
setMqttDescribe
(
mqttDescribe
);
return
mqttxVo
;
}
}
return
null
;
}
/**
* 修改设备状态、电量
* @param mqttx
* @return
*/
private
boolean
updateDevice
(
MqttxVo
mqttx
)
{
String
payload
=
mqttx
.
getPayload
();
JSONObject
json
=
JSONUtil
.
parseObj
(
payload
);
if
(
json
.
size
()
>
0
)
{
JSONArray
array
=
json
.
getJSONArray
(
"params"
);
if
(
array
!=
null
)
{
List
<
Device
>
list
=
new
ArrayList
<>();
for
(
Object
o
:
array
)
{
JSONArray
jsonArray
=
JSONUtil
.
parseArray
(
o
);
Device
device
=
new
Device
();
device
.
setDevId
(
jsonArray
.
get
(
0
).
toString
());
device
.
setSignalValue
(
jsonArray
.
get
(
1
).
toString
());
device
.
setVoltage
(
jsonArray
.
get
(
2
).
toString
());
device
.
setStatus
(
jsonArray
.
get
(
3
).
toString
());
device
.
setUpdateTime
(
DateUtils
.
getNowDate
());
list
.
add
(
device
);
}
return
0
<
deviceMapper
.
updateBatch
(
list
);
}
}
return
false
;
}
}
share-system/src/main/resources/mapper/system/DeviceGatewayMapper.xml
View file @
95cfbcd7
...
@@ -53,7 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -53,7 +53,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include
refid=
"selectDeviceGatewayVo"
/>
<include
refid=
"selectDeviceGatewayVo"
/>
where id = #{id}
where id = #{id}
</select>
</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
id=
"insertDeviceGateway"
parameterType=
"DeviceGateway"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into s_device_gateway
insert into s_device_gateway
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
...
...
share-system/src/main/resources/mapper/system/DeviceMapper.xml
View file @
95cfbcd7
...
@@ -23,10 +23,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -23,10 +23,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result
property=
"remark"
column=
"remark"
/>
<result
property=
"remark"
column=
"remark"
/>
<result
property=
"devPosition"
column=
"dev_position"
/>
<result
property=
"devPosition"
column=
"dev_position"
/>
<result
property=
"gatewayId"
column=
"gateway_id"
/>
<result
property=
"gatewayId"
column=
"gateway_id"
/>
<result
property=
"voltage"
column=
"voltage"
/>
<result
property=
"signalValue"
column=
"signal_value"
/>
</resultMap>
</resultMap>
<sql
id=
"selectDeviceVo"
>
<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>
</sql>
<select
id=
"selectDeviceList"
parameterType=
"Device"
resultMap=
"DeviceResult"
>
<select
id=
"selectDeviceList"
parameterType=
"Device"
resultMap=
"DeviceResult"
>
...
@@ -44,6 +46,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -44,6 +46,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"status != null and status != ''"
>
and status = #{status}
</if>
<if
test=
"status != null and status != ''"
>
and status = #{status}
</if>
<if
test=
"devPosition != null and devPosition != ''"
>
and dev_position = #{devPosition}
</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=
"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>
</where>
</select>
</select>
...
@@ -51,7 +55,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -51,7 +55,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include
refid=
"selectDeviceVo"
/>
<include
refid=
"selectDeviceVo"
/>
where id = #{id}
where id = #{id}
</select>
</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
id=
"insertDevice"
parameterType=
"Device"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into s_device
insert into s_device
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
...
@@ -72,6 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -72,6 +80,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"remark != null"
>
remark,
</if>
<if
test=
"remark != null"
>
remark,
</if>
<if
test=
"devPosition != null"
>
dev_position,
</if>
<if
test=
"devPosition != null"
>
dev_position,
</if>
<if
test=
"gatewayId != null"
>
gateway_id,
</if>
<if
test=
"gatewayId != null"
>
gateway_id,
</if>
<if
test=
"voltage != null"
>
voltage,
</if>
<if
test=
"signalValue != null"
>
signal_value,
</if>
</trim>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"devName != null"
>
#{devName},
</if>
<if
test=
"devName != null"
>
#{devName},
</if>
...
@@ -91,6 +101,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -91,6 +101,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"remark != null"
>
#{remark},
</if>
<if
test=
"remark != null"
>
#{remark},
</if>
<if
test=
"devPosition != null"
>
#{devPosition},
</if>
<if
test=
"devPosition != null"
>
#{devPosition},
</if>
<if
test=
"gatewayId != null"
>
#{gatewayId},
</if>
<if
test=
"gatewayId != null"
>
#{gatewayId},
</if>
<if
test=
"voltage != null"
>
#{voltage},
</if>
<if
test=
"signalValue != null"
>
#{signalValue},
</if>
</trim>
</trim>
</insert>
</insert>
...
@@ -114,10 +126,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -114,10 +126,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"remark != null"
>
remark = #{remark},
</if>
<if
test=
"remark != null"
>
remark = #{remark},
</if>
<if
test=
"devPosition != null"
>
dev_position = #{devPosition},
</if>
<if
test=
"devPosition != null"
>
dev_position = #{devPosition},
</if>
<if
test=
"gatewayId != null"
>
gateway_id = #{gatewayId},
</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>
</trim>
where id = #{id}
where id = #{id}
</update>
</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
id=
"deleteDeviceById"
parameterType=
"Long"
>
delete from s_device where id = #{id}
delete from s_device where id = #{id}
</delete>
</delete>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment