|
@@ -5,7 +5,15 @@ import mongoose from 'mongoose';
|
|
|
import async_c from 'async';
|
|
|
import UnitPriceFileModel from "../../glj/models/unit_price_file_model";
|
|
|
import UnitPriceFiles from '../../glj/models/schemas/unit_price_file';
|
|
|
-import {defaultDecimal, billsQuantityDecimal, basicInformation, projectFeature,displaySetting} from './project_property_template';
|
|
|
+import {
|
|
|
+ defaultDecimal,
|
|
|
+ billsQuantityDecimal,
|
|
|
+ basicInformation,
|
|
|
+ projectFeature,
|
|
|
+ displaySetting,
|
|
|
+ calcOptions
|
|
|
+} from './project_property_template';
|
|
|
+import fixedFlag from '../../common/const/bills_fixed';
|
|
|
let FeeRateFiles = mongoose.model('fee_rate_file');
|
|
|
let counter = require("../../../public/counter/counter.js");
|
|
|
|
|
@@ -14,7 +22,9 @@ let copyProjController = require('../controllers/copy_proj_controller');
|
|
|
let feeRateFacade = require('../../fee_rates/facade/fee_rates_facade');
|
|
|
let labourCoeFacade = require('../../main/facade/labour_coe_facade');
|
|
|
let calcProgramFacade = require('../../main/facade/calc_program_facade');
|
|
|
+let installationFacade = require('../../main/facade/installation_facade');
|
|
|
let logger = require("../../../logs/log_helper").logger;
|
|
|
+let BillsModel = require("../../main/models/bills").model;
|
|
|
|
|
|
let Projects = require("./project_schema");
|
|
|
let projectType = {
|
|
@@ -28,20 +38,36 @@ let fileType = {
|
|
|
feeRateFile: 'FeeRateFile'
|
|
|
};
|
|
|
|
|
|
-let ProjectsDAO = function(){};
|
|
|
+let ProjectsDAO = function () {
|
|
|
+};
|
|
|
|
|
|
-ProjectsDAO.prototype.getUserProjects = function(userId, compilation, callback){
|
|
|
- Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id', function(err, templates){
|
|
|
- if (err) {
|
|
|
- callback(1, 'Error', null);
|
|
|
- } else {
|
|
|
- callback(0, '', templates);
|
|
|
+ProjectsDAO.prototype.getUserProjects = async function (userId, compilation, callback) {
|
|
|
+ try {
|
|
|
+ let projects = await Projects.find({
|
|
|
+ '$or': [{
|
|
|
+ 'userID': userId,
|
|
|
+ 'compilation': compilation,
|
|
|
+ 'deleteInfo': null
|
|
|
+ }, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]
|
|
|
+ }, '-_id');
|
|
|
+ for (let i = 0, len = projects.length; i < len; i++) {
|
|
|
+ let proj = projects[i];
|
|
|
+ let engineeringCost = await BillsModel.find({
|
|
|
+ projectID: proj.ID,
|
|
|
+ 'flags.flag': fixedFlag.ENGINEERINGCOST,
|
|
|
+ 'fees.totalFee': {$exists: true}
|
|
|
+ });
|
|
|
+ proj._doc.engineeringCost = engineeringCost.length > 0 ? engineeringCost[0].fees[0].totalFee : 0;
|
|
|
}
|
|
|
- });
|
|
|
+ callback(0, '', projects);
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ callback(1, 'Error', null);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
|
|
|
- Projects.findOne({userID: userId, ID: ProjId}, '-_id', function(err, template){
|
|
|
+ Projects.findOne({userID: userId, ID: ProjId}, '-_id', function (err, template) {
|
|
|
if (err) {
|
|
|
callback(1, '找不到标段数据', null);
|
|
|
} else {
|
|
@@ -50,22 +76,22 @@ ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId, datas, callback){
|
|
|
+ProjectsDAO.prototype.updateUserProjects = async function (userId, compilationId, datas, callback) {
|
|
|
let data, project, updateLength = 0, hasError = false, deleteInfo = null, i, newProject;
|
|
|
let updateAll = function (err) {
|
|
|
- if (!err){
|
|
|
- updateLength += 1;
|
|
|
- if (updateLength === datas.length) {
|
|
|
- callback(0, '', datas);
|
|
|
- }
|
|
|
- } else {
|
|
|
- hasError = true;
|
|
|
- console.log(err);
|
|
|
- callback(1, '提交数据出错.', null);
|
|
|
+ if (!err) {
|
|
|
+ updateLength += 1;
|
|
|
+ if (updateLength === datas.length) {
|
|
|
+ callback(0, '', datas);
|
|
|
}
|
|
|
- };
|
|
|
- if (datas){
|
|
|
- for (i = 0; i < datas.length && !hasError; i++){
|
|
|
+ } else {
|
|
|
+ hasError = true;
|
|
|
+ console.log(err);
|
|
|
+ callback(1, '提交数据出错.', null);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ if (datas) {
|
|
|
+ for (i = 0; i < datas.length && !hasError; i++) {
|
|
|
data = datas[i];
|
|
|
if (data.updateData.name !== undefined) {
|
|
|
data.updateData.name = data.updateData.name.trim();
|
|
@@ -96,7 +122,9 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
}
|
|
|
data.updateData.property.unitPriceFile.id = addResult.id;
|
|
|
}
|
|
|
- if(data.updateData.projType === projectType.tender){
|
|
|
+ if (data.updateData.projType === projectType.tender) {
|
|
|
+ //单价文件
|
|
|
+ data.updateData.property.unitPriceFile.id=parseInt(data.updateData.property.unitPriceFile.id);
|
|
|
//小数位数
|
|
|
data.updateData.property.decimal = defaultDecimal;
|
|
|
//清单工程量精度
|
|
@@ -107,10 +135,18 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
//工程特征
|
|
|
data.updateData.property.projectFeature = projectFeature;
|
|
|
//呈现选项
|
|
|
- data.updateData.property.displaySetting = displaySetting;
|
|
|
-
|
|
|
+ data.updateData.property.displaySetting = displaySetting;
|
|
|
+
|
|
|
data.updateData.property.billsCalcMode = 0;
|
|
|
- data.updateData.property.zanguCalcMode = 0;
|
|
|
+ data.updateData.property.zanguCalcMode = 0;
|
|
|
+ //计算选项
|
|
|
+ data.updateData.property.calcOptions = calcOptions
|
|
|
+ //安装增加费
|
|
|
+ if(parseInt(data.updateData.property.engineering)==4){
|
|
|
+ await installationFacade.copyInstallationFeeFromLib(data.updateData.ID,data.updateData.property.engineering_id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
newProject = new Projects(data.updateData);
|
|
|
// 查找同级是否存在同名数据
|
|
@@ -119,9 +155,9 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
callback(1, '同级目录已存在相同名称数据.', null);
|
|
|
return;
|
|
|
}
|
|
|
- if(data.updateData.projType==='Tender'){
|
|
|
- let feeRateFileID = await feeRateFacade.newFeeRateFile(userId, data.updateData);
|
|
|
- newProject.property.feeFile = feeRateFileID?feeRateFileID:-1;
|
|
|
+ if (data.updateData.projType === 'Tender') {
|
|
|
+ let feeRateFileID = await feeRateFacade.newFeeRateFile(userId, data.updateData);
|
|
|
+ newProject.property.feeFile = feeRateFileID ? feeRateFileID : -1;
|
|
|
|
|
|
// 新建人工系数文件 CSL, 2017.10.13
|
|
|
let lcFile = await labourCoeFacade.newProjectLabourCoe(data.updateData);
|
|
@@ -146,22 +182,28 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
data.updateData['deleteInfo'] = deleteInfo;
|
|
|
//Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
//update
|
|
|
- try{
|
|
|
- if(data.updateData.projType === projectType.project){
|
|
|
+ try {
|
|
|
+ if (data.updateData.projType === projectType.project) {
|
|
|
let engineerings = await Projects.find({userID: userId, ParentID: data.updateData.ID});
|
|
|
let isExist = false;
|
|
|
- if(engineerings.length > 0){
|
|
|
- for(let j = 0, jLen = engineerings.length; j < jLen; j++){
|
|
|
+ if (engineerings.length > 0) {
|
|
|
+ for (let j = 0, jLen = engineerings.length; j < jLen; j++) {
|
|
|
let e_tenders = await Projects.find({userID: userId, ParentID: engineerings[j].ID});
|
|
|
- if(e_tenders.length > 0){
|
|
|
+ if (e_tenders.length > 0) {
|
|
|
isExist = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(isExist){//fake
|
|
|
- await UnitPriceFiles.update({user_id: userId, root_project_id: data.updateData.ID}, {$set: {deleteInfo: deleteInfo}}, {multi: true});
|
|
|
- await FeeRateFiles.update({userID: userId, rootProjectID: data.updateData.ID}, {$set: {deleteInfo: deleteInfo}}, {multi: true});
|
|
|
+ if (isExist) {//fake
|
|
|
+ await UnitPriceFiles.update({
|
|
|
+ user_id: userId,
|
|
|
+ root_project_id: data.updateData.ID
|
|
|
+ }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
|
|
|
+ await FeeRateFiles.update({
|
|
|
+ userID: userId,
|
|
|
+ rootProjectID: data.updateData.ID
|
|
|
+ }, {$set: {deleteInfo: deleteInfo}}, {multi: true});
|
|
|
await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
}
|
|
|
else {//true
|
|
@@ -171,9 +213,9 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
|
|
|
}
|
|
|
}
|
|
|
- else if(data.updateData.projType === projectType.engineering){
|
|
|
+ else if (data.updateData.projType === projectType.engineering) {
|
|
|
let tenders = await Projects.find({userID: userId, ParentID: data.updateData.ID});
|
|
|
- if(tenders.length > 0){//fake
|
|
|
+ if (tenders.length > 0) {//fake
|
|
|
await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
}
|
|
|
else {//true
|
|
@@ -181,15 +223,15 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
|
|
|
}
|
|
|
}
|
|
|
- else if(data.updateData.projType === projectType.tender){//fake
|
|
|
+ else if (data.updateData.projType === projectType.tender) {//fake
|
|
|
await Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
|
|
|
}
|
|
|
- else if(data.updateData.projType === projectType.folder){//true
|
|
|
+ else if (data.updateData.projType === projectType.folder) {//true
|
|
|
await Projects.remove({userID: userId, ID: data.updateData.ID}, updateAll);
|
|
|
}
|
|
|
else throw '未知文件类型,删除失败!';
|
|
|
}
|
|
|
- catch (error){
|
|
|
+ catch (error) {
|
|
|
callback(1, error, null);
|
|
|
}
|
|
|
}
|
|
@@ -201,29 +243,38 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId,
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback){
|
|
|
+ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback) {
|
|
|
let updateType = {update: 'update', delete: 'delete'};
|
|
|
let deleteInfo = Object.create(null);
|
|
|
deleteInfo.deleted = true;
|
|
|
deleteInfo.deleteBy = userId;
|
|
|
deleteInfo.deleteDateTime = new Date();
|
|
|
- try{
|
|
|
- for(let i = 0, len = datas.length; i < len; i++){
|
|
|
+ try {
|
|
|
+ for (let i = 0, len = datas.length; i < len; i++) {
|
|
|
let data = datas[i];
|
|
|
- if(data.updateType === updateType.update && data.fileType === fileType.unitPriceFile){
|
|
|
+ if (data.updateType === updateType.update && data.fileType === fileType.unitPriceFile) {
|
|
|
await UnitPriceFiles.update({user_id: userId, id: parseInt(data.updateData.id)}, data.updateData);
|
|
|
- await Projects.update({userID: userId, 'property.unitPriceFile.id': data.updateData.id}, {$set: {'property.unitPriceFile.name': data.updateData.name}});
|
|
|
+ await Projects.update({
|
|
|
+ userID: userId,
|
|
|
+ 'property.unitPriceFile.id': data.updateData.id
|
|
|
+ }, {$set: {'property.unitPriceFile.name': data.updateData.name}});
|
|
|
}
|
|
|
- else if(data.updateType === updateType.update && data.fileType === fileType.feeRateFile){
|
|
|
+ else if (data.updateType === updateType.update && data.fileType === fileType.feeRateFile) {
|
|
|
await FeeRateFiles.update({userID: userId, ID: data.updateData.ID}, data.updateData);
|
|
|
- await Projects.update({userID: userId, 'property.feeFile.id': data.updateData.ID}, {$set: {'property.feeFile.name': data.updateData.name}});
|
|
|
+ await Projects.update({
|
|
|
+ userID: userId,
|
|
|
+ 'property.feeFile.id': data.updateData.ID
|
|
|
+ }, {$set: {'property.feeFile.name': data.updateData.name}});
|
|
|
}
|
|
|
- else if(data.updateType === updateType.delete && data.fileType === fileType.unitPriceFile){
|
|
|
+ else if (data.updateType === updateType.delete && data.fileType === fileType.unitPriceFile) {
|
|
|
data.updateData.deleteInfo = deleteInfo;
|
|
|
await UnitPriceFiles.update({user_id: userId, id: parseInt(data.updateData.id)}, data.updateData);
|
|
|
- await Projects.update({userID: userId, 'property.feeFile.id': data.updateData.id}, {$set: {'property.feeFile.name': data.updateData.name}});
|
|
|
+ await Projects.update({
|
|
|
+ userID: userId,
|
|
|
+ 'property.feeFile.id': data.updateData.id
|
|
|
+ }, {$set: {'property.feeFile.name': data.updateData.name}});
|
|
|
}
|
|
|
- else if(data.updateType === updateType.delete && data.fileType === fileType.feeRateFile){
|
|
|
+ else if (data.updateType === updateType.delete && data.fileType === fileType.feeRateFile) {
|
|
|
data.updateData.deleteInfo = deleteInfo;
|
|
|
await FeeRateFiles.update({userID: userId, ID: data.updateData.ID}, data.updateData);
|
|
|
}
|
|
@@ -231,7 +282,7 @@ ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback)
|
|
|
}
|
|
|
callback(false, '删除成功', null);
|
|
|
}
|
|
|
- catch(error){
|
|
|
+ catch (error) {
|
|
|
callback(true, '删除失败', null);
|
|
|
}
|
|
|
};
|
|
@@ -239,7 +290,7 @@ ProjectsDAO.prototype.udpateUserFiles = async function (userId, datas, callback)
|
|
|
ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
|
|
|
let data, project, updateLength = 0, hasError = false, deleteInfo = null, tempType = 1, i;
|
|
|
let updateAll = function (err) {
|
|
|
- if (!err){
|
|
|
+ if (!err) {
|
|
|
updateLength += 1;
|
|
|
if (updateLength === datas.length) {
|
|
|
callback(0, '', datas);
|
|
@@ -274,7 +325,7 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectsDAO.prototype.rename = async function (userId, compilationId, data, callback){
|
|
|
+ProjectsDAO.prototype.rename = async function (userId, compilationId, data, callback) {
|
|
|
try {
|
|
|
if (data.id === undefined || data.id === '') {
|
|
|
throw '数据错误!';
|
|
@@ -289,8 +340,8 @@ ProjectsDAO.prototype.rename = async function (userId, compilationId, data, call
|
|
|
throw '同级目录已存在相同名称数据';
|
|
|
}
|
|
|
|
|
|
- Projects.update({userID: userId, ID: data.id}, {name: data.newName}, function(err){
|
|
|
- if (err){
|
|
|
+ Projects.update({userID: userId, ID: data.id}, {name: data.newName}, function (err) {
|
|
|
+ if (err) {
|
|
|
throw '项目不存在';
|
|
|
}
|
|
|
});
|
|
@@ -301,10 +352,10 @@ ProjectsDAO.prototype.rename = async function (userId, compilationId, data, call
|
|
|
callback(0, '');
|
|
|
};
|
|
|
|
|
|
-ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback){
|
|
|
+ProjectsDAO.prototype.beforeOpenProject = function (userId, projectId, updateData, callback) {
|
|
|
updateData['recentDateTime'] = new Date();
|
|
|
- Projects.update({userID: userId, ID: projectId}, updateData, function(err){
|
|
|
- if (err){
|
|
|
+ Projects.update({userID: userId, ID: projectId}, updateData, function (err) {
|
|
|
+ if (err) {
|
|
|
callback(1, '项目不存在.');
|
|
|
} else {
|
|
|
callback(0, '');
|
|
@@ -337,28 +388,28 @@ ProjectsDAO.prototype.getProject = function (key, callback) {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectsDAO.prototype.getProjectsByIds = async function (userId, compilationId, ids){
|
|
|
+ProjectsDAO.prototype.getProjectsByIds = async function (userId, compilationId, ids) {
|
|
|
return await Projects.find({userID: userId, compilation: compilationId, ID: {$in: ids}});
|
|
|
};
|
|
|
|
|
|
-ProjectsDAO.prototype.getGCFiles = async function (fileType, userID){
|
|
|
+ProjectsDAO.prototype.getGCFiles = async function (fileType, userID) {
|
|
|
let rst;
|
|
|
- if(fileType === 'UnitPriceFile'){
|
|
|
+ if (fileType === 'UnitPriceFile') {
|
|
|
let unitPriceFileModel = new UnitPriceFileModel();
|
|
|
rst = await unitPriceFileModel.getGCUnitPriceFiles(userID);
|
|
|
}
|
|
|
- else if(fileType === 'FeeRateFile'){
|
|
|
+ else if (fileType === 'FeeRateFile') {
|
|
|
rst = await feeRateFacade.getGCFeeRateFiles(userID);
|
|
|
}
|
|
|
else {
|
|
|
let isExist = false;
|
|
|
- for(let type in projectType){
|
|
|
- if(projectType[type] === fileType) {
|
|
|
+ for (let type in projectType) {
|
|
|
+ if (projectType[type] === fileType) {
|
|
|
isExist = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- if(!isExist) throw '不存在此项目类型!';
|
|
|
+ if (!isExist) throw '不存在此项目类型!';
|
|
|
rst = await Projects.find({userID: userID, projType: fileType, 'deleteInfo.deleted': true});
|
|
|
}
|
|
|
return rst;
|
|
@@ -366,55 +417,55 @@ ProjectsDAO.prototype.getGCFiles = async function (fileType, userID){
|
|
|
|
|
|
ProjectsDAO.prototype.getFirstNodeID = async function (userID, pid) {
|
|
|
let nodes = await Projects.find({userID: userID, ParentID: pid, deleteInfo: null});
|
|
|
- if(nodes.length === 0){
|
|
|
+ if (nodes.length === 0) {
|
|
|
return -1;
|
|
|
}
|
|
|
else {
|
|
|
let prefix = 'ID_';
|
|
|
let chain = Object.create(null);
|
|
|
- for(let i = 0, len = nodes.length; i < len; i++){
|
|
|
+ for (let i = 0, len = nodes.length; i < len; i++) {
|
|
|
let nodeDoc = nodes[i]._doc;
|
|
|
let node = Object.create(null);
|
|
|
node.ID = nodeDoc.ID;
|
|
|
node.NextSiblingID = nodeDoc.NextSiblingID;
|
|
|
chain[prefix + node.ID] = node;
|
|
|
}
|
|
|
- for(let i =0, len = nodes.length; i < len; i++){
|
|
|
+ for (let i = 0, len = nodes.length; i < len; i++) {
|
|
|
let nodeDoc = nodes[i]._doc;
|
|
|
let next = nodeDoc.NextSiblingID > 0 ? chain[prefix + nodeDoc.NextSiblingID] : null;
|
|
|
chain[prefix + nodeDoc.ID].next = next;
|
|
|
- if(next){
|
|
|
+ if (next) {
|
|
|
next.pre = chain[prefix + nodeDoc.ID]
|
|
|
}
|
|
|
}
|
|
|
- for(let node in chain){
|
|
|
+ for (let node in chain) {
|
|
|
let pre = chain[node].pre || null;
|
|
|
- if(!pre){
|
|
|
+ if (!pre) {
|
|
|
return chain[node].ID;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
|
|
|
+ProjectsDAO.prototype.recGC = async function (userID, datas, callback) {
|
|
|
let functions = [];
|
|
|
let updateDatas = [];
|
|
|
- for(let i = 0, len = datas.length; i < len; i++){
|
|
|
- if(datas[i].findData.ParentID !== undefined && datas[i].findData.NextSiblingID === -1 && !datas[i].findData.deleteInfo){//维护项目管理树
|
|
|
+ for (let i = 0, len = datas.length; i < len; i++) {
|
|
|
+ if (datas[i].findData.ParentID !== undefined && datas[i].findData.NextSiblingID === -1 && !datas[i].findData.deleteInfo) {//维护项目管理树
|
|
|
let findNode = await Projects.find(datas[i].findData);
|
|
|
- if(findNode.length > 0){
|
|
|
+ if (findNode.length > 0) {
|
|
|
datas[i].findData = Object.create(null);
|
|
|
datas[i].findData.ID = findNode[0].ID;
|
|
|
updateDatas.push(datas[i]);
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
- if(datas[i].updateType === projectType.project && datas[i].updateData.NextSiblingID === undefined){//则为待查询NextSiblingID,前端无法查询
|
|
|
+ if (datas[i].updateType === projectType.project && datas[i].updateData.NextSiblingID === undefined) {//则为待查询NextSiblingID,前端无法查询
|
|
|
let projData = await Projects.find({userID: userID, ID: datas[i].findData.ID});//建设项目原本可能属于某文件夹、文件夹的存在需要判断
|
|
|
let projPid = projData[0].ParentID;
|
|
|
- if(projPid !== -1){
|
|
|
+ if (projPid !== -1) {
|
|
|
let projFolder = await Projects.find({userID: userID, ID: projPid});
|
|
|
- if(projFolder.length === 0){//文件夹已不存在
|
|
|
+ if (projFolder.length === 0) {//文件夹已不存在
|
|
|
projPid = -1;
|
|
|
datas[i].updateData.ParentID = -1;
|
|
|
}
|
|
@@ -425,45 +476,50 @@ ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
|
|
|
updateDatas.push(datas[i])
|
|
|
}
|
|
|
}
|
|
|
- for(let i = 0, len = updateDatas.length; i < len; i ++){
|
|
|
- functions.push((function(data){
|
|
|
+ for (let i = 0, len = updateDatas.length; i < len; i++) {
|
|
|
+ functions.push((function (data) {
|
|
|
return function (cb) {
|
|
|
- if(data.updateType === fileType.unitPriceFile){
|
|
|
+ if (data.updateType === fileType.unitPriceFile) {
|
|
|
UnitPriceFiles.update({id: parseInt(data.findData.id)}, data.updateData, function (err) {
|
|
|
- if(err) cb(err);
|
|
|
+ if (err) cb(err);
|
|
|
else {
|
|
|
- Projects.update({userID: userID, 'property.unitPriceFile.id': data.findData.id}, {$set: {'property.unitPriceFile.name': data.updateData.name}}, function (err) {
|
|
|
- if(err) cb(err);
|
|
|
+ Projects.update({
|
|
|
+ userID: userID,
|
|
|
+ 'property.unitPriceFile.id': data.findData.id
|
|
|
+ }, {$set: {'property.unitPriceFile.name': data.updateData.name}}, function (err) {
|
|
|
+ if (err) cb(err);
|
|
|
else cb(false);
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- else if(data.updateType === fileType.feeRateFile){
|
|
|
+ else if (data.updateType === fileType.feeRateFile) {
|
|
|
FeeRateFiles.update(data.findData, data.updateData, function (err) {
|
|
|
- if(err) cb(err);
|
|
|
+ if (err) cb(err);
|
|
|
else {
|
|
|
- Projects.update({userID: userID, 'property.feeFile.id': data.findData.ID}, {$set: {'property.feeFile.name': data.updateData.name}}, function (err) {
|
|
|
- if(err) cb(err);
|
|
|
+ Projects.update({
|
|
|
+ userID: userID,
|
|
|
+ 'property.feeFile.id': data.findData.ID
|
|
|
+ }, {$set: {'property.feeFile.name': data.updateData.name}}, function (err) {
|
|
|
+ if (err) cb(err);
|
|
|
else cb(false);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- else{
|
|
|
- if(data){
|
|
|
+ else {
|
|
|
+ if (data) {
|
|
|
Projects.update(data.findData, data.updateData, function (err) {
|
|
|
- if(err)cb(err);
|
|
|
+ if (err) cb(err);
|
|
|
else cb(false);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- )(updateDatas[i]));
|
|
|
+ })(updateDatas[i]));
|
|
|
}
|
|
|
async_c.parallel(functions, function (err, results) {
|
|
|
- if(err) callback(err, 'fail', null);
|
|
|
+ if (err) callback(err, 'fail', null);
|
|
|
else callback(0, 'success', null);
|
|
|
});
|
|
|
};
|
|
@@ -474,12 +530,18 @@ ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
|
|
|
* @param {Object} data
|
|
|
* @return {Boolean}
|
|
|
*/
|
|
|
-ProjectsDAO.prototype.isExist = async function(userId, compilationId, name, parentID) {
|
|
|
+ProjectsDAO.prototype.isExist = async function (userId, compilationId, name, parentID) {
|
|
|
parentID = parseInt(parentID);
|
|
|
if (name === '' || isNaN(parentID)) {
|
|
|
return true;
|
|
|
}
|
|
|
- let condition = {userID: userId, compilation: compilationId, ParentID: parentID, name: name, "$or":[{deleteInfo: null}, {"deleteInfo.deleted": false}]};
|
|
|
+ let condition = {
|
|
|
+ userID: userId,
|
|
|
+ compilation: compilationId,
|
|
|
+ ParentID: parentID,
|
|
|
+ name: name,
|
|
|
+ "$or": [{deleteInfo: null}, {"deleteInfo.deleted": false}]
|
|
|
+ };
|
|
|
let count = await Projects.count(condition);
|
|
|
return count > 0;
|
|
|
};
|
|
@@ -490,7 +552,7 @@ ProjectsDAO.prototype.isExist = async function(userId, compilationId, name, pare
|
|
|
* @param {Number} projectId
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
-ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
|
|
|
+ProjectsDAO.prototype.getTenderByProjectId = async function (projectId) {
|
|
|
let result = [];
|
|
|
// 首先获取对应的单位工程id
|
|
|
let engineeringData = await Projects.find({ParentID: projectId});
|
|
@@ -499,7 +561,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
|
|
|
}
|
|
|
|
|
|
let engineeringIdList = [];
|
|
|
- for(let tmp of engineeringData) {
|
|
|
+ for (let tmp of engineeringData) {
|
|
|
engineeringIdList.push(tmp.ID);
|
|
|
}
|
|
|
|
|
@@ -509,7 +571,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- for(let tmp of tenderData) {
|
|
|
+ for (let tmp of tenderData) {
|
|
|
result.push(tmp.ID);
|
|
|
}
|
|
|
|
|
@@ -522,7 +584,7 @@ ProjectsDAO.prototype.getTenderByProjectId = async function(projectId) {
|
|
|
* @param {Number} unitPriceFileId
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
-ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function(unitPriceFileId) {
|
|
|
+ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function (unitPriceFileId) {
|
|
|
let result = [];
|
|
|
|
|
|
unitPriceFileId = parseInt(unitPriceFileId);
|
|
@@ -542,7 +604,7 @@ ProjectsDAO.prototype.getTenderByUnitPriceFileId = async function(unitPriceFileI
|
|
|
* @param {Number} projectId
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
-ProjectsDAO.prototype.getUnitPriceFileId = async function(projectId) {
|
|
|
+ProjectsDAO.prototype.getUnitPriceFileId = async function (projectId) {
|
|
|
let result = 0;
|
|
|
let projectData = await Projects.findOne({ID: projectId});
|
|
|
if (projectData === null) {
|
|
@@ -559,12 +621,12 @@ ProjectsDAO.prototype.getUnitPriceFileId = async function(projectId) {
|
|
|
* @param {Number} userId
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
-ProjectsDAO.prototype.getUserProjectData = async function(userId) {
|
|
|
+ProjectsDAO.prototype.getUserProjectData = async function (userId) {
|
|
|
let projectList = await Projects.find({
|
|
|
'$or': [
|
|
|
{'userID': userId, 'deleteInfo': null, projType: 'Project'},
|
|
|
{'userID': userId, 'deleteInfo.deleted': {'$in': [null, false]}, projType: 'Project'}
|
|
|
- ]
|
|
|
+ ]
|
|
|
}, {_id: 0, name: 1, ID: 1});
|
|
|
|
|
|
return projectList;
|
|
@@ -577,7 +639,7 @@ ProjectsDAO.prototype.getUserProjectData = async function(userId) {
|
|
|
* @param {Object} changeInfo
|
|
|
* @return {Promise}
|
|
|
*/
|
|
|
-ProjectsDAO.prototype.changeUnitPriceFileInfo = async function(projectId, changeInfo) {
|
|
|
+ProjectsDAO.prototype.changeUnitPriceFileInfo = async function (projectId, changeInfo) {
|
|
|
projectId = parseInt(projectId);
|
|
|
if (isNaN(projectId) || projectId <= 0) {
|
|
|
return false;
|
|
@@ -587,8 +649,67 @@ ProjectsDAO.prototype.changeUnitPriceFileInfo = async function(projectId, change
|
|
|
return result.ok === 1;
|
|
|
};
|
|
|
|
|
|
-module.exports ={
|
|
|
- project: new ProjectsDAO(),
|
|
|
+
|
|
|
+/**
|
|
|
+ * 更新项目属性
|
|
|
+ *
|
|
|
+ * @param {Number} projectId - 项目id
|
|
|
+ * @param {Object} propertyData - 项目属性数据
|
|
|
+ * @return {Promise}
|
|
|
+ */
|
|
|
+ProjectsDAO.prototype.updateProjectProperty = async function(projectId, propertyData) {
|
|
|
+ projectId = parseInt(projectId);
|
|
|
+ if (isNaN(projectId) || projectId <= 0 || propertyData.property === undefined || propertyData.data === undefined) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const updateData = {};
|
|
|
+ updateData["property." + propertyData.property] = propertyData.data;
|
|
|
+ let result = await Projects.update({ID: projectId}, updateData);
|
|
|
+
|
|
|
+ return result.ok === 1;
|
|
|
+};
|
|
|
+
|
|
|
+// CSL, 2018-01-11 获取指定ID节点(如单项工程、建设项目)下所有单位工程的各项汇总金额,用于报表计算汇总。
|
|
|
+ProjectsDAO.prototype.getSummaryFees = async function (ID) {
|
|
|
+ async function getProject(ID){
|
|
|
+ return await Projects.findOne({'ID': ID, deleteInfo: null}, need);
|
|
|
+ };
|
|
|
+ async function getChildrenDocs(IDs){
|
|
|
+ return await Projects.find({'ParentID': {"$in":IDs}, deleteInfo: null}, need);
|
|
|
+ };
|
|
|
+ async function getEgrIDs(ID){
|
|
|
+ let _docs = await Projects.find({'ParentID': ID, deleteInfo: null}, ['ID', '-_id']);
|
|
|
+ let arr = [];
|
|
|
+ for (let doc of _docs){
|
|
|
+ arr.push(doc.ID);
|
|
|
+ };
|
|
|
+ return arr;
|
|
|
+ };
|
|
|
+
|
|
|
+ let need = ['ID', 'ParentID', 'NextSiblingID', 'name', 'projType',
|
|
|
+ 'fullFolder', 'summaryFees', '-_id'];
|
|
|
+ let _doc = await getProject(ID);
|
|
|
+ if (!_doc) return _doc;
|
|
|
+
|
|
|
+ if (_doc.projType.sameText('Engineering')){
|
|
|
+ return await getChildrenDocs([ID]);
|
|
|
+ }
|
|
|
+ else if (_doc.projType.sameText('Project')){
|
|
|
+ let eIDs = await getEgrIDs(ID);
|
|
|
+ return await getChildrenDocs(eIDs);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ return _doc;
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+ProjectsDAO.prototype.updateUnitFileToProject=async function(projectID,unitFile){
|
|
|
+ return await Projects.findOneAndUpdate({'ID':projectID},{'property.unitPriceFile':unitFile});
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+module.exports ={ project: new ProjectsDAO(),
|
|
|
projType: projectType,
|
|
|
fileType: fileType
|
|
|
};
|