|
|
@@ -10,7 +10,8 @@ module.exports={ //先导出后require可以解决循环引用问题
|
|
|
updateMaterialCalcTasks:updateMaterialCalcTasks,
|
|
|
updateUserFreight:updateUserFreight,
|
|
|
getUserFreights:getUserFreights,
|
|
|
- insertElectrovalence:insertElectrovalence
|
|
|
+ insertElectrovalence:insertElectrovalence,
|
|
|
+ updateElectrovalence:updateElectrovalence
|
|
|
};
|
|
|
|
|
|
const mongoose = require('mongoose');
|
|
|
@@ -26,6 +27,7 @@ let freight_calc_model = mongoose.model('freight_calc');
|
|
|
let unit_price_model = mongoose.model('unit_price');
|
|
|
let user_freights_model = mongoose.model('user_freights');
|
|
|
let std_glj_lib_model = mongoose.model('std_glj_lib_map');
|
|
|
+let com_electrovalence_model = mongoose.model('com_electrovalence');
|
|
|
|
|
|
let ration_glj = require('../../ration_glj/facade/ration_glj_facade');
|
|
|
const uuidV1 = require('uuid/v1');
|
|
|
@@ -44,7 +46,7 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
|
|
|
|
|
|
let insertData = null;
|
|
|
if (type > 0) {
|
|
|
- let currentUnitPrice = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
|
|
|
+ let currentUnitPrice = await unitPriceFileModel.model.findOne({id: changeUnitPriceId}).lean();
|
|
|
if (currentUnitPrice === null) {
|
|
|
throw '不存在对应单价文件';
|
|
|
}
|
|
|
@@ -52,13 +54,12 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
|
|
|
let projectData = await ProjectModel.getProject(projectId);
|
|
|
let rootProjectId = projectData.property.rootProjectID !== undefined ? projectData.property.rootProjectID : 0;
|
|
|
|
|
|
- insertData = JSON.parse(JSON.stringify(currentUnitPrice));
|
|
|
+ insertData = currentUnitPrice;
|
|
|
insertData.root_project_id = rootProjectId;
|
|
|
newName?insertData.name = newName:'';
|
|
|
insertData.user_id = userID;
|
|
|
delete insertData._id;
|
|
|
- delete insertData.ID;
|
|
|
- currentUnitPriceId = changeUnitPriceId; //从其它建设项目复制时,这个ID要变成被选中的来源的单价文件ID
|
|
|
+ delete insertData.id;
|
|
|
|
|
|
}
|
|
|
// 获取即将更改的单价文件信息
|
|
|
@@ -70,12 +71,9 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
|
|
|
|
|
|
// 查找对应单价文件的项目工料机数据
|
|
|
let unitPriceModel = new UnitPriceModel();
|
|
|
- /* if(type ===1){//从其它项目复制,则先复制一份数据。 后面会做复制操作了,
|
|
|
- let needCopyList = await unitPriceModel.findDataByCondition({unit_price_file_id: changeUnitPriceId}, null, false);
|
|
|
+ if(type ===1){//从其它项目复制,则先复制一份数据。
|
|
|
+ let needCopyList = await unitPriceModel.model.find({unit_price_file_id: changeUnitPriceId}).lean();
|
|
|
if(needCopyList){
|
|
|
- // 过滤mongoose格式
|
|
|
- needCopyList = JSON.stringify(needCopyList);
|
|
|
- needCopyList = JSON.parse(needCopyList);
|
|
|
let copyList = [];
|
|
|
for(let n of needCopyList){
|
|
|
delete n._id; // 删除原有id信息
|
|
|
@@ -85,7 +83,7 @@ async function changeUnitFile(projectData,unitFile,type,userID) {
|
|
|
}
|
|
|
copyList.length>0 ? await unitPriceModel.add(copyList):'';
|
|
|
}
|
|
|
- }*/
|
|
|
+ }
|
|
|
let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id,projectId);
|
|
|
// 复制成功后更改project数据
|
|
|
if (!copyResult) {
|
|
|
@@ -229,6 +227,21 @@ async function insertElectrovalence(data,compilationID) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+//更新或新建综合电价信息
|
|
|
+async function updateElectrovalence(data) {
|
|
|
+ let elec = data["electrovalence"];
|
|
|
+ if(elec){
|
|
|
+ let actionType = elec.actionType;
|
|
|
+ if(actionType == "add"){
|
|
|
+ await com_electrovalence_model.create(elec.doc);
|
|
|
+ }else if(actionType == "update"){
|
|
|
+ await com_electrovalence_model.updateOne({'ID':elec.ID},elec.doc);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(data["unitPrice"]) await updateUnitPrice(data["unitPrice"]);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
async function updateMaterialCalcTasks(data) {
|
|
|
let freightTasks = [];
|