ソースを参照

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

reloaded 5 年 前
コミット
bbc68987de

+ 47 - 0
app/controller/.setting.js

@@ -0,0 +1,47 @@
+module.exports = {
+  create: {
+    requestBody: [
+      'am_start',
+      'am_end',
+      'pm_start',
+      'pm_end',
+      'bd_start',
+      'bd_end'
+    ]
+  },
+  destroy: {
+    params: ['!id'],
+    service: 'delete'
+  },
+  update: {
+    params: ['!id'],
+    requestBody: [
+      'am_start',
+      'am_end',
+      'pm_start',
+      'pm_end',
+      'bd_start',
+      'bd_end'
+    ]
+  },
+  show: {
+    parameters: {
+      params: ['!id']
+    },
+    service: 'fetch'
+  },
+  index: {
+    parameters: {
+      query: {
+        am_start :'am_start'
+      }
+    },
+    service: 'query',
+    options: {
+      query: ['skip', 'limit'],
+      sort: ['meta.createdAt'],
+      desc: true,
+      count: true
+    }
+  },
+};

+ 18 - 0
app/controller/setting.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.setting.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 设置表管理
+class SettingController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.setting;
+  }
+
+}
+
+module.exports = CrudController(SettingController, meta);

+ 23 - 0
app/model/setting.js

@@ -0,0 +1,23 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+// 设置表
+const SettingSchema = {
+  am_start: { type: String, required: true, maxLength: 20 }, // 上午考勤开始时间
+  am_end: { type: String, required: true, maxLength: 20 }, // 上午考勤结束时间
+  pm_start: { type: String, required: true, maxLength: 20 }, // 下午开始时间
+  pm_end: { type: String, required: false, maxLength: 20 }, // 下午结束时间
+  bd_start: { type: String, required: true, maxLength: 20 }, // 寝室开始时间
+  bd_end: { type: String, required: false, maxLength: 20 }, // 寝室结束时间
+};
+
+
+const schema = new Schema(SettingSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Setting', schema, 'setting');
+};

+ 77 - 2
app/service/attendance.js

@@ -4,6 +4,7 @@
 const assert = require('assert');
 const _ = require('lodash');
 const sd = require('silly-datetime');
+const moment = require('moment');
 const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
@@ -16,6 +17,7 @@ class AttendanceService extends CrudService {
     this.clamodel = this.ctx.model.Class;
     this.lomodel = this.ctx.model.Location;
     this.bmodel = this.ctx.model.Bedroom;
+    this.setmodel = this.ctx.model.Setting;
   }
 
   async attendancecreate(data) {
@@ -30,6 +32,11 @@ class AttendanceService extends CrudService {
     if (!student) {
       throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '学生信息不存在');
     }
+    // 取得设置表内考勤时间
+    const setting = await this.setmodel.findOne();
+    if (!setting) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '考勤设置信息不存在');
+    }
     // type为0是上课考勤
     if (type === '0') {
       const classes = await this.clamodel.findById(student.classid);
@@ -46,7 +53,11 @@ class AttendanceService extends CrudService {
       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 newData = { date: datetime.substr(0, 10), time: datetime.substr(11, 5), type, status: '1' };
+      const diffres = await this.islate(datetime, setting, type);
+      if (diffres === 0) {
+        throw new BusinessError(ErrorCode.BUSINESS, '考勤时间不正确,请稍后在签到');
+      }
+      const newData = { date: datetime.substr(0, 10), time: datetime.substr(11, 5), type, status: diffres + '' };
       if (attendance) {
         // TODO: 保存数据
         const attends = attendance.attend;
@@ -86,7 +97,11 @@ class AttendanceService extends CrudService {
       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 newData = { date: datetime.substr(0, 10), time: datetime.substr(11, 5), type, status: '1' };
+      const diffres = await this.islate(datetime, setting, type);
+      if (diffres === 0) {
+        throw new BusinessError(ErrorCode.BUSINESS, '考勤时间不正确,请稍后在签到');
+      }
+      const newData = { date: datetime.substr(0, 10), time: datetime.substr(11, 5), type, status: diffres + '' };
       if (attendance) {
         // TODO: 保存数据
         const attends = attendance.attend;
@@ -117,6 +132,66 @@ class AttendanceService extends CrudService {
 
   }
 
+  async test() {
+    const setting = await this.setmodel.findOne();
+    if (!setting) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '考勤设置信息不存在');
+    }
+    const datetime = sd.format(new Date(), 'YYYY-MM-DD HH:mm');
+    // TODO 考勤时间没有处理
+    const diffres = await this.islate(datetime, setting, '0');
+    console.log(diffres);
+
+  }
+
+  // 判断上课考勤是否迟到和开始
+  async islate(nowdata, setting, type) {
+    nowdata = nowdata + ':00';
+    let res = 0;
+    if (type === '0') {
+      const am_start = nowdata.substr(0, 10) + ' ' + setting.am_start + ':00';
+      const am_end = nowdata.substr(0, 10) + ' ' + setting.am_end + ':00';
+      const pm_start = nowdata.substr(0, 10) + ' ' + setting.pm_start + ':00';
+      const pm_end = nowdata.substr(0, 10) + ' ' + setting.pm_end + ':00';
+      const resamstart = moment(nowdata).diff(moment(am_start), 'minutes');
+      const resamend = moment(nowdata).diff(moment(am_end), 'minutes');
+      const respmstart = moment(nowdata).diff(moment(pm_start), 'minutes');
+      const respmend = moment(nowdata).diff(moment(pm_end), 'minutes');
+      // 当前时间大于am开始时间
+      if (resamstart > 0) {
+        // 当前时间小于pm开始时间
+        if (respmstart < 0) {
+          // 判断上午考勤是否迟到
+          if (resamend > 0) {
+            res = 2;
+          } else {
+            res = 1;
+          }
+        } else {
+          // 判断下午考勤是否迟到
+          if (respmend > 0) {
+            res = 2;
+          } else {
+            res = 1;
+          }
+        }
+      } else if (type === '1') {
+        const bd_start = nowdata.substr(0, 10) + ' ' + setting.bd_start + ':00';
+        const bd_end = nowdata.substr(0, 10) + ' ' + setting.bd_end + ':00';
+        const resstart = moment(nowdata).diff(moment(bd_start), 'minutes');
+        const resend = moment(nowdata).diff(moment(bd_end), 'minutes');
+        if (resstart > 0) {
+          if (resend > 0) {
+            res = 2;
+          } else {
+            res = 1;
+          }
+        }
+      }
+    }
+    return res;
+  }
+
 }
 
 module.exports = AttendanceService;

+ 18 - 0
app/service/setting.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class SettingService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'setting');
+    this.model = this.ctx.model.Setting;
+  }
+
+}
+
+module.exports = SettingService;

+ 1 - 1
app/service/util.js

@@ -21,7 +21,7 @@ class UtilService extends CrudService {
     const user_email = this.ctx.app.config.user_email;
     const auth_code = this.ctx.app.config.auth_code;
     const transporter = nodemailer.createTransport({
-      service: 'qq',
+      host: 'smtp.exmail.qq.com',
       secureConnection: true,
       port: 465,
       auth: {

+ 2 - 2
config/config.default.js

@@ -56,8 +56,8 @@ module.exports = appInfo => {
   config.REVIEW_TEMPLATE_ID = 'oqmozBcdkCzBOvNrdzMQ1lDJcobD5uBEpNoLWec0bPY';
 
   // 邮箱配置
-  config.user_email = '1345526645@qq.com';
-  config.auth_code = 'vnrzrxwserhyfeda';
+  config.user_email = 'system@jilinjobs.cn';
+  config.auth_code = 'vgWtywkwMJpN8QDL';
 
   // mq配置
   config.amqp = {