|
@@ -0,0 +1,135 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @author Mai
|
|
|
+ * @date
|
|
|
+ * @version
|
|
|
+ */
|
|
|
+
|
|
|
+const defaultInfo = {
|
|
|
+ main_quantity: [
|
|
|
+ { id: 1, name: '路基土石方', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 2, name: '特殊路基处理', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 3, name: '路基排水坞工', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 4, name: '路基防护坞工', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 5, name: '路面工程', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 6, name: '大、特大桥', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 7, name: '中、小桥', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 8, name: '涵洞', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 9, name: '隧道', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 10, name: '分离式立交', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 11, name: '通道、天桥', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 12, name: '平面交叉', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 13, name: '互通式立交', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 14, name: '连接线长度、辅导长度', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 15, name: '管理及养护房屋', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ ],
|
|
|
+ gcl_quantity: [
|
|
|
+ { id: 1, name: '主要人工消耗', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 2, name: '主要材料消耗', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 3, name: '钢材', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 4, name: '沥青', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 5, name: '路面工程', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 6, name: '汽油、柴油', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 7, name: '水泥', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 8, name: '碎石、砂', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 9, name: '电', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ { id: 10, name: '主要机械消耗', unit: 'm3', dgn_qty: 0, final_qty: 0, },
|
|
|
+ ],
|
|
|
+};
|
|
|
+
|
|
|
+module.exports = app => {
|
|
|
+
|
|
|
+ class SubProjInfo extends app.BaseService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx);
|
|
|
+ this.tableName = 'sub_project_info';
|
|
|
+ }
|
|
|
+
|
|
|
+ async addInfo(id, project_id, transaction) {
|
|
|
+ const info = { id, project_id };
|
|
|
+ for (const di in defaultInfo) {
|
|
|
+ info[di] = JSON.stringify(defaultInfo[di]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (transaction) {
|
|
|
+ await transaction.insert(this.tableName, info);
|
|
|
+ } else {
|
|
|
+ await this.db.insert(this.tableName, info);
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取标段相关信息
|
|
|
+ * @param tenderId
|
|
|
+ * @return {Promise<void>}
|
|
|
+ */
|
|
|
+ async getInfo(id) {
|
|
|
+ let info = await this.getDataByCondition({ id });
|
|
|
+ // 兼容不存在info的情况
|
|
|
+ if (!info) info = await this.addInfo(id, this.ctx.session.sessionProject.id);
|
|
|
+
|
|
|
+ for (const ai in defaultInfo) {
|
|
|
+ info[ai] = !info[ai] || info[ai] === '' ? defaultInfo[ai] : JSON.parse(info[ai]);
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ async _saveCommonInfo(id, data) {
|
|
|
+ const updateData = { id };
|
|
|
+ for (const d in data) {
|
|
|
+ if (d === 'id' || d === 'project_id') continue;
|
|
|
+ if (defaultInfo[d]) continue;
|
|
|
+
|
|
|
+ updateData[d] = data[d];
|
|
|
+ }
|
|
|
+
|
|
|
+ await this.db.update(this.tableName, updateData);
|
|
|
+ return updateData;
|
|
|
+ }
|
|
|
+
|
|
|
+ async _saveArrayInfo(id, type, data) {
|
|
|
+ const info = await this.getInfo(id);
|
|
|
+ const source = info[type];
|
|
|
+ const result = [];
|
|
|
+ for (const d of data) {
|
|
|
+ const s = source.find(x => { return x.id === d.id });
|
|
|
+ if (d.dgn_qty !== undefined) s.dgn_qty = d.dgn_qty || 0;
|
|
|
+ if (d.final_qty !== undefined) s.final_qty = d.final_qty || 0;
|
|
|
+ result.push(s);
|
|
|
+ }
|
|
|
+ const updateData = { id };
|
|
|
+ updateData[type] = JSON.stringify(source);
|
|
|
+ await this.db.update(this.tableName, updateData);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存标段相关信息
|
|
|
+ *
|
|
|
+ * @param data
|
|
|
+ * @return {Promise<void>}
|
|
|
+ */
|
|
|
+ async saveInfo(id, data) {
|
|
|
+ switch (data.type) {
|
|
|
+ case 'main_quantity':
|
|
|
+ case 'gcl_quantity':
|
|
|
+ return await this._saveArrayInfo(id, data.type, data.updateData);
|
|
|
+ default:
|
|
|
+ return await this._saveCommonInfo(id, data.updateData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return SubProjInfo;
|
|
|
+};
|