ruifeng_liu 3 년 전
부모
커밋
87755604b2
1개의 변경된 파일35개의 추가작업 그리고 0개의 파일을 삭제
  1. 35 0
      app/service/patent/patentinfo.js

+ 35 - 0
app/service/patent/patentinfo.js

@@ -28,6 +28,41 @@ class PatentinfoService extends CrudService {
     this.export_limit = 50;
     this.export_limit = 50;
   }
   }
 
 
+  async query(query, { skip = 0, limit = 0 }) {
+    query = await this.resetCode(query);
+    const res = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
+      .sort({ 'meta.createdAt': -1 });
+    return res;
+
+  }
+  async count(query) {
+    query = await this.resetCode(query);
+    const res = await this.model.countDocuments(trimData(query)).exec();
+    return res;
+  }
+
+  async resetCode(query) {
+    query = this.ctx.service.util.util.dealQuery(query);
+    const { type } = query;
+    if (type === 'else') {
+      query.$and = [{ type: { $ne: '发明' } }, { type: { $ne: '实用新型' } }];
+      delete query.type;
+    }
+    const { code } = query;
+    let ids = [];
+    if (code) {
+      const plist = await this.personalModel.find({ code });
+      ids = plist.map(i => i._id);
+      const olist = await this.organizationModel.find({ code });
+      ids = [ ...ids, ...olist.map(i => i._id) ];
+    }
+    if (ids.length > 0) {
+      query.user_id = { $elemMatch: { $in: ids } };
+      delete query.code;
+    }
+    return query;
+  }
+
   async toImport({ uri, origin, user_id }) {
   async toImport({ uri, origin, user_id }) {
     assert(uri, '未获取到文件地址');
     assert(uri, '未获取到文件地址');
     const file = await this.ctx.curl(`${this.domain}${uri}`);
     const file = await this.ctx.curl(`${this.domain}${uri}`);