diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6fa694fbf..79b22d571 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1519,7 +1519,7 @@ class ExercisesController < ApplicationController if exercise.present? if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷 - if (exercise_user_status == exercise_status) || exercise_status == Exercise::ENDED #未发布的情况 + if (exercise_user_status == exercise_status) || exercise_status == Exercise::DEADLINE #未发布的情况 unpublish_group = unpublish_group + user_groups_id end else @@ -1527,7 +1527,7 @@ class ExercisesController < ApplicationController ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级 if exercise_status == Exercise::UNPUBLISHED unpublish_group = user_groups_id - ex_group_settings - elsif exercise_status == Exercise::ENDED + elsif exercise_status == Exercise::DEADLINE ex_ended_groups = ex_all_group_settings.exercise_group_ended.pluck(:course_group_id).uniq ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班 unpublish_group = unpublish_group + ex_and_user - ex_ended_groups #已发布的全部班级减去截止的全部班级 @@ -1627,7 +1627,7 @@ class ExercisesController < ApplicationController def check_exercise_public if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first - unless @exercise.get_exercise_status(current_user) == Exercise::ENDED && ex_user.present? && ex_user.commit_status == 1 && + unless @exercise.get_exercise_status(current_user) == Exercise::DEADLINE && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic normal_status(-1,"学生暂不能查看") end @@ -1650,7 +1650,7 @@ class ExercisesController < ApplicationController ex_question_random = exercise.question_random question_answered = 0 exercise_questions.each_with_index do |q,index| - if ex_question_random && exercise_user_status != Exercise::ENDED + if ex_question_random && exercise_user_status != Exercise::DEADLINE ques_number = index + 1 else ques_number = q.question_number diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 969296539..1f7433f8b 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -819,38 +819,69 @@ class HomeworkCommonsController < ApplicationController # 选用实训 def shixuns - search = params[:search] - type = params[:type] - # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) - if current_user.admin? - @shixuns = Shixun.unhidden - else - none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") + @homework_category = @main_catrgory.take.course_second_categories - @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden + ## 我的实训 + @shixuns = + if params[:order_by] == 'mine' + current_user.my_shixuns.unhidden + else + if current_user.admin? + Shixun.unhidden + else + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + + @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden + end + end + + ## 方向 + if params[:tag_level].present? && params[:tag_id].present? + @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) + case params[:tag_level].to_i + when 1 #大类 + @search_tags = Repertoire.find(params[:tag_id].to_i).name + when 2 #子类 + @search_tags = SubRepertoire.find(params[:tag_id].to_i).name + when 3 #tag + tag = TagRepertoire.find(params[:tag_id].to_i) + @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" + end end - # 实训的所有标签 - @tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct + ## 搜索关键字创建者、实训名称、院校名称 + if params[:keyword].present? + keyword = params[:keyword].strip + @shixuns = @shixuns.joins(user: [user_extenison: :school]). + where("schools.name like '%#{keyword}%' + or concat(lastname, firstname) like '%#{keyword}%' + or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct + end - if params[:search] && params[:search].strip != "" - @shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?", - "%#{search}%", "%#{search}%").distinct + ## 筛选 难度 + if params[:diff].present? && params[:diff].to_i != 0 + @shixuns = @shixuns.where(trainee: params[:diff]) end - unless type.blank? || type == "all" - @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct + ## 排序参数 + bsort = params[:sort] || 'desc' + case params[:order_by] || 'hot' + when 'hot' + @shixuns = @shixuns.order("myshixuns_count #{bsort}") + when 'mine' + @shixuns = @shixuns.order("shixuns.created_at #{bsort}") + else + @shixuns = @shixuns.order("myshixuns_count #{bsort}") end - @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier]).reorder("shixuns.created_at desc") - @shixuns_count = @shixuns.size + @total_count = @shixuns.count ## 分页参数 - page = params[:page] || 1 - @shixuns = @shixuns.page(page).per(10) + page = params[:page] || 1 + limit = params[:limit] || 15 - @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") - @homework_category = @main_catrgory.take.course_second_categories + @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) end def create_shixun_homework @@ -876,30 +907,65 @@ class HomeworkCommonsController < ApplicationController # 选用实训课程 def subjects + @tags = Repertoire.where(nil).order("updated_at desc") + select = params[:select] # 路径导航类型 + reorder = params[:order] || "myshixun_count" + sort = params[:sort] || "desc" search = params[:search] - type = params[:type] - # 显示所有未隐藏的、已发布的实训课程 - @subjects = Subject.select([:id, :name, :status, :repertoire_id]).visible.unhidden - @tags = Repertoire.select([:id, :name]).where(id: @subjects.pluck(:repertoire_id).uniq).order("updated_at desc") + ## 分页参数 + page = params[:page] || 1 + limit = params[:limit] || 15 + offset = (page.to_i-1) * limit + + # 最热排序 + if reorder == "myshixun_count" + if select + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") + else + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") + end + else + # 我的路径 + if reorder == "mine" + mine_subject_id = StageShixun.find_by_sql("select DISTINCT(subject_id) from stage_shixuns where shixun_id in + (select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id) + manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id) + total_subject_id = (mine_subject_id + manage_subject_id).uniq + @subjects = Subject.where(id: total_subject_id) + end - if params[:search] && params[:search].strip != "" - @subjects = @subjects.joins(:user).where("subjects.name like ? or concat(users.lastname, users.firstname) like ?", - "%#{search}%", "%#{search}%") - end + # 类型 + if select + @subjects = @subjects.where(repertoire_id: select) + end - unless type.blank? || type == "all" - @subjects = @subjects.where(repertoire_id: type) - end + if search.present? + @subjects = @subjects.where("name like ?", "%#{search}%") + end - @subjects = @subjects.reorder("subjects.created_at desc") - @subjects_count = @subjects.size + # 排序 + order_str = "updated_at #{sort}" + @subjects = @subjects.reorder(order_str) + end - ## 分页参数 - page = params[:page] || 1 - @subjects = @subjects.page(page).per(10) + @total_count = @subjects.size - @subjects = @subjects.includes(:shixuns) + if reorder != "myshixun_count" + @subjects = @subjects.page(page).per(limit).includes(:shixuns, user: [user_extension: :school]) + else + @subjects = @subjects[offset, limit] + subject_ids = @subjects.pluck(:id) + @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, user: [user_extension: :school]) + end end def create_subject_homework diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 3e73931e0..92816d68b 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,6 +89,7 @@ module ExercisesHelper questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers + if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -98,13 +99,16 @@ module ExercisesHelper ques_less_title = ex.question_title effictive_users = ex.exercise_shixun_answers.search_shixun_answers("user_id",user_ids) end - effictive_users_count = effictive_users.count #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 + + effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 + if ex_total_score == 0.0 percent = 0.0 else percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 end + question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #单选题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 79701767f..e7d141ea9 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -135,7 +135,7 @@ class Exercise < ApplicationRecord if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now status = Exercise::PUBLISHED elsif ed_time.present? && ed_time <= Time.now - status = Exercise::ENDED + status = Exercise::DEADLINE else status = Exercise::UNPUBLISHED end diff --git a/app/models/subject.rb b/app/models/subject.rb index d0b3e7aed..b9dd49f5a 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -91,4 +91,9 @@ class Subject < ApplicationRecord def published? status == 2 end + + def shixun_tags + challenges = Challenge.where(shixun_id: shixuns.unhidden) + @tags = ChallengeTag.where(challenge_id: challenges).pluck(:name).uniq + end end \ No newline at end of file diff --git a/app/views/homework_commons/shixuns.json.jbuilder b/app/views/homework_commons/shixuns.json.jbuilder index 129a0b6d3..8bfeea562 100644 --- a/app/views/homework_commons/shixuns.json.jbuilder +++ b/app/views/homework_commons/shixuns.json.jbuilder @@ -1,12 +1,15 @@ -json.tags @tags do |tag| - json.tag_id tag.id - json.tag_name tag.name +json.shixun_list @shixuns do |shixun| + json.shixun_identifier shixun.identifier + json.name shixun.name + json.creator shixun.user&.full_name + json.creator_login shixun.user&.login + json.school shixun.user&.school_name + json.myshixuns_count shixun.myshixuns_count + json.level level_to_s(shixun.trainee) + json.challenge_tags shixun.challenge_tags_name end -json.shixun_list do - json.partial! 'shixuns/choose_shixun', locals: {shixuns: @shixuns} -end - -json.shixuns_count @shixuns_count +json.shixuns_count @total_count +json.search_tags @search_tags json.partial! 'homework_commons/second_category', locals: {main_catrgory: @main_catrgory, homework_category: @homework_category} \ No newline at end of file diff --git a/app/views/homework_commons/subjects.json.jbuilder b/app/views/homework_commons/subjects.json.jbuilder index ea63f2125..257fcc9d5 100644 --- a/app/views/homework_commons/subjects.json.jbuilder +++ b/app/views/homework_commons/subjects.json.jbuilder @@ -6,8 +6,12 @@ end json.subject_list @subjects do |subject| json.subject_id subject.id json.subject_name subject.name + json.challenge_tags subject.shixun_tags json.shixun_count subject.shixuns.unhidden.size json.myshixun_count subject.shixuns.pluck(:myshixuns_count).sum + json.creator subject.user&.full_name + json.creator_login subject.user&.login + json.school subject.user&.school_name end -json.subjects_count @subjects_count \ No newline at end of file +json.subjects_count @total_count \ No newline at end of file diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index cadce7465..7fa1c0edb 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -36,7 +36,7 @@ module Educoder params['mobile'] = mobile params['text'] = "" if send_type.nil? - params['text'] = "【Edu实训】" + code + "(手机验证码)。如非本人操作,请忽略。" + params['text'] = "【Edu实训】" + code + "(手机验证码),有效期为10分钟。如非本人操作,请忽略。" elsif send_type == 'competition_start' params['text'] = "【Edu实训】亲爱的#{user_name},你参与的#{name}将于#{result}开始,请及时参赛" Rails.logger.info "#{params['text']}"