|
@@ -361,9 +361,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
lineInfoDayService.saveOrUpdateBatch(lineInfos);
|
|
|
}
|
|
|
|
|
|
- public void calcLineSwGWCyDlSameDay(Date time) {
|
|
|
+ public void calcLineSwGWCyDlSameDay() {
|
|
|
//date当天零点
|
|
|
- DateTime time0 = DateUtil.beginOfDay(time);
|
|
|
+ DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
|
|
|
|
|
|
List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
|
|
|
Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
|
|
@@ -418,9 +418,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
stationInfoDayService.saveOrUpdateBatch(byDate);
|
|
|
}
|
|
|
|
|
|
- public void calcStationZhcyRfDlSameDay(Date time) {
|
|
|
+ public void calcStationZhcyRfDlSameDay() {
|
|
|
//date当天零点
|
|
|
- DateTime time0 = DateUtil.beginOfDay(time);
|
|
|
+ DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
|
|
|
|
|
|
QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
|
|
|
wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
|
|
@@ -493,9 +493,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
stationInfoDayService.saveOrUpdateBatch(byDate);
|
|
|
}
|
|
|
|
|
|
- public void calcStationSwGwCyDlSameDay(Date time) {
|
|
|
+ public void calcStationSwGwCyDlSameDay() {
|
|
|
//date当天零点
|
|
|
- DateTime time0 = DateUtil.beginOfDay(time);
|
|
|
+ DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
|
|
|
|
|
|
List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
|
|
|
List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
|
|
@@ -665,9 +665,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void calcLineRfdlSameDay(Date time) {
|
|
|
+ public void calcLineRfdlSameDay() {
|
|
|
//date当天零点
|
|
|
- DateTime time0 = DateUtil.beginOfDay(time);
|
|
|
+ DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
|
|
|
|
|
|
List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
|
|
|
entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
|
|
@@ -2009,9 +2009,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void writeReportPoolSameDay(Date time) {
|
|
|
+ public void writeReportPoolSameDay() {
|
|
|
//date当天零点
|
|
|
- DateTime time0 = DateUtil.beginOfDay(time);
|
|
|
+ DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
|
|
|
DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
|
|
|
DateTime beginOfYear = DateUtil.beginOfYear(time0);
|
|
|
|
|
@@ -2031,6 +2031,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
|
|
|
wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
|
|
|
List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
|
|
|
+ wrapperRp = new QueryWrapper<>();
|
|
|
+ wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
|
|
|
+ ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
|
|
|
|
|
|
StationInfoDay day, month, year;
|
|
|
if (pools.isEmpty()) {
|
|
@@ -2056,6 +2059,16 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
}
|
|
|
}
|
|
|
reportIndicatorPoolService.saveOrUpdateBatch(pools);
|
|
|
+ if (poolsCompany == null) {
|
|
|
+ poolsCompany = new ProEconReportIndicatorPool();
|
|
|
+ poolsCompany.setRecordDate(time0);
|
|
|
+ poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
|
|
|
+ poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
|
|
|
+ poolSetValueDl(poolsCompany, pools);
|
|
|
+ } else {
|
|
|
+ poolSetValueDl(poolsCompany, pools);
|
|
|
+ }
|
|
|
+ reportIndicatorPoolService.saveOrUpdate(poolsCompany);
|
|
|
}
|
|
|
|
|
|
public void poolSetValueDl1(ProEconReportIndicatorPool pool, StationInfoDay day, StationInfoDay month, StationInfoDay year) {
|
|
@@ -2094,6 +2107,25 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
pool.setNzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
|
|
|
}
|
|
|
|
|
|
+ public void poolSetValueDl(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
|
|
|
+ ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
|
|
|
+ pool.setRfdldb(p.getRfdldb());
|
|
|
+ pool.setRswdldb(p.getRswdldb());
|
|
|
+ pool.setRgwgwdldb(p.getRgwgwdldb());
|
|
|
+ pool.setRfdcydldb(p.getRfdcydldb());
|
|
|
+ pool.setRzhcydldb(p.getRzhcydldb());
|
|
|
+ pool.setYfdldb(p.getYfdldb());
|
|
|
+ pool.setYswdldb(p.getYswdldb());
|
|
|
+ pool.setYgwgwdldb(p.getYgwgwdldb());
|
|
|
+ pool.setYfdcydldb(p.getYfdcydldb());
|
|
|
+ pool.setYzhcydldb(p.getYzhcydldb());
|
|
|
+ pool.setNfdldb(p.getNfdldb());
|
|
|
+ pool.setNswdldb(p.getNswdldb());
|
|
|
+ pool.setNgwgwdldb(p.getNgwgwdldb());
|
|
|
+ pool.setNfdcydldb(p.getNfdcydldb());
|
|
|
+ pool.setNzhcydldb(p.getNzhcydldb());
|
|
|
+ }
|
|
|
+
|
|
|
public void writeReportPoolProject(Date date) {
|
|
|
//date当天零点
|
|
|
DateTime time = DateUtil.beginOfDay(date);
|
|
@@ -2165,9 +2197,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void writeReportPoolProjectSameDay(Date time) {
|
|
|
+ public void writeReportPoolProjectSameDay() {
|
|
|
//date当天零点
|
|
|
- DateTime time0 = DateUtil.beginOfDay(time);
|
|
|
+ DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
|
|
|
DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
|
|
|
DateTime beginOfYear = DateUtil.beginOfYear(time0);
|
|
|
|
|
@@ -2455,9 +2487,17 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public void calcRealtimeTurbineZt() {
|
|
|
- DateTime date = DateUtil.date();
|
|
|
+ DateTime date0 = DateUtil.date();
|
|
|
+ boolean isOnMin = false;
|
|
|
+ //分钟变化
|
|
|
+ if (CalcCache.minuteNow.minute() != date0.minute()) {
|
|
|
+ date0 = DateUtil.beginOfMinute(date0);
|
|
|
+ CalcCache.minuteNow = date0;
|
|
|
+ isOnMin = true;
|
|
|
+ }
|
|
|
+ DateTime date = date0;
|
|
|
+
|
|
|
List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
|
|
|
List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
|
|
|
turbineZt.addAll(turbineAizt);
|
|
@@ -2542,15 +2582,110 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
|
|
|
List<PointData> dataList = turbineZt.stream().map(zt -> {
|
|
|
PointData data = zt.getPointDatas().get(0);
|
|
|
- data.setTs(DateUtil.date().getTime());
|
|
|
+ data.setTs(date.getTime());
|
|
|
data.setTagName(entityMxzt.get(zt.getTurbineId()));
|
|
|
return data;
|
|
|
}).collect(Collectors.toList());
|
|
|
- adapter.writeHistoryBatch(taosUri(), dataList);
|
|
|
- ThreadUtil.sleep(1000);
|
|
|
+ if (isOnMin) {
|
|
|
+ adapter.writeHistoryBatch(taosUri(), dataList);
|
|
|
+ } else {
|
|
|
+ List<PointData> collect = dataList.stream().filter(d -> {
|
|
|
+ if (Objects.equals(CalcCache.statusCache.get(d.getTagName()), d.getValue())) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ CalcCache.statusCache.put(d.getTagName(), d.getValue());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ adapter.writeHistoryBatch(taosUri(), collect);
|
|
|
+ }
|
|
|
}
|
|
|
//此处加公式
|
|
|
|
|
|
+ // 计算每种状态的总持续时间
|
|
|
+ public void calcTurbineStateMin(Date date) {
|
|
|
+ //date当天零点
|
|
|
+ DateTime time = DateUtil.beginOfDay(date);
|
|
|
+ //date昨天零点
|
|
|
+ DateTime time0 = DateUtil.offsetDay(time, -1);
|
|
|
+
|
|
|
+ List<PointInfo> entityMxzt = getEntity("MXZT", "turbine");
|
|
|
+ getRawDataByEntity(entityMxzt, taosUri(), time0, time);
|
|
|
+
|
|
|
+ Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entityMxzt);
|
|
|
+
|
|
|
+ for (PointInfo info : entityMxzt) {
|
|
|
+ TurbineInfoDay infoDay = byDate.get(info.getTurbineId());
|
|
|
+ Map<Double, Long> durations = calculateStateDurations(info.getPointDatas());
|
|
|
+ infoDay.setDjMin(durations.getOrDefault(0.0, 0L) / 60000.0);
|
|
|
+ infoDay.setTjMin(durations.getOrDefault(1.0, 0L) / 60000.0);
|
|
|
+ infoDay.setYxMin(durations.getOrDefault(2.0, 0L) / 60000.0);
|
|
|
+ infoDay.setGzMin(durations.getOrDefault(4.0, 0L) / 60000.0);
|
|
|
+ infoDay.setJxMin(durations.getOrDefault(6.0, 0L) / 60000.0);
|
|
|
+ infoDay.setXdMin(durations.getOrDefault(8.0, 0L) / 60000.0);
|
|
|
+ infoDay.setLxMin(durations.getOrDefault(12.0, 0L) / 60000.0);
|
|
|
+ }
|
|
|
+ turbineInfoDayService.saveOrUpdateBatch(byDate.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ public Map<Double, Long> calculateStateDurations(List<PointData> datas) {
|
|
|
+ if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
|
|
|
+
|
|
|
+ Map<Double, Long> durations = new HashMap<>();
|
|
|
+ double prevState = datas.get(0).getValue(); // 初始状态
|
|
|
+ long prevTs = datas.get(0).getTs(); // 初始时间戳
|
|
|
+
|
|
|
+ PointData current;
|
|
|
+ double currentState;
|
|
|
+ long currentTs;
|
|
|
+ for (int i = 1; i < datas.size(); i++) {
|
|
|
+ current = datas.get(i);
|
|
|
+ currentState = current.getValue();
|
|
|
+ currentTs = current.getTs();
|
|
|
+
|
|
|
+ if (currentState != prevState) {
|
|
|
+ // 当状态变化时,计算前一个状态的持续时间并更新map
|
|
|
+ durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
|
|
|
+ prevState = currentState;
|
|
|
+ prevTs = currentTs;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
|
|
|
+ durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
|
|
|
+ return durations;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
|
|
|
+ for (PointInfo info : entity) {
|
|
|
+ List<PointData> snap = adapter.getHistoryRaw(uri, info.getPointKey(), start.getTime(), end.getTime());
|
|
|
+ ThreadUtil.sleep(5);
|
|
|
+ info.setPointDatas(snap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 主函数或测试方法(如果需要)
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Double b = 2.0;
|
|
|
+ double c = 2.0;
|
|
|
+ System.out.println(b == c);
|
|
|
+ Double d = Double.valueOf(c);
|
|
|
+ System.out.println(Objects.equals(b, c));
|
|
|
+ System.out.println(Objects.equals(d, b));
|
|
|
+ System.out.println(Objects.equals(null, null));
|
|
|
+
|
|
|
+
|
|
|
+ List<PointData> points = new ArrayList<>();
|
|
|
+ points.add(new PointData(1000, 1));
|
|
|
+ points.add(new PointData(1500, 2));
|
|
|
+ points.add(new PointData(2000, 1));
|
|
|
+ points.add(new PointData(2500, 3));
|
|
|
+
|
|
|
+// Map<Integer, Long> durations = calculateStateDurations(points);
|
|
|
+// for (Map.Entry<Integer, Long> entry : durations.entrySet()) {
|
|
|
+// System.out.println("State " + entry.getKey() + ": " + entry.getValue() + "ms");
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
public List<PointInfo> getLatest(String uniformCode, String institutionType) {
|
|
|
List<PointInfo> entity = getEntity(uniformCode, institutionType);
|
|
|
String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
|
|
@@ -2970,6 +3105,23 @@ public class JavaFunctionJobHandler extends IJobHandler {
|
|
|
if (b == null) b = 0.0;
|
|
|
return a + b;
|
|
|
}
|
|
|
+
|
|
|
+ public double calcQfzt(double ssgl, double zsgl) {
|
|
|
+ double qfzt, ratioll;
|
|
|
+ ratioll = zsgl != 0 ? (zsgl - ssgl) / zsgl : 0;
|
|
|
+ if (ratioll < 0.05) {
|
|
|
+ qfzt = 0;
|
|
|
+ } else if (ratioll < 0.1) {
|
|
|
+ qfzt = 1;
|
|
|
+ } else if (ratioll < 0.2) {
|
|
|
+ qfzt = 2;
|
|
|
+ } else if (ratioll < 0.4) {
|
|
|
+ qfzt = 3;
|
|
|
+ } else {
|
|
|
+ qfzt = 4;
|
|
|
+ }
|
|
|
+ return qfzt;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|