Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_course
cxt 5 years ago
commit cb1801470c

@ -221,12 +221,12 @@ class GamesController < ApplicationController
@result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer @result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer
end end
# 获取答案 # 获取实践题答案
# GET: /tasks/:identifier/get_answer_info # GET: /tasks/:identifier/get_answer_info
# 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框
def get_answer_info def get_answer_info
challenge = @game.challenge @challenge = @game.challenge
@challenge_answers = challenge.challenge_answers @challenge_answers = @challenge.challenge_answers
# 平台已认证的老师需要控制 # 平台已认证的老师需要控制
@power = (@identity < User::EDU_GAME_MANAGER) @power = (@identity < User::EDU_GAME_MANAGER)
if !@power if !@power
@ -243,16 +243,29 @@ class GamesController < ApplicationController
end end
end end
end end
end
# 获取选择题答案
def get_choose_answer
@challenge = @game.challenge
tip_exception("本接口只能获取选择题答案") if @challenge.st != 1
@power = (@identity < User::EDU_GAME_MANAGER)
# 如果没权限,也没看过答案,则需要解锁
if @game.answer_open == 0 && !@power
tip_exception(1, @challenge.choose_score)
else
@challenge_chooses = @challenge.challenge_chooses
end
end end
# 解锁答案 # 解锁实践题答案
# GET: /tasks/:identifier/get_answer_info?answer_id=? # GET: /tasks/:identifier/get_answer_info?answer_id=?
def unlock_answer def unlock_answer
@challenge = @game.challenge
@answer = ChallengeAnswer.find(params[:answer_id]) @answer = ChallengeAnswer.find(params[:answer_id])
challenge = @answer.challenge challenge = @answer.challenge
# 解锁需要本层级的答案是否需要扣分 # 解锁需要本层级的答案是否需要扣分
points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) points = challenge.challenge_answers.where(level: @game.answer_open + 1..@answer.level).sum(:score)
deduct_score = ((points / 100.0) * challenge.score).to_i deduct_score = ((points / 100.0) * challenge.score).to_i
uid_logger("############金币数目: #{current_user.grade}") uid_logger("############金币数目: #{current_user.grade}")
unless current_user.grade.to_i - deduct_score > 0 unless current_user.grade.to_i - deduct_score > 0
@ -263,15 +276,16 @@ class GamesController < ApplicationController
begin begin
# 积分消耗情况记录 # 积分消耗情况记录
score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i
RewardGradeService.call(current_user, container_id: @answer.id, container_type: 'Answer', score: score) RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: score)
# 通关查看答案 不扣 得分 # 通关查看答案 不扣 得分
answer_open = @challenge.st == 1 ? 1 : @answer.level
if @game.status == 2 if @game.status == 2
@game.update_attributes!(:answer_open => @answer.level) @game.update_attributes!(:answer_open =>answer_open)
else else
# 扣除总分计算 # 扣除总分计算
answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score) answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score)
@game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction) @game.update_attributes!(:answer_open => answer_open, :answer_deduction => answer_deduction)
end end
rescue Exception => e rescue Exception => e
@ -279,7 +293,32 @@ class GamesController < ApplicationController
raise ActiveRecord::Rollback raise ActiveRecord::Rollback
end end
end end
end
# 解锁选择题答案
def unlock_choose_answer
@challenge = @game.challenge
score = @challenge.choose_score
unless current_user.grade.to_i - score > 0
tip_exception("您没有足够的金币")
end
ActiveRecord::Base.transaction do
begin
# 积分消耗情况记录
RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: -score)
# 通关查看答案 不扣 得分
if @game.status == 2
@game.update_attributes!(:answer_open => 1)
else
# 扣除总分计算
@game.update_attributes!(:answer_open => 1, :answer_deduction => 100)
end
@challenge_answers = @challenge.challenge_chooses
rescue Exception => e
uid_logger_error("#######金币扣除异常: #{e.message}")
raise ActiveRecord::Rollback
end
end
end end
# 查看答案需要扣取金币 # 查看答案需要扣取金币

@ -1302,7 +1302,7 @@ class PollsController < ApplicationController
sub_commit = [] sub_commit = []
user_commit = [] user_commit = []
poll_users_info = %w(序号) poll_users_info = %w(序号)
poll_ques_titles = poll_questions.pluck(:question_title).map {|k| k.strip if k.present?} poll_ques_titles = poll_questions.pluck(:question_title).map {|k| ActionController::Base.helpers.strip_tags(k) if k.present?}
poll_un_anony = poll.un_anonymous poll_un_anony = poll.un_anonymous
if poll_un_anony #是否匿名默认为false if poll_un_anony #是否匿名默认为false
user_info = %w(登陆名 真实姓名 邮箱 学号) user_info = %w(登陆名 真实姓名 邮箱 学号)

@ -1,5 +1,6 @@
index = 0 index = 0
json.status 3 json.status 3
# st: 0 实践题 1 选择题
json.message do json.message do
json.array! @challenge_answers do |answer| json.array! @challenge_answers do |answer|
index += 1 index += 1
@ -13,3 +14,5 @@ json.message do
end end
end end

@ -0,0 +1,6 @@
json.choose_answers do
json.array! @challenge_chooses do |choose|
json.position choose.position
json.answer choose.answer.blank? ? choose.standard_answer : choose.answer
end
end

@ -1 +1 @@
json.contents @answer.contents json.contents @answer.contents

@ -0,0 +1,6 @@
json.choose_answers do
json.array! @challenge_chooses do |choose|
json.position choose.position
json.answer choose.answer.blank? ? choose.standard_answer : choose.answer
end
end

@ -1,5 +1,5 @@
wb = xlsx_package.workbook wb = xlsx_package.workbook
wb.use_autowidth = false # wb.use_autowidth = false
wb.use_shared_strings = true wb.use_shared_strings = true
wb.styles do |s| wb.styles do |s|
@ -9,13 +9,13 @@ wb.styles do |s|
bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center }
wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet| wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet|
sheet.sheet_view.show_grid_lines = false sheet.sheet_view.show_grid_lines = false
sheet_title = table_columns sheet_title = table_columns
sheet_title_c = sheet_title.count sheet_title_c = sheet_title.count
sheet.add_row sheet_title, :style => bg_cell,:height => 15 sheet.add_row sheet_title,:height => 32, :style => bg_cell
sheet["J1:L1"].each { |c| c.style = bg_db } sheet["J1:L1"].each { |c| c.style = bg_db }
sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["M1:O1"].each { |c| c.style = bg_cc }
sheet["P1:Q1"].each { |c| c.style = bg_d2 } sheet["P1:Q1"].each { |c| c.style = bg_d2 }
@ -23,10 +23,10 @@ wb.styles do |s|
sheet["U1:W1"].each { |c| c.style = bg_bb } sheet["U1:W1"].each { |c| c.style = bg_bb }
if topic_users.count > 0 if topic_users.count > 0
topic_users.each do |user| topic_users.each do |user|
sheet.add_row user, :style => sz_all sheet.add_row user,:height => 18, :style => sz_all
end #each_widh_index end #each_widh_index
else else
sheet.add_row ["--"]*sheet_title_c sheet.add_row ["--"]*sheet_title_c,:height => 18
end end
sheet.column_widths *([15]*sheet.column_info.count) sheet.column_widths *([15]*sheet.column_info.count)

@ -124,6 +124,8 @@ Rails.application.routes.draw do
get :get_answer_info get :get_answer_info
get :unlock_answer get :unlock_answer
get :check_test_sets get :check_test_sets
get :unlock_choose_answer
get :get_choose_answer
end end
collection do collection do

Loading…
Cancel
Save