|
@@ -17,6 +17,8 @@ const uuidV1 = require('uuid/v1');
|
|
|
let std_glj_lib_gljList_model = mongoose.model('std_glj_lib_gljList');
|
|
|
let coeMolde = mongoose.model('std_ration_lib_coe_list');
|
|
|
let _= require('lodash');
|
|
|
+const projectDao = require('../../pm/models/project_model').project;
|
|
|
+let projectModel = mongoose.model('projects');
|
|
|
|
|
|
module.exports = {
|
|
|
replaceRations: replaceRations,
|
|
@@ -25,15 +27,20 @@ module.exports = {
|
|
|
async function addNewRation(data) {
|
|
|
let query = data.itemQuery;
|
|
|
let stdRation = null;
|
|
|
+ let startTime = +new Date();
|
|
|
if(query){
|
|
|
let searchDao = new SearchDao();
|
|
|
stdRation = await searchDao.getRationItem(query.userID,query.rationRepId,query.code);
|
|
|
data.newData.code = query.code;
|
|
|
}
|
|
|
+ let stdRationTime = +new Date();
|
|
|
+ console.log("取std定额时间-------------------------------"+(stdRationTime - startTime));
|
|
|
if(data.brUpdate.length>0){
|
|
|
await updateSerialNo(data.brUpdate);
|
|
|
}
|
|
|
let newRation =await insertNewRation(data.newData,stdRation,data.calQuantity);
|
|
|
+ let addRationGLJTime = +new Date();
|
|
|
+ console.log("插入新定额时间-------------------------------"+(addRationGLJTime - startTime));
|
|
|
if(stdRation){
|
|
|
return await addRationSubList(stdRation,newRation,data.needInstall);
|
|
|
}else {
|
|
@@ -62,6 +69,7 @@ async function updateSerialNo(serialNoUpdate){
|
|
|
}
|
|
|
|
|
|
async function insertNewRation(newData,std,calQuantity) {//插入新的定额
|
|
|
+ let startTime = +new Date();
|
|
|
if(std){
|
|
|
newData.name = std.name;
|
|
|
newData.caption = std.caption;
|
|
@@ -80,10 +88,10 @@ async function insertNewRation(newData,std,calQuantity) {//插入新的定额
|
|
|
if(calQuantity){
|
|
|
await CalculateQuantity(newData,newData.billsItemID,newData.projectID);
|
|
|
}
|
|
|
-
|
|
|
+ let addRationGLJTime = +new Date();
|
|
|
+ console.log("计算消耗量时间-------------------------------"+(addRationGLJTime - startTime));
|
|
|
let newRation = await ration_model.model.create(newData);
|
|
|
- return newRation;
|
|
|
-
|
|
|
+ return newRation;
|
|
|
}
|
|
|
|
|
|
async function replaceRations(userID,data) {
|
|
@@ -112,12 +120,19 @@ async function replaceRation(nodeInfo,stdRation,projectID,calQuantity) {
|
|
|
}
|
|
|
|
|
|
async function addRationSubList(stdRation,newRation,needInstall) {
|
|
|
+ let startTime = +new Date();
|
|
|
let ration_gljs = await addRationGLJ(stdRation,newRation);
|
|
|
+ let addRationGLJTime = +new Date();
|
|
|
+ console.log("添加定额工料机时间-----"+(addRationGLJTime - startTime));
|
|
|
let ration_coes = await addRationCoe(stdRation,newRation);
|
|
|
+ let addRationCoeTime = +new Date();
|
|
|
+ console.log("添加定额coe时间-----"+(addRationCoeTime - addRationGLJTime));
|
|
|
let ration_installs = [];
|
|
|
if(needInstall){
|
|
|
ration_installs = await addRationInstallFee(stdRation,newRation);
|
|
|
}
|
|
|
+ let addRationInstallFeeTime = +new Date();
|
|
|
+ console.log("添加定额install时间-----"+(addRationInstallFeeTime - addRationCoeTime));
|
|
|
return {ration:newRation,ration_gljs:ration_gljs,ration_coes:ration_coes,ration_installs:ration_installs};
|
|
|
}
|
|
|
|
|
@@ -212,7 +227,15 @@ function getCustomerCoeData() {
|
|
|
async function addRationGLJ(std,newRation) {
|
|
|
let newRationGLJList = [];
|
|
|
let rationGLJShowList = [];
|
|
|
+ let unitPriceFileId = await projectDao.getUnitPriceFileId(newRation.projectID);
|
|
|
+ let sum=0;
|
|
|
+ let first = +new Date();
|
|
|
if(std.hasOwnProperty('rationGljList') && std.rationGljList.length > 0){
|
|
|
+ let stdGLJID = _.map(std.rationGljList,'gljId');
|
|
|
+ let stdGLJList = await std_glj_lib_gljList_model.find({'ID':{'$in':stdGLJID}});//速度优化-------先一次性取出所有的工料机列表
|
|
|
+ let stdGLJMap = _.indexBy(stdGLJList, 'ID');
|
|
|
+ let stdGLJMapTime = +new Date();
|
|
|
+ console.log("找到标准工料机映射表时间-------------------------------"+(stdGLJMapTime - first));
|
|
|
for(let sub of std.rationGljList){
|
|
|
let newGLJ = {};
|
|
|
newGLJ.ID = uuidV1();
|
|
@@ -223,7 +246,8 @@ async function addRationGLJ(std,newRation) {
|
|
|
newGLJ.rationItemQuantity = sub.consumeAmt;
|
|
|
newGLJ.quantity = sub.consumeAmt;
|
|
|
newGLJ.glj_repository_id = std.rationRepId;
|
|
|
- let std_glj = await std_glj_lib_gljList_model.findOne({'ID':sub.gljId});
|
|
|
+ let std_glj = stdGLJMap[sub.gljId];
|
|
|
+ let std_gljTime = +new Date();
|
|
|
if(std_glj){
|
|
|
newGLJ.name = std_glj.name;
|
|
|
newGLJ.code = std_glj.code;
|
|
@@ -235,16 +259,23 @@ async function addRationGLJ(std,newRation) {
|
|
|
newGLJ.type = std_glj.gljType;
|
|
|
newGLJ.repositoryId = std_glj.repositoryId;
|
|
|
newGLJ.adjCoe = std_glj.adjCoe;
|
|
|
- let info = await ration_glj_facade.getInfoFromProjectGLJ(newGLJ);
|
|
|
+ let info = await ration_glj_facade.getInfoFromProjectGLJ(newGLJ,unitPriceFileId);
|
|
|
newGLJ = ration_glj_facade.createNewRecord(info);
|
|
|
newRationGLJList.push(newGLJ);
|
|
|
rationGLJShowList.push(info);
|
|
|
}
|
|
|
+ let InfoFromProjectGLJ = +new Date();
|
|
|
+ console.log("找到项目工料机时间-------------------------------"+(InfoFromProjectGLJ - std_gljTime));
|
|
|
}
|
|
|
}
|
|
|
+ let before = +new Date();
|
|
|
+ console.log("总查询时间为-------------------------------"+(before-first));
|
|
|
if(newRationGLJList.length>0){
|
|
|
await ration_glj.insertMany(newRationGLJList);
|
|
|
}
|
|
|
+ let after = +new Date();
|
|
|
+ console.log("实际插入时间为-------------------------------"+(after-before));
|
|
|
+ console.log("总操作时间为-------------------------------"+(after-first));
|
|
|
return rationGLJShowList;
|
|
|
}
|
|
|
|
|
@@ -304,11 +335,12 @@ function createRationAss(std) {
|
|
|
|
|
|
async function CalculateQuantity (ration,billsItemID,projectID) {
|
|
|
// calculate ration Quantity
|
|
|
- let decimalObject =await decimal_facade.getProjectDecimal(projectID);
|
|
|
+ let project = await projectModel.findOne({ID:projectID});
|
|
|
+ let decimalObject =await decimal_facade.getProjectDecimal(projectID,project);
|
|
|
let quantity_decimal = (decimalObject&&decimalObject.ration&&decimalObject.ration.quantity)?decimalObject.ration.quantity:3;
|
|
|
let pbill = await bill_model.model.findOne({projectID:projectID,ID:billsItemID});
|
|
|
let billsQuantity = pbill.quantity ? pbill.quantity : 0;
|
|
|
- let bill_decimal = await decimal_facade.getBillsQuantityDecimal(projectID,pbill.unit);
|
|
|
+ let bill_decimal = await decimal_facade.getBillsQuantityDecimal(projectID,pbill.unit,project);
|
|
|
billsQuantity=scMathUtil.roundForObj(billsQuantity,bill_decimal);
|
|
|
ration.quantityEXP="QDL";
|
|
|
ration.quantity = scMathUtil.roundForObj(billsQuantity / FilterNumberFromUnit(ration.unit),quantity_decimal);//不管是否打勾都做转换
|