| | |
| | |
|
| | | 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.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.ruoyi.common.constant.UserConstants;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.ServletUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
| | | import com.ruoyi.framework.security.LoginUser;
|
| | | import com.ruoyi.framework.security.service.TokenService;
|
| | | import com.ruoyi.framework.web.controller.BaseController;
|
| | | import com.ruoyi.framework.web.domain.AjaxResult;
|
| | | import com.ruoyi.framework.web.page.TableDataInfo;
|
| | | import com.ruoyi.project.system.domain.SysDept;
|
| | | import com.ruoyi.project.system.domain.SysRole;
|
| | | import com.ruoyi.project.system.domain.SysUser;
|
| | | import com.ruoyi.project.system.service.ISysDeptService;
|
| | | import com.ruoyi.project.system.service.ISysPostService;
|
| | | import com.ruoyi.project.system.service.ISysRoleService;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | |
| | | private ISysRoleService roleService;
|
| | |
|
| | | @Autowired
|
| | | private ISysPostService postService;
|
| | | private ISysDeptService deptService;
|
| | |
|
| | | @Autowired
|
| | | private TokenService tokenService;
|
| | | private ISysPostService postService;
|
| | |
|
| | | /**
|
| | | * 获取用户列表
|
| | |
| | |
|
| | | @Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
| | | @PreAuthorize("@ss.hasPermi('system:user:export')")
|
| | | @GetMapping("/export")
|
| | | public AjaxResult export(SysUser user)
|
| | | @PostMapping("/export")
|
| | | public void export(HttpServletResponse response, SysUser user)
|
| | | {
|
| | | List<SysUser> list = userService.selectUserList(user);
|
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
| | | return util.exportExcel(list, "用户数据");
|
| | | util.exportExcel(response, list, "用户数据");
|
| | | }
|
| | |
|
| | | @Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
| | |
| | | {
|
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
| | | List<SysUser> userList = util.importExcel(file.getInputStream());
|
| | | LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
| | | String operName = loginUser.getUsername();
|
| | | String operName = getUsername();
|
| | | String message = userService.importUser(userList, updateSupport, operName);
|
| | | return AjaxResult.success(message);
|
| | | return success(message);
|
| | | }
|
| | |
|
| | | @GetMapping("/importTemplate")
|
| | | public AjaxResult importTemplate()
|
| | | @PostMapping("/importTemplate")
|
| | | public void importTemplate(HttpServletResponse response)
|
| | | {
|
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
| | | return util.importTemplateExcel("用户数据");
|
| | | util.importTemplateExcel(response, "用户数据");
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
| | | {
|
| | | AjaxResult ajax = AjaxResult.success();
|
| | | if (StringUtils.isNotNull(userId))
|
| | | {
|
| | | userService.checkUserDataScope(userId);
|
| | | SysUser sysUser = userService.selectUserById(userId);
|
| | | ajax.put(AjaxResult.DATA_TAG, sysUser);
|
| | | ajax.put("postIds", postService.selectPostListByUserId(userId));
|
| | | ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
|
| | | }
|
| | | List<SysRole> roles = roleService.selectRoleAll();
|
| | | ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
| | | ajax.put("posts", postService.selectPostAll());
|
| | | if (StringUtils.isNotNull(userId))
|
| | | {
|
| | | ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId));
|
| | | ajax.put("postIds", postService.selectPostListByUserId(userId));
|
| | | ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
|
| | | }
|
| | | return ajax;
|
| | | }
|
| | |
|
| | |
| | | @PostMapping
|
| | | public AjaxResult add(@Validated @RequestBody SysUser user)
|
| | | {
|
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(user.getUserName())))
|
| | | deptService.checkDeptDataScope(user.getDeptId());
|
| | | roleService.checkRoleDataScope(user.getRoleIds());
|
| | | if (!userService.checkUserNameUnique(user))
|
| | | {
|
| | | return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
| | | return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber())
|
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
| | | {
|
| | | return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
| | | return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(user.getEmail())
|
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
| | | else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
| | | {
|
| | | return AjaxResult.error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
| | | return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
| | | }
|
| | | user.setCreateBy(SecurityUtils.getUsername());
|
| | | user.setCreateBy(getUsername());
|
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
| | | // 查询顶层部门父id做为租户tenant_id
|
| | | Long tenantId = deptService.maxLevelDeptId(user.getDeptId());
|
| | | if(tenantId != null){
|
| | | user.setTenantId(tenantId.intValue());
|
| | | }
|
| | | return toAjax(userService.insertUser(user));
|
| | | }
|
| | |
|
| | |
| | | public AjaxResult edit(@Validated @RequestBody SysUser user)
|
| | | {
|
| | | userService.checkUserAllowed(user);
|
| | | if (StringUtils.isNotEmpty(user.getPhonenumber())
|
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user)))
|
| | | userService.checkUserDataScope(user.getUserId());
|
| | | deptService.checkDeptDataScope(user.getDeptId());
|
| | | roleService.checkRoleDataScope(user.getRoleIds());
|
| | | if (!userService.checkUserNameUnique(user))
|
| | | {
|
| | | return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
| | | return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(user.getEmail())
|
| | | && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user)))
|
| | | else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
|
| | | {
|
| | | return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
| | | return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
|
| | | }
|
| | | user.setUpdateBy(SecurityUtils.getUsername());
|
| | | else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
| | | {
|
| | | return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
| | | }
|
| | | user.setUpdateBy(getUsername());
|
| | | return toAjax(userService.updateUser(user));
|
| | | }
|
| | |
|
| | |
| | | @DeleteMapping("/{userIds}")
|
| | | public AjaxResult remove(@PathVariable Long[] userIds)
|
| | | {
|
| | | if (ArrayUtils.contains(userIds, getUserId()))
|
| | | {
|
| | | return error("当前用户不能删除");
|
| | | }
|
| | | return toAjax(userService.deleteUserByIds(userIds));
|
| | | }
|
| | |
|
| | |
| | | public AjaxResult resetPwd(@RequestBody SysUser user)
|
| | | {
|
| | | userService.checkUserAllowed(user);
|
| | | userService.checkUserDataScope(user.getUserId());
|
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
| | | user.setUpdateBy(SecurityUtils.getUsername());
|
| | | user.setUpdateBy(getUsername());
|
| | | return toAjax(userService.resetPwd(user));
|
| | | }
|
| | |
|
| | |
| | | public AjaxResult changeStatus(@RequestBody SysUser user)
|
| | | {
|
| | | userService.checkUserAllowed(user);
|
| | | user.setUpdateBy(SecurityUtils.getUsername());
|
| | | userService.checkUserDataScope(user.getUserId());
|
| | | user.setUpdateBy(getUsername());
|
| | | return toAjax(userService.updateUserStatus(user));
|
| | | }
|
| | |
|
| | |
| | | @PutMapping("/authRole")
|
| | | public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
|
| | | {
|
| | | userService.checkUserDataScope(userId);
|
| | | roleService.checkRoleDataScope(roleIds);
|
| | | userService.insertUserAuth(userId, roleIds);
|
| | | return success();
|
| | | }
|
| | | } |
| | |
|
| | | /**
|
| | | * 获取部门树列表
|
| | | */
|
| | | @PreAuthorize("@ss.hasPermi('system:user:list')")
|
| | | @GetMapping("/deptTree")
|
| | | public AjaxResult deptTree(SysDept dept)
|
| | | {
|
| | | return success(deptService.selectDeptTreeList(dept));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 不分页用户查询
|
| | | * @param user
|
| | | * @return
|
| | | */
|
| | | @GetMapping("/userListNoPage")
|
| | | public AjaxResult userListNoPage(SysUser user){
|
| | | List<SysUser> sysUserList = userService.userListNoPage(user);
|
| | | return AjaxResult.success(sysUserList);
|
| | | }
|
| | | }
|