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 a6c59d43
authored
Nov 01, 2024
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[add] 接收 Agent 发送的组织关系
1 parent
7e058801
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
137 additions
and
30 deletions
src/main/java/vion/controller/monitor/AgentController.java
src/main/java/vion/controller/mqtt/MonitorController.java
src/main/java/vion/controller/mqtt/MqttController.java
src/main/java/vion/dto/AgentDTO.java → src/main/java/vion/dto/monitor/AgentDTO.java
src/main/java/vion/dto/MqttAuthDTO.java → src/main/java/vion/dto/monitor/MqttAuthDTO.java
src/main/java/vion/dto/monitor/OrgDTO.java
src/main/java/vion/model/monitor/Agent.java
src/main/java/vion/model/monitor/Mall.java
src/main/java/vion/service/impl/monitor/AgentServiceImpl.java
src/main/java/vion/service/impl/monitor/UpgradeServiceImpl.java
src/main/java/vion/service/monitor/IAgentService.java
src/main/java/vion/vo/AgentVO.java → src/main/java/vion/vo/monitor/AgentVO.java
src/main/java/vion/controller/monitor/AgentController.java
View file @
a6c59d4
...
@@ -4,11 +4,11 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
...
@@ -4,11 +4,11 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
vion.dto.AgentDTO
;
import
vion.dto.
monitor.
AgentDTO
;
import
vion.model.monitor.RAgentService
;
import
vion.model.monitor.RAgentService
;
import
vion.model.monitor.ServiceInfo
;
import
vion.model.monitor.ServiceInfo
;
import
vion.service.monitor.IAgentService
;
import
vion.service.monitor.IAgentService
;
import
vion.vo.AgentVO
;
import
vion.vo.
monitor.
AgentVO
;
import
java.util.List
;
import
java.util.List
;
...
@@ -60,7 +60,7 @@ public class AgentController {
...
@@ -60,7 +60,7 @@ public class AgentController {
return
agentService
.
saveServicesByUid
(
uid
,
serviceInfoList
);
return
agentService
.
saveServicesByUid
(
uid
,
serviceInfoList
);
}
}
@PostMapping
(
"/service/{id}"
)
@PostMapping
(
"/service/
edit/
{id}"
)
@SaCheckPermission
(
value
=
"agent:service:edit"
,
orRole
=
"admin"
)
@SaCheckPermission
(
value
=
"agent:service:edit"
,
orRole
=
"admin"
)
public
String
updateAgent2ServiceById
(
@PathVariable
Long
id
,
@RequestBody
RAgentService
rAgentService
)
{
public
String
updateAgent2ServiceById
(
@PathVariable
Long
id
,
@RequestBody
RAgentService
rAgentService
)
{
return
agentService
.
updateAgent2ServiceById
(
id
,
rAgentService
);
return
agentService
.
updateAgent2ServiceById
(
id
,
rAgentService
);
...
...
src/main/java/vion/controller/mqtt/MonitorController.java
View file @
a6c59d4
...
@@ -2,6 +2,7 @@ package vion.controller.mqtt;
...
@@ -2,6 +2,7 @@ package vion.controller.mqtt;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
vion.dto.monitor.OrgDTO
;
import
vion.model.monitor.Agent
;
import
vion.model.monitor.Agent
;
import
vion.model.monitor.AgentRecord
;
import
vion.model.monitor.AgentRecord
;
import
vion.model.monitor.ServiceRecord
;
import
vion.model.monitor.ServiceRecord
;
...
@@ -21,23 +22,58 @@ public class MonitorController {
...
@@ -21,23 +22,58 @@ public class MonitorController {
private
final
IAgentService
agentService
;
private
final
IAgentService
agentService
;
/**
* Agent 注册
*
* @param agent agent自身信息
* @return java.lang.String
*/
@PostMapping
(
"/reg"
)
@PostMapping
(
"/reg"
)
public
String
reg
(
@RequestBody
Agent
agent
)
{
public
String
reg
(
@RequestBody
Agent
agent
)
{
return
agentService
.
reg
(
agent
);
return
agentService
.
reg
(
agent
);
}
}
/**
* Agent 获取升级包信息
*
* @param type 1:store 2:mall
* @return Upgrade 升级包信息
*/
@GetMapping
(
"/upgrade"
)
@GetMapping
(
"/upgrade"
)
public
Upgrade
getUpgradeInfo
(
Short
type
)
{
public
Upgrade
getUpgradeInfo
(
Short
type
)
{
return
agentService
.
getUpgradeInfo
(
type
);
return
agentService
.
getUpgradeInfo
(
type
);
}
}
/**
* Agent 发送服务器信息
*
* @param agentRecord 服务器相关信息
* @return java.lang.String
*/
@PostMapping
(
"/server"
)
@PostMapping
(
"/server"
)
public
String
recServerInfo
(
@RequestBody
AgentRecord
agentRecord
)
{
public
String
recServerInfo
(
@RequestBody
AgentRecord
agentRecord
)
{
return
agentService
.
recAgentRecord
(
agentRecord
);
return
agentService
.
recAgentRecord
(
agentRecord
);
}
}
/**
* Agent 发送服务状态
*
* @param recList 服务状态
* @return java.lang.String
*/
@PostMapping
(
"/service"
)
@PostMapping
(
"/service"
)
public
String
recServiceInfo
(
@RequestBody
List
<
ServiceRecord
>
recList
)
{
public
String
recServiceInfo
(
@RequestBody
List
<
ServiceRecord
>
recList
)
{
return
agentService
.
recServiceInfo
(
recList
);
return
agentService
.
recServiceInfo
(
recList
);
}
}
/**
* Agent 发送组织关系
*
* @param orgDTO account、mall
* @return java.lang.String
*/
@PostMapping
(
"/org"
)
public
String
recOrgInfo
(
@RequestBody
OrgDTO
orgDTO
)
{
return
agentService
.
recOrgInfo
(
orgDTO
);
}
}
}
src/main/java/vion/controller/mqtt/MqttController.java
View file @
a6c59d4
...
@@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
...
@@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
vion.dto.MqttAuthDTO
;
import
vion.dto.
monitor.
MqttAuthDTO
;
import
vion.service.monitor.IAgentService
;
import
vion.service.monitor.IAgentService
;
/**
/**
...
@@ -35,5 +35,7 @@ public class MqttController {
...
@@ -35,5 +35,7 @@ public class MqttController {
}
}
@GetMapping
(
"/stopEvent"
)
@GetMapping
(
"/stopEvent"
)
public
void
stopEvent
()
{
agentService
.
stopEvent
();}
public
void
stopEvent
()
{
agentService
.
stopEvent
();
}
}
}
src/main/java/vion/dto/AgentDTO.java
→
src/main/java/vion/dto/
monitor/
AgentDTO.java
View file @
a6c59d4
package
vion
.
dto
;
package
vion
.
dto
.
monitor
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
import
vion.dto.BaseDTO
;
/**
/**
* @author vion
* @author vion
...
...
src/main/java/vion/dto/MqttAuthDTO.java
→
src/main/java/vion/dto/
monitor/
MqttAuthDTO.java
View file @
a6c59d4
package
vion
.
dto
;
package
vion
.
dto
.
monitor
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
...
...
src/main/java/vion/dto/monitor/OrgDTO.java
0 → 100644
View file @
a6c59d4
package
vion
.
dto
.
monitor
;
import
lombok.Getter
;
import
lombok.Setter
;
import
vion.model.monitor.MAccount
;
import
vion.model.monitor.Mall
;
import
java.util.List
;
/**
* @author vion
* @date 2024/11/1
*/
@Getter
@Setter
public
class
OrgDTO
{
private
String
agentUid
;
private
Short
agentType
;
private
List
<
MAccount
>
accountList
;
private
List
<
Mall
>
mallList
;
}
src/main/java/vion/model/monitor/Agent.java
View file @
a6c59d4
...
@@ -5,8 +5,8 @@ import io.github.linpeilie.annotations.AutoMapper;
...
@@ -5,8 +5,8 @@ import io.github.linpeilie.annotations.AutoMapper;
import
io.github.linpeilie.annotations.AutoMappers
;
import
io.github.linpeilie.annotations.AutoMappers
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
import
vion.dto.AgentDTO
;
import
vion.dto.
monitor.
AgentDTO
;
import
vion.vo.AgentVO
;
import
vion.vo.
monitor.
AgentVO
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
...
src/main/java/vion/model/monitor/Mall.java
View file @
a6c59d4
...
@@ -37,8 +37,8 @@ public class Mall {
...
@@ -37,8 +37,8 @@ public class Mall {
/**
/**
* mall unid
* mall unid
*/
*/
@TableField
(
value
=
"
mall_
uid"
)
@TableField
(
value
=
"uid"
)
private
String
mallU
id
;
private
String
u
id
;
/**
/**
* mall名称
* mall名称
...
...
src/main/java/vion/service/impl/monitor/AgentServiceImpl.java
View file @
a6c59d4
package
vion
.
service
.
impl
.
monitor
;
package
vion
.
service
.
impl
.
monitor
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.segments.MergeSegments
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
...
@@ -30,16 +24,19 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -30,16 +24,19 @@ import org.springframework.transaction.annotation.Transactional;
import
vion.constant.AgentTypeEnum
;
import
vion.constant.AgentTypeEnum
;
import
vion.constant.EventStatusEnum
;
import
vion.constant.EventStatusEnum
;
import
vion.constant.MqttTopic
;
import
vion.constant.MqttTopic
;
import
vion.dto.AgentDTO
;
import
vion.dto.monitor.AgentDTO
;
import
vion.dto.MqttAuthDTO
;
import
vion.dto.monitor.MqttAuthDTO
;
import
vion.dto.monitor.OrgDTO
;
import
vion.mapper.monitor.AgentMapper
;
import
vion.mapper.monitor.AgentMapper
;
import
vion.model.monitor.*
;
import
vion.model.monitor.*
;
import
vion.service.monitor.*
;
import
vion.service.monitor.*
;
import
vion.utils.JsonUtil
;
import
vion.utils.JsonUtil
;
import
vion.vo.AgentVO
;
import
vion.vo.
monitor.
AgentVO
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -59,6 +56,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
...
@@ -59,6 +56,8 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
private
final
IUpgradeService
upgradeService
;
private
final
IUpgradeService
upgradeService
;
private
final
Converter
converter
;
private
final
Converter
converter
;
private
final
MqttClientTemplate
client
;
private
final
MqttClientTemplate
client
;
private
final
IMAccountService
accountService
;
private
final
IMallService
mallService
;
@Value
(
value
=
"${mqtt.client.server-topic:/MS/receive}"
)
@Value
(
value
=
"${mqtt.client.server-topic:/MS/receive}"
)
private
String
serverTopic
;
private
String
serverTopic
;
...
@@ -222,6 +221,52 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
...
@@ -222,6 +221,52 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
}
}
@Override
@Override
public
String
recOrgInfo
(
OrgDTO
orgDTO
)
{
var
agentUid
=
orgDTO
.
getAgentUid
();
var
agentType
=
orgDTO
.
getAgentType
();
var
accountList
=
orgDTO
.
getAccountList
();
var
mallList
=
orgDTO
.
getMallList
();
var
existAccList
=
accountService
.
lambdaQuery
().
eq
(
MAccount:
:
getAgentUid
,
agentUid
).
list
();
var
uid2AccMap
=
existAccList
.
stream
().
collect
(
Collectors
.
toMap
(
MAccount:
:
getUid
,
Function
.
identity
()));
var
existMallList
=
mallService
.
lambdaQuery
().
eq
(
Mall:
:
getAgentUid
,
agentUid
).
list
();
var
uid2MallMap
=
existMallList
.
stream
().
collect
(
Collectors
.
toMap
(
Mall:
:
getUid
,
Function
.
identity
()));
List
<
MAccount
>
insAccList
=
new
ArrayList
<>();
List
<
MAccount
>
updAccList
=
new
ArrayList
<>();
accountList
.
forEach
(
a
->
{
if
(
uid2AccMap
.
containsKey
(
a
.
getUid
()))
{
var
acc
=
uid2AccMap
.
get
(
a
.
getUid
());
a
.
setId
(
acc
.
getId
());
updAccList
.
add
(
a
);
}
else
{
a
.
setAgentUid
(
agentUid
);
a
.
setAgentType
(
agentType
);
insAccList
.
add
(
a
);
}
});
List
<
Mall
>
insMallList
=
new
ArrayList
<>();
List
<
Mall
>
updMallList
=
new
ArrayList
<>();
mallList
.
forEach
(
m
->
{
if
(
uid2MallMap
.
containsKey
(
m
.
getUid
()))
{
var
acc
=
uid2MallMap
.
get
(
m
.
getUid
());
m
.
setId
(
acc
.
getId
());
updMallList
.
add
(
m
);
}
else
{
m
.
setAgentUid
(
agentUid
);
m
.
setAgentType
(
agentType
);
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
);
return
"success"
;
}
@Override
public
ObjectNode
auth
(
MqttAuthDTO
dto
)
{
public
ObjectNode
auth
(
MqttAuthDTO
dto
)
{
var
clientid
=
dto
.
getClientid
();
var
clientid
=
dto
.
getClientid
();
if
(
StrUtil
.
equals
(
clientid
,
"MS8011"
)
||
StrUtil
.
equals
(
clientid
,
"test"
))
{
if
(
StrUtil
.
equals
(
clientid
,
"MS8011"
)
||
StrUtil
.
equals
(
clientid
,
"test"
))
{
...
@@ -284,19 +329,18 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
...
@@ -284,19 +329,18 @@ public class AgentServiceImpl extends MPJBaseServiceImpl<AgentMapper, Agent> imp
@Override
@Override
public
String
getAgentEventTopic
(
String
agentUid
)
{
public
String
getAgentEventTopic
(
String
agentUid
)
{
Agent
agent
=
this
.
baseMapper
.
selectOne
(
new
QueryWrapper
<
Agent
>().
eq
(
"uid"
,
agentUid
)
);
Agent
agent
=
this
.
lambdaQuery
().
eq
(
Agent:
:
getUid
,
agentUid
).
one
(
);
if
(
agent
==
null
)
{
if
(
ObjUtil
.
isNull
(
agent
)
)
{
log
.
info
(
"agent {} 不存在"
,
agentUid
);
log
.
info
(
"agent {} 不存在"
,
agentUid
);
return
null
;
return
null
;
}
}
if
(
agent
.
getType
()
==
AgentTypeEnum
.
STORE
.
getCode
(
))
{
if
(
ObjUtil
.
equals
(
agent
.
getType
(),
AgentTypeEnum
.
STORE
.
getCode
()
))
{
return
StrUtil
.
format
(
MqttTopic
.
STORE_EVENT_TOPIC
,
agentUid
);
return
StrUtil
.
format
(
MqttTopic
.
STORE_EVENT_TOPIC
,
agentUid
);
}
else
if
(
agent
.
getType
()
==
AgentTypeEnum
.
MALL
.
getCode
(
))
{
}
else
if
(
ObjUtil
.
equals
(
agent
.
getType
(),
AgentTypeEnum
.
MALL
.
getCode
()
))
{
return
StrUtil
.
format
(
MqttTopic
.
MALL_EVENT_TOPIC
,
agentUid
);
return
StrUtil
.
format
(
MqttTopic
.
MALL_EVENT_TOPIC
,
agentUid
);
}
else
{
}
else
{
log
.
info
(
"未知的agent类型"
);
log
.
info
(
"未知的agent类型"
);
}
}
return
null
;
return
null
;
}
}
...
...
src/main/java/vion/service/impl/monitor/UpgradeServiceImpl.java
View file @
a6c59d4
...
@@ -49,7 +49,7 @@ public class UpgradeServiceImpl extends ServiceImpl<UpgradeMapper, Upgrade> impl
...
@@ -49,7 +49,7 @@ public class UpgradeServiceImpl extends ServiceImpl<UpgradeMapper, Upgrade> impl
Assert
.
equals
(
version
,
upgrade
.
getVersion
(),
"升级包版本号不一致"
);
Assert
.
equals
(
version
,
upgrade
.
getVersion
(),
"升级包版本号不一致"
);
var
name
=
manifest
.
getMainAttributes
().
getValue
(
Attributes
.
Name
.
IMPLEMENTATION_TITLE
);
var
name
=
manifest
.
getMainAttributes
().
getValue
(
Attributes
.
Name
.
IMPLEMENTATION_TITLE
);
Assert
.
equals
(
version
,
upgrade
.
getName
(),
"升级包名称不一致"
);
Assert
.
equals
(
name
,
upgrade
.
getName
(),
"升级包名称不一致"
);
upgrade
.
setVersion
(
version
);
upgrade
.
setVersion
(
version
);
...
...
src/main/java/vion/service/monitor/IAgentService.java
View file @
a6c59d4
...
@@ -5,10 +5,11 @@ import com.fasterxml.jackson.databind.JsonNode;
...
@@ -5,10 +5,11 @@ import com.fasterxml.jackson.databind.JsonNode;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.github.yulichang.base.MPJBaseService
;
import
com.github.yulichang.base.MPJBaseService
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
vion.dto.AgentDTO
;
import
vion.dto.monitor.AgentDTO
;
import
vion.dto.MqttAuthDTO
;
import
vion.dto.monitor.MqttAuthDTO
;
import
vion.dto.monitor.OrgDTO
;
import
vion.model.monitor.*
;
import
vion.model.monitor.*
;
import
vion.vo.AgentVO
;
import
vion.vo.
monitor.
AgentVO
;
import
java.util.List
;
import
java.util.List
;
...
@@ -42,6 +43,8 @@ public interface IAgentService extends MPJBaseService<Agent> {
...
@@ -42,6 +43,8 @@ public interface IAgentService extends MPJBaseService<Agent> {
String
recAgentRecord
(
AgentRecord
agentRecord
);
String
recAgentRecord
(
AgentRecord
agentRecord
);
String
recServiceInfo
(
List
<
ServiceRecord
>
recList
);
String
recServiceInfo
(
List
<
ServiceRecord
>
recList
);
String
recOrgInfo
(
OrgDTO
orgDTO
);
// endregion
// endregion
// region Mqtt Server 回调接口
// region Mqtt Server 回调接口
...
...
src/main/java/vion/vo/AgentVO.java
→
src/main/java/vion/vo/
monitor/
AgentVO.java
View file @
a6c59d4
package
vion
.
vo
;
package
vion
.
vo
.
monitor
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
...
...
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