Search in sources :

Example 26 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class ThingsModelServiceImpl method insertThingsModel.

/**
 * 新增物模型
 *
 * @param thingsModel 物模型
 * @return 结果
 */
@Override
public int insertThingsModel(ThingsModel thingsModel) {
    // 物模型标识符不能重复 TODO 重复查询待优化
    ThingsModel input = new ThingsModel();
    input.setProductId(thingsModel.getProductId());
    List<ThingsModel> list = thingsModelMapper.selectThingsModelList(input);
    Boolean isRepeat = list.stream().anyMatch(x -> x.getIdentifier().equals(thingsModel.getIdentifier()));
    if (!isRepeat) {
        SysUser user = getLoginUser().getUser();
        thingsModel.setTenantId(user.getUserId());
        thingsModel.setTenantName(user.getUserName());
        thingsModel.setCreateTime(DateUtils.getNowDate());
        int result = thingsModelMapper.insertThingsModel(thingsModel);
        // 更新redis缓存
        setCacheThingsModelByProductId(thingsModel.getProductId());
        return result;
    }
    return 2;
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ThingsModel(com.ruoyi.iot.domain.ThingsModel)

Example 27 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class SysUserServiceImpl method deleteUserByIds.

/**
 * 批量删除用户信息
 *
 * @param userIds 需要删除的用户ID
 * @return 结果
 */
@Override
@Transactional
public int deleteUserByIds(Long[] userIds) {
    for (Long userId : userIds) {
        checkUserAllowed(new SysUser(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 28 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

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)) {
                user.setPassword(SecurityUtils.encryptPassword(password));
                user.setCreateBy(operName);
                this.insertUser(user);
                successNum++;
                successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
            } else if (isUpdateSupport) {
                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.common.core.domain.entity.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 29 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

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 30 with SysUser

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

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