Merge branch 'dev_aliyun' into dev_classes

dev_jupyter
caicai8 5 years ago
commit 6a52118b54

@ -1128,11 +1128,11 @@ class CoursesController < ApplicationController
return normal_status(-1, "邀请码不能为空") if params[:invite_code].blank? return normal_status(-1, "邀请码不能为空") if params[:invite_code].blank?
invite_code = params[:invite_code] invite_code = params[:invite_code]
course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0, laboratory_id: current_laboratory.id) course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0, laboratory_id: current_laboratory.id)
course_group = CourseGroup.find_by(invite_code: invite_code) course_group = CourseGroup.find_by(invite_code: invite_code, invite_code_halt: 0)
if course.blank? if course.blank?
return normal_status(-1, "邀请码无效") if course_group.blank? return normal_status(-1, "邀请码无效") if course_group.blank?
course = Course.find_by(id: course_group.course_id, is_delete: 0, invite_code_halt: 0, laboratory_id: current_laboratory.id) course = Course.find_by(id: course_group.course_id, is_delete: 0, laboratory_id: current_laboratory.id)
return normal_status(-1, "邀请码无效") if course.blank? return normal_status(-1, "邀请码无效") if course.blank?
end end

@ -61,7 +61,7 @@ class ExaminationBanksController < ApplicationController
def set_public def set_public
tip_exception(-1, "该试卷已公开") if @exam.public? tip_exception(-1, "该试卷已公开") if @exam.public?
tip_exception(-1, "请勿重复提交申请") if ApplyAction.where(container_id: @exam.id, container_type: "ExaminationBank").exists? tip_exception(-1, "请勿重复提交申请") if ApplyAction.where(container_id: @exam.id, container_type: "ExaminationBank", status: 0).exists?
ApplyAction.create!(container_id: @exam.id, container_type: "ExaminationBank", user_id: current_user.id) ApplyAction.create!(container_id: @exam.id, container_type: "ExaminationBank", user_id: current_user.id)
# @exam.update_attributes!(public: 1) # @exam.update_attributes!(public: 1)
render_ok render_ok

@ -42,11 +42,14 @@ class ExaminationIntelligentSettingsController < ApplicationController
# 获取可选的题 # 获取可选的题
items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public) items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public)
# 可选题中去掉已组卷的试题
type_items = items.select{ |t_item| t_item.item_type == item.item_type } type_items = items.select{ |t_item| t_item.item_type == item.item_type }
# 如果可选的题数小于等于设置的题数则提示无可换的题 optional_item_ids = (type_items.pluck(:id) - @exam.item_baskets.where(item_type: item.item_type).pluck(:item_bank_id)).uniq
tip_exception("无可换的题") if type_items.size <= exam_type_setting.count
# 可选题中去掉已组卷的同题型试题 # 如果可选的题数等于0则提示无可换的题
optional_item_ids = type_items.pluck(:id) - @exam.item_baskets.where(item_type: item.item_type).pluck(:item_bank_id) tip_exception("无可换的题") if optional_item_ids.size == 0
new_item = ItemBank.find optional_item_ids.sample(1).first new_item = ItemBank.find optional_item_ids.sample(1).first
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@exam.item_baskets << ItemBasket.new(item_bank_id: new_item.id, position: item.position, score: item.score, item_type: new_item.item_type) @exam.item_baskets << ItemBasket.new(item_bank_id: new_item.id, position: item.position, score: item.score, item_type: new_item.item_type)
@ -62,13 +65,15 @@ class ExaminationIntelligentSettingsController < ApplicationController
# 获取可选的题 # 获取可选的题
items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public) items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public)
type_items = items.select{ |t_item| t_item.item_type == params[:item_type] } type_items = items.select{ |t_item| t_item.item_type == params[:item_type] }
# 如果可选的题数小于等于设置的题数则提示无可换的题
tip_exception("无可换的题") if type_items.size <= exam_type_setting.count # 可选题中去掉已组卷的试题
# 可选题中去掉已组卷的同题型试题
choosed_item_ids = choosed_items.pluck(:item_bank_id) choosed_item_ids = choosed_items.pluck(:item_bank_id)
optional_item_ids = type_items.pluck(:id) - choosed_item_ids optional_item_ids = (type_items.pluck(:id) - choosed_item_ids).uniq
# 如果可选的题数等于0则提示无可换的题
tip_exception("无可换的题") if optional_item_ids.size == 0
# 如果可选题数小于设置的题数n则在原来的选题中随机选n个确保换题时能选到新的题 # 如果可选题数小于设置的题数n则在原来的选题中随机选n个确保换题时能选到新的题
if optional_item_ids.size < exam_type_setting.count if optional_item_ids.size < exam_type_setting.count
absence_count = exam_type_setting.count - optional_item_ids.size absence_count = exam_type_setting.count - optional_item_ids.size
optional_item_ids = optional_item_ids + choosed_item_ids.sample(absence_count) optional_item_ids = optional_item_ids + choosed_item_ids.sample(absence_count)

@ -54,7 +54,7 @@ class ItemBanksController < ApplicationController
def set_public def set_public
tip_exception(-1, "该试题已公开") if @item.public? tip_exception(-1, "该试题已公开") if @item.public?
tip_exception(-1, "请勿重复提交申请") if ApplyAction.where(container_id: @item.id, container_type: 'ItemBank').exists? tip_exception(-1, "请勿重复提交申请") if ApplyAction.where(container_id: @item.id, container_type: 'ItemBank', status: 0).exists?
ApplyAction.create!(container_id: @item.id, container_type: 'ItemBank', user_id: current_user.id) ApplyAction.create!(container_id: @item.id, container_type: 'ItemBank', user_id: current_user.id)
# @item.update_attributes!(public: 1) # @item.update_attributes!(public: 1)
render_ok render_ok

@ -3,9 +3,10 @@ class SubjectsController < ApplicationController
# before_action :check_auth, except: [:index] # before_action :check_auth, except: [:index]
before_action :check_account, except: [:index, :show, :right_banner] before_action :check_account, except: [:index, :show, :right_banner]
before_action :find_subject, except: [:index, :create, :new, :append_to_stage, :add_shixun_to_stage] before_action :find_subject, except: [:index, :create, :new, :append_to_stage, :add_shixun_to_stage]
before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, :apply_public,
:search_members, :add_subject_members, :statistics, :shixun_report, :school_report, :search_members, :add_subject_members, :statistics, :shixun_report, :school_report,
:up_member_position, :down_member_position, :update_team_title, :statistics_info] :cancel_has_public, :up_member_position, :down_member_position, :update_team_title,
:statistics_info, :cancel_public]
before_action :require_admin, only: [:copy_subject] before_action :require_admin, only: [:copy_subject]
before_action :shixun_marker, only: [:add_shixun_to_stage] before_action :shixun_marker, only: [:add_shixun_to_stage]
@ -33,16 +34,16 @@ class SubjectsController < ApplicationController
laboratory_join = " AND subjects.id in #{subject_ids} " laboratory_join = " AND subjects.id in #{subject_ids} "
if select if select
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public,
subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' #{laboratory_join} subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join}
AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
else else
@subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public,
subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns
on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where
subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' #{laboratory_join} subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join}
GROUP BY subjects.id ORDER BY myshixun_member_count DESC") GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
end end
else else
@ -59,7 +60,7 @@ class SubjectsController < ApplicationController
elsif reorder == "publish_time" elsif reorder == "publish_time"
@subjects = @subjects.unhidden @subjects = @subjects.unhidden
else else
@subjects = @subjects.visible.unhidden @subjects = @subjects.publiced.unhidden
end end
# 类型 # 类型
@ -72,7 +73,7 @@ class SubjectsController < ApplicationController
end end
# 排序 # 排序
order_str = (reorder == "publish_time" ? "homepage_show desc, excellent desc, status = 2 desc, publish_time asc" : "homepage_show desc, excellent desc, updated_at desc") order_str = (reorder == "publish_time" ? "homepage_show desc, excellent desc, public = 2 desc, publish_time asc" : "homepage_show desc, excellent desc, updated_at desc")
@subjects = @subjects.reorder(order_str) @subjects = @subjects.reorder(order_str)
end end
@ -273,14 +274,44 @@ class SubjectsController < ApplicationController
end end
def publish def publish
@subject.update_attributes(status: 2)
end
def cancel_publish
begin
apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first
if apply && apply.status == 0
apply.update_attributes(status: 3)
apply.tidings.destroy_all
end
@subject.update_attributes(status: 0)
rescue => e
uid_logger_error(e.message)
tip_exception("撤销申请失败")
end
end
def cancel_has_publish
begin
@subject.update_attributes(:status => 0)
rescue => e
uid_logger_error(e.message)
tip_exception("撤销发布失败")
raise ActiveRecord::Rollback
end
end
# 申请公开
def apply_public
tip_exception(-1, "请先发布课程再申请公开") if @subject.status != 2
apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first
if apply && apply.status == 0 if apply && apply.status == 0
@status = 0 @status = 0
else else
@subject.update_attributes(status: 1) @subject.update_attributes(public: 1)
ApplyAction.create(container_type: "ApplySubject", container_id: @subject.id, user_id: current_user.id, status: 0) ApplyAction.create(container_type: "ApplySubject", container_id: @subject.id, user_id: current_user.id, status: 0)
begin begin
status = Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员') Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员')
rescue => e rescue => e
uid_logger_error("发送验证码出错: #{e}") uid_logger_error("发送验证码出错: #{e}")
end end
@ -288,28 +319,28 @@ class SubjectsController < ApplicationController
end end
end end
def cancel_publish def cancel_public
begin begin
apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first apply = ApplyAction.where(container_type: "ApplySubject", container_id: @subject.id).order("created_at desc").first
if apply && apply.status == 0 if apply && apply.status == 0
apply.update_attributes(status: 3) apply.update_attributes(status: 3)
apply.tidings.destroy_all apply.tidings.destroy_all
end end
@subject.update_attributes(status: 0) @subject.update_attributes(public: 0)
render_ok
rescue => e rescue => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("撤销申请失败") tip_exception("撤销申请失败")
raise ActiveRecord::Rollback
end end
end end
def cancel_has_publish def cancel_has_public
begin begin
@subject.update_attributes(:status => 0) @subject.update_attributes(:public => 0)
render_ok
rescue => e rescue => e
uid_logger_error(e.message) uid_logger_error(e.message)
tip_exception("撤销发布失败") tip_exception("撤销公开失败")
raise ActiveRecord::Rollback
end end
end end

@ -42,11 +42,11 @@ class Weapps::CoursesController < Weapps::BaseController
tip_exception(-1, "邀请码不能为空") if params[:invite_code].blank? tip_exception(-1, "邀请码不能为空") if params[:invite_code].blank?
invite_code = params[:invite_code] invite_code = params[:invite_code]
course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0) course = Course.find_by(invite_code: invite_code, is_delete: 0, invite_code_halt: 0)
course_group = CourseGroup.find_by(invite_code: invite_code) course_group = CourseGroup.find_by(invite_code: invite_code, invite_code_halt: 0)
if course.blank? if course.blank?
tip_exception(-1, "邀请码无效") if course_group.blank? tip_exception(-1, "邀请码无效") if course_group.blank?
course = Course.find_by(id: course_group.course_id, is_delete: 0, invite_code_halt: 0) course = Course.find_by(id: course_group.course_id, is_delete: 0)
tip_exception(-1, "邀请码无效") if course.blank? tip_exception(-1, "邀请码无效") if course.blank?
end end

@ -6,6 +6,6 @@ module Admins::SubjectsHelper
when 1 then 'text-warning' when 1 then 'text-warning'
when 2 then 'text-success' when 2 then 'text-success'
end end
raw content_tag(:span, t("subject.status.#{subject.status}"), class: style) raw content_tag(:span, t("subject.public.#{subject.public}"), class: style)
end end
end end

@ -40,6 +40,7 @@ class Subject < ApplicationRecord
scope :visible, lambda{where(status: 2)} scope :visible, lambda{where(status: 2)}
scope :published, lambda{where(status: 1)} scope :published, lambda{where(status: 1)}
scope :unhidden, lambda{where(hidden: 0)} scope :unhidden, lambda{where(hidden: 0)}
scope :publiced, lambda{ where(public: 2) }
after_create :send_tiding after_create :send_tiding
def send_tiding def send_tiding

@ -21,7 +21,7 @@ class Admins::SubjectQuery < ApplicationQuery
when 'applying' then 1 when 'applying' then 1
when 'published' then 2 when 'published' then 2
end end
subjects = subjects.where(status: status) if status subjects = subjects.where(public: status) if status
# 创建者单位 # 创建者单位
if params[:school_id].present? if params[:school_id].present?

@ -8,7 +8,7 @@ class Weapps::SubjectQuery < ApplicationQuery
end end
def call def call
subjects = @current_laboratory.subjects.unhidden.visible subjects = @current_laboratory.subjects.unhidden.publiced
# 课程体系的过滤 # 课程体系的过滤
if params[:sub_discipline_id].present? if params[:sub_discipline_id].present?

@ -10,7 +10,7 @@ class Admins::SubjectAuths::AgreeApplyService < ApplicationService
def call def call
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
apply.update!(status: 1, dealer_id: user.id) apply.update!(status: 1, dealer_id: user.id)
subject.update!(status: 2, publish_time: Time.now) subject.update!(public: 2, publish_time: Time.now)
deal_tiding! deal_tiding!
end end

@ -10,7 +10,7 @@ class Admins::SubjectAuths::RefuseApplyService < ApplicationService
def call def call
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
subject.update!(status: 0) subject.update!(public: 0)
apply.update!(status: 2, reason: reason, dealer_id: user.id) apply.update!(status: 2, reason: reason, dealer_id: user.id)
deal_tiding! deal_tiding!

@ -0,0 +1,2 @@
json.status @status
json.message @status == 0 ? "已公开过申请,请等待管理员审核" : "公开申请已提交,请等待管理员的审核"

@ -1,2 +1,2 @@
json.status 1 json.status 0
json.subject_id @subject.id json.subject_id @subject.id

@ -1,2 +1,2 @@
json.status @status json.status 0
json.message @status == 0 ? "已发布过申请,请等待管理员审核" : "发布申请已提交,请等待管理员的审核" json.message "申请成功"

@ -1,6 +1,10 @@
'zh-CN': 'zh-CN':
subject: subject:
status: status:
'0': 编辑中
'1': 审核中
'2': 已发布
public:
'0': 编辑中 '0': 编辑中
'1': 审核中 '1': 审核中
'2': 已发布 '2': 已发布

@ -406,9 +406,12 @@ Rails.application.routes.draw do
resources :subjects, path: :paths do resources :subjects, path: :paths do
member do member do
get 'choose_subject_shixun' get 'choose_subject_shixun'
get 'publish' post 'publish'
get 'cancel_publish' post :apply_public
get 'cancel_has_publish' post :cancel_public
post 'cancel_publish'
post 'cancel_has_publish'
post :cancel_has_public
get 'statistics' get 'statistics'
get 'statistics_info' get 'statistics_info'
get 'shixun_report' get 'shixun_report'

@ -0,0 +1,5 @@
class AddPublicForSubjects < ActiveRecord::Migration[5.2]
def change
add_column :subjects, :public, :integer, :default => 0
end
end

@ -0,0 +1,7 @@
class MigrateSubjectStatus < ActiveRecord::Migration[5.2]
def change
Subject.unhidden.visible.update_all(public: 2)
Subject.where(status: 1, id: ApplyAction.where(container_type: 'ApplySubject', status: 0)
.pluck(:container_id)).update_all(status: 2, public: 1)
end
end

@ -275,7 +275,7 @@ class TPMIndex extends Component {
url = url.split('?')[0] url = url.split('?')[0]
console.log('loadingContent, url:', url) console.log('loadingContent, url:', url)
this.setState({ loadingContent: true }) this.setState({ loadingContent: false })
cacheInterceptorUrlMap[url] = true cacheInterceptorUrlMap[url] = true
} }
@ -327,7 +327,7 @@ class TPMIndex extends Component {
} }
setLoadingContent = (isLoadingContent) => { setLoadingContent = (isLoadingContent) => {
this.setState({ loadingContent: isLoadingContent }) // this.setState({ loadingContent: isLoadingContent })
} }

Loading…
Cancel
Save