|
@@ -13,14 +13,11 @@ class PatentearlyService extends CrudService {
|
|
|
this.model = this.ctx.model.Patent.Patentearly;
|
|
|
this.patentinfo = this.ctx.model.Patent.Patentinfo;
|
|
|
this.personalModel = this.ctx.model.Personal;
|
|
|
+ this.patentexamineModel = this.ctx.model.Patent.Patentexamine;
|
|
|
}
|
|
|
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 });
|
|
|
+ const res = await this.model.find(newquery).skip(parseInt(skip)).limit(parseInt(limit)).sort({ 'meta.createdAt': -1 });
|
|
|
return res;
|
|
|
}
|
|
|
async count(query) {
|
|
@@ -36,13 +33,13 @@ class PatentearlyService extends CrudService {
|
|
|
let ids = [];
|
|
|
if (code) {
|
|
|
const plist = await this.personalModel.find({ code });
|
|
|
- ids = plist.map(i => i._id);
|
|
|
+ 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) ] } };
|
|
|
+ newquery.user_id = { $elemMatch: { $in: [ObjectId(user_id)] } };
|
|
|
}
|
|
|
|
|
|
return newquery;
|
|
@@ -52,13 +49,9 @@ class PatentearlyService extends CrudService {
|
|
|
assert(code, '缺少机构信息');
|
|
|
let pids = await this.personalModel.find({ code }, { _id: 1 });
|
|
|
if (pids.length <= 0) return { data: [], total: 0 };
|
|
|
- pids = pids.map(i => i._id);
|
|
|
+ pids = pids.map((i) => i._id);
|
|
|
const query = { user_id: { $elemMatch: { $in: pids } } };
|
|
|
- const data = await this.model
|
|
|
- .find(query)
|
|
|
- .skip(parseInt(skip))
|
|
|
- .limit(parseInt(limit))
|
|
|
- .sort({ 'meta.createdAt': -1 });
|
|
|
+ const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit)).sort({ 'meta.createdAt': -1 });
|
|
|
const total = await this.model.count(query);
|
|
|
return { data, total };
|
|
|
}
|
|
@@ -80,17 +73,10 @@ class PatentearlyService extends CrudService {
|
|
|
|
|
|
async searchAndDeal(skip, limit) {
|
|
|
let total = 0;
|
|
|
- let data = await this.patentinfo
|
|
|
- .find(
|
|
|
- { term: '有效' },
|
|
|
- { name: 1, inventor: 1, lose_date: 1, user_id: 1 }
|
|
|
- )
|
|
|
- .skip(skip)
|
|
|
- .limit(limit);
|
|
|
+ let data = await this.patentinfo.find({ term: '有效' }, { name: 1, inventor: 1, lose_date: 1, user_id: 1 }).skip(skip).limit(limit);
|
|
|
if (data.length > 0) data = JSON.parse(JSON.stringify(data));
|
|
|
// 取出今天是不是在失效时间的前1个月范围内
|
|
|
for (const i of data) {
|
|
|
- i.user_id = i.user_id.map(i => ObjectId(i));
|
|
|
const { lose_date } = i;
|
|
|
const start = moment(lose_date).subtract(1, 'M');
|
|
|
const end = moment(lose_date).add(3, 'M');
|
|
@@ -98,9 +84,23 @@ class PatentearlyService extends CrudService {
|
|
|
if (r) {
|
|
|
total++;
|
|
|
const { inventor, name } = i;
|
|
|
- const content = `发明人 【${inventor}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
- const nobj = { ..._.omit(i, [ '_id', 'id' ]), content, parent_id: i._id };
|
|
|
+ // 2021-11-04 修改,因为inventor修改为发明人[Object],所以发明人需要处理成字符串
|
|
|
+ const inventorNameString = inventor.map((i) => i.name).join(';');
|
|
|
+ const content = `发明人 【${inventorNameString}】 的已授权专利 【${name}】 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
|
|
|
+ const nobj = { ..._.omit(i, ['_id', 'id']), content, parent_id: i._id };
|
|
|
this.model.create(nobj);
|
|
|
+ // 2021-11-04添加 向 patentexamine 表中添加数据
|
|
|
+ const patentexamineArray = [];
|
|
|
+ for (const i of inventor) {
|
|
|
+ const { user_id } = i;
|
|
|
+ const peContent = `【${name}】 专利即将过期,请用户及时到相应功能模块中处理专利信息!`;
|
|
|
+ const patentexamineObject = {
|
|
|
+ to: user_id,
|
|
|
+ content: peContent,
|
|
|
+ };
|
|
|
+ patentexamineArray.push(patentexamineObject);
|
|
|
+ }
|
|
|
+ this.patentexamineModel.insertMany(patentexamineArray);
|
|
|
}
|
|
|
}
|
|
|
return total;
|