Search in sources :

Example 6 with CustomException

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("更新定时任务失败");
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) CronTrigger(org.quartz.CronTrigger) CronScheduleBuilder(org.quartz.CronScheduleBuilder) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) CustomException(com.dimple.common.exception.CustomException) Date(java.util.Date) CustomException(com.dimple.common.exception.CustomException)

Example 7 with 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);
}
Also used : Config(com.dimple.project.system.domain.Config) CustomException(com.dimple.common.exception.CustomException) CacheExpire(com.dimple.framework.config.redis.CacheExpire) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 8 with CustomException

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);
}
Also used : CustomException(com.dimple.common.exception.CustomException) Link(com.dimple.project.system.domain.Link)

Example 9 with CustomException

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);
}
Also used : Role(com.dimple.project.system.domain.Role) CustomException(com.dimple.common.exception.CustomException)

Example 10 with CustomException

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);
}
Also used : LocalStorage(com.dimple.project.tool.domain.LocalStorage) CustomException(com.dimple.common.exception.CustomException)

Aggregations

CustomException (com.dimple.common.exception.CustomException)19 QiNiuConfig (com.dimple.project.common.domain.QiNiuConfig)4 QiNiuContent (com.dimple.project.tool.domain.QiNiuContent)4 Auth (com.qiniu.util.Auth)4 CronTrigger (org.quartz.CronTrigger)4 JobKey (org.quartz.JobKey)4 QuartzJob (com.dimple.project.tool.domain.QuartzJob)3 Configuration (com.qiniu.storage.Configuration)3 Date (java.util.Date)3 TriggerKey (org.quartz.TriggerKey)3 LocalStorage (com.dimple.project.tool.domain.LocalStorage)2 QiniuException (com.qiniu.common.QiniuException)2 BucketManager (com.qiniu.storage.BucketManager)2 CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)2 CaptchaException (com.dimple.common.exception.user.CaptchaException)1 CaptchaExpireException (com.dimple.common.exception.user.CaptchaExpireException)1 UserPasswordNotMatchException (com.dimple.common.exception.user.UserPasswordNotMatchException)1 CacheExpire (com.dimple.framework.config.redis.CacheExpire)1 LoginUser (com.dimple.framework.security.LoginUser)1 Config (com.dimple.project.system.domain.Config)1