lrf402788946 %!s(int64=4) %!d(string=hai) anos
pai
achega
904d6db30d
Modificáronse 3 ficheiros con 83 adicións e 41 borrados
  1. 37 33
      app/controller/.bedroom.js
  2. 4 0
      app/router.js
  3. 42 8
      app/service/bedroom.js

+ 37 - 33
app/controller/.bedroom.js

@@ -1,54 +1,58 @@
 module.exports = {
   create: {
     requestBody: [
-      'code',
-      'number',
-      'batch',
-      'gender',
-      'floor',
-      'ibeacon',
-      'status'
-    ]
+      "code",
+      "number",
+      "batch",
+      "gender",
+      "floor",
+      "ibeacon",
+      "status",
+    ],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete'
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
+    params: ["!id"],
     requestBody: [
-      'code',
-      'number',
-      'batch',
-      'gender',
-      'floor',
-      'ibeacon',
-      'status'
-    ]
+      "code",
+      "number",
+      "batch",
+      "gender",
+      "floor",
+      "ibeacon",
+      "status",
+    ],
   },
   show: {
     parameters: {
-      params: ['!id']
+      params: ["!id"],
     },
-    service: 'fetch'
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        code: 'code',
-        number  :'number',
-        batch :'batch',
-        gender:'gender',
-        floor :'floor',
-        status : 'status'
-      }
+        code: "code",
+        number: "number",
+        batch: "batch",
+        gender: "gender",
+        floor: "floor",
+        status: "status",
+      },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
       desc: true,
-      count: true
-    }
+      count: true,
+    },
+  },
+  updateStudent: {
+    requestBody: ["code", "ids", "bedroomid"],
+    service: "updateStudent",
   },
 };

+ 4 - 0
app/router.js

@@ -109,6 +109,7 @@ module.exports = app => {
     '/api/train/student/findbedroom',
     controller.student.findbedroom
   );
+
   router.get('sutdent', '/api/train/student/seek', controller.student.seek);
   router.resources('student', '/api/train/student', controller.student); // index、create、show、destroy
   router.post(
@@ -138,6 +139,7 @@ module.exports = app => {
     controller.student.updatabedroom
   ); // 批量学生寝室号
 
+
   // 班主任表设置路由
   router.resources(
     'headteacher',
@@ -150,6 +152,8 @@ module.exports = app => {
     controller.headteacher.update
   );
 
+  // 批量修改寝室(新)
+  router.post('bedroom', '/api/train/bedroom/batch', controller.bedroom.updateStudent);
   // 寝室表设置路由
   router.get('/api/train/bedroom/student/:id', controller.bedroom.roomstu); // 根据班级id查询寝室信息
   router.resources('bedroom', '/api/train/bedroom', controller.bedroom); // index、create、show、destroy

+ 42 - 8
app/service/bedroom.js

@@ -17,7 +17,6 @@ class BedroomService extends CrudService {
     this.umodel = this.ctx.model.User;
     this.ctmodel = this.ctx.model.Classtype;
     this.nmodel = this.ctx.model.Notice;
-
   }
 
   // 根据班级id查找班级下所有寝室列表并查询出寝室下学生信息
@@ -69,7 +68,9 @@ class BedroomService extends CrudService {
     // 根据批次id查询批次信息
     const _batch = term.batchnum.find(p => p.id === batchid);
     // 查询所有寝室列表
-    const bedroomList = await this.model.find({ batch: _batch.batch, status: '0' }).sort({ floor: -1 });
+    const bedroomList = await this.model
+      .find({ batch: _batch.batch, status: '0' })
+      .sort({ floor: -1 });
     // 循环所有当前批次下的寝室列表进行分寝处理
     const studentList = await this.getstudents(termid, batchid);
     console.log('stulen-->' + studentList.length);
@@ -124,21 +125,41 @@ class BedroomService extends CrudService {
     // 取得当前批次的所有班级
     const classes = await this.cmodel.find({ batchid });
     const detail = '班级学生名单与寝室安排已确认,请及时查收';
-    const nres = await this.nmodel.create({ planyearid: trainplan.planyearid, planid: trainplanid, termid, noticeid: 'system', content: detail, type: '5' });
+    const nres = await this.nmodel.create({
+      planyearid: trainplan.planyearid,
+      planid: trainplanid,
+      termid,
+      noticeid: 'system',
+      content: detail,
+      type: '5',
+    });
 
     for (const _class of classes) {
       // 取得每个班级的班主任id
       const headteacherid = _class.headteacherid;
-      const headteacher = await this.umodel.findOne({ uid: headteacherid, type: '1' });
+      const headteacher = await this.umodel.findOne({
+        uid: headteacherid,
+        type: '1',
+      });
       if (headteacher && headteacher.openid) {
         const openid = headteacher.openid;
         const remark = '感谢您的使用';
         const date = await this.ctx.service.util.updatedate();
-        this.ctx.service.weixin.sendTemplateMsg(this.ctx.app.config.REVIEW_TEMPLATE_ID, openid, '您有一个新的通知', detail, date, remark, _class.id);
-        nres.notified.push({ notifiedid: headteacher.uid, username: headteacher.name });
+        this.ctx.service.weixin.sendTemplateMsg(
+          this.ctx.app.config.REVIEW_TEMPLATE_ID,
+          openid,
+          '您有一个新的通知',
+          detail,
+          date,
+          remark,
+          _class.id
+        );
+        nres.notified.push({
+          notifiedid: headteacher.uid,
+          username: headteacher.name,
+        });
       }
       await nres.save();
-
     }
   }
 
@@ -150,7 +171,9 @@ class BedroomService extends CrudService {
     console.log('-----types-start--');
     console.log(types);
     console.log('-----types-end--');
-    const studentList = await this.smodel.find({ termid, batchid, type: { $in: types } }).sort({ gender: -1 });
+    const studentList = await this.smodel
+      .find({ termid, batchid, type: { $in: types } })
+      .sort({ gender: -1 });
     return studentList;
   }
 
@@ -160,6 +183,17 @@ class BedroomService extends CrudService {
     const studentList = await this.smodel.find({ termid, batchid, bedroom });
     return studentList;
   }
+
+  // 批量修改学生寝室(新)
+  async updateStudent(data, body) {
+    const { code, ids, bedroomid } = body;
+    for (const id of ids) {
+      const r = await this.ctx.model.Student.findById(id);
+      r.bedroom = code;
+      r.bedroomid = bedroomid;
+      await r.save();
+    }
+  }
 }
 
 module.exports = BedroomService;