|
@@ -428,6 +428,65 @@ class GLJController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取项目中所有组成物数据(用户缓存到前端变量)
|
|
|
+ *
|
|
|
+ * @param {object} request
|
|
|
+ * @param {object} response
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async getComposition(request, response) {
|
|
|
+ let projectId = request.body.project_id;
|
|
|
+ projectId = parseInt(projectId);
|
|
|
+
|
|
|
+ let responseData = {
|
|
|
+ err: 0,
|
|
|
+ data: null
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ // 当前单价文件id
|
|
|
+ let currentUnitPriceId = await ProjectModel.getUnitPriceFileId(projectId);
|
|
|
+ if (currentUnitPriceId <= 0) {
|
|
|
+ throw '没有找到对应的单价文件';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取组成物数据
|
|
|
+ let mixRatioModel = new MixRatioModel();
|
|
|
+ let compositionData = await mixRatioModel.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false);
|
|
|
+ if (compositionData === null) {
|
|
|
+ throw '没有找到组成物数据';
|
|
|
+ }
|
|
|
+ compositionData = JSON.parse(JSON.stringify(compositionData));
|
|
|
+ // 查找对应的单价数据
|
|
|
+ let unitPriceModel = new UnitPriceModel();
|
|
|
+ let unitPriceData = await unitPriceModel.findDataByCondition({unit_price_file_id: currentUnitPriceId}, null, false, 'code');
|
|
|
+
|
|
|
+ // 整理数据
|
|
|
+ let result = {};
|
|
|
+ for(let composition of compositionData) {
|
|
|
+ let tmpData = {
|
|
|
+ market_price: unitPriceData[composition.connect_code] !== undefined ?
|
|
|
+ unitPriceData[composition.connect_code].market_price : 0,
|
|
|
+ base_price: unitPriceData[composition.connect_code] !== undefined ?
|
|
|
+ unitPriceData[composition.connect_code].base_price : 0,
|
|
|
+ consumption: composition.consumption,
|
|
|
+ glj_type: composition.glj_type,
|
|
|
+ connect_code: composition.connect_code
|
|
|
+ };
|
|
|
+ if (result[composition.connect_code] === undefined) {
|
|
|
+ result[composition.connect_code] = [];
|
|
|
+ }
|
|
|
+ result[composition.connect_code].push(tmpData);
|
|
|
+ }
|
|
|
+ responseData.data = result;
|
|
|
+ } catch (error) {
|
|
|
+ responseData.err = 1;
|
|
|
+ responseData.data = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ response.json(responseData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 模拟定额插入
|
|
|
*
|
|
|
* @param {object} request
|