|
@ -14,12 +14,15 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import javax.sql.DataSource;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
@ -39,25 +42,37 @@ public class ExtractDataService {
|
|
|
@Value("${es.index}")
|
|
|
private String esIndex;
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;
|
|
|
@Autowired
|
|
|
private ElastricSearchSave elastricSearchSave;//只读库的jdbcTemplate
|
|
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
private Logger logger= LoggerFactory.getLogger(ExtractDataService.class);
|
|
|
/**
|
|
|
* 构造注入只读库的数据源
|
|
|
*
|
|
|
* @param dataSource
|
|
|
*/
|
|
|
@Autowired
|
|
|
public void JdbcTemplateInit(
|
|
|
@Qualifier(value = "primaryRead") DataSource dataSource) {
|
|
|
this.jdbcTemplate = new JdbcTemplate();
|
|
|
this.jdbcTemplate.setDataSource(dataSource);
|
|
|
}
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(ExtractDataService.class);
|
|
|
|
|
|
public void extractOneDate(String date) {
|
|
|
String sql = "select * from wlyy_quota_result w where w.level1_type=1 and w.quato_code !=18 and w.quato_code !=19 and quota_date='" + date + "' ";
|
|
|
List<WlyyQuotaResult> quotaResults = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyyQuotaResult.class));
|
|
|
save2es(quotaResults, date, null);
|
|
|
logger.info("date:"+date+" all quota success");
|
|
|
save2es(quotaResults, null, date);
|
|
|
logger.info("date:" + date + " all quota success");
|
|
|
}
|
|
|
|
|
|
|
|
|
public void extractOneDateWithId(String date, String quotaId) {
|
|
|
String sql = "select * from wlyy_quota_result w where w.level1_type=1 and w.quato_code !=18 and w.quato_code !=19 and quota_date='" + date + "' and quato_code='" + quotaId + "'";
|
|
|
List<WlyyQuotaResult> quotaResults = jdbcTemplate.query(sql, new BeanPropertyRowMapper(WlyyQuotaResult.class));
|
|
|
save2es(quotaResults, date, quotaId);
|
|
|
logger.info("date:"+date+",quotaId:"+quotaId+" success");
|
|
|
save2es(quotaResults, quotaId,date );
|
|
|
logger.info("date:" + date + ",quotaId:" + quotaId + " success");
|
|
|
}
|
|
|
|
|
|
public void extractDate2Date(String start, String end) throws Exception {
|