|
|
@@ -27,7 +27,8 @@ module.exports={
|
|
|
getBasicInfo: getBasicInfo,
|
|
|
getProjectFeature: getProjectFeature,
|
|
|
getProjectByGranularity: getProjectByGranularity,
|
|
|
- importProject: importProject
|
|
|
+ importProject: importProject,
|
|
|
+ getProjectPlaceholder: getProjectPlaceholder
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -65,6 +66,8 @@ let engineeringModel = mongoose.model('engineering_lib');
|
|
|
let basicInfoModel = mongoose.model('std_basic_info_lib');
|
|
|
let projectFeatureModel = mongoose.model('std_project_feature_lib');
|
|
|
let productModel = mongoose.model('product');
|
|
|
+let stdRationItemModel = mongoose.model('std_ration_lib_ration_items');
|
|
|
+let stdGljItemModel = mongoose.model('std_glj_lib_gljList');
|
|
|
import BillsTemplateModel from "../models/templates/bills_template_model";
|
|
|
|
|
|
let featureLibModel = mongoose.model("std_project_feature_lib");
|
|
|
@@ -79,14 +82,11 @@ const notDeleted = [{deleteInfo: null}, {'deleteInfo.deleted': false}];
|
|
|
import {
|
|
|
defaultDecimal,
|
|
|
billsQuantityDecimal,
|
|
|
- basicInformation,
|
|
|
- projectFeature,
|
|
|
displaySetting,
|
|
|
calcOptions,
|
|
|
tenderSetting,
|
|
|
G_FILE_VER
|
|
|
} from '../models/project_property_template';
|
|
|
-import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
|
|
|
let labourCoeFacade = require('../../main/facade/labour_coe_facade');
|
|
|
let calcProgramFacade = require('../../main/facade/calc_program_facade');
|
|
|
let mainColLibModel = mongoose.model('std_main_col_lib');
|
|
|
@@ -1161,38 +1161,56 @@ async function getProjectByGranularity(tenderID, granularity, userID, versionNam
|
|
|
return constructionProject;
|
|
|
}
|
|
|
|
|
|
+//获取项目数据占位ID
|
|
|
+async function getProjectPlaceholder(data) {
|
|
|
+ let rst = {};
|
|
|
+ //项目本身数据
|
|
|
+ if (data.projectCount) {
|
|
|
+ let projectCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.project, data.projectCount);
|
|
|
+ rst.project = projectCount.sequence_value - data.projectCount + 1;
|
|
|
+ }
|
|
|
+ //项目人材机数据
|
|
|
+ if (data.projectGLJCount) {
|
|
|
+ let projectGLJCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.glj_list, data.projectGLJCount);
|
|
|
+ rst.projectGLJ = projectGLJCount.sequence_value - data.projectGLJCount + 1;
|
|
|
+ }
|
|
|
+ //组成物数据
|
|
|
+ if (data.ratioCount) {
|
|
|
+ let ratioCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.mix_ratio, data.ratioCount);
|
|
|
+ rst.ratio = ratioCount.sequence_value - data.ratioCount + 1;
|
|
|
+ }
|
|
|
+ //单价文件数据
|
|
|
+ if (data.unitPriceFileCount) {
|
|
|
+ let unitPriceFileCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.unit_price_file, data.unitPriceFileCount);
|
|
|
+ rst.unitPriceFile = unitPriceFileCount.sequence_value - data.unitPriceFileCount + 1;
|
|
|
+ }
|
|
|
+ //单价数据
|
|
|
+ if (data.unitPriceCount) {
|
|
|
+ let unitPriceCount = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.unit_price, data.unitPriceCount);
|
|
|
+ rst.unitPrice = unitPriceCount.sequence_value - data.unitPriceCount + 1;
|
|
|
+ }
|
|
|
+ return rst;
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* 项目详细数据都导入完成了,再生成项目数据(项目管理界面数据)
|
|
|
* */
|
|
|
async function importProject(importObj, userID, compilationID) {
|
|
|
let toInsertProjects = [importObj]; //待新增项目数据
|
|
|
- //获取项目ID
|
|
|
- let projectIDs = await counter.counterDAO.getIDAfterCountSync(counter.moduleName.project, importObj.projectCount);
|
|
|
- let curID = projectIDs.sequence_value - importObj.projectCount + 1;
|
|
|
- importObj.ID = curID++;
|
|
|
await setupProject(importObj);
|
|
|
//设置项目ID及相关数据
|
|
|
- for (let i = 0; i < importObj.engs.length; i++) {
|
|
|
- let curEng = importObj.engs[i],
|
|
|
- nextEng = importObj.engs[i + 1];
|
|
|
- curEng.ID = curID++;
|
|
|
- curEng.ParentID = importObj.ID;
|
|
|
+ for (let curEng of importObj.engs) {
|
|
|
await setupProject(curEng);
|
|
|
toInsertProjects.push(curEng);
|
|
|
- for (let j = 0; j < curEng.tenders.length; j++) {
|
|
|
- let curTender = curEng.tenders[j],
|
|
|
- nextTender = curEng.tenders[j + 1];
|
|
|
- curTender.ID = curID++;
|
|
|
- curTender.ParentID = curEng.ID;
|
|
|
- curTender.NextSiblingID = nextTender ? curID : -1;
|
|
|
- curTender.property.rootProjectID = importObj.ID;
|
|
|
- await setupProject(curTender);
|
|
|
+ for (let curTender of curEng.tenders) {
|
|
|
+ await setupProject(curTender.tender);
|
|
|
//插入单位工程的详细数据
|
|
|
await importTenderDetail(curTender);
|
|
|
- toInsertProjects.push(curTender);
|
|
|
+ toInsertProjects.push(curTender.tender);
|
|
|
}
|
|
|
- curEng.NextSiblingID = nextEng ? curID : -1;
|
|
|
+ delete curEng.tenders;
|
|
|
}
|
|
|
+ delete importObj.engs;
|
|
|
//项目内部数据设置、新增完毕后,插入项目本身的数据,更新前节点数据
|
|
|
let bulks = [];
|
|
|
//如果有前节点,更新前节点
|
|
|
@@ -1201,23 +1219,32 @@ async function importProject(importObj, userID, compilationID) {
|
|
|
updateOne: {filter: {ID: importObj.preID}, update: {$set: {NextSiblingID: importObj.ID}}}
|
|
|
});
|
|
|
}
|
|
|
- let needFields = ['ID', 'ParentID', 'NextSiblingID', 'name', 'projType', 'userID', 'compilation',
|
|
|
- 'createDateTime', 'fileVer', 'property', 'shareInfo', 'fullFolder'],
|
|
|
- rst = [];
|
|
|
for (let insertP of toInsertProjects) {
|
|
|
- let needData= {};
|
|
|
- for (let needField of needFields) {
|
|
|
- needData[needField] = insertP[needField];
|
|
|
- }
|
|
|
- rst.push(needData);
|
|
|
bulks.push({
|
|
|
- insertOne: {document: needData}
|
|
|
+ insertOne: {document: insertP}
|
|
|
});
|
|
|
}
|
|
|
if (bulks.length > 0) {
|
|
|
await projectModel.bulkWrite(bulks);
|
|
|
}
|
|
|
- return rst;
|
|
|
+ let summaryInfo = await getSummaryInfo([importObj.ID]);
|
|
|
+ //设置汇总字段
|
|
|
+ for(let proj of toInsertProjects){
|
|
|
+ let summaryProj = summaryInfo[proj.ID];
|
|
|
+ if(summaryProj){
|
|
|
+ proj.engineeringCost = summaryProj.engineeringCost;
|
|
|
+ proj.subEngineering = summaryProj.subEngineering;
|
|
|
+ proj.measure = summaryProj.measure;
|
|
|
+ proj.safetyConstruction = summaryProj.safetyConstruction;
|
|
|
+ proj.other = summaryProj.other;
|
|
|
+ proj.charge = summaryProj.charge;
|
|
|
+ proj.tax = summaryProj.tax;
|
|
|
+ proj.rate = summaryProj.rate;
|
|
|
+ proj.buildingArea = summaryProj.buildingArea;
|
|
|
+ proj.perCost = summaryProj.perCost;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return toInsertProjects;
|
|
|
|
|
|
|
|
|
//给项目数据设置一些需要的数据
|
|
|
@@ -1237,13 +1264,22 @@ async function importProject(importObj, userID, compilationID) {
|
|
|
//更新基本信息, 按照key匹配
|
|
|
let infoLib = await getBasicInfo(data.compilation);
|
|
|
if (infoLib) {
|
|
|
+ //标准基本信息库的数据打平
|
|
|
let flatDatas = [];
|
|
|
infoLib.info.forEach(ifData => flatDatas.push(...ifData.items));
|
|
|
data.basicInformation.forEach(importI => {
|
|
|
- let matchData = flatDatas.find(f => f.key === importI.key);
|
|
|
- if (matchData) {
|
|
|
- matchData.value = importI.value;
|
|
|
- }
|
|
|
+ flatDatas.forEach(item => {
|
|
|
+ if (item.key === 'engineeringName') {
|
|
|
+ item.value = data.name;
|
|
|
+ } else if (item.key === 'fileKind') {
|
|
|
+ item.value = {'1': '投标', '2': '招标'}[data.property.fileKind]
|
|
|
+ } else if (item.key === 'taxModel') {
|
|
|
+ item.value = {'1': '一般计税法', '2': '简易计税法'}[data.property.taxType]
|
|
|
+ }
|
|
|
+ if (item.key === importI.key) {
|
|
|
+ item.value = importI.value;
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
data.property.basicInformation = infoLib ? infoLib.info : [];
|
|
|
@@ -1280,12 +1316,11 @@ async function importProject(importObj, userID, compilationID) {
|
|
|
}
|
|
|
});
|
|
|
//设置工程专业的值为费用标准的值..
|
|
|
- let engData = featureLib.feature.find(function (d) {
|
|
|
- return d.key === 'engineering';
|
|
|
+ featureLib.feature.forEach(f => {
|
|
|
+ if (f.key === 'engineering') {
|
|
|
+ f.value = data.property.feeStandardName;
|
|
|
+ }
|
|
|
});
|
|
|
- if (engData) {
|
|
|
- engData.value = data.feeName;
|
|
|
- }
|
|
|
}
|
|
|
data.property.projectFeature = featureLib ? featureLib.feature : [];
|
|
|
}
|
|
|
@@ -1295,218 +1330,163 @@ async function importProject(importObj, userID, compilationID) {
|
|
|
async function importTenderDetail(tenderData) {
|
|
|
//单价文件
|
|
|
let upFile = {
|
|
|
- name: tenderData.name,
|
|
|
- project_id: tenderData.ID,
|
|
|
- user_id: tenderData.userID,
|
|
|
- root_project_id: tenderData.property.rootProjectID
|
|
|
+ id: tenderData.tender.property.unitPriceFile.id,
|
|
|
+ name: tenderData.tender.name,
|
|
|
+ project_id: tenderData.tender.ID,
|
|
|
+ user_id: tenderData.tender.userID,
|
|
|
+ root_project_id: tenderData.tender.property.rootProjectID
|
|
|
};
|
|
|
- let unitPriceFileModel = new UnitPriceFileModel();
|
|
|
- let addResult = await unitPriceFileModel.add(upFile);
|
|
|
- if (!addResult) {
|
|
|
- throw '新增单价文件失败';
|
|
|
- }
|
|
|
- tenderData.property.unitPriceFile.id = parseInt(addResult.id);
|
|
|
+ await unitPriceFileModel.create(upFile);
|
|
|
//费率文件
|
|
|
- let feeRateFileID = await feeRate_facade.newFeeRateFile(tenderData.userID, tenderData);
|
|
|
- tenderData.property.feeFile = feeRateFileID ? feeRateFileID : -1;
|
|
|
+ let feeRateFileID = await feeRate_facade.newFeeRateFile(tenderData.tender.userID, tenderData.tender);
|
|
|
+ tenderData.tender.property.feeFile = feeRateFileID ? feeRateFileID : -1;
|
|
|
//人工系数文件
|
|
|
- let lcFile = await labourCoeFacade.newProjectLabourCoe(tenderData);
|
|
|
- tenderData.property.labourCoeFile = lcFile ? lcFile : null;
|
|
|
- let cpFile = await calcProgramFacade.newProjectCalcProgramFile(tenderData);
|
|
|
- tenderData.property.calcProgramFile = cpFile ? cpFile : null;
|
|
|
+ let lcFile = await labourCoeFacade.newProjectLabourCoe(tenderData.tender);
|
|
|
+ tenderData.tender.property.labourCoeFile = lcFile ? lcFile : null;
|
|
|
+ let cpFile = await calcProgramFacade.newProjectCalcProgramFile(tenderData.tender);
|
|
|
+ tenderData.tender.property.calcProgramFile = cpFile ? cpFile : null;
|
|
|
//列设置
|
|
|
let engineeringModel = new EngineeringLibModel();
|
|
|
- let engineering = await engineeringModel.getEngineering(tenderData.property.engineering_id);
|
|
|
- let mainTreeCol = await mainColLibModel.findOne({ID: tenderData.property.colLibID});
|
|
|
- await projectSettingModel.create({projectID: tenderData.ID, main_tree_col: mainTreeCol.main_tree_col, glj_col: engineering.glj_col});
|
|
|
+ let engineering = await engineeringModel.getEngineering(tenderData.tender.property.engineering_id);
|
|
|
+ let mainTreeCol = await mainColLibModel.findOne({ID: tenderData.tender.property.colLibID});
|
|
|
+ await projectSettingModel.create({projectID: tenderData.tender.ID, main_tree_col: mainTreeCol.main_tree_col, glj_col: engineering.glj_col});
|
|
|
//清单
|
|
|
- await importBills(tenderData);
|
|
|
-}
|
|
|
-
|
|
|
-//插入单位工程的清单
|
|
|
-async function importBills(tenderData) {
|
|
|
- //获取清单模板数据
|
|
|
- let billsTemplateModel = new BillsTemplateModel();
|
|
|
- let templateData = await billsTemplateModel.getTemplateDataForNewProj(tenderData.property.templateLibID);
|
|
|
- let billsDatas = JSON.parse(JSON.stringify(templateData));
|
|
|
- //设置同层序号,为了后续过滤掉非必要模板数据、插入接口清单数据后,能生成正确的顺序的树
|
|
|
- setSeqByNext(billsDatas);
|
|
|
- function getFlag(data) {
|
|
|
- return data.flags && data.flags[0] && data.flags[0].flag || '';
|
|
|
- }
|
|
|
- //过滤掉不含清单固定类别的模板数据 (导入接口只包含必要的清单模板数据)
|
|
|
- let needfulDatas = billsDatas.filter(data => getFlag(data));
|
|
|
- sortToTreeData(tenderData.ID, needfulDatas);
|
|
|
- let newDatas = [];
|
|
|
- //如果模板存在分部分项,插入分部分项数据
|
|
|
- insertAndUpdate(billsFlags.SUB_ENGINERRING, tenderData.fbfx);
|
|
|
- //技术措施项目
|
|
|
- insertAndUpdate(billsFlags.CONSTRUCTION_TECH, tenderData.csxm.jscs);
|
|
|
- //组织措施项目
|
|
|
- insertAndUpdate(billsFlags.CONSTRUCTION_ORGANIZATION, tenderData.csxm.zzcs);
|
|
|
- //暂列
|
|
|
- insertAndUpdate(billsFlags.PROVISIONAL, tenderData.other.provisional);
|
|
|
- //专业工程暂估
|
|
|
- insertAndUpdate(billsFlags.ENGINEERING_ESITIMATE, tenderData.other.engineeringPro);
|
|
|
- //计日工-人工
|
|
|
- insertAndUpdate(billsFlags.LABOUR, tenderData.other.dayWork.labour);
|
|
|
- //计日工-材料
|
|
|
- insertAndUpdate(billsFlags.MATERIAL, tenderData.other.dayWork.material);
|
|
|
- //计日工-机械
|
|
|
- insertAndUpdate(billsFlags.MACHINE, tenderData.other.dayWork.machine);
|
|
|
- //总承包服务费
|
|
|
- insertAndUpdate(billsFlags.TURN_KEY_CONTRACT, tenderData.other.service);
|
|
|
- //索赔
|
|
|
- insertAndUpdate(billsFlags.CLAIM, tenderData.other.claim);
|
|
|
- //签证
|
|
|
- insertAndUpdate(billsFlags.VISA, tenderData.other.visa);
|
|
|
- //其他
|
|
|
- //找出材料工程设备暂估价
|
|
|
- let materialPro = tenderData.other.others.find(data => data.name === '材料(工程设备)暂估价');
|
|
|
- if (materialPro) {
|
|
|
- tenderData.other.others.splice(tenderData.other.others.indexOf(materialPro), 1);
|
|
|
- update(billsFlags.MATERIAL_PROVISIONAL, materialPro);
|
|
|
- }
|
|
|
- insertAndUpdate(billsFlags.OTHER, tenderData.other.others);
|
|
|
- //规费和税金,非规费税金
|
|
|
- let notChargeAndTax = [];
|
|
|
- tenderData.chargeTax.forEach(data => {
|
|
|
- if (data.name === '规费') {
|
|
|
- update(billsFlags.CHARGE, data);
|
|
|
- } else if (data.name === '税金') {
|
|
|
- update(billsFlags.TAX, data);
|
|
|
- } else {
|
|
|
- notChargeAndTax.push(data);
|
|
|
+ if (tenderData.bills.length) {
|
|
|
+ await billsModel.insertMany(tenderData.bills);
|
|
|
+ }
|
|
|
+ //投标文件中,才会有下面这些数据
|
|
|
+ if (enterDetail(tenderData)) {
|
|
|
+ //匹配标准数据,更新一些标准数据
|
|
|
+ await setupStdData(tenderData);
|
|
|
+ let task = [];
|
|
|
+ //定额
|
|
|
+ if (tenderData.ration.length) {
|
|
|
+ task.push(rationModel.insertMany(tenderData.ration))
|
|
|
}
|
|
|
- });
|
|
|
- //除了规费税金,就是税金下的增值税等数据
|
|
|
- insertAndUpdate(billsFlags.TAX, notChargeAndTax);
|
|
|
- insertAndUpdate(billsFlags.CHARGE, tenderData.chargeTax);
|
|
|
- newDatas.push(...needfulDatas);
|
|
|
- console.log(newDatas);
|
|
|
- await billsModel.insertMany(newDatas);
|
|
|
- //数据插入到数据库中
|
|
|
- return newDatas;
|
|
|
- //给新增数据设置ID数据,并且添加到待新增数组中
|
|
|
- function setIDs(projectID, parentID, datas) {
|
|
|
- newDatas.push(...datas);
|
|
|
- datas.forEach((data) => {
|
|
|
- data.projectID = tenderData.ID;
|
|
|
- data.ID = uuidV1();
|
|
|
- data.ParentID = parentID;
|
|
|
- });
|
|
|
- for (let i = 0; i < datas.length; i++) {
|
|
|
- let cur = datas[i],
|
|
|
- next = datas[i + 1];
|
|
|
- cur.NextSiblingID = next ? next.ID : -1;
|
|
|
- if (cur.items && cur.items.length) {
|
|
|
- setIDs(projectID, cur.ID, cur.items);
|
|
|
- }
|
|
|
+ //定额人材机
|
|
|
+ if (tenderData.rationGLJ.length) {
|
|
|
+ task.push(rationGLJModel.insertMany(tenderData.rationGLJ));
|
|
|
}
|
|
|
- }
|
|
|
- //单独更新一条数据
|
|
|
- function update(flag, data) {
|
|
|
- let target = needfulDatas.find(data => getFlag(data) === flag);
|
|
|
- if (target) {
|
|
|
- for (let [k, v] of Object.entries(data)) {
|
|
|
- target[k] = v;
|
|
|
- }
|
|
|
+ //定额调整系数
|
|
|
+ if (tenderData.rationCoe.length) {
|
|
|
+ task.push(rationCoeModel.insertMany(tenderData.rationCoe));
|
|
|
}
|
|
|
- }
|
|
|
- //插入、更新数据
|
|
|
- function insertAndUpdate(flag, inserts) {
|
|
|
- if (!inserts || !inserts.length) {
|
|
|
- return;
|
|
|
+ //项目人材机
|
|
|
+ if (tenderData.projectGLJ.length) {
|
|
|
+ task.push(gljListModel.insertMany(tenderData.projectGLJ));
|
|
|
}
|
|
|
- let target = needfulDatas.find(data => getFlag(data) === flag);
|
|
|
- if (target) {
|
|
|
- let targetChildren = needfulDatas.filter(data => data.ParentID == target.ID);
|
|
|
- for (let insertData of inserts) {
|
|
|
- //存在同名模板数据
|
|
|
- let sameNameData = targetChildren.find(data => data.name === insertData.name);
|
|
|
- if (sameNameData) {
|
|
|
- //将插入数据的子数据插入到同名模板数据中
|
|
|
- setIDs(tenderData.ID, sameNameData.ID, insertData.items);
|
|
|
- //更新该模板数据的一些值
|
|
|
- for (let [k, v] of Object.entries(insertData)) {
|
|
|
- sameNameData[k] = v;
|
|
|
- }
|
|
|
- } else { //不存在同名模板,直接将数据插入到目标中
|
|
|
- setIDs(tenderData.ID, target.ID, [insertData]);
|
|
|
- }
|
|
|
- }
|
|
|
+ //组成物
|
|
|
+ if (tenderData.mixRatio.length) {
|
|
|
+ task.push(mixRatioModel.insertMany(tenderData.mixRatio));
|
|
|
}
|
|
|
+ //单价文件
|
|
|
+ if (tenderData.unitPrice.length) {
|
|
|
+ task.push(unitPriceModel.insertMany(tenderData.unitPrice));
|
|
|
+ }
|
|
|
+ await Promise.all(task);
|
|
|
+ }
|
|
|
+ //继续处理定额等数据
|
|
|
+ function enterDetail(tenderData) {
|
|
|
+ return tenderData.ration.length ||
|
|
|
+ tenderData.rationGLJ.length ||
|
|
|
+ tenderData.projectGLJ.length ||
|
|
|
+ tenderData.mixRatio.length ||
|
|
|
+ tenderData.unitPrice.length;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-/*
|
|
|
-* 将同层的清单数据,按照树结构顺序设置序号
|
|
|
-* @param {Array} billsData(清单模板数据)
|
|
|
-* */
|
|
|
-function setSeqByNext(billsData) {
|
|
|
- //获取同层数据
|
|
|
- let sameDepthDatas = {}; //按照ParentID区分
|
|
|
- for (let data of billsData) {
|
|
|
- if (!sameDepthDatas[data.ParentID]) {
|
|
|
- sameDepthDatas[data.ParentID] = [];
|
|
|
+//匹配标准数据,需要匹配标准定额,更新导入的定额人材机的定额消耗量等数据
|
|
|
+async function setupStdData(tenderData) {
|
|
|
+ //获取标准定额数据 (定额子目的编码查找)
|
|
|
+ let matchRationCodes = [...new Set(tenderData.ration.map(ration => ration.code))];
|
|
|
+ if (!matchRationCodes.length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //限制在当前费用定额可用的定额库里查找
|
|
|
+ let stdRations = await stdRationItemModel.find({code: {$in: matchRationCodes}, rationRepId: {$in: tenderData.tender.rationLibIDs}},
|
|
|
+ '-_id -rationAssList -rationCoeList -rationInstList');
|
|
|
+ //标准定额code - 映射
|
|
|
+ let stdRationCodeMap = {};
|
|
|
+ stdRations.forEach(stdRation => stdRationCodeMap[stdRation.code] = stdRation);
|
|
|
+ //获取标准人材机数据 (人材机汇总的编码查找)
|
|
|
+ let matchGLJCodes = [...new Set(tenderData.projectGLJ.map(pGLJ => pGLJ.original_code))];
|
|
|
+ if (!matchGLJCodes.length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //限制在当前费用定额可用的人材机库里查找
|
|
|
+ let stdGLJs = await stdGljItemModel.find({code: {$in: matchGLJCodes}, repositoryId: {$in: tenderData.tender.gljLibIDs}},
|
|
|
+ '-_id -component -priceProperty');
|
|
|
+ //标准人材机code - 映射
|
|
|
+ let stdGLJCodeMap = {};
|
|
|
+ stdGLJs.forEach(stdGLJ => stdGLJCodeMap[stdGLJ.code] = stdGLJ);
|
|
|
+ //更新定额数据
|
|
|
+ tenderData.ration.forEach(r => {
|
|
|
+ let stdRation = stdRationCodeMap[r.code];
|
|
|
+ if (stdRation) {
|
|
|
+ r.caption = stdRation.caption;
|
|
|
+ r.from = 'std';
|
|
|
+ r.libID = stdRation.rationRepId;
|
|
|
+ r.stdID = stdRation.ID;
|
|
|
+ r.prefix = stdRation.rationRepId == tenderData.tender.defaultRationLib ? '' : '借';
|
|
|
+ r.content = stdRation.jobContent;
|
|
|
+ } else {
|
|
|
+ r.from = 'cpt';
|
|
|
+ r.prefix = '补';
|
|
|
}
|
|
|
- sameDepthDatas[data.ParentID].push(data);
|
|
|
- }
|
|
|
- //设置同层节点的序号
|
|
|
- for (let sameDepth of Object.values(sameDepthDatas)) {
|
|
|
- let sortedData = getDataBySorted(sameDepth),
|
|
|
- seq = 1;
|
|
|
- sortedData.forEach((data => data.seq = seq++));
|
|
|
- }
|
|
|
- //将每个同层的数据设置好序号
|
|
|
- //获取根据树结构NextSibling排序的同层数据
|
|
|
- function getDataBySorted(datas) {
|
|
|
- //链断了返回空数组
|
|
|
- let target = [];
|
|
|
- let last = datas.find(data => data.NextSiblingID == -1);
|
|
|
- while (last && target.length !== datas.length) {
|
|
|
- target.push(last);
|
|
|
- last = datas.find(data => data.NextSiblingID == last.ID);
|
|
|
+ });
|
|
|
+ //更新定额人材机数据
|
|
|
+ tenderData.rationGLJ.forEach(rGLJ => {
|
|
|
+ rGLJ.from = 'cpt';
|
|
|
+ //匹配定额
|
|
|
+ let stdRation = stdRationCodeMap[rGLJ.rationCode];
|
|
|
+ if (stdRation) {
|
|
|
+ //根据导入数据的定额人材机编码匹配人材机
|
|
|
+ let stdGLJ = stdGLJCodeMap[rGLJ.original_code];
|
|
|
+ if (stdGLJ) {
|
|
|
+ rGLJ.from = 'std';
|
|
|
+ rGLJ.GLJID = stdGLJ.ID;
|
|
|
+ rGLJ.type = stdGLJ.gljType;
|
|
|
+ rGLJ.shortName = stdGLJ.shortName;
|
|
|
+ rGLJ.repositoryId = stdGLJ.repositoryId;
|
|
|
+ rGLJ.model = stdGLJ.model;
|
|
|
+ rGLJ.adjCoe = stdGLJ.adjCoe;
|
|
|
+ //找匹配到的标准定额中定额人材机的相应人材机,更新定额消耗
|
|
|
+ let stdRationGLJ = stdRation.rationGljList.find(data => data.gljId === stdGLJ.ID);
|
|
|
+ if (stdRationGLJ) {
|
|
|
+ rGLJ.rationItemQuantity = stdRationGLJ.consumeAmt;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- //链断了即清单模板数据的树结构有问题,这里做下兼容:
|
|
|
- // 1.数据没问题,返回排序过后的同层数据数组 2.数据有问题,返回不排序的同层数组
|
|
|
- return target.length === datas.length ? target.reverse() : datas;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//根据同层序号,设置NextSiblingID
|
|
|
-function sortSeqToNextSibling(needfulData) {
|
|
|
- let sameDepthDatas = {}; //按照ParentID区分
|
|
|
- for (let data of needfulData) {
|
|
|
- if (!sameDepthDatas[data.ParentID]) {
|
|
|
- sameDepthDatas[data.ParentID] = [];
|
|
|
+ });
|
|
|
+ //更新人材机汇总数据
|
|
|
+ tenderData.projectGLJ.forEach(pGLJ => {
|
|
|
+ let stdGLJ = stdGLJCodeMap[pGLJ.original_code];
|
|
|
+ if (stdGLJ) {
|
|
|
+ pGLJ.glj_id = stdGLJ.ID;
|
|
|
+ if (pGLJ.type !== stdGLJ.gljType) { //更新组成物connect_key
|
|
|
+ let keyStr = [pGLJ.code, pGLJ.name, pGLJ.specs, pGLJ.unit, pGLJ.type].join('|-|');
|
|
|
+ let ratios = tenderData.mixRatio.filter(ratio =>
|
|
|
+ ratio.connect_key === keyStr);
|
|
|
+ let newKeyStr = [pGLJ.code, pGLJ.name, pGLJ.specs, pGLJ.unit, stdGLJ.gljType].join('|-|');
|
|
|
+ ratios.forEach(ratio => ratio.connect_key = newKeyStr);
|
|
|
+ }
|
|
|
+ pGLJ.type = stdGLJ.gljType; //更新类型,标准的数据类型更准确,导入的类型数据有细分识别不了
|
|
|
}
|
|
|
- sameDepthDatas[data.ParentID].push(data);
|
|
|
- }
|
|
|
- for (let sameDepth of Object.values(sameDepthDatas)) {
|
|
|
- sameDepth.sort((a, b) => a.seq - a.seq);
|
|
|
- for (let i = 0; i < sameDepth.length; i++) {
|
|
|
- let cur = sameDepth[i],
|
|
|
- next = sameDepth[i + 1];
|
|
|
- cur.NextSiblingID = next ? next.ID : -1;
|
|
|
+ });
|
|
|
+ //更新单价文件数据
|
|
|
+ tenderData.unitPrice.forEach(up => {
|
|
|
+ let stdGLJ = stdGLJCodeMap[up.original_code];
|
|
|
+ if (stdGLJ) {
|
|
|
+ up.glj_id = stdGLJ.ID;
|
|
|
+ up.type = stdGLJ.gljType;
|
|
|
+ up.short_name = stdGLJ.shortName;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //更新组成物数据
|
|
|
+ tenderData.mixRatio.forEach(ratio => {
|
|
|
+ let stdGLJ = stdGLJCodeMap[ratio.code];
|
|
|
+ if (stdGLJ) {
|
|
|
+ ratio.glj_id = stdGLJ.ID;
|
|
|
+ ratio.type = stdGLJ.gljType;
|
|
|
}
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//清单模板数据转换为uuID树结构数据
|
|
|
-function sortToTreeData(projectID, needfulData) {
|
|
|
- sortSeqToNextSibling(needfulData);
|
|
|
- let uuidMaping = {};
|
|
|
- uuidMaping['-1'] = -1;
|
|
|
- //建立uuid-ID映射
|
|
|
- for(let bill of needfulData){
|
|
|
- uuidMaping[bill.ID] = uuidV1();
|
|
|
- }
|
|
|
- needfulData.forEach(function (template) {
|
|
|
- template.projectID = projectID;
|
|
|
- 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;
|
|
|
});
|
|
|
}
|