资源刷新不调用接口的问题

courseware
dinglink 5 years ago
commit 48a4f91e32

@ -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]
# 如果新增的的分班加上之前的分班是课堂的全部分班,则只需创建一条记录
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

@ -1306,7 +1306,7 @@ class CoursesController < ApplicationController
@user = current_user
@switch_student = Course::BUSINESS < @user_course_identity && @user_course_identity < Course::STUDENT
@is_student = @user_course_identity == Course::STUDENT
@teacher_users = @course.teacher_users.where.not(id: @course.tea_id).map(&:real_name)[0..2]
@teacher_users = @course.teacher_users.where.not(id: @course.tea_id).map(&:real_name)[0..3]
@course.increment!(:visits)
end

@ -614,31 +614,21 @@ class ExerciseQuestionsController < ApplicationController
@exercise_current_user.update!(ex_scores)
end
comments = params[:comment]
question_comment = @exercise_question.exercise_answer_comments&.first
if question_comment.present?
comment_option = {
:comment => comments,
:score => @c_score,
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
:user_id => current_user.id
}
question_comment.update!(comment_option)
@exercise_comments = question_comment
if @exercise_question.question_type == Exercise::PRACTICAL
shixun_answer = ExerciseShixunAnswer.find_by(exercise_question_id: @exercise_question.id, user_id: @user_id, exercise_shixun_challenge_id: @shixun_a_id)
answer_comment = shixun_answer&.exercise_answer_comments.take
else
ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)
comment_option = {
:user_id => current_user.id,
:comment => comments,
:score => @c_score,
:exercise_question_id => @exercise_question.id,
:exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil,
:exercise_answer_id => ex_answer_comment_id
}
@exercise_comments = ExerciseAnswerComment.new(comment_option)
@exercise_comments.save!
question_answer = ExerciseAnswer.find_by(exercise_question_id: @exercise_question.id, user_id: @user_id)
answer_comment = question_answer&.exercise_answer_comments.take
end
# 给被评阅人发送消息,同一个教师评阅无需重复发消息
if answer_comment.present?
answer_comment.update!(:comment => comments, :score => @c_score)
else
ExerciseAnswerComment.create!(:comment => comments, :score => @c_score, :user_id => current_user.id,
:exercise_question_id => @exercise_question.id, :exercise_shixun_answer_id => shixun_answer&.id,
:exercise_answer_id => question_answer&.id)
unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists?
Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id,
@ -646,8 +636,42 @@ class ExerciseQuestionsController < ApplicationController
parent_container_type: "ExerciseScore", belong_container_id: @course.id,
belong_container_type: 'Course', tiding_type: "Exercise")
end
end
# question_comment = @exercise_question.exercise_answer_comments&.first
#
# if question_comment.present?
# comment_option = {
# :comment => comments,
# :score => @c_score,
# :exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
# :user_id => current_user.id
# }
# question_comment.update!(comment_option)
# @exercise_comments = question_comment
# else
# ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)
# comment_option = {
# :user_id => current_user.id,
# :comment => comments,
# :score => @c_score,
# :exercise_question_id => @exercise_question.id,
# :exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil,
# :exercise_answer_id => ex_answer_comment_id
# }
# @exercise_comments = ExerciseAnswerComment.new(comment_option)
# @exercise_comments.save!
#
# # 给被评阅人发送消息,同一个教师评阅无需重复发消息
#
# unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists?
# Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id,
# container_type: "Exercise", parent_container_id: @exercise.id,
# parent_container_type: "ExerciseScore", belong_container_id: @course.id,
# belong_container_type: 'Course', tiding_type: "Exercise")
# end
#
# end
end
end

@ -816,7 +816,7 @@ class ExercisesController < ApplicationController
ex_user_ids = exercise_users.pluck(:id)
EndExerciseCalculateJob.perform_later(ex_user_ids, exercise, Time.now.to_s, true, 4)
EndExerciseCalculateJob.perform_later(ex_user_ids, exercise.id, Time.now.to_s, true, 4)
# exercise_users.each do |user|
# if user.commit_status == 0 && user.start_at.present?
# objective_score = calculate_student_score(exercise,user.user)[:total_score]
@ -1194,7 +1194,7 @@ class ExercisesController < ApplicationController
start_time = Time.current - @exercise.time * 60
ex_user_ids = @exercise_users_list.where("start_at <= '#{Time.at(start_time)}' and commit_status = 0").pluck(:id)
if ex_user_ids.size > 0
EndExerciseCalculateJob.perform_later(ex_user_ids, @exercise, Time.now.to_s, false, 2)
EndExerciseCalculateJob.perform_later(ex_user_ids, @exercise.id, Time.now.to_s, false, 2)
end
end

@ -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

@ -76,7 +76,7 @@ class Weapps::CoursesController < Weapps::BaseController
def show
@course = current_course
@current_user = current_user
@teacher_users = @course.teacher_users.where.not(id: @course.tea_id).map(&:real_name)[0..2]
@teacher_users = @course.teacher_users.where.not(id: @course.tea_id).map(&:real_name)[0..3]
end
def shixun_homework_category

@ -7,7 +7,7 @@ class CourseVideoUploadedJob < ApplicationJob
return unless course_ids.present?
course_members = CourseMember.where(course_id: course_ids, role: 'STUDENT').select("user_id, course_id")
course_members = CourseMember.where(course_id: course_ids, role: 'STUDENT').select("id, user_id, course_id")
Tiding.bulk_insert do |worker|
course_members.find_each do |m|
worker.add(

@ -5,7 +5,9 @@ class EndExerciseCalculateJob < ApplicationJob
queue_as :default
def perform(ex_user_ids,exercise,end_time,work_time,commit_method)
def perform(ex_user_ids,exercise_id,end_time,work_time,commit_method)
exercise = Exercise.find_by(id: exercise_id)
return if exercise.blank?
exercise_users = ExerciseUser.where(id: ex_user_ids)
exercise_users.each do |user|
if user.commit_status == 0 && user.start_at.present?

@ -11,7 +11,7 @@ module UserOnline
def set_bit(user_id, flag)
if !Rails.cache.data.exists(cache_key)
Rails.cache.data.setbit(cache_key, user_id, flag)
Rails.cache.data.expire(cache_key, 20 * 60 + 10)
Rails.cache.data.expire(cache_key, 2 * 60 + 10)
else
Rails.cache.data.setbit(cache_key, user_id, flag)
end
@ -27,11 +27,11 @@ module UserOnline
def cache_key
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
# 10分钟为一段记录用户在线, 统计范围为20分钟内的线用户
# 如设置2分钟内即120秒有请求的用户视为在线, 则最大会统计到4分钟内有活动用户
# TODO 更精确时长
begin_hour = Time.now.beginning_of_hour
minutes_piece = (Time.now - begin_hour) / 600
time = begin_hour.since((minutes_piece.to_i - 1) * 600).strftime("%H-%M")
minutes_piece = (Time.now - begin_hour) / 120
time = begin_hour.since((minutes_piece.to_i - 1) * 120).strftime("%H-%M")
"online_user_#{time}"
else
raise '请配置config.cache_store = redis_store'

@ -34,8 +34,10 @@ class Users::ShixunService
def status_filter(relations)
case params[:category]
when 'study', 'collect' then
when 'study' then
study_shixun_status_filter(relations)
when 'collect' then
collect_shixun_status_filter(relations)
when 'manage' then
manage_shixun_status_filter(relations)
else
@ -66,6 +68,16 @@ class Users::ShixunService
relations
end
def collect_shixun_status_filter relations
passed_shixun_ids = user.myshixuns.where(shixun_id: relations, status: 1).pluck(:shixun_id)
if params[:status] == 'passed'
relations = relations.where(id: passed_shixun_ids)
elsif params[:status] == 'processing'
relations = relations.where.not(id: passed_shixun_ids)
end
relations
end
def manage_shixun_status_filter(relations)
if params[:status] == "publiced"
relations = relations.where(public: 2)

@ -13,7 +13,7 @@ json.courses @courses do |course|
json.is_end course.is_end
json.first_category_url module_url(course.none_hidden_course_modules.first, course)
json.excellent course.excellent
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..2] # 取前3名老师
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..3] # 取前4名老师
end
json.courses_count @courses_count

@ -7,7 +7,7 @@ json.homework_commons_count get_tasks_count course
json.attachments_count course.attachments.count
json.visits course.visits
json.school course.school&.name
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..2] # 取前3名老师
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..3] # 取前4名老师
json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course)

@ -26,6 +26,6 @@ json.courses @courses.each do |course|
course_member = @category == "study" ? course.students.where(user_id: @user.id).first : course.teachers.where(user_id: @user.id).first
json.sticky course_member.sticky
json.course_identity current_user.course_identity(course)
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..2] # 取前3名老师
json.teacher_users course.teacher_users.select{|u| u.id != course.tea_id }.map(&:real_name)[0..3] # 取前4名老师
end

@ -0,0 +1,10 @@
class MigrateExerciseShixunAnswerComment < ActiveRecord::Migration[5.2]
def change
ExerciseAnswerComment.where.not(exercise_shixun_answer_id: ExerciseShixunAnswer.all).where("exercise_shixun_answer_id is not null and exercise_answer_id is not null").each do |answer|
exercise_shixun_answer = ExerciseShixunAnswer.find_by(id: answer.exercise_answer_id)
if exercise_shixun_answer.present?
answer.update_columns(exercise_shixun_answer_id: exercise_shixun_answer&.id)
end
end
end
end

@ -1,6 +1,7 @@
class UniqIndexOnCollections < ActiveRecord::Migration[5.2]
def change
remove_index :collections, [:container_type, :container_id]
add_index :collections, [:container_type, :container_id], unique: true
add_index :collections, [:container_type, :container_id]
add_index :collections, [:user_id, :container_type, :container_id], unique: true
end
end

@ -46,7 +46,11 @@ debugType = "admin";
// 老师
// debugType="teacher";
// 学生
<<<<<<< HEAD
//debugType="student";
=======
// debugType="student";
>>>>>>> 97765680b4f08ade017f6db22b1c76dcb0ae29f7

@ -289,7 +289,7 @@ class InfosPath extends Component{
lineHeight: "41px",
marginTop: "10px",
}}>
<span className="fl color-grey-9">共参与{totalCount}{category?category=="manage"?"发布":"学习":"实践课程"}</span>
<span className="fl color-grey-9">{category && category == "collect" ?"共收藏":"共参与"}{totalCount}{category && category == "collect"?"":category?category=="manage"?"发布":"学习":"实践课程"}</span>
<sapn className="relativef color-grey-9 fr"
style={{
display: "flex",

@ -309,7 +309,7 @@ class InfosShixun extends Component{
lineHeight: "41px",
marginTop: "10px",
}}>
<span className="fl color-grey-9">共参与{totalCount}{category?category=="manage"?"发布":"学习":"实训"}</span>
<span className="fl color-grey-9">{category && category == "collect"?"共收藏":"共参与"}{totalCount}{category && category == "collect"?"":category?category=="manage"?"发布":"学习":"实训"}</span>
<sapn className="relativef color-grey-9 fr"
style={{
display: "flex",

Loading…
Cancel
Save