From 2b8c538a7bcd36db9212f3212996288221d911f1 Mon Sep 17 00:00:00 2001 From: aoshiguchen <1052045476@qq.com> Date: Sat, 6 Aug 2022 17:25:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Elicense=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E3=80=81=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/LicenseController.java | 15 ++++ .../controller/req/LicenseUpdateReq.java | 41 +++++++++++ .../controller/res/LicenseDetailRes.java | 73 +++++++++++++++++++ .../controller/res/LicenseUpdateRes.java | 31 ++++++++ .../proxy/server/dal/LicenseMapper.java | 7 ++ .../proxy/server/service/LicenseService.java | 35 +++++++++ 6 files changed, 202 insertions(+) create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateReq.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java create mode 100644 neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseUpdateRes.java 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 87f2ad8e..6d07a9c3 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,8 +32,11 @@ import fun.asgc.neutrino.core.annotation.NonIntercept; import fun.asgc.neutrino.core.web.annotation.*; 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.req.LicenseUpdateReq; import fun.asgc.neutrino.proxy.server.controller.res.LicenseCreateRes; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseDetailRes; import fun.asgc.neutrino.proxy.server.controller.res.LicenseUpdateEnableStatusRes; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseUpdateRes; import fun.asgc.neutrino.proxy.server.service.LicenseService; @NonIntercept @@ -51,6 +54,18 @@ public class LicenseController { return licenseService.create(req); } + @PostMapping("update") + public LicenseUpdateRes update(@RequestBody LicenseUpdateReq req) { + // TODO 参数校验 + return licenseService.update(req); + } + + @GetMapping("detail") + public LicenseDetailRes detail(@RequestParam("id") Integer id) { + // TODO 参数校验 + return licenseService.detail(id); + } + @PostMapping("update/enable-status") public LicenseUpdateEnableStatusRes updateEnableStatus(@RequestBody LicenseUpdateEnableStatusReq req) { // TODO 参数校验 diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateReq.java new file mode 100644 index 00000000..58abcf50 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/LicenseUpdateReq.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; + +/** + * + * @author: aoshiguchen + * @date: 2022/8/6 + */ +@Data +public class LicenseUpdateReq { + /** + * id + */ + private Integer id; + /** + * license名称 + */ + private String name; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.java new file mode 100644 index 00000000..b565ee56 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseDetailRes.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.controller.res; + +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/6 + */ +@Accessors(chain = true) +@Data +public class LicenseDetailRes { + private Integer id; + /** + * 名称 + */ + private String name; + /** + * licenseKey + */ + private String key; + /** + * 用户ID + */ + private Integer userId; + /** + * 用户名 + */ + private String userName; + /** + * 是否在线 + * {@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/controller/res/LicenseUpdateRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseUpdateRes.java new file mode 100644 index 00000000..adf8c051 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/LicenseUpdateRes.java @@ -0,0 +1,31 @@ +/** + * 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: aoshiguchen + * @date: 2022/8/6 + */ +public class LicenseUpdateRes { + +} 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 e49a47af..fd5da8a9 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 @@ -24,6 +24,7 @@ package fun.asgc.neutrino.proxy.server.dal; import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.annotation.Param; import fun.asgc.neutrino.core.db.annotation.Delete; +import fun.asgc.neutrino.core.db.annotation.Select; 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; @@ -52,4 +53,10 @@ public interface LicenseMapper extends SqlMapper { @Delete("delete from `license` where id = ?") void delete(Integer id); + + @Select("select * from `license` where id = ?") + LicenseDO findById(Integer id); + + @Update("update `license` set name = :name where id = :id") + void update(@Param("id") Integer id, @Param("name") String name); } 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 869ffc2d..7ccbdce5 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 @@ -27,10 +27,15 @@ 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.req.LicenseUpdateReq; import fun.asgc.neutrino.proxy.server.controller.res.LicenseCreateRes; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseDetailRes; import fun.asgc.neutrino.proxy.server.controller.res.LicenseUpdateEnableStatusRes; +import fun.asgc.neutrino.proxy.server.controller.res.LicenseUpdateRes; 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 java.util.Date; import java.util.UUID; @@ -45,6 +50,8 @@ public class LicenseService { @Autowired private LicenseMapper licenseMapper; + @Autowired + private UserMapper userMapper; /** * 创建license @@ -67,6 +74,34 @@ public class LicenseService { return new LicenseCreateRes(); } + public LicenseUpdateRes update(LicenseUpdateReq req) { + licenseMapper.update(req.getId(), req.getName()); + return new LicenseUpdateRes(); + } + + public LicenseDetailRes detail(Integer id) { + LicenseDO licenseDO = licenseMapper.findById(id); + if (null == licenseDO) { + return null; + } + UserDO userDO = userMapper.findById(licenseDO.getUserId()); + String userName = ""; + if (null != userDO) { + userName = userDO.getName(); + } + return new LicenseDetailRes() + .setId(licenseDO.getId()) + .setName(licenseDO.getName()) + .setKey(licenseDO.getKey()) + .setUserId(licenseDO.getUserId()) + .setUserName(userName) + .setIsOnline(licenseDO.getIsOnline()) + .setEnable(licenseDO.getEnable()) + .setCreateTime(licenseDO.getCreateTime()) + .setUpdateTime(licenseDO.getUpdateTime()) + ; + } + /** * 更新license启用状态 * @param req