From aba87a146a8796cd04806a1d30e6e0a44747e3c6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 19 Nov 2019 10:38:50 +0800 Subject: [PATCH] =?UTF-8?q?tpi=E8=80=97=E6=97=B6=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 ++++-- app/views/games/cost_time.json.jbuilder | 1 - .../20191119021843_add_close_browser_time_for_games.rb | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) delete mode 100644 app/views/games/cost_time.json.jbuilder create mode 100644 db/migrate/20191119021843_add_close_browser_time_for_games.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1457cafcc..d4275b600 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -767,8 +767,9 @@ class GamesController < ApplicationController # 记录实训花费的时间 # REDO:需要添加详细的说明 def cost_time - cost_time = params[:time].to_i - @game.update_attribute(:cost_time, cost_time) + return if @game.status >= 2 + cost_time = Time.now.to_i - @game.close_browse_time.to_i + @game.update_attributes(close_browse_time: Time.now, cost_time: cost_time) end # 同步challenge的更新时间 @@ -938,6 +939,7 @@ class GamesController < ApplicationController game.update_attributes(status: 0, open_time: Time.now) if game.open_time.blank? || game.status == 3 # 开启实训更新myshixuns的时间,方便跟踪用于的学习进度。 game.myshixun.update_column(:updated_at, Time.now) + @game.update_attribute(:close_browse_time, Time.now) if game.status < 2 && @game.close_browse_time.nil? end # vnc连接 diff --git a/app/views/games/cost_time.json.jbuilder b/app/views/games/cost_time.json.jbuilder deleted file mode 100644 index efe6fc949..000000000 --- a/app/views/games/cost_time.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.game @game \ No newline at end of file diff --git a/db/migrate/20191119021843_add_close_browser_time_for_games.rb b/db/migrate/20191119021843_add_close_browser_time_for_games.rb new file mode 100644 index 000000000..3bd40b679 --- /dev/null +++ b/db/migrate/20191119021843_add_close_browser_time_for_games.rb @@ -0,0 +1,5 @@ +class AddCloseBrowserTimeForGames < ActiveRecord::Migration[5.2] + def change + add_column :games, :close_browse_time, :timestamp + end +end