Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李苗
/
Vion-DevOps
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 571762e0
authored
Nov 04, 2024
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[fix] mall 绑定事件 Bug 修改
1 parent
5111b8c7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
25 deletions
src/main/java/vion/controller/monitor/EventController.java
src/main/java/vion/service/impl/monitor/AgentServiceImpl.java
src/main/java/vion/service/impl/monitor/MallServiceImpl.java
src/main/java/vion/service/impl/monitor/RAgentEventServiceImpl.java
src/main/java/vion/service/monitor/IRAgentEventService.java
src/main/java/vion/vo/monitor/MallVO.java
src/main/java/vion/controller/monitor/EventController.java
View file @
571762e
...
...
@@ -65,13 +65,13 @@ public class EventController {
return
eventService
.
list
(
dto
);
}
@PostMapping
(
"/bind/{agentUid}"
)
@PostMapping
(
"/bind/{agentUid}
/{mallUid}
"
)
@SaCheckPermission
(
value
=
"event:bind"
,
orRole
=
"admin"
)
public
String
bind
(
@PathVariable
String
agentUid
,
@RequestBody
List
<
RAgentEvent
>
dtoList
)
{
return
agentEventService
.
bind
(
agentUid
,
dtoList
);
public
String
bind
(
@PathVariable
String
agentUid
,
@
PathVariable
String
mallUid
,
@
RequestBody
List
<
RAgentEvent
>
dtoList
)
{
return
agentEventService
.
bind
(
agentUid
,
mallUid
,
dtoList
);
}
@PostMapping
(
"/unbind"
)
@PostMapping
(
"/unbind
/{agentUid}/{mallUid}
"
)
@SaCheckPermission
(
value
=
"event:unbind"
,
orRole
=
"admin"
)
public
String
unbind
(
List
<
Long
>
idList
)
{
return
agentEventService
.
unbind
(
idList
);
...
...
src/main/java/vion/service/impl/monitor/AgentServiceImpl.java
View file @
571762e
...
...
@@ -263,9 +263,9 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
var
accountList
=
orgDTO
.
getAccountList
();
var
mallList
=
orgDTO
.
getMallList
();
var
existAccList
=
accountService
.
l
ambdaQuery
().
eq
(
MAccount:
:
getAgentUid
,
agentUid
).
l
ist
();
var
existAccList
=
accountService
.
list
();
var
uid2AccMap
=
existAccList
.
stream
().
collect
(
Collectors
.
toMap
(
MAccount:
:
getUid
,
Function
.
identity
()));
var
existMallList
=
mallService
.
l
ambdaQuery
().
eq
(
Mall:
:
getAgentUid
,
agentUid
).
l
ist
();
var
existMallList
=
mallService
.
list
();
var
uid2MallMap
=
existMallList
.
stream
().
collect
(
Collectors
.
toMap
(
Mall:
:
getUid
,
Function
.
identity
()));
List
<
MAccount
>
insAccList
=
new
ArrayList
<>();
...
...
@@ -286,8 +286,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
List
<
Mall
>
updMallList
=
new
ArrayList
<>();
mallList
.
forEach
(
m
->
{
if
(
uid2MallMap
.
containsKey
(
m
.
getUid
()))
{
var
acc
=
uid2MallMap
.
get
(
m
.
getUid
());
m
.
setId
(
acc
.
getId
());
var
mall
=
uid2MallMap
.
get
(
m
.
getUid
());
m
.
setId
(
mall
.
getId
());
updMallList
.
add
(
m
);
}
else
{
m
.
setAgentUid
(
agentUid
);
...
...
@@ -295,10 +295,18 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
insMallList
.
add
(
m
);
}
});
Opt
.
ofEmptyAble
(
insAccList
).
ifPresent
(
accountService:
:
saveBatch
);
Opt
.
ofEmptyAble
(
insMallList
).
ifPresent
(
mallService:
:
saveBatch
);
Opt
.
ofEmptyAble
(
updAccList
).
ifPresent
(
accountService:
:
updateBatchById
);
Opt
.
ofEmptyAble
(
updMallList
).
ifPresent
(
mallService:
:
updateBatchById
);
if
(
CollUtil
.
isNotEmpty
(
insAccList
))
{
accountService
.
saveBatch
(
insAccList
);
}
if
(
CollUtil
.
isNotEmpty
(
insMallList
))
{
mallService
.
saveBatch
(
insMallList
);
}
if
(
CollUtil
.
isNotEmpty
(
updAccList
))
{
accountService
.
updateBatchById
(
updAccList
);
}
if
(
CollUtil
.
isNotEmpty
(
updMallList
))
{
mallService
.
updateBatchById
(
updMallList
);
}
return
"success"
;
}
...
...
src/main/java/vion/service/impl/monitor/MallServiceImpl.java
View file @
571762e
...
...
@@ -18,7 +18,6 @@ import vion.service.monitor.IEventRecordService;
import
vion.service.monitor.IMallService
;
import
vion.vo.monitor.MallVO
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -50,9 +49,9 @@ public class MallServiceImpl extends MPJBaseServiceImpl<MallMapper, Mall> implem
.
in
(
"mall_uid"
,
mallUidList
)
.
orderByDesc
(
"mall_uid"
,
"create_time"
);
var
eventRecordList
=
eventRecordService
.
list
(
eventRecWrapper
);
var
eventUid2SelfMap
=
eventRecordList
.
stream
().
collect
(
Collectors
.
toMap
(
EventRecord:
:
getEventUid
,
Function
.
identity
()
));
var
mallUid2SelfMap
=
eventRecordList
.
stream
().
collect
(
Collectors
.
groupingBy
(
EventRecord:
:
getMallUid
));
r
.
forEach
(
tmp
->
tmp
.
setEventRecord
(
event
Uid2SelfMap
.
get
(
tmp
.
getUid
())));
r
.
forEach
(
tmp
->
tmp
.
setEventRecord
List
(
mall
Uid2SelfMap
.
get
(
tmp
.
getUid
())));
});
return
mallVOPage
;
}
...
...
src/main/java/vion/service/impl/monitor/RAgentEventServiceImpl.java
View file @
571762e
package
vion
.
service
.
impl
.
monitor
;
import
com.github.yulichang.base.MPJBaseServiceImpl
;
import
org.dromara.hutool.core.lang.Opt
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.iot.mqtt.codec.MqttQoS
;
import
net.dreamlu.iot.mqtt.spring.client.MqttClientTemplate
;
import
org.dromara.hutool.core.collection.CollUtil
;
import
org.dromara.hutool.core.text.StrUtil
;
import
org.springframework.stereotype.Service
;
import
vion.mapper.monitor.RAgentEventMapper
;
import
vion.model.monitor.RAgentEvent
;
import
vion.service.monitor.IRAgentEventService
;
import
vion.utils.JsonUtil
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -17,32 +22,42 @@ import java.util.stream.Collectors;
* @date 2024/10/31
*/
@Service
@RequiredArgsConstructor
public
class
RAgentEventServiceImpl
extends
MPJBaseServiceImpl
<
RAgentEventMapper
,
RAgentEvent
>
implements
IRAgentEventService
{
private
final
MqttClientTemplate
client
;
@Override
public
String
bind
(
String
agentUid
,
List
<
RAgentEvent
>
dtoList
)
{
public
String
bind
(
String
agentUid
,
String
mallUid
,
List
<
RAgentEvent
>
dtoList
)
{
dtoList
.
forEach
(
ae
->
ae
.
setAgentUid
(
agentUid
));
var
agentEventList
=
this
.
lambdaQuery
().
eq
(
RAgentEvent:
:
get
AgentUid
,
agent
Uid
).
list
();
var
mallUid2AEMap
=
agentEventList
.
stream
().
collect
(
Collectors
.
toMap
(
RAgentEvent:
:
getMall
Uid
,
Function
.
identity
()));
var
agentEventList
=
this
.
lambdaQuery
().
eq
(
RAgentEvent:
:
get
MallUid
,
mall
Uid
).
list
();
var
eventUid2AEMap
=
agentEventList
.
stream
().
collect
(
Collectors
.
toMap
(
RAgentEvent:
:
getEvent
Uid
,
Function
.
identity
()));
List
<
RAgentEvent
>
updList
=
new
ArrayList
<>();
List
<
RAgentEvent
>
insList
=
new
ArrayList
<>();
dtoList
.
forEach
(
dto
->
{
if
(
mallUid2AEMap
.
containsKey
(
dto
.
getMall
Uid
()))
{
var
ae
=
mallUid2AEMap
.
get
(
dto
.
getMall
Uid
());
if
(
eventUid2AEMap
.
containsKey
(
dto
.
getEvent
Uid
()))
{
var
ae
=
eventUid2AEMap
.
get
(
dto
.
getEvent
Uid
());
dto
.
setId
(
ae
.
getId
());
updList
.
add
(
dto
);
}
else
{
insList
.
add
(
dto
);
}
});
Opt
.
ofEmptyAble
(
updList
).
ifPresent
(
this
::
updateBatchById
);
Opt
.
ofEmptyAble
(
insList
).
ifPresent
(
this
::
saveBatch
);
if
(
CollUtil
.
isNotEmpty
(
updList
))
{
this
.
updateBatchById
(
updList
);
}
if
(
CollUtil
.
isNotEmpty
(
insList
))
{
this
.
saveBatch
(
insList
);
}
dtoList
.
forEach
(
dto
->
client
.
publish
(
StrUtil
.
format
(
"/SA/{}/event/push"
,
agentUid
),
JsonUtil
.
toJsonByte
(
dto
),
MqttQoS
.
QOS2
));
return
"绑定成功"
;
}
@Override
public
String
unbind
(
List
<
Long
>
idList
)
{
// todo
// client.publish(StrUtil.format("/SA/{}/event/push", agentUid), JsonUtil.toJsonByte(agentEvent), MqttQoS.QOS2);
return
this
.
removeBatchByIds
(
idList
)
?
"解绑成功"
:
"解绑失败"
;
}
}
src/main/java/vion/service/monitor/IRAgentEventService.java
View file @
571762e
...
...
@@ -11,7 +11,7 @@ import java.util.List;
*/
public
interface
IRAgentEventService
extends
MPJBaseService
<
RAgentEvent
>
{
String
bind
(
String
agentUid
,
List
<
RAgentEvent
>
dtoList
);
String
bind
(
String
agentUid
,
String
mallUid
,
List
<
RAgentEvent
>
dtoList
);
String
unbind
(
List
<
Long
>
idList
);
...
...
src/main/java/vion/vo/monitor/MallVO.java
View file @
571762e
...
...
@@ -5,6 +5,7 @@ import lombok.Setter;
import
vion.model.monitor.EventRecord
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
* 项目mall信息
...
...
@@ -59,5 +60,5 @@ public class MallVO {
private
LocalDateTime
updateTime
;
private
EventRecord
eventRecord
;
private
List
<
EventRecord
>
eventRecordList
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment