|
@@ -1,5 +1,5 @@
|
|
/**
|
|
/**
|
|
- * 单价文件业务模型
|
|
|
|
|
|
+ * 单价业务模型
|
|
*
|
|
*
|
|
* @author CaiAoLin
|
|
* @author CaiAoLin
|
|
* @date 2017/6/30
|
|
* @date 2017/6/30
|
|
@@ -24,18 +24,18 @@ class UnitPriceModel extends BaseModel {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 根据标段获取对应单价数据
|
|
|
|
|
|
+ * 根据单价文件id获取单价数据
|
|
*
|
|
*
|
|
- * @param {Number} tenderId
|
|
|
|
|
|
+ * @param {Number} fileId
|
|
* @return {Promise}
|
|
* @return {Promise}
|
|
*/
|
|
*/
|
|
- async getDataByTenderId(tenderId) {
|
|
|
|
- tenderId = parseInt(tenderId);
|
|
|
|
- if (isNaN(tenderId) || tenderId <= 0) {
|
|
|
|
|
|
+ async getDataByFileId(fileId) {
|
|
|
|
+ fileId = parseInt(fileId);
|
|
|
|
+ if (isNaN(fileId) || fileId <= 0) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- let unitPriceList = await this.db.model.find({tender_id: tenderId});
|
|
|
|
|
|
+ let unitPriceList = await this.db.model.find({unit_price_file_id: fileId});
|
|
if (unitPriceList.length <= 0) {
|
|
if (unitPriceList.length <= 0) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
@@ -59,37 +59,37 @@ class UnitPriceModel extends BaseModel {
|
|
switch (scene) {
|
|
switch (scene) {
|
|
// 新增数据的验证规则
|
|
// 新增数据的验证规则
|
|
case 'add':
|
|
case 'add':
|
|
- this.model.schema.path('project_id').required(true);
|
|
|
|
- this.model.schema.path('tender_id').required(true);
|
|
|
|
this.model.schema.path('base_price').required(true);
|
|
this.model.schema.path('base_price').required(true);
|
|
this.model.schema.path('market_price').required(true);
|
|
this.model.schema.path('market_price').required(true);
|
|
this.model.schema.path('name').required(true);
|
|
this.model.schema.path('name').required(true);
|
|
this.model.schema.path('code').required(true);
|
|
this.model.schema.path('code').required(true);
|
|
this.model.schema.path('unit').required(true);
|
|
this.model.schema.path('unit').required(true);
|
|
this.model.schema.path('type').required(true);
|
|
this.model.schema.path('type').required(true);
|
|
|
|
+ this.model.schema.path('unit_price_file_id').required(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 更新单价文件(定额中修改价格时调用)
|
|
|
|
|
|
+ * 更新单价数据(定额中修改价格时调用)
|
|
*
|
|
*
|
|
* @param {Object} data
|
|
* @param {Object} data
|
|
- * @param {Number} unitPriceTenderId
|
|
|
|
|
|
+ * @param {Number} unitPriceFileId
|
|
* @return {Promise}
|
|
* @return {Promise}
|
|
*/
|
|
*/
|
|
- async updateUnitPrice(data, unitPriceTenderId) {
|
|
|
|
- if (data.code === undefined || data.tender_id === undefined || data.name === undefined
|
|
|
|
|
|
+ async updateUnitPrice(data, unitPriceFileId) {
|
|
|
|
+ if (data.code === undefined || data.project_id === undefined || data.name === undefined
|
|
|| data.market_price === undefined) {
|
|
|| data.market_price === undefined) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
let marketPrice = data.market_price !== undefined ? data.market_price : data.base_price;
|
|
let marketPrice = data.market_price !== undefined ? data.market_price : data.base_price;
|
|
|
|
|
|
// 先查找是否有同code的单价记录 @todo 后续可能会加入单位这个字段进一步确定唯一性
|
|
// 先查找是否有同code的单价记录 @todo 后续可能会加入单位这个字段进一步确定唯一性
|
|
- let unitPriceData = await this.findDataByCondition({code: data.code, tender_id: unitPriceTenderId}, null, false);
|
|
|
|
|
|
+ let unitPriceData = await this.findDataByCondition({code: data.code, unit_price_file_id: unitPriceFileId}, null, false);
|
|
|
|
|
|
// 如果有记录,判断是否存在一样的市场单价,有则直接返回数据
|
|
// 如果有记录,判断是否存在一样的市场单价,有则直接返回数据
|
|
- if (unitPriceData && this.isPriceIncluded(unitPriceData, data.market_price)) {
|
|
|
|
- return unitPriceData;
|
|
|
|
|
|
+ let unitPriceIndex = this.isPriceIncluded(unitPriceData, data.market_price);
|
|
|
|
+ if (unitPriceData && unitPriceIndex > 0) {
|
|
|
|
+ return unitPriceData[unitPriceIndex];
|
|
}
|
|
}
|
|
|
|
|
|
// 如果不存在基价单价,则在数据源中获取
|
|
// 如果不存在基价单价,则在数据源中获取
|
|
@@ -104,8 +104,7 @@ class UnitPriceModel extends BaseModel {
|
|
code: data.code,
|
|
code: data.code,
|
|
base_price: data.base_price,
|
|
base_price: data.base_price,
|
|
market_price: marketPrice,
|
|
market_price: marketPrice,
|
|
- project_id: data.project_id,
|
|
|
|
- tender_id: unitPriceTenderId,
|
|
|
|
|
|
+ unit_price_file_id: unitPriceFileId,
|
|
name: data.name,
|
|
name: data.name,
|
|
type: data.type,
|
|
type: data.type,
|
|
unit: data.unit
|
|
unit: data.unit
|
|
@@ -124,7 +123,7 @@ class UnitPriceModel extends BaseModel {
|
|
// 然后再插入一条项目工料机数据
|
|
// 然后再插入一条项目工料机数据
|
|
let gljListModel = new GLJListModel();
|
|
let gljListModel = new GLJListModel();
|
|
// 首先先查找原有数据
|
|
// 首先先查找原有数据
|
|
- let originalData = await gljListModel.findDataByCondition({code: data.code, tender_id: data.tender_id}, {_id: 0});
|
|
|
|
|
|
+ let originalData = await gljListModel.findDataByCondition({code: data.code, project_id: data.project_id}, {_id: 0});
|
|
|
|
|
|
// 查不到数据直接抛出错误
|
|
// 查不到数据直接抛出错误
|
|
if(!originalData) {
|
|
if(!originalData) {
|
|
@@ -164,21 +163,21 @@ class UnitPriceModel extends BaseModel {
|
|
*
|
|
*
|
|
* @param {Array} data
|
|
* @param {Array} data
|
|
* @param {Number} price
|
|
* @param {Number} price
|
|
- * @return boolean
|
|
|
|
|
|
+ * @return {Number}
|
|
*/
|
|
*/
|
|
isPriceIncluded(data, price) {
|
|
isPriceIncluded(data, price) {
|
|
- let result = false;
|
|
|
|
|
|
+ let index = -1;
|
|
if (data.length <= 0) {
|
|
if (data.length <= 0) {
|
|
- return result;
|
|
|
|
|
|
+ return index;
|
|
}
|
|
}
|
|
-
|
|
|
|
- for(let tmp of data) {
|
|
|
|
- if (tmp.market_price === price) {
|
|
|
|
- return true;
|
|
|
|
|
|
+ for(let tmp in data) {
|
|
|
|
+ if (data[tmp].market_price === price) {
|
|
|
|
+ index = tmp;
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ return index;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|