ruifeng_liu 3 anni fa
parent
commit
e96d07789f

+ 2 - 1
app/controller/patent/.patentearly.js

@@ -22,8 +22,9 @@ module.exports = {
         parent_id: "parent_id",
         name: "%name%",
         inventor: "%inventor%",
-        lose_date:'lose_date',
+        lose_date: "lose_date",
         user_id: "user_id",
+        code: "code",
       },
       // options: {
       //   "meta.state": 0 // 默认条件

+ 1 - 0
app/schedule/patentearly.js

@@ -2,6 +2,7 @@
 module.exports = {
   schedule: {
     interval: '30s', // 1 分钟间隔
+    // cron: '0 0 * * * *',
     type: 'all', // 指定所有的 worker 都需要执行
   },
   async task(ctx) {

+ 42 - 1
app/service/patent/patentearly.js

@@ -5,6 +5,7 @@ const { ObjectId } = require('mongoose').Types;
 const _ = require('lodash');
 const assert = require('assert');
 const moment = require('moment');
+const { trimData } = require('naf-core').Util;
 // 专利运营已授权专利预警表
 class PatentearlyService extends CrudService {
   constructor(ctx) {
@@ -12,7 +13,47 @@ class PatentearlyService extends CrudService {
     this.model = this.ctx.model.Patent.Patentearly;
     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) {
         total++;
         const { inventor, name } = i;
-        const content = `发明人 ${inventor} 的已授权专利 ${name} 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
+        const content = `发明人 ${inventor} 的已授权专利 ${name} 即将失效,避免专利失效过期,请用户及时查看消息并处理! `;
         const nobj = { ..._.omit(i, [ '_id', 'id' ]), content, parent_id: i._id };
         this.model.create(nobj);
       }