123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date 2018/10/30
- * @version
- */
- const infoConst = require('../const/tender_info');
- const parseInfo = infoConst.parseInfo;
- const arrayInfo = infoConst.arrayInfo;
- module.exports = app => {
- class PaymentTenderInfo extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'payment_tender_info';
- }
- get DefaultInfo () {
- return infoConst.paymentDefaultInfo;
- }
- /**
- * 新增 标段相关信息
- *
- * @param tenderId - 标段Id
- * @param projectId - 项目Id
- * @param transaction - 事务
- * @return {Promise<void>}
- */
- async addTenderInfo(tenderId, projectId, transaction) {
- const defaultInfo = this.DefaultInfo;
- const info = JSON.parse(JSON.stringify(defaultInfo));
- info.id = tenderId;
- info.pid = projectId;
- for (const pi of parseInfo) {
- if (info[pi] === undefined) continue;
- info[pi] = JSON.stringify(info[pi]);
- }
- for (const pi of arrayInfo) {
- if (info[pi] === undefined) continue;
- info[pi] = JSON.stringify(info[pi]);
- }
- if (transaction) {
- await transaction.insert(this.tableName, info);
- } else {
- await this.db.insert(this.tableName, info);
- }
- return info;
- }
- /**
- * 获取标段相关信息
- * @param tenderId
- * @return {Promise<void>}
- */
- async getTenderInfo(tenderId, projectId) {
- const defaultInfo = this.DefaultInfo;
- let info = await this.getDataByCondition({ id: tenderId });
- // 兼容不存在info的情况
- if (!info) info = await this.addTenderInfo(tenderId, projectId || this.ctx.session.sessionProject.id);
- for (const pi of parseInfo) {
- if (info[pi] === undefined) continue;
- info[pi] = !info[pi] || info[pi] === '' ? defaultInfo[pi] : JSON.parse(info[pi]);
- this.ctx.helper._.defaultsDeep(info[pi], defaultInfo[pi]);
- }
- for (const ai of arrayInfo) {
- if (info[ai] === undefined) continue;
- info[ai] = !info[ai] || info[ai] === '' ? defaultInfo[ai] : JSON.parse(info[ai]);
- }
- return info;
- }
- /**
- * 保存标段相关信息
- *
- * @param data
- * @return {Promise<void>}
- */
- async saveTenderInfo(tenderId, data) {
- for (const di in data) {
- if (parseInfo.indexOf(di) >= 0 || arrayInfo.indexOf(di) >= 0) {
- data[di] = JSON.stringify(data[di]);
- }
- }
- await this.db.update(this.tableName, data, { where: { id: tenderId } });
- }
- /**
- * 拷贝标段数据至当前标段
- * @param {number} id - 当前标段id
- * @param {number} copy_id - 被拷贝的标段id
- */
- async copyTenderHandler(id, copy_id) {
- const [data] = await this.ctx.service.tenderInfo.getDataByCondition({
- where: { id: copy_id },
- columns: ['deal_info', 'construction_unit', 'tech_param'],
- });
- await this.defaultUpdate(data, { id });
- }
- }
- return PaymentTenderInfo;
- };
|