@ -6,7 +6,7 @@ class HomeworkCommonsController < ApplicationController
before_action :require_login , :check_auth , except : [ :index , :choose_category ]
before_action :require_login , :check_auth , except : [ :index , :choose_category ]
before_action :find_course , only : [ :index , :create , :new , :shixuns , :subjects , :create_shixun_homework , :publish_homework ,
before_action :find_course , only : [ :index , :create , :new , :shixuns , :subjects , :create_shixun_homework , :publish_homework ,
:end_homework , :set_public , : choose_category, : move_to_category, :choose_category ,
:end_homework , :set_public , : move_to_category, :choose_category ,
:create_subject_homework , :multi_destroy , :add_to_homework_bank ]
:create_subject_homework , :multi_destroy , :add_to_homework_bank ]
before_action :find_homework , only : [ :edit , :show , :update , :group_list , :homework_code_repeat , :code_review_results ,
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 ,
:code_review_detail , :show_comment , :settings , :works_list , :update_settings ,
@ -34,7 +34,7 @@ class HomeworkCommonsController < ApplicationController
module_type = @homework_type == 4 ? " shixun_homework " : @homework_type == 1 ? " common_homework " : " group_homework "
module_type = @homework_type == 4 ? " shixun_homework " : @homework_type == 1 ? " common_homework " : " group_homework "
@homework_commons = @course . homework_commons . where ( homework_type : @homework_type )
@homework_commons = @course . homework_commons . where ( homework_type : @homework_type )
@main_category = @course . course_modules . find_by ( module_type : module_type )
@main_category = @course . course_modules . find_by ( module_type : module_type )
if @homework_type == 4 && ! params [ :category ] . blank?
if ! params [ :category ] . blank?
@category = @main_category . course_second_categories . find_by ( id : params [ :category ] )
@category = @main_category . course_second_categories . find_by ( id : params [ :category ] )
tip_exception ( " 子目录id有误 " ) if ! @category . present?
tip_exception ( " 子目录id有误 " ) if ! @category . present?
@homework_commons = @homework_commons . where ( course_second_category_id : params [ :category ] )
@homework_commons = @homework_commons . where ( course_second_category_id : params [ :category ] )
@ -70,9 +70,25 @@ class HomeworkCommonsController < ApplicationController
else
else
case order
case order
when '1'
when '1'
if @user_course_identity == Course :: STUDENT
unified_homework_ids = @homework_commons . published_no_end . unified_setting . pluck ( :id )
group_homework_ids = @course . homework_group_settings . where ( " course_group_id = #{ @member . course_group_id & . to_i } " ) . published_no_end . pluck ( :homework_common_id )
homework_ids = unified_homework_ids + group_homework_ids
homework_ids = homework_ids . blank? ? " (-1) " : " ( " + homework_ids . join ( " , " ) + " ) "
sql_str = %Q( homework_commons.id in #{ homework_ids } )
else
sql_str = %Q( homework_detail_manuals.comment_status = #{ order } and homework_commons.end_time > ' #{ Time . now } ' )
sql_str = %Q( homework_detail_manuals.comment_status = #{ order } and homework_commons.end_time > ' #{ Time . now } ' )
end
when '2'
when '2'
if @user_course_identity == Course :: STUDENT
unified_homework_ids = @homework_commons . homework_ended . unified_setting . pluck ( :id )
group_homework_ids = @course . homework_group_settings . where ( " course_group_id = #{ @member . course_group_id & . to_i } " ) . has_end . pluck ( :homework_common_id )
homework_ids = unified_homework_ids + group_homework_ids
homework_ids = homework_ids . blank? ? " (-1) " : " ( " + homework_ids . join ( " , " ) + " ) "
sql_str = %Q( homework_commons.id in #{ homework_ids } and allow_late = 1 and ( late_time is null or late_time > ' #{ Time . now } ' ) )
else
sql_str = %Q( allow_late = 1 and homework_commons.end_time < ' #{ Time . now } ' and ( late_time is null or late_time > ' #{ Time . now } ' ) )
sql_str = %Q( allow_late = 1 and homework_commons.end_time < ' #{ Time . now } ' and ( late_time is null or late_time > ' #{ Time . now } ' ) )
end
when '3'
when '3'
sql_str = %Q( homework_detail_manuals.comment_status = #{ order } and homework_detail_manuals.evaluation_end > ' #{ Time . now } ' )
sql_str = %Q( homework_detail_manuals.comment_status = #{ order } and homework_detail_manuals.evaluation_end > ' #{ Time . now } ' )
when '4'
when '4'
@ -87,16 +103,16 @@ class HomeworkCommonsController < ApplicationController
end
end
@task_count = @homework_commons . size
@task_count = @homework_commons . size
order_str = @homework_type == 4 ? " position DESC" : " IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
order_str = @homework_type == 4 ? " homework_commons. position DESC" : " IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
homework_commons . created_at DESC "
homework_commons . created_at DESC "
@homework_commons = @homework_commons . order ( order_str ) . page ( page ) . per ( 15 )
@homework_commons = @homework_commons . order ( order_str ) . page ( page ) . per ( 15 )
if @homework_type == 4
if @homework_type == 4
@homework_commons = @homework_commons . includes ( :homework_detail_manual , :published_settings , : shixuns)
@homework_commons = @homework_commons . includes ( :homework_detail_manual , :published_settings , : homework_group_settings, : shixuns, :course_second_category , user : :user_extension )
elsif @homework_type == 3
elsif @homework_type == 3
@homework_commons = @homework_commons . includes ( :homework_detail_manual , :published_settings , :homework_ detail_group)
@homework_commons = @homework_commons . includes ( :homework_detail_manual , :published_settings , :homework_ group_settings, :homework_ detail_group, :course_second_category , user : :user_extension )
else
else
@homework_commons = @homework_commons . includes ( :homework_detail_manual , :published_settings )
@homework_commons = @homework_commons . includes ( :homework_detail_manual , :published_settings , :homework_group_settings , :course_second_category , user : :user_extension )
end
end
end
end
@ -112,7 +128,7 @@ class HomeworkCommonsController < ApplicationController
if @homework . publish_time . blank? || ( @homework . publish_time > Time . now )
if @homework . publish_time . blank? || ( @homework . publish_time > Time . now )
@student_works = [ ]
@student_works = [ ]
if ( params [ :format ] == " xlsx " ) || ( params [ :format ] == " zip " )
if ( params [ :format ] == " xlsx " ) || ( params [ :format ] == " zip " )
normal_status ( - 1 , " 作业未发布 " )
normal_status ( - 1 , " 作业未发布 " )
end
end
else
else
if @user_course_identity == Course :: STUDENT
if @user_course_identity == Course :: STUDENT
@ -166,7 +182,7 @@ class HomeworkCommonsController < ApplicationController
# 作品状态 0: 未提交, 1 按时提交, 2 延迟提交
# 作品状态 0: 未提交, 1 按时提交, 2 延迟提交
if params [ :work_status ] . present?
if params [ :work_status ] . present?
params_work_status = params [ :work_status ]
params_work_status = params [ :work_status ]
work_status = params_work_status . map { | status | status . to_i }
work_status = params_work_status . map { | status | status . to_i }
if @homework . homework_type == " practice "
if @homework . homework_type == " practice "
@student_works = @student_works . where ( compelete_status : work_status )
@student_works = @student_works . where ( compelete_status : work_status )
else
else
@ -225,17 +241,17 @@ class HomeworkCommonsController < ApplicationController
if @user_course_identity > = Course :: STUDENT
if @user_course_identity > = Course :: STUDENT
tip_exception ( 403 , " 无权限操作 " )
tip_exception ( 403 , " 无权限操作 " )
elsif @work_excel . blank? || @work_excel . size == 0
elsif @work_excel . blank? || @work_excel . size == 0
normal_status ( - 1 , " 暂无用户提交! " )
normal_status ( - 1 , " 暂无用户提交! " )
elsif params [ :export ] . present? && params [ :export ]
elsif params [ :export ] . present? && params [ :export ]
normal_status ( 0 , " 正在下载中 " )
normal_status ( 0 , " 正在下载中 " )
else
else
respond_to do | format |
respond_to do | format |
format . xlsx {
format . xlsx {
set_export_cookies
set_export_cookies
student_work_to_xlsx ( @work_excel , @homework )
student_work_to_xlsx ( @work_excel , @homework )
exercise_export_name = " #{ current_user . real_name } _ #{ @course . name } _ #{ @homework . name } _ #{ Time . now . strftime ( '%Y%m%d_%H%M%S' ) } "
exercise_export_name = " #{ current_user . real_name } _ #{ @course . name } _ #{ @homework . name } _ #{ Time . now . strftime ( '%Y%m%d_%H%M%S' ) } "
render xlsx : " #{ exercise_export_name . strip } " , template : " homework_commons/works_list.xlsx.axlsx " , locals :
render xlsx : " #{ exercise_export_name . strip } " , template : " homework_commons/works_list.xlsx.axlsx " , locals :
{ table_columns : @work_head_cells , task_users : @work_cells_column }
{ table_columns : @work_head_cells , task_users : @work_cells_column }
}
}
end
end
end
end
@ -252,10 +268,10 @@ class HomeworkCommonsController < ApplicationController
if status == 0
if status == 0
if params [ :export ] . present? && params [ :export ]
if params [ :export ] . present? && params [ :export ]
normal_status ( 0 , " 正在下载中 " )
normal_status ( 0 , " 正在下载中 " )
else
else
respond_to do | format |
respond_to do | format |
format . zip {
format . zip {
set_export_cookies
set_export_cookies
zipfile = zip_homework_common @homework , zip_works
zipfile = zip_homework_common @homework , zip_works
file = decode64 ( zipfile [ 0 ] [ :base64file ] )
file = decode64 ( zipfile [ 0 ] [ :base64file ] )
@ -273,21 +289,14 @@ class HomeworkCommonsController < ApplicationController
def update_score
def update_score
tip_exception ( " 作业还未发布,暂不能计算成绩 " ) if @homework . publish_time . nil? || @homework . publish_time > Time . now
tip_exception ( " 作业还未发布,暂不能计算成绩 " ) if @homework . publish_time . nil? || @homework . publish_time > Time . now
begin
@homework . update_homework_work_score
@homework . update_homework_work_score
normal_status ( " 更新成功 " )
normal_status ( " 更新成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
def update_student_score
def update_student_score
work = @homework . student_works . find_by ( user_id : current_user . id )
work = @homework . student_works . find_by ( user_id : current_user . id )
myshixun = Myshixun . find_by ( shixun_id : params [ :shixun_id ] , user_id : current_user . id )
myshixun = Myshixun . find_by ( shixun_id : params [ :shixun_id ] , user_id : current_user . id )
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
if work && myshixun
if work && myshixun
challenge_settings = @homework . homework_challenge_settings
challenge_settings = @homework . homework_challenge_settings
games = myshixun . games . where ( challenge_id : challenge_settings . pluck ( :challenge_id ) )
games = myshixun . games . where ( challenge_id : challenge_settings . pluck ( :challenge_id ) )
@ -296,11 +305,6 @@ class HomeworkCommonsController < ApplicationController
else
else
normal_status ( " 还未开启挑战,暂不能更新成绩 " )
normal_status ( " 还未开启挑战,暂不能更新成绩 " )
end
end
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
end
end
@ -355,6 +359,9 @@ class HomeworkCommonsController < ApplicationController
def new
def new
tip_exception ( " type参数有误 " ) if params [ :type ] . blank? || ! [ 1 , 3 ] . include? ( params [ :type ] . to_i )
tip_exception ( " type参数有误 " ) if params [ :type ] . blank? || ! [ 1 , 3 ] . include? ( params [ :type ] . to_i )
@homework_type = params [ :type ] . to_i
@homework_type = params [ :type ] . to_i
module_type = params [ :type ] . to_i == 1 ? " common_homework " : " group_homework "
@main_category = @course . course_modules . find_by ( module_type : module_type )
@category = @main_category . course_second_categories . find_by ( id : params [ :category ] ) if params [ :category ] . present?
end
end
def create
def create
@ -366,13 +373,17 @@ class HomeworkCommonsController < ApplicationController
end
end
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
@homework = HomeworkCommon . new ( homework_params )
@homework = HomeworkCommon . new ( homework_params )
@homework . reference_answer = params [ :reference_answer ] . to_s . strip
@homework . reference_answer = params [ :reference_answer ] . to_s . strip
@homework . homework_type = @homework_type
@homework . homework_type = @homework_type
@homework . user_id = current_user . id
@homework . user_id = current_user . id
@homework . course_id = @course . id
@homework . course_id = @course . id
if params [ :category ] . present?
category = @course . course_second_categories . find_by ( id : params [ :category ] )
@homework . course_second_category_id = category & . id . to_i
end
homework_detail_manual = HomeworkDetailManual . new
homework_detail_manual = HomeworkDetailManual . new
@homework . homework_detail_manual = homework_detail_manual
@homework . homework_detail_manual = homework_detail_manual
homework_detail_manual . te_proportion = 0 . 7
homework_detail_manual . te_proportion = 0 . 7
@ -397,16 +408,16 @@ class HomeworkCommonsController < ApplicationController
else
else
tip_exception ( " 创建失败 " )
tip_exception ( " 创建失败 " )
end
end
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
end
end
def edit
def edit
if @homework . course_second_category_id == 0
module_type = @homework . homework_type == " normal " ? " common_homework " : " group_homework "
@main_category = @course . course_modules . find_by ( module_type : module_type )
else
@category = @homework . course_second_category
end
end
end
def update
def update
@ -416,7 +427,6 @@ class HomeworkCommonsController < ApplicationController
end
end
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
@homework . update_attributes! ( homework_params )
@homework . update_attributes! ( homework_params )
@homework . reference_answer = params [ :reference_answer ] . to_s . strip
@homework . reference_answer = params [ :reference_answer ] . to_s . strip
@ -435,11 +445,7 @@ class HomeworkCommonsController < ApplicationController
Attachment . associate_container ( params [ :reference_attachment_ids ] , @homework . id , @homework . class , 2 ) if params [ :reference_attachment_ids ]
Attachment . associate_container ( params [ :reference_attachment_ids ] , @homework . id , @homework . class , 2 ) if params [ :reference_attachment_ids ]
normal_status ( 0 , " 更新成功 " )
normal_status ( 0 , " 更新成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
end
end
@ -451,7 +457,6 @@ class HomeworkCommonsController < ApplicationController
end
end
def update_settings
def update_settings
begin
# 课堂结束后不能再更新
# 课堂结束后不能再更新
unless @course . is_end
unless @course . is_end
@ -499,7 +504,7 @@ class HomeworkCommonsController < ApplicationController
# tip_exception("challenge_id参数的长度与challenge_score参数的长度不匹配") if
# tip_exception("challenge_id参数的长度与challenge_score参数的长度不匹配") if
# params[:challenge_settings][:challenge_score].length != params[:challenge_settings][:challenge_id].length
# params[:challenge_settings][:challenge_score].length != params[:challenge_settings][:challenge_id].length
sum_challenge_score = params [ :challenge_settings ] . pluck ( :challenge_score ) . reject ( & :blank? ) & . map { | score | score . to_f } . sum
sum_challenge_score = params [ :challenge_settings ] . pluck ( :challenge_score ) . reject ( & :blank? ) & . map { | score | score . to_f } . sum
total_score = params [ :work_efficiency ] ? ( params [ :eff_score ] . to_f + sum_challenge_score ) : sum_challenge_score
total_score = params [ :work_efficiency ] ? ( params [ :eff_score ] . to_f + sum_challenge_score ) : sum_challenge_score
tip_exception ( " 分值之和必须等于总分值: #{ params [ :total_score ] } 分 " ) if params [ :total_score ] . to_f . round ( 2 ) != total_score . to_f . round ( 2 )
tip_exception ( " 分值之和必须等于总分值: #{ params [ :total_score ] } 分 " ) if params [ :total_score ] . to_f . round ( 2 ) != total_score . to_f . round ( 2 )
@ -744,11 +749,6 @@ class HomeworkCommonsController < ApplicationController
# uid_logger(ex.message)
# uid_logger(ex.message)
# render_error(ex.message)
# render_error(ex.message)
# raise ActiveRecord::Rollback
# raise ActiveRecord::Rollback
rescue Exception = > e
uid_logger ( e . backtrace )
tip_exception ( e . message )
raise ActiveRecord :: Rollback
end
end
end
# 选用实训
# 选用实训
@ -814,7 +814,7 @@ class HomeworkCommonsController < ApplicationController
## 分页参数
## 分页参数
page = params [ :page ] || 1
page = params [ :page ] || 1
limit = params [ :limit ] || 15
limit = params [ :limit ] || 15
offset = ( page . to_i - 1 ) * limit
offset = ( page . to_i - 1 ) * limit
# 最热排序
# 最热排序
if reorder == " myshixun_count "
if reorder == " myshixun_count "
@ -902,7 +902,8 @@ class HomeworkCommonsController < ApplicationController
def publish_groups
def publish_groups
@current_user = current_user
@current_user = current_user
if @homework . publish_immediately @current_user
charge_ids = @course . charge_group_ids ( @current_user )
if @homework . publish_immediately charge_ids
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
# 可立即发布的分班:当前用户管理的分班去除已发布的分班
group_ids = @course . charge_group_ids ( @current_user ) - @homework . homework_group_settings . group_published . pluck ( :course_group_id )
group_ids = @course . charge_group_ids ( @current_user ) - @homework . homework_group_settings . group_published . pluck ( :course_group_id )
@course_groups = @course . course_groups . where ( id : group_ids )
@course_groups = @course . course_groups . where ( id : group_ids )
@ -918,16 +919,14 @@ class HomeworkCommonsController < ApplicationController
if params [ :detail ] . blank?
if params [ :detail ] . blank?
tip_exception ( " 缺少截止时间参数 " ) if params [ :end_time ] . blank?
tip_exception ( " 缺少截止时间参数 " ) if params [ :end_time ] . blank?
tip_exception ( " 截止时间不能早于当前时间 " ) if params [ :end_time ] < = strf_time ( Time . now )
tip_exception ( " 截止时间不能早于当前时间 " ) if params [ :end_time ] < = strf_time ( Time . now )
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if
tip_exception ( " 截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if @course . end_date . present? && params [ :end_time ] > strf_time ( @course . end_date . end_of_day )
@course . end_date . present? && params [ :end_time ] > strf_time ( @course . end_date . end_of_day )
else
else
tip_exception ( " 缺少分班截止时间参数 " ) if params [ :group_end_times ] . blank?
tip_exception ( " 缺少分班截止时间参数 " ) if params [ :group_end_times ] . blank?
group_end_times = params [ :group_end_times ] . reject ( & :blank? ) & . map { | time | time . to_time }
group_end_times = params [ :group_end_times ] . reject ( & :blank? ) & . map { | time | time . to_time }
tip_exception ( " 截止时间和分班参数的个数不一致 " ) if group_end_times . length != group_ids . length
tip_exception ( " 截止时间和分班参数的个数不一致 " ) if group_end_times . length != group_ids . length
group_end_times . each do | time |
group_end_times . each do | time |
tip_exception ( " 分班截止时间不能早于当前时间 " ) if time < = Time . now
tip_exception ( " 分班截止时间不能早于当前时间 " ) if time < = Time . now
tip_exception ( " 分班截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if
tip_exception ( " 分班截止时间不能晚于课堂结束时间( #{ @course . end_date . end_of_day . strftime ( " %Y-%m-%d %H:%M " ) } ) " ) if @course . end_date . present? && time > @course . end_date . end_of_day
@course . end_date . present? && time > @course . end_date . end_of_day
end
end
end
end
@ -938,7 +937,6 @@ class HomeworkCommonsController < ApplicationController
publish_groups = charge_group_ids & group_ids if group_ids
publish_groups = charge_group_ids & group_ids if group_ids
# ActiveRecord::Base.transaction do
# ActiveRecord::Base.transaction do
begin
homeworks . each do | homework |
homeworks . each do | homework |
# 作业未发布时
# 作业未发布时
if homework . homework_detail_manual . try ( :comment_status ) == 0
if homework . homework_detail_manual . try ( :comment_status ) == 0
@ -1013,7 +1011,7 @@ class HomeworkCommonsController < ApplicationController
end
end
# 补交结束时间
# 补交结束时间
homework . late_time = Time . at ( homework . end_time . to_i + 30 * 24 * 3600 ) if homework . allow_late && homework . late_time . nil?
homework . late_time = Time . at ( homework . end_time . to_i + 30 * 24 * 3600 ) if homework . allow_late && homework . late_time . nil?
homework . save!
homework . save!
@ -1021,17 +1019,14 @@ class HomeworkCommonsController < ApplicationController
# HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
# HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id)
end
end
normal_status ( 0 , " 发布成功 " )
normal_status ( 0 , " 发布成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( " 发布失败 " )
raise ActiveRecord :: Rollback
end
# end
# end
end
end
def end_groups
def end_groups
@current_user = current_user
@current_user = current_user
if @homework . end_immediately @current_user
charge_ids = @course . charge_group_ids ( @current_user )
if @homework . end_immediately charge_ids
# 可立即截止的分班:统一设置则是用户管理的所有分班,否则是当前用户管理的分班中已发布且未截止的
# 可立即截止的分班:统一设置则是用户管理的所有分班,否则是当前用户管理的分班中已发布且未截止的
charge_group_ids = @course . charge_group_ids ( @current_user ) # 当前用户管理的分班
charge_group_ids = @course . charge_group_ids ( @current_user ) # 当前用户管理的分班
group_ids = @homework . unified_setting ? charge_group_ids :
group_ids = @homework . unified_setting ? charge_group_ids :
@ -1056,7 +1051,6 @@ class HomeworkCommonsController < ApplicationController
group_ids = params [ :group_ids ] & . reject ( & :blank? ) & . map ( & :to_i )
group_ids = params [ :group_ids ] & . reject ( & :blank? ) & . map ( & :to_i )
end_groups = charge_group_ids & group_ids if group_ids
end_groups = charge_group_ids & group_ids if group_ids
begin
homeworks . each do | homework |
homeworks . each do | homework |
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
homework_detail_manual = homework . homework_detail_manual
homework_detail_manual = homework . homework_detail_manual
@ -1101,11 +1095,6 @@ class HomeworkCommonsController < ApplicationController
HomeworkEndUpdateScoreJob . perform_later ( 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
normal_status ( 0 , " 更新成功 " )
normal_status ( 0 , " 更新成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( " 操作失败 " )
raise ActiveRecord :: Rollback
end
end
end
def set_public
def set_public
@ -1138,7 +1127,6 @@ class HomeworkCommonsController < ApplicationController
# 删除多个作业
# 删除多个作业
def multi_destroy
def multi_destroy
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
homeworks = @course . homework_commons . where ( id : params [ :homework_ids ] )
homeworks = @course . homework_commons . where ( id : params [ :homework_ids ] )
homeworks . destroy_all
homeworks . destroy_all
@ -1146,11 +1134,6 @@ class HomeworkCommonsController < ApplicationController
StudentWork . where ( homework_common_id : homeworks . pluck ( :id ) ) . destroy_all
StudentWork . where ( homework_common_id : homeworks . pluck ( :id ) ) . destroy_all
normal_status ( 0 , " 删除成功 " )
normal_status ( 0 , " 删除成功 " )
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( " 删除失败 " )
raise ActiveRecord :: Rollback
end
end
end
end
end
@ -1160,7 +1143,6 @@ class HomeworkCommonsController < ApplicationController
homeworks . each do | homework |
homeworks . each do | homework |
ActiveRecord :: Base . transaction do
ActiveRecord :: Base . transaction do
begin
homework_bank = current_user . homework_banks . find_by ( homework_common_id : homework . id )
homework_bank = current_user . homework_banks . find_by ( homework_common_id : homework . id )
if homework_bank . present?
if homework_bank . present?
# 如果作业加入过题库则更新参数
# 如果作业加入过题库则更新参数
@ -1190,11 +1172,6 @@ class HomeworkCommonsController < ApplicationController
homework . update_attributes! ( homework_bank_id : new_homework_bank . id )
homework . update_attributes! ( homework_bank_id : new_homework_bank . id )
end
end
rescue Exception = > e
uid_logger ( e . message )
tip_exception ( " 删除失败 " )
raise ActiveRecord :: Rollback
end
end
end
end
end
normal_status ( 0 , " 加入成功 " )
normal_status ( 0 , " 加入成功 " )
@ -1211,7 +1188,7 @@ class HomeworkCommonsController < ApplicationController
# 班级作品查重
# 班级作品查重
def homework_code_repeat
def homework_code_repeat
tip_exception ( - 1 , " 分班id不能为空! " ) if params [ :group_ids ] . nil?
tip_exception ( - 1 , " 分班id不能为空! " ) if params [ :group_ids ] . nil?
shixun = @homework . shixuns . take
shixun = @homework . shixuns . take
# 通过代码文件来判断语言
# 通过代码文件来判断语言
language = shixun . challenges . practice_type . pluck ( :path ) . first
language = shixun . challenges . practice_type . pluck ( :path ) . first
@ -1252,13 +1229,13 @@ class HomeworkCommonsController < ApplicationController
normal_status ( " 代码查重成功 " )
normal_status ( " 代码查重成功 " )
else
else
if result . status == 1
if result . status == 1
tip_exception ( - 4 , " 代码查重异常,请稍后重试 " )
tip_exception ( - 4 , " 代码查重异常,请稍后重试 " )
else
else
tip_exception ( - 3 , " 正在查重,请在几分钟后刷新页面查看结果 " )
tip_exception ( - 3 , " 正在查重,请在几分钟后刷新页面查看结果 " )
end
end
end
end
else
else
tip_exception ( - 2 , " 平台目前支持java、python语言的查重<br/>其他语言正在规划中,敬请期待 " )
tip_exception ( - 2 , " 平台目前支持java、python语言的查重<br/>其他语言正在规划中,敬请期待 " )
end
end
end
end
@ -1313,7 +1290,7 @@ class HomeworkCommonsController < ApplicationController
# 最新一次的查重时间
# 最新一次的查重时间
@last_review_time = format_time @homework . homework_group_reviews . last . try ( :created_at )
@last_review_time = format_time @homework . homework_group_reviews . last . try ( :created_at )
@charge_ids = @course . charge_group_ids ( @current_user )
end
end
# 代码查重代码的详情
# 代码查重代码的详情
@ -1356,8 +1333,8 @@ class HomeworkCommonsController < ApplicationController
# 代码部分
# 代码部分
code_list = [ ]
code_list = [ ]
challenge . path . split ( " ; " ) . each do | path |
challenge . path . split ( " ; " ) . each do | path |
if code_info . select { | info | path == info . origin_path } . size > 0
if code_info . select { | info | path == info . origin_path } . size > 0
info = code_info . select { | info | path == info . origin_path } [ 0 ]
info = code_info . select { | info | path == info . origin_path } [ 0 ]
code_list << { path : path , origin_content : info . origin_content , target_content : info . target_content }
code_list << { path : path , origin_content : info . origin_content , target_content : info . target_content }
end
end
end
end
@ -1415,7 +1392,7 @@ class HomeworkCommonsController < ApplicationController
def require_id_params
def require_id_params
tip_exception ( " 请至少选择一个作业 " ) if params [ :homework_ids ] . blank?
tip_exception ( " 请至少选择一个作业 " ) if params [ :homework_ids ] . blank?
tip_exception ( " 批量设置不能超过15个 " ) if params [ :homework_ids ] . length > 15
tip_exception ( " 批量设置不能超过15个 " ) if params [ :homework_ids ] . length > 15 && params [ :type ] . blank?
end
end
def validate_min_max_num
def validate_min_max_num
@ -1443,7 +1420,7 @@ class HomeworkCommonsController < ApplicationController
user_rate = 0
user_rate = 0
# 计算每个关卡的相似度
# 计算每个关卡的相似度
challenges . each do | challenge |
challenges . each do | challenge |
game_codes = results . user_lists . select { | user_list | user_list . user_id == user &&
game_codes = results . user_lists . select { | user_list | user_list . user_id == user &&
challenge . path . split ( " ; " ) . include? ( user_list . origin_path ) }
challenge . path . split ( " ; " ) . include? ( user_list . origin_path ) }
# 先判断用户该关卡是否查重了 取多个待补充文件的平均值
# 先判断用户该关卡是否查重了 取多个待补充文件的平均值
if game_codes . count > 0
if game_codes . count > 0