Browse Source

批量关联资产接口调试

zhangyu 5 years ago
parent
commit
5797b515e9
3 changed files with 172 additions and 176 deletions
  1. 13 0
      src/api/scan/request.js
  2. 9 9
      src/components/ledger/lib/linkassets.vue
  3. 150 167
      src/views/ledger/facility/batchlink.vue

+ 13 - 0
src/api/scan/request.js

@@ -949,6 +949,19 @@ export function queryEquip(param, success) {
     http.postJson(url, param, success)
 }
 
+//查询项目下的设备或部件-根据项目、建筑、楼层、设备或部件分类、业务空间实例筛选设备 然后通过计算匹配资产
+export function equipCategoryProperty(param, success) {
+    let url = `${baseUrl}/equip-component/equip-query/equip-category-property?category=${param.category}${param.spaceIdList?param.spaceIdList:''}`;
+    let data = param.data;
+    http.postJson(url, data, success)
+}
+
+//批量添加设备和资产的关系
+export function equipRproperty(param, success) {
+    let url = `${baseUrl}/equip-component/equip-query/equip-r-property`;
+    http.postJson(url, param, success)
+}
+
 //创建资产所需(Family族id3位编码)-根据设备类型(4位编码)或部件类型(6位编码)查询
 export function getEquipBelongs(param, success) {
     let url = `${baseUrl}/datacenter/data-dictionary/family-query`;

+ 9 - 9
src/components/ledger/lib/linkassets.vue

@@ -189,6 +189,10 @@ export default {
     // 修改建筑楼层
     handleChangeBf(val) {
       this.zoneListIsShow()
+      // 重置空间实例选择
+      this.space = []
+      this.spaceList = []
+      this.handleChangeSpaceItem()
     },
     //判断是否显示空间分区选择
     zoneListIsShow(){
@@ -204,7 +208,6 @@ export default {
       // 重置空间实例选择
       this.space = []
       this.spaceList = []
-
       this.handleChangeSpaceItem()
     },
     // 获取空间实例
@@ -265,12 +268,6 @@ export default {
             deviceType: this.deviceType,
             buildFloor: this.buildFloor
           }
-        } else if (this.zone == 'noKnow'){//不在空间内
-          query = {
-            deviceType: this.deviceType,
-            buildFloor: this.buildFloor,
-            spaceList: this.zone
-          }
         } else {
           if(this.space.length){//选择了具体的空间实例
             query = {
@@ -279,8 +276,11 @@ export default {
               spaceList: this.space
             }
           } else {
-            this.$message.info('请选择空间实例!')
-            return false
+            query = {
+              deviceType: this.deviceType,
+              buildFloor: this.buildFloor,
+              spaceList: this.zone //(包含具体的业务空间分区和不在任何分区两种情况)
+            }
           }
         }
       } else {

+ 150 - 167
src/views/ledger/facility/batchlink.vue

@@ -3,42 +3,43 @@
     <div class="condition">
       <div class="header">
         <el-button style="float:left;" size="small" type="default" icon="el-icon-back" @click="goBack"></el-button>
-        <span class="statistics-title">发现未关联资产的设备:<b>XXXX</b></span>
-        <span class="statistics-title">可在此功能中批量关联的:<b>XXXX</b></span>
+        <span class="statistics-title">发现未关联资产的设备:<b>{{unlinkNumber}}</b></span>
+        <span class="statistics-title">可在此功能中批量关联的:<b>{{linkNumber}}</b></span>
         <el-button style="float:right;margin-top:1px;" @click="handleClickCreate">保存选定的设备资产关联关系</el-button>
+        <el-button v-show="Object.keys(radio).length" style="float:right;margin-top:1px;margin-right:15px;" @click="handleClickReset">重置</el-button>
       </div>
       <div class="main">
         <el-table ref="multipleTable" :data="tableData" v-loading='loading' stripe height="100%" :span-method="objectSpanMethod">
-          <el-table-column label="设备本地名称" width="200">
-            <template slot-scope="scope">{{ scope.row.EquipLocalName?scope.row.EquipLocalName:scope.row.EquipName }}</template>
+          <el-table-column prop="EquipLocalName" label="设备本地名称" show-overflow-tooltip max-width="150">
+            <!-- <template slot-scope="scope">{{ scope.row.EquipLocalName?scope.row.EquipLocalName:scope.row.EquipName }}</template> -->
           </el-table-column>
-          <el-table-column label="设备本地编码" show-overflow-tooltip>
-            <template slot-scope="scope">{{ scope.row.EquipLocalID?scope.row.EquipLocalID:scope.row.EquipID }}</template>
+          <el-table-column prop="EquipLocalID" label="设备本地编码" show-overflow-tooltip max-width="150">
+            <!-- <template slot-scope="scope">{{ scope.row.EquipLocalID?scope.row.EquipLocalID:scope.row.EquipID }}</template> -->
           </el-table-column>
-          <el-table-column prop="EquipName" label="设备类" show-overflow-tooltip width="200"></el-table-column>
-          <el-table-column prop="BIMID" label="设计图纸中编码"></el-table-column>
+          <el-table-column prop="Category" label="设备类" show-overflow-tooltip width="100"></el-table-column>
+          <el-table-column prop="CADID" label="设计图纸中编码" show-overflow-tooltip max-width="150"></el-table-column>
           <el-table-column label="所属建筑楼层">
-            <template slot-scope="scope">{{ scope.row.BuildLocalName }}-{{ scope.row.FloorLocalName }}</template>
+            <template slot-scope="scope">{{ scope.row.BuildingId }}-{{ scope.row.FloorId }}</template>
           </el-table-column>
-          <el-table-column label="资产本地名称" width="200">
-            <template slot-scope="scope">{{ scope.row.AssetsLocalName }}</template>
+          <el-table-column prop="PropertyItem.EquipLocalName" label="资产本地名称" show-overflow-tooltip max-width="150">
+            <!-- <template slot-scope="scope">{{ scope.row.AssetsLocalName }}</template> -->
           </el-table-column>
-          <el-table-column label="资产本地编码" show-overflow-tooltip>
-            <template slot-scope="scope">{{ scope.row.AssetsLocalId }}</template>
+          <el-table-column prop="PropertyItem.EquipLocalID" label="资产本地编码" show-overflow-tooltip max-width="150">
+            <!-- <template slot-scope="scope">{{ scope.row.AssetsLocalId }}</template> -->
           </el-table-column>
-          <el-table-column prop="Family" label="设备族" show-overflow-tooltip width="200"></el-table-column>
-          <el-table-column prop="AssetsBIMID" label="设计图纸中编码"></el-table-column>
-          <el-table-column label="所属建筑楼层">
-            <template slot-scope="scope">{{ scope.row.AssetsBuildLocalName }}-{{ scope.row.AssetsFloorLocalName }}</template>
+          <el-table-column prop="PropertyItem.Family" label="设备族" show-overflow-tooltip width="100"></el-table-column>
+          <el-table-column prop="PropertyItem.CADID" label="设计图纸中编码" show-overflow-tooltip max-width="150"></el-table-column>
+          <el-table-column label="所属建筑楼层" show-overflow-tooltip width="200">
+            <template slot-scope="scope">{{ scope.row.PropertyItem.BuildingId }}-{{ scope.row.PropertyItem.FloorId }}</template>
           </el-table-column>
           <el-table-column prop="address" label="操作" width="100">
             <template slot-scope="scope">
-              <el-radio v-model="radio[scope.row.EquipLocalID]" :label="scope.row.AssetsLocalId">&nbsp;</el-radio>
+              <el-radio v-model="radio[scope.row.EquipID]" :label="scope.row.PropertyItem.EquipID" :disabled="scope.row.disabled" @change="handleChangeLink(scope.row)">&nbsp;</el-radio>
             </template>
           </el-table-column>
         </el-table>
       </div>
-      <div class=footer>
+      <!-- <div class=footer>
         <el-pagination
           class="right"
           v-show="tableData && tableData.length"
@@ -50,7 +51,7 @@
           layout="total, sizes, prev, pager, next, jumper"
           :total="page.total">
         </el-pagination>
-      </div>
+      </div> -->
     </div>
   </div>
 </template>
@@ -58,62 +59,25 @@
 <script>
 import { mapGetters } from "vuex"
 //api
-import { } from "@/api/scan/request";
-
-let list = [
-  {
-    EquipLocalName: '风机盘管0019',
-    EquipLocalID: '1784815',
-    EquipName: '风机盘管',
-    BIMID: '18168746166',
-    BuildLocalName: 'A座',
-    FloorLocalName: '1F',
-    AssetsList: [{
-      AssetsLocalName: '资产1',
-      AssetsLocalId: '1',
-      Family: '风机盘管-资产',
-      AssetsBIMID: '18168746166',
-      AssetsBuildLocalName: 'A座',
-      AssetsFloorLocalName: '1F',
-    }, {
-      AssetsLocalName: '资产2',
-      AssetsLocalId: '2',
-      Family: '风机盘管-资产',
-      AssetsBIMID: '18168746166',
-      AssetsBuildLocalName: 'A座',
-      AssetsFloorLocalName: '1F',
-    }, {
-      AssetsLocalName: '资产3',
-      AssetsLocalId: '3',
-      Family: '风机盘管-资产',
-      AssetsBIMID: '18168746166',
-      AssetsBuildLocalName: 'A座',
-      AssetsFloorLocalName: '1F',
-    }]
-  },
-  {
-    EquipLocalName: '风机盘管0020',
-    EquipLocalID: '1784812',
-    EquipName: '风机盘管',
-    BIMID: '1816874456457',
-    BuildLocalName: 'A座',
-    FloorLocalName: '1F',
-    AssetsList: [{
-      AssetsLocalName: '资产4',
-      AssetsLocalId: '4',
-      Family: '风机盘管-资产',
-      AssetsBIMID: '234567',
-      AssetsBuildLocalName: 'A座',
-      AssetsFloorLocalName: '1F',
-    }]
-  }
-]
+import { countEquip, equipCategoryProperty, equipRproperty } from "@/api/scan/request";
 
 export default {
+  components: {
+    
+  },
+  computed: {
+    ...mapGetters("layout", ["projectId", "userId", "secret"])
+  },
+  created() {
+    this.params = this.$route.params
+    this.getTableData()
+  },
   data() {
     return {
       params: {},
       loading: false,
+      unlinkNumber: 0,
+      linkNumber: 0,
       page: {
         pageSize: 50,
         pageSizes: [10, 20, 50, 100],
@@ -125,52 +89,80 @@ export default {
       mergeCol: []
     }
   },
-  computed: {
-    ...mapGetters("layout", ["projectId", "userId", "secret"])
-  },
-  components: {
-    
-  },
-  created() {
-    this.params = this.$route.params
-    this.getTableData()
-  },
-  mounted() {
-    
-  },
-  watch: {
-    projectId() {
-      this.$router.push({ name: "facilityLedger" })
-    }
-  },
   methods: {
-    //返回
-    goBack() {
-      this.$router.push({ name: "facilityLedger" })
-    },
     //获取表格数据
     getTableData() {
-      // this.loading = true
-      // let param = this.formatFilter()
-      // queryPartsDie(param, res => {
-      //   this.tableData = res.Content
-      //   this.page.total = res.Total
-      //   this.loading = false
-      // })
-      list.forEach(item =>{
-        if(item.AssetsList && item.AssetsList.length){
-          item.AssetsList.forEach((Assets, index) => {
-            let obj = JSON.parse(JSON.stringify(Object.assign(item,Assets)))
-            delete obj.AssetsList
-            this.tableData.push(obj)
-            if(index == 0){
-              this.mergeCol.push(item.AssetsList.length)
-            } else {
-              this.mergeCol.push(false)
-            }
+      this.loading = true
+      this.tableData = []
+      let param = this.formatFilter()
+      equipCategoryProperty(param, res => {
+        this.unlinkNumber = res.Total
+        this.linkNumber = res.Content.length
+        // this.page.total = res.Total
+        res.Content.forEach(item =>{
+          if(item.PropertyList && item.PropertyList.length){
+            item.PropertyList.forEach((Assets, index) => {
+              let obj = JSON.parse(JSON.stringify(Object.assign(item, {PropertyItem: Assets, disabled: false})))
+              delete obj.PropertyList
+              this.tableData.push(obj)
+              if(index == 0){
+                this.mergeCol.push(item.PropertyList.length)
+              } else {
+                this.mergeCol.push(false)
+              }
+            })
+          }
+        })
+        this.loading = false
+      })
+    },
+    //格式化条件
+    formatFilter() {
+      let param = {
+          data: {
+          //   Cascade: [
+          //   {
+          //     Name: "equipCategory",
+          //     Projection: ["EquipCode", "EquipName"]
+          //   },
+          //   {
+          //     Name: "building",
+          //     Projection: [ "BuildLocalName", "BuildName", "BuildID" ]
+          //   },
+          //   {
+          //     Name: "floor",
+          //     Projection: [ "FloorLocalName", "FloorName", "FloorID" ]
+          //   }
+          // ],
+          Orders: "createTime desc, EquipID asc"
+          // PageNumber: this.page.pageNumber,
+          // PageSize: this.page.pageSize
+        },
+        category: this.params.deviceType
+      }
+
+      if (this.params.buildFloor[0] == "noKnow") {
+        param.data.Filters = `buildingId isNull`
+      } else if (this.params.buildFloor[0] && this.params.buildFloor[0] != "all") {
+        param.data.Filters = `buildingId='${this.params.buildFloor[0]}'`
+        if (this.params.buildFloor[1] == "noKnow") {
+          param.data.Filters += `;floorId isNull`
+        } else if (this.params.buildFloor[1] && this.params.buildFloor[1] != "all") {
+          param.data.Filters += `;floorId='${this.params.buildFloor[1]}'`
+        }
+      }
+      if(this.params.hasOwnProperty('spaceList')){
+        if(typeof this.params.spaceList == 'string'){
+          param.spaceIdList = `&spacrType=${this.params.spaceList}`
+        } else {
+          let spaceIdList = ''
+          this.params.spaceList.forEach(item => {
+            spaceIdList += `&spaceIdList=${item}`
           })
+          param.spaceIdList = spaceIdList
         }
-      })
+      }
+      return param
     },
     objectSpanMethod({ row, column, rowIndex, columnIndex }) {
       if (columnIndex < 5) {
@@ -187,70 +179,65 @@ export default {
         }
       }
     },
-    //格式化条件
-    formatFilter() {
-      let param = {
-        Cascade: [
-          {
-            Name: "equipCategory",
-            Projection: ["EquipCode", "EquipName"]
-          },
-          {
-            Name: "building",
-            Projection: [ "BuildLocalName", "BuildName", "BuildID" ]
-          },
-          {
-            Name: "floor",
-            Projection: [ "FloorLocalName", "FloorName", "FloorID" ]
+    //切换关联
+    handleChangeLink(row) {
+      this.tableData.forEach(item => {
+        item.disabled = false
+        if(Object.keys(this.radio).length){
+          for(let key in this.radio){
+            if(item.EquipID != key && item.PropertyItem.EquipID == this.radio[key]){
+              item.disabled = true
+            }
           }
-        ],
-        Filters: `category='${this.params.category}';PropertyId isNull`,
-        Orders: "createTime desc, EquipID asc",
-        PageNumber: this.page.pageNumber,
-        PageSize: this.page.pageSize
-      }
-
-      if (this.params.buildId == "noKnow") {
-        param.Filters += `;buildingId isNull`
-      } else if (this.params.buildId && this.params.buildId != "all") {
-        param.Filters += `;buildingId='${this.params.buildId}'`
-      }
-
-      if (this.params.floorId == "noKnow") {
-        param.Filters += `;floorId isNull`
-      } else if (this.params.floorId && this.params.floorId != "all") {
-        param.Filters += `;floorId='${this.params.floorId}'`
-      }
-
-      return param
-    },
-    //选择的设备或部件
-    handleSelectionChange(val) {
-      
-    },
-    //切换每页显示多少条数据
-    handleSizeChange(val) {
-      this.page.pageSize = val
-      this.getTableData()
+        }
+      })
     },
-    //切换页数
-    handleCurrentChange(val) {
-      this.page.pageNumber = val
-      this.getTableData()
+    //重置关联选择
+    handleClickReset() {
+      this.tableData.forEach(item => {
+        item.disabled = false
+      })
+      this.radio = {}
     },
     //创建已选
     handleClickCreate() {
-      let params = []
+      let params = {
+        Content: []
+      }
       if(Object.keys(this.radio).length){
         for(let key in this.radio){
-          params.push({
-            id: key,
-            pid: this.radio[key]
+          params.Content.push({
+            EquipId: this.radio[key],
+            EquipmentId: key
           })
         }
+        equipRproperty(params, res => {
+          this.radio = {}
+          this.getTableData()
+          this.$message.success('关联成功!')
+        })
       } else {
         this.$message.info('请选择要关联的关系!')
       }
+    },
+    //切换每页显示多少条数据
+    // handleSizeChange(val) {
+    //   this.page.pageSize = val
+    //   this.getTableData()
+    // },
+    //切换页数
+    // handleCurrentChange(val) {
+    //   this.page.pageNumber = val
+    //   this.getTableData()
+    // },
+    //返回
+    goBack() {
+      this.$router.push({ name: "facilityLedger" })
+    }
+  },
+  watch: {
+    projectId() {
+      this.$router.push({ name: "facilityLedger" })
     }
   }
 };
@@ -278,9 +265,6 @@ export default {
       margin-top: 10px;
       height: calc(100% - 96px);
     }
-    .footer{
-      margin-bottom: 10px;
-    }
   }
 }
 </style>
@@ -291,4 +275,3 @@ export default {
   color: #000;
 }
 </style>
-