|
|
@@ -19,7 +19,7 @@ let mongoose = require('mongoose');
|
|
|
let ration = mongoose.model('ration');
|
|
|
let projectModel = mongoose.model('projects');
|
|
|
let _ = require('lodash');
|
|
|
-
|
|
|
+let glj_facade = require('../facade/glj_facade');
|
|
|
|
|
|
const ProjectModel = require('../../pm/models/project_model').project;
|
|
|
class GLJController extends BaseController {
|
|
|
@@ -365,68 +365,7 @@ class GLJController extends BaseController {
|
|
|
msg: ''
|
|
|
};
|
|
|
try {
|
|
|
- let currentUnitPriceId = await ProjectModel.getUnitPriceFileId(projectId);
|
|
|
- let unitPriceFileModel = new UnitPriceFileModel();
|
|
|
-
|
|
|
- let insertData = null;
|
|
|
- if (type > 0) {
|
|
|
- let currentUnitPrice = await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId});
|
|
|
- if (currentUnitPrice === null) {
|
|
|
- throw '不存在对应单价文件';
|
|
|
- }
|
|
|
- // 获取当前项目的rootProjectId
|
|
|
- let projectData = await ProjectModel.getProject(projectId);
|
|
|
- let rootProjectId = projectData.property.rootProjectID !== undefined ? projectData.property.rootProjectID : 0;
|
|
|
-
|
|
|
- insertData = JSON.parse(JSON.stringify(currentUnitPrice));
|
|
|
- insertData.root_project_id = rootProjectId;
|
|
|
- newName?insertData.name = newName:'';
|
|
|
- insertData.user_id = insertData.user_id === undefined ? request.session.sessionUser.id : insertData.user_id;
|
|
|
- delete insertData._id;
|
|
|
- delete insertData.ID;
|
|
|
- }
|
|
|
- // 获取即将更改的单价文件信息
|
|
|
- let targetUnitPriceFile = type === 0 ? await unitPriceFileModel.findDataByCondition({id: changeUnitPriceId}) :
|
|
|
- await unitPriceFileModel.add(insertData);
|
|
|
- if (targetUnitPriceFile === null) {
|
|
|
- throw '没有找到对应的单价文件';
|
|
|
- }
|
|
|
-
|
|
|
- // 查找对应单价文件的项目工料机数据
|
|
|
- let unitPriceModel = new UnitPriceModel();
|
|
|
- if(type ===1){//从其它项目复制,则先复制一份数据。
|
|
|
- let needCopyList = await unitPriceModel.findDataByCondition({unit_price_file_id: changeUnitPriceId}, null, false);
|
|
|
- if(needCopyList){
|
|
|
- // 过滤mongoose格式
|
|
|
- needCopyList = JSON.stringify(needCopyList);
|
|
|
- needCopyList = JSON.parse(needCopyList);
|
|
|
- let copyList = [];
|
|
|
- for(let n of needCopyList){
|
|
|
- delete n._id; // 删除原有id信息
|
|
|
- delete n.id;
|
|
|
- n.unit_price_file_id = targetUnitPriceFile.id;
|
|
|
- copyList.push(n);
|
|
|
- }
|
|
|
- copyList.length>0 ? await unitPriceModel.add(copyList):'';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- let copyResult = await unitPriceModel.copyNotExist(currentUnitPriceId, targetUnitPriceFile.id,projectId);
|
|
|
- // 复制成功后更改project数据
|
|
|
- if (!copyResult) {
|
|
|
- throw '复制数据失败';
|
|
|
- }
|
|
|
-
|
|
|
- let changeUnitPriceFileInfo = {
|
|
|
- id: targetUnitPriceFile.id,
|
|
|
- name: targetUnitPriceFile.name
|
|
|
- };
|
|
|
- let result = ProjectModel.changeUnitPriceFileInfo(projectId, changeUnitPriceFileInfo);
|
|
|
- if (!result) {
|
|
|
- throw '切换单价文件失败!';
|
|
|
- }
|
|
|
-
|
|
|
+ responseData.unitFile = await glj_facade.changeUnitFile({projectID:projectId}, {id:changeUnitPriceId,name:newName},type,request.session.sessionUser.id);
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
responseData.err = 1;
|