patentsafeg.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const Path = require('path');
  5. const _ = require('lodash');
  6. const moment = require('moment');
  7. const assert = require('assert');
  8. const { ObjectId } = require('mongoose').Types;
  9. const Excel = require('exceljs');
  10. const { sep } = require('path');
  11. const fs = require('fs');
  12. // 专利维权-维权书
  13. class PatentsafegService extends CrudService {
  14. constructor(ctx) {
  15. super(ctx, 'patentsafeg');
  16. this.model = this.ctx.model.Patent.Patentsafeg;
  17. this.notice = this.ctx.model.Patent.Patentexamine;
  18. }
  19. /**
  20. * 维权书
  21. * @param {body} body 参数
  22. * @property id 数据id
  23. * @property status 交底书要改变成的状态
  24. * @property info 其他数据,当做多个备注,记录使用
  25. */
  26. async check({ id, status, remark, file }) {
  27. const data = { status, file };
  28. await this.model.updateOne({ _id: ObjectId(id) }, data);
  29. // 换成对应的状态码,record在下面
  30. return await this.record({ id, method: status, remark });
  31. }
  32. async record({ id, method, remark }) {
  33. let word = '';
  34. switch (`${method}`) {
  35. case 'create':
  36. word = '已申请';
  37. break;
  38. case 'update':
  39. word = '修改';
  40. break;
  41. case '0':
  42. word = '管理员审核';
  43. break;
  44. case '1':
  45. word = '管理员审核通过';
  46. break;
  47. case '-1':
  48. word = '管理员审核未通过';
  49. break;
  50. case '2':
  51. word = '报告文件已发放,请及时下载';
  52. break;
  53. default:
  54. word = '未知状态';
  55. break;
  56. }
  57. const data = await this.model.findById(id);
  58. if (!data) {
  59. throw new BusinessError(
  60. ErrorCode.DATA_NOT_EXIST,
  61. '添加记录----未找到数据'
  62. );
  63. }
  64. const obj = {
  65. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  66. word,
  67. remark,
  68. };
  69. data.record.push(obj);
  70. const res = await data.save();
  71. this.toNotice(id, method);
  72. return res;
  73. }
  74. async toNotice(id, code) {
  75. const data = await this.model.findById(id);
  76. if (!data) return;
  77. const { user_id, admin_id, name, apply_personal } = data;
  78. const arr = [];
  79. let content = '';
  80. let to = '';
  81. switch (code) {
  82. case 'create':
  83. content = `${apply_personal}提交了专利维权书【${name}】的申报,请及时前往申请管理进行处理`;
  84. to = admin_id;
  85. break;
  86. case 'update':
  87. content = `${apply_personal}重新提交了专利维权书【${name}】的申报,请及时前往申请管理进行处理`;
  88. to = admin_id;
  89. break;
  90. case '-1':
  91. content = `您的专利维权书【${name}】未通过管理员的审核,请您及时修改,重新申请`;
  92. to = user_id;
  93. break;
  94. case '2':
  95. content = `您的专利维权书【${name}】已发放报告文件,请您及时下载报告文件查看`;
  96. to = user_id;
  97. break;
  98. default:
  99. break;
  100. }
  101. if (arr.length > 0) {
  102. await this.notice.insertMany(arr);
  103. } else {
  104. const obj = { to, content };
  105. await this.notice.create(obj);
  106. }
  107. }
  108. }
  109. module.exports = PatentsafegService;