DayDataSyncJob.java 6.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.getDepartId(),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() + ",";
					}
				}
				if(!"".equals(fields)){
					Map<String, Object> dataMap = pgService.queryDayData(fields, deviceId, yesterday);
					Map<String, String> data = new HashMap<>();
					if(dataMap.size() != 0){
						if(tagMap.get("CSLL-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSLL-"+departId)) != null){
								data.put("CSL", String.valueOf(24*Double.parseDouble(dataMap.get(tagMap.get("CSLL-"+departId)).toString())));
							}else{
								data.put("CSL", "");
							}
						}else{
							data.put("CSL", "");
						}
						if(tagMap.get("JSLL-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSLL-"+departId)) != null){
								data.put("JSL", String.valueOf(24*Double.parseDouble(dataMap.get(tagMap.get("JSLL-"+departId)).toString())));
							}else{
								data.put("JSL", "");
							}
						}else{
							data.put("JSL", "");
						}
						if(tagMap.get("CSNH3N-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSNH3N-"+departId)) != null){
								data.put("CSAD", dataMap.get(tagMap.get("CSNH3N-"+departId)).toString());
							}else{
								data.put("CSAD", "");
							}
						}else{
							data.put("CSAD", "");
						}
						if(tagMap.get("CSCOD-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSCOD-"+departId)) != null){
								data.put("CSCOD", dataMap.get(tagMap.get("CSCOD-"+departId)).toString());
							}else{
								data.put("CSCOD", "");
							}

						}else{
							data.put("CSCOD", "");
						}
						if(tagMap.get("CSPH-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSPH-"+departId)) != null){
								data.put("CSPH", dataMap.get(tagMap.get("CSPH-"+departId)).toString());
							}else{
								data.put("CSPH", "");
							}
						}else{
							data.put("CSPH", "");
						}
						if(tagMap.get("CSSS-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSSS-"+departId)) != null){
								data.put("CSSS", "");
							}else{
								data.put("CSSS", dataMap.get(tagMap.get("CSSS-"+departId)).toString());
							}
						}else{
							data.put("CSSS", "");
						}
						if(tagMap.get("CSTN-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSTN-"+departId)) != null){
								data.put("CSTN", dataMap.get(tagMap.get("CSTN-"+departId)).toString());
							}else{
								data.put("CSTN", "");
							}
						}else{
							data.put("CSTN", "");
						}
						if(tagMap.get("CSTP-"+departId)!=null){
							if(dataMap.get(tagMap.get("CSTP-"+departId)) != null){
								data.put("CSZL", dataMap.get(tagMap.get("CSTP-"+departId)).toString());
							}else{
								data.put("CSZL", "");
							}
						}else{
							data.put("CSZL", "");
						}
						if(tagMap.get("JSNH3N-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSNH3N-"+departId)) != null){
								data.put("JSAD", dataMap.get(tagMap.get("JSNH3N-"+departId)).toString());
							}else{
								data.put("JSAD", "");
							}
						}else{
							data.put("JSAD", "");
						}
						if(tagMap.get("JSCOD-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSCOD-"+departId)) != null){
								data.put("JSCOD", dataMap.get(tagMap.get("JSCOD-"+departId)).toString());
							}else{
								data.put("JSCOD", "");
							}
						}else{
							data.put("JSCOD", "");
						}
						if(tagMap.get("JSPH-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSPH-"+departId)) != null){
								data.put("JSPH", dataMap.get(tagMap.get("JSPH-"+departId)).toString());
							}else{
								data.put("JSPH", "");
							}
						}else{
							data.put("JSPH", "");
						}
						if(tagMap.get("JSSS-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSSS-"+departId)) != null){
								data.put("JSSS", dataMap.get(tagMap.get("JSSS-"+departId)).toString());
							}else{
								data.put("JSSS", "");
							}
						}else{
							data.put("JSSS", "");
						}
						if(tagMap.get("JSTN-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSTN-"+departId)) != null){
								data.put("JSZD", dataMap.get(tagMap.get("JSTN-"+departId)).toString());
							}else{
								data.put("JSZD", "");
							}
						}else{
							data.put("JSZD", "");
						}
						if(tagMap.get("JSTP-"+departId)!=null){
							if(dataMap.get(tagMap.get("JSTP-"+departId)) != null){
								data.put("JSZL", dataMap.get(tagMap.get("JSTP-"+departId)).toString());
							}else{
								data.put("JSZL", "");
							}
						}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("没有需要同步数据的水厂");
		}

	}

}