diff --git a/app/controllers/admins/base_controller.rb b/app/controllers/admins/base_controller.rb index e2e3babae..ad56afbf7 100644 --- a/app/controllers/admins/base_controller.rb +++ b/app/controllers/admins/base_controller.rb @@ -6,6 +6,7 @@ class Admins::BaseController < ApplicationController layout 'admin' skip_before_action :verify_authenticity_token + skip_before_action :setup_laboratory before_action :require_login, :require_admin! diff --git a/app/controllers/admins/competition_prize_users_controller.rb b/app/controllers/admins/competition_prize_users_controller.rb index 50d11e211..34dbc1f76 100644 --- a/app/controllers/admins/competition_prize_users_controller.rb +++ b/app/controllers/admins/competition_prize_users_controller.rb @@ -6,6 +6,16 @@ class Admins::CompetitionPrizeUsersController < Admins::BaseController include_class = [:competition_team, :competition_prize, :approver, user: [:process_real_name_apply, :process_professional_apply, user_extension: :school]] @prize_users = paginate(prize_users.preload(include_class)) + + respond_to do |format| + format.js + format.html + format.xlsx do + @all_prize_users = prize_users + filename = "#{@competition.name}竞赛获奖人信息列表_#{Time.current.strftime('%Y%m%d%H%M%S')}.xlsx" + render xlsx: 'index', filename: filename + end + end end def create diff --git a/app/controllers/admins/enroll_lists_controller.rb b/app/controllers/admins/enroll_lists_controller.rb index fb7cec9b0..f9fac9316 100644 --- a/app/controllers/admins/enroll_lists_controller.rb +++ b/app/controllers/admins/enroll_lists_controller.rb @@ -12,10 +12,6 @@ class Admins::EnrollListsController < Admins::BaseController respond_to do |format| format.js format.html - format.xls{ - filename = "#{@competition.name}竞赛报名列表_#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}.xls" - send_data(shixun_list_xls(shixuns), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename)) - } end end diff --git a/app/controllers/admins/laboratories_controller.rb b/app/controllers/admins/laboratories_controller.rb index 3bc9383cc..d75b2e11f 100644 --- a/app/controllers/admins/laboratories_controller.rb +++ b/app/controllers/admins/laboratories_controller.rb @@ -1,7 +1,6 @@ class Admins::LaboratoriesController < Admins::BaseController def index - params[:sort_by] = params[:sort_by].presence || 'id' - params[:sort_direction] = params[:sort_direction].presence || 'desc' + default_sort('id', 'desc') laboratories = Admins::LaboratoryQuery.call(params) @laboratories = paginate laboratories.preload(:school, :laboratory_users) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 488289815..5dd001f5a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -288,11 +288,11 @@ class CoursesController < ApplicationController inform = @course.informs.find_by(id: params[:inform_id]) next_inform = inform.next_inform ActiveRecord::Base.transaction do - if next_inform + if next_inform.blank? render_error('已经到达最顶部') else - inform.update_attribute(:position, (position + 1)) - next_inform.update_attribute(:position, last_inform.position - 1) + inform.update_attribute(:position, (inform.position + 1)) + next_inform.update_attribute(:position, inform.position - 1) render_ok end end @@ -302,11 +302,11 @@ class CoursesController < ApplicationController inform = @course.informs.find_by(id: params[:inform_id]) last_inform = inform.last_inform ActiveRecord::Base.transaction do - if last_inform + if last_inform.blank? render_error('已经到达最底部') else - inform.update_attribute(:position, (position - 1)) - last_inform.update_attribute(:position, last_inform.position + 1) + inform.update_attribute(:position, (inform.position - 1)) + last_inform.update_attribute(:position, inform.position + 1) render_ok end end @@ -317,7 +317,7 @@ class CoursesController < ApplicationController inform = Inform.new(container: @course) inform.name = params[:name] inform.description = params[:description] - inform.position = @course.informs.maximum(:position) + 1 + inform.position = @course.informs.maximum(:position).to_i + 1 inform.save! normal_status("创建成功") end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 48c942e65..ba07d42c9 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -26,12 +26,27 @@ class HomeController < ApplicationController @rep_list << {rep_id: rep.id, rep_name: rep.name, sub_rep_list: sub_rep_list} end - @shixuns = Shixun.where(homepage_show: 1).includes(:tag_repertoires, :challenges).limit(8) + shixuns = current_laboratory.shixuns + subjects = current_laboratory.subjects + + if current_laboratory.main_site? + shixuns = shixuns.where(homepage_show: true) + subjects = subjects.where(homepage_show: true) + else + shixuns = shixuns.where(laboratory_shixuns: { homepage: true }) + subjects = subjects.where(laboratory_subjects: { homepage: true }) + end + + @shixuns = shixuns.includes(:tag_repertoires, :challenges).limit(8) + @subjects = subjects.includes(:repertoire, :shixuns).limit(8) - @subjects = Subject.where(homepage_show: 1).includes(:shixuns, :repertoire).limit(8) + @main_shixuns = Shixun.where(homepage_show: true).includes(:tag_repertoires, :challenges).limit(8) + @main_subjects = Subject.where(homepage_show: true).includes(:shixuns, :repertoire).limit(8) - @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") - @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + if current_laboratory.main_site? + @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") + @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + end end def search diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c1e08d440..3a8a25133 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -103,11 +103,14 @@ class MessagesController < ApplicationController return normal_status(403, "您没有权限进行该操作") if current_user != @message.author && !current_user.teacher_of_course?(@message.board.course) begin - h = {is_md: true} + email_notify = @message.email_notify ? 1 : @board.course.email_notify && params[:email_notify] + send_email = !@message.email_notify && email_notify + h = {is_md: true, email_notify: email_notify} m_params = message_params.merge(h) @message.update_attributes(m_params) Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) @message.update_content(params[:content]) + notify_course_students(@message, @board.course) if send_email rescue Exception => e uid_logger_error(e.message) tip_exception("修改失败") @@ -123,6 +126,7 @@ class MessagesController < ApplicationController @message.author = current_user @message.board_id = params[:select_board_id] @message.message_detail_attributes = {content: params[:content]} + @message.email_notify = @board.course.email_notify && params[:email_notify] ? 1 : 0 @message.save! Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) if @board.course.email_notify && params[:email_notify] @@ -189,7 +193,7 @@ class MessagesController < ApplicationController private def validate_sort_type - normal_status(2, "参数sort_tyope暂时只支持 'time', 'hot'两种") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip) + normal_status(2, "参数sort_type暂时只支持 'time', 'hot'两种") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip) end def find_message @@ -207,7 +211,7 @@ class MessagesController < ApplicationController def notify_course_students message, course course.students.includes(:user).each do |student| - UserMailer.course_message_email(student&.user&.mail, message.id).deliver_now if student&.user&.mail + UserMailer.course_message_email(student&.user&.mail, message.id).deliver_later if student&.user&.mail end end end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e2b78ee4b..cfe6141ee 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -33,7 +33,12 @@ class ShixunsController < ApplicationController current_user.my_shixuns else Shixun.unhidden - end + end + + ## 云上实验室过滤 + unless current_laboratory.main_site? + @shixuns = @shixuns.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: current_laboratory.id }) + end ## 方向 if params[:tag_level].present? && params[:tag_id].present? diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 9c6980b69..b76db8a20 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -23,16 +23,17 @@ class SubjectsController < ApplicationController # 最热排序 if reorder == "myshixun_count" + laboratory_join = current_laboratory.main_site? ? '' : " JOIN laboratory_subjects ls ON ls.subject_id = subjects.id AND ls.laboratory_id = #{current_laboratory.id} " if select @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, 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 #{laboratory_join} where subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' 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.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 #{laboratory_join} where subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' GROUP BY subjects.id ORDER BY myshixun_member_count DESC") end @@ -52,6 +53,11 @@ class SubjectsController < ApplicationController @subjects = Subject.visible.unhidden end + # 云上实验室过滤 + unless current_laboratory.main_site? + @subjects = @subjects.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: current_laboratory.id }) + end + # 类型 if select @subjects = @subjects.where(repertoire_id: select) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 5cd9d787c..6e957b4df 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -12,6 +12,6 @@ class UserMailer < ApplicationMailer def course_message_email(mail, message_id) @message = Message.find_by(id: message_id) @course = @message&.board&.course - mail(to: mail, subject: '课堂通知') if @message.present? && @course.present? + mail(to: mail, subject: '课堂发布了新的帖子') if @message.present? && @course.present? end end diff --git a/app/models/inform.rb b/app/models/inform.rb index 93b7d5337..dc979ef32 100644 --- a/app/models/inform.rb +++ b/app/models/inform.rb @@ -7,11 +7,11 @@ class Inform < ApplicationRecord has_many :attachments, as: :container, dependent: :destroy def next_inform - Inform.where(position: self.position+1, container_id: self.container_id, container_type: self.container_type) + Inform.find_by(position: self.position+1, container_id: self.container_id, container_type: self.container_type) end def last_inform - Inform.where(position: self.position-1, container_id: self.container_id, container_type: self.container_type) + Inform.find_by(position: self.position-1, container_id: self.container_id, container_type: self.container_type) end end diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index ff8f89c5e..672294b63 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -38,4 +38,17 @@ class Laboratory < ApplicationRecord def self.current Thread.current[:current_laboratory] ||= Laboratory.find(1) end + + def shixuns + main_site? ? Shixun.all : Shixun.joins(:laboratory_shixuns).where(laboratory_shixuns: { laboratory_id: id }) + end + + def subjects + main_site? ? Subject.all : Subject.joins(:laboratory_subjects).where(laboratory_subjects: { laboratory_id: id }) + end + + # 是否为主站 + def main_site? + id == 1 + end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 85b9ef551..5d9ccd0ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -235,6 +235,28 @@ class User < ApplicationRecord end end + # 实名认证状态 + def auth_status + status = if authentication + "已认证" + elsif process_real_name_apply.present? + "待审核" + else + "未认证" + end + end + + # 职业认证状态 + def pro_status + status = if professional_certification + "已认证" + elsif process_professional_apply.present? + "待审核" + else + "未认证" + end + end + # 判断当前用户是否通过职业认证 def pro_certification? professional_certification diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index acff0a726..fa57a8901 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -94,8 +94,8 @@ class DuplicateCourseService < ApplicationService exercise = course.exercises.create!(attrs.merge(user_id: user.id)) origin_exercise.exercise_questions.find_each do |origin_question| - question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score]) - question_attrs[:question_type] ||= 1 + question_attrs = origin_question.as_json(only: %i[question_title question_type question_number question_score shixun_name shixun_id is_ordered level]) + # question_attrs[:question_type] ||= 1 question = exercise.exercise_questions.create!(question_attrs) exercise_choice_map = {} @@ -103,15 +103,20 @@ class DuplicateCourseService < ApplicationService choice_attrs = { choice_position: index + 1, choice_text: origin_choice.choice_text } choice = question.exercise_choices.create!(choice_attrs) - exercise_choice_map[origin_choice.id] = choice.id + # exercise_choice_map[origin_choice.id] = choice.id 标准答案中存的是choice_position, 直接取原题的exercise_choice_id就行 end origin_question.exercise_standard_answers.find_each do |origin_answer| question.exercise_standard_answers.create!( - exercise_choice_id: exercise_choice_map[origin_answer.exercise_choice_id], + exercise_choice_id: origin_answer.exercise_choice_id, answer_text: origin_answer.answer_text ) end + + origin_question.exercise_shixun_challenges.each_with_index do |sc, index| + question.exercise_shixun_challenges.create!({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) + end end origin_exercise.exercise_bank.increment!(:quotes) if exercise.exercise_bank diff --git a/app/views/admins/competition_prize_users/index.html.erb b/app/views/admins/competition_prize_users/index.html.erb index dbb86d066..735d94d2e 100644 --- a/app/views/admins/competition_prize_users/index.html.erb +++ b/app/views/admins/competition_prize_users/index.html.erb @@ -50,6 +50,12 @@ <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> <%= link_to '清除', admins_competition_competition_prize_users_path(@competition), class: "btn btn-default",'data-disable-with': '清除中...' %> <% end %> + +
+ {hackathonedit===true?"":
{data&&data.hackathon.description===null?"":
} - + } + + {hackathonedit===true?{item.description}
+Card content
-Card content
-Card content
-Card content
-+ 名称 +
+ + this.changeTitle(e)} + className={"Osshackathonmodelinput"} + style={{"width": "100%"}} maxLength="60" + addonAfter={String(this.state.title_value===undefined?0:this.state.title_value.length)+"/60"} + /> + ++ 描述 +
+ +