Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
device-new-platform
Commits
06c92b7f
Commit
06c92b7f
authored
Dec 16, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分组更新设备
parent
b663fa56
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
5 deletions
+39
-5
device-manager/src/main/java/com/mortals/xhx/thread/DeviceUpdateComsumerThread.java
...va/com/mortals/xhx/thread/DeviceUpdateComsumerThread.java
+30
-3
device-manager/src/main/java/com/mortals/xhx/thread/SendThirdPartyThread.java
...ain/java/com/mortals/xhx/thread/SendThirdPartyThread.java
+9
-2
No files found.
device-manager/src/main/java/com/mortals/xhx/thread/DeviceUpdateComsumerThread.java
View file @
06c92b7f
...
...
@@ -13,7 +13,10 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.ObjectUtils
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -31,14 +34,15 @@ public class DeviceUpdateComsumerThread extends AbstractThread {
@Autowired
private
DeviceService
deviceService
;
//
@Override
protected
int
getSleepTime
()
{
return
10
00
;
return
36
00
;
}
@Override
protected
void
process
()
{
//
log.info("DeviceUpdateComsumerThread process");
log
.
info
(
"DeviceUpdateComsumerThread process"
);
List
<
DeviceEntity
>
waitUpdateDeviceList
=
new
ArrayList
<>();
while
(
true
)
{
DeviceEntity
deviceEntity
=
cacheService
.
lpop
(
RedisKey
.
KEY_DEVICE_UPDATE_QUEUE
,
DeviceEntity
.
class
);
...
...
@@ -48,13 +52,36 @@ public class DeviceUpdateComsumerThread extends AbstractThread {
}
waitUpdateDeviceList
.
add
(
deviceEntity
);
}
//分组更新
if
(!
ObjectUtils
.
isEmpty
(
waitUpdateDeviceList
))
{
log
.
info
(
"updateDeviceList size:{}"
,
waitUpdateDeviceList
.
size
());
Map
<
Long
,
List
<
DeviceEntity
>>
collect
=
waitUpdateDeviceList
.
parallelStream
().
collect
(
Collectors
.
groupingBy
(
x
->
x
.
getId
()));
collect
.
entrySet
().
stream
().
forEach
(
item
->{
List
<
DeviceEntity
>
sortUpdateList
=
item
.
getValue
().
stream
().
sorted
(
new
Comparator
<
DeviceEntity
>()
{
@Override
public
int
compare
(
DeviceEntity
o1
,
DeviceEntity
o2
)
{
if
(
o1
.
getUpdateTime
()
==
null
)
return
0
;
if
(
o2
.
getUpdateTime
()
==
null
)
return
0
;
long
start
=
o1
.
getUpdateTime
().
getTime
();
long
end
=
o2
.
getUpdateTime
().
getTime
();
if
(
end
>
start
)
{
return
1
;
}
else
if
(
end
<
start
)
{
return
-
1
;
}
else
{
return
0
;
}
}
}).
collect
(
Collectors
.
toList
());
deviceService
.
update
(
sortUpdateList
);
});
/*
for (DeviceEntity deviceEntity : waitUpdateDeviceList) {
deviceService.update(deviceEntity);
}
*/
}
}
...
...
device-manager/src/main/java/com/mortals/xhx/thread/SendThirdPartyThread.java
View file @
06c92b7f
...
...
@@ -2,11 +2,13 @@ package com.mortals.xhx.thread;
import
cn.hutool.core.net.url.UrlBuilder
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.ap.GlobalSysInfo
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.util.AbstractThread
;
import
com.mortals.xhx.base.system.message.MessageService
;
import
com.mortals.xhx.busiz.rsp.ApiResp
;
import
com.mortals.xhx.common.code.DeviceMethodEnum
;
import
com.mortals.xhx.common.pdu.DeviceReq
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -47,9 +49,14 @@ public class SendThirdPartyThread extends AbstractThread {
// log.info("SendThirdPartyThread process");
DeviceReq
deviceReq
=
cacheService
.
blpop
(
KEY_DEVICE_THIRDPARTY_QUEUE
,
10
,
DeviceReq
.
class
);
if
(!
ObjectUtils
.
isEmpty
(
deviceReq
))
{
//设备上下线信息 不更新
if
(
DeviceMethodEnum
.
ONLINE
.
getValue
()
==
deviceReq
.
getReceiveMethod
()
||
DeviceMethodEnum
.
ONLINE
.
getValue
()
==
deviceReq
.
getReceiveMethod
())
{
return
;
}
//deviceReq.getReceiveMethod()
String
phpInUrl
=
GlobalSysInfo
.
getParamValue
(
PARAM_SERVER_PHP_IN_HTTP_URL
,
"http://127.0.0.1:11078/zwfw_api"
);
ApiResp
<
String
>
resp
=
messageService
.
sendThirdParty
(
UrlBuilder
.
of
(
phpInUrl
).
addPath
(
thirdPartyPath
).
build
(),
deviceReq
);
// log.info("sendThirty resp ==>{}"
, JSON.toJSONString(resp));
log
.
info
(
"sendThirty req==>{} \n resp ==>{}"
,
JSON
.
toJSONString
(
deviceReq
)
,
JSON
.
toJSONString
(
resp
));
}
}
...
...
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