123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- '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: 'km', 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: 'm2', dgn_qty: 0, final_qty: 0, },
- { id: 6, name: '大、特大桥', unit: 'm/座', dgn_qty: 0, final_qty: 0, },
- { id: 7, name: '中、小桥', unit: 'm/座', dgn_qty: 0, final_qty: 0, },
- { id: 8, name: '涵洞', unit: 'm/道', dgn_qty: 0, final_qty: 0, },
- { id: 9, name: '隧道', unit: 'm/座', dgn_qty: 0, final_qty: 0, },
- { id: 10, name: '分离式立交', unit: '处', dgn_qty: 0, final_qty: 0, },
- { id: 11, name: '通道、天桥', unit: '座', dgn_qty: 0, final_qty: 0, },
- { id: 12, name: '平面交叉', unit: '处', dgn_qty: 0, final_qty: 0, },
- { id: 13, name: '互通式立交', unit: 'km/处', dgn_qty: 0, final_qty: 0, },
- { id: 14, name: '连接线长度、辅导长度', unit: 'km', dgn_qty: 0, final_qty: 0, },
- { id: 15, name: '管理及养护房屋', unit: 'm2', dgn_qty: 0, final_qty: 0, },
- ],
- gcl_quantity: [
- { id: 1, pid: -1, full_path: '1', level: 1, is_leaf: 1, order: 1, name: '主要人工消耗', unit: '工日', dgn_qty: 0, final_qty: 0, },
- { id: 2, pid: -1, full_path: '2', level: 1, is_leaf: 0, order: 2, name: '主要材料消耗', unit: '', dgn_qty: 0, final_qty: 0, },
- { id: 3, pid: 2, full_path: '2-3', level: 2, is_leaf: 1, order: 1, name: '钢材', unit: '吨', dgn_qty: 0, final_qty: 0, },
- { id: 4, pid: 2, full_path: '2-4', level: 2, is_leaf: 1, order: 2, name: '沥青', unit: '吨', dgn_qty: 0, final_qty: 0, },
- { id: 5, pid: 2, full_path: '2-5', level: 2, is_leaf: 1, order: 3, name: '汽油、柴油', unit: '吨', dgn_qty: 0, final_qty: 0, },
- { id: 6, pid: 2, full_path: '2-6', level: 2, is_leaf: 1, order: 4, name: '水泥', unit: '吨', dgn_qty: 0, final_qty: 0, },
- { id: 7, pid: 2, full_path: '2-7', level: 2, is_leaf: 1, order: 5, name: '碎石、砂', unit: 'm3', dgn_qty: 0, final_qty: 0, },
- { id: 8, pid: 2, full_path: '2-8', level: 2, is_leaf: 1, order: 6, name: '电', unit: 'km.h', dgn_qty: 0, final_qty: 0, },
- { id: 9, pid: -1, full_path: '9', level: 1, is_leaf: 1, order: 3, name: '主要机械消耗', unit: '台班', 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 getInfo4Report(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]);
- info[ai].forEach(x => {
- x.type = 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;
- };
|