From dd49b9e9adca84254a5fc552acb5a0920354fa8a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 11:26:16 +0800 Subject: [PATCH 001/124] =?UTF-8?q?=20xlsx=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 + app/controllers/exercises_controller.rb | 22 ++-- .../graduation_tasks_controller.rb | 104 ++++++++++++------ .../homework_commons_controller.rb | 86 ++++++++++----- app/controllers/polls_controller.rb | 11 -- 5 files changed, 137 insertions(+), 88 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2d379b555..6d1964840 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -978,6 +978,8 @@ class CoursesController < ApplicationController @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,"无权限操作") + elsif @all_members.size == 0 + normal_status(-1,"课堂暂时没有学生") else 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') diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index dd19c36d1..07113792d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,21 +1300,19 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + 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) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } + end end end - - respond_to do |format| - format.json - format.xlsx{ - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 1931c26a0..23344e7fc 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -123,51 +123,83 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list @work_list = @work_list.page(page).per(limit) - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") - else - if @work_count > 1 - 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} - else - normal_status(-1,"暂无提交的学生!") - end - end - } - format.zip{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") + + if params[:format] == "xlsx" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + elsif @work_count == 0 + normal_status(-1,"暂无提交的学生!") + else + 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') + + 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} + end + elsif params[:format] == "zip" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + else + zip_works = @work_excel.where("work_status > 0") + status = checkfileSize(zip_works) + if status == 0 + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) - if status == 0 - zipfile = zip_homework_common @task, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - else - tip_exception(status == -2 ? "500" : "无附件可下载") - end + tip_exception(status == -2 ? "500M" : "无附件可下载") end - } + end end + # + # respond_to do |format| + # format.json + # format.xlsx{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # if @work_count > 1 + # 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} + # else + # normal_status(-1,"暂无提交的学生!") + # end + # end + # } + # format.zip{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # zip_works = @work_excel.where("work_status > 0") + # status = checkfileSize(zip_works) + # if status == 0 + # zipfile = zip_homework_common @task, zip_works + # file = decode64(zipfile[0][:base64file]) + # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + # else + # tip_exception(status == -2 ? "500" : "无附件可下载") + # end + # end + # } + # end else @work_list = @work @view_work = false @work_count = @work_list.count @all_work_count = @work_list.count - respond_to do |format| - format.json - format.xlsx{ - normal_status(-1,"作业未发布") - } - format.zip{ - normal_status(-1,"作业未发布") - } + if params[:format] == "xlsx" || params[:format] == "zip" + normal_status(-1,"作业未发布") end + # respond_to do |format| + # format.json + # format.xlsx{ + # normal_status(-1,"作业未发布") + # } + # format.zip{ + # normal_status(-1,"作业未发布") + # } + # end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 89e301f93..5de65210f 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,40 +200,68 @@ class HomeworkCommonsController < ApplicationController end # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) end - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") - else - if @work_count > 1 - 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') - 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} - else - normal_status(-1,"暂无提交的学生!") - end + if params[:format] == "xlsx" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + elsif @work_count == 0 + normal_status(-1,"暂无提交的学生!") + else + 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') - end - } - format.zip{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") + 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} + end + elsif params[:format] == "zip" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + else + zip_works = @work_excel.where("work_status > 0") + status = checkfileSize(zip_works) + if status == 0 + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) - if status == 0 - zipfile = zip_homework_common @homework, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - else - tip_exception(status == -2 ? "500M" : "无附件可下载") - end + tip_exception(status == -2 ? "500M" : "无附件可下载") end - } + end end + # respond_to do |format| + # format.json + # format.xlsx{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # if @work_count > 1 + # 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') + # + # 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} + # else + # normal_status(-1,"暂无提交的学生!") + # end + # + # end + # } + # format.zip{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # zip_works = @work_excel.where("work_status > 0") + # status = checkfileSize(zip_works) + # if status == 0 + # zipfile = zip_homework_common @homework, zip_works + # file = decode64(zipfile[0][:base64file]) + # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + # else + # tip_exception(status == -2 ? "500M" : "无附件可下载") + # end + # end + # } + # end end end diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 7075ac0ef..244cdf57f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -945,17 +945,6 @@ class PollsController < ApplicationController end end end - # respond_to do |format| - # format.json - # format.xlsx{ - # polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - # render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { - # poll_questions:@poll_export_questions, - # poll:@poll, - # poll_users: @poll_users, - # poll_commit_ids:@poll_commit_ids} - # } - # end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") From d80b7d924523c715ba0a3341a29d49096fa5dc46 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 11:26:19 +0800 Subject: [PATCH 002/124] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 4e4d0284a..5d8c1408f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -991,7 +991,7 @@ class CoursesController < ApplicationController end rescue Exception => e uid_logger_error(e.message) - tip_exception("没有权限") + tip_exception(e.message) raise ActiveRecord::Rollback end end @@ -1061,15 +1061,11 @@ class CoursesController < ApplicationController AND homework_commons.course_id = #{@course.id} AND student_works.user_id = cm.user_id ) AS score, - (SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id - AND gt.course_id = #{@course.id} AND gw.user_id = cm.user_id) AS graduation_score, - (SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id - AND exercises.course_id = #{@course.id} AND exercise_users.user_id = cm.user_id) AS ex_score, (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, - (SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_num, - (SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_reply_num, - (SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS resource_num, - (SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS homework_journal_num, + (SELECT count(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, From 0a48259433bda039d08363c559f7f2eb5b46298e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 11:27:11 +0800 Subject: [PATCH 003/124] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5d8c1408f..5c03dffee 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1160,7 +1160,7 @@ class CoursesController < ApplicationController user_login = user.login user_name = user.real_name 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_info_array = [user_login,user_name,user_mail,user_stu_id,user_course_group] #用户的信息集合 user_work_scores = [] From 515b6aef09aa4433140305143ebb0700e7787266 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:15:30 +0800 Subject: [PATCH 004/124] fix bug --- app/controllers/homework_commons_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5de65210f..6cffa866d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -202,6 +202,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" + logger.info("#########______@work_count_________#######{@work_count}") if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif @work_count == 0 From 9e720b3d00ac61573eb97ab3987fbd7bcb3e639b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:24:09 +0800 Subject: [PATCH 005/124] fix bug --- .../graduation_tasks_controller.rb | 9 ++++---- .../graduation_topics_controller.rb | 2 +- .../homework_commons_controller.rb | 23 +++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 23344e7fc..a518ac954 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -130,11 +130,10 @@ class GraduationTasksController < ApplicationController elsif @work_count == 0 normal_status(-1,"暂无提交的学生!") else - 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') - 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} + 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 elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -143,7 +142,7 @@ class GraduationTasksController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @homework, zip_works + zipfile = zip_homework_common @task, zip_works file = decode64(zipfile[0][:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index c611069a8..2c9132520 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -269,7 +269,7 @@ class GraduationTopicsController < ApplicationController course = @course students = course.students.joins(user: :user_extension).order("user_extensions.student_id") graduation_topic_to_xlsx(students,course) - exercise_export_name = current_user.real_name + "_" + course.name + "_毕设选题" + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + 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} end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6cffa866d..50ec4f7db 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,11 +208,16 @@ class HomeworkCommonsController < ApplicationController elsif @work_count == 0 normal_status(-1,"暂无提交的学生!") else - 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') + respond_to do |format| + format.xlsx{ + 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') + + 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} + } + end - 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} end elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -221,9 +226,13 @@ class HomeworkCommonsController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @homework, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + respond_to do |format| + format.zip{ + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + } + end else tip_exception(status == -2 ? "500M" : "无附件可下载") end From 44e4496928a1a8ae9a7fcc4c363070d8f60428fb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:56:43 +0800 Subject: [PATCH 006/124] =?UTF-8?q?xlsx=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduation_tasks_controller.rb | 65 +++++-------------- .../graduation_topics_controller.rb | 15 +++-- .../homework_commons_controller.rb | 49 ++------------ app/helpers/export_helper.rb | 11 +++- 4 files changed, 40 insertions(+), 100 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index a518ac954..aebd8b092 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -125,15 +125,19 @@ class GraduationTasksController < ApplicationController @work_list = @work_list.page(page).per(limit) if params[:format] == "xlsx" + complete_works = @work_excel.where("work_status > 0").size if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif @work_count == 0 + elsif complete_works == 0 normal_status(-1,"暂无提交的学生!") else - - 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} + 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 elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -142,46 +146,18 @@ class GraduationTasksController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @task, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + respond_to do |format| + format.zip{ + zipfile = zip_homework_common @task, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + } + end else tip_exception(status == -2 ? "500M" : "无附件可下载") end end end - # - # respond_to do |format| - # format.json - # format.xlsx{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # if @work_count > 1 - # 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} - # else - # normal_status(-1,"暂无提交的学生!") - # end - # end - # } - # format.zip{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # zip_works = @work_excel.where("work_status > 0") - # status = checkfileSize(zip_works) - # if status == 0 - # zipfile = zip_homework_common @task, zip_works - # file = decode64(zipfile[0][:base64file]) - # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - # else - # tip_exception(status == -2 ? "500" : "无附件可下载") - # end - # end - # } - # end else @work_list = @work @view_work = false @@ -190,15 +166,6 @@ class GraduationTasksController < ApplicationController if params[:format] == "xlsx" || params[:format] == "zip" normal_status(-1,"作业未发布") end - # respond_to do |format| - # format.json - # format.xlsx{ - # normal_status(-1,"作业未发布") - # } - # format.zip{ - # normal_status(-1,"作业未发布") - # } - # end end end diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 2c9132520..b20b767a4 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -266,11 +266,16 @@ class GraduationTopicsController < ApplicationController # 导出功能 def export - course = @course - students = course.students.joins(user: :user_extension).order("user_extensions.student_id") - graduation_topic_to_xlsx(students,course) - 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} + begin + course = @course + students = course.students.joins(user: :user_extension).order("user_extensions.student_id") + graduation_topic_to_xlsx(students,course) + 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 private diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 50ec4f7db..2d52b6aa0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -108,14 +108,8 @@ class HomeworkCommonsController < ApplicationController @all_member_count = student_works.size if @homework.publish_time.nil? || @homework.publish_time > Time.now @student_works = [] - respond_to do |format| - format.json - format.xlsx{ - normal_status(-1,"作业未发布") - } - format.zip{ - normal_status(-1,"作业未发布") - } + if params[:format] == "xlsx" || params[:format] == "zip" + normal_status(-1,"作业未发布") end else if @user_course_identity == Course::STUDENT @@ -202,10 +196,10 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - logger.info("#########______@work_count_________#######{@work_count}") + complete_works = @work_excel.where("work_status > 0").size if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif @work_count == 0 + elsif complete_works == 0 normal_status(-1,"暂无提交的学生!") else respond_to do |format| @@ -217,7 +211,6 @@ class HomeworkCommonsController < ApplicationController {table_columns: @work_head_cells,task_users: @work_cells_column} } end - end elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -238,40 +231,6 @@ class HomeworkCommonsController < ApplicationController end end end - # respond_to do |format| - # format.json - # format.xlsx{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # if @work_count > 1 - # 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') - # - # 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} - # else - # normal_status(-1,"暂无提交的学生!") - # end - # - # end - # } - # format.zip{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # zip_works = @work_excel.where("work_status > 0") - # status = checkfileSize(zip_works) - # if status == 0 - # zipfile = zip_homework_common @homework, zip_works - # file = decode64(zipfile[0][:base64file]) - # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - # else - # tip_exception(status == -2 ? "500M" : "无附件可下载") - # end - # end - # } - # end end end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index edb2b7e74..a23cb8a65 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -217,7 +217,16 @@ module ExportHelper else w_6 = nil 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 #关联项目 w_project = project_info work, current_user, @user_course_identity #因为课堂引用了export_helper w_8 = w_project[:name] From af2f6ae95e4581c1aeebfc76055911fb1c23ea28 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 13:46:52 +0800 Subject: [PATCH 007/124] fix bug --- app/controllers/zips_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 984bef6d2..3b9fa7c02 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -101,14 +101,12 @@ class ZipsController < ApplicationController @course = @homework.course ##7。2 -hs新增 @member = @course.course_member(current_user.id) - @all_student_works = @homework.teacher_works(@member) + @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? && !work_status.include?(0) + if work_status.present? @all_student_works = @all_student_works.where(work_status:work_status) - elsif work_status.present? && work_status.include?(0) - normal_status(-1,"仅支持导出已提交的学生!") end if group_id.present? From d3927146dcb2b2a227971d00a306ee903d6759df Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 14:20:35 +0800 Subject: [PATCH 008/124] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5c03dffee..fbc1c04cf 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1062,14 +1062,22 @@ class CoursesController < ApplicationController 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 + (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 @@ -1078,7 +1086,7 @@ class CoursesController < ApplicationController (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} elsif search.present? - ql_select += %Q{ join users on cm.user_id = users.id + 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} @@ -1101,7 +1109,7 @@ class CoursesController < ApplicationController common_titles = common_homeworks.pluck(:name)+ ["总得分"] common_homeworks = common_homeworks.includes(:score_student_works) - group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业 + group_homeworks = homeworks.search_homework_type(3) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] group_homeworks = group_homeworks.includes(:score_student_works) @@ -1179,7 +1187,7 @@ class CoursesController < ApplicationController c_poll_num = user_poll_num*7 c_file_num = user_file_num*5 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_ac_level = { u_1: user_name, From 19ef46f0778775dd80ea25812209b4b8c056f20d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 14:21:53 +0800 Subject: [PATCH 009/124] fix bug --- app/controllers/graduation_tasks_controller.rb | 2 +- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/zips_controller.rb | 11 ++++++++--- app/services/export_shixun_report_service.rb | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index aebd8b092..a89a81798 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无提交的学生!") + normal_status(-1,"暂无用户提交!") else respond_to do |format| format.xlsx{ diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2d52b6aa0..fe2adba45 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,7 +200,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无提交的学生!") + normal_status(-1,"暂无用户提交!") else respond_to do |format| format.xlsx{ diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 3b9fa7c02..8553cbb44 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -44,9 +44,12 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @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] if @exercise.blank? normal_status(-1,"试卷不存在") + elsif @exercise_status == 1 + normal_status(-1,"试卷未发布") else @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed @@ -66,7 +69,7 @@ class ZipsController < ApplicationController 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,"仅支持导出已提交的学生!") + normal_status(-1,"暂无用户提交!") end #可以分班选择 @@ -84,7 +87,7 @@ class ZipsController < ApplicationController default_ex_users_size = @ex_users&.size if default_ex_users_size.blank? || default_ex_users_size == 0 - normal_status(-1,"导出失败,暂时没有已提交的学生") + normal_status(-1,"暂无用户提交") elsif default_ex_users_size > 100 normal_status(-2,"100") end @@ -98,6 +101,8 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) + + @course = @homework.course ##7。2 -hs新增 @member = @course.course_member(current_user.id) @@ -121,7 +126,7 @@ class ZipsController < ApplicationController student_work_sizes = @all_student_works&.size if student_work_sizes.blank? || student_work_sizes == 0 - normal_status(-1,"导出失败,暂时没有已提交的学生") + normal_status(-1,"暂无用户提交") elsif student_work_sizes > 100 normal_status(-2,"100") end diff --git a/app/services/export_shixun_report_service.rb b/app/services/export_shixun_report_service.rb index 8358d422e..4c8dab6aa 100644 --- a/app/services/export_shixun_report_service.rb +++ b/app/services/export_shixun_report_service.rb @@ -45,7 +45,8 @@ class ExportShixunReportService @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) @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } From 77b6b52cff13adb2dea41c5e6a16e2ae32cf6a5c Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 3 Jul 2019 14:53:03 +0800 Subject: [PATCH 010/124] files pemission --- app/controllers/files_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c8fd042ea..2af178e47 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -200,7 +200,7 @@ class FilesController < ApplicationController # 资源设置 def update - return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_or_admin?(@course) || @file.author == current_user + return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@course) >= 5 && @file.author != current_user is_unified_setting = params[:is_unified_setting] publish_time = params[:publish_time] From c1ad4c0585bf34fa89c5974ab3c14b1156a85994 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 14:57:20 +0800 Subject: [PATCH 011/124] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=88=AA=E6=AD=A2?= =?UTF-8?q?=E6=97=B6=E8=AE=A1=E7=AE=97=E6=95=88=E7=8E=87=E5=88=86=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 32 +++++++++++++++++++ lib/tasks/homework_publishtime.rake | 6 ++-- .../homework_end_update_score_job_spec.rb | 5 +++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/jobs/homework_end_update_score_job.rb create mode 100644 spec/jobs/homework_end_update_score_job_spec.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2d52b6aa0..9bbc374a1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1117,7 +1117,7 @@ class HomeworkCommonsController < ApplicationController =end # 更新所有学生的效率分(重新取homework确保是更新后的) - HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: homework.id) if !homework.allow_late && homework.end_time <= time + HomeworkEndUpdateScoreJob.perform_later(homework.id) if !homework.allow_late && homework.end_time <= time end end homework.save! diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb new file mode 100644 index 000000000..ea6d3e5e3 --- /dev/null +++ b/app/jobs/homework_end_update_score_job.rb @@ -0,0 +1,32 @@ +class HomeworkEndUpdateScoreJob < ApplicationJob + # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 + queue_as :score + + def perform(*args) + homework = HomeworkCommon.find_by(id: homework_id) + return if homework.blank? + course = homework.course + return if course.blank? + + if homework.unified_setting + student_works = homework.student_works + user_ids = course.students.pluck(:user_id) + else + user_ids = course.students.where(course_group_id: homework.published_settings.pluck(:course_group_id)).pluck(:user_id) + student_works = homework.student_works.where(user_id: user_ids) + end + + myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)}) + challenge_settings = homework.homework_challenge_settings + myshixuns.find_each(batch_size: 100) do |myshixun| + work = student_works.select{|work| work.user_id == myshixun.user_id}.first + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) + HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings + end + end + HomeworksService.new.update_student_eff_score homework + homework.update_attribute('calculation_time', Time.now) + end +end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 4127a9339..918e70a70 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -84,7 +84,8 @@ namespace :homework_publishtime do student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present? else - HomeworksService.new.update_student_eff_score homework + HomeworkEndUpdateScoreJob.perform_later(homework.id) + # HomeworksService.new.update_student_eff_score homework end =begin @@ -206,7 +207,8 @@ namespace :homework_publishtime do homework_commons = HomeworkCommon.joins(:homework_detail_manual).where("homework_type = 4 and allow_late = 1 and late_time <= ? and late_time > ? and homework_detail_manuals.comment_status != 6", Time.now, Time.now - 900) homework_commons.each do |homework| - HomeworksService.new.update_student_eff_score homework + # HomeworksService.new.update_student_eff_score homework + HomeworkEndUpdateScoreJob.perform_later(homework.id) =begin homework_detail_manual = homework.homework_detail_manual diff --git a/spec/jobs/homework_end_update_score_job_spec.rb b/spec/jobs/homework_end_update_score_job_spec.rb new file mode 100644 index 000000000..492b35d43 --- /dev/null +++ b/spec/jobs/homework_end_update_score_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEndUpdateScoreJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From d38053e0f45f01db3941df89f1f3ca77aadde143 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 15:23:18 +0800 Subject: [PATCH 012/124] =?UTF-8?q?=E5=B7=B2=E5=8F=91=E5=B8=83=E7=9A=84?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BC=96=E8=BE=91=E5=90=8E=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 11 ++++++----- app/controllers/graduation_tasks_controller.rb | 4 ++-- app/controllers/homework_commons_controller.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b231d6af7..77cc108b3 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -350,8 +350,9 @@ class ExerciseQuestionsController < ApplicationController @exercise_question.shixun_name = shixun_name end - #当标准答案修改时,如有已提交的学生,需重新计算分数 - if st_count > 0 + #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. + + if @exercise.exercise_status == 2 ex_users_committed = @exercise.exercise_users.exercise_user_committed if ex_users_committed.size > 0 ex_users_committed.each do |ex_user| @@ -587,15 +588,15 @@ class ExerciseQuestionsController < ApplicationController if @exercise_question.present? @exercise = @exercise_question.exercise if @exercise.blank? - tip_exception(404) + tip_exception(404,"试卷不存在") else @course = @exercise.course if @course.blank? - tip_exception(404) + tip_exception(404,"课堂不存在") end end else - tip_exception(404) + tip_exception(404,"试卷问题不存在") end end diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index a89a81798..545b10e11 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无用户提交!") + normal_status(-1,"暂无用户提交") else respond_to do |format| format.xlsx{ @@ -164,7 +164,7 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @all_work_count = @work_list.count if params[:format] == "xlsx" || params[:format] == "zip" - normal_status(-1,"作业未发布") + normal_status(-1,"毕设任务未发布") end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index fe2adba45..e595c703e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,7 +106,7 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - if @homework.publish_time.nil? || @homework.publish_time > Time.now + if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if params[:format] == "xlsx" || params[:format] == "zip" normal_status(-1,"作业未发布") From b286e432ffb4655196558811a46458d59be274ad Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 15:43:17 +0800 Subject: [PATCH 013/124] =?UTF-8?q?sidekiq=E6=9C=AC=E5=9C=B0=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 7 +++++++ config/routes.rb | 3 +++ 3 files changed, 11 insertions(+) diff --git a/Gemfile b/Gemfile index b8b174a6f..0473e221e 100644 --- a/Gemfile +++ b/Gemfile @@ -84,6 +84,7 @@ gem 'rails-i18n', '~> 5.1' # job gem 'sidekiq' +gem 'sinatra' # batch insert gem 'bulk_insert' diff --git a/Gemfile.lock b/Gemfile.lock index 86f524bc2..728bbc672 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,6 +142,7 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) + mustermann (1.0.3) mysql2 (0.5.2) nio4r (2.3.1) nokogiri (1.8.4) @@ -265,6 +266,11 @@ GEM simple_xlsx_reader (1.0.4) nokogiri rubyzip + sinatra (2.0.5) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.5) + tilt (~> 2.0) spreadsheet (1.2.3) ruby-ole (>= 1.0) spring (2.0.2) @@ -341,6 +347,7 @@ DEPENDENCIES selenium-webdriver sidekiq simple_xlsx_reader + sinatra spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..01e301c3c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do + require 'sidekiq/web' + mount Sidekiq::Web => '/sidekiq' + resources :edu_settings scope '/api' do get 'home/index' From 841bd09f236c9be5807774c7f4d328bd6cf6aaa3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 15:55:50 +0800 Subject: [PATCH 014/124] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E8=AE=BF=E9=97=AE=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/subjects_controller.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 9c3847b3c..e558e657c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -18,7 +18,7 @@ class MyshixunsController < ApplicationController # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game - unless (current_user.admin? || current_user.id == @myshixun.user_id) + unless current_user.admin? tip_exception("403", "") end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index c73fec500..bb7059af6 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -81,6 +81,9 @@ class SubjectsController < ApplicationController @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq # 用户获取的实训标签 @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + + # 访问数变更 + @subject.increment!(:visits) end def create From 748f4dc5779690ee82d46f055111e065fc597c0b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 16:04:52 +0800 Subject: [PATCH 015/124] fix users subject repeat bug --- app/services/users/subject_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb index 7e3eaaa81..745b7cce2 100644 --- a/app/services/users/subject_service.rb +++ b/app/services/users/subject_service.rb @@ -14,7 +14,7 @@ class Users::SubjectService subjects = category_scope_subjects subjects = user_policy_filter(subjects) - custom_sort(subjects, :updated_at, params[:sort_direction]) + custom_sort(subjects.distinct, :updated_at, params[:sort_direction]) end private From b21966c3572d62849d5bd7e179ecb54fb087a81a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:05:45 +0800 Subject: [PATCH 016/124] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=A4=9A=E7=A9=BA?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 5 ---- ...611_add_old_exercise_tiankong_choice_id.rb | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 77cc108b3..deb9b3157 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -223,7 +223,6 @@ class ExerciseQuestionsController < ApplicationController end end #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 - st_count = 0 @exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案 if standard_answer.present? if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个 @@ -232,7 +231,6 @@ class ExerciseQuestionsController < ApplicationController old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建 if old_left_standard_choices.count > 0 - st_count += 1 @exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all end if new_left_standard_choices.count > 0 #新建标准答案 @@ -258,7 +256,6 @@ class ExerciseQuestionsController < ApplicationController #删除多余的选项 if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空 - st_count += 1 delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all end @@ -284,7 +281,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[n-1].update(standard_option) end if new_add_choice.count > 0 #表示有新增的 - st_count += 1 new_add_choice.each do |i| standard_option = { :exercise_question_id => @exercise_question.id, @@ -306,7 +302,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[index].update(standard_option) end if new_delete_choice.count > 0 #表示填空题的答案有删减的 - st_count += 1 new_delete_choice.each do |d| ex_answer_pre[d-1].destroy end diff --git a/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb new file mode 100644 index 000000000..9ad1429e2 --- /dev/null +++ b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb @@ -0,0 +1,23 @@ +class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2] + + def up + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1) + end + + def down + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil) + end + +end From 0d254b0da4c2701e3efc0a8b5184e4e8e0b6434a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 16:16:24 +0800 Subject: [PATCH 017/124] score fix --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4cd9209f3..57ae1023b 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -250,7 +250,7 @@ class HomeworkCommonsController < ApplicationController challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end @@ -271,7 +271,7 @@ class HomeworkCommonsController < ApplicationController myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) ActiveRecord::Base.transaction do begin - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) challenge_settings = @homework.homework_challenge_settings games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings From 0fb454cca58cdbce989441cc7bef237d0623036a Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 3 Jul 2019 16:18:45 +0800 Subject: [PATCH 018/124] ADD files bulk publish --- app/controllers/files_controller.rb | 8 +++++++- config/routes.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 2af178e47..05a9ab841 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -3,7 +3,7 @@ class FilesController < ApplicationController before_action :require_login, except: %i[index] before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] - before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public] + before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish] before_action :file_validate_sort_type, only: :index before_action :validate_send_message_to_course_params, only: :bulk_send before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] @@ -40,6 +40,12 @@ class FilesController < ApplicationController @attachments = @attachments.page(@page).per(@page_size) end + def bulk_publish + return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5 + @course.attachments.by_ids(@attachment_ids).unpublish.update_all(is_publish: 1, publish_time: Time.now) + render_ok + end + def bulk_delete ActiveRecord::Base.transaction do begin diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..f47b704b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -253,6 +253,7 @@ Rails.application.routes.draw do get :mine_with_course_and_project post :import post :upload + put :bulk_publish end member do get :histories From bed09475eda5361252cd32c0a4acceb2318a024a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:35:06 +0800 Subject: [PATCH 019/124] fix bug --- .../exercise_questions_controller.rb | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index deb9b3157..b852e9437 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,17 +347,28 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - if @exercise.exercise_status == 2 - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) - end + # if @exercise.exercise_status == 2 + # ex_users_committed = @exercise.exercise_users.exercise_user_committed + # if ex_users_committed.size > 0 + # ex_users_committed.each do |ex_user| + # user = ex_user.user + # objective_score = calculate_student_score(@exercise,user)[:total_score] + # subjective_score = ex_user.subjective_score + # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + # total_score = objective_score + total_score_subjective_score + # ex_user.update_attributes(objective_score:objective_score,score:total_score) + # end + # end + # end + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) end end From 50ea41ac7ff492eaba5f6d638b37a5f2007b8827 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 16:40:57 +0800 Subject: [PATCH 020/124] git email test --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 9c3847b3c..89d76c16c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -275,7 +275,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: author_email) + author_email: "53246666@qq.com") end end From 75aa92026fa3d563134ca3c695039ddcccfb7aaf Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 16:55:08 +0800 Subject: [PATCH 021/124] add author email for git --- app/controllers/myshixuns_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 87823ce21..3dfb739d0 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -15,7 +15,6 @@ class MyshixunsController < ApplicationController # For Admin # 强制重置实训 - # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game unless current_user.admin? @@ -275,7 +274,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: "53246666@qq.com") + author_email: author_email) end end From 9ee6fee20ad7640d8721431e6e65c5f77046264c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:58:42 +0800 Subject: [PATCH 022/124] fix bug --- .../exercise_questions_controller.rb | 40 ++++++------------- app/helpers/exercises_helper.rb | 9 +++++ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b852e9437..e33e5e2dc 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,36 +347,20 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - # if @exercise.exercise_status == 2 - # ex_users_committed = @exercise.exercise_users.exercise_user_committed - # if ex_users_committed.size > 0 - # ex_users_committed.each do |ex_user| - # user = ex_user.user - # objective_score = calculate_student_score(@exercise,user)[:total_score] - # subjective_score = ex_user.subjective_score - # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - # total_score = objective_score + total_score_subjective_score - # ex_user.update_attributes(objective_score:objective_score,score:total_score) - # end - # end - # end - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) + if @exercise.exercise_status == 2 + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) + end end end - - if @exercise_question.save - normal_status(0,"试卷更新成功!") - else - normal_status(-1,"试卷更新失败!") - end + normal_status(0,"试卷更新成功!") rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 437965ca6..55ade6e7c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -382,6 +382,9 @@ module ExercisesHelper end answers_content.update_all(:score => q_score_1) score1 = score1 + q.question_score + else + answers_content.update_all(:score => -1.0) + score1 += 0.0 end else score1 += 0.0 @@ -403,6 +406,9 @@ module ExercisesHelper if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score2 = score2 + q_score_2 + else + u.update_column('score',-1.0) + score2 += 0.0 end end else @@ -413,6 +419,9 @@ module ExercisesHelper u.update_column("score",q_score_2) score2 = score2 + q_score_2 st_answer_text.delete(u_answer_text) + else + u.update_column('score',-1.0) + score2 += 0.0 end end end From 2c472f44a9a6e8245fd0d7899a2b70d5f056c7b3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:10:03 +0800 Subject: [PATCH 023/124] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4474d47c8..2fcf421f4 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,11 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size + logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if params[:format] == "xlsx" || params[:format] == "zip" + logger.info("##########__________params[:format]______________#############{params[:format]}") normal_status(-1,"作业未发布") end else From 41f01f49614a1885ffe373e7eaeb7033fb4a3a58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:21:21 +0800 Subject: [PATCH 024/124] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + db/migrate/20190703090511_add_index_for_shixun_services.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20190703090511_add_index_for_shixun_services.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5a1773a10..2c4f2a7d1 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -180,6 +180,7 @@ class ShixunsController < ApplicationController end # 同步配置 + logger.info("########-shixun_service_configs_count: #{@shixun.shixun_service_configs.pluck(:id, :shixun_id)}") @shixun.shixun_service_configs.each do |config| ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, :cpu_limit => config.cpu_limit, diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb new file mode 100644 index 000000000..3e6dd3703 --- /dev/null +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -0,0 +1,5 @@ +class AddIndexForShixunServices < ActiveRecord::Migration[5.2] + def change + add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" + end +end From c61cb1190f683a237058ce3babdcfbc26adf3460 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:32:04 +0800 Subject: [PATCH 025/124] fixbug --- app/controllers/homework_commons_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2fcf421f4..018218799 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,11 +106,9 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] - if params[:format] == "xlsx" || params[:format] == "zip" - logger.info("##########__________params[:format]______________#############{params[:format]}") + if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") end else @@ -198,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.where("work_status > 0").size + complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -218,8 +216,13 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) + if @work_excel.exist? + zip_works = @work_excel&.where("work_status > 0") + status = checkfileSize(zip_works) + else + status = -1 + end + if status == 0 respond_to do |format| format.zip{ From 1a96c3841df7faadd0c0cfb6076c8cbf67b94939 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 17:33:59 +0800 Subject: [PATCH 026/124] =?UTF-8?q?job=E4=BB=BB=E5=8A=A1=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/exercise_publish_notify_job.rb | 1 + app/jobs/graduation_task_publish_notify_job.rb | 4 +++- app/jobs/submit_graduation_work_notify_job.rb | 5 +++-- app/jobs/submit_student_work_notify_job.rb | 5 +++-- app/models/course_member.rb | 8 ++++---- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index 563f6ceb0..f68a68c00 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -6,6 +6,7 @@ class ExercisePublishNotifyJob < ApplicationJob exercise = Exercise.find_by(id: exercise_id) return if exercise.blank? user = exercise.user + course = exercise.course if group_ids.present? students = course.students.where(course_group_id: group_ids) diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 92346ab27..16f5893ae 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -5,6 +5,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) return if task.blank? + course = task.course + return if course.blank? attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type @@ -18,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - task.course.course_members.pluck(:user_id).uniq.find_each do |user_id| + course.course_members.pluck(:user_id).uniq.find_each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/submit_graduation_work_notify_job.rb b/app/jobs/submit_graduation_work_notify_job.rb index 17cfc21d2..d4bb21cc4 100644 --- a/app/jobs/submit_graduation_work_notify_job.rb +++ b/app/jobs/submit_graduation_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitGraduationWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = task.graduation_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/jobs/submit_student_work_notify_job.rb b/app/jobs/submit_student_work_notify_job.rb index acb7873ac..c4dff264c 100644 --- a/app/jobs/submit_student_work_notify_job.rb +++ b/app/jobs/submit_student_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitStudentWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = homework.student_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index d9995d463..7db681e67 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -146,11 +146,11 @@ class CourseMember < ApplicationRecord def member_teachers teacher_groups = course.teacher_course_groups if teacher_groups.count > 0 - member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id) + member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact - none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).join(',') : -1 - teachers = course.teachers.where("members.id not in (#{none_group_teachers}) or - members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") + none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 + teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or + course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") else teachers = course.teachers end From 69ed83fae1a2473223189a4972a90e7e81c8afd2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:34:02 +0800 Subject: [PATCH 027/124] fix bug --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 018218799..66dd7c864 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -196,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 + complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -216,7 +216,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.exist? + if @work_excel.present? zip_works = @work_excel&.where("work_status > 0") status = checkfileSize(zip_works) else From 441dcf54e77bfe632dcd501863857d37cc8b5d87 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:39:12 +0800 Subject: [PATCH 028/124] fix bug --- app/controllers/homework_commons_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 66dd7c864..229db7278 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,15 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - if @homework.publish_time.blank? || (@homework.publish_time > Time.now) + logger.info("@@@@@@@_____________@homework.publish_time______________##{@homework.publish_time}") + logger.info("@@@@@@@_____________@homework.publish_time > Time.now______________##{@homework.publish_time > Time.now}") + + if @homework.publish_time.nil? || (@homework.publish_time > Time.now) + logger.info("@@@@@@@_____________1111111111_____________#11111111111") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") + logger.info("@@@@@@@_____________22222222_____________#2222222221") + normal_status(-1,"作业未发布") end else From 0e68cc0e4ccbc1c4ca24726f478859e2c3453058 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:49:37 +0800 Subject: [PATCH 029/124] fix bug --- app/controllers/homework_commons_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 229db7278..d49dac853 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,15 +106,10 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("@@@@@@@_____________@homework.publish_time______________##{@homework.publish_time}") - logger.info("@@@@@@@_____________@homework.publish_time > Time.now______________##{@homework.publish_time > Time.now}") if @homework.publish_time.nil? || (@homework.publish_time > Time.now) - logger.info("@@@@@@@_____________1111111111_____________#11111111111") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") - logger.info("@@@@@@@_____________22222222_____________#2222222221") - normal_status(-1,"作业未发布") end else From ab9b9b2fa0fe8a1b10a911c914bff24aa0744b58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:52:16 +0800 Subject: [PATCH 030/124] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190703090511_add_index_for_shixun_services.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb index 3e6dd3703..693add3e3 100644 --- a/db/migrate/20190703090511_add_index_for_shixun_services.rb +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -1,5 +1,9 @@ class AddIndexForShixunServices < ActiveRecord::Migration[5.2] def change + sql = %Q(delete from shixun_service_configs where (shixun_id, mirror_repository_id) in + (select * from (select shixun_id, mirror_repository_id from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1) a) + and id not in (select * from (select min(id) from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" end end From ce381b24d660a481fc16054d2f7d454234cea248 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:05:18 +0800 Subject: [PATCH 031/124] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D/n=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 1b3349467..d28a42eb6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -407,7 +407,7 @@ class User < ApplicationRecord name = lastname + firstname name.blank? ? (nickname.blank? ? login : nickname) : name - name.gsub(/\s+/, '').strip #6.11 -hs + name.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs end # 用户是否选题毕设课题 From 99d2c9478c2745262de93f99f9553f7982962ee9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:06:25 +0800 Subject: [PATCH 032/124] fixbug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d49dac853..0ab3a6381 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -107,6 +107,8 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size + logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") + if @homework.publish_time.nil? || (@homework.publish_time > Time.now) @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") From fa4e184a032b8fa4fcb3f68d8919451bc3c2ab63 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:11:08 +0800 Subject: [PATCH 033/124] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 0ab3a6381..9780b4eec 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -109,7 +109,7 @@ class HomeworkCommonsController < ApplicationController logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") - if @homework.publish_time.nil? || (@homework.publish_time > Time.now) + if @homework.publish_time.present? || (@homework.publish_time > Time.now) @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") From d957d57b4b01de4d0574dc7063098633e88c2168 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:11:11 +0800 Subject: [PATCH 034/124] add log --- app/models/user.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index d28a42eb6..ca8913526 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -406,8 +406,10 @@ class User < ApplicationRecord return '游客' unless logged? name = lastname + firstname - name.blank? ? (nickname.blank? ? login : nickname) : name - name.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs + username = name.blank? ? (nickname.blank? ? login : nickname) : name + Rail.logger.info("3333333332222222#{username}") + username.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs + end # 用户是否选题毕设课题 From 938190ef9bb549e17eb20f7fde933437493c65ad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:13:18 +0800 Subject: [PATCH 035/124] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9780b4eec..9b77f8dc7 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -109,7 +109,7 @@ class HomeworkCommonsController < ApplicationController logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") - if @homework.publish_time.present? || (@homework.publish_time > Time.now) + if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") From 6516908a5867fb84ed768135a723cca976f78e7c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:15:36 +0800 Subject: [PATCH 036/124] real name --- app/models/user.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ca8913526..20b60dfcb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -404,12 +404,9 @@ class User < ApplicationRecord # 用户的真实姓名(不考虑用户是否隐藏了真实姓名,课堂模块都用真实姓名) def real_name return '游客' unless logged? - name = lastname + firstname - username = name.blank? ? (nickname.blank? ? login : nickname) : name - Rail.logger.info("3333333332222222#{username}") - username.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs - + name.blank? ? (nickname.blank? ? login : nickname) : name + gsub(/\s+/, '').strip #6.11 -hs end # 用户是否选题毕设课题 From e071aeb556a0dd1bb643ea23ebc25db667e6c1b9 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:17:44 +0800 Subject: [PATCH 037/124] .. --- app/controllers/myshixuns_controller.rb | 1 + app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3dfb739d0..fd75b7062 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -269,6 +269,7 @@ class MyshixunsController < ApplicationController author_name = current_user.full_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" + uid_logger("") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message, diff --git a/app/models/user.rb b/app/models/user.rb index 20b60dfcb..e775af5f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -406,7 +406,7 @@ class User < ApplicationRecord return '游客' unless logged? name = lastname + firstname name.blank? ? (nickname.blank? ? login : nickname) : name - gsub(/\s+/, '').strip #6.11 -hs + name.gsub(/\s+/, '').strip #6.11 -hs end # 用户是否选题毕设课题 From ae1046632083dc4601738a210c525f1524ff95f3 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:19:15 +0800 Subject: [PATCH 038/124] =?UTF-8?q?=E6=B7=BB=E5=8A=A0git=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index fd75b7062..2131eed9a 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -269,7 +269,8 @@ class MyshixunsController < ApplicationController author_name = current_user.full_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" - uid_logger("") + uid_logger("112233#{author_name}") + uid_logger("112233#{author_email}") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message, From d2f1a7a06b690ad30996ae74b7254c8234a20da9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:22:00 +0800 Subject: [PATCH 039/124] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9b77f8dc7..5842d2522 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -108,8 +108,10 @@ class HomeworkCommonsController < ApplicationController @all_member_count = student_works.size logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") + logger.info("-----------------------------------------------------") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) + logger.info("+++++++++++++++++#{@homework.publish_time}") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") From 3fecc15aa7fc8c76cf3c708dc9bcb8a06d6dba65 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:24:10 +0800 Subject: [PATCH 040/124] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5842d2522..b25782026 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -114,6 +114,8 @@ class HomeworkCommonsController < ApplicationController logger.info("+++++++++++++++++#{@homework.publish_time}") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") + logger.info("++++++params[:format]params[:format]params[:format]params[:format]+++++++++++#{params[:format]}") + normal_status(-1,"作业未发布") end else From cab3b87de3d311687998f9202c1a6899164dc1d8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:27:33 +0800 Subject: [PATCH 041/124] =?UTF-8?q?git=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E6=88=90=E5=8A=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 2131eed9a..3abc71fd0 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -266,7 +266,7 @@ class MyshixunsController < ApplicationController if content != last_content @content_modified = 1 - author_name = current_user.full_name + author_name = current_user.real_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" uid_logger("112233#{author_name}") From 233965ddca435fb4d350ca135038ac67925f4080 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 08:58:01 +0800 Subject: [PATCH 042/124] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 +++++++- app/views/challenges/index.json.jbuilder | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 2c4f2a7d1..4afba7a7b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -522,7 +522,13 @@ class ShixunsController < ApplicationController end # 如果存在实训,则直接进入实训 - @current_task = current_myshixun.current_task(games) + # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 + @current_task = + if params[:challenge_id] && @shixun.task_pass + current_myshixun.games.where(challenge_id: params[:challenge_id]).take + else + current_myshixun.current_task(games) + end else # 如果未创建关卡一定不能开启实训,否则TPI没法找到当前的关卡 if @shixun.challenges_count == 0 diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 6b92be411..37ce94305 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,7 +17,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.open_game challenge.open_game(@user.id, @shixun) + #json.open_game challenge.open_game(@user.id, @shixun) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From 5cdc8bb687ff3d7ad25b04b71e2a51138c4c8ae2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 09:00:28 +0800 Subject: [PATCH 043/124] =?UTF-8?q?xlsx=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 ------ app/views/polls/commit_result.xlsx.axlsx | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b25782026..519c05c62 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -107,15 +107,9 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") - logger.info("-----------------------------------------------------") - if @homework.publish_time.blank? || (@homework.publish_time > Time.now) - logger.info("+++++++++++++++++#{@homework.publish_time}") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") - logger.info("++++++params[:format]params[:format]params[:format]params[:format]+++++++++++#{params[:format]}") - normal_status(-1,"作业未发布") end else diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 6ce00388c..aa7943d2a 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -49,7 +49,7 @@ wb.styles do |s| end #each_with_index sheet.add_row poll_users_info, :height =>15, :style => blue_cell - poll_users.each_with_index do |u,index| + poll_users.includes(user: :user_extension).each_with_index do |u,index| u_user = u.user user_answer_array = [] poll_questions.each do |q| From 2d6ed002d542530741e8bc206287dbc5e7dc1b06 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 09:21:47 +0800 Subject: [PATCH 044/124] =?UTF-8?q?=E8=B0=83=E6=95=B4job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/exercise_publish_notify_job.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index f68a68c00..9c43b1978 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -31,7 +31,7 @@ class ExercisePublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids) - teacher_ids.find_each do |user_id| + teacher_ids.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index ea6d3e5e3..e141fd758 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -2,7 +2,7 @@ class HomeworkEndUpdateScoreJob < ApplicationJob # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 queue_as :score - def perform(*args) + def perform(homework_id) homework = HomeworkCommon.find_by(id: homework_id) return if homework.blank? course = homework.course From 21c8e0eae856a916ec18c11eab516b27fc95e101 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 09:22:01 +0800 Subject: [PATCH 045/124] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=85=B3=E5=8D=A1?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 4afba7a7b..1c6476a34 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -525,7 +525,7 @@ class ShixunsController < ApplicationController # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 @current_task = if params[:challenge_id] && @shixun.task_pass - current_myshixun.games.where(challenge_id: params[:challenge_id]).take + games.where(challenge_id: params[:challenge_id]).take else current_myshixun.current_task(games) end From 2b745db4b4340f52c601cfe35ed41ac9b0cd1bf3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 09:26:02 +0800 Subject: [PATCH 046/124] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/homework_end_update_score_job.rb | 3 ++- app/jobs/poll_publish_notify_job.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index e141fd758..649a5c37a 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -16,7 +16,8 @@ class HomeworkEndUpdateScoreJob < ApplicationJob student_works = homework.student_works.where(user_id: user_ids) end - myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + shixun_id = homework.homework_commons_shixun.try(:shixun_id) + myshixuns = Myshixun.where(shixun_id: shixun_id, user_id: user_ids). includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)}) challenge_settings = homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index 89fb45ea5..52660abd1 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -31,7 +31,7 @@ class PollPublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) - teacher_ids.find_each do |user_id| + teacher_ids.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end From 9fb26f8ff5627a9096272fa8f91ea19266d11e3a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 09:50:10 +0800 Subject: [PATCH 047/124] poll export test --- app/controllers/polls_controller.rb | 2 +- app/helpers/polls_helper.rb | 13 +++++++++++++ app/views/polls/commit_result.xlsx.axlsx | 11 +++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 244cdf57f..0dfa4b1b8 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -920,7 +920,7 @@ class PollsController < ApplicationController def commit_result ActiveRecord::Base.transaction do begin - @poll_users = @poll.poll_users + @poll_users = @poll.all_poll_users(current_user.id) @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @limit = params[:limit] || 10 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index d9b6ccee7..1892f3fa2 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -127,4 +127,17 @@ module PollsHelper "login":user.login } end + + def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) + poll_users_info = %w(序号) + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + poll_un_anony = poll.un_anonymous + if poll_un_anony #是否匿名,默认为false + user_info = %w(登陆名 真实姓名 邮箱 学号) + else + user_info = [] + end + poll_users_info = poll_users_info + user_info + poll_ques_titles + + end end diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index aa7943d2a..71585dae9 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -8,7 +8,10 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false poll_users_info = %w(序号) + Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}") + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}") poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) @@ -18,13 +21,13 @@ wb.styles do |s| poll_users_info = poll_users_info + user_info + poll_ques_titles poll_questions.each do |q| 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).size #该问题的有效填写量 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_percent = ["比例"] sheet_answer_useful = ["有效填写人次",question_vote_user] 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).size 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_answer_row.push(answer_users_count) @@ -41,8 +44,8 @@ wb.styles do |s| else #主观题答案 main_show_row = ["第#{q.question_number}题",q.question_title] sheet.add_row main_show_row,:height =>15, :style => blue_cell - q.poll_votes.each do |v| #主观题的答案 - sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all + q.poll_votes.each_with_index do |v,index| #主观题的答案 + sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all end sheet.add_row [], :style => sz_all end From b84954dbd21c02b8b7c21c2a6fa1e905061800fb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 10:06:51 +0800 Subject: [PATCH 048/124] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/_student_btn_check.json.jbuilder | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/homework_commons/_student_btn_check.json.jbuilder b/app/views/homework_commons/_student_btn_check.json.jbuilder index efa89203d..7b34622fa 100644 --- a/app/views/homework_commons/_student_btn_check.json.jbuilder +++ b/app/views/homework_commons/_student_btn_check.json.jbuilder @@ -1,6 +1,8 @@ if identity == Course::STUDENT if homework.homework_type == "practice" - json.task_operation task_operation_url(work.try(:myshixun), homework.shixuns.take) + shixun = homework.shixuns.take + myshixun = work.try(:myshixun) ? work.myshixun : shixun.myshixuns.find_by(user_id: work.user_id) + json.task_operation task_operation_url(myshixun, shixun) json.view_report work.work_status > 0 json.commit_des commit_des_status(work, homework) else From 6932dc7127a7c946e1e0e044b4247bd2adce1d13 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 10:12:31 +0800 Subject: [PATCH 049/124] =?UTF-8?q?=20=E5=85=81=E8=AE=B8=E8=B7=B3=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 9 +++++++-- app/models/challenge.rb | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 1c6476a34..0a7a4fece 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -524,8 +524,13 @@ class ShixunsController < ApplicationController # 如果存在实训,则直接进入实训 # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 @current_task = - if params[:challenge_id] && @shixun.task_pass - games.where(challenge_id: params[:challenge_id]).take + if params[:challenge_id] + game = games.where(challenge_id: params[:challenge_id]).take + if game.status == 3 && !@shixun.task_pass + tip_show_exception(-4, "关卡还未开启") + else + game + end else current_myshixun.current_task(games) end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e7a382a51..ac031c31c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -76,8 +76,9 @@ class Challenge < ApplicationRecord ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = games.last - + # 允许跳关则直接开启 + return 1 if shixun.task_pass + game = games.where(user_id: user_id).take if game.blank? self.position == 1 ? 1 : 0 elsif game.status == 2 From 0cd20c6b62728728678b0c77a1c49704bd7be1b2 Mon Sep 17 00:00:00 2001 From: jasder Date: Thu, 4 Jul 2019 10:13:53 +0800 Subject: [PATCH 050/124] FIX update files publish count --- app/controllers/files_controller.rb | 4 ++-- app/views/files/index.json.jbuilder | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 05a9ab841..b75020643 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,8 +23,8 @@ class FilesController < ApplicationController get_category(@course, course_second_category_id) @total_count = @attachments.size - @public_count = @attachments.publiced.size - @private_count = @total_count - @public_count + @publish_count = @attachments.published.size + @unpublish_count = @total_count - @publish_count @attachments = @attachments.by_keywords(params[:search]) @attachments = diff --git a/app/views/files/index.json.jbuilder b/app/views/files/index.json.jbuilder index 03b4d4892..81fa406dd 100644 --- a/app/views/files/index.json.jbuilder +++ b/app/views/files/index.json.jbuilder @@ -3,8 +3,8 @@ json.data do json.id @category_id json.name @category_name json.total_count @total_count - json.public_count @public_count - json.private_count @private_count + json.publish_count @publish_count + json.unpublish_count @unpublish_count json.course_is_public @course.is_public? json.files do json.array! @attachments do |attachment| From e868f9eba134b6fcfe1eff73d2a8d0ac84db7c8b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 10:24:18 +0800 Subject: [PATCH 051/124] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=B7=B3=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0a7a4fece..b3b3023a8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -526,10 +526,10 @@ class ShixunsController < ApplicationController @current_task = if params[:challenge_id] game = games.where(challenge_id: params[:challenge_id]).take - if game.status == 3 && !@shixun.task_pass - tip_show_exception(-4, "关卡还未开启") - else + if @shixun.task_pass || game.status != 3 game + else + current_myshixun.current_task(games) end else current_myshixun.current_task(games) From 394efe9bf58504b5defb2c6b964fc025dd325cb9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 10:31:07 +0800 Subject: [PATCH 052/124] =?UTF-8?q?=E6=8C=91=E6=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3abc71fd0..f0e64bc67 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -17,7 +17,7 @@ class MyshixunsController < ApplicationController # 强制重置实训 # 前段需要按照操作过程提示 def reset_my_game - unless current_user.admin? + unless (current_user.admin? || current_user.id == @myshixun.user_id) tip_exception("403", "") end From 82a3a5aecd1fea4edc19cef9bcd6df2d1844b53c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 10:59:40 +0800 Subject: [PATCH 053/124] =?UTF-8?q?job=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/graduation_task_publish_notify_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 16f5893ae..84049fe90 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -20,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - course.course_members.pluck(:user_id).uniq.find_each do |user_id| + course.course_members.pluck(:user_id).uniq.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end From 1679cfc6b5030663a0340adf2981ce026da9031c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 11:12:41 +0800 Subject: [PATCH 054/124] =?UTF-8?q?=E6=92=A4=E9=94=80=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b3b3023a8..ae75a9a0a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -742,8 +742,8 @@ class ShixunsController < ApplicationController if apply && apply.status == 0 apply.update_attribute(:status, 3) apply.tidings.destroy_all - @shixun.update_column('status', 0) end + @shixun.update_column('status', 0) end private From 82c0318861cbcc40efda9b6abb0c797101a63b87 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 11:14:29 +0800 Subject: [PATCH 055/124] =?UTF-8?q?=E6=92=A4=E9=94=80=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index ae75a9a0a..b8a5ec53c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -743,7 +743,7 @@ class ShixunsController < ApplicationController apply.update_attribute(:status, 3) apply.tidings.destroy_all end - @shixun.update_column('status', 0) + @shixun.update_column(:status, 0) end private From 977a966706f1c32c0db263f0a632cecc03d85f70 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 11:38:18 +0800 Subject: [PATCH 056/124] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/models/challenge.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 7e7b6e082..56c1d9347 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -454,7 +454,7 @@ class GamesController < ApplicationController begin @content = git_fle_content(@myshixun.repo_path, path) || "" rescue - if params[:retry].present? + if params[:retry].to_i == 1 begin begin # 检测TPM对应的路径代码是否正常 diff --git a/app/models/challenge.rb b/app/models/challenge.rb index ac031c31c..6dd93dcc0 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -77,14 +77,17 @@ class Challenge < ApplicationRecord def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 - return 1 if shixun.task_pass game = games.where(user_id: user_id).take if game.blank? self.position == 1 ? 1 : 0 elsif game.status == 2 2 else - 1 + if shixun.task_pass + 1 + else + 0 + end end end From 5321c98037f184bda9672f71b161d054f54f7c04 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 11:38:34 +0800 Subject: [PATCH 057/124] poll export youhua --- app/controllers/polls_controller.rb | 123 +++++++++++++-- app/helpers/polls_helper.rb | 12 -- app/views/polls/commit_result.xlsx.axlsx | 191 ++++++++++++++--------- 3 files changed, 228 insertions(+), 98 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 0dfa4b1b8..1a6981d9f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -924,7 +924,8 @@ class PollsController < ApplicationController @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @limit = params[:limit] || 10 - @poll_export_questions = @poll_questions.order("question_number ASC") + @poll_export_questions = @poll_questions + logger.info("################____________________#{@poll_questions.pluck(:id)}") @poll_questions = @poll_questions.page(@page).per(@limit) if params[:format] == "xlsx" @@ -936,11 +937,14 @@ class PollsController < ApplicationController respond_to do |format| 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} + polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) + render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} + + # 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 @@ -1153,11 +1157,12 @@ class PollsController < ApplicationController end def get_questions_count - @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") + @poll_questions = @poll.poll_questions.order("question_number ASC") @poll_questions_count = @poll_questions.size # 全部的题目数 - @poll_question_singles = @poll_questions.ques_count(1).all.size # 单选题 - @poll_question_doubles = @poll_questions.ques_count(2).all.size # 多选题 - @poll_question_mains = @poll_questions.ques_count(3).all.size #主观题 + @poll_question_singles = @poll_questions.ques_count(1).size # 单选题 + @poll_question_doubles = @poll_questions.ques_count(2).size # 多选题 + @poll_question_mains = @poll_questions.ques_count(3).size #主观题 + @poll_questions = @poll_questions&.includes(:poll_answers,:poll_votes).distinct end def check_poll_question_complete #commit_poll 的权限 @@ -1301,4 +1306,102 @@ class PollsController < ApplicationController end end + #问卷的统计结果的导出 + def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) + obj_commit = [] + sub_commit = [] + user_commit = [] + poll_users_info = %w(序号) + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| k.strip if k.present?} + poll_un_anony = poll.un_anonymous + if poll_un_anony #是否匿名,默认为false + user_info = %w(登陆名 真实姓名 邮箱 学号) + else + user_info = [] + end + poll_users_info = poll_users_info + user_info + poll_ques_titles + poll_questions.each do |q| + if q.question_type != 3 #问题不为主观题 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 + sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 + sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 + sheet_answer_percent = ["比例"] + sheet_answer_useful = ["有效填写人次",question_vote_user] + q.poll_answers.each do |a| #问卷的答案选项 + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size + answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%" + sheet_row.push(a.answer_text) + sheet_answer_row.push(answer_users_count) + sheet_answer_percent.push(answer_percent) + end + sheet_obj_commit = { + sheet_row:sheet_row, + sheet_answer_row:sheet_answer_row, + sheet_answer_percent:sheet_answer_percent, + sheet_answer_useful:sheet_answer_useful + } + obj_commit.push(sheet_obj_commit) + else #主观题答案 + user_votes= [] + main_show_row = ["第#{q.question_number}题", q.question_title] + q.poll_votes.each_with_index do |v,index| #主观题的答案 + q_poll_vote = [(index+1),v.vote_text.present? ? v.vote_text : "--"] + user_votes.push(q_poll_vote) + end + sheet_sub_commit = { + sub_title: main_show_row, + sub_user_votes:user_votes + } + sub_commit.push(sheet_sub_commit) + end + end #each_with_index + + poll_users.includes(user: :user_extension).each_with_index do |u,index| + u_user = u.user + user_answer_array = [] + poll_questions.each do |q| + user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) + if user_poll_votes.present? + user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) + user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) + if user_poll_answer_ids.count > 0 + answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) + if user_poll_answer_ids.count >1 + u_answer = answer_content.pluck(:answer_text).join(";") + else + u_answer = answer_content.first.answer_text + end + elsif user_poll_vote_texts.count > 0 + if user_poll_vote_texts.count > 1 + u_answer = user_poll_vote_texts.join(";") + else + u_answer = user_poll_vote_texts.first + end + else + u_answer = "--" + end + else + u_answer = "--" + end + user_answer_array.push(u_answer) + end + user_cell = [index+1] + if poll_un_anony + user_login = u_user.login + user_name = u_user.real_name.present? ? u_user.real_name : "--" + user_student_id = u_user.student_id.present? ? u_user.student_id : "--" + user_cell += [user_login,user_name, u_user.mail, user_student_id] + end + all_user_cell = user_cell + user_answer_array + user_commit.push(all_user_cell) + end + + { + obj_commit:obj_commit, + poll_users_info:poll_users_info, + sub_commit:sub_commit, + user_commit:user_commit + } + end + end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 1892f3fa2..693149e8f 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -128,16 +128,4 @@ module PollsHelper } end - def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) - poll_users_info = %w(序号) - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - poll_un_anony = poll.un_anonymous - if poll_un_anony #是否匿名,默认为false - user_info = %w(登陆名 真实姓名 邮箱 学号) - else - user_info = [] - end - poll_users_info = poll_users_info + user_info + poll_ques_titles - - end end diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 71585dae9..975668bfe 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -7,91 +7,130 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false - poll_users_info = %w(序号) - Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}") + obj_commit = polls_user_commit[:obj_commit] + sub_commit = polls_user_commit[:sub_commit] + poll_user_info = polls_user_commit[:poll_users_info] + user_commit = polls_user_commit[:user_commit] - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}") - poll_un_anony = poll.un_anonymous - if poll_un_anony #是否匿名,默认为false - user_info = %w(登陆名 真实姓名 邮箱 学号) - else - user_info = [] - end - poll_users_info = poll_users_info + user_info + poll_ques_titles - poll_questions.each do |q| - if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 - sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 - sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 - sheet_answer_percent = ["比例"] - sheet_answer_useful = ["有效填写人次",question_vote_user] - q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size - 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_answer_row.push(answer_users_count) - sheet_answer_percent.push(answer_percent.to_s) - end - sheet.add_row sheet_row, :height =>15,:style => blue_cell - sheet.add_row sheet_answer_row, :height =>15, :style => sz_all - sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all - sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all - #合并单元格,但无法填充style - # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) - # sheet.rows[sheet.rows.last.row_index].style = sz_all + #客观题的导出 + if obj_commit.size > 0 + obj_commit.each do |obj| + sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell + sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all + sheet.add_row obj[:sheet_answer_percent], :height =>15, :style => sz_all + sheet.add_row obj[:sheet_answer_useful], :height =>15, :style => sz_all sheet.add_row [] - else #主观题答案 - main_show_row = ["第#{q.question_number}题",q.question_title] - sheet.add_row main_show_row,:height =>15, :style => blue_cell - q.poll_votes.each_with_index do |v,index| #主观题的答案 - sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all - end - sheet.add_row [], :style => sz_all end - end #each_with_index + end - sheet.add_row poll_users_info, :height =>15, :style => blue_cell - poll_users.includes(user: :user_extension).each_with_index do |u,index| - u_user = u.user - user_answer_array = [] - poll_questions.each do |q| - user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) - if user_poll_votes.present? - user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) - user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) - if user_poll_answer_ids.count > 0 - answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) - if user_poll_answer_ids.count >1 - u_answer = answer_content.pluck(:answer_text).join(";") - else - u_answer = answer_content.first.answer_text - end - elsif user_poll_vote_texts.count > 0 - if user_poll_vote_texts.count > 1 - u_answer = user_poll_vote_texts.join(";") - else - u_answer = user_poll_vote_texts.first - end - else - u_answer = "--" - end - else - u_answer = "--" + #主观题的导出 + if sub_commit.size > 0 + sub_commit.each do |sub| + main_sub_title = sub[:sub_tile] + main_sub_content = sub[:sub_user_votes] + sheet.add_row main_sub_title,:height =>15, :style => blue_cell + main_sub_content.each do |con| + sheet.add_row con,:height =>15, :style => sz_all end - user_answer_array.push(u_answer) + sheet.add_row [] end - user_cell = [index+1] - if poll_un_anony - user_login = u_user.login - user_name = u_user.real_name.present? ? u_user.real_name : "--" - user_student_id = u_user.student_id.present? ? u_user.student_id : "--" - user_cell += [user_login,user_name, u_user.mail, user_student_id] + end + + sheet.add_row poll_user_info, :height =>15, :style => blue_cell + + if user_commit.size > 0 + user_commit.each do |com| + sheet.add_row com, :height =>15,:style => sz_all end - all_user_cell = user_cell + user_answer_array - sheet.add_row all_user_cell, :height =>15,:style => sz_all end sheet.column_widths *([25]*sheet.column_info.count) sheet.column_info.first.width = 10 + + #答题用户的导出 + + # sheet.sheet_view.show_grid_lines = false + # poll_users_info = %w(序号) + # poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + # poll_un_anony = poll.un_anonymous + # if poll_un_anony #是否匿名,默认为false + # user_info = %w(登陆名 真实姓名 邮箱 学号) + # else + # user_info = [] + # end + # poll_users_info = poll_users_info + user_info + poll_ques_titles + # poll_questions.each do |q| + # if q.question_type != 3 #问题不为主观题 + # question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 + # sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 + # sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 + # sheet_answer_percent = ["比例"] + # sheet_answer_useful = ["有效填写人次",question_vote_user] + # q.poll_answers.each do |a| #问卷的答案选项 + # answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size + # 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_answer_row.push(answer_users_count) + # sheet_answer_percent.push(answer_percent.to_s) + # end + # sheet.add_row sheet_row, :height =>15,:style => blue_cell + # sheet.add_row sheet_answer_row, :height =>15, :style => sz_all + # sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all + # sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all + # #合并单元格,但无法填充style + # # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) + # # sheet.rows[sheet.rows.last.row_index].style = sz_all + # sheet.add_row [] + # else #主观题答案 + # main_show_row = ["第#{q.question_number}题",q.question_title] + # sheet.add_row main_show_row,:height =>15, :style => blue_cell + # q.poll_votes.each_with_index do |v,index| #主观题的答案 + # sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all + # end + # sheet.add_row [], :style => sz_all + # end + # end #each_with_index + # + # sheet.add_row poll_users_info, :height =>15, :style => blue_cell + # poll_users.includes(user: :user_extension).each_with_index do |u,index| + # u_user = u.user + # user_answer_array = [] + # poll_questions.each do |q| + # user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) + # if user_poll_votes.present? + # user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) + # user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) + # if user_poll_answer_ids.count > 0 + # answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) + # if user_poll_answer_ids.count >1 + # u_answer = answer_content.pluck(:answer_text).join(";") + # else + # u_answer = answer_content.first.answer_text + # end + # elsif user_poll_vote_texts.count > 0 + # if user_poll_vote_texts.count > 1 + # u_answer = user_poll_vote_texts.join(";") + # else + # u_answer = user_poll_vote_texts.first + # end + # else + # u_answer = "--" + # end + # else + # u_answer = "--" + # end + # user_answer_array.push(u_answer) + # end + # user_cell = [index+1] + # if poll_un_anony + # user_login = u_user.login + # user_name = u_user.real_name.present? ? u_user.real_name : "--" + # user_student_id = u_user.student_id.present? ? u_user.student_id : "--" + # user_cell += [user_login,user_name, u_user.mail, user_student_id] + # end + # all_user_cell = user_cell + user_answer_array + # sheet.add_row all_user_cell, :height =>15,:style => sz_all + # end + # sheet.column_widths *([25]*sheet.column_info.count) + # sheet.column_info.first.width = 10 end #add_worksheet end \ No newline at end of file From 427a437e99e68fe5b76061d7ac9a9ee4a62d881e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 12:14:09 +0800 Subject: [PATCH 058/124] fix bug --- app/controllers/polls_controller.rb | 7 ------- app/views/polls/commit_result.xlsx.axlsx | 14 +++++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 1a6981d9f..e6ada3098 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -925,7 +925,6 @@ class PollsController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 10 @poll_export_questions = @poll_questions - logger.info("################____________________#{@poll_questions.pluck(:id)}") @poll_questions = @poll_questions.page(@page).per(@limit) if params[:format] == "xlsx" @@ -939,12 +938,6 @@ class PollsController < ApplicationController polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} - - # 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 diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 975668bfe..016c6e34c 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -7,13 +7,13 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false - obj_commit = polls_user_commit[:obj_commit] - sub_commit = polls_user_commit[:sub_commit] - poll_user_info = polls_user_commit[:poll_users_info] - user_commit = polls_user_commit[:user_commit] + obj_commit = polls_user_commit[:obj_commit] || [] + sub_commit = polls_user_commit[:sub_commit] || [] + poll_user_info = polls_user_commit[:poll_users_info] || [] + user_commit = polls_user_commit[:user_commit] || [] #客观题的导出 - if obj_commit.size > 0 + if obj_commit&.size > 0 obj_commit.each do |obj| sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all @@ -24,7 +24,7 @@ wb.styles do |s| end #主观题的导出 - if sub_commit.size > 0 + if sub_commit&.size > 0 sub_commit.each do |sub| main_sub_title = sub[:sub_tile] main_sub_content = sub[:sub_user_votes] @@ -38,7 +38,7 @@ wb.styles do |s| sheet.add_row poll_user_info, :height =>15, :style => blue_cell - if user_commit.size > 0 + if user_commit&.size > 0 user_commit.each do |com| sheet.add_row com, :height =>15,:style => sz_all end From bebbbe099d678e3486cc9084103b6355576a7139 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 13:45:22 +0800 Subject: [PATCH 059/124] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/group_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/homework_commons/group_list.json.jbuilder b/app/views/homework_commons/group_list.json.jbuilder index 1be1cdab6..dcc04e761 100644 --- a/app/views/homework_commons/group_list.json.jbuilder +++ b/app/views/homework_commons/group_list.json.jbuilder @@ -7,7 +7,7 @@ json.group_list do end end # 未分班展示情况放在最后 -if @course_groups.count > 0 && @course_groups.count < @limit.to_i +if @course_groups.count < @limit.to_i json.ungroup_list do json.id 0 json.name "未分班" From 17eaebc75a5d34dc759f346a8376b3712768037f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 13:55:56 +0800 Subject: [PATCH 060/124] =?UTF-8?q?=E5=8D=A1=E5=85=B6=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 6dd93dcc0..a4fd71830 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -79,14 +79,14 @@ class Challenge < ApplicationRecord # 允许跳关则直接开启 game = games.where(user_id: user_id).take if game.blank? - self.position == 1 ? 1 : 0 - elsif game.status == 2 - 2 + position == 1 ? 1 : 0 else - if shixun.task_pass - 1 + if game.status == 3 + shixun.task_pass ? 1 : 0 + elsif game.status == 2 + 2 else - 0 + 1 end end end From 77ebf88fde7db138e3a709f2ae6e72f3448f6a42 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 14:01:24 +0800 Subject: [PATCH 061/124] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a4fd71830..cc0f68efb 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -78,6 +78,8 @@ class Challenge < ApplicationRecord # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 game = games.where(user_id: user_id).take + logger.info("########---game_status: #{game.status}") + logger.info("########---challenge_id: #{id}") if game.blank? position == 1 ? 1 : 0 else From aa76382c5e67bada312767e6cc3155df4f17308f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 14:05:13 +0800 Subject: [PATCH 062/124] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=B7=B3=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/myshixun.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 31cc53200..a4f05f2ce 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -56,7 +56,7 @@ class Myshixun < ApplicationRecord # status:0 可以测评的; 1 正在测评的; 2评测通过的; 3未开启的 # 如果都完成,则当前任务为最后一个任务 def current_task games - current_game = games.select{|game| game.status == 1 || game.status == 0}.first + current_game = games.select{|game| game.status == 1 || game.status == 0}.last if current_game.blank? current_game = games.last end From af00e24ce460afba3204514c672d55ec94d1f6c5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 14:07:59 +0800 Subject: [PATCH 063/124] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/works_list.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index a7dc292b8..458db9621 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -13,6 +13,7 @@ json.ta_mode @homework_detail_manual.ta_mode json.is_evaluation @is_evaluation ? @is_evaluation : false json.work_public @homework.work_public +json.allow_late @homework.allow_late if @user_course_identity < Course::STUDENT From 65f82eda89b7b9a61a645a090f6d1bea9b9d5e7a Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 4 Jul 2019 14:29:26 +0800 Subject: [PATCH 064/124] use apply realname auth && apply professional auth api --- .../users/auth_attachments_controller.rb | 39 ++++++++++++ .../authentication_applies_controller.rb | 16 +++++ .../professional_auth_applies_controller.rb | 16 +++++ app/forms/users/apply_authentication_form.rb | 8 +++ .../users/apply_professional_auth_form.rb | 10 +++ app/helpers/application_helper.rb | 12 ++++ app/models/user_extension.rb | 2 +- .../users/apply_authentication_service.rb | 52 ++++++++++++++++ .../users/apply_professional_auth_service.rb | 62 +++++++++++++++++++ .../forms/apply_authentication_form.zh-CN.yml | 7 +++ .../apply_professional_auth_form.zh-CN.yml | 9 +++ config/routes.rb | 3 + lib/educoder/sms.rb | 2 +- 13 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 app/controllers/users/auth_attachments_controller.rb create mode 100644 app/controllers/users/authentication_applies_controller.rb create mode 100644 app/controllers/users/professional_auth_applies_controller.rb create mode 100644 app/forms/users/apply_authentication_form.rb create mode 100644 app/forms/users/apply_professional_auth_form.rb create mode 100644 app/services/users/apply_authentication_service.rb create mode 100644 app/services/users/apply_professional_auth_service.rb create mode 100644 config/locales/forms/apply_authentication_form.zh-CN.yml create mode 100644 config/locales/forms/apply_professional_auth_form.zh-CN.yml diff --git a/app/controllers/users/auth_attachments_controller.rb b/app/controllers/users/auth_attachments_controller.rb new file mode 100644 index 000000000..86c3e70ef --- /dev/null +++ b/app/controllers/users/auth_attachments_controller.rb @@ -0,0 +1,39 @@ +class Users::AuthAttachmentsController < Users::BaseAccountController + before_action :private_user_resources! + before_action :convert_image!, only: [:update] + + def update + image_temp_path = auth_image_path + 'temp' # 上传文件保存至临时文件,提交申请时再移到正常目录 + + File.delete(image_temp_path) if File.exist?(image_temp_path) # 删除之前的临时文件 + + Util.write_file(@image, image_temp_path) + + render_ok + rescue StandardError => ex + logger_error(ex) + render_error('上传失败') + end + + private + + def convert_image! + max_size = EduSetting.get('upload_avatar_max_size') || 10 * 1024 * 1024 # 10M + if params[:image].class == ActionDispatch::Http::UploadedFile + @image = params[:image] + render_error('请上传文件') if @image.size.zero? + render_error('文件大小超过限制') if @image.size > max_size + else + image = params[:image].to_s.strip + return render_error('请上传正确的图片') if image.blank? + @image = Util.convert_base64_image(image, max_size: max_size) + end + rescue Base64ImageConverter::Error => ex + render_error(ex.message) + end + + def auth_image_path + url_method = params[:type] == 'professional' ? :disk_professional_auth_filename : :disk_real_name_auth_filename + ApplicationController.helpers.send(url_method, observed_user.id) + end +end \ No newline at end of file diff --git a/app/controllers/users/authentication_applies_controller.rb b/app/controllers/users/authentication_applies_controller.rb new file mode 100644 index 000000000..d406b33d3 --- /dev/null +++ b/app/controllers/users/authentication_applies_controller.rb @@ -0,0 +1,16 @@ +class Users::AuthenticationAppliesController < Users::BaseAccountController + before_action :private_user_resources! + + def create + Users::ApplyAuthenticationService.call(observed_user, create_params) + render_ok + rescue Users::ApplyAuthenticationService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:name, :id_number, :upload_image) + end +end \ No newline at end of file diff --git a/app/controllers/users/professional_auth_applies_controller.rb b/app/controllers/users/professional_auth_applies_controller.rb new file mode 100644 index 000000000..b2603f642 --- /dev/null +++ b/app/controllers/users/professional_auth_applies_controller.rb @@ -0,0 +1,16 @@ +class Users::ProfessionalAuthAppliesController < Users::BaseAccountController + before_action :private_user_resources! + + def create + Users::ApplyProfessionalAuthService.call(observed_user, create_params) + render_ok + rescue Users::ApplyProfessionalAuthService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:school_id, :department_id, :identity, :extra, :upload_image) + end +end \ No newline at end of file diff --git a/app/forms/users/apply_authentication_form.rb b/app/forms/users/apply_authentication_form.rb new file mode 100644 index 000000000..986ba6223 --- /dev/null +++ b/app/forms/users/apply_authentication_form.rb @@ -0,0 +1,8 @@ +class Users::ApplyAuthenticationForm + include ActiveModel::Model + + attr_accessor :name, :id_number, :upload_image + + validates :name, presence: true + validates :id_number, presence: true +end \ No newline at end of file diff --git a/app/forms/users/apply_professional_auth_form.rb b/app/forms/users/apply_professional_auth_form.rb new file mode 100644 index 000000000..c5de9700c --- /dev/null +++ b/app/forms/users/apply_professional_auth_form.rb @@ -0,0 +1,10 @@ +class Users::ApplyProfessionalAuthForm + include ActiveModel::Model + + attr_accessor :school_id, :department_id, :identity, :extra, :upload_image + + validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 } + validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true + validates :identity, presence: true, inclusion: { in: %w(student teacher professional) } + validates :extra, presence: true +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd72b5651..cdd647ebd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -145,6 +145,18 @@ module ApplicationHelper File.join(storage_path, "#{source_type}", "#{source_id}") end + def disk_auth_filename(source_type, source_id, type) + File.join(storage_path, "#{source_type}", "#{source_id}#{type}") + end + + def disk_real_name_auth_filename(source_id) + disk_auth_filename('UserAuthentication', source_id, 'ID') + end + + def disk_professional_auth_filename(source_id) + disk_auth_filename('UserAuthentication', source_id, 'PRO') + end + def shixun_url_to_avatar(shixun) if File.exist?(disk_filename(shixun.class, shixun.id)) File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 3d8457ce3..49fca7c71 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -4,7 +4,7 @@ class UserExtension < ApplicationRecord belongs_to :user belongs_to :school - belongs_to :department + belongs_to :department, optional: true def identity_text I18n.t("user.identity.#{identity}") diff --git a/app/services/users/apply_authentication_service.rb b/app/services/users/apply_authentication_service.rb new file mode 100644 index 000000000..f31bb335c --- /dev/null +++ b/app/services/users/apply_authentication_service.rb @@ -0,0 +1,52 @@ +class Users::ApplyAuthenticationService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + Users::ApplyAuthenticationForm.new(params).validate! + raise Error, '您已经申请过实名认证了' if ApplyUserAuthentication.real_name_auth.processing.exists?(user_id: user.id) + + user.lastname = params[:name].to_s.strip + user.firstname = '' + user.ID_number = params[:id_number].to_s.strip.presence + + ActiveRecord::Base.transaction do + user.authentication = false + user.save! + + user.apply_user_authentication.create!(auth_type: 1, status: 0) + + move_image_file! unless params[:upload_image].to_s == 'false' + + sms_notify_admin + end + + user + end + + private + + def move_image_file! + image_url = ApplicationController.helpers.disk_real_name_auth_filename(user.id) + temp_image_url = image_url + 'temp' + + FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url) + rescue RuntimeError => ex + Util.logger_error(ex) + raise Error, '申请失败' + ensure + File.delete(temp_image_url) if File.exist?(temp_image_url) + end + + def sms_notify_admin + Educoder::Sms.notify_admin(send_type: 'apply_auth') + rescue => ex + Util.logger_error(ex) + end +end \ No newline at end of file diff --git a/app/services/users/apply_professional_auth_service.rb b/app/services/users/apply_professional_auth_service.rb new file mode 100644 index 000000000..2d8279317 --- /dev/null +++ b/app/services/users/apply_professional_auth_service.rb @@ -0,0 +1,62 @@ +class Users::ApplyProfessionalAuthService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + Users::ApplyProfessionalAuthForm.new(params).validate! + raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id) + + user.professional_certification = false + + extension = user.user_extension + extension.school_id = params[:school_id] + extension.department_id = params[:department_id] + extension.identity = params[:identity] + + extra = params[:extra].to_s.strip.presence + if extension.identity.to_s == 'student' + extension.technical_title = nil + extension.student_id = extra + else + extension.technical_title = extra + extension.student_id = nil + end + + ActiveRecord::Base.transaction do + user.save! + extension.save! + + user.apply_user_authentication.create!(auth_type: 2, status: 0) + + move_image_file! unless params[:upload_image].to_s == 'false' + + sms_notify_admin + end + end + + private + + def move_image_file! + image_url = ApplicationController.helpers.disk_professional_auth_filename(user.id) + temp_image_url = image_url + 'temp' + + FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url) + rescue RuntimeError => ex + Util.logger_error(ex) + raise Error, '申请失败' + ensure + File.delete(temp_image_url) if File.exist?(temp_image_url) + end + + def sms_notify_admin + Educoder::Sms.notify_admin(send_type: 'apply_pro_certification') + rescue => ex + Util.logger_error(ex) + end +end \ No newline at end of file diff --git a/config/locales/forms/apply_authentication_form.zh-CN.yml b/config/locales/forms/apply_authentication_form.zh-CN.yml new file mode 100644 index 000000000..cfc2e5b39 --- /dev/null +++ b/config/locales/forms/apply_authentication_form.zh-CN.yml @@ -0,0 +1,7 @@ +'zh-CN': + activemodel: + attributes: + users/apply_authentication_form: + name: 姓名 + id_number: 身份证号 + diff --git a/config/locales/forms/apply_professional_auth_form.zh-CN.yml b/config/locales/forms/apply_professional_auth_form.zh-CN.yml new file mode 100644 index 000000000..bbba03238 --- /dev/null +++ b/config/locales/forms/apply_professional_auth_form.zh-CN.yml @@ -0,0 +1,9 @@ +'zh-CN': + activemodel: + attributes: + users/apply_professional_auth_form: + school_id: 学校/单位 + department_id: 学院/部门 + identity: 职业 + extra: 职称/学号 + diff --git a/config/routes.rb b/config/routes.rb index 1a81f1175..e09808f6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,6 +74,9 @@ Rails.application.routes.draw do resource :email_bind, only: [:create] resource :password, only: [:update] resource :avatar, only: [:update] + resource :auth_attachment, only: [:update] + resource :authentication_apply, only: [:create] + resource :professional_auth_apply, only: [:create] end end end diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index e79678ad3..237b270d5 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -21,7 +21,7 @@ module Educoder def self.notify_admin(opt) opt[:name] = '管理员' - opt[:mobile] = ENV['NOTIDY_ADMIN_PHONE'] || '17680641960' + opt[:mobile] = ENV['NOTIFY_ADMIN_PHONE'] || EduSetting.get('notify_admin_phone') || '17680641960' send(opt) end From b5ab3785d93d368e90941ac717d994e0a6aa34f8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 14:34:33 +0800 Subject: [PATCH 065/124] poll export youhua --- app/controllers/polls_controller.rb | 33 +++---- app/views/polls/commit_result.xlsx.axlsx | 117 ++--------------------- 2 files changed, 24 insertions(+), 126 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index e6ada3098..ee2b061ba 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -146,7 +146,7 @@ class PollsController < ApplicationController def edit ActiveRecord::Base.transaction do begin - @poll_questions = @poll.poll_questions.order("question_number ASC") + rescue Exception => e uid_logger_error(e.message) tip_exception("页面请求失败!") @@ -183,7 +183,7 @@ class PollsController < ApplicationController else @is_teacher_or = 0 end - @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC") + rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -868,7 +868,6 @@ class PollsController < ApplicationController @user_poll_status = 0 #可编辑 end - # @answer_user = User.find_by(id:@poll_current_user_id) @answer_status = [] question_answered = 0 @@ -925,7 +924,6 @@ class PollsController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 10 @poll_export_questions = @poll_questions - @poll_questions = @poll_questions.page(@page).per(@limit) if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR @@ -1151,7 +1149,7 @@ class PollsController < ApplicationController def get_questions_count @poll_questions = @poll.poll_questions.order("question_number ASC") - @poll_questions_count = @poll_questions.size # 全部的题目数 + @poll_questions_count = @poll_questions&.size # 全部的题目数 @poll_question_singles = @poll_questions.ques_count(1).size # 单选题 @poll_question_doubles = @poll_questions.ques_count(2).size # 多选题 @poll_question_mains = @poll_questions.ques_count(3).size #主观题 @@ -1301,7 +1299,6 @@ class PollsController < ApplicationController #问卷的统计结果的导出 def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) - obj_commit = [] sub_commit = [] user_commit = [] poll_users_info = %w(序号) @@ -1315,30 +1312,28 @@ class PollsController < ApplicationController poll_users_info = poll_users_info + user_info + poll_ques_titles poll_questions.each do |q| if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size #该问题的有效填写量 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_percent = ["比例"] - sheet_answer_useful = ["有效填写人次",question_vote_user] + sheet_answer_useful = ["本题有效填写人次",question_vote_user] q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%" sheet_row.push(a.answer_text) sheet_answer_row.push(answer_users_count) sheet_answer_percent.push(answer_percent) end - sheet_obj_commit = { - sheet_row:sheet_row, - sheet_answer_row:sheet_answer_row, - sheet_answer_percent:sheet_answer_percent, - sheet_answer_useful:sheet_answer_useful + sheet_sub_commit = { + sub_title: sheet_row, + sub_user_votes:[sheet_answer_row,sheet_answer_percent,sheet_answer_useful] } - obj_commit.push(sheet_obj_commit) + sub_commit.push(sheet_sub_commit) else #主观题答案 user_votes= [] - main_show_row = ["第#{q.question_number}题", q.question_title] + main_show_row = ["第#{q.question_number}题", q.question_title ] q.poll_votes.each_with_index do |v,index| #主观题的答案 - q_poll_vote = [(index+1),v.vote_text.present? ? v.vote_text : "--"] + q_poll_vote = [(index+1), v.vote_text.present? ? v.vote_text : "--"] user_votes.push(q_poll_vote) end sheet_sub_commit = { @@ -1347,9 +1342,10 @@ class PollsController < ApplicationController } sub_commit.push(sheet_sub_commit) end + end #each_with_index - poll_users.includes(user: :user_extension).each_with_index do |u,index| + poll_users.includes(user: [:user_extension,:poll_votes]).each_with_index do |u,index| u_user = u.user user_answer_array = [] poll_questions.each do |q| @@ -1390,7 +1386,6 @@ class PollsController < ApplicationController end { - obj_commit:obj_commit, poll_users_info:poll_users_info, sub_commit:sub_commit, user_commit:user_commit diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 016c6e34c..4391e0e8f 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -7,30 +7,19 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false - obj_commit = polls_user_commit[:obj_commit] || [] - sub_commit = polls_user_commit[:sub_commit] || [] - poll_user_info = polls_user_commit[:poll_users_info] || [] - user_commit = polls_user_commit[:user_commit] || [] + sub_commit = polls_user_commit[:sub_commit] + poll_user_info = polls_user_commit[:poll_users_info] + user_commit = polls_user_commit[:user_commit] - #客观题的导出 - if obj_commit&.size > 0 - obj_commit.each do |obj| - sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell - sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all - sheet.add_row obj[:sheet_answer_percent], :height =>15, :style => sz_all - sheet.add_row obj[:sheet_answer_useful], :height =>15, :style => sz_all - sheet.add_row [] - end - end - - #主观题的导出 if sub_commit&.size > 0 sub_commit.each do |sub| - main_sub_title = sub[:sub_tile] + main_sub_title = sub[:sub_title] main_sub_content = sub[:sub_user_votes] sheet.add_row main_sub_title,:height =>15, :style => blue_cell - main_sub_content.each do |con| - sheet.add_row con,:height =>15, :style => sz_all + if main_sub_content.present? + main_sub_content.each do |con| + sheet.add_row con,:height =>15, :style => sz_all + end end sheet.add_row [] end @@ -44,93 +33,7 @@ wb.styles do |s| end end sheet.column_widths *([25]*sheet.column_info.count) - sheet.column_info.first.width = 10 - - #答题用户的导出 + sheet.column_info.first.width = 15 - # sheet.sheet_view.show_grid_lines = false - # poll_users_info = %w(序号) - # poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - # poll_un_anony = poll.un_anonymous - # if poll_un_anony #是否匿名,默认为false - # user_info = %w(登陆名 真实姓名 邮箱 学号) - # else - # user_info = [] - # end - # poll_users_info = poll_users_info + user_info + poll_ques_titles - # poll_questions.each do |q| - # if q.question_type != 3 #问题不为主观题 - # question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 - # sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 - # sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 - # sheet_answer_percent = ["比例"] - # sheet_answer_useful = ["有效填写人次",question_vote_user] - # q.poll_answers.each do |a| #问卷的答案选项 - # answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size - # 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_answer_row.push(answer_users_count) - # sheet_answer_percent.push(answer_percent.to_s) - # end - # sheet.add_row sheet_row, :height =>15,:style => blue_cell - # sheet.add_row sheet_answer_row, :height =>15, :style => sz_all - # sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all - # sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all - # #合并单元格,但无法填充style - # # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) - # # sheet.rows[sheet.rows.last.row_index].style = sz_all - # sheet.add_row [] - # else #主观题答案 - # main_show_row = ["第#{q.question_number}题",q.question_title] - # sheet.add_row main_show_row,:height =>15, :style => blue_cell - # q.poll_votes.each_with_index do |v,index| #主观题的答案 - # sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all - # end - # sheet.add_row [], :style => sz_all - # end - # end #each_with_index - # - # sheet.add_row poll_users_info, :height =>15, :style => blue_cell - # poll_users.includes(user: :user_extension).each_with_index do |u,index| - # u_user = u.user - # user_answer_array = [] - # poll_questions.each do |q| - # user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) - # if user_poll_votes.present? - # user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) - # user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) - # if user_poll_answer_ids.count > 0 - # answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) - # if user_poll_answer_ids.count >1 - # u_answer = answer_content.pluck(:answer_text).join(";") - # else - # u_answer = answer_content.first.answer_text - # end - # elsif user_poll_vote_texts.count > 0 - # if user_poll_vote_texts.count > 1 - # u_answer = user_poll_vote_texts.join(";") - # else - # u_answer = user_poll_vote_texts.first - # end - # else - # u_answer = "--" - # end - # else - # u_answer = "--" - # end - # user_answer_array.push(u_answer) - # end - # user_cell = [index+1] - # if poll_un_anony - # user_login = u_user.login - # user_name = u_user.real_name.present? ? u_user.real_name : "--" - # user_student_id = u_user.student_id.present? ? u_user.student_id : "--" - # user_cell += [user_login,user_name, u_user.mail, user_student_id] - # end - # all_user_cell = user_cell + user_answer_array - # sheet.add_row all_user_cell, :height =>15,:style => sz_all - # end - # sheet.column_widths *([25]*sheet.column_info.count) - # sheet.column_info.first.width = 10 end #add_worksheet -end \ No newline at end of file +end From 37d932b5463b73a1d0a0f6c879cc34575b9e781a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 14:38:25 +0800 Subject: [PATCH 066/124] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=8F=AD=E6=9C=89?= =?UTF-8?q?=E6=95=88=E4=BD=9C=E5=93=81=E4=B8=BA0=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E3=80=82=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/group_list.json.jbuilder | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/homework_commons/group_list.json.jbuilder b/app/views/homework_commons/group_list.json.jbuilder index dcc04e761..5e6c63556 100644 --- a/app/views/homework_commons/group_list.json.jbuilder +++ b/app/views/homework_commons/group_list.json.jbuilder @@ -8,10 +8,13 @@ json.group_list do end # 未分班展示情况放在最后 if @course_groups.count < @limit.to_i - json.ungroup_list do - json.id 0 - json.name "未分班" - json.work_count homework_ungroup_works_count @homework, @ungroup_user_ids - json.last_review_time ungroup_last_review_time @homework + ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids) + if ungroup_work_count > 0 + json.ungroup_list do + json.id 0 + json.name "未分班" + json.work_count ungroup_work_count + json.last_review_time ungroup_last_review_time @homework + end end end \ No newline at end of file From cbb2cf6d1d8b5f04dd9cc6d39ec730f416bd6539 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 15:00:01 +0800 Subject: [PATCH 067/124] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index cc0f68efb..a4fd71830 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -78,8 +78,6 @@ class Challenge < ApplicationRecord # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 game = games.where(user_id: user_id).take - logger.info("########---game_status: #{game.status}") - logger.info("########---challenge_id: #{id}") if game.blank? position == 1 ? 1 : 0 else From c5e283b1bd6ec664871c71fd38ce53f6467be314 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 15:05:52 +0800 Subject: [PATCH 068/124] fix bug --- app/views/graduation_topics/export.xlsx.axlsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index f1d7e8e74..ff5b58b11 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -15,7 +15,7 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title, :style => bg_cell + sheet.add_row sheet_title, :style => bg_cell,:height => 15 sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } From e07d595aabf76c4a24c68e651beb899227830fe5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 15:09:55 +0800 Subject: [PATCH 069/124] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/export_shixun_report_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/export_shixun_report_service.rb b/app/services/export_shixun_report_service.rb index 4c8dab6aa..f9da3d6f2 100644 --- a/app/services/export_shixun_report_service.rb +++ b/app/services/export_shixun_report_service.rb @@ -10,7 +10,7 @@ class ExportShixunReportService end def filename - @_filename ||= "#{homework.name}-#{work.user.user_extension&.student_id}-#{work.user.real_name}.pdf".gsub(' ', '-').gsub('/', '_') + @_filename ||= "#{homework.name}-#{work.user&.student_id}-#{work.user.real_name}.pdf".gsub(' ', '-').gsub('/', '_') end def prepare_binding From d5049dfc74eb0edadeacbc617f82bb3ab04e8bbc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 15:11:10 +0800 Subject: [PATCH 070/124] fix bug --- app/views/graduation_topics/export.xlsx.axlsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index ff5b58b11..77e9bec5a 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -1,5 +1,5 @@ wb = xlsx_package.workbook -wb.use_autowidth = false +# wb.use_autowidth = false wb.use_shared_strings = true wb.styles do |s| @@ -9,13 +9,13 @@ wb.styles do |s| bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } - bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } + bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title, :style => bg_cell,:height => 15 + sheet.add_row sheet_title,:height => 30, :style => bg_cell sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } @@ -23,10 +23,10 @@ wb.styles do |s| sheet["U1:W1"].each { |c| c.style = bg_bb } if topic_users.count > 0 topic_users.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user,:height => 18, :style => sz_all end #each_widh_index else - sheet.add_row ["--"]*sheet_title_c + sheet.add_row ["--"]*sheet_title_c,:height => 18 end sheet.column_widths *([15]*sheet.column_info.count) From d27bb78d32b989017468852b3b685c492869693b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 15:14:00 +0800 Subject: [PATCH 071/124] fix bug --- app/views/graduation_topics/export.xlsx.axlsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index 77e9bec5a..2da608f6a 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -15,7 +15,7 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title,:height => 30, :style => bg_cell + sheet.add_row sheet_title,:height => 32, :style => bg_cell sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } From b990d6b74ea956dbb59efdf4d52ca8d0ca7b1fd0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:14:03 +0800 Subject: [PATCH 072/124] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 13 +++++++-- app/views/games/get_answer_info.json.jbuilder | 28 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 56c1d9347..b490352bb 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -225,8 +225,17 @@ class GamesController < ApplicationController # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - challenge = @game.challenge - @challenge_answers = challenge.challenge_answers + @challenge = @game.challenge + @challenge_answers = if @challenge.st == 0 + @challenge.challenge_answers + else + result = [] + @challenge.challenge_chooses.each do |choose| + result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end + end + + # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 7620a991a..4cfebd856 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,15 +1,25 @@ index = 0 json.status 3 -json.message do - json.array! @challenge_answers do |answer| - index += 1 - json.answer_id answer.id - json.answer_name answer.name - json.answer_score answer.score - # 高层级不给答案 - if @power || @game.answer_open >= index - json.answer_contents answer.contents +if @challenge.st == 0 + json.message do + json.array! @challenge_answers do |answer| + index += 1 + json.answer_id answer.id + json.answer_name answer.name + json.answer_score answer.score + # 高层级不给答案 + if @power || @game.answer_open >= index + json.answer_contents answer.contents + end + end + end +else + json.message do + json.array! @challenge_answers do |answer| + json.position answer[:postion] + json.answer_contents answer[:answer] end end end + From 716b5af39fd8be91981344492f328d18390c488f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:14:56 +0800 Subject: [PATCH 073/124] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 17 +++++++++-------- app/views/games/get_answer_info.json.jbuilder | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b490352bb..0142ef2ba 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -226,14 +226,15 @@ class GamesController < ApplicationController # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info @challenge = @game.challenge - @challenge_answers = if @challenge.st == 0 - @challenge.challenge_answers - else - result = [] - @challenge.challenge_chooses.each do |choose| - result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end - end + if @challenge.st == 0 + @challenge_answers = @challenge.challenge_answers + else + result = [] + @challenge.challenge_chooses.each do |choose| + result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end + @challenge_answers = result + end # 平台已认证的老师需要控制 diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 4cfebd856..57b180816 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,5 +1,6 @@ index = 0 json.status 3 +# st: 0 实践题 1 选择题 if @challenge.st == 0 json.message do json.array! @challenge_answers do |answer| From b6ccd6562cc18fb81e3405541ebfb7c375d9fcf3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:27:04 +0800 Subject: [PATCH 074/124] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=AE=9E=E8=AE=AD=E7=AD=94=E6=A1=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 38 +++++++++---------- app/views/games/get_answer_info.json.jbuilder | 28 +++++--------- app/views/games/unlock_answer.json.jbuilder | 6 ++- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 0142ef2ba..eea4e4dc0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -225,18 +225,8 @@ class GamesController < ApplicationController # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - @challenge = @game.challenge - if @challenge.st == 0 - @challenge_answers = @challenge.challenge_answers - else - result = [] - @challenge.challenge_chooses.each do |choose| - result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end - @challenge_answers = result - end - - + challenge = @game.challenge + @challenge_answers = challenge.challenge_answers # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power @@ -259,14 +249,22 @@ class GamesController < ApplicationController # 解锁答案 # GET: /tasks/:identifier/get_answer_info?answer_id=? def unlock_answer - @answer = ChallengeAnswer.find(params[:answer_id]) - challenge = @answer.challenge - # 解锁需要本层级的答案是否需要扣分 - points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) - deduct_score = ((points / 100.0) * challenge.score).to_i - uid_logger("############金币数目: #{current_user.grade}") - unless current_user.grade.to_i - deduct_score > 0 - tip_exception("您没有足够的金币") + @challenge = @game.challenge + if @challenge.st == 0 + @answer = ChallengeAnswer.find(params[:answer_id]) + challenge = @answer.challenge + # 解锁需要本层级的答案是否需要扣分 + points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) + deduct_score = ((points / 100.0) * challenge.score).to_i + uid_logger("############金币数目: #{current_user.grade}") + unless current_user.grade.to_i - deduct_score > 0 + tip_exception("您没有足够的金币") + end + else + @answer = [] + @challenge.challenge_chooses.each do |choose| + @answer << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end end ActiveRecord::Base.transaction do diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 57b180816..0f150d500 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,26 +1,18 @@ index = 0 json.status 3 # st: 0 实践题 1 选择题 -if @challenge.st == 0 - json.message do - json.array! @challenge_answers do |answer| - index += 1 - json.answer_id answer.id - json.answer_name answer.name - json.answer_score answer.score - # 高层级不给答案 - if @power || @game.answer_open >= index - json.answer_contents answer.contents - end - end - end -else - json.message do - json.array! @challenge_answers do |answer| - json.position answer[:postion] - json.answer_contents answer[:answer] +json.message do + json.array! @challenge_answers do |answer| + index += 1 + json.answer_id answer.id + json.answer_name answer.name + json.answer_score answer.score + # 高层级不给答案 + if @power || @game.answer_open >= index + json.answer_contents answer.contents end end end + diff --git a/app/views/games/unlock_answer.json.jbuilder b/app/views/games/unlock_answer.json.jbuilder index 71018c7be..9776fde46 100644 --- a/app/views/games/unlock_answer.json.jbuilder +++ b/app/views/games/unlock_answer.json.jbuilder @@ -1 +1,5 @@ -json.contents @answer.contents \ No newline at end of file +if @challenge.st == 0 + json.contents @answer.contents +else + json.contents @answer +end From 1730552269ea552aef42f67acd45496bc7f93338 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 17:21:32 +0800 Subject: [PATCH 075/124] fix bug --- app/controllers/polls_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ee2b061ba..57bbc9769 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1302,7 +1302,7 @@ class PollsController < ApplicationController sub_commit = [] user_commit = [] poll_users_info = %w(序号) - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| k.strip if k.present?} + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| ActionController::Base.helpers.strip_tags(k) if k.present?} poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) From eb5cf9f75957910e232397c97f2f2ec6dcdbd45f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 17:38:04 +0800 Subject: [PATCH 076/124] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 75 +++++++++++++------ .../games/get_choose_answer.json.jbuilder | 6 ++ app/views/games/unlock_answer.json.jbuilder | 6 +- .../games/unlock_choose_answer.json.jbuilder | 6 ++ config/routes.rb | 2 + 5 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 app/views/games/get_choose_answer.json.jbuilder create mode 100644 app/views/games/unlock_choose_answer.json.jbuilder diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index eea4e4dc0..ea09b9003 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -221,12 +221,12 @@ class GamesController < ApplicationController @result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer end - # 获取答案 + # 获取实践题答案 # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - challenge = @game.challenge - @challenge_answers = challenge.challenge_answers + @challenge = @game.challenge + @challenge_answers = @challenge.challenge_answers # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power @@ -243,43 +243,49 @@ class GamesController < ApplicationController end end end + end + # 获取选择题答案 + def get_choose_answer + @challenge = @game.challenge + tip_exception("本接口只能获取选择题答案") if @challenge.st != 1 + @power = (@identity < User::EDU_GAME_MANAGER) + # 如果没权限,也没看过答案,则需要解锁 + if @game.answer_open == 0 && !@power + tip_exception(1, @challenge.choose_score) + else + @challenge_chooses = @challenge.challenge_chooses + end end - # 解锁答案 + # 解锁实践题答案 # GET: /tasks/:identifier/get_answer_info?answer_id=? def unlock_answer @challenge = @game.challenge - if @challenge.st == 0 - @answer = ChallengeAnswer.find(params[:answer_id]) - challenge = @answer.challenge - # 解锁需要本层级的答案是否需要扣分 - points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) - deduct_score = ((points / 100.0) * challenge.score).to_i - uid_logger("############金币数目: #{current_user.grade}") - unless current_user.grade.to_i - deduct_score > 0 - tip_exception("您没有足够的金币") - end - else - @answer = [] - @challenge.challenge_chooses.each do |choose| - @answer << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end + @answer = ChallengeAnswer.find(params[:answer_id]) + challenge = @answer.challenge + # 解锁需要本层级的答案是否需要扣分 + points = challenge.challenge_answers.where(level: @game.answer_open + 1..@answer.level).sum(:score) + deduct_score = ((points / 100.0) * challenge.score).to_i + uid_logger("############金币数目: #{current_user.grade}") + unless current_user.grade.to_i - deduct_score > 0 + tip_exception("您没有足够的金币") end ActiveRecord::Base.transaction do begin # 积分消耗情况记录 score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i - RewardGradeService.call(current_user, container_id: @answer.id, container_type: 'Answer', score: score) + RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: score) # 通关查看答案 不扣 得分 + answer_open = @challenge.st == 1 ? 1 : @answer.level if @game.status == 2 - @game.update_attributes!(:answer_open => @answer.level) + @game.update_attributes!(:answer_open =>answer_open) else # 扣除总分计算 answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score) - @game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction) + @game.update_attributes!(:answer_open => answer_open, :answer_deduction => answer_deduction) end rescue Exception => e @@ -287,7 +293,32 @@ class GamesController < ApplicationController raise ActiveRecord::Rollback end end + end + # 解锁选择题答案 + def unlock_choose_answer + @challenge = @game.challenge + score = @challenge.choose_score + unless current_user.grade.to_i - score > 0 + tip_exception("您没有足够的金币") + end + ActiveRecord::Base.transaction do + begin + # 积分消耗情况记录 + RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: -score) + # 通关查看答案 不扣 得分 + if @game.status == 2 + @game.update_attributes!(:answer_open => 1) + else + # 扣除总分计算 + @game.update_attributes!(:answer_open => 1, :answer_deduction => 100) + end + @challenge_answers = @challenge.challenge_chooses + rescue Exception => e + uid_logger_error("#######金币扣除异常: #{e.message}") + raise ActiveRecord::Rollback + end + end end # 查看答案需要扣取金币 diff --git a/app/views/games/get_choose_answer.json.jbuilder b/app/views/games/get_choose_answer.json.jbuilder new file mode 100644 index 000000000..15586de13 --- /dev/null +++ b/app/views/games/get_choose_answer.json.jbuilder @@ -0,0 +1,6 @@ +json.choose_answers do + json.array! @challenge_chooses do |choose| + json.position choose.position + json.answer choose.answer.blank? ? choose.standard_answer : choose.answer + end +end diff --git a/app/views/games/unlock_answer.json.jbuilder b/app/views/games/unlock_answer.json.jbuilder index 9776fde46..322536c2b 100644 --- a/app/views/games/unlock_answer.json.jbuilder +++ b/app/views/games/unlock_answer.json.jbuilder @@ -1,5 +1 @@ -if @challenge.st == 0 - json.contents @answer.contents -else - json.contents @answer -end +json.contents @answer.contents diff --git a/app/views/games/unlock_choose_answer.json.jbuilder b/app/views/games/unlock_choose_answer.json.jbuilder new file mode 100644 index 000000000..15586de13 --- /dev/null +++ b/app/views/games/unlock_choose_answer.json.jbuilder @@ -0,0 +1,6 @@ +json.choose_answers do + json.array! @challenge_chooses do |choose| + json.position choose.position + json.answer choose.answer.blank? ? choose.standard_answer : choose.answer + end +end diff --git a/config/routes.rb b/config/routes.rb index e09808f6c..cf5bad608 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,6 +124,8 @@ Rails.application.routes.draw do get :get_answer_info get :unlock_answer get :check_test_sets + get :unlock_choose_answer + get :get_choose_answer end collection do From e09625df9458409ac00e32f384788305c9feca2a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 17:43:31 +0800 Subject: [PATCH 077/124] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- .../course_add_student_create_works_job.rb | 30 +++++++++++++++++++ .../course_delete_student_delete_works_job.rb | 7 +++++ app/models/course_member.rb | 6 ++-- config/sidekiq.yml | 1 + ...ourse_add_student_create_works_job_spec.rb | 5 ++++ ...se_delete_student_delete_works_job_spec.rb | 5 ++++ 7 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 app/jobs/course_add_student_create_works_job.rb create mode 100644 app/jobs/course_delete_student_delete_works_job.rb create mode 100644 spec/jobs/course_add_student_create_works_job_spec.rb create mode 100644 spec/jobs/course_delete_student_delete_works_job_spec.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d1ab595e5..d6a86ff50 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -711,7 +711,7 @@ class CoursesController < ApplicationController student_ids = [] user_ids.each do |user_id| - existing_course_member = CourseMember.find_by(user_id: user_id.to_i, course_id: @course.id) + existing_course_member = @course.course_members.find_by(user_id: user_id.to_i) new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4) if existing_course_member.present? diff --git a/app/jobs/course_add_student_create_works_job.rb b/app/jobs/course_add_student_create_works_job.rb new file mode 100644 index 000000000..41c3065a1 --- /dev/null +++ b/app/jobs/course_add_student_create_works_job.rb @@ -0,0 +1,30 @@ +# 学生加入课堂时创建相关任务作品 +class CourseAddStudentCreateWorksJob < ApplicationJob + queue_as :course_member + + def perform(course_id, student_ids) + course = Course.find_by(id: course_id) + return if course.blank? + + # 如果之前存在相关作品,则更新is_delete字段 + student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id}) + student_works.update_all(is_delete: 0) + + exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id}) + exercise_users.update_all(is_delete: 0) + + poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id}) + poll_users.update_all(is_delete: 0) + + graduation_works = course.graduation_works.where(user_id: student_ids) + graduation_works.update_all(is_delete: 0) + + attrs = %i[homework_common_id user_id created_at updated_at] + + StudentWork.bulk_insert(*attrs) do |worker| + student_ids.each do |teacher| + worker.add same_attrs.merge(user_id: teacher.user_id) + end + end + end +end diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb new file mode 100644 index 000000000..2eb3fb60e --- /dev/null +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -0,0 +1,7 @@ +class CourseDeleteStudentDeleteWorksJob < ApplicationJob + queue_as :course_member + + def perform(*args) + # Do something later + end +end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index 7db681e67..87d4ffe88 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -52,13 +52,13 @@ class CourseMember < ApplicationRecord def recover_works course = self.course - student_works = StudentWork.where(user_id: self.user_id, homework_common_id: course.homework_commons) + student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id}) student_works.update_all(is_delete: 0) - exercise_users = ExerciseUser.where(user_id: self.user_id, exercise_id: course.exercises) + exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id}) exercise_users.update_all(is_delete: 0) - poll_users = PollUser.where(user_id: self.user_id, poll_id: course.polls) + poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id}) poll_users.update_all(is_delete: 0) graduation_works = course.graduation_works.where(user_id: self.user_id) diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 5bd9dad23..93e89b4dc 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -5,4 +5,5 @@ - [default, 3] - [score, 4] - [evaluation_comment, 5] + - [course_member, 6] - [notify, 100] \ No newline at end of file diff --git a/spec/jobs/course_add_student_create_works_job_spec.rb b/spec/jobs/course_add_student_create_works_job_spec.rb new file mode 100644 index 000000000..5466f830c --- /dev/null +++ b/spec/jobs/course_add_student_create_works_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseAddStudentCreateWorksJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/course_delete_student_delete_works_job_spec.rb b/spec/jobs/course_delete_student_delete_works_job_spec.rb new file mode 100644 index 000000000..71ad3b1dc --- /dev/null +++ b/spec/jobs/course_delete_student_delete_works_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseDeleteStudentDeleteWorksJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 234cdbeab907804f42b9a358fd356a30c1f6779d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:28:37 +0800 Subject: [PATCH 078/124] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0190705011739_add_praises_count_for_challenges.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20190705011739_add_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb new file mode 100644 index 000000000..6455f1f10 --- /dev/null +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -0,0 +1,12 @@ +class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] + def change + add_column :challenges, :praises_count, :integer, :default => 0 + + challenges = Challenge.where(nil) + challenges.each do |c| + praises_count = c.praise_tread.where(praise_or_tread: 1).count + c.update_column(:praises_count, praises_count) + end + + end +end From fbcf9b77f53245d163aec43c78076422308d443f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:32:29 +0800 Subject: [PATCH 079/124] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190705011739_add_praises_count_for_challenges.rb | 9 +-------- ...20190705013203_modify_praises_count_for_challenges.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705013203_modify_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 6455f1f10..2bf246277 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -1,12 +1,5 @@ class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - add_column :challenges, :praises_count, :integer, :default => 0 - - challenges = Challenge.where(nil) - challenges.each do |c| - praises_count = c.praise_tread.where(praise_or_tread: 1).count - c.update_column(:praises_count, praises_count) - end - + #add_column :challenges, :praises_count, :integer, :default => 0 end end diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb new file mode 100644 index 000000000..d2441d948 --- /dev/null +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -0,0 +1,9 @@ +class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] + def change + challenges = Challenge.where(nil) + challenges.each do |c| + praises_count = c.praise_tread.where(praise_or_tread: 1).count + c.update_column(:praises_count, praises_count) + end + end +end From 6f1d84eecc41ef8cf4c6529d0f60c9e4009c39b1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:34:32 +0800 Subject: [PATCH 080/124] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190705011739_add_praises_count_for_challenges.rb | 2 +- .../20190705013203_modify_praises_count_for_challenges.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 2bf246277..6ae1d8420 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -1,5 +1,5 @@ class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - #add_column :challenges, :praises_count, :integer, :default => 0 + add_column :challenges, :praises_count, :integer, :default => 0 end end diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb index d2441d948..35711027a 100644 --- a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -1,7 +1,7 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - challenges = Challenge.where(nil) - challenges.each do |c| + challenges = Challenge.where(nil).unscope + challenges.find_each do |c| praises_count = c.praise_tread.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) end From f0b6c04e5fa9c2a958fc1e2ec7a970c36f66fdb4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:36:27 +0800 Subject: [PATCH 081/124] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rb => 20190705013204_modify_praises_count_for_challenges.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20190705013203_modify_praises_count_for_challenges.rb => 20190705013204_modify_praises_count_for_challenges.rb} (84%) diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb similarity index 84% rename from db/migrate/20190705013203_modify_praises_count_for_challenges.rb rename to db/migrate/20190705013204_modify_praises_count_for_challenges.rb index 35711027a..4cf975f3d 100644 --- a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb @@ -1,6 +1,6 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - challenges = Challenge.where(nil).unscope + challenges = Challenge.where(nil).unscoped challenges.find_each do |c| praises_count = c.praise_tread.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) From 3d7284525f64849b7f8364c0fbf0f5165cfe4987 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:53:23 +0800 Subject: [PATCH 082/124] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ea09b9003..e54d5c34f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -40,10 +40,8 @@ class GamesController < ApplicationController next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) # 关卡点赞数, praise_or_tread = 1则表示赞过 - praise_count = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", - praise_or_tread: 1).count - user_praise = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", - user_id: current_user.id, praise_or_tread: 1).present? ? true : false + praise_count = game_challenge.praises_count + user_praise = game_challenge.praise_tread.exists?(user_id:current_user.id, praise_or_tread: 1) # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index.to_i From db69b3737c93c98ca962672e12e42a6029c54dea Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:55:30 +0800 Subject: [PATCH 083/124] =?UTF-8?q?TPI=E7=82=B9=E8=B5=9E=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a4fd71830..e4524a69a 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -20,7 +20,7 @@ class Challenge < ApplicationRecord # acts_as_attachable scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, - :web_route, :answer, :exec_time]) } + :web_route, :answer, :exec_time, :praises_count]) } scope :choose_type, -> { where(st: 1) } scope :practice_type, -> { where(st: 0) } From 7d81be96a5b6f00b06f58228a409fed174109dfe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 09:57:38 +0800 Subject: [PATCH 084/124] =?UTF-8?q?zip=E5=AF=BC=E5=87=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 4 +- app/controllers/zips_controller.rb | 61 ++++++++++--------- .../batch_export_shixun_report_service.rb | 14 +---- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 07113792d..e6f9876bc 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,7 +1300,9 @@ class ExercisesController < ApplicationController 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) + elsif @exercise_status == 1 + normal_status(-1,"试卷未发布") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else respond_to do |format| diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 8553cbb44..4089e5231 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,12 +6,9 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - # student_work_ids = Array.wrap(params[:student_work_ids]) - # service = BatchExportShixunReportService.new(@homework, @student_work_ids) service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex @@ -23,8 +20,8 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end @@ -44,7 +41,7 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user.id) : 1 group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -101,34 +98,40 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) + @homework_status = @homework.present? ? @homework.homework_detail_manual.comment_status : 0 + if @homework.blank? + normal_status(-1,"该作业不存在") + elsif @homework_status == 0 + normal_status(-1,"该作业未发布") + else + @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 - @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 ? + 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 + 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") + 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 diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index ebb273a87..90c8fb2af 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,7 +3,6 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - # attr_reader :homework, :student_work_ids attr_reader :homework, :all_student_works @@ -15,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{Time.now.strftime('%Y%m%d%H%M%S')}-#{homework.name}.zip" + @_filename ||= "#{homework.name}-#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" end def zip @@ -45,15 +44,4 @@ class BatchExportShixunReportService end end - # private - # - # def validate! - # if student_work_ids.size.zero? - # raise Error, '请选择学生实训作业' - # end - # - # if student_work_ids.size > MAX_BATCH_LIMIT - # raise Error, '导出实训报告太多,请分批导出' - # end - # end end From 155e9a0a37b635a7d99e8d616ecae257d90a611a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 10:40:16 +0800 Subject: [PATCH 085/124] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 4 ++-- app/models/challenge.rb | 2 +- app/models/discuss.rb | 2 +- app/services/shixuns_service.rb | 10 +++++----- app/views/discusses/_discuss.json.jbuilder | 4 ++-- ...190705013204_modify_praises_count_for_challenges.rb | 2 +- .../20190705022502_add_praises_count_for_discuess.rb | 5 +++++ ...20190705022737_modify_praises_count_for_discuess.rb | 9 +++++++++ 8 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20190705022502_add_praises_count_for_discuess.rb create mode 100644 db/migrate/20190705022737_modify_praises_count_for_discuess.rb diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 1d3b524f4..db3047e74 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -10,13 +10,13 @@ class DiscussesController < ApplicationController if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, - :root_id => nil).includes(:user, :praise_tread).offset(offset) + :root_id => nil).includes(:user, :praise_treads).offset(offset) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) @disscuss_count = disscusses.count - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) end @current_user = current_user diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e4524a69a..7afb919a0 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -10,7 +10,7 @@ class Challenge < ApplicationRecord has_many :games, :dependent => :destroy has_many :challenge_chooses, :dependent => :destroy has_many :homework_challenge_settings, :dependent => :destroy - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :tidings # 参考答案 diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 93f0d62cd..737a89ec1 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -5,7 +5,7 @@ class Discuss < ApplicationRecord belongs_to :parent, class_name: 'Discuss', foreign_key: :parent_id, optional: true has_many :children, -> { reorder(created_at: :asc) }, class_name: 'Discuss', foreign_key: :parent_id - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy diff --git a/app/services/shixuns_service.rb b/app/services/shixuns_service.rb index 83d61b352..4efefd4c2 100644 --- a/app/services/shixuns_service.rb +++ b/app/services/shixuns_service.rb @@ -47,7 +47,7 @@ class ShixunsService if current_user.admin? disscuss_count = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil).count discusses = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil) - .includes(:user, :praise_tread).limit(LIMIT).offset(offset) + .includes(:user, :praise_treads).limit(LIMIT).offset(offset) else disscusses = Discuss.where( 'dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)', @@ -55,7 +55,7 @@ class ShixunsService ) disscuss_count = disscusses.count - discusses = disscusses.includes(:user, :praise_tread).limit(LIMIT).offset(offset) + discusses = disscusses.includes(:user, :praise_treads).limit(LIMIT).offset(offset) end base_data discusses, dis, current_user @@ -81,7 +81,7 @@ class ShixunsService offset = page * LIMIT find_status = true if position end - discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_tread).offset(offset) + discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_treads).offset(offset) base_data discusses, dis, current_user Myshixun.find(params[:myshixun_id]).update_attribute(:onclick_time, Time.now) @@ -109,8 +109,8 @@ class ShixunsService if discusses.present? discusses.each do |d| # 总点赞数 - praise_count = d.praise_tread.where(:praise_or_tread => 1).count - user_praise= d.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false + praise_count = d.praises_count + user_praise= d.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false manager = current_user.manager_of_shixun?(dis, current_user) game_url = if manager diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index e7e6e425f..992466559 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -14,8 +14,8 @@ json.game_url discuss.game_url(container, current_user) if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) else - json.praise_count discuss.praise_tread.where(praise_or_tread: 1).count - json.user_praise discuss.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false + json.praise_count discuss.praises_count + json.user_praise discuss.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 end diff --git a/db/migrate/20190705013204_modify_praises_count_for_challenges.rb b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb index 4cf975f3d..59aa6ca53 100644 --- a/db/migrate/20190705013204_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb @@ -2,7 +2,7 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change challenges = Challenge.where(nil).unscoped challenges.find_each do |c| - praises_count = c.praise_tread.where(praise_or_tread: 1).count + praises_count = c.praise_treads.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) end end diff --git a/db/migrate/20190705022502_add_praises_count_for_discuess.rb b/db/migrate/20190705022502_add_praises_count_for_discuess.rb new file mode 100644 index 000000000..47fd5ec1a --- /dev/null +++ b/db/migrate/20190705022502_add_praises_count_for_discuess.rb @@ -0,0 +1,5 @@ +class AddPraisesCountForDiscuess < ActiveRecord::Migration[5.2] + def change + add_column :discusses, :praises_count, :integer, :default => 0 + end +end diff --git a/db/migrate/20190705022737_modify_praises_count_for_discuess.rb b/db/migrate/20190705022737_modify_praises_count_for_discuess.rb new file mode 100644 index 000000000..4d5b6ca97 --- /dev/null +++ b/db/migrate/20190705022737_modify_praises_count_for_discuess.rb @@ -0,0 +1,9 @@ +class ModifyPraisesCountForDiscuess < ActiveRecord::Migration[5.2] + def change + discusses = Discuss.includes(:praise_treads).unscoped + discusses.find_each do |d| + praises_count = d.praise_treads.liker.count + d.update_column(:praises_count, praises_count) + end + end +end From 5666a3564e5199b2ac84a2110eb6c11cdcc0390d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 10:41:38 +0800 Subject: [PATCH 086/124] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e54d5c34f..c36be012f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -41,7 +41,7 @@ class GamesController < ApplicationController # 关卡点赞数, praise_or_tread = 1则表示赞过 praise_count = game_challenge.praises_count - user_praise = game_challenge.praise_tread.exists?(user_id:current_user.id, praise_or_tread: 1) + user_praise = game_challenge.praise_treads.exists?(user_id:current_user.id, praise_or_tread: 1) # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index.to_i From 20657ff933180557e7d20eb746c6a45bda9e4662 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 10:47:15 +0800 Subject: [PATCH 087/124] fix bug --- app/services/batch_export_shixun_report_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 90c8fb2af..2c294395d 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -36,7 +36,7 @@ class BatchExportShixunReportService rescue => ex Rails.logger.error(ex.message) - zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write('文件重复') } + zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } next end end From 6628269df16274745bd24d3680bca631ceb0d4a7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 10:52:47 +0800 Subject: [PATCH 088/124] =?UTF-8?q?=E4=BD=9C=E5=93=81=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=AF=BC=E5=87=BA=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/export_helper.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index a23cb8a65..839686f5b 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -487,6 +487,8 @@ module ExportHelper zipfile_name = "#{output_path}/#{rename_zipfile}" + # 同名文件重命名时用 + index = 1 Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| files_paths.each do |filename| @@ -496,7 +498,11 @@ module ExportHelper begin zipfile.add(rename_file, filename) rescue Exception => e - zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"} + rename_file = rename_same_file(rename_file, index) + index += 1 + zipfile.add(rename_file, filename) + + # zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"} next end end @@ -516,4 +522,11 @@ module ExportHelper def format_sheet_name name name = name.gsub(":", "-") end + + def rename_same_file(name, index) + basename = File.basename(name, ".*") + new_basename = basename + "_" + index.to_s + extname = File.extname(name) + new_basename + extname + end end From 1ab39388137209d5941c953d01bdd69a6799beaf Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 10:54:07 +0800 Subject: [PATCH 089/124] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BC=BA=E8=AF=84?= =?UTF-8?q?=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/homework_absence_penalty_calculation_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb index 87f78f311..6e80f2330 100644 --- a/app/jobs/homework_absence_penalty_calculation_job.rb +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -11,7 +11,7 @@ class HomeworkAbsencePenaltyCalculationJob < ApplicationJob homework_common.student_works.where("work_status != 0").each do |student_work| absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count - - student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count + student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(&:student_work_id).count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 student_work.save From 4b49571ab58b3b6651626d71f7dc505bc62c36e0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 11:31:45 +0800 Subject: [PATCH 090/124] fix bug --- app/controllers/exercises_controller.rb | 40 ++----------------------- app/controllers/polls_controller.rb | 2 -- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e6f9876bc..49dd7edb9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -477,10 +477,8 @@ class ExercisesController < ApplicationController params_end_time = params[:end_time].to_time end - if exercise_status == 2 && @exercise.publish_time != params_publish_time - normal_status(-1,"已发布,不允许修改发布时间") - elsif exercise_status == 3 && (@exercise.end_time != params_end_time || @exercise.publish_time != params_publish_time) - normal_status(-1,"已截止,不允许修改时间") + if (exercise_status != 1) && (@exercise.publish_time != params_publish_time) + normal_status(-1,"已发布/已截止,不允许修改发布时间") elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time normal_status(-1,"截止时间不能小于发布时间") else @@ -523,12 +521,7 @@ class ExercisesController < ApplicationController end # exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在 - if exercise_group.present? && exercise_group.first.end_time <= Time.now && - (exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误 - error_count += 1 - end - if exercise_group.present? && exercise_group.first.publish_time < - Time.now && exercise_publish_time != exercise_group.first.publish_time + if exercise_group.present? && (exercise_group.first.publish_time < Time.now) && (exercise_publish_time != exercise_group.first.publish_time) error_count += 1 end if error_count == 0 @@ -1639,36 +1632,9 @@ class ExercisesController < ApplicationController @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first if @answer_committed_user.blank? normal_status(404,"答题用户不存在") - # elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交 - # normal_status(-1,"提交错误,试卷用户已提交!") end end - # def commit_user_exercise - # @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题 - # if @user_course_identity == Course::STUDENT - # if @exercise_user_current.present? - # if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && - # ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) - # #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 - # objective_score = calculate_student_score(@exercise,current_user)[:total_score] - # subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score - # total_score = objective_score + subjective_score - # commit_option = { - # :status => 1, - # :commit_status => 1, - # :end_at => Time.now, - # :objective_score => objective_score, - # :score => total_score, - # :subjective_score => subjective_score - # } - # @exercise_user_current.update_attributes(commit_option) - # normal_status(0,"已交卷成功!") - # end - # end - # end - # end - #打回重做时的初步判断 def check_exercise_status @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 57bbc9769..64827b375 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1282,8 +1282,6 @@ class PollsController < ApplicationController else normal_status(-1,"请选择分班!") end - # elsif (@poll.poll_status != 1) && (params[:publish_time].to_time != @poll.publish_time) && (@user_course_identity > Course::CREATOR) - # normal_status(-1,"已发布/已截止的不能修发布时间!") #课堂管理员和超级管理员才有权限 end end From 8d2a90a94702ab4b4cc27442b2baafbacf9f68b9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:13:54 +0800 Subject: [PATCH 091/124] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=92=8C=E9=80=80=E5=87=BA=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 13 +++++- .../course_add_student_create_works_job.rb | 41 ++++++++++++++++++- .../course_delete_student_delete_works_job.rb | 16 +++++++- app/models/course_member.rb | 4 +- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d6a86ff50..d7b039e02 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -548,6 +548,7 @@ class CoursesController < ApplicationController course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id) course_student.destroy! course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active + CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) normal_status(0, "退出成功") end @@ -684,11 +685,16 @@ class CoursesController < ApplicationController ActiveRecord::Base.transaction do begin students = params[:students] + student_ids = [] students.each do |student| - course_member = CourseMember.find_by!(id: student[:course_member_id].to_i, course_id: @course.id) - course_member.destroy! + course_member = CourseMember.find_by(id: student[:course_member_id].to_i, course_id: @course.id) + if course_member.present? + student_ids << course_member.user_id + course_member.destroy! + end end + CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present? normal_status(0, "操作成功") rescue => e uid_logger(e.message) @@ -720,6 +726,7 @@ class CoursesController < ApplicationController else new_student.is_active = 0 if existing_course_member.is_active new_student.save! + student_ids << user_id end else new_student.save! @@ -727,6 +734,7 @@ class CoursesController < ApplicationController end end + CourseAddStudentCreateWorksJob.perform_later(@course.id, student_ids) if student_ids.present? TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present? normal_status(0, "添加成功") rescue => e @@ -868,6 +876,7 @@ class CoursesController < ApplicationController new_student.course_group_id = course_group.id if course_group.present? new_student.save! + CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id) end end diff --git a/app/jobs/course_add_student_create_works_job.rb b/app/jobs/course_add_student_create_works_job.rb index 41c3065a1..1631b5b77 100644 --- a/app/jobs/course_add_student_create_works_job.rb +++ b/app/jobs/course_add_student_create_works_job.rb @@ -22,8 +22,45 @@ class CourseAddStudentCreateWorksJob < ApplicationJob attrs = %i[homework_common_id user_id created_at updated_at] StudentWork.bulk_insert(*attrs) do |worker| - student_ids.each do |teacher| - worker.add same_attrs.merge(user_id: teacher.user_id) + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.homework_commons.where(homework_type: %i[normal group practice]).each do |homework| + next if homework.student_works.where(user_id: user_id).any? + worker.add same_attrs.merge(homework_common_id: homework.id) + end + end + end + + attrs = %i[exercise_id user_id created_at updated_at] + ExerciseUser.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.exercises.each do |exercise| + next if exercise.exercise_users.where(user_id: user_id).any? + worker.add same_attrs.merge(exercise_id: exercise.id) + end + end + end + + attrs = %i[poll_id user_id created_at updated_at] + PollUser.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.polls.each do |poll| + next if poll.poll_users.where(user_id: user_id).any? + worker.add same_attrs.merge(poll_id: poll.id) + end + end + end + + attrs = %i[graduation_task_id user_id course_id created_at updated_at] + GraduationWork.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id, course_id: course.id} + course.graduation_tasks.each do |task| + next if task.graduation_works.where(user_id: user_id).any? + worker.add same_attrs.merge(graduation_task_id: task.id) + end end end end diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb index 2eb3fb60e..9bdb93b87 100644 --- a/app/jobs/course_delete_student_delete_works_job.rb +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -1,7 +1,19 @@ class CourseDeleteStudentDeleteWorksJob < ApplicationJob queue_as :course_member - def perform(*args) - # Do something later + def perform(course_id, student_ids) + course = Course.find_by(id: course_id) + return if course.blank? + course = self.course + student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id}) + student_works.update_all(is_delete: 1) + + exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id}) + exercise_users.update_all(is_delete: 1) + + poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id}) + poll_users.update_all(is_delete: 1) + + course.graduation_works.where(user_id: student_ids).update_all(is_delete: 1) end end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index 87d4ffe88..52c13dbbf 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -20,8 +20,8 @@ class CourseMember < ApplicationRecord # 未分班 scope :ungroup_students, -> { where(course_group_id: 0, role: 4) } - after_destroy :delete_works - after_create :work_operation + # after_destroy :delete_works + # after_create :work_operation def delete_works if self.role == "STUDENT" course = self.course From 8828a04432d1e934e06b3ed785a14793516134fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:17:50 +0800 Subject: [PATCH 092/124] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/course_delete_student_delete_works_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb index 9bdb93b87..c12762fbe 100644 --- a/app/jobs/course_delete_student_delete_works_job.rb +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -4,7 +4,7 @@ class CourseDeleteStudentDeleteWorksJob < ApplicationJob def perform(course_id, student_ids) course = Course.find_by(id: course_id) return if course.blank? - course = self.course + student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id}) student_works.update_all(is_delete: 1) From b70179d967f1ea40c98f91d7482289cc7545c662 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:36:20 +0800 Subject: [PATCH 093/124] =?UTF-8?q?=E6=95=B4=E7=BB=84=E5=90=8C=E8=AF=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 5d14a43ea..ef12e5650 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -730,19 +730,19 @@ class StudentWorksController < ApplicationController student_works.each do |st_work| st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score, reviewer_role: new_score.reviewer_role, comment: new_score.comment) - st_work.student_works_scores << st_score - score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id).last + score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id, reviewer_role: new_score.reviewer_role).last # 该用户的历史评阅无效 score.update_column('is_invalid', true) if score.present? && score.score.present? + st_work.student_works_scores << st_score if new_score.reviewer_role == 1 - st_work.teacher_score = new_score.score + st_work.teacher_score = new_score.score if new_score.score.present? elsif new_score.reviewer_role == 2 if homework.homework_detail_manual.ta_mode == 1 - st_work.teaching_asistant_score = new_score.ta_score st_work.id + st_work.teaching_asistant_score = new_score.ta_score st_work.id if new_score.score.present? else - st_work.teaching_asistant_score = new_score.score + st_work.teaching_asistant_score = new_score.score if new_score.score.present? end else st_work.student_score = student_work.student_score From cedb27368ec4314152ff267bd9c042fe357f3413 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 14:40:34 +0800 Subject: [PATCH 094/124] fix bug --- app/controllers/zips_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4089e5231..78151a78a 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -21,7 +21,10 @@ class ZipsController < ApplicationController file_name = filename_for_content_disposition(exercises.filename) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + Rails.logger.info("################___________file_name________________###########{file_name}") + Rails.logger.info("################___________exercises.filename________________###########{exercises.filename}") + + send_file exercises.ex_zip, filename: file_name.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end From 83043baf61bbf95c7cc10d01f1c322f56b066ad8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 14:43:10 +0800 Subject: [PATCH 095/124] fix bug --- app/controllers/zips_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 78151a78a..67c8c74f7 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -10,7 +10,9 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) filename = filename_for_content_disposition(service.filename) - send_file service.zip, filename: filename, type: 'application/zip' + Rails.logger.info("################___________file_name________________###########{filename}") + Rails.logger.info("################___________service.filename________________###########{service.filename}") + send_file service.zip, filename: filename.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) end @@ -21,10 +23,7 @@ class ZipsController < ApplicationController file_name = filename_for_content_disposition(exercises.filename) - Rails.logger.info("################___________file_name________________###########{file_name}") - Rails.logger.info("################___________exercises.filename________________###########{exercises.filename}") - - send_file exercises.ex_zip, filename: file_name.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' + send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end From 495c8d653e40abcf6f4c5f4b575da973f7c271a6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:48:32 +0800 Subject: [PATCH 096/124] =?UTF-8?q?=E5=8A=A9=E6=95=99=E8=AF=84=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index ef12e5650..c85474a10 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -334,7 +334,6 @@ class StudentWorksController < ApplicationController ActiveRecord::Base.transaction do begin # 没传score则取上次评分成绩 - score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id).last new_score = StudentWorksScore.new new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != "" @@ -348,7 +347,9 @@ class StudentWorksController < ApplicationController @work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group" end - new_score.reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 + reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 + new_score.reviewer_role = reviewer_role + score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last if new_score.save! Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class) @@ -740,7 +741,7 @@ class StudentWorksController < ApplicationController st_work.teacher_score = new_score.score if new_score.score.present? elsif new_score.reviewer_role == 2 if homework.homework_detail_manual.ta_mode == 1 - st_work.teaching_asistant_score = new_score.ta_score st_work.id if new_score.score.present? + st_work.teaching_asistant_score = new_score.ta_score st_work.id else st_work.teaching_asistant_score = new_score.score if new_score.score.present? end From f6ae3f329328c1c99104af77506dc22c6b3efbe6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:04:21 +0800 Subject: [PATCH 097/124] fixbug --- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/zips_controller.rb | 5 ++--- app/helpers/export_helper.rb | 15 +++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 519c05c62..d09609bdc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController 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') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode('UTF-8', 'gb2312', {:invalid => :replace, :undef => :replace, :replace => ' '}).strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 67c8c74f7..2b70b9b27 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -10,9 +10,8 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) filename = filename_for_content_disposition(service.filename) - Rails.logger.info("################___________file_name________________###########{filename}") - Rails.logger.info("################___________service.filename________________###########{service.filename}") - send_file service.zip, filename: filename.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' + + send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 839686f5b..7f64a99cd 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -40,10 +40,17 @@ module ExportHelper works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index| w_user = w.user w_1 = (index + 1) - w_2 = w_user.login - w_3 = w_user.real_name - w_3_1 = w_user.mail - w_4 = w_user.student_id.present? ? w_user.student_id : "--" + if w_user.present? + w_2 = w_user&.login + w_3 = w_user&.real_name + w_3_1 = w_user&.mail + w_4 = w_user.student_id.present? ? w_user.student_id : "--" + else + w_2 = "--" + w_3 = "--" + w_3_1 = "--" + w_4 = "--" + end course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" #0: 未提交, 1 按时提交, 2 延迟提交 From bcc66261c61f00e9c89a8412a1dbcc2764bcc711 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:09:03 +0800 Subject: [PATCH 098/124] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d09609bdc..d47ce609c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController 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') - render xlsx: "#{exercise_export_name.encode('UTF-8', 'gb2312', {:invalid => :replace, :undef => :replace, :replace => ' '}).strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode("GBK", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end From 76646a3fbcd723f1aa58c5157afa8ee357e14b09 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:12:00 +0800 Subject: [PATCH 099/124] =?UTF-8?q?xlsx=E4=B8=8B=E8=BD=BD=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d47ce609c..794ccb228 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,9 +208,11 @@ class HomeworkCommonsController < ApplicationController 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') - render xlsx: "#{exercise_export_name.encode("GBK", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode(Encoding.default_external,"UTF-8", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } + + # .encode(Encoding.default_external, 'gb2312') end end elsif params[:format] == "zip" From 61f36ea2379deeabac7792e922872502e58d4a1f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 15:17:01 +0800 Subject: [PATCH 100/124] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=BC=BA=E8=AF=84?= =?UTF-8?q?=E6=89=A3=E5=88=86=E7=9A=84=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/homework_evaluation.rake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index 56c46179c..757b07877 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -60,9 +60,9 @@ namespace :homework_evaluation do HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id) else homework_detail_manual.update_column('comment_status', 5) + # 没有申诉阶段则直接计算缺评扣分 否则申诉结束时才计算 + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end - - HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end end end @@ -71,5 +71,8 @@ namespace :homework_evaluation do task :end_appeal => :environment do homework_detail_manuals = HomeworkDetailManual.where("appeal_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 4") homework_detail_manuals.update_all(:comment_status => 5) + homework_detail_manuals.each do |homework_detail_manual| + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_detail_manual.homework_common_id) + end end end From 425a32680adbd8e7caa04804045ef0927adc8fa3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 15:35:37 +0800 Subject: [PATCH 101/124] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d7b039e02..0679e5619 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -284,7 +284,7 @@ class CoursesController < ApplicationController @is_admin = @user_course_identity < Course::PROFESSOR - @applications= CourseMessage.unhandled_join_course_requests_by_course(@course) + @applications = @is_admin ? CourseMessage.unhandled_join_course_requests_by_course(@course) : CourseMessage.none page = params[:page] || 1 limit = params[:limit] || 20 From df246f245c329c9a6a786455534a5adcb6bbcff5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 15:36:24 +0800 Subject: [PATCH 102/124] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 13 ++++++++++--- .../code_review_detail.json.jbuilder | 18 ------------------ .../get_challenge_detail.json.jbuilder | 17 +++++++++++++++++ config/routes.rb | 1 + 4 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 app/views/homework_commons/get_challenge_detail.json.jbuilder diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 519c05c62..06326fe72 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -11,14 +11,14 @@ class HomeworkCommonsController < ApplicationController before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, - :update_score, :update_student_score] + :update_score, :update_student_score, :get_challenge_detail] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :update_explanation, :update_settings, - :add_to_homework_bank, :publish_groups, :end_groups] + :add_to_homework_bank, :publish_groups, :end_groups, :get_challenge_detail] before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category, :add_to_homework_bank] before_action :course_manager, only: [:alter_name] @@ -1342,7 +1342,14 @@ class HomeworkCommonsController < ApplicationController end - # 代码查重详情 + # 代码查重关卡详情 + def get_challenge_detail + @student_work = @homework.student_works.find_by(user_id: params[:user_id]) + @user = @student_work.user + tip_exception("当前用户无作品可以显示") if @student_work.nil? + end + + # 代码查重代码的详情 def code_review_detail @student_work = @homework.student_works.find_by(user_id: params[:user_id]) @user = @student_work.user diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 4ebabf20a..916e77c0f 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -1,21 +1,3 @@ -json.course_id @course.id -json.course_name @course.name -json.homework_common_id @homework.id -json.homework_common_name @homework.name -json.work_name @student_work.name -json.username @user.full_name -json.user_id @user.id -json.user_login @user.login - -json.work_score @student_work.work_score -if @student_work.ultimate_score - json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -else - json.final_score @student_work.final_score - json.late_penalty @student_work.late_penalty - json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -end - json.challenge_list do json.array! @challenges do |challenge| json.id challenge[:id] diff --git a/app/views/homework_commons/get_challenge_detail.json.jbuilder b/app/views/homework_commons/get_challenge_detail.json.jbuilder new file mode 100644 index 000000000..d3d6c2c1e --- /dev/null +++ b/app/views/homework_commons/get_challenge_detail.json.jbuilder @@ -0,0 +1,17 @@ +json.course_id @course.id +json.course_name @course.name +json.homework_common_id @homework.id +json.homework_common_name @homework.name +json.work_name @student_work.name +json.username @user.full_name +json.user_id @user.id +json.user_login @user.login + +json.work_score @student_work.work_score +if @student_work.ultimate_score + json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +else + json.final_score @student_work.final_score + json.late_penalty @student_work.late_penalty + json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cf5bad608..395ce0ef9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -337,6 +337,7 @@ Rails.application.routes.draw do post :homework_code_repeat get :code_review_results get :code_review_detail + get :get_challenge_detail post :update_explanation get :show_comment get :settings From 118d27c649cbc0642247d3b1638c4c5a27ec2cff Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:45:15 +0800 Subject: [PATCH 103/124] fix bug --- app/controllers/homework_commons_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 794ccb228..1318f3b04 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -204,15 +204,17 @@ class HomeworkCommonsController < ApplicationController normal_status(-1,"暂无用户提交!") else respond_to do |format| + format.json{normal_status(0,"000000")} format.xlsx{ 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') - - render xlsx: "#{exercise_export_name.encode(Encoding.default_external,"UTF-8", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + response.headers['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" + 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} } + # send_data data, :type => 'text/csv', :disposition => 'attachment; filename=my_file_name.csv' - # .encode(Encoding.default_external, 'gb2312') + # .encode(Encoding.default_external, 'gb2312') end end elsif params[:format] == "zip" From 82b0f0f0f5cc1683955c32741ba25d82137ab542 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 15:53:26 +0800 Subject: [PATCH 104/124] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 11 ++--------- .../code_review_detail.json.jbuilder | 18 ++++++++++++++++++ .../get_challenge_detail.json.jbuilder | 17 ----------------- config/routes.rb | 1 - 4 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 app/views/homework_commons/get_challenge_detail.json.jbuilder diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 025218424..f0703d1f0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -11,14 +11,14 @@ class HomeworkCommonsController < ApplicationController before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, - :update_score, :update_student_score, :get_challenge_detail] + :update_score, :update_student_score] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :update_explanation, :update_settings, - :add_to_homework_bank, :publish_groups, :end_groups, :get_challenge_detail] + :add_to_homework_bank, :publish_groups, :end_groups] before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category, :add_to_homework_bank] before_action :course_manager, only: [:alter_name] @@ -1346,13 +1346,6 @@ class HomeworkCommonsController < ApplicationController end - # 代码查重关卡详情 - def get_challenge_detail - @student_work = @homework.student_works.find_by(user_id: params[:user_id]) - @user = @student_work.user - tip_exception("当前用户无作品可以显示") if @student_work.nil? - end - # 代码查重代码的详情 def code_review_detail @student_work = @homework.student_works.find_by(user_id: params[:user_id]) diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 916e77c0f..4ebabf20a 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -1,3 +1,21 @@ +json.course_id @course.id +json.course_name @course.name +json.homework_common_id @homework.id +json.homework_common_name @homework.name +json.work_name @student_work.name +json.username @user.full_name +json.user_id @user.id +json.user_login @user.login + +json.work_score @student_work.work_score +if @student_work.ultimate_score + json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +else + json.final_score @student_work.final_score + json.late_penalty @student_work.late_penalty + json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +end + json.challenge_list do json.array! @challenges do |challenge| json.id challenge[:id] diff --git a/app/views/homework_commons/get_challenge_detail.json.jbuilder b/app/views/homework_commons/get_challenge_detail.json.jbuilder deleted file mode 100644 index d3d6c2c1e..000000000 --- a/app/views/homework_commons/get_challenge_detail.json.jbuilder +++ /dev/null @@ -1,17 +0,0 @@ -json.course_id @course.id -json.course_name @course.name -json.homework_common_id @homework.id -json.homework_common_name @homework.name -json.work_name @student_work.name -json.username @user.full_name -json.user_id @user.id -json.user_login @user.login - -json.work_score @student_work.work_score -if @student_work.ultimate_score - json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -else - json.final_score @student_work.final_score - json.late_penalty @student_work.late_penalty - json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 395ce0ef9..cf5bad608 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -337,7 +337,6 @@ Rails.application.routes.draw do post :homework_code_repeat get :code_review_results get :code_review_detail - get :get_challenge_detail post :update_explanation get :show_comment get :settings From 1a2067698c97622947cc7e5741fb138cbe84a0c1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 16:06:19 +0800 Subject: [PATCH 105/124] fixbug --- app/controllers/homework_commons_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 1318f3b04..cfa54e721 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -204,17 +204,14 @@ class HomeworkCommonsController < ApplicationController normal_status(-1,"暂无用户提交!") else respond_to do |format| - format.json{normal_status(0,"000000")} format.xlsx{ 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') - response.headers['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" + response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" 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} } - # send_data data, :type => 'text/csv', :disposition => 'attachment; filename=my_file_name.csv' - - # .encode(Encoding.default_external, 'gb2312') end end elsif params[:format] == "zip" From 457b4fdf0f1f3b836c66b7c067dfc39013993fa5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 16:28:58 +0800 Subject: [PATCH 106/124] =?UTF-8?q?=E5=8C=BF=E8=AF=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index c85474a10..ed642a557 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -382,7 +382,7 @@ class StudentWorksController < ApplicationController when 3 #学生评分 学生评分显示平均分 # 匿评分 @work.student_score = new_score.stu_score(@work.id) - if @homework.homework_type == "group" && params[:same_score] && new_score.score.present? + if @homework.homework_type == "group" && new_score.score.present? add_score_to_member @work, @homework, new_score end From 0a7715cbc5b5ba001ded6ebae35aa0c1351654c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 16:44:52 +0800 Subject: [PATCH 107/124] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E9=94=81?= =?UTF-8?q?=E6=A0=87=E5=BF=97=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 55ade6e7c..6e3ef835e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -260,6 +260,7 @@ module ExercisesHelper def exercise_index_show(exercise,course,is_teacher_or,user) # exercise_all_users = exercise.exercise_users + # lock_icon 0不出现锁,1和2均出现锁。但是1仅表示私有,可点击,2表示私有,且不点击 ex_show_text = [] if course.is_end #课堂停止后,试卷显示为已结束 @@ -280,6 +281,7 @@ module ExercisesHelper else ex_show_text end + if is_teacher_or == 1 exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生 unreview_count = exercise_users_list.exercise_unreview.size @@ -288,7 +290,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = 3 - lock_icon = 1 #不显示锁图标 + lock_icon = 1 if exercise_status == 1 ex_show_text.push("未发布") elsif exercise_status == 3 @@ -302,7 +304,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = exercise.check_user_answer_status(user) - lock_icon = 1 #不显示锁图标 + lock_icon = 1 if current_status == 4 ex_show_text.push("未提交") end @@ -314,16 +316,20 @@ module ExercisesHelper unreview_count = nil if exercise.is_public current_status = exercise.check_user_answer_status(user) - lock_icon = 1 #非课堂成员,但是试卷为公开的,不加锁 + lock_icon = 0 #不出现锁 if current_status == 4 ex_show_text.push("未提交") end else current_status = 4 - lock_icon = 0 #显示锁图标 + lock_icon = 2 end end + if (course.is_public == 1) && exercise.is_public + lock_icon = 0 + end + if exercise_status > 1 show_unreview_count = unreview_count else @@ -332,8 +338,6 @@ module ExercisesHelper if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) - # elsif exercise_status == 3 && course.end_date.present? - # ex_left_time = how_much_time(course.end_date.to_time) else #已截止后不显示时间 ex_left_time = nil end From ddd24d9acaa50c43d904cbde28db9da4683e8a55 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 17:43:05 +0800 Subject: [PATCH 108/124] fix bug --- app/controllers/exercises_controller.rb | 13 +++++----- .../homework_commons_controller.rb | 3 ++- app/helpers/exercises_helper.rb | 24 +++++++++---------- app/models/exercise.rb | 10 ++++---- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 49dd7edb9..c017d4dc1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -44,25 +44,24 @@ class ExercisesController < ApplicationController # exercises的不同用户群体的显示 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 @is_teacher_or = 1 - # @teacher_groups_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?) - @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) + @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 # get_exercise_left_time(@exercise,current_user) member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) - @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id exercise_settings_ids = @course.exercise_group_settings.exercise_group_published .where(course_group_id: member_group_id).pluck(:exercise_id).uniq - @exercises = member_show_exercises.present? ? + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 - @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] end if @exercises.size > 0 if params[:type].present? @@ -74,12 +73,12 @@ class ExercisesController < ApplicationController exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq if choose_type == 2 - @exercises = @exercises_all.present? ? + @exercises = @exercises_all.exists? ? @exercises_all.exercise_by_status(2).unified_setting .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) : [] elsif choose_type == 3 - @exercises = @exercises_all.present? ? + @exercises = @exercises_all.exists? ? @exercises_all.exercise_by_status(3).unified_setting .or(@exercises_all.where(id: exercise_ended_ids)) : [] diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bd7a36e98..a04d2b1a8 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,8 +208,9 @@ class HomeworkCommonsController < ApplicationController 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') response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6e3ef835e..96507d002 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -251,16 +251,14 @@ module ExercisesHelper #获取试卷的已答/未答人数 def get_exercise_answers(ex_users) - @commit_ex_users = ex_users.commit_exercise_by_status(1) #当前老师的全部学生中已提交的 - - @exercise_answers = @commit_ex_users.present? ? @commit_ex_users.size : 0 #表示已经提交了的用户 - course_all_members_count = ex_users.present? ? ex_users.size : 0 + @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 + course_all_members_count = ex_users.exists? ? ex_users.size : 0 @exercise_unanswers = (course_all_members_count - @exercise_answers) end def exercise_index_show(exercise,course,is_teacher_or,user) # exercise_all_users = exercise.exercise_users - # lock_icon 0不出现锁,1和2均出现锁。但是1仅表示私有,可点击,2表示私有,且不点击 + # lock_icon 0出现锁,1不出现锁 ex_show_text = [] if course.is_end #课堂停止后,试卷显示为已结束 @@ -290,7 +288,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = 3 - lock_icon = 1 + lock_icon = 0 if exercise_status == 1 ex_show_text.push("未发布") elsif exercise_status == 3 @@ -304,7 +302,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = exercise.check_user_answer_status(user) - lock_icon = 1 + lock_icon = 0 if current_status == 4 ex_show_text.push("未提交") end @@ -316,18 +314,18 @@ module ExercisesHelper unreview_count = nil if exercise.is_public current_status = exercise.check_user_answer_status(user) - lock_icon = 0 #不出现锁 + lock_icon = 1 #不出现锁 if current_status == 4 ex_show_text.push("未提交") end else current_status = 4 - lock_icon = 2 + lock_icon = 0 end end if (course.is_public == 1) && exercise.is_public - lock_icon = 0 + lock_icon = 1 end if exercise_status > 1 @@ -336,7 +334,7 @@ module ExercisesHelper show_unreview_count = nil end - if exercise_status == 2 && exercise_end_time.present? + if exercise_status == 2 && exercise_end_time.exists? ex_left_time = how_much_time(exercise_end_time) else #已截止后不显示时间 ex_left_time = nil @@ -725,8 +723,8 @@ module ExercisesHelper if ex_time > 0 exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 - exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 - exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 + exercise_end_time = exercise.end_time.exists? ? exercise.end_time.to_i : 0 + exercise_user_start = exercise_user&.start_at.exists? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 if (exercise_end_time - time_now_i) > time_mill diff --git a/app/models/exercise.rb b/app/models/exercise.rb index ed003286b..d6e9269cc 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -130,11 +130,11 @@ class Exercise < ApplicationRecord else ex_group_setting = exercise_group_settings user_group = course.students.course_find_by_ids("user_id",user_id) - if user_group.present? + if user_group.exists? user_group_id = user_group.first.course_group_id user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) - pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil - en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil + pb_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.publish_time : nil + en_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.end_time : nil else pb_time = nil en_time = nil @@ -152,10 +152,10 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.find_by(user_id: user.id) user_ex_status = get_exercise_status(user.id) user_status = 2 - if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.exists? && (ex_answer_user.start_at.exists? || ex_answer_user.end_at.exists?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.commit_status end - if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 + if ex_answer_user.exists? && ex_answer_user.start_at.blank? && user_ex_status == 3 user_status = 4 end From 16f53062ee3ccba69d0ba82699a9c6a7cc522ae6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 18:00:35 +0800 Subject: [PATCH 109/124] fixbug --- app/controllers/exercises_controller.rb | 13 ++++--- .../homework_commons_controller.rb | 4 +- app/views/exercises/index.json.jbuilder | 37 ++++++++++--------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c017d4dc1..7426a40d5 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -32,13 +32,9 @@ class ExercisesController < ApplicationController @exercises_all = @course.exercises member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 @current_user_ = current_user - @exercises_count = @exercises_all.size # 全部页面,需返回 - @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 - @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 - @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 + # 课堂的学生人数 @course_all_members = @course.students #当前课堂的全部学生 - @course_all_members_count = @course_all_members.size #当前课堂的学生数 @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 # exercises的不同用户群体的显示 @@ -63,6 +59,7 @@ class ExercisesController < ApplicationController @is_teacher_or = 0 @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] end + if @exercises.size > 0 if params[:type].present? choose_type = params[:type].to_i @@ -105,6 +102,12 @@ class ExercisesController < ApplicationController @exercises = [] end + @course_all_members_count = @course_all_members.size #当前课堂的学生数 + @exercises_count = @exercises_all.size # 全部页面,需返回 + @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 + @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 + @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index a04d2b1a8..355a8d8e3 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -207,8 +207,8 @@ class HomeworkCommonsController < ApplicationController format.xlsx{ 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') - response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") - file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) + # response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + file_name = Base64.encode64(exercise_export_name.strip.first(30)) # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index 4694ecdf0..4c143da4b 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -1,22 +1,4 @@ -json.exercises_counts do - json.exercises_total_counts @exercises_count #全部试卷数 - json.exercises_all_counts @exercises_select_count #选择后的全部试卷数 - json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数 - json.exercises_published_counts @exercises_published_counts #已发布试卷数 - json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 - json.left_banner_id @left_banner_id - json.left_banner_name @left_banner_name -end - -json.course_types do - json.course_status @course.is_end ? 1 : 0 #课堂的当前是否结束,如结束,则为1,否则为0 - json.course_end_time @course.end_date #课堂的截止时间 - json.course_is_public @course.is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 - json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 -end - - if @exercises_count > 0 json.exercises do json.array! @exercises do |exercise| @@ -43,3 +25,22 @@ else json.exercises [] end +json.course_types do + json.course_status @course.is_end ? 1 : 0 #课堂的当前是否结束,如结束,则为1,否则为0 + json.course_end_time @course.end_date #课堂的截止时间 + json.course_is_public @course.is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 + json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 +end + +json.exercises_counts do + json.exercises_total_counts @exercises_count #全部试卷数 + json.exercises_all_counts @exercises_select_count #选择后的全部试卷数 + json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数 + json.exercises_published_counts @exercises_published_counts #已发布试卷数 + json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 + json.left_banner_id @left_banner_id + json.left_banner_name @left_banner_name +end + + + From 9b8887fa0f217efb16b980d75606445c78c20b10 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 18:09:44 +0800 Subject: [PATCH 110/124] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 96507d002..fe29497d0 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -334,7 +334,7 @@ module ExercisesHelper show_unreview_count = nil end - if exercise_status == 2 && exercise_end_time.exists? + if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) else #已截止后不显示时间 ex_left_time = nil From f6a6a5e98da0a15cfcd718bcff6d4c981d69f6f6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 18:21:22 +0800 Subject: [PATCH 111/124] fixbug --- app/controllers/exercises_controller.rb | 3 +-- app/models/exercise.rb | 12 ++---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 7426a40d5..9087aeee6 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -105,8 +105,7 @@ class ExercisesController < ApplicationController @course_all_members_count = @course_all_members.size #当前课堂的学生数 @exercises_count = @exercises_all.size # 全部页面,需返回 @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 - @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 - @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 + @exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的 rescue Exception => e uid_logger_error(e.message) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index d6e9269cc..42b737c26 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -69,11 +69,7 @@ class Exercise < ApplicationRecord def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - if course.none_group_count > 0 #有未分班的,则发布到未发布分班 - un_group_ids = [0] - else - un_group_ids = [] - end + un_group_ids = (course.none_group_count > 0) ? [0] : [] published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 else ex_group_setting = exercise_group_settings.pluck("course_group_id").uniq @@ -89,11 +85,7 @@ class Exercise < ApplicationRecord ex_group_settings = exercise_group_settings.pluck(:course_group_id) member = course.course_members.course_find_by_ids("user_id",user_id) member_group_id = member.pluck(:course_group_id).uniq - if (member_group_id & ex_group_settings).size > 0 || user_identity < Course::STUDENT - true - else - false - end + ((member_group_id & ex_group_settings).size > 0 || user_identity < Course::STUDENT) ? true : false end #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 From ade4ffb7076f521c8b6653a6dd2b1f8d82c22e1b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 20:52:31 +0800 Subject: [PATCH 112/124] fixbug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 355a8d8e3..b12980094 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController 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') # response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") - file_name = Base64.encode64(exercise_export_name.strip.first(30)) + file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} From fe77865779b79b87b42843aa3484209325b71a3f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 6 Jul 2019 09:01:15 +0800 Subject: [PATCH 113/124] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E5=8A=A0=E5=85=A5sec?= =?UTF-8?q?=5Fkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- app/controllers/gits_controller.rb | 9 +++++++-- app/controllers/myshixuns_controller.rb | 8 +++----- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 5 +++++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705085829_add_sec_key_to_outputs.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 7e7b6e082..41af7ae68 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -501,6 +501,7 @@ class GamesController < ApplicationController # 编程题评测 def game_build + sec_key = params[:sec_key] game_challenge = Challenge.select([:id, :position, :picture_path]).find(@game.challenge_id) # 更新评测次数 @@ -548,7 +549,7 @@ class GamesController < ApplicationController :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", - :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", + :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key, :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index f00245190..1965f61ba 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -1,10 +1,15 @@ class GitsController < ApplicationController - #供git-workhorse反向调用认证 + # 说明: + # 以下Git认证只针对新版git,Gitlab的Git认证不走该控制器 + # 思路: + # 1、用户通过Git客户端推送代码的时候,这个时候Git客户端肯定会强制用户输入邮箱的 + # 2、通过web端版本库界面更新代码(如果用户邮箱不存在,则用系统备用邮箱) + # 供 git-workhorse反向调用认证 def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") - #logger.info("#########-----request_env: #{request.env}") + # logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} # diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3abc71fd0..499612167 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -85,9 +85,6 @@ class MyshixunsController < ApplicationController # "createPod":"1.610","evaluateAllTime":2820,"evaluateStart":"2017-11-24 11:04:35","execute":"0.294"}' # params[:pics] = "a.png,b.png,c.png" def training_task_status - logger.info("123################{params[:jsonTestDetails]}") - logger.info("456################{params[:timeCost]}") - logger.info("666###############{params}") ActiveRecord::Base.transaction do begin @@ -98,13 +95,14 @@ class MyshixunsController < ApplicationController return_back_time = format("%.3f", ( t1.to_f - brige_end_time.to_f)).to_f status = jsonTestDetails['status'] game_id = jsonTestDetails['buildID'] + sec_key = jsonTestDetails['sec_key'] logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? - logger.info(outPut) + game = Game.find(game_id) myshixun = game.myshixun challenge = game.challenge @@ -125,7 +123,7 @@ class MyshixunsController < ApplicationController logger.info "actual_output:################################################# #{actual_output}" Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, - :compile_success => compile_success.to_i) + :compile_success => compile_success.to_i, :sec_key => sec_key) # 如果设置了按测试集给分,则需要统计测试集的分值 if challenge.test_set_score && j_test_set['passed'].to_i == 1 test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb new file mode 100644 index 000000000..428fbaced --- /dev/null +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -0,0 +1,5 @@ +class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :sec_key, :string + end +end From e6999da273e6b1850297ec1504d6bc16b6aed3e2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 09:19:47 +0800 Subject: [PATCH 114/124] user interest api --- app/controllers/users/interests_controller.rb | 25 +++++++++++++++++++ app/models/repertoire.rb | 1 + app/models/user.rb | 4 +++ app/models/user_interest.rb | 4 +++ config/routes.rb | 1 + .../20190706010307_create_user_interests.rb | 8 ++++++ 6 files changed, 43 insertions(+) create mode 100644 app/controllers/users/interests_controller.rb create mode 100644 app/models/user_interest.rb create mode 100644 db/migrate/20190706010307_create_user_interests.rb diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb new file mode 100644 index 000000000..ca5f63af9 --- /dev/null +++ b/app/controllers/users/interests_controller.rb @@ -0,0 +1,25 @@ +class Users::InterestsController < Users::BaseController + before_action :require_login + before_action :private_user_resources! + + def create + identity = params[:identity].to_s.strip + + extension = observed_user.user_extension || observed_user.build_user_extension + return render_error('请选择职业') unless %w(teacher student professional).include?(identity) + + ActiveRecord::Base.transaction do + extension.update_column(:identity, identity) + + # 兴趣 + observed_user.user_interests.delete_all + UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker| + (Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id| + worker.add(user_id: observed_user.id, repertoire_id: repertoire_id) + end + end + end + + render_ok + end +end \ No newline at end of file diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index d76a022c5..72e1ebfff 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -2,4 +2,5 @@ class Repertoire < ApplicationRecord has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy has_many :tag_repertoires, through: :sub_repertoires + has_many :user_interests, dependent: :delete_all end diff --git a/app/models/user.rb b/app/models/user.rb index e775af5f8..7e04ff423 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -115,6 +115,10 @@ class User < ApplicationRecord has_many :attendances + # 兴趣 + has_many :user_interests, dependent: :delete_all + has_many :interests, through: :user_interests, source: :repertoire + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } diff --git a/app/models/user_interest.rb b/app/models/user_interest.rb new file mode 100644 index 000000000..bdb6e77d4 --- /dev/null +++ b/app/models/user_interest.rb @@ -0,0 +1,4 @@ +class UserInterest < ApplicationRecord + belongs_to :user + belongs_to :repertoire +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cf5bad608..f0123d95b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,7 @@ Rails.application.routes.draw do resource :experience_records, only: [:show] resource :grade_records, only: [:show] resource :watch, only: [:create, :destroy] + resource :interest, only: [:create] end diff --git a/db/migrate/20190706010307_create_user_interests.rb b/db/migrate/20190706010307_create_user_interests.rb new file mode 100644 index 000000000..d64a1c228 --- /dev/null +++ b/db/migrate/20190706010307_create_user_interests.rb @@ -0,0 +1,8 @@ +class CreateUserInterests < ActiveRecord::Migration[5.2] + def change + create_table :user_interests do |t| + t.references :user + t.references :repertoire + end + end +end From 7b8555c51b7d319b34f5974b1762018720a9a1ba Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 6 Jul 2019 09:36:33 +0800 Subject: [PATCH 115/124] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=82=AE=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 0d32926e4..e5d9ba5c4 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -151,6 +151,8 @@ class AccountsController < ApplicationController send_type = verify_type(login_type, type) verification_code = code.sample(6).join + logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ") + # 记录验证码 check_verification_code(verification_code, send_type, value) sucess_status From a13dc35905dddfebf99bb83220c3d36a89fc8832 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 10:05:45 +0800 Subject: [PATCH 116/124] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/course_add_student_create_works_job.rb | 2 +- app/jobs/course_delete_student_delete_works_job.rb | 2 +- app/jobs/graduation_task_cross_comment_job.rb | 2 +- app/jobs/homework_absence_penalty_calculation_job.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 2 +- app/jobs/homework_evaluation_comment_assgin_job.rb | 2 +- app/jobs/homework_publish_update_work_status_job.rb | 2 +- config/sidekiq.yml | 3 --- 8 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/jobs/course_add_student_create_works_job.rb b/app/jobs/course_add_student_create_works_job.rb index 1631b5b77..d8bd6363c 100644 --- a/app/jobs/course_add_student_create_works_job.rb +++ b/app/jobs/course_add_student_create_works_job.rb @@ -1,6 +1,6 @@ # 学生加入课堂时创建相关任务作品 class CourseAddStudentCreateWorksJob < ApplicationJob - queue_as :course_member + queue_as :default def perform(course_id, student_ids) course = Course.find_by(id: course_id) diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb index c12762fbe..a84608b2c 100644 --- a/app/jobs/course_delete_student_delete_works_job.rb +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -1,5 +1,5 @@ class CourseDeleteStudentDeleteWorksJob < ApplicationJob - queue_as :course_member + queue_as :default def perform(course_id, student_ids) course = Course.find_by(id: course_id) diff --git a/app/jobs/graduation_task_cross_comment_job.rb b/app/jobs/graduation_task_cross_comment_job.rb index 64973a3e9..cf2cb613e 100644 --- a/app/jobs/graduation_task_cross_comment_job.rb +++ b/app/jobs/graduation_task_cross_comment_job.rb @@ -1,6 +1,6 @@ # 毕设任务的交叉评阅分配 class GraduationTaskCrossCommentJob < ApplicationJob - queue_as :evaluation_comment + queue_as :default def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb index 6e80f2330..02836d9ec 100644 --- a/app/jobs/homework_absence_penalty_calculation_job.rb +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -1,5 +1,5 @@ class HomeworkAbsencePenaltyCalculationJob < ApplicationJob - queue_as :score + queue_as :default def perform(homework_common_id) homework_common = HomeworkCommon.find_by(id: homework_common_id) diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index 649a5c37a..4ba4502fc 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -1,6 +1,6 @@ class HomeworkEndUpdateScoreJob < ApplicationJob # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 - queue_as :score + queue_as :default def perform(homework_id) homework = HomeworkCommon.find_by(id: homework_id) diff --git a/app/jobs/homework_evaluation_comment_assgin_job.rb b/app/jobs/homework_evaluation_comment_assgin_job.rb index 5921386f2..25a7f0a24 100644 --- a/app/jobs/homework_evaluation_comment_assgin_job.rb +++ b/app/jobs/homework_evaluation_comment_assgin_job.rb @@ -1,5 +1,5 @@ class HomeworkEvaluationCommentAssginJob < ApplicationJob - queue_as :evaluation_comment + queue_as :default def get_assigned_homeworks(student_works, n, index) student_works += student_works diff --git a/app/jobs/homework_publish_update_work_status_job.rb b/app/jobs/homework_publish_update_work_status_job.rb index fe03a3ac5..0060ab270 100644 --- a/app/jobs/homework_publish_update_work_status_job.rb +++ b/app/jobs/homework_publish_update_work_status_job.rb @@ -1,6 +1,6 @@ class HomeworkPublishUpdateWorkStatusJob < ApplicationJob # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 - queue_as :score + queue_as :default def perform(group_ids, homework_id) # Do something later diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 93e89b4dc..a2b3fc0be 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -3,7 +3,4 @@ :logfile: log/sidekiq.log :queues: - [default, 3] - - [score, 4] - - [evaluation_comment, 5] - - [course_member, 6] - [notify, 100] \ No newline at end of file From 3f3f7ed8544d67014f6323d12c412061cd216ead Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 10:06:09 +0800 Subject: [PATCH 117/124] fix interest --- app/controllers/users/interests_controller.rb | 8 ++++---- config/routes.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb index ca5f63af9..93836fd63 100644 --- a/app/controllers/users/interests_controller.rb +++ b/app/controllers/users/interests_controller.rb @@ -1,21 +1,21 @@ class Users::InterestsController < Users::BaseController + skip_before_action :check_observed_user_exists! before_action :require_login - before_action :private_user_resources! def create identity = params[:identity].to_s.strip - extension = observed_user.user_extension || observed_user.build_user_extension + extension = current_user.user_extension || current_user.build_user_extension return render_error('请选择职业') unless %w(teacher student professional).include?(identity) ActiveRecord::Base.transaction do extension.update_column(:identity, identity) # 兴趣 - observed_user.user_interests.delete_all + current_user.user_interests.delete_all UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker| (Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id| - worker.add(user_id: observed_user.id, repertoire_id: repertoire_id) + worker.add(user_id: current_user.id, repertoire_id: repertoire_id) end end end diff --git a/config/routes.rb b/config/routes.rb index f0123d95b..74eaa7bed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,7 +47,6 @@ Rails.application.routes.draw do resource :experience_records, only: [:show] resource :grade_records, only: [:show] resource :watch, only: [:create, :destroy] - resource :interest, only: [:create] end @@ -78,6 +77,7 @@ Rails.application.routes.draw do resource :auth_attachment, only: [:update] resource :authentication_apply, only: [:create] resource :professional_auth_apply, only: [:create] + resource :interest, only: [:create] end end end From 508d24af2c8f350f2c99fe0376f7d9415071cc22 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 10:10:24 +0800 Subject: [PATCH 118/124] fix trial apply --- app/controllers/concerns/controller_rescue_handler.rb | 3 +++ app/controllers/ecs/base_controller.rb | 9 --------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index e9563d1e5..31934db03 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -12,5 +12,8 @@ module ControllerRescueHandler rescue_from ActiveModel::ValidationError do |ex| render_error(ex.model.errors.full_messages.join(',')) end + rescue_from ActiveRecord::RecordInvalid do |ex| + render_error(ex.record.errors.full_messages.join(',')) + end end end \ No newline at end of file diff --git a/app/controllers/ecs/base_controller.rb b/app/controllers/ecs/base_controller.rb index ad11682c3..9fb99c420 100644 --- a/app/controllers/ecs/base_controller.rb +++ b/app/controllers/ecs/base_controller.rb @@ -1,14 +1,5 @@ class Ecs::BaseController < ApplicationController - # model validation error - rescue_from ActiveRecord::RecordInvalid do |ex| - render_error(ex.record.errors.full_messages.join(',')) - end - # form validation error - rescue_from ActiveModel::ValidationError do |ex| - render_error(ex.model.errors.full_messages.join(',')) - end - before_action :require_login before_action :check_user_permission! From 24a0c43d1627cf5cf31ac616784332331f3ca7bf Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 10:19:57 +0800 Subject: [PATCH 119/124] repertoires name list --- app/controllers/repertoires_controller.rb | 5 +++++ app/models/repertoire.rb | 19 +++++++++++++++++++ config/routes.rb | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 app/controllers/repertoires_controller.rb diff --git a/app/controllers/repertoires_controller.rb b/app/controllers/repertoires_controller.rb new file mode 100644 index 000000000..0ac78a15b --- /dev/null +++ b/app/controllers/repertoires_controller.rb @@ -0,0 +1,5 @@ +class RepertoiresController < ApplicationController + def index + render_ok(repertoires: Repertoire.cache_data) + end +end \ No newline at end of file diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 72e1ebfff..140416658 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -3,4 +3,23 @@ class Repertoire < ApplicationRecord has_many :tag_repertoires, through: :sub_repertoires has_many :user_interests, dependent: :delete_all + + after_create_commit :reset_cache_data + after_update_commit :reset_cache_data + + def self.cache_data + Rails.cache.fetch(data_cache_key, expires_in: 1.days) do + Repertoire.select(:id, :name).order(:created_at).as_json + end + end + + def self.data_cache_key + 'repertoire/cache_data' + end + + private + + def reset_cache_data + Rails.cache.delete(self.class.data_cache_key) + end end diff --git a/config/routes.rb b/config/routes.rb index 74eaa7bed..d3d04edfb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -661,6 +661,8 @@ Rails.application.routes.draw do get :export_exercises end end + + resources :repertoires, only: [:index] end #git 认证回调 From fe990abc607c24e1e0b12d4bcb000f4550e971e4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 10:21:18 +0800 Subject: [PATCH 120/124] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8F=8A=E5=AF=BC=E5=87=BA=E7=9A=84=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 +- app/controllers/exercises_controller.rb | 84 ++++++++++++------- .../graduation_tasks_controller.rb | 5 +- .../graduation_topics_controller.rb | 5 +- .../homework_commons_controller.rb | 4 +- app/controllers/polls_controller.rb | 6 +- app/controllers/zips_controller.rb | 8 +- app/helpers/polls_helper.rb | 7 +- app/models/exercise.rb | 4 +- .../batch_export_shixun_report_service.rb | 2 +- app/services/export_exercises_service.rb | 2 +- 11 files changed, 78 insertions(+), 52 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0679e5619..cb2b8d201 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -993,7 +993,8 @@ class CoursesController < ApplicationController normal_status(-1,"课堂暂时没有学生") else 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}_全部成绩" + filename = Base64.urlsafe_encode64(filename_) 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, course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9087aeee6..6d0adef27 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -23,7 +23,6 @@ class ExercisesController < ApplicationController before_action :commit_shixun_present,only: [:commit_shixun] include ExportHelper include ExercisesHelper - # require 'pdfkit' def index ActiveRecord::Base.transaction do @@ -43,46 +42,65 @@ class ExercisesController < ApplicationController @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 - # get_exercise_left_time(@exercise,current_user) - member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 - if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) + @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 + if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id - exercise_settings_ids = @course.exercise_group_settings.exercise_group_published - .where(course_group_id: member_group_id).pluck(:exercise_id).uniq - @exercises = member_show_exercises.exists? ? - member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) - : [] + not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id) + @exercises = member_show_exercises.where.not(id: not_exercise_ids) + # exercise_settings_ids = @course.exercise_group_settings.exercise_group_published + # .where(course_group_id: member_group_id).pluck(:exercise_id).uniq + # @exercises = member_show_exercises.exists? ? + # member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) + # : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 - @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] + @exercises = member_show_exercises.unified_setting end if @exercises.size > 0 if params[:type].present? choose_type = params[:type].to_i - member_group_id = @current_student.first.try(:course_group_id).to_i - if @is_teacher_or == 2 && member_group_id > 0 - exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) - .exercise_group_published - exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) - exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq - if choose_type == 2 - @exercises = @exercises_all.exists? ? - @exercises_all.exercise_by_status(2).unified_setting - .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) - : [] - elsif choose_type == 3 - @exercises = @exercises_all.exists? ? - @exercises_all.exercise_by_status(3).unified_setting - .or(@exercises_all.where(id: exercise_ended_ids)) - : [] - end - else - @exercises = @exercises.exercise_by_status(choose_type) + ex_setting_ids = [] + case choose_type + when 1 + ex_setting_ids = @course.exercise_group_settings.exercise_group_not_published.pluck(:exercise_id) + + # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)) + when 2 + ex_setting_ids = @course.exercise_group_settings.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) + # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_published_groups)) + when 3 + ex_setting_ids = @course.exercise_group_settings.exercise_group_ended.pluck(:exercise_id) + # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_ended_groups)) end + @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct + + + + + # member_group_id = @current_student.first.try(:course_group_id).to_i + # if @is_teacher_or == 2 && member_group_id > 0 + # exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) + # .exercise_group_published + # exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) + # exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq + # if choose_type == 2 + # @exercises = @exercises_all.exists? ? + # @exercises_all.exercise_by_status(2).unified_setting + # .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) + # : [] + # elsif choose_type == 3 + # @exercises = @exercises_all.exists? ? + # @exercises_all.exercise_by_status(3).unified_setting + # .or(@exercises_all.where(id: exercise_ended_ids)) + # : [] + # end + # else + # @exercises = @exercises.exercise_by_status(choose_type) + # end end if params[:search].present? @@ -1302,9 +1320,11 @@ class ExercisesController < ApplicationController respond_to do |format| format.xlsx{ get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + exercise_export_name_ = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" + exercise_export_name = Base64.urlsafe_encode64(exercise_export_name_.strip.first(30)) + + render xlsx: "#{exercise_export_name}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} } end end diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 545b10e11..41d8bd68d 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -134,8 +134,9 @@ class GraduationTasksController < ApplicationController 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} + task_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@task.name}" + task_export_name = Base64.urlsafe_encode64(task_export_name_.strip.first(30)) + render xlsx: "#{task_export_name}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} } end end diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index b20b767a4..75f7ddc6f 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -270,8 +270,9 @@ class GraduationTopicsController < ApplicationController course = @course students = course.students.joins(user: :user_extension).order("user_extensions.student_id") graduation_topic_to_xlsx(students,course) - 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} + topic_export_name_ = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + topic_export_name = Base64.urlsafe_encode64(topic_export_name_.strip.first(30)) + render xlsx: "#{topic_export_name}",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 diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b12980094..cdbfac5bc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -206,10 +206,8 @@ class HomeworkCommonsController < ApplicationController respond_to do |format| format.xlsx{ 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') - # response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@homework.name}" file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) - # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 64827b375..d94299454 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -933,9 +933,11 @@ class PollsController < ApplicationController else respond_to do |format| format.xlsx{ - polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + polls_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}" + polls_export_name = Base64.urlsafe_encode64(polls_export_name_.strip.first(30)) + polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) - render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} + render xlsx: "#{polls_export_name}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} } end end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 2b70b9b27..2d21237f5 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -9,8 +9,8 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename = filename_for_content_disposition(service.filename) - + filename_ = filename_for_content_disposition(service.filename) + filename = Base64.urlsafe_encode64(filename_) send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) @@ -20,8 +20,8 @@ class ZipsController < ApplicationController @request_url = request.base_url exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) - file_name = filename_for_content_disposition(exercises.filename) - + file_name_ = filename_for_content_disposition(exercises.filename) + file_name = Base64.urlsafe_encode64(file_name_) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 693149e8f..aee95eef7 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -65,7 +65,7 @@ module PollsHelper poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] current_status = 3 - lock_icon = 1 #不显示锁图标 + lock_icon = 0 #不显示锁图标 elsif is_teacher_or == 2 poll_users_list = poll.get_poll_exercise_users get_poll_answers(poll_users_list) # 未答和已答的 @@ -74,7 +74,7 @@ module PollsHelper poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] current_status = poll.check_user_votes_status(user) - lock_icon = 1 #不显示锁图标 + lock_icon = 0 #不显示锁图标 else poll_users_list = poll.get_poll_exercise_users get_poll_answers(poll_users_list) # 未答和已答的 @@ -87,6 +87,9 @@ module PollsHelper lock_icon = 0 #显示锁图标 end end + if (course.is_public == 1) && poll.is_public + lock_icon = 1 + end { "publish_time":poll_publish_time, "end_time":poll_end_time, diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 42b737c26..bc5424b6e 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -144,10 +144,10 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.find_by(user_id: user.id) user_ex_status = get_exercise_status(user.id) user_status = 2 - if ex_answer_user.exists? && (ex_answer_user.start_at.exists? || ex_answer_user.end_at.exists?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.commit_status end - if ex_answer_user.exists? && ex_answer_user.start_at.blank? && user_ex_status == 3 + if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 user_status = 4 end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 2c294395d..01d94ffe5 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -14,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{homework.name}-#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" + @_filename ||= "#{homework.name}" end def zip diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 3aac67713..1b284e598 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -10,7 +10,7 @@ class ExportExercisesService end def filename - exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" + exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}" "#{exercise_export_name.strip}.zip" end From b7b5821f939cee7c72717ac01c1f11d60f789dd5 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 10:23:52 +0800 Subject: [PATCH 121/124] fixbug --- app/helpers/exercises_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index fe29497d0..8174d1eea 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -723,8 +723,8 @@ module ExercisesHelper if ex_time > 0 exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 - exercise_end_time = exercise.end_time.exists? ? exercise.end_time.to_i : 0 - exercise_user_start = exercise_user&.start_at.exists? ? exercise_user.start_at.to_i : 0 + exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 + exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 if (exercise_end_time - time_now_i) > time_mill From bd218764e991eacad83ef2b255e3bac0564e29bf Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 10:54:02 +0800 Subject: [PATCH 122/124] fixvbug --- app/controllers/exercises_controller.rb | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6d0adef27..79668dad3 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -64,22 +64,23 @@ class ExercisesController < ApplicationController if params[:type].present? choose_type = params[:type].to_i ex_setting_ids = [] - case choose_type - when 1 - ex_setting_ids = @course.exercise_group_settings.exercise_group_not_published.pluck(:exercise_id) - - # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)) - when 2 - ex_setting_ids = @course.exercise_group_settings.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) - # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_published_groups)) - when 3 - ex_setting_ids = @course.exercise_group_settings.exercise_group_ended.pluck(:exercise_id) - # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_ended_groups)) + if @is_teacher_or != 2 + @exercises = @exercises.where("exercise_status = #{choose_type}") + else + case choose_type + when 1 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id) + when 2 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}") + .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) + when 3 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id) + end + unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id) + ex_ids = (ex_setting_ids + unified_setting_ids).uniq + @exercises = @exercises.where(id: ex_ids) + # @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct end - @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct - - - # member_group_id = @current_student.first.try(:course_group_id).to_i # if @is_teacher_or == 2 && member_group_id > 0 From c5baf84e8562729ee4b45f865fa52b5e5343f413 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 12:40:16 +0800 Subject: [PATCH 123/124] fixbug --- app/controllers/exercises_controller.rb | 25 ++------------------- app/controllers/student_works_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79668dad3..30cc51dc2 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -79,29 +79,7 @@ class ExercisesController < ApplicationController unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id) ex_ids = (ex_setting_ids + unified_setting_ids).uniq @exercises = @exercises.where(id: ex_ids) - # @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct end - - # member_group_id = @current_student.first.try(:course_group_id).to_i - # if @is_teacher_or == 2 && member_group_id > 0 - # exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) - # .exercise_group_published - # exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) - # exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq - # if choose_type == 2 - # @exercises = @exercises_all.exists? ? - # @exercises_all.exercise_by_status(2).unified_setting - # .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) - # : [] - # elsif choose_type == 3 - # @exercises = @exercises_all.exists? ? - # @exercises_all.exercise_by_status(3).unified_setting - # .or(@exercises_all.where(id: exercise_ended_ids)) - # : [] - # end - # else - # @exercises = @exercises.exercise_by_status(choose_type) - # end end if params[:search].present? @@ -1342,7 +1320,8 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf" + filename_ = "#{@exercise.user.real_name}_#{@exercise.exercise_name}" + filename = Base64.urlsafe_encode64(filename_.strip.first(30)) stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets end diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index ed642a557..7c7201d32 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -456,9 +456,9 @@ class StudentWorksController < ApplicationController @echart_data = student_efficiency(@homework, @work) @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } @myself_consume = @echart_data[:consume_list].find { |item| item.last == @user.id } - # filename = "实训报告_#{@shixun.name}_#{@use.real_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" #下载报错 unknown nil name,下面为修改的-hs-0606 - filename = "实训报告_#{@shixun&.name}_#{@use&.real_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" + filename_ = "实训报告_#{@shixun&.name}_#{@use&.real_name}" + filename = Base64.urlsafe_encode64(filename_.strip.first(30)) stylesheets = %w(shixun_work/shixun_work.css shared/codemirror.css) render pdf: 'shixun_work/shixun_work', filename: filename, stylesheets: stylesheets end From 67a1850adc268a8c0aae38c40aa90ef2ac127709 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 6 Jul 2019 13:52:10 +0800 Subject: [PATCH 124/124] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E7=9C=8B=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cbd2962b6..e6c0116fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -72,7 +72,7 @@ class ApplicationController < ActionController::Base UserMailer.register_email(value, code).deliver_now # Mailer.run.email_register(code, value) rescue Exception => e - uid_logger_error(e.message) + logger_error(e) tip_exception("邮件发送失败,请稍后重试") end end