rpt_archive.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. 'use strict';
  2. /**
  3. * Created by Tony on 2021/3/30.
  4. */
  5. const BaseService = require('../base/base_service');
  6. module.exports = app => {
  7. class RptArchive extends BaseService {
  8. /**
  9. * 构造函数
  10. *
  11. * @param {Object} ctx - egg全局变量
  12. * @return {void}
  13. */
  14. constructor(ctx) {
  15. super(ctx);
  16. this.tableName = 'rpt_archive';
  17. this.dataId = 'id';
  18. }
  19. async getArchiveById(id) {
  20. this.initSqlBuilder();
  21. this.sqlBuilder.setAndWhere('id', {
  22. value: id,
  23. operate: '=',
  24. });
  25. this.sqlBuilder.columns = ['id', 'prj_id', 'stage_id', 'content'];
  26. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  27. const list = await this.db.query(sql, sqlParam);
  28. return list;
  29. }
  30. async getPrjStgArchive(prjId, stgId) {
  31. this.initSqlBuilder();
  32. this.sqlBuilder.setAndWhere('prj_id', {
  33. value: prjId,
  34. operate: '=',
  35. });
  36. this.sqlBuilder.setAndWhere('stage_id', {
  37. value: stgId,
  38. operate: '=',
  39. });
  40. this.sqlBuilder.columns = ['id', 'prj_id', 'stage_id', 'content'];
  41. const [sql, sqlParam] = this.sqlBuilder.build(this.tableName);
  42. const rstList = await this.db.query(sql, sqlParam);
  43. return rstList;
  44. }
  45. async createArchive(prj_id, stage_id, archiveArr) {
  46. let rst = null;
  47. this.transaction = await this.db.beginTransaction();
  48. try {
  49. const data = {
  50. prj_id,
  51. stage_id,
  52. content: JSON.stringify(archiveArr),
  53. };
  54. // console.log(data);
  55. rst = await this.transaction.insert(this.tableName, data);
  56. await this.transaction.commit();
  57. } catch (ex) {
  58. console.log(ex);
  59. // 回滚
  60. await this.transaction.rollback();
  61. }
  62. return rst;
  63. }
  64. async updateArchive(id, prj_id, stage_id, archiveArr) {
  65. let rst = null;
  66. this.transaction = await this.db.beginTransaction();
  67. try {
  68. const data = {
  69. id,
  70. prj_id,
  71. stage_id,
  72. content: JSON.stringify(archiveArr),
  73. };
  74. // console.log(data);
  75. rst = await this.transaction.update(this.tableName, data);
  76. await this.transaction.commit();
  77. } catch (ex) {
  78. console.log(ex);
  79. // 回滚
  80. await this.transaction.rollback();
  81. }
  82. return rst;
  83. }
  84. // async addInitialStageData(tender_id, stage, preStage) {
  85. // // 在加stage的时候需要挂上这个,copy之前的签名人
  86. // const rst = [];
  87. // const preRoleRelList = await this.getRoleRptRelByTenderId(tender_id, preStage.id);
  88. // for (const rptRoleRel of preRoleRelList) {
  89. // const relList = JSON.parse(rptRoleRel.rel_content);
  90. // // const newRptRoleRel = {tender_id: tender_id, rpt_id: rptRoleRel.rpt_id, sid: stage.id, rel_content: ''};
  91. // const newRelList = [];
  92. // for (const role of relList) {
  93. // const newRole = {};
  94. // newRelList.push(newRole);
  95. // for (const key in role) {
  96. // if (key !== 'sign_date') {
  97. // newRole[key] = role[key];
  98. // } else {
  99. // newRole[key] = '';
  100. // }
  101. // }
  102. // }
  103. // // rst.push(await this.createRoleRelationship(tender_id, rptRoleRel.rpt_id, stage.id, newRelList));
  104. // await this.createRoleRelationship(tender_id, rptRoleRel.rpt_id, stage.id, newRelList); // 暂时用不到,就先不返回结果
  105. // }
  106. // return rst;
  107. // }
  108. // async updateRoleRelationship(id, tender_id, rpt_id, sid, relArr) {
  109. // let rst = null;
  110. // if (id < 0) {
  111. // rst = await this.createRoleRelationship(tender_id, rpt_id, sid, relArr);
  112. // } else {
  113. // this.transaction = await this.db.beginTransaction();
  114. // try {
  115. // const data = { id, tender_id, rpt_id, sid, rel_content: JSON.stringify(relArr) };
  116. // rst = await this.transaction.update(this.tableName, data);
  117. // await this.transaction.commit();
  118. // } catch (ex) {
  119. // console.log(ex);
  120. // // 回滚
  121. // await this.transaction.rollback();
  122. // }
  123. // }
  124. // return rst;
  125. // }
  126. //
  127. // async updateMultiRoleRelationship(orgParams, newRelArr) {
  128. // for (let idx = 0; idx < orgParams.length; idx++) {
  129. // const param = orgParams[idx];
  130. // const data = { tender_id: param[0], sid: param[1], rpt_id: param[2] };
  131. // this.transaction = await this.db.beginTransaction();
  132. // try {
  133. // await this.transaction.delete(this.tableName, data);
  134. // this.transaction.commit();
  135. // await this.createRoleRelationship(param[0], param[2], param[1], newRelArr);
  136. // } catch (ex) {
  137. // console.log(ex.toString());
  138. // // 回滚
  139. // await this.transaction.rollback();
  140. // }
  141. // }
  142. // return true;
  143. // }
  144. }
  145. return RptArchive;
  146. };