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

dev_forum
jasder 5 years ago
commit 9576602346

@ -9,17 +9,17 @@ module GitHelper
# 版本库文件内容,带转码 # 版本库文件内容,带转码
def git_fle_content(repo_path, path) def git_fle_content(repo_path, path)
begin begin
logger.info("git file content: repo_path is #{repo_path}, path is #{path}") 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("git file content: content is #{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

@ -959,34 +959,33 @@ 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 @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc")
end @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc")
# @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc")
@c_homeworks = @course.homework_commons.homework_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")
@c_exercises = @course.exercises.is_exercise_published.order("publish_time asc, created_at asc")
@c_polls = @course.polls.publish_or_not.order("publish_time asc, created_at asc")
@c_tasks = @course.graduation_tasks.task_published.order("publish_time asc, created_at asc")
if @user_course_identity > Course::ASSISTANT_PROFESSOR if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作") tip_exception(403,"无权限操作")
elsif @all_members.size == 0
normal_status(-1,"课堂暂时没有学生")
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,
@ -994,7 +993,7 @@ class CoursesController < ApplicationController
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("没有权限") tip_exception(e.message)
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
end end
@ -1056,16 +1055,72 @@ 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 max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id,
(SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id}
AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num,
(SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id}
AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num,
(SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course"
AND attachments.author_id = cm.user_id) AS resource_num,
(SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND
jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.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?
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
(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) + ["总得分"]
common_homeworks = homeworks.search_homework_type(1) #全部普通作业 shixun_homeworks = shixun_homeworks.includes(:score_student_works)
common_homeworks = homeworks.search_homework_type(1) #全部普通作业
common_titles = common_homeworks.pluck(:name)+ ["总得分"] common_titles = common_homeworks.pluck(:name)+ ["总得分"]
common_homeworks = common_homeworks.includes(:score_student_works)
group_homeworks = homeworks.search_homework_type(3) #全部分组作业 group_homeworks = homeworks.search_homework_type(3) #全部分组作业
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 = [] #学生总成绩集合
#课堂信息 #课堂信息
@ -1080,7 +1135,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]
@ -1105,11 +1160,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 = "课堂活跃度统计"
@ -1120,27 +1170,26 @@ class CoursesController < ApplicationController
user_login = user.login user_login = user.login
user_name = user.real_name user_name = user.real_name
user_mail = user.mail user_mail = user.mail
user_stu_id = user.student_id.present? ? (user.student_id.to_s + "\t") : "--" user_stu_id = u.student_id.present? ? (u.student_id.to_s + "\t") : "--"
user_course_group = u.course_group_name user_course_group = u.course_group_name
user_info_array = [user_login,user_name,user_mail,user_stu_id,user_course_group] #用户的信息集合 user_info_array = [user_login,user_name,user_mail,user_stu_id,user_course_group] #用户的信息集合
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
c_file_num = user_file_num*5 c_file_num = user_file_num*5
c_message_num = user_messages_num*2 c_message_num = user_messages_num*2
c_reply_num = user_reply_num*2 c_reply_num = user_reply_num
user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num
user_ac_level = { user_ac_level = {
u_1: user_name, u_1: user_name,
@ -1172,14 +1221,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
@ -1189,14 +1237,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
@ -1206,14 +1253,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
@ -1223,13 +1269,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
@ -1239,13 +1285,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
@ -1277,73 +1323,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.score_student_works #该实训题的全部用户回答
all_student_works = s.student_works.has_committed.order("work_score desc") #该实训题的全部用户回答 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 = format_sheet_name (title_no.to_s + "." + s.name).strip.first(30)
shixun_work_display_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.score_student_works #当前用户的对该作业的回答
all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 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 = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
work_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.score_student_works #当前用户的对该作业的回答
all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 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 = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
work_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.score_graduation_works #当前用户的对该作业的回答
all_student_works = c.graduation_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 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 = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
work_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.score_exercise_users #当前用户的对该作业的回答
all_student_works = c.exercise_users.exercise_user_committed #当前用户的对该作业的回答 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 = format_sheet_name (title_no.to_s + "." + c.exercise_name).strip.first(30)
work_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

@ -1238,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 #已评阅
@ -1254,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]
@ -1278,51 +1270,49 @@ 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,如果存在则返回,否则继续查询用户的真实姓名或学生号 end
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_user_joins = @exercise_users_list.joins(user: :user_extension)
@exercise_users_list = nick_name_search
else if order == "student_id"
@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}%") @exercise_users_list = exercise_user_joins.order("user_extensions.student_id DESC")
end 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
if @user_course_identity > Course::ASSISTANT_PROFESSOR @exercise_users_size = 0
tip_exception(403,"无权限操作") end
else
if params[:format] == "xlsx"
if @user_course_identity > Course::ASSISTANT_PROFESSOR
tip_exception(403,"无权限操作")
elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0)
normal_status(-1,"暂无用户提交")
else
respond_to do |format|
format.xlsx{
get_export_users(@exercise,@course,@export_ex_users) get_export_users(@exercise,@course,@export_ex_users)
exercise_export_name = exercise_export_name =
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" "#{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} 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
else
@exercise_users_list = []
@exercise_users_size = 0
respond_to do |format|
format.json
format.xlsx{
normal_status(-1,"暂无用户提交")
}
format.zip{
normal_status(-1,"暂无用户提交")
}
end end
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("页面调用失败!") tip_exception("页面调用失败!")
@ -1335,7 +1325,7 @@ class ExercisesController < ApplicationController
def export_exercise def export_exercise
@request_url = request.base_url @request_url = request.base_url
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" 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

@ -123,46 +123,48 @@ class GraduationTasksController < ApplicationController
@work_count = @work_list.count @work_count = @work_list.count
@work_excel = @work_list @work_excel = @work_list
@work_list = @work_list.page(page).per(limit) @work_list = @work_list.page(page).per(limit)
respond_to do |format|
format.json if params[:format] == "xlsx"
format.xlsx{ complete_works = @work_excel.where("work_status > 0").size
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else elsif complete_works == 0
graduation_work_to_xlsx(@work_excel,@task,current_user) normal_status(-1,"暂无用户提交!")
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @task.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') else
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} respond_to do |format|
format.xlsx{
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')}"
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}
}
end end
} end
format.zip{ elsif params[:format] == "zip"
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
zip_works = @work_excel.where("work_status > 0") zip_works = @work_excel.where("work_status > 0")
status = checkfileSize(zip_works) status = checkfileSize(zip_works)
if status == 0 if status == 0
zipfile = zip_homework_common @task, zip_works respond_to do |format|
file = decode64(zipfile[0][:base64file]) format.zip{
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' zipfile = zip_homework_common @task, zip_works
else file = decode64(zipfile[0][:base64file])
tip_exception(status == -1 ? "文件大小超过500M请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
}
end end
else
tip_exception(status == -2 ? "500M" : "无附件可下载")
end end
} end
end end
else else
@work_list = @work @work_list = @work
@view_work = false @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| if params[:format] == "xlsx" || params[:format] == "zip"
format.json normal_status(-1,"作业未发布")
format.xlsx{
normal_status(-1,"作业未发布")
}
format.zip{
normal_status(-1,"作业未发布")
}
end end
end end
end end

@ -266,11 +266,16 @@ class GraduationTopicsController < ApplicationController
# 导出功能 # 导出功能
def export def export
course = @course begin
students = course.students.joins(user: :user_extension).order("user_extensions.student_id") course = @course
graduation_topic_to_xlsx(students,course) students = course.students.joins(user: :user_extension).order("user_extensions.student_id")
exercise_export_name = current_user.real_name + "_" + course.name + "_毕设选题" + "_" + Time.now.strftime('%Y%m%d_%H%M%S') graduation_topic_to_xlsx(students,course)
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells}
rescue Exception => e
uid_logger(e.message)
missing_template
end
end end
private private

@ -108,14 +108,8 @@ class HomeworkCommonsController < ApplicationController
@all_member_count = student_works.size @all_member_count = student_works.size
if @homework.publish_time.nil? || @homework.publish_time > Time.now if @homework.publish_time.nil? || @homework.publish_time > Time.now
@student_works = [] @student_works = []
respond_to do |format| if params[:format] == "xlsx" || params[:format] == "zip"
format.json normal_status(-1,"作业未发布")
format.xlsx{
normal_status(-1,"作业未发布")
}
format.zip{
normal_status(-1,"作业未发布")
}
end end
else else
if @user_course_identity == Course::STUDENT if @user_course_identity == Course::STUDENT
@ -186,7 +180,7 @@ 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 @students = @course.students
# 分页参数 # 分页参数
@ -200,45 +194,48 @@ class HomeworkCommonsController < ApplicationController
end end
# @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group)
end end
respond_to do |format|
format.json if params[:format] == "xlsx"
format.xlsx{ complete_works = @work_excel.where("work_status > 0").size
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else elsif complete_works == 0
if @work_excel.present? normal_status(-1,"暂无用户提交!")
else
respond_to do |format|
format.xlsx{
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')
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column} {table_columns: @work_head_cells,task_users: @work_cells_column}
else }
normal_status(-1,"暂无提交的学生!")
end
end end
} end
format.zip{ elsif params[:format] == "zip"
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
else else
zip_works = @work_excel.where("work_status > 0") zip_works = @work_excel.where("work_status > 0")
status = checkfileSize(zip_works) status = checkfileSize(zip_works)
if status == 0 if status == 0
zipfile = zip_homework_common @homework, zip_works respond_to do |format|
file = decode64(zipfile[0][:base64file]) format.zip{
send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' zipfile = zip_homework_common @homework, zip_works
else file = decode64(zipfile[0][:base64file])
tip_exception(status == -1 ? "文件大小超过500M请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip'
}
end end
else
tip_exception(status == -2 ? "500M" : "无附件可下载")
end end
} end
end end
end end
end end
def update_score def update_score
tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now tip_exception("作业还未发布,暂不能计算成绩") if @homework.end_or_late_none_group
begin begin
if @homework.unified_setting if @homework.unified_setting
student_works = @homework.student_works student_works = @homework.student_works
@ -258,6 +255,8 @@ class HomeworkCommonsController < ApplicationController
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end end
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) @homework.update_attribute('calculation_time', Time.now)
normal_status("更新成功") normal_status("更新成功")
rescue Exception => e rescue Exception => e
@ -270,7 +269,7 @@ class HomeworkCommonsController < ApplicationController
def update_student_score def update_student_score
work = @homework.student_works.find_by(user_id: current_user.id) 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) myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at)
challenge_settings = @homework.homework_challenge_settings challenge_settings = @homework.homework_challenge_settings
@ -606,14 +605,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
@ -1017,8 +1016,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

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

@ -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
@ -920,21 +920,30 @@ 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 if @user_course_identity > Course::ASSISTANT_PROFESSOR
format.xlsx{ tip_exception(403,"无权限操作")
if @user_course_identity > Course::ASSISTANT_PROFESSOR elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0)
tip_exception(403,"无权限操作") 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{
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 end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
@ -957,9 +966,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
@ -1005,14 +1013,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
@ -1026,20 +1028,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}%")) end
if nick_name_search.present?
@poll_users_list = nick_name_search poll_users_joins = @poll_users_list.joins(user: :user_extension)
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}%") if order == "student_id"
end @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
@ -1149,10 +1154,10 @@ class PollsController < ApplicationController
def get_questions_count def get_questions_count
@poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).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 的权限

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

@ -203,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?
@ -280,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]
@ -388,7 +394,6 @@ 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(shixun_params)
@shixun.shixun_info.update_attributes(shixun_info_params) @shixun.shixun_info.update_attributes(shixun_info_params)
@shixun.shixun_schools.delete_all @shixun.shixun_schools.delete_all
@ -407,9 +412,7 @@ class ShixunsController < ApplicationController
# 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置
if current_user.admin? || current_user.business? if current_user.admin? || current_user.business?
@shixun.shixun_service_configs.destroy_all @shixun.shixun_service_configs.destroy_all
params[:shixun_service_configs].each do |config| @shixun.shixun_service_configs.create!(service_config_params[:shixun_service_configs])
@shixun.shixun_service_configs.create!(config)
end
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
@ -735,15 +738,21 @@ private
def shixun_params def shixun_params
raise("实训名称不能为空") if params[:shixun][: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, :code_hidden, :task_pass, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden,
:hide_code, :forbid_copy) :hide_code, :forbid_copy)
end end
def shixun_info_params def shixun_info_params
raise("实训描述不能为空") if params[:shixun_info][:description].blank? raise("实训描述不能为空") if params[:shixun_info][:description].blank?
raise("评测脚本不能为空") if params[:shixun_info][:evaluate_script].blank? raise("评测脚本不能为空") if params[:shixun_info][:evaluate_script].blank?
params.require(:shixun_info).permit(:description, :evaluate_script) params.require(:shixun_info).permit(:description, :evaluate_script)
end end
def service_config_params
params.permit(shixun_service_configs: [:cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id])
end
def find_shixun def find_shixun
@shixun = Shixun.find_by_identifier(params[:identifier]) @shixun = Shixun.find_by_identifier(params[:identifier])
if @shixun.blank? if @shixun.blank?

@ -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'
@ -42,14 +44,34 @@ class ZipsController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id])
@exercise_status = @exercise.get_exercise_status(current_user.id)
group_id = params[:exercise_group_id] group_id = params[:exercise_group_id]
if @exercise.blank? if @exercise.blank?
normal_status(-1,"试卷不存在") normal_status(-1,"试卷不存在")
elsif @exercise_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
@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.where(course_group_id: group_id) # 试卷所分班的全部人数 exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数
@ -57,12 +79,17 @@ class ZipsController < ApplicationController
@ex_users = @ex_users.where(user_id: user_ids) @ex_users = @ex_users.where(user_id: user_ids)
end end
default_ex_users_size = @ex_users.size #搜索
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
if default_ex_users_size == 0 default_ex_users_size = @ex_users&.size
normal_status(-1,"导出失败,暂时没有已提交的学生")
if default_ex_users_size.blank? || default_ex_users_size == 0
normal_status(-1,"暂无用户提交")
elsif default_ex_users_size > 100 elsif default_ex_users_size > 100
normal_status(-1,"导出数量超过100,请分班导出或联系网站管理员导出") normal_status(-2,"100")
end end
end end
rescue Exception => e rescue Exception => e
@ -74,6 +101,34 @@ 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).where("work_status > 0")
work_status = params[:work_status]
group_id = params[:course_group]
if work_status.present?
@all_student_works = @all_student_works.where(work_status:work_status)
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

@ -734,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
@ -217,7 +217,16 @@ module ExportHelper
else else
w_6 = nil w_6 = nil
end end
w_7 = work.work_status w_status = work.work_status.to_i
if w_status == 0
w_7 = "未提交"
elsif w_status == 1
w_7 = "按时提交"
elsif w_status == 2
w_7 = "延时提交"
else
w_7 = "--"
end
if task_project_boolean #关联项目 if task_project_boolean #关联项目
w_project = project_info work, current_user, @user_course_identity #因为课堂引用了export_helper w_project = project_info work, current_user, @user_course_identity #因为课堂引用了export_helper
w_8 = w_project[:name] w_8 = w_project[:name]
@ -260,20 +269,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 +304,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 +317,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 +374,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 +513,7 @@ module ExportHelper
attach.filename attach.filename
end end
def format_sheet_name name
name = name.gsub(":", "-")
end
end end

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

@ -3,7 +3,8 @@ 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 => :delete_all has_many :exercise_users, -> { where("is_delete = 0") }, :dependent => :delete_all
has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser"
has_many :exercise_questions, :dependent => :delete_all has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all has_many :exercise_group_settings, :dependent => :delete_all
has_many :tidings, as: :container has_many :tidings, as: :container

@ -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
# 分组名 # 分组名

@ -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
# 分组作业的设置 # 分组作业的设置
@ -118,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

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

@ -5,7 +5,7 @@ class Poll < ApplicationRecord
# belongs_to :exercise_bank # belongs_to :exercise_bank
has_many :poll_questions,dependent: :delete_all has_many :poll_questions,dependent: :delete_all
has_many :poll_users, :dependent => :delete_all 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 => :delete_all has_many :poll_group_settings, :dependent => :delete_all
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all
@ -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的交集

@ -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,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,6 +2,7 @@ class ExerciseUserPdfService
include ExercisesHelper include ExercisesHelper
include ApplicationHelper include ApplicationHelper
include StudentWorksHelper include StudentWorksHelper
include GitHelper
attr_reader :exercise, :ex_user, :request_url attr_reader :exercise, :ex_user, :request_url
@ -14,8 +15,8 @@ class ExerciseUserPdfService
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
@ -41,7 +42,7 @@ class ExerciseUserPdfService
# #-----正式需删掉 # #-----正式需删掉
# 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

@ -10,7 +10,7 @@ class ExportExercisesService
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

@ -45,7 +45,8 @@ class ExportShixunReportService
@games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun
# 用户最大评测次数 # 用户最大评测次数
@user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first } if @games @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games
# @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index)&.first } if @games
# 图形效率图的数据 # 图形效率图的数据
@echart_data = student_efficiency(homework, @work) @echart_data = student_efficiency(homework, @work)
@myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id }

@ -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}")

@ -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,17 +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"> <% if @exercise_ques_count > 0 %>
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分 <span class="mr15">
</span>
<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">
@ -94,7 +97,7 @@
<% elsif q.question_type == 2 %> <% elsif q.question_type == 2 %>
<div class="pbt5 clearfix"> <div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %> <% q.exercise_choices.each do |s| %>
<span class="mr15 clearfix"> <span class="mr15">
<span class="choose-radio "></span> <span class="choose-radio "></span>
<span class="mlr5 inline-block"><%= s.choice_text %></span> <span class="mlr5 inline-block"><%= s.choice_text %></span>
</span> </span>

@ -2,6 +2,7 @@ body{
font-size:14px; font-size:14px;
font-family: "微软雅黑","宋体"; font-family: "微软雅黑","宋体";
} }
p{ p{
margin:0; margin:0;
} }
@ -39,7 +40,7 @@ p{
margin-bottom: 10px; margin-bottom: 10px;
} }
.mt8{ .mt8{
margin-top:8px; margin-top:7px;
} }
.mt10{ .mt10{
margin-top:10px; margin-top:10px;
@ -319,6 +320,7 @@ textarea{
border:none; border:none;
background-color:#eee; background-color:#eee;
line-height:2; line-height:2;
} }
.clearfix{ .clearfix{
clear:both; clear:both;
@ -328,6 +330,20 @@ textarea{
.choice-text p{ .choice-text p{
margin-bottom:0; 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 %>
<span class="pull-right">
<% if @exercise_ques_count > 0 %> <% if @exercise_ques_count > 0 %>
<span class="pull-right"> <span class="mr15">
共<span class="text-orange mlr5"><%= @exercise_ques_scores %></span>分
</span>
<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>
@ -177,15 +179,17 @@
<% 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 do |s| %> <% 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" : '' %>
<div class="pbt10 clearfix main-choice"> <div class="pbt10 clearfix main-choice">
<span class="choose-radio <%= check_answer %> pull-left mt10"></span> <span class="choose-radio <%= check_answer %> pull-left mt10"></span>
<span class="inline-block pull-left ml10 choice-text"><%= to_markdown(s.choice_text,@request_url) %></span> <span class="inline-block pull-left ml10 choice-text mt-2"><%= to_markdown(s.choice_text,@request_url) %></span>
</div> </div>
<% end %> <% end %>
<div class="clearfix"></div>
<% elsif q_type == 1 %> <% elsif q_type == 1 %>
<% q.exercise_choices.each do |s| %> <% 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 %>
@ -195,9 +199,10 @@
<% else %> <% else %>
<span class="choose-checkbox pull-left mt10"></span> <span class="choose-checkbox pull-left mt10"></span>
<% end %> <% end %>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span> <span class="inline-block pull-left choice-text ml10 mt-2"><%= to_markdown(s.choice_text,@request_url) %></span>
</div> </div>
<% end %> <% end %>
<div class="clearfix"></div>
<% elsif q_type == 2 %> <% elsif q_type == 2 %>
<div class="pbt5 clearfix"> <div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %> <% q.exercise_choices.each do |s| %>
@ -212,6 +217,7 @@
</span> </span>
<% end %> <% end %>
</div> </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| %>
@ -220,10 +226,11 @@
<% 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"><%= to_markdown(check_answer,@request_url) %></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 : '--') %>
@ -232,6 +239,7 @@
<%= to_markdown(check_answer,@request_url) %> <%= to_markdown(check_answer,@request_url) %>
</div> </div>
</div> </div>
<div class="clearfix"></div>
<% else %> <% else %>
<div class="mbt10"> <div class="mbt10">
<p class="text-gray mbt10"> <p class="text-gray mbt10">
@ -310,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) %>
<div class="mbt20"> <% latest_code = git_fle_content(game.myshixun.repo_path,cha_path) %>
<p class="bgc" > <% else %>
<% latest_code = game.try(:lastest_code) %>
<% end %>
<% con_rows = content_line(latest_code) %>
<div class="mbt20">
<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>
<% end %> </div>
</div> </div>
</div> </div>
<% end %> <% end %>
</div> </div>
<div class="clearfix"></div>
<% end %> <% end %>
</div> </div>
</div> </div>

@ -9,7 +9,7 @@ wb.styles do |s|
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,13 +18,13 @@ 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)
@ -49,7 +49,7 @@ wb.styles do |s|
end #each_with_index end #each_with_index
sheet.add_row poll_users_info, :height =>15, :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|

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

@ -23,7 +23,7 @@ namespace :homework_publishtime do
homework_detail_manual.update_column('comment_status', 1) homework_detail_manual.update_column('comment_status', 1)
# 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发 # 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发
if homework.unified_setting if homework.unified_setting
HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) # HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id)
HomeworkCommonPushNotifyJob.perform_later(homework.id, nil) HomeworkCommonPushNotifyJob.perform_later(homework.id, nil)
else else
course = homework.course course = homework.course
@ -53,7 +53,7 @@ namespace :homework_publishtime do
homework_group_settings.each do |homework_group| homework_group_settings.each do |homework_group|
homework = homework_group.homework_common homework = homework_group.homework_common
if homework.present? if homework.present?
HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) # HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id)
HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id]) HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id])
end end
end end

Loading…
Cancel
Save