| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 | 
							- 'use strict';
 
- /**
 
-  *
 
-  *
 
-  * @author Mai
 
-  * @date
 
-  * @version
 
-  */
 
- const JV = require('../reports/rpt_component/jpc_value_define');
 
- 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);
 
-             if (data && data.gather_select) data.gather_select = JSON.parse(data.gather_select);
 
-             if (data && data.stage_select) data.stage_select = JSON.parse(data.stage_select);
 
-             if (data && data.material_sum_select) data.material_sum_select = JSON.parse(data.material_sum_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;
 
-             }
 
-         }
 
-         async saveCustomSelect(data) {
 
-             const sid = data.audit_select ? data.stage_id : -1;
 
-             const filter = {tid: data.tender_id, sid: sid, rid: data.rpt_tpl_id};
 
-             const count = await this.count(filter);
 
-             const updateData = {};
 
-             if (data.audit_select) updateData.audit_select = JSON.stringify(data.audit_select);
 
-             if (data.gather_select) updateData.gather_select = JSON.stringify(data.gather_select);
 
-             if (data.stage_select) updateData.stage_select = JSON.stringify(data.stage_select);
 
-             if (data.material_sum_select) updateData.material_sum_select = JSON.stringify(data.material_sum_select);
 
-             if (count > 0) {
 
-                 await this.update(updateData, filter);
 
-             } else {
 
-                 updateData.tid = data.tender_id;
 
-                 updateData.sid = sid;
 
-                 updateData.rid = data.rpt_tpl_id;
 
-                 await this.db.insert(this.tableName, updateData);
 
-             }
 
-         }
 
-         async getCustomSelectByRpt(cid, rpt_c_type, tid, sid) {
 
-             const result = await this.ctx.service.rptTpl.getAllDataByCondition({
 
-                 where: {cid: cid, rpt_c_type: rpt_c_type}
 
-             });
 
-             const customSelect = await this.getAllDataByCondition({
 
-                 where: {tid: tid, sid: sid}
 
-             });
 
-             for (const r of result) {
 
-                 const rptObj = JSON.parse(r.rpt_content);
 
-                 if (rptObj) r.custom_define = rptObj[JV.NODE_CUSTOM_DEFINE];
 
-                 delete r.rpt_content;
 
-                 const cs = this.ctx.helper._.find(customSelect, {rid: r.id});
 
-                 if (!cs) continue;
 
-                 r.tid = tid;
 
-                 r.sid = sid;
 
-                 if (cs.audit_select) r.audit_select = JSON.parse(cs.audit_select);
 
-                 if (cs.gather_select) r.gather_select = JSON.parse(cs.gather_select);
 
-                 if (cs.stage_select) r.stage_select = JSON.parse(cs.stage_select);
 
-                 if (cs.material_sum_select) r.material_sum_select = JSON.parse(cs.material_sum_select);
 
-             }
 
-             return result;
 
-         }
 
-         async getDataSelectByRpt(cid, rpt_d_type) {
 
-             const result = await this.ctx.service.rptTpl.getAllDataByCondition({
 
-                 where: {cid: cid, rpt_d_type: rpt_d_type}
 
-             });
 
-             for (const r of result) {
 
-                 const rptObj = JSON.parse(r.rpt_content);
 
-                 if (rptObj) r.custom_define = rptObj[JV.NODE_CUSTOM_DEFINE];
 
-                 delete r.rpt_content;
 
-             }
 
-             return result;
 
-         }
 
-     }
 
-     return RptCustomDefine;
 
- };
 
 
  |