|
@@ -287,8 +287,12 @@ class StatisticsService extends CrudService {
|
|
}
|
|
}
|
|
|
|
|
|
async studentSign({ lesson_id, student_id, range, skip, limit }) {
|
|
async studentSign({ lesson_id, student_id, range, skip, limit }) {
|
|
|
|
+ console.log('line 290 in function:');
|
|
const pipeline = [];
|
|
const pipeline = [];
|
|
- let $match = { lesson_id, student_id };
|
|
|
|
|
|
+ const baseCol = { time_start: 1, title: 1 };
|
|
|
|
+ const studentQuery = {};
|
|
|
|
+ // 返回数据:课程,上课时间,学生,是否签到,是否缴费
|
|
|
|
+ let $match = { lesson_id };
|
|
if (_.isArray(range)) {
|
|
if (_.isArray(range)) {
|
|
const start = _.head(range);
|
|
const start = _.head(range);
|
|
const end = _.last(range);
|
|
const end = _.last(range);
|
|
@@ -297,11 +301,60 @@ class StatisticsService extends CrudService {
|
|
$match = { ...$match, ...tq };
|
|
$match = { ...$match, ...tq };
|
|
}
|
|
}
|
|
pipeline.push({ $match });
|
|
pipeline.push({ $match });
|
|
-
|
|
|
|
- //
|
|
|
|
-
|
|
|
|
|
|
+ pipeline.push({ $addFields: { lesson_id: { $toString: '$_id' } } });
|
|
|
|
+ if (student_id) {
|
|
|
|
+ studentQuery.student_id = student_id;
|
|
|
|
+ }
|
|
|
|
+ // #region 正式学生
|
|
|
|
+ pipeline.push({
|
|
|
|
+ $lookup: {
|
|
|
|
+ from: 'lessonStudent',
|
|
|
|
+ localField: 'lesson_id',
|
|
|
|
+ foreignField: 'lesson_id',
|
|
|
|
+ pipeline: [
|
|
|
|
+ { $match: studentQuery },
|
|
|
|
+ { $project: { is_sign: 1, is_pay: 1, soid: { $toObjectId: '$student_id' } } },
|
|
|
|
+ {
|
|
|
|
+ $lookup: {
|
|
|
|
+ from: 'student',
|
|
|
|
+ localField: 'soid',
|
|
|
|
+ foreignField: '_id',
|
|
|
|
+ as: 'si',
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ { $project: { is_sign: 1, is_pay: 1, name: { $first: '$si.name' }, icon: { $first: '$si.icon' } } },
|
|
|
|
+ ],
|
|
|
|
+ as: 'zStudent',
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ // #endregion
|
|
|
|
+ // #region 临时学生
|
|
|
|
+ pipeline.push({
|
|
|
|
+ $lookup: {
|
|
|
|
+ from: 'tempLessonApply',
|
|
|
|
+ localField: 'lesson_id',
|
|
|
|
+ foreignField: 'lesson_id',
|
|
|
|
+ pipeline: [
|
|
|
|
+ { $match: studentQuery },
|
|
|
|
+ { $addFields: { soid: { $toObjectId: '$student_id' } } },
|
|
|
|
+ {
|
|
|
|
+ $lookup: {
|
|
|
|
+ from: 'student',
|
|
|
|
+ localField: 'soid',
|
|
|
|
+ foreignField: '_id',
|
|
|
|
+ as: 'si',
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ { $project: { name: 1, is_sign: 1, is_pay: 1, icon: { $ifNull: [{ $first: '$si.icon' }, []] } } },
|
|
|
|
+ ],
|
|
|
|
+ as: 'lStudent',
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ // #endregion
|
|
|
|
+ pipeline.push({ $project: { ...baseCol, studentList: { $concatArrays: [ '$zStudent', '$lStudent' ] } } });
|
|
|
|
+ pipeline.push({ $unwind: '$studentList' });
|
|
|
|
+ pipeline.push({ $project: { ...baseCol, name: '$studentList.name', is_pay: '$studentList.is_pay', is_sign: '$studentList.is_sign', icon: '$studentList.icon' } });
|
|
pipeline.push({ $sort: { time_start: 1 } });
|
|
pipeline.push({ $sort: { time_start: 1 } });
|
|
- // 返回数据:学生,上课时间,课程,是否签单,是否缴费
|
|
|
|
const res = await this.lessonModel.aggregate(pipeline);
|
|
const res = await this.lessonModel.aggregate(pipeline);
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|