From 178a448f54d0bacd20f7cff301bcea605231985d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 2 Jul 2019 17:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=88=97=E8=A1=A8=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=88=90=E7=BB=A9=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 72 +++++++++---------- .../graduation_tasks_controller.rb | 2 +- .../homework_commons_controller.rb | 2 +- app/helpers/export_helper.rb | 22 ++---- app/models/exercise.rb | 3 +- app/models/graduation_task.rb | 3 +- app/models/graduation_work.rb | 2 +- app/models/homework_common.rb | 3 +- app/models/poll.rb | 2 +- 9 files changed, 48 insertions(+), 63 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index cef2a1785..bae37d92a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -969,22 +969,17 @@ class CoursesController < ApplicationController @all_members = @course.students end if name.present? - nick_name_search = @all_members.joins(:user).where("nickname like ?","%#{name}%") - if nick_name_search.present? - @all_members = nick_name_search - else - @all_members = @all_members.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{name}%","%#{name}%") - end + @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%") end - @c_homeworks = @course.homework_commons.homework_published.order("publish_time asc, 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") + @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("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_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") 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, @c_polls) 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", locals: {course_info:@course_info, activity_level:@user_activity_level, @@ -1058,14 +1053,14 @@ class CoursesController < ApplicationController def member_to_xlsx(course,all_members,homeworks,exercises,tasks,polls) #课堂的作业信息 - shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 + shixun_homeworks = homeworks.search_homework_type(4).includes(:score_student_works) #全部实训作业 shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] - common_homeworks = homeworks.search_homework_type(1) #全部普通作业 + common_homeworks = homeworks.search_homework_type(1).includes(:score_student_works) #全部普通作业 common_titles = common_homeworks.pluck(:name)+ ["总得分"] - group_homeworks = homeworks.search_homework_type(3) #全部分组作业 + group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] - task_titles = tasks.pluck(:name)+ ["总得分"] - exercise_titles = exercises.pluck(:exercise_name)+ ["总得分"] + task_titles = tasks.includes(:score_graduation_works).pluck(:name) + ["总得分"] + exercise_titles = exercises.includes(:score_exercise_users).pluck(:exercise_name) + ["总得分"] total_user_score_array = [] #学生总成绩集合 #课堂信息 @@ -1114,7 +1109,7 @@ class CoursesController < ApplicationController course_user_level = [] course_activity_title = "课堂活跃度统计" user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度) - all_members.each do |u| + all_members.includes(user: :user_extension).each do |u| #用户的基本信息 user = u.user user_login = user.login @@ -1174,12 +1169,11 @@ class CoursesController < ApplicationController #实训作业 if shixun_homeworks.count > 0 shixun_homeworks.each do |s| - user_student_work = s.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 - if user_student_work.blank? + user_student_work = s.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + if user_student_work.nil? h_score = 0.0 #该作业的得分为0 else - user_stu_work = user_student_work.first - h_score = user_stu_work.work_score.nil? ? 0.0 : user_stu_work.work_score #用户对该作业的分数 + h_score = user_student_work.work_score.nil? ? 0.0 : user_student_work.work_score #用户对该作业的分数 end shixun_score_array.push(h_score) end @@ -1191,12 +1185,11 @@ class CoursesController < ApplicationController #普通作业 if common_homeworks.count > 0 common_homeworks.each do |c| - user_student_work_1 = c.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 - if user_student_work_1.blank? + user_student_work_1 = c.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + if user_student_work_1.nil? h_score_1 = 0.0 #该作业的得分为0 else - user_stu_work_1 = user_student_work_1.first - h_score_1 = user_stu_work_1.work_score.nil? ? 0.0 : user_stu_work_1.work_score #用户对该作业的分数 + h_score_1 = user_student_work_1.work_score.nil? ? 0.0 : user_student_work_1.work_score #用户对该作业的分数 end common_score_array.push(h_score_1) end @@ -1208,12 +1201,11 @@ class CoursesController < ApplicationController #分组作业 if group_homeworks.count > 0 group_homeworks.each do |g| - user_student_work_3 = g.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 - if user_student_work_3.blank? + user_student_work_3 = g.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + if user_student_work_3.nil? h_score_3 = 0.0 #该作业的得分为0 else - user_stu_work_3 = user_student_work_3.first - h_score_3 = user_stu_work_3.work_score.nil? ? 0.0 : user_stu_work_3.work_score #用户对该作业的分数 + h_score_3 = user_student_work_3.work_score.nil? ? 0.0 : user_student_work_3.work_score #用户对该作业的分数 end group_score_array.push(h_score_3) end @@ -1225,11 +1217,11 @@ class CoursesController < ApplicationController #毕设作业 if tasks.count > 0 tasks.each do |task| - graduation_works = task.graduation_works.find_by_task_user(user.id) - if graduation_works.empty? + graduation_work = task.score_graduation_works.find_by_user_id(user.id) + if graduation_work.nil? t_score = 0.0 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 task_score_array.push(t_score) end @@ -1241,11 +1233,11 @@ class CoursesController < ApplicationController #试卷 if exercises.count > 0 exercises.each do |ex| - exercise_works = ex.exercise_users.exercise_commit_users(user.id) - if exercise_works.empty? + exercise_work = ex.score_exercise_users.find_by_user_id(user.id) + if exercise_work.nil? e_score = 0.0 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 exercise_score_array.push(e_score) end @@ -1285,7 +1277,7 @@ class CoursesController < ApplicationController #实训作业 if count_1 > 0 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 student_work_to_xlsx(all_student_works,s) shixun_work_display_name = (title_no.to_s + "." + s.name).strip.first(30) @@ -1297,7 +1289,7 @@ class CoursesController < ApplicationController #普通作业 if count_2 > 0 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 student_work_to_xlsx(all_student_works,c) @@ -1311,7 +1303,7 @@ class CoursesController < ApplicationController #分组作业 if count_3 > 0 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 student_work_to_xlsx(all_student_works,c) work_name = (title_no.to_s + "." + c.name).strip.first(30) @@ -1323,7 +1315,7 @@ class CoursesController < ApplicationController #毕设任务 if count_4 > 0 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 graduation_work_to_xlsx(all_student_works,c,current_user) work_name = (title_no.to_s + "." + c.name).strip.first(30) @@ -1336,7 +1328,7 @@ class CoursesController < ApplicationController #试卷的导出 if count_5 > 0 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 get_export_users(c,course,all_student_works) work_name = (title_no.to_s + "." + c.exercise_name).strip.first(30) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 454f23c81..41ddb7659 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -145,7 +145,7 @@ class GraduationTasksController < ApplicationController file = decode64(zipfile[0][:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - tip_exception(status == -1 ? "文件大小超过500M,请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") + tip_exception(status == -2 ? "500" : "无附件可下载") end end } diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index af1dffe71..ca8d6364d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -229,7 +229,7 @@ class HomeworkCommonsController < ApplicationController file = decode64(zipfile[0][:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - tip_exception(status == -1 ? "文件大小超过500M,请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") + tip_exception(status == -2 ? "500M" : "无附件可下载") end end } diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index b6720c66c..31fadc265 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -37,7 +37,7 @@ module ExportHelper end 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?) - works.each_with_index do |w, index| + works.includes(student_works_scores: :user).each_with_index do |w, index| w_user = w.user w_1 = (index + 1) w_2 = w_user.login @@ -118,7 +118,7 @@ module ExportHelper end shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) @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(:myshixun).each_with_index do |w, index| myshixun = w.try(:myshixun) w_user = w.user w_1 = (index + 1) @@ -262,18 +262,8 @@ module ExportHelper end export_ex_users.each_with_index do |e_user,index| user_info = e_user.user - user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id).first - if user_course_id.present? - 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 + member = course.students.find_by_user_id(e_user.user_id) + user_course = member.try(:course_group_name) 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_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0 @@ -375,11 +365,11 @@ module ExportHelper end if file_size > MAX_DOWN_SIZE - status = -1 + status = -2 elsif file_count > 0 status = 0 else - status = -2 + status = -1 end status end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 60409e51d..ed003286b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,7 +3,8 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true 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_group_settings, :dependent => :delete_all has_many :tidings, as: :container diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index d85f9782d..030978817 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -16,7 +16,8 @@ class GraduationTask < ApplicationRecord has_many :graduation_task_group_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 belongs_to :gtask_bank, optional: true diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index e9be0a43e..093e409a9 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -53,7 +53,7 @@ class GraduationWork < ApplicationRecord # 分班名 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 # 分组名 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 3e0bec5fe..193d9aa6c 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -3,7 +3,8 @@ class HomeworkCommon < ApplicationRecord enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true has_many :homework_group_settings, dependent: :destroy 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 # 分组作业的设置 diff --git a/app/models/poll.rb b/app/models/poll.rb index f72239ba7..1920dd939 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -5,7 +5,7 @@ class Poll < ApplicationRecord # belongs_to :exercise_bank 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 :poll_group_settings, :dependent => :delete_all has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all