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
8166b0b3
Commit
8166b0b3
authored
Nov 07, 2023
by
YG8999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备网关代码修改
parent
e7d48a52
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
106 additions
and
11 deletions
+106
-11
DeviceController.java
...in/java/share/web/controller/system/DeviceController.java
+31
-0
DeviceGatewayController.java
.../share/web/controller/system/DeviceGatewayController.java
+2
-0
MqttConstants.java
...on/src/main/java/share/common/constant/MqttConstants.java
+10
-0
MqttReportType.java
...mmon/src/main/java/share/common/enums/MqttReportType.java
+1
-1
MqttGatewayComponent.java
.../main/java/share/framework/mqtt/MqttGatewayComponent.java
+0
-1
MqttTopicHandler.java
.../src/main/java/share/framework/mqtt/MqttTopicHandler.java
+4
-1
SnowFlakeUtil.java
...ork/src/main/java/share/framework/mqtt/SnowFlakeUtil.java
+0
-6
DeviceParamVo.java
...m/src/main/java/share/system/domain/vo/DeviceParamVo.java
+28
-0
DeviceLogService.java
.../src/main/java/share/system/service/DeviceLogService.java
+10
-0
MqttxService.java
...stem/src/main/java/share/system/service/MqttxService.java
+3
-2
DeviceLogServiceImpl.java
.../java/share/system/service/impl/DeviceLogServiceImpl.java
+17
-0
MqttxServiceImpl.java
...main/java/share/system/service/impl/MqttxServiceImpl.java
+0
-0
No files found.
share-admin/src/main/java/share/web/controller/system/DeviceController.java
View file @
8166b0b3
...
...
@@ -16,10 +16,16 @@ import share.common.annotation.Log;
import
share.common.core.controller.BaseController
;
import
share.common.core.domain.AjaxResult
;
import
share.common.enums.BusinessType
;
import
share.common.utils.SecurityUtils
;
import
share.framework.mqtt.MqttGatewayComponent
;
import
share.system.domain.Device
;
import
share.system.domain.vo.DeviceParamVo
;
import
share.system.domain.vo.MqttxVo
;
import
share.system.service.DeviceLogService
;
import
share.system.service.DeviceService
;
import
share.common.utils.poi.ExcelUtil
;
import
share.common.core.page.TableDataInfo
;
import
share.system.service.MqttxService
;
/**
* 设备信息Controller
...
...
@@ -33,6 +39,12 @@ public class DeviceController extends BaseController
{
@Autowired
private
DeviceService
deviceService
;
@Autowired
private
MqttxService
mqttxService
;
@Autowired
private
DeviceLogService
deviceLogService
;
@Autowired
private
MqttGatewayComponent
mqttGatewayComponent
;
/**
* 查询设备信息列表
...
...
@@ -101,4 +113,23 @@ public class DeviceController extends BaseController
{
return
toAjax
(
deviceService
.
deleteDeviceByIds
(
ids
));
}
/**
* 开门、关门、取电、断电
*/
@PreAuthorize
(
"@ss.hasPermi('system:device:edit')"
)
@Log
(
title
=
"设备信息"
,
businessType
=
BusinessType
.
UPDATE
)
@PostMapping
(
value
=
"/openOrClose"
)
public
AjaxResult
openOrClose
(
@RequestBody
DeviceParamVo
deviceParam
)
{
// 获取mqtt的topic、payload
MqttxVo
mqttxVo
=
mqttxService
.
openOrCloseDevice
(
deviceParam
.
getDevId
(),
SecurityUtils
.
getUsername
(),
deviceParam
.
getOpType
());
// 发送mqtt消息
mqttGatewayComponent
.
sendToMqtt
(
mqttxVo
.
getTopic
(),
0
,
mqttxVo
.
getPayload
());
// 写日志记录
int
result
=
deviceLogService
.
addDeviceLog
(
mqttxVo
);
return
toAjax
(
result
);
}
}
share-admin/src/main/java/share/web/controller/system/DeviceGatewayController.java
View file @
8166b0b3
...
...
@@ -101,4 +101,6 @@ public class DeviceGatewayController extends BaseController
{
return
toAjax
(
deviceGatewayService
.
deleteDeviceGatewayByIds
(
ids
));
}
}
share-common/src/main/java/share/common/constant/MqttConstants.java
View file @
8166b0b3
...
...
@@ -58,6 +58,16 @@ public class MqttConstants {
public
static
final
String
MQTT_DESCRIBE_DEVICE_ELECTRICITY_INTAKE
=
"取电"
;
/**
* mqtt消息描述: 清除网关锁关门
*/
public
static
final
String
MQTT_DESCRIBE_DEVICE_CLOSE
=
"关门"
;
/**
* mqtt消息描述: 清除网关锁断电
*/
public
static
final
String
MQTT_DESCRIBE_DEVICE_ELECTRICITY_CLOSE
=
"断电"
;
/**
* mqtt消息描述: 远程下发密码
*/
public
static
final
String
MQTT_DESCRIBE_DEVICE_PASSWORD
=
"远程下发密码"
;
...
...
share-common/src/main/java/share/common/enums/MqttReportType.java
View file @
8166b0b3
...
...
@@ -43,7 +43,7 @@ public enum MqttReportType {
if
(
StrUtil
.
isNotBlank
(
code
))
{
for
(
MqttReportType
type
:
MqttReportType
.
values
())
{
if
(
type
.
code
.
compareTo
(
code
)==
0
)
{
return
type
.
name
;
return
type
.
topic
;
}
}
}
...
...
share-framework/src/main/java/share/framework/mqtt/MqttGatewayComponent.java
View file @
8166b0b3
...
...
@@ -23,7 +23,6 @@ public interface MqttGatewayComponent {
* @param topic topic
* @see
*/
@Deprecated
void
sendToMqtt
(
String
payload
,
@Header
(
MqttHeaders
.
TOPIC
)
String
topic
);
/**
...
...
share-framework/src/main/java/share/framework/mqtt/MqttTopicHandler.java
View file @
8166b0b3
...
...
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.integration.mqtt.support.MqttHeaders
;
import
org.springframework.messaging.Message
;
import
org.springframework.stereotype.Service
;
import
share.system.service.MqttxService
;
/**
* 消息处理器
...
...
@@ -18,6 +19,8 @@ import org.springframework.stereotype.Service;
@Service
public
class
MqttTopicHandler
{
@Autowired
private
MqttxService
mqttxService
;
/**
* 这一步主要是对消息的有效荷载进行非空校验以及日志打印
...
...
@@ -37,8 +40,8 @@ public class MqttTopicHandler {
private
void
dispose
(
String
payload
,
String
topic
)
{
if
(!
ObjectUtil
.
isNull
(
payload
)){
try
{
mqttxService
.
mqttReport
(
topic
,
payload
);
log
.
info
(
"来自topic:{}的消息处理完毕!"
,
topic
);
log
.
info
(
"消息内容:{}"
,
payload
);
}
catch
(
Exception
e
)
{
log
.
error
(
"来自topic:{}的消息处理异常!原因:{}"
,
topic
,
e
);
}
...
...
share-framework/src/main/java/share/framework/mqtt/SnowFlakeUtil.java
View file @
8166b0b3
...
...
@@ -68,12 +68,6 @@ public class SnowFlakeUtil {
return
Singleton
.
get
(
SnowFlakeUtil
.
class
,
new
Object
[]{
1L
,
1L
}).
nextId
();
}
public
static
void
main
(
String
[]
args
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
{
System
.
out
.
println
(
getDefaultSnowFlakeId
());
System
.
out
.
println
(
getDefaultSnowFlakeId
().
toString
().
length
());
}
}
}
share-system/src/main/java/share/system/domain/vo/DeviceParamVo.java
0 → 100644
View file @
8166b0b3
package
share
.
system
.
domain
.
vo
;
import
lombok.Data
;
import
share.common.core.domain.BaseEntity
;
/**
* @className: share.system.domain.vo.DeviceParamVo
* @description: 设备参数
* @author: lwj
* @create: 2023-11-07 16:10
*/
@Data
public
class
DeviceParamVo
extends
BaseEntity
{
/** 设备mac */
private
String
devMac
;
/** 设备id */
private
String
devId
;
/** 操作类型:10:开门,20:取电,30:锁门,40:断电 */
private
String
opType
;
/** 操作用户 */
private
String
phone
;
}
share-system/src/main/java/share/system/service/DeviceLogService.java
View file @
8166b0b3
...
...
@@ -3,6 +3,7 @@ package share.system.service;
import
java.util.List
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
share.system.domain.DeviceLog
;
import
share.system.domain.vo.MqttxVo
;
/**
* 设备操作日志Service接口
...
...
@@ -59,4 +60,13 @@ public interface DeviceLogService extends IService<DeviceLog>
* @return 结果
*/
public
int
deleteDeviceLogById
(
Long
id
);
/**
* 新增设备操作日志
*
* @param mqttxVo 设备操作信息
* @return 结果
*/
int
addDeviceLog
(
MqttxVo
mqttxVo
);
}
share-system/src/main/java/share/system/service/MqttxService.java
View file @
8166b0b3
...
...
@@ -28,10 +28,11 @@ public interface MqttxService {
/**
* mqtt 上报接口
* @param mqttx 上报数据对象
* @param topic 上报数据主题
* @param payload 上报数据参数
* @return
*/
boolean
mqttReport
(
MqttxVo
mqttx
);
boolean
mqttReport
(
String
topic
,
String
payload
);
/**
* 开锁/关锁、取电/断电
...
...
share-system/src/main/java/share/system/service/impl/DeviceLogServiceImpl.java
View file @
8166b0b3
...
...
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import
share.common.utils.DateUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
share.common.utils.SecurityUtils
;
import
share.system.domain.vo.MqttxVo
;
import
share.system.mapper.DeviceLogMapper
;
import
share.system.domain.DeviceLog
;
import
share.system.service.DeviceLogService
;
...
...
@@ -94,4 +96,19 @@ public class DeviceLogServiceImpl extends ServiceImpl<DeviceLogMapper, DeviceLog
{
return
deviceLogMapper
.
deleteDeviceLogById
(
id
);
}
@Override
public
int
addDeviceLog
(
MqttxVo
mqttxVo
)
{
DeviceLog
deviceLog
=
new
DeviceLog
();
deviceLog
.
setDevId
(
mqttxVo
.
getDevId
());
deviceLog
.
setDevMac
(
mqttxVo
.
getDevMac
());
deviceLog
.
setTopic
(
mqttxVo
.
getTopic
());
deviceLog
.
setPayload
(
mqttxVo
.
getPayload
());
deviceLog
.
setSeq
(
mqttxVo
.
getSeq
());
deviceLog
.
setMqttType
(
mqttxVo
.
getMqttType
());
deviceLog
.
setMqttDescribe
(
mqttxVo
.
getMqttDescribe
());
deviceLog
.
setCreateTime
(
DateUtils
.
getNowDate
());
deviceLog
.
setCreateBy
(
SecurityUtils
.
getUsername
());
return
deviceLogMapper
.
insertDeviceLog
(
deviceLog
);
}
}
share-system/src/main/java/share/system/service/impl/MqttxServiceImpl.java
View file @
8166b0b3
This diff is collapsed.
Click to expand it.
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