diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d737ed126..8812e69fe 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1128,11 +1128,11 @@ class CoursesController < ApplicationController return normal_status(-1, "邀请码不能为空") if params[:invite_code].blank? 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_group = CourseGroup.find_by(invite_code: invite_code) + course_group = CourseGroup.find_by(invite_code: invite_code, invite_code_halt: 0) if course.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? end diff --git a/app/controllers/examination_banks_controller.rb b/app/controllers/examination_banks_controller.rb index 1a2f3f564..bf3bb7a3a 100644 --- a/app/controllers/examination_banks_controller.rb +++ b/app/controllers/examination_banks_controller.rb @@ -61,7 +61,7 @@ class ExaminationBanksController < ApplicationController def set_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) # @exam.update_attributes!(public: 1) render_ok diff --git a/app/controllers/examination_intelligent_settings_controller.rb b/app/controllers/examination_intelligent_settings_controller.rb index 8675e699e..e9456b3dc 100644 --- a/app/controllers/examination_intelligent_settings_controller.rb +++ b/app/controllers/examination_intelligent_settings_controller.rb @@ -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) + + # 可选题中去掉已组卷的试题 type_items = items.select{ |t_item| t_item.item_type == item.item_type } - # 如果可选的题数小于等于设置的题数则提示无可换的题 - tip_exception("无可换的题") if type_items.size <= exam_type_setting.count - # 可选题中去掉已组卷的同题型试题 - optional_item_ids = type_items.pluck(:id) - @exam.item_baskets.where(item_type: item.item_type).pluck(:item_bank_id) + optional_item_ids = (type_items.pluck(:id) - @exam.item_baskets.where(item_type: item.item_type).pluck(:item_bank_id)).uniq + + # 如果可选的题数等于0则提示无可换的题 + tip_exception("无可换的题") if optional_item_ids.size == 0 + new_item = ItemBank.find optional_item_ids.sample(1).first 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) @@ -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) 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) - 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 absence_count = exam_type_setting.count - optional_item_ids.size optional_item_ids = optional_item_ids + choosed_item_ids.sample(absence_count) diff --git a/app/controllers/item_banks_controller.rb b/app/controllers/item_banks_controller.rb index cc046d061..ea10e865b 100644 --- a/app/controllers/item_banks_controller.rb +++ b/app/controllers/item_banks_controller.rb @@ -54,7 +54,7 @@ class ItemBanksController < ApplicationController def set_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) # @item.update_attributes!(public: 1) render_ok diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index efc117d6a..da88e3258 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -3,9 +3,10 @@ class SubjectsController < ApplicationController # before_action :check_auth, except: [:index] 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 :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, - :search_members, :add_subject_members, :statistics, :shixun_report, :school_report, - :up_member_position, :down_member_position, :update_team_title, :statistics_info] + 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, + :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 :shixun_marker, only: [:add_shixun_to_stage] @@ -33,16 +34,16 @@ class SubjectsController < ApplicationController laboratory_join = " AND subjects.id in #{subject_ids} " 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 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") 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 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") end else @@ -59,7 +60,7 @@ class SubjectsController < ApplicationController elsif reorder == "publish_time" @subjects = @subjects.unhidden else - @subjects = @subjects.visible.unhidden + @subjects = @subjects.publiced.unhidden end # 类型 @@ -72,7 +73,7 @@ class SubjectsController < ApplicationController 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) end @@ -273,14 +274,44 @@ class SubjectsController < ApplicationController end 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 if apply && apply.status == 0 @status = 0 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) begin - status = Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员') + Educoder::Sms.send(mobile: '18711011226', send_type:'publish_subject' , name: '管理员') rescue => e uid_logger_error("发送验证码出错: #{e}") end @@ -288,28 +319,28 @@ class SubjectsController < ApplicationController end end - def cancel_publish + def cancel_public 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) + @subject.update_attributes(public: 0) + render_ok rescue => e uid_logger_error(e.message) tip_exception("撤销申请失败") - raise ActiveRecord::Rollback end end - def cancel_has_publish + def cancel_has_public begin - @subject.update_attributes(:status => 0) + @subject.update_attributes(:public => 0) + render_ok rescue => e uid_logger_error(e.message) - tip_exception("撤销发布失败") - raise ActiveRecord::Rollback + tip_exception("撤销公开失败") end end diff --git a/app/controllers/weapps/courses_controller.rb b/app/controllers/weapps/courses_controller.rb index bef1ca9ac..e3af2310d 100644 --- a/app/controllers/weapps/courses_controller.rb +++ b/app/controllers/weapps/courses_controller.rb @@ -42,11 +42,11 @@ class Weapps::CoursesController < Weapps::BaseController tip_exception(-1, "邀请码不能为空") if params[:invite_code].blank? invite_code = params[:invite_code] 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? 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? end diff --git a/app/helpers/admins/subjects_helper.rb b/app/helpers/admins/subjects_helper.rb index 56738fd86..b2c1dbd55 100644 --- a/app/helpers/admins/subjects_helper.rb +++ b/app/helpers/admins/subjects_helper.rb @@ -6,6 +6,6 @@ module Admins::SubjectsHelper when 1 then 'text-warning' when 2 then 'text-success' 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 \ No newline at end of file diff --git a/app/models/subject.rb b/app/models/subject.rb index 99ba4b72b..70f9700df 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -40,6 +40,7 @@ class Subject < ApplicationRecord scope :visible, lambda{where(status: 2)} scope :published, lambda{where(status: 1)} scope :unhidden, lambda{where(hidden: 0)} + scope :publiced, lambda{ where(public: 2) } after_create :send_tiding def send_tiding diff --git a/app/queries/admins/subject_query.rb b/app/queries/admins/subject_query.rb index 935f52bb3..ba410312f 100644 --- a/app/queries/admins/subject_query.rb +++ b/app/queries/admins/subject_query.rb @@ -21,7 +21,7 @@ class Admins::SubjectQuery < ApplicationQuery when 'applying' then 1 when 'published' then 2 end - subjects = subjects.where(status: status) if status + subjects = subjects.where(public: status) if status # 创建者单位 if params[:school_id].present? diff --git a/app/queries/weapps/subject_query.rb b/app/queries/weapps/subject_query.rb index 5ec0c1ed9..8bfe9e9a8 100644 --- a/app/queries/weapps/subject_query.rb +++ b/app/queries/weapps/subject_query.rb @@ -8,7 +8,7 @@ class Weapps::SubjectQuery < ApplicationQuery end def call - subjects = @current_laboratory.subjects.unhidden.visible + subjects = @current_laboratory.subjects.unhidden.publiced # 课程体系的过滤 if params[:sub_discipline_id].present? diff --git a/app/services/admins/subject_auths/agree_apply_service.rb b/app/services/admins/subject_auths/agree_apply_service.rb index 465e3e903..ec5fec4bb 100644 --- a/app/services/admins/subject_auths/agree_apply_service.rb +++ b/app/services/admins/subject_auths/agree_apply_service.rb @@ -10,7 +10,7 @@ class Admins::SubjectAuths::AgreeApplyService < ApplicationService def call ActiveRecord::Base.transaction do 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! end diff --git a/app/services/admins/subject_auths/refuse_apply_service.rb b/app/services/admins/subject_auths/refuse_apply_service.rb index f51d55185..45f2d44d3 100644 --- a/app/services/admins/subject_auths/refuse_apply_service.rb +++ b/app/services/admins/subject_auths/refuse_apply_service.rb @@ -10,7 +10,7 @@ class Admins::SubjectAuths::RefuseApplyService < ApplicationService def call ActiveRecord::Base.transaction do - subject.update!(status: 0) + subject.update!(public: 0) apply.update!(status: 2, reason: reason, dealer_id: user.id) deal_tiding! diff --git a/app/views/subjects/apply_public.json.jbuilder b/app/views/subjects/apply_public.json.jbuilder new file mode 100644 index 000000000..b2266356f --- /dev/null +++ b/app/views/subjects/apply_public.json.jbuilder @@ -0,0 +1,2 @@ +json.status @status +json.message @status == 0 ? "已公开过申请,请等待管理员审核" : "公开申请已提交,请等待管理员的审核" \ No newline at end of file diff --git a/app/views/subjects/cancel_has_publish.json.jbuilder b/app/views/subjects/cancel_has_publish.json.jbuilder index 60f06b5df..224327f30 100644 --- a/app/views/subjects/cancel_has_publish.json.jbuilder +++ b/app/views/subjects/cancel_has_publish.json.jbuilder @@ -1,2 +1,2 @@ -json.status 1 +json.status 0 json.subject_id @subject.id \ No newline at end of file diff --git a/app/views/subjects/publish.json.jbuilder b/app/views/subjects/publish.json.jbuilder index 8484543db..813c3391c 100644 --- a/app/views/subjects/publish.json.jbuilder +++ b/app/views/subjects/publish.json.jbuilder @@ -1,2 +1,2 @@ -json.status @status -json.message @status == 0 ? "已发布过申请,请等待管理员审核" : "发布申请已提交,请等待管理员的审核" \ No newline at end of file +json.status 0 +json.message "申请成功" \ No newline at end of file diff --git a/config/locales/subjects/zh-CN.yml b/config/locales/subjects/zh-CN.yml index 648bd4320..55d3dd9c0 100644 --- a/config/locales/subjects/zh-CN.yml +++ b/config/locales/subjects/zh-CN.yml @@ -1,6 +1,10 @@ 'zh-CN': subject: status: + '0': 编辑中 + '1': 审核中 + '2': 已发布 + public: '0': 编辑中 '1': 审核中 '2': 已发布 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c6cc1c35..9455f7719 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -406,9 +406,12 @@ Rails.application.routes.draw do resources :subjects, path: :paths do member do get 'choose_subject_shixun' - get 'publish' - get 'cancel_publish' - get 'cancel_has_publish' + post 'publish' + post :apply_public + post :cancel_public + post 'cancel_publish' + post 'cancel_has_publish' + post :cancel_has_public get 'statistics' get 'statistics_info' get 'shixun_report' diff --git a/db/migrate/20200220023507_add_public_for_subjects.rb b/db/migrate/20200220023507_add_public_for_subjects.rb new file mode 100644 index 000000000..1783ca4af --- /dev/null +++ b/db/migrate/20200220023507_add_public_for_subjects.rb @@ -0,0 +1,5 @@ +class AddPublicForSubjects < ActiveRecord::Migration[5.2] + def change + add_column :subjects, :public, :integer, :default => 0 + end +end diff --git a/db/migrate/20200220023756_migrate_subject_status.rb b/db/migrate/20200220023756_migrate_subject_status.rb new file mode 100644 index 000000000..e036e6cdb --- /dev/null +++ b/db/migrate/20200220023756_migrate_subject_status.rb @@ -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 diff --git a/public/react/src/modules/tpm/TPMIndex.js b/public/react/src/modules/tpm/TPMIndex.js index 5edea264f..654e27352 100644 --- a/public/react/src/modules/tpm/TPMIndex.js +++ b/public/react/src/modules/tpm/TPMIndex.js @@ -275,7 +275,7 @@ class TPMIndex extends Component { url = url.split('?')[0] console.log('loadingContent, url:', url) - this.setState({ loadingContent: true }) + this.setState({ loadingContent: false }) cacheInterceptorUrlMap[url] = true } @@ -327,7 +327,7 @@ class TPMIndex extends Component { } setLoadingContent = (isLoadingContent) => { - this.setState({ loadingContent: isLoadingContent }) + // this.setState({ loadingContent: isLoadingContent }) }