Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shadow-server
Project
Project
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
ubocare
shadow-server
Commits
d8b03c68
Commit
d8b03c68
authored
Oct 13, 2020
by
003
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
20201013 影子服务跟设备之间做状态同步
parent
02285ac3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
29 deletions
+52
-29
DeviceStatusMQ.java
...a/com/shadow/mq/nats/consumer/process/DeviceStatusMQ.java
+0
-28
ServiceDevicePower.java
...main/java/com/shadow/service/impl/ServiceDevicePower.java
+1
-1
ServiceStatusAll.java
src/main/java/com/shadow/service/impl/ServiceStatusAll.java
+51
-0
No files found.
src/main/java/com/shadow/mq/nats/consumer/process/DeviceStatusMQ.java
View file @
d8b03c68
package
com
.
shadow
.
mq
.
nats
.
consumer
.
process
;
package
com
.
shadow
.
mq
.
nats
.
consumer
.
process
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.dubbo.client.device.DeviceCMDBean
;
import
com.dubbo.client.device.DeviceCmdJsonService
;
import
com.shadow.iot.bean.DeviceStatusBean
;
import
com.shadow.iot.bean.DeviceStatusBean
;
import
com.shadow.iot.entity.DeviceInfoPO
;
import
com.shadow.iot.entity.DeviceInfoPO
;
import
com.shadow.iot.service.DeviceInfoService
;
import
com.shadow.iot.service.DeviceInfoService
;
...
@@ -17,7 +14,6 @@ import org.slf4j.LoggerFactory;
...
@@ -17,7 +14,6 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
/**
/**
...
@@ -31,8 +27,6 @@ public class DeviceStatusMQ implements NatsMQProcess {
...
@@ -31,8 +27,6 @@ public class DeviceStatusMQ implements NatsMQProcess {
.
getLogger
(
DeviceStatusMQ
.
class
);
.
getLogger
(
DeviceStatusMQ
.
class
);
@Autowired
@Autowired
DeviceInfoService
deviceService
;
DeviceInfoService
deviceService
;
@Autowired
DeviceCmdJsonService
deviceCmdJsonService
;
@Override
@Override
public
String
doProcess
(
Message
msg
)
{
public
String
doProcess
(
Message
msg
)
{
...
@@ -62,28 +56,6 @@ public class DeviceStatusMQ implements NatsMQProcess {
...
@@ -62,28 +56,6 @@ public class DeviceStatusMQ implements NatsMQProcess {
deviceService
.
updateById
(
deviceInfoPO
);
deviceService
.
updateById
(
deviceInfoPO
);
}
}
logger
.
info
(
"update device "
+
bean
.
getDevice_id
()
+
" online is "
+
bean
.
getOnline
());
logger
.
info
(
"update device "
+
bean
.
getDevice_id
()
+
" online is "
+
bean
.
getOnline
());
//影子预期的做工状态
String
deviceId
=
bean
.
getDevice_id
();
String
key
=
"desiredData"
+
deviceId
;
String
jsonString
=
RedisUtil
.
get
(
key
);
JSONObject
json
=
JSONObject
.
parseObject
(
jsonString
);
Integer
desiredPower
=
null
==
json
.
getInteger
(
"power"
)
?
0
:
json
.
getInteger
(
"power"
);
//设备上报的工作状态
Integer
realPower
=
null
==
bean
.
getOnline
()
?
0
:
bean
.
getOnline
();
//比较影子的状态跟设备上报状态,不一致则下发控制命令
if
(!
desiredPower
.
equals
(
realPower
))
{
DeviceCMDBean
cmd
=
new
DeviceCMDBean
();
cmd
.
setDevice_id
(
deviceId
);
cmd
.
setData
(
jsonString
);
cmd
.
setTopic
(
deviceId
);
deviceCmdJsonService
.
process
(
cmd
);
logger
.
info
(
"update shadow status "
+
jsonString
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
""
,
e
);
logger
.
error
(
""
,
e
);
}
}
...
...
src/main/java/com/shadow/service/impl/ServiceDevicePower.java
View file @
d8b03c68
...
@@ -21,7 +21,7 @@ public class ServiceDevicePower implements CmdShadowService {
...
@@ -21,7 +21,7 @@ public class ServiceDevicePower implements CmdShadowService {
@Override
@Override
public
void
process
(
PublishTopicMessage
bean
)
{
public
void
process
(
PublishTopicMessage
bean
)
{
logger
.
error
(
"ServiceDevicePower :"
+
bean
.
getData
());
logger
.
info
(
"ServiceDevicePower :"
+
bean
.
getData
());
//获取数据
//获取数据
JSONObject
json
=
JSON
.
parseObject
(
bean
.
getData
());
JSONObject
json
=
JSON
.
parseObject
(
bean
.
getData
());
String
deviceId
=
bean
.
getDeviceId
();
String
deviceId
=
bean
.
getDeviceId
();
...
...
src/main/java/com/shadow/service/impl/ServiceStatusAll.java
0 → 100644
View file @
d8b03c68
package
com
.
shadow
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.component.base.bean.PublishTopicMessage
;
import
com.dubbo.client.device.DeviceCMDBean
;
import
com.dubbo.client.device.DeviceCmdJsonService
;
import
com.shadow.service.CmdShadowService
;
import
com.shadow.util.RedisUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* 设备的全状态上报
*
* @author cavin
*/
@Service
public
class
ServiceStatusAll
implements
CmdShadowService
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ServiceStatusAll
.
class
);
@Autowired
DeviceCmdJsonService
deviceCmdJsonService
;
@Override
public
void
process
(
PublishTopicMessage
bean
)
{
logger
.
info
(
"ServiceStatusAll :"
+
bean
.
getData
());
//影子预期的做工状态
String
deviceId
=
bean
.
getDeviceId
();
String
key
=
"desiredData"
+
deviceId
;
String
jsonString
=
RedisUtil
.
get
(
key
);
JSONObject
json
=
JSONObject
.
parseObject
(
jsonString
);
Integer
desiredPower
=
null
==
json
.
getInteger
(
"power"
)
?
0
:
json
.
getInteger
(
"power"
);
//设备上报的工作状态
JSONObject
realJson
=
JSON
.
parseObject
(
bean
.
getData
());
Integer
realPower
=
null
==
realJson
.
getInteger
(
"power"
)
?
0
:
realJson
.
getInteger
(
"power"
);
//比较影子的状态跟设备上报状态,不一致则下发控制命令
if
(!
desiredPower
.
equals
(
realPower
))
{
DeviceCMDBean
cmd
=
new
DeviceCMDBean
();
cmd
.
setDevice_id
(
deviceId
);
cmd
.
setData
(
jsonString
);
cmd
.
setTopic
(
deviceId
);
deviceCmdJsonService
.
process
(
cmd
);
logger
.
info
(
"update shadow status "
+
jsonString
);
}
}
}
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