DayDataSyncJob.java 4.8 KB
package com.skua.modules.job;

import com.alibaba.fastjson.JSONObject;
import com.skua.core.util.DateUtils;
import com.skua.modules.alarmtmp.entity.SysFactoryDevice;
import com.skua.modules.alarmtmp.service.ISysFactoryDeviceService;
import com.skua.modules.report.service.IFReportItemvService;
import com.skua.modules.report.service.IReportDataService;
import com.skua.modules.system.datestandard.entity.SysMonitorMetricInfo;
import com.skua.modules.system.datestandard.service.ISysMonitorMetricInfoService;
import com.skua.modules.system.service.IPgService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

@Slf4j
public class DayDataSyncJob implements Job {

	@Autowired
	private IPgService pgService;
	@Autowired
	private ISysMonitorMetricInfoService sysMonitorMetricInfoService;
	@Autowired
	private ISysFactoryDeviceService sysFactoryDeviceService;
	@Autowired
	private IReportDataService reportDataService;
	//水质水量报表ID
	private static final String REPORT_ID = "2119ecbf53a1d2d0708258ff67cfd9e1";

	@Override
	public void execute(JobExecutionContext jobExecutionContext) {
		log.info("开始同步昨天的数据入报表");
		String yesterday = DateUtils.getYesterday();
		List<SysFactoryDevice> deviceList = sysFactoryDeviceService.getList();
		if(deviceList.size() > 0){
			Map<String, String> tagMap = new HashMap<>();
			List<SysMonitorMetricInfo> list = sysMonitorMetricInfoService.getTagDataList();
			for (SysMonitorMetricInfo monitorMetricInfo : list) {
				tagMap.put(monitorMetricInfo.getMetricUidTag(),monitorMetricInfo.getId());
			}
			for (SysFactoryDevice sysFactoryDevice : deviceList) {
				String departId = sysFactoryDevice.getDepartId();
				String deviceId = sysFactoryDevice.getDeviceId();
				String fields = "";
				for (SysMonitorMetricInfo monitorMetricInfo : list) {
					if(departId.equals(monitorMetricInfo.getDepartId())){
						fields = fields + monitorMetricInfo.getId().toString() + ",";
					}
				}
				if(!"".equals(fields)){
					Map<String, Object> dataMap = pgService.queryDayData(fields, deviceId, yesterday);
					Map<String, String> data = new HashMap<>();
					if(tagMap.get("CSLL")!=null){
						data.put("CSL", String.valueOf(24*Double.parseDouble(dataMap.get(tagMap.get("CSLL")).toString())));
					}else{
						data.put("CSL", "");
					}
					if(tagMap.get("JSLL")!=null){
						data.put("JSL", String.valueOf(24*Double.parseDouble(dataMap.get(tagMap.get("JSLL")).toString())));
					}else{
						data.put("JSL", "");
					}
					if(tagMap.get("CSAD")!=null){
						data.put("CSAD", dataMap.get(tagMap.get("CSAD")).toString());
					}else{
						data.put("CSAD", "");
					}
					if(tagMap.get("CSCOD")!=null){
						data.put("CSCOD", dataMap.get(tagMap.get("CSCOD")).toString());
					}else{
						data.put("CSCOD", "");
					}
					if(tagMap.get("CSPH")!=null){
						data.put("CSPH", dataMap.get(tagMap.get("CSPH")).toString());
					}else{
						data.put("CSPH", "");
					}
					if(tagMap.get("CSSS")!=null){
						data.put("CSSS", dataMap.get(tagMap.get("CSSS")).toString());
					}else{
						data.put("CSSS", "");
					}
					if(tagMap.get("CSTN")!=null){
						data.put("CSTN", dataMap.get(tagMap.get("CSTN")).toString());
					}else{
						data.put("CSTN", "");
					}
					if(tagMap.get("CSZL")!=null){
						data.put("CSZL", dataMap.get(tagMap.get("CSZL")).toString());
					}else{
						data.put("CSZL", "");
					}
					if(tagMap.get("JSAD")!=null){
						data.put("JSAD", dataMap.get(tagMap.get("JSAD")).toString());
					}else{
						data.put("JSAD", "");
					}
					if(tagMap.get("JSCOD")!=null){
						data.put("JSCOD", dataMap.get(tagMap.get("JSCOD")).toString());
					}else{
						data.put("JSCOD", "");
					}
					if(tagMap.get("JSPH")!=null){
						data.put("JSPH", dataMap.get(tagMap.get("JSPH")).toString());
					}else{
						data.put("JSPH", "");
					}
					if(tagMap.get("JSSS")!=null){
						data.put("JSSS", dataMap.get(tagMap.get("JSSS")).toString());
					}else{
						data.put("JSSS", "");
					}
					if(tagMap.get("JSZD")!=null){
						data.put("JSZD", dataMap.get(tagMap.get("JSZD")).toString());
					}else{
						data.put("JSZD", "");
					}
					if(tagMap.get("JSZL")!=null){
						data.put("JSZL", dataMap.get(tagMap.get("JSZL")).toString());
					}else{
						data.put("JSZL", "");
					}
					data.put("departId", departId);
					data.put("reportId", REPORT_ID);
					data.put("time",yesterday);
					reportDataService.insertOrUpdateReportData(departId, yesterday, data, REPORT_ID);
				}
			}
			log.info("同步昨天的数据入报表完成");
		}else {
			log.info("没有需要同步数据的水厂");
		}

	}

}