ruifeng_liu 3 jaren geleden
bovenliggende
commit
5a63cc2ebe
1 gewijzigde bestanden met toevoegingen van 4 en 10 verwijderingen
  1. 4 10
      app/service/patent/patentnotice.js

+ 4 - 10
app/service/patent/patentnotice.js

@@ -43,7 +43,7 @@ class PatentnoticeService extends CrudService {
    * @param {Object} body 数据
    */
   async create(body) {
-    const arr = []; // 最后insert的数据集
+    let object = {}; // 最后insert的数据集
     const { send_id, to_type, content, send_name } = body;
     const admin = await this.adminModel.findById(send_id);
     if (!admin) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到管理员信息');
@@ -51,10 +51,7 @@ class PatentnoticeService extends CrudService {
     if (org.length <= 0) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到相关机构信息');
     if (to_type === '1') {
       const ids = org.map(i => i._id);
-      for (const id of ids) {
-        const obj = { send_id, send_name, to_type, to_id: id, content };
-        arr.push(obj);
-      }
+      object = { send_id, send_name, to_type, to_id: ids, content };
     } else {
       const p1 = await this.personalModel.find({ code: admin.code }, { id: 1 });
       const p2 = await this.personalModel.find({ code: org.map(i => i.code) }, { id: 1 });
@@ -62,12 +59,9 @@ class PatentnoticeService extends CrudService {
       if (to_type === 0) {
         ids = [ ...ids, ...org.map(i => i._id) ];
       }
-      for (const id of ids) {
-        const obj = { send_id, send_name, to_type, to_id: id, content };
-        arr.push(obj);
-      }
+      object = { send_id, send_name, to_type, to_id: ids, content };
     }
-    return await this.model.insertMany(arr);
+    return await this.model.create(object);
   }
 }