document.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. const moment = require('moment');
  8. class DocumentService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'document');
  11. this.model = this.ctx.model.Document;
  12. this.tmodel = this.ctx.model.Teacher;
  13. }
  14. // 查询教师信息 记录评分
  15. async create() {
  16. const info = { create_time: moment().format('YYYY-MM-DD HH:mm:ss') };
  17. // 只查询相关评分
  18. info.record = await this.tmodel.aggregate([{ $project: { name: 1, zlscore: 1, msscore: 1, xsscore: 1, beforescore: 1 } }]);
  19. // 所有教师评分全部修改为0
  20. await this.tmodel.updateMany({}, { $set: { xsscore: '0' } });
  21. return await this.model.create(info);
  22. }
  23. // 查询
  24. async queryTeacher({ skip, limit, teacher, ...info }) {
  25. const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
  26. const data = [];
  27. for (const val of res) {
  28. if (val.record && val.record.length > 0) {
  29. for (const re of val.record) {
  30. if (re._id.toString() === teacher) data.push({ ...re, ...{ create_time: val.create_time } });
  31. }
  32. }
  33. }
  34. const total = data.length;
  35. return { total, data };
  36. }
  37. }
  38. module.exports = DocumentService;