rpt_custom_define.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const JV = require('../reports/rpt_component/jpc_value_define');
  10. module.exports = app => {
  11. class RptCustomDefine extends app.BaseService {
  12. /**
  13. * 构造函数
  14. *
  15. * @param {Object} ctx - egg全局变量
  16. * @return {void}
  17. */
  18. constructor(ctx) {
  19. super(ctx);
  20. this.tableName = 'rpt_custom_define';
  21. }
  22. async getCustomDefine(tid, sid, rid) {
  23. const data = await this.getDataByCondition({ tid: tid, sid: sid, rid: rid });
  24. if (data && data.audit_select) {
  25. data.audit_select = JSON.parse(data.audit_select);
  26. }
  27. if (data && data.gather_select) {
  28. data.gather_select = JSON.parse(data.gather_select);
  29. }
  30. return data;
  31. }
  32. async addInitialStageData(stage, preStage, transaction) {
  33. if (!stage || !preStage) {
  34. throw '标段数据有误';
  35. }
  36. const preDatas = await this.getAllDataByCondition({
  37. where: {sid: preStage.id}
  38. });
  39. if (preDatas.length > 0) {
  40. for (const pd of preDatas) {
  41. delete pd.id;
  42. pd.sid = stage.id;
  43. }
  44. const result = await transaction.insert(this.tableName, preDatas);
  45. return result.affectedRows === preDatas.length;
  46. } else {
  47. return true;
  48. }
  49. }
  50. async saveCustomSelect(data) {
  51. const sid = data.gather_select ? -1 : data.stage_id;
  52. const filter = {tid: data.tender_id, sid: sid, rid: data.rpt_tpl_id};
  53. const count = await this.count(filter);
  54. const updateData = {};
  55. if (data.audit_select) updateData.audit_select = JSON.stringify(data.audit_select);
  56. if (data.gather_select) updateData.gather_select = JSON.stringify(data.gather_select);
  57. if (count > 0) {
  58. await this.update(updateData, filter);
  59. } else {
  60. updateData.tid = data.tender_id;
  61. updateData.sid = sid;
  62. updateData.rid = data.rpt_tpl_id;
  63. await this.db.insert(this.tableName, updateData);
  64. }
  65. }
  66. async getCustomSelectByRpt(cid, rpt_c_type, tid, sid) {
  67. const result = await this.ctx.service.rptTpl.getAllDataByCondition({
  68. where: {cid: cid, rpt_c_type: rpt_c_type}
  69. });
  70. const customSelect = await this.getAllDataByCondition({
  71. where: {tid: tid, sid: sid}
  72. });
  73. for (const r of result) {
  74. const rptObj = JSON.parse(r.rpt_content);
  75. if (rptObj) r.custom_define = rptObj[JV.NODE_CUSTOM_DEFINE];
  76. delete r.rpt_content;
  77. const cs = this.ctx.helper._.find(customSelect, {rid: r.id});
  78. if (!cs) continue;
  79. r.tid = tid;
  80. r.sid = sid;
  81. if (cs.audit_select) {
  82. r.audit_select = JSON.parse(cs.audit_select);
  83. }
  84. if (cs.gather_select) {
  85. r.gather_select = JSON.parse(cs.gather_select);
  86. }
  87. }
  88. return result;
  89. }
  90. async getDataSelectByRpt(cid, rpt_d_type) {
  91. const result = await this.ctx.service.rptTpl.getAllDataByCondition({
  92. where: {cid: cid, rpt_d_type: rpt_d_type}
  93. });
  94. for (const r of result) {
  95. const rptObj = JSON.parse(r.rpt_content);
  96. if (rptObj) r.custom_define = rptObj[JV.NODE_CUSTOM_DEFINE];
  97. delete r.rpt_content;
  98. }
  99. return result;
  100. }
  101. }
  102. return RptCustomDefine;
  103. };