diff --git a/app/models/course_attendance.rb b/app/models/course_attendance.rb index 1bd96fc29..28059efc1 100644 --- a/app/models/course_attendance.rb +++ b/app/models/course_attendance.rb @@ -1,7 +1,7 @@ class CourseAttendance < ApplicationRecord # status: 0: 未开启,1:已开启,2:已截止 # mode: 0 两种签到,1 二维码签到,2 数字签到 - enum mode: { ALL: 0, QRCODE: 1, NUMBER: 2 } + enum mode: { ALL: 0, QRCODE: 1, NUMBER: 2, QUICK: 3 } belongs_to :course belongs_to :user diff --git a/app/views/weapps/attendances/index.json.jbuilder b/app/views/weapps/attendances/index.json.jbuilder index 34317d08d..da8be3c8d 100644 --- a/app/views/weapps/attendances/index.json.jbuilder +++ b/app/views/weapps/attendances/index.json.jbuilder @@ -1,15 +1,17 @@ json.current_attendance @current_attendance do |attendance| - json.(attendance, :id, :normal_count, :all_count) - json.attendance_date attendance.attendance_date.strftime("%Y/%m/%d") + json.(attendance, :id, :name, :normal_count, :all_count) + json.attendance_date attendance.attendance_date.strftime("%Y-%m-%d") json.start_time attendance.start_time.strftime("%H:%M") json.end_time attendance.end_time.strftime("%H:%M") end all_normal_rate = [] all_absence_rate = [] +all_leave_rate = [] json.history_attendances @history_attendances.each_with_index.to_a do |attendance, index| normal_count = history_member_count(@all_member_attendances, "NORMAL", attendance.id) absence_count = history_member_count(@all_member_attendances, "ABSENCE", attendance.id) + leave_count = history_member_count(@all_member_attendances, "LEAVE", attendance.id) all_count = @all_member_attendances.select{|member_attendance| member_attendance.course_attendance_id == attendance.id}.size json.index index + 1 @@ -17,8 +19,11 @@ json.history_attendances @history_attendances.each_with_index.to_a do |attendanc all_normal_rate << cal_rate(normal_count, all_count) json.absence_rate cal_rate(absence_count, all_count) all_absence_rate << cal_rate(absence_count, all_count) + json.leave_rate cal_rate(leave_count, all_count) + all_leave_rate << cal_rate(leave_count, all_count) end json.all_history_count @all_history_count json.avg_normal_rate @all_history_count == 0 ? 0 : all_normal_rate.sum / @all_history_count json.avg_absence_rate @all_history_count == 0 ? 0 : all_absence_rate.sum / @all_history_count +json.avg_leave_rate @all_history_count == 0 ? 0 : all_leave_rate.sum / @all_history_count diff --git a/app/views/weapps/attendances/show.json.jbuilder b/app/views/weapps/attendances/show.json.jbuilder index 1eb73347e..b3f13ca60 100644 --- a/app/views/weapps/attendances/show.json.jbuilder +++ b/app/views/weapps/attendances/show.json.jbuilder @@ -5,7 +5,8 @@ json.all_count @all_count json.code @attendance.attendance_code json.mode @attendance.mode json.edit_auth @user_course_identity < Course::PROFESSOR || @attendance.user_id == User.current.id -json.attendance_date @attendance.attendance_date.strftime("%Y/%m/%d") +json.name @attendance.name +json.attendance_date @attendance.attendance_date.strftime("%Y-%m-%d") json.start_time @attendance.start_time.strftime("%H:%M") json.end_time @attendance.end_time.strftime("%H:%M")