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);
}
}
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);
}
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);
});
}
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);
}
Aggregations