From fe93d9fac0126904e92bd83a9fda06e81fb0b378 Mon Sep 17 00:00:00 2001 From: MichaelWin Date: Fri, 31 Oct 2025 17:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/corewing/app/entity/User.java | 5 + .../modules/admin/biz/BizUserController.java | 56 ++ .../admin/{ => sys}/SysUserController.java | 23 +- .../corewing/app/service/SysUserService.java | 3 + .../com/corewing/app/service/UserService.java | 12 + .../app/service/impl/SysUserServiceImpl.java | 9 + .../app/service/impl/UserServiceImpl.java | 34 +- .../resources/static/assets/css/table.css | 117 ++++ .../templates/admin/biz/user/index.html | 627 ++++++++++++++++++ 9 files changed, 880 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/corewing/app/modules/admin/biz/BizUserController.java rename src/main/java/com/corewing/app/modules/admin/{ => sys}/SysUserController.java (78%) create mode 100644 src/main/resources/static/assets/css/table.css create mode 100644 src/main/resources/templates/admin/biz/user/index.html diff --git a/src/main/java/com/corewing/app/entity/User.java b/src/main/java/com/corewing/app/entity/User.java index d0e28fe..acd20c9 100644 --- a/src/main/java/com/corewing/app/entity/User.java +++ b/src/main/java/com/corewing/app/entity/User.java @@ -25,6 +25,11 @@ public class User implements Serializable { @TableId(value = "id", type = IdType.AUTO) private Long id; + /** + * 用户昵称 + */ + private String nickName; + /** * 用户名 */ diff --git a/src/main/java/com/corewing/app/modules/admin/biz/BizUserController.java b/src/main/java/com/corewing/app/modules/admin/biz/BizUserController.java new file mode 100644 index 0000000..b416e3a --- /dev/null +++ b/src/main/java/com/corewing/app/modules/admin/biz/BizUserController.java @@ -0,0 +1,56 @@ +package com.corewing.app.modules.admin.biz; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.corewing.app.common.Result; +import com.corewing.app.dto.biz.ResetPassword; +import com.corewing.app.entity.SysUser; +import com.corewing.app.entity.User; +import com.corewing.app.service.UserService; +import io.lettuce.core.ConnectionEvents; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; + +@Controller +@RequestMapping("/biz/user") +public class BizUserController { + + @Resource + private UserService userService; + + /** + * 跳转到用户管理页面 + * @return 页面名称 + */ + @GetMapping("/index") + public String index() { + return "admin/biz/user/index"; + } + + /** + * 获取分页信息 + * @param user 用户搜索对象 + * @return 用户信息集合 + */ + @GetMapping("/page") + @ResponseBody + public Result> page(User user) { + Page sysUserPage = userService.page(user); + return Result.success(sysUserPage); + } + + /** + * 修改密码 + * @param resetPassword 修改密码DTO + * @return 成功 or 失败 + */ + @PutMapping("/resetPassword") + @ResponseBody + public Result resetPassword(@RequestBody ResetPassword resetPassword) { + boolean flag = userService.resetPassword(resetPassword); + return Result.isBoolAsMsg(flag, "修改密码成功"); + } + + +} diff --git a/src/main/java/com/corewing/app/modules/admin/SysUserController.java b/src/main/java/com/corewing/app/modules/admin/sys/SysUserController.java similarity index 78% rename from src/main/java/com/corewing/app/modules/admin/SysUserController.java rename to src/main/java/com/corewing/app/modules/admin/sys/SysUserController.java index 6872eac..529930f 100644 --- a/src/main/java/com/corewing/app/modules/admin/SysUserController.java +++ b/src/main/java/com/corewing/app/modules/admin/sys/SysUserController.java @@ -1,12 +1,14 @@ -package com.corewing.app.modules.admin; +package com.corewing.app.modules.admin.sys; import cn.dev33.satoken.stp.StpUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.corewing.app.common.Result; -import com.corewing.app.dto.SysLoginRequest; +import com.corewing.app.dto.api.SysLoginRequest; import com.corewing.app.entity.SysUser; import com.corewing.app.service.SysUserService; import com.corewing.app.util.I18nUtil; import com.corewing.app.util.IpUtil; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @@ -16,7 +18,7 @@ import java.util.Map; /** * 后台管理用户 Controller */ -@RestController +@Controller @RequestMapping("/sys/user") public class SysUserController { @@ -26,10 +28,23 @@ public class SysUserController { this.sysUserService = sysUserService; } + @GetMapping("/index") + public String index() { + return "admin/sys/user/index"; + } + + @GetMapping("/page") + @ResponseBody + public Result> page(SysUser sysUser) { + Page sysUserPage = sysUserService.page(sysUser); + return Result.success(sysUserPage); + } + /** * 后台管理登录 */ @PostMapping("/login") + @ResponseBody public Result> login(@RequestBody SysLoginRequest request, HttpServletRequest httpRequest) { try { String loginIp = IpUtil.getClientIp(httpRequest); @@ -56,6 +71,7 @@ public class SysUserController { * 后台管理登出 */ @PostMapping("/logout") + @ResponseBody public Result logout() { StpUtil.logout(); return Result.success(I18nUtil.getMessage("user.logout.success")); @@ -65,6 +81,7 @@ public class SysUserController { * 获取当前登录用户信息 */ @GetMapping("/info") + @ResponseBody public Result getUserInfo() { Long userId = StpUtil.getLoginIdAsLong(); SysUser user = sysUserService.getById(userId); diff --git a/src/main/java/com/corewing/app/service/SysUserService.java b/src/main/java/com/corewing/app/service/SysUserService.java index 0b7d5dc..9fefbb6 100644 --- a/src/main/java/com/corewing/app/service/SysUserService.java +++ b/src/main/java/com/corewing/app/service/SysUserService.java @@ -1,5 +1,6 @@ package com.corewing.app.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.corewing.app.entity.SysUser; @@ -8,6 +9,8 @@ import com.corewing.app.entity.SysUser; */ public interface SysUserService extends IService { + Page page(SysUser sysUser); + /** * 根据用户名查询用户 * diff --git a/src/main/java/com/corewing/app/service/UserService.java b/src/main/java/com/corewing/app/service/UserService.java index 89f42a6..2c411f7 100644 --- a/src/main/java/com/corewing/app/service/UserService.java +++ b/src/main/java/com/corewing/app/service/UserService.java @@ -1,6 +1,9 @@ package com.corewing.app.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; +import com.corewing.app.dto.biz.ResetPassword; +import com.corewing.app.entity.SysUser; import com.corewing.app.entity.User; /** @@ -8,6 +11,8 @@ import com.corewing.app.entity.User; */ public interface UserService extends IService { + Page page(User user); + /** * 根据用户名查询用户 * @@ -74,4 +79,11 @@ public interface UserService extends IService { * @param loginIp 登录IP */ void updateLoginInfo(Long userId, String loginIp); + + /** + * 修改密码 + * @param resetPassword + * @return + */ + boolean resetPassword(ResetPassword resetPassword); } diff --git a/src/main/java/com/corewing/app/service/impl/SysUserServiceImpl.java b/src/main/java/com/corewing/app/service/impl/SysUserServiceImpl.java index 733ff0b..1ca111d 100644 --- a/src/main/java/com/corewing/app/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/corewing/app/service/impl/SysUserServiceImpl.java @@ -2,7 +2,9 @@ package com.corewing.app.service.impl; import cn.dev33.satoken.stp.StpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.common.page.PageContext; import com.corewing.app.entity.SysUser; import com.corewing.app.mapper.SysUserMapper; import com.corewing.app.service.SysUserService; @@ -20,6 +22,13 @@ import java.time.LocalDateTime; @Service public class SysUserServiceImpl extends ServiceImpl implements SysUserService { + public Page page(SysUser sysUser) { + Page page = PageContext.getPage(SysUser.class); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + return page(page, queryWrapper); + } + + @Override public SysUser getByUsername(String username) { if (!StringUtils.hasText(username)) { diff --git a/src/main/java/com/corewing/app/service/impl/UserServiceImpl.java b/src/main/java/com/corewing/app/service/impl/UserServiceImpl.java index 1657d3c..8948999 100644 --- a/src/main/java/com/corewing/app/service/impl/UserServiceImpl.java +++ b/src/main/java/com/corewing/app/service/impl/UserServiceImpl.java @@ -2,7 +2,10 @@ package com.corewing.app.service.impl; import cn.dev33.satoken.stp.StpUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.corewing.app.common.page.PageContext; +import com.corewing.app.dto.biz.ResetPassword; import com.corewing.app.entity.User; import com.corewing.app.mapper.UserMapper; import com.corewing.app.service.UserService; @@ -23,10 +26,22 @@ public class UserServiceImpl extends ServiceImpl implements Us private final VerifyCodeService verifyCodeService; private final Ip2RegionUtil ip2RegionUtil; + private final UserMapper userMapper; - public UserServiceImpl(VerifyCodeService verifyCodeService, Ip2RegionUtil ip2RegionUtil) { + public UserServiceImpl(VerifyCodeService verifyCodeService, Ip2RegionUtil ip2RegionUtil, UserMapper userMapper) { this.verifyCodeService = verifyCodeService; this.ip2RegionUtil = ip2RegionUtil; + this.userMapper = userMapper; + } + + @Override + public Page page(User user) { + Page page = PageContext.getPage(User.class); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.like(StringUtils.hasText(user.getNickName()), User::getNickName, user.getNickName()); + queryWrapper.like(StringUtils.hasText(user.getUsername()), User::getUsername, user.getUsername()); + queryWrapper.like(user.getStatus() != null, User::getStatus, user.getStatus()); + return page(page, queryWrapper); } @Override @@ -80,8 +95,9 @@ public class UserServiceImpl extends ServiceImpl implements Us } // 验证密码(MD5加密) - String encryptPassword = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8)); - if (!encryptPassword.equals(user.getPassword())) { +// String encryptPassword = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8)); + // 客户端已经使用加密 + if (!password.equals(user.getPassword())) { throw new RuntimeException(I18nUtil.getMessage("error.password.incorrect")); } @@ -166,4 +182,16 @@ public class UserServiceImpl extends ServiceImpl implements Us user.setLoginRegion(ip2RegionUtil.getRegion(loginIp)); this.updateById(user); } + + @Override + public boolean resetPassword(ResetPassword resetPassword) { + User user = getById(resetPassword.getUserId()); + if(user == null) { + throw new RuntimeException(I18nUtil.getMessage("error.user.not.found")); + } + // 更新新密码 + String newPasswordMd5 = DigestUtils.md5DigestAsHex(resetPassword.getPassword().getBytes(StandardCharsets.UTF_8)); + user.setPassword(newPasswordMd5); + return updateById(user); + } } diff --git a/src/main/resources/static/assets/css/table.css b/src/main/resources/static/assets/css/table.css new file mode 100644 index 0000000..f494e7f --- /dev/null +++ b/src/main/resources/static/assets/css/table.css @@ -0,0 +1,117 @@ +/* 基础样式优化 */ +body { + background-color: #f8f9fa; + padding: 20px; +} + +.table-container { + background: #fff; + box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05); + border-radius: 8px; + padding: 24px; + margin-bottom: 2rem; +} + +.search-bar { + margin-bottom: 2rem; + display: flex; + flex-wrap: wrap; + gap: 1rem; + align-items: center; +} + +/* 批量操作样式(表格下方左侧) */ +.batch-actions { + display: flex; + align-items: center; +} + +.page-info { + display: flex; + align-items: center; + color: #6c757d; + margin-right: 1rem; +} + +/* 表格样式优化 */ +.table { + margin-bottom: 0; +} + +.table-hover tbody tr:hover { + background-color: rgba(14, 165, 233, 0.05); + cursor: pointer; +} + +.table tbody td, table thead th{ + text-align: center; +} + +/*.table tbody tr.selected {*/ +/* background-color: rgba(14, 165, 233, 0.1);*/ +/* border-color: #0ea5e9;*/ +/*}*/ + +/*.table th {*/ +/* font-weight: 600;*/ +/* color: #212529;*/ +/* border-bottom-width: 2px;*/ +/*}*/ + +/*.table td, .table th {*/ +/* vertical-align: middle;*/ +/* padding: 12px 16px;*/ +/*}*/ + +/* 搜索框样式 */ +.search-item { + flex-grow: 1; + flex-shrink: 0; + min-width: 200px; + max-width: 280px; +} + +.input-group-text { + background-color: #f1f3f5; + border-color: #dee2e6; +} + +/* 按钮样式优化 */ +.btn { + padding: 6px 16px; + border-radius: 6px; +} + +.btn-sm { + padding: 4px 12px; +} + +/* 徽章样式 */ +.badge { + padding: 4px 8px; + font-size: 13px; + font-weight: 500; + border-radius: 4px; +} + +/* 加载动画 */ +.loading-container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 40px 0; +} + +/* 无数据提示 */ +.no-data { + color: #6c757d; + text-align: center; + padding: 40px 0; +} + +.no-data i { + font-size: 48px; + margin-bottom: 16px; + color: #adb5bd; +} diff --git a/src/main/resources/templates/admin/biz/user/index.html b/src/main/resources/templates/admin/biz/user/index.html new file mode 100644 index 0000000..2c99239 --- /dev/null +++ b/src/main/resources/templates/admin/biz/user/index.html @@ -0,0 +1,627 @@ + + + + + + 用户管理系统 + + + + + + + +
+
+ +

用户管理

+ + + + + +
+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + ID昵称用户名状态创建时间操作
+
+
+ Loading... +
+

加载中,请稍候...

+
+
+
+ +
暂无匹配数据
+

请尝试调整搜索条件或重置查询

+
+
+ + {{ item.id }}{{ item.nickName }}{{ item.username }} + + {{ item.status === 1 ? '启用' : '禁用' }} + + {{ formatTime(item.createTime) }} +
+ + + +
+
+
+ + +
+
+ 已选中 {{ selectedIds.length }} 条数据 + + + + + +
+
+ + +
+
+ 共 {{ total }} 条数据,当前第 {{ pageNum }}/{{ totalPages }} 页 +
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + +