소스 검색

能源设施属性模型

hsshuxian 10 달 전
부모
커밋
fd3b8e9580

+ 14 - 5
ems-ui/src/api/basecfg/objAttribute.js

@@ -3,7 +3,7 @@ import request from '@/utils/request'
 // 查询能源对象属性列表
 export function listAttr(query) {
   return request({
-    url: '/ems/obj/attr/list',
+    url: '/ems/object/attr/list',
     method: 'get',
     params: query
   })
@@ -12,7 +12,16 @@ export function listAttr(query) {
 // 查询能源对象属性详细
 export function getAttr(id) {
   return request({
-    url: '/ems/obj/attr/' + id,
+    url: '/ems/object/attr/' + id,
+    method: 'get'
+  })
+}
+
+
+// 查询能源对象属性全部列表
+export function getObjAttr(objType, objCode) {
+  return request({
+    url: `/ems/object/attr/getObjAttr?objType=${objType}&objCode=${encodeURIComponent(objCode)}`,
     method: 'get'
   })
 }
@@ -20,7 +29,7 @@ export function getAttr(id) {
 // 新增能源对象属性
 export function addAttr(data) {
   return request({
-    url: '/ems/obj/attr',
+    url: '/ems/object/attr',
     method: 'post',
     data: data
   })
@@ -29,7 +38,7 @@ export function addAttr(data) {
 // 批量-新增能源对象属性
 export function addAttrBatch(data) {
   return request({
-    url: '/ems/obj/attr/batch',
+    url: '/ems/object/attr/batch',
     method: 'post',
     data: data
   })
@@ -38,7 +47,7 @@ export function addAttrBatch(data) {
 // 修改能源对象属性
 export function updateAttr(data) {
   return request({
-    url: '/ems/obj/attr',
+    url: '/ems/object/attr',
     method: 'put',
     data: data
   })

+ 31 - 0
ems-ui/src/api/basecfg/objAttributeValue.js

@@ -0,0 +1,31 @@
+import request from '@/utils/request'
+
+/**
+ * 查询能源对象属性值列表
+ */
+export function listAttrValue(query) {
+  return request({
+    url: '/ems/object/attr/value/list',
+    method: 'get',
+    data: query
+  })
+}
+
+/**
+ * 获取能源对象属性值详细信息
+ */
+export function getAttrValue(id) {
+  return request({
+    url: '/ems/object/attr/value/id',
+    method: 'get',
+  })
+}
+
+// 新增能源对象属性
+export function addAttrValueBatch(data) {
+  return request({
+    url: '/ems/object/attr/value/batch',
+    method: 'post',
+    data: data
+  })
+}

+ 23 - 2
ems-ui/src/views/basecfg/device/model.vue

@@ -64,7 +64,11 @@
       <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="模型编码" align="center" prop="modelCode" />
       <el-table-column label="模型名称" align="center" prop="modelName" />
-      <el-table-column label="对象类型" align="center" prop="objType" />
+      <el-table-column label="对象类型" align="center">
+        <template slot-scope="scope">
+          {{ objTypeMapping[scope.row.objType] }}
+        </template>
+      </el-table-column>
       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
         <template slot-scope="scope">
           <el-button
@@ -110,8 +114,13 @@
           <el-input v-model="form.modelName" placeholder="请输入模型名称" />
         </el-form-item>
         <el-form-item label="对象类型" prop="objType">
-          <el-input v-model="form.objType" placeholder="请输入模型名称" />
+          <el-select v-model="form.objType" placeholder="请选择对象类型">
+            <el-option label="设施" value="1"></el-option>
+            <el-option label="设备" value="2"></el-option>
+            <el-option label="设备部件" value="3"></el-option>
+          </el-select>
         </el-form-item>
+
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitForm">确 定</el-button>
@@ -163,6 +172,12 @@
                 <el-form-item label="属性标识" prop="attrKey">
                   <el-input v-model="attrForm.attrKey" placeholder="请输入属性标识" />
                 </el-form-item>
+                <el-form-item label="属性类型" prop="attrType">
+                  <el-select v-model="attrForm.attrType" placeholder="请选择属性类型">
+                    <el-option label="静态" value="0"></el-option>
+                    <el-option label="动态" value="1"></el-option>
+                  </el-select>
+                </el-form-item>
 <!--                <el-form-item label="属性值" prop="attrValue">-->
 <!--                  <el-input v-model="attrForm.attrValue" type="textarea" placeholder="请输入内容" />-->
 <!--                </el-form-item>-->
@@ -340,6 +355,11 @@ export default {
         modelName: null,
         objType: null
       },
+      objTypeMapping: {
+        1: '设施',
+        2: '设备',
+        3: '设备部件'
+      },
       // 查询参数
       queryEventParams: {
         pageNum: 1,
@@ -528,6 +548,7 @@ export default {
         id: null,
         modelCode: null,
         attrKey: null,
+        attrType:null,
         attrName: null,
         attrValue: null,
         attrUnit: null

+ 306 - 50
ems-ui/src/views/basecfg/emsfacs/index.vue

@@ -89,8 +89,8 @@
           @pagination="getList" />
 
         <!-- 添加或修改能源设施/系统对话框 -->
-        <el-dialog :title="title" :visible.sync="open" width="450px" append-to-body>
-          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
+        <el-dialog :title="title" :visible.sync="open" width="550px" append-to-body >
+          <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
             <el-form-item label="归属区域" prop="refArea">
               <treeselect v-model="form.refArea" :options="areaOptions" :show-count="true" placeholder="请选择归属园区" />
             </el-form-item>
@@ -112,7 +112,7 @@
             </el-form-item>
 
             <el-form-item label="设备模型" prop="facsModel">
-              <el-select v-model="form.facsModel" style="width:100%">
+              <el-select v-model="form.facsModel" style="width:100%" @change="handleModelChange">
                 <el-option
                   v-for="item in modelList"
                   :label="item.modelName"
@@ -121,6 +121,56 @@
                 />
               </el-select>
             </el-form-item>
+            <!-- 这里可以展示属性名称和属性值 -->
+            <div v-if="attrList.length > 0" class="attr-list-container">
+              <h3 >模型属性:</h3>
+              <ul>
+                <li v-for="attr in attrList" :key="attr.attrKey" class="attr-item">
+                  <span class="attr-name">{{ attr.attrName }} ({{ attr.attrUnit }}):</span>
+                  <!-- 使用 el-input 组件允许用户编辑属性值 -->
+                  <el-input
+                    v-model="attrValuesMap[attr.attrKey]"
+                    placeholder="点击编辑"
+                    size="small"
+                   @blur="updateAttrValue(attr.attrKey, attrValuesMap[attr.attrKey])"
+
+                  >
+                  </el-input>
+                </li>
+              </ul>
+            </div>
+
+            <h3 class="attr-list-container"  v-if="attrList.length > 0">自定义属性
+            <el-form-item label="" prop="attrList"  >
+              <el-table class="attr-table" v-loading="loading" :data="form.customAttrs" max-height="280px" key="'customAttrs'" >
+                <el-table-column label="标识" align="center" prop="attrKey">
+                  <template slot-scope="scope">
+                    <el-input size="mini" v-model="scope.row.attrKey" placeholder="请输入标识" />
+                  </template>
+                </el-table-column>
+                <el-table-column label="属性名" align="center" prop="attrName">
+                  <template slot-scope="scope">
+                    <el-input size="mini" v-model="scope.row.attrName" placeholder="请输入属性名" />
+                  </template>
+                </el-table-column>
+                <el-table-column label="属性值" align="center" prop="attrValue" >
+                  <template slot-scope="scope">
+                    <el-input size="mini" v-model="scope.row.attrValue" placeholder="请输入属性值" />
+                  </template>
+                </el-table-column>
+                <el-table-column align="center" label="操作">
+                  <template slot="header">
+                    <div class="operateBtns"  @click="addCustomAttr" >
+                      <span>添加</span><i class="el-icon-circle-plus-outline"></i>
+                    </div>
+                  </template>
+                  <template slot-scope="scope">
+                    <i class="el-icon-delete" @click="deleteCustomAttr(scope.$index)"></i>
+                  </template>
+                </el-table-column>
+              </el-table>
+            </el-form-item>
+            </h3>
 
             <el-form-item label="启用状态" prop="enable">
               <el-select v-model="form.enable" style="width:100%">
@@ -163,7 +213,6 @@
             </div>
             <div v-for="(item, index) in attrData" :key="index">
               <p>属性名称:{{ item.attrName }}</p>
-<!--              <p>属性标识:{{ item.attrKey }}</p>-->
               <p>属性值:{{ item.attrValue }}</p>
               <p>属性单位:{{ item.attrUnit }}</p>
               <!-- 在每个条目之后添加横线,除了最后一个条目 -->
@@ -219,13 +268,17 @@ import { areaTreeSelect } from '@/api/basecfg/area'
 import Treeselect from '@riophae/vue-treeselect'
 import '@riophae/vue-treeselect/dist/vue-treeselect.css'
 import {getModelByCode, listAllModel, listModel} from '@/api/basecfg/objModel'
-
+import {getObjAttr} from "@/api/basecfg/objAttribute";
+import { addAttrValueBatch, getAttrValue, listAttrValue} from "@/api/basecfg/objAttributeValue";
 export default {
   name: 'Facs',
-  components: { Treeselect },
+  components: {Treeselect},
   data() {
     return {
-      code:'',
+      attrList: [], // 属性模板数组
+      attrValues: [],
+      attrValuesMap: {},
+
       showDrawer: false,
       // 遮罩层
       loading: true,
@@ -241,7 +294,7 @@ export default {
       total: 0,
       // 能源设施/系统表格数据
       facsList: [],
-      modelList:[],
+      modelList: [],
       // 弹出层标题
       title: '',
       // 是否显示弹出层
@@ -258,8 +311,8 @@ export default {
       facsCategoryOptions: undefined,
       facsSubCategoryOptions: undefined,
       enableOptions: [
-        { code: 0, name: '关闭' },
-        { code: 1, name: '启用' }
+        {code: 0, name: '关闭'},
+        {code: 1, name: '启用'}
       ],
       // 查询参数
       queryParams: {
@@ -270,7 +323,8 @@ export default {
         facsCategory: 'E',
         facsSubCategory: null,
         enable: null,
-        refArea: null
+        refArea: null,
+        customAttrs: null
       },
       // 表单参数
       form: {
@@ -279,21 +333,23 @@ export default {
         facsName: null,
         facsCategory: null,
         facsSubCategory: null,
-        facsModel:null,
+        facsModel: null,
         enable: null,
         refArea: null,
         createTime: null,
-        updateTime: null
+        updateTime: null,
+        customAttrs: [] // 自定义属性数组
       },
       // 表单校验
       rules: {
-        facsCode: [{ required: true, message: '设施代码不能为空', trigger: 'blur' }],
-        facsName: [{ required: true, message: '设施名称不能为空', trigger: 'blur' }],
-        facsCategory: [{ required: true, message: '设施分类不能为空', trigger: 'change' }],
-        refArea: [{ required: true, message: '归属区域代码不能为空', trigger: 'blur' }]
+        facsCode: [{required: true, message: '设施代码不能为空', trigger: 'blur'}],
+        facsName: [{required: true, message: '设施名称不能为空', trigger: 'blur'}],
+        facsCategory: [{required: true, message: '设施分类不能为空', trigger: 'change'}],
+        refArea: [{required: true, message: '归属区域代码不能为空', trigger: 'blur'}]
       },
       curRow: {},
       attrData: [],
+      attrUnits:[],
       abilityData: [],
       eventData: [],
       attrForm: {
@@ -328,7 +384,8 @@ export default {
     // 根据名称筛选区域树
     areaName(val) {
       this.$refs.tree.filter(val);
-    }
+    },
+
   },
   created() {
     this.getList()
@@ -336,6 +393,11 @@ export default {
     this.getAllFacsCategory()
     this.getSubCategorygetByCode()
     this.getFacsModel()
+    this.$set(this.form, 'customAttrs', []);
+
+
+
+
   },
   methods: {
     /** 查询能源设施/系统列表 */
@@ -386,12 +448,62 @@ export default {
       const id = row.id || this.ids
       getFacs(id).then(response => {
         this.form = response.data
+        console.log('修改按钮展示的数据', this.form)
         this.open = true
         this.title = '修改能源设施'
+        // 获取自定义属性值
       })
     },
-    /** 提交按钮 */
+     /** 提交按钮 */
     submitForm() {
+      // 重置 attrList 和 form.customAttrs
+      if (!this.attrList) {
+        this.attrList = [];
+      }
+      if (!this.form.customAttrs) {
+        this.form.customAttrs = [];
+      }
+      // 准备要发送的数据
+      let dataToSubmit = [];
+      // 添加模型属性数据
+      this.attrList.forEach(attr => {
+        const attrName=attr.attrName;
+        const attrKey = attr.attrKey;
+        const attrValue = this.attrValuesMap[attrKey];
+        const existingIndex = dataToSubmit.findIndex(item => item.attrKey === attrKey);
+        if (existingIndex === -1) {
+          // 如果attrKey不存在于dataToSubmit中,则添加
+          dataToSubmit.push({
+            modelCode: this.form.facsModel, // 这里填写模型代码
+            objCode: this.form.facsCode, // 这里填写设备代码
+            objType: 1, // 这里填写对象类型
+            attrKey: attrKey,
+            attrValue: attrValue,
+            attrName: attrName
+
+          });
+        }
+      });
+
+       // 添加自定义属性数据
+       this.form.customAttrs.forEach(customAttr => {
+         const attrName= customAttr.attrName;
+         const attrKey = customAttr.attrKey;
+         const attrValue = customAttr.attrValue;
+         const existingIndex = dataToSubmit.findIndex(item => item.attrKey === attrKey);
+         if (existingIndex === -1) {
+           // 如果attrKey不存在于dataToSubmit中,则添加
+           dataToSubmit.push({
+             modelCode: '', // 这里填写模型代码
+             objCode: this.form.facsCode, // 这里填写设备代码
+             objType: 1, // 这里填写对象类型
+             attrKey: attrKey,
+             attrValue: attrValue,
+             attrName:attrName
+           });
+         }
+       });
+
       this.$refs['form'].validate(valid => {
         if (valid) {
           if (this.form.id != null) {
@@ -399,13 +511,51 @@ export default {
               this.$modal.msgSuccess('修改成功')
               this.open = false
               this.getList()
-            })
+            }).catch(error => {
+              console.error('修改失败:', error);
+              this.$message.error('修改失败');
+            });
+
+            if (dataToSubmit.length > 0) {
+              addAttrValueBatch(dataToSubmit)
+                .then(response => {
+                  if (response.code === 200) {
+                    this.$message.success('属性添加成功');
+                  } else {
+                    this.$message.error('属性添加失败');
+                  }
+                }).catch(error => {
+                console.error('属性添加失败:', error);
+                this.$message.error('属性添加失败');
+              });
+            } else {
+             // this.$message.info('没有属性需要添加');
+            }
           } else {
             addFacs(this.form).then(response => {
               this.$modal.msgSuccess('新增成功')
               this.open = false
               this.getList()
-            })
+            }).catch(error => {
+              console.error('新增失败:', error);
+              this.$message.error('新增失败');
+            });
+
+            if (dataToSubmit.length > 0) {
+              addAttrValueBatch(dataToSubmit)
+                .then(response => {
+                  if (response.code === 200) {
+                    this.$message.success('属性添加成功');
+                  } else {
+                    this.$message.error('属性添加失败');
+                  }
+                }).catch(error => {
+                console.error('属性添加失败:', error);
+                this.$message.error('属性添加失败');
+              });
+            } else {
+              // this.$message.info('没有属性需要添加');
+            }
           }
         }
       })
@@ -413,17 +563,33 @@ export default {
     // 设配详情
     handleDetail(row) {
       this.showDrawer = true
-      this.curRow= row
-      console.log("data",this.curRow)
+      this.curRow = row
+      console.log("data", this.curRow)
       this.subKey = this.$options.data().subKey
       getModelByCode(this.curRow.facsModel).then(response => {
-        const code=response.data
-        console.log("code",code)
-        this.attrData=response.data.attrList
-        this.eventData=response.data.eventList
-        this.abilityData=response.data.abilityList
+        const code = response.data
+        console.log("code", code)
+        this.eventData = response.data.eventList
+        this.abilityData = response.data.abilityList
 
       })
+
+      getObjAttr(1, this.curRow.facsCode).then(response => {
+        console.log("response值", response.data);
+        const attrs = response.data.attrs;
+        const attrValues = response.data.attrValues;
+
+        // 合并 attrs 和 attrValues 数组
+        const mergedData = attrValues.map(attrValue => {
+          const attr = attrs.find(a => a.attrKey === attrValue.attrKey);
+          return {
+            ...attrValue,
+            attrName: attr ? attr.attrName : attrValue.attrName,
+            attrUnit: attr ? attr.attrUnit : ''
+          };
+        });
+        this.attrData = mergedData;
+      });
     },
 
     /** 删除按钮操作 */
@@ -431,14 +597,15 @@ export default {
       const ids = row.id || this.ids
       this.$modal
         .confirm('是否确认删除能源设施编号为"' + ids + '"的数据项?')
-        .then(function() {
+        .then(function () {
           return delFacs(ids)
         })
         .then(() => {
           this.getList()
           this.$modal.msgSuccess('删除成功')
         })
-        .catch(() => {})
+        .catch(() => {
+        })
     },
     /** 导出按钮操作 */
     handleExport() {
@@ -472,40 +639,108 @@ export default {
         this.facsCategoryOptions = response.data
       })
     },
-    getSubCategorygetByCode () {
+    getSubCategorygetByCode() {
       getFacsCategorygetByCode(this.queryParams.facsCategory).then(response => {
-        this.facsSubCategoryOptions = response.data.subtypeList||[];
+        this.facsSubCategoryOptions = response.data.subtypeList || [];
       })
     },
-    facsCategoryChange () {
+    facsCategoryChange() {
       this.queryParams.facsSubCategory = ''
       this.getSubCategorygetByCode()
       this.handleQuery()
     },
-    getFacsModel(){
-      listAllModel(1).then(response => {
-        this.modelList = response.data;
-        console.log("ListAllmodel",this.modelList)
 
+
+    /**自定义属性表格*/
+    addCustomAttr() {
+      // 添加一个新的自定义属性
+      if (!Array.isArray(this.form.customAttrs)) {
+        this.form.customAttrs = [];
+      }
+       this.form.customAttrs.push({
+         attrKey: '',
+         attrName: '',
+         attrValue: ''
+       });
+       // 强制更新视图
+      this.$forceUpdate();
+
+  },
+  deleteCustomAttr(index) {
+    // 删除指定索引的自定义属性
+    if (this.form.customAttrs.length > 0) {
+      this.form.customAttrs.splice(index, 1);
+    }
+
+  },
+
+  /**模型属性*/
+  updateAttrValue(attrKey, newValue) {
+    this.attrValuesMap[attrKey] = newValue;
+  },
+
+  getFacsModel() {
+    listAllModel(1).then(response => {
+      this.modelList = response.data;
+      this.modelList.forEach(model => {
+        console.log(model.modelCode);
       });
+    });
+  },
+  handleModelChange(modelCode) {
+    console.log("新增的界面进入",modelCode)
+    if (modelCode) {
+      this.getModelByCode(modelCode);
+      console.log("新增的界面进入",this.form.facsCode)
+      this.getObjAttr(1, this.form.facsCode);
     }
-  }
+  },
+  getModelByCode(modelCode) {
+    getModelByCode(modelCode).then(response => {
+      // this.attrList = response.data.attrList;
+      const filteredAttrList = response.data.attrList.filter(attr => attr.attrType === 0);
+      this.attrList = filteredAttrList;
+
+    });
+  },
+  getObjAttr(objType, facsCode) {
+    getObjAttr(objType, facsCode).then(response => {
+      // const attrs = response.data.attrs;
+      const attrs = response.data.attrs.filter(attr => attr.attrType === 0);
+      console.log("attrs", attrs);
+      const attrValues = response.data.attrValues || []; // 确保是一个数组
+      console.log("attrValues", attrValues);
+
+      // 创建一个映射对象,用于存储 attrKey 与对应的 attrValue
+      const attrValuesMap = {};
+
+      // 遍历 attrs 数组
+      attrs.forEach(attr => {
+        // 查找 attrValues 数组中是否有匹配的 attrKey
+        const attrValueObj = attrValues.find(value => value.attrKey === attr.attrKey);
+        // 如果找到匹配的 attrValue,更新 attrValuesMap
+        if (attrValueObj) {
+          attrValuesMap[attr.attrKey] = attrValueObj.attrValue;
+        } else {
+          // 如果没有找到匹配的 attrValue,则设置为 '暂无数据'
+          attrValuesMap[attr.attrKey] = '';
+        }
+      });
+
+      // 更新 attrValuesMap 到组件的数据中
+      this.attrValuesMap = attrValuesMap;
+      // 打印更新后的 attrValuesMap,用于调试
+      console.log("Updated attrValuesMap", this.attrValuesMap);
+
+    });
+  },
+}
+
 }
 </script>
 
 <style lang="scss" scoped>
-.sub-table {
-  .el-icon-delete {
-    cursor: pointer;
-  }
-  .operateBtns {
-    cursor: pointer;
-    i {
-      color: #1990ff;
-      margin-left: 5px;
-    }
-  }
-}
+
 .drawer-content {
   padding: 0 20px;
 }
@@ -520,4 +755,25 @@ export default {
   font-weight: bold; /* 字体加粗 */
 }
 
+.attr-list-container {
+  border: 1px solid #ccc; /* 给ul添加外框 */
+  padding: 10px; /* 内边距 */
+  margin: 10px 0; /* 外边距 */
+  font-weight: bold; /* 加粗标题 */
+}
+
+.attr-list-container h3 {
+  font-weight: bold; /* 加粗标题 */
+}
+
+.attr-item {
+  list-style-type: none; /* 移除列表项前的默认符号 */
+  margin-bottom: 5px; /* 列表项之间的间距 */
+}
+
+.attr-name {
+  font-weight: bold; /* 加粗属性名称 */
+}
+
+
 </style>