|
@@ -0,0 +1,108 @@
|
|
|
+'use strict';
|
|
|
+const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
+const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
+const Path = require('path');
|
|
|
+const _ = require('lodash');
|
|
|
+const moment = require('moment');
|
|
|
+const assert = require('assert');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
+const Excel = require('exceljs');
|
|
|
+const { sep } = require('path');
|
|
|
+const fs = require('fs');
|
|
|
+
|
|
|
+// 专利维权-维权书
|
|
|
+class PatentsafegService extends CrudService {
|
|
|
+ constructor(ctx) {
|
|
|
+ super(ctx, 'patentsafeg');
|
|
|
+ this.model = this.ctx.model.Patent.Patentsafeg;
|
|
|
+ this.notice = this.ctx.model.Patent.Patentexamine;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 维权书
|
|
|
+ * @param {body} body 参数
|
|
|
+ * @property id 数据id
|
|
|
+ * @property status 交底书要改变成的状态
|
|
|
+ * @property info 其他数据,当做多个备注,记录使用
|
|
|
+ */
|
|
|
+ async check({ id, status, remark }) {
|
|
|
+ const data = { status };
|
|
|
+ await this.model.updateOne({ _id: ObjectId(id) }, data);
|
|
|
+ // 换成对应的状态码,record在下面
|
|
|
+ return await this.record({ id, method: status, remark });
|
|
|
+ }
|
|
|
+ async record({ id, method, remark }) {
|
|
|
+ let word = '';
|
|
|
+ switch (`${method}`) {
|
|
|
+ case 'create':
|
|
|
+ word = '已申请';
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ word = '修改';
|
|
|
+ break;
|
|
|
+ case '0':
|
|
|
+ word = '管理员审核';
|
|
|
+ break;
|
|
|
+ case '1':
|
|
|
+ word = '管理员审核通过';
|
|
|
+ break;
|
|
|
+ case '-1':
|
|
|
+ word = '管理员审核未通过';
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ word = '未知状态';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ const data = await this.model.findById(id);
|
|
|
+ if (!data) {
|
|
|
+ throw new BusinessError(
|
|
|
+ ErrorCode.DATA_NOT_EXIST,
|
|
|
+ '添加记录----未找到数据'
|
|
|
+ );
|
|
|
+ }
|
|
|
+ const obj = {
|
|
|
+ time: moment().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
+ word,
|
|
|
+ remark,
|
|
|
+ };
|
|
|
+ data.record.push(obj);
|
|
|
+ const res = await data.save();
|
|
|
+ this.toNotice(id, method);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ async toNotice(id, code) {
|
|
|
+ const data = await this.model.findById(id);
|
|
|
+ if (!data) return;
|
|
|
+ const { user_id, admin_id, name, apply_name } = data;
|
|
|
+ const arr = [];
|
|
|
+ let content = '';
|
|
|
+ let to = '';
|
|
|
+ switch (code) {
|
|
|
+ case 'create':
|
|
|
+ content = `${apply_name}提交了专利维权书【${name}】的申报,请及时前往申请管理进行处理`;
|
|
|
+ to = admin_id;
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ content = `${apply_name}重新提交了专利维权书【${name}】的申报,请及时前往申请管理进行处理`;
|
|
|
+ to = admin_id;
|
|
|
+ break;
|
|
|
+ case '-1':
|
|
|
+ content = `您的专利维权书【${name}】未通过管理员的审核,请您及时修改,重新申请`;
|
|
|
+ to = user_id;
|
|
|
+ break;
|
|
|
+ case '1':
|
|
|
+ content = `您的专利维权书【${name}】已通过管理员的审核,请您耐心等待管理员审核`;
|
|
|
+ to = user_id;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (arr.length > 0) {
|
|
|
+ await this.notice.insertMany(arr);
|
|
|
+ } else {
|
|
|
+ const obj = { to, content };
|
|
|
+ await this.notice.create(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+module.exports = PatentsafegService;
|