'use strict'; /** * * * @author Mai * @date * @version */ module.exports = app => { class RptCustomDefine extends app.BaseService { /** * 构造函数 * * @param {Object} ctx - egg全局变量 * @return {void} */ constructor(ctx) { super(ctx); this.tableName = 'rpt_custom_define'; } async getCustomDefine(tid, sid, rid) { const data = await this.getDataByCondition({ tid: tid, sid: sid, rid: rid }); if (data && data.audit_select) { data.audit_select = JSON.parse(data.audit_select); } return data; } async addInitialStageData(stage, preStage, transaction) { if (!stage || !preStage) { throw '标段数据有误'; } const preDatas = await this.getAllDataByCondition({ where: {sid: preStage.id} }); if (preDatas.length > 0) { for (const pd of preDatas) { delete pd.id; pd.sid = stage.id; } const result = await transaction.insert(this.tableName, preDatas); return result.affectedRows === preDatas.length; } else { return true; } } } return RptCustomDefine; };