Browse Source

Merge branch 'master' of http://git.cc-lotus.info/new_train/service-center

reloaded 4 years ago
parent
commit
6c07eb0758
4 changed files with 40 additions and 5 deletions
  1. 14 0
      app/controller/common.js
  2. 4 1
      app/controller/weixin.js
  3. 1 0
      app/router.js
  4. 21 4
      app/service/trainplan.js

+ 14 - 0
app/controller/common.js

@@ -17,6 +17,20 @@ class CommonController extends Controller {
     this.ctx.ok({ data });
     this.ctx.ok({ data });
   }
   }
 
 
+  async findyear() {
+    const url = 'http://v.juhe.cn/calendar/year?key=ed73fa73956ff995bad705d664002595&year=' + this.ctx.query.year;
+    const res = await this.ctx.curl(url, {
+      method: 'get',
+      headers: {
+        'content-type': 'application/json',
+      },
+      dataType: 'json',
+    });
+    const result = res.data.result.data;
+    const data = JSON.parse(JSON.stringify(result));
+    this.ctx.ok({ data });
+  }
+
 }
 }
 
 
 module.exports = CommonController;
 module.exports = CommonController;

+ 4 - 1
app/controller/weixin.js

@@ -83,7 +83,10 @@ class WeixinController extends Controller {
         if (user) {
         if (user) {
           const token = await this.ctx.service.login.createJwt(user);
           const token = await this.ctx.service.login.createJwt(user);
           if (user.type === '4') {
           if (user.type === '4') {
-            const to_uri = urljoin(redirect_uri, `?token=${token}`);
+            const student = await this.ctx.service.student.fetch(user.uid);
+            const newdata = { planid: student.planid, ...JSON.parse(JSON.stringify(user)) };
+            const token_ = await this.ctx.service.login.createJwt(newdata);
+            const to_uri = urljoin(redirect_uri, `?token=${token_}`);
             // TODO: 重定性页面
             // TODO: 重定性页面
             console.log('to_uri000-->' + to_uri);
             console.log('to_uri000-->' + to_uri);
             this.ctx.redirect(to_uri);
             this.ctx.redirect(to_uri);

+ 1 - 0
app/router.js

@@ -8,6 +8,7 @@ module.exports = app => {
   router.get('/', controller.home.index);
   router.get('/', controller.home.index);
   // 共通查询单条记录方法
   // 共通查询单条记录方法
   router.get('/api/train/common/findone/:modelname', controller.common.findone);
   router.get('/api/train/common/findone/:modelname', controller.common.findone);
+  router.get('/api/train/common/findyear', controller.common.findyear);
   // 基础设置表路由
   // 基础设置表路由
   router.get('/api/train/setting/findone', controller.setting.findone);
   router.get('/api/train/setting/findone', controller.setting.findone);
   router.resources('setting', '/api/train/setting', controller.setting); // index、create、show、destroy
   router.resources('setting', '/api/train/setting', controller.setting); // index、create、show、destroy

+ 21 - 4
app/service/trainplan.js

@@ -67,6 +67,8 @@ class TrainplanService extends CrudService {
       if (status === '1') {
       if (status === '1') {
         // 自动生成班级
         // 自动生成班级
         await this.autoclass(res, trainplanold);
         await this.autoclass(res, trainplanold);
+        // 将生成的班级重新将班级排班名
+        await this.autoclassname(res);
         // 发送培训计划信息通知给相应人员
         // 发送培训计划信息通知给相应人员
         // 查询所有入库的教师
         // 查询所有入库的教师
         const teachers = await this.tmodel.find({ status: '4' });
         const teachers = await this.tmodel.find({ status: '4' });
@@ -123,7 +125,7 @@ class TrainplanService extends CrudService {
           // 取得当前批次的班级数
           // 取得当前批次的班级数
           const classnum = batchnum.class;
           const classnum = batchnum.class;
           for (let i = 1; i <= classnum; i++) {
           for (let i = 1; i <= classnum; i++) {
-            const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+            const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
             await this.clamodel.create(newdata);
             await this.clamodel.create(newdata);
           }
           }
         }
         }
@@ -149,7 +151,7 @@ class TrainplanService extends CrudService {
             // 取得当前批次的班级数
             // 取得当前批次的班级数
             const classnum = batchnum.class;
             const classnum = batchnum.class;
             for (let i = 1; i <= classnum; i++) {
             for (let i = 1; i <= classnum; i++) {
-              const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+              const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
               await this.clamodel.create(newdata);
               await this.clamodel.create(newdata);
             }
             }
           } else {
           } else {
@@ -164,7 +166,7 @@ class TrainplanService extends CrudService {
               } else {
               } else {
                 const classnum = batchnum.class;
                 const classnum = batchnum.class;
                 for (let i = 1; i <= classnum; i++) {
                 for (let i = 1; i <= classnum; i++) {
-                  const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+                  const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
                   await this.clamodel.create(newdata);
                   await this.clamodel.create(newdata);
                 }
                 }
               }
               }
@@ -174,7 +176,7 @@ class TrainplanService extends CrudService {
               await this.clamodel.deleteMany({ termid: el.id, batchid: batchnum.id });
               await this.clamodel.deleteMany({ termid: el.id, batchid: batchnum.id });
               const classnum = batchnum.class;
               const classnum = batchnum.class;
               for (let i = 1; i <= classnum; i++) {
               for (let i = 1; i <= classnum; i++) {
-                const newdata = { name: i + '班', number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
+                const newdata = { name: i, number: batchnum.number, batchid: batchnum.id, termid: el.id, planid: res.id };
                 await this.clamodel.create(newdata);
                 await this.clamodel.create(newdata);
               }
               }
             }
             }
@@ -185,5 +187,20 @@ class TrainplanService extends CrudService {
 
 
   }
   }
 
 
+  // 将分好的班级重新编排名字
+  async autoclassname(res) {
+    // 取得所有期id
+    const tremid_res = _.map(res.termnum, 'id');
+    for (const termid of tremid_res) {
+      const classs = await this.clamodel.find({ planid: res.id, termid });
+      let i = 0;
+      for (const cla of classs) {
+        i = i + 1;
+        cla.name = i;
+        await cla.save();
+      }
+    }
+  }
+
 }
 }
 module.exports = TrainplanService;
 module.exports = TrainplanService;