parent
1294a2cd98
commit
703bcede57
@ -0,0 +1,41 @@ |
|||||||
|
package com.psdc.entity.request; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Component |
||||||
|
public class PsdcTimerRequest { |
||||||
|
|
||||||
|
/** 定时控制任务主键 */ |
||||||
|
private Integer timerId ; |
||||||
|
/** 设备id */ |
||||||
|
private Integer deviceId ; |
||||||
|
/** 用户id */ |
||||||
|
private Long userId ; |
||||||
|
/** 执行日期 */ |
||||||
|
private String runday ; |
||||||
|
/** 执行时间 */ |
||||||
|
private String runtime ; |
||||||
|
/** 执行指令 */ |
||||||
|
private String controlKey ; |
||||||
|
/** 指令描述 */ |
||||||
|
private String controlContext ; |
||||||
|
|
||||||
|
/** 状态:1-开启,2-暂停 */ |
||||||
|
private Integer timerStatus ; |
||||||
|
/** |
||||||
|
* 创建时间开始时间 |
||||||
|
*/ |
||||||
|
private String createStart; |
||||||
|
/** |
||||||
|
* 创建时间结束时间 |
||||||
|
*/ |
||||||
|
private String createEnd; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
package com.psdc.entity.request; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
public class PsdcTimerRunTimeRequest { |
||||||
|
|
||||||
|
/** |
||||||
|
* 设备id |
||||||
|
*/ |
||||||
|
private Integer deviceId; |
||||||
|
|
||||||
|
/** |
||||||
|
* 控制键 |
||||||
|
*/ |
||||||
|
private String controlKey; |
||||||
|
|
||||||
|
/** |
||||||
|
* 控制值 |
||||||
|
*/ |
||||||
|
private String controlValue; |
||||||
|
|
||||||
|
/** |
||||||
|
* 任务状态 1开启,2关闭 |
||||||
|
*/ |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
/** 执行日期 0每天,1-7 周一 - 周日,其中0只会出现一个,周一到周日可以出现多个*/ |
||||||
|
private String runday ; |
||||||
|
|
||||||
|
/** 执行时间 */ |
||||||
|
private String runtime ; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package com.psdc.entity.vo; |
||||||
|
|
||||||
|
import com.psdc.core.domain.BaseEntity; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Component |
||||||
|
public class PsdcTimerVo extends BaseEntity { |
||||||
|
|
||||||
|
/** 定时控制任务主键 */ |
||||||
|
private Integer timerId ; |
||||||
|
/** 设备id */ |
||||||
|
private Integer deviceId ; |
||||||
|
/** 设备名称 */ |
||||||
|
private String deviceName ; |
||||||
|
/** 用户id */ |
||||||
|
private Integer userId ; |
||||||
|
/** 执行日期 */ |
||||||
|
private String runday ; |
||||||
|
/** 执行时间 */ |
||||||
|
private String runtime ; |
||||||
|
/** 执行指令 */ |
||||||
|
private String controlKey ; |
||||||
|
/** 指令描述 */ |
||||||
|
private String controlContext ; |
||||||
|
/** 指令值 */ |
||||||
|
private String controlValue ; |
||||||
|
/** cron表达式 */ |
||||||
|
private String cronText ; |
||||||
|
/** |
||||||
|
*quartz_job表id |
||||||
|
*/ |
||||||
|
private Integer jobId; |
||||||
|
/** 状态:1-开启,2-暂停 */ |
||||||
|
private Integer timerStatus ; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,23 +1,19 @@ |
|||||||
package com.psdc.quartz.controller; |
package com.psdc.controller; |
||||||
|
|
||||||
import java.util.List; |
|
||||||
import javax.servlet.http.HttpServletResponse; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.security.access.prepost.PreAuthorize; |
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping; |
|
||||||
import org.springframework.web.bind.annotation.GetMapping; |
|
||||||
import org.springframework.web.bind.annotation.PathVariable; |
|
||||||
import org.springframework.web.bind.annotation.PostMapping; |
|
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
|
||||||
import org.springframework.web.bind.annotation.RestController; |
|
||||||
import com.psdc.annotation.Log; |
import com.psdc.annotation.Log; |
||||||
import com.psdc.core.controller.BaseController; |
import com.psdc.core.controller.BaseController; |
||||||
import com.psdc.core.domain.AjaxResult; |
import com.psdc.core.domain.AjaxResult; |
||||||
import com.psdc.core.page.TableDataInfo; |
import com.psdc.core.page.TableDataInfo; |
||||||
|
import com.psdc.domain.SysJobLog; |
||||||
import com.psdc.enums.BusinessType; |
import com.psdc.enums.BusinessType; |
||||||
|
import com.psdc.service.ISysJobLogService; |
||||||
import com.psdc.utils.poi.ExcelUtil; |
import com.psdc.utils.poi.ExcelUtil; |
||||||
import com.psdc.quartz.domain.SysJobLog; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import com.psdc.quartz.service.ISysJobLogService; |
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
/** |
/** |
||||||
* 调度日志操作处理 |
* 调度日志操作处理 |
@ -1,22 +1,22 @@ |
|||||||
package com.psdc.quartz.domain; |
package com.psdc.domain; |
||||||
|
|
||||||
import java.util.Date; |
|
||||||
import javax.validation.constraints.NotBlank; |
|
||||||
import javax.validation.constraints.Size; |
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle; |
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat; |
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
import com.psdc.annotation.Excel; |
import com.psdc.annotation.Excel; |
||||||
import com.psdc.annotation.Excel.ColumnType; |
import com.psdc.annotation.Excel.ColumnType; |
||||||
import com.psdc.constant.ScheduleConstants; |
import com.psdc.constant.ScheduleConstants; |
||||||
import com.psdc.core.domain.BaseEntity; |
import com.psdc.core.domain.BaseEntity; |
||||||
|
import com.psdc.util.CronUtils; |
||||||
import com.psdc.utils.StringUtils; |
import com.psdc.utils.StringUtils; |
||||||
import com.psdc.quartz.util.CronUtils; |
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import javax.validation.constraints.Size; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务调度表 sys_job |
* 定时任务调度表 sys_job |
||||||
* |
* |
||||||
* @author ruoyi |
|
||||||
*/ |
*/ |
||||||
public class SysJob extends BaseEntity |
public class SysJob extends BaseEntity |
||||||
{ |
{ |
@ -1,15 +1,15 @@ |
|||||||
package com.psdc.quartz.domain; |
package com.psdc.domain; |
||||||
|
|
||||||
import java.util.Date; |
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder; |
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle; |
|
||||||
import com.psdc.annotation.Excel; |
import com.psdc.annotation.Excel; |
||||||
import com.psdc.core.domain.BaseEntity; |
import com.psdc.core.domain.BaseEntity; |
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务调度日志表 sys_job_log |
* 定时任务调度日志表 sys_job_log |
||||||
* |
* |
||||||
* @author ruoyi |
|
||||||
*/ |
*/ |
||||||
public class SysJobLog extends BaseEntity |
public class SysJobLog extends BaseEntity |
||||||
{ |
{ |
@ -1,13 +1,16 @@ |
|||||||
package com.psdc.quartz.mapper; |
package com.psdc.mapper; |
||||||
|
|
||||||
|
import com.psdc.domain.SysJobLog; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
|
||||||
import java.util.List; |
import java.util.List; |
||||||
import com.psdc.quartz.domain.SysJobLog; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 调度任务日志信息 数据层 |
* 调度任务日志信息 数据层 |
||||||
* |
* |
||||||
* @author ruoyi |
|
||||||
*/ |
*/ |
||||||
|
|
||||||
|
@Mapper |
||||||
public interface SysJobLogMapper |
public interface SysJobLogMapper |
||||||
{ |
{ |
||||||
/** |
/** |
@ -1,12 +1,12 @@ |
|||||||
package com.psdc.quartz.service; |
package com.psdc.service; |
||||||
|
|
||||||
|
import com.psdc.domain.SysJobLog; |
||||||
|
|
||||||
import java.util.List; |
import java.util.List; |
||||||
import com.psdc.quartz.domain.SysJobLog; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务调度日志信息信息 服务层 |
* 定时任务调度日志信息信息 服务层 |
||||||
* |
* |
||||||
* @author ruoyi |
|
||||||
*/ |
*/ |
||||||
public interface ISysJobLogService |
public interface ISysJobLogService |
||||||
{ |
{ |
@ -1,16 +1,16 @@ |
|||||||
package com.psdc.quartz.service.impl; |
package com.psdc.service.impl; |
||||||
|
|
||||||
import java.util.List; |
import com.psdc.domain.SysJobLog; |
||||||
|
import com.psdc.mapper.SysJobLogMapper; |
||||||
|
import com.psdc.service.ISysJobLogService; |
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
||||||
import com.psdc.quartz.domain.SysJobLog; |
|
||||||
import com.psdc.quartz.mapper.SysJobLogMapper; |
import java.util.List; |
||||||
import com.psdc.quartz.service.ISysJobLogService; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务调度日志信息 服务层 |
* 定时任务调度日志信息 服务层 |
||||||
* |
* |
||||||
* @author ruoyi |
|
||||||
*/ |
*/ |
||||||
@Service |
@Service |
||||||
public class SysJobLogServiceImpl implements ISysJobLogService |
public class SysJobLogServiceImpl implements ISysJobLogService |
@ -1,7 +1,7 @@ |
|||||||
package com.psdc.quartz.task; |
package com.psdc.task; |
||||||
|
|
||||||
import org.springframework.stereotype.Component; |
|
||||||
import com.psdc.utils.StringUtils; |
import com.psdc.utils.StringUtils; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务调度测试 |
* 定时任务调度测试 |
@ -1,20 +1,21 @@ |
|||||||
package com.psdc.quartz.util; |
package com.psdc.util; |
||||||
|
|
||||||
import java.util.Date; |
|
||||||
import org.quartz.Job; |
|
||||||
import org.quartz.JobExecutionContext; |
|
||||||
import org.quartz.JobExecutionException; |
|
||||||
import org.slf4j.Logger; |
|
||||||
import org.slf4j.LoggerFactory; |
|
||||||
import com.psdc.constant.Constants; |
import com.psdc.constant.Constants; |
||||||
import com.psdc.constant.ScheduleConstants; |
import com.psdc.constant.ScheduleConstants; |
||||||
|
import com.psdc.domain.SysJob; |
||||||
|
import com.psdc.domain.SysJobLog; |
||||||
|
import com.psdc.service.ISysJobLogService; |
||||||
import com.psdc.utils.ExceptionUtil; |
import com.psdc.utils.ExceptionUtil; |
||||||
import com.psdc.utils.StringUtils; |
import com.psdc.utils.StringUtils; |
||||||
import com.psdc.utils.bean.BeanUtils; |
import com.psdc.utils.bean.BeanUtils; |
||||||
import com.psdc.utils.spring.SpringUtils; |
import com.psdc.utils.spring.SpringUtils; |
||||||
import com.psdc.quartz.domain.SysJob; |
import org.quartz.Job; |
||||||
import com.psdc.quartz.domain.SysJobLog; |
import org.quartz.JobExecutionContext; |
||||||
import com.psdc.quartz.service.ISysJobLogService; |
import org.quartz.JobExecutionException; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
/** |
/** |
||||||
* 抽象quartz调用 |
* 抽象quartz调用 |
@ -1,8 +1,9 @@ |
|||||||
package com.psdc.quartz.util; |
package com.psdc.util; |
||||||
|
|
||||||
|
import org.quartz.CronExpression; |
||||||
|
|
||||||
import java.text.ParseException; |
import java.text.ParseException; |
||||||
import java.util.Date; |
import java.util.Date; |
||||||
import org.quartz.CronExpression; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* cron表达式工具类 |
* cron表达式工具类 |
@ -1,12 +1,13 @@ |
|||||||
package com.psdc.quartz.util; |
package com.psdc.util; |
||||||
|
|
||||||
|
import com.psdc.domain.SysJob; |
||||||
|
import com.psdc.utils.StringUtils; |
||||||
|
import com.psdc.utils.spring.SpringUtils; |
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException; |
import java.lang.reflect.InvocationTargetException; |
||||||
import java.lang.reflect.Method; |
import java.lang.reflect.Method; |
||||||
import java.util.LinkedList; |
import java.util.LinkedList; |
||||||
import java.util.List; |
import java.util.List; |
||||||
import com.psdc.utils.StringUtils; |
|
||||||
import com.psdc.utils.spring.SpringUtils; |
|
||||||
import com.psdc.quartz.domain.SysJob; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 任务执行工具 |
* 任务执行工具 |
@ -1,8 +1,8 @@ |
|||||||
package com.psdc.quartz.util; |
package com.psdc.util; |
||||||
|
|
||||||
|
import com.psdc.domain.SysJob; |
||||||
import org.quartz.DisallowConcurrentExecution; |
import org.quartz.DisallowConcurrentExecution; |
||||||
import org.quartz.JobExecutionContext; |
import org.quartz.JobExecutionContext; |
||||||
import com.psdc.quartz.domain.SysJob; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务处理(禁止并发执行) |
* 定时任务处理(禁止并发执行) |
@ -1,7 +1,7 @@ |
|||||||
package com.psdc.quartz.util; |
package com.psdc.util; |
||||||
|
|
||||||
|
import com.psdc.domain.SysJob; |
||||||
import org.quartz.JobExecutionContext; |
import org.quartz.JobExecutionContext; |
||||||
import com.psdc.quartz.domain.SysJob; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务处理(允许并发执行) |
* 定时任务处理(允许并发执行) |
@ -1,22 +1,13 @@ |
|||||||
package com.psdc.quartz.util; |
package com.psdc.util; |
||||||
|
|
||||||
import org.quartz.CronScheduleBuilder; |
|
||||||
import org.quartz.CronTrigger; |
|
||||||
import org.quartz.Job; |
|
||||||
import org.quartz.JobBuilder; |
|
||||||
import org.quartz.JobDetail; |
|
||||||
import org.quartz.JobKey; |
|
||||||
import org.quartz.Scheduler; |
|
||||||
import org.quartz.SchedulerException; |
|
||||||
import org.quartz.TriggerBuilder; |
|
||||||
import org.quartz.TriggerKey; |
|
||||||
import com.psdc.constant.Constants; |
import com.psdc.constant.Constants; |
||||||
import com.psdc.constant.ScheduleConstants; |
import com.psdc.constant.ScheduleConstants; |
||||||
import com.psdc.exception.job.TaskException; |
import com.psdc.exception.job.TaskException; |
||||||
import com.psdc.exception.job.TaskException.Code; |
import com.psdc.exception.job.TaskException.Code; |
||||||
|
import com.psdc.domain.SysJob; |
||||||
import com.psdc.utils.StringUtils; |
import com.psdc.utils.StringUtils; |
||||||
import com.psdc.utils.spring.SpringUtils; |
import com.psdc.utils.spring.SpringUtils; |
||||||
import com.psdc.quartz.domain.SysJob; |
import org.quartz.*; |
||||||
|
|
||||||
/** |
/** |
||||||
* 定时任务工具类 |
* 定时任务工具类 |
@ -1,14 +1,102 @@ |
|||||||
package com.psdc.controller.control; |
package com.psdc.controller.control; |
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject; |
||||||
|
import com.psdc.core.controller.BaseController; |
||||||
|
import com.psdc.core.domain.AjaxResult; |
||||||
|
import com.psdc.core.page.TableDataInfo; |
||||||
|
import com.psdc.entity.PsdcControlLog; |
||||||
|
import com.psdc.entity.request.PsdcTimerRequest; |
||||||
|
import com.psdc.entity.request.PsdcTimerRunTimeRequest; |
||||||
|
import com.psdc.entity.vo.PsdcTimerVo; |
||||||
|
import com.psdc.service.IPsdcTimerService; |
||||||
import lombok.extern.slf4j.Slf4j; |
import lombok.extern.slf4j.Slf4j; |
||||||
import org.springframework.web.bind.annotation.RequestMapping; |
import org.aspectj.weaver.loadtime.Aj; |
||||||
import org.springframework.web.bind.annotation.RestController; |
import org.quartz.SchedulerException; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
@RestController |
@RestController |
||||||
@Slf4j |
@Slf4j |
||||||
@RequestMapping("/control/timer") |
@RequestMapping("/control/timer") |
||||||
public class TimerControl { |
public class TimerControl extends BaseController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IPsdcTimerService psdcTimerService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取定时任务列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('control:timer:list')") |
||||||
|
@PostMapping("/list") |
||||||
|
public TableDataInfo timerList(@RequestBody JSONObject jsonObject) { |
||||||
|
PsdcTimerRequest psdcTimerRequest = myPage(jsonObject, PsdcTimerRequest.class); |
||||||
|
List<PsdcTimerVo> query = psdcTimerService.query(psdcTimerRequest); |
||||||
|
return getDataTable(query); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取定时任务详情 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('control:timer:info')") |
||||||
|
@GetMapping("/queryTimer/{timerId}") |
||||||
|
public AjaxResult queryTimer(@PathVariable(value = "timerId") Integer timerId) { |
||||||
|
return AjaxResult.success(psdcTimerService.queryById(timerId)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增定时任务 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('control:timer:add')") |
||||||
|
@PostMapping("/addTimer") |
||||||
|
public AjaxResult addTimer(@RequestBody PsdcTimerRunTimeRequest psdcTimerRunTimeRequest) { |
||||||
|
Integer i = psdcTimerService.addTimer(psdcTimerRunTimeRequest); |
||||||
|
if (i == 1){ |
||||||
|
return AjaxResult.success("创建任务成功"); |
||||||
|
} else { |
||||||
|
return AjaxResult.error("创建任务失败,请联系管理员"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改定时任务状态 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('control:timer:update')") |
||||||
|
@GetMapping("/updateStatus/{timerId}/{status}") |
||||||
|
public AjaxResult updateStatus(@PathVariable(value = "timerId")Integer timerId,@PathVariable(value = "status") Integer status) throws SchedulerException { |
||||||
|
int i = psdcTimerService.updateStatus(timerId,status); |
||||||
|
if (i == 1){ |
||||||
|
return AjaxResult.success("修改任务状态成功"); |
||||||
|
} else { |
||||||
|
return AjaxResult.error("修改任务状态失败,请联系管理员"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 更新定时任务 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('control:timer:update')") |
||||||
|
@PostMapping("/update") |
||||||
|
public TableDataInfo updateTimer() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除定时任务 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('control:timer:delete')") |
||||||
|
@GetMapping("/deleteTimer/{timerId}") |
||||||
|
public AjaxResult deleteTimer(@PathVariable(value = "timerId") Integer timerId) throws SchedulerException { |
||||||
|
int i = psdcTimerService.delete(timerId); |
||||||
|
if (i == 1){ |
||||||
|
return AjaxResult.success("删除定时任务成功"); |
||||||
|
} else { |
||||||
|
return AjaxResult.error("删除定时任务失败,请联系管理员"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue