|
@@ -15,6 +15,7 @@ import GLJTypeConst from "../../common/const/glj_type_const";
|
|
import RationGLJFacade from "../../ration_glj/facade/ration_glj_facade";
|
|
import RationGLJFacade from "../../ration_glj/facade/ration_glj_facade";
|
|
import STDRationLibGLJListModel from "../../common/std/std_ration_lib_glj_list_model";
|
|
import STDRationLibGLJListModel from "../../common/std/std_ration_lib_glj_list_model";
|
|
import STDGLJType from "../../../public/cache/std_glj_type_util";
|
|
import STDGLJType from "../../../public/cache/std_glj_type_util";
|
|
|
|
+import MixRatioModel from "./mix_ratio_model";
|
|
|
|
|
|
class GLJListModel extends BaseModel {
|
|
class GLJListModel extends BaseModel {
|
|
|
|
|
|
@@ -27,6 +28,14 @@ class GLJListModel extends BaseModel {
|
|
GLJTypeConst.COMMERCIAL_CONCRETE, GLJTypeConst.COMMERCIAL_MORTAR];
|
|
GLJTypeConst.COMMERCIAL_CONCRETE, GLJTypeConst.COMMERCIAL_MORTAR];
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 拥有组成物的工料机类型id
|
|
|
|
+ *
|
|
|
|
+ * @var {Array}
|
|
|
|
+ */
|
|
|
|
+ ownCompositionTypes = [GLJTypeConst.CONCRETE, GLJTypeConst.MORTAR, GLJTypeConst.MIX_RATIO,
|
|
|
|
+ GLJTypeConst.COMMERCIAL_CONCRETE, GLJTypeConst.COMMERCIAL_MORTAR];
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 构造函数
|
|
* 构造函数
|
|
*
|
|
*
|
|
* @return {void}
|
|
* @return {void}
|
|
@@ -81,8 +90,14 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
// 整理获取工料机ID list
|
|
// 整理获取工料机ID list
|
|
let gljIdList = [];
|
|
let gljIdList = [];
|
|
|
|
+ // 整理获取有组成物的项目工料机编码
|
|
|
|
+ let projectGLJCode = [];
|
|
for(let tmp of gljData) {
|
|
for(let tmp of gljData) {
|
|
gljIdList.push(tmp.id);
|
|
gljIdList.push(tmp.id);
|
|
|
|
+ // 有组成物的类型才入数组
|
|
|
|
+ if (this.ownCompositionTypes.indexOf(tmp.type)) {
|
|
|
|
+ projectGLJCode.push(tmp.code);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 从定额工料机库中获取消耗量
|
|
// 从定额工料机库中获取消耗量
|
|
@@ -97,8 +112,21 @@ class GLJListModel extends BaseModel {
|
|
quantityList[tmp.projectGLJID] = tmp.quantity;
|
|
quantityList[tmp.projectGLJID] = tmp.quantity;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 查找组成物的消耗量
|
|
|
|
+ let totalComposition = {};
|
|
|
|
+ if (projectGLJCode.length > 0) {
|
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
|
+ condition = {connect_code: {"$in": projectGLJCode}, unit_price_file_id: unitPriceFileId};
|
|
|
|
+ let mixRatioList = await mixRatioModel.findDataByCondition(condition, null, false);
|
|
|
|
+ for (let tmp of mixRatioList) {
|
|
|
|
+ totalComposition[tmp.connect_code] = totalComposition[tmp.connect_code] === undefined ? tmp.consumption :
|
|
|
|
+ totalComposition[tmp.connect_code] + tmp.consumption;
|
|
|
|
+ totalComposition[tmp.connect_code] = Number(totalComposition[tmp.connect_code].toFixed(2));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// 组合单价数据
|
|
// 组合单价数据
|
|
- this.combineData(gljData, unitPriceList, quantityList);
|
|
|
|
|
|
+ this.combineData(gljData, unitPriceList, quantityList, [], totalComposition);
|
|
|
|
|
|
// 排序
|
|
// 排序
|
|
gljData.sort(function (a, b) {
|
|
gljData.sort(function (a, b) {
|
|
@@ -118,9 +146,11 @@ class GLJListModel extends BaseModel {
|
|
* @param {object} gljList
|
|
* @param {object} gljList
|
|
* @param {object} unitPriceList
|
|
* @param {object} unitPriceList
|
|
* @param {object} quantityList
|
|
* @param {object} quantityList
|
|
|
|
+ * @param {object} mixRatioData 组合物明细数据
|
|
|
|
+ * @param {object} totalComposition 组合物父工料机统计数据
|
|
* @return {void}
|
|
* @return {void}
|
|
*/
|
|
*/
|
|
- combineData(gljList, unitPriceList, quantityList) {
|
|
|
|
|
|
+ combineData(gljList, unitPriceList, quantityList = {}, mixRatioData = {}, totalComposition = {}) {
|
|
// 循环组合数据
|
|
// 循环组合数据
|
|
for(let glj of gljList) {
|
|
for(let glj of gljList) {
|
|
if (glj.code === undefined) {
|
|
if (glj.code === undefined) {
|
|
@@ -132,8 +162,14 @@ class GLJListModel extends BaseModel {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- // 组合消耗量
|
|
|
|
|
|
+ // 消耗量赋值
|
|
glj.quantity = quantityList[glj.id] !== undefined ? quantityList[glj.id] : 0;
|
|
glj.quantity = quantityList[glj.id] !== undefined ? quantityList[glj.id] : 0;
|
|
|
|
+ glj.quantity = totalComposition[glj.code] !== undefined ? totalComposition[glj.code] : glj.quantity;
|
|
|
|
+
|
|
|
|
+ // 组成物消耗量
|
|
|
|
+ let gljId = glj.glj_id + '';
|
|
|
|
+ glj.consumption = mixRatioData[gljId] !== undefined ? mixRatioData[gljId].consumption : 0;
|
|
|
|
+ glj.mix_ratio_id = mixRatioData[gljId] !== undefined ? mixRatioData[gljId].id : 0;
|
|
|
|
|
|
// 计算调整基价
|
|
// 计算调整基价
|
|
switch (glj.unit_price.type + '') {
|
|
switch (glj.unit_price.type + '') {
|
|
@@ -167,6 +203,7 @@ class GLJListModel extends BaseModel {
|
|
}
|
|
}
|
|
// 首先查找是否有同编码同名称的工料机数据
|
|
// 首先查找是否有同编码同名称的工料机数据
|
|
let projectGljData = await this.findDataByCondition({code: data.code, project_id: data.project_id});
|
|
let projectGljData = await this.findDataByCondition({code: data.code, project_id: data.project_id});
|
|
|
|
+ let isAddProjectGLJ = false;
|
|
// 如果找不到数据则新增
|
|
// 如果找不到数据则新增
|
|
if (!projectGljData) {
|
|
if (!projectGljData) {
|
|
// 新增单条记录 (两个操作本来应该是事务操作,然而mongodb事务支持比较弱,就当作是都可以顺利执行)
|
|
// 新增单条记录 (两个操作本来应该是事务操作,然而mongodb事务支持比较弱,就当作是都可以顺利执行)
|
|
@@ -174,6 +211,7 @@ class GLJListModel extends BaseModel {
|
|
if (!gljInsertData) {
|
|
if (!gljInsertData) {
|
|
throw '新增项目工料机失败!';
|
|
throw '新增项目工料机失败!';
|
|
}
|
|
}
|
|
|
|
+ isAddProjectGLJ = true;
|
|
projectGljData = gljInsertData;
|
|
projectGljData = gljInsertData;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -185,9 +223,9 @@ class GLJListModel extends BaseModel {
|
|
}
|
|
}
|
|
let unitPriceFileId = unitPriceFile.id;
|
|
let unitPriceFileId = unitPriceFile.id;
|
|
|
|
|
|
- // 判断类型,如果是混凝土、砂浆或者配合比则查找对应的组成物
|
|
|
|
- if (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
|
|
|
|
- data.type === GLJTypeConst.MIX_RATIO) {
|
|
|
|
|
|
+ // 判断类型,如果是混凝土、砂浆或者配合比则查找对应的组成物(前提是没有对应的项目工料机数据)
|
|
|
|
+ if (isAddProjectGLJ && (data.type === GLJTypeConst.CONCRETE || data.type === GLJTypeConst.MORTAR ||
|
|
|
|
+ data.type === GLJTypeConst.MIX_RATIO)) {
|
|
this.compositionInit(data.code, data.project_id, unitPriceFileId);
|
|
this.compositionInit(data.code, data.project_id, unitPriceFileId);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -336,6 +374,7 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 工料机中组成物操作
|
|
* 工料机中组成物操作
|
|
|
|
+ * 该方法只在确保没有对应项目工料机的时候才会调用
|
|
*
|
|
*
|
|
* @param {String} code
|
|
* @param {String} code
|
|
* @param {Number} projectId
|
|
* @param {Number} projectId
|
|
@@ -343,10 +382,30 @@ class GLJListModel extends BaseModel {
|
|
* @return {void}
|
|
* @return {void}
|
|
*/
|
|
*/
|
|
async compositionInit(code, projectId, unitPriceFileId) {
|
|
async compositionInit(code, projectId, unitPriceFileId) {
|
|
-
|
|
|
|
// 查找对应组成物的项目工料机数据
|
|
// 查找对应组成物的项目工料机数据
|
|
let [projectGljList, compositionList] = await this.getCompositionGLJList(code, projectId, 'name');
|
|
let [projectGljList, compositionList] = await this.getCompositionGLJList(code, projectId, 'name');
|
|
|
|
|
|
|
|
+ // 整理配合比待插入数据
|
|
|
|
+ let mixRatioInsertData = [];
|
|
|
|
+ for (let tmp of compositionList) {
|
|
|
|
+ // 配合比数据插入
|
|
|
|
+ let mixRatioData = {
|
|
|
|
+ consumption: tmp.consumption,
|
|
|
|
+ glj_id: tmp.glj_id,
|
|
|
|
+ unit_price_file_id: unitPriceFileId,
|
|
|
|
+ connect_code: tmp.connect_code
|
|
|
|
+ };
|
|
|
|
+ mixRatioInsertData.push(mixRatioData);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 插入配合比表
|
|
|
|
+ // 因为有可能项目工料机与单价数据已存在,但配合比数据不存在,所以先插入配合比,后续判断如果存在项目工料机则可以省下数据库操作
|
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
|
+ let addMixRatioResult = await mixRatioModel.add(mixRatioInsertData);
|
|
|
|
+ if (!addMixRatioResult) {
|
|
|
|
+ throw '组成物插入单价数据失败!';
|
|
|
|
+ }
|
|
|
|
+
|
|
// 如果已经存在则后续操作停止
|
|
// 如果已经存在则后续操作停止
|
|
if(projectGljList.length === compositionList.length) {
|
|
if(projectGljList.length === compositionList.length) {
|
|
return;
|
|
return;
|
|
@@ -400,19 +459,22 @@ class GLJListModel extends BaseModel {
|
|
name: tmp.name,
|
|
name: tmp.name,
|
|
specs: tmp.specs,
|
|
specs: tmp.specs,
|
|
unit: tmp.unit,
|
|
unit: tmp.unit,
|
|
- consumption: compositionData[tmp.ID].consumption,
|
|
|
|
unit_price_file_id: unitPriceFileId,
|
|
unit_price_file_id: unitPriceFileId,
|
|
// 如果没有对应的工料机类型则默认设置为普通材料
|
|
// 如果没有对应的工料机类型则默认设置为普通材料
|
|
type: gljType[tmp.unit] !== undefined ? gljType[tmp.unit] : GLJTypeConst.MAIN_MATERIAL
|
|
type: gljType[tmp.unit] !== undefined ? gljType[tmp.unit] : GLJTypeConst.MAIN_MATERIAL
|
|
};
|
|
};
|
|
unitPriceInsertData.push(unitPriceData);
|
|
unitPriceInsertData.push(unitPriceData);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// 整理完后开始插入数据
|
|
// 整理完后开始插入数据
|
|
let addResult = await this.add(gljInsertData);
|
|
let addResult = await this.add(gljInsertData);
|
|
if (!addResult) {
|
|
if (!addResult) {
|
|
throw '组成物插入项目工料机失败!';
|
|
throw '组成物插入项目工料机失败!';
|
|
}
|
|
}
|
|
|
|
+ // 插入单价数据表
|
|
let unitPriceModel = new UnitPriceModel();
|
|
let unitPriceModel = new UnitPriceModel();
|
|
let addUnitPriceResult = await unitPriceModel.add(unitPriceInsertData);
|
|
let addUnitPriceResult = await unitPriceModel.add(unitPriceInsertData);
|
|
if (!addUnitPriceResult) {
|
|
if (!addUnitPriceResult) {
|
|
@@ -449,14 +511,22 @@ class GLJListModel extends BaseModel {
|
|
// 整理出code和name查找相关单价数据
|
|
// 整理出code和name查找相关单价数据
|
|
let codeList = [];
|
|
let codeList = [];
|
|
let nameList = [];
|
|
let nameList = [];
|
|
|
|
+ let gljIdList = [];
|
|
for(let tmp of gljData) {
|
|
for(let tmp of gljData) {
|
|
codeList.push(tmp.code);
|
|
codeList.push(tmp.code);
|
|
nameList.push(tmp.name);
|
|
nameList.push(tmp.name);
|
|
|
|
+ gljIdList.push(tmp.glj_id);
|
|
}
|
|
}
|
|
|
|
+
|
|
// 查找对应的单价数据
|
|
// 查找对应的单价数据
|
|
let unitPriceModel = new UnitPriceModel();
|
|
let unitPriceModel = new UnitPriceModel();
|
|
let condition = {code: {"$in": codeList}, name: {"$in": nameList}, unit_price_file_id: unitPriceFileId};
|
|
let condition = {code: {"$in": codeList}, name: {"$in": nameList}, unit_price_file_id: unitPriceFileId};
|
|
- let unitPriceList = await unitPriceModel.findDataByCondition(condition, null, false);
|
|
|
|
|
|
+ let unitPriceList = await unitPriceModel.findDataByCondition(condition, {_id: 0}, false);
|
|
|
|
+
|
|
|
|
+ // 查找对应的配合比数据
|
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
|
+ condition = {glj_id: {"$in": gljIdList}, connect_code: projectGLJData.code, unit_price_file_id: unitPriceFileId};
|
|
|
|
+ let mixRatioData = await mixRatioModel.findDataByCondition(condition, {_id: 0}, false, 'glj_id');
|
|
|
|
|
|
// 整理数据
|
|
// 整理数据
|
|
let unitPriceData = {};
|
|
let unitPriceData = {};
|
|
@@ -464,8 +534,12 @@ class GLJListModel extends BaseModel {
|
|
unitPriceData[tmp.code + tmp.name] = tmp;
|
|
unitPriceData[tmp.code + tmp.name] = tmp;
|
|
}
|
|
}
|
|
|
|
|
|
- this.combineData(gljData, unitPriceData, []);
|
|
|
|
|
|
+ this.combineData(gljData, unitPriceData, [], mixRatioData);
|
|
|
|
|
|
|
|
+ // 排序
|
|
|
|
+ gljData.sort(function (a, b) {
|
|
|
|
+ return parseInt(a.code) - parseInt(b.code);
|
|
|
|
+ });
|
|
result = gljData;
|
|
result = gljData;
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.log(error);
|
|
console.log(error);
|
|
@@ -501,7 +575,7 @@ class GLJListModel extends BaseModel {
|
|
|
|
|
|
// 查找对应的项目工料机数据
|
|
// 查找对应的项目工料机数据
|
|
let condition = {code: {"$in": codeList}, name: {"$in": nameList}, project_id: projectId};
|
|
let condition = {code: {"$in": codeList}, name: {"$in": nameList}, project_id: projectId};
|
|
- let gljData = await this.findDataByCondition(condition, null, false, indexBy);
|
|
|
|
|
|
+ let gljData = await this.findDataByCondition(condition, {_id: 0}, false, indexBy);
|
|
|
|
|
|
return [gljData, compositionList];
|
|
return [gljData, compositionList];
|
|
}
|
|
}
|