Merge branch 'dev_aliyun' into dev_course

dev_course
p31729568 6 years ago
commit cc786b7f98

@ -39,6 +39,8 @@ gem 'pdfkit'
gem 'wkhtmltopdf-binary' gem 'wkhtmltopdf-binary'
#gem 'iconv' #gem 'iconv'
# markdown 转html
gem 'redcarpet', '~> 3.4'
gem 'rqrcode', '~> 0.10.1' gem 'rqrcode', '~> 0.10.1'
gem 'rqrcode_png' gem 'rqrcode_png'

@ -193,6 +193,7 @@ GEM
rb-inotify (0.9.10) rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2) ffi (>= 0.5.0, < 2)
rchardet (1.8.0) rchardet (1.8.0)
redcarpet (3.4.0)
redis (4.1.0) redis (4.1.0)
redis-actionpack (5.0.2) redis-actionpack (5.0.2)
actionpack (>= 4.0, < 6) actionpack (>= 4.0, < 6)
@ -328,6 +329,7 @@ DEPENDENCIES
rails (~> 5.2.0) rails (~> 5.2.0)
rails-i18n (~> 5.1) rails-i18n (~> 5.1)
rchardet (~> 1.8) rchardet (~> 1.8)
redcarpet (~> 3.4)
redis-rails redis-rails
roo-xls roo-xls
rqrcode (~> 0.10.1) rqrcode (~> 0.10.1)

@ -83,7 +83,6 @@ class AccountsController < ApplicationController
email = params[:login] email = params[:login]
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
user = User.find_by_mail(email) #这里有问题应该是为email,而不是mail 6.13-hs user = User.find_by_mail(email) #这里有问题应该是为email,而不是mail 6.13-hs
end end
check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60)
unless check_code unless check_code

@ -23,6 +23,13 @@ class ApplicationController < ActionController::Base
EduSetting.get(name) EduSetting.get(name)
end end
# 实训的访问权限
def shixun_access_allowed
if !current_user.shixun_permission(@shixun)
tip_exception(403, "..")
end
end
def user_course_identity def user_course_identity
@user_course_identity = current_user.course_identity(@course) @user_course_identity = current_user.course_identity(@course)
if @user_course_identity > Course::STUDENT && @course.is_public == 0 if @user_course_identity > Course::STUDENT && @course.is_public == 0
@ -420,6 +427,24 @@ class ApplicationController < ActionController::Base
container.to_json container.to_json
end end
# 实训中间层pod配置
def shixun_container_limit shixun
container = []
shixun.shixun_service_configs.each do |config|
mirror = config.mirror_repository
if mirror.name.present?
container << {:image => mirror.name,
:cpuLimit => config.cpu_limit,
:cpuRequest => config.lower_cpu_limit,
:memoryLimit => "#{config.memory_limit}M",
:memoryRequest => "#{config.request_limit}M",
:resourceLimit => "#{config.resource_limit}K",
:type => mirror.try(:main_type) == "1" ? "main" : "sub"}
end
end
container.to_json
end
# 毕设任务列表的赛选 # 毕设任务列表的赛选
def course_work(task, **option) def course_work(task, **option)
logger.info("#############{option}") logger.info("#############{option}")

@ -5,8 +5,10 @@ class ChallengesController < ApplicationController
before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up,
:edit_choose_question, :show_choose_question, :destroy_challenge_choose, :edit_choose_question, :show_choose_question, :destroy_challenge_choose,
:update_choose_question, :destroy, :crud_answer, :answer] :update_choose_question, :destroy, :crud_answer, :answer]
# before_action :allowed, except: [:index, :show, :edit_choose_question, :edit] # 关卡更新和操作的权限控制
before_action :update_allowed, except: [:index]
# 关卡访问的权限控制
before_action :shixun_access_allowed, only: [:index]
include ShixunsHelper include ShixunsHelper
include ChallengesHelper include ChallengesHelper
@ -136,7 +138,7 @@ class ChallengesController < ApplicationController
# tab 0,nil 过关任务, 1 评测设置, 2 参考答案 # tab 0,nil 过关任务, 1 评测设置, 2 参考答案
def edit def edit
@tab = params[:tab].to_i @tab = params[:tab].to_i
@power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @power = @shixun.status == 0
challenge_num = Challenge.where(:shixun_id => @shixun).count challenge_num = Challenge.where(:shixun_id => @shixun).count
@position = @challenge.position @position = @challenge.position
@chooses = @challenge.challenge_chooses @chooses = @challenge.challenge_chooses
@ -148,16 +150,17 @@ class ChallengesController < ApplicationController
def index def index
uid_logger("identifier: #{params}") uid_logger("identifier: #{params}")
# 通过调试发现 这里includes(:games)性能会慢10倍
@challenges = @shixun.challenges.fields_for_list @challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id)
@editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0
@editable = @shixun.status == 0 # before_action有判断权限如果没发布则肯定是管理人员
@user = current_user @user = current_user
end end
def show def show
@tab = params[:tab].nil? ? 1 : params[:tab].to_i @tab = params[:tab].nil? ? 1 : params[:tab].to_i
challenge_num = Challenge.where(shixun_id: @shixun).count challenge_num = @shixun.challenges_count
@power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @power = @shixun.status == 0 # 之前验证走过了是不是管理员,因此这里只用判断是否发布
@position = @challenge.position @position = @challenge.position
if @position < challenge_num if @position < challenge_num
@next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first @next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first
@ -247,7 +250,6 @@ class ChallengesController < ApplicationController
# 关卡位置被修改,需要修改脚本 # 关卡位置被修改,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script) @shixun.update_column(:evaluate_script, script)
end end
def index_up def index_up
@ -287,7 +289,7 @@ class ChallengesController < ApplicationController
def challenge_params def challenge_params
params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average, params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average,
:path, :exec_path, :show_type, :original_picture_path, :test_set_score, :path, :exec_path, :show_type, :original_picture_path, :test_set_score,
:expect_picture_path, :picture_path, :web_route, :answer) :expect_picture_path, :picture_path, :web_route, :answer, :exec_time)
end end
def chooce_params def chooce_params
@ -295,9 +297,8 @@ class ChallengesController < ApplicationController
:standard_answer, :score, :difficult) :standard_answer, :score, :difficult)
end end
def allowed def update_allowed
# 实训为发布前,除实训的管理者外,其他人都不人都不允许访问 unless current_user.manager_of_shixun?(@shixun)
if !current_user.manager_of_shixun?(@shixun) && (@shixun.status < 1 || @shixun.hidden == 1)
raise Educoder::TipException.new(403, "..") raise Educoder::TipException.new(403, "..")
end end
end end

@ -42,7 +42,18 @@ class CommonsController < ApplicationController
end end
def validate_power def validate_power
tip_exception(403, "无操作权限") unless current_user.admin? code =
case params[:object_type].strip
when 'message'
if current_user.course_identity(@object.board.course) >= 5 && @object.author != current_user
403
else
200
end
else
current_user.admin? ? 200 : 403
end
return normal_status(code, "你没有权限操作!") if code == 403
end end
def action(flag) def action(flag)

@ -28,7 +28,6 @@ module GitCommon
end end
def file_content def file_content
logger.info("#################{@repo_path}, #{@path}")
@content = git_fle_content @repo_path, @path @content = git_fle_content @repo_path, @path
end end

@ -9,16 +9,17 @@ module GitHelper
# 版本库文件内容,带转码 # 版本库文件内容,带转码
def git_fle_content(repo_path, path) def git_fle_content(repo_path, path)
begin begin
Rails.logger.info("git file content: repo_path is #{repo_path}, path is #{path}")
content = GitService.file_content(repo_path: repo_path, path: path) content = GitService.file_content(repo_path: repo_path, path: path)
logger.info("@@@@@@@@@@@@@@@@@@#{content}") Rails.logger.info("git file content: content is #{content}")
decode_content = nil decode_content = nil
if content.present? if content.present?
content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass
content = Base64.decode64(content) content = Base64.decode64(content)
cd = CharDet.detect(content) cd = CharDet.detect(content)
logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" Rails.logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}"
decode_content = decode_content =
if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8
@ -31,7 +32,7 @@ module GitHelper
decode_content decode_content
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) Rails.logger.error(e.message)
raise Educoder::TipException.new("文档内容获取异常") raise Educoder::TipException.new("文档内容获取异常")
end end
end end

@ -11,7 +11,7 @@ class CoursesController < ApplicationController
render_error(ex.model.errors.full_messages.join(',')) render_error(ex.model.errors.full_messages.join(','))
end end
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups] before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner]
before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
:set_public_or_private, :search_teacher_candidate, :teachers, :set_public_or_private, :search_teacher_candidate, :teachers,
:top_banner, :left_banner, :add_teacher_popup, :add_teacher, :top_banner, :left_banner, :add_teacher_popup, :add_teacher,
@ -776,7 +776,7 @@ class CoursesController < ApplicationController
name = attachment.disk_filename name = attachment.disk_filename
if name.split(".").last == "xls" if name.split(".").last == "xls"
begin begin
attachment_folder = Rails.configuration.educoder['attachment_folder'] attachment_folder = edu_setting('attachment_folder')
full_path = "#{attachment_folder}/#{path}/#{name}" full_path = "#{attachment_folder}/#{path}/#{name}"
xls = Roo::Spreadsheet.open(full_path, extension: :xls) xls = Roo::Spreadsheet.open(full_path, extension: :xls)
worksheet = xls.sheet(0) worksheet = xls.sheet(0)
@ -799,6 +799,8 @@ class CoursesController < ApplicationController
uid_logger_error(e.message) uid_logger_error(e.message)
normal_status(-1, "无法完成导入,原因:文件内容无法读取") normal_status(-1, "无法完成导入,原因:文件内容无法读取")
end end
else
normal_status(-1, "只支持xls文件的导入")
end end
end end
end end
@ -957,34 +959,31 @@ class CoursesController < ApplicationController
def export_member_scores_excel def export_member_scores_excel
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
name = params[:name] ? "#{params[:name].strip}" : "" #用户名或学生学号id搜索 search = params[:search] ? "#{params[:search].strip}" : "" #用户名或学生学号id搜索
group_id = params[:group_id] #分班的班级id group_id = params[:group_id] #分班的班级id
if group_id && group_id != "0" && group_id != "-1" # if group_id && group_id != "0" && group_id != "-1"
@all_members = @course.students.course_find_by_ids("course_group_id",group_id) # @all_members = @course.students.course_find_by_ids("course_group_id",group_id)
elsif group_id && group_id == "0" # 未分班 # elsif group_id && group_id == "0" # 未分班
@all_members = @course.course_members.ungroup_students # @all_members = @course.course_members.ungroup_students
else # else
@all_members = @course.students # @all_members = @course.students
end # end
if name.present? # if name.present?
nick_name_search = @all_members.joins(:user).where("nickname like ?","%#{name}%") # @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%")
if nick_name_search.present? # end
@all_members = nick_name_search
else @all_members = student_act_score group_id, search
@all_members = @all_members.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{name}%","%#{name}%")
end
end
@c_homeworks = @course.homework_commons.homework_published.order("publish_time asc, created_at asc") @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc")
@c_exercises = @course.exercises.is_exercise_published.order("publish_time asc, created_at asc") @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc")
@c_polls = @course.polls.publish_or_not.order("publish_time asc, created_at asc") # @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc")
@c_tasks = @course.graduation_tasks.task_published.order("publish_time asc, created_at asc") @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc")
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
else else
member_to_xlsx(@course,@all_members,@c_homeworks,@c_exercises,@c_tasks,@c_polls) member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks)
filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S')
render xlsx: "#{filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", render xlsx: "#{format_sheet_name filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx",
locals: {course_info:@course_info, activity_level:@user_activity_level, locals: {course_info:@course_info, activity_level:@user_activity_level,
course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, course_scores:@course_user_scores,shixun_works:@shixun_work_arrays,
common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays, common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays,
@ -1054,16 +1053,68 @@ class CoursesController < ApplicationController
end end
end end
def member_to_xlsx(course,all_members,homeworks,exercises,tasks,polls) def student_act_score group_id, search
sql_select = %Q{SELECT cm.*,(
SELECT SUM(student_works.work_score)
FROM student_works,homework_commons
WHERE student_works.homework_common_id = homework_commons.id
AND homework_commons.course_id = #{@course.id}
AND student_works.user_id = cm.user_id
) AS score,
(SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id
AND gt.course_id = #{@course.id} AND gw.user_id = cm.user_id) AS graduation_score,
(SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id
AND exercises.course_id = #{@course.id} AND exercise_users.user_id = cm.user_id) AS ex_score,
(SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id,
(SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_num,
(SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_reply_num,
(SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS resource_num,
(SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS homework_journal_num,
(SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num,
(SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num,
(SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num,
(SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num
FROM course_members cm}
if search.present? && group_id.present?
sql_select += %Q{ join users on cm.user_id = users.id
joins user_extensions ue on ue.user_id = users.id
WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} and
(concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc}
elsif search.present?
ql_select += %Q{ join users on cm.user_id = users.id
joins user_extensions ue on ue.user_id = users.id
WHERE cm.role = 4 and
(concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc}
elsif group_id.present?
sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} ORDER BY score desc}
else
sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} ORDER BY score desc}
end
act_scores = CourseMember.find_by_sql(sql_select)
act_scores
end
def member_to_xlsx(course,all_members,homeworks,exercises,tasks)
#课堂的作业信息 #课堂的作业信息
shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业
shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"]
shixun_homeworks = shixun_homeworks.includes(:score_student_works)
common_homeworks = homeworks.search_homework_type(1) #全部普通作业 common_homeworks = homeworks.search_homework_type(1) #全部普通作业
common_titles = common_homeworks.pluck(:name)+ ["总得分"] common_titles = common_homeworks.pluck(:name)+ ["总得分"]
group_homeworks = homeworks.search_homework_type(3) #全部分组作业 common_homeworks = common_homeworks.includes(:score_student_works)
group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业
group_titles = group_homeworks.pluck(:name)+ ["总得分"] group_titles = group_homeworks.pluck(:name)+ ["总得分"]
task_titles = tasks.pluck(:name)+ ["总得分"] group_homeworks = group_homeworks.includes(:score_student_works)
exercise_titles = exercises.pluck(:exercise_name)+ ["总得分"]
task_titles = tasks.pluck(:name) + ["总得分"]
tasks = tasks.includes(:score_graduation_works)
exercise_titles = exercises.pluck(:exercise_name) + ["总得分"]
exercises = exercises.includes(:score_exercise_users)
total_user_score_array = [] #学生总成绩集合 total_user_score_array = [] #学生总成绩集合
#课堂信息 #课堂信息
@ -1078,7 +1129,7 @@ class CoursesController < ApplicationController
course_teacher_member = course.course_members.course_user_role(%i[CREATOR]) course_teacher_member = course.course_members.course_user_role(%i[CREATOR])
course_teacher = course_teacher_member.present? ? course_teacher_member.first.user.real_name : "--" course_teacher = course_teacher_member.present? ? course_teacher_member.first.user.real_name : "--"
course_class_counts = course.course_groups_count course_class_counts = course.course_groups_count
course_students_count = course.students.count course_students_count = course.students.size
course_1 = ["课堂编号",course_id] course_1 = ["课堂编号",course_id]
course_2 = ["课程名称",course_list_name] course_2 = ["课程名称",course_list_name]
course_3 = ["课堂名称",course_name] course_3 = ["课堂名称",course_name]
@ -1103,11 +1154,6 @@ class CoursesController < ApplicationController
@course_info += [course_info_title,course_main_info,course_group_info] @course_info += [course_info_title,course_main_info,course_group_info]
#课堂活跃度 #课堂活跃度
course_homework_ids = homeworks.pluck(:id) #该课堂的全部作业id
course_graduate_task_ids = tasks.pluck(:id) #该课堂的全部毕业任务id
course_exercise_ids = exercises.pluck(:id) #课堂的全部试卷数
course_poll_ids = polls.pluck(:id) #课堂的全部问卷数
course_board_ids = course.boards.pluck(:id) #课堂的全部讨论区
@user_activity_level = [] @user_activity_level = []
course_user_level = [] course_user_level = []
course_activity_title = "课堂活跃度统计" course_activity_title = "课堂活跃度统计"
@ -1124,15 +1170,14 @@ class CoursesController < ApplicationController
user_work_scores = [] user_work_scores = []
#课堂活跃度统计 #课堂活跃度统计
user_homeworks_num = user.student_works.find_by_homework(course_homework_ids).has_committed.count #完成的作业数 user_homeworks_num = u.homework_num.to_i #完成的作业数
user_graduate_num = user.graduation_works.find_by_task(course_graduate_task_ids).has_committed.count #毕业任务完成数 user_graduate_num = u.graduation_num.to_i #毕业任务完成数
user_exercise_num = user.exercise_users.search_by_exercise(course_exercise_ids).commit_exercise_by_status(1).count #根据试卷的id来查找 user_exercise_num = u.exercise_num.to_i #根据试卷的id来查找
user_poll_num = user.poll_users.search_by_poll(course_poll_ids).commit_by_status(1).count #已完成问卷 user_poll_num = u.poll_num.to_i #已完成问卷
user_file_num = user.attachments.search_by_container(course.id).count user_file_num = u.resource_num.to_i
user_messages = user.messages user_messages_num = u.message_num.to_i #帖子发布数
user_messages_num = user_messages.root_nodes.find_by_boards(course_board_ids).count #帖子发布数 user_reply_num = u.message_reply_num.to_i #帖子回复数
user_reply_num = user_messages.reply_nodes.find_by_boards(course_board_ids).count #帖子回复数 user_work_reply_num = u.homework_journal_num.to_i #作业回复数的数量
user_work_reply_num = user.journals_for_messages.search_by_jour_type("HomeworkCommon",course_homework_ids).count #作业回复数的数量
c_works_num = (user_homeworks_num + user_graduate_num)*10 c_works_num = (user_homeworks_num + user_graduate_num)*10
c_exercise_num = user_exercise_num*10 c_exercise_num = user_exercise_num*10
c_poll_num = user_poll_num*7 c_poll_num = user_poll_num*7
@ -1170,14 +1215,13 @@ class CoursesController < ApplicationController
exercise_score_array = [] exercise_score_array = []
#实训作业 #实训作业
if shixun_homeworks.count > 0 if shixun_homeworks.size > 0
shixun_homeworks.each do |s| shixun_homeworks.each do |s|
user_student_work = s.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答
if user_student_work.blank? if user_student_work.nil?
h_score = 0.0 #该作业的得分为0 h_score = 0.0 #该作业的得分为0
else else
user_stu_work = user_student_work.first h_score = user_student_work.work_score.nil? ? 0.0 : user_student_work.work_score #用户对该作业的分数
h_score = user_stu_work.work_score.nil? ? 0.0 : user_stu_work.work_score #用户对该作业的分数
end end
shixun_score_array.push(h_score) shixun_score_array.push(h_score)
end end
@ -1187,14 +1231,13 @@ class CoursesController < ApplicationController
user_work_scores += user_info_array + shixun_score_array #单个用户的实训作业得分信息 user_work_scores += user_info_array + shixun_score_array #单个用户的实训作业得分信息
#普通作业 #普通作业
if common_homeworks.count > 0 if common_homeworks.size > 0
common_homeworks.each do |c| common_homeworks.each do |c|
user_student_work_1 = c.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答
if user_student_work_1.blank? if user_student_work_1.nil?
h_score_1 = 0.0 #该作业的得分为0 h_score_1 = 0.0 #该作业的得分为0
else else
user_stu_work_1 = user_student_work_1.first h_score_1 = user_student_work_1.work_score.nil? ? 0.0 : user_student_work_1.work_score #用户对该作业的分数
h_score_1 = user_stu_work_1.work_score.nil? ? 0.0 : user_stu_work_1.work_score #用户对该作业的分数
end end
common_score_array.push(h_score_1) common_score_array.push(h_score_1)
end end
@ -1204,14 +1247,13 @@ class CoursesController < ApplicationController
user_work_scores += common_score_array #单个用户的普通作业得分信息 user_work_scores += common_score_array #单个用户的普通作业得分信息
#分组作业 #分组作业
if group_homeworks.count > 0 if group_homeworks.size > 0
group_homeworks.each do |g| group_homeworks.each do |g|
user_student_work_3 = g.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答
if user_student_work_3.blank? if user_student_work_3.nil?
h_score_3 = 0.0 #该作业的得分为0 h_score_3 = 0.0 #该作业的得分为0
else else
user_stu_work_3 = user_student_work_3.first h_score_3 = user_student_work_3.work_score.nil? ? 0.0 : user_student_work_3.work_score #用户对该作业的分数
h_score_3 = user_stu_work_3.work_score.nil? ? 0.0 : user_stu_work_3.work_score #用户对该作业的分数
end end
group_score_array.push(h_score_3) group_score_array.push(h_score_3)
end end
@ -1221,13 +1263,13 @@ class CoursesController < ApplicationController
user_work_scores += group_score_array #单个用户的分组作业得分信息 user_work_scores += group_score_array #单个用户的分组作业得分信息
#毕设作业 #毕设作业
if tasks.count > 0 if tasks.size > 0
tasks.each do |task| tasks.each do |task|
graduation_works = task.graduation_works.find_by_task_user(user.id) graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first
if graduation_works.empty? if graduation_work.nil?
t_score = 0.0 t_score = 0.0
else else
t_score = graduation_works.first.work_score.nil? ? 0.0 : graduation_works.first.work_score t_score = graduation_work.work_score.nil? ? 0.0 : graduation_work.work_score
end end
task_score_array.push(t_score) task_score_array.push(t_score)
end end
@ -1237,13 +1279,13 @@ class CoursesController < ApplicationController
user_work_scores += task_score_array #单个用户的分组作业得分信息 user_work_scores += task_score_array #单个用户的分组作业得分信息
#试卷 #试卷
if exercises.count > 0 if exercises.size > 0
exercises.each do |ex| exercises.each do |ex|
exercise_works = ex.exercise_users.exercise_commit_users(user.id) exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first
if exercise_works.empty? if exercise_work.nil?
e_score = 0.0 e_score = 0.0
else else
e_score = exercise_works.first.score.nil? ? 0.0 : exercise_works.first.score e_score = exercise_work.score.nil? ? 0.0 : exercise_work.score
end end
exercise_score_array.push(e_score) exercise_score_array.push(e_score)
end end
@ -1275,73 +1317,63 @@ class CoursesController < ApplicationController
@common_work_arrays = [] @common_work_arrays = []
@task_work_arrays = [] @task_work_arrays = []
@exercise_work_arrays = [] @exercise_work_arrays = []
count_1 = shixun_homeworks.count count_1 = shixun_homeworks.size
count_2 = common_homeworks.count count_2 = common_homeworks.size
count_3 = group_homeworks.count count_3 = group_homeworks.size
count_4 = tasks.count count_4 = tasks.size
count_5 = exercises.count count_5 = exercises.size
#实训作业 #实训作业
if count_1 > 0
shixun_homeworks.each_with_index do |s,index| shixun_homeworks.each_with_index do |s,index|
all_student_works = s.student_works.has_committed.order("work_score desc") #该实训题的全部用户回答 all_student_works = s.score_student_works #该实训题的全部用户回答
title_no = index.to_i + 1 title_no = index.to_i + 1
student_work_to_xlsx(all_student_works,s) student_work_to_xlsx(all_student_works,s)
shixun_work_display_name = (title_no.to_s + "." + s.name).strip.first(30) shixun_work_display_name = format_sheet_name (title_no.to_s + "." + s.name).strip.first(30)
shixun_work_content = [shixun_work_display_name,@work_head_cells,@work_cells_column] shixun_work_content = [shixun_work_display_name,@work_head_cells,@work_cells_column]
@shixun_work_arrays.push(shixun_work_content) @shixun_work_arrays.push(shixun_work_content)
end end
end
#普通作业 #普通作业
if count_2 > 0
common_homeworks.each_with_index do |c,index| common_homeworks.each_with_index do |c,index|
all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 all_student_works = c.score_student_works #当前用户的对该作业的回答
title_no = count_1 + index.to_i + 1 title_no = count_1 + index.to_i + 1
student_work_to_xlsx(all_student_works,c) student_work_to_xlsx(all_student_works,c)
work_name = (title_no.to_s + "." + c.name).strip.first(30) work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
work_content = [work_name,@work_head_cells,@work_cells_column] work_content = [work_name,@work_head_cells,@work_cells_column]
@common_work_arrays.push(work_content) @common_work_arrays.push(work_content)
title_no title_no
end end
end
#分组作业 #分组作业
if count_3 > 0
group_homeworks.each_with_index do |c,index| group_homeworks.each_with_index do |c,index|
all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 all_student_works = c.score_student_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + index.to_i + 1 title_no = count_1 + count_2 + index.to_i + 1
student_work_to_xlsx(all_student_works,c) student_work_to_xlsx(all_student_works,c)
work_name = (title_no.to_s + "." + c.name).strip.first(30) work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
work_content = [work_name,@work_head_cells,@work_cells_column] work_content = [work_name,@work_head_cells,@work_cells_column]
@group_work_arrays.push(work_content) @group_work_arrays.push(work_content)
end end
end
#毕设任务 #毕设任务
if count_4 > 0
tasks.each_with_index do |c,index| tasks.each_with_index do |c,index|
all_student_works = c.graduation_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 all_student_works = c.score_graduation_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + index.to_i + 1 title_no = count_1 + count_2 + count_3 + index.to_i + 1
graduation_work_to_xlsx(all_student_works,c,current_user) graduation_work_to_xlsx(all_student_works,c,current_user)
work_name = (title_no.to_s + "." + c.name).strip.first(30) work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
# work_content = [work_name,@work_head_cells,@work_cells_column] # work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [work_name,@head_cells_column,@task_cells_column] work_content = [work_name,@head_cells_column,@task_cells_column]
@task_work_arrays.push(work_content) @task_work_arrays.push(work_content)
end end
end
#试卷的导出 #试卷的导出
if count_5 > 0
exercises.each_with_index do |c,index| exercises.each_with_index do |c,index|
all_student_works = c.exercise_users.exercise_user_committed #当前用户的对该作业的回答 all_student_works = c.score_exercise_users #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1
get_export_users(c,course,all_student_works) get_export_users(c,course,all_student_works)
work_name = (title_no.to_s + "." + c.exercise_name).strip.first(30) work_name = format_sheet_name (title_no.to_s + "." + c.exercise_name).strip.first(30)
# work_content = [work_name,@work_head_cells,@work_cells_column] # work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [work_name,@table_columns,@user_columns] work_content = [work_name,@table_columns,@user_columns]
@exercise_work_arrays.push(work_content) @exercise_work_arrays.push(work_content)
end end
end end
end
end end

@ -0,0 +1,11 @@
class DepartmentsController < ApplicationController
def for_option
render_ok(departments: Department.cached_names_data(current_school))
end
private
def current_school
@_current_school ||= School.find(params[:id])
end
end

@ -7,9 +7,18 @@ class DiscussesController < ApplicationController
page = params[:page].to_i page = params[:page].to_i
offset = page * LIMIT offset = page * LIMIT
# 总数,分页使用 # 总数,分页使用
if current_user.admin?
@disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count
@discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil). @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s,
includes(:user, :praise_tread).offset(offset) :root_id => nil).includes(:user, :praise_tread).offset(offset)
else
disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and
(hidden = :hidden or user_id = :user_id)",
{dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id})
@disscuss_count = disscusses.count
@discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset)
end
@current_user = current_user @current_user = current_user
end end
@ -23,8 +32,10 @@ class DiscussesController < ApplicationController
def create def create
begin begin
@discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], :content => params[:content].gsub("&nbsp\;", "").strip, @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type],
:user_id => current_user.id, :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id]) :content => params[:content].gsub("&nbsp\;", "").strip, :user_id => current_user.id,
:praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id],
:hidden => !current_user.admin?) # 管理员回复的能够显示
rescue Exception => e rescue Exception => e
uid_logger_error("create discuss failed : #{e.message}") uid_logger_error("create discuss failed : #{e.message}")
raise Educoder::TipException.new("评论异常") raise Educoder::TipException.new("评论异常")

@ -424,14 +424,9 @@ class ExerciseQuestionsController < ApplicationController
begin begin
choice_d_id = params[:choice_no].to_i # 选项的当前位置 choice_d_id = params[:choice_no].to_i # 选项的当前位置
question_choices = @exercise_question.exercise_choices question_choices = @exercise_question.exercise_choices
delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first delete_answer = question_choices.find_by(choice_position: choice_d_id)
left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) left_choices = question_choices.where("choice_position > ? ",choice_d_id)
if left_choice.present? left_choices.update_all("choice_position = choice_position - 1") if left_choices
left_choice.each do |p|
p.choice_position -= 1
p.save
end
end
if delete_answer.destroy if delete_answer.destroy
normal_status(0, "答案删除成功!") normal_status(0, "答案删除成功!")
else else
@ -450,13 +445,8 @@ class ExerciseQuestionsController < ApplicationController
begin begin
question_d_id = @exercise_question.question_number.to_i #问题的当前位置 question_d_id = @exercise_question.question_number.to_i #问题的当前位置
exercise_questions = @exercise.exercise_questions exercise_questions = @exercise.exercise_questions
left_question = exercise_questions.left_question_choose("question_number",question_d_id) left_questions = exercise_questions.where("question_number > ?", question_d_id)
if left_question.present? left_questions.update_all("question_number = question_number - 1") if left_questions
left_question.each do |q|
q.question_number -= 1
q.save
end
end
if @exercise_question.destroy if @exercise_question.destroy
normal_status(0, "问题删除成功!") normal_status(0, "问题删除成功!")
else else
@ -626,7 +616,7 @@ class ExerciseQuestionsController < ApplicationController
elsif params[:question_type].to_i == 2 && (params[:standard_answers].count > 1 || params[:question_choices].blank? || params[:question_choices].include?("")) #判断题的标准答案不能大于1个选项不能为空 elsif params[:question_type].to_i == 2 && (params[:standard_answers].count > 1 || params[:question_choices].blank? || params[:question_choices].include?("")) #判断题的标准答案不能大于1个选项不能为空
normal_status(-1,"判断题选项不能为空/标准答案不能大于1个") normal_status(-1,"判断题选项不能为空/标准答案不能大于1个")
elsif params[:question_type].to_i <= 1 && (params[:question_choices].blank? || params[:question_choices].include?("") || params[:question_choices].count < 2) #选择题选项不能为空,且不能小于2 elsif params[:question_type].to_i <= 1 && (params[:question_choices].blank? || params[:question_choices].include?("") || params[:question_choices].count < 2) #选择题选项不能为空,且不能小于2
normal_status(-1,"选择题选项内容不能为空,且不能少于3个!") normal_status(-1,"选择题选项内容不能为空,且不能少于2个!")
elsif params[:question_type].to_i == 3 && (params[:standard_answers].blank? || params[:standard_answers].count > 5 ) #填空题选项最多为5个,且如果为1个的话不允许修改is_ordered elsif params[:question_type].to_i == 3 && (params[:standard_answers].blank? || params[:standard_answers].count > 5 ) #填空题选项最多为5个,且如果为1个的话不允许修改is_ordered
normal_status(-1,"填空题标准答案不能为空/不能超过5个") normal_status(-1,"填空题标准答案不能为空/不能超过5个")
elsif params[:question_type].to_i == 4 && params[:standard_answers].count > 2 #简单题参考答案最多为1个 elsif params[:question_type].to_i == 4 && params[:standard_answers].count > 2 #简单题参考答案最多为1个
@ -650,7 +640,7 @@ class ExerciseQuestionsController < ApplicationController
if @exercise.exercise_status != 1 if @exercise.exercise_status != 1
question_score = @exercise_question.question_score #原来的分数 question_score = @exercise_question.question_score #原来的分数
update_question_score = params[:question_score].to_f.round(1) #传入的分数 update_question_score = params[:question_score].to_f.round(1) #传入的分数
choices_count = @exercise_question.exercise_choices.count #原来的选项个数 choices_count = @exercise_question.exercise_choices.size #原来的选项个数
exercise_choice_ids = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).uniq exercise_choice_ids = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).uniq
standard_answers_text = @exercise_question.exercise_standard_answers.pluck(:answer_text).uniq standard_answers_text = @exercise_question.exercise_standard_answers.pluck(:answer_text).uniq
update_choices_count = params[:question_choices].present? ? params[:question_choices].count : choices_count #传入的选项个数 update_choices_count = params[:question_choices].present? ? params[:question_choices].count : choices_count #传入的选项个数

@ -32,13 +32,13 @@ class ExercisesController < ApplicationController
@exercises_all = @course.exercises @exercises_all = @course.exercises
member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
@current_user_ = current_user @current_user_ = current_user
@exercises_count = @exercises_all.count # 全部页面,需返回 @exercises_count = @exercises_all.size # 全部页面,需返回
@exercises_unpublish_counts = @exercises_all.exercise_by_status(1).count #未发布的试卷数 @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
@exercises_published_counts = @exercises_all.exercise_by_status([2,3]).count # 已发布的试卷数,包含已截止的 @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的
@exercises_ended_counts = @exercises_all.exercise_by_status(3).count #已截止的试卷数 @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数
# 课堂的学生人数 # 课堂的学生人数
@course_all_members = @course.students #当前课堂的全部学生 @course_all_members = @course.students #当前课堂的全部学生
@course_all_members_count = @course_all_members.count #当前课堂的学生数 @course_all_members_count = @course_all_members.size #当前课堂的学生数
@current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生
# exercises的不同用户群体的显示 # exercises的不同用户群体的显示
@ -64,7 +64,7 @@ class ExercisesController < ApplicationController
@is_teacher_or = 0 @is_teacher_or = 0
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
end end
if @exercises.count > 0 if @exercises.size > 0
if params[:type].present? if params[:type].present?
choose_type = params[:type].to_i choose_type = params[:type].to_i
member_group_id = @current_student.first.try(:course_group_id).to_i member_group_id = @current_student.first.try(:course_group_id).to_i
@ -101,7 +101,7 @@ class ExercisesController < ApplicationController
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 15 @limit = params[:limit] || 15
@exercises = @exercises.page(@page).per(@limit) @exercises = @exercises.page(@page).per(@limit)
@exercises = @exercises.includes(:exercise_users,:exercise_questions,:exercise_group_settings) @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings)
else else
@exercises = [] @exercises = []
end end
@ -188,7 +188,7 @@ class ExercisesController < ApplicationController
else else
@is_teacher_or = 0 #为学生 @is_teacher_or = 0 #为学生
end end
@exercise_questions = @exercise.exercise_questions.order("question_number ASC") @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_standard_answers).order("question_number ASC")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("试卷创建失败!") tip_exception("试卷创建失败!")
@ -402,7 +402,7 @@ class ExercisesController < ApplicationController
:position => c.position, :position => c.position,
:challenge_id => c.challenge_id, :challenge_id => c.challenge_id,
:shixun_id => q.shixun_id, :shixun_id => q.shixun_id,
:question_score => q.question_score :question_score => c.question_score
} }
shixun_challenge_bank = exercise_bank_question.exercise_bank_shixun_challenges.new challenge_option shixun_challenge_bank = exercise_bank_question.exercise_bank_shixun_challenges.new challenge_option
shixun_challenge_bank.save shixun_challenge_bank.save
@ -729,7 +729,6 @@ class ExercisesController < ApplicationController
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置
exercise.exercise_group_settings.destroy_all exercise.exercise_group_settings.destroy_all
ex_unified = true ex_unified = true
notify_receiver_ids = @course.students.pluck(:user_id)
else else
ex_unified = false ex_unified = false
g_course.each do |i| g_course.each do |i|
@ -749,12 +748,11 @@ class ExercisesController < ApplicationController
end end
end end
notify_receiver_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) group_ids = params[:group_ids]
end end
else else
exercise.exercise_group_settings.destroy_all exercise.exercise_group_settings.destroy_all
ex_unified = true ex_unified = true
notify_receiver_ids = @course.students.pluck(:user_id)
end end
if exercise.end_time.blank? if exercise.end_time.blank?
e_time = ex_end_time e_time = ex_end_time
@ -775,7 +773,7 @@ class ExercisesController < ApplicationController
if exercise.course_acts.size == 0 if exercise.course_acts.size == 0
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
end end
ExercisePublishNotifyJob.perform_later(exercise.id, notify_receiver_ids) ExercisePublishNotifyJob.perform_later(exercise.id, group_ids)
end end
end end
end end
@ -1179,15 +1177,16 @@ class ExercisesController < ApplicationController
@exercise_status = @exercise.get_exercise_status(current_user.id) @exercise_status = @exercise.get_exercise_status(current_user.id)
@course_all_members = @course.students @course_all_members = @course.students
@c_group_counts = @course.course_groups_count @c_group_counts = @course.course_groups_count
question_types = @exercise.exercise_questions.pluck(:question_type) question_types = @exercise.exercise_questions.pluck(:question_type).uniq
@exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班 @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班
@exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班 @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班
if question_types.include?(4) #是否包含主观题 if (question_types.size > 1) && question_types.include?(4) #是否包含主观题,或者是否大于1
@subjective_type = 1 @subjective_type = 1
else else
@subjective_type = 0 @subjective_type = 0
end end
if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷 if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷
@exercise_current_user_status = 0 @exercise_current_user_status = 0
if @exercise_status == 1 if @exercise_status == 1
@ -1239,7 +1238,7 @@ class ExercisesController < ApplicationController
@teacher_unreview_count = 0 @teacher_unreview_count = 0
#筛选/分类,排序 #筛选/分类,排序
order = params[:order] order = params[:order]
if @exercise_users_list.present? && @exercise_users_list.count > 0 if @exercise_users_list.present? && @exercise_users_list.size > 0
teacher_reviews = @exercise_users_list.exercise_review teacher_reviews = @exercise_users_list.exercise_review
teacher_unreviews = @exercise_users_list.exercise_unreview teacher_unreviews = @exercise_users_list.exercise_unreview
@teacher_review_count = teacher_reviews.count #已评阅 @teacher_review_count = teacher_reviews.count #已评阅
@ -1255,14 +1254,6 @@ class ExercisesController < ApplicationController
end end
end end
if order == "student_id"
@exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).order("user_extensions.student_id DESC")
elsif order == "score"
@exercise_users_list = @exercise_users_list.order("#{order} DESC")
else
@exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC")
end
#答题状态的选择 #答题状态的选择
if params[:commit_status].present? if params[:commit_status].present?
choose_type = params[:commit_status] choose_type = params[:commit_status]
@ -1279,51 +1270,51 @@ class ExercisesController < ApplicationController
#搜索 #搜索
if params[:search].present? if params[:search].present?
search_content = params[:search] @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
#搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号
nick_name_search = @exercise_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%"))
if nick_name_search.present?
@exercise_users_list = nick_name_search
else
@exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%")
end end
exercise_user_joins = @exercise_users_list.joins(user: :user_extension)
if order == "student_id"
@exercise_users_list = exercise_user_joins.order("user_extensions.student_id DESC")
elsif order == "score"
@exercise_users_list = exercise_user_joins.order("#{order} DESC")
else
@exercise_users_list = exercise_user_joins.order("end_at DESC, start_at DESC")
end end
@export_ex_users = @exercise_users_list @export_ex_users = @exercise_users_list
@exercise_users_size = @exercise_users_list.count @exercise_users_size = @exercise_users_list.size
# 分页 # 分页
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 20 @limit = params[:limit] || 20
@exercise_users_list = @exercise_users_list.page(@page).per(@limit) @exercise_users_list = @exercise_users_list.page(@page).per(@limit)
respond_to do |format| else
format.json @exercise_users_list = []
format.xlsx{ @export_ex_users = @exercise_users_list
@exercise_users_size = 0
end
if params[:format] == "xlsx"
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
else elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0)
get_export_users(@exercise,@course,@export_ex_users) normal_status(-1,"暂无用户提交")
exercise_export_name =
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
end end
}
end end
else
@exercise_users_list = []
@exercise_users_size = 0
respond_to do |format| respond_to do |format|
format.json format.json
format.xlsx{ format.xlsx{
normal_status(-1,"暂无用户提交") get_export_users(@exercise,@course,@export_ex_users)
} exercise_export_name =
format.zip{ "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
normal_status(-1,"暂无用户提交") render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
} }
end end
end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")
@ -1334,8 +1325,9 @@ class ExercisesController < ApplicationController
#导出空白试卷 #导出空白试卷
def export_exercise def export_exercise
@exercise_questions = @exercise.exercise_questions.order("question_number ASC") @request_url = request.base_url
filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf"
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets
end end
@ -1419,7 +1411,7 @@ class ExercisesController < ApplicationController
:best_counts => best_counts, :best_counts => best_counts,
} }
@exercise_questions = @exercise.exercise_questions @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers)
@paging_type = "percent" @paging_type = "percent"
# 按题型排序 # 按题型排序
@ -1512,39 +1504,42 @@ class ExercisesController < ApplicationController
end end
def get_exercise_question_counts #获取试卷的问题数及总分数 def get_exercise_question_counts #获取试卷的问题数及总分数
exercise_questions = @exercise.exercise_questions.all exercise_questions = @exercise.exercise_questions
@exercise_ques_count = exercise_questions.count # 全部的题目数 @exercise_ques_count = exercise_questions.size # 全部的题目数
@exercise_ques_scores = exercise_questions.pluck(:question_score).sum @exercise_ques_scores = exercise_questions.pluck(:question_score).sum
#单选题的数量及分数 #单选题的数量及分数
exercise_single_ques = exercise_questions.find_by_custom("question_type",0) exercise_single_ques = exercise_questions.find_by_custom("question_type",0)
@exercise_single_ques_count = exercise_single_ques.all.count @exercise_single_ques_count = exercise_single_ques.size
@exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum
#多选题的数量及分数 #多选题的数量及分数
exercise_double_ques = exercise_questions.find_by_custom("question_type",1) exercise_double_ques = exercise_questions.find_by_custom("question_type",1)
@exercise_double_ques_count = exercise_double_ques.all.count @exercise_double_ques_count = exercise_double_ques.size
@exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum
# 判断题数量及分数 # 判断题数量及分数
exercise_ques_judge = exercise_questions.find_by_custom("question_type",2) exercise_ques_judge = exercise_questions.find_by_custom("question_type",2)
@exercise_ques_judge_count = exercise_ques_judge.all.count @exercise_ques_judge_count = exercise_ques_judge.size
@exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum
#填空题数量及分数 #填空题数量及分数
exercise_ques_null = exercise_questions.find_by_custom("question_type",3) exercise_ques_null = exercise_questions.find_by_custom("question_type",3)
@exercise_ques_null_count = exercise_ques_null.all.count @exercise_ques_null_count = exercise_ques_null.size
@exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum
#简答题数量及分数 #简答题数量及分数
exercise_ques_main = exercise_questions.find_by_custom("question_type",4) exercise_ques_main = exercise_questions.find_by_custom("question_type",4)
@exercise_ques_main_count = exercise_ques_main.all.count @exercise_ques_main_count = exercise_ques_main.size
@exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum
#实训题数量及分数 #实训题数量及分数
exercise_ques_shixun = exercise_questions.find_by_custom("question_type",5) exercise_ques_shixun = exercise_questions.find_by_custom("question_type",5)
@exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_count = exercise_ques_shixun.size
@exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum
@exercise_questions = @exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers)
end end
#获取用户有权限的分班 #获取用户有权限的分班

@ -16,26 +16,27 @@ class FilesController < ApplicationController
sort = params[:sort] || 0 # 0: 降序1: 升序 sort = params[:sort] || 0 # 0: 降序1: 升序
sort_type = params[:sort_type] || 'created_on' # created_on时间排序 downloads下载次数排序; quotes: 引用次数排序 sort_type = params[:sort_type] || 'created_on' # created_on时间排序 downloads下载次数排序; quotes: 引用次数排序
course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id
@user = current_user || nil @user = current_user
@attachments = @course.attachments.by_keywords(params[:search]) @attachments = @course.attachments.by_course_second_category_id(course_second_category_id)
.includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members])
.by_course_second_category_id(course_second_category_id)
.ordered(sort: sort.to_i, sort_type: sort_type.strip) .ordered(sort: sort.to_i, sort_type: sort_type.strip)
get_category(@course, course_second_category_id) get_category(@course, course_second_category_id)
@total_count = @attachments.size
@public_count = @attachments.publiced.size
@private_count = @total_count - @public_count
@attachments = @attachments.by_keywords(params[:search])
@attachments =
case @user.course_identity(@course) case @user.course_identity(@course)
when 5 when 5
# 课程学生 @attachments.published
@attachments = @attachments.published when 6, 7
when 6 || 7 @attachments.publiced.published
# 非课堂成员 else
@attachments = @attachments.publiced.published @attachments
end end
@total_count = @attachments.size
@public_count = @attachments.publiced.size
@private_count = @total_count - @public_count
@attachments = @attachments.page(@page).per(@page_size) @attachments = @attachments.page(@page).per(@page_size)
end end
@ -180,6 +181,8 @@ class FilesController < ApplicationController
attach_copied_obj.created_on = Time.now attach_copied_obj.created_on = Time.now
attach_copied_obj.author = current_user attach_copied_obj.author = current_user
attach_copied_obj.is_public = 0 attach_copied_obj.is_public = 0
attach_copied_obj.is_publish = 1
attach_copied_obj.publish_time = Time.now
attach_copied_obj.course_second_category_id = course_second_category_id attach_copied_obj.course_second_category_id = course_second_category_id
attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from
if attach_copied_obj.attachtype == nil if attach_copied_obj.attachtype == nil

@ -33,7 +33,7 @@ class GamesController < ApplicationController
is_teacher = @user.is_teacher? is_teacher = @user.is_teacher?
# 实训超时设置 # 实训超时设置
time_limit = @shixun.exec_time time_limit = game_challenge.exec_time
# 上一关、下一关 # 上一关、下一关
prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position)
@ -51,9 +51,8 @@ class GamesController < ApplicationController
# 统计评测时间 # 统计评测时间
record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time) record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time)
# power判断用户是否有权限查看隐藏测试集(TPM管理员平台认证的老师花费金币查看者) # myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员平台认证的老师花费金币查看者)
# myshixun_manager myshixun_manager = @identity < User::EDU_GAME_MANAGER
myshixun_manager = current_user.manager_of_shixun?(@shixun) || (current_user.is_teacher? && current_user.pro_certification?)
# 选择题和编程题公共部分 # 选择题和编程题公共部分
@base_date = {st: @st, discusses_count: discusses_count, game_count: game_count, myshixun: @myshixun, @base_date = {st: @st, discusses_count: discusses_count, game_count: game_count, myshixun: @myshixun,
@ -67,7 +66,7 @@ class GamesController < ApplicationController
shixun_tomcat = edu_setting('cloud_bridge') shixun_tomcat = edu_setting('cloud_bridge')
service_host = edu_setting('vnc_url') service_host = edu_setting('vnc_url')
uri = "#{shixun_tomcat}/bridge/vnc/getvnc" uri = "#{shixun_tomcat}/bridge/vnc/getvnc"
params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}"}
res = uri_post uri, params res = uri_post uri, params
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
raise("实训云平台繁忙繁忙等级99") raise("实训云平台繁忙繁忙等级99")
@ -270,7 +269,9 @@ class GamesController < ApplicationController
if @game.status == 2 if @game.status == 2
@game.update_attributes!(:answer_open => @answer.level) @game.update_attributes!(:answer_open => @answer.level)
else else
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => deduct_score) # 扣除总分计算
answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score)
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction)
end end
rescue Exception => e rescue Exception => e
@ -342,11 +343,10 @@ class GamesController < ApplicationController
@game.update_attribute(:test_sets_view, true) @game.update_attribute(:test_sets_view, true)
# 扣分记录 # 扣分记录
Grade.create(:user_id => current_user.id, :container_id => @game.id, :score => -@minus_grade, :container_type => "testSet") Grade.create(:user_id => current_user.id, :container_id => @game.id, :score => -@minus_grade, :container_type => "testSet")
@status = 0 max_query_index = @game.query_index.to_i
@message = "解锁成功!" testset_detail max_query_index, challenge
else else
@status = -1 tip_exception(-1, "本操作需要扣除#{ @minus_grade }金币,您的金币不够了")
@message = "本操作需要扣除#{ @minus_grade }金币,您的金币不够了"
end end
end end
@ -426,12 +426,12 @@ class GamesController < ApplicationController
game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first
if game_code.present? if game_code.present?
content = game_code.try(:new_code) content = game_code.try(:new_code)
@content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present? # @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present?
content.gsub(/\t/, ' ') # content.gsub(/\t/, ' ')
else # else
content # content
end # end
update_file_content(@content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset") update_file_content(content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset")
else else
tip_exception("代码重置失败,代码为空") tip_exception("代码重置失败,代码为空")
end end
@ -461,6 +461,7 @@ class GamesController < ApplicationController
git_fle_content(@myshixun.shixun.repo_path, path) git_fle_content(@myshixun.shixun.repo_path, path)
rescue Exception => e rescue Exception => e
uid_logger_error("#{e.message}") uid_logger_error("#{e.message}")
# 如果已发布的TPM实训也不能获取到内容那么肯定是版本库异常了
if @myshixun.shixun.try(:status) < 2 if @myshixun.shixun.try(:status) < 2
tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") tip_exception("代码获取异常,请检查实训模板的评测设置是否正确")
else else
@ -546,7 +547,7 @@ class GamesController < ApplicationController
br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}", br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}",
:instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}",
:times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified,
:containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}", :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}",
:persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}",
:timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) }
@ -811,7 +812,7 @@ class GamesController < ApplicationController
# 评测测试机封装 # 评测测试机封装
def testset_detail max_query_index, challenge def testset_detail max_query_index, challenge
# 是否允许查看隐藏的测试集以前的power # 是否允许查看隐藏的测试集以前的power
@allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户
if max_query_index > 0 if max_query_index > 0
uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}")

@ -59,7 +59,8 @@ class GraduationTasksController < ApplicationController
# 任务发布的情况下: 是老师身份或者任务已截止的情况下公开任务了作品设置的学生也能查看其他人的作品 # 任务发布的情况下: 是老师身份或者任务已截止的情况下公开任务了作品设置的学生也能查看其他人的作品
if @task.published? && (@user_course_identity < Course::STUDENT || if @task.published? && (@user_course_identity < Course::STUDENT ||
(@user_course_identity == Course::STUDENT && @work.present? && @work.take.work_status > 0 && (@user_course_identity == Course::STUDENT && @work.present? && @work.take.work_status > 0 &&
@task.status > 1 && @task.open_work)) ((!@task.allow_late && @task.status > 1) || (@task.allow_late && @task.late_time && @task.late_time < Time.now)) &&
(@task.open_work || @task.open_score)))
# 如有有分班则看分班内的学生,否则看所有学生的作品 # 如有有分班则看分班内的学生,否则看所有学生的作品
user_ids = user_ids =
if @user_course_identity < Course::STUDENT if @user_course_identity < Course::STUDENT
@ -117,19 +118,24 @@ class GraduationTasksController < ApplicationController
@work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}")
end end
@view_work = @task.open_work || @user_course_identity < Course::STUDENT
@work_count = @work_list.count @work_count = @work_list.count
@work_excel = @work_list @work_excel = @work_list
@work_list = @work_list.page(page).limit(limit) @work_list = @work_list.page(page).per(limit)
respond_to do |format| respond_to do |format|
format.json format.json
format.xlsx{ format.xlsx{
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
if @work_count > 1
graduation_work_to_xlsx(@work_excel,@task,current_user) graduation_work_to_xlsx(@work_excel,@task,current_user)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @task.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column}
else
normal_status(-1,"暂无提交的学生!")
end
end end
} }
format.zip{ format.zip{
@ -143,13 +149,14 @@ class GraduationTasksController < ApplicationController
file = decode64(zipfile[0][:base64file]) file = decode64(zipfile[0][:base64file])
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
else else
tip_exception(status == -1 ? "文件大小超过500M请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") tip_exception(status == -2 ? "500" : "无附件可下载")
end end
end end
} }
end end
else else
@work_list = @work @work_list = @work
@view_work = false
@work_count = @work_list.count @work_count = @work_list.count
@all_work_count = @work_list.count @all_work_count = @work_list.count
respond_to do |format| respond_to do |format|

@ -24,8 +24,7 @@ class GraduationTopicsController < ApplicationController
end end
# 当前用户是否已经选过题 # 当前用户是否已经选过题
user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) #6.12 -hs @user_selected = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]).count > 0 #6.12 -hs
@user_selected = user_graduation_topics.size > 0
## 分页参数 ## 分页参数
page = params[:page] || 1 page = params[:page] || 1
limit = params[:limit] || 15 limit = params[:limit] || 15
@ -173,7 +172,7 @@ class GraduationTopicsController < ApplicationController
member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first
tip_exception("分班名称不能为空") if params[:course_group_name].blank? tip_exception("分班名称不能为空") if params[:course_group_name].blank?
course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id) course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id)
teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :member_id => member.try(:id), teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :course_member_id => member.try(:id),
:user_id => @graduation_topic.tea_id, :user_id => @graduation_topic.tea_id,
:course_group_id => course_group.try(:id)) :course_group_id => course_group.try(:id))
end end
@ -194,8 +193,8 @@ class GraduationTopicsController < ApplicationController
def student_select_topic def student_select_topic
user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1])
if user_unaccept_topics.size == 0 if user_unaccept_topics.size == 0
member_id = @course.course_members.find_by_user_id(current_user.id) member = @course.course_members.find_by_user_id(current_user.id)
StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, member_id: member_id, StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member.try(:id),
graduation_topic_id: @graduation_topic.id) graduation_topic_id: @graduation_topic.id)
@graduation_topic.update_attribute(:status, 1) @graduation_topic.update_attribute(:status, 1)
normal_status("选题成功") normal_status("选题成功")

@ -13,6 +13,7 @@ class GraduationWorksController < ApplicationController
before_action :published_task, only: [:new, :create, :edit, :update, :search_member_list, :relate_project, before_action :published_task, only: [:new, :create, :edit, :update, :search_member_list, :relate_project,
:cancel_relate_project, :revise_attachment] :cancel_relate_project, :revise_attachment]
before_action :edit_duration, only: [:edit, :update] before_action :edit_duration, only: [:edit, :update]
before_action :open_work, only: [:show, :supply_attachments, :comment_list]
def new def new
if @task.task_type == 2 && @task.base_on_project if @task.task_type == 2 && @task.base_on_project
@ -432,11 +433,11 @@ class GraduationWorksController < ApplicationController
# 交叉评阅分配老师 # 交叉评阅分配老师
def assign_teacher def assign_teacher
tip_exception(-1, "user_id不能为空") if params[:user_id].nil? tip_exception(-1, "user_id不能为空") if params[:user_id].nil?
@work_assign_teacher = @work.graduation_work_comment_assignations.first @work_assign_teacher = @work.graduation_work_comment_assignations.find_by(user_id: params[:user_id])
if @work_assign_teacher if @work_assign_teacher.present?
# graduation_group_id: 已经是答辩组的需要 将答辩组清空 # graduation_group_id: 已经是答辩组的需要 将答辩组清空
@work_assign_teacher.update_attributes(user_id: params[:user_id], graduation_group_id: 0) @work_assign_teacher.update_attributes(graduation_group_id: 0)
else else
@work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id, @work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id,
user_id: params[:user_id], user_id: params[:user_id],
@ -489,6 +490,11 @@ class GraduationWorksController < ApplicationController
tip_exception("已过了修改时间") if @task.end_time && @task.end_time < Time.now tip_exception("已过了修改时间") if @task.end_time && @task.end_time < Time.now
end end
# 作品是否公开
def open_work
tip_exception(403,"没有操作权限") unless (@user_course_identity < Course::STUDENT || current_user == @work.user || @task.open_work)
end
def update_check work def update_check work
tip_exception("作品描述不能为空") if params[:description].blank? tip_exception("作品描述不能为空") if params[:description].blank?
if @task.task_type == 2 if @task.task_type == 2

@ -10,9 +10,10 @@ class HomeworkCommonsController < ApplicationController
:create_subject_homework, :multi_destroy, :add_to_homework_bank] :create_subject_homework, :multi_destroy, :add_to_homework_bank]
before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results,
:code_review_detail, :show_comment, :settings, :works_list, :update_settings, :code_review_detail, :show_comment, :settings, :works_list, :update_settings,
:reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation] :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation,
:update_score, :update_student_score]
before_action :user_course_identity before_action :user_course_identity
before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer] before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score]
before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework,
:publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category,
:choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat,
@ -121,23 +122,26 @@ class HomeworkCommonsController < ApplicationController
@work = @homework.user_work(current_user.id) @work = @homework.user_work(current_user.id)
# 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段
if @work.work_status > 0 && @homework.work_public && if @work&.work_status.to_i > 0 && (@homework.work_public || @homework.score_open) &&
((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4)
@student_works = student_works.where("user_id != #{@work.id}") @student_works = student_works.where("user_id != #{@work.user_id}")
# 匿评、申诉阶段只能看到分配给自己的匿评作品 # 匿评、申诉阶段只能看到分配给自己的匿评作品
elsif @work.work_status > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2
@is_evaluation = true @is_evaluation = true
@student_works = student_works.joins(:student_works_evaluation_distributions).where( @student_works = student_works.joins(:student_works_evaluation_distributions).where(
"student_works_evaluation_distributions.user_id = #{@current_user.id}") "student_works_evaluation_distributions.user_id = #{@current_user.id}")
else else
@student_works = [] @student_works = []
end end
@score_open = @homework.score_open && @work&.work_status.to_i > 0
elsif @user_course_identity < Course::STUDENT elsif @user_course_identity < Course::STUDENT
@student_works = @homework.teacher_works(@member) @student_works = @homework.teacher_works(@member)
@all_member_count = @student_works.size @all_member_count = @student_works.size
@score_open = true
elsif @user_course_identity > Course::STUDENT && @homework.work_public elsif @user_course_identity > Course::STUDENT && @homework.work_public
@student_works = student_works @student_works = student_works
@score_open = false
else else
@student_works = [] @student_works = []
end end
@ -182,7 +186,8 @@ class HomeworkCommonsController < ApplicationController
end end
@work_count = @student_works.size @work_count = @student_works.size
@work_excel = @student_works @work_excel = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games)
@students = @course.students
# 分页参数 # 分页参数
page = params[:page] || 1 page = params[:page] || 1
@ -201,7 +206,7 @@ class HomeworkCommonsController < ApplicationController
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
if @work_excel.present? if @work_count > 1
student_work_to_xlsx(@work_excel,@homework) student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
@ -224,7 +229,7 @@ class HomeworkCommonsController < ApplicationController
file = decode64(zipfile[0][:base64file]) file = decode64(zipfile[0][:base64file])
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
else else
tip_exception(status == -1 ? "文件大小超过500M请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") tip_exception(status == -2 ? "500M" : "无附件可下载")
end end
end end
} }
@ -232,6 +237,59 @@ class HomeworkCommonsController < ApplicationController
end end
end end
def update_score
tip_exception("作业还未发布,暂不能计算成绩") if @homework.end_or_late_none_group
begin
if @homework.unified_setting
student_works = @homework.student_works
user_ids = @course.students.pluck(:user_id)
else
user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id)
student_works = @homework.student_works.where(user_id: user_ids)
end
myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids).
includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)})
challenge_settings = @homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun|
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)
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end
end
HomeworksService.new.update_student_eff_score @homework if (@homework.allow_late && @homework.late_time < Time.now) ||
(!@homework.allow_late && @homework.end_time < Time.now)
@homework.update_attribute('calculation_time', Time.now)
normal_status("更新成功")
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
def update_student_score
work = @homework.student_works.find_by(user_id: current_user.id)
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
ActiveRecord::Base.transaction do
begin
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
challenge_settings = @homework.homework_challenge_settings
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
normal_status("更新成功")
else
normal_status("已是最新成绩")
end
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
end
def alter_name def alter_name
tip_exception("作业名称不能为空") if params[:name].blank? tip_exception("作业名称不能为空") if params[:name].blank?
@homework.update_attributes(name: params[:name].strip) @homework.update_attributes(name: params[:name].strip)
@ -550,14 +608,14 @@ class HomeworkCommonsController < ApplicationController
@homework.score_open = params[:score_open] @homework.score_open = params[:score_open]
@homework.save! @homework.save!
if score_change # if score_change
@homework.student_works.has_committed.each do |student_work| # @homework.student_works.has_committed.each do |student_work|
HomeworksService.new.set_shixun_final_score student_work # HomeworksService.new.set_shixun_final_score student_work
end # end
end # end
# 更新所有学生的效率分(作业允许补交且补交已截止 或者 作业不允许补交且提交已截止) # 更新所有学生的效率分(作业允许补交且补交已截止 或者 作业不允许补交且提交已截止)
if (score_change || update_eff_score) && @homework.end_or_late if update_eff_score && @homework.end_or_late_none_group
HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: @homework.id) HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: @homework.id)
end end
@ -617,7 +675,7 @@ class HomeworkCommonsController < ApplicationController
if @homework_detail_manual.comment_status < 4 if @homework_detail_manual.comment_status < 4
tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank? tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank?
tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment && tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment &&
params[:evaluation_end] <= params[:evaluation_start] params[:evaluation_end] <= strf_time(@homework_detail_manual.evaluation_start)
tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment && tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment &&
@course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day)
@ -940,7 +998,7 @@ class HomeworkCommonsController < ApplicationController
if homework.course_acts.size == 0 if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
end end
# 发消息
HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids) HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids)
else else
create_homework_group_settings(homework) create_homework_group_settings(homework)
@ -961,7 +1019,8 @@ class HomeworkCommonsController < ApplicationController
homework.save! homework.save!
HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) # 更新学生状态及成绩(手动点击计算)
# HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
end end
normal_status(0, "发布成功") normal_status(0, "发布成功")
rescue Exception => e rescue Exception => e

@ -128,7 +128,7 @@ class MessagesController < ApplicationController
def destroy def destroy
begin begin
return normal_status(403, "您没有权限进行该操作") unless @message.author == current_user || current_user.teacher_of_course?(@message.board.course) return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@message.board.course) >= 5 || @message.author != current_user
@message.destroy! @message.destroy!
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)

@ -167,7 +167,7 @@ class MyshixunsController < ApplicationController
end end
# 更新实训关联的作品分数 TODO: 更新作品分数 # 更新实训关联的作品分数 TODO: 更新作品分数
HomeworksService.new.update_myshixun_work_score myshixun # HomeworksService.new.update_myshixun_work_score myshixun
end end
# 如果过关了下一关的状态是3为开启则需要把状态改成1已开启 # 如果过关了下一关的状态是3为开启则需要把状态改成1已开启
# next_game = game.next_game # next_game = game.next_game
@ -217,7 +217,7 @@ class MyshixunsController < ApplicationController
shixun_tomcat = edu_setting('tomcat_webssh') shixun_tomcat = edu_setting('tomcat_webssh')
uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo" uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo"
params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh), params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh),
containers:(Base64.urlsafe_encode64(container_limit @myshixun.shixun.mirror_repositories))} containers:(Base64.urlsafe_encode64(shixun_container_limit @myshixun.shixun))}
res = uri_post uri, params res = uri_post uri, params
if res && res['code'].to_i != 0 if res && res['code'].to_i != 0
tip_exception("实训云平台繁忙繁忙等级92") tip_exception("实训云平台繁忙繁忙等级92")
@ -243,43 +243,39 @@ class MyshixunsController < ApplicationController
# -----Repository # -----Repository
# TODO: 之类需要一个resubmit参数,但是是关于games. # TODO: 之类需要一个resubmit参数,但是是关于games.
def update_file def update_file
begin
@hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first
tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? tip_exception("技术平台为空!") if @myshixun.mirror_name.blank?
path = params[:path].strip unless params[:path].blank? path = params[:path].strip unless params[:path].blank?
game_id = params[:game_id] game_id = params[:game_id]
game = Game.find(game_id) game = Game.find(game_id)
@content_modified = 0 @content_modified = 0
# params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过
# 自动保存的时候evaluate为0点评测的时候为1 # 自动保存的时候evaluate为0点评测的时候为1
if params[:evaluate] == 1 if params[:evaluate] == 1
record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id) @sec_key = generate_identifier(EvaluateRecord, 12)
uid_logger("-- game is #{game_id}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id,
student_work_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f :identifier => @sec_key)
record.update_attributes!(:student_work => student_work_time) uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
end end
unless @hide_code unless @hide_code
# 远程版本库文件内容 # 远程版本库文件内容
last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"]
content = params[:content]
content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present?
params[:content].gsub(/\t/, ' ')
else
params[:content]
end
if content != last_content if content != last_content
@content_modified = 1 @content_modified = 1
author_name = current_user.full_name author_name = current_user.full_name
author_email = current_user.mail author_email = current_user.mail
message = params[:evaluate] == 0 ? "auto commit" : "task commit" message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted"
@content = GitService.update_file(repo_path: @repo_path, @content = GitService.update_file(repo_path: @repo_path,
file_path: path, file_path: path,
message: message, message: message,
content: content, content: content,
author_name: author_name, author_name: author_name,
author_email: author_email) author_email: author_email)
uid_logger("-- file update #{@content}")
end end
end end
@ -293,6 +289,10 @@ class MyshixunsController < ApplicationController
consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f
record.update_attributes!(:file_update => consume_time) record.update_attributes!(:file_update => consume_time)
end end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("文件内容更新异常,请稍后重试")
end
end end
# 渲染实训代码 # 渲染实训代码

@ -156,14 +156,10 @@ class PollQuestionsController < ApplicationController
begin begin
answer_d_id = params[:answer_no].to_i # 答案的当前位置 answer_d_id = params[:answer_no].to_i # 答案的当前位置
poll_answers = @poll_question.poll_answers poll_answers = @poll_question.poll_answers
delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first delete_answer = poll_answers.find_by(answer_position: answer_d_id)
left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) left_answers = poll_answers.where("answer_position > ?",answer_d_id)
if left_answer.present? left_answers.update_all("answer_position = answer_position - 1") if left_answers
left_answer.each do |p|
p.answer_position -= 1
p.save
end
end
if delete_answer.destroy if delete_answer.destroy
normal_status(0, "答案删除成功!") normal_status(0, "答案删除成功!")
else else

@ -18,7 +18,7 @@ class PollsController < ApplicationController
before_action :check_user_id_start_answer,only: [:start_answer] before_action :check_user_id_start_answer,only: [:start_answer]
before_action :check_poll_question_complete,only: [:commit_poll] #问卷提交前来判断问题是否完成 before_action :check_poll_question_complete,only: [:commit_poll] #问卷提交前来判断问题是否完成
before_action :check_poll_commit_result,only: [:commit_result] before_action :check_poll_commit_result,only: [:commit_result]
before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户 # before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户
before_action :get_left_banner_id, only:[:common_header,:start_answer,:new,:edit,:index] before_action :get_left_banner_id, only:[:common_header,:start_answer,:new,:edit,:index]
include PollsHelper include PollsHelper
@ -90,7 +90,7 @@ class PollsController < ApplicationController
@limit = params[:limit] || 15 @limit = params[:limit] || 15
@polls = @polls.page(@page).per(@limit) @polls = @polls.page(@page).per(@limit)
@polls = @polls.includes(:poll_users,:poll_questions,:poll_group_settings) @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings)
else else
@polls = [] @polls = []
@ -183,7 +183,7 @@ class PollsController < ApplicationController
else else
@is_teacher_or = 0 @is_teacher_or = 0
end end
@poll_questions = @poll.poll_questions.order("question_number ASC") @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("没有权限") tip_exception("没有权限")
@ -263,7 +263,6 @@ class PollsController < ApplicationController
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置
poll.poll_group_settings.destroy_all poll.poll_group_settings.destroy_all
poll_unified = true poll_unified = true
notify_student_ids = @course.students.pluck(:user_id)
else else
poll_unified = false poll_unified = false
g_course.each do |i| g_course.each do |i|
@ -282,13 +281,11 @@ class PollsController < ApplicationController
new_poll_group.save new_poll_group.save
end end
end end
group_ids = params[:group_ids]
notify_student_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id)
end end
else else
poll.poll_group_settings.destroy_all poll.poll_group_settings.destroy_all
poll_unified = true poll_unified = true
notify_student_ids = @course.students.pluck(:user_id)
end end
if poll.end_time.blank? if poll.end_time.blank?
e_time = ex_end_time e_time = ex_end_time
@ -309,7 +306,7 @@ class PollsController < ApplicationController
if poll.course_acts.size == 0 if poll.course_acts.size == 0
poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id)
end end
PollPublishNotifyJob.perform_later(poll.id, notify_student_ids) PollPublishNotifyJob.perform_later(poll.id, group_ids)
end end
end end
normal_status(0, "问卷发布成功!") normal_status(0, "问卷发布成功!")
@ -923,22 +920,42 @@ class PollsController < ApplicationController
def commit_result def commit_result
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
# 分页 @poll_users = @poll.poll_users
@poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id
@page = params[:page] || 1 @page = params[:page] || 1
@limit = params[:limit] || 10 @limit = params[:limit] || 10
@poll_export_questions = @poll_questions.order("question_number ASC") @poll_export_questions = @poll_questions.order("question_number ASC")
@poll_questions = @poll_questions.page(@page).per(@limit) @poll_questions = @poll_questions.page(@page).per(@limit)
respond_to do |format| if params[:format] == "xlsx"
format.json
format.xlsx{
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0)
normal_status(-1,"暂无用户提交")
else else
polls_export_name = current_user.real_name + "_" + @course.name + "_" + @poll.polls_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') respond_to do |format|
render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {poll_questions:@poll_export_questions} format.xlsx{
end polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {
poll_questions:@poll_export_questions,
poll:@poll,
poll_users: @poll_users,
poll_commit_ids:@poll_commit_ids}
} }
end end
end
end
# respond_to do |format|
# format.json
# format.xlsx{
# polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
# render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {
# poll_questions:@poll_export_questions,
# poll:@poll,
# poll_users: @poll_users,
# poll_commit_ids:@poll_commit_ids}
# }
# end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")
@ -960,9 +977,8 @@ class PollsController < ApplicationController
if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷
@poll_current_user_status = 0 @poll_current_user_status = 0
@poll_users_list = @poll.all_poll_users(current_user.id).distinct #该老师分班的全部学生 @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生
get_poll_answers(@poll_users_list) get_poll_answers(@poll_users_list)
if @poll_list_status == 1 if @poll_list_status == 1
@poll_course_groups =[] @poll_course_groups =[]
else else
@ -1008,14 +1024,8 @@ class PollsController < ApplicationController
search_content = params[:search] search_content = params[:search]
if @poll_users_list.present? && @poll_users_list.count > 0 if @poll_users_list.present? && @poll_users_list.count > 0
if order == "student_id"
@poll_users_list = @poll_users_list.joins(user: [:user_extension]).order("user_extensions.student_id DESC")
else
@poll_users_list = @poll_users_list.order("end_at DESC")
end
#答题状态的选择 #答题状态的选择
#
if choose_type.present? if choose_type.present?
@poll_users_list = @poll_users_list.commit_by_status(choose_type) @poll_users_list = @poll_users_list.commit_by_status(choose_type)
end end
@ -1029,20 +1039,23 @@ class PollsController < ApplicationController
#搜索 #搜索
if search_content.present? if search_content.present?
#搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%")
nick_name_search = @poll_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%"))
if nick_name_search.present?
@poll_users_list = nick_name_search
else
@poll_users_list = @poll_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%")
end end
poll_users_joins = @poll_users_list.joins(user: :user_extension)
if order == "student_id"
@poll_users_list = poll_users_joins.order("user_extensions.student_id DESC")
else
@poll_users_list = poll_users_joins.order("end_at DESC")
end end
@poll_users_size = @poll_users_list.count @poll_users_size = @poll_users_list.count
# 分页 # 分页
@page = params[:page] || 1 page = params[:page] || 1
@limit = params[:limit] || 20 limit = params[:limit] || 20
@poll_users_list = @poll_users_list.page(@page).per(@limit) @poll_users_list = @poll_users_list.page(page).per(limit)
else else
@poll_users_list = [] @poll_users_list = []
@poll_users_size = 0 @poll_users_size = 0
@ -1151,11 +1164,11 @@ class PollsController < ApplicationController
end end
def get_questions_count def get_questions_count
@poll_questions = @poll.poll_questions.order("question_number ASC") @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC")
@poll_questions_count = @poll_questions.count # 全部的题目数 @poll_questions_count = @poll_questions.size # 全部的题目数
@poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 @poll_question_singles = @poll_questions.ques_count(1).all.size # 单选题
@poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题 @poll_question_doubles = @poll_questions.ques_count(2).all.size # 多选题
@poll_question_mains = @poll_questions.ques_count(3).all.count #主观题 @poll_question_mains = @poll_questions.ques_count(3).all.size #主观题
end end
def check_poll_question_complete #commit_poll 的权限 def check_poll_question_complete #commit_poll 的权限
@ -1184,7 +1197,7 @@ class PollsController < ApplicationController
def check_poll_commit_result def check_poll_commit_result
poll_status = @poll.get_poll_status(current_user.id) poll_status = @poll.get_poll_status(current_user.id)
commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的
unless @user_course_identity < Course::STUDENT || (@poll.show_result && poll_status == 3 && commit_poll_user.present?) unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?)
normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的
end end
end end

@ -266,11 +266,12 @@ class QuestionBanksController < ApplicationController
def quote_gtopic_bank topic, course def quote_gtopic_bank topic, course
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
new_topic = GraduationTopic.new new_topic = GraduationTopic.new
new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", "quotes",
"course_list_id", "gtopic_bank_id", "created_at", "updated_at") "course_list_id", "gtopic_bank_id", "created_at", "updated_at")
new_topic.course_id = course.id new_topic.course_id = course.id
new_topic.gtopic_bank_id = topic.id new_topic.gtopic_bank_id = topic.id
new_topic.user_id = current_user.id new_topic.user_id = current_user.id
new_topic.tea_id = current_user.id
new_topic.save new_topic.save
topic.attachments.each.try(:each) do |attachment| topic.attachments.each.try(:each) do |attachment|

@ -9,4 +9,8 @@ class SchoolsController < ApplicationController
render_ok(school_names: schools.pluck(:name)) render_ok(school_names: schools.pluck(:name))
end end
def for_option
render_ok(schools: School.cached_names_data)
end
end end

@ -2,8 +2,9 @@ class ShixunsController < ApplicationController
before_action :require_login, except: [:download_file, :index, :menus] before_action :require_login, except: [:download_file, :index, :menus]
before_action :check_auth, except: [:download_file, :index] before_action :check_auth, except: [:download_file, :index]
before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, before_action :find_shixun, :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns,
:departments, :apply_shixun_mirror, :get_mirror_script, :download_file] :propaedeutics, :departments, :apply_shixun_mirror,
:get_mirror_script, :download_file]
before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy] before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy]
before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish, before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish,
@ -178,6 +179,16 @@ class ShixunsController < ApplicationController
ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => @new_shixun.id) ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => @new_shixun.id)
end end
# 同步配置
@shixun.shixun_service_configs.each do |config|
ShixunServiceConfig.create!(:shixun_id => @new_shixun.id,
:cpu_limit => config.cpu_limit,
:lower_cpu_limit => config.lower_cpu_limit,
:memory_limit => config.memory_limit,
:request_limit => config.request_limit,
:mirror_repository_id => config.mirror_repository_id)
end
# fork版本库 # fork版本库
logger.info("###########fork_repo_path: ######{@repo_path}") logger.info("###########fork_repo_path: ######{@repo_path}")
project_fork(@new_shixun, @repo_path, current_user.login) project_fork(@new_shixun, @repo_path, current_user.login)
@ -192,6 +203,13 @@ class ShixunsController < ApplicationController
new_challenge.user_id = User.current.id new_challenge.user_id = User.current.id
new_challenge.shixun_id = @new_shixun.id new_challenge.shixun_id = @new_shixun.id
new_challenge.save! new_challenge.save!
# 同步参考答案
challenge.challenge_answers.each do |answer|
new_answer = ChallengeAnswer.new
new_answer.attributes = answer.attributes.dup.except("id","challenge_id")
new_answer.challenge_id = new_challenge.id
new_answer.save!
end
if challenge.st == 0 # 评测题 if challenge.st == 0 # 评测题
# 同步测试集 # 同步测试集
if challenge.test_sets.present? if challenge.test_sets.present?
@ -269,7 +287,6 @@ class ShixunsController < ApplicationController
@small_type = shixun_small_type @small_type = shixun_small_type
end end
# 注意这里传参都应该使用params[:shixun]['name']这种格式
def create def create
# 评测脚本的一些操作 # 评测脚本的一些操作
main_type, sub_type = params[:main_type], params[:small_type] main_type, sub_type = params[:main_type], params[:small_type]
@ -314,9 +331,13 @@ class ShixunsController < ApplicationController
# 镜像-实训关联表 # 镜像-实训关联表
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present? ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present?
# 实训主镜像服务配置
ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i)
if sub_type.present? if sub_type.present?
sub_type.each do |mirror| sub_type.each do |mirror|
ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
# 实训子镜像服务配置
ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
end end
end end
@ -362,11 +383,6 @@ class ShixunsController < ApplicationController
end end
def update def update
h = {test_set_permission: params[:test_set_permission], code_hidden: params[:code_hidden],
task_pass: params[:task_pass], hide_code: params[:hide_code], forbid_copy: params[:forbid_copy]}
s_params = shixun_params.merge(h)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@shixun.shixun_mirror_repositories.destroy_all @shixun.shixun_mirror_repositories.destroy_all
@ -378,9 +394,8 @@ class ShixunsController < ApplicationController
ShixunMirrorRepository.create(:shixun_id => @shixun.id, :mirror_repository_id => mirror) ShixunMirrorRepository.create(:shixun_id => @shixun.id, :mirror_repository_id => mirror)
end end
end end
@shixun.update_attributes(shixun_params)
@shixun.update_attributes(s_params) @shixun.shixun_info.update_attributes(shixun_info_params)
@shixun.shixun_info.update_attributes(description: params[:description], evaluate_script: params[:evaluate_script])
@shixun.shixun_schools.delete_all @shixun.shixun_schools.delete_all
if params[:scope_partment].present? && params[:user_scope].to_i == 1 if params[:scope_partment].present? && params[:user_scope].to_i == 1
arr = [] arr = []
@ -394,6 +409,11 @@ class ShixunsController < ApplicationController
use_scope = 0 use_scope = 0
end end
@shixun.update_attributes!(:use_scope => use_scope) @shixun.update_attributes!(:use_scope => use_scope)
# 超级管理员和运营人员才能保存 中间层服务器pod信息的配置
if current_user.admin? || current_user.business?
@shixun.shixun_service_configs.destroy_all
@shixun.shixun_service_configs.create!(service_config_params[:shixun_service_configs])
end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("实训保存失败") tip_exception("实训保存失败")
@ -429,6 +449,7 @@ class ShixunsController < ApplicationController
@choice_small_type = @shixun.small_mirror_id @choice_small_type = @shixun.small_mirror_id
@main_type = shixun_main_type @main_type = shixun_main_type
@small_type = shixun_small_type @small_type = shixun_small_type
@configs = @shixun.shixun_service_configs
#@mirror_script = MirrorScript.select([:id, :script_type]).find(@shixun.mirror_script_id).attributes if @shixun.mirror_script_id && @shixun.mirror_script_id != 0 #@mirror_script = MirrorScript.select([:id, :script_type]).find(@shixun.mirror_script_id).attributes if @shixun.mirror_script_id && @shixun.mirror_script_id != 0
# @shixun_main_mirror = @shixun.show_shixun_mirror # @shixun_main_mirror = @shixun.show_shixun_mirror
# @script_type = @shixun.script_tag.try(:script_type) || "无" # @script_type = @shixun.script_tag.try(:script_type) || "无"
@ -488,17 +509,19 @@ class ShixunsController < ApplicationController
tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}")
end end
current_myshixun = @shixun.current_myshixun(current_user.id) current_myshixun = @shixun.current_myshixun(current_user.id)
min_challenges = @shixun.challenges.pluck(:id , :st)
if current_myshixun if current_myshixun
games = current_myshixun.games
# 如果TPM和TPI的管卡数不相等或者关卡顺序错了说明实训被极大的改动需要重置 # 如果TPM和TPI的管卡数不相等或者关卡顺序错了说明实训被极大的改动需要重置
if current_myshixun.games.count != @shixun.challenges_count || if games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first}
current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id)
uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}")
# 这里页面弹框要收到 当前用户myshixun的identifier. # 这里页面弹框要收到 当前用户myshixun的identifier.
tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game")
end end
# 如果存在实训,则直接进入实训 # 如果存在实训,则直接进入实训
@current_task = current_myshixun.current_task @current_task = current_myshixun.current_task(games)
else else
# 如果未创建关卡一定不能开启实训否则TPI没法找到当前的关卡 # 如果未创建关卡一定不能开启实训否则TPI没法找到当前的关卡
if @shixun.challenges_count == 0 if @shixun.challenges_count == 0
@ -506,17 +529,17 @@ class ShixunsController < ApplicationController
end end
# 判断实训是否全为选择题 # 判断实训是否全为选择题
is_choice_type = @shixun.is_choice_type? is_choice_type = (min_challenges.size == min_challenges.select{|challenge| challenge.last == 1}.count)
if !is_choice_type if !is_choice_type
commit = GitService.commits(repo_path: @repo_path).try(:first) commit = GitService.commits(repo_path: @repo_path).try(:first)
Rails.logger.info("First comit########{commit}") uid_logger("First comit########{commit}")
tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? tip_exception("开启实战前请先在版本库中提交代码") if commit.blank?
commit_id = commit["id"] commit_id = commit["id"]
end end
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
#cloud_bridge = edu_setting('cloud_bridge') cloud_bridge = edu_setting('cloud_bridge')
myshixun_identifier = generate_identifier Myshixun, 10 myshixun_identifier = generate_identifier Myshixun, 10
myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
@ -528,13 +551,13 @@ class ShixunsController < ApplicationController
# fork仓库 # fork仓库
project_fork(myshixun, @repo_path, current_user.login) project_fork(myshixun, @repo_path, current_user.login)
#rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path )
#uid_logger("start openGameInstance") uid_logger("start openGameInstance")
#uri = "#{cloud_bridge}/bridge/game/openGameInstance" uri = "#{cloud_bridge}/bridge/game/openGameInstance"
#logger.info("end openGameInstance") logger.info("end openGameInstance")
#params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last}
#uid_logger("openGameInstance params is #{params}") uid_logger("openGameInstance params is #{params}")
# res = interface_post uri, params, 83, "实训云平台繁忙繁忙等级83" interface_post uri, params, 83, "实训云平台繁忙繁忙等级83"
end end
# 其它创建关卡等操作 # 其它创建关卡等操作
challenges = @shixun.challenges challenges = @shixun.challenges
@ -550,12 +573,7 @@ class ShixunsController < ApplicationController
end end
end end
# REDO:开启实训时更新关联作品的状态 @current_task = myshixun.current_task(myshixun.games)
# TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做
# HomeworksService.new.update_myshixun_work_status myshixun
UpdateMyshixunWorkStatusJob.perform_later(myshixun.id)
@current_task = myshixun.current_task
uid_logger("## shixun exec: myshixun id is #{myshixun.id}") uid_logger("## shixun exec: myshixun id is #{myshixun.id}")
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
@ -565,6 +583,7 @@ class ShixunsController < ApplicationController
end end
end end
end end
# gameID 及实训ID # gameID 及实训ID
# status: 0 , 1 申请过, 2实训关卡路径未填 3 实训标签未填, 4 实训未创建关卡 # status: 0 , 1 申请过, 2实训关卡路径未填 3 实训标签未填, 4 实训未创建关卡
def publish def publish
@ -619,10 +638,21 @@ class ShixunsController < ApplicationController
end end
def add_collaborators def add_collaborators
raise("搜索内容不能为空") unless params[:search]
member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")"
condition = "%#{params[:search].strip}%".gsub(" ","") user_name = "%#{params[:user_name].to_s.strip}%"
@users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'") school_name = "%#{params[:school_name].to_s.strip}%"
if user_name.present? || school_name.present?
@users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND
LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE
'#{school_name}'")
else
@users = User.none
end
page = params[:page] || 1
limit = params[:limit] || 20
@user_count = @users.count
@users = @users.page(page).per(limit)
end end
def shixun_members_added def shixun_members_added
@ -664,14 +694,14 @@ class ShixunsController < ApplicationController
limit = params[:limit] || 20 limit = params[:limit] || 20
if params[:search] if params[:search]
search = "%#{params[:search].to_s.strip.downcase}%" search = "%#{params[:search].to_s.strip.downcase}%"
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0 AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0
AND c.name like '#{search}' ").map(&:id) AND c.name like '#{search}' ").map(&:id)
else else
course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id)
end end
@ -683,7 +713,7 @@ class ShixunsController < ApplicationController
# 将实训发送到课程 # 将实训发送到课程
def send_to_course def send_to_course
@course = Course.find(params[:course_id]) @course = Course.find(params[:course_id])
homework = HomeworksService.new.create_homework shixun, @course, nil, current_user homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user
end end
# 二维码扫描下载 # 二维码扫描下载
@ -706,9 +736,21 @@ class ShixunsController < ApplicationController
private private
def shixun_params def shixun_params
raise("实训名称不能为空") if params[:name].blank? raise("实训名称不能为空") if params[:shixun][:name].blank?
params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission, params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission,
:task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id) :task_pass, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden,
:hide_code, :forbid_copy)
end
def shixun_info_params
raise("实训描述不能为空") if params[:shixun_info][:description].blank?
raise("评测脚本不能为空") if params[:shixun_info][:evaluate_script].blank?
params.require(:shixun_info).permit(:description, :evaluate_script)
end
def service_config_params
params.permit(shixun_service_configs: [:cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id])
end end
def find_shixun def find_shixun
@ -717,10 +759,6 @@ private
normal_status(404, "...") normal_status(404, "...")
return return
end end
if !current_user.shixun_permission(@shixun)
tip_exception(403, "..")
end
end end
def find_repo_name def find_repo_name

@ -25,7 +25,7 @@ class StudentWorksController < ApplicationController
before_action :require_score_id, only: [:destroy_score, :add_score_reply, :appeal_anonymous_score, :deal_appeal_score, :cancel_appeal] before_action :require_score_id, only: [:destroy_score, :add_score_reply, :appeal_anonymous_score, :deal_appeal_score, :cancel_appeal]
before_action :is_evaluation, only: [:show, :supply_attachments] before_action :is_evaluation, :open_work, only: [:show, :supply_attachments]
def new def new
uid_logger("#######new current_user : 1111") uid_logger("#######new current_user : 1111")
@ -43,7 +43,7 @@ class StudentWorksController < ApplicationController
def search_member_list def search_member_list
# 统一设置的作业取所有学生,否则取已发布的分班学生 # 统一设置的作业取所有学生,否则取已发布的分班学生
students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id))
unless params[:search].blank? if !params[:search].blank?
@members = students.joins(user: :user_extension).where("course_members.user_id != #{current_user.id} and (concat(users.lastname, users.firstname) @members = students.joins(user: :user_extension).where("course_members.user_id != #{current_user.id} and (concat(users.lastname, users.firstname)
like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%") like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%")
else else
@ -704,6 +704,11 @@ class StudentWorksController < ApplicationController
[3, 4].include?(@homework.homework_detail_manual.comment_status) [3, 4].include?(@homework.homework_detail_manual.comment_status)
end end
# 作品是否公开
def open_work
tip_exception(403,"没有操作权限") unless (@user_course_identity < Course::STUDENT || current_user == @work.user || @homework.work_public || @is_evaluation)
end
def allow_add_score def allow_add_score
# 老师始终有评阅权限,匿评阶段内,学生对分配给该学生的作品有评阅权限 # 老师始终有评阅权限,匿评阶段内,学生对分配给该学生的作品有评阅权限
tip_exception(403, "没有权限") unless allow_score(@homework, @user_course_identity, current_user.id, @work) tip_exception(403, "没有权限") unless allow_score(@homework, @user_course_identity, current_user.id, @work)

@ -164,8 +164,8 @@ class SubjectsController < ApplicationController
end end
def choose_course def choose_course
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id)
@courses = Course.where(id: course_ids) @courses = Course.where(id: course_ids)
@none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id)

@ -6,9 +6,11 @@ class ZipsController < ApplicationController
before_action :require_admin_or_teacher before_action :require_admin_or_teacher
def shixun_report def shixun_report
student_work_ids = Array.wrap(params[:student_work_ids]) # student_work_ids = Array.wrap(params[:student_work_ids])
# service = BatchExportShixunReportService.new(@homework, @student_work_ids)
service = BatchExportShixunReportService.new(@homework, @all_student_works)
service = BatchExportShixunReportService.new(@homework, student_work_ids)
filename = filename_for_content_disposition(service.filename) filename = filename_for_content_disposition(service.filename)
send_file service.zip, filename: filename, type: 'application/zip' send_file service.zip, filename: filename, type: 'application/zip'
@ -17,7 +19,8 @@ class ZipsController < ApplicationController
end end
def export_exercises def export_exercises
exercises = ExportExercisesService.new(@exercise,@ex_users) @request_url = request.base_url
exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url)
file_name = filename_for_content_disposition(exercises.filename) file_name = filename_for_content_disposition(exercises.filename)
send_file exercises.ex_zip, filename: file_name, type: 'application/zip' send_file exercises.ex_zip, filename: file_name, type: 'application/zip'
@ -46,21 +49,44 @@ class ZipsController < ApplicationController
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")
else else
@course = @exercise.course @course = @exercise.course
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
default_ex_users_size = default_ex_users.size
@ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。
#是否评阅
if params[:review].present?
review_type = params[:review].first.to_i #已评则数据为1未评则数据为0,前端传过来的为数组
if review_type == 1
@ex_users = @ex_users.where("subjective_score >= ?",0.0)
else
@ex_users = @ex_users.where("subjective_score < ?",0.0)
end
end
#答题状态的选择
if params[:commit_status].present? && (params[:commit_status].to_i == 1)
@exercise_users_list = @exercise_users_list.where(commit_status:params[:commit_status])
elsif params[:commit_status].present? && (params[:commit_status].to_i == 0)
normal_status(-1,"仅支持导出已提交的学生!")
end
#可以分班选择 #可以分班选择
if group_id.present? if group_id.present?
exercise_students = @course.students.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数
user_ids = exercise_students.pluck(:user_id).reject(&:blank?) user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq
@ex_users = @ex_users.exercise_commit_users(user_ids) @ex_users = @ex_users.where(user_id: user_ids)
end end
# @ex_users = @ex_users.first(200)
if default_ex_users_size == 0 #搜索
if params[:search].present?
@ex_users = @ex_users.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
end
default_ex_users_size = @ex_users&.size
if default_ex_users_size.blank? || default_ex_users_size == 0
normal_status(-1,"导出失败,暂时没有已提交的学生") normal_status(-1,"导出失败,暂时没有已提交的学生")
elsif default_ex_users_size > 200 elsif default_ex_users_size > 100
normal_status(-1,"导出数量超过200,请分班导出或联系网站管理员导出") normal_status(-2,"100")
end end
end end
rescue Exception => e rescue Exception => e
@ -73,5 +99,33 @@ class ZipsController < ApplicationController
def load_homework def load_homework
@homework = HomeworkCommon.find(params[:homework_common_id]) @homework = HomeworkCommon.find(params[:homework_common_id])
@course = @homework.course @course = @homework.course
##7。2 -hs新增
@member = @course.course_member(current_user.id)
@all_student_works = @homework.teacher_works(@member)
work_status = params[:work_status]
group_id = params[:course_group]
if work_status.present? && !work_status.include?(0)
@all_student_works = @all_student_works.where(work_status:work_status)
elsif work_status.present? && work_status.include?(0)
normal_status(-1,"仅支持导出已提交的学生!")
end
if group_id.present?
group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id)
@all_student_works = @all_student_works.where(user_id: group_user_ids)
end
unless params[:search].blank?
@all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ?
or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
end
student_work_sizes = @all_student_works&.size
if student_work_sizes.blank? || student_work_sizes == 0
normal_status(-1,"导出失败,暂时没有已提交的学生")
elsif student_work_sizes > 100
normal_status(-2,"100")
end
end end
end end

@ -1,6 +1,7 @@
# 所有的方法请按首字母的顺序依次列出 # 所有的方法请按首字母的顺序依次列出
module ApplicationHelper module ApplicationHelper
include Educoder::I18n include Educoder::I18n
include GitHelper
ONE_MINUTE = 60 * 1000 ONE_MINUTE = 60 * 1000
ONE_HOUR = 60 * ONE_MINUTE ONE_HOUR = 60 * ONE_MINUTE
@ -332,6 +333,24 @@ module ApplicationHelper
raw arr.join('') raw arr.join('')
end end
# 导出pdf时转化markdown为html
def to_markdown(text,origin_url)
return nil if text.blank?
options = {
:autolink => true,
:no_intra_emphasis => true,
:fenced_code_blocks => true,
:lax_html_blocks => true,
:strikethrough => true,
:superscript => true,
:tables => true
}
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options)
m_t = markdown.render(text)
m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t
end
end end

@ -1,5 +1,6 @@
module ExercisesHelper module ExercisesHelper
# include GitHelper
#获取每个学生对每个题的答案状态 #获取每个学生对每个题的答案状态
def get_each_student_exercise(exercise_id,exercise_questions,user_id) def get_each_student_exercise(exercise_id,exercise_questions,user_id)
@ -13,7 +14,8 @@ module ExercisesHelper
ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum
end end
if ques_score == q.question_score #满分作答为正确 if ques_score >= q.question_score #满分作答为正确
ques_score = q.question_score
stand_answer = 1 stand_answer = 1
elsif ques_score > 0.0 #部分作答 elsif ques_score > 0.0 #部分作答
stand_answer = 2 stand_answer = 2
@ -35,7 +37,8 @@ module ExercisesHelper
exercise_sub_status.each do |s| exercise_sub_status.each do |s|
sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答 sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答
if sub_answer.present? && sub_answer.first.score >= 0.0 if sub_answer.present? && sub_answer.first.score >= 0.0
if s.question_score == sub_answer.first.score
if s.question_score <= sub_answer.first.score
stand_status = 1 stand_status = 1
else else
stand_status = 2 stand_status = 2
@ -44,7 +47,7 @@ module ExercisesHelper
sub_answer_score = sub_answer.first.score sub_answer_score = sub_answer.first.score
else else
stand_status = 0 stand_status = 0
sub_answer_score = 0.0 sub_answer_score = nil
end end
sub_score = { sub_score = {
@ -52,7 +55,7 @@ module ExercisesHelper
"q_type":s.question_type, "q_type":s.question_type,
"q_position":s.question_number, "q_position":s.question_number,
"stand_status":stand_status, "stand_status":stand_status,
"user_score":sub_answer_score.round(1).to_s "user_score":sub_answer_score.present? ? sub_answer_score.round(1).to_s : nil
} }
@ex_sub_array.push(sub_score) @ex_sub_array.push(sub_score)
end end
@ -164,10 +167,13 @@ module ExercisesHelper
ex_score = ex&.question_score ex_score = ex&.question_score
full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数
no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数
all_zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的及未评阅的 zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的及未评阅的
review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量
un_review_scores = effictive_users_count - review_scores #未评阅数 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数
zero_scores = all_zero_scores - un_review_scores #已评阅且答案未0分的人数 if un_review_scores < 0
un_review_scores = 0
end
# zero_scores = all_zero_scores - un_review_scores #已评阅且答案未0分的人数
main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores]
main_scores_array.each_with_index do |s,index| main_scores_array.each_with_index do |s,index|
if index == 0 if index == 0
@ -419,31 +425,37 @@ module ExercisesHelper
if game.present? if game.present?
exercise_cha_score = 0.0 exercise_cha_score = 0.0
answer_status = 0 answer_status = 0
if game.status == 2 && game.final_score >= 0 # if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score #每一关卡的得分 if game.final_score > 0
exercise_cha_score = game.real_score(exercise_cha.question_score)
# exercise_cha_score = exercise_cha.question_score #每一关卡的得分
answer_status = 1 answer_status = 1
end end
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 code = nil
if exercise_cha.challenge&.path.present?
cha_path = challenge_path(exercise_cha.challenge&.path) cha_path = challenge_path(exercise_cha.challenge&.path)
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
if game_challenge.present? if game_challenge.present?
game_code = game_challenge game_code = game_challenge
code = game_code.try(:new_code) code = game_code.try(:new_code)
else else
code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) code = git_fle_content(game.myshixun.repo_path,cha_path)
end end
end
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了涉及到code的多个版本库的修改
sx_option = { sx_option = {
:exercise_question_id => q.id, :exercise_question_id => q.id,
:exercise_shixun_challenge_id => exercise_cha.id, :exercise_shixun_challenge_id => exercise_cha.id,
:user_id => user.id, :user_id => user.id,
:score => exercise_cha_score, :score => exercise_cha_score.round(1),
:answer_text => code, :answer_text => code,
:status => answer_status :status => answer_status
} }
ExerciseShixunAnswer.create(sx_option) ExerciseShixunAnswer.create(sx_option)
else else
ex_shixun_answer_content.first.update_column('score',exercise_cha_score) ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code)
end end
score5 += exercise_cha_score score5 += exercise_cha_score
else else
@ -504,15 +516,14 @@ module ExercisesHelper
current_user_group_name = course_group.first.name if course_group.present? current_user_group_name = course_group.first.name if course_group.present?
end end
teacher_review = ex_user.subjective_score < 0.0 ? false : true teacher_review = ex_user.subjective_score < 0.0 ? false : true
if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看
# if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数
ex_object_score = nil
ex_subject_score = nil
score = nil
else
ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s
ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s
score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s
else
ex_object_score = nil
ex_subject_score = nil
score = nil
end end
{ {
@ -624,16 +635,25 @@ module ExercisesHelper
#学生的分数状态及回答的内容 #学生的分数状态及回答的内容
def user_question_answers(q,ex_answerer_id,student_status,is_teacher_or,ex_status,ques_type,ex_type) def user_question_answers(q,ex_answerer_id,student_status,is_teacher_or,ex_status,ques_type,ex_type)
answered_content = [] answered_content = []
user_score = 0.0 user_score = nil
shixun_type = 0 shixun_type = 0
question_comment = [] question_comment = []
if q.question_type == 5 if ques_type == 5
exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id)
else else
exercise_answers = q.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答 exercise_answers = q.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答
end end
if student_status == 2 #当前为老师,或为学生且已提交 if student_status == 2 #当前为老师,或为学生且已提交
user_score = exercise_answers.score_reviewed.pluck(:score).sum user_score_pre = exercise_answers.score_reviewed
if ques_type == 4 && user_score_pre.blank? #主观题时且没有大于0的分数时为空
user_score = nil
else
user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0
end
end
if user_score.present? && (user_score > q.question_score)
user_score = q.question_score
end end
if ques_type <= 2 if ques_type <= 2
answered_content = exercise_answers.pluck(:exercise_choice_id) answered_content = exercise_answers.pluck(:exercise_choice_id)
@ -661,7 +681,7 @@ module ExercisesHelper
question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id) question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id)
end end
{ {
"user_score": user_score.round(1), "user_score": (user_score.present? ? user_score.round(1).to_s : nil),
"answered_content":answered_content, "answered_content":answered_content,
"shixun_type":shixun_type, "shixun_type":shixun_type,
"question_comment":question_comment "question_comment":question_comment
@ -714,6 +734,6 @@ module ExercisesHelper
#实训题学生代码的行数 #实训题学生代码的行数
def content_line(content) def content_line(content)
content.split(/\r?\n/).length content.split(/\r?\n/).length + 1
end end
end end

@ -37,14 +37,14 @@ module ExportHelper
end end
normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语) normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语)
@work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?)
works.each_with_index do |w, index| works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index|
w_user = w.user w_user = w.user
w_1 = (index + 1) w_1 = (index + 1)
w_2 = w_user.login w_2 = w_user.login
w_3 = w_user.real_name w_3 = w_user.real_name
w_3_1 = w_user.mail w_3_1 = w_user.mail
w_4 = w_user.student_id.present? ? w_user.student_id : "--" w_4 = w_user.student_id.present? ? w_user.student_id : "--"
course_name = course.course_member(w.user_id).try(:course_group_name) course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name)
w_5 = course_name.present? ? course_name : "--" w_5 = course_name.present? ? course_name : "--"
#0 未提交, 1 按时提交, 2 延迟提交 #0 未提交, 1 按时提交, 2 延迟提交
if w.work_status == 0 if w.work_status == 0
@ -118,7 +118,7 @@ module ExportHelper
end end
shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语)
@work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?)
works.each_with_index do |w, index| works.includes(:student_works_scores, user: :user_extension, myshixun: :games).each_with_index do |w, index|
myshixun = w.try(:myshixun) myshixun = w.try(:myshixun)
w_user = w.user w_user = w.user
w_1 = (index + 1) w_1 = (index + 1)
@ -126,7 +126,7 @@ module ExportHelper
w_3 = w_user.real_name w_3 = w_user.real_name
w_3_1 = w_user.mail w_3_1 = w_user.mail
w_4 = w_user.student_id.present? ? w_user.student_id : "--" w_4 = w_user.student_id.present? ? w_user.student_id : "--"
course_name = course.course_member(w.user_id).try(:course_group_name) course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name)
w_5 = course_name.present? ? course_name : "--" w_5 = course_name.present? ? course_name : "--"
#0 未提交, 1 按时提交, 2 延迟提交 #0 未提交, 1 按时提交, 2 延迟提交
if w.work_status == 0 if w.work_status == 0
@ -138,7 +138,7 @@ module ExportHelper
else else
w_6 = "--" w_6 = "--"
end end
w_7 = w.work_status == 0 ? '--' : myshixun.try(:passed_count).to_s+"/"+shixun.challenges.count.to_s w_7 = w.work_status == 0 ? '--' : myshixun.try(:passed_count).to_s+"/"+shixun.challenges_count.to_s
w_8 = myshixun ? myshixun.try(:passed_time) == "--" ? "--" : format_time(myshixun.try(:passed_time)) : "--" # 通关时间 w_8 = myshixun ? myshixun.try(:passed_time) == "--" ? "--" : format_time(myshixun.try(:passed_time)) : "--" # 通关时间
w_9 = myshixun ? (myshixun.try(:passed_count) > 0 ? myshixun.total_spend_time : '--') : "--" #总耗时 w_9 = myshixun ? (myshixun.try(:passed_count) > 0 ? myshixun.total_spend_time : '--') : "--" #总耗时
w_10 = myshixun ? myshixun.output_times : 0 #评测次数 w_10 = myshixun ? myshixun.output_times : 0 #评测次数
@ -204,7 +204,7 @@ module ExportHelper
@head_cells_column = head_cells_format @head_cells_column = head_cells_format
@task_cells_column = [] @task_cells_column = []
items.each_with_index do |work,index| items.includes(user: :user_extension).each_with_index do |work,index|
w_1 = (index+1) w_1 = (index+1)
w_user = work.user w_user = work.user
w_2 = w_user.login w_2 = w_user.login
@ -260,20 +260,10 @@ module ExportHelper
else else
@table_columns = @table_columns + %w(最终成绩 开始答题时间 提交时间) @table_columns = @table_columns + %w(最终成绩 开始答题时间 提交时间)
end end
export_ex_users.each_with_index do |e_user,index| export_ex_users.includes(user: :user_extension).each_with_index do |e_user,index|
user_info = e_user.user user_info = e_user.user
user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id).first member = course.students.find_by_user_id(e_user.user_id)
if user_course_id.present? user_course = member.try(:course_group_name)
get_course_group_id = user_course_id.course_group_id
if get_course_group_id.present? && get_course_group_id != 0
user_course_info = CourseGroup.by_group_ids(get_course_group_id)
user_course = user_course_info.first.name
else
user_course = "--"
end
else
user_course = "--"
end
user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s
user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s
user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0 user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0
@ -305,7 +295,7 @@ module ExportHelper
@topic_body_cells = [] @topic_body_cells = []
if students.count > 0 if students.count > 0
students.each_with_index do |student, index| students.includes(user: :user_extension).each_with_index do |student, index|
user = student.user user = student.user
student_topic = course.student_graduation_topics.user_topics_accept(user.id).first student_topic = course.student_graduation_topics.user_topics_accept(user.id).first
if student_topic.present? if student_topic.present?
@ -318,7 +308,7 @@ module ExportHelper
w_2 = user.login w_2 = user.login
w_3 = user.real_name w_3 = user.real_name
w_3_1 = user.mail w_3_1 = user.mail
w_4 = user.user_extension.student_id w_4 = user.student_id
w_5 = student.course_group_name w_5 = student.course_group_name
w_6 = topic.present? ? topic.name : "--" w_6 = topic.present? ? topic.name : "--"
w_7 = topic.present? ? topic.teacher.full_name : "--" w_7 = topic.present? ? topic.teacher.full_name : "--"
@ -375,11 +365,11 @@ module ExportHelper
end end
if file_size > MAX_DOWN_SIZE if file_size > MAX_DOWN_SIZE
status = -1 status = -2
elsif file_count > 0 elsif file_count > 0
status = 0 status = 0
else else
status = -2 status = -1
end end
status status
end end
@ -514,4 +504,7 @@ module ExportHelper
attach.filename attach.filename
end end
def format_sheet_name name
name = name.gsub(":", "-")
end
end end

@ -65,7 +65,7 @@ module HomeworkCommonsHelper
# 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份 # 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份
if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN || if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN ||
(identity < Course::STUDENT && teacher_course_groups.size == 0) (identity < Course::STUDENT && teacher_course_groups.blank?)
case ho_detail_manual.comment_status case ho_detail_manual.comment_status
when 0 when 0
status << "未发布" status << "未发布"

@ -3,8 +3,8 @@ module PollsHelper
#获取试卷的已答/未答人数 #获取试卷的已答/未答人数
def get_poll_answers(poll_users) def get_poll_answers(poll_users)
@commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的 @commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的
@poll_answers = @commit_poll_users.present? ? @commit_poll_users.count : 0 #表示已经提交了的用户 @poll_answers = @commit_poll_users.present? ? @commit_poll_users.size : 0 #表示已经提交了的用户
course_all_members_count = poll_users.present? ? poll_users.count : 0 course_all_members_count = poll_users.present? ? poll_users.size : 0
@poll_unanswers = (course_all_members_count - @poll_answers) @poll_unanswers = (course_all_members_count - @poll_answers)
end end
@ -110,7 +110,7 @@ module PollsHelper
poll_user_name = user.nickname poll_user_name = user.nickname
end end
course_member = course_members.find_by(user_id:user.id) course_member = course_members.find_by(user_id:user.id)
course_group_id = course_members.present? ? course_member.course_group_id : nil course_group_id = course_member.present? ? course_member.course_group_id : nil
if course_group_id == 0 if course_group_id == 0
course_group_name = "未分班" course_group_name = "未分班"
else else

@ -145,7 +145,7 @@ module StudentWorksHelper
else else
user_name = message_user.real_name user_name = message_user.real_name
user_login = message_user.login user_login = message_user.login
image_url = url_to_avatar(score.user) image_url = url_to_avatar(message_user)
end end
{user_name: user_name, user_login: user_login, user_image_url: image_url} {user_name: user_name, user_login: user_login, user_image_url: image_url}
end end

@ -2,11 +2,20 @@
class ExercisePublishNotifyJob < ApplicationJob class ExercisePublishNotifyJob < ApplicationJob
queue_as :notify queue_as :notify
def perform(exercise_id, receiver_ids) def perform(exercise_id, group_ids)
exercise = Exercise.find_by(id: exercise_id) exercise = Exercise.find_by(id: exercise_id)
return if exercise.blank? return if exercise.blank?
user = exercise.user user = exercise.user
if group_ids.present?
students = course.students.where(course_group_id: group_ids)
subquery = course.teacher_course_groups.where(course_group_id: group_ids).select(:course_member_id)
teachers = course.teachers.where(id: subquery)
else
students = course.students
teachers = course.teachers
end
attrs = %i[ attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type user_id trigger_user_id container_id container_type parent_container_id parent_container_type
belong_container_id belong_container_type viewed tiding_type created_at updated_at belong_container_id belong_container_type viewed tiding_type created_at updated_at
@ -19,14 +28,14 @@ class ExercisePublishNotifyJob < ApplicationJob
viewed: 0, tiding_type: 'Exercise' viewed: 0, tiding_type: 'Exercise'
} }
Tiding.bulk_insert(*attrs) do |worker| Tiding.bulk_insert(*attrs) do |worker|
teacher_ids = exercise.course.teachers.pluck(:user_id) teacher_ids = teachers.pluck(:user_id)
unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids)
exercise.course.teachers.find_each do |teacher| teacher_ids.find_each do |user_id|
worker.add same_attrs.merge(user_id: teacher.user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end
receiver_ids.each do |user_id| students.pluck(:user_id).each do |user_id|
worker.add same_attrs.merge(user_id: user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end

@ -0,0 +1,39 @@
# 毕设任务的交叉评阅分配
class GraduationTaskCrossCommentJob < ApplicationJob
queue_as :evaluation_comment
def perform(graduation_task_id)
task = GraduationTask.find_by(id: graduation_task_id)
return if task.blank?
course = task.course
task.graduation_task_group_assignations.each do |assignation|
graduation_group = assignation.graduation_group
assign_group = assignation.assign_group
if graduation_group.present? && assign_group.present?
course_group_ids = course.teacher_course_groups.where(course_member_id: graduation_group.course_members.pluck(:id)).pluck(:course_group_id)
graduation_works = task.graduation_works.where(user_id: course.course_members.where(:course_group_id => course_group_ids).map(&:user_id),
work_status: [1, 2])
if assign_group.course_members.count <= task.comment_num
graduation_works.each do |work|
assign_group.course_members.each do |member|
work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(
graduation_group_id: assign_group.id, user_id: member.user_id, graduation_task_id: task.id)
end
end
else
member_user_ids = assign_group.course_members.pluck(:user_id)
count = 0
graduation_works.each do |work|
for i in 1 .. task.comment_num
assign_user_id = member_user_ids[count % member_user_ids.size]
work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(
graduation_group_id: assign_group.id, user_id: assign_user_id, graduation_task_id: task.id)
count += 1
end
end
end
end
end
end
end

@ -18,8 +18,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob
viewed: 0, tiding_type: 'GraduationTask' viewed: 0, tiding_type: 'GraduationTask'
} }
Tiding.bulk_insert(*attrs) do |worker| Tiding.bulk_insert(*attrs) do |worker|
task.course.students.find_each do |student| task.course.course_members.pluck(:user_id).uniq.find_each do |user_id|
worker.add same_attrs.merge(user_id: student.user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end
end end

@ -0,0 +1,33 @@
class HomeworkAbsencePenaltyCalculationJob < ApplicationJob
queue_as :score
def perform(homework_common_id)
homework_common = HomeworkCommon.find_by(id: homework_common_id)
return if homework_common.blank?
#计算缺评扣分 参与匿评
work_ids = homework_common.student_works.has_committed.pluck(:id)
homework_detail_manual = homework_common.homework_detail_manual
homework_common.student_works.where("work_status != 0").each do |student_work|
absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count -
student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count
student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0
student_work.save
end
# 未参与匿评
if homework_detail_manual.no_anon_penalty == 0
all_dis_eva = StudentWorksEvaluationDistribution.where(student_work_id: work_ids)
has_sw_count = all_dis_eva.select("distinct user_id").count
anon_count = all_dis_eva.count / has_sw_count
homework_common.student_works.where("work_status != 0").each do |student_work|
if student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count == 0
student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count
student_work.save
end
end
end
end
end

@ -0,0 +1,28 @@
# 匿评申诉开启时给分配了匿评的学生发消息
class HomeworkAnonymousAppealStartNotifyJob < ApplicationJob
queue_as :notify
def perform(homework_common_id)
homework = HomeworkCommon.find_by(id: homework_common_id)
return if homework.blank?
eva_distribution = StudentWorksEvaluationDistribution.where(student_work_id: homework.student_works.pluck(:id))
attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
belong_container_id belong_container_type viewed tiding_type created_at updated_at
]
same_attrs = {
trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon',
parent_container_id: homework.id, parent_container_type: 'AnonymousAppeal',
belong_container_id: homework.course_id, belong_container_type: 'Course',
viewed: 0, tiding_type: 'HomeworkCommon'
}
Tiding.bulk_insert(*attrs) do |worker|
eva_distribution.pluck(:user_id).uniq.each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end
end
end

@ -24,7 +24,7 @@ class HomeworkCommonPushNotifyJob < ApplicationJob
same_attrs = { same_attrs = {
trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon',
parent_container_id: homework.id, parent_container_type: 'HomeworkPublish', parent_container_id: homework.id, parent_container_type: 'HomeworkPublish',
belong_container_id: task.course_id, belong_container_type: 'Course', belong_container_id: homework.course_id, belong_container_type: 'Course',
viewed: 0, tiding_type: 'HomeworkCommon' viewed: 0, tiding_type: 'HomeworkCommon'
} }
Tiding.bulk_insert(*attrs) do |worker| Tiding.bulk_insert(*attrs) do |worker|

@ -0,0 +1,48 @@
class HomeworkEvaluationCommentAssginJob < ApplicationJob
queue_as :evaluation_comment
def get_assigned_homeworks(student_works, n, index)
student_works += student_works
student_works[index + 1..index + n]
end
def perform(homework_common_id)
homework_common = HomeworkCommon.find_by(id: homework_common_id)
return if homework_common.blank?
homework_detail_manual = homework_common.homework_detail_manual
if homework_common.homework_type == "group"
student_works = homework_common.student_works.where("work_status != 0").group(:group_id)
student_work_projects = homework_common.student_works.where("work_status != 0").shuffle
student_work_projects.each do |pro_work|
n = homework_detail_manual.evaluation_num
n = (n < student_works.length && n != -1) ? n : student_works.length - 1
work_index = -1
student_works.each_with_index do |stu_work, stu_index|
if stu_work.group_id.to_i == pro_work.group_id.to_i
work_index = stu_index
end
end
assigned_homeworks = get_assigned_homeworks(student_works, n, work_index)
assigned_homeworks.each do |h|
student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id)
student_works_evaluation_distributions.save
end
end
else
student_works = homework_common.student_works.has_committed
student_works = student_works.shuffle
student_works.each_with_index do |work, index|
user = work.user
n = homework_detail_manual.evaluation_num
n = (n < student_works.size && n != -1) ? n : student_works.size - 1
assigned_homeworks = get_assigned_homeworks(student_works, n, index)
assigned_homeworks.each do |h|
student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id)
student_works_evaluation_distributions.save
end
end
end
end
end

@ -0,0 +1,30 @@
class HomeworkEvaluationStartNotifyJob < ApplicationJob
queue_as :notify
def perform(homework_common_id, content)
homework = HomeworkCommon.find_by(id: homework_common_id)
return if homework.blank?
course = homework.course
members = content.blank? ? course.course_members : course.teachers
tiding_type = content.blank? ? "HomeworkCommon" : "System"
attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type
belong_container_id belong_container_type viewed tiding_type extra created_at updated_at
]
same_attrs = {
trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon',
parent_container_id: homework.id, parent_container_type: 'AnonymousComment',
belong_container_id: homework.course_id, belong_container_type: 'Course',
viewed: 0, tiding_type: tiding_type, extra: content
}
Tiding.bulk_insert(*attrs) do |worker|
member_ids = members.pluck(:user_id).uniq
member_ids.each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end
end
end

@ -1,6 +1,6 @@
class HomeworkPublishUpdateWorkStatusJob < ApplicationJob class HomeworkPublishUpdateWorkStatusJob < ApplicationJob
# 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩
queue_as :default queue_as :score
def perform(group_ids, homework_id) def perform(group_ids, homework_id)
# Do something later # Do something later

@ -2,10 +2,20 @@
class PollPublishNotifyJob < ApplicationJob class PollPublishNotifyJob < ApplicationJob
queue_as :notify queue_as :notify
def perform(poll_id, receiver_ids) def perform(poll_id, group_ids)
poll = Poll.find_by(id: poll_id) poll = Poll.find_by(id: poll_id)
return if poll.blank? return if poll.blank?
user = poll.user user = poll.user
course = poll.course
if group_ids.present?
students = course.students.where(course_group_id: group_ids)
subquery = course.teacher_course_groups.where(course_group_id: group_ids).select(:course_member_id)
teachers = course.teachers.where(id: subquery)
else
students = course.students
teachers = course.teachers
end
attrs = %i[ attrs = %i[
user_id trigger_user_id container_id container_type parent_container_id parent_container_type user_id trigger_user_id container_id container_type parent_container_id parent_container_type
@ -19,14 +29,14 @@ class PollPublishNotifyJob < ApplicationJob
viewed: 0, tiding_type: 'Poll' viewed: 0, tiding_type: 'Poll'
} }
Tiding.bulk_insert(*attrs) do |worker| Tiding.bulk_insert(*attrs) do |worker|
teacher_ids = poll.course.teachers.pluck(:user_id) teacher_ids = teachers.pluck(:user_id)
unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids)
poll.course.teachers.find_each do |teacher| teacher_ids.find_each do |user_id|
worker.add same_attrs.merge(user_id: teacher.user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end
receiver_ids.each do |user_id| students.pluck(:user_id).each do |user_id|
worker.add same_attrs.merge(user_id: user_id) worker.add same_attrs.merge(user_id: user_id)
end end
end end

@ -20,7 +20,7 @@ class Challenge < ApplicationRecord
# acts_as_attachable # acts_as_attachable
scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time,
:web_route, :answer]) } :web_route, :answer, :exec_time]) }
scope :choose_type, -> { where(st: 1) } scope :choose_type, -> { where(st: 1) }
scope :practice_type, -> { where(st: 0) } scope :practice_type, -> { where(st: 0) }
@ -51,9 +51,8 @@ class Challenge < ApplicationRecord
end end
# 开启挑战 # 开启挑战
def open_game(user_id) def open_game user_id, shixun
game = self.games.select([:status, :identifier]).where(user_id: user_id).first game = self.games.where(user_id: user_id).first
shixun = self.shixun
if game.present? if game.present?
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
else else
@ -61,11 +60,24 @@ class Challenge < ApplicationRecord
end end
end end
# # 开启挑战
# def open_game(user_id, shixun)
#
#
# game = self.games.select([:status, :identifier]).where(user_id: user_id).first
# game = self.games.select{|game| game.user_id == user_id}
# if game.present?
# shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
# else
# "/api/shixuns/#{shixun.identifier}/shixun_exec"
# end
# end
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games # todo: 以前没加索引导致相同关卡,同一用户有多个games
game = self.games.where(user_id: user_id).last game = games.last
status =
if game.blank? if game.blank?
self.position == 1 ? 1 : 0 self.position == 1 ? 1 : 0
elsif game.status == 2 elsif game.status == 2

@ -1,5 +1,5 @@
class ChallengeTag < ApplicationRecord class ChallengeTag < ApplicationRecord
belongs_to :challenge, counter_cache: true belongs_to :challenge, counter_cache: true
belongs_to :challenge_choose belongs_to :challenge_choose, optional: true
end end

@ -2,4 +2,26 @@ class Department < ApplicationRecord
belongs_to :school belongs_to :school
has_many :department_members, dependent: :destroy has_many :department_members, dependent: :destroy
after_create_commit :reset_data_cache
after_update_commit :reset_data_cache
def self.cached_names_data(school)
Rails.cache.fetch(names_data_cache_key(school.id), expires_in: 7.days) do
school.departments.select(:id, :name).as_json
end
end
private
def reset_data_cache
# 清除部门名称缓存
if new_record? || name_previously_changed?
Rails.cache.delete(self.class.names_data_cache_key(school_id))
end
end
def self.names_data_cache_key(school_id)
"schools/#{school_id}/department_names_data"
end
end end

@ -33,10 +33,16 @@ class Discuss < ApplicationRecord
"/tasks/#{game&.identifier}" "/tasks/#{game&.identifier}"
end end
def contents(shixun, user) # def contents(shixun, user)
return content unless hidden? # return content unless hidden?
#
shixun.has_manager?(user) ? content : '违规评论已被屏蔽!' # shixun.has_manager?(user) ? content : ''
# end
def child_discuss(user)
user.admin? ?
Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) :
Discuss.where(parent_id: self.id, :hidden => false).includes(:user).reorder(created_at: :asc)
end end
private private

@ -3,11 +3,12 @@ class Exercise < ApplicationRecord
belongs_to :exercise_bank, optional: true belongs_to :exercise_bank, optional: true
belongs_to :user belongs_to :user
has_many :exercise_users,:dependent => :destroy has_many :exercise_users, -> { where("is_delete = 0") }, :dependent => :delete_all
has_many :exercise_questions,:dependent => :destroy has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
has_many :exercise_group_settings,:dependent => :destroy has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all
has_many :tidings, as: :container has_many :tidings, as: :container
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
scope :is_exercise_published, -> { where("exercise_status > ? ",1)} scope :is_exercise_published, -> { where("exercise_status > ? ",1)}
scope :unified_setting, -> { where("unified_setting = ?",true) } scope :unified_setting, -> { where("unified_setting = ?",true) }

@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :exercise_question belongs_to :exercise_question
belongs_to :exercise_choice, optional: true belongs_to :exercise_choice, optional: true
has_many :exercise_answer_comments, :dependent => :destroy has_many :exercise_answer_comments, :dependent => :delete_all
scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)}
scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)}

@ -1,9 +1,10 @@
class ExerciseChoice < ApplicationRecord class ExerciseChoice < ApplicationRecord
belongs_to :exercise_question belongs_to :exercise_question
has_many :exercise_answers, :dependent => :destroy has_many :exercise_answers, :dependent => :delete_all
has_many :exercise_standard_answers, :dependent => :destroy has_many :exercise_standard_answers, :dependent => :delete_all
scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
end end

@ -4,19 +4,18 @@ class ExerciseQuestion < ApplicationRecord
belongs_to :exercise belongs_to :exercise
belongs_to :shixun, optional: true belongs_to :shixun, optional: true
has_many :exercise_choices, :dependent => :destroy has_many :exercise_choices, :dependent => :delete_all
has_many :exercise_answers, :dependent => :destroy has_many :exercise_answers
has_many :exercise_shixun_challenges,:dependent => :destroy has_many :exercise_shixun_challenges, :dependent => :delete_all
has_many :exercise_shixun_answers, :dependent => :destroy has_many :exercise_shixun_answers
has_many :exercise_answer_comments, :dependent => :destroy has_many :exercise_answer_comments
has_many :exercise_standard_answers, :dependent => :destroy has_many :exercise_standard_answers
scope :insert_question_ex, lambda {|k| where("question_number > ?",k)} scope :insert_question_ex, lambda {|k| where("question_number > ?",k)}
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
# scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
# scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
def question_type_name def question_type_name
case self.question_type case self.question_type

@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord
belongs_to :exercise_question belongs_to :exercise_question
belongs_to :user belongs_to :user
belongs_to :exercise_shixun_challenge belongs_to :exercise_shixun_challenge
has_many :exercise_answer_comments, :dependent => :destroy has_many :exercise_answer_comments, :dependent => :delete_all
# status 0: 未通过, 1通过 # status 0: 未通过, 1通过
# attr_accessible :answer_text, :score, :status # attr_accessible :answer_text, :score, :status
scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)}

@ -16,7 +16,8 @@ class GraduationTask < ApplicationRecord
has_many :graduation_task_group_assignations, dependent: :destroy has_many :graduation_task_group_assignations, dependent: :destroy
has_many :graduation_work_comment_assignations, dependent: :destroy has_many :graduation_work_comment_assignations, dependent: :destroy
has_many :graduation_works, -> { where("is_delete != 1") } has_many :graduation_works, -> { where("is_delete = 0") }
has_many :score_graduation_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "GraduationWork"
has_many :graduation_work_scores has_many :graduation_work_scores
belongs_to :gtask_bank, optional: true belongs_to :gtask_bank, optional: true

@ -53,7 +53,7 @@ class GraduationWork < ApplicationRecord
# 分班名 # 分班名
def class_grouping_name def class_grouping_name
CourseMember.find_by(user_id: self.user_id, course_id: self.course_id, role: 4).try(:course_group).try(:name) || '未分班' CourseMember.find_by(course_id: self.course_id, user_id: self.user_id, role: 4).try(:course_group).try(:name) || '未分班'
end end
# 分组名 # 分组名
@ -63,7 +63,7 @@ class GraduationWork < ApplicationRecord
#用户是否有查看分数的权限 #用户是否有查看分数的权限
def check_score_power? current_user, course_identity def check_score_power? current_user, course_identity
self.work_score.present? || course_identity < Course::STUDENT || self.user_id = current_user.id self.work_score.present? && (course_identity < Course::STUDENT || self.user_id = current_user.id || graduation_task.open_score)
end end
# 作品是否能够分配指导老师 # 作品是否能够分配指导老师

@ -3,7 +3,8 @@ class HomeworkCommon < ApplicationRecord
enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true
has_many :homework_group_settings, dependent: :destroy has_many :homework_group_settings, dependent: :destroy
has_many :published_settings, -> { group_published }, class_name: "HomeworkGroupSetting" has_many :published_settings, -> { group_published }, class_name: "HomeworkGroupSetting"
has_many :student_works, -> { where("is_delete != 1") } has_many :student_works, -> { where("is_delete = 0") }
has_many :score_student_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "StudentWork"
has_one :homework_detail_manual, dependent: :destroy has_one :homework_detail_manual, dependent: :destroy
# 分组作业的设置 # 分组作业的设置
@ -78,8 +79,7 @@ class HomeworkCommon < ApplicationRecord
# 根据是否统一发布获取作业的作品列表 # 根据是否统一发布获取作业的作品列表
def all_works def all_works
student_works = self.unified_setting ? self.student_works : student_works = self.unified_setting ? self.student_works :
self.student_works.joins("join course_members on student_works.user_id=course_members.user_id"). self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)})
end end
# 分班权限的老师可见的作品列表 # 分班权限的老师可见的作品列表
@ -90,7 +90,7 @@ class HomeworkCommon < ApplicationRecord
# 有分班权限的统计管理的分班且已发布的学生情况 # 有分班权限的统计管理的分班且已发布的学生情况
if member.present? && teacher_course_groups.size > 0 if member.present? && teacher_course_groups.size > 0
group_ids = teacher_course_groups.pluck(:course_group_id) group_ids = teacher_course_groups.pluck(:course_group_id)
all_student_works = all_student_works.joins("join course_members course_members on student_works.user_id=course_members.user_id"). all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id").
where(course_members: {course_group_id: group_ids}) where(course_members: {course_group_id: group_ids})
end end
all_student_works all_student_works
@ -119,6 +119,11 @@ class HomeworkCommon < ApplicationRecord
status status
end end
# 作业是否补交截止或者不允许补交且提交截止(不考虑分班)
def end_or_late_none_group
course.is_end || (allow_late && late_time < Time.now) || (!allow_late && end_time < Time.now)
end
# 作业是否可以查重 # 作业是否可以查重
def code_review def code_review
self.homework_type == 'practice' && self.publish_time.present? && self.publish_time < Time.now && self.homework_group_reviews.count == 0 self.homework_type == 'practice' && self.publish_time.present? && self.publish_time < Time.now && self.homework_group_reviews.count == 0
@ -170,12 +175,8 @@ class HomeworkCommon < ApplicationRecord
#删除时更新题库中的引用数 #删除时更新题库中的引用数
def update_homework_bank_quotes def update_homework_bank_quotes
old_banks = self.homework_bank old_bank = self.homework_bank
unless old_banks.blank? old_bank.update_attributes(quotes: (old_bank.quotes - 1) > 0 ? (old_bank.quotes - 1) : 0, homework_common_id: nil) if old_bank.present?
old_banks.each do |bank|
bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil)
end
end
end end
# 查重是否有新结果 # 查重是否有新结果
@ -236,9 +237,13 @@ class HomeworkCommon < ApplicationRecord
# 作业的分班设置时间 # 作业的分班设置时间
def homework_group_setting user_id def homework_group_setting user_id
if unified_setting
homework_setting = self
else
member = course.course_member(user_id) member = course.course_member(user_id)
group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id)) group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id))
homework_setting = group_setting.present? ? group_setting : self homework_setting = group_setting.present? ? group_setting : self
end
homework_setting homework_setting
end end

@ -18,7 +18,7 @@ class Myshixun < ApplicationRecord
end end
def output_times def output_times
games.sum(:evaluate_count) games.pluck(:evaluate_count).sum.to_i
end end
def repo_path def repo_path
@ -53,14 +53,12 @@ class Myshixun < ApplicationRecord
end end
# 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录) # 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录)
# status:0 可以测评的,正在测评 # status:0 可以测评的; 1 正在测评的; 2评测通过的 3未开启
# 如果都完成,则当前任务为最后一个任务 # 如果都完成,则当前任务为最后一个任务
def current_task def current_task games
games = self.games
current_game = games.select{|game| game.status == 1 || game.status == 0}.first current_game = games.select{|game| game.status == 1 || game.status == 0}.first
if current_game.blank? if current_game.blank?
current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} current_game = games.last
and g.challenge_id = c.id and g.status = 2 order by c.position desc").first
end end
current_game current_game
end end
@ -74,12 +72,12 @@ class Myshixun < ApplicationRecord
# 个人实训得分 # 个人实训得分
def total_score def total_score
self.games.select{|game| game.status = 2 && game.final_score > 0}.pluck(:final_score).sum.to_i self.games.select{|game| game.status == 2 && game.final_score > 0}.pluck(:final_score).sum.to_i
end end
# 个人通关数 # 个人通关数
def passed_count def passed_count
self.games.select{|game| game.status = 2}.size self.games.select{|game| game.status == 2}.size
end end
# 通关时间 # 通关时间
@ -94,7 +92,7 @@ class Myshixun < ApplicationRecord
# 通关总耗时 # 通关总耗时
def total_cost_time def total_cost_time
self.games.select{|game| game.status = 2}.map(&:cost_time).sum.to_i self.games.select{|game| game.status == 2}.map(&:cost_time).sum.to_i
end end
end end

@ -4,13 +4,13 @@ class Poll < ApplicationRecord
belongs_to :exercise_bank, optional: true belongs_to :exercise_bank, optional: true
# belongs_to :exercise_bank # belongs_to :exercise_bank
has_many :poll_questions,dependent: :destroy has_many :poll_questions,dependent: :delete_all
has_many :poll_users, :dependent => :destroy has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
has_many :poll_group_settings, :dependent => :destroy has_many :poll_group_settings, :dependent => :delete_all
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all
has_many :tidings, as: :container, dependent: :destroy has_many :tidings, as: :container, dependent: :delete_all
scope :publish_or_not, -> { where("polls_status > ? ",1)} scope :publish_or_not, -> { where("polls_status > ? ",1)}
scope :only_public, -> {where("is_public = ?",true)} scope :only_public, -> {where("is_public = ?",true)}
@ -52,12 +52,12 @@ class Poll < ApplicationRecord
# 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
def all_poll_users(user_id) def all_poll_users(user_id)
poll_users = self.poll_users poll_all_users = poll_users
group_ids = poll_published_ids(user_id) group_ids = poll_published_ids(user_id)
if group_ids.present? if group_ids.present?
poll_users = poll_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id).uniq)
end end
poll_users poll_all_users
end end
#当前用户已发布的班级id和试卷分组已发布的班级id的交集 #当前用户已发布的班级id和试卷分组已发布的班级id的交集
@ -137,16 +137,17 @@ class Poll < ApplicationRecord
#判断当前用户的答题状态 #判断当前用户的答题状态
def check_user_votes_status(user) def check_user_votes_status(user)
poll_answer_user = poll_users.find_by(user_id: user.id) poll_answer_user = poll_users.find_by(user_id: user.id)
user_poll_status = get_poll_status(user.id) # user_poll_status = get_poll_status(user.id)
user_status = 2 user_status = 2
if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的
user_status = poll_answer_user.commit_status user_status = poll_answer_user.commit_status
end end
#
if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 # if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3
user_status = 4 # # user_status = 4
end # user_status = 2 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示
# end
user_status user_status
end end

@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord
# include Redmine::SafeAttributes # include Redmine::SafeAttributes
belongs_to :poll_question belongs_to :poll_question
has_many :poll_votes, :dependent => :destroy has_many :poll_votes, :dependent => :delete_all
scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题
scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题

@ -1,9 +1,9 @@
class PollQuestion < ApplicationRecord class PollQuestion < ApplicationRecord
belongs_to :poll belongs_to :poll
has_many :poll_answers, :dependent => :destroy has_many :poll_answers, :dependent => :delete_all
attr_accessor :question_answers, :question_other_anser attr_accessor :question_answers, :question_other_anser
has_many :poll_votes, :dependent => :destroy has_many :poll_votes
scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :ques_necessary, -> {where("is_necessary = ?",1)}

@ -1,6 +1,5 @@
class Repertoire < ApplicationRecord class Repertoire < ApplicationRecord
has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy
has_many :sub_repertoires
has_many :tag_repertoires, through: :sub_repertoires has_many :tag_repertoires, through: :sub_repertoires
end end

@ -1,4 +1,6 @@
class School < ApplicationRecord class School < ApplicationRecord
has_many :departments, dependent: :destroy
has_many :shixun_schools, :dependent => :destroy has_many :shixun_schools, :dependent => :destroy
has_many :shixuns, :through => :shixun_schools has_many :shixuns, :through => :shixun_schools
@ -8,6 +10,9 @@ class School < ApplicationRecord
has_many :ec_major_schools, :dependent => :destroy has_many :ec_major_schools, :dependent => :destroy
has_many :ec_majors, :through => :ec_major_schools has_many :ec_majors, :through => :ec_major_schools
after_create_commit :reset_data_cache
after_update_commit :reset_data_cache
# 学校管理员 # 学校管理员
def manager?(user) def manager?(user)
ec_school_users.exists?(user_id: user.id) ec_school_users.exists?(user_id: user.id)
@ -28,4 +33,23 @@ class School < ApplicationRecord
def manage_permission?(user) def manage_permission?(user)
manager?(user) || major_manager?(user) || course_manager?(user) manager?(user) || major_manager?(user) || course_manager?(user)
end end
def self.cached_names_data
Rails.cache.fetch(names_data_cache_key, expires_in: 7.days) do
School.select(:id, :name).as_json
end
end
private
def reset_data_cache
# 清除学校名称缓存
if new_record? || name_previously_changed?
Rails.cache.delete(self.class.names_data_cache_key)
end
end
def self.names_data_cache_key
'schools/names_data'
end
end end

@ -1,5 +1,7 @@
class Shixun < ApplicationRecord class Shixun < ApplicationRecord
# status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除 # status: 0编辑 1申请发布 2正式发布 3关闭 -1软删除
# hide_code 隐藏代码窗口
# code_hidden: 隐藏代码目录
has_many :challenges, dependent: :destroy has_many :challenges, dependent: :destroy
has_many :myshixuns, :dependent => :destroy has_many :myshixuns, :dependent => :destroy
has_many :shixun_members, dependent: :destroy has_many :shixun_members, dependent: :destroy
@ -30,6 +32,8 @@ class Shixun < ApplicationRecord
has_one :shixun_info, dependent: :destroy has_one :shixun_info, dependent: :destroy
belongs_to :user belongs_to :user
# 实训服务配置
has_many :shixun_service_configs, :dependent => :destroy
scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", scope :search_by_name, ->(keyword) { where("name like ? or description like ? ",

@ -0,0 +1,4 @@
class ShixunServiceConfig < ApplicationRecord
belongs_to :shixun
belongs_to :mirror_repository
end

@ -39,24 +39,34 @@ class StudentWork < ApplicationRecord
# 助教评分次数 # 助教评分次数
def ta_comment_count def ta_comment_count
self.student_works_scores.where(reviewer_role: 2).group_by(&:user_id).count self.student_works_scores.select{|score| score.reviewer_role == 2}.group_by(&:user_id).count
end end
# 匿评次数 # 匿评次数
def student_comment_num def student_comment_num
homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.where(reviewer_role: 3).group_by(&:user_id).count : 0 homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.select{|score| score.reviewer_role == 3}.group_by(&:user_id).count : 0
end end
# 匿评申诉总条数 # 匿评申诉总条数
def appeal_all_count def appeal_all_count
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status != 0"). homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.
group_by(&:user_id).count : 0 select{|score| score.reviewer_role == 3 && score.appeal_status != 0}.group_by(&:user_id).count : 0
end end
# 匿评申诉待处理条数 # 匿评申诉待处理条数
def appeal_deal_count def appeal_deal_count
homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status = 1"). homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.
group_by(&:user_id).count : 0 select{|score| score.reviewer_role == 3 && score.appeal_status == 1}.group_by(&:user_id).count : 0
end
# 当前用户该作品的匿评申诉总条数
def my_appeal_all_count user_id
student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status != 0 && score.user_id == user_id}.size
end
# 当前用户该作品的匿评申诉总条数
def my_appeal_deal_count user_id
student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status == 1 && score.user_id == user_id}.size
end end
# 分组名 # 分组名

@ -1,3 +1,5 @@
class SubRepertoire < ApplicationRecord class SubRepertoire < ApplicationRecord
has_many :tag_repertoires belongs_to :repertoire
has_many :tag_repertoires, ->{order(updated_at: :desc)} ,:dependent => :destroy
end end

@ -3,11 +3,15 @@ class BatchExportShixunReportService
MAX_BATCH_LIMIT = 20 MAX_BATCH_LIMIT = 20
attr_reader :homework, :student_work_ids # attr_reader :homework, :student_work_ids
attr_reader :homework, :all_student_works
def initialize(homework, student_work_ids)
def initialize(homework, all_student_works)
@homework = homework @homework = homework
@student_work_ids = student_work_ids # @student_work_ids = student_work_ids
@all_student_works = all_student_works
end end
def filename def filename
@ -15,8 +19,8 @@ class BatchExportShixunReportService
end end
def zip def zip
validate! # validate!
student_works = homework.student_works.where(id: student_work_ids).includes(:myshixun, user: :user_extension) student_works = all_student_works.includes(:myshixun, user: :user_extension)
if student_works.count.zero? if student_works.count.zero?
raise Error, '请选择要导出的学生实训报告' raise Error, '请选择要导出的学生实训报告'
@ -41,15 +45,15 @@ class BatchExportShixunReportService
end end
end end
private # private
#
def validate! # def validate!
if student_work_ids.size.zero? # if student_work_ids.size.zero?
raise Error, '请选择学生实训作业' # raise Error, '请选择学生实训作业'
end # end
#
if student_work_ids.size > MAX_BATCH_LIMIT # if student_work_ids.size > MAX_BATCH_LIMIT
raise Error, '导出实训报告太多,请分批导出' # raise Error, '导出实训报告太多,请分批导出'
end # end
end # end
end end

@ -2,19 +2,21 @@ class ExerciseUserPdfService
include ExercisesHelper include ExercisesHelper
include ApplicationHelper include ApplicationHelper
include StudentWorksHelper include StudentWorksHelper
include GitHelper
attr_reader :exercise, :ex_user attr_reader :exercise, :ex_user, :request_url
def initialize(exercise, ex_user) def initialize(exercise, ex_user,request_url)
@exercise = exercise @exercise = exercise
@ex_user = ex_user @ex_user = ex_user
@request_url = request_url
@ex_user_user = @ex_user.user @ex_user_user = @ex_user.user
@course = @exercise.course @course = @exercise.course
end end
def filename def filename
user_course = @course.course_members.find_by(user_id:@ex_user_user.id).course_group_name user_course = @course.course_members.find_by(user_id:@ex_user_user.id)&.course_group_name
exercise_user_name = user_course + "_" + exercise.exercise_name + "_" + @ex_user_user.real_name exercise_user_name = "#{@ex_user_user.real_name}_#{user_course.present? ? user_course : "未分班"}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}"
"#{exercise_user_name.strip}.pdf" "#{exercise_user_name.strip}.pdf"
end end
@ -37,10 +39,10 @@ class ExerciseUserPdfService
kit = PDFKit.new(html) kit = PDFKit.new(html)
base_css = %w(app/templates/exercise_export/exercise_export.css) base_css = %w(app/templates/exercise_export/exercise_export.css)
base_css.each { |css| kit.stylesheets << Rails.root.join(css) } base_css.each { |css| kit.stylesheets << Rails.root.join(css) }
#-----正式需删掉 # #-----正式需删掉
# aa = File.open(Rails.root.join("public/123.html"),"w+") # aa = File.open(Rails.root.join("public/123.html"),"w+")
# aa.syswrite(kit.source) # aa.syswrite(kit.source)
#正式需删掉------- # #正式需删掉-------s
file = Tempfile.new(filename) file = Tempfile.new(filename)
kit.to_pdf(file.path) kit.to_pdf(file.path)
file file
@ -48,42 +50,41 @@ class ExerciseUserPdfService
def load_data def load_data
@exercise_questions = exercise.exercise_questions @exercise_questions = exercise.exercise_questions
@exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_count = @exercise_questions.size # 全部的题目数
@exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum
#单选题的数量及分数 #单选题的数量及分数
exercise_single_ques = @exercise_questions.find_by_custom("question_type",0) exercise_single_ques = @exercise_questions.find_by_custom("question_type",0)
@exercise_single_ques_count = exercise_single_ques.all.count @exercise_single_ques_count = exercise_single_ques.size
@exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum
#多选题的数量及分数 #多选题的数量及分数
exercise_double_ques = @exercise_questions.find_by_custom("question_type",1) exercise_double_ques = @exercise_questions.find_by_custom("question_type",1)
@exercise_double_ques_count = exercise_double_ques.all.count @exercise_double_ques_count = exercise_double_ques.size
@exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum
# 判断题数量及分数 # 判断题数量及分数
exercise_ques_judge = @exercise_questions.find_by_custom("question_type",2) exercise_ques_judge = @exercise_questions.find_by_custom("question_type",2)
@exercise_ques_judge_count = exercise_ques_judge.all.count @exercise_ques_judge_count = exercise_ques_judge.size
@exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum
#填空题数量及分数 #填空题数量及分数
exercise_ques_null = @exercise_questions.find_by_custom("question_type",3) exercise_ques_null = @exercise_questions.find_by_custom("question_type",3)
@exercise_ques_null_count = exercise_ques_null.all.count @exercise_ques_null_count = exercise_ques_null.size
@exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum
#简答题数量及分数 #简答题数量及分数
exercise_ques_main = @exercise_questions.find_by_custom("question_type",4) exercise_ques_main = @exercise_questions.find_by_custom("question_type",4)
@exercise_ques_main_count = exercise_ques_main.all.count @exercise_ques_main_count = exercise_ques_main.size
@exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum
#实训题数量及分数 #实训题数量及分数
exercise_ques_shixun = @exercise_questions.find_by_custom("question_type",5) exercise_ques_shixun = @exercise_questions.find_by_custom("question_type",5)
@exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_count = exercise_ques_shixun.size
@exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum
challenge_ids = @exercise_questions.joins(:exercise_shixun_challenges).pluck("exercise_shixun_challenges.challenge_id") @exercise_questions = @exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers)
get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id)
@games = @exercise_user.user.games.ch_games(challenge_ids)
end end
end end

@ -1,15 +1,16 @@
class ExportExercisesService class ExportExercisesService
include ExercisesHelper include ExercisesHelper
include StudentWorksHelper include StudentWorksHelper
attr_reader :exercise, :ex_users attr_reader :exercise, :ex_users, :request_url
def initialize(exercise, ex_users) def initialize(exercise, ex_users, request_url)
@exercise = exercise @exercise = exercise
@ex_users = ex_users @ex_users = ex_users
@request_url = request_url
end end
def filename def filename
exercise_export_name = exercise.user.real_name + "_" + exercise.exercise_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}"
"#{exercise_export_name.strip}.zip" "#{exercise_export_name.strip}.zip"
end end
@ -18,7 +19,7 @@ class ExportExercisesService
pdfs = [] pdfs = []
Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip|
ex_users.each do |ex_user| ex_users.each do |ex_user|
export = ExerciseUserPdfService.new(exercise, ex_user) export = ExerciseUserPdfService.new(exercise, ex_user,@request_url)
pdf = export.ex_pdf pdf = export.ex_pdf
pdfs << pdf pdfs << pdf
begin begin

@ -33,7 +33,12 @@ class GitService
res = https.request(req) res = https.request(req)
body = res.body body = res.body
logger.info("--uri_exec: .....res is #{body}") logger.info("--uri_exec: .....res is #{body}")
content = JSON.parse(body) content = JSON.parse(body)
if content["code"] != 0
raise("版本库异常")
logger.error("repository error: #{content['msg']}")
end
#raise content["msg"] if content["code"] != 0 #raise content["msg"] if content["code"] != 0
content["data"] content["data"]

@ -156,7 +156,7 @@ class HomeworksService
end end
# 用户评测时更新实训作业成绩 # 用户评测时更新实训作业成绩
def update_myshixun_work_score myshixun def update_myshixun_work_score_old myshixun
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
student_works = myshixun.student_works.where(user_id: myshixun.user_id) student_works = myshixun.student_works.where(user_id: myshixun.user_id)
#logger.info("#############student_works_count: #{student_works.count}") #logger.info("#############student_works_count: #{student_works.count}")
@ -272,4 +272,67 @@ class HomeworksService
end end
end end
end end
# 计算实训作品成绩
def update_myshixun_work_score work, myshixun, games, homework, challenge_settings
user_total_score = 0
pass_consume_time = 0
final_score = 0
setting_time = homework.homework_group_setting myshixun.user_id
homework_end_or_late_time = homework.allow_late ? homework.late_time : setting_time.end_time
games.each do |game|
# 在截止时间前通关的关卡才考虑得分
if game.status == 2 && game.end_time <= homework_end_or_late_time
challenge_setting = challenge_settings.select{|setting| setting.challenge_id == game.challenge_id}.first
pass_consume_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i
adjust_score = work.challenge_work_scores.where(:challenge_id => game.challenge_id).last
final_score += if adjust_score.present?
adjust_score.score
elsif homework.homework_detail_manual.answer_open_evaluation
challenge_setting.score
elsif game.final_score > 0
game.real_score(challenge_setting.score)
else
0
end
end
end
myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil
if myshixun_endtime.present?
work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i
efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0))
work.efficiency = format("%.2f", efficiency)
if myshixun_endtime <= homework_end_or_late_time
work.compelete_status = myshixun_endtime < setting_time.publish_time ? 2 : 1
# 如果作业的最大效率值有变更则更新所有作品的效率分
homework.update_column("max_efficiency", work.efficiency) if homework.work_efficiency && homework.max_efficiency < work.efficiency
end
end
if work.work_status == 0
is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time)
if is_complete || (!homework.allow_late && myshixun.created_at < setting_time.end_time)
work.work_status = 1
elsif homework.allow_late && myshixun.created_at < homework.late_time
work.work_status = 2
end
work.late_penalty = work.work_status == 2 ? homework.late_penalty : 0
work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at
work.myshixun_id = myshixun.id
end
work.update_time = myshixun.updated_at
work.final_score = final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")
work.calculation_time = Time.now
work.save!
end
end end

@ -8,39 +8,24 @@ class ExercisePublishTask
exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
exercises&.each do |exercise| exercises&.each do |exercise|
exercise.update_column('exercise_status', 2) exercise.update_column('exercise_status', 2)
if exercise.unified_setting
ExercisePublishNotifyJob.perform_later(exercise.id, nil)
else
course = exercise.course course = exercise.course
teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id))
tid_str = "" tid_str = ""
course.teachers.find_each do |member| teachers.find_each do |member|
tid_str += "," if tid_str != "" tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end end
if exercise.unified_setting
course.students.find_each do |student|
tid_str += "," if tid_str != ""
tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
end
if tid_str != "" if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql ActiveRecord::Base.connection.execute tid_sql
end end
if exercise.exercise_users.size == 0
str = ""
course.students.find_each do |student|
str += "," if str != ""
str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if str != ""
sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str
ActiveRecord::Base.connection.execute sql
end
end end
if exercise.course_acts.size == 0 exercise.course_acts << CourseActivity.new(user_id: exercise.user_id, course_id: exercise.course_id) if !exercise.course_acts.exists?
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
end
end end
# 分组设置发布时间的测验 # 分组设置发布时间的测验
@ -48,18 +33,8 @@ class ExercisePublishTask
exercise_group_settings&.each do |exercise_group| exercise_group_settings&.each do |exercise_group|
exercise = exercise_group.exercise exercise = exercise_group.exercise
if exercise.present? if exercise.present?
course = exercise.course
exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1
tid_str = "" ExercisePublishNotifyJob.perform_later(exercise.id, [exercise_group.course_group_id])
members = course.students.where(:course_group_id => exercise_group.course_group_id)
members.find_each do |member|
tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql
end
end end
end end
Rails.logger.info("log--------------------------------exercise_publish end") Rails.logger.info("log--------------------------------exercise_publish end")

@ -17,9 +17,9 @@
</p> </p>
</div> </div>
</div> </div>
<div class="mbt20 bgc"> <div class="mbt20 bgc width100">
<div class="ex-scores pd10 text-gray fs13"> <div class="ex-scores pd10 text-gray fs13">
<p class="clearfix"> <p class="clearfix inline-block width100">
<% if @exercise_single_ques_count > 0 %> <% if @exercise_single_ques_count > 0 %>
<span class="mr15">单选题<span class="mlr5"><%= @exercise_single_ques_count %></span>题, <span class="mr15">单选题<span class="mlr5"><%= @exercise_single_ques_count %></span>题,
共<span class="mlr5"><%= @exercise_single_ques_scores %></span>分</span> 共<span class="mlr5"><%= @exercise_single_ques_scores %></span>分</span>
@ -44,22 +44,24 @@
<span class="mr15">实训题<span class="mlr5"><%= @exercise_ques_shixun_count %></span>题, <span class="mr15">实训题<span class="mlr5"><%= @exercise_ques_shixun_count %></span>题,
共<span class="mlr5"><%= @exercise_ques_shixun_scores %></span>分</span> 共<span class="mlr5"><%= @exercise_ques_shixun_scores %></span>分</span>
<% end %> <% end %>
<% if @exercise_ques_count > 0 %>
<span class="pull-right"> <span class="pull-right">
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分 <% if @exercise_ques_count > 0 %>
</span> <span class="mr15">
<span class="mr15 pull-right">
合计<span class="text-blue mlr5"><%= @exercise_ques_count %></span>题 合计<span class="text-blue mlr5"><%= @exercise_ques_count %></span>题
</span> </span>
<span>
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分
</span>
<% end %> <% end %>
</span>
</p> </p>
</div> </div>
</div> </div>
<div class="clearfix"></div>
<div class="mbt10"> <div class="mbt10">
<% @exercise_questions.each do |q| %> <% @exercise_questions.each do |q| %>
<div class="bdc"> <div class="bdc">
<div class="pbt10"> <div class="pbt5">
<div class="pbt5"> <div class="pbt5">
<span class="mr5 text-blue"><%= q.question_number %>、</span> <span class="mr5 text-blue"><%= q.question_number %>、</span>
<span class="text-blue"> <span class="text-blue">
@ -69,38 +71,38 @@
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% if q.question_type == 5 %> <% if q.question_type == 5 %>
<span class="ques-title"><%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %></span> <span class="ques-title" ><%= to_markdown(q.shixun_name,@request_url) %></span>
<div class="mt8 text-gray"> <div class="mt8 text-gray">
<span><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span> <span><%= to_markdown(q.question_title,@request_url) %></span>
</div> </div>
<% else %> <% else %>
<span class="ques-title"><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span> <span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% if q.question_type == 0 %> <% if q.question_type == 0 %>
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each do |s| %>
<p class="pbt5"> <div class="pbt5 clearfix main-choice">
<span class="choose-radio"></span> <span class="choose-radio pull-left mt8"></span>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%> <span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</p> </div>
<% end %> <% end %>
<% elsif q.question_type == 1 %> <% elsif q.question_type == 1 %>
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each do |s| %>
<p class="pbt5"> <div class="pbt5 clearfix main-choice">
<span class="choose-checkbox"></span> <span class="choose-checkbox pull-left mt8"></span>
<span class="mr20"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%> <span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
</p> </div>
<% end %> <% end %>
<% elsif q.question_type == 2 %> <% elsif q.question_type == 2 %>
<p class="pbt5"> <div class="pbt5 clearfix">
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each do |s| %>
<span class="mr15"> <span class="mr15">
<span class="choose-radio"></span> <span class="choose-radio "></span>
<span class="mlr5"><%= s.choice_text %></span> <span class="mlr5 inline-block"><%= s.choice_text %></span>
</span> </span>
<% end %> <% end %>
</p> </div>
<% elsif q.question_type == 3 %> <% elsif q.question_type == 3 %>
<% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %>
<% st_counts.each_with_index do |s,index| %> <% st_counts.each_with_index do |s,index| %>
@ -132,4 +134,5 @@
</div> </div>
</div> </div>
</body> </body>
</html> </html>

@ -2,6 +2,7 @@ body{
font-size:14px; font-size:14px;
font-family: "微软雅黑","宋体"; font-family: "微软雅黑","宋体";
} }
p{ p{
margin:0; margin:0;
} }
@ -39,11 +40,17 @@ p{
margin-bottom: 10px; margin-bottom: 10px;
} }
.mt8{ .mt8{
margin-top:8px; margin-top:7px;
}
.mt10{
margin-top:10px;
} }
.mbt10{ .mbt10{
margin: 10px 0; margin: 10px 0;
} }
.mt5{
margin-top:5px;
}
.pull-right{ .pull-right{
float:right; float:right;
} }
@ -82,9 +89,15 @@ p{
.ml20{ .ml20{
margin-left:20px; margin-left:20px;
} }
.ml10{
margin-left:10px;
}
.mr3{ .mr3{
margin-right:3px; margin-right:3px;
} }
.mr8{
margin-right:8px;
}
.mr15{ .mr15{
margin-right:15px; margin-right:15px;
} }
@ -100,6 +113,9 @@ p{
white-space: normal; white-space: normal;
min-height:12px; min-height:12px;
} }
.null-answer p{
display: inline-block;
}
.choose-radio{ .choose-radio{
display: inline-block; display: inline-block;
width: 12px; width: 12px;
@ -156,7 +172,7 @@ p{
position: absolute; position: absolute;
display: inline-block; display: inline-block;
bottom: 6px; bottom: 6px;
/*left: 1px;*/ left: 1px;
} }
.line-line { .line-line {
@ -231,7 +247,7 @@ p{
position: absolute; position: absolute;
display: inline-block; display: inline-block;
bottom: 9px; bottom: 9px;
left: 1px; left: 2px;
} }
.circle-right:after{ .circle-right:after{
color:#fff; color:#fff;
@ -248,7 +264,7 @@ table{
text-align:center; text-align:center;
} }
table, tr, td, th, tbody, thead, tfoot,textarea{ table, tr, td, th, tbody, thead, tfoot,textarea,.main-choice{
page-break-inside: avoid; page-break-inside: avoid;
} }
table th{ table th{
@ -304,11 +320,31 @@ textarea{
border:none; border:none;
background-color:#eee; background-color:#eee;
line-height:2; line-height:2;
} }
.clearfix{ .clearfix{
clear:both; clear:both;
zoom:1; zoom:1;
} }
.choice-text p{
margin-bottom:0;
}
.mt-2{
margin-top:-2px;
}
.width100{
width:100%;
}
.ex-scores{
/*width:100%;*/
/*display:inline-block;*/
word-break: break-all;
line-height:2;
}

@ -17,9 +17,9 @@
</p> </p>
</div> </div>
</div> </div>
<div class="mbt20 bgc"> <div class="mbt20 bgc width100">
<div class="ex-scores pd10 text-gray fs13"> <div class="ex-scores pd10 text-gray fs13">
<p class="clearfix"> <p class="clearfix inline-block width100">
<% if @exercise_single_ques_count > 0 %> <% if @exercise_single_ques_count > 0 %>
<span class="mr15">单选题<span class="mlr5"><%= @exercise_single_ques_count %></span>题, <span class="mr15">单选题<span class="mlr5"><%= @exercise_single_ques_count %></span>题,
共<span class="mlr5"><%= @exercise_single_ques_scores %></span>分</span> 共<span class="mlr5"><%= @exercise_single_ques_scores %></span>分</span>
@ -44,18 +44,20 @@
<span class="mr15">实训题<span class="mlr5"><%= @exercise_ques_shixun_count %></span>题, <span class="mr15">实训题<span class="mlr5"><%= @exercise_ques_shixun_count %></span>题,
共<span class="mlr5"><%= @exercise_ques_shixun_scores %></span>分</span> 共<span class="mlr5"><%= @exercise_ques_shixun_scores %></span>分</span>
<% end %> <% end %>
<% if @exercise_ques_count > 0 %>
<span class="pull-right"> <span class="pull-right">
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分 <% if @exercise_ques_count > 0 %>
</span> <span class="mr15">
<span class="mr15 pull-right">
合计<span class="text-blue mlr5"><%= @exercise_ques_count %></span>题 合计<span class="text-blue mlr5"><%= @exercise_ques_count %></span>题
</span> </span>
<span>
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分
</span>
<% end %> <% end %>
</span>
</p> </p>
</div> </div>
</div> </div>
<div class="clearfix"></div>
<div class="mbt10"> <div class="mbt10">
<% if @ex_obj_array.size > 0 %> <% if @ex_obj_array.size > 0 %>
<div> <div>
@ -112,6 +114,7 @@
<div class="mbt10"> <div class="mbt10">
<% @exercise_questions.each do |q| %> <% @exercise_questions.each do |q| %>
<% q_type = q.question_type %> <% q_type = q.question_type %>
<% games =( q_type == 5 ? @ex_user_user.games.ch_games(q.exercise_shixun_challenges.pluck(:challenge_id)) : nil) %>
<% user_answer = (q_type == 5 ? q.exercise_shixun_answers.where(user_id: @ex_user_user.id) : q.exercise_answers.where(user_id: @ex_user_user.id)) %> <% user_answer = (q_type == 5 ? q.exercise_shixun_answers.where(user_id: @ex_user_user.id) : q.exercise_answers.where(user_id: @ex_user_user.id)) %>
<% this_ques_status = @ex_obj_array.detect{|f| f[:q_id] == q.id} %> <% this_ques_status = @ex_obj_array.detect{|f| f[:q_id] == q.id} %>
<% main_ques_status = @ex_sub_array.detect{|f| f[:q_id] == q.id} %> <% main_ques_status = @ex_sub_array.detect{|f| f[:q_id] == q.id} %>
@ -166,41 +169,42 @@
<% end %> <% end %>
</div> </div>
<div class="pbt5"> <div class="pbt5">
<% if q_type == 5 %> <% if q.question_type == 5 %>
<span class="ques-title"><%= q.shixun_name&.html_safe %></span> <span class="ques-title" ><%= to_markdown(q.shixun_name,@request_url) %></span>
<div class="mt8 text-gray"> <div class="mt8 text-gray">
<span><%= q.question_title&.html_safe %></span> <span><%= to_markdown(q.question_title,@request_url) %></span>
</div> </div>
<% elsif q_type == 4 %>
<span class="ques-title"><%= q.question_title&.html_safe %></span>
<% else %> <% else %>
<span class="ques-title"><%= q.question_title&.html_safe %></span> <span class="ques-title"><%= to_markdown(q.question_title,@request_url) %></span>
<% end %> <% end %>
</div> </div>
</div> </div>
<div class="clearfix"></div>
<div class="pbt5"> <div class="pbt5">
<% if q_type == 0 %> <% if q_type == 0 %>
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each do |s| %>
<% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
<p class="pbt5"> <div class="pbt10 clearfix main-choice">
<span class="choose-radio <%= check_answer %>"></span> <span class="choose-radio <%= check_answer %> pull-left mt10"></span>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%> <span class="inline-block pull-left ml10 choice-text mt-2"><%= to_markdown(s.choice_text,@request_url) %></span>
</p> </div>
<% end %> <% end %>
<div class="clearfix"></div>
<% elsif q_type == 1 %> <% elsif q_type == 1 %>
<% q.exercise_choices.each_with_index do |s,index| %> <% q.exercise_choices.each do |s| %>
<% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %>
<p class="pbt5"> <div class="pbt10 clearfix main-choice">
<% if check_answer %> <% if check_answer %>
<span class="choose-checkbox choose-answer-multi" ></span> <span class="choose-checkbox choose-answer-multi mt10 pull-left" ></span>
<% else %> <% else %>
<span class="choose-checkbox"></span> <span class="choose-checkbox pull-left mt10"></span>
<% end %> <% end %>
<span class="mr15"><%= convert_to_char((index+1).to_s)%></span><%= s.choice_text%> <span class="inline-block pull-left choice-text ml10 mt-2"><%= to_markdown(s.choice_text,@request_url) %></span>
</p> </div>
<% end %> <% end %>
<div class="clearfix"></div>
<% elsif q_type == 2 %> <% elsif q_type == 2 %>
<p class="pbt5"> <div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %> <% q.exercise_choices.each do |s| %>
<% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %>
<% check_answer = 'choose-answer' %> <% check_answer = 'choose-answer' %>
@ -212,7 +216,8 @@
<span class="mlr5"><%= s.choice_text %></span> <span class="mlr5"><%= s.choice_text %></span>
</span> </span>
<% end %> <% end %>
</p> </div>
<div class="clearfix"></div>
<% elsif q_type == 3 %> <% elsif q_type == 3 %>
<% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %>
<% st_counts.each_with_index do |s,index| %> <% st_counts.each_with_index do |s,index| %>
@ -221,16 +226,20 @@
<% else %> <% else %>
<% check_answer = "--" %> <% check_answer = "--" %>
<% end %> <% end %>
<p class="pbt10 flex-nowrap"> <div class="pbt10 flex-nowrap clearfix">
<span class="pull-left line-34">答案(填空<%= index+1 %></span> <span class="pull-left line-34">答案(填空<%= index+1 %></span>
<span class="null-answer"><%= check_answer&.html_safe %></span> <span class="null-answer pull-left"><%= to_markdown(check_answer,@request_url) %></span>
</p> </div>
<div class="clearfix"></div>
<% end %> <% end %>
<% elsif q_type == 4 %> <% elsif q_type == 4 %>
<% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>
<p class="flex-nowrap"> <div class="flex-nowrap">
<span class="null-answer main-height"><%= check_answer&.html_safe %></span> <div class="null-answer main-height">
</p> <%= to_markdown(check_answer,@request_url) %>
</div>
</div>
<div class="clearfix"></div>
<% else %> <% else %>
<div class="mbt10"> <div class="mbt10">
<p class="text-gray mbt10"> <p class="text-gray mbt10">
@ -247,8 +256,8 @@
<th width="13%">得分/满分</th> <th width="13%">得分/满分</th>
</thead> </thead>
<tbody> <tbody>
<% if @games.size > 0 %> <% if games.present? %>
<% @games.each_with_index do |game, index| %> <% games&.each_with_index do |game, index| %>
<% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %>
<% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %> <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %>
<tr> <tr>
@ -286,7 +295,7 @@
<p class="text-gray mbt10"> <p class="text-gray mbt10">
<span class="fl font-bd">实训详情</span> <span class="fl font-bd">实训详情</span>
</p> </p>
<% @games.each_with_index do |game, index| %> <% games&.each_with_index do |game, index| %>
<div class="mbt10"> <div class="mbt10">
<p class="clearfix"> <p class="clearfix">
<span class="fl mt3"><span class="font-bd mr15">第<%= index+1 %>关</span><%= game.challenge.subject %></span> <span class="fl mt3"><span class="font-bd mr15">第<%= index+1 %>关</span><%= game.challenge.subject %></span>
@ -309,24 +318,29 @@
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<% if game.try(:lastest_code).present? && game.challenge.st == 0 %> <% if game.try(:lastest_code).blank? %>
<% con_rows = content_line(game.lastest_code) %> <% cha_path = challenge_path(game.challenge&.path) %>
<% latest_code = git_fle_content(game.myshixun.repo_path,cha_path) %>
<% else %>
<% latest_code = game.try(:lastest_code) %>
<% end %>
<% con_rows = content_line(latest_code) %>
<div class="mbt20"> <div class="mbt20">
<p class="bgc" > <p class="bgc" >
<span class="pd10" style="display:inherit;"> <span class="pd10" style="display:inherit;">
<span class="fl">最近通过的代码</span> <span class="fl">最近通过的代码</span>
<span class="pull-right"><%= game.challenge.path %></span> <span class="pull-right"><%= game.challenge&.path %></span>
</span> </span>
</p> </p>
<div class="bg-e pd10"> <div class="bg-e pd10">
<textarea class="" id="content_show_<%= game.id %>" name="content" rows="<%= con_rows %>"><%= game.lastest_code %></textarea> <textarea class="" id="content_show_<%= game.id %>" name="content" rows="<%= con_rows %>">><%= latest_code %></textarea>
</div> </div>
</div> </div>
<% end %>
</div> </div>
</div> </div>
<% end %> <% end %>
</div> </div>
<div class="clearfix"></div>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -336,7 +350,7 @@
<div class="bdc"> <div class="bdc">
<div class="pbt10"> <div class="pbt10">
<div class="inline-block pull-left"> <div class="inline-block pull-left">
<span><img src="/images/avatars/User/<%= ques_user.id %>" class="avatar-32"/></span> <span><img src="<%= @request_url %>/images/avatars/User/<%= ques_user.id %>" class="avatar-32"/></span>
</div> </div>
<div class="ml38"> <div class="ml38">
<p class="mb10"><span class="pr"><%= ques_user.real_name %></span><span class="plr15 text-gray"><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %></span></p> <p class="mb10"><span class="pr"><%= ques_user.real_name %></span><span class="plr15 text-gray"><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %></span></p>

@ -7,7 +7,7 @@ json.chooses do
end end
if @tab == 0 if @tab == 0
# 本关任务tab的编辑模式 # 本关任务tab的编辑模式
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score) json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time)
json.tags @challenge.challenge_tags.map(&:name) json.tags @challenge.challenge_tags.map(&:name)
elsif @tab == 1 elsif @tab == 1
# 评测设置的编辑模式 # 评测设置的编辑模式

@ -17,7 +17,7 @@ if @challenges.present?
json.passed_count challenge.user_passed_count json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game(@user.id) json.open_game challenge.open_game(@user.id, @shixun)
if @editable if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)

@ -1,6 +1,6 @@
# 导航栏公共数据 # 导航栏公共数据
json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier
json.(@challenge, :id, :subject, :task_pass, :difficulty, :score) json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time)
json.tags @challenge.challenge_tags.map(&:name) json.tags @challenge.challenge_tags.map(&:name)

@ -2,7 +2,7 @@ json.author do
json.partial! 'users/user', user: discuss.user json.partial! 'users/user', user: discuss.user
end end
json.id discuss.id json.id discuss.id
json.content discuss.contents(container, current_user) json.content discuss.content
json.time time_from_now(discuss.created_at) json.time time_from_now(discuss.created_at)
json.position discuss.position json.position discuss.position
json.shixun_id discuss.dis_id json.shixun_id discuss.dis_id

@ -2,8 +2,7 @@ json.disscuss_count @disscuss_count
json.all @current_user.admin? json.all @current_user.admin?
json.comments @discusses do |discuss| json.comments @discusses do |discuss|
json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user } json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user }
child_discuss = Discuss.children(discuss.id) json.children discuss.child_discuss(current_user) do |c_d|
json.children child_discuss do |c_d|
json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user } json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user }
end end
end end

@ -1,15 +1,20 @@
json.question_id question.id json.question_id question.id
# json.question_number question.question_number # json.question_number question.question_number
json.q_position ques_position.present? ? ques_position : question.question_number q_positon = question.question_number
if ques_position.present?
q_positon = ques_position
end
json.q_position q_positon
json.question_title question.question_title json.question_title question.question_title
json.question_type question.question_type json.question_type question.question_type
json.question_score question.question_score.round(1).to_s json.question_score question.question_score.round(1).to_s
if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置
standard_answers_array = question.get_standard_answer_ids standard_answers_array = question.get_standard_answer_ids
exercise_choices = choices.order("choice_position ASC")
ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱 ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱
if ex_choice_random_boolean if ex_choice_random_boolean
exercise_choices = exercise_choices.order("RAND()") exercise_choices = choices.order("RAND()")
else
exercise_choices = choices.order("choice_position ASC")
end end
json.question_choices do json.question_choices do
json.array! exercise_choices.each_with_index.to_a do |a,index| json.array! exercise_choices.each_with_index.to_a do |a,index|
@ -85,7 +90,7 @@ elsif question.question_type == 5
user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0
json.shixun_challenge_id s.id json.shixun_challenge_id s.id
if games_score[:games].count > 0 if games_score[:games].count > 0
json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score] json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score],shixun_challenge:s
else else
json.partial! "exercises/shixun_undo",games: [s], user_score: user_get_score ,game_score: s.question_score json.partial! "exercises/shixun_undo",games: [s], user_score: user_get_score ,game_score: s.question_score
end end

@ -26,6 +26,17 @@ json.shixun_detail do
json.position output.query_index json.position output.query_index
json.output_detail output_detail game, output json.output_detail output_detail game, output
end end
json.passed_code game.try(:lastest_code)
latest_code = nil
if shixun_challenge.challenge&.path.present?
if game.try(:lastest_code).blank?
cha_path = challenge_path(shixun_challenge.challenge&.path)
latest_code = git_fle_content(game.myshixun.repo_path,cha_path)
else
latest_code = game.try(:lastest_code)
end
end
json.passed_code latest_code
end end
end end

@ -47,14 +47,13 @@ end
json.exercise_questions do json.exercise_questions do
json.array! exercise_questions do |q| json.array! exercise_questions do |q|
user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,exercise_status,q.question_type,ex_type) user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,exercise_status,q.question_type,ex_type)
user_ques_comments = user_ques_answers[:question_comment] user_ques_comments = user_ques_answers[:question_comment]
if all_question_status.size > 0 if all_question_status.size > 0
this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id} this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id}
json.answer_status this_ques_status[:stand_status] json.answer_status this_ques_status[:stand_status]
end end
json.user_score user_ques_answers[:user_score].to_s json.user_score user_ques_answers[:user_score]
json.partial! "exercise_questions/exercise_questions", json.partial! "exercise_questions/exercise_questions",
question: q, question: q,
ex_answerer: ex_answerer, ex_answerer: ex_answerer,
@ -63,7 +62,7 @@ json.exercise_questions do
exercise_type: ex_type, exercise_type: ex_type,
user_answer: user_ques_answers[:answered_content], user_answer: user_ques_answers[:answered_content],
shixun_type: user_ques_answers[:shixun_type], shixun_type: user_ques_answers[:shixun_type],
ques_position:nil ques_position: nil
if user_ques_comments.count > 0 if user_ques_comments.count > 0
json.question_comments do json.question_comments do
json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first

@ -40,8 +40,8 @@ json.exercise_questions do
question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id)
# json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号
if @t_user_exercise_status == 3 if @t_user_exercise_status == 3
this_answer_status = "0.0" this_answer_status = 0
user_score = "0.0" user_score = nil
if all_question_status.size > 0 if all_question_status.size > 0
this_ques_status = all_question_status.detect {|f| f[:q_id] == question.id} this_ques_status = all_question_status.detect {|f| f[:q_id] == question.id}
this_answer_status = this_ques_status[:stand_status] this_answer_status = this_ques_status[:stand_status]

@ -1,2 +1,10 @@
json.status @status json.test_sets @qurey_test_sets do |test_set|
json.message @message json.is_public test_set.is_public
json.result test_set.try(:result)
if test_set.is_public || @allowed_hidden_testset
json.input test_set.input
json.output test_set.output
json.actual_output evaluate_actual_output(test_set)
end
json.compile_success test_set.try(:compile_success)
end

@ -59,6 +59,7 @@ if @task.published? || @user_course_identity < Course::STUDENT
json.late_penalty work.late_penalty if @task.allow_late json.late_penalty work.late_penalty if @task.allow_late
json.final_score work_final_score work, @current_user, @user_course_identity json.final_score work_final_score work, @current_user, @user_course_identity
json.assign work.assign_power?(@user_course_identity) json.assign work.assign_power?(@user_course_identity)
json.view_work @view_work || @current_user.id == work.user_id
end end
end end
end end

@ -11,4 +11,5 @@ json.homework_id homework.id
json.homework_type homework.homework_type json.homework_type homework.homework_type
if homework.homework_type == "practice" if homework.homework_type == "practice"
json.shixun_identifier homework.shixuns.take.try(:identifier) json.shixun_identifier homework.shixuns.take.try(:identifier)
json.shixun_id homework.shixuns.take.try(:id)
end end

@ -16,6 +16,7 @@ json.work_public @homework.work_public
if @user_course_identity < Course::STUDENT if @user_course_identity < Course::STUDENT
json.calculation_time @homework.calculation_time if @homework.homework_type == "practice"
# 教师身份的评阅、提交状态、分班过滤 # 教师身份的评阅、提交状态、分班过滤
if @homework.homework_type != "practice" if @homework.homework_type != "practice"
json.teacher_comment teacher_comment @homework, @current_user.id json.teacher_comment teacher_comment @homework, @current_user.id
@ -30,22 +31,22 @@ elsif @user_course_identity == Course::STUDENT
if @homework.homework_type == "practice" if @homework.homework_type == "practice"
json.(@work, :id, :work_status, :update_time, :ultimate_score) json.(@work, :id, :work_status, :update_time, :ultimate_score)
json.calculation_time @work.calculation_time
json.late_penalty @work.late_penalty if @homework.allow_late json.late_penalty @work.late_penalty if @homework.allow_late
json.cost_time @work.myshixun.try(:total_cost_time) json.cost_time @work.myshixun.try(:total_cost_time)
json.work_score work_score_format(@work.work_score, true, @homework.score_open) json.work_score work_score_format(@work.work_score, true, @score_open)
json.final_score work_score_format(@work.final_score, true, @homework.score_open) json.final_score work_score_format(@work.final_score, true, @score_open)
json.efficiency work_score_format(@work.efficiency, true, @homework.score_open) json.efficiency work_score_format(@work.efficiency, true, @score_open)
json.eff_score work_score_format(@work.eff_score, true, @homework.score_open) json.eff_score work_score_format(@work.eff_score, true, @score_open)
json.complete_count @work.myshixun.try(:passed_count) json.complete_count @work.myshixun.try(:passed_count)
else else
json.(@work, :id, :work_status, :update_time, :ultimate_score) json.(@work, :id, :work_status, :update_time, :ultimate_score)
json.work_score work_score_format(@work.work_score, true, @homework.score_open) json.work_score work_score_format(@work.work_score, true, @score_open)
json.final_score work_score_format(@work.final_score, true, @homework.score_open) json.final_score work_score_format(@work.final_score, true, @score_open)
json.teacher_score work_score_format(@work.teacher_score, true, @homework.score_open) json.teacher_score work_score_format(@work.teacher_score, true, @score_open)
json.student_score work_score_format(@work.student_score, true, @homework.score_open) json.student_score work_score_format(@work.student_score, true, @score_open)
json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @homework.score_open) json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @score_open)
json.ta_comment_count @work.ta_comment_count json.ta_comment_count @work.ta_comment_count
@ -84,17 +85,17 @@ if @homework.homework_type == "practice"
json.(work, :id, :work_status, :update_time, :ultimate_score) json.(work, :id, :work_status, :update_time, :ultimate_score)
json.late_penalty work.late_penalty if @homework.allow_late json.late_penalty work.late_penalty if @homework.allow_late
json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open)
json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open)
json.efficiency work_score_format(work.efficiency, @current_user == work.user, @homework.score_open) json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open)
json.eff_score work_score_format(work.eff_score, @current_user == work.user, @homework.score_open) json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open)
json.cost_time work.myshixun.try(:total_cost_time) json.cost_time work.myshixun.try(:total_cost_time)
json.complete_count work.myshixun.try(:passed_count) json.complete_count work.myshixun.try(:passed_count)
json.user_login work.user.try(:login) json.user_login work.user.try(:login)
json.user_name work.user.try(:real_name) json.user_name work.user.try(:real_name)
json.student_id work.user.try(:student_id) json.student_id work.user.try(:student_id)
json.group_name @course.course_student(work.user_id).try(:course_group_name) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
end end
elsif @homework.homework_type == "group" || @homework.homework_type == "normal" elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.anonymous_comment @homework.anonymous_comment json.anonymous_comment @homework.anonymous_comment
@ -106,16 +107,22 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.student_score work_score_format(anon_comments(@current_user, work.id).last.try(:score), false, true) json.student_score work_score_format(anon_comments(@current_user, work.id).last.try(:score), false, true)
# json.student_comment_count anon_comments(@current_user, work.id).count # json.student_comment_count anon_comments(@current_user, work.id).count
# 申诉条数
if @homework.anonymous_appeal
json.appeal_all_count work.my_appeal_all_count @current_user.id
json.appeal_deal_count work.my_appeal_deal_count @current_user.id
end
else else
json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score, json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score,
:teaching_asistant_score, :ultimate_score) :teaching_asistant_score, :ultimate_score)
json.late_penalty work.late_penalty if @homework.allow_late json.late_penalty work.late_penalty if @homework.allow_late
json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open)
json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open)
json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @homework.score_open) json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @score_open)
json.student_score work_score_format(work.student_score, @current_user == work.user, @homework.score_open) json.student_score work_score_format(work.student_score, @current_user == work.user, @score_open)
json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @homework.score_open) json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @score_open)
# 助教评分次数 # 助教评分次数
json.ta_comment_count work.ta_comment_count json.ta_comment_count work.ta_comment_count
@ -127,14 +134,13 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
end end
json.student_id work.user.try(:student_id) json.student_id work.user.try(:student_id)
json.group_name @course.course_student(work.user_id).try(:course_group_name) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
if @homework.homework_type == "group" if @homework.homework_type == "group"
if @homework.homework_detail_group.base_on_project if @homework.homework_detail_group.base_on_project
json.project_info project_info work, @current_user, @user_course_identity json.project_info project_info work, @current_user, @user_course_identity
end end
json.work_group work.work_group_name json.work_group work.work_group_name
end end
end
# 申诉条数 # 申诉条数
if @homework.anonymous_appeal if @homework.anonymous_appeal
@ -142,6 +148,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.appeal_deal_count work.appeal_deal_count json.appeal_deal_count work.appeal_deal_count
json.appeal_penalty work.appeal_penalty json.appeal_penalty work.appeal_penalty
end end
end
json.user_login @is_evaluation ? "--" : work.user.try(:login) json.user_login @is_evaluation ? "--" : work.user.try(:login)
json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name) json.user_name @is_evaluation ? "匿名" : work.user.try(:real_name)

@ -1,3 +1,4 @@
json.content @content json.content @content
json.resubmit "#{@resubmit}" json.resubmit "#{@resubmit}"
json.sec_key "#{@sec_key}"
json.content_modified @hide_code ? false : @content_modified json.content_modified @hide_code ? false : @content_modified

@ -2,14 +2,14 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
# wb.use_autowidth = false # wb.use_autowidth = false
wb.styles do |s| wb.styles do |s|
sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {:horizontal => :left} sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {wrap_text: true,:horizontal => :left}
blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :left} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :left}
wb.add_worksheet(:name => "统计结果") do |sheet| wb.add_worksheet(:name => "统计结果") do |sheet|
sheet.sheet_view.show_grid_lines = false sheet.sheet_view.show_grid_lines = false
poll_users_info = %w(序号) poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?}
poll_un_anony = @poll.un_anonymous poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号) user_info = %w(登陆名 真实姓名 邮箱 学号)
else else
@ -18,38 +18,38 @@ wb.styles do |s|
poll_users_info = poll_users_info + user_info + poll_ques_titles poll_users_info = poll_users_info + user_info + poll_ques_titles
poll_questions.each do |q| poll_questions.each do |q|
if q.question_type != 3 #问题不为主观题 if q.question_type != 3 #问题不为主观题
question_vote_user = q.poll_votes.find_current_vote("user_id",@poll_commit_ids).count #该问题的有效填写量 question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).count #该问题的有效填写量
sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组
sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组
sheet_answer_percent = ["比例"] sheet_answer_percent = ["比例"]
sheet_answer_useful = ["有效填写人次",question_vote_user] sheet_answer_useful = ["有效填写人次",question_vote_user]
q.poll_answers.each do |a| #问卷的答案选项 q.poll_answers.each do |a| #问卷的答案选项
answer_users_count = a.poll_votes.find_current_vote("user_id",@poll_commit_ids).count answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).count
answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1)
sheet_row.push(a.answer_text) sheet_row.push(a.answer_text)
sheet_answer_row.push(answer_users_count) sheet_answer_row.push(answer_users_count)
sheet_answer_percent.push(answer_percent.to_s) sheet_answer_percent.push(answer_percent.to_s)
end end
sheet.add_row sheet_row, :style => blue_cell sheet.add_row sheet_row, :height =>15,:style => blue_cell
sheet.add_row sheet_answer_row, :style => sz_all sheet.add_row sheet_answer_row, :height =>15, :style => sz_all
sheet.add_row sheet_answer_percent, :style => sz_all sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all
sheet.add_row sheet_answer_useful, :style => sz_all sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all
#合并单元格但无法填充style #合并单元格但无法填充style
# sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index))
# sheet.rows[sheet.rows.last.row_index].style = sz_all # sheet.rows[sheet.rows.last.row_index].style = sz_all
sheet.add_row [] sheet.add_row []
else #主观题答案 else #主观题答案
main_show_row = ["第#{q.question_number}题",q.question_title] main_show_row = ["第#{q.question_number}题",q.question_title]
sheet.add_row main_show_row, :style => blue_cell sheet.add_row main_show_row,:height =>15, :style => blue_cell
q.poll_votes.each do |v| #主观题的答案 q.poll_votes.each do |v| #主观题的答案
sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"], :style => sz_all sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all
end end
sheet.add_row [], :style => sz_all sheet.add_row [], :style => sz_all
end end
end #each_with_index end #each_with_index
sheet.add_row poll_users_info, :style => blue_cell sheet.add_row poll_users_info, :height =>15, :style => blue_cell
@poll.poll_users.each_with_index do |u,index| poll_users.each_with_index do |u,index|
u_user = u.user u_user = u.user
user_answer_array = [] user_answer_array = []
poll_questions.each do |q| poll_questions.each do |q|
@ -86,7 +86,7 @@ wb.styles do |s|
user_cell += [user_login,user_name, u_user.mail, user_student_id] user_cell += [user_login,user_name, u_user.mail, user_student_id]
end end
all_user_cell = user_cell + user_answer_array all_user_cell = user_cell + user_answer_array
sheet.add_row all_user_cell, :style => sz_all sheet.add_row all_user_cell, :height =>15,:style => sz_all
end end
sheet.column_widths *([25]*sheet.column_info.count) sheet.column_widths *([25]*sheet.column_info.count)
sheet.column_info.first.width = 10 sheet.column_info.first.width = 10

@ -1,7 +1,6 @@
json.course do json.course do
json.partial! "polls/course_name",locals:{course:@course} json.partial! "polls/course_name",locals:{course:@course}
end end
json.poll_types do json.poll_types do
if @poll_current_user_status == 0 if @poll_current_user_status == 0
json.published_count @poll_publish_count json.published_count @poll_publish_count

@ -1,7 +1,11 @@
#json.partial! "users/users_list", users: @users #json.partial! "users/users_list", users: @users
json.array! @users do |user| json.user_count @user_count
json.users do
json.array! @users do |user|
json.user_id user.id json.user_id user.id
json.identify user.identity json.identify user.identity
json.nickname user.nickname json.nickname user.real_name
json.school_name user.school_name json.school_name user.school_name
end
end end

@ -1,4 +1,3 @@
json.status 1 json.status 1
json.message "发送成功" json.message "发送成功"
json.url course_homework_commons_path(@course.id, type: 4) json.course_id @course.id
# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4"

@ -22,13 +22,21 @@ json.shixun do
json.hide_code @shixun.hide_code # 隐藏代码窗口 json.hide_code @shixun.hide_code # 隐藏代码窗口
json.code_hidden @shixun.code_hidden # 代码目录隐藏 json.code_hidden @shixun.code_hidden # 代码目录隐藏
json.vnc @shixun.vnc json.vnc @shixun.vnc
json.exec_time @shixun.exec_time #json.exec_time @shixun.exec_time
json.webssh @shixun.webssh json.webssh @shixun.webssh
json.multi_webssh @shixun.multi_webssh json.multi_webssh @shixun.multi_webssh
json.use_scope @shixun.use_scope json.use_scope @shixun.use_scope
json.scope_partment @shixun.schools.map(&:name) # 公开范围 json.scope_partment @shixun.schools.map(&:name) # 公开范围
json.opening_time @shixun.opening_time json.opening_time @shixun.opening_time
json.forbid_copy @shixun.forbid_copy json.forbid_copy @shixun.forbid_copy
# 实训服务配置
json.shixun_service_configs do
json.array! @configs do |config|
json.name config.mirror_repository&.name
json.(config, :cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id)
end
end
end end

@ -117,6 +117,7 @@ Rails.application.routes.draw do
get :close_webssh get :close_webssh
get :get_answer_info get :get_answer_info
get :unlock_answer get :unlock_answer
get :check_test_sets
end end
collection do collection do
@ -337,6 +338,8 @@ Rails.application.routes.draw do
get :publish_groups get :publish_groups
get :end_groups get :end_groups
post :alter_name post :alter_name
get :update_score
get :update_student_score
end end
collection do collection do
@ -573,9 +576,13 @@ Rails.application.routes.draw do
resources :schools do resources :schools do
member do member do
resources :departments, only: [] do
get :for_option, on: :collection
end
end end
collection do collection do
get "school_list" get :school_list
get :for_option
end end
scope module: :ecs do scope module: :ecs do

@ -3,4 +3,6 @@
:logfile: log/sidekiq.log :logfile: log/sidekiq.log
:queues: :queues:
- [default, 3] - [default, 3]
- [score, 4]
- [evaluation_comment, 5]
- [notify, 100] - [notify, 100]

@ -0,0 +1,6 @@
class ModifyQuotesForGtopicBanks < ActiveRecord::Migration[5.2]
def change
GtopicBank.where("quotes is null").update_all(:quotes => 0)
change_column :gtopic_banks, :quotes, :integer, :default => 0
end
end

@ -0,0 +1,6 @@
class AddCalculationTimeToHomework < ActiveRecord::Migration[5.2]
def change
add_column :homework_commons, :calculation_time, :datetime
add_column :student_works, :calculation_time, :datetime
end
end

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save