rpt_archive.js 7.1 KB

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