video_log
cxt 5 years ago
parent c3d98855cb
commit e7b8946bda

@ -1,7 +1,7 @@
class Weapps::AttendancesController < ApplicationController
before_action :require_login
before_action :find_course, only: [:create, :index]
before_action :find_attendance, except: [:create, :index]
before_action :find_course, only: [:create, :index, :student_attendances]
before_action :find_attendance, except: [:create, :index, :student_attendances]
before_action :user_course_identity
before_action :teacher_allowed, only: [:create]
@ -25,38 +25,37 @@ class Weapps::AttendancesController < ApplicationController
end
def student_attendances
if @user_course_identity == Course::STUDENT
current_date = Date.current
current_end_time = Time.current.strftime("%H:%M:%S")
member = @course.students.find_by(user_id: current_user.id)
# 先算出该学生所在分班的签到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}").take
@history_count = @history_attendances.size
student_attendance_ids = @history_attendances.pluck(:id)
student_attendance_ids += @current_attendance.present? ? [@current_attendance.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_attendance_id: student_attendance_ids, attendance_status: 1).size
@leave_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 2).size
@absence_count = student_attendance_ids.uniq.size - @normal_count - @leave_count
end
@all_history_count = @history_attendances.size
@history_attendances = paginate @history_attendances.includes(:course_member_attendances)
tip_exception(403, "") 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}'").take
@history_count = @history_attendances.size
student_attendance_ids = @history_attendances.pluck(:id)
student_attendance_ids += @current_attendance.present? ? [@current_attendance.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_attendance_id: student_attendance_ids, attendance_status: 1).size
@leave_count = @course.course_member_attendances.where(course_attendance_id: student_attendance_ids, attendance_status: 2).size
@absence_count = student_attendance_ids.uniq.size - @normal_count - @leave_count
end
@all_history_count = @history_attendances.size
@history_attendances = paginate @history_attendances.includes(:course_member_attendances)
end
def show

@ -0,0 +1,7 @@
module Weapps::AttendancesHelper
def student_attendance_status attendance, user
st_attendance = attendance.course_member_attendances.find_by(user_id: user.id)
st_attendance.present? ? st_attendance.attendance_status : 0
end
end

@ -1,5 +1,5 @@
class CourseAttendanceGroup < ApplicationRecord
belongs_to :course
belongs_to :course_attendance
belongs_to :course_group
belongs_to :course_group, optional: true
end

@ -0,0 +1,5 @@
json.(attendance, :name, :mode)
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")
json.attendance_status student_attendance_status(attendance, User.current)

@ -1,5 +1,5 @@
json.current_attendance do
json.partial! 'student_attendance', locals: {attendance: @current_attendance}
json.partial! 'student_attendance', locals: {attendance: @current_attendance} if @current_attendance.present?
end
json.history_attendances @history_attendances do |attendance|

@ -1054,7 +1054,7 @@ Rails.application.routes.draw do
end
resources :attendances, only: [:index, :update, :create, :show, :destroy], shallow: true do
member do
collection do
get :student_attendances
end
end

Loading…
Cancel
Save