diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3b14eea84..a319dc58a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -488,17 +488,19 @@ class ShixunsController < ApplicationController tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") end current_myshixun = @shixun.current_myshixun(current_user.id) + + min_challenges = @shixun.challenges.pluck(:id , :st) + if current_myshixun + games = current_myshixun.games # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - if current_myshixun.games.count != @shixun.challenges_count || - current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id) - uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") + if games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end # 如果存在实训,则直接进入实训 - @current_task = current_myshixun.current_task + @current_task = current_myshixun.current_task(games) else # 如果未创建关卡一定不能开启实训,否则TPI没法找到当前的关卡 if @shixun.challenges_count == 0 @@ -506,10 +508,10 @@ class ShixunsController < ApplicationController end # 判断实训是否全为选择题 - is_choice_type = @shixun.is_choice_type? + is_choice_type = (min_challenges.size == min_challenges.select{|challenge| challenge.last == 1}.count) if !is_choice_type commit = GitService.commits(repo_path: @repo_path).try(:first) - Rails.logger.info("First comit########{commit}") + uid_logger("First comit########{commit}") tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? commit_id = commit["id"] end @@ -528,13 +530,13 @@ class ShixunsController < ApplicationController # fork仓库 project_fork(myshixun, @repo_path, current_user.login) - #rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) - #uid_logger("start openGameInstance") - #uri = "#{cloud_bridge}/bridge/game/openGameInstance" - #logger.info("end openGameInstance") - #params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} - #uid_logger("openGameInstance params is #{params}") - # res = interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" + rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) + uid_logger("start openGameInstance") + uri = "#{cloud_bridge}/bridge/game/openGameInstance" + logger.info("end openGameInstance") + params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} + uid_logger("openGameInstance params is #{params}") + interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" end # 其它创建关卡等操作 challenges = @shixun.challenges @@ -565,6 +567,7 @@ class ShixunsController < ApplicationController end end end + # gameID 及实训ID # status: 0 , 1 申请过, 2,实训关卡路径未填, 3 实训标签未填, 4 实训未创建关卡 def publish diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index a1aca3253..d8f294a39 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -53,14 +53,12 @@ class Myshixun < ApplicationRecord end # 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录) - # status:0 可以测评的,正在测评的 + # status:0 可以测评的; 1 正在测评的; 2评测通过的; 3未开启的 # 如果都完成,则当前任务为最后一个任务 - def current_task - games = self.games + def current_task games current_game = games.select{|game| game.status == 1 || game.status == 0}.first if current_game.blank? - current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} - and g.challenge_id = c.id and g.status = 2 order by c.position desc").first + current_game = games.last end current_game end diff --git a/app/services/git_service.rb b/app/services/git_service.rb index 3298185bf..076f62920 100644 --- a/app/services/git_service.rb +++ b/app/services/git_service.rb @@ -33,7 +33,12 @@ class GitService res = https.request(req) body = res.body logger.info("--uri_exec: .....res is #{body}") + content = JSON.parse(body) + if content["code"] != 0 + raise("版本库异常") + logger.error("repository error: #{content['msg']}") + end #raise content["msg"] if content["code"] != 0 content["data"]