use of io.renren.common.exception.RRException in project mall by wangxl-git.
the class ScheduleUtils method createScheduleJob.
/**
* 创建定时任务
*/
public static void createScheduleJob(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
// 构建job信息
JobDetail jobDetail = JobBuilder.newJob(ScheduleJob.class).withIdentity(getJobKey(scheduleJob.getJobId())).build();
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCronExpression()).withMisfireHandlingInstructionDoNothing();
// 按新的cronExpression表达式构建一个新的trigger
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(scheduleJob.getJobId())).withSchedule(scheduleBuilder).build();
// 放入参数,运行时的方法可以获取
jobDetail.getJobDataMap().put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
scheduler.scheduleJob(jobDetail, trigger);
// 暂停任务
if (scheduleJob.getStatus() == Constant.ScheduleStatus.PAUSE.getValue()) {
pauseJob(scheduler, scheduleJob.getJobId());
}
} catch (SchedulerException e) {
throw new RRException("创建定时任务失败", e);
}
}
use of io.renren.common.exception.RRException in project mall by wangxl-git.
the class ScheduleUtils method run.
/**
* 立即执行任务
*/
public static void run(Scheduler scheduler, ScheduleJobEntity scheduleJob) {
try {
// 参数
JobDataMap dataMap = new JobDataMap();
dataMap.put(ScheduleJobEntity.JOB_PARAM_KEY, scheduleJob);
scheduler.triggerJob(getJobKey(scheduleJob.getJobId()), dataMap);
} catch (SchedulerException e) {
throw new RRException("立即执行定时任务失败", e);
}
}
use of io.renren.common.exception.RRException in project mall by wangxl-git.
the class QcloudCloudStorageService method upload.
@Override
public String upload(byte[] data, String path) {
// 腾讯云必需要以"/"开头
if (!path.startsWith("/")) {
path = "/" + path;
}
// 上传到腾讯云
UploadFileRequest request = new UploadFileRequest(config.getQcloudBucketName(), path, data);
String response = client.uploadFile(request);
JSONObject jsonObject = JSONObject.parseObject(response);
if (jsonObject.getInteger("code") != 0) {
throw new RRException("文件上传失败," + jsonObject.getString("message"));
}
return config.getQcloudDomain() + path;
}
use of io.renren.common.exception.RRException in project mall by wangxl-git.
the class SysOssController method upload.
/**
* 上传文件
*/
@PostMapping("/upload")
@RequiresPermissions("sys:oss:all")
public R upload(@RequestParam("file") MultipartFile file) throws Exception {
if (file.isEmpty()) {
throw new RRException("上传文件不能为空");
}
// 上传文件
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String url = OSSFactory.build().uploadSuffix(file.getBytes(), suffix);
// 保存文件信息
SysOssEntity ossEntity = new SysOssEntity();
ossEntity.setUrl(url);
ossEntity.setCreateDate(new Date());
sysOssService.save(ossEntity);
return R.ok().put("url", url);
}
use of io.renren.common.exception.RRException in project mall by wangxl-git.
the class SysCaptchaServiceImpl method getCaptcha.
@Override
public BufferedImage getCaptcha(String uuid) {
if (StringUtils.isBlank(uuid)) {
throw new RRException("uuid不能为空");
}
// 生成文字验证码
String code = producer.createText();
SysCaptchaEntity captchaEntity = new SysCaptchaEntity();
captchaEntity.setUuid(uuid);
captchaEntity.setCode(code);
// 5分钟后过期
captchaEntity.setExpireTime(DateUtils.addDateMinutes(new Date(), 5));
this.save(captchaEntity);
return producer.createImage(code);
}
Aggregations