新增端口映射相关接口实现

This commit is contained in:
aoshiguchen
2022-08-09 23:16:46 +08:00
parent 7b81dd115d
commit 0b7a815196
7 changed files with 160 additions and 5 deletions
@@ -30,5 +30,20 @@ import lombok.Data;
*/
@Data
public class PortMappingCreateReq {
/**
* licenseId
*/
private Integer licenseId;
/**
* 服务端端口
*/
private Integer serverPort;
/**
* 客户端ip
*/
private String clientIp;
/**
* 客户端端口
*/
private Integer clientPort;
}
@@ -21,8 +21,11 @@
*/
package fun.asgc.neutrino.proxy.server.controller.res;
import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum;
import lombok.Data;
import java.util.Date;
/**
* 端口映射列表响应
* @author: aoshiguchen
@@ -30,5 +33,51 @@ import lombok.Data;
*/
@Data
public class PortMappingListRes {
private Integer id;
/**
* licenseId
*/
private Integer licenseId;
/**
* license名称
*/
private String licenseName;
/**
* 用户ID
*/
private Integer userId;
/**
* 用户姓名
*/
private String userName;
/**
* 服务端端口
*/
private Integer serverPort;
/**
* 客户端ip
*/
private String clientIp;
/**
* 客户端端口
*/
private Integer port;
/**
* 是否在线
* {@link OnlineStatusEnum}
*/
private Integer isOnline;
/**
* 启用状态
* {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum}
*/
private Integer enable;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
}
@@ -24,6 +24,7 @@ package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.annotation.Param;
import fun.asgc.neutrino.core.db.annotation.Delete;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.annotation.Update;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
@@ -33,6 +34,8 @@ import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq;
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
import java.util.Date;
import java.util.List;
import java.util.Set;
/**
*
@@ -69,4 +72,8 @@ public interface LicenseMapper extends SqlMapper {
@Update("update `license` set name = :name where id = :id")
void update(@Param("id") Integer id, @Param("name") String name);
@ResultType(LicenseDO.class)
@Select("select * from `license` where in in (:ids)")
List<LicenseDO> findByIds(@Param("ids")Set<Integer> ids);
}
@@ -22,7 +22,13 @@
package fun.asgc.neutrino.proxy.server.dal;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.db.annotation.ResultType;
import fun.asgc.neutrino.core.db.annotation.Select;
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq;
import fun.asgc.neutrino.proxy.server.controller.res.PortMappingListRes;
import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO;
/**
*
@@ -32,4 +38,11 @@ import fun.asgc.neutrino.core.db.mapper.SqlMapper;
@Component
public interface PortMappingMapper extends SqlMapper {
@ResultType(PortMappingListRes.class)
@Select("select * from port_mapping")
void page(Page page, PortMappingListReq req);
void add(PortMappingDO portMappingDO);
void update(PortMappingDO portMappingDO);
}
@@ -57,7 +57,7 @@ public class PortMappingDO {
/**
* 客户端端口
*/
private Integer port;
private Integer clientPort;
/**
* 是否在线
* {@link OnlineStatusEnum}
@@ -21,13 +21,31 @@
*/
package fun.asgc.neutrino.proxy.server.service;
import fun.asgc.neutrino.core.annotation.Autowired;
import fun.asgc.neutrino.core.annotation.Component;
import fun.asgc.neutrino.core.db.page.Page;
import fun.asgc.neutrino.core.db.page.PageQuery;
import fun.asgc.neutrino.core.util.CollectionUtil;
import fun.asgc.neutrino.core.util.DateUtil;
import fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum;
import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum;
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingCreateReq;
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq;
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingUpdateEnableStatusReq;
import fun.asgc.neutrino.proxy.server.controller.res.*;
import fun.asgc.neutrino.proxy.server.dal.LicenseMapper;
import fun.asgc.neutrino.proxy.server.dal.PortMappingMapper;
import fun.asgc.neutrino.proxy.server.dal.UserMapper;
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
import fun.asgc.neutrino.proxy.server.dal.entity.PortMappingDO;
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
*
@@ -36,13 +54,53 @@ import fun.asgc.neutrino.proxy.server.controller.res.*;
*/
@Component
public class PortMappingService {
@Autowired
private PortMappingMapper portMappingMapper;
@Autowired
private LicenseMapper licenseMapper;
@Autowired
private UserMapper userMapper;
public Page<PortMappingListRes> page(PageQuery pageQuery, PortMappingListReq req) {
return null;
Page<PortMappingListRes> page = Page.create(pageQuery);
portMappingMapper.page(page, req);
if (!CollectionUtil.isEmpty(page.getRecords())) {
Set<Integer> licenseIds = page.getRecords().stream().map(PortMappingListRes::getLicenseId).collect(Collectors.toSet());
List<LicenseDO> licenseList = licenseMapper.findByIds(licenseIds);
Set<Integer> userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet());
List<UserDO> userList = userMapper.findByIds(userIds);
Map<Integer, LicenseDO> licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity()));
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
page.getRecords().forEach(item -> {
LicenseDO license = licenseMap.get(item.getLicenseId());
if (null == license) {
return;
}
item.setLicenseName(license.getName());
item.setUserId(license.getUserId());
UserDO user = userMap.get(license.getUserId());
if (null == user) {
return;
}
item.setUserName(user.getName());
});
}
return page;
}
public PortMappingCreateRes create(PortMappingCreateReq req) {
return null;
Date now = new Date();
PortMappingDO portMappingDO = new PortMappingDO();
portMappingDO.setLicenseId(req.getLicenseId());
portMappingDO.setServerPort(req.getServerPort());
portMappingDO.setClientIp(req.getClientIp());
portMappingDO.setClientPort(req.getClientPort());
portMappingDO.setIsOnline(OnlineStatusEnum.OFFLINE.getStatus());
portMappingDO.setEnable(EnableStatusEnum.ENABLE.getStatus());
portMappingDO.setCreateTime(now);
portMappingDO.setUpdateTime(now);
portMappingMapper.add(portMappingDO);
return new PortMappingCreateRes();
}
public PortMappingUpdateRes update(PortMappingUpdateRes req) {
@@ -0,0 +1,13 @@
<mapper namespace = "fun.asgc.neutrino.proxy.server.dal.PortMappingMapper">
<insert id="add">
insert into `port_mapping`(`license_id`,`server_port`,`client_ip`,`client_port`,`is_online`,`enable`,`create_time`,`update_time`)
values (:licenseId, :serverPort, :clientIp, :clientPort, :isOnline, :enable, :createTime, :updateTime)
</insert>
<update id="update">
update `port_mapping`
set license_id = :licenseId,server_port = :serverPort,client_ip=:clientIp,client_port=:clientPort,is_online=:isOnline,update_time=:updateTime
where id =:id
</update>
</mapper>