浏览代码

修改分组问题

liuyu 5 年之前
父节点
当前提交
fca7ed298d
共有 1 个文件被更改,包括 7 次插入4 次删除
  1. 7 4
      app/service/class.js

+ 7 - 4
app/service/class.js

@@ -61,10 +61,13 @@ class ClassService extends CrudService {
 
   // 自动分组
   async groupcreate(termid, batchid, classid) {
-    for (let i = 1; i < 8; i++) {
-      const name = i + '组';
-      const newdata = { name, termid, batchid, classid };
-      await this.gmodel.create(newdata);
+    const group = await this.gmodel.find({ termid, batchid, classid });
+    if (group.length === 0) {
+      for (let i = 1; i < 8; i++) {
+        const name = i + '组';
+        const newdata = { name, termid, batchid, classid };
+        await this.gmodel.create(newdata);
+      }
     }
   }