|
@@ -0,0 +1,41 @@
|
|
|
|
+'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;
|
|
|
|
+const moment = require('moment');
|
|
|
|
+
|
|
|
|
+class DocumentService extends CrudService {
|
|
|
|
+ constructor(ctx) {
|
|
|
|
+ super(ctx, 'document');
|
|
|
|
+ this.model = this.ctx.model.Document;
|
|
|
|
+ this.tmodel = this.ctx.model.Teacher;
|
|
|
|
+ }
|
|
|
|
+ // 查询教师信息 记录评分
|
|
|
|
+ async create() {
|
|
|
|
+ const info = { create_time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
|
+ // 只查询相关评分
|
|
|
|
+ info.record = await this.tmodel.aggregate([{ $project: { name: 1, zlscore: 1, msscore: 1, xsscore: 1, beforescore: 1 } }]);
|
|
|
|
+ // 所有教师评分全部修改为0
|
|
|
|
+ await this.tmodel.updateMany({}, { $set: { xsscore: '0' } });
|
|
|
|
+ return await this.model.create(info);
|
|
|
|
+ }
|
|
|
|
+ // 查询
|
|
|
|
+ async queryTeacher({ skip, limit, teacher, ...info }) {
|
|
|
|
+ const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
|
|
|
|
+ const data = [];
|
|
|
|
+ for (const val of res) {
|
|
|
|
+ if (val.record && val.record.length > 0) {
|
|
|
|
+ for (const re of val.record) {
|
|
|
|
+ if (re._id.toString() === teacher) data.push({ ...re, ...{ create_time: val.create_time } });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ const total = data.length;
|
|
|
|
+ return { total, data };
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+module.exports = DocumentService;
|