use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class QuartzManage method updateJobCron.
/**
* 更新job cron表达式
*/
public void updateJobCron(QuartzJob quartzJob) {
try {
TriggerKey triggerKey = TriggerKey.triggerKey(JOB_NAME + quartzJob.getId());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 如果不存在则创建一个定时任务
if (trigger == null) {
addJob(quartzJob);
trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
}
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression());
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
// 重置启动时间
((CronTriggerImpl) trigger).setStartTime(new Date());
trigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
scheduler.rescheduleJob(triggerKey, trigger);
// 暂停任务
if (!quartzJob.getStatus().booleanValue()) {
pauseJob(quartzJob);
}
} catch (Exception e) {
log.error("更新定时任务失败", e);
throw new CustomException("更新定时任务失败");
}
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class ConfigServiceImpl method selectConfigByConfigKey.
@Override
@Cacheable(value = CacheConstants.CACHE_NAME_BACKEND_CONFIG, key = "#key")
@CacheExpire(expire = 5, type = TimeType.HOURS)
public <T> T selectConfigByConfigKey(String key, Class<T> tClass) {
Config config = new Config();
config.setConfigKey(key);
Config retConfig = configMapper.selectConfig(config);
if (retConfig == null) {
throw new CustomException("Can not get config by key " + key);
}
return JSON.parseObject(retConfig.getConfigValue(), tClass);
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class LinkServiceImpl method handleLinkPass.
@Override
public int handleLinkPass(Long id, Boolean pass) {
Link link = selectLinkById(id);
if (Objects.isNull(link)) {
throw new CustomException("友链不存在");
}
if (!pass) {
// todo 发送email
return linkMapper.deleteLinkById(id, SecurityUtils.getUsername());
}
link.setStatus(true);
return linkMapper.updateLink(link);
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class RoleServiceImpl method deleteRoleByIds.
@Override
public int deleteRoleByIds(String ids) {
Long[] roleIds = ConvertUtils.toLongArray(ids);
for (Long roleId : roleIds) {
checkRoleAllowed(new Role(roleId));
Role role = selectRoleById(roleId);
if (countUserRoleByRoleId(roleId) > 0) {
throw new CustomException(String.format("%1$s已分配,不能删除", role.getRoleName()));
}
}
String loginUsername = SecurityUtils.getUsername();
return roleMapper.deleteRoleByIds(roleIds, loginUsername);
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class LocalStorageServiceImpl method deleteLocalStorage.
@Override
public int deleteLocalStorage(Long id) {
String username = SecurityUtils.getUsername();
LocalStorage localStorage = localStorageMapper.selectLocalStorageById(id);
if (Objects.isNull(localStorage)) {
throw new CustomException("文件不存在");
}
// 删除文件
String path = localStorage.getPath();
FileUtils.del(path);
return localStorageMapper.deleteLocalStorageById(id, username);
}
Aggregations