diff --git a/app/controllers/weapps/attendances_controller.rb b/app/controllers/weapps/attendances_controller.rb index da305bf8b..6d65219f0 100644 --- a/app/controllers/weapps/attendances_controller.rb +++ b/app/controllers/weapps/attendances_controller.rb @@ -44,35 +44,41 @@ class Weapps::AttendancesController < ApplicationController def student_attendances # tip_exception("学生身份的签到列表") if @user_course_identity != Course::STUDENT member = @course.students.find_by(user_id: current_user.id) - current_date = Date.current - current_end_time = Time.current.strftime("%H:%M:%S") - - # 先算出该学生所在分班的签到id - # 分班id为0 表示签到不限制分班 - group_ids = [member&.course_group_id.to_i, 0] - all_attendance_ids = @course.course_attendance_groups.where(course_group_id: group_ids).pluck(:course_attendance_id) - - @history_attendances = @course.course_attendances.where(id: all_attendance_ids.uniq). - where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and end_time < '#{current_end_time}')").order("id desc") - @current_attendance = @course.course_attendances.where(id: all_attendance_ids.uniq). - where("attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}'") - @history_count = @history_attendances.size - - student_attendance_ids = @history_attendances.pluck(:id) - student_attendance_ids += @current_attendance.present? ? @current_attendance.pluck(:id) : [] + if member.present? + current_date = Date.current + current_end_time = Time.current.strftime("%H:%M:%S") + + # 先算出该学生所在分班的签到id + # 分班id为0 表示签到不限制分班 + group_ids = [member&.course_group_id.to_i, 0] + all_attendance_ids = @course.course_attendance_groups.where(course_group_id: group_ids).pluck(:course_attendance_id) + + # 学生的历史签到只统计加入课堂后创建的签到 + history_attendance_ids = member.course_member_attendances.where(course_id: @course.id).pluck(:course_attendance_id) + + @history_attendances = @course.course_attendances.where(id: history_attendance_ids.uniq). + where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and end_time < '#{current_end_time}')").order("id desc") + @current_attendance = @course.course_attendances.where(id: all_attendance_ids.uniq). + where("attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}'") + @history_count = @history_attendances.size + + student_attendance_ids = @history_attendances.pluck(:id) + student_attendance_ids += @current_attendance.present? ? @current_attendance.pluck(:id) : [] + + if student_attendance_ids.uniq.blank? + @normal_count = 0 + @leave_count = 0 + @absence_count = 0 + else + @normal_count = @course.course_member_attendances.where(course_member_id: member&.id, course_attendance_id: student_attendance_ids, attendance_status: "NORMAL").size + @leave_count = @course.course_member_attendances.where(course_member_id: member&.id, course_attendance_id: student_attendance_ids, attendance_status: "LEAVE").size + # 旷课只统计历史签到的 + @absence_count = @course.course_member_attendances.where(course_member_id: member&.id, course_attendance_id: @history_attendances.pluck(:id), attendance_status: "ABSENCE").size + end - if student_attendance_ids.uniq.blank? - @normal_count = 0 - @leave_count = 0 - @absence_count = 0 - else - @normal_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: "NORMAL").size - @leave_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: "LEAVE").size - @absence_count = student_attendance_ids.uniq.size - @normal_count - @leave_count + @all_history_count = @history_attendances.size + @history_attendances = paginate @history_attendances.includes(:course_member_attendances) end - - @all_history_count = @history_attendances.size - @history_attendances = paginate @history_attendances.includes(:course_member_attendances) end def show diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index 4ba4502fc..dec13cc36 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -22,7 +22,7 @@ class HomeworkEndUpdateScoreJob < ApplicationJob challenge_settings = homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work.present? && myshixun games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings end diff --git a/app/jobs/student_join_attendance_record_job.rb b/app/jobs/student_join_attendance_record_job.rb index f1b33c492..28935f771 100644 --- a/app/jobs/student_join_attendance_record_job.rb +++ b/app/jobs/student_join_attendance_record_job.rb @@ -10,7 +10,7 @@ class StudentJoinAttendanceRecordJob < ApplicationJob current_end_time = Time.current.strftime("%H:%M:%S") group_ids = member.course_group_id == 0 ? [0] : [member.course_group_id, 0] - current_attendance_ids = course.course_attendances.joins(:course_attendance_groups).where(course_group_id: group_ids). + current_attendance_ids = course.course_attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: group_ids}). where("(attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}') or (attendance_date > '#{current_date}')").pluck(:id) @@ -21,7 +21,9 @@ class StudentJoinAttendanceRecordJob < ApplicationJob CourseMemberAttendance.bulk_insert(*attrs) do |worker| current_attendance_ids.each do |attendance_id| - worker.add same_attrs.merge(course_attendance_id: attendance_id) + unless course.course_member_attendances.where(course_member_id: member_id, course_attendance_id: attendance_id).exists? + worker.add same_attrs.merge(course_attendance_id: attendance_id) + end end end end