diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 47c8fc68c..e73243b94 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -162,7 +162,7 @@ class ChallengesController < ApplicationController #@pass_games_map = @shixun.challenges.joins(:games).where(games: {status:2}).group(:challenge_id).reorder(nil).count #@play_games_map = @shixun.challenges.joins(:games).where(games: {status:[0,1]}).group(:challenge_id).reorder(nil).count - @challenges = @shixun.challenges.joins(join_sql).select(base_columns) + @challenges = @shixun.challenges.joins(join_sql).select(base_columns).uniq #@challenges = @shixun.challenges.fields_for_list @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 29a9a9730..e816ab667 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -22,23 +22,17 @@ class MyshixunsController < ApplicationController tip_exception("403", "") end begin + @shixun = Shixun.select(:id, :identifier, :challenges_count).find(@myshixun.shixun_id) ActiveRecord::Base.transaction do - begin - @shixun = Shixun.select(:id, :identifier, :challenges_count).find(@myshixun.shixun_id) @myshixun.destroy! - StudentWork.where(:myshixun_id => @myshixun.id).update_all(myshixun_id: 0, work_status: 0, work_score: nil, - final_score: nil, efficiency: 0, eff_score: 0, calculation_time: nil, cost_time: 0, compelete_status: 0) - rescue Exception => e - logger.error("######reset_my_game_failed:#{e.message}") - raise("ActiveRecord::RecordInvalid") - end + + StudentWork.where(:myshixun_id => @myshixun.id) + .update_all(myshixun_id: 0, work_status: 0, work_score: nil, + final_score: nil, efficiency: 0, eff_score: 0, calculation_time: nil, cost_time: 0, compelete_status: 0) end # 删除版本库 GitService.delete_repository(repo_path: @repo_path) unless @shixun.is_choice_type? rescue Exception => e - if e.message != "ActiveRecord::RecordInvalid" - logger.error("######delete_repository_error-:#{e.message}") - end raise "delete_repository_error:#{e.message}" end end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 31a683760..42d7f3499 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -143,7 +143,7 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count #games.map{|g| g.status == 2}.count - self.games.where(status: 1).count + self.games.where(status: 2).count end # 关卡用户正在挑战的人数 diff --git a/app/models/game.rb b/app/models/game.rb index 144dbced2..d0d59c0e3 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -7,6 +7,7 @@ class Game < ApplicationRecord default_scope { order("games.created_at desc") } + #TODO: games表要增加challenge_id与user_id的唯一索引 has_many :outputs, -> { order('query_index DESC') } has_many :challenge_samples, :dependent => :destroy has_many :game_codes, :dependent => :destroy diff --git a/lib/tasks/schools.rake b/lib/tasks/schools.rake new file mode 100644 index 000000000..a788d57d1 --- /dev/null +++ b/lib/tasks/schools.rake @@ -0,0 +1,28 @@ +#coding=utf-8 + +desc "合并高校的数据,第一个参数是: 正确高校的id, 第二个参数是: 错误高校需要合并到正确高校的id" +# 命令: bundle exec rake schools:merge_school_data f_school=1 s_school=2,3 +namespace :schools do + task merge_school_data: :environment do + f_school = ENV['f_school'].to_i + school = School.find_by(id: f_school) + return if school.blank? + + s_school = ENV['s_school'].split(",") + merge_schools = School.where(id: s_school) + + # 改变用户的学校id 和 单位 + UserExtension.where(school_id: merge_schools) + .update_all(school_id: f_school, department_id: nil) + + # 改变课堂的学校id + Course.where(school_id: merge_schools).update_all(school_id: f_school) + + # 实训报告表迁移数据 + s_report = SchoolReport.find_by(school_id: f_school) + SchoolReport.where(school_id: merge_schools).each do |sr| + s_report.update_column(:shixun_evaluate_count, (s_report.shixun_evaluate_count+sr.shixun_evaluate_count)) + sr.update(shixun_evaluate_count: 0) + end + end +end \ No newline at end of file diff --git a/lib/tasks/video_transcode.rake b/lib/tasks/video_transcode.rake index 995f9a82f..4fb7c17bd 100644 --- a/lib/tasks/video_transcode.rake +++ b/lib/tasks/video_transcode.rake @@ -2,13 +2,18 @@ namespace :video_transcode do desc "视频转码成h264" task :submit => :environment do - Video.find_each do |v| - if v.uuid && !v.transcoded && !v.file_url.include?('.mp4') && !AliyunVod::Service.get_meta_code_info(v.uuid)[:codecnamne].start_with?("h264", "h265") - p "--- Start submit video trans code #{v.uuid}" - AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') - else + i = [] + Video.where.not(uuid: nil, file_url: nil).where(transcoded: false, status: "published").find_each do |v| + code_info = AliyunVod::Service.get_meta_code_info(v.uuid) + if v.file_url.include?('.mp4') && code_info[:codecnamne]&.include?("h264") v.update(transcoded: true) + else + puts("uuid: #{v.uuid}") + i << "#{v.id}, #{v.file_url}, #{code_info[:codecnamne]}" + AliyunVod::Service.submit_transcode_job(v.uuid, 'a0277c5c0c7458458e171b0cee6ebf5e') end end + puts "###########转码个数:#{i.size}" + puts "###########id,file_url, codecnamne:#{i}" end end \ No newline at end of file