From 0e12e4ab45db6768a0f45d8952f78b0ae9190723 Mon Sep 17 00:00:00 2001 From: ZQN <364596817@qq.com> Date: 星期一, 19 五月 2025 16:09:01 +0800 Subject: [PATCH] 手机号登录,去掉短信验证。脱敏 --- project-admin/src/main/java/com/project/admin/controller/system/SysUserController.java | 177 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 134 insertions(+), 43 deletions(-) diff --git a/project-admin/src/main/java/com/project/admin/controller/system/SysUserController.java b/project-admin/src/main/java/com/project/admin/controller/system/SysUserController.java index ddfc6e7..411b4ff 100644 --- a/project-admin/src/main/java/com/project/admin/controller/system/SysUserController.java +++ b/project-admin/src/main/java/com/project/admin/controller/system/SysUserController.java @@ -1,22 +1,7 @@ package com.project.admin.controller.system; -import java.util.List; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang3.ArrayUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; import com.project.common.annotation.Log; +import com.project.common.annotation.RepeatSubmit; import com.project.common.constant.UserConstants; import com.project.common.core.controller.BaseController; import com.project.common.core.domain.AjaxResult; @@ -26,12 +11,25 @@ import com.project.common.core.page.TableDataInfo; import com.project.common.enums.BusinessType; import com.project.common.utils.SecurityUtils; +import com.project.common.utils.SensitiveUtil; import com.project.common.utils.StringUtils; import com.project.common.utils.poi.ExcelUtil; -import com.project.system.service.ISysDeptService; -import com.project.system.service.ISysPostService; -import com.project.system.service.ISysRoleService; -import com.project.system.service.ISysUserService; +import com.project.system.domain.bo.editBo.UserDeptBo; +import com.project.system.domain.vo.SysUserResultVo; +import com.project.system.domain.vo.SysUserVo; +import com.project.system.service.*; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.stream.Collectors; /** * 鐢ㄦ埛淇℃伅 @@ -40,19 +38,14 @@ */ @RestController @RequestMapping("/system/user") +@RequiredArgsConstructor public class SysUserController extends BaseController { - @Autowired - private ISysUserService userService; - - @Autowired - private ISysRoleService roleService; - - @Autowired - private ISysDeptService deptService; - - @Autowired - private ISysPostService postService; + private final ISysUserService userService; + private final ISysRoleService roleService; + private final ISysDeptService deptService; + private final ISysPostService postService; + private final ISysUserDeptService userDeptService; /** * 鑾峰彇鐢ㄦ埛鍒楄〃 @@ -62,7 +55,8 @@ public TableDataInfo list(SysUser user) { startPage(); - List<SysUser> list = userService.selectUserList(user); + List<SysUser> list = userService.selectUserListCommon(user); + list.forEach(SensitiveUtil::desensitize); return getDataTable(list); } @@ -71,29 +65,26 @@ @PostMapping("/export") public void export(HttpServletResponse response, SysUser user) { - List<SysUser> list = userService.selectUserList(user); - ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); + List<SysUser> list = userService.selectUserListCommon(user); + ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class); util.exportExcel(response, list, "鐢ㄦ埛鏁版嵁"); } + + @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.IMPORT) @PreAuthorize("@ss.hasPermi('system:user:import')") @PostMapping("/importData") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { - ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); + ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class); List<SysUser> userList = util.importExcel(file.getInputStream()); String operName = getUsername(); String message = userService.importUser(userList, updateSupport, operName); return success(message); } - @PostMapping("/importTemplate") - public void importTemplate(HttpServletResponse response) - { - ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); - util.importTemplateExcel(response, "鐢ㄦ埛鏁版嵁"); - } + /** * 鏍规嵁鐢ㄦ埛缂栧彿鑾峰彇璇︾粏淇℃伅 @@ -125,6 +116,18 @@ @PostMapping public AjaxResult add(@Validated @RequestBody SysUser user) { + user.setPassword(user.getPhonenumber()); + if (user.getDeptId()!=null){ + user.setUserType("01"); + SysDept sysDept = deptService.selectDeptById(user.getDeptId()); + if (sysDept.getAncestors().contains("101") || sysDept.getDeptId().equals(101L)){ + user.setUserType("00"); + user.setRecommendPhone(deptService.getCheckDeptIdByLoginDeptId(user.getDeptId()).toString()); + } else { + user.setUserType("01"); + } + } + if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) { return error("鏂板鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岀櫥褰曡处鍙峰凡瀛樺湪"); @@ -139,7 +142,9 @@ { return error("鏂板鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岄偖绠辫处鍙峰凡瀛樺湪"); } + user.setCreateBy(getUsername()); + user.setRecommendUser(user.getPassword()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); return toAjax(userService.insertUser(user)); } @@ -154,6 +159,15 @@ { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); + user.setPassword(user.getPhonenumber()); + if (user.getDeptId()!=null){ + SysDept sysDept = deptService.selectDeptById(user.getDeptId()); + if (sysDept.getAncestors().contains("101") || sysDept.getDeptId().equals(101L)){ + user.setUserType("00"); + } else { + user.setUserType("01"); + } + } if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user))) { return error("淇敼鐢ㄦ埛'" + user.getUserName() + "'澶辫触锛岀櫥褰曡处鍙峰凡瀛樺湪"); @@ -190,18 +204,56 @@ /** * 閲嶇疆瀵嗙爜 */ - @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") +// @PreAuthorize("@ss.hasPermi('system:user:resetPwd')") @Log(title = "鐢ㄦ埛绠$悊", businessType = BusinessType.UPDATE) @PutMapping("/resetPwd") public AjaxResult resetPwd(@RequestBody SysUser user) { userService.checkUserAllowed(user); userService.checkUserDataScope(user.getUserId()); - user.setRemark(user.getPassword()); + user.setRecommendUser(user.getPassword()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); user.setUpdateBy(getUsername()); return toAjax(userService.resetPwd(user)); + } + + @ApiOperation("鐢ㄦ埛澶氭満鏋勨�斺�斿洖鏄�") + @GetMapping("/batchUserDeptView") + public AjaxResult batchUserDeptView(@RequestParam("userId") Long userId) + { + return AjaxResult.success(userDeptService.batchUserDeptView(userId)); + } + + @ApiOperation("鐢ㄦ埛澶氭満鏋勨�斺�斾繚瀛�") + @Log(title = "鐢ㄦ埛澶氭満鏋勪繚瀛�", businessType = BusinessType.UPDATE) + @PostMapping("/batchUserDeptSave") + public AjaxResult batchUserDeptSave(@RequestBody UserDeptBo bo) + { + return AjaxResult.success(userDeptService.batchUserDeptSave(bo)); + } + + @ApiOperation("鐢ㄦ埛澶氭満鏋勨�斺�旀満鏋勬爲") + @GetMapping("/batchUserDeptTree") + public AjaxResult batchUserDeptTree(@RequestParam("deptId") Long deptId) + { + return AjaxResult.success(userDeptService.batchUserDeptTree(deptId)); + } + + @ApiOperation("浼佷笟鐢ㄦ埛閲嶇疆瀵嗙爜") + @Log(title = "浼佷笟鐢ㄦ埛閲嶇疆瀵嗙爜", businessType = BusinessType.UPDATE) + @PostMapping("/resetCompanyUserPwd") + public AjaxResult resetCompanyUserPwd(@RequestParam("companyId") Long companyId,@RequestParam("newPassword") String newPassword) + { + SysUser user = userService.list(userService.lq().eq(SysUser::getDeptId, companyId)).get(0); + if (user==null) { + return AjaxResult.error("娌℃湁璇ヤ紒涓氬搴旇处鎴�"); + } + if (userService.resetUserPwd(user.getUserName(), SecurityUtils.encryptPassword(newPassword), newPassword) > 0) + { + return success(); + } + return error("淇敼瀵嗙爜寮傚父锛岃鑱旂郴绠$悊鍛�"); } /** @@ -255,4 +307,43 @@ { return success(deptService.selectDeptTreeList(dept)); } + + + @ApiOperation("鐢ㄦ埛妯℃澘涓嬭浇") + @GetMapping("/exportTemplate") + public AjaxResult exportTemplate() + { + ExcelUtil<SysUserVo> util = new ExcelUtil<>(SysUserVo.class); + return util.exportExcel(null, "鐢ㄦ埛淇℃伅妯℃澘"); + } + + @ApiOperation(value = "澶勭悊瀵煎叆淇℃伅") + @Log(title = "瀵煎叆鐢ㄦ埛淇℃伅澶勭悊" , businessType = BusinessType.OTHER) + @ApiImplicitParam(value = "鐢ㄦ埛淇℃伅", name = "file", dataType = "file", dataTypeClass = MultipartFile.class) + @PostMapping("/doImport") + public AjaxResult doImport(@RequestPart(value = "file") MultipartFile file, @RequestParam("deptId") Long deptId) throws Exception + { + + ExcelUtil<SysUserVo> util = new ExcelUtil<>(SysUserVo.class); + List<SysUserVo> list = util.importExcel(file.getInputStream()); + return AjaxResult.success(userService.doImport(list, deptId)); + } + + @ApiOperation(value = "鏍¢獙瀵煎叆淇℃伅") + @Log(title = "瀵煎叆鐢ㄦ埛淇℃伅鏍¢獙" , businessType = BusinessType.OTHER) + @PostMapping("/checkImport") + public AjaxResult checkImport(@RequestBody SysUserResultVo resultVo) + { + return AjaxResult.success(userService.checkImport(resultVo)); + } + + @ApiOperation(value = "淇濆瓨瀵煎叆淇℃伅") + @Log(title = "瀵煎叆鐢ㄦ埛淇℃伅淇濆瓨" , businessType = BusinessType.IMPORT) + @PostMapping("/saveImport") + @RepeatSubmit + public AjaxResult saveImport(@RequestBody SysUserResultVo resultVo) + { + return toAjax(userService.saveImport(resultVo) ? 1 : 0); + } + } -- Gitblit v1.9.1