|
@@ -5,6 +5,7 @@ const { ObjectId } = require('mongoose').Types;
|
|
const _ = require('lodash');
|
|
const _ = require('lodash');
|
|
const assert = require('assert');
|
|
const assert = require('assert');
|
|
const moment = require('moment');
|
|
const moment = require('moment');
|
|
|
|
+const { trimData } = require('naf-core').Util;
|
|
// 专利运营已授权专利预警表
|
|
// 专利运营已授权专利预警表
|
|
class PatentearlyService extends CrudService {
|
|
class PatentearlyService extends CrudService {
|
|
constructor(ctx) {
|
|
constructor(ctx) {
|
|
@@ -12,7 +13,47 @@ class PatentearlyService extends CrudService {
|
|
this.model = this.ctx.model.Patent.Patentearly;
|
|
this.model = this.ctx.model.Patent.Patentearly;
|
|
this.patentinfo = this.ctx.model.Patent.Patentinfo;
|
|
this.patentinfo = this.ctx.model.Patent.Patentinfo;
|
|
}
|
|
}
|
|
|
|
+ async query(query, { skip = 0, limit = 0 }) {
|
|
|
|
+ const newquery = await this.resetCode(query);
|
|
|
|
+ const res = await this.model
|
|
|
|
+ .find(newquery)
|
|
|
|
+ .skip(parseInt(skip))
|
|
|
|
+ .limit(parseInt(limit))
|
|
|
|
+ .sort({ 'meta.createdAt': -1 });
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+ async count(query) {
|
|
|
|
+ const newquery = await this.resetCode(query);
|
|
|
|
+ const res = await this.model.countDocuments(trimData(newquery)).exec();
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ async resetCode(query) {
|
|
|
|
+ let newquery = _.cloneDeep(query);
|
|
|
|
+ newquery = this.ctx.service.util.util.dealQuery(newquery);
|
|
|
|
+ const { type } = newquery;
|
|
|
|
+ if (type === 'else') {
|
|
|
|
+ newquery.$and = [
|
|
|
|
+ { type: { $ne: '发明' } },
|
|
|
|
+ { type: { $ne: '实用新型' } },
|
|
|
|
+ ];
|
|
|
|
+ delete newquery.type;
|
|
|
|
+ }
|
|
|
|
+ const { code, user_id } = newquery;
|
|
|
|
+ let ids = [];
|
|
|
|
+ if (code) {
|
|
|
|
+ const plist = await this.personalModel.find({ code });
|
|
|
|
+ ids = plist.map(i => i._id);
|
|
|
|
+ if (ids.length > 0) {
|
|
|
|
+ newquery.user_id = { $elemMatch: { $in: ids } };
|
|
|
|
+ delete newquery.code;
|
|
|
|
+ }
|
|
|
|
+ } else if (user_id) {
|
|
|
|
+ newquery.user_id = { $elemMatch: { $in: [ ObjectId(user_id) ] } };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return newquery;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 产生警告
|
|
* 产生警告
|
|
*/
|
|
*/
|
|
@@ -49,7 +90,7 @@ class PatentearlyService extends CrudService {
|
|
if (r) {
|
|
if (r) {
|
|
total++;
|
|
total++;
|
|
const { inventor, name } = i;
|
|
const { inventor, name } = i;
|
|
- const content = `发明人 ${inventor} 的已授权专利 ${name} 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
|
|
|
+ const content = `发明人 【${inventor}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
const nobj = { ..._.omit(i, [ '_id', 'id' ]), content, parent_id: i._id };
|
|
const nobj = { ..._.omit(i, [ '_id', 'id' ]), content, parent_id: i._id };
|
|
this.model.create(nobj);
|
|
this.model.create(nobj);
|
|
}
|
|
}
|