From 650a2c072c5a7411b6afe70738c3a2f68db08f75 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Sun, 14 Aug 2022 15:11:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=98=A0=E5=B0=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=AE=8C=E5=96=84.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/aop/proxy/ProxyCompiler.java | 5 +- .../core/db/mapper/SqlMapperInterceptor.java | 16 ++-- .../asgc/neutrino/core/db/page/PageQuery.java | 4 - .../core/db/template/JdbcOperations.java | 1 - .../neutrino/core/web/HttpRequestHandler.java | 8 +- .../web/interceptor/HandlerInterceptor.java | 2 +- .../web/interceptor/MappedInterceptor.java | 4 +- .../core/web/test1/BaseAuthInterceptor.java | 5 -- .../proxy/server/base/rest/SystemContext.java | 6 ++ .../server/base/rest/SystemContextHolder.java | 4 + .../rest/config/WebConfigurerAdapter.java | 6 +- .../base/rest/constant/ExceptionConstant.java | 15 +++- .../rest/interceptor/BaseAuthInterceptor.java | 2 +- .../rest/interceptor/CorsInterceptor.java | 2 +- .../rest/interceptor/VisitLogInterceptor.java | 73 +++++++++++++++++++ .../server/controller/LicenseController.java | 33 +++++++-- .../controller/PortMappingController.java | 28 +++++-- .../server/controller/PortPoolController.java | 23 +++++- .../req/PortMappingUpdateEnableStatusReq.java | 9 +++ .../controller/req/PortMappingUpdateReq.java | 21 +++++- .../controller/res/PortMappingDetailRes.java | 55 +++++++++++++- .../proxy/server/dal/LicenseMapper.java | 13 ++++ .../proxy/server/dal/PortMappingMapper.java | 12 +++ .../proxy/server/dal/PortPoolMapper.java | 9 +++ .../proxy/server/service/LicenseService.java | 28 +++++++ .../server/service/PortMappingService.java | 47 ++++++++++-- .../proxy/server/service/PortPoolService.java | 10 +++ .../proxy/server/util/ParamCheckUtil.java | 40 ++++++++-- .../resources/mapper/PortMappingMapper.xml | 2 +- 29 files changed, 411 insertions(+), 72 deletions(-) create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/VisitLogInterceptor.java diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyCompiler.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyCompiler.java index 5b0e3842..5097cf45 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyCompiler.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/aop/proxy/ProxyCompiler.java @@ -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 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())); } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java index 9a629203..f6f8a48a 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/mapper/SqlMapperInterceptor.java @@ -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 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()) { diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/page/PageQuery.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/page/PageQuery.java index 1ff198a6..3b25d67e 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/page/PageQuery.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/page/PageQuery.java @@ -21,10 +21,6 @@ */ package fun.asgc.neutrino.core.db.page; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - /** * * @author: aoshiguchen diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/template/JdbcOperations.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/template/JdbcOperations.java index a796127a..483da757 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/template/JdbcOperations.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/db/template/JdbcOperations.java @@ -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++){ diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java index 8b7e2c0c..ca272d5d 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/HttpRequestHandler.java @@ -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); } } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/HandlerInterceptor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/HandlerInterceptor.java index daf722da..3726047f 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/HandlerInterceptor.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/HandlerInterceptor.java @@ -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) { diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/MappedInterceptor.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/MappedInterceptor.java index 5d0b46d6..ca43fa1c 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/MappedInterceptor.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/interceptor/MappedInterceptor.java @@ -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); } } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/BaseAuthInterceptor.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/BaseAuthInterceptor.java index c8a7b8cd..d4575e8b 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/BaseAuthInterceptor.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/BaseAuthInterceptor.java @@ -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 { - - } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContext.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContext.java index 0817bf06..091b32e5 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContext.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContext.java @@ -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; } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContextHolder.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContextHolder.java index a0647e3d..aaa2a75f 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContextHolder.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/SystemContextHolder.java @@ -50,4 +50,8 @@ public class SystemContextHolder { public static String getIp() { return systemContextHolder.get().getIp(); } + + public static SystemContext getContext() { + return systemContextHolder.get(); + } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/WebConfigurerAdapter.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/WebConfigurerAdapter.java index 7bc79a53..a806df64 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/WebConfigurerAdapter.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/config/WebConfigurerAdapter.java @@ -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 diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java index 52a6d440..5f3a76b0 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/ExceptionConstant.java @@ -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, "系统异常"), ; diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java index ffbf176f..35a43604 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/BaseAuthInterceptor.java @@ -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); diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/CorsInterceptor.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/CorsInterceptor.java index fee5778f..68ccaddd 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/CorsInterceptor.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/CorsInterceptor.java @@ -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"); diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/VisitLogInterceptor.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/VisitLogInterceptor.java new file mode 100644 index 00000000..52c8080d --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/interceptor/VisitLogInterceptor.java @@ -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); + } +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/LicenseController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/LicenseController.java index 715a0a20..b13f81ff 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/LicenseController.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/LicenseController.java @@ -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 page(PageQuery pageQuery, LicenseListReq req) { - // TODO 参数校验 + ParamCheckUtil.checkNotNull(pageQuery, "pageQuery"); + return licenseService.page(pageQuery, req); } + @GetMapping("list") + public List 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); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortMappingController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortMappingController.java index 98f84497..6af60752 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortMappingController.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortMappingController.java @@ -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 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); } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortPoolController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortPoolController.java index 809e7908..833ad2bb 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortPoolController.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/PortPoolController.java @@ -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 page(PageQuery pageQuery, PortPoolListReq req) { - // TODO 参数校验 + ParamCheckUtil.checkNotNull(pageQuery, "pageQuery"); + return portPoolService.page(pageQuery, req); } + @GetMapping("list") + public List 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); } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateEnableStatusReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateEnableStatusReq.java index 84ceab11..9a455b3b 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateEnableStatusReq.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateEnableStatusReq.java @@ -31,4 +31,13 @@ import lombok.Data; @Data public class PortMappingUpdateEnableStatusReq { + /** + * id + */ + private Integer id; + /** + * 启用状态 + */ + private Integer enable; + } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateReq.java index 710d4e7a..bd3e6adc 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateReq.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/PortMappingUpdateReq.java @@ -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; } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java index 3c95b11c..9dcb8826 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/PortMappingDetailRes.java @@ -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; } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/LicenseMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/LicenseMapper.java index 728d002f..339a16f1 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/LicenseMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/LicenseMapper.java @@ -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 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 findByIds(@Param("ids")Set 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 excludeIds); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortMappingMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortMappingMapper.java index 1e784228..d5fa7993 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortMappingMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortMappingMapper.java @@ -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); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortPoolMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortPoolMapper.java index 2a6c3a83..bdc8cb6d 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortPoolMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/PortPoolMapper.java @@ -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 page, PortPoolListReq req); + @ResultType(PortPoolListRes.class) + @Select("select * from port_pool where enable = 1") + List 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); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java index 2a11c6b9..e2da0984 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java @@ -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 list(LicenseListReq req) { + List licenseList = licenseMapper.list(); + if (!CollectionUtil.isEmpty(licenseList)) { + Set userIds = licenseList.stream().map(LicenseListRes::getUserId).collect(Collectors.toSet()); + List userList = userMapper.findByIds(userIds); + Map 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(); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java index 91bcaadc..31c69f63 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortMappingService.java @@ -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); } } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java index 9adbd6cf..36a68dae 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/PortPoolService.java @@ -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 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() diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java index d561e4b4..d228339e 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/util/ParamCheckUtil.java @@ -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); + } + } } diff --git a/neutrino-proxy-server/src/main/resources/mapper/PortMappingMapper.xml b/neutrino-proxy-server/src/main/resources/mapper/PortMappingMapper.xml index 1022b7ac..664f990c 100644 --- a/neutrino-proxy-server/src/main/resources/mapper/PortMappingMapper.xml +++ b/neutrino-proxy-server/src/main/resources/mapper/PortMappingMapper.xml @@ -7,7 +7,7 @@ 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