dev_forum
cxt 6 years ago
commit d1511241b2

@ -1,6 +1,5 @@
class AccountsController < ApplicationController
include ErrorCommon
#skip_before_action :check_account, :only => [:logout]
def index

@ -30,6 +30,10 @@ class ApplicationController < ActionController::Base
end
end
def admin_or_business?
User.current.admin? || User.current.business?
end
def user_course_identity
@user_course_identity = current_user.course_identity(@course)
if @user_course_identity > Course::STUDENT && @course.is_public == 0
@ -43,14 +47,14 @@ class ApplicationController < ActionController::Base
# params[:type] 1: 注册2忘记密码
def check_mail_and_phone_valid login, type
unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/
tip_exception("请输入正确的手机号或邮箱")
tip_exception(-2, "请输入正确的手机号或邮箱")
end
# 考虑到安全参数问题多一次查询去掉Union
user = User.where(phone: login).first || User.where(mail: login).first
if type.to_i == 1 && !user.nil?
tip_exception(-2, "该手机号码或邮箱已被注册")
elsif type.to_i == 2 && user.nil?
tip_exception("该手机号码或邮箱未注册")
tip_exception(-2, "该手机号码或邮箱未注册")
end
sucess_status
end

@ -5,7 +5,6 @@ class AttachmentsController < ApplicationController
before_action :require_login, :check_auth
before_action :find_file, only: %i[show destroy]
include ErrorCommon
include ApplicationHelper
def show

@ -0,0 +1,11 @@
class Competitions::BaseController < ApplicationController
include PaginateHelper
before_action :require_login
helper_method :current_competition
def current_competition
@_current_competition ||= Competition.find_by!(identifier: params[:competition_id].presence || params[:id])
end
end

@ -0,0 +1,4 @@
class Competitions::CompetitionStaffsController < Competitions::BaseController
def show
end
end

@ -0,0 +1,32 @@
class Competitions::CompetitionsController < Competitions::BaseController
skip_before_action :require_login
def index
# 已上架 或者 即将上架
competitions = Competition.where(status: true).or(Competition.where.not(published_at: nil))
competitions =
case params[:category]
when 'nearly_published' then competitions.where(status: false)
when 'progressing' then competitions.where('end_time > NOW()')
when 'ended' then competitions.where('end_time < NOW()')
else competitions
end
@count = competitions.count
competitions = competitions.order(published_at: :desc, online_time: :desc)
@competitions = paginate(competitions.includes(current_stage_section: :competition_stage))
ids = @competitions.map(&:id)
@member_count_map = TeamMember.where(competition_id: ids).group(:competition_id).count
@stage_count_map = CompetitionStage.where(competition_id: ids).group(:competition_id).count
end
def show
unless current_competition.published? || admin_or_business?
render_forbidden
return
end
end
end

@ -2,6 +2,10 @@ module ControllerRescueHandler
extend ActiveSupport::Concern
included do
rescue_from Exception do |e|
logger.error e
render json: {status: -1, message: e.message}
end
# rescue_from ActionView::MissingTemplate, with: :object_not_found
# rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
rescue_from Educoder::TipException, with: :tip_show

@ -1,10 +0,0 @@
module ErrorCommon
extend ActiveSupport::Concern
included do
rescue_from Exception do |e|
logger.error e
render json: {status: -1, message: e.message}
end
end
end

@ -0,0 +1,8 @@
module PaginateHelper
def paginate(objs, **opts)
page = params[:page].to_i <= 0 ? 1 : params[:page].to_i
per_page = params[:per_page].to_i > 0 ? params[:per_page].to_i : 20
Kaminari.paginate_array(objs).page(page).per(per_page)
end
end

@ -689,7 +689,7 @@ class ExercisesController < ApplicationController
ActiveRecord::Base.transaction do
begin
check_ids = Exercise.where(id: params[:check_ids])
ex_end_time = params[:end_time] || Time.at(((1.month.since.to_i)/3600.0).ceil * 3600)
ex_end_time = params[:end_time].to_time
check_ids.each do |exercise|
if exercise.present?
if exercise.unified_setting
@ -701,20 +701,13 @@ class ExercisesController < ApplicationController
if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改
if g_course
# course_groups = @course.teacher_course_groups.get_user_groups(current_user.id)
#
# if course_groups.blank?
# user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : []
# else
# user_course_groups = course_groups.pluck(:course_group_id).reject(&:blank?).uniq
# end
user_course_groups = @course.charge_group_ids(current_user)
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置
exercise.exercise_group_settings.destroy_all
ex_unified = true
e_time = ex_end_time
else
e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max
ex_unified = false
g_course.each do |i|
exercise_group_setting = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",i).first #根据课堂分班的id寻找试卷所在的班级
@ -732,20 +725,14 @@ class ExercisesController < ApplicationController
new_exercise_group.save
end
end
group_ids = params[:group_ids]
end
else
exercise.exercise_group_settings.destroy_all
ex_unified = true
end
if exercise.end_time.blank?
e_time = ex_end_time
elsif exercise.exercise_group_settings.end_time_no_null.count > 0 # 该试卷分组有结束时间为空的
e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max
else
e_time = exercise.end_time
end
ex_status = set_exercise_status(Time.now,e_time)
exercise_params = {
:publish_time => Time.now,
@ -1294,7 +1281,7 @@ class ExercisesController < ApplicationController
def export_exercise
@request_url = request.base_url
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}"
filename_ = "#{@exercise.user.real_name}_#{@course.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}.pdf"
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename_, stylesheets: stylesheets
end

@ -258,15 +258,12 @@ class PollsController < ApplicationController
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数那么poll的统一设置需修改
if g_course
user_course_groups = @course.charge_group_ids(current_user)
# if course_groups.blank?
# user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : []
# else
# user_course_groups = course_groups.pluck(:course_group_id)
# end
if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置
poll.poll_group_settings.destroy_all
poll_unified = true
e_time = ex_end_time
else
e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max
poll_unified = false
g_course.each do |i|
poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id寻找问卷所在的班级
@ -289,14 +286,15 @@ class PollsController < ApplicationController
else
poll.poll_group_settings.destroy_all
poll_unified = true
end
if poll.end_time.blank?
e_time = ex_end_time
elsif poll.poll_group_settings.end_time_present.count > 0 # 该问卷分组有结束时间为空的
e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max
else
e_time = poll.end_time
end
# if poll.end_time.blank?
# e_time = ex_end_time
# elsif poll.poll_group_settings.end_time_present.count > 0 # 该问卷分组有结束时间为空的
# e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max
# else
# e_time = poll.end_time
# end
poll_status = set_poll_status(Time.now,e_time)
poll_params = {

@ -0,0 +1,9 @@
module ApplicationDecorator
def display_time_method(*columns, format: '%Y-%m-%d %H:%M:%S')
columns.each do |column_name|
define_method "display_#{column_name}" do
public_send(column_name)&.strftime(format)
end
end
end
end

@ -0,0 +1,6 @@
module CompetitionDecorator
extend ApplicationDecorator
display_time_method :start_time, :end_time, :enroll_end_time
end

@ -0,0 +1,5 @@
module CompetitionStageSectionDecorator
extend ApplicationDecorator
display_time_method :start_time, :end_time
end

@ -87,8 +87,9 @@ module ExercisesHelper
def exercise_commit_result(questions,user_ids)
question_infos = []
percent = 0.0
questions.each do |ex|
ex_total_score = user_ids.size * ex&.question_score #该试卷的已回答的总分
questions.includes(:exercise_choices).each do |ex|
ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分
ex_answers = ex.exercise_answers
if ex.question_type != Exercise::PRACTICAL
ques_title = ex.question_title
ques_less_title = nil
@ -111,11 +112,14 @@ module ExercisesHelper
question_answer_infos = []
if ex.question_type <= Exercise::JUDGMENT #选择题和判断题
ex_choices = ex.exercise_choices
standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置
right_users_count = 0 #该问题的回答正确的人数
if ex.question_type == Exercise::MULTIPLE #多选题
user_ids.each do |user_id|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq
ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq
# answer_choice_array = ex_choices.where(id:ex_choice_ids).pluck(:choice_position)
answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq
if answer_choice_array.sort == standard_answer
right_users_count += 1
end
@ -132,7 +136,7 @@ module ExercisesHelper
end
percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0
ex.exercise_choices.each do |c|
ex_choices.each do |c|
right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置
answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id)
answer_users_count = answer_this_choice.size

@ -39,6 +39,7 @@ module Util
end
def extract_content(str)
return '' if str.blank?
str.gsub(/<\/?.*?>/, '').gsub(/[\n\t\r]/, '').gsub(/&nbsp;/, '')
end
end

@ -6,4 +6,5 @@ class ApplyUserAuthentication < ApplicationRecord
scope :real_name_auth, -> { where(auth_type: 1) }
scope :professional_auth, -> { where(auth_type: 2) }
scope :processing, -> { where(status: 0) }
scope :passed, -> { where(status: 1) }
end

@ -0,0 +1,40 @@
class Competition < ApplicationRecord
has_many :competition_modules, dependent: :destroy
has_many :competition_stages, dependent: :destroy
has_many :competition_stage_sections, dependent: :destroy
has_one :current_stage_section, -> { where('end_time > NOW()') }, class_name: 'CompetitionStageSection'
has_many :team_members, dependent: :destroy
has_many :competition_staffs, dependent: :destroy
has_one :teacher_staff, -> { where(category: :teacher) }, class_name: 'CompetitionStaff'
has_one :member_staff, -> { where.not(category: :teacher) }, class_name: 'CompetitionStaff'
has_many :attachments, as: :container
after_create :create_competition_modules
# 是否上架
def published?
status?
end
# 报名是否结束
def enroll_ended?
enroll_end_time.blank? || enroll_end_time < Time.now
end
# 是否已经报名
def enrolled?(user)
team_members.exists?(user_id: user.id)
end
private
def create_competition_modules
CompetitionModule.bulk_insert(*%i[competition_id name position]) do |worker|
%w(首页 报名 通知公告 排行榜 资料下载).each_with_index do |name, index|
worker.add(competition_id: id, name: name, position: index + 1)
end
end
end
end

@ -0,0 +1,4 @@
class CompetitionEntry < ApplicationRecord
belongs_to :competition_stage
belongs_to :competition_stage_section
end

@ -0,0 +1,7 @@
class CompetitionModule < ApplicationRecord
default_scope { order('position ASC') }
belongs_to :competition
has_one :competition_module_md_content, dependent: :destroy
end

@ -0,0 +1,5 @@
class CompetitionModuleMdContent < ApplicationRecord
belongs_to :competition_module
has_many :attachments, as: :container, dependent: :destroy
end

@ -0,0 +1,3 @@
class CompetitionStaff < ApplicationRecord
belongs_to :competition
end

@ -0,0 +1,7 @@
class CompetitionStage < ApplicationRecord
belongs_to :competition
has_many :competition_stage_sections, dependent: :destroy
has_many :competition_entries, dependent: :destroy
end

@ -0,0 +1,6 @@
class CompetitionStageSection < ApplicationRecord
belongs_to :competition
belongs_to :competition_stage
has_many :competition_entries, dependent: :destroy
end

@ -0,0 +1,8 @@
class CompetitionTeam < ApplicationRecord
belongs_to :user
belongs_to :competition
has_many :team_members, dependent: :destroy
has_many :members, -> { without_teachers }, class_name: 'TeamMember'
has_many :teachers, -> { only_teachers }, class_name: 'TeamMember'
end

@ -31,7 +31,7 @@ class Game < ApplicationRecord
# 根据得分比例来算实际得分(试卷、实训作业)
def real_score score
final_score == challenge.score ? score : (final_score.to_f / challenge.score) * score
(final_score.to_f / challenge.all_score) * score
end
# 判断实训是否全部通关

@ -21,8 +21,8 @@ module Searchable::Shixun
def searchable_user_data
{
author_name: user.real_name,
author_school_name: user.school_name,
author_name: user&.real_name,
author_school_name: user&.school_name,
}
end

@ -0,0 +1,8 @@
class TeamMember < ApplicationRecord
belongs_to :user
belongs_to :competition
belongs_to :competition_team
scope :only_teachers, -> { where(is_teacher: true) }
scope :without_teachers, -> { where(is_teacher: false) }
end

@ -58,7 +58,7 @@ class User < ApplicationRecord
has_many :tidings, :dependent => :destroy
has_many :games, :dependent => :destroy
has_many :created_subjects
has_many :created_subjects, foreign_key: :user_id, class_name: 'Subject'
has_many :subjects, :through => :subject_members
has_many :subject_members, :dependent => :destroy
has_many :grades, :dependent => :destroy
@ -544,15 +544,6 @@ class User < ApplicationRecord
Educoder::Utils.random_hex(16)
end
# 基本资料是否完善
def base_info_completed?
user_columns = %i[nickname lastname]
user_extension_columns = %i[gender location location_city identity school_id department]
user_columns.all? { |column| public_send(column).present? } &&
user_extension_columns.all? { |column| user_extension.send(column).present? }
end
# 全部已认证
def all_certified?
authentication? && professional_certification?

@ -35,6 +35,13 @@ class Users::UpdateAccountService < ApplicationService
extension.technical_title = params[:technical_title]
end
# 职业、学校变动需要重新进行职业认证
if extension.identity_changed? || extension.school_id_changed?
user.professional_certification = false
# 撤销之前的职业认证
user.apply_user_authentication.professional_auth.passed.update_all(status: 3)
end
# 表示资料完整
user.profile_completed = true

@ -0,0 +1,26 @@
competition = current_competition
json.enroll_ended competition.enroll_ended?
json.enrolled competition.enrolled?(current_user)
# 教师报名设置
if competition.teacher_staff.present?
json.teacher_staff do
json.minimum competition.teacher_staff.minimum
json.maximum competition.teacher_staff.maximum
json.mutiple_limited competition.teacher_staff.mutiple_limited
end
else
json.teacher_staff nil
end
# 教师报名设置
if competition.member_staff.present?
json.member_staff do
json.minimum competition.member_staff.minimum
json.maximum competition.member_staff.maximum
json.mutiple_limited competition.member_staff.mutiple_limited
end
else
json.member_staff nil
end

@ -0,0 +1,29 @@
json.count @count
json.competitions do
json.array! @competitions.each do |competition|
json.extract! competition, :id, :identifier, :name, :sub_title
json.visits_count competition.visits
member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count
json.member_count member_count.zero? ? 268 : member_count
json.image url_to_avatar(competition)
json.published competition.published?
json.nearly_published competition.published_at.present?
json.single_stage (@stage_count_map&.fetch(competition.id, 0) || competition.competition_stages.count) == 1
json.start_time competition.display_start_time
json.end_time competition.display_end_time
json.enroll_end_time competition.display_enroll_end_time
section = competition.current_stage_section
if section
json.current_stage do
json.name = section.competition_stage.name
json.start_time section.display_start_time
json.end_time section.display_end_time
end
end
end
end

@ -0,0 +1,36 @@
competition = current_competition
json.extract! competition, :id, :name, :sub_title, :identifier
json.start_time competition.display_start_time
json.end_time competition.display_end_time
json.enroll_end_time competition.display_enroll_end_time
json.images do
json.array! competition.attachments, partial: 'attachments/attachment_simple', as: :attachment
end
json.competition_stages do
stages = competition.competition_stages.includes(competition_stage_sections: :competition_entries)
json.array! stages.each do |stage|
json.extract! stage, :id, :name
json.sections do
json.array! stage.competition_stage_sections.each do |section|
json.extract! section, :id, :name
decorator_section = ActiveDecorator::Decorator.instance.decorate(section)
json.start_time decorator_section.display_start_time
json.end_time decorator_section.display_end_time
is_start = section.start_time > Time.now
json.entries do
json.array! section.competition_entries.each do |entry|
json.extract! entry, :id, :name
json.url is_start ? entry.url : ''
end
end
end
end
end
end

@ -1,5 +1,4 @@
json.question_id question.id
# json.question_number question.question_number
q_positon = question.question_number
if ques_position.present?
q_positon = ques_position
@ -22,7 +21,7 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选
user_answer_b = user_answer.include?(a.id)
json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现
json.choice_id a.id
json.choice_text a.choice_text
json.choice_text "#{(index+65).chr}.#{a.choice_text}"
json.choice_position a.choice_position
if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题2为空白试卷即标准答案和用户答案都不显示3为用户开始答题的显示4为老师评阅试卷或学生在截止后查看试卷
json.standard_boolean standard_answer_b

@ -34,9 +34,16 @@ json.commit_results do
json.effictive_counts q[:ques_effictive_counts]
if q[:type] != Exercise::PRACTICAL
json.ques_details do
json.array! q[:ques_details] do |d|
json.array! q[:ques_details].each_with_index.to_a do |d,index|
if q[:type] <= Exercise::MULTIPLE
ques_index = (index+65).chr
elsif q[:type] == Exercise::JUDGMENT
ques_index = (index+1).to_s
else
ques_index = nil
end
json.choice_position d[:choice_position]
json.choice_text d[:choice_text]
json.choice_text ques_index.present? ? "#{ques_index}.#{d[:choice_text]}" : d[:choice_text]
json.choice_users_count d[:choice_users_count]
json.choice_percent d[:choice_percent]
json.choice_right_boolean d[:right_answer]

@ -21,5 +21,5 @@ json.school_name extension&.school&.name
json.department_id extension&.department_id
json.department_name extension&.department&.name
json.base_info_completed user.base_info_completed?
json.base_info_completed user.profile_completed?
json.all_certified user.all_certified?

@ -10,7 +10,7 @@ json.top do
json.new_project_url "#{@old_domain}/projects/new"
json.join_course_url "#{@old_domain}/courses/join_course_multi_role"
json.join_project_url "#{@old_domain}/applied_project/applied_project_info"
json.message_url "#{@user_url}/user_tidings"
json.message_url "#{@old_domain}#{@user_url}/user_tidings"
json.new_message @new_message
json.career_url do

@ -668,6 +668,14 @@ Rails.application.routes.draw do
end
resources :repertoires, only: [:index]
scope module: :competitions do
resources :competitions, only: [:index, :show] do
resources :competition_modules, only: [:index, :show]
resource :competition_staff
resources :competition_teams, only: [:index, :show]
end
end
end
#git 认证回调

Loading…
Cancel
Save