From e7812194c9cb2c6e38af05524b55f687905fb5f6 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期五, 08 十一月 2024 13:50:42 +0800
Subject: [PATCH] 计划数据查询

---
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/dto/ApiPlanItemDTO.java                     |   33 ++++++++
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java                            |    7 +
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/framework/rpc/config/RpcConfiguration.java        |    3 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java                        |   15 +++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/enums/ModelParamType.java              |   37 +++++++++
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java             |   58 ++++++++++---
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreqEnum.java                         |   12 +-
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java             |    4 
 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java |    4 
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/TimeGranularityEnum.java                       |   38 +++++++++
 10 files changed, 185 insertions(+), 26 deletions(-)

diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
index a5f8c9b..46c4473 100644
--- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
@@ -1,12 +1,15 @@
 package com.iailab.module.data.api.plan;
 
 import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.common.ApiDataQueryDTO;
 import com.iailab.module.data.common.ApiDataValueDTO;
 import com.iailab.module.data.enums.ApiConstants;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
@@ -31,4 +34,8 @@
     @PostMapping(PREFIX + "/query-plans/record-value")
     @Operation(summary = "查询计划记录")
     LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(@RequestBody ApiDataQueryDTO dto);
+
+    @GetMapping(PREFIX + "/info/no/{itemNo}")
+    @Operation(summary = "根据测点编号查询测点信息")
+    ApiPlanItemDTO getInfoByNo(@PathVariable("itemNo") String itemNo);
 }
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/dto/ApiPlanItemDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/dto/ApiPlanItemDTO.java
new file mode 100644
index 0000000..1f59ec1
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/dto/ApiPlanItemDTO.java
@@ -0,0 +1,33 @@
+package com.iailab.module.data.api.plan.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月08日
+ */
+@Data
+@Tag(name = "计划项")
+public class ApiPlanItemDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Schema(description = "ID")
+    private String id;
+
+    @Schema(description = "指标编码")
+    private String itemNo;
+
+    @Schema(description = "指标名称")
+    private String itemName;
+
+    @Schema(description = "指标分类")
+    private String itemCategory;
+
+    @Schema(description = "时间粒度")
+    private String timeGranularity;
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreq.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreqEnum.java
similarity index 62%
rename from iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreq.java
rename to iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreqEnum.java
index 9615258..6221f9c 100644
--- a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreq.java
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/DataPointFreqEnum.java
@@ -8,21 +8,21 @@
  */
 @Getter
 @AllArgsConstructor
-public enum DataPointFreq {
-    NET10("NET10", 10),
-    NET30("NET30", 30),
-    NET60("NET60",60);
+public enum DataPointFreqEnum {
+    NET_10S("10s", 10),
+    NET_30S("30s", 30),
+    NET_1MIN("1min",60);
 
     private String code;
 
     private Integer value;
 
-    public static DataPointFreq getEumByCode(String code) {
+    public static DataPointFreqEnum getEumByCode(String code) {
         if (code == null) {
             return null;
         }
 
-        for (DataPointFreq statusEnum : DataPointFreq.values()) {
+        for (DataPointFreqEnum statusEnum : DataPointFreqEnum.values()) {
             if (statusEnum.getCode().equals(code)) {
                 return statusEnum;
             }
diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/TimeGranularityEnum.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/TimeGranularityEnum.java
new file mode 100644
index 0000000..4731528
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/enums/TimeGranularityEnum.java
@@ -0,0 +1,38 @@
+package com.iailab.module.data.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.util.Calendar;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月08日
+ */
+@Getter
+@AllArgsConstructor
+public enum TimeGranularityEnum {
+
+    TG_MIN("min", Calendar.MINUTE),
+    TG_HOUR("hour", Calendar.HOUR_OF_DAY),
+    TG_DAY("day", Calendar.DAY_OF_YEAR),
+    TG_MON("mon",Calendar.MONTH);
+
+    private String code;
+
+    private Integer value;
+
+    public static TimeGranularityEnum getEumByCode(String code) {
+        if (code == null) {
+            return null;
+        }
+
+        for (TimeGranularityEnum statusEnum : TimeGranularityEnum.values()) {
+            if (statusEnum.getCode().equals(code)) {
+                return statusEnum;
+            }
+        }
+        return null;
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
index 46f93e7..4fcf398 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
@@ -2,14 +2,18 @@
 
 import com.iailab.framework.common.util.object.ConvertUtils;
 import com.iailab.module.data.api.plan.dto.ApiPlanDataDTO;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.common.ApiDataQueryDTO;
 import com.iailab.module.data.common.ApiDataValueDTO;
 import com.iailab.module.data.plan.item.collection.PlanItemCollector;
+import com.iailab.module.data.plan.item.entity.PlanItemEntity;
+import com.iailab.module.data.plan.item.service.PlanItemService;
 import com.iailab.module.data.plan.item.vo.PlanItemDataVO;
 import com.iailab.module.data.plan.item.vo.PlanItemValueVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.LinkedHashMap;
@@ -27,11 +31,16 @@
     @Autowired
     private PlanItemCollector planItemCollector;
 
+    @Autowired
+    private PlanItemService planItemService;
+
+    @Override
     public List<ApiDataValueDTO> queryPlanItemHistoryValue(ApiDataQueryDTO dto) {
         List<PlanItemValueVO> list = planItemCollector.queryValue(dto.getItemNo(), dto.getStart(), dto.getEnd());
         return ConvertUtils.sourceToTarget(list, ApiDataValueDTO.class);
     }
 
+    @Override
     public LinkedHashMap<String, List<ApiPlanDataDTO>> queryPlanItemRecordValue(ApiDataQueryDTO dto) {
         LinkedHashMap<String, List<ApiPlanDataDTO>> result = new LinkedHashMap<>();
         if (CollectionUtils.isEmpty(dto.getItemNos())) {
@@ -44,4 +53,10 @@
         return result;
     }
 
+    @Override
+    public ApiPlanItemDTO getInfoByNo(String itemNo){
+        PlanItemEntity entity = planItemService.getInfoByNo(itemNo);
+        return ConvertUtils.sourceToTarget(entity, ApiPlanItemDTO.class);
+    }
+
 }
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/framework/rpc/config/RpcConfiguration.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/framework/rpc/config/RpcConfiguration.java
index 6616b2c..8e9dfde 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/framework/rpc/config/RpcConfiguration.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/framework/rpc/config/RpcConfiguration.java
@@ -1,5 +1,6 @@
 package com.iailab.module.model.framework.rpc.config;
 
+import com.iailab.module.data.api.plan.PlanItemApi;
 import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.infra.api.config.ConfigApi;
 import com.iailab.module.system.api.tenant.TenantApi;
@@ -7,6 +8,6 @@
 import org.springframework.context.annotation.Configuration;
 
 @Configuration(proxyBeanMethods = false)
-@EnableFeignClients(clients = {DataPointApi.class, ConfigApi.class, TenantApi.class})
+@EnableFeignClients(clients = {DataPointApi.class, PlanItemApi.class, ConfigApi.class, TenantApi.class})
 public class RpcConfiguration {
 }
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/enums/ModelParamType.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/enums/ModelParamType.java
new file mode 100644
index 0000000..fec116a
--- /dev/null
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/enums/ModelParamType.java
@@ -0,0 +1,37 @@
+package com.iailab.module.model.mdk.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 模型参数类型
+ *
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月08日
+ */
+@Getter
+@AllArgsConstructor
+public enum ModelParamType {
+
+    DATAPOINT("DATAPOINT", "测点值"),
+    PREDICTITEM("PREDICTITEM", "预测值"),
+    IND("IND", "指标值"),
+    PLAN("PLAN", "计划值");
+
+    private String code;
+    private String desc;
+
+    public static ModelParamType getEumByCode(String code) {
+        if (code == null) {
+            return null;
+        }
+
+        for (ModelParamType statusEnum : ModelParamType.values()) {
+            if (statusEnum.getCode().equals(code)) {
+                return statusEnum;
+            }
+        }
+        return null;
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
index b0ab71d..ca8d21a 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/PredictResultHandler.java
@@ -2,7 +2,7 @@
 
 import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
-import com.iailab.module.data.enums.DataPointFreq;
+import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.model.mcs.pre.service.MmItemResultService;
 import com.iailab.module.model.mdk.factory.ItemEntityFactory;
 import com.iailab.module.model.mdk.vo.MmItemOutputVO;
@@ -49,7 +49,7 @@
             dateTimeList.add(tempTime);
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(tempTime);
-            calendar.add(Calendar.SECOND, DataPointFreq.getEumByCode(point.getMinfreqid()).getValue());
+            calendar.add(Calendar.SECOND, DataPointFreqEnum.getEumByCode(point.getMinfreqid()).getValue());
             tempTime = calendar.getTime();
         }
         for (Integer i = 0; i < columns; i++) {
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
index d996277..5e4e599 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/predict/impl/PredictItemMergeHandlerImpl.java
@@ -2,7 +2,7 @@
 
 import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
-import com.iailab.module.data.enums.DataPointFreq;
+import com.iailab.module.data.enums.DataPointFreqEnum;
 import com.iailab.module.model.mdk.common.enums.ItemPredictStatus;
 import com.iailab.module.model.mdk.common.exceptions.ItemInvokeException;
 import com.iailab.module.model.mdk.factory.ItemEntityFactory;
@@ -71,7 +71,7 @@
 
                         Calendar calendar = Calendar.getInstance();
                         calendar.setTime(endTime);
-                        calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreq.getEumByCode(pointEntity.getMinfreqid()).getValue());
+                        calendar.add(Calendar.SECOND, (predictLength - 1) * DataPointFreqEnum.getEumByCode(pointEntity.getMinfreqid()).getValue());
                         endTime = new Timestamp(calendar.getTime().getTime());
                         List<DataValueVO> predictValueList = predictResultHandler.getPredictValueByItemNo(itemNo, predictTime, endTime);
                         if (predictValueList.size() != predictLength) {
diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
index a67ac2d..5ca85de 100644
--- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
+++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/sample/SampleInfoConstructor.java
@@ -1,8 +1,12 @@
 package com.iailab.module.model.mdk.sample;
 
+import com.iailab.module.data.api.plan.PlanItemApi;
+import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO;
 import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.data.api.point.dto.ApiPointDTO;
-import com.iailab.module.data.enums.DataPointFreq;
+import com.iailab.module.data.enums.DataPointFreqEnum;
+import com.iailab.module.data.enums.TimeGranularityEnum;
+import com.iailab.module.model.mdk.common.enums.ModelParamType;
 import com.iailab.module.model.mdk.factory.ItemEntityFactory;
 import com.iailab.module.model.mdk.sample.dto.ColumnItem;
 import com.iailab.module.model.mdk.sample.dto.ColumnItemPort;
@@ -25,6 +29,9 @@
 
     @Autowired
     private ItemEntityFactory itemEntityFactory;
+
+    @Autowired
+    private PlanItemApi planItemApi;
 
     /**
      * prepareSampleInfo
@@ -64,21 +71,21 @@
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
-        switch (columnItem.getParamType()) {
-            case "DATAPOINT":
+        switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
+            case DATAPOINT:
                 ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
                 if (dataPoint == null) {
                     return null;
                 }
-                dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue());
+                dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue());
                 break;
-            case "PREDICTITEM":
+            case PREDICTITEM:
                 dateTime = calendar.getTime();
                 break;
-            case "IND-HIS":
+            case IND:
                 dateTime = calculateTime(originalTime, true, columnItem.getDataLength(), 60);
                 break;
-            case "IND-PLAN":
+            case PLAN:
                 dateTime = calendar.getTime();
                 break;
             default:
@@ -99,22 +106,27 @@
         Date dateTime = new Date();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(originalTime);
-        switch (columnItem.getParamType()) {
-            case "DATAPOINT":
+        switch (ModelParamType.getEumByCode(columnItem.getParamType())) {
+            case DATAPOINT:
                 ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
                 if (dataPoint == null) {
                     return null;
                 }
-                calendar.add(Calendar.SECOND, DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue() * -1);
+                calendar.add(Calendar.SECOND, DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue() * -1);
                 break;
-            case "PREDICTITEM":
+            case PREDICTITEM:
                 dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60);
                 break;
-            case "IND-HIS":
+            case IND:
                 dateTime = calendar.getTime();
                 break;
-            case "IND-PLAN":
-                dateTime = calculateTime(originalTime, false, columnItem.getDataLength(), 60);
+            case PLAN:
+                ApiPlanItemDTO planItem = planItemApi.getInfoByNo(columnItem.getParamId());
+                if (planItem == null) {
+                    return null;
+                }
+                dateTime = calculateDate(originalTime, false, columnItem.getDataLength(),
+                        TimeGranularityEnum.getEumByCode(planItem.getTimeGranularity()).getValue());
                 break;
             default:
                 break;
@@ -134,7 +146,7 @@
         switch (columnItem.getParamType()) {
             case "DATAPOINT":
                 ApiPointDTO dataPoint = dataPointApi.getInfoById(columnItem.getParamId());
-                granularity = DataPointFreq.getEumByCode(dataPoint.getMinfreqid()).getValue();
+                granularity = DataPointFreqEnum.getEumByCode(dataPoint.getMinfreqid()).getValue();
                 break;
             case "PREDICTITEM":
                 granularity = itemEntityFactory.getItemById(columnItem.getParamId()).getGranularity();
@@ -192,4 +204,20 @@
         calendar.add(Calendar.SECOND, timeLength * granularity);
         return calendar.getTime();
     }
+
+    public Date calculateDate(Date originalTime, Boolean backward, int dataLength, int field) {
+        int timeLength;
+        if (backward) {
+            timeLength = (-1) * dataLength;
+        } else {
+            timeLength = dataLength - 1;
+        }
+        Date desTime = originalTime;
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(desTime);
+        calendar.set(Calendar.MILLISECOND, 0);
+        // 数据长度 * 粒度
+        calendar.add(Calendar.SECOND, timeLength);
+        return calendar.getTime();
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3