patentanalysis.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose/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. default:
  51. word = '未知状态';
  52. break;
  53. }
  54. const data = await this.model.findById(id);
  55. if (!data) {
  56. throw new BusinessError(
  57. ErrorCode.DATA_NOT_EXIST,
  58. '添加记录----未找到数据'
  59. );
  60. }
  61. const obj = {
  62. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  63. word,
  64. remark,
  65. };
  66. data.record.push(obj);
  67. const res = await data.save();
  68. this.toNotice(id, method);
  69. return res;
  70. }
  71. async toNotice(id, code) {
  72. const data = await this.model.findById(id);
  73. if (!data) return;
  74. const { user_id, admin_id, name, apply_name } = data;
  75. const arr = [];
  76. let content = '';
  77. let to = '';
  78. switch (code) {
  79. case 'create':
  80. content = `${apply_name}提交了专利申请书【${name}】的申报,请及时前往申请管理进行处理`;
  81. to = admin_id;
  82. break;
  83. case 'update':
  84. content = `${apply_name}重新提交了专利申请书【${name}】的申报,请及时前往申请管理进行处理`;
  85. to = admin_id;
  86. break;
  87. case '-1':
  88. content = `您的专利申请书【${name}】未通过管理员的审核,请您及时修改,重新申请`;
  89. to = user_id;
  90. break;
  91. case '1':
  92. content = `您的专利申请书【${name}】已通过管理员的审核,请您耐心等待管理员发放报告文件`;
  93. to = user_id;
  94. break;
  95. default:
  96. break;
  97. }
  98. if (arr.length > 0) {
  99. await this.notice.insertMany(arr);
  100. } else {
  101. const obj = { to, content };
  102. await this.notice.create(obj);
  103. }
  104. }
  105. }
  106. module.exports = PatentanalysisService;