Merge branch 'dev_course' into dev_aliyun

dev_course
jingquan huang 6 years ago
commit b77cca1117

@ -19,8 +19,8 @@ class ApplicationController < ActionController::Base
# 全局配置参数 # 全局配置参数
# 返回name对应的value # 返回name对应的value
def edu_setting name def edu_setting(name)
EduSetting.find_by_name(name).try(:value) EduSetting.get(name)
end end
def user_course_identity def user_course_identity

@ -1,7 +1,6 @@
class ExerciseAnswersController < ApplicationController class ExerciseAnswersController < ApplicationController
before_action :require_login before_action :require_login
before_action :get_exercise_question before_action :get_exercise_question
before_action :commit_exercise_time
include ExercisesHelper include ExercisesHelper
def create #每一次答案的点击,请求一次,实训题不在这里回答 def create #每一次答案的点击,请求一次,实训题不在这里回答
@ -95,9 +94,11 @@ class ExerciseAnswersController < ApplicationController
def get_exercise_question def get_exercise_question
@exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id]) @exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id])
@exercise = @exercise_question.exercise @exercise = @exercise_question.exercise.includes(:exercise_users)
@course = @exercise.course @course = @exercise.course
@exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first #当前用户 @exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise_user_status = @exercise.get_exercise_status(current_user.id)
if @exercise_question.blank? if @exercise_question.blank?
normal_status(-1,"试卷问题不存在!") normal_status(-1,"试卷问题不存在!")
@ -105,34 +106,15 @@ class ExerciseAnswersController < ApplicationController
normal_status(-1,"试卷不存在!") normal_status(-1,"试卷不存在!")
elsif @course.blank? elsif @course.blank?
normal_status(-1,"该课堂不存在!") normal_status(-1,"该课堂不存在!")
elsif (@exercise_user.present? && @exercise_user.commit_status == 1) || (@exercise.end_time.present? && @exercise.end_time < Time.now) #已提交答案的/时间已结束的试卷不允许再修改 elsif (@exercise_user.present? && @exercise_user&.commit_status == 1) || @exercise_user_status == 3 #已提交答案的/时间已结束的试卷不允许再修改
normal_status(-1,"已提交/已结束的试卷不允许修改!") normal_status(-1,"已提交/已结束的试卷不允许修改!")
elsif @exercise.time > 0 elsif @exercise.time > 0
user_start_at = @exercise.exercise_users.exercise_commit_users(current_user.id).first.start_at user_start_at = @exercise_user&.start_at
exercise_time = @exercise.time.to_i exercise_time = @exercise.time.to_i + 1 #
if (user_start_at + exercise_time.minutes) < Time.now if (user_start_at + exercise_time.minutes) < Time.now
normal_status(-1,"限时试卷已结束!") normal_status(-1,"限时试卷已结束!")
end end
end
end
def commit_exercise_time
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(current_user.id).first #查找当前用户是否有过答题
if @exercise.exercise_status == 3 || (@exercise.time > 0 && ((@exercise_user_current&.start_at + (@exercise.time.to_i + 1).minutes) < Time.now))
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
subjective_score = @exercise_user_current&.subjective_score < 0.0 ? 0.0 : @exercise_user_current&.subjective_score
total_score = objective_score + subjective_score
commit_option = {
:status => 1,
:commit_status => 1,
:end_at => Time.now,
:objective_score => objective_score,
:score => total_score,
:subjective_score => subjective_score
}
@exercise_user_current.update_attributes(commit_option)
normal_status(-1,"考试时间已到,已交卷成功!")
end end
end end

@ -90,8 +90,10 @@ class HomeworkCommonsController < ApplicationController
if @homework_type == 4 if @homework_type == 4
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns)
elsif @homework_type == 3
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group)
else else
@homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings)
end end
end end
@ -907,10 +909,9 @@ class HomeworkCommonsController < ApplicationController
# 创建作业分班设置homework_group_setting # 创建作业分班设置homework_group_setting
create_homework_group_settings(homework) create_homework_group_settings(homework)
# 选中的分班设置的发布时间改为当前时间,截止时间不为空的保持原状,为空的改为一个月后 # 选中的分班设置的发布时间改为当前时间,截止时间改为传的截止时间参数
homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now) homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now,
homework.homework_group_settings.where(course_group_id: publish_groups, end_time: nil). end_time: params[:end_time])
update_all(end_time: params[:end_time])
# 发消息 # 发消息
tiding_group_ids = publish_groups tiding_group_ids = publish_groups
end end
@ -938,8 +939,7 @@ class HomeworkCommonsController < ApplicationController
create_homework_group_settings(homework) create_homework_group_settings(homework)
none_publish_settings = homework.homework_group_settings.where(course_group_id: publish_groups).none_published none_publish_settings = homework.homework_group_settings.where(course_group_id: publish_groups).none_published
none_publish_settings.update_all(publish_time: Time.now) none_publish_settings.update_all(publish_time: Time.now, end_time: params[:end_time])
none_publish_settings.where(end_time: nil).update_all(end_time: params[:end_time])
if homework.max_group_end_time if homework.max_group_end_time
homework.end_time = homework.max_group_end_time homework.end_time = homework.max_group_end_time
end end

@ -2,8 +2,7 @@ class PollVotesController < ApplicationController
#在开始回答和提交问卷的时候,已经做了判断用户的身份权限 #在开始回答和提交问卷的时候,已经做了判断用户的身份权限
before_action :require_login before_action :require_login
before_action :get_poll_question before_action :get_poll_question
before_action :check_answer_in_question,only: [:create] before_action :check_answer_in_question
before_action :check_multi_answers
def create #每一次答案的点击,请求一次 def create #每一次答案的点击,请求一次
@ -124,7 +123,7 @@ class PollVotesController < ApplicationController
if @poll_question.blank? if @poll_question.blank?
normal_status(-1,"问卷试题不存在!") normal_status(-1,"问卷试题不存在!")
else else
@poll = @poll_question.poll @poll = @poll_question.poll.includes(:poll_users)
@course = @poll.course @course = @poll.course
if @poll.blank? if @poll.blank?
normal_status(-1,"问卷不存在!") normal_status(-1,"问卷不存在!")
@ -132,20 +131,22 @@ class PollVotesController < ApplicationController
normal_status(-1,"课堂不存在!") normal_status(-1,"课堂不存在!")
end end
end end
end end
def check_answer_in_question def check_answer_in_question
poll_answer_ids = @poll_question.poll_answers.pluck(:id) # poll_answer_ids = @poll_question.poll_answers.pluck(:id)
if @poll_question.question_type == 1 #单选题/多选题 # if @poll_question.question_type == 1 #单选题/多选题
unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?) # unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?)
normal_status(-1, "答案ID错误") # normal_status(-1, "答案ID错误")
end # end
end # end
end poll_user_status = @poll.get_poll_status(current_user.id)
poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户
def check_multi_answers question_type = @poll_question&.question_type
if @poll_question.question_type == 2 if [1,2].include?(question_type) && params[:poll_answer_id].blank?
normal_status(-1,"答案ID错误!")
elsif question_type == 2
user_vote_count = params[:poll_answer_id].size user_vote_count = params[:poll_answer_id].size
if @poll_question.max_choices.present? if @poll_question.max_choices.present?
question_max_choices = @poll_question.max_choices question_max_choices = @poll_question.max_choices
@ -155,6 +156,9 @@ class PollVotesController < ApplicationController
if question_max_choices > 0 && user_vote_count > question_max_choices if question_max_choices > 0 && user_vote_count > question_max_choices
normal_status(-1,"多选题答案超过最大限制!") normal_status(-1,"多选题答案超过最大限制!")
end end
elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3
normal_status(-1,"已提交/已结束的问卷不允许修改!")
end end
end end
end end

@ -91,10 +91,6 @@ class UsersController < ApplicationController
def brief_introduction def brief_introduction
content = params[:content].to_s.strip content = params[:content].to_s.strip
if content.blank?
render_error('内容不能为空')
return
end
current_user.user_extension.update!(brief_introduction: content) current_user.user_extension.update!(brief_introduction: content)

@ -11,7 +11,7 @@ module ApplicationHelper
# 全局参数配置 # 全局参数配置
def edu_setting name def edu_setting name
EduSetting.find_by_name(name).try(:value) EduSetting.get(name)
end end
def graduation_navigation graduation def graduation_navigation graduation

@ -35,7 +35,7 @@ class Base64ImageConverter
end end
def size_limit def size_limit
EduSetting.find_by_name('upload_avatar_max_size')&.value EduSetting.get('upload_avatar_max_size')
end end
class Image class Image

@ -1,5 +1,25 @@
class EduSetting < ApplicationRecord class EduSetting < ApplicationRecord
after_commit :expire_value_cache
def value_cache_key
self.class.value_cache_key(name)
end
def self.get(key) def self.get(key)
find_by_name(key.to_s)&.value Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do
find_by_name(key.to_s)&.value
end
end
def self.value_cache_key(name)
raise ArgumentError if name.blank?
"educoder/edu-settings/#{name.to_s}"
end
private
def expire_value_cache
Rails.cache.clear(value_cache_key)
end end
end end

@ -15,7 +15,7 @@ class GitService
private private
def root_url def root_url
new_git_address = EduSetting.find_by_name('git_address_domain').try(:value) new_git_address = EduSetting.get('git_address_domain')
raise 'error: new_git_address not configuration' unless new_git_address.present? raise 'error: new_git_address not configuration' unless new_git_address.present?
new_git_address new_git_address
end end

@ -4,7 +4,7 @@ require 'net/http'
require 'uri' require 'uri'
class ReviewService class ReviewService
@review_server_url = EduSetting.find_by_name('review_server_url').try(:value) @review_server_url = EduSetting.get('review_server_url')
def self.logger def self.logger

@ -30,6 +30,7 @@ json.top do
json.my_project_url "#{@user_url}?type=a_project" json.my_project_url "#{@user_url}?type=a_project"
json.account_manager_url "#{@old_domain}/my/account" json.account_manager_url "#{@old_domain}/my/account"
json.logout_url logout_accounts_path json.logout_url logout_accounts_path
json.college_identifier @user.college_identifier
# 旧版的域名 # 旧版的域名
json.old_url @old_domain json.old_url @old_domain
end end

@ -27,7 +27,7 @@ module Educoder
def self.sendYunpian(mobile, code, send_type, name, user_name, result) def self.sendYunpian(mobile, code, send_type, name, user_name, result)
#修改为您的apikey.可在官网http://www.yunpian.com)登录后用户中心首页看到 #修改为您的apikey.可在官网http://www.yunpian.com)登录后用户中心首页看到
apikey = EduSetting.find_by_name('sms_apikey').try(:value) apikey = EduSetting.get('sms_apikey')
#指定模板发送接口HTTP地址 #指定模板发送接口HTTP地址
send_tpl_sms_uri = URI.parse('https://sms.yunpian.com/v2/sms/single_send.json') send_tpl_sms_uri = URI.parse('https://sms.yunpian.com/v2/sms/single_send.json')

@ -111,28 +111,48 @@ namespace :poll_publish do
end end
task :end => :environment do task :end => :environment do
polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now)
#1.统一设置的截止
polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900)
polls.each do |poll| polls.each do |poll|
poll.update_attributes(:polls_status => 3) poll.update_column('polls_status', 3)
poll.poll_users.each do |poll_user| poll.poll_users.each do |poll_user|
if poll_user.commit_status == 0 && !poll_user.start_at.nil? if poll_user.commit_status == 0 && poll_user.start_at.present?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end end
end end
end end
PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| #2.分班设置的截止
polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = false AND end_time > ?",Time.now + 900)
poll_ids = polls.blank? ? "(-1)" : "(" + polls.map(&:id).join(",") + ")"
polls_group_settings = PollGroupSetting.where("end_time <= '#{Time.now}' and poll_id in #{poll_ids}")
polls_group_settings.each do |poll_setting|
poll = poll_setting.poll poll = poll_setting.poll
poll.update_column('polls_status',3) if poll&.end_time <= Time.now
poll.update_column('polls_status', 3)
end
users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id)
poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) poll_users = poll.poll_users.where(:user_id => users.map(&:user_id))
poll_users.each do |poll_user| poll_users.each do |poll_user|
if poll_user.commit_status == 0 && !poll_user.start_at.nil? if poll_user.commit_status == 0 && !poll_user.start_at.nil?
poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
end end
end end
end end
# PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting|
# poll = poll_setting.poll
# poll.update_column('polls_status',3)
#
# users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id)
# poll_users = poll.poll_users.where(:user_id => users.map(&:user_id))
#
# poll_users.each do |poll_user|
# if poll_user.commit_status == 0 && !poll_user.start_at.nil?
# poll_user.update_attributes(:commit_status => 1, :end_at => Time.now)
# end
# end
# end
end end
end end

Loading…
Cancel
Save