Search in sources :

Example 1 with SysJobEntity

use of com.jun.plugin.system.entity.SysJobEntity in project jun_springboot_api_service by wujun728.

the class ScheduleJob method executeInternal.

@Override
protected void executeInternal(JobExecutionContext context) {
    SysJobEntity scheduleJob = (SysJobEntity) context.getMergedJobDataMap().get(SysJobEntity.JOB_PARAM_KEY);
    // 获取spring bean
    SysJobLogService scheduleJobLogService = (SysJobLogService) SpringContextUtils.getBean("sysJobLogService");
    // 数据库保存执行记录
    SysJobLogEntity log = new SysJobLogEntity();
    log.setJobId(scheduleJob.getId());
    log.setBeanName(scheduleJob.getBeanName());
    log.setParams(scheduleJob.getParams());
    // 任务开始时间
    long startTime = System.currentTimeMillis();
    try {
        // 执行任务
        logger.debug("任务准备执行,任务ID:" + scheduleJob.getId());
        Object target = SpringContextUtils.getBean(scheduleJob.getBeanName());
        assert target != null;
        Method method = target.getClass().getDeclaredMethod("run", String.class);
        method.invoke(target, scheduleJob.getParams());
        // 任务执行总时长
        long times = System.currentTimeMillis() - startTime;
        log.setTimes((int) times);
        // 任务状态    0:成功    1:失败
        log.setStatus(0);
        logger.debug("任务执行完毕,任务ID:" + scheduleJob.getId() + "  总共耗时:" + times + "毫秒");
    } catch (Exception e) {
        logger.error("任务执行失败,任务ID:" + scheduleJob.getId(), e);
        // 任务执行总时长
        long times = System.currentTimeMillis() - startTime;
        log.setTimes((int) times);
        // 任务状态    0:成功    1:失败
        log.setStatus(1);
        log.setError(StringUtils.substring(e.toString(), 0, 2000));
    } finally {
        assert scheduleJobLogService != null;
        scheduleJobLogService.save(log);
    }
}
Also used : SysJobLogService(com.jun.plugin.system.service.SysJobLogService) SysJobLogEntity(com.jun.plugin.system.entity.SysJobLogEntity) Method(java.lang.reflect.Method) SysJobEntity(com.jun.plugin.system.entity.SysJobEntity)

Example 2 with SysJobEntity

use of com.jun.plugin.system.entity.SysJobEntity in project jun_springboot_api_service by wujun728.

the class SysJobServiceImpl method updateJobById.

@Override
public void updateJobById(SysJobEntity sysJob) {
    SysJobEntity sysJobEntity = this.getById(sysJob.getId());
    if (sysJobEntity == null) {
        throw new BusinessException("获取定时任务异常");
    }
    sysJob.setStatus(sysJobEntity.getStatus());
    ScheduleUtils.updateScheduleJob(scheduler, sysJob);
    this.updateById(sysJob);
}
Also used : BusinessException(com.jun.plugin.system.common.exception.BusinessException) SysJobEntity(com.jun.plugin.system.entity.SysJobEntity)

Example 3 with SysJobEntity

use of com.jun.plugin.system.entity.SysJobEntity in project jun_springboot_api_service by wujun728.

the class SysJobServiceImpl method updateBatch.

@Override
public void updateBatch(List<String> ids, int status) {
    ids.parallelStream().forEach(id -> {
        SysJobEntity sysJobEntity = new SysJobEntity();
        sysJobEntity.setId(id);
        sysJobEntity.setStatus(status);
        baseMapper.updateById(sysJobEntity);
    });
}
Also used : SysJobEntity(com.jun.plugin.system.entity.SysJobEntity)

Example 4 with SysJobEntity

use of com.jun.plugin.system.entity.SysJobEntity in project jun_springboot_api_service by wujun728.

the class SysJobController method findListByPage.

@ApiOperation(value = "查询分页数据")
@PostMapping("/listByPage")
@RequiresPermissions("sysJob:list")
public DataResult findListByPage(@RequestBody SysJobEntity sysJob) {
    Page page = new Page(sysJob.getPage(), sysJob.getLimit());
    LambdaQueryWrapper<SysJobEntity> queryWrapper = Wrappers.lambdaQuery();
    // 查询条件示例
    if (!StringUtils.isEmpty(sysJob.getBeanName())) {
        queryWrapper.like(SysJobEntity::getBeanName, sysJob.getBeanName());
    }
    IPage<SysJobEntity> iPage = sysJobService.page(page, queryWrapper);
    return DataResult.success(iPage);
}
Also used : Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SysJobEntity(com.jun.plugin.system.entity.SysJobEntity) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

SysJobEntity (com.jun.plugin.system.entity.SysJobEntity)4 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BusinessException (com.jun.plugin.system.common.exception.BusinessException)1 SysJobLogEntity (com.jun.plugin.system.entity.SysJobLogEntity)1 SysJobLogService (com.jun.plugin.system.service.SysJobLogService)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Method (java.lang.reflect.Method)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1