Переглянути джерело

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

ws 11 місяців тому
батько
коміт
3b10d189b4

+ 10 - 0
industry-admin/src/api/collector.js

@@ -101,6 +101,16 @@ export function refreshConfig(id) {
   })
 }
 
+export function refreshConfigByItemGroupId(itemGroupId) {
+  return request({
+    url: '/collector/refreshConfigByItemGroupId',
+    method: 'get',
+    params: {
+      itemGroupId
+    }
+  })
+}
+
 export function deleteCollectorApi(id) {
   return request({
     url: '/collector/deleteCollector',

+ 24 - 1
industry-admin/src/views/source/itemGroup/item.vue

@@ -55,7 +55,7 @@ import {
   getItemValueByIds,
   deleteItemByIdList
 } from '@/api/source/itemGroup'
-import {getClientStatus, getClientNameByItemGroupId} from "@/api/collector";
+import {getClientStatus, getClientNameByItemGroupId, refreshConfigByItemGroupId} from "@/api/collector";
 import UpdateItem from './updateItem.vue'
 import MultipleModel from './multipleModel.vue'
 import ItemChoose from './itemChoose.vue'
@@ -90,6 +90,7 @@ export default {
           labelName: "点位",
           align: "left",
           formatter: (row, column, cellValue, index) => {
+            console.info("row.modbusConfig",row)
             if (row.modbusConfig) {
               return row.itemName
             } else {
@@ -256,14 +257,28 @@ export default {
       this.runCheckbox = false
       this.groupRunCheckboxEvent()
     },
+    refreshConfigByItemGroupId(id) {
+      refreshConfigByItemGroupId(id).then((json) => {
+      }).catch(() => {
+      })
+    },
     /** 数据组实时数据按钮事件 */
     groupRunCheckboxEvent() {
       if (this.runCheckbox) {
+        this.refreshConfigByItemGroupId(this.queryParams.itemGroupId)
         let loading = showLoading(this, '数据加载中,请稍候···')
         this.stopTimer()
         this.tableHeaderTitle = [
           {
             propName: "itemReadName",
+            formatter: (row, column, cellValue, index) => {
+              console.info("row.modbusConfig",row)
+              if (row.modbusConfig) {
+                return row.itemName
+              } else {
+                return row.itemReadName
+              }
+            },
             labelName: "点位",
           },
           {
@@ -299,6 +314,14 @@ export default {
         this.tableHeaderTitle = [
           {
             propName: "itemReadName",
+            formatter: (row, column, cellValue, index) => {
+              console.info("row.modbusConfig",row)
+              if (row.modbusConfig) {
+                return row.itemName
+              } else {
+                return row.itemReadName
+              }
+            },
             labelName: "点位",
             align: "left"
           },

+ 26 - 1
industry-admin/src/views/source/itemGroup/model/modbusView.vue

@@ -23,7 +23,7 @@
       <el-row :span="24" v-if="modbusForm.ioType > 1">
         <el-col :span="23">
           <el-form-item label="精度" prop="scale">
-            <el-input v-model="modbusForm.scale" placeholder="请输入精度" />
+            <el-input v-model="modbusForm.scale" @input="handleScaleInput()" @blur="handleScaleBlur()" placeholder="请输入精度" />
           </el-form-item>
         </el-col>
         <el-col :span="1">
@@ -70,11 +70,21 @@ export default {
           message: '点位名称不能为空',
           trigger: 'blur'
         }],
+        byteOrder: [{
+          required: true,
+          message: '字节序不能为空',
+          trigger: 'blur'
+        }],
         dataType: [{
           required: true,
           message: '值类型不能为空',
           trigger: 'change'
         }],
+        scale: [{
+          required: true,
+          message: '精度不能为空',
+          trigger: 'change'
+        }],
         startAddress: [{
           required: true,
           message: '地址格式错误',
@@ -113,6 +123,21 @@ export default {
   created() {
   },
   methods: {
+    handleScaleInput(){
+      if(this.modbusForm.scale){
+        this.modbusForm.scale = this.modbusForm.scale.replace(/[^0-9.-]/g,'')
+      }
+    },
+    handleScaleBlur(){
+      if(this.modbusForm.scale){
+        let v = Number.parseFloat(this.modbusForm.scale)
+        v = isNaN(v) ? "": v + ''
+        if(v && v.indexOf(".") === -1){
+          v += ".0"
+        }
+        this.modbusForm.scale = v
+      }
+    },
     ioSelect(value) {
       if (value > 1) {
         this.config.dataType = this.config.dataType2;

+ 56 - 0
industry-system/industry-da/src/main/java/com/example/opc_da/controller/CollectorController.java

@@ -1,6 +1,7 @@
 package com.example.opc_da.controller;
 
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.example.opc_common.entity.Collector;
@@ -10,12 +11,16 @@ import com.example.opc_common.util.ClientUtil;
 import com.example.opc_common.util.Result;
 import com.example.opc_da.service.CollectorService;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+@Slf4j
 @RestController
 @RequestMapping("collector")
 @RequiredArgsConstructor
@@ -208,4 +213,55 @@ public class CollectorController {
         }
         return collectorService.getClientNameByItemGroupId(itemGroupId);
     }
+
+    /**
+     * 根据数据组刷新采集器
+     * @param itemGroupId
+     * @return
+     */
+
+    @GetMapping("refreshConfigByItemGroupId")
+    public Result refreshConfigByItemGroupId(Integer itemGroupId){
+        Result clientNameByItemGroupIdResult = collectorService.getClientNameByItemGroupId(itemGroupId);
+        List<Map<String, Object>> clientNameList = (List<Map<String, Object>>)clientNameByItemGroupIdResult.getData();
+        List<Map<String, Object>> errorClientNameList = new ArrayList<>();
+        List<Map<String, Object>> successClientNameList = new ArrayList<>();
+        for (int i = 0; i < clientNameList.size(); i++) {
+            Map<String, Object> clientNameMap = clientNameList.get(i);
+            try {
+                String ip = Convert.toStr(clientNameMap.get("ipAddr"), "");
+                Integer id = Convert.toInt(clientNameMap.get("id"), 0);
+                String clientName = Convert.toStr(clientNameMap.get("clientName"), "");
+                if(StrUtil.isEmpty(ip)){
+                    log.warn("采集器【" + clientName + "】IP为空");
+                    errorClientNameList.add(clientNameMap);
+                    continue;
+                }
+                String body = ClientUtil.http(ip, clientPort, ClientUtil.Client.STATUS_API).execute().body();
+                JSONObject obj = JSONUtil.parseObj(body);
+                obj = obj.getJSONObject("data");
+                Integer runStatus = Convert.toInt(obj.get("status"), 0);
+                if(runStatus.equals(0)){
+                    log.warn("采集器【" + clientName + "】未运行");
+                    errorClientNameList.add(clientNameMap);
+                    continue;
+                }
+                // 刷新采集器
+                Result result = collectorService.refreshConfig(id);
+                if(!result.getCode().equals(ResultEnum.SUCCESS.getRespCode())){
+                    log.warn("采集器【" + clientName + "】刷新失败:" + result.getMsg());
+                    errorClientNameList.add(clientNameMap);
+                    continue;
+                }
+                successClientNameList.add(clientNameMap);
+            } catch (Exception e) {
+                log.error("实时数据刷新采集器失败", e);
+                errorClientNameList.add(clientNameMap);
+            }
+        }
+        Map<String,Object> resultMap = new HashMap<>();
+        resultMap.put("successClientNameList", successClientNameList);
+        resultMap.put("errorClientNameList", errorClientNameList);
+        return Result.ok(resultMap);
+    }
 }

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

@@ -38,6 +38,8 @@ public interface ItemGroupDao {
 
     Integer addItem(Integer itemGroupId, List<Item> itemList);
 
+    Integer updateItemBasicList(List<Item> itemList);
+
     Integer delItemByGroupId(Integer itemGroupId);
 
     Integer delItemGroupById(Integer id);

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

@@ -404,6 +404,7 @@ public class ItemGroupServiceImpl implements ItemGroupService {
         return Result.ok("设置表达式成功");
     }
 
+    @Transactional
     @Override
     public Result addItemList(ItemGroup itemGroup) {
         Integer id = itemGroup.getId();
@@ -474,8 +475,38 @@ public class ItemGroupServiceImpl implements ItemGroupService {
 //        } else {
 //            itemGroupDao.addItem(id, itemList);
 //        }
-        itemGroupDao.delItemByGroupId(id);
-        itemGroupDao.addItem(id, itemList);
+//        itemGroupDao.delItemByGroupId(id);
+//        itemGroupDao.addItem(id, itemList);
+
+
+        List<Item> addList = new ArrayList<>();
+        List<Item> updateList = new ArrayList<>();
+        for (int i = 0; i < itemList.size(); i++) {
+            String dbValue = itemList.get(i).getItemName();
+            Boolean findFlag = false;
+            for (int j = 0; j < dbItemList.size(); j++) {
+                String value = dbItemList.get(j).getItemName();
+                if (dbValue.equals(value)) {
+                    findFlag = true;
+                    itemList.get(i).setId(dbItemList.get(j).getId());
+                    break;
+                }
+            }
+            if (!findFlag) {
+                addList.add(itemList.get(i));
+            }else{
+                updateList.add(itemList.get(i));
+            }
+        }
+        if(addList.size() > 0){
+            itemGroupDao.addItem(id, addList);
+        }
+        if(updateList.size() > 0){
+            itemGroupDao.updateItemBasicList(updateList);
+        }
+        if(delList.size() > 0){
+            itemGroupDao.deleteItemByIdList(delList);
+        }
         return Result.ok("添加数据组成功");
     }
 

+ 29 - 8
industry-system/industry-da/src/main/resources/mapper/ItemGroupDao.xml

@@ -9,7 +9,8 @@
 
     <sql id="item">
         ti.id
-        , ti.item_group_id, ti.item_name, ti.item_read_name, ti.item_type, ti.node_index , ti.data_type, ti.upper_limit, ti.lower_limit, ti.`describe`, ti.unit,ti.scale ,ti.data_model_id
+        , ti.item_group_id, ti.item_name, ti.item_read_name, ti.item_type, ti.node_index , ti.data_type, ti.upper_limit, ti.lower_limit
+        , ti.`describe`, ti.unit,ti.scale ,ti.data_model_id, ti.modbus_config
     </sql>
 
     <insert id="addItemGroup" parameterType="com.example.opc_common.entity.ItemGroup" useGeneratedKeys="true"
@@ -61,6 +62,29 @@
         where id = #{id}
     </update>
 
+
+
+    <update id="updateItemBasicList">
+        <foreach collection="itemList" item="item" index="index" separator=";">
+            update t_item
+            <set>
+                <if test="item.itemName != null">
+                    item_name=#{item.itemName},
+                </if>
+                <if test="item.itemReadName != null">
+                    item_read_name=#{item.itemReadName},
+                </if>
+                <if test="item.dataModelId != null">
+                    data_model_id=#{item.dataModelId},
+                </if>
+                <if test="item.modbusConfig != null">
+                    modbus_config=#{item.modbusConfig},
+                </if>
+            </set>
+            where id = #{item.id}
+        </foreach>
+    </update>
+
     <update id="updateItemExpresses">
         update t_item
         set data_model_id=#{dataModelId}
@@ -131,13 +155,10 @@
 
     <delete id="deleteItemByIdList">
         delete from t_item
-        where 1=1
-        <if test="idList!= null and idList.size() >0">
-            AND id IN
-            <foreach collection="idList" item="id" separator="," open="(" close=")">
-                #{id}
-            </foreach>
-        </if>
+        where id IN
+        <foreach collection="idList" item="id" separator="," open="(" close=")">
+            #{id}
+        </foreach>
     </delete>
 
     <select id="getItemGroupByName" resultType="com.example.opc_common.entity.ItemGroup">

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

@@ -224,8 +224,8 @@
     </select>-->
 
     <select id="getReportDataPolicyNameByItemId" resultType="map">
-        select ti.itemReadName,GROUP_CONCAT(trdp.reportDataPolicyName order by trdp.reportDataPolicyName SEPARATOR '、') reportDataPolicyName
-        (
+        select ti.itemReadName,GROUP_CONCAT(ti.reportDataPolicyName order by ti.reportDataPolicyName SEPARATOR '、') reportDataPolicyName
+        from (
             select ti.item_read_name itemReadName,trdp.report_data_policy_name reportDataPolicyName
             from t_report_data_policy trdp,t_report_data_policy_item trdpi,t_item ti
             where trdp.id = trdpi.report_data_policy_id and trdpi.item_id = ti.id and trdpi.item_id IN