Search in sources :

Example 26 with UacBizException

use of com.paascloud.provider.model.exceptions.UacBizException in project paascloud-master by paascloud.

the class UacUserServiceImpl method checkUserMenuList.

/**
 * 校验数据是否合法
 *
 * @param menuIdList      需要操作的菜单Id集合
 * @param authResDto      登录用户
 * @param uacUserMenuList 需要插入的记录
 */
private void checkUserMenuList(List<Long> menuIdList, LoginAuthDto authResDto, List<UacUserMenu> uacUserMenuList) {
    List<MenuVo> currentUserMenuVoList = uacMenuService.findAllMenuListByAuthResDto(authResDto);
    List<Long> currentUserMenuIdList = Lists.newArrayList();
    for (MenuVo menuVo : currentUserMenuVoList) {
        Long menuId = menuVo.getId();
        if (PublicUtil.isEmpty(menuId)) {
            continue;
        }
        currentUserMenuIdList.add(menuId);
    }
    Preconditions.checkArgument(currentUserMenuIdList.containsAll(menuIdList), "参数异常");
    // TODO 预留一个过滤已失效菜单的接口
    for (Long menuId : menuIdList) {
        if (uacMenuService.checkMenuHasChildMenu(menuId)) {
            logger.error(" 选择菜单不是根目录 menuId= {}", menuId);
            throw new UacBizException(ErrorCodeEnum.UAC10013010, menuId);
        }
        UacUserMenu uacUserMenu = new UacUserMenu();
        uacUserMenu.setUserId(authResDto.getUserId());
        uacUserMenu.setMenuId(menuId);
        uacUserMenuList.add(uacUserMenu);
    }
}
Also used : MenuVo(com.paascloud.provider.model.vo.MenuVo) UacBizException(com.paascloud.provider.model.exceptions.UacBizException)

Example 27 with UacBizException

use of com.paascloud.provider.model.exceptions.UacBizException in project paascloud-master by paascloud.

the class EmailServiceImpl method submitResetPwdEmail.

@Override
public void submitResetPwdEmail(String email) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(email), ErrorCodeEnum.UAC10011018.msg());
    // 获取用户名
    UacUser uacUser = new UacUser();
    uacUser.setEmail(email);
    uacUser = uacUserService.selectOne(uacUser);
    if (uacUser == null) {
        throw new UacBizException(ErrorCodeEnum.UAC10011004, email);
    }
    String resetPwdKey = PubUtils.uuid() + UniqueIdGenerator.generateId();
    redisTemplate.opsForValue().set(RedisKeyUtil.getResetPwdTokenKey(resetPwdKey), uacUser, 7 * 24, TimeUnit.HOURS);
    Map<String, Object> param = Maps.newHashMap();
    param.put("loginName", uacUser.getLoginName());
    param.put("email", email);
    param.put("resetPwdUrl", resetPwdUrl + resetPwdKey);
    param.put("dateTime", DateUtil.formatDateTime(new Date()));
    Set<String> to = Sets.newHashSet();
    to.add(email);
    MqMessageData messageData = emailProducer.sendEmailMq(to, UacEmailTemplateEnum.RESET_PWD_SEND_MAIL, AliyunMqTopicConstants.MqTagEnum.FORGOT_PASSWORD_AUTH_CODE, param);
    userManager.submitResetPwdEmail(messageData);
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) UacBizException(com.paascloud.provider.model.exceptions.UacBizException) Date(java.util.Date)

Example 28 with UacBizException

use of com.paascloud.provider.model.exceptions.UacBizException in project paascloud-master by paascloud.

the class EmailServiceImpl method sendEmailCode.

@Override
public void sendEmailCode(SendEmailMessage sendEmailMessage, String loginName) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(loginName), "用户名不能为空");
    String email = sendEmailMessage.getEmail();
    Preconditions.checkArgument(StringUtils.isNotEmpty(email), ErrorCodeEnum.UAC10011018.msg());
    Preconditions.checkArgument(StringUtils.isNotEmpty(loginName), ErrorCodeEnum.UAC10011007.msg());
    // 解密
    email = decryptEmail(loginName, email);
    Example example = new Example(UacUser.class);
    Example.Criteria criteria = example.createCriteria();
    criteria.andEqualTo("email", email);
    criteria.andNotEqualTo("loginName", loginName);
    int result = uacUserService.selectCountByExample(example);
    if (result > 0) {
        throw new UacBizException(ErrorCodeEnum.UAC10011019);
    }
    String emailCode = RandomUtil.createNumberCode(6);
    String key = RedisKeyUtil.getSendEmailCodeKey(loginName, email);
    // 在redis中绑定验证码
    redisService.setKey(key, emailCode, 7 * 24, TimeUnit.HOURS);
    // 先写死 类型多了再抽方法
    Map<String, Object> param = Maps.newHashMap();
    param.put("loginName", loginName);
    param.put("email", email);
    param.put("emailCode", emailCode);
    param.put("dateTime", DateUtil.formatDateTime(new Date()));
    Set<String> to = Sets.newHashSet();
    to.add(email);
    MqMessageData mqMessageData = emailProducer.sendEmailMq(to, UacEmailTemplateEnum.RESET_USER_EMAIL, AliyunMqTopicConstants.MqTagEnum.RESET_LOGIN_PWD, param);
    userManager.sendEmailCode(mqMessageData);
}
Also used : Example(tk.mybatis.mapper.entity.Example) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) UacBizException(com.paascloud.provider.model.exceptions.UacBizException) Date(java.util.Date)

Example 29 with UacBizException

use of com.paascloud.provider.model.exceptions.UacBizException in project paascloud-master by paascloud.

the class UacGroupServiceImpl method updateUacGroupStatusById.

@Override
public int updateUacGroupStatusById(IdStatusDto idStatusDto, LoginAuthDto loginAuthDto) {
    Long groupId = idStatusDto.getId();
    Integer status = idStatusDto.getStatus();
    UacGroup uacGroup = new UacGroup();
    uacGroup.setId(groupId);
    uacGroup.setStatus(status);
    UacGroup group = uacGroupMapper.selectByPrimaryKey(groupId);
    if (PublicUtil.isEmpty(group)) {
        throw new UacBizException(ErrorCodeEnum.UAC10015001, groupId);
    }
    if (!UacGroupStatusEnum.contains(status)) {
        throw new UacBizException(ErrorCodeEnum.UAC10015002);
    }
    // 查询所有的组织
    List<UacGroup> totalGroupList = uacGroupMapper.selectAll();
    List<GroupZtreeVo> totalList = Lists.newArrayList();
    GroupZtreeVo zTreeVo;
    for (UacGroup vo : totalGroupList) {
        zTreeVo = new GroupZtreeVo();
        zTreeVo.setId(vo.getId());
        totalList.add(zTreeVo);
    }
    UacGroupUser uacGroupUser = new UacGroupUser();
    uacGroupUser.setUserId(loginAuthDto.getUserId());
    UacGroupUser groupUser = uacGroupUserMapper.selectOne(uacGroupUser);
    // 查询当前登陆人所在的组织信息
    UacGroup currentUserUacGroup = uacGroupMapper.selectByPrimaryKey(groupUser.getGroupId());
    // 查询当前登陆人能禁用的所有子节点
    List<GroupZtreeVo> childGroupList = this.getGroupTree(currentUserUacGroup.getId());
    // 计算不能禁用的组织= 所有的组织 - 禁用的所有子节点
    totalList.removeAll(childGroupList);
    // 判断所选的组织是否在不能禁用的列表里
    GroupZtreeVo zTreeVo1 = new GroupZtreeVo();
    zTreeVo1.setId(group.getId());
    if (totalList.contains(zTreeVo1)) {
        throw new UacBizException(ErrorCodeEnum.UAC10011023);
    }
    if (groupUser.getGroupId().equals(uacGroup.getId()) && UacGroupStatusEnum.ENABLE.getStatus() == group.getStatus()) {
        throw new UacBizException(ErrorCodeEnum.UAC10011023);
    }
    uacGroup.setGroupName(group.getGroupName());
    uacGroup.setGroupCode(group.getGroupCode());
    uacGroup.setVersion(group.getVersion() + 1);
    int result = uacGroupMapper.updateByPrimaryKeySelective(uacGroup);
    // 获取当前所选组织的所有子节点
    List<GroupZtreeVo> childUacGroupList = this.getGroupTree(uacGroup.getId());
    // 批量修改组织状态
    if (PublicUtil.isNotEmpty(childUacGroupList)) {
        UacGroup childGroup;
        for (GroupZtreeVo uacGroup1 : childUacGroupList) {
            if (UacGroupStatusEnum.ENABLE.getStatus() == status) {
                UacGroup parentGroup = uacGroupMapper.selectByPrimaryKey(uacGroup1.getpId());
                if (parentGroup.getStatus() == UacGroupStatusEnum.DISABLE.getStatus()) {
                    throw new UacBizException(ErrorCodeEnum.UAC10015003);
                }
            }
            childGroup = new UacGroup();
            childGroup.setStatus(uacGroup.getStatus());
            childGroup.setId(uacGroup1.getId());
            result = uacGroupMapper.updateByPrimaryKeySelective(childGroup);
            if (result < 1) {
                throw new UacBizException(ErrorCodeEnum.UAC10015006, uacGroup1.getId());
            }
        }
    }
    return result;
}
Also used : GroupZtreeVo(com.paascloud.provider.model.vo.GroupZtreeVo) UacGroup(com.paascloud.provider.model.domain.UacGroup) UacBizException(com.paascloud.provider.model.exceptions.UacBizException) UacGroupUser(com.paascloud.provider.model.domain.UacGroupUser)

Example 30 with UacBizException

use of com.paascloud.provider.model.exceptions.UacBizException in project paascloud-master by paascloud.

the class UacGroupServiceImpl method bindUacUser4Group.

/**
 * Bind uac user 4 group int.
 *
 * @param groupBindUserReqDto the group bind user req dto
 * @param authResDto          the auth res dto
 */
@Override
public void bindUacUser4Group(GroupBindUserReqDto groupBindUserReqDto, LoginAuthDto authResDto) {
    if (groupBindUserReqDto == null) {
        logger.error("参数不能为空");
        throw new IllegalArgumentException("参数不能为空");
    }
    Long groupId = groupBindUserReqDto.getGroupId();
    Long loginUserId = authResDto.getUserId();
    List<Long> userIdList = groupBindUserReqDto.getUserIdList();
    if (null == groupId) {
        throw new IllegalArgumentException("組織ID不能为空");
    }
    UacGroup group = uacGroupMapper.selectByPrimaryKey(groupId);
    if (group == null) {
        logger.error("找不到角色信息 groupId={}", groupId);
        throw new UacBizException(ErrorCodeEnum.UAC10015001, groupId);
    }
    if (PublicUtil.isNotEmpty(userIdList) && userIdList.contains(loginUserId)) {
        logger.error("不能操作当前登录用户 userId={}", loginUserId);
        throw new UacBizException(ErrorCodeEnum.UAC10011023);
    }
    // 查询超级管理员用户Id集合
    List<Long> superUserList = uacRoleUserMapper.listSuperUser(GlobalConstant.Sys.SUPER_MANAGER_ROLE_ID);
    List<Long> unionList = Collections3.intersection(userIdList, superUserList);
    if (PublicUtil.isNotEmpty(userIdList) && PublicUtil.isNotEmpty(unionList)) {
        logger.error("不能操作超级管理员用户 超级用户={}", unionList);
        throw new UacBizException(ErrorCodeEnum.UAC10011023);
    }
    // 1. 先取消对该角色的用户绑定(不包含超级管理员用户)
    List<UacGroupUser> groupUsers = uacGroupUserMapper.listByGroupId(groupId);
    if (PublicUtil.isNotEmpty(groupUsers)) {
        uacGroupUserMapper.deleteExcludeSuperMng(groupId, GlobalConstant.Sys.SUPER_MANAGER_ROLE_ID);
    }
    if (PublicUtil.isEmpty(userIdList)) {
        // 取消该角色的所有用户的绑定
        logger.info("取消绑定所有非超级管理员用户成功");
        return;
    }
    // 绑定所选用户
    for (Long userId : userIdList) {
        UacUser uacUser = uacUserService.queryByUserId(userId);
        if (PublicUtil.isEmpty(uacUser)) {
            logger.error("找不到绑定的用户 userId={}", userId);
            throw new UacBizException(ErrorCodeEnum.UAC10011024, userId);
        }
        UacGroupUser uacGroupUser = new UacGroupUser();
        uacGroupUser.setUserId(userId);
        uacGroupUser.setGroupId(groupId);
        uacGroupUserMapper.insertSelective(uacGroupUser);
    }
}
Also used : UacUser(com.paascloud.provider.model.domain.UacUser) UacGroup(com.paascloud.provider.model.domain.UacGroup) UacBizException(com.paascloud.provider.model.exceptions.UacBizException) UacGroupUser(com.paascloud.provider.model.domain.UacGroupUser)

Aggregations

UacBizException (com.paascloud.provider.model.exceptions.UacBizException)37 Transactional (org.springframework.transaction.annotation.Transactional)8 UacGroup (com.paascloud.provider.model.domain.UacGroup)6 UacMenu (com.paascloud.provider.model.domain.UacMenu)6 LoginAuthDto (com.paascloud.base.dto.LoginAuthDto)5 UacGroupUser (com.paascloud.provider.model.domain.UacGroupUser)5 MqMessageData (com.paascloud.provider.model.domain.MqMessageData)4 UacRoleMenu (com.paascloud.provider.model.domain.UacRoleMenu)4 UacRoleUser (com.paascloud.provider.model.domain.UacRoleUser)4 MenuVo (com.paascloud.provider.model.vo.MenuVo)4 UacRoleAction (com.paascloud.provider.model.domain.UacRoleAction)3 UacUser (com.paascloud.provider.model.domain.UacUser)3 BindAuthVo (com.paascloud.provider.model.vo.BindAuthVo)2 UserBindRoleVo (com.paascloud.provider.model.vo.UserBindRoleVo)2 ApiOperation (io.swagger.annotations.ApiOperation)2 Date (java.util.Date)2 LogAnnotation (com.paascloud.core.annotation.LogAnnotation)1 MqProducerStore (com.paascloud.provider.annotation.MqProducerStore)1 UacAction (com.paascloud.provider.model.domain.UacAction)1 UacRole (com.paascloud.provider.model.domain.UacRole)1