diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/ClientConnectRecordController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/ClientConnectRecordController.java new file mode 100644 index 00000000..8ade1dde --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/ClientConnectRecordController.java @@ -0,0 +1,54 @@ +/** + * 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; + +import fun.asgc.neutrino.core.annotation.Autowired; +import fun.asgc.neutrino.core.annotation.NonIntercept; +import fun.asgc.neutrino.core.db.page.Page; +import fun.asgc.neutrino.core.db.page.PageQuery; +import fun.asgc.neutrino.core.web.annotation.GetMapping; +import fun.asgc.neutrino.core.web.annotation.RequestMapping; +import fun.asgc.neutrino.core.web.annotation.RestController; +import fun.asgc.neutrino.proxy.server.controller.req.ClientConnectRecordListReq; +import fun.asgc.neutrino.proxy.server.controller.res.ClientConnectRecordListRes; +import fun.asgc.neutrino.proxy.server.service.ClientConnectRecordService; +import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil; +import lombok.extern.slf4j.Slf4j; + +/** + * @author: aoshiguchen + * @date: 2022/11/26 + */ +@Slf4j +@NonIntercept +@RequestMapping("client-connect-record") +@RestController +public class ClientConnectRecordController { + @Autowired + private ClientConnectRecordService clientConnectRecordService; + + @GetMapping("page") + public Page page(PageQuery pageQuery, ClientConnectRecordListReq req) { + ParamCheckUtil.checkNotNull(pageQuery, "pageQuery"); + return clientConnectRecordService.page(pageQuery, req); + } +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/ClientConnectRecordListReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/ClientConnectRecordListReq.java new file mode 100644 index 00000000..a0e3caf9 --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/ClientConnectRecordListReq.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.req; + +import lombok.Data; + +/** + * @author: aoshiguchen + * @date: 2022/11/26 + */ +@Data +public class ClientConnectRecordListReq { + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/ClientConnectRecordListRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/ClientConnectRecordListRes.java new file mode 100644 index 00000000..4c6116ea --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/ClientConnectRecordListRes.java @@ -0,0 +1,52 @@ +/** + * 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; + +import java.util.Date; + +/** + * @author: aoshiguchen + * @date: 2022/11/26 + */ +@Data +public class ClientConnectRecordListRes { + private Integer id; + private String ip; + private Integer licenseId; + private Integer type; + private Integer userId; + private String userName; + private String licenseName; + private String msg; + /** + * 1、成功 + * 2、失败 + */ + private Integer code; + private String err; + /** + * 创建时间 + */ + private Date createTime; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java index 42ecd441..fb39c3a8 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/ClientConnectRecordMapper.java @@ -2,7 +2,12 @@ package fun.asgc.neutrino.proxy.server.dal; import fun.asgc.neutrino.core.annotation.Component; import fun.asgc.neutrino.core.aop.Intercept; +import fun.asgc.neutrino.core.db.annotation.ResultType; +import fun.asgc.neutrino.core.db.annotation.Select; import fun.asgc.neutrino.core.db.mapper.SqlMapper; +import fun.asgc.neutrino.core.db.page.Page; +import fun.asgc.neutrino.proxy.server.controller.req.ClientConnectRecordListReq; +import fun.asgc.neutrino.proxy.server.controller.res.ClientConnectRecordListRes; import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; /** @@ -14,4 +19,8 @@ import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; public interface ClientConnectRecordMapper extends SqlMapper { void add(ClientConnectRecordDO clientConnectRecordDO); + + @ResultType(ClientConnectRecordListRes.class) + @Select("select * from client_connect_record") + void page(Page page, ClientConnectRecordListReq req); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java index 83b75878..718939fb 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/ClientConnectRecordService.java @@ -24,10 +24,25 @@ 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.annotation.NonIntercept; +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.controller.req.ClientConnectRecordListReq; +import fun.asgc.neutrino.proxy.server.controller.res.ClientConnectRecordListRes; import fun.asgc.neutrino.proxy.server.dal.ClientConnectRecordMapper; +import fun.asgc.neutrino.proxy.server.dal.LicenseMapper; +import fun.asgc.neutrino.proxy.server.dal.UserMapper; import fun.asgc.neutrino.proxy.server.dal.entity.ClientConnectRecordDO; +import fun.asgc.neutrino.proxy.server.dal.entity.LicenseDO; +import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; import lombok.extern.slf4j.Slf4j; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + /** * @author: aoshiguchen * @date: 2022/11/23 @@ -38,8 +53,46 @@ import lombok.extern.slf4j.Slf4j; public class ClientConnectRecordService { @Autowired private ClientConnectRecordMapper clientConnectRecordMapper; + @Autowired + private LicenseMapper licenseMapper; + @Autowired + private UserMapper userMapper; public void add(ClientConnectRecordDO clientConnectRecordDO) { clientConnectRecordMapper.add(clientConnectRecordDO); } + + public Page page(PageQuery pageQuery, ClientConnectRecordListReq req) { + Page page = Page.create(pageQuery); + clientConnectRecordMapper.page(page, req); + if (CollectionUtil.isEmpty(page.getRecords())) { + return page; + } + Set licenseIds = page.getRecords().stream().map(ClientConnectRecordListRes::getLicenseId).collect(Collectors.toSet()); + if (CollectionUtil.isEmpty(licenseIds)) { + return page; + } + List licenseList = licenseMapper.findByIds(licenseIds); + if (CollectionUtil.isEmpty(licenseList)) { + return page; + } + Set userIds = licenseList.stream().map(LicenseDO::getUserId).collect(Collectors.toSet()); + List userList = userMapper.findByIds(userIds); + Map licenseMap = licenseList.stream().collect(Collectors.toMap(LicenseDO::getId, Function.identity())); + Map userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity())); + page.getRecords().forEach(item -> { + LicenseDO license = licenseMap.get(item.getLicenseId()); + if (null == license) { + return; + } + item.setLicenseName(license.getName()); + item.setUserId(license.getUserId()); + UserDO user = userMap.get(license.getUserId()); + if (null == user) { + return; + } + item.setUserName(user.getName()); + }); + return page; + } }