Search in sources :

Example 16 with SysUser

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

the class SysUserServiceImpl method importUser.

/**
 * 导入用户数据
 *
 * @param userList 用户数据列表
 * @param isUpdateSupport 是否更新支持,如果已存在,则进行更新数据
 * @param operName 操作用户
 * @return 结果
 */
@Override
public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName) {
    if (StringUtils.isNull(userList) || userList.size() == 0) {
        throw new ServiceException("导入用户数据不能为空!");
    }
    int successNum = 0;
    int failureNum = 0;
    StringBuilder successMsg = new StringBuilder();
    StringBuilder failureMsg = new StringBuilder();
    String password = configService.selectConfigByKey("sys.user.initPassword");
    for (SysUser user : userList) {
        try {
            // 验证是否存在这个用户
            SysUser u = userMapper.selectUserByUserName(user.getUserName());
            if (StringUtils.isNull(u)) {
                BeanValidators.validateWithException(validator, user);
                user.setPassword(SecurityUtils.encryptPassword(password));
                user.setCreateBy(operName);
                this.insertUser(user);
                successNum++;
                successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
            } else if (isUpdateSupport) {
                BeanValidators.validateWithException(validator, user);
                user.setUpdateBy(operName);
                this.updateUser(user);
                successNum++;
                successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
            } else {
                failureNum++;
                failureMsg.append("<br/>" + failureNum + "、账号 " + user.getUserName() + " 已存在");
            }
        } catch (Exception e) {
            failureNum++;
            String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败:";
            failureMsg.append(msg + e.getMessage());
            log.error(msg, e);
        }
    }
    if (failureNum > 0) {
        failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
        throw new ServiceException(failureMsg.toString());
    } else {
        successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
    }
    return successMsg.toString();
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysUser(com.ruoyi.project.system.domain.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 17 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-fast 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.project.system.domain.SysUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-fast 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)

Example 19 with SysUser

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

the class SysUserServiceImpl method checkEmailUnique.

/**
 * 校验email是否唯一
 *
 * @param user 用户信息
 * @return
 */
@Override
public String checkEmailUnique(SysUser user) {
    Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
    SysUser info = userMapper.checkEmailUnique(user.getEmail());
    if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue()) {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
Also used : SysUser(com.ruoyi.project.system.domain.SysUser)

Example 20 with SysUser

use of com.ruoyi.project.system.domain.SysUser in project RuoYi-Vue-Oracle 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.project.system.domain.SysUser) Transactional(org.springframework.transaction.annotation.Transactional)

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