田源
2024-04-18 5db4019b73a704d8ecdcf7892e39e6190699846d
整合前几日代码
已修改3个文件
284 ■■■■ 文件已修改
Source/UBCS-WEB/src/api/vciAttrbute.js 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS-WEB/src/views/integration/integrationIndex.vue 147 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS-WEB/src/views/integration/vciAttribute.vue 121 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/UBCS-WEB/src/api/vciAttrbute.js
@@ -26,3 +26,19 @@
    data
  })
}
//自动填充
export const getByGroupAttrMapping = (data) => {
  return request({
    url: '/api/ubcs-applyjtcodeservice/groupAttrPoolMapping/getByGroupAttrKeyList',
    method: 'post',
    data
  })
}
// 取值范围自动填充
export const getEnumAttrByClsOidAndAttrId = (data) => {
  return request({
    url: '/api/ubcs-applyjtcodeservice/groupAttrPoolMapping/getEnumAttrByClsOIdAndAttrId',
    method: 'post',
    data
  })
}
Source/UBCS-WEB/src/views/integration/integrationIndex.vue
@@ -50,6 +50,11 @@
                       @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">新 增-->
@@ -74,7 +79,7 @@
                       @row-dblclick="handleRowClick">
              <template slot="menuLeft">
                <el-button icon="el-icon-coordinate" size="small" type="primary"
                           @click="handlerAuto">自动填充
                           @click="handlerBottomAuto">自动填充
                </el-button>
              </template>
            </avue-crud>
@@ -98,7 +103,7 @@
  listCodeAttributeByClassId,
  syncClassifyModel
} from '@/api/integration/integration.js'
import {getPage} from "@/api/omd/OmdAttribute";
import {getByGroupAttrMapping, getEnumAttrByClsOidAndAttrId} from "@/api/vciAttrbute";
export default {
  components: {
@@ -122,6 +127,7 @@
      highlightCurrentRow: true,
    }
    return {
      selectRow: "",
      targetNameList: [], // 元数据返回名称
      defaultCheckedKeys: [],
      isNodeDisabled: true,
@@ -179,7 +185,6 @@
        refreshBtn: false,
        delBtn: false,
        addBtn: false,
        index: true,
        columnBtn: false,
        searchShow: true,
        emptyBtn: false,
@@ -191,6 +196,7 @@
        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},
@@ -245,7 +251,8 @@
      mappingForm: {},
      // 定时器
      times: null,
      TreeSelectOid: ""
      TreeOid: "",
      tableSelectId: ''
    }
  },
@@ -277,6 +284,102 @@
    }
  },
  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() !== "") // 过滤掉name为空的属性
        .map(item => {
@@ -284,7 +387,7 @@
            targetAttrId: item.oid,
            targetAttrKey: item.id,
            targetAttrName: item.name,
            disabled: false
            // disabled: false
          }
        });
    },
@@ -312,12 +415,12 @@
        this.loading = false
        this.mappingData = response.data.data
        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;
          }
        }
        // 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;
        //   }
        // }
      }
    },
    // 接口获取属性映射取值范围
@@ -429,11 +532,12 @@
      }
      for (const item of this.mappingData) {
        item.$cellEdit = false;
        if (item.targetAttrName) {
        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({
@@ -484,6 +588,7 @@
    },
    // 左侧树点击
    handelTreeCell(event) {
      this.TreeOid = event.oid;
      this.treeParam.codeClassifyId = event.oid
      this.form.groupValue = ''
      this.groupVal = ''
@@ -517,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(() => {
@@ -556,10 +664,15 @@
        // 获取目标属性信息
        const {targetAttrId, targetAttrKey, targetAttrName} = await getTargetCorresponding(row);
        // 更新行数据
        Object.assign(row, {targetAttrId, targetAttrKey, targetAttrName});
        const response = await batchAddSave({dockingPreAttrMappingVOList: this.mappingData});
        // 更新行数据
        Object.assign(row, {
          targetAttrId: targetAttrId.toLowerCase(),
          targetAttrKey: targetAttrKey.toLowerCase(),
          targetAttrName: targetAttrName.toLowerCase()
        });
        const response = await batchAddSave({dockingPreAttrMappingVOList: [row]});
        if (response.status === 200) {
          this.$message({
@@ -585,12 +698,14 @@
      }
    },
    setCurrentRow(selection, row) {
      console.log(selection, row)
      this.mappingForm = row
      this.disabledPush = false
    },
    handleSelectAll(selection) {
      this.$refs.crudMapping.toggleSelection()
    }
    },
  }
}
</script>
Source/UBCS-WEB/src/views/integration/vciAttribute.vue
@@ -4,7 +4,7 @@
               @size-change="sizeChange" @row-dblclick="handleRowClick" @row-update="handleUpdate"
               @selection-change="selectChange">
      <template slot="menuLeft">
        <!--        <el-button plain size="small" type="success" @click="savaHandler">保存</el-button>-->
        <el-button plain size="small" type="success" @click="savaHandler">保存</el-button>
        <el-button plain size="small" type="primary" @click="syncHandler">同步</el-button>
      </template>
    </avue-crud>
@@ -25,7 +25,7 @@
        calcHeight: 20,
        headerAlign: "center",
        border: true,
        // selection: true,
        selection: true,
        tip: false,
        index: true,
        refreshBtn: false,
@@ -80,12 +80,7 @@
    }
  },
  created() {
    const params = {
      'conditionMap[groupAttrKey_like]': 'RY_',
      page: this.page.currentPage,
      limit: this.page.pageSize
    }
    this.onLoad(params)
    this.onLoad()
    this.codeColumnOnload()
  },
  computed: {
@@ -107,7 +102,11 @@
    selectChange(list) {
      this.selectList = list;
    },
    async onLoad(params) {
    async onLoad() {
      const params = {
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      getGroupAttrPoolALlList(params).then(res => {
        const data = res.data.data;
        this.data = data.records;
@@ -140,18 +139,24 @@
      // row.codeMetaAttrName因为下拉框value值原因绑定为codeMetaAttrOid
      let updataList = []
      // console.log(this.ChangeName)
      // console.log(row.codeMetaAttrName)
      // if (this.ChangeName && this.ChangeName === row.codeMetaAttrName) {
      //   updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrOid)
      // } else {
      //   console.log('2')
      //     updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
      // }
      updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
      if (this.ChangeName && this.ChangeName === row.codeMetaAttrName) {
        updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrOid)
      } else {
        if (row.codeMetaAttrName !== "" && row.codeMetaAttrName) {
          updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
        }
      }
      // 因为row里面的值是不正确的 重新赋值一遍
      if (updataList) {
        const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
        Object.assign(row, {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName});
        Object.assign(row, {
          codeMetaAttrOid: codeMetaAttrOid.toLowerCase(),
          codeMetaAttrKey: codeMetaAttrKey.toLowerCase(),
          codeMetaAttrName: codeMetaAttrName.toLowerCase()
        });
      }
      const objet = {
@@ -162,6 +167,7 @@
        codeMetaAttrKey: row.codeMetaAttrKey,
        codeMetaAttrName: row.codeMetaAttrName
      }
      const response = await editGroupAttr([objet])
      if (response.data.success) {
        this.$message.success('保存成功!')
@@ -174,30 +180,41 @@
      } else {
        const hasTrueValue = this.selectList.some(item => !item.$cellEdit);
        if (hasTrueValue) {
          this.$message.warning('请开启编辑后保存!')
        } else {
          let saveList = []
          for (const item of this.selectList) {
            console.log(item)
            const updataList = this.codeMetaColumn.dicData.find(p => p.codeMetaAttrOid === item.codeMetaAttrName);
            const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
            Object.assign(item, {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName});
            console.log(updataList)
            item.$cellEdit = false;
            saveList.push({
              oid: item.oid,
              groupAttrKey: item.groupAttrKey,
              groupAttrName: item.groupAttrName,
              codeMetaAttrOid: item.codeMetaAttrOid,
              codeMetaAttrKey: item.codeMetaAttrKey,
              codeMetaAttrName: item.codeMetaAttrName
            })
          }
          const response = await editGroupAttr(saveList)
          if (response.data.success) {
            this.$message.success('保存成功!')
          }
          this.$message.warning('请开启编辑后进行保存!')
          return
        }
        const codeMetaInput = this.selectList.some(item => item.codeMetaAttrName === "");
        if (codeMetaInput) {
          this.$message.warning('请检查已勾选数据中是否存在未选择的项!');
          return
        }
        let saveList = []
        for (const item of this.selectList) {
          const updataList = this.codeMetaColumn.dicData.find(column => column.codeMetaAttrOid === item.codeMetaAttrName);
          if (updataList) {
            const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
            Object.assign(item, {
              codeMetaAttrOid: codeMetaAttrOid.toLowerCase(),
              codeMetaAttrKey: codeMetaAttrKey.toLowerCase(),
              codeMetaAttrName: codeMetaAttrName.toLowerCase()
            });
          }
          item.$cellEdit = false;
          saveList.push({
            oid: item.oid,
            groupAttrKey: item.groupAttrKey,
            groupAttrName: item.groupAttrName,
            codeMetaAttrOid: item.codeMetaAttrOid,
            codeMetaAttrKey: item.codeMetaAttrKey,
            codeMetaAttrName: item.codeMetaAttrName
          })
        }
        const response = await editGroupAttr(saveList)
        if (response.data.success) {
          this.$message.success('保存成功!')
          await this.onLoad()
        }
      }
    },
    async syncHandler() {
@@ -214,32 +231,20 @@
        const response = await syncGroupAttrMapping(syncList)
        if (response.data.success) {
          this.$message.success(response.data.msg);
          const params = {
            'conditionMap[groupAttrKey_like]': 'RY_',
            page: this.page.currentPage,
            limit: this.page.pageSize
          }
          await this.onLoad(params)
          await this.onLoad()
        }
      }
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      const params = {
        'conditionMap[groupAttrKey_like]': 'RY_',
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      this.onLoad(params)
      this.onLoad()
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      const params = {
        'conditionMap[groupAttrKey_like]': 'RY_',
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      this.onLoad(params)
      this.onLoad()
    },
  }
}