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
391570b2
Commit
391570b2
authored
Jan 16, 2024
by
YG8999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备网关状态监控
parent
491c2809
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
1 deletions
+81
-1
DeviceTask.java
share-quartz/src/main/java/share/quartz/task/DeviceTask.java
+15
-0
DeviceGateway.java
...stem/src/main/java/share/system/domain/DeviceGateway.java
+10
-0
DeviceGatewayService.java
.../main/java/share/system/service/DeviceGatewayService.java
+7
-0
DeviceGatewayServiceImpl.java
...a/share/system/service/impl/DeviceGatewayServiceImpl.java
+25
-0
MqttxServiceImpl.java
...main/java/share/system/service/impl/MqttxServiceImpl.java
+12
-0
DeviceGatewayMapper.xml
.../src/main/resources/mapper/system/DeviceGatewayMapper.xml
+12
-1
No files found.
share-quartz/src/main/java/share/quartz/task/DeviceTask.java
View file @
391570b2
...
@@ -2,6 +2,7 @@ package share.quartz.task;
...
@@ -2,6 +2,7 @@ package share.quartz.task;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
share.system.service.DeviceGatewayService
;
import
share.system.service.DeviceStatusLogService
;
import
share.system.service.DeviceStatusLogService
;
/**
/**
...
@@ -15,12 +16,26 @@ public class DeviceTask {
...
@@ -15,12 +16,26 @@ public class DeviceTask {
@Autowired
@Autowired
private
DeviceStatusLogService
deviceStatusLogService
;
private
DeviceStatusLogService
deviceStatusLogService
;
@Autowired
private
DeviceGatewayService
deviceGatewayService
;
/**
/**
* 设备异常状态短信提醒任务
* 设备异常状态短信提醒任务
*/
*/
public
void
sendSmsByYc
()
{
public
void
sendSmsByYc
()
{
// 设备状态异常变更发送短信
deviceStatusLogService
.
sendSmsByYc
();
deviceStatusLogService
.
sendSmsByYc
();
}
}
/**
* 设备网关状态监控
*/
public
void
deviceGatewayStatusMonitor
()
{
// 更新网关状态
boolean
b
=
deviceGatewayService
.
deviceGatewayStatusMonitor
();
if
(
b
)
{
// 离线网关,发送短信提醒
}
}
}
}
share-system/src/main/java/share/system/domain/DeviceGateway.java
View file @
391570b2
...
@@ -6,6 +6,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
...
@@ -6,6 +6,9 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import
share.common.annotation.Excel
;
import
share.common.annotation.Excel
;
import
share.common.core.domain.BaseEntity
;
import
share.common.core.domain.BaseEntity
;
import
lombok.Data
;
import
lombok.Data
;
import
java.util.Date
;
/**
/**
* 设备网关信息对象 s_device_gateway
* 设备网关信息对象 s_device_gateway
*
*
...
@@ -48,10 +51,12 @@ public class DeviceGateway extends BaseEntity
...
@@ -48,10 +51,12 @@ public class DeviceGateway extends BaseEntity
/** 网络分组 */
/** 网络分组 */
@Excel
(
name
=
"网络分组"
)
@Excel
(
name
=
"网络分组"
)
@TableField
(
value
=
"`group`"
)
private
String
group
;
private
String
group
;
/** 设备状态 */
/** 设备状态 */
@Excel
(
name
=
"设备状态"
)
@Excel
(
name
=
"设备状态"
)
@TableField
(
value
=
"`status`"
)
private
String
status
;
private
String
status
;
/** mqtt服务器IP/域名 */
/** mqtt服务器IP/域名 */
...
@@ -74,6 +79,11 @@ public class DeviceGateway extends BaseEntity
...
@@ -74,6 +79,11 @@ public class DeviceGateway extends BaseEntity
@Excel
(
name
=
"设备位置"
)
@Excel
(
name
=
"设备位置"
)
private
String
devPosition
;
private
String
devPosition
;
/** 网关最后上报时间 */
private
Date
lastReportDate
;
/** 网关最后上报内容 */
private
String
lastReportContent
;
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
...
share-system/src/main/java/share/system/service/DeviceGatewayService.java
View file @
391570b2
...
@@ -59,4 +59,11 @@ public interface DeviceGatewayService extends IService<DeviceGateway>
...
@@ -59,4 +59,11 @@ public interface DeviceGatewayService extends IService<DeviceGateway>
* @return 结果
* @return 结果
*/
*/
public
int
deleteDeviceGatewayById
(
Long
id
);
public
int
deleteDeviceGatewayById
(
Long
id
);
/**
* 网关状态监控
* @return
*/
boolean
deviceGatewayStatusMonitor
();
}
}
share-system/src/main/java/share/system/service/impl/DeviceGatewayServiceImpl.java
View file @
391570b2
package
share
.
system
.
service
.
impl
;
package
share
.
system
.
service
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
cn.hutool.core.date.DateUtil
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
share.common.enums.DeviceStatusEnum
;
import
share.common.utils.DateUtils
;
import
share.common.utils.DateUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -94,4 +99,24 @@ public class DeviceGatewayServiceImpl extends ServiceImpl<DeviceGatewayMapper, D
...
@@ -94,4 +99,24 @@ public class DeviceGatewayServiceImpl extends ServiceImpl<DeviceGatewayMapper, D
{
{
return
deviceGatewayMapper
.
deleteDeviceGatewayById
(
id
);
return
deviceGatewayMapper
.
deleteDeviceGatewayById
(
id
);
}
}
/**
* 网关状态监控
* @return
*/
@Override
public
boolean
deviceGatewayStatusMonitor
()
{
List
<
DeviceGateway
>
list
=
deviceGatewayMapper
.
selectDeviceGatewayList
(
new
DeviceGateway
());
list
.
stream
().
forEach
(
gateway
->
{
Date
lastReportDate
=
gateway
.
getLastReportDate
();
// 网关上报(最近10分钟内没有上报数据,网关设备离线)
Date
startDate
=
DateUtil
.
offsetMinute
(
DateUtil
.
date
(),
-
10
);
if
(
lastReportDate
!=
null
&&
lastReportDate
.
compareTo
(
startDate
)
>
0
)
{
gateway
.
setStatus
(
DeviceStatusEnum
.
DEVICE_ONLINE
.
getCode
());
}
else
{
gateway
.
setStatus
(
DeviceStatusEnum
.
DEVICE_OFFLINE
.
getCode
());
}
});
return
this
.
updateBatchById
(
list
);
}
}
}
share-system/src/main/java/share/system/service/impl/MqttxServiceImpl.java
View file @
391570b2
...
@@ -530,6 +530,18 @@ public class MqttxServiceImpl implements MqttxService {
...
@@ -530,6 +530,18 @@ public class MqttxServiceImpl implements MqttxService {
private
boolean
updateDevice
(
String
topic
,
String
payload
)
{
private
boolean
updateDevice
(
String
topic
,
String
payload
)
{
JSONObject
json
=
JSONUtil
.
parseObj
(
payload
);
JSONObject
json
=
JSONUtil
.
parseObj
(
payload
);
if
(
json
.
size
()
>
0
)
{
if
(
json
.
size
()
>
0
)
{
// 网关devId
String
gatewayDevId
=
json
.
getStr
(
"devId"
);
// 网关信息查询
DeviceGateway
deviceGateway
=
deviceGatewayMapper
.
selectDeviceGatewayByDevId
(
gatewayDevId
);
if
(
deviceGateway
!=
null
)
{
deviceGateway
.
setLastReportDate
(
DateUtil
.
date
());
deviceGateway
.
setLastReportContent
(
payload
);
deviceGateway
.
setUpdateTime
(
DateUtil
.
date
());
// 更新网关信息
deviceGatewayMapper
.
updateDeviceGateway
(
deviceGateway
);
}
// 设备上报信息
JSONArray
array
=
json
.
getJSONArray
(
"params"
);
JSONArray
array
=
json
.
getJSONArray
(
"params"
);
if
(
array
!=
null
&&
array
.
size
()
>
0
)
{
if
(
array
!=
null
&&
array
.
size
()
>
0
)
{
List
<
String
>
devIds
=
new
ArrayList
<>();
List
<
String
>
devIds
=
new
ArrayList
<>();
...
...
share-system/src/main/resources/mapper/system/DeviceGatewayMapper.xml
View file @
391570b2
...
@@ -24,10 +24,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -24,10 +24,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result
property=
"updateTime"
column=
"update_time"
/>
<result
property=
"updateTime"
column=
"update_time"
/>
<result
property=
"remark"
column=
"remark"
/>
<result
property=
"remark"
column=
"remark"
/>
<result
property=
"devPosition"
column=
"dev_position"
/>
<result
property=
"devPosition"
column=
"dev_position"
/>
<result
property=
"lastReportDate"
column=
"last_report_date"
/>
<result
property=
"lastReportContent"
column=
"last_report_content"
/>
</resultMap>
</resultMap>
<sql
id=
"selectDeviceGatewayVo"
>
<sql
id=
"selectDeviceGatewayVo"
>
select id, dev_name, dev_mac, dev_id, dev_psw, dev_ver, dev_type, `group`, status, mqtt_iP, mqtt_port, mqtt_user, mqtt_paswd, create_by, create_time, update_by, update_time, remark, dev_position from s_device_gateway
select id, dev_name, dev_mac, dev_id, dev_psw, dev_ver, dev_type, `group`, status, mqtt_iP, mqtt_port,
mqtt_user, mqtt_paswd, create_by, create_time, update_by, update_time, remark,
dev_position, last_report_date, last_report_content
from s_device_gateway
</sql>
</sql>
<select
id=
"selectDeviceGatewayList"
parameterType=
"DeviceGateway"
resultMap=
"DeviceGatewayResult"
>
<select
id=
"selectDeviceGatewayList"
parameterType=
"DeviceGateway"
resultMap=
"DeviceGatewayResult"
>
...
@@ -79,6 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -79,6 +84,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"updateTime != null"
>
update_time,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
<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=
"lastReportDate != null"
>
last_report_date,
</if>
<if
test=
"lastReportContent != null"
>
last_report_content,
</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>
...
@@ -99,6 +106,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -99,6 +106,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"updateTime != null"
>
#{updateTime},
</if>
<if
test=
"updateTime != null"
>
#{updateTime},
</if>
<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=
"lastReportDate != null"
>
#{lastReportDate},
</if>
<if
test=
"lastReportContent != null"
>
#{lastReportContent},
</if>
</trim>
</trim>
</insert>
</insert>
...
@@ -123,6 +132,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
...
@@ -123,6 +132,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if
test=
"updateTime != null"
>
update_time = #{updateTime},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime},
</if>
<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=
"lastReportDate != null"
>
last_report_date = #{lastReportDate},
</if>
<if
test=
"lastReportContent != null"
>
last_report_content = #{lastReportContent},
</if>
</trim>
</trim>
where id = #{id}
where id = #{id}
</update>
</update>
...
...
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