|
@@ -1,14 +1,111 @@
|
|
|
'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 PatentassessService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'patentassess');
|
|
|
this.model = this.ctx.model.Patent.Patentassess;
|
|
|
+ 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 };
|
|
|
+ if (status === '4') data['meta.state'] = 1;
|
|
|
+ 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 '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, status, patent_name } = data;
|
|
|
+ const arr = [];
|
|
|
+ let content = '';
|
|
|
+ let to = '';
|
|
|
+ switch (code) {
|
|
|
+ case 'create':
|
|
|
+ content = `${patent_name}提交了专利评估的申报,请及时前往申请管理进行处理`;
|
|
|
+ if (status === '0') {
|
|
|
+ to = admin_id;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ content = `${patent_name}重新提交了专利评估的申报,请及时前往申请管理进行处理`;
|
|
|
+ if (status === '0') {
|
|
|
+ to = admin_id;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case '-1':
|
|
|
+ content = `您的提交的专利评估【${patent_name}】未通过管理员的审核,请您及时修改,重新申请`;
|
|
|
+ to = user_id;
|
|
|
+ break;
|
|
|
+ case '1':
|
|
|
+ arr.push({
|
|
|
+ content: `您的提交的专利评估【${patent_name}】通过了管理员的审核`,
|
|
|
+ to: user_id,
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (code !== '2') {
|
|
|
+ const obj = { to, content };
|
|
|
+ await this.notice.create(obj);
|
|
|
+ } else {
|
|
|
+ await this.notice.insertMany(arr);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|