Browse Source

修改手动报表获取历史数据接口

zhoupeng 1 year ago
parent
commit
c436fec399

+ 4 - 4
industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java

@@ -204,9 +204,10 @@ public class ItemGroupServiceImpl implements ItemGroupService {
         //赋值计算值
         for (Item item : allItemList) {
             String dataValue = item.getDataValue();
-            if (Blank.isNotEmpty(dataValue)) {
-                Integer itemId = item.getId();
-                DataModel dm = dmMap.get(itemId);
+            Integer itemId = item.getId();
+            DataModel dm = dmMap.get(itemId);
+            if (Blank.isNotEmpty(dataValue) && Blank.isNotEmpty(dm)) {
+                // 添加数据校验逻辑
                 item.setCountDataValue(
                         DataModelValidateFactory.getDataModelValidate(dm.getModelType()).getValue(dm, dataValue)
                 );
@@ -218,7 +219,6 @@ public class ItemGroupServiceImpl implements ItemGroupService {
     @Override
     public synchronized Result updateItem(Item item) {
         Item item1 = itemGroupDao.getItemById(item.getId());
-        ItemGroup itemGroup = itemGroupDao.getItemGroupById(item1.getItemGroupId());
         if (itemGroupDao.updateItem(item) <= 0) {
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改item失败");
         }

+ 41 - 46
industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ReportDataPolicyServiceImpl.java

@@ -339,24 +339,19 @@ public class ReportDataPolicyServiceImpl implements ReportDataPolicyService {
             //limit在饼图中不生效
             //先判断数据项长度,如果为1,则有切换周期,生成对应数据集
             if (idList.size() == 1) {
-                policyItemList.forEach(policyItem -> {
-                    generateDataSet(policyItem, valueTakingMode, bucketType
-                            , bucketValue, startLocalDateTime, endLocalDateTime);
-                });
+                policyItemList.forEach(policyItem ->
+                        generateDataSet(policyItem, valueTakingMode, bucketType
+                                , bucketValue, startLocalDateTime, endLocalDateTime));
                 //如果大于1,则没得切换周期,生成每个数据项的值
             } else {
-                policyItemList.forEach(policyItem -> {
-                    generateSingleValue(policyItem, valueTakingMode, startLocalDateTime);
-                });
+                policyItemList.forEach(policyItem ->
+                        generateSingleValue(policyItem, valueTakingMode, startLocalDateTime));
             }
         } else {
-            if (Blank.isNotEmpty(limit)) {
-                policyItemList.forEach(policyItem -> {
+            policyItemList.forEach(policyItem ->
                     extracted(dataValueType, valueTakingMode, bucketType
                             , bucketValue, limit, policyItem
-                            , startLocalDateTime, endLocalDateTime);
-                });
-            }
+                            , startLocalDateTime, endLocalDateTime));
         }
         return Result.ok(policyItemList);
     }
@@ -364,49 +359,49 @@ public class ReportDataPolicyServiceImpl implements ReportDataPolicyService {
     /**
      * 根据数据项的集合数据,生成对应的数据
      *
-     * @param dataValueType
-     * @param valueTakingMode
-     * @param bucketType
-     * @param bucketValue
-     * @param limit
-     * @param policyItem
-     * @param startLocalDateTime
-     * @param endLocalDateTime
+     * @param dataValueType      数据值类型
+     * @param valueTakingMode    值获取模式
+     * @param bucketType         时段类型
+     * @param bucketValue        时段值
+     * @param limit              限制
+     * @param policyItem         报告数据策略项
+     * @param startLocalDateTime 开始时间
+     * @param endLocalDateTime   结束时间
+     * @return
      */
-    private ReportDataPolicyItem extracted(String dataValueType, Integer valueTakingMode, Integer bucketType
+    private void extracted(String dataValueType, Integer valueTakingMode, Integer bucketType
             , Integer bucketValue, Integer limit, ReportDataPolicyItem policyItem
             , LocalDateTime startLocalDateTime, LocalDateTime endLocalDateTime) {
         //获取数据集
-        if (Blank.isEmpty(dataValueType) || dataValueType.equals(ConstantStr.DATA_SET)) {
+        if (Blank.isEmpty(dataValueType) || Objects.equals(dataValueType, ConstantStr.DATA_SET)) {
             generateDataSet(policyItem, valueTakingMode, bucketType
                     , bucketValue, startLocalDateTime, endLocalDateTime);
+            //limit在数据集中才生效
+            List<String> dataValueList = policyItem.getDataValueList();
+            List<String> dataTimeList = policyItem.getDataTimeList();
+            if (limit != null && limit > 0) {
+                int effectiveLimit = Math.min(limit, dataValueList.size());
+                policyItem.setDataValueList(dataValueList.subList(0, effectiveLimit));
+                policyItem.setDataTimeList(dataTimeList.subList(0, effectiveLimit));
+            }
             //单值
-        } else if (dataValueType.equals(ConstantStr.SINGLE_VALUE)) {
+        } else if (Objects.equals(dataValueType, ConstantStr.SINGLE_VALUE)) {
             generateSingleValue(policyItem, valueTakingMode, startLocalDateTime);
         }
-        List<String> dataValueList = policyItem.getDataValueList();
-        List<String> dataTimeList = policyItem.getDataTimeList();
-        policyItem.setDataValueList(
-                dataValueList.size() > limit ?
-                        dataValueList.subList(0, limit) : dataValueList
-        );
-        policyItem.setDataTimeList(
-                dataTimeList.size() > limit ?
-                        dataTimeList.subList(0, limit) : dataTimeList
-        );
-        return policyItem;
     }
 
     /**
      * 获取数据项的数据集数据
      *
-     * @param valueTakingMode
-     * @param bucketType
-     * @param bucketValue
-     * @param startLocalDateTime
-     * @param endLocalDateTime
+     * @param policyItem         数据策略项
+     * @param valueTakingMode    值取值模式
+     * @param bucketType         时段类型
+     * @param bucketValue        时段值
+     * @param startLocalDateTime 开始时间
+     * @param endLocalDateTime   结束时间
+     * @return 填充数据后的数据策略项
      */
-    private ReportDataPolicyItem generateDataSet(ReportDataPolicyItem policyItem, Integer valueTakingMode
+    private void generateDataSet(ReportDataPolicyItem policyItem, Integer valueTakingMode
             , Integer bucketType, Integer bucketValue, LocalDateTime startLocalDateTime
             , LocalDateTime endLocalDateTime) {
         List<String> flagDataValueList = new ArrayList<>();
@@ -448,16 +443,17 @@ public class ReportDataPolicyServiceImpl implements ReportDataPolicyService {
         }
         policyItem.setDataValueList(flagDataValueList);
         policyItem.setDataTimeList(flagDataTimeList);
-        return policyItem;
     }
 
     /**
-     * 获取数据项的数据集数据
+     * 生成单一数值的方法
      *
-     * @param policyItem
-     * @param valueTakingMode
+     * @param policyItem         数据策略项
+     * @param valueTakingMode    值获取模式
+     * @param startLocalDateTime 开始时间
+     * @return 带有新数值的数据策略项
      */
-    private ReportDataPolicyItem generateSingleValue(ReportDataPolicyItem policyItem
+    private void generateSingleValue(ReportDataPolicyItem policyItem
             , Integer valueTakingMode, LocalDateTime startLocalDateTime) {
         List<String> flagDataValueList = new ArrayList<>();
         List<String> flagDataTimeList = new ArrayList<>();
@@ -466,7 +462,6 @@ public class ReportDataPolicyServiceImpl implements ReportDataPolicyService {
         flagDataTimeList.add(startLocalDateTime.toString());
         policyItem.setDataValueList(flagDataValueList);
         policyItem.setDataTimeList(flagDataTimeList);
-        return policyItem;
     }
 
     public void addReportDataPolicyTaskRegister(ReportDataPolicy reportDataPolicy) {