|
@@ -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 });
|