From 5db4019b73a704d8ecdcf7892e39e6190699846d Mon Sep 17 00:00:00 2001
From: 田源 <lastanimals@163.com>
Date: 星期四, 18 四月 2024 00:05:28 +0800
Subject: [PATCH] 整合前几日代码

---
 Source/UBCS-WEB/src/views/integration/integrationIndex.vue |  250 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 227 insertions(+), 23 deletions(-)

diff --git a/Source/UBCS-WEB/src/views/integration/integrationIndex.vue b/Source/UBCS-WEB/src/views/integration/integrationIndex.vue
index d175b2d..5cb52d3 100644
--- a/Source/UBCS-WEB/src/views/integration/integrationIndex.vue
+++ b/Source/UBCS-WEB/src/views/integration/integrationIndex.vue
@@ -50,10 +50,15 @@
                        @row-click="handleMapingClick" @row-dblclick="handleMapingRowClick"
                        @selection-change="selectionChange"
                        @select-all="handleSelectAll">
+              <template slot="radio"
+                        slot-scope="{row}">
+
+                <el-radio v-model="selectRow" :label="row.$index">-</el-radio>
+              </template>
               <template slot="menuLeft">
-                <el-button :disabled="disabledPush" icon="el-icon-plus" size="small" type="primary"
-                           @click="dialogPush = true">鏂� 澧�
-                </el-button>
+                <!--                <el-button :disabled="disabledPush" icon="el-icon-plus" size="small" type="primary"-->
+                <!--                           @click="dialogPush = true">鏂� 澧�-->
+                <!--                </el-button>-->
                 <el-button icon="el-icon-check" size="small" type="primary" @click="handleSave">淇� 瀛�
                 </el-button>
                 <el-button icon="el-icon-connection" size="small" type="primary"
@@ -62,6 +67,9 @@
                 <el-button icon="el-icon-connection" size="small" type="primary"
                            @click="handleSync('one')">鍚屾璇︾粏妯″瀷
                 </el-button>
+                <el-button icon="el-icon-coordinate" size="small" type="primary"
+                           @click="handlerAuto">鑷姩濉厖
+                </el-button>
               </template>
             </avue-crud>
           </el-card>
@@ -69,6 +77,11 @@
             <avue-crud ref="crudRange" :data="rangeData" :option="optinoRange" :style="{ marginTop: '-20px'}"
                        @row-update="handleUpdate"
                        @row-dblclick="handleRowClick">
+              <template slot="menuLeft">
+                <el-button icon="el-icon-coordinate" size="small" type="primary"
+                           @click="handlerBottomAuto">鑷姩濉厖
+                </el-button>
+              </template>
             </avue-crud>
           </el-card>
         </el-card>
@@ -90,6 +103,7 @@
   listCodeAttributeByClassId,
   syncClassifyModel
 } from '@/api/integration/integration.js'
+import {getByGroupAttrMapping, getEnumAttrByClsOidAndAttrId} from "@/api/vciAttrbute";
 
 export default {
   components: {
@@ -113,6 +127,8 @@
       highlightCurrentRow: true,
     }
     return {
+      selectRow: "",
+      targetNameList: [], // 鍏冩暟鎹繑鍥炲悕绉�
       defaultCheckedKeys: [],
       isNodeDisabled: true,
       // 琛ㄥ崟鍊�
@@ -138,8 +154,8 @@
       optinoRange: {
         title: '灞炴�ф槧灏勫彇鍊艰寖鍥�',
         maxHeight: '280px',
-        header: false,
         rowKey: 'oid',
+        refreshBtn: false,
         column: [
           {label: '灞炴�ч泦鍥㈡灇涓惧��', prop: 'numTextValue', minWidth: 80},
           {label: '闆嗗洟灞炴�ф灇涓炬樉绀哄悕绉�', prop: 'numText', minWidth: 80},
@@ -167,7 +183,20 @@
         rowKey: 'oid',
         selection: false,
         refreshBtn: false,
+        delBtn: false,
+        addBtn: false,
+        columnBtn: false,
+        searchShow: true,
+        emptyBtn: false,
+        searchBtn: false,
+        searchShowBtn: false,
+        cellBtn: true,
+        border: true,
+        searchMenuSpan: 8,
+        highlightCurrentRow: true,
+        $cellEdit: true,
         column: [
+          {label: '', prop: 'radio', width: 60, hide: false},
           {label: '闆嗗洟鍒嗙被', prop: 'sourceClassifyName', minWidth: 80},
           {label: '鎵�灞炶鍥�', prop: 'viewName', minWidth: 80},
           {label: '闆嗗洟灞炴��', prop: 'sourceAttrName', minWidth: 80},
@@ -175,17 +204,24 @@
           {
             label: '灞炴�у悕绉�',
             prop: 'targetAttrName',
-            minWidth: 80,
-          },
-          {
-            label: '榛樿鍊�',
-            prop: 'defaultValue',
-            minWidth: 140,
+            type: 'select',
             cell: true,
-            blur: (value) => window.handleBlur(value, 'mapping')
+            filterable: true,
+            minWidth: 80,
+            props: {
+              label: 'targetAttrName',
+              value: 'targetAttrName'
+            },
+            dicData: [],
           },
+          // {
+          //   label: '榛樿鍊�',
+          //   prop: 'defaultValue',
+          //   minWidth: 140,
+          //   cell: true,
+          //   blur: (value) => window.handleBlur(value, 'mapping')
+          // },
         ],
-        ...options
       },
       // 涓绘暟鎹垎绫绘爲
       treeData: [],
@@ -215,7 +251,8 @@
       mappingForm: {},
       // 瀹氭椂鍣�
       times: null,
-      TreeSelectOid: ""
+      TreeOid: "",
+      tableSelectId: ''
 
     }
   },
@@ -231,7 +268,6 @@
   mounted() {
     let that = this
     window.handleBlur = that.handleBlur
-
   },
   computed: {
     filtermapping() {
@@ -242,9 +278,119 @@
         return obj.targetAttrName
       })
       return transfer
+    },
+    targetColumn() {
+      return this.optionMapping.column.find(column => column.prop === 'targetAttrName');
     }
   },
   methods: {
+    handlerAuto() {
+      if (!this.TreeOid || this.TreeOid === "") {
+        return;
+      }
+      // 杩囨护鍑洪泦鍥㈠睘鎬х殑key鍊�
+      const groupArray = this.mappingData ? this.mappingData.map(obj => obj.sourceAttrKey) : [];
+      // 鑾峰彇鍒伴渶瑕佽嚜鍔ㄥ~鍏呯殑鍊�
+      getByGroupAttrMapping({classifyId: this.TreeOid, groupAttrKeyList: groupArray})
+        .then(res => {
+          //  鍗曠嫭鎶婅繑鍥炲�肩殑groupAttrKey鏀句竴涓暟缁勶紝鐒跺悗杩囨护鍑鸿繑鍥炲�肩殑groupAttrKey鏄惁绛変簬琛ㄦ牸鏁版嵁涓殑sourceAttrKey
+          // const groupReturnData = res.data && res.data.data ? res.data.data.map(item => item.groupAttrKey) : [];
+          const groupReturnData = res.data.data;
+          // 杩囨护鍖归厤
+          // console.log(groupReturnData)
+          this.mappingData.forEach(mappingItem => {
+            groupReturnData.forEach(groupItem => {
+              if (mappingItem.sourceAttrKey === groupItem.groupAttrKey) {
+                const result = this.transferData.find(obj => obj.id.toLowerCase() === groupItem.codeMetaAttrKey.toLowerCase());
+                if (result) {
+                  mappingItem.targetAttrId = groupItem.codeMetaAttrOid.toLowerCase();
+                  mappingItem.targetAttrName = groupItem.codeMetaAttrName.toLowerCase();
+                  mappingItem.targetAttrKey = groupItem.codeMetaAttrKey.toLowerCase();
+                } else {
+                  mappingItem.targetAttrId = '';
+                  mappingItem.targetAttrName = '';
+                  mappingItem.targetAttrKey = '';
+                }
+              }
+            })
+          })
+          this.$message.success('濉厖鎴愬姛锛�');
+        })
+        .catch(error => {
+          console.log(error)
+          this.$message.error('濉厖澶辫触锛岃绋嶅悗鍐嶈瘯锛�');
+        });
+    },
+    handlerBottomAuto() {
+      if (this.rangeData.length <= 0) {
+        this.$message.warning('璇烽�夋嫨涓�鏉℃灇涓剧被鍨嬪睘鎬�!')
+        return
+      }
+      getEnumAttrByClsOidAndAttrId({classifyId: this.TreeOid, codeMetaAttrKey: this.tableSelectId}).then(res => {
+        const data = res.data.data;
+        this.rangeData.forEach(rangeItem => {
+          data.forEach(dataItem => {
+            const similarity = this.calculateSimilarity(rangeItem.numText, dataItem.itemName);
+            if (similarity > 70) {
+              rangeItem.targetNumTextValue = rangeItem.numTextValue;
+              rangeItem.targetNumText = dataItem.itemName;
+            }
+          })
+        })
+
+      })
+    },
+    calculateSimilarity(str1, str2) {
+      // 璁$畻缂栬緫璺濈
+      function editDistance(s1, s2) {
+        s1 = s1.toLowerCase();
+        s2 = s2.toLowerCase();
+
+        const costs = [];
+        for (let i = 0; i <= s1.length; i++) {
+          let lastValue = i;
+          for (let j = 0; j <= s2.length; j++) {
+            if (i === 0)
+              costs[j] = j;
+            else {
+              if (j > 0) {
+                let newValue = costs[j - 1];
+                if (s1.charAt(i - 1) !== s2.charAt(j - 1))
+                  newValue = Math.min(Math.min(newValue, lastValue),
+                    costs[j]) + 1;
+                costs[j - 1] = lastValue;
+                lastValue = newValue;
+              }
+            }
+          }
+          if (i > 0)
+            costs[s2.length] = lastValue;
+        }
+        return costs[s2.length];
+      }
+
+      // 璁$畻鐩镐技搴︾櫨鍒嗘瘮
+      function similarityPercent(s1, s2) {
+        let maxLength = Math.max(s1.length, s2.length);
+        let distance = editDistance(s1, s2);
+        return ((maxLength - distance) / maxLength) * 100;
+      }
+
+      // 璋冪敤鐩镐技搴﹁绠楀嚱鏁板苟杩斿洖鐧惧垎姣斿舰寮忕殑鐩镐技搴�
+      const similarity = similarityPercent(str1, str2);
+      return similarity;
+    },
+    getTargetName(data) {
+      this.targetColumn.dicData = data.filter(item => item.name && item.name.trim() !== "") // 杩囨护鎺塶ame涓虹┖鐨勫睘鎬�
+        .map(item => {
+          return {
+            targetAttrId: item.oid,
+            targetAttrKey: item.id,
+            targetAttrName: item.name,
+            // disabled: false
+          }
+        });
+    },
     // 鎺ュ彛宸︿晶鏍�
     async getReferCodeClassifyTree() {
       this.treeData = []
@@ -268,7 +414,13 @@
       if (response.status === 200) {
         this.loading = false
         this.mappingData = response.data.data
-        // console.log(this.filtermapping)
+
+        // for (const item of this.mappingData) {
+        //   if (item.targetAttrName && item.targetAttrId && item.targetAttrKey) {
+        //     const targetObject = this.targetColumn.dicData.find(obj => obj.targetAttrName === item.targetAttrName);
+        //     targetObject.disabled = true;
+        //   }
+        // }
       }
     },
     // 鎺ュ彛鑾峰彇灞炴�ф槧灏勫彇鍊艰寖鍥�
@@ -288,6 +440,7 @@
       if (response.status === 200) {
         const data = response.data.data
         this.transferData = data;
+        this.getTargetName(data)
         // console.log(data)
       }
     },
@@ -374,6 +527,17 @@
     },
     // 淇濆瓨鎸夐挳
     async handleSave() {
+      const getTargetCorresponding = (row) => {
+        return this.targetColumn.dicData.find(column => column.targetAttrName === row.targetAttrName);
+      }
+      for (const item of this.mappingData) {
+        item.$cellEdit = false;
+        if (item.targetAttrName && !item.targetAttrId && !item.targetAttrKey) {
+          const {targetAttrId, targetAttrKey, targetAttrName} = await getTargetCorresponding(item);
+          Object.assign(item, {targetAttrId, targetAttrKey, targetAttrName});
+        }
+      }
+      this.mappingData[this.selectRow].dockingPreAttrRangeVoList = (this.rangeData)
       const response = await batchAddSave({dockingPreAttrMappingVOList: this.mappingData})
       if (response.status === 200) {
         this.$message({
@@ -424,6 +588,7 @@
     },
     // 宸︿晶鏍戠偣鍑�
     handelTreeCell(event) {
+      this.TreeOid = event.oid;
       this.treeParam.codeClassifyId = event.oid
       this.form.groupValue = ''
       this.groupVal = ''
@@ -457,6 +622,9 @@
     },
     // 闆嗗洟鏄犲皠灞炴�ц閫夋嫨锛堝崟鍑伙級
     handleMapingClick(row) {
+      // console.log(row)
+      this.tableSelectId = row.targetAttrKey || "";
+      this.selectRow = row.$index;
       clearTimeout(this.times)
       this.mappingForm = row
       this.times = setTimeout(() => {
@@ -481,13 +649,42 @@
       done();
     },
     // 灞炴�у彇鍊艰寖鍥村崟鍏冩牸缂栬緫鍚�
-    handleMapingUpdate(row, index, done) {
-      this.$message({
-        showClose: true,
-        message: "淇敼鎴愬姛",
-        type: "success",
-      });
-      done();
+    async handleMapingUpdate(row, index, done) {
+      const getTargetCorresponding = async (row) => {
+        return this.targetColumn.dicData.find(column => column.targetAttrName === row.targetAttrName);
+      };
+
+      try {
+        if (!row.targetAttrName) {
+          this.$message.warning('璇烽�夋嫨瑕佷繚瀛樼殑灞炴�у悕绉帮紒');
+          done();
+          return;
+        }
+
+        // 鑾峰彇鐩爣灞炴�т俊鎭�
+        const {targetAttrId, targetAttrKey, targetAttrName} = await getTargetCorresponding(row);
+
+
+        // 鏇存柊琛屾暟鎹�
+        Object.assign(row, {
+          targetAttrId: targetAttrId.toLowerCase(),
+          targetAttrKey: targetAttrKey.toLowerCase(),
+          targetAttrName: targetAttrName.toLowerCase()
+        });
+
+        const response = await batchAddSave({dockingPreAttrMappingVOList: [row]});
+
+        if (response.status === 200) {
+          this.$message({
+            type: "success",
+            message: "淇敼鎴愬姛!"
+          });
+        }
+      } catch (error) {
+        console.error('澶勭悊鏄犲皠鏇存柊鏃跺嚭閿欙細', error);
+      } finally {
+        done();
+      }
     },
     // 闆嗗洟鏄犲皠灞炴�ч�夋嫨锛堝崟閫夛級
     selectionChange(selection) {
@@ -501,12 +698,14 @@
       }
     },
     setCurrentRow(selection, row) {
+      console.log(selection, row)
       this.mappingForm = row
       this.disabledPush = false
     },
     handleSelectAll(selection) {
       this.$refs.crudMapping.toggleSelection()
-    }
+    },
+
   }
 }
 </script>
@@ -536,5 +735,10 @@
   .el-transfer-panel {
     width: 270px;
   }
+
+  .el-scrollbar__view {
+    height: 100px;
+  }
 }
+
 </style>

--
Gitblit v1.9.3