Parcourir la source

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

liuyu il y a 4 ans
Parent
commit
cde7def26b

+ 4 - 1
app/controller/.student.js

@@ -33,6 +33,7 @@ module.exports = {
       "selfscore",
       "score",
       "diy",
+      "isComming",
     ],
   },
   destroy: {
@@ -74,6 +75,7 @@ module.exports = {
       "selfscore",
       "score",
       "diy",
+      "isComming",
     ],
   },
   show: {
@@ -116,7 +118,8 @@ module.exports = {
         is_fine: "is_fine",
         selfscore: "selfscore",
         score: "score",
-        diy:"diy"
+        diy: "diy",
+        isComming:"isComming",
       },
     },
     service: "query",

+ 4 - 2
app/controller/attendance.js

@@ -7,7 +7,6 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 考勤表管理
 class AttendanceController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.attendance;
@@ -24,7 +23,10 @@ class AttendanceController extends Controller {
     const res = await this.service.attendancecreate(this.ctx.request.body);
     this.ctx.ok({ res });
   }
-
+  async attendancecreateList() {
+    const res = await this.service.attendancecreateList(this.ctx.request.body);
+    this.ctx.ok({ res });
+  }
 }
 
 module.exports = CrudController(AttendanceController, meta);

+ 1 - 0
app/model/student.js

@@ -36,6 +36,7 @@ const StudentSchema = {
   selfscore: { type: String, required: false, maxLength: 200, zh: '个人分' }, // 个人分
   score: { type: String, required: false, maxLength: 200, zh: '总分' }, // 总分
   diy: { type: { Object }, required: false, zh: '自定义' }, // 自定义
+  isComming: { type: String, default: '0', zh: '签到' }, // 是否签到0否,1是
 };
 
 

+ 1 - 1
app/router.js

@@ -152,7 +152,7 @@ module.exports = app => {
   router.resources('attendance', '/api/train/attendance', controller.attendance); // index、create、show、destroy
   router.post('attendance', '/api/train/attendance/update/:id', controller.attendance.update);
   router.post('attendance', '/api/train/attendance/attendancecreate', controller.attendance.attendancecreate);
-
+  router.post('attendance', '/api/train/attendance/attendancecreateList', controller.attendance.attendancecreateList);
   // 学校上传学生名单
   router.resources('school', '/api/train/school', controller.school); // index、create、show、destroy
   router.post('school', '/api/train/school/update/:id', controller.school.update);

+ 73 - 15
app/service/attendance.js

@@ -7,6 +7,7 @@ const sd = require('silly-datetime');
 const moment = require('moment');
 const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
+const student = require('../model/student');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 
 class AttendanceService extends CrudService {
@@ -50,22 +51,37 @@ class AttendanceService extends CrudService {
       if (location.ibeacon !== ibeacon) {
         throw new BusinessError(ErrorCode.BUSINESS, '考勤位置不正确');
       }
-      const attendance = await this.model.findOne({ termid: student.termid, batchid: student.batchid, classid: student.classid, studentid: student.id });
+      const attendance = await this.model.findOne({
+        termid: student.termid,
+        batchid: student.batchid,
+        classid: student.classid,
+        studentid: student.id,
+      });
       const datetime = sd.format(new Date(), 'YYYY-MM-DD HH:mm');
       // TODO 考勤时间没有处理
       const diffres = await this.islate(datetime, setting, type);
       if (diffres === 0) {
-        throw new BusinessError(ErrorCode.BUSINESS, '考勤时间不正确,请稍后在签到');
+        throw new BusinessError(
+          ErrorCode.BUSINESS,
+          '考勤时间不正确,请稍后在签到'
+        );
       }
-      const newData = { date: datetime.substr(0, 10), time: datetime.substr(11, 5), type, status: diffres + '' };
+      const newData = {
+        date: datetime.substr(0, 10),
+        time: datetime.substr(11, 5),
+        type,
+        status: diffres + '',
+      };
       if (attendance) {
         // TODO: 保存数据
         const attends = attendance.attend;
         let result = false;
         for (const elm of attends) {
-          if (elm.date === datetime.substr(0, 10)
-              && elm.type === '0'
-              && elm.time.substr(0, 2) === datetime.substr(11, 2)) {
+          if (
+            elm.date === datetime.substr(0, 10) &&
+            elm.type === '0' &&
+            elm.time.substr(0, 2) === datetime.substr(11, 2)
+          ) {
             result = true;
             break;
           }
@@ -77,7 +93,8 @@ class AttendanceService extends CrudService {
           await attendance.save();
         }
       } else {
-        const newdatastu = { termid: student.termid,
+        const newdatastu = {
+          termid: student.termid,
           batchid: student.batchid,
           classid: student.classid,
           planyearid: student.planyearid,
@@ -99,14 +116,27 @@ class AttendanceService extends CrudService {
       if (beedroom.ibeacon !== ibeacon) {
         throw new BusinessError(ErrorCode.BUSINESS, '考勤位置不正确');
       }
-      const attendance = await this.model.findOne({ termid: student.termid, batchid: student.batchid, classid: student.classid, studentid: student.id });
+      const attendance = await this.model.findOne({
+        termid: student.termid,
+        batchid: student.batchid,
+        classid: student.classid,
+        studentid: student.id,
+      });
       const datetime = sd.format(new Date(), 'YYYY-MM-DD HH:mm');
       // TODO 考勤时间没有处理
       const diffres = await this.islate(datetime, setting, type);
       if (diffres === 0) {
-        throw new BusinessError(ErrorCode.BUSINESS, '考勤时间不正确,请稍后在签到');
+        throw new BusinessError(
+          ErrorCode.BUSINESS,
+          '考勤时间不正确,请稍后在签到'
+        );
       }
-      const newData = { date: datetime.substr(0, 10), time: datetime.substr(11, 5), type, status: diffres + '' };
+      const newData = {
+        date: datetime.substr(0, 10),
+        time: datetime.substr(11, 5),
+        type,
+        status: diffres + '',
+      };
       if (attendance) {
         // TODO: 保存数据
         const attends = attendance.attend;
@@ -124,7 +154,8 @@ class AttendanceService extends CrudService {
           await attendance.save();
         }
       } else {
-        const newdatastu = { termid: student.termid,
+        const newdatastu = {
+          termid: student.termid,
           batchid: student.batchid,
           classid: student.classid,
           studentid: student.id,
@@ -135,9 +166,7 @@ class AttendanceService extends CrudService {
         };
         await this.model.create(newdatastu);
       }
-
     }
-
   }
 
   async test() {
@@ -149,7 +178,6 @@ class AttendanceService extends CrudService {
     // TODO 考勤时间没有处理
     const diffres = await this.islate(datetime, setting, '0');
     console.log(diffres);
-
   }
 
   // 判断上课考勤是否迟到和开始
@@ -199,7 +227,37 @@ class AttendanceService extends CrudService {
     }
     return res;
   }
-
+  async attendancecreateList({ studentIds }) {
+    for (const studentId of studentIds) {
+      // 查出这个学生,更新这个学生的签到并签到
+      const student = await this.stumodel.findById(studentId);
+      if (!student) {
+        throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '学生信息不存在');
+      }
+      // 签到学生是否来了
+      student.isComming = '1';
+      await student.save();
+      const attendInfo = {
+        date: new Date().getDate(),
+        time: new Date().getHours(),
+        type: '0',
+        status: '1',
+      };
+      const data = {
+        planyearid: student.planyearid,
+        planid: student.planid,
+        termid: student.termid,
+        batchid: student.batchid,
+        classid: student.classid,
+        schid: student.schid,
+        schname: student.school_name,
+        studentid: student.id,
+        stuname: student.name,
+        attendInfo,
+      };
+      await this.model.create(data);
+    }
+  }
 }
 
 module.exports = AttendanceService;

+ 2 - 0
app/service/trainplan.js

@@ -240,6 +240,7 @@ class TrainplanService extends CrudService {
       const trainplandName = trainplan.title;
       // 在计划中找到这个学生在哪期以及哪期下的哪批次
       for (const student of studentList) {
+        student.isComming = utils.getIsNot(student.isComming);
         student.trainplandName = trainplandName;
         // 期次
         const term = trainplan.termnum.filter(term => {
@@ -287,6 +288,7 @@ class TrainplanService extends CrudService {
         // { key: 'selfscore', title: '个人分' },
         // { key: 'score', title: '总分' },
         // { key: 'diy', title: '自定义' },
+        { key: 'isComming', title: '是否签到' },
       ];
 
       // 需要打出的列表

+ 1 - 0
app/service/user.js

@@ -94,6 +94,7 @@ class UserService extends CrudService {
         throw new BusinessError(ErrorCode.USER_NOT_EXIST);
       }
       stud.openid = openid;
+      stud.isComming = '1';
       await stud.save();
       const newdata = { name: stud.name, mobile: stud.phone, type: '4', uid: stud.id, openid, unionid };
       newdata.passwd = { secret: '12345678' };