lrf402788946 4 年之前
父节点
当前提交
6755faf8c5
共有 3 个文件被更改,包括 78 次插入55 次删除
  1. 63 55
      app/controller/.class.js
  2. 2 0
      app/router.js
  3. 13 0
      app/service/class.js

+ 63 - 55
app/controller/.class.js

@@ -1,76 +1,84 @@
 module.exports = {
   create: {
     requestBody: [
-      '!name',
-      'number',
-      'batchid',
-      'termid',
-      'planid',
-      'planyearid',
-      'headteacherid',
-      'lyteacherid',
-      'yclocationid',
-      'kzjhlocationid',
-      'kbyslocationid',
-      'jslocationid',
-      'lessonid',
-      'type'
-    ]
+      "!name",
+      "number",
+      "batchid",
+      "termid",
+      "planid",
+      "planyearid",
+      "headteacherid",
+      "lyteacherid",
+      "yclocationid",
+      "kzjhlocationid",
+      "kbyslocationid",
+      "jslocationid",
+      "lessonid",
+      "type",
+    ],
   },
   destroy: {
-    params: ['!id'],
-    service: 'delete'
+    params: ["!id"],
+    service: "delete",
   },
   update: {
-    params: ['!id'],
+    params: ["!id"],
     requestBody: [
-      'name',
-      'number',
-      'batchid',
-      'termid',
-      'planid',
-      'planyearid',
-      'headteacherid',
-      'lyteacherid',
-      'yclocationid',
-      'kzjhlocationid',
-      'kbyslocationid',
-      'jslocationid',
-      'lessonid',
-      'type'
-    ]
+      "name",
+      "number",
+      "batchid",
+      "termid",
+      "planid",
+      "planyearid",
+      "headteacherid",
+      "lyteacherid",
+      "yclocationid",
+      "kzjhlocationid",
+      "kbyslocationid",
+      "jslocationid",
+      "lessonid",
+      "type",
+    ],
   },
   show: {
     parameters: {
-      params: ['!id']
+      params: ["!id"],
     },
-    service: 'fetch'
+    service: "fetch",
   },
   index: {
     parameters: {
       query: {
-        name: 'name',
-        number  :'number',
-        batchid:'batchid',
-        termid: 'termid',
-        planid: 'planid',
-        planyearid:'planyearid',
-        headteacherid : 'headteacherid',
-        lyteacherid : 'lyteacherid',
-        yclocationid:'yclocationid',
-        kzjhlocationid :'kzjhlocationid',
-        kbyslocationid :'kbyslocationid',
-        jslocationid: 'jslocationid',
-        lessonid :'lessonid',
-        type: 'type'
-      }
+        name: "name",
+        number: "number",
+        batchid: "batchid",
+        termid: "termid",
+        planid: "planid",
+        planyearid: "planyearid",
+        headteacherid: "headteacherid",
+        lyteacherid: "lyteacherid",
+        yclocationid: "yclocationid",
+        kzjhlocationid: "kzjhlocationid",
+        kbyslocationid: "kbyslocationid",
+        jslocationid: "jslocationid",
+        lessonid: "lessonid",
+        type: "type",
+      },
     },
-    service: 'query',
+    service: "query",
     options: {
-      query: ['skip', 'limit'],
-      sort: ['meta.createdAt'],
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
       desc: true,
-      count: true
-    }
+      count: true,
+    },
+  },
+  toSetClassSetting: {
+    parameters: {
+      query:{
+        classid:"classid"
+      }
+    },
+    service: "toSetClassSetting",
   },
 };

+ 2 - 0
app/router.js

@@ -173,6 +173,8 @@ module.exports = app => {
     controller.bedroom.ibeacon
   );
 
+  // 模板设置班级
+  router.get('class', '/api/train/class/settemplate', controller.class.toSetClassSetting);
   // 班级表设置路由
   router.get(
     'class',

+ 13 - 0
app/service/class.js

@@ -385,6 +385,17 @@ class ClassService extends CrudService {
     if (!tClass) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '班级不存在,无法复制设定的班级设置');
     const { name, termid, batchid } = tClass;
     const r = templateList.find(f => f.name === name);
+    // 找到班主任全年计划
+    const trainPlan = await this.tmodel.findById(tClass.planid);
+    if (!trainPlan) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该班所在的年度计划信息');
+    const tpt = trainPlan.termnum.id(tClass.termid);
+    if (!tpt) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该班所在年度计划的期信息');
+    const tpb = tpt.batchnum.id(tClass.batchid);
+    if (!tpb) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该班所在年度计划的批次信息');
+    if (!tpb.class) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该班所在年度计划批次下的班级');
+    const tpc = tpb.class.find(f => f.name === tClass.name);
+    if (!tpc) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该班所在年度计划的班级信息');
+    const { headteacherid } = tpc;
     if (r) {
       // 说明这个是正常班,且从模板中找得到; 除了礼仪教师外,都复制过来
       const { jslocationid, kbyslocationid, kzjhlocationid, yclocationid } = r;
@@ -392,6 +403,7 @@ class ClassService extends CrudService {
       if (!tClass.kbyslocationid && kbyslocationid) tClass.kbyslocationid = kbyslocationid;
       if (!tClass.kzjhlocationid && kzjhlocationid) tClass.kzjhlocationid = kzjhlocationid;
       if (!tClass.yclocationid && yclocationid) tClass.yclocationid = yclocationid;
+      if (!tClass.headteacherid && headteacherid) tClass.headteacherid = headteacherid;
       await tClass.save();
     } else {
       // 没找到,有可能是普通班,也有可能是非普通班
@@ -410,6 +422,7 @@ class ClassService extends CrudService {
         if (!tClass.kbyslocationid && kbyslocationid) tClass.kbyslocationid = kbyslocationid;
         if (!tClass.kzjhlocationid && kzjhlocationid) tClass.kzjhlocationid = kzjhlocationid;
         if (!tClass.yclocationid && yclocationid) tClass.yclocationid = yclocationid;
+        if (!tClass.headteacherid && headteacherid) tClass.headteacherid = headteacherid;
         await tClass.save();
       }
     }