|
@@ -7,6 +7,7 @@ const sd = require('silly-datetime');
|
|
const moment = require('moment');
|
|
const moment = require('moment');
|
|
const { ObjectId } = require('mongoose').Types;
|
|
const { ObjectId } = require('mongoose').Types;
|
|
const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
const { CrudService } = require('naf-framework-mongoose/lib/service');
|
|
|
|
+const student = require('../model/student');
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
|
|
|
class AttendanceService extends CrudService {
|
|
class AttendanceService extends CrudService {
|
|
@@ -50,22 +51,37 @@ class AttendanceService extends CrudService {
|
|
if (location.ibeacon !== ibeacon) {
|
|
if (location.ibeacon !== ibeacon) {
|
|
throw new BusinessError(ErrorCode.BUSINESS, '考勤位置不正确');
|
|
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');
|
|
const datetime = sd.format(new Date(), 'YYYY-MM-DD HH:mm');
|
|
// TODO 考勤时间没有处理
|
|
// TODO 考勤时间没有处理
|
|
const diffres = await this.islate(datetime, setting, type);
|
|
const diffres = await this.islate(datetime, setting, type);
|
|
if (diffres === 0) {
|
|
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) {
|
|
if (attendance) {
|
|
// TODO: 保存数据
|
|
// TODO: 保存数据
|
|
const attends = attendance.attend;
|
|
const attends = attendance.attend;
|
|
let result = false;
|
|
let result = false;
|
|
for (const elm of attends) {
|
|
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;
|
|
result = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -77,7 +93,8 @@ class AttendanceService extends CrudService {
|
|
await attendance.save();
|
|
await attendance.save();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- const newdatastu = { termid: student.termid,
|
|
|
|
|
|
+ const newdatastu = {
|
|
|
|
+ termid: student.termid,
|
|
batchid: student.batchid,
|
|
batchid: student.batchid,
|
|
classid: student.classid,
|
|
classid: student.classid,
|
|
planyearid: student.planyearid,
|
|
planyearid: student.planyearid,
|
|
@@ -99,14 +116,27 @@ class AttendanceService extends CrudService {
|
|
if (beedroom.ibeacon !== ibeacon) {
|
|
if (beedroom.ibeacon !== ibeacon) {
|
|
throw new BusinessError(ErrorCode.BUSINESS, '考勤位置不正确');
|
|
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');
|
|
const datetime = sd.format(new Date(), 'YYYY-MM-DD HH:mm');
|
|
// TODO 考勤时间没有处理
|
|
// TODO 考勤时间没有处理
|
|
const diffres = await this.islate(datetime, setting, type);
|
|
const diffres = await this.islate(datetime, setting, type);
|
|
if (diffres === 0) {
|
|
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) {
|
|
if (attendance) {
|
|
// TODO: 保存数据
|
|
// TODO: 保存数据
|
|
const attends = attendance.attend;
|
|
const attends = attendance.attend;
|
|
@@ -124,7 +154,8 @@ class AttendanceService extends CrudService {
|
|
await attendance.save();
|
|
await attendance.save();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- const newdatastu = { termid: student.termid,
|
|
|
|
|
|
+ const newdatastu = {
|
|
|
|
+ termid: student.termid,
|
|
batchid: student.batchid,
|
|
batchid: student.batchid,
|
|
classid: student.classid,
|
|
classid: student.classid,
|
|
studentid: student.id,
|
|
studentid: student.id,
|
|
@@ -135,9 +166,7 @@ class AttendanceService extends CrudService {
|
|
};
|
|
};
|
|
await this.model.create(newdatastu);
|
|
await this.model.create(newdatastu);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
async test() {
|
|
async test() {
|
|
@@ -149,7 +178,6 @@ class AttendanceService extends CrudService {
|
|
// TODO 考勤时间没有处理
|
|
// TODO 考勤时间没有处理
|
|
const diffres = await this.islate(datetime, setting, '0');
|
|
const diffres = await this.islate(datetime, setting, '0');
|
|
console.log(diffres);
|
|
console.log(diffres);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// 判断上课考勤是否迟到和开始
|
|
// 判断上课考勤是否迟到和开始
|
|
@@ -199,7 +227,37 @@ class AttendanceService extends CrudService {
|
|
}
|
|
}
|
|
return res;
|
|
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;
|
|
module.exports = AttendanceService;
|