parent
5afcf116fd
commit
7dfed8e62e
@ -0,0 +1,77 @@
|
||||
package com.xxl.job.core.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* xxl-job info
|
||||
* @author xuxueli 2016-1-12 18:25:49
|
||||
*/
|
||||
public class XxlJobInfo {
|
||||
|
||||
private int id;
|
||||
// job info
|
||||
private String jobName;
|
||||
private String jobCron; // base on quartz
|
||||
private String jobClass; // base on quartz
|
||||
private String jobStatus; // base on quartz
|
||||
private String jobData; // base on db, Map-JSON-String
|
||||
private Date addTime;
|
||||
private Date updateTime;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getJobName() {
|
||||
return jobName;
|
||||
}
|
||||
public void setJobName(String jobName) {
|
||||
this.jobName = jobName;
|
||||
}
|
||||
public String getJobCron() {
|
||||
return jobCron;
|
||||
}
|
||||
public void setJobCron(String jobCron) {
|
||||
this.jobCron = jobCron;
|
||||
}
|
||||
public String getJobClass() {
|
||||
return jobClass;
|
||||
}
|
||||
public void setJobClass(String jobClass) {
|
||||
this.jobClass = jobClass;
|
||||
}
|
||||
public String getJobStatus() {
|
||||
return jobStatus;
|
||||
}
|
||||
public void setJobStatus(String jobStatus) {
|
||||
this.jobStatus = jobStatus;
|
||||
}
|
||||
public String getJobData() {
|
||||
return jobData;
|
||||
}
|
||||
public void setJobData(String jobData) {
|
||||
this.jobData = jobData;
|
||||
}
|
||||
public Date getAddTime() {
|
||||
return addTime;
|
||||
}
|
||||
public void setAddTime(Date addTime) {
|
||||
this.addTime = addTime;
|
||||
}
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "XxlJobInfo [id=" + id + ", jobName=" + jobName + ", jobCron=" + jobCron + ", jobClass=" + jobClass
|
||||
+ ", jobStatus=" + jobStatus + ", jobData=" + jobData + ", addTime=" + addTime + ", updateTime="
|
||||
+ updateTime + "]";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.xxl.job.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.xxl.job.core.model.XxlJobInfo;
|
||||
|
||||
/**
|
||||
* job info
|
||||
* @author xuxueli 2016-1-12 18:03:45
|
||||
*/
|
||||
public interface IXxlJobInfoDao {
|
||||
|
||||
public List<XxlJobInfo> pageList(int offset, int pagesize, String jobName, Date addTimeStart, Date addTimeEnd);
|
||||
public int pageListCount(int offset, int pagesize, String jobName, Date addTimeStart, Date addTimeEnd);
|
||||
|
||||
public int save(XxlJobInfo info);
|
||||
|
||||
public XxlJobInfo load(String jobName);
|
||||
|
||||
public int update(XxlJobInfo item);
|
||||
|
||||
public int delete(String jobName);
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.xxl.job.dao.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.xxl.job.core.model.XxlJobInfo;
|
||||
import com.xxl.job.dao.IXxlJobInfoDao;
|
||||
|
||||
/**
|
||||
* job info
|
||||
* @author xuxueli 2016-1-12 18:03:45
|
||||
*/
|
||||
@Repository
|
||||
public class XxlJobInfoDaoImpl implements IXxlJobInfoDao {
|
||||
|
||||
@Resource
|
||||
public SqlSessionTemplate sqlSessionTemplate;
|
||||
|
||||
@Override
|
||||
public List<XxlJobInfo> pageList(int offset, int pagesize, String jobName, Date addTimeStart, Date addTimeEnd) {
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("offset", offset);
|
||||
params.put("pagesize", pagesize);
|
||||
params.put("jobName", jobName);
|
||||
params.put("addTimeStart", addTimeStart);
|
||||
params.put("addTimeEnd", addTimeEnd);
|
||||
|
||||
return sqlSessionTemplate.selectList("XxlJobInfoMapper.pageList", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int pageListCount(int offset, int pagesize, String jobName, Date addTimeStart, Date addTimeEnd) {
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("offset", offset);
|
||||
params.put("pagesize", pagesize);
|
||||
params.put("jobName", jobName);
|
||||
params.put("addTimeStart", addTimeStart);
|
||||
params.put("addTimeEnd", addTimeEnd);
|
||||
|
||||
return sqlSessionTemplate.selectOne("XxlJobInfoMapper.pageListCount", params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int save(XxlJobInfo info) {
|
||||
return sqlSessionTemplate.insert("XxlJobInfoMapper.save", info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XxlJobInfo load(String jobName) {
|
||||
return sqlSessionTemplate.selectOne("XxlJobInfoMapper.load", jobName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(XxlJobInfo item) {
|
||||
return sqlSessionTemplate.update("XxlJobInfoMapper.update", item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(String jobName) {
|
||||
return sqlSessionTemplate.update("XxlJobInfoMapper.delete", jobName);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
<?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="XxlJobInfoMapper">
|
||||
|
||||
<resultMap id="XxlJobInfo" type="com.xxl.job.core.model.XxlJobInfo" >
|
||||
<result column="id" property="id" />
|
||||
|
||||
<result column="job_name" property="jobName" />
|
||||
<result column="job_cron" property="jobCron" />
|
||||
<result column="job_class" property="jobClass" />
|
||||
<result column="job_data" property="jobData" />
|
||||
|
||||
<result column="add_time" property="addTime" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
t.id,
|
||||
t.job_name,
|
||||
t.job_cron,
|
||||
t.job_class,
|
||||
t.job_data,
|
||||
t.add_time,
|
||||
t.update_time
|
||||
</sql>
|
||||
|
||||
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM xxl_job_qrtz_trigger_info AS t
|
||||
<trim prefix="WHERE" prefixOverrides="AND | OR" >
|
||||
<if test="jobName != null and jobName!=''">
|
||||
AND t.job_name = #{jobName}
|
||||
</if>
|
||||
<if test="addTimeStart != null">
|
||||
AND t.add_time <![CDATA[ > ]]> #{addTimeStart}
|
||||
</if>
|
||||
<if test="addTimeEnd != null">
|
||||
AND t.add_time <![CDATA[ < ]]> #{addTimeEnd}
|
||||
</if>
|
||||
</trim>
|
||||
ORDER BY id DESC
|
||||
LIMIT #{offset}, #{pagesize}
|
||||
</select>
|
||||
|
||||
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
|
||||
SELECT count(1)
|
||||
FROM xxl_job_qrtz_trigger_info AS t
|
||||
<trim prefix="WHERE" prefixOverrides="AND | OR" >
|
||||
<if test="jobName != null and jobName!=''">
|
||||
AND t.job_name = #{jobName}
|
||||
</if>
|
||||
<if test="addTimeStart != null">
|
||||
AND t.add_time <![CDATA[ > ]]> #{addTimeStart}
|
||||
</if>
|
||||
<if test="addTimeEnd != null">
|
||||
AND t.add_time <![CDATA[ < ]]> #{addTimeEnd}
|
||||
</if>
|
||||
</trim>
|
||||
</select>
|
||||
|
||||
<insert id="save" parameterType="com.xxl.job.core.model.XxlJobInfo" useGeneratedKeys="true" keyProperty="id" >
|
||||
INSERT INTO `xxl_job_qrtz_trigger_info` (
|
||||
`job_name`,
|
||||
`job_cron`,
|
||||
`job_class`,
|
||||
`job_data`,
|
||||
`add_time`,
|
||||
`update_time`
|
||||
) VALUES (
|
||||
#{jobName},
|
||||
#{jobCron},
|
||||
#{jobClass},
|
||||
#{jobData},
|
||||
NOW(),
|
||||
NOW()
|
||||
);
|
||||
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
|
||||
SELECT LAST_INSERT_ID()
|
||||
</selectKey>
|
||||
</insert>
|
||||
|
||||
<select id="load" parameterType="java.lang.String" resultMap="XxlJobInfo">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM xxl_job_qrtz_trigger_info AS t
|
||||
WHERE t.job_name = #{jobName}
|
||||
</select>
|
||||
|
||||
<update id="update">
|
||||
UPDATE `xxl_job_qrtz_trigger_info`
|
||||
SET `job_cron`= #{jobCron},
|
||||
`job_data`= #{jobData},
|
||||
`update_time`= NOW()
|
||||
WHERE `id`= #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete" parameterType="java.lang.String">
|
||||
delete from xxl_job_qrtz_trigger_info
|
||||
where job_name = #{jobName}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,55 @@
|
||||
package com.xxl.job.dao.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.xxl.job.core.model.XxlJobInfo;
|
||||
import com.xxl.job.dao.IXxlJobInfoDao;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "classpath*:applicationcontext-*.xml")
|
||||
public class XxlJobInfoTest {
|
||||
|
||||
@Resource
|
||||
private IXxlJobInfoDao xxlJobInfoDao;
|
||||
|
||||
@Test
|
||||
public void pageList(){
|
||||
List<XxlJobInfo> list = xxlJobInfoDao.pageList(0, 20, null, null, null);
|
||||
int list_count = xxlJobInfoDao.pageListCount(0, 20, null, null, null);
|
||||
|
||||
System.out.println(list);
|
||||
System.out.println(list_count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void save_load(){
|
||||
XxlJobInfo info = new XxlJobInfo();
|
||||
info.setJobName("job_name");
|
||||
info.setJobCron("jobCron");
|
||||
info.setJobClass("jobClass");
|
||||
info.setJobData("jobData");
|
||||
int count = xxlJobInfoDao.save(info);
|
||||
System.out.println(count);
|
||||
System.out.println(info.getId());
|
||||
|
||||
XxlJobInfo item = xxlJobInfoDao.load(info.getId());
|
||||
System.out.println(item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update(){
|
||||
XxlJobInfo item = xxlJobInfoDao.load(2);
|
||||
|
||||
item.setJobCron("jobCron2");
|
||||
item.setJobData("jobData2");
|
||||
xxlJobInfoDao.update(item);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue