浏览代码

Merge branch 'master' of http://116.63.33.55/git/industry-data-platform

ws 11 月之前
父节点
当前提交
0c7b94251c

+ 1 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportTableTask.java

@@ -177,7 +177,7 @@ public class EventReportTableTask implements DisposableBean {
         //得到sheet数据
         JSONObject sheet = reportTableData.getJSONObject("sheet");
         JSONArray sheetData = sheet.getJSONArray("data");
-        System.err.println("getReportTableDataStr");
+        System.err.println("EventReportTableTask.getReportTableDataStr.echoSheetAll");
         EventReportTableValidate.echoSheetAll(this.reportTable.getId(), sheetData, this.itemDataMap);
         sheet.put("data", sheetData);
         return reportTableData.toJSONString();

+ 6 - 3
industry-system/industry-da/src/main/java/com/example/opc_da/policy/ReportDataPolicyTask.java

@@ -38,9 +38,12 @@ public abstract class ReportDataPolicyTask implements DisposableBean {
 
     public ReportDataPolicyTask(ReportDataPolicy reportDataPolicy) {
         this.reportDataPolicy = reportDataPolicy;
-        this.policyItemList = (List<ReportDataPolicyItem>) queryServiceUtil.exchangeData(
-                reportDataPolicyDao.getRdpItemByPolicyId(reportDataPolicy.getId())
-        );
+        try {
+            List<ReportDataPolicyItem> rdpItemByPolicyList = reportDataPolicyDao.getRdpItemByPolicyId(reportDataPolicy.getId());
+            this.policyItemList = (List<ReportDataPolicyItem>) queryServiceUtil.exchangeData(rdpItemByPolicyList);
+        }catch (NullPointerException e){
+            throw new NullPointerException("策略配置中的点位ID未对应到点位,策略名称为:" + reportDataPolicy.getReportDataPolicyName());
+        }
         this.dataSourceId = this.policyItemList.get(0).getDataSourceId().toString();
         //因为点位来源同一个数据组,所以肯定是同一数据源
         this.items = this.policyItemList.stream()

+ 1 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/task/AsyncTask.java

@@ -129,7 +129,7 @@ public class AsyncTask {
         //得到sheet数据
         JSONObject sheet = reportTableData.getJSONObject("sheet");
         JSONArray sheetData = sheet.getJSONArray("data");
-        System.err.println("updateReportTableDataById");
+        System.err.println("AsyncTask.updateReportTableDataById.echoSheetAll");
         EventReportTableValidate.echoSheetAll(mainReportTableId, sheetData, itemDataMap);
         sheet.put("data", sheetData);
         reportTableDao.updateReportTableDataById(reportTableId, reportTableData.toJSONString());

+ 49 - 40
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventReportTableValidate.java

@@ -42,14 +42,14 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
      * @return
      */
     private static String replaceValueByScale(String value,String policyItemId,List<ReportDataPolicyItem> itemScaleList, Integer defaultScale){
-        log.info("事件驱动报表:EventReportTableValidate.itemScaleList=" + itemScaleList.toString() + ",policyItemId=" + policyItemId);
+        //log.info("事件驱动报表:EventReportTableValidate.itemScaleList=" + itemScaleList.toString() + ",policyItemId=" + policyItemId);
         Optional<ReportDataPolicyItem> first = itemScaleList.stream()
                 .filter((item) -> policyItemId.equals(item.getId().toString()))
                 .findFirst();
         Integer scale = null;
         if (first.isPresent()) {
             scale = first.get().getScale();
-            log.info("事件驱动报表:EventReportTableValidate.scale=" + scale);
+            //log.info("事件驱动报表:EventReportTableValidate.scale=" + scale);
         }
         if(Blank.isEmpty(scale)){
             scale = defaultScale;
@@ -85,34 +85,57 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
                 if (Blank.isNotEmpty(rowCol)) {
                     //能解析的数据才赋值
                     try {
+                        String v = rowCol.getString("v");
+                        String regex = "^\\$\\{.*\\}$";
+                        //赋值基础数据项
+                        if (v != null && v.matches(regex)) {
+                            ReportTableBasicItemEnum o = Arrays.stream(ReportTableBasicItemEnum.values())
+                                    .filter(b -> b.name().equals(v.substring(2, v.length() - 1)))
+                                    .findFirst()
+                                    .orElse(null);
+                            if (o != null) {
+                                String value = o.getValue();
+                                rowCol.put("v", value);
+                                rowCol.put("m", value);
+                                continue;
+                            }
+                            rowCol.put("v", null);
+                            rowCol.put("m", null);
+                            continue;
+                        }
                         JSONObject rowColJson = JSONObject.parseObject(rowCol.getString("celldata"));
                         String type = rowColJson.getString("type");
                         //如果类型为数据,则存入数据
                         if (type.equals("data")) {
                             JSONObject rowColData = rowColJson.getJSONObject("data");
                             String itemId = rowColData.getString("itemId");
-                            if (Blank.isNotEmpty(itemId)) {
-                                if(CollUtil.isEmpty(itemDataMap)){
-                                    rowCol.put("v", null);
-                                    rowCol.put("m", null);
-                                };
-                                List<Item> itemList = itemDataMap.get(itemId);
-                                if (CollUtil.isNotEmpty(itemList)) {
-                                    String value = itemList.get(0).getValue();
-                                    value = replaceValueByScale(value, itemId, itemScaleList, defaultScale);
-                                    rowCol.put("v", value);
-                                    rowCol.put("m", value);
-                                    itemList.remove(0);
-                                } else {
-                                    rowCol.put("v", null);
-                                    rowCol.put("m", null);
-                                }
+                            if (Blank.isEmpty(itemId)) {
+                                continue;
                             }
-                            //如果类型为时间,则存入时间
-                        } else if (type.equals("datatime")) {
                             if(CollUtil.isEmpty(itemDataMap)){
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
+                                continue;
+                            };
+                            List<Item> itemList = itemDataMap.get(itemId);
+                            if (CollUtil.isEmpty(itemList)) {
+                                rowCol.put("v", null);
+                                rowCol.put("m", null);
+                                continue;
+                            }
+                            String value = itemList.get(0).getValue();
+                            value = replaceValueByScale(value, itemId, itemScaleList, defaultScale);
+                            rowCol.put("v", value);
+                            rowCol.put("m", value);
+                            itemList.remove(0);
+                            continue;
+                        }
+                        //如果类型为时间,则存入时间
+                        if (type.equals("datatime")) {
+                            if(CollUtil.isEmpty(itemDataMap)){
+                                rowCol.put("v", null);
+                                rowCol.put("m", null);
+                                continue;
                             };
                             List<Item> itemList = itemDataMap.entrySet()
                                     .stream()
@@ -120,31 +143,17 @@ public abstract class EventReportTableValidate implements ReportTableValidate {
                                     .map(Map.Entry::getValue)
                                     .orElse(new ArrayList<>());
 
-                            if (CollUtil.isNotEmpty(itemList)) {
-                                String time = itemList.get(0).getTime();
-                                rowCol.put("v", time);
-                                rowCol.put("m", time);
-                            } else {
+                            if (CollUtil.isEmpty(itemList)) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
+                                continue;
                             }
+                            String time = itemList.get(0).getTime();
+                            rowCol.put("v", time);
+                            rowCol.put("m", time);
                         }
                     } catch (Exception e) {
-                        String v = rowCol.getString("v");
-                        String regex = "^\\$\\{.*\\}$";
-                        //赋值基础数据项
-                        if (v != null && v.matches(regex)) {
-                            if (Arrays.stream(ReportTableBasicItemEnum.values())
-                                    .filter(b -> b.name().equals(v.substring(2, v.length() - 1))).findFirst().orElse(null) != null) {
-                                String value = Objects.requireNonNull(Arrays.stream(ReportTableBasicItemEnum.values())
-                                        .filter(b -> b.name().equals(v.substring(2, v.length() - 1))).findFirst().orElse(null)).getValue();
-                                rowCol.put("v", value);
-                                rowCol.put("m", value);
-                            } else {
-                                rowCol.put("v", null);
-                                rowCol.put("m", null);
-                            }
-                        }
+                        log.error("事件驱动报表解析数据出错",e);
                     }
                 }
             }