瀏覽代碼

清单模板行引用问题

zeweizhong 6 年之前
父節點
當前提交
5c1a714279
共有 2 個文件被更改,包括 20 次插入0 次删除
  1. 0 0
      .tgitconfig
  2. 20 0
      modules/pm/controllers/new_proj_controller.js

+ 0 - 0
.tgitconfig


+ 20 - 0
modules/pm/controllers/new_proj_controller.js

@@ -15,6 +15,21 @@ import EngineeringLibModel from "../../users/models/engineering_lib_model";
 
 module.exports = {
     copyTemplateData: async function (property, newProjID, callback) {
+        // 原ID引用更新成新ID引用
+        function parseCalcBase(calcBase, uuidMapping) {
+            const orgIDRefs = [...new Set(calcBase.match(/@\d+/g))];
+            orgIDRefs.forEach(orgRef => {
+                const orgID = orgRef.match(/\d+/)[0];
+                const newID = uuidMapping[orgID] || null;
+                // ID匹配不上则不转换这个引用
+                if (!newID) {
+                    return;
+                }
+                const replaceStr = `@${newID}`;
+                calcBase = calcBase.replace(new RegExp(`${orgRef}\\b`, 'g'), replaceStr);
+            });
+            return calcBase;
+        }
         async.parallel([
             async function (cb) {
                 // 获取清单模板数据
@@ -27,11 +42,16 @@ module.exports = {
                 for(let bill of billsDatas){
                     uuidMaping[bill.ID] = uuidV1();
                 }
+                const reg = /@\d+/;
                 billsDatas.forEach(function (template) {
                     template.projectID = newProjID;
                     template.ID = uuidMaping[template.ID] ? uuidMaping[template.ID] : -1;
                     template.ParentID = uuidMaping[template.ParentID] ? uuidMaping[template.ParentID] : -1;
                     template.NextSiblingID = uuidMaping[template.NextSiblingID] ? uuidMaping[template.NextSiblingID] : -1;
+                    const needToParseCalcBase = template.calcBase && reg.test(template.calcBase);
+                    if (needToParseCalcBase) {
+                        template.calcBase = parseCalcBase(template.calcBase, uuidMaping);
+                    }
                 });
                 billsData.insertData(billsDatas, callback);
             },