patentassess.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 PatentassessService extends CrudService {
  14. constructor(ctx) {
  15. super(ctx, 'patentassess');
  16. this.model = this.ctx.model.Patent.Patentassess;
  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, report, is_money }) {
  27. const data = { status, report, is_money };
  28. if (status === '4') data['meta.state'] = 1;
  29. await this.model.updateOne({ _id: ObjectId(id) }, data);
  30. // 换成对应的状态码,record在下面
  31. return await this.record({ id, method: status, remark });
  32. }
  33. async record({ id, method, remark }) {
  34. let word = '';
  35. switch (`${method}`) {
  36. case 'create':
  37. word = '已申请';
  38. break;
  39. case 'update':
  40. word = '修改';
  41. break;
  42. case '1':
  43. word = '审核通过';
  44. break;
  45. case '-1':
  46. word = '审核拒绝';
  47. break;
  48. default:
  49. word = '未知状态';
  50. break;
  51. }
  52. const data = await this.model.findById(id);
  53. if (!data) {
  54. throw new BusinessError(
  55. ErrorCode.DATA_NOT_EXIST,
  56. '添加记录----未找到数据'
  57. );
  58. }
  59. const obj = {
  60. time: moment().format('YYYY-MM-DD HH:mm:ss'),
  61. word,
  62. remark,
  63. };
  64. data.record.push(obj);
  65. const res = await data.save();
  66. this.toNotice(id, method);
  67. return res;
  68. }
  69. async toNotice(id, code) {
  70. const data = await this.model.findById(id);
  71. if (!data) return;
  72. const { user_id, admin_id, status, patent_name } = data;
  73. const arr = [];
  74. let content = '';
  75. let to = '';
  76. switch (code) {
  77. case 'create':
  78. content = `${patent_name}提交了价值评估的申报,请及时前往申请管理进行处理`;
  79. if (status === '0') {
  80. to = admin_id;
  81. }
  82. break;
  83. case 'update':
  84. content = `${patent_name}重新提交了价值评估的申报,请及时前往申请管理进行处理`;
  85. if (status === '0') {
  86. to = admin_id;
  87. }
  88. break;
  89. case '-1':
  90. content = `您提交的价值评估【${patent_name}】未通过管理员的审核,请您及时修改,重新申请`;
  91. to = user_id;
  92. break;
  93. case '1':
  94. content = `您提交的价值评估【${patent_name}】通过了管理员的审核,系统管理员会在3-5个工作日发出价值评估报告,以供用户下载`;
  95. to = user_id;
  96. break;
  97. case '2':
  98. content = `您提交的价值评估【${patent_name}】系统管理员已发放报告文件,请及时查看并下载`;
  99. to = user_id;
  100. break;
  101. default:
  102. break;
  103. }
  104. if (arr.length > 0) {
  105. await this.notice.insertMany(arr);
  106. } else {
  107. const obj = { to, content };
  108. await this.notice.create(obj);
  109. }
  110. }
  111. }
  112. module.exports = PatentassessService;