Search in sources :

Example 31 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue by yangzongzhuan.

the class SysUserServiceImpl method checkPhoneUnique.

/**
 * 校验手机号码是否唯一
 *
 * @param user 用户信息
 * @return
 */
@Override
public String checkPhoneUnique(SysUser user) {
    Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
    SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
    if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser)

Example 32 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue by yangzongzhuan.

the class SysUserServiceImpl method deleteUserByIds.

/**
 * 批量删除用户信息
 *
 * @param userIds 需要删除的用户ID
 * @return 结果
 */
@Override
@Transactional
public int deleteUserByIds(Long[] userIds) {
    for (Long userId : userIds) {
        checkUserAllowed(new SysUser(userId));
        checkUserDataScope(userId);
    }
    // 删除用户与角色关联
    userRoleMapper.deleteUserRole(userIds);
    // 删除用户与岗位关联
    userPostMapper.deleteUserPost(userIds);
    return userMapper.deleteUserByIds(userIds);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue 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.common.core.domain.entity.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 34 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue 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.common.core.domain.AjaxResult) SysUser(com.ruoyi.common.core.domain.entity.SysUser) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 35 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project RuoYi-Vue 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.common.core.domain.entity.SysUser) LoginUser(com.ruoyi.common.core.domain.model.LoginUser) Log(com.ruoyi.common.annotation.Log) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Aggregations

SysUser (com.ruoyi.common.core.domain.entity.SysUser)78 Log (com.ruoyi.common.annotation.Log)16 SysRole (com.ruoyi.common.core.domain.entity.SysRole)13 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)10 ServiceException (com.ruoyi.common.exception.ServiceException)10 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)8 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)8 Transactional (org.springframework.transaction.annotation.Transactional)8 UserConstants (com.ruoyi.common.constant.UserConstants)7 BaseController (com.ruoyi.common.core.controller.BaseController)7 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)7 BusinessType (com.ruoyi.common.enums.BusinessType)7 StringUtils (com.ruoyi.common.utils.StringUtils)7 ISysPostService (com.ruoyi.system.service.ISysPostService)7 ISysRoleService (com.ruoyi.system.service.ISysRoleService)7 ISysUserService (com.ruoyi.system.service.ISysUserService)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7