Ver Fonte

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

reloaded há 5 anos atrás
pai
commit
6ea6c56139
4 ficheiros alterados com 31 adições e 9 exclusões
  1. 6 0
      app/controller/attendance.js
  2. 1 0
      app/router.js
  3. 16 2
      app/service/login.js
  4. 8 7
      app/service/uploadquestion.js

+ 6 - 0
app/controller/attendance.js

@@ -13,6 +13,12 @@ class AttendanceController extends Controller {
     this.service = this.ctx.service.attendance;
   }
 
+  // 考勤专用页面
+  async wxauth() {
+    console.log(this.ctx.query);
+    const res = '{}';
+    this.ctx.ok({ res });
+  }
 
 }
 

+ 1 - 0
app/router.js

@@ -108,6 +108,7 @@ module.exports = app => {
   router.post('uploadquestion', '/api/train/uploadquestion/update/:id', controller.uploadquestion.update);
 
   // 考勤表设置路由
+  router.get('/api/train/attendance/wxauth', controller.attendance.wxauth); // 统计完成度
   router.resources('attendance', '/api/train/attendance', controller.attendance); // index、create、show、destroy
   router.post('attendance', '/api/train/attendance/update/:id', controller.attendance.update);
 

+ 16 - 2
app/service/login.js

@@ -40,12 +40,26 @@ class LoginService extends CrudService {
     const { secret, expiresIn = '1d', issuer = type } = this.config.jwt;
     const subject = mobile;
     let _userid = '';
+    let res = {};
     if (type === '0') {
       _userid = _id.toString();
-    } else {
+    } else if (type === '1') {
+      _userid = uid.toString();
+      res = await this.hModel.findById(_userid);
+    } else if (type === '2') {
+      _userid = uid.toString();
+      res = await this.schModel.findById(_userid);
+    } else if (type === '3') {
+      _userid = uid.toString();
+      res = await this.tModel.findById(_userid);
+    } else if (type === '4') {
       _userid = uid.toString();
+      res = await this.stuModel.findById(_userid);
     }
-    const token = await jwt.sign({ userid: _userid, name, openid, type }, secret, { expiresIn, issuer, subject });
+    res.userid = _userid;
+    res.openid = openid;
+    res.type = type;
+    const token = await jwt.sign(res, secret, { expiresIn, issuer, subject });
     return token;
   }
 

+ 8 - 7
app/service/uploadquestion.js

@@ -18,7 +18,8 @@ class UploadquestionService extends CrudService {
 
   // 完成度查询
   async completion(data) {
-    const { type, typeid, trainplanid } = data;
+    const { type, typeid, trainplanid, questionnaireid } = data;
+    assert(type && typeid && questionnaireid, '缺少部分信息项');
     const datas = [];
     let answertotal = '';
     let alltotal = '';
@@ -31,7 +32,7 @@ class UploadquestionService extends CrudService {
         // 取得当前期学生总数
         const allcount = await this.smodel.count({ batchid: batch.id });
         // 取得当前期学生答问卷数
-        const answercount = await this.model.count({ batchid: batch.id });
+        const answercount = await this.model.count({ batchid: batch.id, questionnaireid });
         let completion = (answercount / allcount * 100).toFixed(2);
         completion = completion + '%';
         const newdata = { id: batch.id, name: batch.name, allcount, answercount, completion };
@@ -40,14 +41,14 @@ class UploadquestionService extends CrudService {
       // 取得当前期学生总数
       alltotal = await this.smodel.count({ termid: typeid });
       // 取得当前期学生答问卷数
-      answertotal = await this.model.count({ termid: typeid });
+      answertotal = await this.model.count({ termid: typeid, questionnaireid });
     } else if (type === '1') {
       const classs = await this.cmodel.find({ batchid: typeid });
       for (const elm of classs) {
         // 取得当前期学生总数
         const allcount = await this.smodel.count({ classid: elm.id });
         // 取得当前期学生答问卷数
-        const answercount = await this.model.count({ classid: elm.id });
+        const answercount = await this.model.count({ classid: elm.id, questionnaireid });
         let completion = (answercount / allcount * 100).toFixed(2);
         completion = completion + '%';
         const newdata = { id: elm.id, name: elm.name, allcount, answercount, completion };
@@ -56,13 +57,13 @@ class UploadquestionService extends CrudService {
       // 取得当前期学生总数
       alltotal = await this.smodel.count({ batchid: typeid });
       // 取得当前期学生答问卷数
-      answertotal = await this.model.count({ batchid: typeid });
+      answertotal = await this.model.count({ batchid: typeid, questionnaireid });
     } else if (type === '2') {
       // 取得当前期学生总数
       const stus = await this.smodel.find({ classid: typeid });
       for (const elm of stus) {
         // 取得当前期学生答问卷数
-        const answer = await this.model.find({ studentid: elm.id });
+        const answer = await this.model.find({ studentid: elm.id, questionnaireid });
         let completion = '';
         if (answer) {
           completion = '100%';
@@ -75,7 +76,7 @@ class UploadquestionService extends CrudService {
       // 取得当前期学生总数
       alltotal = await this.smodel.count({ classid: typeid });
       // 取得当前期学生答问卷数
-      answertotal = await this.model.count({ classid: typeid });
+      answertotal = await this.model.count({ classid: typeid, questionnaireid });
 
     }
     let completiontotal = (answertotal / alltotal * 100).toFixed(2);