patentapply.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 PatentapplyService extends CrudService {
  14. constructor(ctx) {
  15. super(ctx, 'patentapply');
  16. this.model = this.ctx.model.Patent.Patentapply;
  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, remark, ...data }) {
  27. // const data = { status, admin_id, admin_name };
  28. await this.model.updateOne({ _id: ObjectId(id) }, data);
  29. // 换成对应的状态码,record在下面
  30. return await this.record({ id, method: data.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 '1':
  42. word = '企业/学校审批通过';
  43. break;
  44. case '-1':
  45. word = '企业/学校审未通过';
  46. break;
  47. case '2':
  48. word = '科企代理';
  49. break;
  50. case '3':
  51. word = '代理机构代理';
  52. break;
  53. case '4':
  54. word = '代理机构受理通过';
  55. break;
  56. case '-4':
  57. word = '代理机构受理拒绝';
  58. break;
  59. case '5':
  60. word = '科企代理';
  61. break;
  62. case '-5':
  63. word = '代理机构自行代理';
  64. break;
  65. case '6':
  66. word = '接收申请文件通过';
  67. break;
  68. case '-6':
  69. word = '接收申请文件未通过';
  70. break;
  71. case '7':
  72. word = '已上报国知局';
  73. break;
  74. default:
  75. word = '未知状态';
  76. break;
  77. }
  78. const data = await this.model.findById(id);
  79. if (!data) {
  80. throw new BusinessError(
  81. ErrorCode.DATA_NOT_EXIST,
  82. '添加记录----未找到数据'
  83. );
  84. }
  85. const obj = {
  86. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  87. word,
  88. remark,
  89. };
  90. data.record.push(obj);
  91. const res = await data.save();
  92. this.toNotice(id, method);
  93. return res;
  94. }
  95. async toNotice(id, code) {
  96. const data = await this.model.findById(id);
  97. if (!data) return;
  98. const {
  99. user_id,
  100. mech_id,
  101. admin_id,
  102. agentmech_id,
  103. name,
  104. apply_name,
  105. status,
  106. } = data;
  107. const arr = [];
  108. let content = '';
  109. let to = '';
  110. switch (code) {
  111. case 'create':
  112. content = `${apply_name}提交了专利申请书【${name}】的申报,及时前往专利申请管理进行处理`;
  113. if (status === '0') {
  114. to = mech_id;
  115. }
  116. break;
  117. case 'update':
  118. content = `${apply_name}重新提交了专利申请书【${name}】的申报,请及时前往专利申请管理进行处理`;
  119. if (status === '0') {
  120. to = mech_id;
  121. } else if (status === '2') {
  122. to = admin_id;
  123. } else if (status === '3') {
  124. to = agentmech_id;
  125. }
  126. break;
  127. case '1':
  128. content = `您的专利申请书【${name}】通过机构的审批,请您及时选择机构,并上传申请文件进行专利CPC系统申报`;
  129. to = user_id;
  130. break;
  131. case '-1':
  132. content = `您的专利申请书【${name}】未通过机构的审批,请您及时修改,重新申请`;
  133. to = user_id;
  134. break;
  135. case '4':
  136. content = `您的专利申请书【${name}】已通过代理机构受理,请等待代理机构进行对申请文件查看`;
  137. to = user_id;
  138. break;
  139. case '-4':
  140. content = `您的专利申请书【${name}】未通过代理机构的受理,请及时查看审核结果,并重新选择代理机构`;
  141. to = user_id;
  142. break;
  143. case '5':
  144. arr.push({
  145. content: `您的专利申请书【${name}】已由代理机构推行给科企机构,请等待科企机构进行受理`,
  146. to: user_id,
  147. });
  148. arr.push({
  149. content: `${apply_name}的专利申请书【${name}】已由代理机构推送给科企机构,请您尽快对其进行受理`,
  150. to: admin_id,
  151. });
  152. break;
  153. case '-5':
  154. content = `您的专利申请书【${name}】已由代理机构自行上报国知局系统`;
  155. to = user_id;
  156. break;
  157. case '6':
  158. content = `您的专利申请书【${name}】通过科企机构的受理,请耐心等待科企机构上报国知局`;
  159. to = user_id;
  160. break;
  161. case '-6':
  162. content = `您的专利申请书【${name}】未通过科企机构的受理,请及时查看审核结果,并重新选择代理机构`;
  163. to = user_id;
  164. break;
  165. case '7':
  166. content = `您的专利申请书【${name}】已上传到国知局,请耐心等待国知局反馈信息`;
  167. to = user_id;
  168. break;
  169. default:
  170. break;
  171. }
  172. if (arr.length > 0) {
  173. await this.notice.insertMany(arr);
  174. } else {
  175. const obj = { to, content };
  176. await this.notice.create(obj);
  177. }
  178. }
  179. }
  180. module.exports = PatentapplyService;