浏览代码

导入清单模板重复问题

zeweizhong 6 年之前
父节点
当前提交
392b62d91f

+ 1 - 0
config/gulpConfig.js

@@ -49,6 +49,7 @@ module.exports = {
         'lib/JSExpressionEval_src/Date.js',
         'web/building_saas/glj/js/socket.io.slim.js',
         'public/web/socket/connection.js',
+        'public/billsUtil.js',
         'web/building_saas/main/js/models/importStandardInterface.js',
         'web/building_saas/pm/js/**/*.js',
         'lib/ztree/*.js',

+ 17 - 0
modules/main/facade/project_facade.js

@@ -176,6 +176,23 @@ async function updateNodes(datas){
 
         }
     }
+    //test------------------------
+    if (billTasks.length) {
+        console.log(`billTasks===============================`);
+        billTasks.forEach(task => {
+            if (task.updateOne.update.name === '分部分项工程') {
+                console.log(`task.updateOne.filter`);
+                console.log(task.updateOne.filter);
+                console.log(`task.updateOne.update`);
+                console.log(task.updateOne.update);
+            }
+            /*console.log(`task.updateOne.filter`);
+            console.log(task.updateOne.filter);
+            console.log(`task.updateOne.update`);
+            console.log(task.updateOne.update);*/
+        });
+    }
+    //test------------------------
     rationTasks.length>0?asyncTasks.push(ration_model.model.bulkWrite(rationTasks)):'';
     billTasks.length>0?asyncTasks.push(bill_model.model.bulkWrite(billTasks)):"";
     rationGLJTasks.length>0?asyncTasks.push(ration_glj_model.bulkWrite(rationGLJTasks)):"";

+ 2 - 16
modules/pm/controllers/new_proj_controller.js

@@ -9,27 +9,13 @@ let async = require('async');
 const uuidV1 = require('uuid/v1');
 const mongoose = require('mongoose');
 let mainColLibModel = mongoose.model('std_main_col_lib');
+const billsUtil = require('../../../public/billsUtil');
 
 import BillsTemplateModel from "../models/templates/bills_template_model";
 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) {
                 // 获取清单模板数据
@@ -50,7 +36,7 @@ module.exports = {
                     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);
+                        template.calcBase = billsUtil.parseCalcBase(template.calcBase, uuidMaping);
                     }
                 });
                 billsData.insertData(billsDatas, callback);

+ 9 - 1
modules/templates/models/bills_template.js

@@ -8,6 +8,7 @@ let BillsTemplates = mongoose.model('temp_bills');
 let BillsTemplateDAO = function(){};
 import BillsTemplateModel from "../../pm/models/templates/bills_template_model";
 const uuidV1 = require('uuid/v1');
+const billsUtil = require('../../../public/billsUtil');
 
 BillsTemplateDAO.prototype.getTemplate = function (type, callback) {
     if (callback) {
@@ -82,7 +83,9 @@ BillsTemplateDAO.prototype.getNeedfulTemplate = async function (templateLibID) {
     }
     //过滤掉不含清单固定类别的模板数据 (导入接口只包含必要的清单模板数据)
     let needfulDatas = billsDatas.filter(data => getFlag(data));
-    sortToTreeData(needfulDatas);
+    sortSeqToNextSibling(needfulDatas);
+    //sortToTreeData(needfulDatas);
+    billsUtil.resetTreeData(needfulDatas, uuidV1);
     return needfulDatas;
 };
 
@@ -152,10 +155,15 @@ function sortToTreeData(needfulData) {
     for(let bill of needfulData){
         uuidMaping[bill.ID] = uuidV1();
     }
+    const reg = /@\d+/;
     needfulData.forEach(function (template) {
         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 = billsUtil.parseCalcBase(template.calcBase, uuidMaping);
+        }
     });
 }
 

+ 60 - 0
public/billsUtil.js

@@ -0,0 +1,60 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Zhong
+ * @date 2019/11/1
+ * @version
+ */
+
+((factory) => {
+    if (typeof module !== 'undefined') {
+        module.exports = factory();
+    } else {
+        window.BILLS_UTIL = factory();
+    }
+})(() => {
+    // 清单模板各清单重设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;
+    }
+
+    /*
+     * @param {Array}billsList (完整的清单树结构数据)
+     * @param {Function}idFactory 生成ID的方法
+     * @return {void}
+     * */
+    function resetTreeData(billsList, idFactory) {
+        const idMapping = {};
+        idMapping['-1'] = -1;
+        // 建立新ID-旧ID映射
+        billsList.forEach(bills => idMapping[bills.ID] = idFactory());
+        const reg = /@\d+/;
+        billsList.forEach(function (bills) {
+            bills.ID = idMapping[bills.ID] ? idMapping[bills.ID] : -1;
+            bills.ParentID = idMapping[bills.ParentID] ? idMapping[bills.ParentID] : -1;
+            bills.NextSiblingID = idMapping[bills.NextSiblingID] ? idMapping[bills.NextSiblingID] : -1;
+            const needToParseCalcBase = bills.calcBase && reg.test(bills.calcBase);
+            if (needToParseCalcBase) {
+                bills.calcBase = parseCalcBase(bills.calcBase, idMapping);
+            }
+        });
+    }
+
+    return {
+        parseCalcBase,
+        resetTreeData
+    };
+});

+ 2 - 0
web/building_saas/main/js/models/importStandardInterface.js

@@ -1594,6 +1594,8 @@ const ImportXML = (() => {
                     }
                     //提取详细数据
                     let needfulTemplate = _.cloneDeep(templateMapping[curTender.property.templateLibID]);
+                    // 重设模板树结构数据
+                    BILLS_UTIL.resetTreeData(needfulTemplate, uuid.v1);
                     let postTenderData = await transformTender(curTender, IDPlaceholder, needfulTemplate);
                     postTenderData.tender.property.rootProjectID = postConstructData.ID;
                     postEngData.tenders.push(postTenderData);

+ 1 - 0
web/building_saas/pm/html/project-management.html

@@ -951,6 +951,7 @@
 <script src="/lib/JSExpressionEval_src/Date.js"></script>
 <script src="/web/building_saas/glj/js/socket.io.slim.js"></script>
 <script src="/public/web/socket/connection.js"></script>
+<script src="/public/billsUtil.js"></script>
 <script src="/web/building_saas/main/js/models/importStandardInterface.js"></script>
 <script src="/web/building_saas/pm/js/pm_ajax.js"></script>
 <script src="/web/building_saas/pm/js/pm_newMain.js"></script>