| | |
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import com.ruoyi.common.core.constant.UserConstants;
|
| | | import com.ruoyi.common.core.domain.R;
|
| | | import com.ruoyi.common.core.utils.SecurityUtils;
|
| | | import com.ruoyi.common.core.utils.StringUtils;
|
| | | import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
| | | import com.ruoyi.common.core.web.controller.BaseController;
|
| | |
| | | import com.ruoyi.common.log.enums.BusinessType;
|
| | | import com.ruoyi.common.security.annotation.InnerAuth;
|
| | | import com.ruoyi.common.security.annotation.RequiresPermissions;
|
| | | import com.ruoyi.common.security.service.TokenService;
|
| | | import com.ruoyi.common.security.utils.SecurityUtils;
|
| | | import com.ruoyi.system.api.domain.SysDept;
|
| | | import com.ruoyi.system.api.domain.SysRole;
|
| | | import com.ruoyi.system.api.domain.SysUser;
|
| | | import com.ruoyi.system.api.model.LoginUser;
|
| | | import com.ruoyi.system.service.ISysConfigService;
|
| | | import com.ruoyi.system.service.ISysDeptService;
|
| | | import com.ruoyi.system.service.ISysPermissionService;
|
| | | import com.ruoyi.system.service.ISysPostService;
|
| | | import com.ruoyi.system.service.ISysRoleService;
|
| | |
| | | private ISysRoleService roleService;
|
| | |
|
| | | @Autowired
|
| | | private ISysDeptService deptService;
|
| | |
|
| | | @Autowired
|
| | | private ISysPostService postService;
|
| | |
|
| | | @Autowired
|
| | |
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | |
|
| | | @Autowired
|
| | | private TokenService tokenService;
|
| | |
|
| | | /**
|
| | | * 获取用户列表
|
| | |
| | | @Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
| | | @RequiresPermissions("system:user:export")
|
| | | @PostMapping("/export")
|
| | | public void export(HttpServletResponse response, SysUser user) throws IOException
|
| | | public void export(HttpServletResponse response, SysUser user)
|
| | | {
|
| | | List<SysUser> list = userService.selectUserList(user);
|
| | | ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
|
| | |
| | | List<SysUser> userList = util.importExcel(file.getInputStream());
|
| | | String operName = SecurityUtils.getUsername();
|
| | | String message = userService.importUser(userList, updateSupport, operName);
|
| | | return AjaxResult.success(message);
|
| | | return success(message);
|
| | | }
|
| | |
|
| | | @PostMapping("/importTemplate")
|
| | |
| | | return R.fail("用户名或密码错误");
|
| | | }
|
| | | // 角色集合
|
| | | Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
|
| | | Set<String> roles = permissionService.getRolePermission(sysUser);
|
| | | // 权限集合
|
| | | Set<String> permissions = permissionService.getMenuPermission(sysUser.getUserId());
|
| | | Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
| | | LoginUser sysUserVo = new LoginUser();
|
| | | sysUserVo.setSysUser(sysUser);
|
| | | sysUserVo.setRoles(roles);
|
| | |
| | | {
|
| | | return R.fail("当前系统没有开启注册功能!");
|
| | | }
|
| | | if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username)))
|
| | | if (!userService.checkUserNameUnique(sysUser))
|
| | | {
|
| | | return R.fail("保存用户'" + username + "'失败,注册账号已存在");
|
| | | }
|
| | | return R.ok(userService.registerUser(sysUser));
|
| | | }
|
| | |
|
| | | /**
|
| | | *记录用户登录IP地址和登录时间
|
| | | */
|
| | | @InnerAuth
|
| | | @PutMapping("/recordlogin")
|
| | | public R<Boolean> recordlogin(@RequestBody SysUser sysUser)
|
| | | {
|
| | | return R.ok(userService.updateUserProfile(sysUser));
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @GetMapping("getInfo")
|
| | | public AjaxResult getInfo()
|
| | | {
|
| | | Long userId = SecurityUtils.getUserId();
|
| | | LoginUser loginUser = SecurityUtils.getLoginUser();
|
| | | SysUser user = loginUser.getSysUser();
|
| | | // 角色集合
|
| | | Set<String> roles = permissionService.getRolePermission(userId);
|
| | | Set<String> roles = permissionService.getRolePermission(user);
|
| | | // 权限集合
|
| | | Set<String> permissions = permissionService.getMenuPermission(userId);
|
| | | Set<String> permissions = permissionService.getMenuPermission(user);
|
| | | if (!loginUser.getPermissions().equals(permissions))
|
| | | {
|
| | | loginUser.setPermissions(permissions);
|
| | | tokenService.refreshToken(loginUser);
|
| | | }
|
| | | AjaxResult ajax = AjaxResult.success();
|
| | | ajax.put("user", userService.selectUserById(userId));
|
| | | ajax.put("user", user);
|
| | | ajax.put("roles", roles);
|
| | | ajax.put("permissions", permissions);
|
| | | return ajax;
|
| | |
| | | @GetMapping(value = { "/", "/{userId}" })
|
| | | public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
|
| | | {
|
| | | userService.checkUserDataScope(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.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
| | |
| | | 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() + "'失败,手机号码已存在");
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
|
| | | {
|
| | | return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
| | | }
|
| | | user.setUpdateBy(SecurityUtils.getUsername());
|
| | | return toAjax(userService.updateUser(user));
|
| | |
| | | {
|
| | | if (ArrayUtils.contains(userIds, SecurityUtils.getUserId()))
|
| | | {
|
| | | return AjaxResult.error("当前用户不能删除");
|
| | | 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());
|
| | | return toAjax(userService.resetPwd(user));
|
| | |
| | | public AjaxResult changeStatus(@RequestBody SysUser user)
|
| | | {
|
| | | userService.checkUserAllowed(user);
|
| | | userService.checkUserDataScope(user.getUserId());
|
| | | user.setUpdateBy(SecurityUtils.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();
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取部门树列表
|
| | | */
|
| | | @RequiresPermissions("system:user:list")
|
| | | @GetMapping("/deptTree")
|
| | | public AjaxResult deptTree(SysDept dept)
|
| | | {
|
| | | return success(deptService.selectDeptTreeList(dept));
|
| | | }
|
| | | }
|