rpt_custom_define.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. if (data && data.stage_select) {
  31. data.stage_select = JSON.parse(data.stage_select);
  32. }
  33. return data;
  34. }
  35. async addInitialStageData(stage, preStage, transaction) {
  36. if (!stage || !preStage) {
  37. throw '标段数据有误';
  38. }
  39. const preDatas = await this.getAllDataByCondition({
  40. where: {sid: preStage.id}
  41. });
  42. if (preDatas.length > 0) {
  43. for (const pd of preDatas) {
  44. delete pd.id;
  45. pd.sid = stage.id;
  46. }
  47. const result = await transaction.insert(this.tableName, preDatas);
  48. return result.affectedRows === preDatas.length;
  49. } else {
  50. return true;
  51. }
  52. }
  53. async saveCustomSelect(data) {
  54. const sid = data.gather_select || data.stage_select ? -1 : data.stage_id;
  55. const filter = {tid: data.tender_id, sid: sid, rid: data.rpt_tpl_id};
  56. const count = await this.count(filter);
  57. const updateData = {};
  58. if (data.audit_select) updateData.audit_select = JSON.stringify(data.audit_select);
  59. if (data.gather_select) updateData.gather_select = JSON.stringify(data.gather_select);
  60. if (data.stage_select) updateData.stage_select = JSON.stringify(data.stage_select);
  61. if (count > 0) {
  62. await this.update(updateData, filter);
  63. } else {
  64. updateData.tid = data.tender_id;
  65. updateData.sid = sid;
  66. updateData.rid = data.rpt_tpl_id;
  67. await this.db.insert(this.tableName, updateData);
  68. }
  69. }
  70. async getCustomSelectByRpt(cid, rpt_c_type, tid, sid) {
  71. const result = await this.ctx.service.rptTpl.getAllDataByCondition({
  72. where: {cid: cid, rpt_c_type: rpt_c_type}
  73. });
  74. const customSelect = await this.getAllDataByCondition({
  75. where: {tid: tid, sid: sid}
  76. });
  77. for (const r of result) {
  78. const rptObj = JSON.parse(r.rpt_content);
  79. if (rptObj) r.custom_define = rptObj[JV.NODE_CUSTOM_DEFINE];
  80. delete r.rpt_content;
  81. const cs = this.ctx.helper._.find(customSelect, {rid: r.id});
  82. if (!cs) continue;
  83. r.tid = tid;
  84. r.sid = sid;
  85. if (cs.audit_select) {
  86. r.audit_select = JSON.parse(cs.audit_select);
  87. }
  88. if (cs.gather_select) {
  89. r.gather_select = JSON.parse(cs.gather_select);
  90. }
  91. if (cs.stage_select) {
  92. r.stage_select = JSON.parse(cs.stage_select);
  93. }
  94. }
  95. return result;
  96. }
  97. async getDataSelectByRpt(cid, rpt_d_type) {
  98. const result = await this.ctx.service.rptTpl.getAllDataByCondition({
  99. where: {cid: cid, rpt_d_type: rpt_d_type}
  100. });
  101. for (const r of result) {
  102. const rptObj = JSON.parse(r.rpt_content);
  103. if (rptObj) r.custom_define = rptObj[JV.NODE_CUSTOM_DEFINE];
  104. delete r.rpt_content;
  105. }
  106. return result;
  107. }
  108. }
  109. return RptCustomDefine;
  110. };