From ed4f78cccbb2cf672d6b3230069979288232ab4a Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期一, 04 十一月 2024 08:25:28 +0800
Subject: [PATCH] 计划数据

---
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/dao/PlanItemDao.java                     |   10 +
 iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql                                                                     |    2 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java        |  138 +++++++++++++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java    |   10 
 iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/plan/PlanItemDao.xml                                          |   19 +
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueVO.java                  |   23 ++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/ApiSecurityUtils.java                 |    7 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemDataVO.java                   |   18 +
 /dev/null                                                                                                                         |   63 ------
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java                          |   28 ++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java                      |   30 +++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/controller/admin/PlanItemController.java |   11 +
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java             |    4 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/DateUtils.java                        |    2 
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueExportVO.java            |   25 ++
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataQueryDTO.java                        |   44 ++++
 iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/collection/PlanItemCollector.java        |   85 ++++++++
 iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataValueDTO.java                        |   22 ++
 18 files changed, 467 insertions(+), 74 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
new file mode 100644
index 0000000..35bfb3c
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/api/plan/PlanItemApi.java
@@ -0,0 +1,28 @@
+package com.iailab.module.data.api.plan;
+
+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.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.List;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月03日
+ */
+@FeignClient(name = ApiConstants.NAME)
+@Tag(name = "计划数据")
+public interface PlanItemApi {
+
+    String PREFIX = ApiConstants.PREFIX + "/plan-item";
+
+    @PostMapping(PREFIX + "/query-plan/history-value")
+    @Operation(summary = "查询计划历史值")
+    List<ApiDataValueDTO> queryPlanItemHistoryValue(@RequestBody ApiDataQueryDTO dto);
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataQueryDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataQueryDTO.java
new file mode 100644
index 0000000..6b2f59b
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataQueryDTO.java
@@ -0,0 +1,44 @@
+package com.iailab.module.data.common;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月03日
+ */
+@Data
+@Tag(name = "值查询")
+public class ApiDataQueryDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @Schema(description = "itemNo")
+    @NotNull(message="itemNo不能为空")
+    private String itemNo;
+
+    @Schema(description = "itemNo")
+    @NotNull(message="itemNo不能为空")
+    private List<String> itemNos;
+
+    @Schema(description = "粒度")
+    @NotNull(message="粒度不能为空")
+    private Integer granularity;
+
+    @Schema(description = "开始时间")
+    @NotNull(message="start不能为空")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date start;
+
+    @Schema(description = "结束时间")
+    @NotNull(message="end不能为空")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date end;
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataValueDTO.java b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataValueDTO.java
new file mode 100644
index 0000000..6f64ccb
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-api/src/main/java/com/iailab/module/data/common/ApiDataValueDTO.java
@@ -0,0 +1,22 @@
+package com.iailab.module.data.common;
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月03日
+ */
+@Data
+@Tag(name = "值结果")
+public class ApiDataValueDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    private Date dataTime;
+
+    private double dataValue;
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql b/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql
index 4ac9a5e..6997f33 100644
--- a/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql
+++ b/iailab-module-data/iailab-module-data-biz/db/mysql/tenant.sql
@@ -348,7 +348,7 @@
                                `id` VARCHAR(36) NOT NULL  COMMENT 'ID' ,
                                `name` VARCHAR(30) NOT NULL   COMMENT '名称' ,
                                `data_source` VARCHAR(64) NOT NULL   COMMENT '数据源ID',
-                               `query_sql` VARCHAR(200) NOT NULL   COMMENT '查询语句',
+                               `query_sql` VARCHAR(300) NOT NULL   COMMENT '查询语句',
                                `remark` VARCHAR(100)   COMMENT '备注',
                                `sort` int   COMMENT '排序',
                                `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '创建者',
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java
index a1c2d64..f2f803f 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java
@@ -1,36 +1,57 @@
 package com.iailab.module.data.api.controller.admin;
 
+import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
 import com.iailab.framework.common.pojo.CommonResult;
 import com.iailab.framework.common.util.date.DateUtils;
+import com.iailab.framework.common.util.object.ConvertUtils;
+import com.iailab.framework.excel.core.util.ExcelUtils;
+import com.iailab.framework.tenant.core.context.TenantContextHolder;
 import com.iailab.module.data.api.dto.IndexQueryDTO;
 import com.iailab.module.data.api.dto.echarts.BarLineDTO;
 import com.iailab.module.data.api.dto.echarts.SeriesItem;
+import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO;
+import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO;
+import com.iailab.module.data.api.plan.PlanItemApi;
 import com.iailab.module.data.api.point.DataPointApi;
 import com.iailab.module.data.api.point.dto.ApiPointValueDTO;
 import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO;
 import com.iailab.module.data.api.point.dto.ApiPointsValueQueryDTO;
+import com.iailab.module.data.common.ApiDataQueryDTO;
+import com.iailab.module.data.common.ApiDataValueDTO;
+import com.iailab.module.data.ind.collection.IndItemCollector;
+import com.iailab.module.data.ind.item.vo.IndItemValueVO;
+import com.iailab.module.data.plan.item.entity.PlanItemEntity;
+import com.iailab.module.data.plan.item.vo.PlanItemValueExportVO;
 import com.iailab.module.data.point.common.PointDataTypeEnum;
 import com.iailab.module.data.point.dto.DaPointDTO;
 import com.iailab.module.data.point.service.DaPointService;
 import com.iailab.module.data.api.dto.DeviceValueDTO;
-import com.iailab.module.data.api.utils.ApiSecurityUtils;
+import com.iailab.module.data.common.utils.ApiSecurityUtils;
+import com.iailab.module.data.plan.item.service.PlanItemService;
+import com.iailab.module.data.point.vo.PointValueExportVO;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
 
 import javax.annotation.Resource;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.security.PermitAll;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static com.iailab.framework.common.pojo.CommonResult.success;
 
 /**
@@ -52,6 +73,15 @@
 
     @Autowired
     private DataPointApi dataPointApi;
+
+    @Autowired
+    private PlanItemApi planItemApi;
+
+    @Autowired
+    private IndItemCollector indItemCollector;
+
+    @Autowired
+    private PlanItemService planItemService;
 
     @PermitAll
     @PostMapping("/query-points/history-value")
@@ -175,4 +205,110 @@
         }
         return CommonResult;
     }
+
+    @PermitAll
+    @PostMapping("/query-plan/history-value")
+    @Operation(summary = "查询单个计划历史值")
+    public CommonResult<List<ApiDataValueDTO>> queryPlanItemHistoryValue(HttpServletResponse response, HttpServletRequest
+            request, @RequestBody ApiDataQueryDTO dto) {
+        List<ApiDataValueDTO> result = new ArrayList<>();
+        try {
+            apiSecurityUtils.validate(request);
+            result = planItemApi.queryPlanItemHistoryValue(dto);
+            return new CommonResult<List<ApiDataValueDTO>>().setData(result);
+        }  catch (Exception ex) {
+            return new CommonResult<List<ApiDataValueDTO>>().setMsg(ex.getMessage());
+        }
+    }
+
+    @PostMapping("/query-plans/chart")
+    public CommonResult<BarLineDTO> queryPlansChart(HttpServletResponse response, HttpServletRequest
+            request, @RequestBody ApiDataQueryDTO dto) {
+
+        BarLineDTO CommonResult = new BarLineDTO();
+        try {
+            apiSecurityUtils.validate(request);
+            List<String> legend = new ArrayList<>();
+            List<SeriesItem> series = new ArrayList<>();
+            String endDateStr = dto.getEnd() == null ? DateUtils.format(new Date(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) : DateUtils.format(dto.getEnd(),  DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
+            Date endDate = DateUtils.parse(endDateStr, "yyyy-MM-dd HH:mm");
+            Date startDate = dto.getStart() == null ? DateUtils.addDateHours(endDate, -2) : dto.getStart();
+            List<String> categories = DateUtils.getTimeScale(startDate, endDate, dto.getGranularity() == null ? 60 : dto.getGranularity());
+            if (CollectionUtils.isEmpty(dto.getItemNos())) {
+                return new CommonResult<BarLineDTO>().setData(CommonResult);
+            }
+            List<PlanItemEntity> planItemList = new ArrayList<>();
+            dto.getItemNos().forEach(item -> {
+                planItemList.add(planItemService.getInfoByNo(item));
+            });
+            planItemList.forEach(item -> {
+                legend.add(item.getItemName());
+                SeriesItem seriesItem = new SeriesItem();
+                seriesItem.setName(item.getItemName());
+                ApiDataQueryDTO queryDto = new ApiDataQueryDTO();
+                queryDto.setItemNo(item.getItemNo());
+                queryDto.setStart(startDate);
+                queryDto.setEnd(endDate);
+                List<ApiDataValueDTO> list = planItemApi.queryPlanItemHistoryValue(queryDto);
+
+                List<Object[]> sData = list.stream().map(dataItem -> {
+                    Object[] valueArray = new Object[]{DateUtils.format(dataItem.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND),
+                            dataItem.getDataValue()};
+                    return valueArray;
+                }).collect(Collectors.toList());
+                seriesItem.setData(sData);
+                series.add(seriesItem);
+            });
+            CommonResult.setLegend(legend);
+            CommonResult.setCategories(categories);
+            CommonResult.setSeries(series);
+        } catch (Exception ex) {
+            ex.printStackTrace();
+        }
+        return new CommonResult<BarLineDTO>().setData(CommonResult);
+    }
+
+    @GetMapping("/export-plan/history-value")
+    @Operation(summary = "导出计划数据")
+    public void exportPlanHistoryValue(@RequestParam("itemNo") String itemNo,
+                                 @RequestParam("start") String start,
+                                 @RequestParam("end") String end,
+                                 HttpServletResponse response) throws IOException {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MILLISECOND, 0);
+        calendar.set(Calendar.SECOND, 0);
+        Date startDate = StringUtils.isBlank(start) ? DateUtils.addDateHours(calendar.getTime(), 0) : DateUtils.parse(start, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
+        Date endDate = StringUtils.isBlank(end) ? DateUtils.addDateHours(calendar.getTime(), 3) : DateUtils.parse(end, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
+        ApiDataQueryDTO queryDto = new ApiDataQueryDTO();
+        queryDto.setItemNo(itemNo);
+        queryDto.setStart(startDate);
+        queryDto.setEnd(endDate);
+        List<ApiDataValueDTO> list = planItemApi.queryPlanItemHistoryValue(queryDto);
+        List<PlanItemValueExportVO> exportList = ConvertUtils.sourceToTarget(list, PlanItemValueExportVO.class);
+        ExcelUtils.write(response, "计划数据.xls", "数据", PlanItemValueExportVO.class, exportList);
+    }
+
+    @PermitAll
+    @GetMapping("/query-ind/default-value")
+    @Operation(summary = "查询指标默认值")
+    public CommonResult<List<ApiIndItemValueDTO>> queryIndItemDefaultValue(@RequestParam String itemNo) {
+        TenantContextHolder.setTenantId(161L);
+        List<IndItemValueVO> list = indItemCollector.queryValue(itemNo);
+        List<ApiIndItemValueDTO> dtoList = new ArrayList<>();
+        list.forEach(item -> {
+            ApiIndItemValueDTO dto = new ApiIndItemValueDTO();
+            dto.setDataTime(item.getDataTime());
+            dto.setDataValue(item.getDataValue().doubleValue());
+            dtoList.add(dto);
+        });
+        return success(dtoList);
+    }
+
+    @PermitAll
+    @GetMapping("/query-ind/history-value")
+    @Operation(summary = "查询指标历史值")
+    public CommonResult<List<ApiIndItemValueDTO>> queryIndItemHistoryValue(@RequestParam ApiIndItemQueryDTO dto) {
+        List<IndItemValueVO> list = indItemCollector.queryValue(dto.getItemNo(), dto.getStart(), dto.getEnd());
+        return success(ConvertUtils.sourceToTarget(list, ApiIndItemValueDTO.class));
+    }
 }
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java
deleted file mode 100644
index 13957c8..0000000
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiIndItemController.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.iailab.module.data.api.controller.admin;
-
-import com.iailab.framework.common.pojo.CommonResult;
-import com.iailab.framework.common.util.object.ConvertUtils;
-import com.iailab.framework.tenant.core.context.TenantContextHolder;
-import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO;
-import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO;
-import com.iailab.module.data.ind.collection.IndItemCollector;
-import com.iailab.module.data.ind.item.vo.IndItemValueVO;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.tags.Tag;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-import javax.annotation.security.PermitAll;
-import java.util.ArrayList;
-import java.util.List;
-
-import static com.iailab.framework.common.pojo.CommonResult.success;
-
-/**
- * @author PanZhibao
- * @Description
- * @createTime 2024年10月10日
- */
-@Slf4j
-@RestController
-@RequestMapping("/api/data/ind-item")
-@Tag(name = "指标")
-public class ApiIndItemController {
-
-    @Autowired
-    private IndItemCollector indItemCollector;
-
-    @PermitAll
-    @GetMapping("/query-ind/default-value")
-    @Operation(summary = "查询指标默认值")
-    public CommonResult<List<ApiIndItemValueDTO>> queryIndItemDefaultValue(@RequestParam String itemNo) {
-        TenantContextHolder.setTenantId(161L);
-        List<IndItemValueVO> list = indItemCollector.queryValue(itemNo);
-        List<ApiIndItemValueDTO> dtoList = new ArrayList<>();
-        list.forEach(item -> {
-            ApiIndItemValueDTO dto = new ApiIndItemValueDTO();
-            dto.setDataTime(item.getDataTime());
-            dto.setDataValue(item.getDataValue().doubleValue());
-            dtoList.add(dto);
-        });
-        return success(dtoList);
-
-    }
-
-    @PermitAll
-    @GetMapping("/query-ind/history-value")
-    @Operation(summary = "查询指标历史值")
-    public CommonResult<List<ApiIndItemValueDTO>> queryIndItemHistoryValue(@RequestParam ApiIndItemQueryDTO dto) {
-        List<IndItemValueVO> list = indItemCollector.queryValue(dto.getItemNo(), dto.getStart(), dto.getEnd());
-        return success(ConvertUtils.sourceToTarget(list, ApiIndItemValueDTO.class));
-    }
-}
\ 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
new file mode 100644
index 0000000..e679c6b
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/plan/PlanItemApiImpl.java
@@ -0,0 +1,30 @@
+package com.iailab.module.data.api.plan;
+
+import com.iailab.framework.common.util.object.ConvertUtils;
+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.vo.PlanItemValueVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月03日
+ */
+@RestController // 提供 RESTful API 接口,给 Feign 调用
+@Validated
+public class PlanItemApiImpl implements PlanItemApi{
+
+    @Autowired
+    private PlanItemCollector planItemCollector;
+
+    public List<ApiDataValueDTO> queryPlanItemHistoryValue(ApiDataQueryDTO dto) {
+        List<PlanItemValueVO> list = planItemCollector.queryValue(dto.getItemNo(), dto.getStart(), dto.getEnd());
+        return ConvertUtils.sourceToTarget(list, ApiDataValueDTO.class);
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/ApiSecurityUtils.java
similarity index 88%
rename from iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java
rename to iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/ApiSecurityUtils.java
index 016cb99..c016afe 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/utils/ApiSecurityUtils.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/ApiSecurityUtils.java
@@ -1,19 +1,14 @@
-package com.iailab.module.data.api.utils;
+package com.iailab.module.data.common.utils;
 
 
 import com.iailab.framework.common.constant.Constant;
-import com.iailab.framework.common.pojo.CommonResult;
-import com.iailab.framework.security.core.LoginUser;
-import com.iailab.framework.security.core.util.SecurityFrameworkUtils;
 import com.iailab.framework.tenant.core.context.TenantContextHolder;
 import com.iailab.module.system.api.user.AdminUserApi;
-import com.iailab.module.system.api.user.dto.AdminUserRespDTO;
 import org.apache.commons.lang3.StringUtils;
 
 import javax.annotation.Resource;
 
 import org.springframework.stereotype.Component;
-import org.springframework.util.ObjectUtils;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.regex.Pattern;
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/DateUtils.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/DateUtils.java
index 0accd61..506ebbe 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/DateUtils.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/common/utils/DateUtils.java
@@ -31,6 +31,8 @@
 	public final static String DATE_PATTERN = "yyyy-MM-dd";
 	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
 	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
+    /** 时间格式(yyyyMMddHHmmss) */
+    public final static String DATE_NUMBER_PATTERN = "yyyyMMddHHmmss";
 
     /**
      * 日期格式化 日期格式为:yyyy-MM-dd
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/collection/PlanItemCollector.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/collection/PlanItemCollector.java
new file mode 100644
index 0000000..e8f862b
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/collection/PlanItemCollector.java
@@ -0,0 +1,85 @@
+package com.iailab.module.data.plan.item.collection;
+
+import com.iailab.framework.tenant.core.context.DataContextHolder;
+import com.iailab.module.data.common.utils.DateUtils;
+import com.iailab.module.data.plan.data.entity.PlanDataSetEntity;
+import com.iailab.module.data.plan.data.service.PlanDataSetService;
+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 lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月02日
+ */
+@Slf4j
+@Component
+public class PlanItemCollector {
+
+    @Autowired
+    private PlanItemService planItemService;
+
+    @Autowired
+    private PlanDataSetService planDataSetService;
+
+    public List<PlanItemValueVO> queryValue(String itemNo, Date startTime, Date endTime) {
+        List<PlanItemValueVO> result = new ArrayList<>();
+        PlanItemEntity itemEntity = planItemService.getInfoByNo(itemNo);
+        Map<String, Object> params = new HashMap<String, Object>();
+
+        PlanDataSetEntity dataSet = planDataSetService.get(itemEntity.getDataSet());
+        if (dataSet == null) {
+            log.warn("数据集不能为空");
+            return null;
+        }
+        if (StringUtils.isEmpty(dataSet.getDataSource())) {
+            log.warn("数据源不能为空");
+            return null;
+        }
+        DataContextHolder.setDataSourceId(Long.valueOf(dataSet.getDataSource()));
+
+        params.put("selectSql", " plan_t.start_time, plan_t.end_time");
+        params.put("viewSql", dataSet.getQuerySql());
+        StringBuilder whereSql = new StringBuilder();
+        String startStr = DateUtils.format(startTime, DateUtils.DATE_NUMBER_PATTERN);
+        String endStr = DateUtils.format(endTime, DateUtils.DATE_NUMBER_PATTERN);
+        whereSql.append(" plan_t.start_time <= " )
+                .append(endStr)
+                .append(" and plan_t.end_time >= ")
+                .append(startStr);
+        params.put("whereSql", whereSql.toString());
+        List<PlanItemDataVO> dataList = planItemService.getSourceValue(params);
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(startTime);
+        int dataLength = (int)((endTime.getTime() - startTime.getTime()) / (1000 * 60)) + 1;
+        for (int i = 0; i < dataLength; i ++) {
+            PlanItemValueVO itemValue = new PlanItemValueVO();
+            Date dataTime = calendar.getTime();
+            itemValue.setDataTime(dataTime);
+            itemValue.setDataValue(0d);
+            if (!CollectionUtils.isEmpty(dataList)) {
+                dataList.forEach(item -> {
+                    Date s = DateUtils.parse(item.getStartTime(), DateUtils.DATE_NUMBER_PATTERN);
+                    Date e = DateUtils.parse(item.getEndTime(), DateUtils.DATE_NUMBER_PATTERN);
+                    if ((dataTime.after(s) && dataTime.before(e))
+                            || dataTime.equals(s) || dataTime.equals(e)) {
+                        itemValue.setDataValue(1d);
+                    }
+                });
+            }
+            calendar.add(Calendar.MINUTE, 1);
+            result.add(itemValue);
+        }
+        return result;
+    }
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/controller/admin/PlanItemController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/controller/admin/PlanItemController.java
index c5a9a0b..c9cf4e4 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/controller/admin/PlanItemController.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/controller/admin/PlanItemController.java
@@ -1,14 +1,18 @@
 package com.iailab.module.data.plan.item.controller.admin;
 
+import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
 import com.iailab.framework.common.pojo.CommonResult;
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.util.object.BeanUtils;
 import com.iailab.framework.common.util.object.ConvertUtils;
+import com.iailab.framework.excel.core.util.ExcelUtils;
+import com.iailab.module.data.api.dto.ApiPointValueQueryDTO;
 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.PlanItemPageReqVO;
 import com.iailab.module.data.plan.item.vo.PlanItemRespVO;
 import com.iailab.module.data.plan.item.vo.PlanItemSaveReqVO;
+import com.iailab.module.data.point.vo.PointValueExportVO;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -17,10 +21,17 @@
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
+import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
 import static com.iailab.framework.common.pojo.CommonResult.success;
 
 /**
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/dao/PlanItemDao.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/dao/PlanItemDao.java
index 61ba104..4c0df90 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/dao/PlanItemDao.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/dao/PlanItemDao.java
@@ -3,10 +3,16 @@
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.mybatis.core.mapper.BaseMapperX;
 import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX;
+import com.iailab.framework.tenant.core.aop.TenantIgnore;
+import com.iailab.framework.tenant.core.db.dynamic.DataDS;
 import com.iailab.framework.tenant.core.db.dynamic.TenantDS;
 import com.iailab.module.data.plan.item.entity.PlanItemEntity;
+import com.iailab.module.data.plan.item.vo.PlanItemDataVO;
 import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO;
 import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -17,6 +23,10 @@
 @Mapper
 public interface PlanItemDao extends BaseMapperX<PlanItemEntity> {
 
+    @DataDS
+    @TenantIgnore
+    List<PlanItemDataVO> getSourceValue(Map<String, Object> params);
+
     default PageResult<PlanItemEntity> selectPage(PlanItemPageReqVO reqVO) {
         return selectPage(reqVO, new LambdaQueryWrapperX<PlanItemEntity>()
                 .likeIfPresent(PlanItemEntity::getItemNo, reqVO.getItemNo())
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java
index 4bec74e..78ab077 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/PlanItemService.java
@@ -3,10 +3,12 @@
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.service.BaseService;
 import com.iailab.module.data.plan.item.entity.PlanItemEntity;
+import com.iailab.module.data.plan.item.vo.PlanItemDataVO;
 import com.iailab.module.data.plan.item.vo.PlanItemPageReqVO;
 import com.iailab.module.data.plan.item.vo.PlanItemSaveReqVO;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author PanZhibao
@@ -28,4 +30,6 @@
     PlanItemEntity getInfoByNo(String no);
 
     void delete(String id);
+
+    List<PlanItemDataVO> getSourceValue(Map<String, Object> params);
 }
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java
index ccbe1e7..29a7b42 100644
--- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/service/impl/PlanItemServiceImpl.java
@@ -7,6 +7,7 @@
 import com.iailab.module.data.plan.item.dao.PlanItemDao;
 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.PlanItemPageReqVO;
 import com.iailab.module.data.plan.item.vo.PlanItemSaveReqVO;
 import com.iailab.module.data.common.enums.IncreaseCodeEnum;
@@ -14,9 +15,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
 
 /**
  * @author PanZhibao
@@ -73,4 +72,9 @@
     public void delete(String id) {
         baseDao.deleteById(id);
     }
+
+    @Override
+    public List<PlanItemDataVO> getSourceValue(Map<String, Object> params) {
+        return baseDao.getSourceValue(params);
+    }
 }
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemDataVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemDataVO.java
new file mode 100644
index 0000000..bbdc214
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemDataVO.java
@@ -0,0 +1,18 @@
+package com.iailab.module.data.plan.item.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月02日
+ */
+@Schema(description = "数据平台 - ")
+@Data
+public class PlanItemDataVO {
+
+    private String startTime;
+
+    private String endTime;
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueExportVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueExportVO.java
new file mode 100644
index 0000000..f962918
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueExportVO.java
@@ -0,0 +1,25 @@
+package com.iailab.module.data.plan.item.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年11月04日
+ */
+@Schema(description = "导出 - 测点数据 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class PlanItemValueExportVO {
+
+    @Schema(description = "采集值")
+    @ExcelProperty("采集值")
+    private String dataValue;
+
+    @Schema(description = "采集时间")
+    @ExcelProperty("采集时间")
+    private String dataTime;
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueVO.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueVO.java
new file mode 100644
index 0000000..eea4c72
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/plan/item/vo/PlanItemValueVO.java
@@ -0,0 +1,23 @@
+package com.iailab.module.data.plan.item.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author PanZhibao
+ * @Description
+ * @createTime 2024年10月04日
+ */
+@Schema(description = "数据平台 - ")
+@Data
+public class PlanItemValueVO {
+
+    private String itemNo;
+
+    private Date dataTime;
+
+    private double dataValue;
+}
\ No newline at end of file
diff --git a/iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/plan/PlanItemDao.xml b/iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/plan/PlanItemDao.xml
new file mode 100644
index 0000000..de2e592
--- /dev/null
+++ b/iailab-module-data/iailab-module-data-biz/src/main/resources/mapper/plan/PlanItemDao.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.iailab.module.data.plan.item.dao.PlanItemDao">
+
+    <select id="getSourceValue" parameterType="map" resultType="com.iailab.module.data.plan.item.vo.PlanItemDataVO">
+        select
+        ${selectSql}
+        from (
+        ${viewSql}
+        ) plan_t
+        <where>
+            <if test="whereSql != null and whereSql != ''">
+                and ${whereSql}
+            </if>
+        </where>
+    </select>
+
+</mapper>
\ No newline at end of file

--
Gitblit v1.9.3