diff --git a/app/controllers/attendances_controller.rb b/app/controllers/attendances_controller.rb index 633da5d5d..2147d9070 100644 --- a/app/controllers/attendances_controller.rb +++ b/app/controllers/attendances_controller.rb @@ -81,19 +81,20 @@ class AttendancesController < ApplicationController old_group_ids = @attendance.course_attendance_groups.pluck(:course_group_id) unless old_group_ids.include?(0) - all_groups_ids = old_group_ids + params[:group_ids].map(&:to_i) - # 如果新增的的分班加上之前的分班是课堂的全部分班,则只需创建一条记录 - if all_groups_ids.uniq.count == @course.course_groups_count - @attendance.course_attendance_groups.destroy_all - @attendance.course_attendance_groups.create!(course_group_id: 0, course_id: @attendance.course_id) - new_group = true - else - new_group_ids = params[:group_ids] - old_group_ids + # all_groups_ids = old_group_ids + params[:group_ids].map(&:to_i) + # 如果新增的的分班加上之前的分班是课堂的全部分班,则只需创建一条记录(未分班需要区分考虑,不需要这步) + # if all_groups_ids.uniq.count == @course.course_groups_count + # @attendance.course_attendance_groups.destroy_all + # @attendance.course_attendance_groups.create!(course_group_id: 0, course_id: @attendance.course_id) + # new_group = true + # else + new_group = false + new_group_ids = params[:group_ids].map(&:to_i) - old_group_ids new_group_ids.each do |group_id| @attendance.course_attendance_groups.create!(course_group_id: group_id, course_id: @attendance.course_id) new_group = true end - end + # end end diff --git a/app/controllers/weapps/attendances_controller.rb b/app/controllers/weapps/attendances_controller.rb index 90f8c24b6..9ce089ccb 100644 --- a/app/controllers/weapps/attendances_controller.rb +++ b/app/controllers/weapps/attendances_controller.rb @@ -11,15 +11,15 @@ class Weapps::AttendancesController < ApplicationController attendance = @course.course_attendances.create!(create_params.merge(user_id: current_user.id)) group_ids = params[:group_ids] || [] group_ids = group_ids.blank? ? @course.charge_group_ids(current_user) : @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i) - unless group_ids.blank? || @course.course_groups.where(id: group_ids).count == @course.course_groups.count + if group_ids.blank? || (params[:group_ids].blank? && @course.course_groups.where(id: group_ids).count == @course.course_groups.count) + @course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance) + CreateStudentAttendanceRecordJob.perform_now(attendance.id, [0]) + else # group_ids = @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i) group_ids.each do |group_id| @course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance) end CreateStudentAttendanceRecordJob.perform_now(attendance.id, group_ids) - else - @course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance) - CreateStudentAttendanceRecordJob.perform_now(attendance.id, [0]) end render_ok({attendance_id: attendance.id}) end