|
@@ -0,0 +1,393 @@
|
|
|
+package com.gyee.healthmodel.init;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.gyee.common.contant.ContantXk;
|
|
|
+import com.gyee.common.model.PointData;
|
|
|
+import com.gyee.healthmodel.model.auto.*;
|
|
|
+import com.gyee.healthmodel.service.auto.IProBasicEquipmentPointService;
|
|
|
+import com.gyee.healthmodel.service.auto.IProBasicPowerstationPointService;
|
|
|
+import com.gyee.healthmodel.service.auto.IProEconWtPowerCurveFittingService;
|
|
|
+import com.gyee.healthmodel.util.DateUtils;
|
|
|
+import com.gyee.healthmodel.util.IRealTimeDataBaseUtil;
|
|
|
+import com.gyee.healthmodel.util.RealTimeDataBaseFactory;
|
|
|
+import com.gyee.healthmodel.util.redis.RedisService;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class InitialRedis {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IProBasicPowerstationPointService proBasicPowerstationPointService;
|
|
|
+ @Resource
|
|
|
+ private IProBasicEquipmentPointService proBasicEquipmentPointService;
|
|
|
+ @Resource
|
|
|
+ private IProEconWtPowerCurveFittingService proEconWtPowerCurveFittingService;
|
|
|
+ @Resource
|
|
|
+ private RedisService redisService;
|
|
|
+ public static Map<String, Map<Double, ProEconWtPowerCurveFitting>> wpcmap = new HashMap<>();
|
|
|
+
|
|
|
+
|
|
|
+ IRealTimeDataBaseUtil realApiUtil = RealTimeDataBaseFactory.createRealTimeDataBase();
|
|
|
+
|
|
|
+
|
|
|
+ public void initialRedisAll() throws Exception {
|
|
|
+
|
|
|
+ System.out.println("初始化开始!");
|
|
|
+ intialWpScatter();
|
|
|
+ intialPjScatter();
|
|
|
+ intialLnScatter();
|
|
|
+ intialWtScatter();
|
|
|
+ System.out.println("初始化完成!");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void intialWindturbinepowercurvefitting() throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<ProEconWtPowerCurveFitting> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.orderByAsc("windturbine_id").orderByAsc("speed");
|
|
|
+ List<ProEconWtPowerCurveFitting> wpclist = proEconWtPowerCurveFittingService.list(queryWrapper);
|
|
|
+
|
|
|
+ if (!wpclist.isEmpty()) {
|
|
|
+ for (ProEconWtPowerCurveFitting wc : wpclist) {
|
|
|
+ if (wpcmap.containsKey(wc.getWindturbineId())) {
|
|
|
+ Map<Double, ProEconWtPowerCurveFitting> map = wpcmap.get(wc.getWindturbineId());
|
|
|
+ map.put(wc.getSpeed(), wc);
|
|
|
+ } else {
|
|
|
+ Map<Double, ProEconWtPowerCurveFitting> map = new HashMap<Double, ProEconWtPowerCurveFitting>();
|
|
|
+ map.put(wc.getSpeed(), wc);
|
|
|
+ wpcmap.put(wc.getWindturbineId(), map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ redisService.set("wpcmap", JSON.toJSONString(wpcmap));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void intialWpScatter() throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+
|
|
|
+ int month=cal.get(Calendar.MONTH)+1;
|
|
|
+
|
|
|
+
|
|
|
+ cal.set(Calendar.MONTH, 0);
|
|
|
+
|
|
|
+ for(int j=0;j<month;j++)
|
|
|
+ {
|
|
|
+ List<List<Double>> vos = new ArrayList<List<Double>>();
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
+ Date beginDate = cal.getTime();
|
|
|
+ Date endDate =null;
|
|
|
+ if(month-1==cal.get(Calendar.MONTH))
|
|
|
+ {
|
|
|
+ cal = Calendar.getInstance();
|
|
|
+ //cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ cal.add(Calendar.MONTH,1);;
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(ProBasicPowerstation wp:CacheContext.wpls)
|
|
|
+ {
|
|
|
+ String wpId=wp.getId();
|
|
|
+ ProBasicPowerstationPoint gl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
|
|
|
+ ProBasicPowerstationPoint fs = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSPJFS);
|
|
|
+
|
|
|
+ int daynum = DateUtils.daysDiff(beginDate, endDate);
|
|
|
+ long pried = 600 ;
|
|
|
+ long count = 6 * 24 * daynum;
|
|
|
+
|
|
|
+ DecimalFormat dcmFmt = new DecimalFormat("0.00");
|
|
|
+ List<PointData> gls = realApiUtil.getHistoryDatasSnap(gl, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+ List<PointData> fss = realApiUtil.getHistoryDatasSnap(fs, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+
|
|
|
+ if (!gls.isEmpty() && !fss.isEmpty()) {
|
|
|
+ for (int i = 0; i < fss.size(); i++) {
|
|
|
+
|
|
|
+ List<Double> ds = new ArrayList<Double>();
|
|
|
+
|
|
|
+ double f = fss.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ f = gls.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ vos.add(ds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // cal.add(Calendar.MONTH,1);
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("scatter_").append(wpId).append("_").append(j+1);
|
|
|
+ redisService.set(String.valueOf(sb), JSON.toJSONString(vos));
|
|
|
+ System.out.println(String.valueOf(sb.append("完成")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void intialPjScatter() throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+
|
|
|
+ int month=cal.get(Calendar.MONTH)+1;
|
|
|
+
|
|
|
+
|
|
|
+ cal.set(Calendar.MONTH, 0);
|
|
|
+
|
|
|
+ for(int j=0;j<month;j++)
|
|
|
+ {
|
|
|
+ List<List<Double>> vos = new ArrayList<List<Double>>();
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
+ Date beginDate = cal.getTime();
|
|
|
+ Date endDate =null;
|
|
|
+ if(month-1==cal.get(Calendar.MONTH))
|
|
|
+ {
|
|
|
+ cal = Calendar.getInstance();
|
|
|
+ //cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ cal.add(Calendar.MONTH,1);;
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(ProBasicProject pj:CacheContext.projects)
|
|
|
+ {
|
|
|
+ String wpId=pj.getId();
|
|
|
+ ProBasicPowerstationPoint gl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
|
|
|
+ ProBasicPowerstationPoint fs = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSPJFS);
|
|
|
+
|
|
|
+ int daynum = DateUtils.daysDiff(beginDate, endDate);
|
|
|
+ long pried = 600 ;
|
|
|
+ long count = 6 * 24 * daynum;
|
|
|
+
|
|
|
+ DecimalFormat dcmFmt = new DecimalFormat("0.00");
|
|
|
+ List<PointData> gls = realApiUtil.getHistoryDatasSnap(gl, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+ List<PointData> fss = realApiUtil.getHistoryDatasSnap(fs, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+
|
|
|
+ if (!gls.isEmpty() && !fss.isEmpty()) {
|
|
|
+ for (int i = 0; i < fss.size(); i++) {
|
|
|
+
|
|
|
+ List<Double> ds = new ArrayList<Double>();
|
|
|
+
|
|
|
+ double f = fss.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ f = gls.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ vos.add(ds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // cal.add(Calendar.MONTH,1);
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("scatter_").append(wpId).append("_").append(j+1);
|
|
|
+ redisService.set(String.valueOf(sb), JSON.toJSONString(vos));
|
|
|
+ System.out.println(String.valueOf(sb.append("完成")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void intialLnScatter() throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+
|
|
|
+ int month=cal.get(Calendar.MONTH)+1;
|
|
|
+
|
|
|
+
|
|
|
+ cal.set(Calendar.MONTH, 0);
|
|
|
+
|
|
|
+ for(int j=0;j<month;j++)
|
|
|
+ {
|
|
|
+ List<List<Double>> vos = new ArrayList<List<Double>>();
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
+ Date beginDate = cal.getTime();
|
|
|
+ Date endDate =null;
|
|
|
+ if(month-1==cal.get(Calendar.MONTH))
|
|
|
+ {
|
|
|
+ cal = Calendar.getInstance();
|
|
|
+ //cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ cal.add(Calendar.MONTH,1);;
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(ProBasicLine wp:CacheContext.lines)
|
|
|
+ {
|
|
|
+ String wpId=wp.getId();
|
|
|
+ ProBasicPowerstationPoint gl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
|
|
|
+ ProBasicPowerstationPoint fs = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSPJFS);
|
|
|
+
|
|
|
+ int daynum = DateUtils.daysDiff(beginDate, endDate);
|
|
|
+ long pried = 600 ;
|
|
|
+ long count = 6 * 24 * daynum;
|
|
|
+
|
|
|
+ DecimalFormat dcmFmt = new DecimalFormat("0.00");
|
|
|
+ List<PointData> gls = realApiUtil.getHistoryDatasSnap(gl, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+ List<PointData> fss = realApiUtil.getHistoryDatasSnap(fs, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+
|
|
|
+ if (!gls.isEmpty() && !fss.isEmpty()) {
|
|
|
+ for (int i = 0; i < fss.size(); i++) {
|
|
|
+
|
|
|
+ List<Double> ds = new ArrayList<Double>();
|
|
|
+
|
|
|
+ double f = fss.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ f = gls.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ vos.add(ds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // cal.add(Calendar.MONTH,1);
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("scatter_").append(wpId).append("_").append(j+1);
|
|
|
+ redisService.set(String.valueOf(sb), JSON.toJSONString(vos));
|
|
|
+ System.out.println(String.valueOf(sb.append("完成")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void intialWtScatter() throws Exception {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
+ cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ cal.set(Calendar.MINUTE, 0);
|
|
|
+ cal.set(Calendar.SECOND, 0);
|
|
|
+
|
|
|
+ int month=cal.get(Calendar.MONTH)+1;
|
|
|
+
|
|
|
+
|
|
|
+// cal.set(Calendar.MONTH, 0);
|
|
|
+
|
|
|
+
|
|
|
+ List<List<Double>> vos = new ArrayList<>();
|
|
|
+ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
|
|
|
+ Date beginDate = cal.getTime();
|
|
|
+ Date endDate =null;
|
|
|
+ if(month-1==cal.get(Calendar.MONTH))
|
|
|
+ {
|
|
|
+ cal = Calendar.getInstance();
|
|
|
+ //cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ cal.add(Calendar.MONTH,1);
|
|
|
+ endDate = cal.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(ProBasicEquipment wt:CacheContext.wtls)
|
|
|
+ {
|
|
|
+ String wpId=wt.getId();
|
|
|
+ ProBasicEquipmentPoint gl = proBasicEquipmentPointService.getEquipmentPoint(wpId, ContantXk.CJ_SSGL);
|
|
|
+ ProBasicEquipmentPoint fs = proBasicEquipmentPointService.getEquipmentPoint(wpId, ContantXk.CJ_SSFS);
|
|
|
+
|
|
|
+ int daynum = DateUtils.daysDiff(beginDate, endDate);
|
|
|
+ long pried = 600 ;
|
|
|
+ long count = 6 * 24 * daynum;
|
|
|
+
|
|
|
+ DecimalFormat dcmFmt = new DecimalFormat("0.00");
|
|
|
+ List<PointData> gls = realApiUtil.getHistoryDatasSnap(gl, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+ List<PointData> fss = realApiUtil.getHistoryDatasSnap(fs, beginDate.getTime() / 1000, endDate.getTime() / 1000, count, pried);
|
|
|
+
|
|
|
+
|
|
|
+ if (!gls.isEmpty() && !fss.isEmpty() && gls.size() ==fss.size()) {
|
|
|
+ for (int i = 0; i < fss.size(); i++) {
|
|
|
+
|
|
|
+ List<Double> ds = new ArrayList<Double>();
|
|
|
+
|
|
|
+ double f = fss.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ f = gls.get(i).getPointValueInDouble();
|
|
|
+ ds.add(Double.valueOf(dcmFmt.format(f)));
|
|
|
+ vos.add(ds);
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ System.out.println("begin-"+DateUtils.format(beginDate));
|
|
|
+ System.out.println("end-"+DateUtils.format(endDate));
|
|
|
+ System.out.println("gl-"+gl.getNemCode());
|
|
|
+ System.out.println("fs-"+fs.getNemCode());
|
|
|
+ System.out.println("glsl-"+gls.size());
|
|
|
+ System.out.println("fssl-"+fss.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ // cal.add(Calendar.MONTH,1);
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append("scatter_").append(wpId).append("_").append(month);
|
|
|
+ redisService.set(String.valueOf(sb), JSON.toJSONString(vos));
|
|
|
+ System.out.println(String.valueOf(sb.append("完成")));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[]args) throws Exception {
|
|
|
+
|
|
|
+// SpringApplication.run(SpringbootStart.class, args);
|
|
|
+//
|
|
|
+// InitialRedis initialRedis=new InitialRedis();
|
|
|
+// //初始化风机拟合功率
|
|
|
+// // initialRedis.intialWindturbinepowercurvefitting();
|
|
|
+//
|
|
|
+// //初始化场站没有散点图
|
|
|
+// initialRedis.intialWpScatter();
|
|
|
+ }
|
|
|
+}
|