Ver código fonte

1、数据采集策略模块查询正在使用的数据组
2、判断报表中没有点位时,不保存报表、策略组、数据组关系

lhy 1 ano atrás
pai
commit
c29343d83d

+ 15 - 0
industry-admin/src/api/source/itemGroup.js

@@ -16,6 +16,21 @@ export function getAllItemGroup(params) {
 }
 
 /**
+ * 查询组配置和采集器IP
+ * @returns {AxiosPromise}
+ */
+export function getAllItemGroupAndCollector(params) {
+  return request({
+    url: '/itemGroup/getAllItemGroupAndCollector',
+    headers: {
+      isToken: true
+    },
+    method: 'get',
+    params: params
+  })
+}
+
+/**
  * 通过id查看数据组信息
  * @param {*} id
  * @returns

+ 38 - 7
industry-admin/src/views/report/reportTablePolicy/reportDataPolicy.vue

@@ -22,11 +22,12 @@
                                 <el-select v-model="reportDataPolicyForm.itemGroupId" filterable placeholder="请选择数据组"
                                     @change="itemGroupChange" style="width: calc(100% - 110px)">
                                     <el-option v-for="dict in groupList" :key="dict.id" :label="dict.groupName"
-                                        :value="dict.id"></el-option>
+                                        :value="dict.id" :disabled="dict.runStatus !== 1 || dict.onLine !== 1">
+                                    </el-option>
                                 </el-select>
                                 <el-button size="mini" @click="addDataItem"
                                     style="float: right; width: 100px; margin-top: 4px">添加点位</el-button>
-                              <el-tag size="mini" v-if="groupList.length == 0" style="color:red">
+                              <el-tag size="mini" v-if="groupStatus == 0" style="color:red">
                                 当前用户没有任何数据组正在采集!
                               </el-tag>
                             </el-form-item>
@@ -174,9 +175,12 @@
 <script>
 import { showLoading } from "@/utils/cqcy";
 import {
-    getAllItemGroup,
+  getAllItemGroupAndCollector,
 } from "@/api/source/itemGroup"
 import {
+  getClientStatus
+} from "@/api/collector";
+import {
     addReportDataPolicy, updateReportDataPolicy,
     getReportDataPolicyById
 } from "@/api/report/reportDataPolicy"
@@ -193,6 +197,7 @@ export default {
             visible: false,
             currTabs: 'base-setting',
             groupList: [],
+            groupStatus: -1,
             reportDataPolicyForm: {
                 id: null,
                 reportDataPolicyName: "",
@@ -396,15 +401,41 @@ export default {
         /** 获取所有数据组 */
         getAllItemGroup() {
             let params = {
-                page: 1,
-                limit: 9999
             }
-            getAllItemGroup(params).then(res => {
+          this.groupList = []
+          this.groupStatus = -1
+            getAllItemGroupAndCollector(params).then(res => {
                 if (res.data) {
-                    this.groupList = res.data.itemGroupList
+                    this.groupList = res.data
+                    this.getClientStatusByList()
                 }
             })
         },
+        getClientStatusByList() {
+          if (this.groupList && this.groupList.length) {
+            let lastIndex = -1;
+            for (let i = 0; i < this.groupList.length; i++) {
+              getClientStatus(this.groupList[i].ipAddr).then((json) => {
+                lastIndex++;
+                const client = json.data;
+                this.groupList[i].onLine = client.onLine;
+                this.groupList[i].runStatus = client.runStatus;
+                if(client.runStatus === 1 && client.onLine === 1){
+                  if(this.groupStatus === -1){
+                    this.groupStatus = 1
+                  }
+                }
+                if(lastIndex === i){
+                  if(this.groupStatus === -1){
+                    this.groupStatus = 0
+                  }
+                }
+              })
+            }
+          }else{
+            this.groupStatus = 0
+          }
+        },
         /** 查询字典表:记录模式 */
         getReadMode() {
             getDictByKey({ keyType: "read_policy" }).then((res) => {

+ 6 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/controller/ItemGroupController.java

@@ -69,6 +69,12 @@ public class ItemGroupController {
         return itemGroupService.getAllItemGroup(page, limit, readMode);
     }
 
+    @GetMapping("/getAllItemGroupAndCollector")
+    @WebLog(ServerEnum = ServerEnum.CLIENT, ModelEnum = ModelEnum.DATAGROUP, OperationEnum = OperationEnum.SELECT)
+    public Result getAllItemGroupAndCollector(){
+        return itemGroupService.getAllItemGroupAndCollector();
+    }
+
     /**
      * 通过id获取数据组,数据组中返回的点位,如果传入itemType为空,则是获取全部,如果为0,则是附属属性,1基础属性
      * 项类型,0附属属性,1基础属性

+ 3 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/dao/ItemGroupDao.java

@@ -8,6 +8,7 @@ import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
+import java.util.Map;
 
 @Repository
 public interface ItemGroupDao {
@@ -29,6 +30,8 @@ public interface ItemGroupDao {
 
     List<ItemGroup> getAllItemGroup(String userId, Integer startNum, Integer limitNum, Integer readMode);
 
+    List<Map<String, Object>> getAllItemGroupAndCollector(String userId);
+
     ItemGroup getItemGroupByNameNoId(Integer id,String userId, String groupName);
 
     Integer updateItemGroup(ItemGroup itemGroup);

+ 3 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/service/ItemGroupService.java

@@ -7,6 +7,7 @@ import com.example.opc_common.util.Result;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+import java.util.Map;
 
 public interface ItemGroupService {
     Result addItemGroup(ItemGroup itemGroup);
@@ -17,6 +18,8 @@ public interface ItemGroupService {
 
     Result getAllItemGroup(Integer page, Integer limit, Integer readMode);
 
+    Result getAllItemGroupAndCollector();
+
     Result delItemGroupById(Integer id);
 
     Result getItemValueById(Integer id);

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

@@ -201,6 +201,13 @@ public class ItemGroupServiceImpl implements ItemGroupService {
     }
 
     @Override
+    public Result getAllItemGroupAndCollector(){
+        String currentUserId = userUtil.getCurrentUserId();
+        List<Map<String, Object>> list = itemGroupDao.getAllItemGroupAndCollector(currentUserId);
+        return Result.ok(list);
+    }
+
+    @Override
     public synchronized Result delItemGroupById(Integer id) {
         itemGroupDao.delItemByGroupId(id);
         itemGroupDao.delItemGroupById(id);

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

@@ -1,6 +1,7 @@
 package com.example.opc_da.service.impl;
 
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -116,7 +117,9 @@ public class ReportTableServiceImpl implements ReportTableService {
         // 从报表中分析报表、策略、点位关系
         List<Map<String, Object>> resultList = getReportTableIdAndPolicyIdAndItemIdToMapList(reportTable);
         // 添加报表、策略、点位关系
-        reportTableDao.addReportTableIdAndPolicyIdAndItemIdToMapList(resultList);
+        if(resultList.size() > 0){
+            reportTableDao.addReportTableIdAndPolicyIdAndItemIdToMapList(resultList);
+        }
 
         return Result.ok("添加报表模板成功");
     }
@@ -172,9 +175,13 @@ public class ReportTableServiceImpl implements ReportTableService {
         // 从报表中分析报表、策略、点位关系
         List<Map<String, Object>> resultList = getReportTableIdAndPolicyIdAndItemIdToMapList(reportTable);
         // 删除报表、策略、点位关系
-        reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+        if(StrUtil.isNotEmpty(reportTableId)){
+            reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+        }
         // 添加报表、策略、点位关系
-        reportTableDao.addReportTableIdAndPolicyIdAndItemIdToMapList(resultList);
+        if(resultList.size() > 0){
+            reportTableDao.addReportTableIdAndPolicyIdAndItemIdToMapList(resultList);
+        }
         return Result.ok("修改报表模板成功");
     }
 
@@ -241,7 +248,9 @@ public class ReportTableServiceImpl implements ReportTableService {
                 reportTableDao.delTableUserGroup(reportTableId);
 
                 // 删除报表、策略、点位关系
-                reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+                if(StrUtil.isNotEmpty(reportTableId)){
+                    reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+                }
             } else {
                 //将相应的报表变为逻辑删除
                 reportTableDao.logicDeleteReportTable(id, templateType, ConstantStr.PUBLIC_IS_DELETE);
@@ -249,7 +258,9 @@ public class ReportTableServiceImpl implements ReportTableService {
                 ReportTable reportTable = reportTableDao.getReportTableByTemplate(tableTemplate);
                 String reportTableId = reportTable.getId();
                 // 删除报表、策略、点位关系
-                reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+                if(StrUtil.isNotEmpty(reportTableId)){
+                    reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+                }
             }
             return Result.ok("删除报表成功");
         } else {
@@ -271,7 +282,9 @@ public class ReportTableServiceImpl implements ReportTableService {
 
                 String reportTableId = reportTable.getId();
                 // 删除报表、策略、点位关系
-                reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+                if(StrUtil.isNotEmpty(reportTableId)){
+                    reportTableDao.delReportTableIdAndPolicyIdAndItemIdToMapListByReportTableId(reportTableId);
+                }
                 return Result.ok("删除报表模板成功");
             }
             throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());

+ 12 - 0
industry-system/industry-da/src/main/resources/mapper/ItemGroupDao.xml

@@ -166,6 +166,18 @@
         limit #{startNum}, #{limitNum}
     </select>
 
+
+
+    <select id="getAllItemGroupAndCollector" resultType="map">
+        select tig.id id,tig.group_name groupName,ip_addr ipAddr
+        from t_item_group tig,f_telegraf_client_item ftci,f_telegraf_client ftc
+        where
+            tig.id = ftci.item_group_id
+            and ftci.client_id = ftc.id
+            and tig.user_id=#{userId}
+        order by tig.create_time
+    </select>
+
     <select id="getItemGroupByNameNoId" resultType="com.example.opc_common.entity.ItemGroup">
         select
         <include refid="itemGroup"/>