Procházet zdrojové kódy

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

lry před 11 měsíci
rodič
revize
e3f749df29
19 změnil soubory, kde provedl 373 přidání a 149 odebrání
  1. 2 1
      industry-system/industry-da/src/main/java/com/example/opc_da/dao/ReportTableDao.java
  2. 1 1
      industry-system/industry-da/src/main/java/com/example/opc_da/policy/EventReportTableTask.java
  3. 10 7
      industry-system/industry-da/src/main/java/com/example/opc_da/policy/ReportDataPolicyTask.java
  4. 3 3
      industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ItemGroupServiceImpl.java
  5. 7 7
      industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java
  6. 1 1
      industry-system/industry-da/src/main/java/com/example/opc_da/task/AsyncTask.java
  7. 41 0
      industry-system/industry-da/src/main/java/com/example/opc_da/task/DeviceTableQuartzTask.java
  8. 38 0
      industry-system/industry-da/src/main/java/com/example/opc_da/task/DeviceTableTimerTask.java
  9. 8 0
      industry-system/industry-da/src/main/java/com/example/opc_da/util/ItemUtil.java
  10. 11 0
      industry-system/industry-da/src/main/java/com/example/opc_da/util/calculate/DifferenceCalculate.java
  11. 42 27
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticReportTableValidate.java
  12. 4 2
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceMaReportTableValidate.java
  13. 24 16
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceReportTableValidate.java
  14. 55 40
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/EventReportTableValidate.java
  15. 44 28
      industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ManualReportTableValidate.java
  16. 15 2
      industry-system/industry-da/src/main/resources/mapper/ReportTableDao.xml
  17. 1 1
      industry-system/industry-da/src/main/resources/static/reportSheet/js/src/model/chart-right-window.js
  18. 0 3
      industry-system/industry-da/src/main/resources/static/reportSheet/js/src/model/data-setting-window.js
  19. 66 10
      industry-system/industry-da/src/main/resources/static/reportSheet/js/src/model/item-list-table.js

+ 2 - 1
industry-system/industry-da/src/main/java/com/example/opc_da/dao/ReportTableDao.java

@@ -165,13 +165,14 @@ public interface ReportTableDao {
 
     //通过模板的id和模板的名称,获取相应的报表(自动报表和驱动报表是获取到的主报表)
     ReportTable getReportTableByTemplate(TableTemplate tableTemplate);
+    ReportTable getReportTableByTemplateAndNoData(TableTemplate tableTemplate);
 
     //通过模板统计图id,获取模板统计图相应的点位信息
     List<TableTemplateChartItem> getTtciByTtcId(Integer tableTemplateChartId);
 
     Integer setAutoTableTime(ReportTable reportTable);
 
-    Integer logicDeleteReportTable(Integer id, Integer reportTableType, Integer isDelete);
+    Integer logicDeleteReportTable(String reportTableId, Integer isDelete);
 
     //通过传入的点位,查看配置在报表中统计图的点位总数
     List<TableTemplate> getTtciCountByItemId(List<Item> itemList);

+ 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();

+ 10 - 7
industry-system/industry-da/src/main/java/com/example/opc_da/policy/ReportDataPolicyTask.java

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

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

@@ -529,7 +529,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                 List<String> header = CollUtil.newArrayList("时间", "点位名称", "值");
                 rows.add(header);
                 for (Item item : itemList) {
-                    String itemReadName = ItemUtil.getFullItemName(item);
+                    String itemReadName = ItemUtil.getTableItemName(item);
                     List<String> dataTimeList = item.getDataTimeList();
                     List<String> dataValueList = item.getDataValueList();
                     if (Blank.isNotEmpty(dataTimeList)) {
@@ -544,7 +544,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                 TreeMap<String, Map<String, String>> map = new TreeMap<>();
                 List<String> header = CollUtil.newArrayList("时间");
                 for (Item item : itemList) {
-                    String itemKey = ItemUtil.getFullItemName(item);
+                    String itemKey = ItemUtil.getTableItemName(item);
                     List<String> dataTimeList = item.getDataTimeList();
                     List<String> dataValueList = item.getDataValueList();
                     if (Blank.isNotEmpty(dataTimeList)) {
@@ -569,7 +569,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
                     List<String> row = CollUtil.newArrayList(key);
                     for (int i = 0; i < itemList.size(); i++) {
                         Item item = itemList.get(i);
-                        String itemKey = ItemUtil.getFullItemName(item);
+                        String itemKey = ItemUtil.getTableItemName(item);
                         row.add(m.get(itemKey));
                     }
                     rows.add(row);

+ 7 - 7
industry-system/industry-da/src/main/java/com/example/opc_da/service/impl/ReportTableServiceImpl.java

@@ -241,7 +241,7 @@ public class ReportTableServiceImpl implements ReportTableService {
             }
             reportTableDao.delTableTemplateLogByTtId(id);
             if (templateType.equals(ConstantStr.MANUAL_REPORT)) {
-                ReportTable reportTable = reportTableDao.getReportTableByTemplate(tableTemplate);
+                ReportTable reportTable = reportTableDao.getReportTableByTemplateAndNoData(tableTemplate);
                 String reportTableId = reportTable.getId();
                 reportTableDao.delReportTableById(reportTableId);
                 reportTableDao.delTableUserGroup(reportTableId);
@@ -251,11 +251,11 @@ public class ReportTableServiceImpl implements ReportTableService {
                     reportTableDao.delReportTableIdAndPolicyIdAndItemIdByReportTableId(reportTableId);
                 }
             } else {
-                //将相应的报表变为逻辑删除
-                reportTableDao.logicDeleteReportTable(id, templateType, ConstantStr.PUBLIC_IS_DELETE);
 
-                ReportTable reportTable = reportTableDao.getReportTableByTemplate(tableTemplate);
+                ReportTable reportTable = reportTableDao.getReportTableByTemplateAndNoData(tableTemplate);
                 String reportTableId = reportTable.getId();
+                //将相应的报表变为逻辑删除
+                reportTableDao.logicDeleteReportTable(reportTableId, ConstantStr.PUBLIC_IS_DELETE);
                 // 删除报表、策略、点位关系
                 if(StrUtil.isNotEmpty(reportTableId)){
                     reportTableDao.delReportTableIdAndPolicyIdAndItemIdByReportTableId(reportTableId);
@@ -263,7 +263,7 @@ public class ReportTableServiceImpl implements ReportTableService {
             }
             return Result.ok("删除报表成功");
         } else {
-            ReportTable reportTable = reportTableDao.getReportTableByTemplate(tableTemplate);
+            ReportTable reportTable = reportTableDao.getReportTableByTemplateAndNoData(tableTemplate);
             if (templateType.equals(ConstantStr.MANUAL_REPORT) || templateType.equals(ConstantStr.EVENT_DRIVEN_REPORT)
                     || templateType.equals(ConstantStr.DEVICE_REPORT)) {
                 return Result.ok("此报表在运行配置中生成了相应的数据报表,确认要删除?", "fail");
@@ -276,10 +276,10 @@ public class ReportTableServiceImpl implements ReportTableService {
                     return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "删除报表失败");
                 }
                 reportTableDao.delTableTemplateLogByTtId(id);
-                //将相应的报表变为逻辑删除
-                reportTableDao.logicDeleteReportTable(id, templateType, ConstantStr.PUBLIC_IS_DELETE);
 
                 String reportTableId = reportTable.getId();
+                //将相应的报表变为逻辑删除
+                reportTableDao.logicDeleteReportTable(reportTableId, ConstantStr.PUBLIC_IS_DELETE);
                 // 删除报表、策略、点位关系
                 if(StrUtil.isNotEmpty(reportTableId)){
                     reportTableDao.delReportTableIdAndPolicyIdAndItemIdByReportTableId(reportTableId);

+ 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());

+ 41 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/task/DeviceTableQuartzTask.java

@@ -0,0 +1,41 @@
+package com.example.opc_da.task;
+
+import cn.hutool.core.util.IdUtil;
+import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_da.validate.reportTable.ReportTableValidateFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SerializationUtils;
+import org.quartz.JobDataMap;
+import org.quartz.JobExecutionContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.quartz.QuartzJobBean;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+
+@Slf4j
+@Component
+public class DeviceTableQuartzTask extends QuartzJobBean {
+
+    @Autowired
+    private AsyncTask asyncTask;
+
+    @Override
+    protected void executeInternal(JobExecutionContext context) {
+        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
+        ReportTable reportTable = (ReportTable) jobDataMap.get("reportTable");
+        log.info("自动报表,{},执行开始,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+        //使用深拷贝或者其他方式创建一个新的报表对象,并将其设置为运行状态
+        ReportTable newReportTable = SerializationUtils.clone(reportTable);
+        newReportTable.setRunState(ConstantStr.START_UP);
+        //生成一张新的子报表,并添加相应的日志,以及用户组授权
+        String id = IdUtil.createSnowflake(1, 1).nextId() + "";
+        asyncTask.addHaveKeyChReport(reportTable.getId(), id, ConstantStr.DEVICE_GENERATE_REPORT,
+                ReportTableValidateFactory.getReportTableValidate(
+                        reportTable.getReportTableType()
+                ).getData(newReportTable).getReportTableData(), true);
+        log.info("自动报表,{},执行结束,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+    }
+}

+ 38 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/task/DeviceTableTimerTask.java

@@ -0,0 +1,38 @@
+package com.example.opc_da.task;
+
+import cn.hutool.core.util.IdUtil;
+import com.example.opc_common.entity.ReportTable;
+import com.example.opc_common.util.ConstantStr;
+import com.example.opc_common.util.DateUtil;
+import com.example.opc_da.config.SpringContextUtils;
+import com.example.opc_da.timer.PeriodTimerTask;
+import com.example.opc_da.validate.reportTable.ReportTableValidateFactory;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SerializationUtils;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.Map;
+
+@Slf4j
+@Component
+public class DeviceTableTimerTask extends PeriodTimerTask {
+
+    AsyncTask asyncTask = SpringContextUtils.getBean(AsyncTask.class);
+
+    @Override
+    protected void runInit(Map<String, Object> map) {
+        ReportTable reportTable = (ReportTable) map.get("reportTable");
+        log.info("自动报表,{},执行开始,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+        //使用深拷贝或者其他方式创建一个新的报表对象,并将其设置为运行状态
+        ReportTable newReportTable = SerializationUtils.clone(reportTable);
+        newReportTable.setRunState(ConstantStr.START_UP);
+        //生成一张新的子报表,并添加相应的日志,以及用户组授权
+        String id = IdUtil.createSnowflake(1, 1).nextId() + "";
+        asyncTask.addHaveKeyChReport(reportTable.getId(), id, ConstantStr.DEVICE_GENERATE_REPORT,
+                ReportTableValidateFactory.getReportTableValidate(
+                        reportTable.getReportTableType()
+                ).getData(newReportTable).getReportTableData(), true);
+        log.info("自动报表,{},执行结束,时间为{}", reportTable.getId(), DateUtil.dateChangeStrYmdhmss(new Date()));
+    }
+}

+ 8 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/util/ItemUtil.java

@@ -6,6 +6,14 @@ import com.example.opc_common.util.Blank;
 public class ItemUtil {
 
     public static String getFullItemName(Item item){
+        String value = item.getItemName();
+        if(Blank.isNotEmpty(item.getModbusConfig())){
+            value = item.getItemReadName();
+        }
+        return value;
+    }
+
+    public static String getTableItemName(Item item){
         String value = item.getItemReadName();
         if(Blank.isNotEmpty(item.getModbusConfig())){
             value = item.getItemName();

+ 11 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/util/calculate/DifferenceCalculate.java

@@ -1,5 +1,7 @@
 package com.example.opc_da.util.calculate;
 
+import com.example.opc_common.util.Blank;
+
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.List;
@@ -11,10 +13,19 @@ public class DifferenceCalculate implements CalculateData {
         if (valueList == null || valueList.isEmpty()) {
             return null;
         } else {
+            if(Blank.isEmpty(scale)){
+                scale = defaultScale;
+            }
+
             BigDecimal start  = new BigDecimal(valueList.get(0));
             BigDecimal end  = new BigDecimal(valueList.get(valueList.size() - 1));
+            if(scale == null || scale == -1){
+                return String.valueOf(end.subtract(start)); // 返回计算得到的平均值
+            }
             BigDecimal rond = end.subtract(start).setScale(scale, RoundingMode.HALF_UP);
             return String.valueOf(rond);
         }
     }
+
+
 }

+ 42 - 27
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/AutomaticReportTableValidate.java

@@ -109,8 +109,30 @@ public abstract class AutomaticReportTableValidate implements ReportTableValidat
                 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"));
+                        if(Blank.isEmpty(rowColJson)){
+                            continue;
+                        }
                         String type = rowColJson.getString("type");
+                        if(Blank.isEmpty(type)){
+                            continue;
+                        }
                         String tableId = rowColJson.getString("tableId");
                         //如果类型为数据,则存入数据
                         if (type.equals("data")) {
@@ -120,42 +142,35 @@ public abstract class AutomaticReportTableValidate implements ReportTableValidat
                                     || sheetTableDataMap.get(tableId).get(uid).isEmpty()) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
-                            } else {
-                                List<Item> itemList = sheetTableDataMap.get(tableId).get(uid);
-                                String value = itemList.get(0).getValue();
-                                rowCol.put("v", value);
-                                rowCol.put("m", value);
-                                itemList.remove(0);
+                                continue;
                             }
+                            List<Item> itemList = sheetTableDataMap.get(tableId).get(uid);
+                            String value = itemList.get(0).getValue();
+                            rowCol.put("v", value);
+                            rowCol.put("m", value);
+                            itemList.remove(0);
+                            continue;
                             //如果类型为时间,则存入时间
-                        } else if (type.equals("datatime")) {
-                            if (Blank.isEmpty(sheetTableDataMap.get(tableId))
-                                    || sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>()).isEmpty()) {
+                        }
+                        if (type.equals("datatime")) {
+                            if (Blank.isEmpty(sheetTableDataMap.get(tableId))) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
-                            } else {
-                                List<Item> itemList = sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>());
-                                String time = itemList.get(0).getTime();
-                                rowCol.put("v", time);
-                                rowCol.put("m", time);
+                                continue;
                             }
-                        }
-                    } 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 {
+
+                            List<Item> itemList = sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>());
+                            if (itemList.isEmpty()) {
                                 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) {
+                        log.error("自动报表解析数据出错",e);
                     }
                 }
             }

+ 4 - 2
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceMaReportTableValidate.java

@@ -16,6 +16,8 @@ import com.example.opc_da.dao.DictDao;
 import com.example.opc_da.dao.ReportTableDao;
 import com.example.opc_da.task.AutoTableQuartzTask;
 import com.example.opc_da.task.AutoTableTimerTask;
+import com.example.opc_da.task.DeviceTableQuartzTask;
+import com.example.opc_da.task.DeviceTableTimerTask;
 import com.example.opc_da.timer.PeriodTimerFactory;
 import com.example.opc_da.timer.QuartzTimerFactory;
 import org.quartz.CronExpression;
@@ -75,9 +77,9 @@ public class DeviceMaReportTableValidate extends DeviceReportTableValidate {
             Integer type = reportTable.getType();
             map.put("reportTable", reportTable);
             if (type.equals(0)) {
-                PeriodTimerFactory.creteTimer().addTask(cronId, AutoTableTimerTask.class, cron, map);
+                PeriodTimerFactory.creteTimer().addTask(cronId, DeviceTableTimerTask.class, cron, map);
             } else if (type.equals(1)) {
-                QuartzTimerFactory.creteTimer().addTask(cronId, AutoTableQuartzTask.class, cron, map);
+                QuartzTimerFactory.creteTimer().addTask(cronId, DeviceTableQuartzTask.class, cron, map);
             } else {
                 throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前没有此种类型的定时器");
             }

+ 24 - 16
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/DeviceReportTableValidate.java

@@ -117,8 +117,30 @@ public abstract class DeviceReportTableValidate 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"));
+                        if(Blank.isEmpty(rowColJson)){
+                            continue;
+                        }
                         String type = rowColJson.getString("type");
+                        if(Blank.isEmpty(type)){
+                            continue;
+                        }
                         String tableId = rowColJson.getString("tableId");
                         List<Map<String, String>> itemList = sheetTableDataMap.get(tableId);
 
@@ -135,7 +157,7 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
                         if (itemList != null && json.getInteger(tableId + "_row") < itemList.size()) {
                             item = itemList.get(json.getInteger(tableId + "_row"));
                         }
-                        if (Blank.isEmpty(item)) {
+                        if (Blank.isEmpty(item) || Blank.isEmpty(rowCol.get("v")) || Blank.isEmpty(rowCol.get("m"))) {
                             rowCol.put("v", null);
                             rowCol.put("m", null);
                             continue;
@@ -160,21 +182,7 @@ public abstract class DeviceReportTableValidate implements ReportTableValidate {
                             rowCol.put("m", item.get("countTime"));
                         }
                     } 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);
                     }
                 }
             }

+ 55 - 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,63 @@ 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"));
+                        if(Blank.isEmpty(rowColJson)){
+                            continue;
+                        }
                         String type = rowColJson.getString("type");
+                        if(Blank.isEmpty(type)){
+                            continue;
+                        }
                         //如果类型为数据,则存入数据
                         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 +149,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);
                     }
                 }
             }

+ 44 - 28
industry-system/industry-da/src/main/java/com/example/opc_da/validate/reportTable/ManualReportTableValidate.java

@@ -558,8 +558,30 @@ public class ManualReportTableValidate 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"));
+                        if(Blank.isEmpty(rowColJson)){
+                            continue;
+                        }
                         String type = rowColJson.getString("type");
+                        if(Blank.isEmpty(type)){
+                            continue;
+                        }
                         String tableId = rowColJson.getString("tableId");
                         //如果类型为数据,则存入数据
                         if (type.equals("data")) {
@@ -569,42 +591,36 @@ public class ManualReportTableValidate implements ReportTableValidate {
                                     || sheetTableDataMap.get(tableId).get(uid).isEmpty()) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
-                            } else {
-                                List<Item> itemList = sheetTableDataMap.get(tableId).get(uid);
-                                String value = itemList.get(0).getValue();
-                                rowCol.put("v", value);
-                                rowCol.put("m", value);
-                                itemList.remove(0);
+                                continue;
                             }
-                            //如果类型为时间,则存入时间
-                        } else if (type.equals("datatime")) {
-                            if (Blank.isEmpty(sheetTableDataMap.get(tableId))
-                                    || sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>()).isEmpty()) {
+                            List<Item> itemList = sheetTableDataMap.get(tableId).get(uid);
+                            String value = itemList.get(0).getValue();
+                            rowCol.put("v", value);
+                            rowCol.put("m", value);
+                            itemList.remove(0);
+                            continue;
+
+                        }
+                        //如果类型为时间,则存入时间
+                        if (type.equals("datatime")) {
+                            if (Blank.isEmpty(sheetTableDataMap.get(tableId))) {
                                 rowCol.put("v", null);
                                 rowCol.put("m", null);
-                            } else {
-                                List<Item> itemList = sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>());
-                                String time = itemList.get(0).getTime();
-                                rowCol.put("v", time);
-                                rowCol.put("m", time);
+                                continue;
                             }
-                        }
-                    } 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 {
+
+                            List<Item> itemList = sheetTableDataMap.get(tableId).values().stream().findFirst().orElse(new ArrayList<>());
+                            if (itemList.isEmpty()) {
                                 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) {
+                        log.error("手动报表解析数据出错",e);
                     }
                 }
             }

+ 15 - 2
industry-system/industry-da/src/main/resources/mapper/ReportTableDao.xml

@@ -54,6 +54,12 @@
             current_num, is_gen_count_time, version, is_run_print, print_ip, print_config_id, cron_id, type, cron , run_state, create_time, is_delete
     </sql>
 
+    <sql id="reportTableCronAndNoData">
+        id
+        , report_table_type, table_template_id, user_id, report_table_name, start_time,
+            current_num, is_gen_count_time, version, is_run_print, print_ip, print_config_id, cron_id, type, cron , run_state, create_time, is_delete
+    </sql>
+
     <sql id="reportTableCronNoData">
         id
         , report_table_type, table_template_id, user_id, report_table_name, start_time, current_num,
@@ -285,8 +291,7 @@
     <update id="logicDeleteReportTable">
         update t_report_table
         set is_delete=#{isDelete}
-        where table_template_id = #{id}
-          and report_table_type = #{reportTableType}
+        where id = #{reportTableId}
     </update>
 
     <delete id="delTableTemplateById">
@@ -898,6 +903,14 @@
         and table_template_id=#{id}
     </select>
 
+    <select id="getReportTableByTemplateAndNoData" resultType="com.example.opc_common.entity.ReportTable">
+        select
+        <include refid="reportTableCronAndNoData"/>
+        from t_report_table
+        where report_table_type = #{templateType}
+        and table_template_id=#{id}
+    </select>
+
     <select id="getTtciByTtcId" resultType="com.example.opc_common.entity.TableTemplateChartItem">
         select tttci.id,
                tttci.table_template_chart_id,

+ 1 - 1
industry-system/industry-da/src/main/resources/static/reportSheet/js/src/model/chart-right-window.js

@@ -1793,7 +1793,7 @@ layui.define(['layer', 'form', 'jquery', 'element', 'laydate', 'colorpicker', 's
 			return `
 			<form class="layui-form" action="" lay-filter="pieForm">
 				<div class="layui-form-item">
-					<label class="layui-form-label">南丁格尔图:</label>
+					<label class="layui-form-label" style="padding-left: 0;width: 95px;">南丁格尔图:</label>
 					<div class="layui-input-block">
 						<input type="checkbox" name="chart-pie-rose-show" lay-filter="chart-pie-rose-show" lay-skin="switch">
 					</div>

+ 0 - 3
industry-system/industry-da/src/main/resources/static/reportSheet/js/src/model/data-setting-window.js

@@ -294,9 +294,6 @@ layui.define(['layer', 'form'], function(exports) {
 						}
 						if(!data.hasOwnProperty('valueTakingMode')){
 							data.valueTakingMode = 1
-							if (type == 5) {
-								data.valueTakingMode = 5
-							}
 						}
 						if(!data.hasOwnProperty('bucketType')){
 							data.bucketType = 2

+ 66 - 10
industry-system/industry-da/src/main/resources/static/reportSheet/js/src/model/item-list-table.js

@@ -293,7 +293,7 @@ layui.define(['layer', 'form', 'table', 'util', 'dataSettingw', 'sheetUtil', 'it
 						</div>
 					</form>
 					<div id="item-list-table" lay-filter="item-list-table"></div>
-					<form lay-filter="item-list-form" class="layui-form ${fn.data.type == 'edit'? 'layui-hide' : ''}" action="" style="margin-top: 30px;">
+					<form lay-filter="item-list-form" class="layui-form " action="" style="margin-top: 30px;">
 						${this.bottomContent()}
 					</form>
 				</div>
@@ -584,11 +584,12 @@ layui.define(['layer', 'form', 'table', 'util', 'dataSettingw', 'sheetUtil', 'it
 			_this.data.dataSetting = params.type == 'edit' ? params.dataSetting : {}
 			_this.data.tableId = params.type == 'edit' ? params.tableId : uuidv4()
 			_this.data.position = params.type == 'edit' ? params.position : {}
-			if (params.type == 'edit' && layui.sheetTypew.templateReportType == 5) {
-				_this.data.deviceDataSetting = params.dataSetting
-			}
 			if (params.type == 'edit') {
 				_this.data.itemEditInfo = params.data[0]
+				if (layui.sheetTypew.templateReportType == 5) {
+					_this.data.deviceDataSetting = params.dataSetting
+				}
+				
 			}
 			//console.log(_this.data.dataSetting)
 			layer.open({
@@ -601,8 +602,48 @@ layui.define(['layer', 'form', 'table', 'util', 'dataSettingw', 'sheetUtil', 'it
 					form.render()
 					view.render()
 					setTimeout(() => {
-						if (params.type == 'edit' && layui.sheetTypew.templateReportType == 1) {
-							form.val('item-list-form', params.itemForm)
+						if (params.type == 'edit') {
+							if (layui.sheetTypew.templateReportType == 1) {
+								form.val('item-list-form', params.itemForm)
+							} else if (layui.sheetTypew.templateReportType == 5) {
+								const deviceDataSetting = _this.data.deviceDataSetting
+								$('#itemvar-name-1').attr('data-itemid', deviceDataSetting.var1)
+								$('#itemvar-name-2').attr('data-itemid', deviceDataSetting.var2)
+								$('#itemvar-input-1').val(deviceDataSetting.ipt1)
+								$('#itemvar-input-2').val(deviceDataSetting.ipt2)
+								
+								form.val('item-list-form', {
+									variableType: deviceDataSetting.var1 == deviceDataSetting.var2 ? 1 : 2,
+									isGenCountTime: deviceDataSetting.isGenCountTime,
+									rowNumber: deviceDataSetting.rowNumber
+								})
+								layui.api.getReportDataPolicyById(_this.data.itemList[0].policyId).then(res => {
+									const arr = res.data.policyItemList
+									.filter(item => item.id == deviceDataSetting.var1 || item.id == deviceDataSetting.var2)
+									.map(item => {
+										const width = sheetUtil.getTextWidth('^.' + item.modbusConfig ? item.itemName : item.itemReadName)
+										return {
+											itemDesc: item.describe,
+											itemId: item.id,
+											itemName: item.modbusConfig ? item.itemName : item.itemReadName,
+											itemScale: item.scale,
+											policyId: res.data.id,
+											policyName: res.data.reportDataPolicyName,
+											tableId: _this.data.itemList[0].tableId,
+											uid: uuidv4(),
+											width
+										}
+									})
+									_this.data.itemList = _this.data.itemList.concat(arr)
+									$('#itemvar-name-1').text(_this.data.itemList.filter(item => item.itemId == deviceDataSetting.var1)[0].itemName)
+									$('#itemvar-name-2').text(_this.data.itemList.filter(item => item.itemId == deviceDataSetting.var2)[0].itemName)
+									$('#itemvar-name-1').parent().removeClass('layui-hide')
+									$('#itemvar-name-2').parent().removeClass('layui-hide')
+									if (deviceDataSetting.var1 != deviceDataSetting.var2) {
+										$('button[lay-on="itemvar-event-2"]').removeClass('layui-hide')
+									}
+								})
+							}
 						}
 						luckysheet.exitEditMode()
 					}, 500)
@@ -656,12 +697,27 @@ layui.define(['layer', 'form', 'table', 'util', 'dataSettingw', 'sheetUtil', 'it
 								})
 							})
 						} else if (type == 5) {
+							const dataList = _this.data.itemList.filter(item => item.itemId != $('#itemvar-name-1').attr('data-itemid')
+							&& item.itemId != $('#itemvar-name-2').attr('data-itemid'))
 							_this.data.deviceDataSetting.valueType = _this.data.dataSetting.valueType
 							layui.itemUtil.clearCell(_this.data.tableId, function() {
-								layui.itemUtil.deviceReport(_this.data.itemList, {
-									valLine: _this.data.deviceDataSetting.rowNumber,
-									isGenCountTime: _this.data.deviceDataSetting.isGenCountTime,
-								}, _this.data.deviceDataSetting, _this.data.tableId, function() {
+								layui.itemUtil.deviceReport(dataList, {
+									valLine: itemForm.rowNumber,
+									isGenCountTime: $('input[type="radio"][name="isGenCountTime"]:checked').val(),
+								}, {
+									var1: $('#itemvar-name-1').attr('data-itemid'),
+									var2: $('#itemvar-name-2').attr('data-itemid'),
+									ipt1: $('#itemvar-input-1').val(),
+									ipt2: $('#itemvar-input-2').val(),
+									isGenCountTime: $('input[type="radio"][name="isGenCountTime"]:checked').val(),
+									valueType: _this.data.dataSetting.valueType,
+									valueTakingMode: _this.data.dataSetting.valueTakingMode,
+									dateTimeType1: _this.data.dataSetting.dateTimeType1,
+									dateTimeType2: _this.data.dataSetting.dateTimeType2,
+									startTime: _this.data.dataSetting.startTime,
+									endTime: _this.data.dataSetting.endTime,
+									rowNumber: itemForm.rowNumber,
+								}, _this.data.tableId, function() {
 									layer.close(index)
 								}, function() {
 									layer.alert('检测到数据生成区域含有其他定义报表,生成失败!', {icon: 2})