新增Task
This commit is contained in:
parent
b0e6cfc049
commit
63aca636ba
|
|
@ -0,0 +1,176 @@
|
|||
package com.qihang.tao.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName sys_task
|
||||
*/
|
||||
public class SysTask implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String taskName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String cron;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getTaskName() {
|
||||
return taskName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setTaskName(String taskName) {
|
||||
this.taskName = taskName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getCron() {
|
||||
return cron;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setCron(String cron) {
|
||||
this.cron = cron;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != that.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SysTask other = (SysTask) that;
|
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
|
||||
&& (this.getTaskName() == null ? other.getTaskName() == null : this.getTaskName().equals(other.getTaskName()))
|
||||
&& (this.getCron() == null ? other.getCron() == null : this.getCron().equals(other.getCron()))
|
||||
&& (this.getMethod() == null ? other.getMethod() == null : this.getMethod().equals(other.getMethod()))
|
||||
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
|
||||
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getTaskName() == null) ? 0 : getTaskName().hashCode());
|
||||
result = prime * result + ((getCron() == null) ? 0 : getCron().hashCode());
|
||||
result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode());
|
||||
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
|
||||
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [");
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", taskName=").append(taskName);
|
||||
sb.append(", cron=").append(cron);
|
||||
sb.append(", method=").append(method);
|
||||
sb.append(", remark=").append(remark);
|
||||
sb.append(", createTime=").append(createTime);
|
||||
sb.append(", serialVersionUID=").append(serialVersionUID);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.qihang.tao.mapper;
|
||||
|
||||
import com.qihang.tao.domain.SysTask;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author TW
|
||||
* @description 针对表【sys_task】的数据库操作Mapper
|
||||
* @createDate 2024-03-07 10:22:03
|
||||
* @Entity com.qihang.tao.domain.SysTask
|
||||
*/
|
||||
public interface SysTaskMapper extends BaseMapper<SysTask> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.qihang.tao.service;
|
||||
|
||||
import com.qihang.tao.domain.SysTask;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author TW
|
||||
* @description 针对表【sys_task】的数据库操作Service
|
||||
* @createDate 2024-03-07 10:22:03
|
||||
*/
|
||||
public interface SysTaskService extends IService<SysTask> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.qihang.tao.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.qihang.tao.domain.SysTask;
|
||||
import com.qihang.tao.service.SysTaskService;
|
||||
import com.qihang.tao.mapper.SysTaskMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author TW
|
||||
* @description 针对表【sys_task】的数据库操作Service实现
|
||||
* @createDate 2024-03-07 10:22:03
|
||||
*/
|
||||
@Service
|
||||
public class SysTaskServiceImpl extends ServiceImpl<SysTaskMapper, SysTask>
|
||||
implements SysTaskService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.qihang.tao.task;
|
||||
|
||||
import com.qihang.common.task.SchedulingConfiguration;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Component
|
||||
public class CronTaskLoader implements ApplicationRunner {
|
||||
// private static final Logger log = LoggerFactory.getLogger(CronTaskLoader.class);
|
||||
private final SchedulingConfiguration schedulingConfiguration;
|
||||
private final AtomicBoolean appStarted = new AtomicBoolean(false);
|
||||
private final AtomicBoolean initializing = new AtomicBoolean(false);
|
||||
|
||||
public CronTaskLoader(SchedulingConfiguration schedulingConfiguration) {
|
||||
this.schedulingConfiguration = schedulingConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务配置刷新(1分钟刷新一次)
|
||||
*/
|
||||
@Scheduled(fixedDelay = 600000)
|
||||
public void cronTaskConfigRefresh() {
|
||||
if (appStarted.get() && initializing.compareAndSet(false, true)) {
|
||||
// log.info("定时调度任务动态加载开始>>>>>>");
|
||||
try {
|
||||
schedulingConfiguration.refresh();
|
||||
} finally {
|
||||
initializing.set(false);
|
||||
}
|
||||
// log.info("定时调度任务动态加载结束<<<<<<");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (appStarted.compareAndSet(false, true)) {
|
||||
cronTaskConfigRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.qihang.tao.task;
|
||||
|
||||
import com.qihang.common.task.IPollableService;
|
||||
import com.qihang.tao.domain.SysTask;
|
||||
import com.qihang.tao.service.SysTaskService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class OrderTask implements IPollableService {
|
||||
|
||||
private final SysTaskService taskService;
|
||||
@Override
|
||||
public void poll() {
|
||||
System.out.printf("更新TAO订单%s","echo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCronExpression() {
|
||||
SysTask task = taskService.getById(1);
|
||||
// return "0/1 * * * * ?";
|
||||
return task.getCron();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.qihang.tao.mapper.SysTaskMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.qihang.tao.domain.SysTask">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="taskName" column="task_name" jdbcType="VARCHAR"/>
|
||||
<result property="cron" column="cron" jdbcType="VARCHAR"/>
|
||||
<result property="method" column="method" jdbcType="VARCHAR"/>
|
||||
<result property="remark" column="remark" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,task_name,cron,
|
||||
method,remark,create_time
|
||||
</sql>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue