signature_controller.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. 'use strict';
  2. /**
  3. * Created by Tony on 2019/9/26.
  4. */
  5. module.exports = app => {
  6. class ReportController extends app.BaseController {
  7. /**
  8. * 创建电子签名角色
  9. *
  10. * @param {Object} ctx - egg全局context
  11. * @return {void}
  12. */
  13. async createSignatureRole(ctx) {
  14. const params = JSON.parse(ctx.request.body.params);
  15. // console.log(params);
  16. const rst = await ctx.service.signatureRole.createRole(params.name, params.bind_acc_id, params.prj_id, params.tender_id);
  17. // console.log(rst);
  18. ctx.body = { data: rst };
  19. // ctx.body = { data: { msg: 'test the network' } };
  20. ctx.status = 201;
  21. }
  22. /**
  23. * 创建签名角色关联
  24. *
  25. * @param {Object} ctx - egg全局context
  26. * @return {void}
  27. */
  28. async createRoleRel(ctx) {
  29. const params = JSON.parse(ctx.request.body.params);
  30. // console.log(params);
  31. const rst = await ctx.service.roleRptRel.createRoleRelationship(params.tender_id, params.rpt_id, params.rel_content);
  32. // console.log(rst);
  33. ctx.body = { data: rst };
  34. // ctx.body = { data: { msg: 'test the network' } };
  35. ctx.status = 201;
  36. }
  37. /**
  38. * 更新签名角色关联
  39. *
  40. * @param {Object} ctx - egg全局context
  41. * @return {void}
  42. */
  43. async updateRoleRel(ctx) {
  44. const params = JSON.parse(ctx.request.body.params);
  45. // console.log(params);
  46. const rst = await ctx.service.roleRptRel.updateRoleRelationship(params.id, params.tender_id, params.rpt_id, params.stage_id, params.rel_content);
  47. const roleRel = await ctx.service.roleRptRel.getRoleRptRelByDetailIds(params.tender_id, params.rpt_id, params.stage_id);
  48. // const roleRel = params.rel_content;
  49. await encodeSignatureDataUri(roleRel, this.app.baseDir);
  50. // console.log(rst);
  51. ctx.body = { data: rst, signatureRelInfo: roleRel };
  52. // ctx.body = { data: { msg: 'test the network' } };
  53. ctx.status = 201;
  54. }
  55. /**
  56. * 获取多个标段签名角色关联
  57. *
  58. * @param {Object} ctx - egg全局context
  59. * @return {void}
  60. */
  61. async getMultiRoleRptRels(ctx) {
  62. const params = JSON.parse(ctx.request.body.params);
  63. const conParams = params.selectedTenders;
  64. const rst = await ctx.service.roleRptRel.getCrossTenderRoleRptRels(conParams);
  65. ctx.body = { data: rst };
  66. ctx.status = 201;
  67. }
  68. /**
  69. * 跨标段更新签名角色关联
  70. *
  71. * @param {Object} ctx - egg全局context
  72. * @return {void}
  73. */
  74. async updateCrossTendersRoleRelationship(ctx) {
  75. const params = JSON.parse(ctx.request.body.params);
  76. const conParams = params.selectedTenders;
  77. // conParams.push([params.tender_id, params.stage_id, params.rpt_id]); // 传过来的数据是额外项目的,还需要加上自己一个
  78. const roleRel = params.rel_content;
  79. // updateMultiRoleRelationship
  80. // console.log(params.rel_content);
  81. await ctx.service.roleRptRel.updateRoleRelationship(params.id, params.tender_id, params.rpt_id, params.stage_id, params.rel_content); // 传过来的数据是额外项目的,还需要单独处理当前的
  82. const rst = await ctx.service.roleRptRel.updateMultiRoleRelationship(conParams, roleRel);
  83. ctx.body = { data: rst };
  84. ctx.status = 201;
  85. }
  86. /**
  87. * 更新最近使用签名
  88. *
  89. * @param {Object} ctx - egg全局context
  90. * @return {void}
  91. */
  92. async updateSignatureUsed(ctx) {
  93. const params = JSON.parse(ctx.request.body.params);
  94. const used_time = ctx.request.body.create_time;
  95. const signused = await ctx.service.signatureUsed.updateUsed(params, used_time);
  96. const signUsedList = await ctx.service.signatureUsed.getSignatureUsedByTenderId(params.tender_id);
  97. // const rst = await ctx.service.signatureRole.createRole(params.name, params.bind_acc_id, params.prj_id, params.tender_id);
  98. // console.log(rst);
  99. ctx.body = { data: signUsedList };
  100. // ctx.body = { data: { msg: 'test the network' } };
  101. ctx.status = 201;
  102. }
  103. }
  104. return ReportController;
  105. };
  106. async function encodeSignatureDataUri(roleRel, baseDir) {
  107. if (roleRel) {
  108. for (const singleRoleRel of roleRel) {
  109. if (singleRoleRel.rel_content !== null && singleRoleRel.rel_content !== undefined && singleRoleRel.rel_content !== '') {
  110. const roleRelContent = JSON.parse(singleRoleRel.rel_content);
  111. for (const role of roleRelContent) {
  112. // console.log(role);
  113. if (role.sign_path !== '') {
  114. const filePath = baseDir + '/app' + role.sign_path;
  115. try {
  116. const res = await isFileExisted(filePath);
  117. if (res) {
  118. const bData = fs.readFileSync(filePath);
  119. const base64Str = bData.toString('base64');
  120. const datauri = 'data:image/png;base64,' + base64Str;
  121. role.sign_pic = datauri;
  122. } else {
  123. console.log('文件不存在:' + filePath);
  124. }
  125. } catch (err) {
  126. console.error(err);
  127. }
  128. }
  129. }
  130. singleRoleRel.rel_content = JSON.stringify(roleRelContent);
  131. } else {
  132. singleRoleRel.rel_content = [];
  133. }
  134. }
  135. }
  136. }