|
@ -2,7 +2,8 @@ package com.yihu.wlyy.figure.label.service;
|
|
|
|
|
|
import com.yihu.figure_label.entity.FLJobConfig;
|
|
|
import com.yihu.wlyy.figure.label.dao.FLJobConfigDao;
|
|
|
import com.yihu.wlyy.figure.label.util.QuartzHelper;
|
|
|
import com.yihu.wlyy.figure.label.util.IdCardUtil;
|
|
|
import com.yihu.wlyy.figure.label.util.QuartzHelpers;
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -22,21 +23,25 @@ public class JobService {
|
|
|
private Integer sleepTime;
|
|
|
|
|
|
@Autowired
|
|
|
private QuartzHelper quartzHelper;
|
|
|
private IdCardUtil idCardUtil;
|
|
|
|
|
|
@Autowired
|
|
|
private FLJobConfigDao flJobConfigDao;
|
|
|
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
private QuartzHelpers quartzHelpers;
|
|
|
|
|
|
|
|
|
@Transactional
|
|
|
public void stopById(String id) throws Exception {
|
|
|
FLJobConfig flJobConfig = flJobConfigDao.findByIdAndStatus(id, "1");
|
|
|
FLJobConfig flJobConfig = flJobConfigDao.findByIdAndStatus(Long.valueOf(id), "1");
|
|
|
if (flJobConfig != null) {
|
|
|
for (int j = 1; j <= 2; j++) {
|
|
|
quartzHelper.removeJob(flJobConfig.getId() + "-" + j);
|
|
|
flJobConfigDao.updateStatus(flJobConfig.getId().toString(),"0") ;;
|
|
|
quartzHelpers.removeJob(flJobConfig.getId() + "-" + j);
|
|
|
flJobConfigDao.updateStatus(flJobConfig.getId(),"0") ;;
|
|
|
}
|
|
|
} else {
|
|
|
throw new Exception("任务已经停止");
|
|
@ -45,7 +50,7 @@ public class JobService {
|
|
|
|
|
|
@Transactional
|
|
|
public void startById(String id) throws Exception {
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findByIdAndStatus(id, "0");
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findByIdAndStatus(Long.valueOf(id), "0");
|
|
|
if (FLJobConfig != null) {
|
|
|
startOneJob(FLJobConfig);
|
|
|
} else {
|
|
@ -60,9 +65,9 @@ public class JobService {
|
|
|
if (FLJobConfigs != null && FLJobConfigs.size() > 0) {
|
|
|
for (FLJobConfig FLJobConfig : FLJobConfigs) {
|
|
|
for (int j = 1; j <= 2; j++) {
|
|
|
quartzHelper.removeJob(FLJobConfig.getId() + "-" + j);
|
|
|
quartzHelpers.removeJob(FLJobConfig.getId() + "-" + j);
|
|
|
|
|
|
flJobConfigDao.updateStatus(FLJobConfig.getId().toString(),"0") ;;
|
|
|
flJobConfigDao.updateStatus(FLJobConfig.getId(),"0") ;;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@ -102,24 +107,31 @@ public class JobService {
|
|
|
}else{
|
|
|
params.put(flJobConfigVO.getSqlField(), DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
}
|
|
|
params.put("sqlFiledCondition", ">");
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
//往quartz框架添加任务
|
|
|
quartzHelper.addJob(getRightClass(FLJobConfig), FLJobConfig.getQuartzCron(), FLJobConfig.getId().toString(), params);
|
|
|
flJobConfigDao.updateStatus(FLJobConfig.getId().toString(), "1");//设置任务状态是启动 }
|
|
|
quartzHelpers.addJob(getRightClass(FLJobConfig), FLJobConfig.getQuartzCron(), FLJobConfig.getId().toString(), params);
|
|
|
flJobConfigDao.updateStatus(FLJobConfig.getId(), "1");//设置任务状态是启动 }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void startNowById(String id) throws Exception {
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findOne(id);
|
|
|
|
|
|
FLJobConfig wlyyJobConfigVO = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, wlyyJobConfigVO);
|
|
|
FLJobConfig flJobConfigVO = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, flJobConfigVO);
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
params.put("jobConfig", wlyyJobConfigVO.getId().toString());
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("jobConfig", flJobConfigVO.getId());
|
|
|
if(!StringUtils.isEmpty(flJobConfigVO.getSqlFieldValue())){
|
|
|
params.put(flJobConfigVO.getSqlField(),flJobConfigVO.getSqlFieldValue());
|
|
|
}else{
|
|
|
params.put(flJobConfigVO.getSqlField(), DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
|
|
|
}
|
|
|
params.put("sqlFiledCondition", ">");
|
|
|
//往quartz框架添加任务
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
quartzHelper.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
quartzHelpers.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
Thread.sleep(sleepTime);
|
|
|
}
|
|
|
}
|
|
@ -152,13 +164,13 @@ public class JobService {
|
|
|
FLJobConfig flJobConfig = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, flJobConfig);
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("jobConfig", flJobConfig.getId().toString());
|
|
|
//往quartz框架添加任务
|
|
|
params.put("sqlFiledValue", daybefore+","+yesterday);
|
|
|
params.put("sqlFiledCondition", "<");
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
quartzHelper.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
quartzHelpers.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
Thread.sleep(sleepTime);
|
|
|
}
|
|
|
|
|
@ -186,42 +198,42 @@ public class JobService {
|
|
|
Date nowDate = calendar.getTime(); //这个时间就是日期往后推一天的结果
|
|
|
String daybefore = new SimpleDateFormat("yyyy-MM-dd").format(nowDate.getTime());
|
|
|
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findById(id);
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findById(Long.valueOf(id));
|
|
|
if (FLJobConfig == null) {
|
|
|
throw new Exception("id不存在");
|
|
|
}
|
|
|
FLJobConfig flJobConfigVO = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, flJobConfigVO);
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("jobConfig", flJobConfigVO.getId().toString());
|
|
|
|
|
|
//往quartz框架添加任务
|
|
|
params.put("sqlFiledValue", daybefore + "," + yesterday);
|
|
|
params.put("sqlFiledCondition", "<");
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
quartzHelper.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
quartzHelpers.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
Thread.sleep(sleepTime);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public void productDataByDayAndId(Integer day, String id) throws Exception {
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findById(id);
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findById(Long.valueOf(id));
|
|
|
if (FLJobConfig == null) {
|
|
|
throw new Exception("id不存在");
|
|
|
}
|
|
|
FLJobConfig flJobConfigVO = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, flJobConfigVO);
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("jobConfig", flJobConfigVO.getId().toString());
|
|
|
for (int i = 1; i <= day; i++) {
|
|
|
//往quartz框架添加任务
|
|
|
params.put("sqlFiledValue", getYesterday(0 - i - 1)+","+getYesterday(0 - i));
|
|
|
params.put("sqlFiledCondition", "<");
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
quartzHelper.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
quartzHelpers.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
Thread.sleep(sleepTime);
|
|
|
}
|
|
|
}
|
|
@ -307,21 +319,21 @@ public class JobService {
|
|
|
Date nowDate = calendar.getTime(); //这个时间就是日期往后推一天的结果
|
|
|
String daybefore = new SimpleDateFormat("yyyy-MM-dd").format(nowDate.getTime());
|
|
|
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findById(id);
|
|
|
FLJobConfig FLJobConfig = flJobConfigDao.findById(Long.valueOf(id));
|
|
|
if (FLJobConfig == null) {
|
|
|
throw new Exception("id不存在");
|
|
|
}
|
|
|
FLJobConfig flJobConfigVO = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, flJobConfigVO);
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("jobConfig", flJobConfigVO.getId().toString());
|
|
|
|
|
|
//往quartz框架添加任务
|
|
|
params.put("sqlFiledValue", daybefore + "," + yesterday);
|
|
|
params.put("sqlFiledCondition", "<");
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
quartzHelper.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
quartzHelpers.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
}
|
|
|
Thread.sleep(sleepTime * 1000L);
|
|
|
}
|
|
@ -345,14 +357,14 @@ public class JobService {
|
|
|
FLJobConfig flJobConfigVO = new FLJobConfig();
|
|
|
BeanUtils.copyProperties(FLJobConfig, flJobConfigVO);
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("jobConfig", flJobConfigVO.getId().toString());
|
|
|
//往quartz框架添加任务
|
|
|
params.put("sqlFiledValue", daybefore + "," + yesterday);
|
|
|
params.put("sqlFiledCondition", "<");
|
|
|
|
|
|
if (!StringUtils.isEmpty(FLJobConfig.getJobClass())) {
|
|
|
quartzHelper.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
quartzHelpers.startNow(getRightClass(FLJobConfig), FLJobConfig.getId() + UUID.randomUUID().toString().replace("-", ""), params);
|
|
|
}
|
|
|
Thread.sleep(sleepTime * 1000L);
|
|
|
|