Эх сурвалжийг харах

Merge branch 'master' of http://116.63.33.55/git/read_opc

DESKTOP-227F4HN\Zt 2 жил өмнө
parent
commit
6274d42379

+ 104 - 16
chuanyi_client2/src/components/HeaderMain/index.vue

@@ -1,5 +1,5 @@
 <template>
-  <el-tabs class="cy-tabs" type="border-card">
+  <el-tabs class="cy-tabs" type="border-card" @tab-click="navGroupItemEvent">
     <el-tab-pane>
       <div slot="label" class="tab-div">
         <el-image :src="require('@/assets/images/report_model.png')" fit="contain"></el-image>
@@ -95,7 +95,7 @@
                   </el-select>
                   <el-button size="mini" @click="addDataItem" style="float: right;width: 100px;margin-top: 4px;">添加数据项</el-button>
                 </el-form-item>
-                <el-tag size="mini" v-if="chooseItemDataView" class="cy-item-tag">已选择({{ chooseItemDataList.length }})项</el-tag>
+                <el-tag size="mini" v-if="chooseItemDataView" class="cy-item-tag">已选择({{ chooseItemDataListByTree.length }})项</el-tag>
               </div>
 <!--              <el-button size="mini"  style="float: right;margin-top: 15px;margin-right: 14px;">添加数据项</el-button>-->
             </el-form>
@@ -172,7 +172,7 @@
                 <svg-icon v-if="!data.children" icon-class="file"/>
                 <svg-icon v-else-if="node.expanded" icon-class="folder-open"/>
                 <svg-icon v-else icon-class="folder"/>
-                <span :title='node.label || "-"' style="margin-left: 2px;">{{node.label}}</span>
+                <span :title='node.label || "-"' style="margin-left: 2px;">{{ node.label }}</span>
               </span>
             </el-tree>
           </div>
@@ -205,7 +205,7 @@
                 <svg-icon v-if="!data.children" icon-class="file"/>
                 <svg-icon v-else-if="node.expanded" icon-class="folder-open"/>
                 <svg-icon v-else icon-class="folder"/>
-                <span :title='node.label || "-"' style="margin-left: 2px;">{{node.label}}</span>
+                <span :title='node.label || data.itemName' style="margin-left: 2px;">{{ node.label || data.itemName }}</span>
               </span>
             </el-tree>
           </div>
@@ -271,6 +271,7 @@ export default {
       chooseItemDataListByTree: [],
       chooseItemDataView: false,
       groupBasicForm: {
+        id: null,
         groupName: '',
         groupDescribe: '',
         dataSourceId: null,
@@ -280,6 +281,8 @@ export default {
         readMode: null,
         modeValue: ''
       },
+      updateGroupData: null,
+      tempItemList: [],
       groupRules: {
         groupName: [
           { required: true, message: '组名称不能为空', trigger: 'blur' },
@@ -311,6 +314,7 @@ export default {
   computed: {
   },
   created() {
+    this.getReadMode()
   },
   methods: {
     /** 数据项搜索过滤 */
@@ -321,6 +325,28 @@ export default {
     /** 数据组组配置点击事件 */
     handleNodeClick(data, node, target) {
       this.closeMenu()
+      if (data.id != -1 && !data.itemName) {
+        sessionStorage.setItem('GROUP_ID', data.id)
+        this.gotoPageByName('/groupItem')
+      }
+    },
+    /** 组菜单点击事件 */
+    navGroupItemEvent(e) {
+      sessionStorage.removeItem('GROUP_ITEM')
+      if (e.paneName == '1') {
+        this.gotoPageByName('/groupItem')
+      } else {
+        this.gotoPageByName('/index')
+      }
+    },
+    /** 页面跳转 */
+    gotoPageByName(path) {
+      this.$router.push({
+        path: path,
+        query: {
+          t: new Date().getTime()
+        }
+      })
     },
     /** 懒加载查询组配置文件 */
     loadGroupNode(node, resolve) {
@@ -330,6 +356,7 @@ export default {
       if (node.data.id == -1) {
         getAllItemGroup().then(res => {
           resolve(res.data)
+          sessionStorage.setItem('GROUP_LIST', JSON.stringify(res.data))
         }).catch((e) => {
           resolve([])
         })
@@ -354,6 +381,7 @@ export default {
       this.closeMenu()
       // 判断是否最后一级菜单
       this.menuLeft = 80
+      this.updateGroupData = null
       if (data.id == -1) {
         this.menuTop = 30
         this.visibleGroupMenu = true
@@ -368,8 +396,19 @@ export default {
     /** 添加数据组事件 */
     createGroupEvent() {
       this.closeMenu()
+      this.groupBasicForm = {
+        id: null,
+        groupName: '',
+        groupDescribe: '',
+        dataSourceId: null,
+        itemList: []
+      }
+      this.groupRateForm = {
+        readMode: null,
+        modeValue: ''
+      }
+      this.chooseItemDataView = false
       this.getDataSourceList()
-      this.getReadMode()
       this.groupDialogVisible = true
     },
     /** 保存数据组 */
@@ -380,17 +419,21 @@ export default {
           let params = JSON.parse(JSON.stringify(this.groupBasicForm))
           params.readMode = this.groupRateForm.readMode
           params.modeValue = this.groupRateForm.modeValue
-          this.addGroupItem(params)
+          if (params.id) {
+            this.addGroupItem(params, '修改')
+          } else {
+            this.addGroupItem(params, '保存')
+          }
         }
       })
     },
     /** 保存组配置 */
-    addGroupItem(params) {
-      const loading = showLoading(this, '保存中,请稍候···')
+    addGroupItem(params, type) {
+      const loading = showLoading(this, type + '中,请稍候···')
       saveOrUpdateItemGroup(params).then(res => {
         loading.close()
         if (res.data) {
-          this.$alert('保存成功!', '温馨提示', {
+          this.$alert(type + '成功!', '温馨提示', {
             confirmButtonText: '确定',
             callback: action => {
               this.handleCancel()
@@ -403,20 +446,53 @@ export default {
           return
         }
         this.$message({
-          message: '保存失败!',
+          message: type + '失败!',
           type: 'error'
         })
       }).catch((e) => {
         loading.close()
         this.$message({
-          message: '保存失败!',
+          message: type + '失败!',
           type: 'error'
         })
       })
     },
     /** 更新组信息 */
     updateGroup() {
-      console.log(this.chooseGroupData)
+      let id = this.chooseGroupData.id
+      if (!id) {
+        this.$message({
+          message: '修改失败!',
+          type: 'error'
+        })
+        return
+      }
+      getItemGroupById(id).then(res => {
+        this.createGroupEvent()
+        let item = res.data
+        this.updateGroupData = item
+        this.groupBasicForm.id = item.id
+        this.groupBasicForm.groupName = item.groupName
+        this.groupBasicForm.groupDescribe = item.groupDescribe
+        this.groupBasicForm.dataSourceId = item.dataSourceId
+        this.groupBasicForm.itemList = item.itemList
+        this.getChooseItemData(item)
+        this.chooseItemDataView = true
+        this.groupRateForm.readMode = item.readMode + ''
+        this.groupRateForm.modeValue = item.modeValue
+      }).catch((e) => {
+      })
+    },
+    /** 选择的数据项值初始化 */
+    getChooseItemData(item) {
+      let arr = []
+      for (let i in item.itemList) {
+        arr.push({
+          'label': item.itemList[i].itemName
+        })
+      }
+      this.chooseItemDataListByTree = arr
+      this.chooseItemDataList = arr
     },
     /** 删除组信息 */
     delGroup() {
@@ -464,9 +540,14 @@ export default {
     /** 选择数据源值改变事件 */
     dataSourceChange(val) {
       this.groupBasicForm.dataSourceId = val
-      this.chooseItemDataList = []
-      this.chooseItemDataListByTree = []
-      this.chooseItemDataView = false
+      if (this.groupBasicForm.id && this.updateGroupData.dataSourceId == val) {
+        this.chooseItemDataView = true
+        this.getChooseItemData(this.updateGroupData)
+      } else {
+        this.chooseItemDataView = false
+        this.chooseItemDataList = []
+        this.chooseItemDataListByTree = []
+      }
     },
     /** 读取模式值改变事件 */
     readModeChange(val) {
@@ -500,6 +581,7 @@ export default {
         })
         return
       }
+      this.tempItemList = JSON.parse(JSON.stringify(this.groupBasicForm.itemList))
       // const loading = showLoading(this, '加载中,请稍候···')
       // getDataSourceItemTree(id).then(res => {
       //   loading.close()
@@ -727,8 +809,14 @@ export default {
     },
     /** 选择数据项弹出层关闭事件 */
     itemDialogClose(done) {
+      if ((!this.groupBasicForm.id && !this.chooseItemDataView) || !this.chooseItemDataView) {
+        this.chooseItemDataListByTree = []
+      }
+      if (this.groupBasicForm.id && this.groupBasicForm.dataSourceId == this.updateGroupData.dataSourceId) {
+        this.chooseItemDataListByTree = this.tempItemList
+        this.groupBasicForm.itemList = this.tempItemList
+      }
       this.itemDataListByTree = []
-      this.chooseItemDataListByTree = []
       if (typeof(done) === 'function') {
         done()
       } else {

+ 4 - 0
chuanyi_client2/src/router/index.js

@@ -39,6 +39,10 @@ const routes = [
             {
                 path: 'index',
                 component: () => import('@/views/home/index')
+            },
+            {
+                path: 'groupItem',
+                component: () => import('@/views/group_item/index')
             }
         ]
     }

+ 94 - 0
chuanyi_client2/src/views/group_item/index.vue

@@ -0,0 +1,94 @@
+<template>
+  <div class="cqcy-content">
+    <div style="margin-bottom: 10px;">
+      <el-select v-model="chooseGroupId" disabled size="mini">
+        <el-option
+            v-for="dict in groupDataList"
+            :key="dict.id"
+            :label="dict.groupName"
+            :value="dict.id"
+        ></el-option>
+      </el-select>
+      <el-checkbox v-model="groupRunStatus" size="mini" style="margin-left: 20px;" @change="groupRunCheckboxEvent">运行</el-checkbox>
+    </div>
+    <el-table
+        :data="itemDataList"
+        border
+        style="width: 100%">
+      <el-table-column label="序号" align="center" width="80">
+        <template slot-scope="scope">
+          {{ scope.$index + 1 }}
+        </template>
+      </el-table-column>
+      <el-table-column prop="itemName" label="数据项名称" align="center">
+      </el-table-column>
+      <el-table-column prop="val" label="数据项值" align="center" width="120">
+      </el-table-column>
+      <el-table-column prop="dataSourceName" label="数据源名称" align="center">
+      </el-table-column>
+      <el-table-column prop="runState" label="运行状态" align="center" width="100">
+      </el-table-column>
+      <el-table-column prop="time" label="运行时间" align="center" width="120">
+      </el-table-column>
+    </el-table>
+  </div>
+</template>
+
+<script>
+
+import {getItemGroupById} from "@/api/datasource";
+import {showLoading} from "@/utils/cqcy";
+
+export default {
+  name: "index",
+  components: {
+  },
+  data() {
+    return {
+      itemDataList: [],
+      groupDataList: [],
+      chooseGroup: null,
+      chooseGroupId: null,
+      groupRunStatus: false
+    }
+  },
+  watch: {
+    '$route'(to, from) {
+      this.readParams()
+    },
+  },
+  methods: {
+    /** 读取参数 */
+    readParams() {
+      let groupListStorage = sessionStorage.getItem('GROUP_LIST') ? sessionStorage.getItem('GROUP_LIST') : '[]'
+      this.groupDataList = JSON.parse(groupListStorage)
+      let groupId = sessionStorage.getItem('GROUP_ID') ? sessionStorage.getItem('GROUP_ID') : '-1'
+      this.chooseGroupId = parseInt(groupId)
+      this.getGroupById(this.chooseGroupId)
+    },
+    /** 运行状态值 */
+    groupRunCheckboxEvent(val) {
+      console.log(val)
+      console.log(this.chooseGroup)
+    },
+    /** 获取组详细信息 */
+    getGroupById(id) {
+      if (!id) {
+        return
+      }
+      const loading = showLoading(this, '加载中,请稍候···')
+      getItemGroupById(id).then(res => {
+        loading.close()
+        this.chooseGroup = res.data
+        this.itemDataList = this.chooseGroup.itemList
+      }).catch((e) => {
+        loading.close()
+      })
+    }
+  }
+}
+</script>
+
+<style scoped>
+
+</style>

+ 4 - 0
chuanyi_client2/src/views/index.vue

@@ -81,4 +81,8 @@ export default {
   opacity: unset !important;
   background: #2c3e50 !important;
 }
+
+.cqcy-content {
+  margin: 20px;
+}
 </style>

+ 1 - 1
chuanyi_client2/src/views/login.vue

@@ -105,7 +105,7 @@ export default {
   watch: {
     $route: {
       handler: function (route) {
-        this.redirect = route.query && route.query.redirect;
+        // this.redirect = route.query && route.query.redirect;
       },
       immediate: true
     }

+ 39 - 27
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ItemGroupServiceImpl.java

@@ -53,36 +53,48 @@ public class ItemGroupServiceImpl implements ItemGroupService {
             if (itemGroupDao.updateItemGroup(itemGroup) <= 0) {
                 return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "修改item组失败");
             }
-            List<Item> itemList = itemGroup.getItemList();
-            if (Blank.isEmpty(itemList)) {
-                itemGroupDao.delItemByGroupId(id);
-                return Result.ok("修改item组成功");
-            }
-            List<Item> oldItemList = itemGroupDao.getItemList(id);
-            if (Blank.isEmpty(oldItemList)) {
-                itemGroupDao.addItem(id, itemList);
-                return Result.ok("修改item组成功");
-            }
-            List<Item> publicItemList = itemGroupDao.getPublicItemList(id, itemList);
-            if (Blank.isEmpty(publicItemList)) {
-                itemGroupDao.delItemByGroupId(id);
-                itemGroupDao.addItem(id, itemList);
-                return Result.ok("修改item组成功");
-            }
-            itemGroupDao.delItemNoPub(id, publicItemList);
-            List<Item> addItemList = new ArrayList<>();
-            for (int i = 0; i < itemList.size(); i++) {
-                Boolean flage = true;
-                for (int j = 0; j < publicItemList.size(); j++) {
-                    if (itemList.get(i).getItemGroupId().equals(publicItemList.get(j).getItemName())) {
-                        flage = false;
+            if (Blank.isNotEmpty(itemGroup.getDataSourceId()) && Blank.isNotEmpty(itemGroup1.getDataSourceId())) {
+                if (itemGroup.getDataSourceId() == itemGroup1.getDataSourceId()) {
+                    List<Item> itemList = itemGroup.getItemList();
+                    if (Blank.isEmpty(itemList)) {
+                        itemGroupDao.delItemByGroupId(id);
+                        return Result.ok("修改item组成功");
                     }
+                    List<Item> oldItemList = itemGroupDao.getItemList(id);
+                    if (Blank.isEmpty(oldItemList)) {
+                        itemGroupDao.addItem(id, itemList);
+                        return Result.ok("修改item组成功");
+                    }
+                    List<Item> publicItemList = itemGroupDao.getPublicItemList(id, itemList);
+                    if (Blank.isEmpty(publicItemList)) {
+                        itemGroupDao.delItemByGroupId(id);
+                        itemGroupDao.addItem(id, itemList);
+                        return Result.ok("修改item组成功");
+                    }
+                    itemGroupDao.delItemNoPub(id, publicItemList);
+                    List<Item> addItemList = new ArrayList<>();
+                    for (int i = 0; i < itemList.size(); i++) {
+                        Boolean flage = true;
+                        for (int j = 0; j < publicItemList.size(); j++) {
+                            if (itemList.get(i).getItemName().equals(publicItemList.get(j).getItemName())) {
+                                flage = false;
+                                break;
+                            }
+                        }
+                        if (flage) {
+                            addItemList.add(itemList.get(i));
+                        }
+                    }
+                    if(Blank.isNotEmpty(addItemList)){
+                        itemGroupDao.addItem(id, addItemList);
+                    }
+                    return Result.ok("修改item组成功");
                 }
-                if (flage) {
-                    addItemList.add(itemList.get(i));
-                }
             }
-            itemGroupDao.addItem(id, addItemList);
+            itemGroupDao.delItemByGroupId(id);
+            if (Blank.isNotEmpty(itemGroup.getItemList())) {
+                itemGroupDao.addItem(id, itemGroup.getItemList());
+            }
             return Result.ok("修改item组成功");
         }
     }

+ 6 - 3
chuanyi_server/src/main/resources/mapper/ItemGroupDao.xml

@@ -2,7 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.judong.chuanyiserver.dao.ItemGroupDao">
 
-    <insert id="addItemGroup" parameterType="com.judong.chuanyiserver.entity.ItemGroup" useGeneratedKeys="true" keyProperty="id">
+    <insert id="addItemGroup" parameterType="com.judong.chuanyiserver.entity.ItemGroup" useGeneratedKeys="true"
+            keyProperty="id">
         insert into t_item_group(user_id, group_name, group_describe, data_source_id, read_mode, mode_value,
                                  create_time)
         values (#{userId}, #{groupName}, #{groupDescribe}, #{dataSourceId}, #{readMode}, #{modeValue}, now())
@@ -23,6 +24,7 @@
             data_source_id=#{dataSourceId},
             read_mode=#{readMode},
             mode_value=#{modeValue}
+        where id = #{id}
     </update>
 
     <delete id="delItemByGroupId">
@@ -40,7 +42,7 @@
     <delete id="delItemNoPub">
         delete
         from t_item
-        where item_name not in
+        where item_group_id=#{itemGroupId} and item_name not in
         <foreach collection="itemList" item="item" index="index" open="(" close=")" separator=",">
             #{item.itemName}
         </foreach>
@@ -120,7 +122,8 @@
     <select id="getPublicItemList" resultType="com.judong.chuanyiserver.entity.Item">
         select id, item_group_id, item_name
         from t_item
-        where item_name in
+        where item_group_id=#{itemGroupId} and
+        item_name in
         <foreach collection="itemList" item="item" index="index" open="(" close=")" separator=",">
             #{item.itemName}
         </foreach>