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

import com.skua.common.constant.ReportConstant;
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;

	/**
	 * 若参数变量名修改 QuartzJobController中也需对应修改
	 */
	private String parameter;

	public void setParameter(String parameter) {
		this.parameter = parameter;
	}

	@Override
	public void execute(JobExecutionContext jobExecutionContext) {
		String yesterday = DateUtils.getYesterday();
		if(StringUtils.isNotEmpty(this.parameter)){
			yesterday = this.parameter;
		}
		log.info("开始同步【"+yesterday+"】恩菲的数据入报表");
		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("departId", departId);
				data.put("time",yesterday);
				if("szsl".equals(itemType)){
					data.put(itemCode, itemValue);
					data.put("reportId", ReportConstant.view2119);
					reportDataService.insertOrUpdateReportData(departId, time, data, ReportConstant.view2119);
				}else if("hyrb".equals(itemType)){
					String indexs = "JSCOD,JSAD,JSPH,JSZD,JSZL,JSSS,CSCOD,CSAD,CSPH,CSTN,CSZL,CSSS";
					if(indexs.indexOf(itemCode) > 0){
						data.put(itemCode+"HY", itemValue);
					}else{
						data.put(itemCode, itemValue);
					}
					data.put("reportId", ReportConstant.view9bff);
					reportDataService.insertOrUpdateReportData(departId, time, data, ReportConstant.view9bff);
				}else {
					log.info("恩菲【"+itemType+"】类型数据未进行数据同步");
				}
			}
		}
		log.info("恩菲的数据入报表完成");
	}

}