[fix] // TODO 流量并发异常

This commit is contained in:
wujiawei 2024-10-30 20:56:46 +08:00
parent c665bf687d
commit 2eb6dc2775
16 changed files with 439 additions and 29 deletions

View File

@ -6,6 +6,7 @@ import org.framework.lazy.cloud.network.heartbeat.common.ChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.MessageType;
import org.framework.lazy.cloud.network.heartbeat.common.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.server.AbstractHandleReportStagingOpenedTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.common.utils.ChannelAttributeKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.LazyNettyClientLoginCommand;
@ -40,18 +41,22 @@ public class ServerHandleReportStagingOpenedTypeAdvanced extends AbstractHandleR
String appKey = ChannelAttributeKeyUtils.getAppKey(stagingOpenedChannel);
String appSecret = ChannelAttributeKeyUtils.getAppSecret(stagingOpenedChannel);
String originalIp = ChannelAttributeKeyUtils.getOriginalIp(stagingOpenedChannel);
List<Channel> stagingOpenedClientChannel = ChannelContext.get(clientIdBytes);
// 存储当前客户端暂存关闭
String clientId = new String(clientIdBytes);
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId);
lazyNettyClientLoginCommand.setAppKey(appKey);
lazyNettyClientLoginCommand.setAppSecret(appSecret);
lazyNettyClientLoginCommand.setOriginalIp(originalIp);
lazyNettyClientLoginCommand.setOnLineState(NettyClientStatus.OFF_LINE);
lazyClientStatsChangeApplication.stagingOpened(lazyNettyClientLoginCommand);
if (stagingOpenedClientChannel != null) {
ChannelContext.getChannels().forEach((existClientId, channels) -> {
for (Channel channel : channels) {
// 存储当前客户端暂存关闭
String clientId = new String(clientIdBytes);
LazyNettyClientLoginCommand lazyNettyClientLoginCommand = new LazyNettyClientLoginCommand();
lazyNettyClientLoginCommand.setClientId(clientId);
lazyNettyClientLoginCommand.setAppKey(appKey);
lazyNettyClientLoginCommand.setAppSecret(appSecret);
lazyNettyClientLoginCommand.setOriginalIp(originalIp);
lazyClientStatsChangeApplication.stagingOpened(lazyNettyClientLoginCommand);
// 告诉他们 当前参数这个通道 暂存开启了
NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_STAGING_OPENED_NOTIFICATION);

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.server.standalone.application
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateGroupByClientDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.web.response.Result;
@ -88,6 +89,29 @@ public interface LazyNettyClientStateApplication {
Result<LazyPage<LazyNettyClientStateDTO>> findPage(int size, int current, LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand);
/**
* describe 查询多个客户端状态
*
* @param lazyNettyClientStateQueryListCommand 查询多个客户端状态
* @return {@link Result <List<LazyNettyClientStateDTO>>} 客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
Result<List<LazyNettyClientStateGroupByClientDTO>> findListGroupByClient(LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand);
/**
* describe 分页查询多个客户端状态
*
* @param lazyNettyClientStateQueryListCommand 分页查询多个客户端状态
* @return {@link Result <LazyPage<LazyNettyClientStateDTO>>} 分页客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
Result<LazyPage<LazyNettyClientStateGroupByClientDTO>> findPageGroupByClient(int size, int current, LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand);
/**
* describe 删除客户端状态
*

View File

@ -1,8 +1,10 @@
package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.assembler;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateGroupByClientDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateGroupByClient;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyAssembler;
@ -86,4 +88,14 @@ public interface NettyClientStateDTOAssembler {
* @date 2023/12/27 03:46 下午
**/
LazyNettyClientStateDTO fromNettyClientState(LazyNettyClientState lazyNettyClientState);
/**
* describe 持久层领域对象转换成DTO对象
*
* @param lazyNettyClientStateGroupByClient 客户端状态领域对象
* @return {@link LazyNettyClientStateGroupByClientDTO} 客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
LazyNettyClientStateGroupByClientDTO fromNettyClientState(LazyNettyClientStateGroupByClient lazyNettyClientStateGroupByClient);
}

View File

@ -67,10 +67,19 @@ public class LazyNettyClientStateDTO {
* 描述
*/
@Schema(description = "描述", name = "describe", example = "")
private String describe; /**
private String describe;
/**
* 服务端ID
*/
@Schema(description = "服务端ID", name = "serverId", example = "")
private String serverId;
/**
* 原始IP
* byte[] 长度 4
*
* @since 1.2.9
*/
private String originalIp;
}

View File

@ -0,0 +1,81 @@
package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyDTO;
import java.time.LocalDateTime;
/**
* describe 客户端状态
*
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
* @see DefaultDDDLazyDTO
**/
@Data
@Accessors(chain = true)
@Schema(title = "lazy_netty_client_state_group_by_client_dto", description = "客户端状态")
public class LazyNettyClientStateGroupByClientDTO {
/**
* 客户端ID
*/
@Schema(description = "客户端ID", name = "clientId", example = "")
private String clientId;
/**
* 创建时间
*/
@Schema(description = "创建时间", name = "createTime", example = "")
private LocalDateTime createTime;
/**
* 主键
*/
@Schema(description = "主键", name = "id", example = "")
private Long id;
/**
* 是否删除
*/
@Schema(description = "是否删除", name = "isDeleted", example = "")
private Boolean isDeleted;
/**
* 修改时间
*/
@Schema(description = "修改时间", name = "updateTime", example = "")
private LocalDateTime updateTime;
/**
* 描述
*/
@Schema(description = "描述", name = "describe", example = "")
private String describe;
/**
* 服务端ID
*/
@Schema(description = "服务端ID", name = "serverId", example = "")
private String serverId;
/**
* 客户端数量
*/
@Schema(description = "客户端数量", name = "clientNum", example = "")
private Integer clientNum;
/**
* 在线数量
*/
@Schema(description = "在线数量", name = "onLineNum", example = "")
private Integer onLineNum;
/**
* 暂存打开数量
*/
@Schema(description = "暂存打开数量", name = "onStagingNum", example = "")
private Integer onStagingNum;
}

View File

@ -1,17 +1,17 @@
package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.impl;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ClientConfigKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.framework.lazy.cloud.network.heartbeat.server.properties.ServerNodeProperties;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyClientStatsChangeApplication;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.LazyNettyClientLoginCommand;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateRepository;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.record.LazyNettyClientStateRecord;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.record.LazyNettyClientStateRecordRepository;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateRepository;
import org.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.constant.ClientConfigKeyUtils;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import java.time.LocalDateTime;
@ -34,13 +34,20 @@ public class LazyClientStatsChangeApplicationImpl implements LazyClientStatsChan
this.lazyNettyClientStateRecordRepository = lazyNettyClientStateRecordRepository;
}
private void storyClientStateRecord(String clientId,String serverId,String onLineState,String stagingState){
// private void storyClientStateRecord(String clientId,String serverId,String onLineState,String stagingState){
private void storyClientStateRecord(LazyNettyClientLoginCommand lazyNettyClientLoginCommand) {
String clientId = lazyNettyClientLoginCommand.getClientId();
String serverId = lazyNettyClientLoginCommand.getServerId();
NettyClientStatus onLineState = lazyNettyClientLoginCommand.getOnLineState();
String originalIp = lazyNettyClientLoginCommand.getOriginalIp();
String stagingState = lazyNettyClientLoginCommand.getStagingState();
LazyNettyClientStateRecord lazyNettyClientStateRecord = new LazyNettyClientStateRecord();
lazyNettyClientStateRecord.setClientId(clientId);
lazyNettyClientStateRecord.setCreateTime(LocalDateTime.now());
lazyNettyClientStateRecord.setServerId(serverId);
lazyNettyClientStateRecord.setOnLineState(onLineState);
lazyNettyClientStateRecord.setStagingState(stagingState);
lazyNettyClientStateRecord.setOriginalIp(originalIp);
lazyNettyClientStateRecordRepository.story(lazyNettyClientStateRecord);
}
@ -60,8 +67,12 @@ public class LazyClientStatsChangeApplicationImpl implements LazyClientStatsChan
lazyNettyClientState.setOnLineState(NettyClientStatus.ON_LINE);
String serverId = serverNodeProperties.getNodeId();
lazyNettyClientState.setServerId(serverId);
lazyNettyClientState.setOriginalIp(lazyNettyClientLoginCommand.getOriginalIp());
lazyNettyClientStateRepository.updateOnLIneState(lazyNettyClientState);
storyClientStateRecord(clientId,serverId,NettyClientStatus.ON_LINE.name(),null);
lazyNettyClientLoginCommand.setOnLineState(NettyClientStatus.ON_LINE);
lazyNettyClientLoginCommand.setStagingState("CLOSE");
lazyNettyClientLoginCommand.setServerId(serverId);
storyClientStateRecord(lazyNettyClientLoginCommand);
// 触发暂存扫描
// ClientOnLineState clientOnLineState = new ClientOnLineState();
// clientOnLineState.setClientId(clientId);
@ -87,9 +98,13 @@ public class LazyClientStatsChangeApplicationImpl implements LazyClientStatsChan
lazyNettyClientState.setStagingState("OPENED");
String serverId = serverNodeProperties.getNodeId();
lazyNettyClientState.setServerId(serverId);
lazyNettyClientState.setOriginalIp(lazyNettyClientLoginCommand.getOriginalIp());
lazyNettyClientStateRepository.updateOnLIneState(lazyNettyClientState);
// 创建变更记录
storyClientStateRecord(clientId,serverId,NettyClientStatus.OFF_LINE.name(),null);
lazyNettyClientLoginCommand.setOnLineState(NettyClientStatus.OFF_LINE);
lazyNettyClientLoginCommand.setStagingState("OPENED");
lazyNettyClientLoginCommand.setServerId(serverId);
storyClientStateRecord(lazyNettyClientLoginCommand);
// // 触发暂存扫描
// ClientOnLineState clientOnLineState = new ClientOnLineState();
// clientOnLineState.setClientId(lazyNettyClientLoginCommand);
@ -111,15 +126,17 @@ public class LazyClientStatsChangeApplicationImpl implements LazyClientStatsChan
lazyNettyClientState.setStagingState("CLOSED");
String serverId = serverNodeProperties.getNodeId();
lazyNettyClientState.setServerId(serverId);
lazyNettyClientState.setOriginalIp(lazyNettyClientLoginCommand.getOriginalIp());
lazyNettyClientStateRepository.updateStagingState(lazyNettyClientState);
storyClientStateRecord(clientId,serverId,null,"CLOSE");
lazyNettyClientLoginCommand.setStagingState("CLOSED");
lazyNettyClientLoginCommand.setServerId(serverId);
storyClientStateRecord(lazyNettyClientLoginCommand);
}
/**
* 客户端暂存开启
*
* @param clientId 客户端ID
* @param lazyNettyClientLoginCommand
* @param lazyNettyClientLoginCommand 客户端登陆信息
*/
@Override
public void stagingOpened(LazyNettyClientLoginCommand lazyNettyClientLoginCommand) {
@ -130,6 +147,9 @@ public class LazyClientStatsChangeApplicationImpl implements LazyClientStatsChan
String serverId = serverNodeProperties.getNodeId();
lazyNettyClientState.setServerId(serverId);
lazyNettyClientStateRepository.updateStagingState(lazyNettyClientState);
storyClientStateRecord(clientId,serverId,null,"CLOSE");
lazyNettyClientLoginCommand.setStagingState("OPENED");
lazyNettyClientLoginCommand.setOnLineState(NettyClientStatus.OFF_LINE);
lazyNettyClientLoginCommand.setServerId(serverId);
storyClientStateRecord(lazyNettyClientLoginCommand);
}
}

View File

@ -13,6 +13,7 @@ import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.assembler.NettyClientStateDTOAssembler;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateGroupByClientDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateRepository;
import org.wu.framework.core.utils.ObjectUtils;
@ -150,6 +151,41 @@ public class LazyNettyClientStateApplicationImpl implements LazyNettyClientState
return lazyNettyClientStateRepository.findPage(size, current, lazyNettyClientState).convert(page -> page.convert(NettyClientStateDTOAssembler.INSTANCE::fromNettyClientState));
}
/**
* describe 查询多个客户端状态
*
* @param lazyNettyClientStateQueryListCommand 查询多个客户端状态
* @return {@link Result <List<LazyNettyClientStateDTO>>} 客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
@Override
public Result<List<LazyNettyClientStateGroupByClientDTO>> findListGroupByClient(LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand) {
LazyNettyClientState lazyNettyClientState = NettyClientStateDTOAssembler.INSTANCE.toNettyClientState(lazyNettyClientStateQueryListCommand);
String serverId = serverNodeProperties.getNodeId();
lazyNettyClientState.setServerId(serverId);
return lazyNettyClientStateRepository.findListGroupByClient(lazyNettyClientState).convert(nettyClientStates -> nettyClientStates.stream().map(NettyClientStateDTOAssembler.INSTANCE::fromNettyClientState).collect(Collectors.toList()));
}
/**
* describe 分页查询多个客户端状态
*
* @param size
* @param current
* @param lazyNettyClientStateQueryListCommand 分页查询多个客户端状态
* @return {@link Result <LazyPage<LazyNettyClientStateDTO>>} 分页客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
@Override
public Result<LazyPage<LazyNettyClientStateGroupByClientDTO>> findPageGroupByClient(int size, int current, LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand) {
LazyNettyClientState lazyNettyClientState = NettyClientStateDTOAssembler.INSTANCE.toNettyClientState(lazyNettyClientStateQueryListCommand);
String serverId = serverNodeProperties.getNodeId();
lazyNettyClientState.setServerId(serverId);
return lazyNettyClientStateRepository.findPageGroupByClient(size, current, lazyNettyClientState).convert(page -> page.convert(NettyClientStateDTOAssembler.INSTANCE::fromNettyClientState));
}
/**
* describe 删除客户端状态
*

View File

@ -3,6 +3,7 @@ package org.framework.lazy.cloud.network.heartbeat.server.standalone.controller;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.state.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientStateGroupByClientDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
import org.wu.framework.web.spring.EasyController;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
@ -122,6 +123,37 @@ public class LazyNettyClientStateProvider {
return lazyNettyClientStateApplication.findPage(size, current, lazyNettyClientStateQueryListCommand);
}
/**
* describe 查询多个客户端状态
*
* @param lazyNettyClientStateQueryListCommand 查询多个客户端状态
* @return {@link Result<List< LazyNettyClientStateDTO >>} 客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
@Operation(summary = "查询多个客户端状态")
@GetMapping("/findListGroupByClient")
public Result<List<LazyNettyClientStateGroupByClientDTO>> findListGroupByClient(@ModelAttribute LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand) {
return lazyNettyClientStateApplication.findListGroupByClient(lazyNettyClientStateQueryListCommand);
}
/**
* describe 分页查询多个客户端状态
*
* @param lazyNettyClientStateQueryListCommand 分页查询多个客户端状态
* @return {@link Result< LazyPage < LazyNettyClientStateDTO >>} 分页客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
@Operation(summary = "分页查询多个客户端状态")
@GetMapping("/findPageGroupByClient")
public Result<LazyPage<LazyNettyClientStateGroupByClientDTO>> findPageGroupByClient(@Parameter(description = "分页大小") @RequestParam(defaultValue = "10", value = "size") int size,
@Parameter(description = "当前页数") @RequestParam(defaultValue = "1", value = "current") int current, @ModelAttribute LazyNettyClientStateQueryListCommand lazyNettyClientStateQueryListCommand) {
return lazyNettyClientStateApplication.findPageGroupByClient(size, current, lazyNettyClientStateQueryListCommand);
}
/**
* describe 删除客户端状态
*

View File

@ -3,8 +3,8 @@ package org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.mode
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyDomain;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyDomain;
import java.time.LocalDateTime;
@ -66,10 +66,19 @@ public class LazyNettyClientState {
* 描述
*/
@Schema(description = "描述", name = "describe", example = "")
private String describe; /**
private String describe;
/**
* 服务端ID
*/
@Schema(description = "服务端ID", name = "serverId", example = "")
private String serverId;
/**
* 原始IP
* byte[] 长度 4
*
* @since 1.2.9
*/
private String originalIp;
}

View File

@ -0,0 +1,76 @@
package org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyDomain;
import java.time.LocalDateTime;
/**
* describe 客户端状态
*
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
* @see DefaultDDDLazyDomain
**/
@Data
@Accessors(chain = true)
@Schema(title = "LazyNettyClientStateGroupByClient", description = "客户端状态")
public class LazyNettyClientStateGroupByClient {
/**
* 客户端ID
*/
@Schema(description = "客户端ID", name = "clientId", example = "")
private String clientId;
/**
* 创建时间
*/
@Schema(description = "创建时间", name = "createTime", example = "")
private LocalDateTime createTime;
/**
* 主键
*/
@Schema(description = "主键", name = "id", example = "")
private Long id;
/**
* 修改时间
*/
@Schema(description = "修改时间", name = "updateTime", example = "")
private LocalDateTime updateTime;
/**
* 描述
*/
@Schema(description = "描述", name = "describe", example = "")
private String describe;
/**
* 服务端ID
*/
@Schema(description = "服务端ID", name = "serverId", example = "")
private String serverId;
/**
* 客户端数量
*/
@Schema(description = "客户端数量", name = "clientNum", example = "")
private Integer clientNum;
/**
* 在线数量
*/
@Schema(description = "在线数量", name = "onLineNum", example = "")
private Integer onLineNum;
/**
* 暂存打开数量
*/
@Schema(description = "暂存打开数量", name = "onStagingNum", example = "")
private Integer onStagingNum;
}

View File

@ -74,6 +74,29 @@ public interface LazyNettyClientStateRepository {
Result<LazyPage<LazyNettyClientState>> findPage(int size, int current, LazyNettyClientState lazyNettyClientState);
/**
* describe 查询多个客户端状态
*
* @param lazyNettyClientState 查询多个客户端状态
* @return {@link Result<List< LazyNettyClientState >>} 客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
Result<List<LazyNettyClientStateGroupByClient>> findListGroupByClient(LazyNettyClientState lazyNettyClientState);
/**
* describe 分页查询多个客户端状态
*
* @param size 当前页数
* @param current 当前页
* @param lazyNettyClientState 分页查询多个客户端状态
* @return {@link Result<LazyPage< LazyNettyClientState >>} 分页客户端状态领域对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
Result<LazyPage<LazyNettyClientStateGroupByClient>> findPageGroupByClient(int size, int current, LazyNettyClientState lazyNettyClientState);
/**
* describe 删除客户端状态
*

View File

@ -3,6 +3,8 @@ package org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.mode
import lombok.Data;
import lombok.experimental.Accessors;
import io.swagger.v3.oas.annotations.media.Schema;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import java.lang.String;
import java.time.LocalDateTime;
import java.lang.Long;
@ -45,7 +47,7 @@ public class LazyNettyClientStateRecord {
* 在线状态true在线false离线
*/
@Schema(description ="在线状态true在线false离线",name ="onLineState",example = "")
private String onLineState;
private NettyClientStatus onLineState;
/**
*
@ -61,4 +63,13 @@ public class LazyNettyClientStateRecord {
@Schema(description ="暂存状态(开启、关闭)",name ="stagingState",example = "")
private String stagingState;
/**
* 原始IP
* byte[] 长度 4
*
* @since 1.2.9
*/
private String originalIp;
}

View File

@ -4,9 +4,9 @@ package org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastruct
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructureEntity;
import org.wu.framework.lazy.orm.core.stereotype.*;
import org.framework.lazy.cloud.network.heartbeat.common.enums.NettyClientStatus;
import java.time.LocalDateTime;
@ -79,10 +79,21 @@ public class LazyNettyClientStateDO {
@Schema(description = "描述", name = "describe", example = "")
@LazyTableField(comment = "描述")
private String describe;
/**
* 服务端ID
*/
@LazyTableFieldUnique(name = "server_id", comment = "服务端ID",notNull = true)
@Schema(description = "服务端ID", name = "serverId", example = "")
private String serverId;
/**
* 原始IP
* byte[] 长度 4
*
* @since 1.2.9
*/
@Schema(description = "客户端IP", name = "originalIp", example = "")
@LazyTableFieldUnique(name = "original_ip", comment = "客户端IP", columnType = "varchar(255)", notNull = true)
private String originalIp;
}

View File

@ -76,4 +76,14 @@ public class LazyNettyClientStateRecordDO {
@LazyTableField(name="staging_state",comment="暂存状态(开启、关闭)",columnType="varchar(255)")
private String stagingState;
/**
* 原始IP
* byte[] 长度 4
*
* @since 1.2.9
*/
@Schema(description ="客户端IP",name ="originalIp",example = "")
@LazyTableField(name="original_ip",comment="客户端IP",columnType="varchar(255)")
private String originalIp;
}

View File

@ -2,14 +2,15 @@ package org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastruct
import jakarta.annotation.Resource;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientState;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateGroupByClient;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.state.LazyNettyClientStateRepository;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.LazyNettyClientStateDO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.converter.LazyNettyClientStateConverter;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.LazyNettyClientStateDO;
import org.springframework.stereotype.Repository;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
@ -118,6 +119,56 @@ public class LazyNettyClientStateRepositoryImpl implements LazyNettyClientStateR
return ResultFactory.successOf(nettyClientStateLazyPage);
}
/**
* describe 查询多个客户端状态
*
* @param lazyNettyClientState 查询多个客户端状态
* @return {@link Result<List< LazyNettyClientState >>} 客户端状态DTO对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
@Override
public Result<List<LazyNettyClientStateGroupByClient>> findListGroupByClient(LazyNettyClientState lazyNettyClientState) {
LazyNettyClientStateDO lazyNettyClientStateDO = LazyNettyClientStateConverter.INSTANCE.fromNettyClientState(lazyNettyClientState);
List<LazyNettyClientStateGroupByClient> lazyNettyClientStateList = lazyLambdaStream
.selectList(LazyWrappers.lambdaWrapperBean(lazyNettyClientStateDO)
.eq(LazyNettyClientStateDO::getIsDeleted, false)
.orderByDesc(LazyNettyClientStateDO::getCreateTime)
.groupBy(LazyNettyClientStateDO::getClientId)
.as(LazyNettyClientStateDO.class)
.functionAs("count(1)", LazyNettyClientStateGroupByClient::getClientNum)
.functionAs("SUM(CASE WHEN on_line_state = 'ON_LINE' THEN 1 ELSE 0 END)", LazyNettyClientStateGroupByClient::getOnLineNum)
.functionAs("SUM(CASE WHEN staging_state = 'CLOSED' THEN 1 ELSE 0 END)", LazyNettyClientStateGroupByClient::getOnStagingNum)
, LazyNettyClientStateGroupByClient.class);
return ResultFactory.successOf(lazyNettyClientStateList);
}
/**
* describe 分页查询多个客户端状态
*
* @param size 当前页数
* @param current 当前页
* @param lazyNettyClientState 分页查询多个客户端状态
* @return {@link Result<LazyPage< LazyNettyClientState >>} 分页客户端状态领域对象
* @author Jia wei Wu
* @date 2023/12/27 03:46 下午
**/
@Override
public Result<LazyPage<LazyNettyClientStateGroupByClient>> findPageGroupByClient(int size, int current, LazyNettyClientState lazyNettyClientState) {
LazyNettyClientStateDO lazyNettyClientStateDO = LazyNettyClientStateConverter.INSTANCE.fromNettyClientState(lazyNettyClientState);
LazyPage<LazyNettyClientStateGroupByClient> lazyPage = new LazyPage<>(current, size);
LazyPage<LazyNettyClientStateGroupByClient> nettyClientStateLazyPage = lazyLambdaStream.selectPage(
LazyWrappers.lambdaWrapperBean(lazyNettyClientStateDO)
.groupBy(LazyNettyClientStateDO::getClientId)
.as(LazyNettyClientStateDO.class)
.functionAs("count(1)", LazyNettyClientStateGroupByClient::getClientNum)
.functionAs("SUM(CASE WHEN on_line_state = 'ON_LINE' THEN 1 ELSE 0 END)", LazyNettyClientStateGroupByClient::getOnLineNum)
.functionAs("SUM(CASE WHEN staging_state = 'CLOSED' THEN 1 ELSE 0 END)", LazyNettyClientStateGroupByClient::getOnStagingNum)
, lazyPage, LazyNettyClientStateGroupByClient.class);
return ResultFactory.successOf(nettyClientStateLazyPage);
}
/**
* describe 删除客户端状态
*

View File

@ -19,6 +19,6 @@ spring:
# inet-port: 7101
---
logging1:
level:
root: DEBUG
#logging:
# level:
# root: DEBUG