diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 23240fa75..99cb013b7 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -185,6 +185,9 @@ class AccountsController < ApplicationController send_type = verify_type(login_type, type) verification_code = code.sample(6).join + sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}") + tip_exception(501, "请求不合理") if sign != params[:smscode] + logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ") # 记录验证码 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index dd015ba9e..f68784db8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,23 +23,23 @@ class ApplicationController < ActionController::Base # 所有请求必须合法签名 def check_sign - # unless Rails.env.development? - # Rails.logger.info("66666 #{params}") - # suffix = request.url.split(".").last.split("?").first - # suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释 - # unless suffix_arr.include?(suffix) - # if params[:client_key].present? - # randomcode = params[:randomcode] - # # tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5) - # - # sign = Digest::MD5.hexdigest("#{OPENKEY}#{randomcode}") - # Rails.logger.info("2222 #{sign}") - # tip_exception(501, "请求不合理") if sign != params[:client_key] - # else - # tip_exception(501, "请求不合理") - # end - # end - # end + if !Rails.env.development? && EduSetting.get("host_name") != "https://test-newweb.educoder.net" + Rails.logger.info("66666 #{params}") + suffix = request.url.split(".").last.split("?").first + suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释 + unless suffix_arr.include?(suffix) + if params[:client_key].present? + randomcode = params[:randomcode] + # tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5) + + sign = Digest::MD5.hexdigest("#{OPENKEY}#{randomcode}") + Rails.logger.info("2222 #{sign}") + tip_exception(501, "请求不合理") if sign != params[:client_key] + else + tip_exception(501, "请求不合理") + end + end + end end # 全局配置参数 @@ -85,8 +85,8 @@ class ApplicationController < ActionController::Base # 题库的访问权限 def bank_visit_auth - tip_exception(-2,"未通过职业认证") if current_user.is_teacher? && !current_user.certification_teacher? && !current_user.admin? && @bank.user_id != current_user.id && @bank.is_public - tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin? || + tip_exception(-2,"未通过职业认证") if current_user.is_teacher? && !current_user.certification_teacher? && !current_user.admin_or_business? && @bank.user_id != current_user.id && @bank.is_public + tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? || (current_user.certification_teacher? && @bank.is_public) end @@ -165,7 +165,7 @@ class ApplicationController < ActionController::Base def find_course return normal_status(2, '缺少course_id参数!') if params[:course_id].blank? @course = Course.find(params[:course_id]) - tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin? + tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin_or_business? rescue Exception => e tip_exception(e.message) end diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index bcb0fa45a..16e9dc2be 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -58,7 +58,7 @@ class CommonsController < ApplicationController 200 end else - current_user.admin? ? 200 : 403 + current_user.admin_or_business? ? 200 : 403 end return normal_status(code, "你没有权限操作!") if code == 403 end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 599a4440c..da9f8240a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -396,7 +396,7 @@ class CoursesController < ApplicationController def teachers @search_str = params[:search].present? ? params[:search].strip : "" - if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 + if @course.try(:id) != 1309 || current_user.admin_or_business? || current_user.try(:id) == 15582 @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3) and LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_str}%") else @@ -441,7 +441,7 @@ class CoursesController < ApplicationController @applications = CourseMessage.unhandled_join_course_requests_by_course(@course). joins("join users on course_messages.course_message_id=users.id"). where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") - if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 + if @course.try(:id) != 1309 || current_user.admin_or_business? || current_user.try(:id) == 15582 teacher_list = @course.course_members.where("course_members.role in (1, 2, 3)") else teacher_list = @course.course_members.where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} @@ -838,7 +838,7 @@ class CoursesController < ApplicationController # 已通过职业认证的教师复制课堂 def duplicate_course - return tip_exception("没有复制权限") unless current_user.admin? || current_user.is_teacher? || current_user.teacher_of_course?(@course) + return tip_exception("没有复制权限") unless current_user.admin_or_business? || current_user.is_teacher? || current_user.teacher_of_course?(@course) return tip_exception("教师职业认证未通过") unless current_user.pro_certification? new_course = @course.self_duplicate @@ -1280,7 +1280,7 @@ class CoursesController < ApplicationController end if @all_members.size == 0 - normal_status(-1,"课堂暂时没有学生") + normal_status(-1,"暂无学生数据") elsif params[:export].present? && params[:export] normal_status(0,"正在下载中") else @@ -1308,7 +1308,7 @@ class CoursesController < ApplicationController end if @all_members.length == 0 - normal_status(-1,"课堂暂时没有学生") + normal_status(-1,"暂无学生数据") elsif params[:export].present? && params[:export] normal_status(0,"正在下载中") else @@ -1404,7 +1404,7 @@ class CoursesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_course @course = Course.find_by!(id: params[:id]) - tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin? + tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin_or_business? end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/exercise_bank_questions_controller.rb b/app/controllers/exercise_bank_questions_controller.rb index 1fd8ad874..46547ecb0 100644 --- a/app/controllers/exercise_bank_questions_controller.rb +++ b/app/controllers/exercise_bank_questions_controller.rb @@ -372,7 +372,7 @@ class ExerciseBankQuestionsController < ApplicationController private def bank_admin - tip_exception(403, "无权限") unless @exercise.user_id == current_user.id || current_user.admin? + tip_exception(403, "无权限") unless @exercise.user_id == current_user.id || current_user.admin_or_business? end def get_exercise diff --git a/app/controllers/exercise_banks_controller.rb b/app/controllers/exercise_banks_controller.rb index 9a35bfcdb..556b445ba 100644 --- a/app/controllers/exercise_banks_controller.rb +++ b/app/controllers/exercise_banks_controller.rb @@ -26,7 +26,7 @@ class ExerciseBanksController < ApplicationController search = params[:search] type = params[:type] # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) - if current_user.admin? + if current_user.admin_or_business? @shixuns = Shixun.unhidden else none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) @@ -67,7 +67,7 @@ class ExerciseBanksController < ApplicationController end def bank_admin - tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin? + tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? end #判断实训是否已选择 diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb index 67f21e85c..fd47df172 100644 --- a/app/controllers/graduation_works_controller.rb +++ b/app/controllers/graduation_works_controller.rb @@ -382,6 +382,7 @@ class GraduationWorksController < ApplicationController tip_exception("成绩不能为空") if params[:score].blank? tip_exception("成绩不能小于零") if params[:score].to_f < 0 tip_exception("成绩不能大于100") if params[:score].to_f.round(1) > 100 + tip_exception("调分原因不能超过100个字符") if params[:comment].present? && params[:comment].length > 100 ActiveRecord::Base.transaction do begin # 分数不为空的历史评阅都置为失效 @@ -410,7 +411,7 @@ class GraduationWorksController < ApplicationController # 删除教师/教辅的评分记录 def delete_score score = @work.graduation_work_scores.where(id: params[:comment_id]).first - if score.present? && (score.is_invalid || score.score.nil?) && (score.user == current_user || current_user.admin?) + if score.present? && (score.is_invalid || score.score.nil?) && (score.user == current_user || current_user.admin_or_business?) begin score.destroy normal_status("删除成功") diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb index f09a8554c..504868a6e 100644 --- a/app/controllers/gtopic_banks_controller.rb +++ b/app/controllers/gtopic_banks_controller.rb @@ -26,7 +26,7 @@ class GtopicBanksController < ApplicationController end def bank_admin - tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin? + tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? end def gtopic_bank_params diff --git a/app/controllers/homework_banks_controller.rb b/app/controllers/homework_banks_controller.rb index 61bded033..00efbbd5f 100644 --- a/app/controllers/homework_banks_controller.rb +++ b/app/controllers/homework_banks_controller.rb @@ -47,7 +47,7 @@ class HomeworkBanksController < ApplicationController end def bank_admin - tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin? + tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? end def bank_params diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index f9931c370..1d47fa293 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -145,7 +145,7 @@ class HomeworkCommonsController < ApplicationController @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.size @score_open = true - elsif @user_course_identity > Course::STUDENT && @homework.work_public + elsif @user_course_identity > Course::STUDENT @student_works = student_works @score_open = false else @@ -757,7 +757,7 @@ class HomeworkCommonsController < ApplicationController search = params[:search] type = params[:type] # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) - if current_user.admin? + if current_user.admin_or_business? @shixuns = Shixun.unhidden else none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index d2c386681..3c76972b8 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -144,6 +144,7 @@ class MemosController < ApplicationController def reply tip_exception("parent_id不能为空") if params[:parent_id].blank? tip_exception("content不能为空") if params[:content].blank? + tip_exception("content不能超过1000字符") if params[:content].length > 1000 ActiveRecord::Base.transaction do begin diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 153598990..7b096f1ec 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -63,6 +63,7 @@ class MessagesController < ApplicationController def reply return normal_status(2, "回复内容不能为空") if params[:content].blank? + return normal_status(2, "回复内容不能超过1000字符") if params[:content].length > 1000 @reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id, author: current_user, parent: @message, message_detail_attributes: { @@ -126,7 +127,7 @@ class MessagesController < ApplicationController end def create - return normal_status(403, "您没有权限进行该操作") unless current_user.admin? || current_user.member_of_course?(@board.course) + return normal_status(403, "您没有权限进行该操作") unless current_user.admin_or_business? || current_user.member_of_course?(@board.course) begin @message = Message.new(message_params) diff --git a/app/controllers/poll_bank_questions_controller.rb b/app/controllers/poll_bank_questions_controller.rb index 71f302115..9e3e890b0 100644 --- a/app/controllers/poll_bank_questions_controller.rb +++ b/app/controllers/poll_bank_questions_controller.rb @@ -114,7 +114,7 @@ class PollBankQuestionsController < ApplicationController private def bank_admin - tip_exception(403, "无权限") unless @poll.user_id == current_user.id || current_user.admin? + tip_exception(403, "无权限") unless @poll.user_id == current_user.id || current_user.admin_or_business? end def get_poll diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index ddb0f3ce1..5183c7a96 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -10,7 +10,7 @@ class QuestionBanksController < ApplicationController def bank_list page = params[:page] || 1 limit = params[:limit] || 15 - @certification_teacher = current_user.is_certification_teacher || current_user.admin? + @certification_teacher = current_user.is_certification_teacher || current_user.admin_or_business? @objects = @object_type.classify.constantize.where(@object_filter) @objects = if params[:search] @@ -134,7 +134,7 @@ class QuestionBanksController < ApplicationController def destroy bank = current_bank - unless current_user.admin? || bank.user_id == current_user.id + unless current_user.admin_or_business? || bank.user_id == current_user.id render_forbidden return end @@ -165,7 +165,7 @@ class QuestionBanksController < ApplicationController def object_banks banks ||= @object_type.classify.constantize.where(@object_filter).where(id: params[:object_id]) - unless current_user.admin? + unless current_user.admin_or_business? banks = banks.where(user_id: current_user.id) end banks @@ -202,7 +202,7 @@ class QuestionBanksController < ApplicationController end def teacher_or_admin - tip_exception(403, "无权限操作") unless current_user.is_certification_teacher || current_user.admin? + tip_exception(403, "无权限操作") unless current_user.is_certification_teacher || current_user.admin_or_business? end def quote_homework_bank homework, course diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 0b7874299..734229501 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -546,6 +546,7 @@ class StudentWorksController < ApplicationController tip_exception("成绩不能为空") if params[:score].blank? tip_exception("成绩不能小于零") if params[:score].to_f < 0 tip_exception("成绩不能大于100") if params[:score].to_f.round(1) > 100 + tip_exception("调分原因不能超过100个字符") if params[:comment].present? && params[:comment].length > 100 ActiveRecord::Base.transaction do begin # 分数不为空的历史评阅都置为失效 diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 7df9aae89..8e23590ef 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -7,7 +7,7 @@ class SubjectsController < ApplicationController :search_members, :add_subject_members, :statistics, :shixun_report, :school_report, :up_member_position, :down_member_position, :update_team_title] before_action :require_admin, only: [:copy_subject] - before_action :shixun_marker, only: [:new, :create, :add_shixun_to_stage] + before_action :shixun_marker, only: [:add_shixun_to_stage] include ApplicationHelper @@ -456,6 +456,25 @@ class SubjectsController < ApplicationController end end + def statistics_new + # data = Subjects::DataStatisticService.new(@subject) + # Rails.logger.info("study_count: #{data.study_count}") + # Rails.logger.info("course_study_count: #{ data.course_study_count}") + # Rails.logger.info("passed_count: #{data.passed_count}") + # Rails.logger.info("course_used_count: #{data.course_used_count}") + # Rails.logger.info("school_used_count: #{data.school_used_count}") + + # data_1 = Subjects::CourseUsedInfoService.call(@subject) + # Rails.logger.info("study_count: #{data_1}") + + # data_2 = Subjects::ShixunUsedInfoService.call(@subject) + # Rails.logger.info("study_count: #{data_2}") + + data_3 = Subjects::UserUsedInfoService.call(@subject) + Rails.logger.info("study_count: #{data_3}") + render_ok() + end + def shixun_report end diff --git a/app/controllers/task_banks_controller.rb b/app/controllers/task_banks_controller.rb index 2b1a400ef..768c4cb2a 100644 --- a/app/controllers/task_banks_controller.rb +++ b/app/controllers/task_banks_controller.rb @@ -29,7 +29,7 @@ class TaskBanksController < ApplicationController end def bank_admin - tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin? + tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? end def gtask_bank_params diff --git a/app/controllers/users/question_banks_controller.rb b/app/controllers/users/question_banks_controller.rb index c5b837d0b..73d1d4dec 100644 --- a/app/controllers/users/question_banks_controller.rb +++ b/app/controllers/users/question_banks_controller.rb @@ -66,9 +66,9 @@ class Users::QuestionBanksController < Users::BaseController def check_user_permission! if params[:type] == 'publicly' - normal_status(-2,"未通过职业认证") unless User.current.admin? || User.current.certification_teacher? + normal_status(-2,"未通过职业认证") unless User.current.admin_or_business? || User.current.certification_teacher? else - render_forbidden unless User.current.admin? || User.current.is_teacher? + render_forbidden unless User.current.admin_or_business? || User.current.is_teacher? end end end \ No newline at end of file diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index cb3c195d6..d732416ba 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -39,7 +39,7 @@ class Weapps::CoursesController < Weapps::BaseController @page = (params[:page] || 1).to_i @limit = (params[:limit] || 20).to_i search = params[:search].present? ? params[:search].strip : "" - if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 + if @course.try(:id) != 1309 || current_user.admin_or_business? || current_user.try(:id) == 15582 @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3)") else @teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} @@ -203,6 +203,6 @@ class Weapps::CoursesController < Weapps::BaseController def set_course @course = Course.find_by!(id: params[:id]) - tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin? + tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin_or_business? end end \ No newline at end of file diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 22adf3005..8b61ca2b6 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -47,9 +47,10 @@ module ExportHelper user_name = user.real_name user_mail = user.mail user_stu_id = user.student_id.present? ? (user.student_id.to_s + "\t") : "--" + user_grade = user.grade user_school = user.school_name user_course_group = u.course_group_name - user_info_array = [user_name,user_login,user_mail,user_stu_id,user_school,user_course_group] #用户的信息集合 + user_info_array = [user_name,user_login,user_mail,user_stu_id,user_grade,user_school,user_course_group] #用户的信息集合 user_work_scores = [] #学生总成绩 @@ -150,7 +151,7 @@ module ExportHelper course_user_score_title = "学生总成绩" score_title_cells = shixun_titles + common_titles + group_titles + task_titles + exercise_titles score_title_counts = [shixun_titles.count,common_titles.count,group_titles.count,task_titles.count,exercise_titles.count] - score_cell_head = %w(序号 真实姓名 登录名 邮箱 学号 学校 分班 个人总成绩) + score_title_cells + score_cell_head = %w(序号 真实姓名 登录名 邮箱 学号 金币 学校 分班 个人总成绩) + score_title_cells @course_user_scores = [course_user_score_title,score_cell_head,score_title_counts,total_user_score_array] #作业的全部集合 diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 73079d82b..e9bef0c9d 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -28,6 +28,9 @@ class Challenge < ApplicationRecord scope :fields_for_list, -> { select([:id, :subject, :st, :score, :position, :shixun_id]) } + validates :task_pass, length: { maximum: 10000 } + + after_commit :create_diff_record def next_challenge diff --git a/app/models/challenge_answer.rb b/app/models/challenge_answer.rb index 0ce757d71..d3fd69cd0 100644 --- a/app/models/challenge_answer.rb +++ b/app/models/challenge_answer.rb @@ -3,6 +3,8 @@ class ChallengeAnswer < ApplicationRecord belongs_to :challenge has_many :game_answers, :dependent => :destroy + validates :contents, length: { maximum: 5000 } + def view_answer_time(user_id) game_answers.where(user_id: user_id).last&.view_time end diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb index 2463d3317..2b8858f21 100644 --- a/app/models/challenge_choose.rb +++ b/app/models/challenge_choose.rb @@ -3,4 +3,7 @@ class ChallengeChoose < ApplicationRecord belongs_to :challenge, optional: true has_many :challenge_tags, :dependent => :destroy has_many :challenge_questions, dependent: :destroy + + validates :subject, length: { maximum: 1000 } + end diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb index b0927aec0..959b033f9 100644 --- a/app/models/challenge_question.rb +++ b/app/models/challenge_question.rb @@ -1,3 +1,6 @@ class ChallengeQuestion < ApplicationRecord belongs_to :challenge_choose + + validates :option_name, length: { maximum: 500 } + end diff --git a/app/models/competition.rb b/app/models/competition.rb index 96fd14c1c..1d10e2032 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -33,6 +33,8 @@ class Competition < ApplicationRecord has_many :competition_prizes, dependent: :destroy has_many :competition_prize_users, dependent: :destroy + validates :introduction, length: { maximum: 500 } + before_save :set_laboratory after_create :create_competition_modules diff --git a/app/models/competition_module_md_content.rb b/app/models/competition_module_md_content.rb index 4a8dacf9e..936ded8ef 100644 --- a/app/models/competition_module_md_content.rb +++ b/app/models/competition_module_md_content.rb @@ -5,4 +5,6 @@ class CompetitionModuleMdContent < ApplicationRecord # validates :name, presence: true validates :content, presence: true + validates :content, length: { maximum: 10000 } + end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 9100f8470..83d2bb56e 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -251,7 +251,7 @@ class Course < ApplicationRecord member = course_member(user.id) group_ids = if member.present? member.teacher_course_groups.size > 0 ? member.teacher_course_groups.pluck(:course_group_id) : course_groups.pluck(:id) - elsif user.admin? + elsif user.admin_or_business? course_groups.pluck(:id) else [] diff --git a/app/models/discuss.rb b/app/models/discuss.rb index a236a2bbc..f35ca4751 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -13,6 +13,8 @@ class Discuss < ApplicationRecord belongs_to :challenge, optional: true validate :validate_sensitive_string + validates :content, length: { maximum: 1000 } + after_create :send_tiding scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) } diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 9bc9bd1fb..1fd84d1f7 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -20,6 +20,7 @@ class Exercise < ApplicationRecord where("exercise_name LIKE ?", "%#{keywords}%") unless keywords.blank?} validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } + validates :exercise_description, length: { maximum: 100 } after_create :create_exercise_list diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 11558f937..00c08dd77 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -11,4 +11,6 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 + validates :answer_text, length: { maximum: 5000 } + end \ No newline at end of file diff --git a/app/models/exercise_answer_comment.rb b/app/models/exercise_answer_comment.rb index 4279ba445..110efc737 100644 --- a/app/models/exercise_answer_comment.rb +++ b/app/models/exercise_answer_comment.rb @@ -6,4 +6,6 @@ class ExerciseAnswerComment < ApplicationRecord belongs_to :exercise_answer, optional: true scope :search_answer_comments, lambda {|name,ids| where("#{name}":ids)} + + validates :comment, length: { maximum: 100 } end diff --git a/app/models/exercise_bank_choice.rb b/app/models/exercise_bank_choice.rb index be29ca786..8f1dc9028 100644 --- a/app/models/exercise_bank_choice.rb +++ b/app/models/exercise_bank_choice.rb @@ -4,4 +4,7 @@ class ExerciseBankChoice < ApplicationRecord scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + + validates :choice_text, length: { maximum: 500 } + end \ No newline at end of file diff --git a/app/models/exercise_bank_question.rb b/app/models/exercise_bank_question.rb index fdd343f5a..fbb6da88f 100644 --- a/app/models/exercise_bank_question.rb +++ b/app/models/exercise_bank_question.rb @@ -11,6 +11,8 @@ class ExerciseBankQuestion < ApplicationRecord scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 + validates :question_title, length: { maximum: 1000 } + def question_type_name case self.question_type when 0 diff --git a/app/models/exercise_bank_standard_answer.rb b/app/models/exercise_bank_standard_answer.rb index 2535473b0..9bfbd67aa 100644 --- a/app/models/exercise_bank_standard_answer.rb +++ b/app/models/exercise_bank_standard_answer.rb @@ -3,4 +3,7 @@ class ExerciseBankStandardAnswer < ApplicationRecord belongs_to :exercise_bank_choice #attr_accessible :answer_text scope :standard_by_ids, lambda { |s| where(exercise_bank_choice_id: s) } + + validates :answer_text, length: { maximum: 5000 } + end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index 72dc30c9d..54b844ad9 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -7,4 +7,6 @@ class ExerciseChoice < ApplicationRecord scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + validates :choice_text, length: { maximum: 500 } + end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 2c9b281c3..3f1a49625 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -16,6 +16,8 @@ class ExerciseQuestion < ApplicationRecord scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 + validates :question_title, length: { maximum: 1000 } + def question_type_name case self.question_type diff --git a/app/models/exercise_standard_answer.rb b/app/models/exercise_standard_answer.rb index b4c71bd76..ccf5c1203 100644 --- a/app/models/exercise_standard_answer.rb +++ b/app/models/exercise_standard_answer.rb @@ -6,5 +6,5 @@ class ExerciseStandardAnswer < ApplicationRecord scope :find_standard_answer_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :standard_by_ids, lambda { |s| where(exercise_choice_id: s) } - + validates :answer_text, length: { maximum: 5000 } end diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index 96dce0c49..7fb0ecc24 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -55,7 +55,7 @@ class GraduationWork < ApplicationRecord end def delete_atta atta - last_score = graduation_work_scores.where.not(score: nil).last + last_score = graduation_work_scores.last (atta.author_id == User.current.id) && (last_score.blank? || last_score.try(:created_at) < atta.created_on) end diff --git a/app/models/graduation_work_score.rb b/app/models/graduation_work_score.rb index eaf59ffbd..853b996a1 100644 --- a/app/models/graduation_work_score.rb +++ b/app/models/graduation_work_score.rb @@ -5,5 +5,5 @@ class GraduationWorkScore < ApplicationRecord belongs_to :graduation_task has_many :attachments, as: :container, dependent: :destroy - validates :comment, length: { maximum: 2000 } + validates :comment, length: { maximum: 1000 } end diff --git a/app/models/gtask_bank.rb b/app/models/gtask_bank.rb index 55f83ef10..f9d38d33f 100644 --- a/app/models/gtask_bank.rb +++ b/app/models/gtask_bank.rb @@ -9,4 +9,6 @@ class GtaskBank < ApplicationRecord scope :myself, ->(user_id) { where(user_id: user_id)} scope :is_public, -> { where(:is_public => true) } + validates :name, length: { maximum: 60 } + validates :description, length: { maximum: 5000 } end diff --git a/app/models/gtopic_bank.rb b/app/models/gtopic_bank.rb index 609219711..fe9f184eb 100644 --- a/app/models/gtopic_bank.rb +++ b/app/models/gtopic_bank.rb @@ -7,4 +7,11 @@ class GtopicBank < ApplicationRecord has_many :graduation_topics, dependent: :nullify scope :myself, ->(user_id) { where(user_id: user_id)} + + + # 课题名称和描述字段长度限制 + validates :name, length: { maximum: 60, + too_long: "60 characters is the maximum allowed" } + validates :description, length: { maximum: 5000, + too_long: "5000 characters is the maximum allowed" } end diff --git a/app/models/hack.rb b/app/models/hack.rb index 79c7a0f82..e89212cc3 100644 --- a/app/models/hack.rb +++ b/app/models/hack.rb @@ -3,6 +3,7 @@ class Hack < ApplicationRecord # diffcult: 难度 1:简单;2:中等; 3:困难 # 编程题 validates_length_of :name, maximum: 60 + validates_length_of :description, maximum: 5000 validates :description, presence: { message: "描述不能为空" } validates :name, presence: { message: "名称不能为空" } # 测试集 diff --git a/app/models/hack_set.rb b/app/models/hack_set.rb index 9e2186fb5..4dafd94a7 100644 --- a/app/models/hack_set.rb +++ b/app/models/hack_set.rb @@ -1,4 +1,6 @@ class HackSet < ApplicationRecord + validates_length_of :input, maximum: 500 + validates_length_of :output, maximum: 500 validates :input, presence: { message: "测试集输入不能为空" } validates :output, presence: { message: "测试集输出不能为空" } validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同" diff --git a/app/models/homework_bank.rb b/app/models/homework_bank.rb index 7c9de0cda..d6db7bfab 100644 --- a/app/models/homework_bank.rb +++ b/app/models/homework_bank.rb @@ -10,4 +10,7 @@ class HomeworkBank < ApplicationRecord scope :is_public, -> { where(is_public: true)} scope :myself, ->(user_id) { where(user_id: user_id)} + validates :name, length: { maximum: 60 } + validates :description, length: { maximum: 15000 } + validates :reference_answer, length: { maximum: 15000 } end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 4300ae9cc..66ab98c9b 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -24,7 +24,9 @@ class JournalsForMessage < ApplicationRecord # "m_reply_count", # 留言的回复数量 # "m_reply_id" , # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) # "is_comprehensive_evaluation", # 1 教师评论、2 匿评、3 留言 - # "hidden", 隐藏 + # "hidden", 隐藏、 + + validates :notes, length: { maximum: 1000 } after_create :send_tiding diff --git a/app/models/library.rb b/app/models/library.rb index 743959d30..982db732b 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -13,6 +13,7 @@ class Library < ApplicationRecord has_one :praise_tread_cache, foreign_key: :object_id has_many :praise_treads, as: :praise_tread_object, dependent: :destroy + validates :content, length: { maximum: 5000 } validates :uuid, presence: true, uniqueness: true diff --git a/app/models/memo.rb b/app/models/memo.rb index d79081350..9140fb5db 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -27,6 +27,8 @@ class Memo < ApplicationRecord scope :hot, -> { order("all_replies_count desc, updated_at desc") } scope :posts, -> { where(root_id: nil, forum_id: [3, 5]) } + validates :content, length: { maximum: 10000 } + after_create :send_tiding # 帖子的回复 @@ -39,6 +41,13 @@ class Memo < ApplicationRecord Memo.where(parent_id: id).includes(:author).reorder("created_at asc") end + # 主贴的名称 + def main_subject + memo = Memo.find_by(root_id: id) + Rails.logger.info("###############memo: #{memo&.subject}") + memo ? memo.subject : subject + end + private def send_tiding diff --git a/app/models/message.rb b/app/models/message.rb index 7588ddc2a..7620ef11d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -39,6 +39,12 @@ class Message < ApplicationRecord message_detail.update_attributes(content: content) end + # 主贴的名称 + def main_subject + Rails.logger.info("##########parent: #{parent&.subject}") + parent.present? ? parent.subject : subject + end + def copy_attachments_to_new_message(new_message, user) attachments.each do |attach| new_message.attachments << Attachment.new(attach.attributes.except("id").merge( diff --git a/app/models/message_detail.rb b/app/models/message_detail.rb index 945d875f5..0d7aaa1c1 100644 --- a/app/models/message_detail.rb +++ b/app/models/message_detail.rb @@ -1,4 +1,5 @@ class MessageDetail < ApplicationRecord belongs_to :message, :touch => true + validates :content, length: { maximum: 5000 } end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 1a89c755e..8d2012381 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -5,6 +5,7 @@ class Myshixun < ApplicationRecord has_one :shixun_modify, :dependent => :destroy belongs_to :user + belongs_to :user_extension, foreign_key: :user_id belongs_to :shixun, counter_cache: true has_one :last_executable_task, -> { where(status: [0, 1]).reorder(created_at: :asc) }, class_name: 'Game' @@ -21,7 +22,7 @@ class Myshixun < ApplicationRecord end def output_times - games.pluck(:evaluate_count).sum.to_i + games.map(&:evaluate_count).sum.to_i end def repo_path diff --git a/app/models/poll.rb b/app/models/poll.rb index 365e46008..1c38d2426 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -25,6 +25,7 @@ class Poll < ApplicationRecord where("polls_name LIKE ?", "%#{keywords}%") unless keywords.blank?} validates :polls_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } + validates :polls_description, length: { maximum: 100 } after_create :create_polls_list diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 8e2421328..c7fa7e75c 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -8,4 +8,6 @@ class PollAnswer < ApplicationRecord scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + validates :answer_text, length: { maximum: 500 } + end \ No newline at end of file diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index a0854aa48..dd7f3f95f 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -9,6 +9,8 @@ class PollQuestion < ApplicationRecord scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :insert_question, lambda {|k| where("question_number > ?",k)} + validates :question_title, length: { maximum: 1000 } + def question_type_name case self.question_type when 1 diff --git a/app/models/poll_vote.rb b/app/models/poll_vote.rb index 67b832890..2e70f1342 100644 --- a/app/models/poll_vote.rb +++ b/app/models/poll_vote.rb @@ -8,4 +8,7 @@ class PollVote < ApplicationRecord scope :find_current_vote,lambda {|k,v| where("#{k}": v)} scope :find_vote_text,-> {where("vote_text IS NOT NULL")} + + validates :vote_text, length: { maximum: 5000 } + end \ No newline at end of file diff --git a/app/models/shixun.rb b/app/models/shixun.rb index d8a41ba6a..c16c4df4e 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -30,6 +30,8 @@ class Shixun < ApplicationRecord has_one :first_tag_repertoire, through: :first_shixun_tag_repertoire, source: :tag_repertoire has_many :homework_commons_shixuns, class_name: 'HomeworkCommonsShixun' + has_many :homework_commons, through: :homework_commons_shixuns + has_many :fork_shixuns, foreign_key: "fork_from", class_name: 'Shixun' #实训的关卡 @@ -59,6 +61,9 @@ class Shixun < ApplicationRecord # Jupyter数据集,附件 has_many :data_sets, ->{where(attachtype: 2)}, class_name: 'Attachment', as: :container, dependent: :destroy + # 试卷的实训题 + has_many :exercise_questions + scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", "%#{keyword}%", "%#{keyword}%") } diff --git a/app/models/shixun_info.rb b/app/models/shixun_info.rb index 7f7aa364e..e3a8d334b 100644 --- a/app/models/shixun_info.rb +++ b/app/models/shixun_info.rb @@ -4,6 +4,8 @@ class ShixunInfo < ApplicationRecord validates_length_of :fork_reason, maximum: 60 after_commit :create_diff_record + validates :description, length: { maximum: 5000 } + private def create_diff_record diff --git a/app/models/shixun_work_comment.rb b/app/models/shixun_work_comment.rb index 7a67238ab..1d23718d3 100644 --- a/app/models/shixun_work_comment.rb +++ b/app/models/shixun_work_comment.rb @@ -2,4 +2,6 @@ class ShixunWorkComment < ApplicationRecord belongs_to :student_work belongs_to :user belongs_to :challenge, optional: true + validates :comment, length: { maximum: 500 } + validates :hidden_comment, length: { maximum: 500 } end diff --git a/app/models/stage.rb b/app/models/stage.rb index db7b5c0b3..84873b01f 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -7,5 +7,5 @@ class Stage < ApplicationRecord has_many :shixuns, :through => :stage_shixuns validates :name, length: { maximum: 60 } - validates :description, length: { maximum: 300 } + validates :description, length: { maximum: 1000 } end diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 4da23a30f..473efa756 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -105,7 +105,7 @@ class StudentWork < ApplicationRecord end def delete_atta atta - last_score = student_works_scores.where.not(score: nil).last + last_score = student_works_scores.last (atta.author_id == User.current.id) && (last_score.blank? || last_score.try(:created_at) < atta.created_on) end diff --git a/app/models/student_works_score.rb b/app/models/student_works_score.rb index 299b61596..f9f4f4220 100644 --- a/app/models/student_works_score.rb +++ b/app/models/student_works_score.rb @@ -7,7 +7,7 @@ class StudentWorksScore < ApplicationRecord has_many :tidings, as: :container, dependent: :destroy has_many :attachments, as: :container, dependent: :destroy - validates :comment, length: { maximum: 2000 } + validates :comment, length: { maximum: 1000 } scope :shixun_comment, lambda { where(is_ultimate: 0) } @@ -17,7 +17,7 @@ class StudentWorksScore < ApplicationRecord end def allow_delete current_user - (self.is_invalid || self.score.nil?) && (current_user == self.user || current_user.admin?) + (self.is_invalid || self.score.nil?) && (current_user == self.user || current_user.admin_or_business?) end # 匿评分 diff --git a/app/models/subject.rb b/app/models/subject.rb index 28c45e4ba..df9271e5f 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -25,6 +25,11 @@ class Subject < ApplicationRecord has_many :courses, -> { where("is_delete = 0").order("courses.created_at ASC") } has_many :laboratory_subjects, dependent: :destroy + # 学习统计 + has_one :subject_record, dependent: :destroy + has_many :subject_course_records, dependent: :destroy + has_many :subject_shixun_infos, dependent: :destroy + has_many :subject_user_infos, dependent: :destroy validates :name, length: { maximum: 60 } validates :description, length: { maximum: 8000 } diff --git a/app/models/subject_course_record.rb b/app/models/subject_course_record.rb new file mode 100644 index 000000000..2240c0eb3 --- /dev/null +++ b/app/models/subject_course_record.rb @@ -0,0 +1,3 @@ +class SubjectCourseRecord < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/subject_record.rb b/app/models/subject_record.rb new file mode 100644 index 000000000..cdd5b15e4 --- /dev/null +++ b/app/models/subject_record.rb @@ -0,0 +1,3 @@ +class SubjectRecord < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/subject_shixun_info.rb b/app/models/subject_shixun_info.rb new file mode 100644 index 000000000..6ce4ccb50 --- /dev/null +++ b/app/models/subject_shixun_info.rb @@ -0,0 +1,3 @@ +class SubjectShixunInfo < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/subject_user_info.rb b/app/models/subject_user_info.rb new file mode 100644 index 000000000..4435a1aea --- /dev/null +++ b/app/models/subject_user_info.rb @@ -0,0 +1,3 @@ +class SubjectUserInfo < ApplicationRecord + belongs_to :subject +end diff --git a/app/models/test_set.rb b/app/models/test_set.rb index 7772a3a00..1fae89afa 100644 --- a/app/models/test_set.rb +++ b/app/models/test_set.rb @@ -1,3 +1,7 @@ class TestSet < ApplicationRecord # match_rule: 匹配规则: full: 完全匹配, last: 末尾匹配 + # + validates :input, length: { maximum: 5000 } + validates :input, length: { maximum: 5000 } + end diff --git a/app/models/user.rb b/app/models/user.rb index 2af43b6f5..e74290c84 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -43,6 +43,7 @@ class User < ApplicationRecord has_many :shixun_members, :dependent => :destroy has_many :shixuns, :through => :shixun_members has_many :myshixuns, :dependent => :destroy + has_many :games, :dependent => :destroy has_many :study_shixuns, through: :myshixuns, source: :shixun # 已学习的实训 has_many :course_messages has_many :courses, foreign_key: 'tea_id', dependent: :destroy diff --git a/app/services/discusses_service.rb b/app/services/discusses_service.rb index 81ac1eb33..ae6a538ca 100644 --- a/app/services/discusses_service.rb +++ b/app/services/discusses_service.rb @@ -58,7 +58,7 @@ class DiscussesService praise_count: 0, position: params[:position], challenge_id: params[:challenge_id], hidden: !current_user.admin? ) # 发送手机通知 - Educoder::Sms.send(mobile:'18173242757', send_type:'discuss', name:'管理员') + # Educoder::Sms.send(mobile:'18173242757', send_type:'discuss', name:'管理员') rescue Exception => e raise(e.message) end diff --git a/app/services/subjects/course_used_info_service.rb b/app/services/subjects/course_used_info_service.rb new file mode 100644 index 000000000..2561f3aa4 --- /dev/null +++ b/app/services/subjects/course_used_info_service.rb @@ -0,0 +1,40 @@ +class Subjects::CourseUsedInfoService < ApplicationService + attr_reader :subject + def initialize(subject) + @subject = subject + @shixun_ids = subject.shixuns.pluck(:id) + end + + def call + return if subject.blank? + homework_commons = + HomeworkCommon.joins(:homework_commons_shixun) + .where(homework_type: %i[practice]) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}) + course_ids = homework_commons.pluck(:course_id) + homework_common_ids = homework_commons.pluck("homework_commons.id") + schools = School.joins(:courses).where(courses: {id: course_ids}).group("schools.id").select("schools.*, count(courses.id) course_count") + + # name:将该课程使用到课堂的单位 + # course_count: 将该课程使用到课堂的数量 + # student_count: 课堂的学生总数(去掉重复) + # choice_shixun_num: 选用该课程实训的个数(去重) + # choice_shixun_frequency: 选用该课程实训的次数 + course_info = [] + schools.map do |school| + name = school.name + course_count = school.course_count + student_count = school.courses.joins(:course_members).where(course_members: {role: 4, course_id: course_ids}).size + shixun_ids = school.courses.joins(homework_commons: :homework_commons_shixun) + .where(homework_commons: {id: homework_common_ids}) + .pluck("homework_commons_shixuns.shixun_id") + choice_shixun_frequency = shixun_ids.size + choice_shixun_num = shixun_ids.uniq.size + course_info << {school_id: school.id, school_name: name, course_count: course_count, student_count: student_count, + choice_shixun_num: choice_shixun_num, choice_shixun_frequency: choice_shixun_frequency} + end + course_info + end + +end + diff --git a/app/services/subjects/data_statistic_service.rb b/app/services/subjects/data_statistic_service.rb new file mode 100644 index 000000000..32b636400 --- /dev/null +++ b/app/services/subjects/data_statistic_service.rb @@ -0,0 +1,72 @@ +class Subjects::DataStatisticService < ApplicationService + attr_reader :subject + def initialize(subject) + @subject = subject + @shixuns = subject.shixuns + @shixun_ids = @shixuns.pluck(:id) + end + + # 学习总人数: + # 文案解释:学习该课程的全部人数(学习总人数=课堂学习人数+自主学习人数) + # 开发备注:只要点击该课程的任何一个实训(生成了tpi),都算一个学习人数;(去重,一个人数计算1次) + def study_count + @shixuns.joins(:myshixuns).pluck("myshixuns.user_id").uniq.size + end + + # 课堂学习人数: + # 文案解释:通过课堂学习该课程的人数 + # 开发备注:只要通过课堂进入,并点击了实训(生成了tpi),则算一个可以学习人数;(去重,一个人数计算1次) + def course_study_count + # 实训作业 + sw_user_ids = StudentWork.where.not(myshixun_id: 0).joins(homework_common: :homework_commons_shixun) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("student_works.user_id") + # 试卷的实训题 + esa_user_ids = ExerciseShixunAnswer.joins(exercise_shixun_challenge: :shixun) + .where(shixuns: {id: @shixun_ids}).pluck("exercise_shixun_answers.user_id") + (sw_user_ids + esa_user_ids).uniq.size + end + + # 自主学习人数: + # 文案解释:通过自主学习该课程的人数 + # 开发备注:非课程进入,生成了实训的tpi(去重。一个人数计算1次 + def initiative_study + study_count - course_study_count + end + + # 通关总人数: + # 文案解释: + # 通关该课程所有实训的人数(去重。一个人数计算1次) + def passed_count + @shixuns.includes(:myshixuns).where(myshixuns: {status: 1}).pluck("myshixuns.user_id").uniq.size + end + + # 使用课堂数: + # 文案解释:使用该课程的课堂数量 + # 开发备注:课堂加入该课程的实训到自己课堂,则算一个使用课堂数。(去重,一个课堂计算1次) + def course_used_count + hc_course_ids = + HomeworkCommon.joins(:homework_commons_shixun) + .where(homework_type: %i[practice]) + .where(homework_commons_shixuns: {shixun_id: @shixun_ids}).pluck("homework_commons.course_id").uniq + ex_course_ids = + Exercise.joins(:exercise_questions) + .where(exercise_questions: {question_type: 5, shixun_id: @shixun_ids}).pluck("exercises.course_id").uniq + + (hc_course_ids + ex_course_ids).uniq.size + end + + # 使用单位数: + # 文案解释:使用该课程的单位数量(包括自主学习者所在单位) + # 开发备注:凡事该单位有使用该课程的实训(自主学习+课堂使用)都算;(去重,一个单位计算一次) + def school_used_count + school_ids.size + end + + + private + def school_ids + @shixuns.joins(myshixuns: :user_extension).pluck("user_extensions.school_id").uniq + end + + +end diff --git a/app/services/subjects/shixun_used_info_service.rb b/app/services/subjects/shixun_used_info_service.rb new file mode 100644 index 000000000..32309fd59 --- /dev/null +++ b/app/services/subjects/shixun_used_info_service.rb @@ -0,0 +1,30 @@ +class Subjects::ShixunUsedInfoService < ApplicationService + attr_reader :subject, :stages + def initialize(subject) + @subject = subject + @stages = subject.stages.includes(shixuns: [myshixuns: :games, homework_commons_shixuns: [homework_common: :course]]) + end + + def call + shixun_infos = [] + stages.each do |stage| + position = stage.position + stage.shixuns.each_with_index do |shixun, index| + stage = "#{position}-#{index+1}" + name = shixun.name + challenge_count = shixun.challenges_count + course_count = shixun.homework_commons.map{|hc| hc.course_id}.uniq.size + school_count = shixun.homework_commons.map{|hc| hc.course&.school_id}.uniq.size + used_count = shixun.myshixuns_count + passed_count = shixun.myshixuns.select{|m| m.status == 1}.size + evaluate_count = shixun.myshixuns.map{|m| m.output_times }.sum + passed_ave_time = passed_count > 0 ? shixun.myshixuns.map{|m| m.total_cost_time}.sum : 0 + shixun_infos << {stage: stage, name: name, challenge_count: challenge_count, course_count: course_count, + school_count: school_count, used_count: used_count, passed_count: passed_count, + evaluate_count: evaluate_count, passed_ave_time: passed_ave_time, shixun_id: shixun.id} + end + end + shixun_infos + end + +end diff --git a/app/services/subjects/user_used_info_service.rb b/app/services/subjects/user_used_info_service.rb new file mode 100644 index 000000000..3b1b969f0 --- /dev/null +++ b/app/services/subjects/user_used_info_service.rb @@ -0,0 +1,28 @@ +class Subjects::UserUsedInfoService < ApplicationService + attr_reader :subject, :shixun_ids + + def initialize(subject) + @subject = subject + @shixun_ids = subject.shixuns.pluck(:id) + + end + + def call + users_info = [] + users = User.includes(myshixuns: :games).where(myshixuns: {shixun_id: shixun_ids}, games: {status: 2}) + users.each do |user| + myshixuns = user.myshixuns.select{|m| shixun_ids.include?(m.shixun_id)} + name = "#{user.lastname}#{user.firstname}" + passed_myshixun_count = myshixuns.select{|m| m.status == 1}.size + passed_games_count = myshixuns.map{|m| m.games.select{|g| g.status == 2}.size }.size + code_line_count = 0 + evaluate_count = myshixuns.map{|m| m.output_times }.sum + cost_time = myshixuns.map{|m|m.total_cost_time }.sum + users_info << {user_id: user.id, name: name, passed_myshixun_count: passed_myshixun_count, + passed_games_count: passed_games_count, code_line_count: code_line_count, + evaluate_count: evaluate_count, cost_time: cost_time} + end + users_info + end + +end diff --git a/app/templates/shixun_work/shixun_work.html.erb b/app/templates/shixun_work/shixun_work.html.erb index 76a269f3f..9a8481f94 100644 --- a/app/templates/shixun_work/shixun_work.html.erb +++ b/app/templates/shixun_work/shixun_work.html.erb @@ -178,20 +178,21 @@ 实训详情
<%#= ApplicationController.helpers.javascript_include_tag "/codemirror/lib/codemirror", "/codemirror/mode/javascript/javascript", "/codemirror/addon/hint/show-hint", "/codemirror/addon/hint/javascript-hint", "/codemirror/addon/selection/active-line", "/codemirror/addon/lint/javascript-lint", "/codemirror/addon/lint/css-lint", "/codemirror/addon/lint/lint", "/codemirror/addon/lint/json-lint", "/editormd/lib/codemirror/addon/lint/css-lint" %> - <% @games.each_with_index do |game, index| %> + <% @challenges.each_with_index do |challenge, index| %> + <% game = @games.select{|game| game.challenge_id == challenge.id}.first if @games %>第<%= index+1 %>关<%= game.challenge.subject %> + 第<%= index+1 %>关<%= challenge.subject %>
-评测次数 | @@ -209,7 +210,7 @@
---|
最近通过的代码 @@ -240,129 +241,129 @@ window.onload = function() { console.debug("window.onload"); - <% @games.map(&:id).each do |game_id| %> + <% if @games.present? %> + <% @games.map(&:id).each do |game_id| %> var ele = document.getElementById("content_show_<%= game_id %>"); if (ele) { - var ide = CodeMirror.fromTextArea(ele, { - lineNumbers: true, - theme: "default", - // extraKeys: {"Ctrl-Q": "autocomplete"}, // 快捷键 - indentUnit: 4, //代码缩进为一个tab的距离 - matchBrackets: true, - autoRefresh: true, - smartIndent: true,//智能换行 - styleActiveLine: true, - lineWrapping: true, - lint: true, - readOnly: "nocursor" - }); + var ide = CodeMirror.fromTextArea(ele, { + lineNumbers: true, + theme: "default", + // extraKeys: {"Ctrl-Q": "autocomplete"}, // 快捷键 + indentUnit: 4, //代码缩进为一个tab的距离 + matchBrackets: true, + autoRefresh: true, + smartIndent: true,//智能换行 + styleActiveLine: true, + lineWrapping: true, + lint: true, + readOnly: "nocursor" + }); - ide.setSize("auto", ide.lineCount() * 18); + ide.setSize("auto", ide.lineCount() * 18); } - <% end %> + <% end %> + // 基于准备好的dom,初始化echarts实例 + if(document.getElementById('shixun_skill_chart')){ + var effChart = echarts.init(document.getElementById('shixun_skill_chart')); + // 指定图表的配置项和数据 + var option = { + grid: { + left: '3%', + right: '9%', + bottom: '3%', + containLabel: true + }, + tooltip : {}, + xAxis : [ + { + type : 'value', + name: '学生序号', + scale:true, + axisLabel : { + formatter: ' ' + }, + axisTick:{ + show:false + }, + splitLine: { + show: false + } + } + ], + yAxis : [ + { + type : 'value', + name : '工作效率', + scale:true, + axisLabel : { + formatter: '{value} ' + }, + splitLine: { + show: false + } + } + ], + series : [ + { + name:'', + type:'scatter', + data: <%= @echart_data[:efficiency_list] %>, + itemStyle:{ + normal:{color:'#2e65ad'} + }, + markArea: { + silent: true, + itemStyle: { + normal: { + color: 'transparent', + borderWidth: 1, + borderType: 'dashed' + } + } + }, + markPoint : { + data : [ + { + name: 'daiao', + xAxis:<%= @myself_eff[0] %>, + yAxis:<%= @myself_eff[1] %> + } + ], + itemStyle: { + normal:{ + color:'#c23531' + } + } + }, + markLine : { + lineStyle: { + normal: { + type: 'solid', + color:'#c23531' + } + }, + data : [ + {type : 'average', name: '中位值'} + ] + } + }, + { + name:'二班', + type:'scatter', + data: [<%= @myself_eff %>], + itemStyle:{ + color:'#c23531' + } + } + ] + }; + // 使用刚指定的配置项和数据显示图表 + effChart.setOption(option); + console.debug(<%= @myself_consume %>); + } - // 基于准备好的dom,初始化echarts实例 - if(document.getElementById('shixun_skill_chart')){ - var effChart = echarts.init(document.getElementById('shixun_skill_chart')); - // 指定图表的配置项和数据 - var option = { - grid: { - left: '3%', - right: '9%', - bottom: '3%', - containLabel: true - }, - tooltip : {}, - xAxis : [ - { - type : 'value', - name: '学生序号', - scale:true, - axisLabel : { - formatter: ' ' - }, - axisTick:{ - show:false - }, - splitLine: { - show: false - } - } - ], - yAxis : [ - { - type : 'value', - name : '工作效率', - scale:true, - axisLabel : { - formatter: '{value} ' - }, - splitLine: { - show: false - } - } - ], - series : [ - { - name:'', - type:'scatter', - data: <%= @echart_data[:efficiency_list] %>, - itemStyle:{ - normal:{color:'#2e65ad'} - }, - markArea: { - silent: true, - itemStyle: { - normal: { - color: 'transparent', - borderWidth: 1, - borderType: 'dashed' - } - } - }, - markPoint : { - data : [ - { - name: 'daiao', - xAxis:<%= @myself_eff[0] %>, - yAxis:<%= @myself_eff[1] %> - } - ], - itemStyle: { - normal:{ - color:'#c23531' - } - } - }, - markLine : { - lineStyle: { - normal: { - type: 'solid', - color:'#c23531' - } - }, - data : [ - {type : 'average', name: '中位值'} - ] - } - }, - { - name:'二班', - type:'scatter', - data: [<%= @myself_eff %>], - itemStyle:{ - color:'#c23531' - } - } - ] - }; - // 使用刚指定的配置项和数据显示图表 - effChart.setOption(option); - console.debug(<%= @myself_consume %>); - } - - if(document.getElementById('shixun_skill_chart')) { + if(document.getElementById('shixun_overall_ablility_chart')) { var ablChart = echarts.init(document.getElementById('shixun_overall_ablility_chart')); var dataBJ = <%= @echart_data[:consume_list] %>; var schema = [ @@ -477,6 +478,8 @@ // 使用刚指定的配置项和数据显示图表。 ablChart.setOption(option1); } + <% end %> + }