institution.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class InstitutionService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'institution');
  10. this.model = this.ctx.model.Institution;
  11. this.releaseModel = this.ctx.model.Release;
  12. }
  13. // publish:发布还是取消发布;finid:股权ID;userid:金控管理员ID;type:1-股权;
  14. async makePublish(data) {
  15. const { publish, finid } = data;
  16. const finalStutus = {};
  17. const newdata = {};
  18. newdata.review_id = data.userid;
  19. newdata.product_id = finid;
  20. newdata.type = '1';
  21. if (publish === 1) {
  22. newdata.status = publish;
  23. const financ = await this.model.findById(finid);
  24. financ.status = '2';
  25. const res = await financ.save();
  26. if (res) {
  27. finalStutus.status = 'SUCCESS';
  28. await this.releaseModel.create(newdata);
  29. } else {
  30. finalStutus.status = 'ERROR';
  31. }
  32. } else {
  33. newdata.status = publish;
  34. const financ = await this.model.findById(finid);
  35. financ.status = '1';
  36. const res = await financ.save();
  37. if (res) {
  38. finalStutus.status = 'SUCCESS';
  39. const relea = await this.releaseModel.find({ product_id: finid });
  40. relea.status = '0';
  41. await relea.save();
  42. } else {
  43. finalStutus.status = 'ERROR';
  44. }
  45. }
  46. return finalStutus;
  47. }
  48. // 查询股权信息详情
  49. async getOne(data) {
  50. const { insid } = data;
  51. const match = {};
  52. if (insid) { // 股权ID
  53. match._id = ObjectId(insid);
  54. }
  55. const res = await this.model.aggregate([
  56. { $match: match},
  57. { $lookup: {
  58. from: 'dictionary',
  59. localField: 'profession',
  60. foreignField: 'code',
  61. as: 'pronew' } },
  62. { $lookup: {
  63. from: 'dictionary',
  64. localField: 'round',
  65. foreignField: 'code',
  66. as: 'roundnew' } },
  67. { $project: { profession: 0, round: 0 } },
  68. ]);
  69. return res;
  70. }
  71. }
  72. module.exports = InstitutionService;