NFDataSyncJob.java 2.1 KB
package com.skua.modules.job;

import com.skua.core.context.SpringContextUtils;
import com.skua.core.util.DateUtils;
import com.skua.modules.report.service.IReportDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 发送消息任务
 */

@Slf4j
public class NFDataSyncJob implements Job {

	@Autowired
	private IReportDataService reportDataService;
	//水质水量报表
	private static final String SZSL = "2119ecbf53a1d2d0708258ff67cfd9e1";
	//化验日报
	private static final String HYRB = "9bffaf9187093d6e6a4390e8c56acca8";

	@Override
	public void execute(JobExecutionContext jobExecutionContext) {
		log.info("开始同步昨日恩菲的数据入报表");
		String yesterday = DateUtils.getYesterday();
		JdbcTemplate nfDb = (JdbcTemplate) SpringContextUtils.getBean("nf-db");
		String sql = "select * from day_report_data where update_time like '"+yesterday+"%'";
		List<Map<String, Object>> dataList = nfDb.queryForList(sql);
		if(dataList.size() > 0){
			for (Map<String, Object> map : dataList) {
				String departId = map.get("depart_id").toString();
				String time = map.get("time").toString();
				String itemCode = map.get("item_code").toString();
				String itemValue = map.get("item_value").toString();
				String itemType = map.get("item_type").toString();
				Map<String, String> data = new HashMap<>();
				data.put(itemCode, itemValue);
				data.put("departId", departId);
				data.put("time",yesterday);
				if("szsl".equals(itemType)){
					data.put("reportId", SZSL);
					reportDataService.insertOrUpdateReportData(departId, time, data, SZSL);
				}else if("hyrb".equals(itemType)){
					data.put("reportId", HYRB);
					reportDataService.insertOrUpdateReportData(departId, time, data, HYRB);
				}else {
					log.info("恩菲【"+itemType+"】类型数据未进行数据同步");
				}
			}
		}
		log.info("同步昨日恩菲的数据入报表完成");
	}

}