rpt_custom_define.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. return data;
  27. }
  28. async addInitialStageData(stage, preStage, transaction) {
  29. if (!stage || !preStage) {
  30. throw '标段数据有误';
  31. }
  32. const preDatas = await this.getAllDataByCondition({
  33. where: {sid: preStage.id}
  34. });
  35. if (preDatas.length > 0) {
  36. for (const pd of preDatas) {
  37. delete pd.id;
  38. pd.sid = stage.id;
  39. }
  40. const result = await transaction.insert(this.tableName, preDatas);
  41. return result.affectedRows === preDatas.length;
  42. } else {
  43. return true;
  44. }
  45. }
  46. }
  47. return RptCustomDefine;
  48. };