use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class LocalStorageServiceImpl method upload.
@Override
public int upload(String name, MultipartFile multipartFile) {
// 检查大小
// 获取后缀
String suffix = FileUtils.getExtensionName(multipartFile.getOriginalFilename());
String type = FileUtils.getFileType(suffix);
File file = FileUtils.upload(multipartFile, DimpleBlogConfig.getProfile() + type + File.separator);
if (Objects.isNull(file)) {
throw new CustomException("上传失败");
}
// 防止异常出错
try {
name = StringUtils.isBlank(name) ? FileUtils.getFileNameNoExtension(multipartFile.getOriginalFilename()) : name;
LocalStorage localStorage = new LocalStorage(file.getName(), name, suffix, file.getPath(), type, FileUtils.getSizeString(multipartFile.getSize()));
localStorage.setCreateBy(SecurityUtils.getUsername());
return localStorageMapper.insertLocalStorage(localStorage);
} catch (Exception e) {
FileUtils.del(file);
throw e;
}
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class QiNiuServiceImpl method synchronize.
@Override
@Transactional
public int synchronize() {
QiNiuConfig qiNiuConfig = getQiNiuConfig();
if (!qiNiuConfig.check()) {
throw new CustomException("七牛云配置信息不完整,请先填写七牛云配置信息");
}
// 构造一个带指定Zone对象的配置类
Configuration cfg = new Configuration(QiNiuUtils.getRegion(qiNiuConfig.getZone()));
Auth auth = Auth.create(qiNiuConfig.getAccessKey(), qiNiuConfig.getSecretKey());
BucketManager bucketManager = new BucketManager(auth, cfg);
// 文件名前缀
String prefix = "";
// 每次迭代的长度限制,最大1000,推荐值 1000
int limit = 1000;
// 指定目录分隔符,列出所有公共前缀(模拟列出目录效果)。缺省值为空字符串
String delimiter = "";
// 列举空间文件列表
BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(qiNiuConfig.getBucket(), prefix, limit, delimiter);
int count = 0;
while (fileListIterator.hasNext()) {
// 处理获取的file list结果
QiNiuContent qiNiuContent;
// 删除所有数据
qiNiuContentMapper.clearContent();
FileInfo[] items = fileListIterator.next();
if (Objects.nonNull(items)) {
String username = SecurityUtils.getUsername();
for (FileInfo item : items) {
qiNiuContent = new QiNiuContent();
qiNiuContent.setSize(FileUtils.getSizeString(Integer.parseInt(item.fsize + "")));
qiNiuContent.setSuffix(FileUtils.getExtensionName(item.key));
qiNiuContent.setName(FileUtils.getFileNameNoExtension(item.key));
qiNiuContent.setType(qiNiuConfig.getType());
qiNiuContent.setBucket(qiNiuConfig.getBucket());
qiNiuContent.setUrl("http://" + qiNiuConfig.getHost() + "/" + item.key);
qiNiuContent.setCreateBy(username);
qiNiuContent.setCreateTime(convertUnixTime(item.putTime + ""));
count += qiNiuContentMapper.insertContent(qiNiuContent);
}
}
}
return count;
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class QuartzJobServiceImpl method executeQuartzJobById.
@Override
public void executeQuartzJobById(Long id) {
QuartzJob quartzJob = quartzJobMapper.selectQuartzJobById(id);
if (Objects.isNull(quartzJob)) {
throw new CustomException("当前任务不存在");
}
quartzManage.runAJobNow(quartzJob);
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class QuartzManage method deleteJob.
/**
* 删除一个job
*/
public void deleteJob(QuartzJob quartzJob) {
try {
JobKey jobKey = JobKey.jobKey(JOB_NAME + quartzJob.getId());
scheduler.pauseJob(jobKey);
scheduler.deleteJob(jobKey);
} catch (Exception e) {
log.error("删除定时任务失败", e);
throw new CustomException("删除定时任务失败");
}
}
use of com.dimple.common.exception.CustomException in project DimpleBlog by martin-chips.
the class QuartzManage method addJob.
/**
* 添加任务
*
* @param quartzJob
*/
public void addJob(QuartzJob quartzJob) {
try {
log.info("开始创建任务{}", quartzJob.getJobName());
// 构建job信息
JobDetail jobDetail = JobBuilder.newJob(ExecutionJob.class).withIdentity(JOB_NAME + quartzJob.getId()).build();
// 通过触发器名和cron 表达式创建 Trigger
Trigger cronTrigger = newTrigger().withIdentity(JOB_NAME + quartzJob.getId()).startNow().withSchedule(CronScheduleBuilder.cronSchedule(quartzJob.getCronExpression())).build();
cronTrigger.getJobDataMap().put(QuartzJob.JOB_KEY, quartzJob);
// 重置启动时间
((CronTriggerImpl) cronTrigger).setStartTime(new Date());
// 执行定时任务
scheduler.scheduleJob(jobDetail, cronTrigger);
// 暂停任务
if (!quartzJob.getStatus().booleanValue()) {
pauseJob(quartzJob);
}
} catch (Exception e) {
log.error("创建定时任务失败", e);
throw new CustomException("创建定时任务失败");
}
}
Aggregations