Search in sources :

Example 1 with RRException

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);
    }
}
Also used : RRException(io.renren.common.exception.RRException)

Example 2 with RRException

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);
    }
}
Also used : RRException(io.renren.common.exception.RRException)

Example 3 with RRException

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;
}
Also used : UploadFileRequest(com.qcloud.cos.request.UploadFileRequest) JSONObject(com.alibaba.fastjson.JSONObject) RRException(io.renren.common.exception.RRException)

Example 4 with RRException

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);
}
Also used : RRException(io.renren.common.exception.RRException) SysOssEntity(io.renren.modules.oss.entity.SysOssEntity) Date(java.util.Date) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions)

Example 5 with RRException

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);
}
Also used : SysCaptchaEntity(io.renren.modules.sys.entity.SysCaptchaEntity) RRException(io.renren.common.exception.RRException) Date(java.util.Date)

Aggregations

RRException (io.renren.common.exception.RRException)10 Date (java.util.Date)2 JSONObject (com.alibaba.fastjson.JSONObject)1 UploadFileRequest (com.qcloud.cos.request.UploadFileRequest)1 Claims (io.jsonwebtoken.Claims)1 Login (io.renren.modules.app.annotation.Login)1 UserEntity (io.renren.modules.app.entity.UserEntity)1 SysOssEntity (io.renren.modules.oss.entity.SysOssEntity)1 SysCaptchaEntity (io.renren.modules.sys.entity.SysCaptchaEntity)1 SysMenuEntity (io.renren.modules.sys.entity.SysMenuEntity)1 MessageDigest (java.security.MessageDigest)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1