liuyu 4 gadi atpakaļ
vecāks
revīzija
6ebc2a8a36
3 mainītis faili ar 35 papildinājumiem un 4 dzēšanām
  1. 6 3
      app/controller/.location.js
  2. 1 0
      app/model/location.js
  3. 28 1
      app/service/class.js

+ 6 - 3
app/controller/.location.js

@@ -2,7 +2,8 @@ module.exports = {
   create: {
     requestBody: [
       '!name',
-      'ibeacon'
+      'ibeacon',
+      'type',
     ]
   },
   destroy: {
@@ -13,7 +14,8 @@ module.exports = {
     params: ['!id'],
     requestBody: [
       'name',
-      'ibeacon'
+      'ibeacon',
+      'type',
     ]
   },
   show: {
@@ -25,7 +27,8 @@ module.exports = {
   index: {
     parameters: {
       query: {
-        name: 'name'
+        name: 'name',
+        type: 'type',
       }
     },
     service: 'query',

+ 1 - 0
app/model/location.js

@@ -5,6 +5,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 位置表
 const LocationSchema = {
   name: { type: String, required: true, maxLength: 500 }, // 名称
+  type: { type: String, required: true, maxLength: 10 }, // 0、教室位置 1、开班仪式地点 2、拓展计划地点 3、用餐地点
   ibeacon: { type: String, required: true, maxLength: 500 }, // 蓝牙设备号
 };
 

+ 28 - 1
app/service/class.js

@@ -100,10 +100,37 @@ class ClassService extends CrudService {
     }
     // 循环出所有班级进行添加操作
     const term = await res.termnum.id(termid);
+    let yclocationid = ''; // 用餐地点
+    let kzjhlocationid = ''; // 拓展计划地点
+    let kbyslocationid = ''; // 开班仪式地点
+    let jslocationid = ''; // 教室位置
+    const locations = await this.locamodel.find();
+    const jslocationids = _.filter(locations, { type: '0' });
+    const kbyslocationids = _.filter(locations, { type: '1' });
+    const kzjhlocationids = _.filter(locations, { type: '2' });
+    const yclocationids = _.filter(locations, { type: '3' });
     for (const batch of term.batchnum) {
       const classs = await batch.class;
       for (const cla of classs) {
-        const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid };
+        // 取得班级各个地点
+        // 同一地点同期只能使用一次
+        if (jslocationids.length > 0) {
+          jslocationid = jslocationids[0].id;
+          _.remove(jslocationids, { id: jslocationid });
+        }
+        if (kbyslocationids.length > 0) {
+          kbyslocationid = kbyslocationids[0].id;
+          _.remove(kbyslocationids, { id: kbyslocationid });
+        }
+        if (kzjhlocationids.length > 0) {
+          kzjhlocationid = kzjhlocationids[0].id;
+          _.remove(kzjhlocationids, { id: kzjhlocationid });
+        }
+        if (yclocationids.length > 0) {
+          yclocationid = yclocationids[0].id;
+          _.remove(yclocationids, { id: yclocationid });
+        }
+        const newdata = { name: cla.name, number: cla.number, batchid: batch.id, termid: term.id, planid: res.id, type: cla.type, headteacherid: cla.headteacherid, jslocationid, kbyslocationid, kzjhlocationid, yclocationid };
         await this.model.create(newdata);
       }
     }