Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

video_transcode
jingquan huang 5 years ago
commit 38a2cb2503

@ -9,7 +9,7 @@ class Admins::UserSchoolsStatisticsController < Admins::BaseController
end end
def index def index
default_sort('finish_challenge_count', 'desc') default_sort('cnt', 'desc')
total_count, schools = Admins::UserSchoolsStatisticQuery.call(params) total_count, schools = Admins::UserSchoolsStatisticQuery.call(params)
@schools = paginate schools, total_count: total_count @schools = paginate schools, total_count: total_count

@ -72,6 +72,15 @@ class ApplicationController < ActionController::Base
if !current_user.shixun_permission(@shixun) if !current_user.shixun_permission(@shixun)
tip_exception(403, "..") tip_exception(403, "..")
end end
# if !current_user.shixun_permission(@shixun)
# if @shixun.user_scope == 1
# school_id = @shixun.shixun_schools.first&.school_id
# name = School.find_by(id: school_id)&.name
# tip_exception(-5, "当前实训只对#{name}等单位开放")
# else
# tip_exception(403, "..")
# end
# end
end end
def admin_or_business? def admin_or_business?
@ -321,7 +330,7 @@ class ApplicationController < ActionController::Base
end end
if !User.current.logged? && Rails.env.development? if !User.current.logged? && Rails.env.development?
User.current = User.find 3117 User.current = User.find 1
end end

@ -747,6 +747,12 @@ class CoursesController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
course_student.destroy! course_student.destroy!
course_teacher.update!(is_active: 1) course_teacher.update!(is_active: 1)
teacher_course_record = @course.teacher_group_records.find_by(user_id: current_user.id)
if teacher_course_record.present?
teacher_course_record.update!(group_id: course_student.course_group_id)
else
TeacherGroupRecord.create!(user_id: current_user.id, course_id: @course.id, group_id: course_student.course_group_id)
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
end end
normal_status(0, "切换成功") normal_status(0, "切换成功")
@ -766,6 +772,12 @@ class CoursesController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
course_student.destroy! course_student.destroy!
course_teacher.update!(is_active: 1) course_teacher.update!(is_active: 1)
teacher_course_record = @course.teacher_group_records.find_by(user_id: current_user.id)
if teacher_course_record.present?
teacher_course_record.update!(group_id: course_student.course_group_id)
else
TeacherGroupRecord.create!(user_id: current_user.id, course_id: @course.id, group_id: course_student.course_group_id)
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
end end
normal_status(0, "切换成功") normal_status(0, "切换成功")
@ -788,7 +800,9 @@ class CoursesController < ApplicationController
course_student.update_attributes!(is_active: 1) course_student.update_attributes!(is_active: 1)
else else
# 学生身份不存在则创建 # 学生身份不存在则创建
CourseMember.create!(user_id: current_user.id, role: 4, course_id: @course.id) course_group_id = @course.teacher_group_records.find_by(user_id: current_user.id)&.group_id.to_i
course_group_id = @course.course_groups.find_by(id: course_group_id)&.id.to_i
CourseMember.create!(user_id: current_user.id, role: 4, course_id: @course.id, course_group_id: course_group_id)
CourseAddStudentCreateWorksJob.perform_later(@course.id, [current_user.id]) CourseAddStudentCreateWorksJob.perform_later(@course.id, [current_user.id])
end end
normal_status(0, "切换成功") normal_status(0, "切换成功")

@ -9,7 +9,7 @@ class Weapps::AttendancesController < ApplicationController
def create def create
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
attendance = @course.course_attendances.create!(create_params.merge(user_id: current_user.id)) attendance = @course.course_attendances.create!(create_params.merge(user_id: current_user.id))
unless params[:group_ids].blank? unless params[:group_ids].blank? || @course.course_groups.where(id: params[:group_ids]).count == @course.course_groups.count
group_ids = @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i) group_ids = @course.charge_group_ids(current_user) & params[:group_ids].map(&:to_i)
group_ids.each do |group_id| group_ids.each do |group_id|
@course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance) @course.course_attendance_groups.create!(course_group_id: group_id, course_attendance: attendance)
@ -17,7 +17,7 @@ class Weapps::AttendancesController < ApplicationController
CreateStudentAttendanceRecordJob.perform_now(attendance.id, group_ids) CreateStudentAttendanceRecordJob.perform_now(attendance.id, group_ids)
else else
@course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance) @course.course_attendance_groups.create!(course_group_id: 0, course_attendance: attendance)
CreateStudentAttendanceRecordJob.perform_later(attendance.id, [0]) CreateStudentAttendanceRecordJob.perform_now(attendance.id, [0])
end end
render_ok({attendance_id: attendance.id}) render_ok({attendance_id: attendance.id})
end end
@ -44,35 +44,41 @@ class Weapps::AttendancesController < ApplicationController
def student_attendances def student_attendances
# tip_exception("学生身份的签到列表") if @user_course_identity != Course::STUDENT # tip_exception("学生身份的签到列表") if @user_course_identity != Course::STUDENT
member = @course.students.find_by(user_id: current_user.id) member = @course.students.find_by(user_id: current_user.id)
current_date = Date.current if member.present?
current_end_time = Time.current.strftime("%H:%M:%S") current_date = Date.current
current_end_time = Time.current.strftime("%H:%M:%S")
# 先算出该学生所在分班的签到id
# 分班id为0 表示签到不限制分班 # 先算出该学生所在分班的签到id
group_ids = [member&.course_group_id.to_i, 0] # 分班id为0 表示签到不限制分班
all_attendance_ids = @course.course_attendance_groups.where(course_group_id: group_ids).pluck(:course_attendance_id) 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). history_attendance_ids = member.course_member_attendances.where(course_id: @course.id).pluck(:course_attendance_id)
where("attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}'")
@history_count = @history_attendances.size @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")
student_attendance_ids = @history_attendances.pluck(:id) @current_attendance = @course.course_attendances.where(id: all_attendance_ids.uniq).
student_attendance_ids += @current_attendance.present? ? @current_attendance.pluck(:id) : [] 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? @all_history_count = @history_attendances.size
@normal_count = 0 @history_attendances = paginate @history_attendances.includes(:course_member_attendances)
@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
end end
@all_history_count = @history_attendances.size
@history_attendances = paginate @history_attendances.includes(:course_member_attendances)
end end
def show def show
@ -84,12 +90,13 @@ class Weapps::AttendancesController < ApplicationController
@_is_current_attendance = @attendance.current_attendance? @_is_current_attendance = @attendance.current_attendance?
if @attendance.course_attendance_groups.first&.course_group_id.to_i == 0 if @attendance.course_attendance_groups.first&.course_group_id.to_i == 0
@groups = @course.course_groups @group_ids = @course.course_groups.pluck(:id) + [0]
else else
@groups = @course.course_groups.where(id: @attendance.course_attendance_groups.pluck(:course_group_id)) @group_ids = @attendance.course_attendance_groups.pluck(:course_group_id)
end end
@groups = @groups.includes(:course_members) if @_is_current_attendance @groups = @course.course_groups.where(id: @group_ids)
@course_members = @course.students if @_is_current_attendance
@all_attendances = @attendance.course_member_attendances @all_attendances = @attendance.course_member_attendances
end end

@ -4,13 +4,27 @@ class Weapps::CourseMemberAttendancesController < ApplicationController
def index def index
attendance = CourseAttendance.find params[:attendance_id] attendance = CourseAttendance.find params[:attendance_id]
if attendance.course_attendance_groups.first&.course_group_id.to_i == 0
@members = attendance.course.students
else
@members = attendance.course.students.where(course_group_id: attendance.course_attendance_groups.pluck(:course_group_id))
end
@member_attendances = attendance.course_member_attendances @member_attendances = attendance.course_member_attendances
if params[:group_ids].present? if params[:group_ids].present?
@member_attendances = @member_attendances.joins(:course_member).where(course_members: {course_group_id: params[:group_ids]}) @members = @members.where(course_group_id: params[:group_ids])
end
if params[:attendance_status].present?
@members = @members.joins(:course_member_attendances).where(course_member_attendances: {course_attendance_id: attendance.id, attendance_status: params[:attendance_status]})
end end
@member_attendances = @member_attendances.where(attendance_status: params[:attendance_status]) if params[:attendance_status].present?
@member_attendances = @member_attendances.joins(user: :user_extension).order("attendance_status=1 desc, course_member_attendances.updated_at desc, user_extensions.student_id asc") @members = @members.joins(:course_member_attendances).order("attendance_status=1 desc, course_member_attendances.updated_at desc")
@member_attendances = paginate @member_attendances.preload(user: :user_extension) @members_count = @members.uniq.count
@members = paginate @members.preload(user: :user_extension).uniq
# @member_attendances = @member_attendances.where(attendance_status: params[:attendance_status]) if params[:attendance_status].present?
# @member_attendances = @member_attendances.joins(user: :user_extension).order("attendance_status=1 desc, course_member_attendances.updated_at desc, user_extensions.student_id asc")
# @member_attendances = paginate @member_attendances.preload(user: :user_extension)
end end
def create def create

@ -8,18 +8,32 @@ class Weapps::CoursesController < Weapps::BaseController
def course_activities def course_activities
@course = current_course @course = current_course
homework_commons = @course.homework_commons.where(homework_type: ["practice", "normal"]).homework_published
member = @course.course_members.find_by(user_id: current_user.id, is_active: 1) member = @course.course_members.find_by(user_id: current_user.id, is_active: 1)
# 签到数据
attendances = @course.course_attendances
current_date = Date.current
current_end_time = Time.current.strftime("%H:%M:%S")
if @user_course_identity == Course::STUDENT
attendances = attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: [member.try(:course_group_id).to_i, 0]})
.where("attendance_date < '#{current_date}' or (attendance_date = '#{current_date}' and start_time < '#{current_end_time}')")
end
attendance_ids = attendances.blank? ? "(-1)" : "(" + attendances.pluck(:id).join(",") + ")"
homework_commons = @course.homework_commons.where(homework_type: ["practice", "normal"]).homework_published
if (@user_course_identity == Course::STUDENT && member.try(:course_group_id).to_i == 0) || @user_course_identity > Course::STUDENT if (@user_course_identity == Course::STUDENT && member.try(:course_group_id).to_i == 0) || @user_course_identity > Course::STUDENT
homework_commons = homework_commons.unified_setting homework_commons = homework_commons.unified_setting
elsif @user_course_identity == Course::STUDENT elsif @user_course_identity == Course::STUDENT
not_homework_ids = @course.homework_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}").pluck(:homework_common_id) not_homework_ids = @course.homework_group_settings.none_published.where("course_group_id = #{member.try(:course_group_id)}")
.pluck(:homework_common_id)
homework_commons = homework_commons.where.not(id: not_homework_ids) homework_commons = homework_commons.where.not(id: not_homework_ids)
end end
homework_ids = homework_commons.blank? ? "(-1)" : "(" + homework_commons.pluck(:id).join(",") + ")" homework_ids = homework_commons.blank? ? "(-1)" : "(" + homework_commons.pluck(:id).join(",") + ")"
activities = @course.course_activities.where("course_act_type in ('Course', 'CourseMessage') or activities = @course.course_activities.where("course_act_type in ('Course', 'CourseMessage') or
(course_act_type = 'HomeworkCommon' and course_act_id in #{homework_ids})").order("id desc") (course_act_type = 'HomeworkCommon' and course_act_id in #{homework_ids}) or
(course_act_type = 'CourseAttendance' and course_act_id in #{attendance_ids})").order("id desc")
@activities_count = activities.size @activities_count = activities.size
@activities = paginate activities.includes(:course_act, user: :user_extension) @activities = paginate activities.includes(:course_act, user: :user_extension)
end end

@ -5,9 +5,9 @@ module Weapps::AttendancesHelper
st_attendance.present? ? st_attendance.attendance_status : "ABSENCE" st_attendance.present? ? st_attendance.attendance_status : "ABSENCE"
end end
def group_attendance_count attendances, group def group_attendance_count attendances, member_ids
course_member_ids = group.course_members.pluck(:id) # course_member_ids = group.course_members.pluck(:id)
attendances.select{|attendance| course_member_ids.include?(attendance.course_member_id) && attendance.attendance_status == "NORMAL"}.size attendances.select{|attendance| member_ids.include?(attendance.course_member_id) && attendance.attendance_status == "NORMAL"}.size
end end
def history_member_count member_attendances, status, attendance_id def history_member_count member_attendances, status, attendance_id

@ -22,7 +22,7 @@ class HomeworkEndUpdateScoreJob < ApplicationJob
challenge_settings = homework.homework_challenge_settings challenge_settings = homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun| myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first 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)) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings
end end

@ -10,9 +10,11 @@ class StudentJoinAttendanceRecordJob < ApplicationJob
current_end_time = Time.current.strftime("%H:%M:%S") current_end_time = Time.current.strftime("%H:%M:%S")
group_ids = member.course_group_id == 0 ? [0] : [member.course_group_id, 0] 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) where("(attendance_date = '#{current_date}' and start_time <= '#{current_end_time}' and end_time > '#{current_end_time}') or (attendance_date > '#{current_date}')").pluck(:id)
all_group_attendance_ids = course.course_attendances.joins(:course_attendance_groups).where(course_attendance_groups: {course_group_id: 0}).pluck(:id)
member.course_member_attendances.where.not(course_attendance_id: all_group_attendance_ids+current_attendance_ids).delete_all
attrs = %i[course_attendance_id user_id course_member_id course_id course_group_id created_at updated_at] attrs = %i[course_attendance_id user_id course_member_id course_id course_group_id created_at updated_at]
@ -21,7 +23,9 @@ class StudentJoinAttendanceRecordJob < ApplicationJob
CourseMemberAttendance.bulk_insert(*attrs) do |worker| CourseMemberAttendance.bulk_insert(*attrs) do |worker|
current_attendance_ids.each do |attendance_id| 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 end
end end

@ -95,6 +95,8 @@ class Course < ApplicationRecord
has_many :course_attendance_groups has_many :course_attendance_groups
has_many :course_member_attendances has_many :course_member_attendances
has_many :teacher_group_records, dependent: :destroy
validate :validate_sensitive_string validate :validate_sensitive_string
scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) }

@ -2,10 +2,11 @@ class CourseActivity < ApplicationRecord
belongs_to :course_act, polymorphic: true belongs_to :course_act, polymorphic: true
belongs_to :course belongs_to :course
belongs_to :user belongs_to :user
belongs_to :exercise belongs_to :exercise, optional: true
belongs_to :poll belongs_to :poll, optional: true
belongs_to :course_message belongs_to :course_message, optional: true
belongs_to :homework_common belongs_to :homework_common, optional: true
belongs_to :course_attendance, optional: true
# after_create :add_course_lead # after_create :add_course_lead

@ -9,13 +9,15 @@ class CourseAttendance < ApplicationRecord
has_many :course_attendance_groups, dependent: :destroy has_many :course_attendance_groups, dependent: :destroy
has_many :course_member_attendances, dependent: :destroy has_many :course_member_attendances, dependent: :destroy
validates :name, presence: true has_one :course_act, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
validates :name, presence: true, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :mode, presence: true validates :mode, presence: true
validates :attendance_date, presence: true validates :attendance_date, presence: true
validates :start_time, presence: true validates :start_time, presence: true
validates :end_time, presence: true validates :end_time, presence: true
after_create :generate_attendance_code after_create :generate_attendance_code, :act_as_course_activity
# 正常签到人数 # 正常签到人数
def normal_count def normal_count
@ -43,6 +45,11 @@ class CourseAttendance < ApplicationRecord
a_start_time < Time.current && Time.current < a_end_time a_start_time < Time.current && Time.current < a_end_time
end end
#课程动态公共表记录
def act_as_course_activity
CourseActivity.create(user_id: user_id, course_id: course_id, course_act: self)
end
# 延迟生成邀请码 # 延迟生成邀请码
def attendance_code def attendance_code
return generate_attendance_code return generate_attendance_code

@ -9,6 +9,8 @@ class CourseGroup < ApplicationRecord
has_many :homework_group_settings, :dependent => :destroy has_many :homework_group_settings, :dependent => :destroy
scope :by_group_ids, lambda { |ids| where(id: ids)} scope :by_group_ids, lambda { |ids| where(id: ids)}
has_many :course_attendance_groups, dependent: :destroy
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" } validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班" validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班"

@ -24,10 +24,8 @@ class CourseMember < ApplicationRecord
# after_destroy :delete_works # after_destroy :delete_works
# after_create :work_operation # after_create :work_operation
after_create :create_attendance_record after_create :create_attendance_record
after_commit :create_attendance_record
def create_attendance_record
StudentJoinAttendanceRecordJob.perform_later(id)
end
def delete_works def delete_works
if self.role == "STUDENT" if self.role == "STUDENT"
@ -163,4 +161,11 @@ class CourseMember < ApplicationRecord
end end
teachers teachers
end end
private
def create_attendance_record
StudentJoinAttendanceRecordJob.perform_later(id)
end
end end

@ -104,7 +104,7 @@ class HomeworkCommon < ApplicationRecord
end end
def user_work user_id def user_work user_id
work = self.student_works.find_by_user_id(user_id) || StudentWork.create!(homework_common_id: id, user_id: user_id) work = StudentWork.find_by(homework_common_id: id, user_id: user_id) || StudentWork.create!(homework_common_id: id, user_id: user_id)
end end
# 是否在补交阶段内 # 是否在补交阶段内

@ -0,0 +1,4 @@
class TeacherGroupRecord < ApplicationRecord
belongs_to :user
belongs_to :course
end

@ -160,6 +160,8 @@ class User < ApplicationRecord
has_many :examination_banks, dependent: :destroy has_many :examination_banks, dependent: :destroy
has_many :examination_intelligent_settings, dependent: :destroy has_many :examination_intelligent_settings, dependent: :destroy
has_many :teacher_group_records, dependent: :destroy
# Groups and active users # Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) } scope :active, lambda { where(status: STATUS_ACTIVE) }

@ -3,15 +3,15 @@ class Admins::UserSchoolsStatisticQuery < ApplicationQuery
attr_reader :params attr_reader :params
sort_columns :study_challenge_count, :finish_challenge_count, :study_shixun_count, :finish_shixun_count, sort_columns :cnt,
default_by: :finish_challenge_count, default_direction: :desc default_by: :cnt, default_direction: :desc
def initialize(params) def initialize(params)
@params = params @params = params
end end
def call def call
schools = School.all schools = School
if params[:province].present? if params[:province].present?
schools = schools.where("province like ?", "%#{params[:province]}%") schools = schools.where("province like ?", "%#{params[:province]}%")
end end
@ -22,14 +22,11 @@ class Admins::UserSchoolsStatisticQuery < ApplicationQuery
total = schools.count total = schools.count
# 根据排序字段进行查询 # 根据排序字段进行查询
#schools = query_by_sort_column(schools, params[:sort_by]) schools = query_by_sort_column(schools.group(:id), params[:sort_by])
#schools = custom_sort(schools, params[:sort_by], params[:sort_direction]) #schools = custom_sort(schools, params[:sort_by], params[:sort_direction])
#
schools = schools.limit(page_size).offset(offset).to_a schools = schools.limit(page_size).offset(offset).to_a
# 查询并组装其它数据 # 查询并组装其它数据
schools = package_other_data(schools) schools = package_other_data(schools)
[total, schools] [total, schools]
end end
@ -83,56 +80,14 @@ class Admins::UserSchoolsStatisticQuery < ApplicationQuery
schools schools
end end
def query_by_sort_column(users, sort_by_column) def query_by_sort_column(schools, sort_by_column)
base_query_column = 'users.*' #base_query_column = 'schools.*'
case sort_by_column.to_s case sort_by_column.to_s
when 'study_shixun_count' then when 'cnt' then
users = schools.left_joins(:user_extensions).select("schools.*, count(*) cnt").order("cnt desc")
if time_range.present?
users.joins("LEFT JOIN myshixuns ON myshixuns.user_id = users.id "\
"AND myshixuns.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
else
users.left_joins(:myshixuns)
end
users.select("#{base_query_column}, COUNT(*) study_shixun_count")
when 'finish_shixun_count' then
users =
if time_range.present?
users.joins("LEFT JOIN myshixuns ON myshixuns.user_id = users.id AND myshixuns.status = 1 AND "\
"myshixuns.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
else
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id AND myshixuns.status = 1')
end
users.select("#{base_query_column}, COUNT(*) finish_shixun_count")
when 'study_challenge_count' then
users =
if time_range.present?
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
.joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id "\
"AND games.status IN (0,1,2) AND games.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
else
users.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
.joins("LEFT JOIN games ON games.myshixun_id = myshixuns.id AND games.status IN (0,1,2)")
end
users.select("#{base_query_column}, COUNT(*) study_challenge_count")
when 'finish_challenge_count' then
users =
if time_range.present?
users#.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
.joins("LEFT JOIN games ON games.user_id = users.id "\
"AND games.status = 2 AND games.updated_at BETWEEN '#{time_range.min}' AND '#{time_range.max}'")
else
users#.joins('LEFT JOIN myshixuns ON myshixuns.user_id = users.id')
.joins("LEFT JOIN games ON games.user_id = users.id AND games.status = 2")
end
users.select("#{base_query_column}, COUNT(*) finish_challenge_count")
else else
users schools
end end
end end

@ -19,6 +19,11 @@ class Weapps::SubjectQuery < ApplicationQuery
subjects = subjects.joins(:sub_discipline_containers).where(sub_discipline_containers: {container_type: "Subject"}) subjects = subjects.joins(:sub_discipline_containers).where(sub_discipline_containers: {container_type: "Subject"})
end end
# 搜索
if params[:keyword].present?
subjects = subjects.where("subjects.name like '%#{params[:keyword]}%'")
end
subjects = subjects.left_joins(:shixuns, :repertoire).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show, subjects = subjects.left_joins(:shixuns, :repertoire).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show,
subjects.shixuns_count, subjects.repertoire_id, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count') subjects.shixuns_count, subjects.repertoire_id, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count')
.group('subjects.id').order("subjects.homepage_show #{sort_type}, #{order_type} #{sort_type}") .group('subjects.id').order("subjects.homepage_show #{sort_type}, #{order_type} #{sort_type}")

@ -13,7 +13,7 @@ json.identifier shixun.identifier
json.name shixun.name json.name shixun.name
json.stu_num shixun.myshixuns_count json.stu_num shixun.myshixuns_count
json.experience shixun.all_score json.experience shixun.all_score
json.diffcult diff_to_s(shixun.trainee) json.diffcult level_to_s(shixun.trainee)
json.score_info shixun.shixun_preference_info # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。 json.score_info shixun.shixun_preference_info # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。
json.is_jupyter shixun.is_jupyter json.is_jupyter shixun.is_jupyter
# 用于是否显示导航栏中的'背景知识' # 用于是否显示导航栏中的'背景知识'

@ -42,7 +42,7 @@ json.top do
# 云上实验室管理权限 # 云上实验室管理权限
laboratory_user = current_laboratory.laboratory_users.exists?(user_id: @user&.id) || @user&.admin_or_business? laboratory_user = current_laboratory.laboratory_users.exists?(user_id: @user&.id) || @user&.admin_or_business?
json.laboratory_user laboratory_user # json.laboratory_user laboratory_user
json.laboratory_admin_url laboratory_user ? "/cooperative" : nil json.laboratory_admin_url laboratory_user ? "/cooperative" : nil
end end

@ -9,7 +9,22 @@ json.attendance_date @attendance.attendance_date.strftime("%Y/%m/%d")
json.start_time @attendance.start_time.strftime("%H:%M") json.start_time @attendance.start_time.strftime("%H:%M")
json.end_time @attendance.end_time.strftime("%H:%M") json.end_time @attendance.end_time.strftime("%H:%M")
json.course_groups @groups do |group| # json.course_groups @group_ids do |group|
json.(group, :id, :name, :course_members_count) # json.(group, :id, :name, :course_members_count)
json.attendance_count group_attendance_count(@all_attendances, group) if @_is_current_attendance # json.attendance_count group_attendance_count(@all_attendances, group) if @_is_current_attendance
# end
json.course_groups @group_ids do |group_id|
if group_id != 0
group = @groups.select{|group| group.id == group_id}.first
json.(group, :id, :name, :course_members_count)
else
json.id 0
json.name "未分班"
json.course_members_count @course.none_group_count
end
if @_is_current_attendance
member_ids = @course_members.select{|member| member.course_group_id == group_id}.map(&:id)
json.attendance_count group_attendance_count(@all_attendances, member_ids)
end
end end

@ -1,5 +1,14 @@
json.member_attendances @member_attendances.each do |member| # json.member_attendances @member_attendances.each do |member|
json.(member, :user_id, :attendance_status) # json.(member, :user_id, :attendance_status)
# json.user_name member.user&.real_name
# json.student_id member.user&.student_id
# end
json.member_attendances @members.each do |member|
json.(member, :user_id)
json.user_name member.user&.real_name json.user_name member.user&.real_name
json.student_id member.user&.student_id json.student_id member.user&.student_id
end json.attendance_status @member_attendances.select{|attendance| attendance.course_member_id == member.id}.first&.attendance_status || "ABSENCE"
end
json.members_count @members_count

@ -0,0 +1,13 @@
class CreateTeacherGroupRecords < ActiveRecord::Migration[5.2]
def change
create_table :teacher_group_records do |t|
t.references :user
t.references :course
t.integer :group_id
t.timestamps
end
add_index :teacher_group_records, [:user_id, :course_id], unique: true
end
end

@ -2,16 +2,18 @@ desc "同步学院或者单位评测数"
namespace :sync_evaluate do namespace :sync_evaluate do
task outpus_count: :environment do task outpus_count: :environment do
School.find_each do |school| School.find_in_batches(batch_size: 500) do |school|
puts school.id Parallel.each_with_index(school, in_processes: 5) do |s|
evaluate_count = Game.find_by_sql("select sum(g.evaluate_count) as e_count from games g, user_extensions ue where puts "school_id:#{s.id}"
g.user_id = ue.user_id and ue.school_id = '#{school.id}'").first.try(:e_count) evaluate_count = Game.find_by_sql("select sum(g.evaluate_count) as e_count from games g, user_extensions ue where
g.user_id = ue.user_id and ue.school_id = '#{s.id}'").first.try(:e_count)
report = SchoolReport.find_or_initialize_by(school_id: school.id) report = SchoolReport.find_or_initialize_by(school_id: s.id)
report.school_name = school.name report.school_name = s.name
report.shixun_evaluate_count = evaluate_count report.shixun_evaluate_count = evaluate_count
report.save report.save
end
end end
end end
end end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe TeacherGroupRecord, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save