端口映射相关接口完善.
This commit is contained in:
@@ -71,8 +71,6 @@ public class ProxyCompiler {
|
||||
if (cp != null && cp.trim().length() != 0) {
|
||||
ret.add("-classpath");
|
||||
ret.add(cp);
|
||||
|
||||
System.out.println("classpath:" + cp);
|
||||
}
|
||||
|
||||
options = ret;
|
||||
@@ -224,8 +222,7 @@ public class ProxyCompiler {
|
||||
|
||||
protected void outputCompileError(Boolean result, DiagnosticCollector<JavaFileObject> collector) {
|
||||
if (! result) {
|
||||
// collector.getDiagnostics().forEach(item -> log.error(item.toString()));
|
||||
collector.getDiagnostics().forEach(item -> System.out.println(item.toString()));
|
||||
collector.getDiagnostics().forEach(item -> log.error(item.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-10
@@ -68,22 +68,18 @@ public class SqlMapperInterceptor implements Interceptor {
|
||||
if (Page.class.isAssignableFrom(inv.getTargetMethod().getParameters()[0].getType())) {
|
||||
// 分页查询 TODO 此处暂时临时处理,假设后面的参数是一个DO对象
|
||||
Page page = (Page) inv.getArgs()[0];
|
||||
// Map<String, Object> params = new HashMap<>();
|
||||
// for (int i = 1; i < inv.getTargetMethod().getParameterCount(); i++) {
|
||||
// Parameter parameter = inv.getTargetMethod().getParameters()[i];
|
||||
// Param param = parameter.getAnnotation(Param.class);
|
||||
// if (null == param || StringUtil.isEmpty(param.value())) {
|
||||
// continue;
|
||||
// }
|
||||
// params.put(param.value(), inv.getArgs()[i]);
|
||||
// }
|
||||
int offset = (page.getCurrentPage() - 1) * page.getPageSize();
|
||||
long total = jdbcTemplate.queryForLongByModel(String.format("select count(1) from (%s) T", sql), inv.getArgs()[1]);
|
||||
List resultList = jdbcTemplate.queryForListByModel(resultComponentType, String.format("%s limit %s,%s", sql, offset, page.getPageSize()), inv.getArgs()[1]);
|
||||
page.setTotal(total);
|
||||
page.setRecords(resultList);
|
||||
} else {
|
||||
res = jdbcTemplate.query(resultType, sql, inv.getArgs());
|
||||
Object params = getParams(inv);
|
||||
if (null == params || params.getClass().isArray()) {
|
||||
res = jdbcTemplate.query(resultType, sql, inv.getArgs());
|
||||
} else {
|
||||
res = jdbcTemplate.queryByMap(resultType, sql, (Map)params);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (sqlParser.isInsert() || sqlParser.isDelete() || sqlParser.isUpdate()) {
|
||||
|
||||
@@ -21,10 +21,6 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.core.db.page;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
|
||||
@@ -185,7 +185,6 @@ public class JdbcOperations {
|
||||
map.put(DbCache.fromColumnName(name), value);
|
||||
}
|
||||
}else{
|
||||
System.out.println(clazz);
|
||||
obj = clazz.newInstance();
|
||||
|
||||
for(int i = 1;i <= columnCount;i++){
|
||||
|
||||
@@ -112,7 +112,7 @@ public class HttpRequestHandler {
|
||||
res = JSONObject.toJSONString(invokeResult);
|
||||
}
|
||||
|
||||
postHandle(httpRouteResult.getPageRoute(), httpRouteResult.getMethod());
|
||||
postHandle(httpRouteResult.getPageRoute(), httpRouteResult.getMethod(), invokeResult);
|
||||
|
||||
HttpResponseWrapper httpResponseWrapper = HttpContextHolder.getHttpResponseWrapper();
|
||||
httpResponseWrapper.setContent(Unpooled.wrappedBuffer(res.getBytes()));
|
||||
@@ -130,7 +130,7 @@ public class HttpRequestHandler {
|
||||
mimeType += ";charset=utf-8";
|
||||
}
|
||||
|
||||
postHandle(httpRouteResult.getPageRoute(), null);
|
||||
postHandle(httpRouteResult.getPageRoute(), null, null);
|
||||
|
||||
HttpResponseWrapper httpResponseWrapper = HttpContextHolder.getHttpResponseWrapper();
|
||||
httpResponseWrapper.setContent(Unpooled.wrappedBuffer(FileUtil.readBytes(httpRouteResult.getPageLocation())));
|
||||
@@ -165,10 +165,10 @@ public class HttpRequestHandler {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
private void postHandle(String route, Method targetMethod) throws Exception {
|
||||
private void postHandle(String route, Method targetMethod, Object result) throws Exception {
|
||||
if (!CollectionUtil.isEmpty(HttpContextHolder.getInterceptorList())) {
|
||||
for (HandlerInterceptor handlerInterceptor : HttpContextHolder.getInterceptorList()) {
|
||||
handlerInterceptor.postHandle(HttpContextHolder.getHttpRequestWrapper(), HttpContextHolder.getHttpResponseWrapper(), route, targetMethod);
|
||||
handlerInterceptor.postHandle(HttpContextHolder.getHttpRequestWrapper(), HttpContextHolder.getHttpResponseWrapper(), route, targetMethod, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public interface HandlerInterceptor {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod) throws Exception {
|
||||
default void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod, Object result) throws Exception {
|
||||
}
|
||||
|
||||
default void afterCompletion(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod) {
|
||||
|
||||
+2
-2
@@ -105,7 +105,7 @@ public class MappedInterceptor {
|
||||
return this.interceptor.preHandle(requestParser, responseWrapper, route, targetMethod);
|
||||
}
|
||||
|
||||
public void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod) throws Exception {
|
||||
this.interceptor.postHandle(requestParser, responseWrapper, route, targetMethod);
|
||||
public void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod, Object result) throws Exception {
|
||||
this.interceptor.postHandle(requestParser, responseWrapper, route, targetMethod, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,4 @@ public class BaseAuthInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod) throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -25,6 +25,8 @@ import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -45,4 +47,8 @@ public class SystemContext {
|
||||
* 客户端ip
|
||||
*/
|
||||
private String ip;
|
||||
/**
|
||||
* 接收请求时间
|
||||
*/
|
||||
private Date receiveTime;
|
||||
}
|
||||
|
||||
+4
@@ -50,4 +50,8 @@ public class SystemContextHolder {
|
||||
public static String getIp() {
|
||||
return systemContextHolder.get().getIp();
|
||||
}
|
||||
|
||||
public static SystemContext getContext() {
|
||||
return systemContextHolder.get();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -26,10 +26,7 @@ import fun.asgc.neutrino.core.web.config.WebMvcConfigurer;
|
||||
import fun.asgc.neutrino.core.web.interceptor.ExceptionHandlerRegistry;
|
||||
import fun.asgc.neutrino.core.web.interceptor.InterceptorRegistry;
|
||||
import fun.asgc.neutrino.core.web.interceptor.RestControllerAdviceHandler;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.interceptor.BaseAuthInterceptor;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.interceptor.CorsInterceptor;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.interceptor.GlobalAdviceHandler;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.interceptor.GlobalExceptionHandler;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.interceptor.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,6 +41,7 @@ public class WebConfigurerAdapter implements WebMvcConfigurer {
|
||||
registry.addInterceptor(new BaseAuthInterceptor())
|
||||
.addPathPatterns("/**").excludePathPatterns("/**/*.html", "/**/*.js", "/**/*.ico");
|
||||
registry.addInterceptor(new CorsInterceptor());
|
||||
registry.addInterceptor(new VisitLogInterceptor());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
-3
@@ -35,9 +35,18 @@ public enum ExceptionConstant {
|
||||
SUCCESS(0, "成功"),
|
||||
USER_NOT_LOGIN(1, "用户未登录"),
|
||||
PARAMS_INVALID(2, "参数不正确"),
|
||||
PARAMS_NOT_NULL(3, "参数[%s]不能为空"),
|
||||
USER_NAME_OR_PASSWORD_ERROR(4, "用户名或密码错误"),
|
||||
USER_DISBLE(5, "当前用户已被禁止登录"),
|
||||
USER_NAME_OR_PASSWORD_ERROR(3, "用户名或密码错误"),
|
||||
USER_DISABLE(4, "当前用户已被禁止登录"),
|
||||
PARAMS_NOT_NULL(10, "参数[{}]不能为空"),
|
||||
PARAMS_NOT_EMPTY(11, "参数[{}]不能为空"),
|
||||
|
||||
// 用户管理(11000)
|
||||
// license管理(12000)
|
||||
LICENSE_NAME_CANNOT_REPEAT(12000, "license名称不能重复"),
|
||||
LICENSE_NOT_EXIST(12001, "license数据不存在"),
|
||||
// 端口池管理(13000)
|
||||
PORT_CANNOT_REPEAT(13000,"端口不能重复"),
|
||||
// 端口映射管理(14000)
|
||||
SYSTEM_ERROR(500, "系统异常"),
|
||||
;
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class BaseAuthInterceptor implements HandlerInterceptor {
|
||||
throw ServiceException.create(ExceptionConstant.USER_NOT_LOGIN);
|
||||
}
|
||||
if (EnableStatusEnum.DISABLE.getStatus().equals(userDO.getEnable())) {
|
||||
throw ServiceException.create(ExceptionConstant.USER_DISBLE);
|
||||
throw ServiceException.create(ExceptionConstant.USER_DISABLE);
|
||||
}
|
||||
systemContext.setToken(authorize);
|
||||
systemContext.setUser(userDO);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ import java.lang.reflect.Method;
|
||||
public class CorsInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod) throws Exception {
|
||||
public void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod, Object result) throws Exception {
|
||||
responseWrapper.headers().add("Access-Control-Allow-Origin", "*");
|
||||
responseWrapper.headers().add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
|
||||
responseWrapper.headers().add("Access-Control-Max-Age", "86400");
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Copyright (c) 2022 aoshiguchen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.base.rest.interceptor;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import fun.asgc.neutrino.core.web.context.HttpRequestWrapper;
|
||||
import fun.asgc.neutrino.core.web.context.HttpResponseWrapper;
|
||||
import fun.asgc.neutrino.core.web.interceptor.HandlerInterceptor;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 访问日志拦截器
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/14
|
||||
*/
|
||||
@Slf4j
|
||||
public class VisitLogInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod) throws Exception {
|
||||
SystemContextHolder.getContext().setReceiveTime(new Date());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpRequestWrapper requestParser, HttpResponseWrapper responseWrapper, String route, Method targetMethod, Object result) throws Exception {
|
||||
Date receiveTime = SystemContextHolder.getContext().getReceiveTime();
|
||||
Date now = new Date();
|
||||
long elapsedTime = now.getTime() - receiveTime.getTime();
|
||||
log.info("\n-----------------------------------------------------------------接口请求日志:\n{} url:{} 执行耗时:{}\nURL参数:{}\n请求体参数:{}\n响应结果:{}",
|
||||
requestParser.getMethod().name(), requestParser.getUrl(), getElapsedTimeStr(elapsedTime),
|
||||
requestParser.getQueryString(),
|
||||
requestParser.getContentAsString(),
|
||||
JSONObject.toJSONString(result));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取耗时描述
|
||||
* @param elapsedTime
|
||||
* @return
|
||||
*/
|
||||
private static String getElapsedTimeStr(long elapsedTime) {
|
||||
if (elapsedTime < 1000) {
|
||||
return String.format("%s毫秒", elapsedTime);
|
||||
} else if (elapsedTime < 60000) {
|
||||
return String.format("%.2f秒", (elapsedTime * 1.0) / 1000);
|
||||
}
|
||||
return String.format("%.2f分钟", (elapsedTime * 1.0) / 1000 / 60);
|
||||
}
|
||||
}
|
||||
+26
-7
@@ -32,6 +32,9 @@ import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateEnableStatusRe
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.service.LicenseService;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -48,45 +51,61 @@ public class LicenseController {
|
||||
|
||||
@GetMapping("page")
|
||||
public Page<LicenseListRes> page(PageQuery pageQuery, LicenseListReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(pageQuery, "pageQuery");
|
||||
|
||||
return licenseService.page(pageQuery, req);
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public List<LicenseListRes> list(LicenseListReq req) {
|
||||
return licenseService.list(req);
|
||||
}
|
||||
|
||||
@PostMapping("create")
|
||||
public LicenseCreateRes create(@RequestBody LicenseCreateReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotEmpty(req.getName(), "name");
|
||||
ParamCheckUtil.checkNotNull(req.getUserId(), "userId");
|
||||
|
||||
return licenseService.create(req);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
public LicenseUpdateRes update(@RequestBody LicenseUpdateReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotEmpty(req.getName(), "name");
|
||||
|
||||
return licenseService.update(req);
|
||||
}
|
||||
|
||||
@GetMapping("detail")
|
||||
public LicenseDetailRes detail(@RequestParam("id") Integer id) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
|
||||
return licenseService.detail(id);
|
||||
}
|
||||
|
||||
@PostMapping("update/enable-status")
|
||||
public LicenseUpdateEnableStatusRes updateEnableStatus(@RequestBody LicenseUpdateEnableStatusReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
|
||||
return licenseService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
public void delete(@RequestParam("id") Integer id) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
|
||||
licenseService.delete(id);
|
||||
}
|
||||
|
||||
@PostMapping("reset")
|
||||
public void reset(@RequestParam("id") Integer id) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
|
||||
licenseService.reset(id);
|
||||
}
|
||||
|
||||
|
||||
+21
-7
@@ -29,8 +29,10 @@ import fun.asgc.neutrino.core.web.annotation.*;
|
||||
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.req.PortMappingUpdateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.service.PortMappingService;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
/**
|
||||
* 端口映射
|
||||
@@ -46,37 +48,49 @@ public class PortMappingController {
|
||||
|
||||
@GetMapping("page")
|
||||
public Page<PortMappingListRes> page(PageQuery pageQuery, PortMappingListReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(pageQuery, "pageQuery");
|
||||
|
||||
return portMappingService.page(pageQuery, req);
|
||||
}
|
||||
|
||||
@PostMapping("create")
|
||||
public PortMappingCreateRes create(@RequestBody PortMappingCreateReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getLicenseId(), "licenseId");
|
||||
ParamCheckUtil.checkNotNull(req.getServerPort(), "serverPort");
|
||||
ParamCheckUtil.checkNotEmpty(req.getClientIp(), "clientIp");
|
||||
ParamCheckUtil.checkNotNull(req.getClientPort(), "clientPort");
|
||||
|
||||
return portMappingService.create(req);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
public PortMappingUpdateRes update(@RequestBody PortMappingUpdateRes req) {
|
||||
// TODO 参数校验
|
||||
public PortMappingUpdateRes update(@RequestBody PortMappingUpdateReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
|
||||
return portMappingService.update(req);
|
||||
}
|
||||
|
||||
@GetMapping("detail")
|
||||
public PortMappingDetailRes detail(@RequestParam("id") Integer id) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
|
||||
return portMappingService.detail(id);
|
||||
}
|
||||
|
||||
@PostMapping("update/enable-status")
|
||||
public PortMappingUpdateEnableStatusRes updateEnableStatus(@RequestBody PortMappingUpdateEnableStatusReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
|
||||
return portMappingService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
public void delete(@RequestParam("id") Integer id) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
|
||||
portMappingService.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-4
@@ -33,6 +33,9 @@ import fun.asgc.neutrino.proxy.server.controller.res.PortPoolCreateRes;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolListRes;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolUpdateEnableStatusRes;
|
||||
import fun.asgc.neutrino.proxy.server.service.PortPoolService;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 端口池
|
||||
@@ -48,25 +51,37 @@ public class PortPoolController {
|
||||
|
||||
@GetMapping("page")
|
||||
public Page<PortPoolListRes> page(PageQuery pageQuery, PortPoolListReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(pageQuery, "pageQuery");
|
||||
|
||||
return portPoolService.page(pageQuery, req);
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public List<PortPoolListRes> list(PortPoolListReq req) {
|
||||
return portPoolService.list(req);
|
||||
}
|
||||
|
||||
@PostMapping("create")
|
||||
public PortPoolCreateRes create(@RequestBody PortPoolCreateReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getPort(), "port");
|
||||
|
||||
return portPoolService.create(req);
|
||||
}
|
||||
|
||||
@PostMapping("update/enable-status")
|
||||
public PortPoolUpdateEnableStatusRes updateEnableStatus(@RequestBody PortPoolUpdateEnableStatusReq req) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotNull(req.getEnable(), "enable");
|
||||
|
||||
return portPoolService.updateEnableStatus(req);
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
public void delete(@RequestParam("id") Integer id) {
|
||||
// TODO 参数校验
|
||||
ParamCheckUtil.checkNotNull(id, "id");
|
||||
|
||||
portPoolService.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -31,4 +31,13 @@ import lombok.Data;
|
||||
@Data
|
||||
public class PortMappingUpdateEnableStatusReq {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* 启用状态
|
||||
*/
|
||||
private Integer enable;
|
||||
|
||||
}
|
||||
|
||||
+20
-1
@@ -30,5 +30,24 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
public class PortMappingUpdateReq {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* licenseId
|
||||
*/
|
||||
private Integer licenseId;
|
||||
/**
|
||||
* 服务端端口
|
||||
*/
|
||||
private Integer serverPort;
|
||||
/**
|
||||
* 客户端ip
|
||||
*/
|
||||
private String clientIp;
|
||||
/**
|
||||
* 客户端端口
|
||||
*/
|
||||
private Integer clientPort;
|
||||
}
|
||||
|
||||
+54
-1
@@ -21,14 +21,67 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.controller.res;
|
||||
|
||||
import fun.asgc.neutrino.core.db.annotation.Id;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 端口映射详情响应
|
||||
* @author: aoshiguchen
|
||||
* @date: 2022/8/8
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class PortMappingDetailRes {
|
||||
|
||||
@Id
|
||||
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 clientPort;
|
||||
/**
|
||||
* 是否在线
|
||||
* {@link OnlineStatusEnum}
|
||||
*/
|
||||
private Integer isOnline;
|
||||
/**
|
||||
* 启用状态
|
||||
* {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum}
|
||||
*/
|
||||
private Integer enable;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
}
|
||||
|
||||
+13
@@ -31,6 +31,7 @@ import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
import fun.asgc.neutrino.core.db.page.Page;
|
||||
import fun.asgc.neutrino.core.db.page.PageQuery;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.LicenseListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -52,6 +53,10 @@ public interface LicenseMapper extends SqlMapper {
|
||||
*/
|
||||
void page(Page page, LicenseListReq req);
|
||||
|
||||
@ResultType(LicenseListRes.class)
|
||||
@Select("select * from license where enable = 1")
|
||||
List<LicenseListRes> list();
|
||||
|
||||
/**
|
||||
* 新增license
|
||||
* @param license
|
||||
@@ -76,4 +81,12 @@ public interface LicenseMapper extends SqlMapper {
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where in in (:ids)")
|
||||
List<LicenseDO> findByIds(@Param("ids")Set<Integer> ids);
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where user_id = :userId and name =:name limit 0,1")
|
||||
LicenseDO checkRepeat(@Param("userId") Integer userId, @Param("name") String name);
|
||||
|
||||
@ResultType(LicenseDO.class)
|
||||
@Select("select * from `license` where user_id = :userId and name =:name and id not in (:excludeIds) limit 0,1")
|
||||
LicenseDO checkRepeat(@Param("userId") Integer userId, @Param("name") String name, @Param("excludeIds") Set<Integer> excludeIds);
|
||||
}
|
||||
|
||||
+12
@@ -22,8 +22,11 @@
|
||||
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;
|
||||
import fun.asgc.neutrino.core.db.page.Page;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortMappingListReq;
|
||||
@@ -45,4 +48,13 @@ public interface PortMappingMapper extends SqlMapper {
|
||||
void add(PortMappingDO portMappingDO);
|
||||
|
||||
void update(PortMappingDO portMappingDO);
|
||||
|
||||
@Select("select * from port_mapping where id = ?")
|
||||
PortMappingDO findById(Integer id);
|
||||
|
||||
@Update("update `port_mapping` set enable = :enable where id = :id")
|
||||
void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable);
|
||||
|
||||
@Delete("delete from `port_mapping` where id = ?")
|
||||
void delete(Integer id);
|
||||
}
|
||||
|
||||
+9
@@ -30,6 +30,8 @@ import fun.asgc.neutrino.proxy.server.controller.req.PortPoolListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -42,6 +44,10 @@ public interface PortPoolMapper extends SqlMapper {
|
||||
@Select("select * from port_pool")
|
||||
void page(Page<PortPoolListRes> page, PortPoolListReq req);
|
||||
|
||||
@ResultType(PortPoolListRes.class)
|
||||
@Select("select * from port_pool where enable = 1")
|
||||
List<PortPoolListRes> list();
|
||||
|
||||
@Insert("insert into port_pool(`port`,`enable`,`create_time`,`update_time`) values(:port,:enable,:createTime,:updateTime)")
|
||||
void add(PortPoolDO portPool);
|
||||
|
||||
@@ -50,4 +56,7 @@ public interface PortPoolMapper extends SqlMapper {
|
||||
|
||||
@Delete("delete from `port_pool` where id = ?")
|
||||
void delete(Integer id);
|
||||
|
||||
@Select("select * from port_pool where port = ? limit 0,1")
|
||||
PortPoolDO findByPort(Integer port);
|
||||
}
|
||||
|
||||
+28
@@ -21,12 +21,14 @@
|
||||
*/
|
||||
package fun.asgc.neutrino.proxy.server.service;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
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.proxy.server.base.rest.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseCreateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.LicenseListReq;
|
||||
@@ -37,6 +39,7 @@ import fun.asgc.neutrino.proxy.server.dal.LicenseMapper;
|
||||
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.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -72,12 +75,31 @@ public class LicenseService {
|
||||
return page;
|
||||
}
|
||||
|
||||
public List<LicenseListRes> list(LicenseListReq req) {
|
||||
List<LicenseListRes> licenseList = licenseMapper.list();
|
||||
if (!CollectionUtil.isEmpty(licenseList)) {
|
||||
Set<Integer> userIds = licenseList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet());
|
||||
List<UserDO> userList = userMapper.findByIds(userIds);
|
||||
Map<Integer, UserDO> userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity()));
|
||||
for (LicenseListRes item : licenseList) {
|
||||
UserDO userDO = userMap.get(item.getUserId());
|
||||
if (null != userDO) {
|
||||
item.setUserName(userDO.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return licenseList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建license
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
public LicenseCreateRes create(LicenseCreateReq req) {
|
||||
LicenseDO licenseDO = licenseMapper.checkRepeat(req.getUserId(), req.getName());
|
||||
ParamCheckUtil.checkExpression(null == licenseDO, ExceptionConstant.LICENSE_NAME_CANNOT_REPEAT);
|
||||
|
||||
String key = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
Date now = new Date();
|
||||
|
||||
@@ -94,6 +116,12 @@ public class LicenseService {
|
||||
}
|
||||
|
||||
public LicenseUpdateRes update(LicenseUpdateReq req) {
|
||||
LicenseDO oldLicenseDO = licenseMapper.findById(req.getId());
|
||||
ParamCheckUtil.checkExpression(null != oldLicenseDO, ExceptionConstant.LICENSE_NOT_EXIST);
|
||||
|
||||
LicenseDO licenseCheck = licenseMapper.checkRepeat(oldLicenseDO.getUserId(), req.getName(), Sets.newHashSet(oldLicenseDO.getId()));
|
||||
ParamCheckUtil.checkExpression(null == licenseCheck, ExceptionConstant.LICENSE_NAME_CANNOT_REPEAT);
|
||||
|
||||
licenseMapper.update(req.getId(), req.getName());
|
||||
return new LicenseUpdateRes();
|
||||
}
|
||||
|
||||
+41
-6
@@ -26,12 +26,12 @@ 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.req.PortMappingUpdateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.dal.LicenseMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.PortMappingMapper;
|
||||
@@ -103,20 +103,55 @@ public class PortMappingService {
|
||||
return new PortMappingCreateRes();
|
||||
}
|
||||
|
||||
public PortMappingUpdateRes update(PortMappingUpdateRes req) {
|
||||
return null;
|
||||
public PortMappingUpdateRes update(PortMappingUpdateReq req) {
|
||||
PortMappingDO portMappingDO = new PortMappingDO();
|
||||
portMappingDO.setId(req.getId());
|
||||
portMappingDO.setLicenseId(req.getLicenseId());
|
||||
portMappingDO.setServerPort(req.getServerPort());
|
||||
portMappingDO.setClientIp(req.getClientIp());
|
||||
portMappingDO.setClientPort(req.getClientPort());
|
||||
portMappingDO.setUpdateTime(new Date());
|
||||
portMappingMapper.update(portMappingDO);
|
||||
return new PortMappingUpdateRes();
|
||||
}
|
||||
|
||||
public PortMappingDetailRes detail(Integer id) {
|
||||
return null;
|
||||
PortMappingDO portMappingDO = portMappingMapper.findById(id);
|
||||
if (null == portMappingDO) {
|
||||
return null;
|
||||
}
|
||||
PortMappingDetailRes res = new PortMappingDetailRes()
|
||||
.setId(portMappingDO.getId())
|
||||
.setLicenseId(portMappingDO.getLicenseId())
|
||||
.setServerPort(portMappingDO.getServerPort())
|
||||
.setClientIp(portMappingDO.getClientIp())
|
||||
.setClientPort(portMappingDO.getClientPort())
|
||||
.setIsOnline(portMappingDO.getIsOnline())
|
||||
.setEnable(portMappingDO.getEnable())
|
||||
.setCreateTime(portMappingDO.getCreateTime())
|
||||
.setUpdateTime(portMappingDO.getUpdateTime());
|
||||
|
||||
LicenseDO license = licenseMapper.findById(portMappingDO.getLicenseId());
|
||||
if (null != license) {
|
||||
res.setLicenseName(license.getName());
|
||||
res.setUserId(license.getUserId());
|
||||
UserDO user = userMapper.findById(license.getUserId());
|
||||
if (null != user) {
|
||||
res.setUserName(user.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public PortMappingUpdateEnableStatusRes updateEnableStatus(PortMappingUpdateEnableStatusReq req) {
|
||||
return null;
|
||||
portMappingMapper.updateEnableStatus(req.getId(), req.getEnable());
|
||||
|
||||
return new PortMappingUpdateEnableStatusRes();
|
||||
}
|
||||
|
||||
public void delete(Integer id) {
|
||||
|
||||
portMappingMapper.delete(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
@@ -26,6 +26,7 @@ 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.proxy.server.base.rest.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolCreateReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.PortPoolUpdateEnableStatusReq;
|
||||
@@ -35,8 +36,10 @@ import fun.asgc.neutrino.proxy.server.controller.res.PortPoolListRes;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.PortPoolUpdateEnableStatusRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.PortPoolMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -55,7 +58,14 @@ public class PortPoolService {
|
||||
return page;
|
||||
}
|
||||
|
||||
public List<PortPoolListRes> list(PortPoolListReq req) {
|
||||
return portPoolMapper.list();
|
||||
}
|
||||
|
||||
public PortPoolCreateRes create(PortPoolCreateReq req) {
|
||||
PortPoolDO oldPortPoolDO = portPoolMapper.findByPort(req.getPort());
|
||||
ParamCheckUtil.checkExpression(null == oldPortPoolDO, ExceptionConstant.PORT_CANNOT_REPEAT);
|
||||
|
||||
Date now = new Date();
|
||||
|
||||
portPoolMapper.add(new PortPoolDO()
|
||||
|
||||
+35
-5
@@ -25,6 +25,10 @@ import fun.asgc.neutrino.core.util.StringUtil;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.ServiceException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author: aoshiguchen
|
||||
@@ -32,13 +36,39 @@ import fun.asgc.neutrino.proxy.server.base.rest.ServiceException;
|
||||
*/
|
||||
public class ParamCheckUtil {
|
||||
|
||||
public static void checkNotEmpty(Object obj, String name) {
|
||||
if (obj == null) {
|
||||
throw ServiceException.create(ExceptionConstant.PARAMS_NOT_NULL, name);
|
||||
}
|
||||
if (obj instanceof String && StringUtil.isEmpty((String) obj)) {
|
||||
public static void checkNotNull(Object obj, String name) {
|
||||
if (null == obj) {
|
||||
throw ServiceException.create(ExceptionConstant.PARAMS_NOT_NULL, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotEmpty(String str, String name) {
|
||||
if (StringUtil.isEmpty(str)) {
|
||||
throw ServiceException.create(ExceptionConstant.PARAMS_NOT_EMPTY, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotEmpty(Collection collection, String name) {
|
||||
if (null == collection || collection.isEmpty()) {
|
||||
throw ServiceException.create(ExceptionConstant.PARAMS_NOT_EMPTY, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotEmpty(Map map, String name) {
|
||||
if (null == map || map.isEmpty()) {
|
||||
throw ServiceException.create(ExceptionConstant.PARAMS_NOT_EMPTY, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkNotEmpty(Set set, String name) {
|
||||
if (null == set || set.isEmpty()) {
|
||||
throw ServiceException.create(ExceptionConstant.PARAMS_NOT_EMPTY, name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkExpression(boolean expression, ExceptionConstant constant, Object... params) {
|
||||
if (!expression) {
|
||||
throw ServiceException.create(constant, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<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
|
||||
set license_id = :licenseId,server_port = :serverPort,client_ip=:clientIp,client_port=:clientPort,update_time=:updateTime
|
||||
where id =:id
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user