优化基于CID 的用户统计

This commit is contained in:
2025-11-13 11:28:25 +08:00
parent 56771a0de0
commit 3dae5f40b8
13 changed files with 84 additions and 29 deletions

View File

@@ -18,6 +18,18 @@
<spring-boot.version>3.3.5</spring-boot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
<version>4.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
<version>4.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>

View File

@@ -1,4 +1,4 @@
package com.sdm.gateway2.route;
package com.sdm.common.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
@@ -20,9 +20,10 @@ import java.util.concurrent.atomic.AtomicInteger;
@Component
public class CustomLoadBalancerClient implements ReactorServiceInstanceLoadBalancer {
@Value("${serverType}")
@Value("${serverType:1}")
private int serverType;
@Value("${serverIp}")
@Value("${serverIp:}")
private String serverIp;
private final AtomicInteger atomicInteger = new AtomicInteger(0);
@@ -52,22 +53,22 @@ public class CustomLoadBalancerClient implements ReactorServiceInstanceLoadBalan
log.error("服务器列表为空");
return new EmptyResponse();
}
// log.info("request url:{}" + url);
// return new DefaultResponse(instances.get(0));
ServiceInstance serviceInstance = null;
// 0单机处理1负载均衡轮询
if (serverType == 0) {
// DefaultRequestContext requestContext = (DefaultRequestContext) request.getContext();
// RequestData clientRequest = (RequestData) requestContext.getClientRequest();
// String url = clientRequest.getUrl().toString();
for (ServiceInstance instance : instances) {
if (instance.getHost().equals(serverIp)) {
serviceInstance = instance;
break;
}
}
//serviceInstance = instances.get(0);
log.info("转发到服务器:" + serviceInstance.getHost());
if (serviceInstance != null) {
log.info("转发到指定服务器:" + serviceInstance.getHost());
} else {
log.warn("未找到指定IP的服务器使用列表中的第一个服务器");
serviceInstance = instances.get(0);
}
} else {
// 获取当前的调用编号(每来一次请求则累加1)
int sequence = atomicInteger.getAndIncrement();

View File

@@ -0,0 +1,9 @@
package com.sdm.common.config;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.Configuration;
@Configuration
@LoadBalancerClients(defaultConfiguration = CustomLoadBalancerClient.class)
public class LoadBalancerConfig {
}

View File

@@ -33,6 +33,6 @@ public interface ISysUserFeignClient {
/**
* 根据用户组id查询用户组及组成员列表详情
*/
@PostMapping("/queryGroupDetail")
@PostMapping("/user/queryGroupDetail")
SdmResponse<SysUserGroupDetailResp> queryGroupDetail(@RequestBody @Validated QueryGroupDetailReq req);
}

View File

@@ -114,4 +114,10 @@ management:
redis:
enabled: false
db:
enabled: false
enabled: false
# 0单机处理可以指向本地1负载均衡轮询
serverType: 0
#serverIp: 192.168.65.161
serverIp: 192.168.65.73

View File

@@ -32,7 +32,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>4.1.4</version>
<!-- 排除 Spring Web 同步依赖Gateway 基于 WebFlux -->
<exclusions>
<exclusion>
@@ -87,7 +86,6 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
@@ -117,6 +115,19 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- 引入common模块以使用其中的负载均衡器 -->
<dependency>
<groupId>com.sdm</groupId>
<artifactId>common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
@@ -128,4 +139,4 @@
</plugins>
</build>
</project>
</project>

View File

@@ -1,7 +1,7 @@
package com.sdm.gateway2;
import com.sdm.gateway2.route.CustomLoadBalancerClient;
import com.sdm.common.config.CustomLoadBalancerClient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

View File

@@ -104,7 +104,7 @@ logging:
org.springframework.cloud.gateway: INFO
reactor.netty: INFO
# 0单机处理1负载均衡轮询
# 0单机处理可以指向本地,1负载均衡轮询
serverType: 0
#serverIp: 192.168.65.161
serverIp: 192.168.65.73

View File

@@ -112,4 +112,9 @@ management:
redis:
enabled: false
db:
enabled: false
enabled: false
# 0单机处理可以指向本地1负载均衡轮询
serverType: 0
#serverIp: 192.168.65.161
serverIp: 192.168.65.73

View File

@@ -119,7 +119,7 @@ file:
system:
useCidSwitch: false
useCidSwitch: true
userSystem:
cidUser: cid
@@ -134,8 +134,8 @@ tenantSystem:
localTenant: local
cid:
## url: http://192.168.65.162:8989/honeycom-spdm # 请根据实际CID服务地址修改
url: http://192.168.65.75:8989/honeycom-spdm # 朱欣茹地址
url: http://192.168.65.162:8989/honeycom-spdm # 请根据实际CID服务地址修改
## url: http://192.168.65.75:8989/honeycom-spdm # 朱欣茹地址
user:
listUser: /spdm-user/listUser
queryUserDetail: /spdm-user/queryUserDetail
@@ -157,4 +157,9 @@ cid:
queryFlowTemplate: /spdm-flow/listProcessByGroup
queryApproveDetail: /spdm-flow/queryFlowNodeDetail
stopApproveFlow: /spdm-flow/stopFlow
group: SPDM
group: SPDM
# 0单机处理可以指向本地1负载均衡轮询
serverType: 0
#serverIp: 192.168.65.161
serverIp: 192.168.65.73

View File

@@ -130,7 +130,7 @@ scheduled:
syncUser: 0 0 4 * * ?
system:
useCidSwitch: false
useCidSwitch: true
userSystem:
cidUser: cid
@@ -145,8 +145,8 @@ tenantSystem:
localTenant: local
cid:
## url: http://192.168.65.162:8989/honeycom-spdm # 请根据实际CID服务地址修改
url: http://192.168.65.75:8989/honeycom-spdm # 朱欣茹地址
url: http://192.168.65.162:8989/honeycom-spdm # 请根据实际CID服务地址修改
## url: http://192.168.65.75:8989/honeycom-spdm # 朱欣茹地址
user:
listUser: /spdm-user/listUser
queryUserDetail: /spdm-user/queryUserDetail

View File

@@ -128,7 +128,7 @@ scheduled:
syncUser: 0 0 4 * * ?
system:
useCidSwitch: false
useCidSwitch: true
userSystem:
cidUser: cid
@@ -143,8 +143,8 @@ tenantSystem:
localTenant: local
cid:
## url: http://192.168.65.162:8989/honeycom-spdm # 请根据实际CID服务地址修改
url: http://192.168.65.75:8989/honeycom-spdm # 朱欣茹地址
url: http://192.168.65.162:8989/honeycom-spdm # 请根据实际CID服务地址修改
## url: http://192.168.65.75:8989/honeycom-spdm # 朱欣茹地址
user:
listUser: /spdm-user/listUser
queryUserDetail: /spdm-user/queryUserDetail

View File

@@ -114,4 +114,10 @@ file:
approve:
replyUrl: http:192.168.65.161:7102/simulation/task/taskpool/approveHandleNotice
#logging:
# config: ./config/logback.xml
# config: ./config/logback.xml
# 0单机处理可以指向本地1负载均衡轮询
serverType: 0
#serverIp: 192.168.65.161
serverIp: 192.168.65.73