Search in sources :

Example 21 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class UserServiceImpl method addUser.

@Override
public void addUser(SysUser vo) {
    SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, vo.getUsername()));
    if (sysUserOne != null) {
        throw new BusinessException("用户已存在,请勿重复添加!");
    }
    vo.setSalt(PasswordUtils.getSalt());
    String encode = PasswordUtils.encode(vo.getPassword(), vo.getSalt());
    vo.setPassword(encode);
    vo.setStatus(1);
    vo.setCreateWhere(1);
    sysUserMapper.insert(vo);
    if (!CollectionUtils.isEmpty(vo.getRoleIds())) {
        UserRoleOperationReqVO reqVO = new UserRoleOperationReqVO();
        reqVO.setUserId(vo.getId());
        reqVO.setRoleIds(vo.getRoleIds());
        userRoleService.addUserRoleInfo(reqVO);
    }
}
Also used : UserRoleOperationReqVO(com.company.project.vo.req.UserRoleOperationReqVO) BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser)

Example 22 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class UserServiceImpl method register.

@Override
public void register(SysUser sysUser) {
    SysUser sysUserOne = sysUserMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, sysUser.getUsername()));
    if (sysUserOne != null) {
        throw new BusinessException("用户名已存在!");
    }
    sysUser.setSalt(PasswordUtils.getSalt());
    String encode = PasswordUtils.encode(sysUser.getPassword(), sysUser.getSalt());
    sysUser.setPassword(encode);
    sysUserMapper.insert(sysUser);
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SysUser(com.company.project.entity.SysUser)

Example 23 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class CustomRealm method doGetAuthorizationInfo.

/**
 * 执行授权逻辑
 */
@Override
@SuppressWarnings("unchecked")
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
    String sessionInfoStr = redisDb.get(userTokenPrefix + principalCollection.getPrimaryPrincipal());
    if (StringUtils.isEmpty(sessionInfoStr)) {
        throw new BusinessException(BaseResponseCode.TOKEN_ERROR);
    }
    JSONObject redisSession = JSON.parseObject(sessionInfoStr);
    if (redisSession == null) {
        throw new BusinessException(BaseResponseCode.TOKEN_ERROR);
    }
    if (redisSession.get(Constant.ROLES_KEY) != null) {
        authorizationInfo.addRoles((Collection<String>) redisSession.get(Constant.ROLES_KEY));
    }
    if (redisSession.get(Constant.PERMISSIONS_KEY) != null) {
        authorizationInfo.addStringPermissions((Collection<String>) redisSession.get(Constant.PERMISSIONS_KEY));
    }
    return authorizationInfo;
}
Also used : BusinessException(com.company.project.common.exception.BusinessException) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) JSONObject(com.alibaba.fastjson.JSONObject)

Example 24 with BusinessException

use of com.company.project.common.exception.BusinessException in project springboot-manager by aitangbao.

the class ScheduleUtils method updateScheduleJob.

/**
 * 更新定时任务
 */
public static void updateScheduleJob(Scheduler scheduler, SysJobEntity scheduleJob) {
    try {
        TriggerKey triggerKey = getTriggerKey(scheduleJob.getId());
        // 表达式调度构建器
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()).withMisfireHandlingInstructionDoNothing();
        CronTrigger trigger = getCronTrigger(scheduler, scheduleJob.getId());
        // 按新的cronExpression表达式重新构建trigger
        trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
        // 参数
        trigger.getJobDataMap().put(SysJobEntity.JOB_PARAM_KEY, scheduleJob);
        scheduler.rescheduleJob(triggerKey, trigger);
        // 暂停任务
        if (Constant.SCHEDULER_STATUS_PAUSE.equals(scheduleJob.getStatus())) {
            pauseJob(scheduler, scheduleJob.getId());
        }
    } catch (SchedulerException e) {
        throw new BusinessException("更新定时任务失败");
    }
}
Also used : BusinessException(com.company.project.common.exception.BusinessException)

Aggregations

BusinessException (com.company.project.common.exception.BusinessException)24 SysUser (com.company.project.entity.SysUser)7 SysDept (com.company.project.entity.SysDept)5 SysPermission (com.company.project.entity.SysPermission)3 SysRolePermission (com.company.project.entity.SysRolePermission)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SysRole (com.company.project.entity.SysRole)2 DeptRespNodeVO (com.company.project.vo.resp.DeptRespNodeVO)2 IOException (java.io.IOException)2 JSONObject (com.alibaba.fastjson.JSONObject)1 LogAnnotation (com.company.project.common.aop.annotation.LogAnnotation)1 ColumnEntity (com.company.project.entity.ColumnEntity)1 SysDictDetailEntity (com.company.project.entity.SysDictDetailEntity)1 SysDictEntity (com.company.project.entity.SysDictEntity)1 SysFilesEntity (com.company.project.entity.SysFilesEntity)1 SysJobEntity (com.company.project.entity.SysJobEntity)1 SysRoleDeptEntity (com.company.project.entity.SysRoleDeptEntity)1 TableEntity (com.company.project.entity.TableEntity)1 RolePermissionOperationReqVO (com.company.project.vo.req.RolePermissionOperationReqVO)1 UserRoleOperationReqVO (com.company.project.vo.req.UserRoleOperationReqVO)1