lrf402788946 há 4 anos atrás
pai
commit
e9c1782c9c
1 ficheiros alterados com 13 adições e 10 exclusões
  1. 13 10
      app/service/school.js

+ 13 - 10
app/service/school.js

@@ -112,16 +112,19 @@ class SchoolService extends CrudService {
       throw new BusinessError(ErrorCode.SERVICE_FAULT, reason);
     } else {
       // 复制,删除,添加
-      dbStuList = JSON.parse(JSON.stringify(dbStuList));
-      dbStuList = dbStuList.map(i => {
-        delete i.meta;
-        i.studentid = _.clone(i._id);
-        delete i.id;
-        delete i._id;
-        return i;
-      });
-      await this.ctx.model.Dstudent.insertMany(dbStuList);
-      await this.smodel.deleteMany({ termid, batchid, schid });
+      if (dbStuList.length > 0) {
+        dbStuList = JSON.parse(JSON.stringify(dbStuList));
+        dbStuList = dbStuList.map(i => {
+          delete i.meta;
+          i.studentid = _.clone(i._id);
+          delete i.id;
+          delete i._id;
+          return i;
+        });
+        await this.ctx.model.Dstudent.insertMany(dbStuList);
+        await this.smodel.deleteMany({ termid, batchid, schid });
+      }
+
       await this.smodel.insertMany(studentList);
     }
   }