first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package com.dcsoft.job;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import com.dcsoft.common.security.annotation.EnableCustomConfig;
|
||||
import com.dcsoft.common.security.annotation.EnableRyFeignClients;
|
||||
import com.dcsoft.common.swagger.annotation.EnableCustomSwagger2;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableRyFeignClients
|
||||
@SpringBootApplication
|
||||
public class DCSJobApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(com.dcsoft.job.DCSJobApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ 定时任务模块启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
" .-------. ____ __ \n" +
|
||||
" | _ _ \\ \\ \\ / / \n" +
|
||||
" | ( ' ) | \\ _. / ' \n" +
|
||||
" |(_ o _) / _( )_ .' \n" +
|
||||
" | (_,_).' __ ___(_ o _)' \n" +
|
||||
" | |\\ \\ | || |(_,_)' \n" +
|
||||
" | | \\ `' /| `-' / \n" +
|
||||
" | | \\ / \\ / \n" +
|
||||
" ''-' `'-' `-..-' ");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
//package com.dcsoft.job.config;
|
||||
//
|
||||
//import java.util.Properties;
|
||||
//import javax.sql.DataSource;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.scheduling.quartz.SchedulerFactoryBean;
|
||||
//
|
||||
///**
|
||||
// * 定时任务配置(单机部署建议删除此类和qrtz数据库表,默认走内存会最高效)
|
||||
// *
|
||||
// * @author dcsoft
|
||||
// */
|
||||
//@Configuration
|
||||
//public class ScheduleConfig
|
||||
//{
|
||||
// @Bean
|
||||
// public SchedulerFactoryBean schedulerFactoryBean(DataSource dataSource)
|
||||
// {
|
||||
// SchedulerFactoryBean factory = new SchedulerFactoryBean();
|
||||
// factory.setDataSource(dataSource);
|
||||
//
|
||||
// // quartz参数
|
||||
// Properties prop = new Properties();
|
||||
// prop.put("org.quartz.scheduler.instanceName", "RuoyiScheduler");
|
||||
// prop.put("org.quartz.scheduler.instanceId", "AUTO");
|
||||
// // 线程池配置
|
||||
// prop.put("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
|
||||
// prop.put("org.quartz.threadPool.threadCount", "20");
|
||||
// prop.put("org.quartz.threadPool.threadPriority", "5");
|
||||
// // JobStore配置
|
||||
// prop.put("org.quartz.jobStore.class", "org.springframework.scheduling.quartz.LocalDataSourceJobStore");
|
||||
// // 集群配置
|
||||
// prop.put("org.quartz.jobStore.isClustered", "true");
|
||||
// prop.put("org.quartz.jobStore.clusterCheckinInterval", "15000");
|
||||
// prop.put("org.quartz.jobStore.maxMisfiresToHandleAtATime", "1");
|
||||
// prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
|
||||
//
|
||||
// // sqlserver 启用
|
||||
// // prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
|
||||
// prop.put("org.quartz.jobStore.misfireThreshold", "12000");
|
||||
// prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
|
||||
// factory.setQuartzProperties(prop);
|
||||
//
|
||||
// factory.setSchedulerName("RuoyiScheduler");
|
||||
// // 延时启动
|
||||
// factory.setStartupDelay(1);
|
||||
// factory.setApplicationContextSchedulerContextKey("applicationContextKey");
|
||||
// // 可选,QuartzScheduler
|
||||
// // 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了
|
||||
// factory.setOverwriteExistingJobs(true);
|
||||
// // 设置自动启动,默认为true
|
||||
// factory.setAutoStartup(true);
|
||||
//
|
||||
// return factory;
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,186 @@
|
||||
package com.dcsoft.job.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.dcsoft.common.core.constant.Constants;
|
||||
import com.dcsoft.common.core.exception.job.TaskException;
|
||||
import com.dcsoft.common.core.utils.StringUtils;
|
||||
import com.dcsoft.common.core.utils.poi.ExcelUtil;
|
||||
import com.dcsoft.common.core.web.controller.BaseController;
|
||||
import com.dcsoft.common.core.web.domain.AjaxResult;
|
||||
import com.dcsoft.common.core.web.page.TableDataInfo;
|
||||
import com.dcsoft.common.log.annotation.Log;
|
||||
import com.dcsoft.common.log.enums.BusinessType;
|
||||
import com.dcsoft.common.security.annotation.RequiresPermissions;
|
||||
import com.dcsoft.common.security.utils.SecurityUtils;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
import com.dcsoft.job.service.ISysJobService;
|
||||
import com.dcsoft.job.util.CronUtils;
|
||||
import com.dcsoft.job.util.ScheduleUtils;
|
||||
|
||||
/**
|
||||
* 调度任务信息操作处理
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/job")
|
||||
public class SysJobController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISysJobService jobService;
|
||||
|
||||
/**
|
||||
* 查询定时任务列表
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysJob sysJob)
|
||||
{
|
||||
startPage();
|
||||
List<SysJob> list = jobService.selectJobList(sysJob);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出定时任务列表
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:export")
|
||||
@Log(title = "定时任务", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysJob sysJob)
|
||||
{
|
||||
List<SysJob> list = jobService.selectJobList(sysJob);
|
||||
ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);
|
||||
util.exportExcel(response, list, "定时任务");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取定时任务详细信息
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:query")
|
||||
@GetMapping(value = "/{jobId}")
|
||||
public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
||||
{
|
||||
return success(jobService.selectJobById(jobId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增定时任务
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:add")
|
||||
@Log(title = "定时任务", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody SysJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
if (!CronUtils.isValid(job.getCronExpression()))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
||||
}
|
||||
else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
||||
}
|
||||
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
||||
}
|
||||
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
||||
}
|
||||
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
||||
}
|
||||
else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
||||
{
|
||||
return error("新增任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
||||
}
|
||||
job.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(jobService.insertJob(job));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改定时任务
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:edit")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody SysJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
if (!CronUtils.isValid(job.getCronExpression()))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,Cron表达式不正确");
|
||||
}
|
||||
else if (StringUtils.containsIgnoreCase(job.getInvokeTarget(), Constants.LOOKUP_RMI))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'rmi'调用");
|
||||
}
|
||||
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.LOOKUP_LDAP, Constants.LOOKUP_LDAPS }))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'ldap(s)'调用");
|
||||
}
|
||||
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), new String[] { Constants.HTTP, Constants.HTTPS }))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不允许'http(s)'调用");
|
||||
}
|
||||
else if (StringUtils.containsAnyIgnoreCase(job.getInvokeTarget(), Constants.JOB_ERROR_STR))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串存在违规");
|
||||
}
|
||||
else if (!ScheduleUtils.whiteList(job.getInvokeTarget()))
|
||||
{
|
||||
return error("修改任务'" + job.getJobName() + "'失败,目标字符串不在白名单内");
|
||||
}
|
||||
job.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(jobService.updateJob(job));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务状态修改
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:changeStatus")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody SysJob job) throws SchedulerException
|
||||
{
|
||||
SysJob newJob = jobService.selectJobById(job.getJobId());
|
||||
newJob.setStatus(job.getStatus());
|
||||
return toAjax(jobService.changeStatus(newJob));
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务立即执行一次
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:changeStatus")
|
||||
@Log(title = "定时任务", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/run")
|
||||
public AjaxResult run(@RequestBody SysJob job) throws SchedulerException
|
||||
{
|
||||
boolean result = jobService.run(job);
|
||||
return result ? success() : error("任务不存在或已过期!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:remove")
|
||||
@Log(title = "定时任务", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{jobIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] jobIds) throws SchedulerException, TaskException
|
||||
{
|
||||
jobService.deleteJobByIds(jobIds);
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.dcsoft.job.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.dcsoft.common.core.utils.poi.ExcelUtil;
|
||||
import com.dcsoft.common.core.web.controller.BaseController;
|
||||
import com.dcsoft.common.core.web.domain.AjaxResult;
|
||||
import com.dcsoft.common.core.web.page.TableDataInfo;
|
||||
import com.dcsoft.common.log.annotation.Log;
|
||||
import com.dcsoft.common.log.enums.BusinessType;
|
||||
import com.dcsoft.common.security.annotation.RequiresPermissions;
|
||||
import com.dcsoft.job.domain.SysJobLog;
|
||||
import com.dcsoft.job.service.ISysJobLogService;
|
||||
|
||||
/**
|
||||
* 调度日志操作处理
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/job/log")
|
||||
public class SysJobLogController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private ISysJobLogService jobLogService;
|
||||
|
||||
/**
|
||||
* 查询定时任务调度日志列表
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysJobLog sysJobLog)
|
||||
{
|
||||
startPage();
|
||||
List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出定时任务调度日志列表
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:export")
|
||||
@Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysJobLog sysJobLog)
|
||||
{
|
||||
List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
|
||||
ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
|
||||
util.exportExcel(response, list, "调度日志");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据调度编号获取详细信息
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:query")
|
||||
@GetMapping(value = "/{jobLogId}")
|
||||
public AjaxResult getInfo(@PathVariable Long jobLogId)
|
||||
{
|
||||
return success(jobLogService.selectJobLogById(jobLogId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除定时任务调度日志
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:remove")
|
||||
@Log(title = "定时任务调度日志", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{jobLogIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] jobLogIds)
|
||||
{
|
||||
return toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空定时任务调度日志
|
||||
*/
|
||||
@RequiresPermissions("monitor:job:remove")
|
||||
@Log(title = "调度日志", businessType = BusinessType.CLEAN)
|
||||
@DeleteMapping("/clean")
|
||||
public AjaxResult clean()
|
||||
{
|
||||
jobLogService.cleanJobLog();
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dcsoft.job.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DeviceVo {
|
||||
|
||||
private String ip;
|
||||
private String password;
|
||||
private String state;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.dcsoft.job.domain;
|
||||
|
||||
public class HolidayVo {
|
||||
private String data;//日期
|
||||
|
||||
private String status;//状态:0工作日/1周末/2法定节假日/3节假日调休补班
|
||||
|
||||
private String msg;//描述
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.dcsoft.job.domain;
|
||||
|
||||
|
||||
import com.dcsoft.common.core.annotation.Excel;
|
||||
import com.dcsoft.common.core.web.domain.BaseEntity;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 假期设置对象 kq_holiday
|
||||
*
|
||||
* @author dcsoft
|
||||
* @date 2023-01-11
|
||||
*/
|
||||
public class KqHoliday extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 假期id */
|
||||
private Long holidayId;
|
||||
|
||||
/** 假期时长 */
|
||||
@Excel(name = "假期时长")
|
||||
private Long timeStamp;
|
||||
|
||||
/** 假期时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "假期时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date time;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
private Long selectTimeStep;
|
||||
|
||||
private Long startTimeStep;
|
||||
|
||||
private Long endTimeStep;
|
||||
|
||||
private String status;
|
||||
|
||||
|
||||
|
||||
|
||||
public void setHolidayId(Long holidayId)
|
||||
{
|
||||
this.holidayId = holidayId;
|
||||
}
|
||||
|
||||
public Long getHolidayId()
|
||||
{
|
||||
return holidayId;
|
||||
}
|
||||
public void setTimeStamp(Long timeStamp)
|
||||
{
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
public Long getTimeStamp()
|
||||
{
|
||||
return timeStamp;
|
||||
}
|
||||
public void setTime(Date time)
|
||||
{
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Date getTime()
|
||||
{
|
||||
return time;
|
||||
}
|
||||
public void setDelFlag(String delFlag)
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public Long getSelectTimeStep() {
|
||||
return selectTimeStep;
|
||||
}
|
||||
|
||||
public void setSelectTimeStep(Long selectTimeStep) {
|
||||
this.selectTimeStep = selectTimeStep;
|
||||
}
|
||||
|
||||
public Long getStartTimeStep() {
|
||||
return startTimeStep;
|
||||
}
|
||||
|
||||
public void setStartTimeStep(Long startTimeStep) {
|
||||
this.startTimeStep = startTimeStep;
|
||||
}
|
||||
|
||||
public Long getEndTimeStep() {
|
||||
return endTimeStep;
|
||||
}
|
||||
|
||||
public void setEndTimeStep(Long endTimeStep) {
|
||||
this.endTimeStep = endTimeStep;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("holidayId", getHolidayId())
|
||||
.append("timeStamp", getTimeStamp())
|
||||
.append("time", getTime())
|
||||
.append("delFlag", getDelFlag())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.dcsoft.job.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.dcsoft.common.core.annotation.Excel;
|
||||
import com.dcsoft.common.core.annotation.Excel.ColumnType;
|
||||
import com.dcsoft.common.core.constant.ScheduleConstants;
|
||||
import com.dcsoft.common.core.utils.StringUtils;
|
||||
import com.dcsoft.common.core.web.domain.BaseEntity;
|
||||
import com.dcsoft.job.util.CronUtils;
|
||||
|
||||
/**
|
||||
* 定时任务调度表 sys_job
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public class SysJob extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 任务ID */
|
||||
@Excel(name = "任务序号", cellType = ColumnType.NUMERIC)
|
||||
private Long jobId;
|
||||
|
||||
/** 任务名称 */
|
||||
@Excel(name = "任务名称")
|
||||
private String jobName;
|
||||
|
||||
/** 任务组名 */
|
||||
@Excel(name = "任务组名")
|
||||
private String jobGroup;
|
||||
|
||||
/** 调用目标字符串 */
|
||||
@Excel(name = "调用目标字符串")
|
||||
private String invokeTarget;
|
||||
|
||||
/** cron执行表达式 */
|
||||
@Excel(name = "执行表达式 ")
|
||||
private String cronExpression;
|
||||
|
||||
/** cron计划策略 */
|
||||
@Excel(name = "计划策略 ", readConverterExp = "0=默认,1=立即触发执行,2=触发一次执行,3=不触发立即执行")
|
||||
private String misfirePolicy = ScheduleConstants.MISFIRE_DEFAULT;
|
||||
|
||||
/** 是否并发执行(0允许 1禁止) */
|
||||
@Excel(name = "并发执行", readConverterExp = "0=允许,1=禁止")
|
||||
private String concurrent;
|
||||
|
||||
/** 任务状态(0正常 1暂停) */
|
||||
@Excel(name = "任务状态", readConverterExp = "0=正常,1=暂停")
|
||||
private String status;
|
||||
|
||||
public Long getJobId()
|
||||
{
|
||||
return jobId;
|
||||
}
|
||||
|
||||
public void setJobId(Long jobId)
|
||||
{
|
||||
this.jobId = jobId;
|
||||
}
|
||||
|
||||
@NotBlank(message = "任务名称不能为空")
|
||||
@Size(min = 0, max = 64, message = "任务名称不能超过64个字符")
|
||||
public String getJobName()
|
||||
{
|
||||
return jobName;
|
||||
}
|
||||
|
||||
public void setJobName(String jobName)
|
||||
{
|
||||
this.jobName = jobName;
|
||||
}
|
||||
|
||||
public String getJobGroup()
|
||||
{
|
||||
return jobGroup;
|
||||
}
|
||||
|
||||
public void setJobGroup(String jobGroup)
|
||||
{
|
||||
this.jobGroup = jobGroup;
|
||||
}
|
||||
|
||||
@NotBlank(message = "调用目标字符串不能为空")
|
||||
@Size(min = 0, max = 500, message = "调用目标字符串长度不能超过500个字符")
|
||||
public String getInvokeTarget()
|
||||
{
|
||||
return invokeTarget;
|
||||
}
|
||||
|
||||
public void setInvokeTarget(String invokeTarget)
|
||||
{
|
||||
this.invokeTarget = invokeTarget;
|
||||
}
|
||||
|
||||
@NotBlank(message = "Cron执行表达式不能为空")
|
||||
@Size(min = 0, max = 255, message = "Cron执行表达式不能超过255个字符")
|
||||
public String getCronExpression()
|
||||
{
|
||||
return cronExpression;
|
||||
}
|
||||
|
||||
public void setCronExpression(String cronExpression)
|
||||
{
|
||||
this.cronExpression = cronExpression;
|
||||
}
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
public Date getNextValidTime()
|
||||
{
|
||||
if (StringUtils.isNotEmpty(cronExpression))
|
||||
{
|
||||
return CronUtils.getNextExecution(cronExpression);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMisfirePolicy()
|
||||
{
|
||||
return misfirePolicy;
|
||||
}
|
||||
|
||||
public void setMisfirePolicy(String misfirePolicy)
|
||||
{
|
||||
this.misfirePolicy = misfirePolicy;
|
||||
}
|
||||
|
||||
public String getConcurrent()
|
||||
{
|
||||
return concurrent;
|
||||
}
|
||||
|
||||
public void setConcurrent(String concurrent)
|
||||
{
|
||||
this.concurrent = concurrent;
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("jobId", getJobId())
|
||||
.append("jobName", getJobName())
|
||||
.append("jobGroup", getJobGroup())
|
||||
.append("cronExpression", getCronExpression())
|
||||
.append("nextValidTime", getNextValidTime())
|
||||
.append("misfirePolicy", getMisfirePolicy())
|
||||
.append("concurrent", getConcurrent())
|
||||
.append("status", getStatus())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.dcsoft.job.domain;
|
||||
|
||||
import java.util.Date;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.dcsoft.common.core.annotation.Excel;
|
||||
import com.dcsoft.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 定时任务调度日志表 sys_job_log
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public class SysJobLog extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** ID */
|
||||
@Excel(name = "日志序号")
|
||||
private Long jobLogId;
|
||||
|
||||
/** 任务名称 */
|
||||
@Excel(name = "任务名称")
|
||||
private String jobName;
|
||||
|
||||
/** 任务组名 */
|
||||
@Excel(name = "任务组名")
|
||||
private String jobGroup;
|
||||
|
||||
/** 调用目标字符串 */
|
||||
@Excel(name = "调用目标字符串")
|
||||
private String invokeTarget;
|
||||
|
||||
/** 日志信息 */
|
||||
@Excel(name = "日志信息")
|
||||
private String jobMessage;
|
||||
|
||||
/** 执行状态(0正常 1失败) */
|
||||
@Excel(name = "执行状态", readConverterExp = "0=正常,1=失败")
|
||||
private String status;
|
||||
|
||||
/** 异常信息 */
|
||||
@Excel(name = "异常信息")
|
||||
private String exceptionInfo;
|
||||
|
||||
/** 开始时间 */
|
||||
private Date startTime;
|
||||
|
||||
/** 停止时间 */
|
||||
private Date stopTime;
|
||||
|
||||
public Long getJobLogId()
|
||||
{
|
||||
return jobLogId;
|
||||
}
|
||||
|
||||
public void setJobLogId(Long jobLogId)
|
||||
{
|
||||
this.jobLogId = jobLogId;
|
||||
}
|
||||
|
||||
public String getJobName()
|
||||
{
|
||||
return jobName;
|
||||
}
|
||||
|
||||
public void setJobName(String jobName)
|
||||
{
|
||||
this.jobName = jobName;
|
||||
}
|
||||
|
||||
public String getJobGroup()
|
||||
{
|
||||
return jobGroup;
|
||||
}
|
||||
|
||||
public void setJobGroup(String jobGroup)
|
||||
{
|
||||
this.jobGroup = jobGroup;
|
||||
}
|
||||
|
||||
public String getInvokeTarget()
|
||||
{
|
||||
return invokeTarget;
|
||||
}
|
||||
|
||||
public void setInvokeTarget(String invokeTarget)
|
||||
{
|
||||
this.invokeTarget = invokeTarget;
|
||||
}
|
||||
|
||||
public String getJobMessage()
|
||||
{
|
||||
return jobMessage;
|
||||
}
|
||||
|
||||
public void setJobMessage(String jobMessage)
|
||||
{
|
||||
this.jobMessage = jobMessage;
|
||||
}
|
||||
|
||||
public String getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status)
|
||||
{
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getExceptionInfo()
|
||||
{
|
||||
return exceptionInfo;
|
||||
}
|
||||
|
||||
public void setExceptionInfo(String exceptionInfo)
|
||||
{
|
||||
this.exceptionInfo = exceptionInfo;
|
||||
}
|
||||
|
||||
public Date getStartTime()
|
||||
{
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(Date startTime)
|
||||
{
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public Date getStopTime()
|
||||
{
|
||||
return stopTime;
|
||||
}
|
||||
|
||||
public void setStopTime(Date stopTime)
|
||||
{
|
||||
this.stopTime = stopTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("jobLogId", getJobLogId())
|
||||
.append("jobName", getJobName())
|
||||
.append("jobGroup", getJobGroup())
|
||||
.append("jobMessage", getJobMessage())
|
||||
.append("status", getStatus())
|
||||
.append("exceptionInfo", getExceptionInfo())
|
||||
.append("startTime", getStartTime())
|
||||
.append("stopTime", getStopTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.dcsoft.job.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class VisitorVo {
|
||||
private String guid;
|
||||
private String faceGuid;
|
||||
private String userId;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.dcsoft.job.mapper;
|
||||
|
||||
|
||||
|
||||
import com.dcsoft.job.domain.KqHoliday;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 假期设置Mapper接口
|
||||
*
|
||||
* @author dcsoft
|
||||
* @date 2023-01-11
|
||||
*/
|
||||
public interface KqHolidayMapper
|
||||
{
|
||||
/**
|
||||
* 查询假期设置
|
||||
*
|
||||
* @param holidayId 假期设置主键
|
||||
* @return 假期设置
|
||||
*/
|
||||
public KqHoliday selectKqHolidayByHolidayId(Long holidayId);
|
||||
|
||||
/**
|
||||
* 查询假期设置列表
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 假期设置集合
|
||||
*/
|
||||
public List<KqHoliday> selectKqHolidayList(KqHoliday kqHoliday);
|
||||
|
||||
/**
|
||||
* 新增假期设置
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertKqHoliday(KqHoliday kqHoliday);
|
||||
|
||||
/**
|
||||
* 修改假期设置
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateKqHoliday(KqHoliday kqHoliday);
|
||||
|
||||
/**
|
||||
* 删除假期设置
|
||||
*
|
||||
* @param holidayId 假期设置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteKqHolidayByHolidayId(Long holidayId);
|
||||
|
||||
/**
|
||||
* 批量删除假期设置
|
||||
*
|
||||
* @param holidayIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteKqHolidayByHolidayIds(Long[] holidayIds);
|
||||
|
||||
public KqHoliday selectKqHolidayByHolidayTimeStamp(Long timeStamp);
|
||||
|
||||
public int deleteKqHolidayByHolidayTimeStamp(Long holidayId);
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.dcsoft.job.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dcsoft.job.domain.DeviceVo;
|
||||
import com.dcsoft.job.domain.SysJobLog;
|
||||
import com.dcsoft.job.domain.VisitorVo;
|
||||
|
||||
/**
|
||||
* 调度任务日志信息 数据层
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public interface SysJobLogMapper
|
||||
{
|
||||
/**
|
||||
* 获取quartz调度器日志的计划任务
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 调度任务日志集合
|
||||
*/
|
||||
public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
|
||||
|
||||
/**
|
||||
* 查询所有调度任务日志
|
||||
*
|
||||
* @return 调度任务日志列表
|
||||
*/
|
||||
public List<SysJobLog> selectJobLogAll();
|
||||
|
||||
/**
|
||||
* 通过调度任务日志ID查询调度信息
|
||||
*
|
||||
* @param jobLogId 调度任务日志ID
|
||||
* @return 调度任务日志对象信息
|
||||
*/
|
||||
public SysJobLog selectJobLogById(Long jobLogId);
|
||||
|
||||
/**
|
||||
* 新增任务日志
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertJobLog(SysJobLog jobLog);
|
||||
|
||||
/**
|
||||
* 批量删除调度日志信息
|
||||
*
|
||||
* @param logIds 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobLogByIds(Long[] logIds);
|
||||
|
||||
/**
|
||||
* 删除任务日志
|
||||
*
|
||||
* @param jobId 调度日志ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobLogById(Long jobId);
|
||||
|
||||
/**
|
||||
* 清空任务日志
|
||||
*/
|
||||
public void cleanJobLog();
|
||||
|
||||
List<DeviceVo> queryDevice(List<String> list);
|
||||
|
||||
/**
|
||||
* 刷新梯口设备在线离线状态
|
||||
* @param deviceVos
|
||||
*/
|
||||
void updateLadderState(List<DeviceVo> deviceVos);
|
||||
|
||||
/**
|
||||
* 查询访guid和faceGuid
|
||||
* @return
|
||||
*/
|
||||
List<VisitorVo> queryGuidAndFaceGuid();
|
||||
|
||||
String queryPointId(String userId);
|
||||
|
||||
/**
|
||||
* 查询通行设备
|
||||
* @return
|
||||
*/
|
||||
List<DeviceVo> queryDeviceInfo();
|
||||
|
||||
/**
|
||||
* 定时签离访客人员
|
||||
*/
|
||||
void updateVisitorSignOff();
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.dcsoft.job.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
|
||||
/**
|
||||
* 调度任务信息 数据层
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public interface SysJobMapper
|
||||
{
|
||||
/**
|
||||
* 查询调度任务日志集合
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 操作日志集合
|
||||
*/
|
||||
public List<SysJob> selectJobList(SysJob job);
|
||||
|
||||
/**
|
||||
* 查询所有调度任务
|
||||
*
|
||||
* @return 调度任务列表
|
||||
*/
|
||||
public List<SysJob> selectJobAll();
|
||||
|
||||
/**
|
||||
* 通过调度ID查询调度任务信息
|
||||
*
|
||||
* @param jobId 调度ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
public SysJob selectJobById(Long jobId);
|
||||
|
||||
/**
|
||||
* 通过调度ID删除调度任务信息
|
||||
*
|
||||
* @param jobId 调度ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobById(Long jobId);
|
||||
|
||||
/**
|
||||
* 批量删除调度任务信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 修改调度任务信息
|
||||
*
|
||||
* @param job 调度任务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateJob(SysJob job);
|
||||
|
||||
/**
|
||||
* 新增调度任务信息
|
||||
*
|
||||
* @param job 调度任务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertJob(SysJob job);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.dcsoft.job.service;
|
||||
|
||||
|
||||
|
||||
import com.dcsoft.job.domain.KqHoliday;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 假期设置Service接口
|
||||
*
|
||||
* @author dcsoft
|
||||
* @date 2023-01-11
|
||||
*/
|
||||
public interface IKqHolidayService
|
||||
{
|
||||
/**
|
||||
* 查询假期设置
|
||||
*
|
||||
* @param holidayId 假期设置主键
|
||||
* @return 假期设置
|
||||
*/
|
||||
public KqHoliday selectKqHolidayByHolidayId(Long holidayId);
|
||||
|
||||
/**
|
||||
* 查询假期设置列表
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 假期设置集合
|
||||
*/
|
||||
public List<KqHoliday> selectKqHolidayList(KqHoliday kqHoliday);
|
||||
|
||||
/**
|
||||
* 新增假期设置
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertKqHoliday(KqHoliday kqHoliday);
|
||||
|
||||
/**
|
||||
* 修改假期设置
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateKqHoliday(KqHoliday kqHoliday);
|
||||
|
||||
/**
|
||||
* 批量删除假期设置
|
||||
*
|
||||
* @param holidayIds 需要删除的假期设置主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteKqHolidayByHolidayIds(Long[] holidayIds);
|
||||
|
||||
/**
|
||||
* 删除假期设置信息
|
||||
*
|
||||
* @param holidayId 假期设置主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteKqHolidayByHolidayId(Long holidayId);
|
||||
|
||||
public KqHoliday selectKqHolidayByHolidayTimeStamp(Long timeStamp);
|
||||
|
||||
public int deleteKqHolidayByHolidayTimeStamp(Long timeStamp);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.dcsoft.job.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import com.dcsoft.job.domain.SysJobLog;
|
||||
|
||||
/**
|
||||
* 定时任务调度日志信息信息 服务层
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public interface ISysJobLogService
|
||||
{
|
||||
/**
|
||||
* 获取quartz调度器日志的计划任务
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 调度任务日志集合
|
||||
*/
|
||||
public List<SysJobLog> selectJobLogList(SysJobLog jobLog);
|
||||
|
||||
/**
|
||||
* 通过调度任务日志ID查询调度信息
|
||||
*
|
||||
* @param jobLogId 调度任务日志ID
|
||||
* @return 调度任务日志对象信息
|
||||
*/
|
||||
public SysJobLog selectJobLogById(Long jobLogId);
|
||||
|
||||
/**
|
||||
* 新增任务日志
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
*/
|
||||
public void addJobLog(SysJobLog jobLog);
|
||||
|
||||
/**
|
||||
* 批量删除调度日志信息
|
||||
*
|
||||
* @param logIds 需要删除的日志ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobLogByIds(Long[] logIds);
|
||||
|
||||
/**
|
||||
* 删除任务日志
|
||||
*
|
||||
* @param jobId 调度日志ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJobLogById(Long jobId);
|
||||
|
||||
/**
|
||||
* 清空任务日志
|
||||
*/
|
||||
public void cleanJobLog();
|
||||
|
||||
void setDeviceCallBackInfo(String sequence);
|
||||
|
||||
/**
|
||||
* 刷新梯口设备在线离线状态
|
||||
* @param sequence
|
||||
*/
|
||||
void updateLadderState(String sequence) throws IOException;
|
||||
|
||||
/**
|
||||
* 删除宇泛人脸设备访客结束时间的数据
|
||||
*/
|
||||
void deleteVisitorFaceDevice();
|
||||
|
||||
/**
|
||||
* 设置宇泛二维码回调地址
|
||||
*/
|
||||
void setQRCodeCallback(String sequence);
|
||||
|
||||
/**
|
||||
* 定时签离访客人员
|
||||
*/
|
||||
void updateVisitorSignOff();
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.dcsoft.job.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.quartz.SchedulerException;
|
||||
import com.dcsoft.common.core.exception.job.TaskException;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
|
||||
/**
|
||||
* 定时任务调度信息信息 服务层
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public interface ISysJobService
|
||||
{
|
||||
/**
|
||||
* 获取quartz调度器的计划任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 调度任务集合
|
||||
*/
|
||||
public List<SysJob> selectJobList(SysJob job);
|
||||
|
||||
/**
|
||||
* 通过调度任务ID查询调度信息
|
||||
*
|
||||
* @param jobId 调度任务ID
|
||||
* @return 调度任务对象信息
|
||||
*/
|
||||
public SysJob selectJobById(Long jobId);
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int pauseJob(SysJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 恢复任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int resumeJob(SysJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 删除任务后,所对应的trigger也将被删除
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteJob(SysJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 批量删除调度信息
|
||||
*
|
||||
* @param jobIds 需要删除的任务ID
|
||||
* @return 结果
|
||||
*/
|
||||
public void deleteJobByIds(Long[] jobIds) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 任务调度状态修改
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int changeStatus(SysJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 立即运行任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean run(SysJob job) throws SchedulerException;
|
||||
|
||||
/**
|
||||
* 新增任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertJob(SysJob job) throws SchedulerException, TaskException;
|
||||
|
||||
/**
|
||||
* 更新任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateJob(SysJob job) throws SchedulerException, TaskException;
|
||||
|
||||
/**
|
||||
* 校验cron表达式是否有效
|
||||
*
|
||||
* @param cronExpression 表达式
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean checkCronExpressionIsValid(String cronExpression);
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.dcsoft.job.service;
|
||||
|
||||
|
||||
import com.dcsoft.common.core.utils.DateUtils;
|
||||
|
||||
import com.dcsoft.job.domain.KqHoliday;
|
||||
import com.dcsoft.job.mapper.KqHolidayMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 假期设置Service业务层处理
|
||||
*
|
||||
* @author dcsoft
|
||||
* @date 2023-01-11
|
||||
*/
|
||||
@Service
|
||||
public class KqHolidayServiceImpl implements IKqHolidayService
|
||||
{
|
||||
@Autowired
|
||||
private KqHolidayMapper kqHolidayMapper;
|
||||
|
||||
/**
|
||||
* 查询假期设置
|
||||
*
|
||||
* @param holidayId 假期设置主键
|
||||
* @return 假期设置
|
||||
*/
|
||||
@Override
|
||||
public KqHoliday selectKqHolidayByHolidayId(Long holidayId)
|
||||
{
|
||||
return kqHolidayMapper.selectKqHolidayByHolidayId(holidayId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询假期设置列表
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 假期设置
|
||||
*/
|
||||
@Override
|
||||
public List<KqHoliday> selectKqHolidayList(KqHoliday kqHoliday)
|
||||
{
|
||||
return kqHolidayMapper.selectKqHolidayList(kqHoliday);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增假期设置
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertKqHoliday(KqHoliday kqHoliday)
|
||||
{
|
||||
kqHoliday.setCreateTime(DateUtils.getNowDate());
|
||||
return kqHolidayMapper.insertKqHoliday(kqHoliday);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改假期设置
|
||||
*
|
||||
* @param kqHoliday 假期设置
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateKqHoliday(KqHoliday kqHoliday)
|
||||
{
|
||||
kqHoliday.setUpdateTime(DateUtils.getNowDate());
|
||||
return kqHolidayMapper.updateKqHoliday(kqHoliday);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除假期设置
|
||||
*
|
||||
* @param holidayIds 需要删除的假期设置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteKqHolidayByHolidayIds(Long[] holidayIds)
|
||||
{
|
||||
return kqHolidayMapper.deleteKqHolidayByHolidayIds(holidayIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除假期设置信息
|
||||
*
|
||||
* @param holidayId 假期设置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteKqHolidayByHolidayId(Long holidayId)
|
||||
{
|
||||
return kqHolidayMapper.deleteKqHolidayByHolidayId(holidayId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KqHoliday selectKqHolidayByHolidayTimeStamp(Long timeStamp) {
|
||||
return kqHolidayMapper.selectKqHolidayByHolidayTimeStamp(timeStamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除假期设置信息
|
||||
*
|
||||
* @param timeStamp 假期设置主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteKqHolidayByHolidayTimeStamp(Long timeStamp)
|
||||
{
|
||||
return kqHolidayMapper.deleteKqHolidayByHolidayTimeStamp(timeStamp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
package com.dcsoft.job.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.*;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dcsoft.common.core.constant.Constants;
|
||||
import com.dcsoft.common.core.enums.exception.CommonExceptionEnum;
|
||||
import com.dcsoft.common.core.exception.ServiceException;
|
||||
import com.dcsoft.job.domain.DeviceVo;
|
||||
import com.dcsoft.job.domain.VisitorVo;
|
||||
import com.dcsoft.job.util.HttpUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.dcsoft.job.domain.SysJobLog;
|
||||
import com.dcsoft.job.mapper.SysJobLogMapper;
|
||||
|
||||
/**
|
||||
* 定时任务调度日志信息 服务层
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SysJobLogServiceImpl implements ISysJobLogService
|
||||
{
|
||||
@Autowired
|
||||
private SysJobLogMapper jobLogMapper;
|
||||
|
||||
/**
|
||||
* 获取quartz调度器日志的计划任务
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
* @return 调度任务日志集合
|
||||
*/
|
||||
@Override
|
||||
public List<SysJobLog> selectJobLogList(SysJobLog jobLog)
|
||||
{
|
||||
return jobLogMapper.selectJobLogList(jobLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过调度任务日志ID查询调度信息
|
||||
*
|
||||
* @param jobLogId 调度任务日志ID
|
||||
* @return 调度任务日志对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysJobLog selectJobLogById(Long jobLogId)
|
||||
{
|
||||
return jobLogMapper.selectJobLogById(jobLogId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增任务日志
|
||||
*
|
||||
* @param jobLog 调度日志信息
|
||||
*/
|
||||
@Override
|
||||
public void addJobLog(SysJobLog jobLog)
|
||||
{
|
||||
jobLogMapper.insertJobLog(jobLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除调度日志信息
|
||||
*
|
||||
* @param logIds 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteJobLogByIds(Long[] logIds)
|
||||
{
|
||||
return jobLogMapper.deleteJobLogByIds(logIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务日志
|
||||
*
|
||||
* @param jobId 调度日志ID
|
||||
*/
|
||||
@Override
|
||||
public int deleteJobLogById(Long jobId)
|
||||
{
|
||||
return jobLogMapper.deleteJobLogById(jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空任务日志
|
||||
*/
|
||||
@Override
|
||||
public void cleanJobLog()
|
||||
{
|
||||
jobLogMapper.cleanJobLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* 梯控刷卡回调接口设置
|
||||
* @param sequence
|
||||
*/
|
||||
@Override
|
||||
public void setDeviceCallBackInfo(String sequence) {
|
||||
if(StringUtils.isNotEmpty(sequence)){
|
||||
String[] split = sequence.split(",");
|
||||
List<String> list = Arrays.asList(split);
|
||||
List<DeviceVo> deviceVos = jobLogMapper.queryDevice(list);
|
||||
for (DeviceVo deviceVo : deviceVos) {
|
||||
String body = null;
|
||||
try {
|
||||
deviceVo.setIp("http://" + deviceVo.getIp() + ":8090" + "/SetDeviceCallBackInfo");
|
||||
body = setDeviceCallBackInfo(deviceVo, "http://192.168.255.52:6609/system/sdk/saveLadderRecord");
|
||||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
log.info("设置设备识别回调ip:" + deviceVo.getIp());
|
||||
log.info("设置设备识别回调返回参:" + body);
|
||||
JSONObject object = JSONObject.parseObject(body);
|
||||
if(!Constants.CODE.equals(object.get("msg"))) {
|
||||
throw new ServiceException(CommonExceptionEnum.REQUEST_ERROR.getCode(), "设置设备识别回调接口接口" +
|
||||
CommonExceptionEnum.REQUEST_ERROR.getMessage() + "设置设备识别回调接口接口异常码" + object.get("msg").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String setDeviceCallBackInfo(DeviceVo deviceVo, String url) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("callbackUrl", url);
|
||||
map.put("pass", deviceVo.getPassword());
|
||||
return HttpUtil.createPost(deviceVo.getIp()).timeout(5000).body(JSON.toJSONString(map)).execute().body();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新梯控设备在线离线状态
|
||||
* @param sequence
|
||||
*/
|
||||
@Override
|
||||
public void updateLadderState(String sequence) throws IOException {
|
||||
String[] split = sequence.split(",");
|
||||
List<String> list = Arrays.asList(split);
|
||||
List<DeviceVo> deviceVos = jobLogMapper.queryDevice(list);
|
||||
for (DeviceVo deviceVo : deviceVos) {
|
||||
InetAddress address = InetAddress.getByName(deviceVo.getIp());
|
||||
boolean isIpReachable = address.isReachable(3000);
|
||||
if(isIpReachable) {
|
||||
deviceVo.setState(Constants.ZERO);
|
||||
} else {
|
||||
deviceVo.setState(Constants.ONE);
|
||||
}
|
||||
}
|
||||
jobLogMapper.updateLadderState(deviceVos);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除宇泛人脸设备访客结束时间的数据
|
||||
*/
|
||||
@Override
|
||||
public void deleteVisitorFaceDevice() {
|
||||
List<VisitorVo> visitorVo = jobLogMapper.queryGuidAndFaceGuid();
|
||||
List<DeviceVo> list = jobLogMapper.queryDeviceInfo();
|
||||
for (VisitorVo vo : visitorVo) {
|
||||
for (DeviceVo deviceVo : list) {
|
||||
try {
|
||||
if(StringUtils.isNotEmpty(vo.getFaceGuid())) {
|
||||
// 删除照片
|
||||
imageDelete(vo.getFaceGuid(), deviceVo.getIp(), deviceVo.getPassword());
|
||||
}
|
||||
|
||||
if(StringUtils.isNotEmpty(vo.getGuid())) {
|
||||
// 删除人员
|
||||
personDelete(vo.getGuid(), deviceVo.getIp(), deviceVo.getPassword());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("删除宇泛人脸设备访客结束时间的数据:" + deviceVo.getIp() + "异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置宇泛二维码回调地址
|
||||
*/
|
||||
@Override
|
||||
public void setQRCodeCallback(String sequence) {
|
||||
List<String> list = Arrays.asList(sequence.split(","));
|
||||
List<DeviceVo> deviceVos = jobLogMapper.queryDevice(list);
|
||||
for (DeviceVo deviceVo : deviceVos) {
|
||||
String body = null;
|
||||
try {
|
||||
deviceVo.setIp("http://" + deviceVo.getIp() + ":8090/device/setQRCodeCallback");
|
||||
body = setDeviceCallBackInfo(deviceVo, "http://192.168.255.52:6609/system/sdk/backUrlEwm");
|
||||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
log.info("设置宇泛门镜设备识别回调ip:" + deviceVo.getIp());
|
||||
log.info("设置宇泛门镜设备识别回调返回参:" + body);
|
||||
JSONObject object = JSONObject.parseObject(body);
|
||||
if(!Constants.CODE.equals(object.get("msg"))) {
|
||||
throw new ServiceException(CommonExceptionEnum.REQUEST_ERROR.getCode(), "设置宇泛门镜设备识别回调接口接口" +
|
||||
CommonExceptionEnum.REQUEST_ERROR.getMessage() + "设置宇泛门镜设备识别回调接口接口异常码" + object.get("msg").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时签离访客人员
|
||||
*/
|
||||
@Override
|
||||
public void updateVisitorSignOff() {
|
||||
jobLogMapper.updateVisitorSignOff();
|
||||
}
|
||||
|
||||
private String personDelete(String id, String ip, String pass) {
|
||||
String url="http://"+ip+":8090/person/delete";
|
||||
Map<String, Object> paramMap=new HashMap<String, Object>();
|
||||
paramMap.put("pass",pass);
|
||||
paramMap.put("id",id);
|
||||
String response= HttpUtils.sendxwwwform(url,paramMap);
|
||||
return response;
|
||||
}
|
||||
|
||||
private String imageDelete(String faceId, String ip, String pass) {
|
||||
String url="http://"+ip+":8090/face/delete";
|
||||
Map<String, Object> paramMap=new HashMap<String, Object>();
|
||||
paramMap.put("pass",pass);
|
||||
paramMap.put("faceId",faceId);//可不传,设为空
|
||||
String response= HttpUtils.sendxwwwform(url,paramMap);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备信息接口
|
||||
*/
|
||||
private String getDeviceInfo(DeviceVo deviceVo) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("pass", deviceVo.getPassword());
|
||||
map.put("idcardnum", "11111111");
|
||||
return HttpUtil.createGet("http://" + deviceVo.getIp() + ":8090" + "/cardinfo/find").timeout(5000).body(JSON.toJSONString(map)).execute().body();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
package com.dcsoft.job.service;
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobKey;
|
||||
import org.quartz.Scheduler;
|
||||
import org.quartz.SchedulerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.dcsoft.common.core.constant.ScheduleConstants;
|
||||
import com.dcsoft.common.core.exception.job.TaskException;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
import com.dcsoft.job.mapper.SysJobMapper;
|
||||
import com.dcsoft.job.util.CronUtils;
|
||||
import com.dcsoft.job.util.ScheduleUtils;
|
||||
|
||||
/**
|
||||
* 定时任务调度信息 服务层
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
@Service
|
||||
public class SysJobServiceImpl implements ISysJobService
|
||||
{
|
||||
@Autowired
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Autowired
|
||||
private SysJobMapper jobMapper;
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据)
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() throws SchedulerException, TaskException
|
||||
{
|
||||
scheduler.clear();
|
||||
List<SysJob> jobList = jobMapper.selectJobAll();
|
||||
for (SysJob job : jobList)
|
||||
{
|
||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取quartz调度器的计划任务列表
|
||||
*
|
||||
* @param job 调度信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysJob> selectJobList(SysJob job)
|
||||
{
|
||||
return jobMapper.selectJobList(job);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过调度任务ID查询调度信息
|
||||
*
|
||||
* @param jobId 调度任务ID
|
||||
* @return 调度任务对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysJob selectJobById(Long jobId)
|
||||
{
|
||||
return jobMapper.selectJobById(jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int pauseJob(SysJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
||||
int rows = jobMapper.updateJob(job);
|
||||
if (rows > 0)
|
||||
{
|
||||
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int resumeJob(SysJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
job.setStatus(ScheduleConstants.Status.NORMAL.getValue());
|
||||
int rows = jobMapper.updateJob(job);
|
||||
if (rows > 0)
|
||||
{
|
||||
scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除任务后,所对应的trigger也将被删除
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteJob(SysJob job) throws SchedulerException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
int rows = jobMapper.deleteJobById(jobId);
|
||||
if (rows > 0)
|
||||
{
|
||||
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除调度信息
|
||||
*
|
||||
* @param jobIds 需要删除的任务ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobByIds(Long[] jobIds) throws SchedulerException
|
||||
{
|
||||
for (Long jobId : jobIds)
|
||||
{
|
||||
SysJob job = jobMapper.selectJobById(jobId);
|
||||
deleteJob(job);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 任务调度状态修改
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int changeStatus(SysJob job) throws SchedulerException
|
||||
{
|
||||
int rows = 0;
|
||||
String status = job.getStatus();
|
||||
if (ScheduleConstants.Status.NORMAL.getValue().equals(status))
|
||||
{
|
||||
rows = resumeJob(job);
|
||||
}
|
||||
else if (ScheduleConstants.Status.PAUSE.getValue().equals(status))
|
||||
{
|
||||
rows = pauseJob(job);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即运行任务
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean run(SysJob job) throws SchedulerException
|
||||
{
|
||||
boolean result = false;
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
SysJob properties = selectJobById(job.getJobId());
|
||||
// 参数
|
||||
JobDataMap dataMap = new JobDataMap();
|
||||
dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
|
||||
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
||||
if (scheduler.checkExists(jobKey))
|
||||
{
|
||||
result = true;
|
||||
scheduler.triggerJob(jobKey, dataMap);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增任务
|
||||
*
|
||||
* @param job 调度信息 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertJob(SysJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
|
||||
int rows = jobMapper.insertJob(job);
|
||||
if (rows > 0)
|
||||
{
|
||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务的时间表达式
|
||||
*
|
||||
* @param job 调度信息
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int updateJob(SysJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
SysJob properties = selectJobById(job.getJobId());
|
||||
int rows = jobMapper.updateJob(job);
|
||||
if (rows > 0)
|
||||
{
|
||||
updateSchedulerJob(job, properties.getJobGroup());
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务
|
||||
*
|
||||
* @param job 任务对象
|
||||
* @param jobGroup 任务组名
|
||||
*/
|
||||
public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
|
||||
{
|
||||
Long jobId = job.getJobId();
|
||||
// 判断是否存在
|
||||
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
|
||||
if (scheduler.checkExists(jobKey))
|
||||
{
|
||||
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
||||
scheduler.deleteJob(jobKey);
|
||||
}
|
||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验cron表达式是否有效
|
||||
*
|
||||
* @param cronExpression 表达式
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkCronExpressionIsValid(String cronExpression)
|
||||
{
|
||||
return CronUtils.isValid(cronExpression);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package com.dcsoft.job.task;
|
||||
|
||||
import com.dcsoft.common.core.constant.SecurityConstants;
|
||||
import com.dcsoft.job.domain.HolidayVo;
|
||||
import com.dcsoft.job.domain.KqHoliday;
|
||||
import com.dcsoft.job.service.IKqHolidayService;
|
||||
import com.dcsoft.job.service.ISysJobLogService;
|
||||
import com.dcsoft.job.util.HolidayUtil;
|
||||
import com.dcsoft.system.api.RemoteStudentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.dcsoft.common.core.utils.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 定时任务调度测试
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
@Component("ryTask")
|
||||
public class RyTask
|
||||
{
|
||||
|
||||
@Autowired
|
||||
private IKqHolidayService holidayService;
|
||||
|
||||
@Autowired
|
||||
private RemoteStudentService remoteStudentService;
|
||||
|
||||
@Autowired
|
||||
private ISysJobLogService sysJobLogService;
|
||||
|
||||
|
||||
public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
|
||||
{
|
||||
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
|
||||
}
|
||||
|
||||
public void ryParams(String params)
|
||||
{
|
||||
System.out.println("执行有参方法:" + params);
|
||||
}
|
||||
|
||||
public void ryNoParams()
|
||||
{
|
||||
System.out.println("执行无参方法");
|
||||
}
|
||||
|
||||
public void holiday()
|
||||
{
|
||||
try {
|
||||
Date date=new Date();
|
||||
SimpleDateFormat sdf1=new SimpleDateFormat("yyyy");
|
||||
ArrayList<HolidayVo> list=HolidayUtil.getAllHolidayByYear(sdf1.format(date));
|
||||
for(HolidayVo h:list){
|
||||
if(!"0".equals(h.getStatus())){
|
||||
//添加到节假日库中
|
||||
KqHoliday kqHoliday=new KqHoliday();
|
||||
kqHoliday.setStatus(h.getStatus());
|
||||
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
kqHoliday.setTime(sdf.parse(h.getData()));
|
||||
kqHoliday.setTimeStamp(sdf.parse(h.getData()).getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
holidayService.insertKqHoliday(kqHoliday);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void gatherMonth()
|
||||
{
|
||||
remoteStudentService.gatherMonth(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
public void backUp()
|
||||
{
|
||||
remoteStudentService.backUp(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
public void gather()
|
||||
{
|
||||
remoteStudentService.gather(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
public void peopleLeave()
|
||||
{
|
||||
remoteStudentService.peopleLeave(SecurityConstants.INNER);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增请假信息
|
||||
*/
|
||||
public void saveAskForLeave() {
|
||||
remoteStudentService.saveAskForLeave(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增补卡信息
|
||||
*/
|
||||
public void saveCardReplacement() {
|
||||
remoteStudentService.saveCardReplacement(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时批量下发
|
||||
*/
|
||||
public void batchDistribute() {
|
||||
remoteStudentService.batchDistribute(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时部门
|
||||
*/
|
||||
public void saveBranchTree() {
|
||||
remoteStudentService.saveBranchTree(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时人员
|
||||
*/
|
||||
public void saveUserInfo() {
|
||||
remoteStudentService.saveUserInfo(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时岗位
|
||||
*/
|
||||
public void saveStation() {
|
||||
remoteStudentService.saveStation(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时批量下发部门人员
|
||||
*/
|
||||
public void batchDown() {
|
||||
remoteStudentService.batchDown(SecurityConstants.INNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 梯控刷卡回调接口设置
|
||||
*/
|
||||
public void setDeviceCallBackInfo(String sequence) {
|
||||
sysJobLogService.setDeviceCallBackInfo(sequence);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新梯口设备在线离线状态
|
||||
*/
|
||||
public void updateLadderState(String sequence) throws IOException {
|
||||
sysJobLogService.updateLadderState(sequence);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除宇泛人脸设备访客结束时间的数据
|
||||
*/
|
||||
public void deleteVisitorFaceDevice() {
|
||||
sysJobLogService.deleteVisitorFaceDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置宇泛二维码回调地址
|
||||
*/
|
||||
public void setQRCodeCallback(String sequence) {
|
||||
sysJobLogService.setQRCodeCallback(sequence);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时签离访客人员
|
||||
*/
|
||||
public void updateVisitorSignOff() {
|
||||
sysJobLogService.updateVisitorSignOff();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.dcsoft.job.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.dcsoft.common.core.constant.ScheduleConstants;
|
||||
import com.dcsoft.common.core.utils.ExceptionUtil;
|
||||
import com.dcsoft.common.core.utils.SpringUtils;
|
||||
import com.dcsoft.common.core.utils.StringUtils;
|
||||
import com.dcsoft.common.core.utils.bean.BeanUtils;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
import com.dcsoft.job.domain.SysJobLog;
|
||||
import com.dcsoft.job.service.ISysJobLogService;
|
||||
|
||||
/**
|
||||
* 抽象quartz调用
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public abstract class AbstractQuartzJob implements Job
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractQuartzJob.class);
|
||||
|
||||
/**
|
||||
* 线程本地变量
|
||||
*/
|
||||
private static ThreadLocal<Date> threadLocal = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||
{
|
||||
SysJob sysJob = new SysJob();
|
||||
BeanUtils.copyBeanProp(sysJob, context.getMergedJobDataMap().get(ScheduleConstants.TASK_PROPERTIES));
|
||||
try
|
||||
{
|
||||
before(context, sysJob);
|
||||
if (sysJob != null)
|
||||
{
|
||||
doExecute(context, sysJob);
|
||||
}
|
||||
after(context, sysJob, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.error("任务执行异常 - :", e);
|
||||
after(context, sysJob, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行前
|
||||
*
|
||||
* @param context 工作执行上下文对象
|
||||
* @param sysJob 系统计划任务
|
||||
*/
|
||||
protected void before(JobExecutionContext context, SysJob sysJob)
|
||||
{
|
||||
threadLocal.set(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行后
|
||||
*
|
||||
* @param context 工作执行上下文对象
|
||||
* @param sysJob 系统计划任务
|
||||
*/
|
||||
protected void after(JobExecutionContext context, SysJob sysJob, Exception e)
|
||||
{
|
||||
Date startTime = threadLocal.get();
|
||||
threadLocal.remove();
|
||||
|
||||
final SysJobLog sysJobLog = new SysJobLog();
|
||||
sysJobLog.setJobName(sysJob.getJobName());
|
||||
sysJobLog.setJobGroup(sysJob.getJobGroup());
|
||||
sysJobLog.setInvokeTarget(sysJob.getInvokeTarget());
|
||||
sysJobLog.setStartTime(startTime);
|
||||
sysJobLog.setStopTime(new Date());
|
||||
long runMs = sysJobLog.getStopTime().getTime() - sysJobLog.getStartTime().getTime();
|
||||
sysJobLog.setJobMessage(sysJobLog.getJobName() + " 总共耗时:" + runMs + "毫秒");
|
||||
if (e != null)
|
||||
{
|
||||
sysJobLog.setStatus("1");
|
||||
String errorMsg = StringUtils.substring(ExceptionUtil.getExceptionMessage(e), 0, 2000);
|
||||
sysJobLog.setExceptionInfo(errorMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
sysJobLog.setStatus("0");
|
||||
}
|
||||
|
||||
// 写入数据库当中
|
||||
SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行方法,由子类重载
|
||||
*
|
||||
* @param context 工作执行上下文对象
|
||||
* @param sysJob 系统计划任务
|
||||
* @throws Exception 执行过程中的异常
|
||||
*/
|
||||
protected abstract void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.dcsoft.job.util;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import org.quartz.CronExpression;
|
||||
|
||||
/**
|
||||
* cron表达式工具类
|
||||
*
|
||||
* @author dcsoft
|
||||
*
|
||||
*/
|
||||
public class CronUtils
|
||||
{
|
||||
/**
|
||||
* 返回一个布尔值代表一个给定的Cron表达式的有效性
|
||||
*
|
||||
* @param cronExpression Cron表达式
|
||||
* @return boolean 表达式是否有效
|
||||
*/
|
||||
public static boolean isValid(String cronExpression)
|
||||
{
|
||||
return CronExpression.isValidExpression(cronExpression);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回一个字符串值,表示该消息无效Cron表达式给出有效性
|
||||
*
|
||||
* @param cronExpression Cron表达式
|
||||
* @return String 无效时返回表达式错误描述,如果有效返回null
|
||||
*/
|
||||
public static String getInvalidMessage(String cronExpression)
|
||||
{
|
||||
try
|
||||
{
|
||||
new CronExpression(cronExpression);
|
||||
return null;
|
||||
}
|
||||
catch (ParseException pe)
|
||||
{
|
||||
return pe.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回下一个执行时间根据给定的Cron表达式
|
||||
*
|
||||
* @param cronExpression Cron表达式
|
||||
* @return Date 下次Cron表达式执行时间
|
||||
*/
|
||||
public static Date getNextExecution(String cronExpression)
|
||||
{
|
||||
try
|
||||
{
|
||||
CronExpression cron = new CronExpression(cronExpression);
|
||||
return cron.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
throw new IllegalArgumentException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.dcsoft.job.util;
|
||||
|
||||
|
||||
import com.dcsoft.job.domain.HolidayVo;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 节假日工具类
|
||||
*/
|
||||
public class HolidayUtil {
|
||||
|
||||
/**
|
||||
* 发送get请求
|
||||
*/
|
||||
private static String get(String url){
|
||||
StringBuilder inputLine = new StringBuilder();
|
||||
String read;
|
||||
try {
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
|
||||
urlConnection.setReadTimeout(30 * 1000);
|
||||
urlConnection.setConnectTimeout(30 * 1000);
|
||||
urlConnection.setRequestProperty("Charset", "UTF-8");
|
||||
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36)");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), StandardCharsets.UTF_8));
|
||||
while ((read = in.readLine()) != null) {
|
||||
inputLine.append(read);
|
||||
}
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return inputLine.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用免费API查询全年工作日、周末、法定节假日、节假日调休补班数据
|
||||
* 1、调用 https://api.apihubs.cn/holiday/get?size=500&year=2021 查询全年日历(含周末)
|
||||
* 2、调用 https://timor.tech/api/holiday/year/2021 查询全年节假日、调休
|
||||
*/
|
||||
public static ArrayList<HolidayVo> getAllHolidayByYear(String year) throws IOException {
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
ArrayList<HolidayVo> holidayVoList = new ArrayList<>();
|
||||
HashMap<String,HolidayVo> hashMap = new HashMap<>();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
//查询全年日历包含周末
|
||||
/*String allDayJson = HolidayUtil.get("https://api.apihubs.cn/holiday/get?size=500&year="+year);
|
||||
Map allDayMap = mapper.readValue(allDayJson,Map.class);
|
||||
Map allDayData = (Map)allDayMap.get("data");
|
||||
List allDayDataList = (List)allDayData.get("list");
|
||||
allDayDataList.forEach((value) -> {
|
||||
HolidayVo holidayVo = new HolidayVo();
|
||||
|
||||
Map value1 = (Map) value;
|
||||
String YEAR = value1.get("year").toString();
|
||||
String MONTH = value1.get("month").toString().replace(YEAR,"");
|
||||
String DAY = value1.get("date").toString().replace(YEAR+MONTH,"");
|
||||
|
||||
holidayVo.setData(YEAR + "-" + MONTH + "-" + DAY);
|
||||
String STATUS = "0";
|
||||
String msg = "工作日";
|
||||
if("1".equals(value1.get("weekend").toString())){
|
||||
STATUS = "1";
|
||||
msg = "周末";
|
||||
}
|
||||
holidayVo.setStatus(STATUS);
|
||||
holidayVo.setMsg(msg);
|
||||
|
||||
hashMap.put(holidayVo.getData(),holidayVo);
|
||||
});*/
|
||||
|
||||
//查询全年节假日、调休
|
||||
String holidayJson = HolidayUtil.get("https://timor.tech/api/holiday/year/"+year + "/");
|
||||
Map holidayMap = mapper.readValue(holidayJson,Map.class);
|
||||
//LinkedHashMap holidayList = (LinkedHashMap)holidayMap.get("holiday");
|
||||
Map<String, Map<String, Object>> holiday= (Map<String, Map<String, Object>>) holidayMap.get("holiday");
|
||||
Set<String> strings = holiday.keySet();
|
||||
for(String str:strings){
|
||||
HolidayVo holidayVo = new HolidayVo();
|
||||
Map<String, Object> stringObjectMap = holiday.get(str);
|
||||
Boolean holidays = (Boolean) stringObjectMap.get("holiday");
|
||||
if(holidays){
|
||||
holidayVo.setStatus("2");
|
||||
}else{
|
||||
holidayVo.setStatus("1");
|
||||
}
|
||||
String date = (String) stringObjectMap.get("date");
|
||||
String dateTime = date;
|
||||
holidayVo.setData(dateTime);
|
||||
|
||||
holidayVoList.add(holidayVo);
|
||||
}
|
||||
|
||||
//排序
|
||||
holidayVoList.sort((a,b)->{
|
||||
try {
|
||||
return sf.parse(a.getData()).compareTo(sf.parse(b.getData()));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
||||
return holidayVoList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
package com.dcsoft.job.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class HttpUtils {
|
||||
|
||||
public static String getData(String url) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
CloseableHttpResponse response = null;
|
||||
String result = "";
|
||||
try {
|
||||
// 通过址默认配置创建一个httpClient实例
|
||||
httpClient = HttpClients.createDefault();
|
||||
// 创建httpGet远程连接实例
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
// 设置请求头信息,鉴权
|
||||
httpGet.setHeader("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
|
||||
// 设置配置请求参数
|
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间
|
||||
.setConnectionRequestTimeout(35000)// 请求超时时间
|
||||
.setSocketTimeout(60000)// 数据读取超时时间
|
||||
.build();
|
||||
// 为httpGet实例设置配置
|
||||
httpGet.setConfig(requestConfig);
|
||||
// 执行get请求得到返回对象
|
||||
response = httpClient.execute(httpGet);
|
||||
// 通过返回对象获取返回数据
|
||||
HttpEntity entity = response.getEntity();
|
||||
// 通过EntityUtils中的toString方法将结果转换为字符串
|
||||
result = EntityUtils.toString(entity);
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != response) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != httpClient) {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String postData(String url, Map<String, Object> paramMap) {
|
||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||
HttpPost post = new HttpPost(url);
|
||||
String result = "";
|
||||
try (CloseableHttpClient closeableHttpClient = httpClientBuilder.build()) {
|
||||
// HttpEntity entity = new StringEntity(jsonStrData);
|
||||
// 修复 POST json 导致中文乱码
|
||||
HttpEntity entity = new StringEntity(JSONObject.toJSONString(paramMap), "UTF-8");
|
||||
post.setEntity(entity);
|
||||
post.setHeader("Content-type", "application/json");
|
||||
HttpResponse resp = closeableHttpClient.execute(post);
|
||||
try {
|
||||
InputStream respIs = resp.getEntity().getContent();
|
||||
byte[] respBytes = IOUtils.toByteArray(respIs);
|
||||
result = new String(respBytes, Charset.forName("UTF-8"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String postDataJson(String url, JSONObject paramMap) {
|
||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||
HttpPost post = new HttpPost(url);
|
||||
String result = "";
|
||||
try (CloseableHttpClient closeableHttpClient = httpClientBuilder.build()) {
|
||||
// HttpEntity entity = new StringEntity(jsonStrData);
|
||||
// 修复 POST json 导致中文乱码
|
||||
HttpEntity entity = new StringEntity(paramMap.toJSONString(), "UTF-8");
|
||||
post.setEntity(entity);
|
||||
post.setHeader("Content-type", "application/json");
|
||||
HttpResponse resp = closeableHttpClient.execute(post);
|
||||
try {
|
||||
InputStream respIs = resp.getEntity().getContent();
|
||||
byte[] respBytes = IOUtils.toByteArray(respIs);
|
||||
result = new String(respBytes, Charset.forName("UTF-8"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* form表单提交
|
||||
*
|
||||
* @param url
|
||||
* @param paramMap
|
||||
* @return
|
||||
*/
|
||||
public static String sendxwwwform(String url, Map<String, Object> paramMap) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
CloseableHttpResponse httpResponse = null;
|
||||
String result = "";
|
||||
// 创建httpClient实例
|
||||
httpClient = HttpClients.createDefault();
|
||||
// 创建httpPost远程连接实例
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 配置请求参数实例
|
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 设置连接主机服务超时时间
|
||||
.setConnectionRequestTimeout(35000)// 设置连接请求超时时间
|
||||
.setSocketTimeout(60000)// 设置读取数据连接超时时间
|
||||
.build();
|
||||
// 为httpPost实例设置配置
|
||||
httpPost.setConfig(requestConfig);
|
||||
// 设置请求头
|
||||
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
// 封装post请求参数
|
||||
if (null != paramMap && paramMap.size() > 0) {
|
||||
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
||||
// 通过map集成entrySet方法获取entity
|
||||
Set<Entry<String, Object>> entrySet = paramMap.entrySet();
|
||||
// 循环遍历,获取迭代器
|
||||
Iterator<Entry<String, Object>> iterator = entrySet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<String, Object> mapEntry = iterator.next();
|
||||
nvps.add(new BasicNameValuePair(mapEntry.getKey(), mapEntry.getValue().toString()));
|
||||
}
|
||||
|
||||
// 为httpPost设置封装好的请求参数
|
||||
try {
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
// httpClient对象执行post请求,并返回响应参数对象
|
||||
httpResponse = httpClient.execute(httpPost);
|
||||
// 从响应对象中获取响应内容
|
||||
HttpEntity entity = httpResponse.getEntity();
|
||||
result = EntityUtils.toString(entity);
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != httpResponse) {
|
||||
try {
|
||||
httpResponse.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != httpClient) {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getUrl(String url,Map<String, Object> headMap,String projectGuid ) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
CloseableHttpResponse response = null;
|
||||
String result = "";
|
||||
try {
|
||||
// 通过址默认配置创建一个httpClient实例
|
||||
httpClient = HttpClients.createDefault();
|
||||
// 创建httpGet远程连接实例
|
||||
StringBuffer sb = new StringBuffer(url);
|
||||
sb.append("projectGuid=" + projectGuid);
|
||||
HttpGet httpGet = new HttpGet(sb.toString());
|
||||
// 设置请求头信息,鉴权
|
||||
httpGet.setHeader("Authorization", "Bearer da3efcbf-0845-4fe3-8aba-ee040be542c0");
|
||||
httpGet.setHeader("appKey",headMap.get("appKey").toString());
|
||||
httpGet.setHeader("timestamp",headMap.get("timestamp").toString());
|
||||
httpGet.setHeader("sign",headMap.get("sign").toString());
|
||||
// 设置配置请求参数
|
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间
|
||||
.setConnectionRequestTimeout(35000)// 请求超时时间
|
||||
.setSocketTimeout(60000)// 数据读取超时时间
|
||||
.build();
|
||||
// 为httpGet实例设置配置
|
||||
httpGet.setConfig(requestConfig);
|
||||
// 执行get请求得到返回对象
|
||||
response = httpClient.execute(httpGet);
|
||||
// 通过返回对象获取返回数据
|
||||
HttpEntity entity = response.getEntity();
|
||||
// 通过EntityUtils中的toString方法将结果转换为字符串
|
||||
result = EntityUtils.toString(entity);
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != response) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != httpClient) {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String postData(String url,Map<String, Object> headMap, Map<String, Object> paramMap) {
|
||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||
HttpPost post = new HttpPost(url);
|
||||
String result = "";
|
||||
try (CloseableHttpClient closeableHttpClient = httpClientBuilder.build()) {
|
||||
// HttpEntity entity = new StringEntity(jsonStrData);
|
||||
// 修复 POST json 导致中文乱码
|
||||
HttpEntity entity = new StringEntity(JSONObject.toJSONString(paramMap), "UTF-8");
|
||||
post.setEntity(entity);
|
||||
post.setHeader("Content-type", "application/json");
|
||||
if (null != headMap && headMap.size() > 0) {
|
||||
// 通过map集成entrySet方法获取entity
|
||||
Set<Entry<String, Object>> entrySet = headMap.entrySet();
|
||||
// 循环遍历,获取迭代器
|
||||
Iterator<Entry<String, Object>> iterator = entrySet.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<String, Object> mapEntry = iterator.next();
|
||||
post.setHeader(mapEntry.getKey(),mapEntry.getValue().toString());
|
||||
}
|
||||
}
|
||||
HttpResponse resp = closeableHttpClient.execute(post);
|
||||
try {
|
||||
InputStream respIs = resp.getEntity().getContent();
|
||||
byte[] respBytes = IOUtils.toByteArray(respIs);
|
||||
result = new String(respBytes, Charset.forName("UTF-8"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getDataToken(String url,String token) {
|
||||
CloseableHttpClient httpClient = null;
|
||||
CloseableHttpResponse response = null;
|
||||
String result = "";
|
||||
try {
|
||||
// 通过址默认配置创建一个httpClient实例
|
||||
httpClient = HttpClients.createDefault();
|
||||
// 创建httpGet远程连接实例
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
// 设置请求头信息,鉴权
|
||||
httpGet.setHeader("Authorization", "Bearer "+token);
|
||||
// 设置配置请求参数
|
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间
|
||||
.setConnectionRequestTimeout(35000)// 请求超时时间
|
||||
.setSocketTimeout(60000)// 数据读取超时时间
|
||||
.build();
|
||||
// 为httpGet实例设置配置
|
||||
httpGet.setConfig(requestConfig);
|
||||
// 执行get请求得到返回对象
|
||||
response = httpClient.execute(httpGet);
|
||||
// 通过返回对象获取返回数据
|
||||
HttpEntity entity = response.getEntity();
|
||||
// 通过EntityUtils中的toString方法将结果转换为字符串
|
||||
result = EntityUtils.toString(entity);
|
||||
} catch (ClientProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != response) {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != httpClient) {
|
||||
try {
|
||||
httpClient.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.dcsoft.job.util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import com.dcsoft.common.core.utils.SpringUtils;
|
||||
import com.dcsoft.common.core.utils.StringUtils;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
|
||||
/**
|
||||
* 任务执行工具
|
||||
*
|
||||
* @author dcsoft
|
||||
*/
|
||||
public class JobInvokeUtil
|
||||
{
|
||||
/**
|
||||
* 执行方法
|
||||
*
|
||||
* @param sysJob 系统任务
|
||||
*/
|
||||
public static void invokeMethod(SysJob sysJob) throws Exception
|
||||
{
|
||||
String invokeTarget = sysJob.getInvokeTarget();
|
||||
String beanName = getBeanName(invokeTarget);
|
||||
String methodName = getMethodName(invokeTarget);
|
||||
List<Object[]> methodParams = getMethodParams(invokeTarget);
|
||||
|
||||
if (!isValidClassName(beanName))
|
||||
{
|
||||
Object bean = SpringUtils.getBean(beanName);
|
||||
invokeMethod(bean, methodName, methodParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object bean = Class.forName(beanName).newInstance();
|
||||
invokeMethod(bean, methodName, methodParams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用任务方法
|
||||
*
|
||||
* @param bean 目标对象
|
||||
* @param methodName 方法名称
|
||||
* @param methodParams 方法参数
|
||||
*/
|
||||
private static void invokeMethod(Object bean, String methodName, List<Object[]> methodParams)
|
||||
throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException,
|
||||
InvocationTargetException
|
||||
{
|
||||
if (StringUtils.isNotNull(methodParams) && methodParams.size() > 0)
|
||||
{
|
||||
Method method = bean.getClass().getMethod(methodName, getMethodParamsType(methodParams));
|
||||
method.invoke(bean, getMethodParamsValue(methodParams));
|
||||
}
|
||||
else
|
||||
{
|
||||
Method method = bean.getClass().getMethod(methodName);
|
||||
method.invoke(bean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验是否为为class包名
|
||||
*
|
||||
* @param invokeTarget 名称
|
||||
* @return true是 false否
|
||||
*/
|
||||
public static boolean isValidClassName(String invokeTarget)
|
||||
{
|
||||
return StringUtils.countMatches(invokeTarget, ".") > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bean名称
|
||||
*
|
||||
* @param invokeTarget 目标字符串
|
||||
* @return bean名称
|
||||
*/
|
||||
public static String getBeanName(String invokeTarget)
|
||||
{
|
||||
String beanName = StringUtils.substringBefore(invokeTarget, "(");
|
||||
return StringUtils.substringBeforeLast(beanName, ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bean方法
|
||||
*
|
||||
* @param invokeTarget 目标字符串
|
||||
* @return method方法
|
||||
*/
|
||||
public static String getMethodName(String invokeTarget)
|
||||
{
|
||||
String methodName = StringUtils.substringBefore(invokeTarget, "(");
|
||||
return StringUtils.substringAfterLast(methodName, ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取method方法参数相关列表
|
||||
*
|
||||
* @param invokeTarget 目标字符串
|
||||
* @return method方法相关参数列表
|
||||
*/
|
||||
public static List<Object[]> getMethodParams(String invokeTarget)
|
||||
{
|
||||
String methodStr = StringUtils.substringBetween(invokeTarget, "(", ")");
|
||||
if (StringUtils.isEmpty(methodStr))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String[] methodParams = methodStr.split(",(?=([^\"']*[\"'][^\"']*[\"'])*[^\"']*$)");
|
||||
List<Object[]> classs = new LinkedList<>();
|
||||
for (int i = 0; i < methodParams.length; i++)
|
||||
{
|
||||
String str = StringUtils.trimToEmpty(methodParams[i]);
|
||||
// String字符串类型,以'或"开头
|
||||
if (StringUtils.startsWithAny(str, "'", "\""))
|
||||
{
|
||||
classs.add(new Object[] { StringUtils.substring(str, 1, str.length() - 1), String.class });
|
||||
}
|
||||
// boolean布尔类型,等于true或者false
|
||||
else if ("true".equalsIgnoreCase(str) || "false".equalsIgnoreCase(str))
|
||||
{
|
||||
classs.add(new Object[] { Boolean.valueOf(str), Boolean.class });
|
||||
}
|
||||
// long长整形,以L结尾
|
||||
else if (StringUtils.endsWith(str, "L"))
|
||||
{
|
||||
classs.add(new Object[] { Long.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Long.class });
|
||||
}
|
||||
// double浮点类型,以D结尾
|
||||
else if (StringUtils.endsWith(str, "D"))
|
||||
{
|
||||
classs.add(new Object[] { Double.valueOf(StringUtils.substring(str, 0, str.length() - 1)), Double.class });
|
||||
}
|
||||
// 其他类型归类为整形
|
||||
else
|
||||
{
|
||||
classs.add(new Object[] { Integer.valueOf(str), Integer.class });
|
||||
}
|
||||
}
|
||||
return classs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数类型
|
||||
*
|
||||
* @param methodParams 参数相关列表
|
||||
* @return 参数类型列表
|
||||
*/
|
||||
public static Class<?>[] getMethodParamsType(List<Object[]> methodParams)
|
||||
{
|
||||
Class<?>[] classs = new Class<?>[methodParams.size()];
|
||||
int index = 0;
|
||||
for (Object[] os : methodParams)
|
||||
{
|
||||
classs[index] = (Class<?>) os[1];
|
||||
index++;
|
||||
}
|
||||
return classs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参数值
|
||||
*
|
||||
* @param methodParams 参数相关列表
|
||||
* @return 参数值列表
|
||||
*/
|
||||
public static Object[] getMethodParamsValue(List<Object[]> methodParams)
|
||||
{
|
||||
Object[] classs = new Object[methodParams.size()];
|
||||
int index = 0;
|
||||
for (Object[] os : methodParams)
|
||||
{
|
||||
classs[index] = (Object) os[0];
|
||||
index++;
|
||||
}
|
||||
return classs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.dcsoft.job.util;
|
||||
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
|
||||
/**
|
||||
* 定时任务处理(禁止并发执行)
|
||||
*
|
||||
* @author dcsoft
|
||||
*
|
||||
*/
|
||||
@DisallowConcurrentExecution
|
||||
public class QuartzDisallowConcurrentExecution extends AbstractQuartzJob
|
||||
{
|
||||
@Override
|
||||
protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception
|
||||
{
|
||||
JobInvokeUtil.invokeMethod(sysJob);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dcsoft.job.util;
|
||||
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
|
||||
/**
|
||||
* 定时任务处理(允许并发执行)
|
||||
*
|
||||
* @author dcsoft
|
||||
*
|
||||
*/
|
||||
public class QuartzJobExecution extends AbstractQuartzJob
|
||||
{
|
||||
@Override
|
||||
protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception
|
||||
{
|
||||
JobInvokeUtil.invokeMethod(sysJob);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.dcsoft.job.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.dcsoft.common.core.constant.Constants;
|
||||
import com.dcsoft.common.core.constant.ScheduleConstants;
|
||||
import com.dcsoft.common.core.exception.job.TaskException;
|
||||
import com.dcsoft.common.core.exception.job.TaskException.Code;
|
||||
import com.dcsoft.common.core.utils.SpringUtils;
|
||||
import com.dcsoft.common.core.utils.StringUtils;
|
||||
import com.dcsoft.job.domain.SysJob;
|
||||
|
||||
/**
|
||||
* 定时任务工具类
|
||||
*
|
||||
* @author dcsoft
|
||||
*
|
||||
*/
|
||||
public class ScheduleUtils
|
||||
{
|
||||
/**
|
||||
* 得到quartz任务类
|
||||
*
|
||||
* @param sysJob 执行计划
|
||||
* @return 具体执行任务类
|
||||
*/
|
||||
private static Class<? extends Job> getQuartzJobClass(SysJob sysJob)
|
||||
{
|
||||
boolean isConcurrent = "0".equals(sysJob.getConcurrent());
|
||||
return isConcurrent ? QuartzJobExecution.class : QuartzDisallowConcurrentExecution.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建任务触发对象
|
||||
*/
|
||||
public static TriggerKey getTriggerKey(Long jobId, String jobGroup)
|
||||
{
|
||||
return TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建任务键对象
|
||||
*/
|
||||
public static JobKey getJobKey(Long jobId, String jobGroup)
|
||||
{
|
||||
return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建定时任务
|
||||
*/
|
||||
public static void createScheduleJob(Scheduler scheduler, SysJob job) throws SchedulerException, TaskException
|
||||
{
|
||||
Class<? extends Job> jobClass = getQuartzJobClass(job);
|
||||
// 构建job信息
|
||||
Long jobId = job.getJobId();
|
||||
String jobGroup = job.getJobGroup();
|
||||
JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build();
|
||||
|
||||
// 表达式调度构建器
|
||||
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression());
|
||||
cronScheduleBuilder = handleCronScheduleMisfirePolicy(job, cronScheduleBuilder);
|
||||
|
||||
// 按新的cronExpression表达式构建一个新的trigger
|
||||
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(getTriggerKey(jobId, jobGroup))
|
||||
.withSchedule(cronScheduleBuilder).build();
|
||||
|
||||
// 放入参数,运行时的方法可以获取
|
||||
jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job);
|
||||
|
||||
// 判断是否存在
|
||||
if (scheduler.checkExists(getJobKey(jobId, jobGroup)))
|
||||
{
|
||||
// 防止创建时存在数据问题 先移除,然后在执行创建操作
|
||||
scheduler.deleteJob(getJobKey(jobId, jobGroup));
|
||||
}
|
||||
|
||||
// 判断任务是否过期
|
||||
if (StringUtils.isNotNull(CronUtils.getNextExecution(job.getCronExpression())))
|
||||
{
|
||||
// 执行调度任务
|
||||
scheduler.scheduleJob(jobDetail, trigger);
|
||||
}
|
||||
|
||||
// 暂停任务
|
||||
if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue()))
|
||||
{
|
||||
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置定时任务策略
|
||||
*/
|
||||
public static CronScheduleBuilder handleCronScheduleMisfirePolicy(SysJob job, CronScheduleBuilder cb)
|
||||
throws TaskException
|
||||
{
|
||||
switch (job.getMisfirePolicy())
|
||||
{
|
||||
case ScheduleConstants.MISFIRE_DEFAULT:
|
||||
return cb;
|
||||
case ScheduleConstants.MISFIRE_IGNORE_MISFIRES:
|
||||
return cb.withMisfireHandlingInstructionIgnoreMisfires();
|
||||
case ScheduleConstants.MISFIRE_FIRE_AND_PROCEED:
|
||||
return cb.withMisfireHandlingInstructionFireAndProceed();
|
||||
case ScheduleConstants.MISFIRE_DO_NOTHING:
|
||||
return cb.withMisfireHandlingInstructionDoNothing();
|
||||
default:
|
||||
throw new TaskException("The task misfire policy '" + job.getMisfirePolicy()
|
||||
+ "' cannot be used in cron schedule tasks", Code.CONFIG_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查包名是否为白名单配置
|
||||
*
|
||||
* @param invokeTarget 目标字符串
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean whiteList(String invokeTarget)
|
||||
{
|
||||
String packageName = StringUtils.substringBefore(invokeTarget, "(");
|
||||
int count = StringUtils.countMatches(packageName, ".");
|
||||
if (count > 1)
|
||||
{
|
||||
return StringUtils.containsAnyIgnoreCase(invokeTarget, Constants.JOB_WHITELIST_STR);
|
||||
}
|
||||
Object obj = SpringUtils.getBean(StringUtils.split(invokeTarget, ".")[0]);
|
||||
return StringUtils.containsAnyIgnoreCase(obj.getClass().getPackage().getName(), Constants.JOB_WHITELIST_STR);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user