rpt_custom_define.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class RptCustomDefine extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'rpt_custom_define';
  20. }
  21. async getCustomDefine(tid, sid, rid) {
  22. const data = await this.getDataByCondition({ tid: tid, sid: sid, rid: rid });
  23. if (data && data.audit_select) {
  24. data.audit_select = JSON.parse(data.audit_select);
  25. }
  26. if (data && data.gather_select) {
  27. data.gather_select = JSON.parse(data.gather_select);
  28. }
  29. return data;
  30. }
  31. async addInitialStageData(stage, preStage, transaction) {
  32. if (!stage || !preStage) {
  33. throw '标段数据有误';
  34. }
  35. const preDatas = await this.getAllDataByCondition({
  36. where: {sid: preStage.id}
  37. });
  38. if (preDatas.length > 0) {
  39. for (const pd of preDatas) {
  40. delete pd.id;
  41. pd.sid = stage.id;
  42. }
  43. const result = await transaction.insert(this.tableName, preDatas);
  44. return result.affectedRows === preDatas.length;
  45. } else {
  46. return true;
  47. }
  48. }
  49. }
  50. return RptCustomDefine;
  51. };