|
@ -1,8 +1,10 @@
|
|
|
package com.yihu.quota.service.job;
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
import com.yihu.ehr.util.datetime.DateUtil;
|
|
|
import com.yihu.quota.contants.JobConstant;
|
|
|
import com.yihu.quota.kafka.Producer;
|
|
|
import com.yihu.quota.util.sql.DbKit;
|
|
|
import org.quartz.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@ -12,6 +14,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@ -87,6 +90,7 @@ public class SingleTableJob implements Job {
|
|
|
do {
|
|
|
list = fetch();
|
|
|
saveData(list);
|
|
|
|
|
|
} while (list != null && list.size() != 0);
|
|
|
}
|
|
|
|
|
@ -112,7 +116,7 @@ public class SingleTableJob implements Job {
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
String jsonData = gson.toJson(dataMap);
|
|
|
producer.sendMessage(jsonData);
|
|
|
producer.sendMessage(Producer.sepTopic, jsonData);
|
|
|
}
|
|
|
}
|
|
|
|
|
@ -136,17 +140,45 @@ public class SingleTableJob implements Job {
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
String jsonData = gson.toJson(dataMap);
|
|
|
producer.sendMessage(jsonData);
|
|
|
producer.sendMessage(Producer.sepTopic, jsonData);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
private List<Map<String, Object>> fetch() {
|
|
|
//TODO:filterFieldType过滤
|
|
|
|
|
|
String sql = "select * from " + table +
|
|
|
" where " + filterField + ">=" + start + " and " + filterField + "<" + (start + size) + " and " +
|
|
|
filterField + "<=" + end;
|
|
|
/**
|
|
|
* TODO:没有设置数据库来源和数据库类型,当前使用默认数据库
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Map<String, Object>> fetch() {
|
|
|
String sql = "";
|
|
|
if ("number".equals(filterFieldType)) {
|
|
|
Long lngTemp = Long.parseLong(start) + Long.parseLong(size);
|
|
|
String temp = lngTemp.toString();
|
|
|
|
|
|
sql = "select * from " + table +
|
|
|
" where " + filterField + ">=" + start + " and " + filterField + "<" + temp + " and " +
|
|
|
filterField + "<=" + end;
|
|
|
|
|
|
start = temp;
|
|
|
|
|
|
} else if ("date".equals(filterFieldType)) {
|
|
|
Date date = DateUtil.toDateFromTime(start);
|
|
|
java.util.Calendar calendar = java.util.Calendar.getInstance();
|
|
|
calendar.setTime(date);
|
|
|
calendar.add(java.util.Calendar.HOUR_OF_DAY, Integer.parseInt(size));
|
|
|
String temp = DateUtil.toString(calendar.getTime(), DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
|
|
|
|
|
|
sql = "select * from " + table +
|
|
|
" where " + filterField + ">=" + DbKit.use().getLongDate(start) + " and " + filterField + "<" + DbKit.use().getLongDate(temp) + " and " +
|
|
|
filterField + "<=" + DbKit.use().getLongDate(end);
|
|
|
|
|
|
start = temp;
|
|
|
} else {
|
|
|
logger.warn("不支持的过滤字段类型");
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return jdbcTemplate.queryForList(sql);
|
|
|
}
|