浏览代码

修改警告

ruifeng_liu 3 年之前
父节点
当前提交
3656a84aee
共有 3 个文件被更改,包括 22 次插入8 次删除
  1. 5 0
      app/controller/patent/patentearly.js
  2. 2 0
      app/router/patent/patentearly.js
  3. 15 8
      app/service/patent/patentearly.js

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

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

+ 2 - 0
app/router/patent/patentearly.js

@@ -7,6 +7,8 @@ module.exports = app => {
   const vision = 'v0';
   const index = 'patent';
   const target = 'patentearly';
+  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}`, controller[index][target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
 };

+ 15 - 8
app/service/patent/patentearly.js

@@ -31,14 +31,6 @@ class PatentearlyService extends CrudService {
   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) {
@@ -54,6 +46,21 @@ class PatentearlyService extends CrudService {
 
     return newquery;
   }
+
+  async queryByOrg({ code, skip = 0, limit = 0 }) {
+    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);
+    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 total = await this.model.count(query);
+    return { data, total };
+  }
   /**
    * 产生警告
    */