diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/UserLoginRecordController.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/UserLoginRecordController.java new file mode 100644 index 00000000..4b7dcb5d --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/UserLoginRecordController.java @@ -0,0 +1,53 @@ +/** + * 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.UserLoginRecordListReq; +import fun.asgc.neutrino.proxy.server.controller.res.UserLoginRecordListRes; +import fun.asgc.neutrino.proxy.server.service.UserLoginRecordService; +import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil; + +/** + * @author: aoshiguchen + * @date: 2022/10/20 + */ +@NonIntercept +@RequestMapping("user-login-record") +@RestController +public class UserLoginRecordController { + @Autowired + private UserLoginRecordService userLoginRecordService; + + @GetMapping("page") + public Page page(PageQuery pageQuery, UserLoginRecordListReq req) { + ParamCheckUtil.checkNotNull(pageQuery, "pageQuery"); + + return userLoginRecordService.page(pageQuery, req); + } +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/UserLoginRecordListReq.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/UserLoginRecordListReq.java new file mode 100644 index 00000000..82c11c7e --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/req/UserLoginRecordListReq.java @@ -0,0 +1,34 @@ +/** + * 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/10/20 + */ +@Data +public class UserLoginRecordListReq { + +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/UserLoginRecordListRes.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/UserLoginRecordListRes.java new file mode 100644 index 00000000..2f5ba48e --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/controller/res/UserLoginRecordListRes.java @@ -0,0 +1,56 @@ +/** + * 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/10/20 + */ +@Data +public class UserLoginRecordListRes { + private Integer id; + /** + * 用户ID + */ + private Integer userId; + /** + * 用户名 + */ + private String userName; + /** + * ip + */ + private String ip; + /** + * 类型 + */ + private Integer type; + /** + * 创建时间 + */ + private Date createTime; +} diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserLoginRecordMapper.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserLoginRecordMapper.java index 61154085..90ba0c26 100644 --- a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserLoginRecordMapper.java +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/dal/UserLoginRecordMapper.java @@ -24,7 +24,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.Insert; +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.UserLoginRecordListReq; +import fun.asgc.neutrino.proxy.server.controller.res.UserLoginRecordListRes; import fun.asgc.neutrino.proxy.server.dal.entity.UserLoginRecordDO; /** @@ -42,4 +47,8 @@ public interface UserLoginRecordMapper extends SqlMapper { */ @Insert("insert into `user_login_record`(`user_id`,`ip`,`token`,`type`,`create_time`) values(:userId,:ip,:token,:type,:createTime)") int add(UserLoginRecordDO userLoginRecord); + + @ResultType(UserLoginRecordListRes.class) + @Select("select * from user_login_record order by create_time desc") + void page(Page page, UserLoginRecordListReq req); } diff --git a/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserLoginRecordService.java b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserLoginRecordService.java new file mode 100644 index 00000000..e1a50c8e --- /dev/null +++ b/neutrino-proxy-server/src/main/java/fun/asgc/neutrino/proxy/server/service/UserLoginRecordService.java @@ -0,0 +1,71 @@ +/** + * 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.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.UserLoginRecordListReq; +import fun.asgc.neutrino.proxy.server.controller.res.UserLoginRecordListRes; +import fun.asgc.neutrino.proxy.server.dal.UserLoginRecordMapper; +import fun.asgc.neutrino.proxy.server.dal.UserMapper; +import fun.asgc.neutrino.proxy.server.dal.entity.UserDO; + +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/10/20 + */ +@NonIntercept +@Component +public class UserLoginRecordService { + @Autowired + private UserLoginRecordMapper userLoginRecordMapper; + @Autowired + private UserMapper userMapper; + + public Page page(PageQuery pageQuery, UserLoginRecordListReq req) { + Page page = Page.create(pageQuery); + userLoginRecordMapper.page(page, req); + if (!CollectionUtil.isEmpty(page.getRecords())) { + Set userIds = page.getRecords().stream().map(UserLoginRecordListRes::getUserId).collect(Collectors.toSet()); + List userList = userMapper.findByIds(userIds); + Map userMap = userList.stream().collect(Collectors.toMap(UserDO::getId, Function.identity())); + for (UserLoginRecordListRes item : page.getRecords()) { + UserDO userDO = userMap.get(item.getUserId()); + if (null != userDO) { + item.setUserName(userDO.getName()); + } + } + } + return page; + } +}