lrf402788946 4 rokov pred
rodič
commit
50c96989c5
2 zmenil súbory, kde vykonal 93 pridanie a 26 odobranie
  1. 27 3
      app/service/cerconfirm.js
  2. 66 23
      app/service/student.js

+ 27 - 3
app/service/cerconfirm.js

@@ -37,10 +37,9 @@ class CerconfirmService extends CrudService {
     // 根据期id,和问卷得到学生应该答的问卷
     const allquestionList = await this.questionnairemodel.find({ $or: [{ _id: { $in: innormal } }, { type: '0' }] }); // { type: '0', $or: [{ _id: { $in: innormal } }] }
     const allquestionidList = allquestionList.map(i => JSON.parse(JSON.stringify(i._id))); // 整理成单纯的id数组,反正下面只要判断有没有就行
-    console.log(allquestionidList);
     // 根据范围查找填写的问卷
     const uqList = await this.uqmodel.find({ classid });
-    const list = [];
+    let list = [];
     // 判断学生是否将所有问卷都答完了
     for (const student of stuList) {
       const answerList = uqList.filter(f => ObjectId(f.studentid).equals(student._id)).map(i => i.questionnaireid); // 该学生填写过的问卷
@@ -48,8 +47,33 @@ class CerconfirmService extends CrudService {
         const res = _.difference(allquestionidList, answerList);
         if (res.length <= 0)list.push(student);
       }
-
     }
+    // 计算分数
+    list = await this.getScore(list);
+    return list;
+  }
+
+  async getScore(list) {
+    if (!(_.isArray(list) && list.length > 0)) return;
+    const h = _.head(list);
+    const { classid } = h;
+    // 日常分
+    let dailyScoreList = await this.ctx.model.Personalscore.find({ classid });
+    dailyScoreList = this.ctx.service.student.getDailyScore(dailyScoreList);
+    list = this.ctx.service.student.dealScoreList(dailyScoreList, list, 'daily');
+    // 作业分
+    let taskScoreList = await this.ctx.model.Uploadtask.find({ classid });
+    taskScoreList = this.ctx.service.student.getTaskScore(taskScoreList);
+    list = this.ctx.service.student.dealScoreList(taskScoreList, list, 'task');
+    // 团队分
+    const groupList = await this.ctx.model.Group.find({ classid });
+    const groupScoreList = await this.ctx.model.Groupscore.find({ classid });
+    list = this.ctx.service.student.dealGroupScoreList(
+      groupList,
+      groupScoreList,
+      list
+    );
+    list = _.orderBy(list, 'number');
     return list;
   }
 }

+ 66 - 23
app/service/student.js

@@ -285,11 +285,14 @@ class StudentService extends CrudService {
       f => f.is_fine !== '2' && f.job.includes('普通')
     );
     // 获取平时分
-    const dailyScoreList = await this.psmodel.find({ classid });
-    studentList = this.dealScoreList(dailyScoreList, studentList);
+    let dailyScoreList = await this.psmodel.find({ classid });
+    // 去重复
+    dailyScoreList = this.getDailyScore(dailyScoreList);
+    studentList = this.dealScoreList(dailyScoreList, studentList, 'daily');
     // 获取作业分
-    const taskScoreList = await this.upmodel.find({ classid });
-    studentList = this.dealScoreList(taskScoreList, studentList);
+    let taskScoreList = await this.upmodel.find({ classid });
+    taskScoreList = this.getTaskScore(taskScoreList);
+    studentList = this.dealScoreList(taskScoreList, studentList, 'task');
     // 获取小组分,小组
     const groupList = await this.gmodel.find({ classid });
     const groupScoreList = await this.gsmodel.find({ classid });
@@ -298,16 +301,21 @@ class StudentService extends CrudService {
       groupScoreList,
       studentList
     );
+    studentList = studentList.map(i => {
+      i.score = _.round((i.daily || 0) + (i.task || 0) + (i.groupscore || 0), 2);
+      return i;
+    });
     studentList = studentList.sort(
       (a, b) => (b.score * 1 || 0) - (a.score * 1 || 0)
     );
     // 排名
     // eslint-disable-next-line no-unused-vars
     let num = 0;
-    for (const student of studentList) {
+    for (let student of studentList) {
       // 先判断是否超过第10位,超过就跳出
       if (num > 10) break;
-      const { score, is_fine } = student;
+      const { score, is_fine, job, name, _id } = student;
+      console.log(`${name}-${job}:${score};${is_fine} ;${num}`);
       // 最开始初始化过所有人的状态,并且将干部和不能评优的人都过滤出去,所以正常学生应该都是没有评优,如果此处已经是优秀,那么就是和前人同分改的,直接跳过就好
       if (is_fine === '1') continue;
       // 没有分凑什么热闹
@@ -315,7 +323,7 @@ class StudentService extends CrudService {
       let plus = 1; // 这轮有多少人,到这了,这个人肯定是要改了,所以默认1
       // 评优
       student.is_fine = '1';
-      const rlist = studentList.filter(f => f.score === score);
+      const rlist = studentList.filter(f => f.score === score && !ObjectId(f._id).equals(_id));
       // 处理同分的人也都变成is_fine
       for (const stud of rlist) {
         stud.is_fine = '1';
@@ -333,32 +341,42 @@ class StudentService extends CrudService {
     // 算完的和不用算的合并,提交
     const lastList = [ ...studentList, ...reverseList ];
     for (const student of lastList) {
-      const res = await student.save();
+      if (student.is_fine === '1' && student.job.includes('普通')) {
+        console.log(student.name);
+      }
+      // const res = await student.save();
       // const { meta, ...data } = student;
-      // const r = await this.model.findByIdAndUpdate(
-      //   { _id: ObjectId(student._id) },
-      //   data
-      // );
-      console.log(res);
+      const r = await this.model.findByIdAndUpdate(
+        { _id: ObjectId(student._id) },
+        { score: student.score, is_fine: student.is_fine }
+      );
+      // console.log(res);
     }
   }
   /**
    * 将分数放到学生身上
    * @param {Array} scoreList 班级的分数列表
    * @param {Array} studentList 学生列表
+   * @param {String} type 分数类型
    */
-  dealScoreList(scoreList, studentList) {
+  dealScoreList(scoreList, studentList, type) {
+    scoreList = JSON.parse(JSON.stringify(scoreList));
+    studentList = JSON.parse(JSON.stringify(studentList));
     scoreList = _.groupBy(scoreList, 'studentid');
-    studentList = studentList.map(i => {
+    const arr = [];
+    for (let i of studentList) {
       const slist = scoreList[i._id];
       if (slist) {
-        i.score =
-          (i.score * 1 || 0) +
-          slist.reduce((p, n) => p + (n.score * 1 || 0), 0);
+        const score = slist.reduce((p, n) => p + (n.score * 1 || 0), 0);
+        // i.score = _.round((i.score * 1 || 0) + score, 2);
+        const obj = {};
+        obj[type] = score;
+        i = Object.assign(i, obj);
+        arr.push(i);
       }
-      return i;
-    });
-    return studentList;
+    }
+
+    return arr;
   }
   /**
    * 将 学生所在 组的 团队平均分 + 到学生身上
@@ -367,7 +385,6 @@ class StudentService extends CrudService {
    * @param {Array} studentList 学生列表
    */
   dealGroupScoreList(groupList, scoreList, studentList) {
-    // console.log(groupList);
     scoreList = _.groupBy(scoreList, 'groupid');
     // 算出每组的平均分,之后加给学生
     groupList = groupList.map(i => {
@@ -387,12 +404,38 @@ class StudentService extends CrudService {
       const r = groupList.find(f =>
         f.students.find(sf => ObjectId(sf.stuid).equals(i._id))
       );
-      if (r) i.score = (i.score * 1 || 0) + (r.score * 1 || 0);
+      if (r) {
+        // i.score = _.round((i.score * 1 || 0) + (r.score * 1 || 0), 2);
+        i.groupscore = r.score * 1 || 0;
+      }
       return i;
     });
     return studentList;
   }
 
+  // 平时分去重处理
+  getDailyScore(list) {
+    const arr = [];
+    const mid1 = _.groupBy(list, 'studentid');
+    const keys = Object.keys(mid1);
+    for (const key of keys) {
+      const mid2 = _.uniqBy(mid1[key], 'subid');
+      arr.push(...mid2);
+    }
+    return arr;
+  }
+  // 作业分去重处理
+  getTaskScore(list) {
+    const arr = [];
+    const mid1 = _.groupBy(list, 'studentid');
+    const keys = Object.keys(mid1);
+    for (const key of keys) {
+      const mid2 = _.uniqBy(mid1[key], 'lessonid');
+      arr.push(...mid2);
+    }
+    return arr;
+  }
+
   // 将学生排号
   async arrangeNumber({ classid }) {
     const studList = await this.model.find({ classid });