From e11b0cd629d130b98d88bc70efc86a9fcadc66a9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 13 Dec 2019 11:54:51 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/homework_commons_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index efc14dc5e..7a474526c 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -81,8 +81,9 @@ module HomeworkCommonsHelper if homework_common.allow_late && (homework_common.late_time.nil? || homework_common.late_time >= Time.now) time = "补交剩余时间:" + how_much_time(homework_common.late_time) time_status = 2 + else + status << "已截止" end - status << "评阅中" end end else @@ -117,11 +118,10 @@ module HomeworkCommonsHelper time = "提交剩余时间:" + how_much_time(max_end_time) time_status = 1 elsif homework_common.allow_late && (homework_common.late_time.nil? || homework_common.late_time >= Time.now) - status << "评阅中" time = "补交剩余时间:" + how_much_time(homework_common.late_time) time_status = 2 else - status << "评阅中" + status << "已截止" time = "" time_status = 5 end From 02f60c83a97f67335fac230f26d2f1d3dc5fa9b3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 13 Dec 2019 18:57:50 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?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 --- .../homework_commons_controller.rb | 5 +++-- app/helpers/homework_commons_helper.rb | 12 ++++++++--- app/models/myshixun.rb | 5 +++++ app/models/student_work.rb | 20 +++++++++++++++++++ .../homework_commons/works_list.json.jbuilder | 12 +++++++---- ...3_migrate_student_work_compelete_status.rb | 5 +++++ 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20191213101853_migrate_student_work_compelete_status.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index e11fefea1..66a01ea6e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -78,7 +78,7 @@ class HomeworkCommonsController < ApplicationController when '4' sql_str = %Q((homework_detail_manuals.comment_status = #{order} and homework_detail_manuals.appeal_time > '#{Time.now}')) when '5' - sql_str = %Q((homework_detail_manuals.comment_status = #{order} or (anonymous_comment = 0 and homework_commons.end_time <= '#{Time.now}'))) + sql_str = %Q((homework_detail_manuals.comment_status = #{order} or (anonymous_comment = 0 and ((allow_late= 0 and homework_commons.end_time <= '#{Time.now}') or (allow_late= 1 and late_time <= '#{Time.now}'))))) else sql_str = %Q(homework_detail_manuals.comment_status = #{order}) end @@ -168,7 +168,8 @@ class HomeworkCommonsController < ApplicationController params_work_status = params[:work_status] work_status = params_work_status.map{|status| status.to_i} all_student_works = @student_works.left_joins(:myshixun) - @student_works = all_student_works.where(work_status: work_status) + @student_works = all_student_works.where(work_status: work_status) if work_status.include?(0) + @student_works = @student_works.or(all_student_works.where(work_status: 0)).or(all_student_works.where(myshixuns: {status: 0})) if work_status.include?(1) @student_works = @student_works.or(all_student_works.where(work_status: 0)).or(all_student_works.where(myshixuns: {status: 0})) if work_status.include?(3) @student_works = @student_works.or(all_student_works.where(myshixuns: {status: 1})) if work_status.include?(4) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 7a474526c..7ad55e2ae 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -34,6 +34,12 @@ module HomeworkCommonsHelper # 作业状态大于“提交”状态时,不用考虑分班权限 if ho_detail_manual.comment_status > 1 case ho_detail_manual.comment_status + when 2 + unless homework_common.allow_late + status << "已截止" + time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" + time_status = 5 + end when 3 if ho_detail_manual.evaluation_end && ho_detail_manual.evaluation_end > Time.now status << "匿评中" @@ -46,8 +52,8 @@ module HomeworkCommonsHelper time = "申诉剩余时间:" + how_much_time(ho_detail_manual.appeal_time) time_status = 4 end - when 2, 5, 6 - status << "评阅中" + when 5, 6 + status << "已截止" time = course.end_date.present? ? ("评阅剩余时间:" + how_much_time(course.end_date.end_of_day)) : "" time_status = 5 end @@ -77,12 +83,12 @@ module HomeworkCommonsHelper time = "提交剩余时间:" + how_much_time(homework_common.end_time) time_status = 1 elsif homework_common.end_time && homework_common.end_time < Time.now - time_status = 5 if homework_common.allow_late && (homework_common.late_time.nil? || homework_common.late_time >= Time.now) time = "补交剩余时间:" + how_much_time(homework_common.late_time) time_status = 2 else status << "已截止" + time_status = 5 end end end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 9b824c0d8..d510d880a 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -83,6 +83,11 @@ class Myshixun < ApplicationRecord self.games.select{|game| game.status == 2}.size end + # 指定时间前完成的关卡数 + def time_passed_count time + time.present? ? self.games.select{|game| game.status == 2 && game.end_time < time}.size : 0 + end + # 查看答案的关卡数,只统计通关前看的关卡 def view_answer_count answer_ids = user.grades.joins("join games on grades.container_id = games.id").where("container_type = 'Answer' and games.status=2 and games.end_time > grades.created_at").pluck(:container_id) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index d4f372823..4da23a30f 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -123,6 +123,26 @@ class StudentWork < ApplicationRecord end end + # 实训作业的作品状态 0:未提交,1:未通关,2:按时通关(提交截止前通关),3:迟交通关(提交截止-补交截止间通关) + def real_work_status + status = work_status + if status > 0 && myshixun + if myshixun.status != 1 + status = 1 + else + homework_end_time = homework_common.homework_group_setting(user_id)&.end_time + if homework_end_time.present? && homework_end_time > myshixun.passed_time + status = 2 + elsif homework_end_time.present? && homework_common.allow_late && homework_common.late_time > myshixun.passed_time + status = 3 + else + status = 1 + end + end + end + status + end + # 更新作品成绩 def set_work_score if work_status > 0 && homework_common && !self.ultimate_score diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 34123e829..b0007954f 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -33,7 +33,7 @@ elsif @user_course_identity == Course::STUDENT json.left_time left_time @homework, @current_user.id if @homework.homework_type == "practice" - json.(@work, :id, :work_status, :update_time, :ultimate_score) + json.(@work, :id, :update_time, :ultimate_score) json.calculation_time @work.calculation_time json.late_penalty @work.late_penalty if @homework.allow_late json.cost_time @work.myshixun.try(:total_spend_time) @@ -41,8 +41,10 @@ elsif @user_course_identity == Course::STUDENT json.final_score work_score_format(@work.final_score, true, @score_open) json.efficiency work_score_format(@work.efficiency, true, @score_open) json.eff_score work_score_format(@work.eff_score, true, @score_open) - json.complete_count @work.myshixun.try(:passed_count) + json.current_complete_count @work.myshixun.try(:passed_count) if @homework.end_or_late + json.complete_count @work.myshixun&.time_passed_count(@homework.homework_group_setting(@work.user_id)&.end_time) json.view_answer_count @work.myshixun.try(:view_answer_count) + json.work_status @work.real_work_status else json.(@work, :id, :work_status, :update_time, :ultimate_score) @@ -87,7 +89,7 @@ if @homework.homework_type == "practice" json.work_efficiency @homework.work_efficiency json.student_works @student_works.each do |work| - json.(work, :id, :work_status, :update_time, :ultimate_score, :myshixun_id) + json.(work, :id, :update_time, :ultimate_score, :myshixun_id) json.late_penalty work.late_penalty if @homework.allow_late json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) @@ -96,12 +98,14 @@ if @homework.homework_type == "practice" json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open) json.cost_time work.myshixun.try(:total_spend_time) - json.complete_count work.myshixun.try(:passed_count) + json.current_complete_count work.myshixun.try(:passed_count) if @homework.end_or_late + json.complete_count work.myshixun&.time_passed_count(@homework.homework_group_setting(work.user_id)&.end_time) json.view_answer_count work.myshixun.try(:view_answer_count) json.user_login work.user.try(:login) json.user_name work.user.try(:real_name) json.student_id work.user.try(:student_id) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) + json.work_status work.real_work_status end elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.anonymous_comment @homework.anonymous_comment diff --git a/db/migrate/20191213101853_migrate_student_work_compelete_status.rb b/db/migrate/20191213101853_migrate_student_work_compelete_status.rb new file mode 100644 index 000000000..865114914 --- /dev/null +++ b/db/migrate/20191213101853_migrate_student_work_compelete_status.rb @@ -0,0 +1,5 @@ +class MigrateStudentWorkCompeleteStatus < ActiveRecord::Migration[5.2] + def change + + end +end From 45177122c82a62dfa14ab16f55acdb5028973a09 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 16 Dec 2019 11:29:28 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=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 | 7 +----- app/controllers/student_works_controller.rb | 3 ++- app/helpers/application_helper.rb | 2 +- app/helpers/homework_commons_helper.rb | 10 ++++----- app/models/homework_common.rb | 21 +++++++----------- app/services/homeworks_service.rb | 7 +++++- .../homework_commons/works_list.json.jbuilder | 4 ++-- ...3_migrate_student_work_compelete_status.rb | 22 ++++++++++++++++++- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 66a01ea6e..d2d2a37a9 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -167,12 +167,7 @@ class HomeworkCommonsController < ApplicationController if params[:work_status].present? params_work_status = params[:work_status] work_status = params_work_status.map{|status| status.to_i} - all_student_works = @student_works.left_joins(:myshixun) - @student_works = all_student_works.where(work_status: work_status) if work_status.include?(0) - @student_works = @student_works.or(all_student_works.where(work_status: 0)).or(all_student_works.where(myshixuns: {status: 0})) if work_status.include?(1) - - @student_works = @student_works.or(all_student_works.where(work_status: 0)).or(all_student_works.where(myshixuns: {status: 0})) if work_status.include?(3) - @student_works = @student_works.or(all_student_works.where(myshixuns: {status: 1})) if work_status.include?(4) + @student_works = @student_works.where(compelete_status: work_status) end # 分班情况 diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 946b65d24..a347e062d 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -739,7 +739,8 @@ class StudentWorksController < ApplicationController comment: comment) challenge_score.create_tiding current_user.id if @work.work_status != 0 && @work.myshixun - HomeworksService.new.update_myshixun_work_score @work, @work.myshixun, @work.myshixun&.games, @homework, @homework.homework_challenge_settings + games = @work.myshixun.games.where(challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)) + HomeworksService.new.update_myshixun_work_score @work, @work.myshixun, games, @homework, @homework.homework_challenge_settings else update_none_commit_work @work, @homework end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index be633b2cc..cabf8d244 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -210,7 +210,7 @@ module ApplicationHelper # 普通/分组 作业作品状态数组 def student_work_status homework, user_id, course, work status = [] - homework_setting = homework.homework_group_setting user_id + homework_setting = homework.homework_group_setting user_id, true work = work || StudentWork.create(homework_common_id: homework.id, user_id: user_id) late_time = homework.late_time || course.end_date diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 7ad55e2ae..ecf5083f6 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -150,7 +150,7 @@ module HomeworkCommonsHelper # 阶段剩余时间 def left_time homework, user_id - setting = homework.homework_group_setting(user_id) + setting = homework.homework_group_setting(user_id, true) if setting.publish_time && setting.publish_time < Time.now if setting.end_time > Time.now status = "剩余提交时间" @@ -230,10 +230,10 @@ module HomeworkCommonsHelper # 作品状态 def practice_homework_status homework, member - [{id: 3, name: "未通关", count: homework.un_complete_count(member)}, - {id: 4, name: "已通关", count: homework.complete_count(member)}, - {id: 1, name: "按时完成", count: homework.finished_count(member)}, - {id: 2, name: "延时完成", count: homework.delay_finished_count(member)}] + [{id: 0, name: "未提交", count: homework.compelete_status_count(member, 0)}, + {id: 1, name: "未通关", count: homework.compelete_status_count(member, 1)}, + {id: 2, name: "按时通关", count: homework.compelete_status_count(member, 2)}, + {id: 3, name: "迟交通关", count: homework.compelete_status_count(member, 3)}] end # 作品状态 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index d37650c37..58b52bdd2 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -108,7 +108,7 @@ class HomeworkCommon < ApplicationRecord # 是否在补交阶段内 def late_duration - homework_setting = self.homework_group_setting(User.current.id) + homework_setting = self.homework_group_setting(User.current.id, true) !course.is_end && self.publish_time && self.publish_time < Time.now && homework_setting.end_time && homework_setting.end_time < Time.now && self.allow_late && (self.late_time.nil? || self.late_time > Time.now) end @@ -119,7 +119,7 @@ class HomeworkCommon < ApplicationRecord if self.course.is_end || (self.allow_late && self.late_time && self.late_time < Time.now) status = true elsif !self.allow_late - homework_setting = self.homework_group_setting(User.current.id) + homework_setting = self.homework_group_setting(User.current.id, true) status = homework_setting.end_time && homework_setting.end_time < Time.now end status @@ -241,14 +241,8 @@ class HomeworkCommon < ApplicationRecord self.teacher_works(member).delay_finished.count end - # 未通关数 - def un_complete_count member - teacher_works(member).count - complete_count(member) - end - - # 通关数 - def complete_count member - Myshixun.where(id: self.teacher_works(member).pluck(:myshixun_id), status: 1).count + def compelete_status_count member, status + teacher_works(member).where(compelete_status: status).count end # 分组作业的最大分组id @@ -257,12 +251,13 @@ class HomeworkCommon < ApplicationRecord end # 作业的分班设置时间 - def homework_group_setting user_id + def homework_group_setting user_id, current_user=false if unified_setting homework_setting = self else - member = course.course_member(user_id) - group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id)) + # 当前用户是从course_member中取,否则是从学生中取(双重身份的原因) + member = current_user ? course.course_member(user_id) : course.students.find_by(user_id: user_id) + group_setting = self.homework_group_settings.select{ |setting| setting.course_group_id == member.try(:course_group_id)}.first homework_setting = group_setting.present? ? group_setting : self end homework_setting diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 0dc814c89..10557e88f 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -322,11 +322,16 @@ class HomeworksService work.efficiency = format("%.2f", efficiency) if myshixun_endtime <= homework_end_or_late_time - work.compelete_status = myshixun_endtime < setting_time.publish_time ? 2 : 1 + # 2是按时通关, 3是迟交通关 + work.compelete_status = myshixun_endtime < setting_time.end_time ? 2 : 3 # 如果作业的最大效率值有变更则更新所有作品的效率分 homework.update_column("max_efficiency", work.efficiency) if homework.work_efficiency && homework.max_efficiency < work.efficiency + else + work.compelete_status = 1 # 未通关 end + else + work.compelete_status = 1 # 未通关 end work.late_penalty = work.work_status == 2 ? homework.late_penalty : 0 diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index b0007954f..e3a5d9b84 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -44,7 +44,7 @@ elsif @user_course_identity == Course::STUDENT json.current_complete_count @work.myshixun.try(:passed_count) if @homework.end_or_late json.complete_count @work.myshixun&.time_passed_count(@homework.homework_group_setting(@work.user_id)&.end_time) json.view_answer_count @work.myshixun.try(:view_answer_count) - json.work_status @work.real_work_status + json.work_status @work.compelete_status else json.(@work, :id, :work_status, :update_time, :ultimate_score) @@ -105,7 +105,7 @@ if @homework.homework_type == "practice" json.user_name work.user.try(:real_name) json.student_id work.user.try(:student_id) json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) - json.work_status work.real_work_status + json.work_status work.compelete_status end elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.anonymous_comment @homework.anonymous_comment diff --git a/db/migrate/20191213101853_migrate_student_work_compelete_status.rb b/db/migrate/20191213101853_migrate_student_work_compelete_status.rb index 865114914..5bb4a2699 100644 --- a/db/migrate/20191213101853_migrate_student_work_compelete_status.rb +++ b/db/migrate/20191213101853_migrate_student_work_compelete_status.rb @@ -1,5 +1,25 @@ class MigrateStudentWorkCompeleteStatus < ActiveRecord::Migration[5.2] def change - + student_works = StudentWork.where("myshixun_id is not null and myshixun_id != 0") + student_works.includes(homework_common: :homework_challenge_settings, myshixun: :games).find_each do |work| + if work.myshixun + myshixun = work.myshixun + homework= work.homework_common + setting_time = homework.homework_group_setting myshixun.user_id + homework_end_or_late_time = homework.allow_late ? homework.late_time : setting_time.end_time + challenge_ids = homework.homework_challenge_settings.pluck(:challenge_id) + games = myshixun.games.select{ |game| challenge_ids.include?(game.challenge_id) } + myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil + if work.work_status != 0 && homework_end_or_late_time.present? + if myshixun_endtime.present? && myshixun_endtime <= homework_end_or_late_time + # 2是按时通关, 3是迟交通关 + compelete_status = setting_time.end_time.present? && myshixun_endtime < setting_time.end_time ? 2 : 3 + else + compelete_status = 1 # 未通关 + end + work.update_column("compelete_status", compelete_status) + end + end + end end end From b12559ad4c16afb5a2f7aab912430e1cb0737645 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 16 Dec 2019 14:18:54 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20191213101853_migrate_student_work_compelete_status.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20191213101853_migrate_student_work_compelete_status.rb b/db/migrate/20191213101853_migrate_student_work_compelete_status.rb index 5bb4a2699..da45ccfac 100644 --- a/db/migrate/20191213101853_migrate_student_work_compelete_status.rb +++ b/db/migrate/20191213101853_migrate_student_work_compelete_status.rb @@ -2,10 +2,10 @@ class MigrateStudentWorkCompeleteStatus < ActiveRecord::Migration[5.2] def change student_works = StudentWork.where("myshixun_id is not null and myshixun_id != 0") student_works.includes(homework_common: :homework_challenge_settings, myshixun: :games).find_each do |work| - if work.myshixun + if work.myshixun && work.homework_common myshixun = work.myshixun homework= work.homework_common - setting_time = homework.homework_group_setting myshixun.user_id + setting_time = homework.homework_group_setting(myshixun.user_id) homework_end_or_late_time = homework.allow_late ? homework.late_time : setting_time.end_time challenge_ids = homework.homework_challenge_settings.pluck(:challenge_id) games = myshixun.games.select{ |game| challenge_ids.include?(game.challenge_id) }