|  | @@ -1,13 +1,5 @@
 | 
											
												
													
														|  |  package com.steerinfo.ems.emsetiming.service.impl;
 |  |  package com.steerinfo.ems.emsetiming.service.impl;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -import com.steerinfo.framework.mapper.IBaseMapper;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.framework.service.impl.BaseServiceImpl;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.rtdb.Client;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.rtdb.ClientConfig;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.rtdb.ClientImpl;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.rtdb.SingleSocketChannelProviderImpl;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.rtdb.SocketChannelProvider;
 |  | 
 | 
											
												
													
														|  | -import com.steerinfo.ems.emsetiming.model.EmsETiming;
 |  | 
 | 
											
												
													
														|  |  import com.alibaba.fastjson.JSONObject;
 |  |  import com.alibaba.fastjson.JSONObject;
 | 
											
												
													
														|  |  import com.steerinfo.ems.Utils.EmsEAiUtil;
 |  |  import com.steerinfo.ems.Utils.EmsEAiUtil;
 | 
											
												
													
														|  |  import com.steerinfo.ems.emseaihoursumtab1.mapper.EmsEAiHourSumTab1Mapper;
 |  |  import com.steerinfo.ems.emseaihoursumtab1.mapper.EmsEAiHourSumTab1Mapper;
 | 
											
										
											
												
													
														|  | @@ -15,24 +7,22 @@ import com.steerinfo.ems.emseaihoursumtab1.model.EmsEAiHourSumTab1;
 | 
											
												
													
														|  |  import com.steerinfo.ems.emseaihoursumtab1org.mapper.EmsEAiHourSumTab1OrgMapper;
 |  |  import com.steerinfo.ems.emseaihoursumtab1org.mapper.EmsEAiHourSumTab1OrgMapper;
 | 
											
												
													
														|  |  import com.steerinfo.ems.emseaihoursumtab1org.model.EmsEAiHourSumTab1Org;
 |  |  import com.steerinfo.ems.emseaihoursumtab1org.model.EmsEAiHourSumTab1Org;
 | 
											
												
													
														|  |  import com.steerinfo.ems.emsetiming.mapper.EmsETimingMapper;
 |  |  import com.steerinfo.ems.emsetiming.mapper.EmsETimingMapper;
 | 
											
												
													
														|  | 
 |  | +import com.steerinfo.ems.emsetiming.model.EmsETiming;
 | 
											
												
													
														|  |  import com.steerinfo.ems.emsetiming.service.IEmsETimingService;
 |  |  import com.steerinfo.ems.emsetiming.service.IEmsETimingService;
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -import java.math.BigDecimal;
 |  | 
 | 
											
												
													
														|  | -import java.text.SimpleDateFormat;
 |  | 
 | 
											
												
													
														|  | -import java.util.ArrayList;
 |  | 
 | 
											
												
													
														|  | -import java.util.Calendar;
 |  | 
 | 
											
												
													
														|  | -import java.util.Collections;
 |  | 
 | 
											
												
													
														|  | -import java.util.Date;
 |  | 
 | 
											
												
													
														|  | -import java.util.HashMap;
 |  | 
 | 
											
												
													
														|  | -import java.util.List;
 |  | 
 | 
											
												
													
														|  | -import java.util.Map;
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | 
 |  | +import com.steerinfo.ems.rttable.mapper.RttableMapper;
 | 
											
												
													
														|  | 
 |  | +import com.steerinfo.ems.rttable.model.Rttable;
 | 
											
												
													
														|  | 
 |  | +import com.steerinfo.framework.mapper.IBaseMapper;
 | 
											
												
													
														|  | 
 |  | +import com.steerinfo.framework.service.impl.BaseServiceImpl;
 | 
											
												
													
														|  | 
 |  | +import com.steerinfo.rtdb.*;
 | 
											
												
													
														|  |  import org.slf4j.Logger;
 |  |  import org.slf4j.Logger;
 | 
											
												
													
														|  |  import org.slf4j.LoggerFactory;
 |  |  import org.slf4j.LoggerFactory;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.stereotype.Service;
 |  |  import org.springframework.stereotype.Service;
 | 
											
												
													
														|  |  import org.springframework.transaction.annotation.Transactional;
 |  |  import org.springframework.transaction.annotation.Transactional;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import java.text.SimpleDateFormat;
 | 
											
												
													
														|  | 
 |  | +import java.util.*;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  /**
 |  |  /**
 | 
											
												
													
														|  |   * EmsETiming服务实现:
 |  |   * EmsETiming服务实现:
 | 
											
												
													
														|  |   * @author generator
 |  |   * @author generator
 | 
											
										
											
												
													
														|  | @@ -60,6 +50,9 @@ public class EmsETimingServiceImpl extends BaseServiceImpl<EmsETiming, String> i
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private EmsEAiHourSumTab1OrgMapper emsEAiHourSumTab1OrgMapper;
 |  |      private EmsEAiHourSumTab1OrgMapper emsEAiHourSumTab1OrgMapper;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +	@Autowired
 | 
											
												
													
														|  | 
 |  | +	private RttableMapper rttableMapper;
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  |      protected IBaseMapper<EmsETiming, String> getMapper() {
 |  |      protected IBaseMapper<EmsETiming, String> getMapper() {
 | 
											
												
													
														|  |          return emsETimingMapper;
 |  |          return emsETimingMapper;
 | 
											
										
											
												
													
														|  | @@ -215,4 +208,81 @@ public class EmsETimingServiceImpl extends BaseServiceImpl<EmsETiming, String> i
 | 
											
												
													
														|  |              throw new RuntimeException("出错了:" + e.getMessage());
 |  |              throw new RuntimeException("出错了:" + e.getMessage());
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	@Override
 | 
											
												
													
														|  | 
 |  | +	public void getETimingTenData() {
 | 
											
												
													
														|  | 
 |  | +		int addSize = 0;
 | 
											
												
													
														|  | 
 |  | +		List<Rttable> rttableList = rttableMapper.selectElectricAltId();
 | 
											
												
													
														|  | 
 |  | +		if(rttableList!=null && rttableList.size()>0) {
 | 
											
												
													
														|  | 
 |  | +			try {
 | 
											
												
													
														|  | 
 |  | +				Calendar cal = Calendar.getInstance();
 | 
											
												
													
														|  | 
 |  | +				cal.set(Calendar.SECOND, 0);
 | 
											
												
													
														|  | 
 |  | +				int mimute = (cal.get(Calendar.MINUTE) + 1) / 15 * 15;
 | 
											
												
													
														|  | 
 |  | +				cal.set(Calendar.MINUTE, mimute);
 | 
											
												
													
														|  | 
 |  | +				String clock = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(cal.getTime());
 | 
											
												
													
														|  | 
 |  | +				EmsETiming e = new EmsETiming();
 | 
											
												
													
														|  | 
 |  | +				e.setClock(clock);
 | 
											
												
													
														|  | 
 |  | +				String[] tens;
 | 
											
												
													
														|  | 
 |  | +				String tag;
 | 
											
												
													
														|  | 
 |  | +				for (Rttable rttable : rttableList) {
 | 
											
												
													
														|  | 
 |  | +					tens = rttable.getNote().split("\\.");
 | 
											
												
													
														|  | 
 |  | +					tag = tens[1];
 | 
											
												
													
														|  | 
 |  | +					e.setVal(tag.substring(1), rttable.getRtvalue().toString(), tag.substring(0, 1).toLowerCase());
 | 
											
												
													
														|  | 
 |  | +					addSize ++ ;
 | 
											
												
													
														|  | 
 |  | +				}
 | 
											
												
													
														|  | 
 |  | +				e.setInsertTime(new Date());
 | 
											
												
													
														|  | 
 |  | +				if (emsETimingMapper.updateByPrimaryKeySelective(e) == 0) {
 | 
											
												
													
														|  | 
 |  | +					emsETimingMapper.insert(e);
 | 
											
												
													
														|  | 
 |  | +				}
 | 
											
												
													
														|  | 
 |  | +			} catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +				e.printStackTrace();
 | 
											
												
													
														|  | 
 |  | +			} finally {
 | 
											
												
													
														|  | 
 |  | +				logger.info("本次总共新增电力力十分钟数据条数:" + addSize);
 | 
											
												
													
														|  | 
 |  | +			}
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +		try {
 | 
											
												
													
														|  | 
 |  | +		// 1小时30分钟后,更新前一小时表数据(采集器有延时)
 | 
											
												
													
														|  | 
 |  | +		Calendar cal = Calendar.getInstance();
 | 
											
												
													
														|  | 
 |  | +		int minute = cal.get(Calendar.MINUTE);
 | 
											
												
													
														|  | 
 |  | +		if(minute>=13 && minute < 25){
 | 
											
												
													
														|  | 
 |  | +			// 2019-11-20 09
 | 
											
												
													
														|  | 
 |  | +			String clke = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
 | 
											
												
													
														|  | 
 |  | +			cal.add(Calendar.HOUR_OF_DAY, -1);
 | 
											
												
													
														|  | 
 |  | +			// 2019-11-20 08
 | 
											
												
													
														|  | 
 |  | +			String clk = new SimpleDateFormat("yyyy-MM-dd HH").format(cal.getTime());
 | 
											
												
													
														|  | 
 |  | +			// String minuClock = clk+":00"; // 2019-11-20 08:00
 | 
											
												
													
														|  | 
 |  | +			// 2019-11-20 09:00
 | 
											
												
													
														|  | 
 |  | +			String minuClocke = clke+":00";
 | 
											
												
													
														|  | 
 |  | +			//EmsEAiHourSumTab1 eh = emsEAiHourSumTab1Mapper.selectByPrimaryKey(clk);
 | 
											
												
													
														|  | 
 |  | +			//if (eh==null){
 | 
											
												
													
														|  | 
 |  | +				// 从EMS_E_TIMING读取小时准点值
 | 
											
												
													
														|  | 
 |  | +				Map<String, Object> mp = emsETimingMapper.getHourPointVal(minuClocke);
 | 
											
												
													
														|  | 
 |  | +				// 整点数据
 | 
											
												
													
														|  | 
 |  | +				EmsEAiHourSumTab1Org eeho = new EmsEAiHourSumTab1Org();
 | 
											
												
													
														|  | 
 |  | +				if(mp!=null && mp.size()>0){
 | 
											
												
													
														|  | 
 |  | +					eeho.setClock(clke);
 | 
											
												
													
														|  | 
 |  | +					eeho.setInsertTime(new Date());
 | 
											
												
													
														|  | 
 |  | +					eeho = EmsEAiUtil.setValByMap(eeho, mp);
 | 
											
												
													
														|  | 
 |  | +					emsEAiHourSumTab1OrgMapper.insert(eeho);
 | 
											
												
													
														|  | 
 |  | +				}
 | 
											
												
													
														|  | 
 |  | +				// 小时累计值 = 当前小时准点值 - 前1小时小时准点值
 | 
											
												
													
														|  | 
 |  | +				EmsEAiHourSumTab1Org eehol = emsEAiHourSumTab1OrgMapper.selectByPrimaryKey(clk);
 | 
											
												
													
														|  | 
 |  | +				if(eehol==null || eehol.getClock()==null || eehol.getClock().isEmpty() || eeho.getClock()==null || eeho.getClock().isEmpty()){
 | 
											
												
													
														|  | 
 |  | +					logger.error("数据表EMS_E_AI_HOUR_SUM_TAB1_ORG缺少数据:" + clk);
 | 
											
												
													
														|  | 
 |  | +				}else{
 | 
											
												
													
														|  | 
 |  | +					EmsEAiHourSumTab1 eeh = new EmsEAiHourSumTab1();
 | 
											
												
													
														|  | 
 |  | +					eeh.setClock(clk);
 | 
											
												
													
														|  | 
 |  | +					eeh.setInsertTime(new Date());
 | 
											
												
													
														|  | 
 |  | +					eeh = EmsEAiUtil.setVal(eeh, eeho, eehol);
 | 
											
												
													
														|  | 
 |  | +					emsEAiHourSumTab1Mapper.insert(eeh);
 | 
											
												
													
														|  | 
 |  | +				}
 | 
											
												
													
														|  | 
 |  | +			//}
 | 
											
												
													
														|  | 
 |  | +		}
 | 
											
												
													
														|  | 
 |  | +		logger.info(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "-计量点电数据定时获取任务执行完毕");
 | 
											
												
													
														|  | 
 |  | +		// System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "-计量点电数据定时获取任务执行完毕");
 | 
											
												
													
														|  | 
 |  | +	} catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +		//e.printStackTrace();
 | 
											
												
													
														|  | 
 |  | +		throw new RuntimeException("出错了:" + e.getMessage());
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  |  }
 |  |  }
 |