瀏覽代碼

清单导入匹配标准库数据

zhongzewei 7 年之前
父節點
當前提交
9dbb570421

+ 51 - 2
modules/main/controllers/bills_controller.js

@@ -11,6 +11,9 @@ let bill_detail = require("../facade/bill_facade");
 let ration_glj = mongoose.model('ration_glj');
 let ration_coe = mongoose.model('ration_coe');
 let rationInstallationModel = mongoose.model('ration_installation');
+let stdBillsModel = mongoose.model('std_bills_lib_bills');
+let stdBillJobsModel = mongoose.model('std_bills_lib_jobContent');
+let stdBillCharacterModel = mongoose.model('std_bills_lib_itemCharacter');
 import fixedFlag from  '../../common/const/bills_fixed';
 const uuidV1 = require('uuid/v1');
 const billType ={
@@ -228,8 +231,16 @@ module.exports = {
                     await billsData.model.create(insertFixedBill);
                     fixedBill = insertFixedBill;
                 }
+                //匹配的清单库
+                const billsLibId = fields.billsLibId !== undefined && fields.billsLibId.length > 0 && fields.billsLibId[0]? parseInt(fields.billsLibId[0]) : null;
+                let stdBills = [], stdJobs = [], stdCharacters = [];
+                if(billsLibId){
+                    stdBills = await stdBillsModel.find({billsLibId: billsLibId, deleted: false});
+                    stdJobs = await stdBillJobsModel.find({billsLibId: billsLibId, deleted: false});
+                    stdCharacters = await stdBillCharacterModel.find({billsLibId: billsLibId, deleted: false});
+                }
                 //将excel数据转换成清单树结构数据
-                let insertDatas = parseToBillData(getValidImportData(sheet[0].data), getColMapping(sheet[0].data), fixedBill, projectID);
+                let insertDatas = parseToBillData(getValidImportData(sheet[0].data), getColMapping(sheet[0].data), fixedBill, projectID, {stdBills: stdBills, stdJobs: stdJobs, stdCharacters: stdCharacters});
                 //删除相关数据
                 let deleteDatas = await billsData.deepDeleteBill([fixedBill], req.session.sessionUser.ssoId);
                 //新增清单数据
@@ -327,7 +338,7 @@ function getImportFlag(sheetName){
     return null;
 }
 //excel数据转换成清单数据
-function parseToBillData(validData, colMapping, fixedBill, projectID){
+function parseToBillData(validData, colMapping, fixedBill, projectID, stdData){
     let rst = [];
     let billIdx = {};
     let preRootID = -1,
@@ -354,6 +365,41 @@ function parseToBillData(validData, colMapping, fixedBill, projectID){
         }
         return null;
     }
+    //excel数据与标准库数据匹配,根据清单前九位编码匹配,匹配成功则获取标准清单对应的工程专业、特征及内容
+    function matchStdBill(excelBill, stdData){
+        let regExp = /^\d{12}$/g;
+        if(regExp.test(excelBill.code)){
+            let nineCode = excelBill.code.substr(0, 9);
+            for(let stdBill of stdData.stdBills){
+                //set programID
+                if(nineCode == stdBill.code){
+                    excelBill.programID = stdBill.engineering ? stdBill.engineering : null;
+                    //set jobContent and itemCharacter
+                    let tempJob = [], tempCharacter = [];
+                    for(let billJob of stdBill.jobs){
+                        for(let stdJob of stdData.stdJobs) {
+                            if (billJob.id == stdJob.id) {
+                                tempJob.push({isChecked: false, serialNo: billJob.serialNo, content: stdJob.content});
+                            }
+                        }
+                    }
+                    for(let billCharacter of stdBill.items){
+                        for(let stdCharacter of stdData.stdCharacters){
+                            if(billCharacter.id == stdCharacter.id){
+                                let eigenvalue = [];
+                                for(let eValue of stdCharacter.itemValue){
+                                    eigenvalue.push({isSelected: false, value: eValue.value});
+                                }
+                                tempCharacter.push({isChecked: false, serialNo: billCharacter.serialNo, character: stdCharacter.content, eigenvalue: eigenvalue});
+                            }
+                        }
+                    }
+                    excelBill.jobContent = tempJob;
+                    excelBill.itemCharacter = tempCharacter;
+                }
+            }
+        }
+    }
     for(let r = 0; r < validData.length; r++){
         let preData = validData[r-1],
             rData = validData[r];
@@ -397,6 +443,7 @@ function parseToBillData(validData, colMapping, fixedBill, projectID){
                 itemCharacter: [],
                 jobContentText: '',
                 jobContent: [],
+                programID: null,
                 unit: rData[colMapping.unit] ? rData[colMapping.unit] : '',
                 quantity: rData[colMapping.quantity] ? rData[colMapping.quantity] : '',
                 flags: fixedBill.flags[0].flag === fixedFlag.CONSTRUCTION_ORGANIZATION && rData[colMapping.name] === '安全文明施工专项费用' ?
@@ -404,6 +451,8 @@ function parseToBillData(validData, colMapping, fixedBill, projectID){
                 fees: [],
                 projectID: projectID,
                 type: getBillType(rData, fixedBill.flags[0].flag)};
+            //match stdBill and reset programID、jobContent、itemCharacter
+            matchStdBill(billIdx[newID], stdData);
             //update preBill NextSibling
             if(preBill){
                 preBill.NextSiblingID = newID;

+ 3 - 0
web/building_saas/main/js/views/project_view.js

@@ -1545,6 +1545,9 @@ $('#uploadConfirm').click(function () {
             throw '项目数据出错';
         }
         formData.append('projectID', projectID);
+        //要去匹配的清单库(第一个)
+        let matchBillLibId = projectInfoObj.projectInfo.engineeringInfo.bill_lib.length > 0 ? projectInfoObj.projectInfo.engineeringInfo.bill_lib[0].id : null;
+        formData.append('billsLibId', matchBillLibId);
         $.ajax({
             url: '/bills/upload',
             type: 'POST',

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

@@ -514,5 +514,6 @@
     let rationValuation = '<%- rationValuation %>';
     let engineeringList = '<%- engineeringList %>';
     let compilationData = JSON.parse('<%- compilationData %>');
+    console.log(billValuation);
 </script>
 </html>