ruifeng_liu 3 年之前
父节点
当前提交
688d1336af
共有 3 个文件被更改,包括 20 次插入2 次删除
  1. 5 0
      app/controller/patent/patentinfo.js
  2. 1 0
      app/router/patent/patentinfo.js
  3. 14 2
      app/service/patent/patentinfo.js

+ 5 - 0
app/controller/patent/patentinfo.js

@@ -9,5 +9,10 @@ class PatentinfoController extends Controller {
     super(ctx);
     this.service = this.ctx.service.patent.patentinfo;
   }
+
+  async queryByOrg() {
+    const data = await this.service.queryByOrg(this.ctx.query);
+    return data;
+  }
 }
 module.exports = CrudController(PatentinfoController, meta);

+ 1 - 0
app/router/patent/patentinfo.js

@@ -8,6 +8,7 @@ module.exports = app => {
   const index = 'patent';
   const target = 'patentinfo';
   const metaTime = app.middleware.createTime();
+  router.get(target, `${profix}${vision}/${index}/${target}/queryByOrg`, metaTime, controller[index][target].queryByOrg);
   router.resources(target, `${profix}${vision}/${index}/${target}`, metaTime, controller[index][target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
   router.post(target, `${profix}${vision}/${index}/${target}/toImport`, controller[index][target].toImport);

+ 14 - 2
app/service/patent/patentinfo.js

@@ -15,6 +15,8 @@ class PatentinfoService extends CrudService {
   constructor(ctx) {
     super(ctx, 'patentinfo');
     this.model = this.ctx.model.Patent.Patentinfo;
+    this.personalModel = this.ctx.model.Personal;
+
     this.root_path = _.get(this.ctx.app.config.export, 'root_path');
     if (process.env.NODE_ENV === 'development') this.root_path = 'E:\\exportFile\\';
     this.file_type = '';
@@ -53,8 +55,6 @@ class PatentinfoService extends CrudService {
     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 } };
@@ -63,6 +63,18 @@ class PatentinfoService extends CrudService {
     return query;
   }
 
+  async queryByOrg({ id, skip = 0, limit = 0 }) {
+    assert(id, '缺少机构信息');
+    let pids = await this.personalModel.find({ pid: id }, { _id: 1 });
+    if (pids.length <= 0) return { data: [], total: 0 };
+    pids = pids.map(i => i._id);
+    const query = { $elemMatch: { $in: pids } };
+    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 };
+  }
+
   async toImport({ uri, origin, user_id }) {
     assert(uri, '未获取到文件地址');
     const file = await this.ctx.curl(`${this.domain}${uri}`);