Merge branch 'leng_dev' into wx

This commit is contained in:
冷冷 committed 2019-03-28 21:12:54 +08:00
commit 1535eec2e9
10 files changed
+74 -97

No files matched your search

@@ -76,9 +76,6 @@ mybatis-plus:
field-strategy: 1
# 默认数据库表下划线命名
table-underline: true
configuration:
map-underscore-to-camel-case: true
#swagger公共信息
swagger:
@@ -9,7 +9,7 @@ security:
ignore-urls:
- /actuator/**
- /v2/api-docs
- /innerjob/**
- /inner-job/**
# 数据源配置
spring:
@@ -154,8 +154,8 @@
`user`.update_time AS uupdate_time,
`user`.del_flag AS udel_flag,
`user`.lock_flag AS lock_flag,
`user`.dept_id AS deptId,
`user`.tenant_id AS tenantId
`user`.tenant_id AS tenantId,
d.name AS deptName
FROM
sys_user AS `user`
LEFT JOIN sys_dept AS d ON d.dept_id = `user`.dept_id
@@ -49,8 +49,8 @@ import static com.pig4cloud.pigx.daemon.quartz.constant.enums.PigxQuartzEnum.*;
*/
@RestController
@AllArgsConstructor
@RequestMapping("/sysjob")
@Api(value = "sysjob", description = "定时任务")
@RequestMapping("/sys-job")
@Api(value = "sys-job", description = "定时任务")
public class SysJobController {
private final SysJobService sysJobService;
private final SysJobLogService sysJobLogService;
@@ -75,13 +75,13 @@ public class SysJobController {
/**
* 通过id查询定时任务
*
* @param jobId id
* @param id id
* @return R
*/
@GetMapping("/{jobId}")
@GetMapping("/{id}")
@ApiOperation(value = "唯一标识查询定时任务")
public R getById(@PathVariable("jobId") Integer jobId) {
return R.builder().data(sysJobService.getById(jobId)).build();
public R getById(@PathVariable("id") Integer id) {
return R.builder().data(sysJobService.getById(id)).build();
}
/**
@@ -92,7 +92,7 @@ public class SysJobController {
*/
@SysLog("新增定时任务")
@PostMapping
@PreAuthorize("@pms.hasPermission('job_sysjob_add')")
@PreAuthorize("@pms.hasPermission('job_sys_job_add')")
@ApiOperation(value = "新增定时任务")
public R save(@RequestBody SysJob sysJob) {
sysJob.setJobStatus(JOB_STATUS_RELEASE.getType());
@@ -109,7 +109,7 @@ public class SysJobController {
*/
@SysLog("修改定时任务")
@PutMapping
@PreAuthorize("@pms.hasPermission('job_sysjob_edit')")
@PreAuthorize("@pms.hasPermission('job_sys_job_edit')")
@ApiOperation(value = "修改定时任务")
public R updateById(@RequestBody SysJob sysJob) {
sysJob.setUpdateBy(SecurityUtils.getUser().getUsername());
@@ -130,8 +130,8 @@ public class SysJobController {
* @return R
*/
@SysLog("删除定时任务")
@DeleteMapping("/{jobId}")
@PreAuthorize("@pms.hasPermission('job_sysjob_del')")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('job_sys_job_del')")
@ApiOperation(value = "唯一标识查询定时任务,暂停任务才能删除")
public R removeById(@PathVariable Integer jobId) {
SysJob querySysJob = this.sysJobService.getById(jobId);
@@ -150,8 +150,8 @@ public class SysJobController {
* @return
*/
@SysLog("暂停全部定时任务")
@PostMapping("/shutdownJobs")
@PreAuthorize("@pms.hasPermission('job_sysjob_shutdownJobs')")
@PostMapping("/shutdown-jobs")
@PreAuthorize("@pms.hasPermission('job_sys_job_shutdown_job')")
@ApiOperation(value = "暂停全部定时任务")
public R shutdownJobs() {
taskUtil.pauseJobs(scheduler);
@@ -174,8 +174,8 @@ public class SysJobController {
* @return
*/
@SysLog("启动全部定时任务")
@PostMapping("/startJobs")
@PreAuthorize("@pms.hasPermission('job_sysjob_startJob')")
@PostMapping("/start-jobs")
@PreAuthorize("@pms.hasPermission('job_sys_job_start_job')")
@ApiOperation(value = "启动全部定时任务")
public R startJobs() {
//更新定时任务状态条件,暂停状态3更新为运行状态2
@@ -192,8 +192,8 @@ public class SysJobController {
* @return
*/
@SysLog("刷新全部定时任务")
@PostMapping("/refreshJobs")
@PreAuthorize("@pms.hasPermission('job_sysjob_refreshJobs')")
@PostMapping("/refresh-jobs")
@PreAuthorize("@pms.hasPermission('job_sys_job_refresh_job')")
@ApiOperation(value = "刷新全部定时任务")
public R refreshJobs() {
sysJobService.list().forEach((sysjob) -> {
@@ -217,10 +217,10 @@ public class SysJobController {
* @return
*/
@SysLog("启动定时任务")
@GetMapping("/startJob/{jobId}")
@PreAuthorize("@pms.hasPermission('job_sysjob_startJob')")
@PostMapping("/start-job/{id}")
@PreAuthorize("@pms.hasPermission('job_sys_job_start_job')")
@ApiOperation(value = "启动定时任务")
public R startJob(@PathVariable("jobId") Integer jobId) {
public R startJob(@PathVariable("id") Integer jobId) {
SysJob querySysJob = this.sysJobService.getById(jobId);
if (querySysJob != null && JOB_LOG_STATUS_FAIL.getType()
.equals(querySysJob.getJobStatus())) {
@@ -240,11 +240,11 @@ public class SysJobController {
* @return
*/
@SysLog("暂停定时任务")
@GetMapping("/shutdownJob/{jobId}")
@PreAuthorize("@pms.hasPermission('job_sysjob_shutdownJob')")
@PostMapping("/shutdown-job/{id}")
@PreAuthorize("@pms.hasPermission('job_sys_job_shutdown_job')")
@ApiOperation(value = "暂停定时任务")
public R shutdownJob(@PathVariable("jobId") Integer jobId) {
SysJob querySysJob = this.sysJobService.getById(jobId);
public R shutdownJob(@PathVariable("id") Integer id) {
SysJob querySysJob = this.sysJobService.getById(id);
//更新定时任务状态条件,运行状态2更新为暂停状态3
this.sysJobService.updateById(SysJob.builder().jobId(querySysJob.getJobId())
.jobStatus(JOB_STATUS_NOT_RUNNING.getType()).build());
@@ -257,30 +257,18 @@ public class SysJobController {
*
* @return
*/
@GetMapping("/getJobLog")
@GetMapping("/job-log")
@ApiOperation(value = "唯一标识查询定时执行日志")
public R getJobLog(Page page, SysJobLog sysJobLog) {
return R.builder().data(sysJobLogService.page(page, Wrappers.query(sysJobLog))).build();
}
/**
* 判断cron表达式是否正确
*
* @return
*/
@PostMapping("/isValidCron")
@ApiOperation(value = "判断cron是否正确")
public R isValidCron(@RequestParam String cronExpression) {
return R.builder().data(this.taskUtil.isValidCron(cronExpression)
? CommonConstants.SUCCESS : CommonConstants.FAIL).build();
}
/**
* 检验任务名称和任务组联合是否唯一
*
* @return
*/
@PostMapping("/isValidTaskName")
@GetMapping("/is-valid-task-name")
@ApiOperation(value = "检验任务名称和任务组联合是否唯一")
public R isValidTaskName(@RequestParam String jobName, @RequestParam String jobGroup) {
return R.builder().data(this.sysJobService
@@ -38,8 +38,8 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@AllArgsConstructor
@RequestMapping("/sysjoblog")
@Api(value = "sysjoblog", description = "定时任务日志")
@RequestMapping("/sys-job-log")
@Api(value = "sys-job-log", description = "定时任务日志")
public class SysJobLogController {
private final SysJobLogService sysJobLogService;
@@ -117,15 +117,15 @@ public class SysJob extends Model<SysJob> {
/**
* 首次执行时间
*/
private LocalDateTime starttime;
private LocalDateTime startTime;
/**
* 上次执行时间
*/
private LocalDateTime previoustime;
private LocalDateTime previousTime;
/**
* 下次执行时间
*/
private LocalDateTime nexttime;
private LocalDateTime nextTime;
/**
* 租户id
*/
@@ -1,39 +0,0 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.daemon.quartz.task;
import com.pig4cloud.pigx.daemon.quartz.constant.enums.PigxQuartzEnum;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Date;
/**
* @author 郑健楠
*/
@Slf4j
@Component("demo1")
public class Demo1 {
@SneakyThrows
public String demoMethod(String para) {
log.info("demo1测试于:{},输入参数L{}", new Date(), para);
return PigxQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
}
}
@@ -0,0 +1,30 @@
package com.pig4cloud.pigx.daemon.quartz.task;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
/**
* 用于测试REST风格调用的demo
*
* @author lishangbu
* @date 2019/3/25
*/
@Slf4j
@RestController
@RequestMapping("/inner-job")
public class RestTaskDemo {
/**
* 测试REST风格调用定时任务的演示方法
*/
@GetMapping("/{param}")
public R demoMethod(@PathVariable("param") String param) {
log.info("测试于:{},传入参数{}", LocalDateTime.now(), param);
return R.builder().build();
}
}
@@ -17,24 +17,25 @@
package com.pig4cloud.pigx.daemon.quartz.task;
import cn.hutool.core.date.DateUtil;
import com.pig4cloud.pigx.daemon.quartz.constant.enums.PigxQuartzEnum;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* @author 郑健楠
*/
@Slf4j
@Component("demo")
public class Demo {
public class SpringBeanTaskDemo {
/**
*
* 测试Spring Bean的演示方法
*/
@SneakyThrows
public String demoMethod(String para) {
log.info("郑健楠测试于:{},输入参数L{}", DateUtil.now(), para);
log.info("测试于:{},输入参数{}", LocalDateTime.now(), para);
return PigxQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType();
}
}
@@ -110,9 +110,9 @@ public class TaskInvokUtil {
sysJobLog.setExecuteTime(String.valueOf(endTime - startTime));
//任务表信息更新
updateSysjob.setJobExecuteStatus(PigxQuartzEnum.JOB_LOG_STATUS_SUCCESS.getType());
updateSysjob.setStarttime(trigger.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setPrevioustime(trigger.getPreviousFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setNexttime(trigger.getNextFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setStartTime(trigger.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setPreviousTime(trigger.getPreviousFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setNextTime(trigger.getNextFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
} catch (Throwable e) {
//获取执行结束时间
endTime = System.currentTimeMillis();
@@ -123,9 +123,9 @@ public class TaskInvokUtil {
sysJobLog.setExceptionInfo(StrUtil.sub(e.getMessage(), 0, 2000));
//任务表信息更新
updateSysjob.setJobExecuteStatus(PigxQuartzEnum.JOB_LOG_STATUS_FAIL.getType());
updateSysjob.setStarttime(trigger.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setPrevioustime(trigger.getPreviousFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setNexttime(trigger.getNextFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setStartTime(trigger.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setPreviousTime(trigger.getPreviousFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
updateSysjob.setNextTime(trigger.getNextFireTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
} finally {
publisher.publishEvent(new SysJobLogEvent(sysJobLog));
sysJobService.updateById(updateSysjob);