diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/annotation/Param.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/annotation/Param.java new file mode 100644 index 00000000..728cf91e --- /dev/null +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/annotation/Param.java @@ -0,0 +1,38 @@ +/** + * 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.core.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Target({ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Param { + String value() default ""; +} 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 01cfd5df..c64f0f80 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 @@ -23,12 +23,15 @@ package fun.asgc.neutrino.core.db.mapper; import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.annotation.NonIntercept; +import fun.asgc.neutrino.core.annotation.Param; import fun.asgc.neutrino.core.aop.Invocation; import fun.asgc.neutrino.core.aop.interceptor.Interceptor; import fun.asgc.neutrino.core.cache.MemoryCache; import fun.asgc.neutrino.core.db.template.JdbcTemplate; import fun.asgc.neutrino.core.util.*; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.HashMap; import java.util.Map; /** @@ -65,9 +68,45 @@ public class SqlMapperInterceptor implements Interceptor { } else if (argsCount == 1 && !TypeUtil.isNormalBasicType(inv.getArgs()[0].getClass())) { res = jdbcTemplate.updateByModel(sql, inv.getArgs()[0]); } else { - res = jdbcTemplate.update(sql, inv.getArgs()); + Object params = getParams(inv); + if (null == params) { + res = jdbcTemplate.update(sql); + } else if (params.getClass().isArray()){ + res = jdbcTemplate.update(sql, params); + } else if (params instanceof Map) { + res = jdbcTemplate.updateByMap(sql, (Map)params); + } } } inv.setReturnValue(TypeUtil.conversion(res, resultType)); } + + /** + * 获取请求参数 + * @param inv + * @return + */ + private Object getParams(Invocation inv) { + if (inv.getTargetMethod().getParameterCount() == 0) { + return null; + } + if (!inv.getTargetMethod().getParameters()[0].isAnnotationPresent(Param.class)) { + return inv.getArgs(); + } + Map params = new HashMap<>(); + for (int i = 0; i < inv.getTargetMethod().getParameterCount(); i++) { + Parameter parameter = inv.getTargetMethod().getParameters()[i]; + Param param = parameter.getAnnotation(Param.class); + if (null == param) { + continue; + } + String key = param.value(); + Object val = inv.getArgs()[i]; + if (!StringUtil.isEmpty(key)) { + params.put(key, val); + } + + } + return params; + } } diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java index b9c0b486..95f14886 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java @@ -191,6 +191,9 @@ public class DefaultHttpRouter implements HttpRouter { } private synchronized void addRoute(BeanWrapper beanWrapper, Method method, HttpMethod httpMethod, String path) { + if (!path.startsWith("/")) { + path = "/" + path; + } log.info("addRoute[{}#{}] httpMethod:{} path:{}", beanWrapper.getType().getName(), method.getName(), httpMethod.name(), path); HttpRouteIdentity identity = new HttpRouteIdentity(httpMethod, path); if (routeCache.containsKey(identity)) { diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/OnlineStatusEnum.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/OnlineStatusEnum.java new file mode 100644 index 00000000..a8f1e6ef --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/base/rest/constant/OnlineStatusEnum.java @@ -0,0 +1,40 @@ +/** + * 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.constant; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 在线状态枚举 + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Getter +@AllArgsConstructor +public enum OnlineStatusEnum { + ONLINE(1, "在线"), + OFFLINE(2, "离线"); + + private Integer status; + private String desc; +} 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 new file mode 100644 index 00000000..18b50d05 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/LicenseController.java @@ -0,0 +1,64 @@ +/** + * 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.controller; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/6 + */ + +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.NonIntercept; +import fun.asgc.neutrino.core.web.annotation.PostMapping; +import fun.asgc.neutrino.core.web.annotation.RequestBody; +import fun.asgc.neutrino.core.web.annotation.RequestMapping; +import fun.asgc.neutrino.core.web.annotation.RestController; +import fun.asgc.neutrino.proxy.server.controller.req.LicenseCreateReq; +import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateEnableStatusReq; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseCreateRes; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseUpdateEnableStatusRes; +import fun.asgc.neutrino.proxy.server.service.LicenseService; + +@NonIntercept +@RequestMapping("license") +@RestController +public class LicenseController { + + @Autowired + private LicenseService licenseService; + + @PostMapping("create") + public LicenseCreateRes create(@RequestBody LicenseCreateReq req) { + // TODO 参数校验 + + return licenseService.create(req); + } + + @PostMapping("update/enable-status") + public LicenseUpdateEnableStatusRes updateEnableStatus(@RequestBody LicenseUpdateEnableStatusReq req) { + // TODO 参数校验 + + return licenseService.updateEnableStatus(req); + } + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseCreateReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseCreateReq.java new file mode 100644 index 00000000..8b3a0025 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseCreateReq.java @@ -0,0 +1,41 @@ +/** + * 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.controller.req; + +import lombok.Data; + +/** + * license创建请求 + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Data +public class LicenseCreateReq { + /** + * 名称 + */ + private String name; + /** + * 用户ID + */ + private Integer userId; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java new file mode 100644 index 00000000..70ae03e4 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateEnableStatusReq.java @@ -0,0 +1,42 @@ +/** + * 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.controller.req; + +import lombok.Data; + +/** + * 更新启用状态请求 + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Data +public class LicenseUpdateEnableStatusReq { + /** + * id + */ + private Integer id; + /** + * 启用状态 + * {@link fun.asgc.neutrino.proxy.server.base.rest.constant.EnableStatusEnum} + */ + private Integer enable; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseCreateRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseCreateRes.java new file mode 100644 index 00000000..86b7e303 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseCreateRes.java @@ -0,0 +1,33 @@ +/** + * 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.controller.res; + +import lombok.Data; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Data +public class LicenseCreateRes { +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseUpdateEnableStatusRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseUpdateEnableStatusRes.java new file mode 100644 index 00000000..f829e8b6 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseUpdateEnableStatusRes.java @@ -0,0 +1,30 @@ +/** + * 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.controller.res; + +/** + * 更新启用状态响应 + * @author: wen.y + * @date: 2022/8/6 + */ +public class LicenseUpdateEnableStatusRes { +} 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 new file mode 100644 index 00000000..792c4083 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/LicenseMapper.java @@ -0,0 +1,46 @@ +/** + * 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.dal; + +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.annotation.Param; +import fun.asgc.neutrino.core.db.annotation.Update; +import fun.asgc.neutrino.core.db.mapper.SqlMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Component +public interface LicenseMapper extends SqlMapper { + + /** + * 新增license + * @param license + */ + int add(LicenseDO license); + + @Update("update `license` set enable = :enable where id = :id") + void updateEnableStatus(@Param("id") Integer id, @Param("enable") Integer enable); +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java new file mode 100644 index 00000000..ed870d79 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/entity/LicenseDO.java @@ -0,0 +1,75 @@ +/** + * 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.dal.entity; + +import fun.asgc.neutrino.core.db.annotation.Id; +import fun.asgc.neutrino.core.db.annotation.Table; +import fun.asgc.neutrino.proxy.server.base.rest.constant.OnlineStatusEnum; +import lombok.Data; +import lombok.ToString; +import lombok.experimental.Accessors; + +import java.util.Date; + +/** + * 许可证 + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@ToString +@Accessors(chain = true) +@Data +@Table("license") +public class LicenseDO { + @Id + private Integer id; + /** + * 名称 + */ + private String name; + /** + * licenseKey + */ + private String key; + /** + * 用户ID + */ + private Integer userId; + /** + * 是否在线 + * {@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/service/LicenseService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java new file mode 100644 index 00000000..8467fea0 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/LicenseService.java @@ -0,0 +1,77 @@ +/** + * 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.service; + +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.Component; +import fun.asgc.neutrino.core.web.annotation.RequestBody; +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.LicenseCreateReq; +import fun.asgc.neutrino.proxy.server.controller.req.LicenseUpdateEnableStatusReq; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseCreateRes; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseUpdateEnableStatusRes; +import fun.asgc.neutrino.proxy.server.dal.LicenseMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO; + +import java.util.Date; +import java.util.UUID; + +/** + * license服务 + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Component +public class LicenseService { + + @Autowired + private LicenseMapper licenseMapper; + + /** + * 创建license + * @param req + * @return + */ + public LicenseCreateRes create(LicenseCreateReq req) { + String key = UUID.randomUUID().toString().replaceAll("-", ""); + Date now = new Date(); + + licenseMapper.add(new LicenseDO() + .setName(req.getName()) + .setKey(key) + .setUserId(req.getUserId()) + .setIsOnline(OnlineStatusEnum.OFFLINE.getStatus()) + .setEnable(EnableStatusEnum.ENABLE.getStatus()) + .setCreateTime(now) + .setUpdateTime(now) + ); + return new LicenseCreateRes(); + } + + public LicenseUpdateEnableStatusRes updateEnableStatus(LicenseUpdateEnableStatusReq req) { + licenseMapper.updateEnableStatus(req.getId(), req.getEnable()); + + return new LicenseUpdateEnableStatusRes(); + } + +} diff --git a/neutrino-proxy-server/src/main/resources/mapper/LicenseMapper.xml b/neutrino-proxy-server/src/main/resources/mapper/LicenseMapper.xml new file mode 100644 index 00000000..52a65c78 --- /dev/null +++ b/neutrino-proxy-server/src/main/resources/mapper/LicenseMapper.xml @@ -0,0 +1,8 @@ + + + + insert into `license`(`name`,`key`,`user_id`,`is_online`,`enable`,`create_time`,`update_time`) + values (:name, :key, :userId, :isOnline, :enable, :createTime, :updateTime) + + +