lrf402788946 vor 4 Jahren
Ursprung
Commit
29fe98d519

+ 4 - 0
app/controller/patent/disclosure.js

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

+ 1 - 1
app/router/patent/disclosure.js

@@ -9,7 +9,7 @@ module.exports = app => {
   const target = 'disclosure';
   const mware = app.middleware.disclosureRecord();
   const mware2 = app.middleware.disclosureReport();
-
+  router.get(target, `${profix}${vision}/${index}/${target}/haveReport`, mware, controller[index][target].haveReport);
   router.resources(target, `${profix}${vision}/${index}/${target}`, mware, mware2, controller[index][target]); // index、create、show、destroy
   router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, mware, controller[index][target].update);
   router.post(target, `${profix}${vision}/${index}/${target}/check`, controller[index][target].check);

+ 41 - 2
app/service/patent/disclosure.js

@@ -13,6 +13,41 @@ class DisclosureService extends CrudService {
     this.model = this.ctx.model.Patent.Disclosure;
   }
 
+  /**
+   * 查询有评估报告的交底书
+   * @param {Object} param0 条件
+   */
+  async haveReport({ skip, limit, ...query }) {
+    const { user_id, admin_id, mechanism_id } = query;
+    if (user_id) query.user_id = ObjectId(user_id);
+    if (admin_id) query.admin_id = ObjectId(admin_id);
+    if (mechanism_id) query.mechanism_id = ObjectId(mechanism_id);
+    const condition = [
+      { $match: { ...query } },
+      {
+        $lookup: {
+          from: 'disclosure_report',
+          localField: '_id',
+          foreignField: 'disclosure_id',
+          as: 'report',
+        },
+      },
+      { $match: { 'report.0': { $exists: true } } },
+      { $sort: { 'meta.createdAt': -1 } },
+    ];
+    const ctotal = [
+      ...condition,
+      { $group: { _id: '', total: { $sum: 1 } } },
+    ];
+    const tres = await this.model.aggregate(ctotal);
+    const total = _.get(_.head(tres), 'total', 0);
+    if (skip && limit) {
+      condition.push({ $skip: parseInt(skip) });
+      condition.push({ $limit: parseInt(limit) });
+    }
+    const res = await this.model.aggregate(condition);
+    return { data: res, total };
+  }
 
   /**
    * 交底书审核
@@ -62,7 +97,12 @@ class DisclosureService extends CrudService {
         break;
     }
     const data = await this.model.findById(id);
-    if (!data) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '添加记录----未找到数据');
+    if (!data) {
+      throw new BusinessError(
+        ErrorCode.DATA_NOT_EXIST,
+        '添加记录----未找到数据'
+      );
+    }
     const obj = {
       time: moment().format('YYYY-MM-DD HH:mm:ss'),
       word,
@@ -70,7 +110,6 @@ class DisclosureService extends CrudService {
     };
     data.record.push(obj);
     return await data.save();
-
   }
 }