|
@@ -20,13 +20,14 @@ 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');
|
|
|
+const fs = require('fs');
|
|
|
|
|
|
module.exports = {
|
|
|
replaceRations: replaceRations,
|
|
|
addNewRation:addNewRation,
|
|
|
addMultiRation: addMultiRation
|
|
|
};
|
|
|
-async function addNewRation(data) {
|
|
|
+async function addNewRation(data,compilation) {
|
|
|
let query = data.itemQuery;
|
|
|
let stdRation = null;
|
|
|
let startTime = +new Date();
|
|
@@ -44,16 +45,16 @@ async function addNewRation(data) {
|
|
|
let addRationGLJTime = +new Date();
|
|
|
console.log("插入新定额时间-------------------------------"+(addRationGLJTime - stdRationTime));
|
|
|
if(stdRation){
|
|
|
- return await addRationSubList(stdRation,newRation,data.needInstall);
|
|
|
+ return await addRationSubList(stdRation,newRation,data.needInstall,compilation);
|
|
|
}else {
|
|
|
return {ration:newRation};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function addMultiRation(datas) {
|
|
|
+async function addMultiRation(datas,compilation) {
|
|
|
let rst = [];
|
|
|
for(let data of datas){
|
|
|
- let r = await addNewRation(data);
|
|
|
+ let r = await addNewRation(data,compilation);
|
|
|
rst.push(r);
|
|
|
}
|
|
|
return rst;
|
|
@@ -120,12 +121,12 @@ async function insertNewRation(newData,defaultLibID,std,calQuantity) {//插入
|
|
|
return newData;*/
|
|
|
}
|
|
|
|
|
|
-async function replaceRations(userID,data) {
|
|
|
+async function replaceRations(userID,data,compilation) {
|
|
|
let searchDao = new SearchDao();
|
|
|
let recodes = [];
|
|
|
for(let recode of data.nodeInfo){
|
|
|
let stdRation = await searchDao.getRationItem(userID,data.libIDs,recode.newCode, null);
|
|
|
- let newRecode = await replaceRation(recode,stdRation,data.defaultLibID,data.projectID,data.calQuantity);
|
|
|
+ let newRecode = await replaceRation(recode,stdRation,data.defaultLibID,data.projectID,data.calQuantity,compilation);
|
|
|
if(newRecode){
|
|
|
recodes.push(newRecode);
|
|
|
}else {
|
|
@@ -135,25 +136,25 @@ async function replaceRations(userID,data) {
|
|
|
return recodes;
|
|
|
}
|
|
|
|
|
|
-async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuantity) {
|
|
|
+async function replaceRation(nodeInfo,stdRation,defaultLibID,projectID,calQuantity,compilation) {
|
|
|
if(nodeInfo.newCode == null||nodeInfo.newCode ==""){//说明是删除编号,则要变成一条空定额
|
|
|
await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
|
|
|
return await setEmptyRation(projectID,nodeInfo.ID);
|
|
|
}else if(stdRation){
|
|
|
await deleRationSubRecode(projectID,nodeInfo.ID);//删除定额下挂的各种数据,如定额工料机等
|
|
|
let newRation = await updateRation(stdRation,defaultLibID,nodeInfo.ID,nodeInfo.billsItemID,projectID,calQuantity);//生成并插入新的定额
|
|
|
- return await addRationSubList(stdRation,newRation,nodeInfo.needInstall);
|
|
|
+ return await addRationSubList(stdRation,newRation,nodeInfo.needInstall,compilation);
|
|
|
}else {
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function addRationSubList(stdRation,newRation,needInstall) {
|
|
|
+async function addRationSubList(stdRation,newRation,needInstall,compilation) {
|
|
|
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 ration_coes = await addRationCoe(stdRation,newRation,compilation);
|
|
|
let addRationCoeTime = +new Date();
|
|
|
console.log("添加定额coe时间-----"+(addRationCoeTime - addRationGLJTime));
|
|
|
let ration_installs = [];
|
|
@@ -203,7 +204,7 @@ async function addRationInstallFee(std,newRation) {
|
|
|
return install_fee_list;
|
|
|
}
|
|
|
|
|
|
-async function addRationCoe(std,newRation) {
|
|
|
+async function addRationCoe(std,newRation,compilation) {
|
|
|
let ration_coe_list = [];
|
|
|
let seq = 0;
|
|
|
if(std.hasOwnProperty('rationCoeList')&&std.rationCoeList.length>0){//添加标准库的工料机
|
|
@@ -225,33 +226,55 @@ async function addRationCoe(std,newRation) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ let lastCoe = await getCustomerCoe(newRation.projectID,newRation.ID,seq,compilation);
|
|
|
+ ration_coe_list.push(lastCoe);
|
|
|
+ await ration_coe.insertMany(ration_coe_list);
|
|
|
+ return ration_coe_list;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function getCustomerCoeData() {
|
|
|
+ var coeList = [
|
|
|
+ {amount:1, operator:'*', gljCode:null, coeType:'定额'},
|
|
|
+ { amount:1, operator:'*', gljCode:null, coeType:'人工'},
|
|
|
+ { amount:1, operator:'*', gljCode:null, coeType:'材料'},
|
|
|
+ { amount:1, operator:'*', gljCode:null, coeType:'机械'},
|
|
|
+ { amount:1, operator:'*', gljCode:null, coeType:'主材'},
|
|
|
+ { amount:1, operator:'*', gljCode:null, coeType:'设备'}
|
|
|
+ ];
|
|
|
+ return coeList;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+async function getCustomerCoe(projectID,rationID,seq,compilation){//取自定义乘系数,根据编办不同,内容可能不同
|
|
|
+ //生成默认的自定义乘系数
|
|
|
let lastCoe ={
|
|
|
coeID:-1,
|
|
|
name : '自定义系数',
|
|
|
content:'人工×1,材料×1,机械×1,主材×1,设备×1',
|
|
|
isAdjust:0,
|
|
|
seq:seq,
|
|
|
- rationID : newRation.ID,
|
|
|
- projectID : newRation.projectID
|
|
|
+ rationID : rationID,
|
|
|
+ projectID : projectID
|
|
|
};
|
|
|
lastCoe.ID = uuidV1();
|
|
|
lastCoe.coes = getCustomerCoeData();
|
|
|
- ration_coe_list.push(lastCoe);
|
|
|
- await ration_coe.insertMany(ration_coe_list);
|
|
|
- return ration_coe_list;
|
|
|
-
|
|
|
+ try {
|
|
|
+ //查看编办中有没有重写路径
|
|
|
+ if(compilation.overWriteUrl && compilation.overWriteUrl!=""){
|
|
|
+ let overWrite = require("../../.."+compilation.overWriteUrl);
|
|
|
+ if(overWrite.getCusCoeContent) lastCoe.content = overWrite.getCusCoeContent();
|
|
|
+ if(overWrite.getCustomerCoeData) lastCoe.coes = overWrite.getCustomerCoeData();
|
|
|
+ }
|
|
|
+ return lastCoe
|
|
|
+ }catch (err){
|
|
|
+ console.log("读取自定义系数重写文件失败");
|
|
|
+ console.log(err.message);
|
|
|
+ return lastCoe
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function getCustomerCoeData() {
|
|
|
- var coeList = [];
|
|
|
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'定额'});
|
|
|
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'人工'});
|
|
|
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'材料'});
|
|
|
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'机械'});
|
|
|
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
|
|
|
- coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
|
|
|
- return coeList;
|
|
|
-};
|
|
|
+
|
|
|
|
|
|
async function addRationGLJ(std,newRation) {
|
|
|
let newRationGLJList = [];
|