Browse Source

分组表调整字段

reloaded 5 năm trước cách đây
mục cha
commit
c15f0235a8
4 tập tin đã thay đổi với 27 bổ sung10 xóa
  1. 3 3
      app/controller/.group.js
  2. 7 1
      app/model/group.js
  3. 2 0
      app/service/bedroom.js
  4. 15 6
      app/service/group.js

+ 3 - 3
app/controller/.group.js

@@ -5,7 +5,7 @@ module.exports = {
       'termid',
       'batchid',
       'classid',
-      'studentid',
+      'students',
       'score'
     ]
   },
@@ -20,7 +20,7 @@ module.exports = {
       'termid',
       'batchid',
       'classid',
-      'studentid',
+      'students',
       'score'
     ]
   },
@@ -37,7 +37,7 @@ module.exports = {
         termid :'termid',
         batchid:'batchid',
         classid :'classid',
-        studentid :'studentid',
+        students :'students',
         score :'score'
       }
     },

+ 7 - 1
app/model/group.js

@@ -2,13 +2,19 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
+// 学生信息表
+const stuInfo = new Schema({
+  stuid: { type: String, required: false, maxLength: 500 }, // 学生id
+  stuname: { type: String, required: false, maxLength: 500 }, // 学生姓名
+});
+
 // 分组表
 const GroupSchema = {
   name: { type: String, required: true, maxLength: 500 }, // 名称
   termid: { type: String, required: false, maxLength: 500 }, // 期id
   batchid: { type: String, required: false, maxLength: 500 }, // 批次id
   classid: { type: String, required: false, maxLength: 500 }, // 班级id
-  studentid: [ String ], // 学生id
+  students: { type: [ stuInfo ], select: true }, // 学生信息
   score: { type: String, required: false, maxLength: 500 }, // 分数
 };
 

+ 2 - 0
app/service/bedroom.js

@@ -83,8 +83,10 @@ class BedroomService extends CrudService {
         }
       }
     }
+    // 取得当前批次的所有班级
     const classes = await this.cmodel.find({ batchid });
     for (const _class of classes) {
+      // 取得每个班级的班主任id
       const headteacherid = _class.headteacherid;
       const headteacher = await this.umodel.findOne({ uid: headteacherid, type: '1' });
       const openid = headteacher.openid;

+ 15 - 6
app/service/group.js

@@ -14,23 +14,32 @@ class GroupService extends CrudService {
   }
 
   async insert(data) {
-    const { groupid, studentid } = data;
+    const { groupid, stuid, stuname } = data;
     const group = await this.model.findById(groupid);
-    if (group.studentid.includes(studentid)) {
+    const stuids = [];
+    for (const student of group.students) {
+      stuids.push(student.stuid);
+    }
+    if (stuids.includes(stuid)) {
       throw new BusinessError(ErrorCode.DATA_EXIST, '您已加入该组,请勿重复操作');
     } else {
-      group.studentid.push(studentid);
+      group.students.push({ stuid, stuname });
       await group.save();
     }
   }
 
   async exit(data) {
-    const { groupid, studentid } = data;
+    const { groupid, stuid } = data;
     const group = await this.model.findById(groupid);
-    group.studentid.remove(studentid);
+    const students = group.students;
+    for (const student of students) {
+      if (student.stuid === stuid) {
+        students.remove(student);
+      }
+    }
     await group.save();
   }
-
 }
 
+
 module.exports = GroupService;