|
@@ -1,14 +1,133 @@
|
|
|
'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 PatentanalysisService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'patentanalysis');
|
|
|
this.model = this.ctx.model.Patent.Patentanalysis;
|
|
|
+ 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;
|
|
|
+ case '2':
|
|
|
+ word = '管理员审核通过';
|
|
|
+ break;
|
|
|
+ case '-2':
|
|
|
+ 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, mechanism_id, status, name, apply_name } = data;
|
|
|
+ const arr = [];
|
|
|
+ let content = '';
|
|
|
+ let to = '';
|
|
|
+ switch (code) {
|
|
|
+ case 'create':
|
|
|
+ content = `${apply_name}提交了专利申请书【${name}】的申报,请及时前往申请管理进行处理`;
|
|
|
+ if (status === '0') {
|
|
|
+ to = mechanism_id;
|
|
|
+ } else {
|
|
|
+ to = admin_id;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'update':
|
|
|
+ content = `${apply_name}重新提交了专利申请书【${name}】的申报,请及时前往申请管理进行处理`;
|
|
|
+ if (status === '0') {
|
|
|
+ to = mechanism_id;
|
|
|
+ } else {
|
|
|
+ to = admin_id;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case '-1':
|
|
|
+ content = `您的专利申请书【${name}】未通过机构的审核,请您及时修改,重新申请`;
|
|
|
+ to = user_id;
|
|
|
+ break;
|
|
|
+ case '-2':
|
|
|
+ content = `您的专利申请书【${name}】未通过管理员的审核,请您及时修改,重新申请`;
|
|
|
+ to = user_id;
|
|
|
+ break;
|
|
|
+ case '1':
|
|
|
+ arr.push({
|
|
|
+ content: `您的专利申请书【${name}】已通过机构的审核,请您耐心等待管理员审核`,
|
|
|
+ to: user_id,
|
|
|
+ });
|
|
|
+ arr.push({
|
|
|
+ content: `${apply_name}的专利申请书【${name}】已通过机构的审核,请您尽快对其进行再次审核`,
|
|
|
+ to: admin_id,
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case '2':
|
|
|
+ content = `您的专利申请书【${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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|