dev_haigong
daiao 6 years ago
commit 0fc5fadcb9

@ -671,6 +671,7 @@ class HomeworkCommonController < ApplicationController
def destroy
if @homework.destroy
StudentWork.where(:homework_common_id => @homework.id).destroy_all
#更新CourseHomeworkStatistics中每个学生的未交作品数、已交作品数、迟交作品数
# hw_count = @course.homework_commons.includes(:homework_detail_manual).where("homework_detail_manuals.comment_status > 0").count
# homework_ids = @course.homework_commons.empty? ? "(-1)" : "(" + @course.homework_commons.map{|hw| hw.id}.join(",") + ")"
@ -1347,7 +1348,7 @@ class HomeworkCommonController < ApplicationController
def find_homework
@homework = HomeworkCommon.find params[:id]
@homework_detail_manual = @homework.homework_detail_manual
@homework_detail_programing = @homework.homework_detail_programing
# @homework_detail_programing = @homework.homework_detail_programing
@homework_detail_group = @homework.homework_detail_group
@course = @homework.course
rescue

@ -6793,7 +6793,9 @@ def update_myshixun_work_score myshixun
end
work.update_time = Time.now
work.final_score = final_score
# 为迁移的数据做特殊处理, 若分数小于当前通关分数则不更新
work.final_score = final_score if work.final_score.nil? || final_score > work.final_score
score = work.final_score + work.eff_score - work.late_penalty
work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score
#logger.info("#############work_score: #{score}")

@ -15,7 +15,7 @@ class HomeworkCommon < ActiveRecord::Base
belongs_to :homework_bank
has_many :homework_group_settings, :dependent => :destroy
has_one :homework_detail_manual, :dependent => :destroy
has_one :homework_detail_programing, :dependent => :destroy
# has_one :homework_detail_programing, :dependent => :destroy
has_one :homework_detail_group, :dependent => :destroy
has_one :homework_commons_shixuns, :dependent => :destroy
has_many :homework_challenge_settings, :dependent => :destroy
@ -24,21 +24,21 @@ class HomeworkCommon < ActiveRecord::Base
has_many :homework_review_results, :dependent => :destroy # 学生的查重情况
belongs_to :course_homework_category
has_many :student_work_projects, :dependent => :destroy
has_many :homework_tests, :dependent => :destroy
has_many :homework_samples, :dependent => :destroy
has_many :student_works, :dependent => :destroy, :conditions => "student_works.is_test=0 and student_works.is_delete != 1"
has_many :student_work_projects
# has_many :homework_tests, :dependent => :destroy
# has_many :homework_samples, :dependent => :destroy
has_many :student_works, :conditions => "student_works.is_test=0 and student_works.is_delete != 1"
has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :apply_homeworks, :dependent => :destroy
has_many :apply_homeworks
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
# has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
has_and_belongs_to_many :shixuns
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# 课程消息
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
# has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
has_many :tidings, as: :container, dependent: :destroy
acts_as_attachable
acts_as_event :title => Proc.new {|o| "#{l(:label_course_homework)} ##{o.id}: #{o.name}" },
@ -48,7 +48,7 @@ class HomeworkCommon < ActiveRecord::Base
# after_create :act_as_activity
after_update :update_activity
after_save :act_as_course_activity
after_destroy :delete_kindeditor_assets
# after_destroy :delete_kindeditor_assets
before_destroy :update_homework_bank_quotes
#删除时更新题库中的引用数

@ -13,9 +13,9 @@ class StudentWork < ActiveRecord::Base
has_many :student_works_scores, :dependent => :destroy
has_many :challenge_work_scores, :dependent => :destroy
belongs_to :project
has_many :student_work_tests, order: 'id desc'
# has_many :student_work_tests, order: 'id desc'
# course's message
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
# has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
has_many :attachments, :dependent => :destroy
has_many :tidings, as: :container, dependent: :destroy
belongs_to :myshixun

@ -0,0 +1,8 @@
class AddIndexToHomework < ActiveRecord::Migration
def change
add_index :homework_detail_manuals, :homework_common_id
add_index :homework_commons_shixuns, :homework_common_id
add_index :student_works_evaluation_distributions, :student_work_id
add_index :tidings, :container_id
end
end

@ -0,0 +1,30 @@
class MigrationShixunStudentWork < ActiveRecord::Migration
def up
works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and (work_score is null or work_score = 0)")
works.update_all(:myshixun_id => 0, :work_status => 0, :work_score => nil, :final_score => nil,
:cost_time => 0, :update_time => nil, :compelete_status => 0, :commit_time => nil)
shixun_works = StudentWork.where("myshixun_id != 0 and myshixun_id not in (select id from myshixuns) and work_score > 0")
shixun_works.each do |work|
if work.homework_common && work.homework_common.homework_commons_shixuns.try(:shixun)
shixun = work.homework_common.homework_commons_shixuns.try(:shixun)
# 创建新的myshixun和games
myshixun = nil
work_score = work.final_score
work.homework_common.homework_challenge_settings.each do |setting|
if work_score > 1
myshixun.games.where(:challenge_id => setting.challenge_id).first.update_attributes(:status => 2)
work_score -= setting.score
end
end
work.update_column("myshixun_id", myshixun.id)
end
end
end
def down
end
end
Loading…
Cancel
Save