Pārlūkot izejas kodu

Merge branch 'master' of http://192.168.1.41:3000/SmartCost/ConstructionCost

TonyKang 3 gadi atpakaļ
vecāks
revīzija
cdf518e008

+ 13 - 0
config/config.js

@@ -56,6 +56,19 @@ module.exports = {
         },
         importURL:"172.18.111.231:6050"
     },
+    pp_outer:{  server: "112.74.42.187",
+    port: "27017",
+    options:{
+        user:'smartcost',
+        pass:'SmartCost3850888',
+        auth: {
+            "authdb": "admin"
+        },
+        connectTimeoutMS: 50000,
+        useMongoClient: true
+    },
+    importURL:"112.74.42.187:6050"
+},
     uat: {
         server: "112.74.42.187",
         port: "27017",

+ 1 - 1
modules/all_models/stdBills_itemCharacter.js

@@ -8,7 +8,7 @@ const stdBills_itemCharacter = new Schema({
         code: Number,
         content: String,
         itemValue: Array,
-        billsLibId: Number,
+        billsLibId: {type:Number, index: true},
         deleted: Boolean
     },
     {versionKey: false}

+ 1 - 1
modules/all_models/stdBills_jobContent.js

@@ -8,7 +8,7 @@ const stdBills_jobContent = new Schema({
         id: Number,
         code: Number,
         content: String,
-        billsLibId: Number,
+        billsLibId: {type:Number, index: true},
         deleted: Boolean
     },
     {versionKey: false}

+ 54 - 36
modules/main/controllers/bills_controller.js

@@ -227,21 +227,38 @@ module.exports = {
                 if(compressData === null){
                     throw 'excel没有对应数据'
                 }
+                const date1 = Date.now();
                 let importData = JSON.parse(LZString.decompressFromUTF16(compressData));
                 //匹配的清单库
+                const date2 = Date.now();
+                console.log(date2 - date1, 'decompressFromUTF16');
                 const billsLibId = fields.billsLibId !== undefined && fields.billsLibId.length > 0 && fields.billsLibId[0]? parseInt(fields.billsLibId[0]) : null;
                 let stdBills = [], stdJobs = [], stdCharacters = [];
+                const stdBillMap = {};
+                const stdJobMap = {};
+                const stdCharacterMap = {};
                 if(billsLibId){
-                    stdBills = await stdBillsModel.find({billsLibId: billsLibId, deleted: false}, '-_id code jobs items engineering billsLibId ruleText');
-                    stdJobs = await stdBillJobsModel.find({billsLibId: billsLibId, deleted: false});
-                    stdCharacters = await stdBillCharacterModel.find({billsLibId: billsLibId, deleted: false});
+                    stdBills = await stdBillsModel.find({billsLibId: billsLibId}, '-_id code jobs items engineering billsLibId ruleText');
+                    stdJobs = await stdBillJobsModel.find({billsLibId: billsLibId});
+                    stdCharacters = await stdBillCharacterModel.find({billsLibId: billsLibId});
+                    // 标准数据映射
+                    stdBills.forEach(bill => {
+                        stdBillMap[bill.code] = bill;
+                    });
+                    stdJobs.forEach(job => {
+                        stdJobMap[job.id] = job;
+                    });
+                    stdCharacters.forEach(character => {
+                        stdCharacterMap[character.id] = character;
+                    });
                 }
-                let stdData = {stdBills: stdBills, stdJobs: stdJobs, stdCharacters: stdCharacters};
+                let stdData = {stdBills: stdBills, stdJobs: stdJobs, stdCharacters: stdCharacters, stdBillMap, stdJobMap, stdCharacterMap};
+                console.log(Date.now() - date2, 'getStd');
                 //导入表
                 let importDateA = +new Date();
                 for(let position in importData){
-                    if(importData[position].length > 0){
-                        let updateFrontData = await importSheet(position, importData[position], req.session.sessionUser.id, projectID, stdData);
+                    if(importData[position] && importData[position].insert && importData[position].insert.length > 0){
+                        let updateFrontData = await importSheet(position, importData[position].insert, importData[position].remove, projectID, stdData);
                         if(updateFrontData){
                             responseData.data.push(updateFrontData);
                         }
@@ -271,7 +288,7 @@ module.exports = {
     }
 };
 
-async function importSheet(position, excelBills, userID, projectID, stdData){
+async function importSheet(position, excelBills, removeData, projectID, stdData){
         //导入位置的有固定行
         let flag = getImportFlag(position);
         if(!flag){
@@ -307,13 +324,17 @@ async function importSheet(position, excelBills, userID, projectID, stdData){
         //将excel清单数据转换成完整清单数据(设置ParentID、匹配标准清单库)
         parseToCompleteBills(excelBills, fixedBill, stdData);
         //删除相关数据
-        let deleteDatas = await billsData.deepDeleteBill([fixedBill], userID);
+        const date = Date.now();
+        let deleteDatas = await billsData.deepDeleteBill(removeData.rBillIDs, removeData.rRationIDs);
+        const date1 = Date.now();
+        console.log(date1 - date, 'deepDeleteBill');
         //新增清单数据
         await billsData.importBills(excelBills);
+        console.log(Date.now() - date1, 'importBills');
         // 如果导入招标、控制价文件、每个分项底下自动生成一条空定额
         const rations = [];
         excelBills.forEach(bills => {
-            if (bills.type === billType.FX) {
+            if (bills.type === billType.FX && !bills.lockUnitPrice) {
                 const emptyRation = {
                     projectID: bills.projectID,
                     ID: uuidV1(),
@@ -355,45 +376,42 @@ function parseToCompleteBills(excelBills, fixedBills, stdData){
             bills.ParentID = rootID;
         }
         delete bills.nodeType;
+        const date = Date.now();
         matchStdBill(bills, stdData);
+        console.log(Date.now() - date, 'matchStdBill');
     }
 
     //excel数据与标准库数据匹配,根据清单前九位编码匹配,匹配成功则获取标准清单对应的工程专业、特征及内容
     function matchStdBill(excelBill, stdData){
         let isMatch = false;
-        let regExp = /^\d{12}$/g;
         if(excelBill.code.length >8){
             let nineCode = excelBill.code.substr(0, 9);
-            for(let stdBill of stdData.stdBills){
-                //set programID
-                if(nineCode == stdBill.code){
-                    isMatch = true;
-                    excelBill.programID = stdBill.engineering ? stdBill.engineering : null;
-                    excelBill.billsLibId = stdBill.billsLibId ? stdBill.billsLibId : null;
-                    excelBill.ruleText = stdBill.ruleText ? stdBill.ruleText : '';
-                    //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});
-                            }
-                        }
+            const stdBill = stdData.stdBillMap[nineCode];
+            if (stdBill) {
+                isMatch = true;
+                excelBill.programID = stdBill.engineering ? stdBill.engineering : null;
+                excelBill.billsLibId = stdBill.billsLibId ? stdBill.billsLibId : null;
+                excelBill.ruleText = stdBill.ruleText ? stdBill.ruleText : '';
+                //set jobContent and itemCharacter
+                let tempJob = [], tempCharacter = [];
+                for(let billJob of stdBill.jobs){
+                    const stdJob = stdData.stdJobMap[billJob.id];
+                    if (stdJob) {
+                        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});
-                            }
+                }
+                for(let billCharacter of stdBill.items){
+                    const stdCharacter = stdData.stdCharacterMap[billCharacter.id];
+                    if (stdCharacter) {
+                        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;
                 }
+                excelBill.jobContent = tempJob;
+                excelBill.itemCharacter = tempCharacter;
             }
         }
         if(!isMatch && excelBill.type === billType.FX){//分项不为空,同时在标准清单中不匹配,则识别为补项

+ 5 - 27
modules/main/models/bills.js

@@ -166,40 +166,18 @@ class billsModel extends baseModel {
         return bills.update(findSet, update);
     };
     async importBills(bills){
-        let operations = [];
+        /* let operations = [];
         for(let bill of bills){
             operations.push({insertOne: {document: bill}});
+        } */
+        if (bills.length) {
+            await this.model.insertMany(bills)
         }
-        return await this.model.bulkWrite(operations);
     }
     //删除清单节点的所有子节点及其他附带数据
-    async deepDeleteBill(bills, userID){
-        let bill_ids = [],
-            ration_ids = [];
+    async deepDeleteBill(bill_ids, ration_ids){
         let me = this;
-        async function findBillsChildren(bills){
-            if(bills.length > 0){
-                let ids = getIDs(bills);
-                bill_ids = bill_ids.concat(ids);
-                let findBills = await me.model.find({ParentID: {$in: ids}, deleteInfo: null});
-                await findBillsChildren(findBills);
-            }
-        }
-        function getIDs(datas){
-            let ids = [];
-            for(let data of datas){
-                ids.push(data.ID);
-            }
-            return ids;
-        }
-        await findBillsChildren(bills);
-        //剔除第一个节点
-        bill_ids = bill_ids.slice(1);
-        //获取删除清单下的所有定额
-        let rations = await rationModel.find({billsItemID: {$in: bill_ids}, deleteInfo: null}, 'ID');
-        ration_ids = ration_ids.concat(getIDs(rations));
         //deep delete datas
-        let deleteInfo = {deleted: true, deleteDateTime: new Date(), deleteBy: userID};
         if(bill_ids.length > 0){
             //删除bills
             await me.model.deleteMany({ID: {$in: bill_ids}});

+ 2 - 1
public/web/sheet/sheet_common.js

@@ -391,7 +391,8 @@ var sheetCommonObj = {
             if(setting.getStyle && setting.getStyle(data[row],row,null,setting.header[col].dataCode)){
                 let cstyle = setting.getStyle(data[row],row,null,setting.header[col].dataCode);
                 if(cstyle){
-                    sheet.setStyle(row, col,cstyle);
+                    let oldStyle = sheet.getStyle(row, col);
+                    sheet.setStyle(row, col,{...oldStyle,...cstyle});
                 }   
             }
         }

+ 10 - 0
web/building_saas/main/js/models/calc_base.js

@@ -448,6 +448,11 @@ let baseFigureTemplate = {
         }
         return rst;
     },
+    'FBFXDERGFTZ': function (tender) {
+        let feeField = 'labourInc',
+            subFeeField = tender ? 'tenderTotalFee' : 'totalFee';
+        return cbTools.getBillsFee(fixedFlag.SUB_ENGINERRING, feeField, subFeeField);
+    },
     'FBFXRGTSFDERGF': function (tender) {
         const programID = projectObj.project.calcProgram.compiledTemplateMaps['人工土石方工程'];
         return cbTools.getFeeWithTypeByFlag(fixedFlag.SUB_ENGINERRING, programID, 'labour', tender);
@@ -551,6 +556,11 @@ let baseFigureTemplate = {
         }
         return rst;
     },
+    'JSCSXMDERGFTZ': function (tender) {
+        let feeField = 'labourInc',
+            subFeeField = tender ? 'tenderTotalFee' : 'totalFee';
+        return cbTools.getBillsFee(fixedFlag.CONSTRUCTION_TECH, feeField, subFeeField);
+    },
     JSCSXMRGTSFDERGF: function (tender) {
         const programID = projectObj.project.calcProgram.compiledTemplateMaps['人工土石方工程'];
         return cbTools.getFeeWithTypeByFlag(fixedFlag.CONSTRUCTION_TECH, programID, 'labour', tender);

+ 1 - 1
web/building_saas/main/js/models/calc_program.js

@@ -2166,7 +2166,7 @@ class CalcProgram {
 
     function isBaseFeeType(type) {
       return (
-        ["labour", "material", "machine", "mainMaterial", "equipment"].indexOf(
+        ["labour", "material", "machine", "mainMaterial", "equipment", "labourInc"].indexOf(
           type
         ) > -1
       );

+ 52 - 1
web/building_saas/main/js/views/importBills.js

@@ -36,6 +36,7 @@ const importBills = (function(){
         unit: ['单位', '计量单位'],
         quantity: ['工程量', '项目工程量'],
         money: ['金额'],
+        unitPrice: ['综合单价', '单价'],
         quantityDetail: ['工程量明细'],
         feeDetail: ['费用明细'],
         summation: ['合计', '本页小计'],
@@ -184,6 +185,8 @@ const importBills = (function(){
             //金额
             else if(colMapping.money === undefined && _deESC(cellData).includes(colText.money[0])){
                 colMapping.money = colIdx;
+                // 特殊处理单价
+                colMapping.unitPrice = colIdx;
             }
             //工程量明细
             else if(colMapping.quantityDetail === undefined && _deESC(cellData) === colText.quantityDetail[0]){
@@ -402,6 +405,7 @@ const importBills = (function(){
                         ? '\n' + _deNR(rData[colMapping.itemCharacterText]['value']) : '';
                     preBill.unit += rData[colMapping.unit] && rData[colMapping.unit]['value'] && _isDef(_deESC(rData[colMapping.unit]['value'])) ? rData[colMapping.unit]['value'] : '';
                     preBill.quantity += rData[colMapping.quantity] && rData[colMapping.quantity]['value'] && _isDef(_deESC(rData[colMapping.quantity]['value'])) ? rData[colMapping.quantity]['value'] : '';
+                    preBill.unitPrice += rData[colMapping.unitPrice] && rData[colMapping.unitPrice]['value'] && _isDef(_deESC(rData[colMapping.unitPrice]['value'])) ? rData[colMapping.unitPrice]['value'] : '';
                 }
             } else {
                 let newID = uuid.v1();
@@ -435,6 +439,7 @@ const importBills = (function(){
                     unit: rData[colMapping.unit] && rData[colMapping.unit]['value'] ? _deESC(rData[colMapping.unit]['value']) : '',
                     quantity: rData[colMapping.quantity] && rData[colMapping.quantity]['value'] ? _deESC(rData[colMapping.quantity]['value']) : '',
                     quantityEXP: rData[colMapping.quantity] && rData[colMapping.quantity]['value'] ? _deESC(rData[colMapping.quantity]['value']) : '',
+                    unitPrice: rData[colMapping.unitPrice] && rData[colMapping.unitPrice]['value'] ? _deESC(rData[colMapping.unitPrice]['value']) : '',
                     //安全文明
                     flags: flag === fixedFlag.CONSTRUCTION_ORGANIZATION && (rData[colMapping.name] && (rData[colMapping.name]['value'] === '安全文明施工专项费用' || rData[colMapping.name]['value'] === '安全文明施工费')) ?
                         [{fieldName: 'fixed', flag: fixedFlag.SAFETY_CONSTRUCTION}] : [],
@@ -458,6 +463,22 @@ const importBills = (function(){
             preData = rData;
         }
         for(let i in billIdx){
+            if (!commonUtil.isEmptyVal(billIdx[i].unitPrice)) {
+                billIdx[i].lockUnitPrice = true;
+                const quantity = +billIdx[i].quantity || 0;
+                const unitPrice = +billIdx[i].unitPrice;
+                const totalPrice = scMathUtil.roundForObj(unitPrice * quantity, decimalObj.bills.totalPrice);
+                billIdx[i].fees = [
+                    {
+                        fieldName: "common",
+                        tenderTotalFee: totalPrice,
+                        tenderUnitFee: unitPrice,
+                        totalFee: totalPrice,
+                        unitFee: unitPrice,
+                    }
+                ];
+                delete billIdx[i].unitPrice;
+            }
             rst.push(billIdx[i]);
         }
         return rst;
@@ -608,7 +629,37 @@ const importBills = (function(){
         return false;
     }
 
+    // 获取需要删除的D
+    function getRemoveIDs(position, positionBills) {
+        const rBillIDs = [];
+        const rRationIDs = [];
+        const rst = { rBillIDs, rRationIDs };
+        if (!positionBills || !positionBills.length) {
+            return rst;
+        }
+        let flag;
+        if (position === 'fbfx') {
+            flag = fixedFlag.SUB_ENGINERRING;
+        } else if (position === 'jscsxm') {
+            flag = fixedFlag.CONSTRUCTION_TECH;
+        } else {
+            flag = fixedFlag.CONSTRUCTION_ORGANIZATION;
+        }
+        const fixedNode = calcTools.getNodeByFlag(flag);
+        if (!fixedNode) {
+            return rst;
+        }
+        fixedNode.getPosterity().forEach(node => {
+            if (node.sourceType === 'bills') {
+                rBillIDs.push(node.data.ID);
+            } else {      
+                rRationIDs.push(node.data.ID);
+            }
+        });
+        return rst;
+    }
+
 
 
-    return {setImportSheetsInfo, getImportSheetsInfo, getImportSheets, getImportData, excelHasValidBills}
+    return {setImportSheetsInfo, getImportSheetsInfo, getImportSheets, getImportData, excelHasValidBills, getRemoveIDs}
 })();

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

@@ -3184,15 +3184,21 @@ $('#importConfirm').click(function () {
             throw '请勾选要导入的表';
         }
         let importSheets = importBills.getImportSheets(importJson.sheets, importSheetsInfo, fileType);
-        console.log(`importSheets`);
-        console.log(importSheets);
         let invalidSheetsInfo = importSheets.invalidSheets.join('、');
         //获取同类表的有效数据
         let importBillsData = importBills.getImportData(importSheets.validSheets, projectID);
         if(!importBills.excelHasValidBills(importBillsData)){
             throw 'excel无有效数据'
         }
-        let compressData = LZString.compressToUTF16(JSON.stringify(importBillsData));
+        const postData = {};
+        Object.keys(importBillsData).forEach(position => {
+            postData[position] = {
+                insert: importBillsData[position],
+                remove: importBills.getRemoveIDs(position, importBillsData[position]),
+            }
+        })
+        console.log(postData);
+        let compressData = LZString.compressToUTF16(JSON.stringify(postData));
         formData.append('compressData', compressData);
         let eDate = +new Date();
         console.log(`解析excel数据时间:${eDate - sDate}`);
@@ -3318,6 +3324,10 @@ function doAfterImportPosition(positionData){
             node.source = projectObj.project.Bills.tree.nodes['id_' + node.getID()];
             node.data = node.source.data;
             node.sourceType = projectObj.project.Bills.getSourceType();
+            node.data.feesIndex = {};
+            for (let fee of node.data.fees) {
+                node.data.feesIndex[fee.fieldName] = fee;
+            }
         }
         ProjectController.syncDisplayNewNodes(projectObj.mainController, newNodes);
     }

+ 16 - 9
web/building_saas/pm/js/pm_newMain.js

@@ -2087,13 +2087,7 @@ $(document).ready(function() {
 
     //选择计价规则
     $("#valuation").change(function () {
-        curValuation = $(this).val();
-        curValuationName = $(this).text();
-        let engineeringList = getEngineeringList();
-        let engineeringHtml = getEngineeringHtml(engineeringList);
-        $("#tender-engineering").html(engineeringHtml);
-        $('#valuation-info').hide();
-        changeEngineering();
+        changeValuation($(this).val(),$(this).text())
     });
 
     //选择计税方式
@@ -2121,13 +2115,16 @@ $(document).ready(function() {
         let nameList = getNameList($('#poj-name-list').children());
         let isExist = hasListName(nameList, pojName);
         if(!isExist){
-            if(pojName !== ''){
-                console.log(curValuation);
+            if(pojName !== ''){    
+                if($("#valuation").val()) {
+                    changeValuation($("#valuation").val(),$("#valuation").text()); //这时候计价规则可能变了
+                }
                 //新建建设项目,显示计价规则、文件类型、计税方法选项
                 $('#newProjectSet').show();
                 $('input[name="fileKind-tender"]:eq(0)').prop('checked', true);
                 $('input[name="taxType-tender"]:eq(0)').prop('checked', true);
                 curTaxType = 1;
+       
                 getStdCalcProgramFiles();
                 replaceClass($('#poj-name-info'), 'text-danger', 'text-info');
                 setDangerInfo($('#poj-name-info'), `新建“${pojName}”`);
@@ -2787,6 +2784,16 @@ async function changeEngineering(){
     initFeeStandardSel();
 }
 
+function changeValuation(newValuation,newName) {
+    curValuation = newValuation;
+    curValuationName = newName;
+    let engineeringList = getEngineeringList();
+    let engineeringHtml = getEngineeringHtml(engineeringList);
+    $("#tender-engineering").html(engineeringHtml);
+    $('#valuation-info').hide();
+    changeEngineering();
+}
+
 function changeFeeRate(engLib) {
     if(engLib){
         /*

+ 3 - 0
web/over_write/js/neimenggu_2017.js

@@ -38,6 +38,7 @@ if(typeof materialComponent !== 'undefined'){
         {type: 'marketMaterial', name: '材料费'},
         {type: 'marketMachine', name: '施工机具使用费'},
         {type: 'labour', name: '定额人工费'},
+        {type: 'labourInc', name: '定额人工费调增'},
         {type: 'material', name: '定额材料费'},
         {type: 'machine', name: '定额施工机具使用费'},
         {type: 'mainMaterial', name: '主材费'},
@@ -194,6 +195,7 @@ function overwriteRationCalcBases (taxType){
             '分部分项主材费': {base: 'FBFXZCF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
             '分部分项设备费': {base: 'FBFXSBF', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
             '分部分项人工工日': {base: 'FBFXRGGR', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
+            '分部分项定额人工费调增': {base: 'FBFXDERGFTZ', fixedFlag: fixedFlag.SUB_ENGINERRING, class: 'FBFX'},
             '措施项目费': {base: 'CSXMF', fixedFlag: fixedFlag.MEASURE, class: 'CSXM'},
             '组织措施项目费': {base: 'ZZCSXMF', fixedFlag: fixedFlag.CONSTRUCTION_ORGANIZATION, class: 'CSXM'},
             '组织措施项目定额人工费': {base: 'ZZCSXMDEJJRGF', fixedFlag: fixedFlag.CONSTRUCTION_ORGANIZATION, class: 'CSXM'},
@@ -206,6 +208,7 @@ function overwriteRationCalcBases (taxType){
             '技术措施项目主材费': {base: 'JSCSXMZCF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
             '技术措施项目设备费': {base: 'JSCSXMSBF', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
             '技术措施项目人工工日': {base: 'JSCSXMRGGR', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
+            '技术措施项目定额人工费调增': {base: 'JSCSXMDERGFTZ', fixedFlag: fixedFlag.CONSTRUCTION_TECH, class: 'CSXM'},
             '其他项目费': {base: 'QTXMF', fixedFlag: fixedFlag.OTHER, class: 'QTXM'},
             '规费': {base: 'GF', fixedFlag: fixedFlag.CHARGE, class: 'GF'},
             '税金': {base: 'SJ', fixedFlag: fixedFlag.TAX, class: 'SJ'},