From 601c2b5badd3076ebdbd3223a0eee402cd7d0f90 Mon Sep 17 00:00:00 2001 From: wangxy <1356089412@qq.com> Date: Fri, 26 Jul 2024 10:57:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=94=9F=E6=88=90=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/system/SysUserController.java | 121 ++++++++---------- ruoyi-common/pom.xml | 6 + 2 files changed, 56 insertions(+), 71 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java index 3ba6013..4c1a038 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/system/SysUserController.java @@ -1,13 +1,10 @@ package com.ruoyi.web.controller.system.system; -import java.io.IOException; import java.util.List; import java.util.stream.Collectors; -import com.ruoyi.common.config.RuoYiConfig; -import com.ruoyi.common.exception.file.InvalidExtensionException; -import com.ruoyi.common.utils.file.FileUploadUtils; -import com.ruoyi.common.utils.file.MimeTypeUtils; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.extra.pinyin.PinyinUtil; import org.apache.commons.lang3.ArrayUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.slf4j.Logger; @@ -40,13 +37,12 @@ import com.ruoyi.system.service.ISysUserService; /** * 用户信息 - * + * * @author ruoyi */ @Controller @RequestMapping("/system/user") -public class SysUserController extends BaseController -{ +public class SysUserController extends BaseController { private static final Logger log = LoggerFactory.getLogger(SysUserController.class); private String prefix = "system/user"; @@ -55,7 +51,7 @@ public class SysUserController extends BaseController @Autowired private ISysRoleService roleService; - + @Autowired private ISysDeptService deptService; @@ -67,16 +63,14 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:view") @GetMapping() - public String user() - { + public String user() { return prefix + "/user"; } @RequiresPermissions("system:user:list") @PostMapping("/list") @ResponseBody - public TableDataInfo list(SysUser user) - { + public TableDataInfo list(SysUser user) { startPage(); List list = userService.selectUserList(user); return getDataTable(list); @@ -86,8 +80,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:export") @PostMapping("/export") @ResponseBody - public AjaxResult export(SysUser user) - { + public AjaxResult export(SysUser user) { List list = userService.selectUserList(user); ExcelUtil util = new ExcelUtil(SysUser.class); return util.exportExcel(list, "用户数据"); @@ -97,8 +90,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:import") @PostMapping("/importData") @ResponseBody - public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception - { + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil(SysUser.class); List userList = util.importExcel(file.getInputStream()); String message = userService.importUser(userList, updateSupport, getLoginName()); @@ -108,8 +100,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:view") @GetMapping("/importTemplate") @ResponseBody - public AjaxResult importTemplate() - { + public AjaxResult importTemplate() { ExcelUtil util = new ExcelUtil(SysUser.class); return util.importTemplateExcel("用户数据"); } @@ -118,8 +109,7 @@ public class SysUserController extends BaseController * 新增用户 */ @GetMapping("/add") - public String add(ModelMap mmap) - { + public String add(ModelMap mmap) { mmap.put("roles", roleService.selectRoleAll().stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); mmap.put("posts", postService.selectPostAll()); return prefix + "/add"; @@ -132,17 +122,12 @@ public class SysUserController extends BaseController @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @ResponseBody - public AjaxResult addSave(@Validated SysUser user) { - if (!userService.checkLoginNameUnique(user)) - { + public AjaxResult addSave(@Validated SysUser user) { + if (!userService.checkLoginNameUnique(user)) { return error("新增用户'" + user.getLoginName() + "'失败,登录账号已存在"); - } - else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { return error("新增用户'" + user.getLoginName() + "'失败,手机号码已存在"); - } - else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { return error("新增用户'" + user.getLoginName() + "'失败,邮箱账号已存在"); } user.setSalt(ShiroUtils.randomSalt()); @@ -156,8 +141,7 @@ public class SysUserController extends BaseController */ @RequiresPermissions("system:user:edit") @GetMapping("/edit/{userId}") - public String edit(@PathVariable("userId") Long userId, ModelMap mmap) - { + public String edit(@PathVariable("userId") Long userId, ModelMap mmap) { userService.checkUserDataScope(userId); List roles = roleService.selectRolesByUserId(userId); mmap.put("user", userService.selectUserById(userId)); @@ -173,20 +157,14 @@ public class SysUserController extends BaseController @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody - public AjaxResult editSave(@Validated SysUser user) - { + public AjaxResult editSave(@Validated SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); - if (!userService.checkLoginNameUnique(user)) - { + if (!userService.checkLoginNameUnique(user)) { return error("修改用户'" + user.getLoginName() + "'失败,登录账号已存在"); - } - else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在"); - } - else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) - { + } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在"); } user.setUpdateBy(getLoginName()); @@ -196,8 +174,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:resetPwd") @GetMapping("/resetPwd/{userId}") - public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap) - { + public String resetPwd(@PathVariable("userId") Long userId, ModelMap mmap) { mmap.put("user", userService.selectUserById(userId)); return prefix + "/resetPwd"; } @@ -206,16 +183,13 @@ public class SysUserController extends BaseController @Log(title = "重置密码", businessType = BusinessType.RESET) @PostMapping("/resetPwd") @ResponseBody - public AjaxResult resetPwdSave(SysUser user) - { + public AjaxResult resetPwdSave(SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); - if (userService.resetUserPwd(user) > 0) - { - if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue()) - { + if (userService.resetUserPwd(user) > 0) { + if (ShiroUtils.getUserId().longValue() == user.getUserId().longValue()) { setSysUser(userService.selectUserById(user.getUserId())); } return success(); @@ -227,8 +201,7 @@ public class SysUserController extends BaseController * 进入授权角色页 */ @GetMapping("/authRole/{userId}") - public String authRole(@PathVariable("userId") Long userId, ModelMap mmap) - { + public String authRole(@PathVariable("userId") Long userId, ModelMap mmap) { SysUser user = userService.selectUserById(userId); // 获取用户所属的角色列表 List roles = roleService.selectRolesByUserId(userId); @@ -244,8 +217,7 @@ public class SysUserController extends BaseController @Log(title = "用户管理", businessType = BusinessType.GRANT) @PostMapping("/authRole/insertAuthRole") @ResponseBody - public AjaxResult insertAuthRole(Long userId, Long[] roleIds) - { + public AjaxResult insertAuthRole(Long userId, Long[] roleIds) { userService.checkUserDataScope(userId); userService.insertUserAuth(userId, roleIds); AuthorizationUtils.clearAllCachedAuthorizationInfo(); @@ -256,10 +228,8 @@ public class SysUserController extends BaseController @Log(title = "用户管理", businessType = BusinessType.DELETE) @PostMapping("/remove") @ResponseBody - public AjaxResult remove(String ids) - { - if (ArrayUtils.contains(Convert.toLongArray(ids), getUserId())) - { + public AjaxResult remove(String ids) { + if (ArrayUtils.contains(Convert.toLongArray(ids), getUserId())) { return error("当前用户不能删除"); } return toAjax(userService.deleteUserByIds(ids)); @@ -270,8 +240,7 @@ public class SysUserController extends BaseController */ @PostMapping("/checkLoginNameUnique") @ResponseBody - public boolean checkLoginNameUnique(SysUser user) - { + public boolean checkLoginNameUnique(SysUser user) { return userService.checkLoginNameUnique(user); } @@ -280,8 +249,7 @@ public class SysUserController extends BaseController */ @PostMapping("/checkPhoneUnique") @ResponseBody - public boolean checkPhoneUnique(SysUser user) - { + public boolean checkPhoneUnique(SysUser user) { return userService.checkPhoneUnique(user); } @@ -290,8 +258,7 @@ public class SysUserController extends BaseController */ @PostMapping("/checkEmailUnique") @ResponseBody - public boolean checkEmailUnique(SysUser user) - { + public boolean checkEmailUnique(SysUser user) { return userService.checkEmailUnique(user); } @@ -302,8 +269,7 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:edit") @PostMapping("/changeStatus") @ResponseBody - public AjaxResult changeStatus(SysUser user) - { + public AjaxResult changeStatus(SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); return toAjax(userService.changeStatus(user)); @@ -315,25 +281,38 @@ public class SysUserController extends BaseController @RequiresPermissions("system:user:list") @GetMapping("/deptTreeData") @ResponseBody - public List deptTreeData() - { + public List deptTreeData() { List ztrees = deptService.selectDeptTree(new SysDept()); return ztrees; } /** * 选择部门树 - * + * * @param deptId 部门ID */ @RequiresPermissions("system:user:list") @GetMapping("/selectDeptTree/{deptId}") - public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap) - { + public String selectDeptTree(@PathVariable("deptId") Long deptId, ModelMap mmap) { mmap.put("dept", deptService.selectDeptById(deptId)); return prefix + "/deptTree"; } + @GetMapping("/getPinyin") + @ResponseBody + public AjaxResult getPinyin(@RequestParam String name) { + return AjaxResult.success(getFirstLetter(name)); + } + + /** + * 中文转拼音 + * + * @param columnName + * @return java.lang.String + */ + public String getFirstLetter(String columnName) { + return PinyinUtil.getFirstLetter(columnName, "") + RandomUtil.randomNumbers(4); + } } \ No newline at end of file diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 57025dc..311db82 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -122,6 +122,12 @@ 4.1.2 + + com.belerweb + pinyin4j + 2.5.1 + +