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);
}
}
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);
}
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;
}
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("更新定时任务失败");
}
}
Aggregations