浏览代码

状态时间接口

xushili 1 年之前
父节点
当前提交
bf41adc63f

+ 3 - 1
power-fitting-JN/src/main/java/com.gyee.power.fitting/common/config/MybatisPlusConfig.java

@@ -12,6 +12,8 @@ public class MybatisPlusConfig {
      */
     @Bean
     public PaginationInterceptor paginationInterceptor() {
-        return new PaginationInterceptor();
+        PaginationInterceptor interceptor = new PaginationInterceptor();
+        interceptor.setDbType(DbType.POSTGRE_SQL);
+        return interceptor;
     }
 }

+ 91 - 17
power-fitting-JN/src/main/java/com.gyee.power.fitting/controller/gf/PhotovoltaicAnalysisController.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gyee.power.fitting.common.result.JsonResult;
 import com.gyee.power.fitting.common.result.ResultCode;
+import com.gyee.power.fitting.model.Device;
 import com.gyee.power.fitting.model.PhotovoltaicAnalysis;
 import com.gyee.power.fitting.model.ProBasicEquipment;
 import com.gyee.power.fitting.model.StateCause;
@@ -19,10 +20,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -55,14 +53,29 @@ public class PhotovoltaicAnalysisController {
             @RequestParam("pageSize") int pageSize) {
 
         List<ProBasicEquipment> equipments = proBasicEquipmentService.getStationMap(type).get(stationId);
-        QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
-        Page<StateCause> page = new Page<>(pageNum, pageSize);
-        scWrapper.in("equipment_id", equipments).gt("start_time", startTime).lt("end_time", endTime);
-        PageMap<StateCause> stateCauses = (PageMap<StateCause>) stateCauseService.page(page, scWrapper);
+        if (equipments == null) return JsonResult.successData(ResultCode.SUCCESS, new HashMap<>());
+        Map<String, String> stringMap = equipments.stream().collect(Collectors.toMap(ProBasicEquipment::getId, ProBasicEquipment::getNemCode));
+        List<String> collect = equipments.stream().map(ProBasicEquipment::getId).collect(Collectors.toList());
+
+        List<String> pageItems = collect.subList(pageSize * (pageNum - 1), Math.min(collect.size(), pageSize * pageNum));
 
-        stateCauses.setRecordMap(stateCauses.getRecords().stream().collect(Collectors.groupingBy(StateCause::getEquipmentId)));
-        stateCauses.setRecords(Collections.emptyList());
-        return JsonResult.successData(ResultCode.SUCCESS, stateCauses);
+        QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
+//        Page<StateCause> page = new Page<>(pageNum, pageSize);
+        scWrapper.eq("state_type", "8种状态").in("equipment_id", pageItems)
+                .gt("start_time", startTime).lt("end_time", endTime);
+        List<StateCause> list = stateCauseService.list(scWrapper);
+        Map<String, List<StateCause>> listMap = list.stream().peek(sc -> sc.setEquipmentId(stringMap.get(sc.getEquipmentId()))).collect(Collectors.groupingBy(StateCause::getEquipmentId));
+//        PageMap<StateCause> stateCauses = (PageMap<StateCause>) stateCauseService.page(page, scWrapper);
+
+//        stateCauses.setRecordMap(stateCauses.getRecords().stream().collect(Collectors.groupingBy(StateCause::getEquipmentId)));
+//        stateCauses.setRecords(Collections.emptyList());
+
+        Map<String, Object> map = new HashMap<>();
+        map.put("total", collect.size());
+        map.put("size", listMap.size());
+        map.put("current", pageNum);
+        map.put("data", listMap);
+        return JsonResult.successData(ResultCode.SUCCESS, map);
     }
 
     //状态时间
@@ -75,18 +88,79 @@ public class PhotovoltaicAnalysisController {
             @RequestParam("pageNum") int pageNum,
             @RequestParam("pageSize") int pageSize) {
 
-        List<ProBasicEquipment> equipments = proBasicEquipmentService.getStationMap(type).get(stationId);
+        Map<String, List<ProBasicEquipment>> stationMap = proBasicEquipmentService.getStationMap(type);
+        List<ProBasicEquipment> equipments = stationMap.get(stationId);
+        if (equipments == null) return JsonResult.successData(ResultCode.SUCCESS, new HashMap<>());
+        Map<String, String> stringMap = equipments.stream().collect(Collectors.toMap(ProBasicEquipment::getId, ProBasicEquipment::getNemCode));
+        List<String> collect = equipments.stream().map(ProBasicEquipment::getId).collect(Collectors.toList());
+
+        List<String> pageItems = collect.subList(pageSize * (pageNum - 1), Math.min(collect.size(), pageSize * pageNum));
+
         QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
-        Page<StateCause> page = new Page<>(pageNum, pageSize);
-        scWrapper.in("equipment_id", equipments).gt("start_time", startTime).lt("end_time", endTime);
-        PageMap<StateCause> stateCauses = (PageMap<StateCause>) stateCauseService.page(page, scWrapper);
+//        Page<StateCause> page = new Page<>(pageNum, pageSize);
+        scWrapper.select("equipment_id,event,sum(time)/3600 hour");
+        scWrapper.eq("state_type", "8种状态").in("equipment_id", pageItems)
+                .gt("start_time", startTime).lt("end_time", endTime);
+        ;
+        scWrapper.groupBy("equipment_id,event");
+        List<StateCause> causePage = stateCauseService.list(scWrapper);
+        Map<String, List<StateCause>> listMap = causePage.stream().peek(sc -> sc.setEquipmentId(stringMap.get(sc.getEquipmentId()))).collect(Collectors.groupingBy(StateCause::getEquipmentId));
+        List<Device> deviceList = statecauses2Devices(listMap);
+        /*PageMap<StateCause> pageMap = new PageMap<>();
+        pageMap.
+        PageMap<StateCause> stateCauses = (PageMap<StateCause>) causePage;
 
         Map<String, Map<Short, Double>> collect = stateCauses.getRecords().stream().collect(Collectors.groupingBy(StateCause::getEquipmentId,
                 Collectors.groupingBy(StateCause::getEvent, Collectors.summingDouble(t -> t.getTime() / (60 * 24.0)))));
 
         stateCauses.setRecordMap(collect);
-        stateCauses.setRecords(Collections.emptyList());
-        return JsonResult.successData(ResultCode.SUCCESS, stateCauses);
+        stateCauses.setRecords(Collections.emptyList());*/
+
+//        protected long total;
+//        protected long size;
+//        protected long current;
+        Map<String, Object> map = new HashMap<>();
+        map.put("total", collect.size());
+        map.put("size", deviceList.size());
+        map.put("current", pageNum);
+        map.put("data", deviceList);
+        return JsonResult.successData(ResultCode.SUCCESS, map);
+    }
+
+    private List<Device> statecauses2Devices(Map<String, List<StateCause>> listMap) {
+        List<Device> deviceList = new ArrayList<>();
+        listMap.forEach((wt, scs) -> {
+            Device device = new Device();
+            device.setStationId(scs.get(0).getStationId());
+            device.setDeviceId(wt);
+            scs.forEach(sc -> {
+                switch (sc.getEvent()) {
+                    case 0:
+                        device.setStandbyTime(sc.getHour());
+                        break;
+                    case 1:
+                        device.setGridConnectionTime(sc.getHour());
+                        break;
+                    case 2:
+                        device.setFaultTime(sc.getHour());
+                        break;
+                    case 3:
+                        device.setMaintenanceTime(sc.getHour());
+                        break;
+                    case 4:
+                        device.setPowerLimitTime(sc.getHour());
+                        break;
+                    case 5:
+                        device.setStressedTime(sc.getHour());
+                        break;
+                    case 6:
+                        device.setOfflineTime(sc.getHour());
+                        break;
+                }
+            });
+            deviceList.add(device);
+        });
+        return deviceList;
     }
 
     @GetMapping("/analysis")

+ 4 - 3
power-fitting-JN/src/main/java/com.gyee.power.fitting/dispersionanalysis/CalculateTask.java

@@ -40,7 +40,7 @@ public class CalculateTask {
         Map<String, ProBasicEquipmentPoint> mxztMap = proBasicEquipmentPointService.getEquipmentMapByUniformcode("MXZT");
         //获取最新更新时间
         QueryWrapper<StateCause> scWrapper = new QueryWrapper<>();
-        scWrapper.select("last_row(end_time) end_time").groupBy("equipment_id");
+        scWrapper.select("equipment_id,last_row(end_time) end_time").groupBy("equipment_id");
         List<StateCause> scList = stateCauseService.list(scWrapper);
         Map<String, StateCause> stateCauseMap;
         if (scList.isEmpty()) {
@@ -59,7 +59,7 @@ public class CalculateTask {
             if (stateCause == null) {
                 starttime = DateUtil.yesterday().getTime();
             } else {
-                starttime = stateCause.getEndTime() != null ? stateCause.getEndTime().getTime() - 6000 : DateUtil.yesterday().getTime();
+                starttime = stateCause.getEndTime() != null ? stateCause.getEndTime() - 6000 : DateUtil.yesterday().getTime();
             }
             List<TsDoubleData> datas8 = getDatas(sbztMap.get(equipmentId).getNemCode(), starttime, endtime);
 
@@ -148,7 +148,8 @@ public class CalculateTask {
                 }
             }
         }
-        stateCauseService.saveBatch(stateCauseList);
+        int i = stateCauseService.saveBatch(stateCauseList);
+        System.out.println("计算完成"+i);
     }
 
     private List<TsDoubleData> getDatas(String nemCode, long starttime, long endtime) {

+ 1 - 1
power-fitting-JN/src/main/java/com.gyee.power.fitting/dispersionanalysis/PhotovoltaicAnalysisTask.java

@@ -222,7 +222,7 @@ public class PhotovoltaicAnalysisTask {
         DateTime startTime;
         DateTime endTime = DateUtil.beginOfDay(DateUtil.yesterday());
         if (paList == null || paList.getDataDate() == null) {
-            startTime = DateUtil.beginOfMonth(DateUtil.date());
+            startTime = endTime;
         } else {
             startTime = DateUtil.offsetDay(paList.getDataDate(), 1);
             if (startTime.isAfter(endTime)) return null;

+ 2 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/mapper/StateCauseMapper.java

@@ -1,5 +1,6 @@
 package com.gyee.power.fitting.mapper;
 
+import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.gyee.power.fitting.model.StateCause;
 import org.apache.ibatis.annotations.Insert;
@@ -14,6 +15,7 @@ import org.apache.ibatis.annotations.Update;
  * @author gfhd
  * @since 2023-05-04
  */
+@DS("jsfw")
 @Mapper
 public interface StateCauseMapper extends BaseMapper<StateCause> {
     @Insert("insert into ${entity}")

+ 66 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/Device.java

@@ -0,0 +1,66 @@
+package com.gyee.power.fitting.model;
+
+import lombok.Data;
+
+@Data
+public class Device {
+    private String stationId;
+    private String deviceId;
+    //0待机, 1并网, 2故障, 3检修, 4限电, 5受累, 6离线
+    private Double standbyTime;//0待机
+    private Double gridConnectionTime;//1并网
+    private Double faultTime;//2故障
+    private Double maintenanceTime;//3检修
+    private Double powerLimitTime;//4限电
+    private Double stressedTime;//5受累
+    private Double offlineTime;//6离线
+
+    public Double getStandbyTime() {
+        if (standbyTime==null) {
+            standbyTime = 0.0;
+        }
+        return standbyTime;
+    }
+
+    public Double getGridConnectionTime() {
+        if (gridConnectionTime==null) {
+            gridConnectionTime = 0.0;
+        }
+        return gridConnectionTime;
+    }
+
+    public Double getFaultTime() {
+        if (faultTime==null) {
+            faultTime = 0.0;
+        }
+        return faultTime;
+    }
+
+    public Double getMaintenanceTime() {
+        if (maintenanceTime==null) {
+            maintenanceTime = 0.0;
+        }
+        return maintenanceTime;
+    }
+
+    public Double getPowerLimitTime() {
+        if (powerLimitTime==null) {
+            powerLimitTime = 0.0;
+        }
+        return powerLimitTime;
+    }
+
+    public Double getStressedTime() {
+        if (stressedTime==null) {
+            stressedTime = 0.0;
+        }
+        return stressedTime;
+    }
+
+    public Double getOfflineTime() {
+        if (offlineTime==null) {
+            offlineTime = 0.0;
+        }
+        return offlineTime;
+    }
+}

+ 20 - 8
power-fitting-JN/src/main/java/com.gyee.power.fitting/model/StateCause.java

@@ -1,5 +1,6 @@
 package com.gyee.power.fitting.model;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 
 import java.io.Serializable;
@@ -24,12 +25,12 @@ public class StateCause implements Serializable {
     /**
      * 开始时间
      */
-    private Timestamp startTime;
+    private Long startTime;
 
     /**
      * 结束时间
      */
-    private Timestamp endTime;
+    private Long endTime;
 
     /**
      * 事件-运行、限电、故障、受累、计划检修、待机
@@ -65,17 +66,28 @@ public class StateCause implements Serializable {
 
     private String stateType;
 
+    @TableField(exist = false)
+    private Double hour;
+
     public StateCause() {
     }
 
     public StateCause(String tbname, int event, long startTime, long endTime, long time) {
         this.tbname = tbname;
         this.event = (short) event;
-        this.startTime = new Timestamp(startTime);
-        this.endTime = new Timestamp(endTime);
+        this.startTime = startTime;
+        this.endTime = endTime;
         this.time = time / 1000;
     }
 
+    public Double getHour() {
+        return hour;
+    }
+
+    public void setHour(Double hour) {
+        this.hour = hour;
+    }
+
     public String getTbname() {
         return tbname;
     }
@@ -108,19 +120,19 @@ public class StateCause implements Serializable {
         this.event = event;
     }
 
-    public Date getStartTime() {
+    public Long getStartTime() {
         return startTime;
     }
 
-    public void setStartTime(Timestamp startTime) {
+    public void setStartTime(Long startTime) {
         this.startTime = startTime;
     }
 
-    public Timestamp getEndTime() {
+    public Long getEndTime() {
         return endTime;
     }
 
-    public void setEndTime(Timestamp endTime) {
+    public void setEndTime(Long endTime) {
         this.endTime = endTime;
     }
 

+ 2 - 0
power-fitting-JN/src/main/java/com.gyee.power.fitting/service/IStateCauseService.java

@@ -1,5 +1,6 @@
 package com.gyee.power.fitting.service;
 
+import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.gyee.power.fitting.model.StateCause;
 
@@ -13,6 +14,7 @@ import java.util.List;
  * @author gfhd
  * @since 2023-05-04
  */
+@DS("jsfw")
 public interface IStateCauseService extends IService<StateCause> {
     int saveBatch(List<StateCause> entityList);
 

+ 2 - 2
power-fitting-JN/src/main/java/com.gyee.power.fitting/service/impl/StateCauseServiceImpl.java

@@ -29,8 +29,8 @@ public class StateCauseServiceImpl extends ServiceImpl<StateCauseMapper, StateCa
         for (List<StateCause> targets : split) {
             StringBuilder sb = new StringBuilder();
             for (StateCause target : targets) {
-                sb.append(target.getTbname()).append(" values(").append(target.getStartTime().getTime())
-                        .append(",").append(target.getEndTime().getTime()).append(",'").append(target.getEvent())
+                sb.append(target.getTbname()).append(" values(").append(target.getStartTime())
+                        .append(",").append(target.getEndTime()).append(",'").append(target.getEvent())
                         .append("','").append(target.getAdvanceState()).append("','").append(target.getAfterState())
                         .append("','").append(target.getUserFlag()).append("',").append(target.getTime())
                         .append(") ");