patentanalysis.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 PatentanalysisService extends CrudService {
  14. constructor(ctx) {
  15. super(ctx, 'patentanalysis');
  16. this.model = this.ctx.model.Patent.Patentanalysis;
  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 }) {
  27. const data = { status };
  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_name } = data;
  78. const arr = [];
  79. let content = '';
  80. let to = '';
  81. switch (code) {
  82. case 'create':
  83. content = `${apply_name}提交了【${name}】的专利检索申报,请及时前往相应功能管理进行处理`;
  84. to = admin_id;
  85. break;
  86. case 'update':
  87. content = `${apply_name}重新提交了【${name}】的专利检索申报,请及时前往相应功能管理进行处理`;
  88. to = admin_id;
  89. break;
  90. case '-1':
  91. content = `您的【${name}】的专利检索未通过系统管理员的审核`;
  92. to = user_id;
  93. break;
  94. case '1':
  95. content = `您的【${name}】的专利检索通过了系统管理员的审核,请您耐心等待系统管理员发放报告文件`;
  96. to = user_id;
  97. break;
  98. case '2':
  99. content = `您的【${name}】的专利检索的报告已发放,请及时查看`;
  100. to = user_id;
  101. break;
  102. default:
  103. break;
  104. }
  105. if (arr.length > 0) {
  106. await this.notice.insertMany(arr);
  107. } else {
  108. const obj = { to, content };
  109. await this.notice.create(obj);
  110. }
  111. }
  112. }
  113. module.exports = PatentanalysisService;