端口池管理操作(增删改、启用、禁用)时,代理实时生效

This commit is contained in:
aoshiguchen
2023-02-05 18:40:47 +08:00
parent 42886aef91
commit 417a53fec5
5 changed files with 47 additions and 2 deletions
@@ -50,7 +50,7 @@ public enum ExceptionConstant {
LOGIN_PASSWORD_NO_CHANGE_MODIFY_FAIL(12004, "密码没有变化,修改失败"),
// 端口池管理(13000)
PORT_CANNOT_REPEAT(13000,"端口不能重复"),
PORT_NOT_EXIST(13001, "该端口在端口池中不存在,不允许映射"),
PORT_NOT_EXIST(13001, "该端口在端口池中不存在"),
// 端口映射管理(14000)
PORT_MAPPING_NOT_EXIST(14000, "端口映射记录不存在"),
PORT_CANNOT_REPEAT_MAPPING(14001, "服务端口[{}]不能重复映射"),
@@ -74,6 +74,10 @@ public interface PortMappingMapper extends SqlMapper {
@Select("select * from port_mapping where license_id = ? and enable = 1")
List<PortMappingDO> findEnableListByLicenseId(Integer licenseId);
@ResultType(PortMappingDO.class)
@Select("select * from port_mapping where server_port = :serverPort")
List<PortMappingDO> findListByServerPort(@Param("serverPort") Integer serverPort);
@ResultType(PortMappingDO.class)
@Select("select * from port_mapping where license_id = ?")
List<PortMappingDO> findListByLicenseId(Integer licenseId);
@@ -62,4 +62,7 @@ public interface PortPoolMapper extends SqlMapper {
@Select("select * from port_pool where port = ? limit 0,1")
PortPoolDO findByPort(Integer port);
@Select("select * from port_pool where id = ?")
PortPoolDO findById(Integer id);
}
@@ -52,6 +52,8 @@ public class PortPoolService {
@Autowired
private PortPoolMapper portPoolMapper;
@Autowired
private VisitorChannelService visitorChannelService;
public Page<PortPoolListRes> page(PageQuery pageQuery, PortPoolListReq req) {
Page<PortPoolListRes> page = Page.create(pageQuery);
@@ -75,19 +77,31 @@ public class PortPoolService {
.setCreateTime(now)
.setUpdateTime(now)
);
// 更新visitorChannel
visitorChannelService.updateVisitorChannelByPortPool(req.getPort(), EnableStatusEnum.ENABLE.getStatus());
return new PortPoolCreateRes();
}
public PortPoolUpdateEnableStatusRes updateEnableStatus(PortPoolUpdateEnableStatusReq req) {
PortPoolDO portPoolDO = portPoolMapper.findById(req.getId());
ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
portPoolMapper.updateEnableStatus(req.getId(), req.getEnable(), new Date());
// 更新visitorChannel
visitorChannelService.updateVisitorChannelByPortPool(portPoolDO.getPort(), req.getEnable());
return new PortPoolUpdateEnableStatusRes();
}
public void delete(Integer id) {
PortPoolDO portPoolDO = portPoolMapper.findById(id);
ParamCheckUtil.checkNotNull(portPoolDO, ExceptionConstant.PORT_NOT_EXIST);
portPoolMapper.delete(id);
// 更新visitorChannel
visitorChannelService.updateVisitorChannelByPortPool(portPoolDO.getPort(), EnableStatusEnum.DISABLE.getStatus());
}
}
@@ -92,6 +92,30 @@ public class VisitorChannelService {
startUserPortServer(ProxyUtil.getAttachInfo(cmdChannel), portMappingList);
}
/**
* 更新
* 触发时机:删除端口池、禁用端口池、启用端口池
* @param serverPort
* @param enable
*/
public void updateVisitorChannelByPortPool(Integer serverPort, Integer enable) {
if (null == serverPort) {
return;
}
List<PortMappingDO> portMappingDOList = portMappingMapper.findListByServerPort(serverPort);
if (CollectionUtil.isEmpty(portMappingDOList)) {
return;
}
EnableStatusEnum enableStatusEnum = EnableStatusEnum.of(enable);
for (PortMappingDO portMappingDO : portMappingDOList) {
if (EnableStatusEnum.DISABLE == enableStatusEnum) {
removeVisitorChannelByPortMapping(portMappingDO);
} else if (EnableStatusEnum.ENABLE == EnableStatusEnum.of(portMappingDO.getEnable())) {
addVisitorChannelByPortMapping(portMappingDO);
}
}
}
/**
* 更新
* 触发时机:删除用户、禁用用户、启用用户 (新增、修改用户不涉及VisitorChannel的变更)