Search in sources :

Example 1 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysProfileController method updateProfile.

/**
 * 修改用户
 */
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult updateProfile(@RequestBody SysUser user) {
    LoginUser loginUser = getLoginUser();
    SysUser sysUser = loginUser.getUser();
    user.setUserName(sysUser.getUserName());
    if (StringUtils.isNotEmpty(user.getPhonenumber()) && UserConstants.NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
        return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
    }
    if (StringUtils.isNotEmpty(user.getEmail()) && UserConstants.NOT_UNIQUE.equals(userService.checkEmailUnique(user))) {
        return AjaxResult.error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
    }
    user.setUserId(sysUser.getUserId());
    user.setPassword(null);
    if (userService.updateUserProfile(user) > 0) {
        // 更新缓存用户信息
        sysUser.setNickName(user.getNickName());
        sysUser.setPhonenumber(user.getPhonenumber());
        sysUser.setEmail(user.getEmail());
        sysUser.setSex(user.getSex());
        tokenService.setLoginUser(loginUser);
        return AjaxResult.success();
    }
    return AjaxResult.error("修改个人信息异常,请联系管理员");
}
Also used : SysUser(com.ruoyi.project.system.domain.SysUser) LoginUser(com.ruoyi.framework.security.LoginUser) Log(com.ruoyi.framework.aspectj.lang.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 2 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysProfileController method profile.

/**
 * 个人信息
 */
@GetMapping
public AjaxResult profile() {
    LoginUser loginUser = getLoginUser();
    SysUser user = loginUser.getUser();
    AjaxResult ajax = AjaxResult.success(user);
    ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
    ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
    return ajax;
}
Also used : AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) SysUser(com.ruoyi.project.system.domain.SysUser) LoginUser(com.ruoyi.framework.security.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysUserController method getInfo.

/**
 * 根据用户编号获取详细信息
 */
@PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping(value = { "/", "/{userId}" })
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
    userService.checkUserDataScope(userId);
    AjaxResult ajax = AjaxResult.success();
    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)) {
        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()));
    }
    return ajax;
}
Also used : SysUser(com.ruoyi.project.system.domain.SysUser) PathVariable(org.springframework.web.bind.annotation.PathVariable) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TableDataInfo(com.ruoyi.framework.web.page.TableDataInfo) ISysRoleService(com.ruoyi.project.system.service.ISysRoleService) Log(com.ruoyi.framework.aspectj.lang.annotation.Log) ISysPostService(com.ruoyi.project.system.service.ISysPostService) RequestBody(org.springframework.web.bind.annotation.RequestBody) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) StringUtils(com.ruoyi.common.utils.StringUtils) PutMapping(org.springframework.web.bind.annotation.PutMapping) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) SysRole(com.ruoyi.project.system.domain.SysRole) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ISysUserService(com.ruoyi.project.system.service.ISysUserService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) BaseController(com.ruoyi.framework.web.controller.BaseController) List(java.util.List) UserConstants(com.ruoyi.common.constant.UserConstants) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) MultipartFile(org.springframework.web.multipart.MultipartFile) BusinessType(com.ruoyi.framework.aspectj.lang.enums.BusinessType) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) SysUser(com.ruoyi.project.system.domain.SysUser) SysRole(com.ruoyi.project.system.domain.SysRole) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysUserController method authRole.

/**
 * 根据用户编号获取授权角色
 */
@PreAuthorize("@ss.hasPermi('system:user:query')")
@GetMapping("/authRole/{userId}")
public AjaxResult authRole(@PathVariable("userId") Long userId) {
    AjaxResult ajax = AjaxResult.success();
    SysUser user = userService.selectUserById(userId);
    List<SysRole> roles = roleService.selectRolesByUserId(userId);
    ajax.put("user", user);
    ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
    return ajax;
}
Also used : SysUser(com.ruoyi.project.system.domain.SysUser) PathVariable(org.springframework.web.bind.annotation.PathVariable) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) TableDataInfo(com.ruoyi.framework.web.page.TableDataInfo) ISysRoleService(com.ruoyi.project.system.service.ISysRoleService) Log(com.ruoyi.framework.aspectj.lang.annotation.Log) ISysPostService(com.ruoyi.project.system.service.ISysPostService) RequestBody(org.springframework.web.bind.annotation.RequestBody) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) StringUtils(com.ruoyi.common.utils.StringUtils) PutMapping(org.springframework.web.bind.annotation.PutMapping) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) GetMapping(org.springframework.web.bind.annotation.GetMapping) SysRole(com.ruoyi.project.system.domain.SysRole) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ISysUserService(com.ruoyi.project.system.service.ISysUserService) PostMapping(org.springframework.web.bind.annotation.PostMapping) Validated(org.springframework.validation.annotation.Validated) HttpServletResponse(javax.servlet.http.HttpServletResponse) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) BaseController(com.ruoyi.framework.web.controller.BaseController) List(java.util.List) UserConstants(com.ruoyi.common.constant.UserConstants) ExcelUtil(com.ruoyi.common.utils.poi.ExcelUtil) MultipartFile(org.springframework.web.multipart.MultipartFile) BusinessType(com.ruoyi.framework.aspectj.lang.enums.BusinessType) AjaxResult(com.ruoyi.framework.web.domain.AjaxResult) SysUser(com.ruoyi.project.system.domain.SysUser) SysRole(com.ruoyi.project.system.domain.SysRole) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-Oracle by yangzongzhuan.

the class SysUserServiceImpl method checkUserDataScope.

/**
 * 校验用户是否有数据权限
 *
 * @param userId 用户id
 */
@Override
public void checkUserDataScope(Long userId) {
    if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
        SysUser user = new SysUser();
        user.setUserId(userId);
        List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user);
        if (StringUtils.isEmpty(users)) {
            throw new ServiceException("没有权限访问用户数据!");
        }
    }
}
Also used : SysUser(com.ruoyi.project.system.domain.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Aggregations

SysUser (com.ruoyi.project.system.domain.SysUser)24 AjaxResult (com.ruoyi.framework.web.domain.AjaxResult)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 Log (com.ruoyi.framework.aspectj.lang.annotation.Log)6 PutMapping (org.springframework.web.bind.annotation.PutMapping)6 UserConstants (com.ruoyi.common.constant.UserConstants)4 ServiceException (com.ruoyi.common.exception.ServiceException)4 SecurityUtils (com.ruoyi.common.utils.SecurityUtils)4 StringUtils (com.ruoyi.common.utils.StringUtils)4 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)4 BusinessType (com.ruoyi.framework.aspectj.lang.enums.BusinessType)4 LoginUser (com.ruoyi.framework.security.LoginUser)4 BaseController (com.ruoyi.framework.web.controller.BaseController)4 TableDataInfo (com.ruoyi.framework.web.page.TableDataInfo)4 SysRole (com.ruoyi.project.system.domain.SysRole)4 ISysPostService (com.ruoyi.project.system.service.ISysPostService)4 ISysRoleService (com.ruoyi.project.system.service.ISysRoleService)4 ISysUserService (com.ruoyi.project.system.service.ISysUserService)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4