Merge branch 'dev_shixuns' into dev_hjm_build

dev_hjm_build
hjm 6 years ago
commit cad884e6f7

@ -68,7 +68,8 @@ class ApplicationController < ActionController::Base
def ecloud_auth ucloud_user_id def ecloud_auth ucloud_user_id
euser = EcloudUser.where("id =? and opttype not in(3, 5)", ucloud_user_id).first euser = EcloudUser.where("id =? and opttype not in(3, 5)", ucloud_user_id).first
if euser.present? # 开通过业务 if euser.present? # 开通过业务
# # ni
else else
false false
end end

@ -33,10 +33,18 @@ class EcloudController < ApplicationController
def trustie_login def trustie_login
end end
CLIENT_ID = '1022' # 测试环境
CLIENT_SECRET = '2112037a-6d7a-432b-9081-feb1153d8668' # CLIENT_ID = '1022'
ROOT_URl = 'http://localhost:3000' # CLIENT_SECRET = '2112037a-6d7a-432b-9081-feb1153d8668'
SERVER_URL = "https://221.176.54.92:9081/restful/services/" # SERVER_URL = "https://221.176.54.92:9081/restful/services/"
#
# 正式环境
CLIENT_ID = '1056'
CLIENT_SECRET = '2e84256a-3de4-4713-9e02-10ee88a14592'
SERVER_URL = "https://221.176.53.130:44390/services/"
## 签名 ## 签名
def sign(timestamp) def sign(timestamp)
@ -55,12 +63,12 @@ class EcloudController < ApplicationController
begin begin
if params['opttype'] == 0 # 开通企业/个人业务 if params['opttype'] == 0 # 开通企业/个人业务
ecloud = Ecloud.create!(eloud_params) ecloud = Ecloud.create!(eloud_params)
create_service(params['services'], ecloud.try(:id)) create_service(params['services'], ecloud.try(:id)) if params['services'].present?
create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present? create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present?
# 为管理员添加一条记录 # 为管理员添加一条记录
# 开通的时候都是用户的opttype也是0 # 开通的时候都是用户的opttype也是0
# 如果管理员已经存在,则不用重复开通 # 如果管理员已经存在,则不用重复开通
euser = EcloudUser.where(id: params['userid'], custid: params['custid']).first euser = EcloudUser.where(userid: params['userid'], custid: params['custid']).first
unless euser unless euser
EcloudUser.create!(custid: params['custid'], opttype: params['opttype'], userid: params['userid'], EcloudUser.create!(custid: params['custid'], opttype: params['opttype'], userid: params['userid'],
username: params['username'], useralias: params['useralias'], username: params['username'], useralias: params['useralias'],
@ -88,7 +96,8 @@ class EcloudController < ApplicationController
elsif params['opttype'] == 1 # 业务变更 elsif params['opttype'] == 1 # 业务变更
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode']).first ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode']).first
# 套餐变更 # 套餐变更
# 新增业务 # 操作代码 0新增业务1注销业务2修改业务
# # 新增服务
add_service = params['services'].select{|s| s['opttype'] == 0} add_service = params['services'].select{|s| s['opttype'] == 0}
create_service(add_service, ecloud.try(:id)) if add_service.present? create_service(add_service, ecloud.try(:id)) if add_service.present?
@ -106,8 +115,8 @@ class EcloudController < ApplicationController
if edt_services.present? if edt_services.present?
edt_services.each do |es| edt_services.each do |es|
ese = EcloudService.where(ecloud_id: ecloud.try(:id), code: es['code']).first ese = EcloudService.where(ecloud_id: ecloud.try(:id), code: es['code']).first
ese.update_attributes!(opttype: es['opttype'], begintime: es['begintime'], endtime: es['endtime']) ese.update_attributes!(opttype: es['opttype'], begintime: es['begintime'], endtime: es['endtime']) if ese.present?
create_serviceparas es['serviceparas'].first, ese.id create_serviceparas(es['serviceparas'].first, ese.id) if ese.present?
end end
end end
@ -120,6 +129,7 @@ class EcloudController < ApplicationController
# ecloud_id = ecloud.try(:id) # ecloud_id = ecloud.try(:id)
elsif params['opttype'] == 4 # 再次重复开通 elsif params['opttype'] == 4 # 再次重复开通
# 再次申请开通,这种情况就是累加时间
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode']).first ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode']).first
create_service(params['services'], ecloud.try(:id)) create_service(params['services'], ecloud.try(:id))
create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present? create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present?

@ -1,10 +1,10 @@
# encoding: utf-8 # encoding: utf-8
class MyshixunsController < ApplicationController class MyshixunsController < ApplicationController
layout 'base_myshixun' layout 'base_myshixun'
skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh] skip_before_filter :verify_authenticity_token, :only => [:training_task_status, :close_webssh, :code_runinng_message]
before_filter :require_login, :except => [:training_task_status, :close_webssh] before_filter :require_login, :except => [:training_task_status, :close_webssh, :code_runinng_message]
before_filter :check_authentication, :except => [:training_task_status, :close_webssh, :mul_test_home, :mul_test_user, before_filter :check_authentication, :except => [:training_task_status, :close_webssh, :mul_test_home, :mul_test_user,
:mul_test_myshixun, :mul_test_shixun, :mul_test_start] :mul_test_myshixun, :mul_test_shixun, :mul_test_start, :code_runinng_message]
before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh, :sync_reset_time, :destroy, :search_file_list, :vnc] before_filter :find_myshixun, :only => [:show, :myshixun_reset, :open_webssh, :sync_reset_time, :destroy, :search_file_list, :vnc]
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
@ -435,6 +435,39 @@ class MyshixunsController < ApplicationController
end end
# 代码运行中的信息接口
def code_runinng_message
begin
logger.info("######################params: #{params}")
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
game_id = jsonTestDetails['buildID']
message = jsonTestDetails['textMsg']
logger.info("##################code_runinng_message:#{jsonTestDetails}")
logger.info("##################buildID: #{game_id}")
logger.info("##################textMsg: #{message}")
if game_id.present? && message.present?
game = Game.find game_id
msg = game.run_code_message
# 只有评测中的game才会创建和更新代码评测中的信息
logger.info("##################game: #{game.status}")
logger.info("##################retry_status: #{game.retry_status}")
if game.status == 1 || game.status == 2 && game.retry_status == 1
if msg.blank?
RunCodeMessage.create!(:game_id => game_id, :status => 1, :message => message)
else
msg.update_attributes(:status => (msg.status + 1), :message => message)
end
else
# 评测完成,初始化评测信息的状态
msg.update_attributes(:status => 0, :message => nil) if msg.present?
end
render :json => {:data => "success"}
end
rescue Exception => e
render :json => {:data => "failed"}
end
end
# taskId 即返回的game id # taskId 即返回的game id
# 返回结果params [:stauts] 0 表示成功,其它则失败 # 返回结果params [:stauts] 0 表示成功,其它则失败
# msg 错误信息 # msg 错误信息
@ -537,6 +570,9 @@ class MyshixunsController < ApplicationController
:create_pod => timeCost['createPod'], :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :create_pod => timeCost['createPod'], :pod_execute => timeCost['execute'], :test_cases => test_cases_time,
:brige => timeCost['evaluateAllTime'], :return_back => return_back_time) :brige => timeCost['evaluateAllTime'], :return_back => return_back_time)
end end
# 清空代码评测信息
msg = game.run_code_message
msg.update_column(:status => 0, :message => nil) if msg.present?
logger.info("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") logger.info("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
render :json => {:data => "success"} render :json => {:data => "success"}
rescue Exception => e rescue Exception => e

@ -113,7 +113,7 @@ class StudentWorkController < ApplicationController
pass_consume_time += (game.cost_time / 60.0).to_f pass_consume_time += (game.cost_time / 60.0).to_f
end end
all_time += (game.cost_time / 60.0).to_f all_time += (game.cost_time / 60.0).to_f
user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i user_total_score += game.final_score.to_i <= 0 ? 0 : game.challenge.score.to_i
if myshixun.user_id == @work.user.id if myshixun.user_id == @work.user.id
@game_user_query << [game.id, game.outputs.first.try(:query_index).to_i] @game_user_query << [game.id, game.outputs.first.try(:query_index).to_i]
end end

@ -1,3 +1,4 @@
# 操作代码 0新增业务1注销业务2修改业务
class EcloudService < ActiveRecord::Base class EcloudService < ActiveRecord::Base
attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid
belongs_to :ecloud belongs_to :ecloud

@ -13,6 +13,7 @@ class Game < ActiveRecord::Base
has_many :challenge_samples has_many :challenge_samples
has_many :game_codes, :dependent => :destroy has_many :game_codes, :dependent => :destroy
has_many :evaluate_records, :dependent => :destroy has_many :evaluate_records, :dependent => :destroy
has_one :run_code_message, :dependent => :destroy
include ApplicationHelper include ApplicationHelper
scope :min, lambda { select([:id, :status, :myshixun_id, :user_id, :final_score, :challenge_id, :identifier, scope :min, lambda { select([:id, :status, :myshixun_id, :user_id, :final_score, :challenge_id, :identifier,

@ -0,0 +1,5 @@
class RunCodeMessage < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :game
end

@ -793,7 +793,10 @@ class GamesService
# 如果没有超时并且正在评测中 # 如果没有超时并且正在评测中
# 判断评测中的状态有两种1、如果之前没有通关的只需判断status为1即可如果通过关则判断game的resubmit_identifier是否更新 # 判断评测中的状态有两种1、如果之前没有通关的只需判断status为1即可如果通过关则判断game的resubmit_identifier是否更新
if (params[:time_out] == "false") && ((params[:resubmit].blank? && game.status==1) || (params[:resubmit].present? && (params[:resubmit] != resubmit_identifier))) if (params[:time_out] == "false") && ((params[:resubmit].blank? && game.status==1) || (params[:resubmit].present? && (params[:resubmit] != resubmit_identifier)))
return # 代码评测的信息
running_code_status = game.run_code_message.try(:status)
running_code_message = game.run_code_message.try(:message)
return {:running_code_status => running_code_status, :running_code_message => running_code_message}
end end
Rails.logger.info("##### resubmit_identifier is #{resubmit_identifier}") Rails.logger.info("##### resubmit_identifier is #{resubmit_identifier}")
@ -886,8 +889,10 @@ class GamesService
next_game = Game.next_game(shixun.id, game.myshixun_id, game_challenge.position).try(:identifier) next_game = Game.next_game(shixun.id, game.myshixun_id, game_challenge.position).try(:identifier)
output_hash = {:test_sets => test_sets, :had_test_count => test_sets_count, :test_sets_count => test_sets_count, :had_passed_testsests_error_count => had_passed_testsests_error_count} output_hash = {:test_sets => test_sets, :had_test_count => test_sets_count, :test_sets_count => test_sets_count, :had_passed_testsests_error_count => had_passed_testsests_error_count}
return {:grade => grade, :gold => score, :experience => experience, :status => game_status, :had_done => had_done, :position => game_challenge.position,
:port => port, :power => power, :record => record, :mirror_name => mirror_name, :picture => picture, :web_route => web_route, :latest_output => latest_output, return {:grade => grade, :gold => score, :experience => experience, :status => game_status, :had_done => had_done,
:position => game_challenge.position, :port => port, :power => power, :record => record,
:mirror_name => mirror_name, :picture => picture, :web_route => web_route, :latest_output => latest_output,
:star => game.star, :next_game => next_game, :prev_game => prev_game}.merge(output_hash) :star => game.star, :next_game => next_game, :prev_game => prev_game}.merge(output_hash)
end end

@ -464,6 +464,7 @@ RedmineApp::Application.routes.draw do ## oauth相关
get 'sigle_mul_test' get 'sigle_mul_test'
get 'sigle_update_myshixun' get 'sigle_update_myshixun'
match 'training_task_status', :via => [:get, :post] match 'training_task_status', :via => [:get, :post]
match 'code_runinng_message', :via => [:get, :post]
end end
resources :games, :path => "stages" do resources :games, :path => "stages" do
member do member do

@ -0,0 +1,10 @@
class CreateRunCodeMessages < ActiveRecord::Migration
def change
create_table :run_code_messages do |t|
t.integer :status
t.string :message
t.references :game
t.timestamps
end
end
end

@ -0,0 +1,5 @@
FactoryGirl.define do
factory :run_code_message do
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe RunCodeMessage, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save