|
|
@@ -10,7 +10,8 @@ module.exports = {
|
|
|
saveProperty: saveProperty,
|
|
|
getDefaultColSetting: getDefaultColSetting,
|
|
|
markProjectsToChange:markProjectsToChange,
|
|
|
- getBudgetSummayDatas:getBudgetSummayDatas
|
|
|
+ getBudgetSummayDatas:getBudgetSummayDatas,
|
|
|
+ getGLJSummayDatas:getGLJSummayDatas
|
|
|
};
|
|
|
|
|
|
let mongoose = require('mongoose');
|
|
|
@@ -32,6 +33,7 @@ let stdColSettingModel = mongoose.model('std_main_col_lib');
|
|
|
let decimal_facade = require('../../main/facade/decimal_facade');
|
|
|
const scMathUtil = require('../../../public/scMathUtil').getUtil();
|
|
|
import fixedFlag from '../../common/const/bills_fixed';
|
|
|
+import GLJListModel from "../../glj/models/glj_list_model";
|
|
|
const projectDao = require('../../pm/models/project_model').project;
|
|
|
|
|
|
|
|
|
@@ -571,4 +573,158 @@ function sortChildren(lists) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+async function getGLJSummayDatas(projectIDs) {
|
|
|
+ let projects = [];
|
|
|
+ let names = [];
|
|
|
+ let prjTypeNames = [];
|
|
|
+ try {
|
|
|
+ for(let ID of projectIDs){
|
|
|
+ projects.push(await getProjectData(ID)) ;
|
|
|
+ }
|
|
|
+ if(projects.length == 0){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ let mp = projects[0];
|
|
|
+ for(let p of projects){
|
|
|
+ names.push(p.name);
|
|
|
+ prjTypeNames.push(p.prjTypeName);
|
|
|
+ p.gljList = await getProjectGLJData(p.ID,p.unitPriceFileId,mp.property);
|
|
|
+ }
|
|
|
+
|
|
|
+ let mList = mergeGLJ(mp,projects,names,prjTypeNames);
|
|
|
+ mList = gljUtil.sortProjectGLJ(mList,_);
|
|
|
+ let summaryGLJDatas = getSummaryGLJDatas(mList,mp.property.decimal,names,prjTypeNames);
|
|
|
+
|
|
|
+ let parentProject = await projectsModel.findOne({ID:mp.ParentID});
|
|
|
+ let result = {
|
|
|
+ prj: {},
|
|
|
+ SummaryAudit:{
|
|
|
+ "name": parentProject?parentProject.name:"",
|
|
|
+ "编制": mp.author,
|
|
|
+ "复核": mp.auditor,
|
|
|
+ "编制范围":mp.compilationScope
|
|
|
+ },
|
|
|
+ SummaryAuditDetail:summaryGLJDatas
|
|
|
+ };
|
|
|
+ return result;
|
|
|
+ }catch (e){
|
|
|
+ console.log(e);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function getSummaryGLJDatas(gljList,decimal,nameList,prjTypeNames) {
|
|
|
+ let datas = [],qdecimal = decimal.glj.quantity,process = decimal.process;
|
|
|
+ for(let tem of gljList){
|
|
|
+ let d = {
|
|
|
+ code:tem.code,
|
|
|
+ name:tem.name,
|
|
|
+ type:tem.type,
|
|
|
+ unit:tem.unit,
|
|
|
+ specs:tem.specs,
|
|
|
+ marketPrice:tem.marketPrice,
|
|
|
+ prjNames:nameList,
|
|
|
+ prjTypeNames:prjTypeNames,
|
|
|
+ quantityList:[]
|
|
|
+ };
|
|
|
+ let totalQuantity = 0;
|
|
|
+ for(let n of nameList){
|
|
|
+ let q = tem.quantityMap[n]?scMathUtil.roundForObj(tem.quantityMap[n],qdecimal):0;
|
|
|
+ totalQuantity = scMathUtil.roundForObj(q+totalQuantity,process);
|
|
|
+ d.quantityList.push(q);
|
|
|
+ }
|
|
|
+ d.totalQuantity = scMathUtil.roundForObj(totalQuantity,qdecimal);
|
|
|
+ datas.push(d);
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function mergeGLJ(mp,projects) {
|
|
|
+ let gljMap = {},gljList=[];
|
|
|
+ for(let g of mp.gljList){
|
|
|
+ g.quantityMap={};
|
|
|
+ g.quantityMap[mp.name] = g.quantity;
|
|
|
+ gljMap[gljUtil.getIndex(g)] = g;
|
|
|
+ gljList.push(g);
|
|
|
+
|
|
|
+ }
|
|
|
+ for(let i = 1;i<projects.length;i++){
|
|
|
+ let temList = projects[i].gljList;
|
|
|
+ for(let t of temList){
|
|
|
+ t.quantityMap={};
|
|
|
+ t.quantityMap[projects[i].name] = t.quantity;
|
|
|
+ //这里除了5个属性相同判断为同一个之外,还要判断市场价相同,才认为是同一个工料机
|
|
|
+ let connect_key = gljUtil.getIndex(t);
|
|
|
+ let g = gljMap[connect_key];
|
|
|
+ if(g&&g.marketPrice == t.marketPrice){
|
|
|
+ g.quantityMap[projects[i].name] = t.quantity;
|
|
|
+ }else {
|
|
|
+ gljMap[connect_key] = t;
|
|
|
+ gljList.push(t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return gljList;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+async function getProjectGLJData(projectID,unitPriceFileId,property){
|
|
|
+ //取项目工料机数据
|
|
|
+ let projectGLJDatas = await getProjectGLJPrice(projectID,unitPriceFileId,property);
|
|
|
+ await calcProjectGLJQuantity(projectID,projectGLJDatas,property);
|
|
|
+ _.remove(projectGLJDatas.gljList,{'quantity':0});
|
|
|
+ return projectGLJDatas.gljList;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+async function getProjectData(projectID){
|
|
|
+ let project = await projectsModel.findOne({ID:projectID});
|
|
|
+ if(!project) throw new Error(`找不到项目:${projectID}`);
|
|
|
+ let projectName = project.name;
|
|
|
+ let author='';//编制人
|
|
|
+ let auditor='';//审核人
|
|
|
+ let compilationScope='';//编制范围
|
|
|
+ let engineering='';//养护类别
|
|
|
+ if(project.property&&project.property.projectFeature){
|
|
|
+ for(let f of project.property.projectFeature){
|
|
|
+ if(f.key == 'author') author = f.value;
|
|
|
+ if(f.key == 'auditor') auditor = f.value;
|
|
|
+ if(f.key =='compilationScope') compilationScope = f.value;
|
|
|
+ if(f.key == 'engineering') engineering = f.value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!(project.property&&project.property.unitPriceFile)) throw new Error(`找不到单价文件:${projectID}`);
|
|
|
+ let unitPriceFileId = project.property.unitPriceFile.id;
|
|
|
+ return {ID:projectID,name:projectName,author:author,auditor:auditor,compilationScope:compilationScope,ParentID:project.ParentID,prjTypeName:engineering,property:project.property,unitPriceFileId:unitPriceFileId}
|
|
|
+}
|
|
|
+
|
|
|
+async function getProjectGLJPrice(projectID,unitPriceFileId,property){
|
|
|
+ //取项目工料机数据
|
|
|
+ let calcOptions=property.calcOptions;
|
|
|
+ let decimalObj = property.decimal;
|
|
|
+ let labourCoeDatas = [];//取调整价才需要用到
|
|
|
+ let gljListModel = new GLJListModel();
|
|
|
+ let [gljList, mixRatioConnectData,mixRatioMap,unitPriceMap] = await gljListModel.getListByProjectId(projectID, unitPriceFileId);
|
|
|
+ gljList = JSON.parse(JSON.stringify(gljList));
|
|
|
+ for(let glj of gljList){
|
|
|
+ let result = gljUtil.getGLJPrice(glj,{gljList:gljList},calcOptions,labourCoeDatas,decimalObj,false,_,scMathUtil);
|
|
|
+ glj.marketPrice = result.marketPrice;
|
|
|
+ glj.basePrice = result.basePrice;
|
|
|
+ }
|
|
|
+ return {gljList:gljList,mixRatioMap:mixRatioMap};
|
|
|
+}
|
|
|
+
|
|
|
+async function calcProjectGLJQuantity(projectID,projectGLJDatas,property){
|
|
|
+ let q_decimal = property.decimal.glj.quantity;
|
|
|
+ let rationGLJDatas = await ration_glj_model.find({'projectID':projectID});
|
|
|
+ let rationDatas = await ration_model.model.find({'projectID':projectID});
|
|
|
+ gljUtil.calcProjectGLJQuantity(projectGLJDatas,rationGLJDatas,rationDatas,[],q_decimal)
|
|
|
+}
|
|
|
+
|
|
|
+
|