From b4fa106873267fd5d74e578396226e5165b9ae3d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 10:36:45 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=97=B6=E6=88=AA=E6=AD=A2=E6=97=B6=E9=97=B4=E6=9C=AA=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bb37283ca..ee6cc80e0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -907,10 +907,9 @@ class HomeworkCommonsController < ApplicationController # 创建作业分班设置:homework_group_setting 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, end_time: nil). - update_all(end_time: params[:end_time]) + # 选中的分班设置的发布时间改为当前时间,截止时间改为传的截止时间参数 + homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now, + end_time: params[:end_time]) # 发消息 tiding_group_ids = publish_groups end @@ -938,8 +937,7 @@ class HomeworkCommonsController < ApplicationController create_homework_group_settings(homework) 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.where(end_time: nil).update_all(end_time: params[:end_time]) + none_publish_settings.update_all(publish_time: Time.now, end_time: params[:end_time]) if homework.max_group_end_time homework.end_time = homework.max_group_end_time end From 09d8e6e5da4b0b2a0ce60370a807743773ae8e4f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 10:42:40 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ee6cc80e0..ec3f0ab9a 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -90,8 +90,10 @@ class HomeworkCommonsController < ApplicationController if @homework_type == 4 @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 - @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 From 34dc1032d83ed071d695dc27903efb10b2132207 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:45:54 +0800 Subject: [PATCH 3/8] add cache to edusetting get --- app/controllers/application_controller.rb | 4 ++-- app/helpers/application_helper.rb | 2 +- app/libs/base64_image_converter.rb | 2 +- app/models/edu_setting.rb | 22 +++++++++++++++++++++- app/services/git_service.rb | 2 +- app/services/review_service.rb | 2 +- lib/educoder/sms.rb | 2 +- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d1aac6f3a..89b3ed5d8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,8 +19,8 @@ class ApplicationController < ActionController::Base # 全局配置参数 # 返回name对应的value - def edu_setting name - EduSetting.find_by_name(name).try(:value) + def edu_setting(name) + EduSetting.get(name) end def user_course_identity diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 42bc16343..b4e3baf51 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,7 +11,7 @@ module ApplicationHelper # 全局参数配置 def edu_setting name - EduSetting.find_by_name(name).try(:value) + EduSetting.get(name) end def graduation_navigation graduation diff --git a/app/libs/base64_image_converter.rb b/app/libs/base64_image_converter.rb index 2a8155283..2dc9aa41e 100644 --- a/app/libs/base64_image_converter.rb +++ b/app/libs/base64_image_converter.rb @@ -35,7 +35,7 @@ class Base64ImageConverter end def size_limit - EduSetting.find_by_name('upload_avatar_max_size')&.value + EduSetting.get('upload_avatar_max_size') end class Image diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index db6d545f0..e6e4d900e 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -1,5 +1,25 @@ class EduSetting < ApplicationRecord + after_commit :expire_cache + + def cache_key + self.class.cache_key(name) + end + def self.get(key) - find_by_name(key.to_s)&.value + Rails.cache.fetch(cache_key(key), expires_in: 1.days) do + find_by_name(key.to_s)&.value + end + end + + def self.cache_key(name) + raise ArgumentError if name.blank? + + "educoder/edu-settings/#{name.to_s}" + end + + private + + def expire_cache + Rails.cache.clear(cache_key) end end diff --git a/app/services/git_service.rb b/app/services/git_service.rb index 4b6bf17ef..3298185bf 100644 --- a/app/services/git_service.rb +++ b/app/services/git_service.rb @@ -15,7 +15,7 @@ class GitService private 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? new_git_address end diff --git a/app/services/review_service.rb b/app/services/review_service.rb index 7602aa51b..df004fd19 100644 --- a/app/services/review_service.rb +++ b/app/services/review_service.rb @@ -4,7 +4,7 @@ require 'net/http' require 'uri' 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 diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index 9d54a6df5..e79678ad3 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -27,7 +27,7 @@ module Educoder def self.sendYunpian(mobile, code, send_type, name, user_name, result) #修改为您的apikey.可在官网(http://www.yunpian.com)登录后用户中心首页看到 - apikey = EduSetting.find_by_name('sms_apikey').try(:value) + apikey = EduSetting.get('sms_apikey') #指定模板发送接口HTTP地址 send_tpl_sms_uri = URI.parse('https://sms.yunpian.com/v2/sms/single_send.json') From 3f837dbda5c742c104c5e9330852948ed7197ff5 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:48:01 +0800 Subject: [PATCH 4/8] modify edusetting cache key method Avoid duplication --- app/models/edu_setting.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index e6e4d900e..4b39dea81 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -1,17 +1,17 @@ class EduSetting < ApplicationRecord - after_commit :expire_cache + after_commit :expire_value_cache - def cache_key - self.class.cache_key(name) + def value_cache_key + self.class.value_cache_key(name) end def self.get(key) - Rails.cache.fetch(cache_key(key), expires_in: 1.days) do + Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do find_by_name(key.to_s)&.value end end - def self.cache_key(name) + def self.value_cache_key(name) raise ArgumentError if name.blank? "educoder/edu-settings/#{name.to_s}" @@ -19,7 +19,7 @@ class EduSetting < ApplicationRecord private - def expire_cache - Rails.cache.clear(cache_key) + def expire_value_cache + Rails.cache.clear(value_cache_key) end end From 460a89fe6e086e0fdb5bc80c7cc6db472b6ffc20 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:55:12 +0800 Subject: [PATCH 5/8] user brief introduction allow blank --- app/controllers/users_controller.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d01973175..408e73fa5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -90,10 +90,6 @@ class UsersController < ApplicationController def brief_introduction content = params[:content].to_s.strip - if content.blank? - render_error('内容不能为空') - return - end current_user.user_extension.update!(brief_introduction: content) From 98a541e5a8883e004f9cc4cb5c2ff347a3746b68 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 10:55:26 +0800 Subject: [PATCH 6/8] fix bug --- lib/tasks/poll_publish.rake | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index d10db7a5d..48c289050 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -111,28 +111,48 @@ namespace :poll_publish do end 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| - poll.update_attributes(:polls_status => 3) + poll.update_column('polls_status', 3) 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) 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.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) 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 + + # 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 From 41f92346dbc9d22bb286bc20d960dacc90d0c429 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 11:33:10 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=AD=A6=E9=99=A2url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_navigation_info.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/get_navigation_info.json.jbuilder b/app/views/users/get_navigation_info.json.jbuilder index 57a303cb6..6b04a121c 100644 --- a/app/views/users/get_navigation_info.json.jbuilder +++ b/app/views/users/get_navigation_info.json.jbuilder @@ -30,6 +30,7 @@ json.top do json.my_project_url "#{@user_url}?type=a_project" json.account_manager_url "#{@old_domain}/my/account" json.logout_url logout_accounts_path + json.college_identifier @user.college_identifier # 旧版的域名 json.old_url @old_domain end From 6f7598bde102ae255bdf76d3aa196ffaf9d5dd33 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 12:08:22 +0800 Subject: [PATCH 8/8] fix bug --- .../exercise_answers_controller.rb | 32 ++++--------------- app/controllers/poll_votes_controller.rb | 30 +++++++++-------- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 81f117daf..fec26d674 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -1,7 +1,6 @@ class ExerciseAnswersController < ApplicationController before_action :require_login before_action :get_exercise_question - before_action :commit_exercise_time include ExercisesHelper def create #每一次答案的点击,请求一次,实训题不在这里回答 @@ -95,9 +94,11 @@ class ExerciseAnswersController < ApplicationController def get_exercise_question @exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id]) - @exercise = @exercise_question.exercise + @exercise = @exercise_question.exercise.includes(:exercise_users) @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? normal_status(-1,"试卷问题不存在!") @@ -105,34 +106,15 @@ class ExerciseAnswersController < ApplicationController normal_status(-1,"试卷不存在!") elsif @course.blank? 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,"已提交/已结束的试卷不允许修改!") elsif @exercise.time > 0 - user_start_at = @exercise.exercise_users.exercise_commit_users(current_user.id).first.start_at - exercise_time = @exercise.time.to_i + user_start_at = @exercise_user&.start_at + exercise_time = @exercise.time.to_i + 1 # if (user_start_at + exercise_time.minutes) < Time.now normal_status(-1,"限时试卷已结束!") 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 diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index a2f805a97..789d5748e 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -2,8 +2,7 @@ class PollVotesController < ApplicationController #在开始回答和提交问卷的时候,已经做了判断用户的身份权限 before_action :require_login before_action :get_poll_question - before_action :check_answer_in_question,only: [:create] - before_action :check_multi_answers + before_action :check_answer_in_question def create #每一次答案的点击,请求一次 @@ -124,7 +123,7 @@ class PollVotesController < ApplicationController if @poll_question.blank? normal_status(-1,"问卷试题不存在!") else - @poll = @poll_question.poll + @poll = @poll_question.poll.includes(:poll_users) @course = @poll.course if @poll.blank? normal_status(-1,"问卷不存在!") @@ -132,20 +131,22 @@ class PollVotesController < ApplicationController normal_status(-1,"课堂不存在!") end end - end def check_answer_in_question - poll_answer_ids = @poll_question.poll_answers.pluck(:id) - 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?) - normal_status(-1, "答案ID错误!") - end - end - end + # poll_answer_ids = @poll_question.poll_answers.pluck(:id) + # 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?) + # normal_status(-1, "答案ID错误!") + # 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 - if @poll_question.question_type == 2 + question_type = @poll_question&.question_type + 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 if @poll_question.max_choices.present? 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 normal_status(-1,"多选题答案超过最大限制!") end + elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3 + normal_status(-1,"已提交/已结束的问卷不允许修改!") end end + end