瀏覽代碼

批量修改

reloaded 4 年之前
父節點
當前提交
8a444bbf52
共有 5 個文件被更改,包括 55 次插入14 次删除
  1. 5 0
      app/controller/class.js
  2. 4 1
      app/controller/lesson.js
  3. 2 0
      app/router.js
  4. 6 0
      app/service/class.js
  5. 38 13
      app/service/lesson.js

+ 5 - 0
app/controller/class.js

@@ -35,6 +35,11 @@ class ClassController extends Controller {
     );
     this.ctx.ok({ data: res });
   }
+
+  async upclasses() {
+    const res = await this.service.upclasses(this.ctx.request.body);
+    this.ctx.ok({ msg: 'ok', data: res });
+  }
 }
 
 module.exports = CrudController(ClassController, meta);

+ 4 - 1
app/controller/lesson.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 课程表管理
 class LessonController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.lesson;
@@ -25,6 +24,10 @@ class LessonController extends Controller {
     this.ctx.ok({ data });
   }
 
+  async uplessones() {
+    const res = await this.service.uplessones(this.ctx.request.body);
+    this.ctx.ok({ msg: 'ok', data: res });
+  }
 }
 
 module.exports = CrudController(LessonController, meta);

+ 2 - 0
app/router.js

@@ -59,6 +59,7 @@ module.exports = app => {
   router.post('bedroom', '/api/train/bedroom/ibeacon', controller.bedroom.ibeacon);
 
   // 班级表设置路由
+  router.post('class', '/api/train/class/upclasses', controller.class.upclasses);
   router.post('class', '/api/train/class/notice', controller.class.notice);
   router.resources('class', '/api/train/class', controller.class); // index、create、show、destroy
   router.post('class', '/api/train/class/update/:id', controller.class.update);
@@ -87,6 +88,7 @@ module.exports = app => {
   router.post('festival', '/api/train/festival/update/:id', controller.festival.update);
 
   // 课程表设置路由
+  router.post('lesson', '/api/train/lesson/uplessones', controller.lesson.uplessones);
   router.get('/api/train/lesson/classbyteaid', controller.lesson.classbyteaid); // 根据计划id与教师id查询班级信息
   router.resources('lesson', '/api/train/lesson', controller.lesson); // index、create、show、destroy
   router.post('lesson', '/api/train/lesson/update/:id', controller.lesson.update);

+ 6 - 0
app/service/class.js

@@ -166,6 +166,12 @@ class ClassService extends CrudService {
     }
     return classInfo;
   }
+
+  async upclasses(data) {
+    for (const _data of data) {
+      await this.model.findByIdAndUpdate(_data.id, _data);
+    }
+  }
 }
 
 module.exports = ClassService;

+ 38 - 13
app/service/lesson.js

@@ -42,7 +42,11 @@ class LessonService extends CrudService {
         // 取得当前批次开始结束日期,并根据日期取得所有天数
         const sedays = await this.getAllDays(batch.startdate, batch.enddate);
         // 根据批次取得当前批次下所有班级
-        const _classs = await this.clamodel.find({ planid: id, termid: elm.id, batchid: batch.id });
+        const _classs = await this.clamodel.find({
+          planid: id,
+          termid: elm.id,
+          batchid: batch.id,
+        });
         // 循环班级
         for (const cla of _classs) {
           // 记录天数
@@ -64,18 +68,27 @@ class LessonService extends CrudService {
                 if (i === 6) {
                   allday = _lessonmode.allday;
                 }
-                const data = { subid: _subid, subname: lessm['day' + i], date: day, time: lessm.time, day: allday };
+                const data = {
+                  subid: _subid,
+                  subname: lessm['day' + i],
+                  date: day,
+                  time: lessm.time,
+                  day: allday,
+                };
                 newlesson.push(data);
               }
             }
             i = i + 1;
           }
-          const newdata = { termid: elm.id, batchid: batch.id, classid: cla.id, lessons: newlesson };
+          const newdata = {
+            termid: elm.id,
+            batchid: batch.id,
+            classid: cla.id,
+            lessons: newlesson,
+          };
           // 将课程信息填入课程表
           await this.model.create(newdata);
         }
-
-
       }
     }
   }
@@ -86,11 +99,19 @@ class LessonService extends CrudService {
       resultArr = [],
       dateReg = /^[2]\d{3}-[01]\d-[0123]\d$/;
 
-    if (typeof begin_date !== 'string' || begin_date === '' || !dateReg.test(begin_date)) {
+    if (
+      typeof begin_date !== 'string' ||
+      begin_date === '' ||
+      !dateReg.test(begin_date)
+    ) {
       return errArr;
     }
 
-    if (typeof end_date !== 'string' || end_date === '' || !dateReg.test(end_date)) {
+    if (
+      typeof end_date !== 'string' ||
+      end_date === '' ||
+      !dateReg.test(end_date)
+    ) {
       return errArr;
     }
 
@@ -112,15 +133,12 @@ class LessonService extends CrudService {
       let tempTimestamp = beginTimestamp,
         tempDate = begin_date;
 
-
       // 新增日期是否和结束日期相等, 相等跳出循环
       while (tempTimestamp !== endTimestamp) {
         resultArr.push(tempDate);
 
         // 增加一天
-        tempDate = moment(tempTimestamp)
-          .add(1, 'd')
-          .format('YYYY-MM-DD');
+        tempDate = moment(tempTimestamp).add(1, 'd').format('YYYY-MM-DD');
 
         // 将增加时间变为时间戳
         tempTimestamp = Date.parse(new Date(tempDate));
@@ -129,7 +147,6 @@ class LessonService extends CrudService {
       // 将最后一天放入数组
       resultArr.push(end_date);
       return resultArr;
-
     } catch (err) {
       return errArr;
     }
@@ -148,7 +165,10 @@ class LessonService extends CrudService {
     const data = [];
     for (const term of terms) {
       // 根据期id与教师id查出课程班级信息
-      const lessons = await this.model.find({ termid: term.id, 'lessons.teaid': teaid });
+      const lessons = await this.model.find({
+        termid: term.id,
+        'lessons.teaid': teaid,
+      });
       const batchs = await term.batchnum;
       for (const elm of lessons) {
         const newdata = {};
@@ -174,6 +194,11 @@ class LessonService extends CrudService {
     return data;
   }
 
+  async uplessones(data) {
+    for (const _data of data) {
+      await this.model.findByIdAndUpdate(_data.id, _data);
+    }
+  }
 }
 
 module.exports = LessonService;