diff --git a/app/controllers/add_department_applies_controller.rb b/app/controllers/add_department_applies_controller.rb new file mode 100644 index 000000000..ed8067c84 --- /dev/null +++ b/app/controllers/add_department_applies_controller.rb @@ -0,0 +1,15 @@ +class AddDepartmentAppliesController < ApplicationController + before_action :require_login + + def create + CreateAddDepartmentApplyService.call(current_user, create_params) + render_ok + rescue CreateAddDepartmentApplyService::Error => ex + render_error(ex.message) + end + + private + def create_params + params.permit(:name, :school_id, :remarks) + end +end \ No newline at end of file diff --git a/app/controllers/add_school_applies_controller.rb b/app/controllers/add_school_applies_controller.rb new file mode 100644 index 000000000..9f2376b9e --- /dev/null +++ b/app/controllers/add_school_applies_controller.rb @@ -0,0 +1,16 @@ +class AddSchoolAppliesController < ApplicationController + before_action :require_login + + def create + CreateAddSchoolApplyService.call(current_user, create_params) + render_ok + rescue CreateAddSchoolApplyService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:name, :province, :city, :address, :remarks) + end +end \ No newline at end of file diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index deb9b3157..e33e5e2dc 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -360,12 +360,7 @@ class ExerciseQuestionsController < ApplicationController end end end - - if @exercise_question.save - normal_status(0,"试卷更新成功!") - else - normal_status(-1,"试卷更新失败!") - end + normal_status(0,"试卷更新成功!") rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4474d47c8..519c05c62 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,10 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size + if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] - if params[:format] == "xlsx" || params[:format] == "zip" + if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") end else @@ -196,7 +197,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.where("work_status > 0").size + complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -216,8 +217,13 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) + if @work_excel.present? + zip_works = @work_excel&.where("work_status > 0") + status = checkfileSize(zip_works) + else + status = -1 + end + if status == 0 respond_to do |format| format.zip{ diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index e558e657c..3abc71fd0 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -15,7 +15,6 @@ class MyshixunsController < ApplicationController # For Admin # 强制重置实训 - # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game unless current_user.admin? @@ -267,9 +266,11 @@ class MyshixunsController < ApplicationController if content != last_content @content_modified = 1 - author_name = current_user.full_name + author_name = current_user.real_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" + uid_logger("112233#{author_name}") + uid_logger("112233#{author_email}") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message, diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 244cdf57f..0dfa4b1b8 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -920,7 +920,7 @@ class PollsController < ApplicationController def commit_result ActiveRecord::Base.transaction do begin - @poll_users = @poll.poll_users + @poll_users = @poll.all_poll_users(current_user.id) @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @limit = params[:limit] || 10 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5a1773a10..0a7a4fece 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -180,6 +180,7 @@ class ShixunsController < ApplicationController end # 同步配置 + logger.info("########-shixun_service_configs_count: #{@shixun.shixun_service_configs.pluck(:id, :shixun_id)}") @shixun.shixun_service_configs.each do |config| ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, :cpu_limit => config.cpu_limit, @@ -521,7 +522,18 @@ class ShixunsController < ApplicationController end # 如果存在实训,则直接进入实训 - @current_task = current_myshixun.current_task(games) + # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 + @current_task = + if params[:challenge_id] + game = games.where(challenge_id: params[:challenge_id]).take + if game.status == 3 && !@shixun.task_pass + tip_show_exception(-4, "关卡还未开启") + else + game + end + else + current_myshixun.current_task(games) + end else # 如果未创建关卡一定不能开启实训,否则TPI没法找到当前的关卡 if @shixun.challenges_count == 0 diff --git a/app/forms/add_school_apply_form.rb b/app/forms/add_school_apply_form.rb new file mode 100644 index 000000000..c0b767f06 --- /dev/null +++ b/app/forms/add_school_apply_form.rb @@ -0,0 +1,10 @@ +class AddSchoolApplyForm + include ActiveModel::Model + + attr_accessor :name, :province, :city, :address, :remarks + + validates :name, presence: true + validates :province, presence: true + validates :city, presence: true + validates :address, presence: true +end \ No newline at end of file diff --git a/app/forms/users/update_account_form.rb b/app/forms/users/update_account_form.rb index 68e7fb7bf..d82459fcf 100644 --- a/app/forms/users/update_account_form.rb +++ b/app/forms/users/update_account_form.rb @@ -10,9 +10,9 @@ class Users::UpdateAccountForm validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] } validates :location, presence: true validates :location_city, presence: true - validates :identity, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1, 2] } - validates :technical_title, presence: true, unless: -> { identity == 1 } - validates :student_id, presence: true, if: -> { identity == 1 } + validates :identity, presence: true, inclusion: { in: %w[teacher student professional ] } + validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' } + validates :student_id, presence: true, if: -> { identity.to_s == 'student' } validates :school_id, presence: true validate :check_school_exist diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 437965ca6..55ade6e7c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -382,6 +382,9 @@ module ExercisesHelper end answers_content.update_all(:score => q_score_1) score1 = score1 + q.question_score + else + answers_content.update_all(:score => -1.0) + score1 += 0.0 end else score1 += 0.0 @@ -403,6 +406,9 @@ module ExercisesHelper if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score2 = score2 + q_score_2 + else + u.update_column('score',-1.0) + score2 += 0.0 end end else @@ -413,6 +419,9 @@ module ExercisesHelper u.update_column("score",q_score_2) score2 = score2 + q_score_2 st_answer_text.delete(u_answer_text) + else + u.update_column('score',-1.0) + score2 += 0.0 end end end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index d9b6ccee7..1892f3fa2 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -127,4 +127,17 @@ module PollsHelper "login":user.login } end + + def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) + poll_users_info = %w(序号) + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + poll_un_anony = poll.un_anonymous + if poll_un_anony #是否匿名,默认为false + user_info = %w(登陆名 真实姓名 邮箱 学号) + else + user_info = [] + end + poll_users_info = poll_users_info + user_info + poll_ques_titles + + end end diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index 563f6ceb0..9c43b1978 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -6,6 +6,7 @@ class ExercisePublishNotifyJob < ApplicationJob exercise = Exercise.find_by(id: exercise_id) return if exercise.blank? user = exercise.user + course = exercise.course if group_ids.present? students = course.students.where(course_group_id: group_ids) @@ -30,7 +31,7 @@ class ExercisePublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids) - teacher_ids.find_each do |user_id| + teacher_ids.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 92346ab27..16f5893ae 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -5,6 +5,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) return if task.blank? + course = task.course + return if course.blank? attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type @@ -18,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - task.course.course_members.pluck(:user_id).uniq.find_each do |user_id| + course.course_members.pluck(:user_id).uniq.find_each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index ea6d3e5e3..649a5c37a 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -2,7 +2,7 @@ class HomeworkEndUpdateScoreJob < ApplicationJob # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 queue_as :score - def perform(*args) + def perform(homework_id) homework = HomeworkCommon.find_by(id: homework_id) return if homework.blank? course = homework.course @@ -16,7 +16,8 @@ class HomeworkEndUpdateScoreJob < ApplicationJob student_works = homework.student_works.where(user_id: user_ids) end - myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + shixun_id = homework.homework_commons_shixun.try(:shixun_id) + myshixuns = Myshixun.where(shixun_id: shixun_id, user_id: user_ids). includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)}) challenge_settings = homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index 89fb45ea5..52660abd1 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -31,7 +31,7 @@ class PollPublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) - teacher_ids.find_each do |user_id| + teacher_ids.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/submit_graduation_work_notify_job.rb b/app/jobs/submit_graduation_work_notify_job.rb index 17cfc21d2..d4bb21cc4 100644 --- a/app/jobs/submit_graduation_work_notify_job.rb +++ b/app/jobs/submit_graduation_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitGraduationWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = task.graduation_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/jobs/submit_student_work_notify_job.rb b/app/jobs/submit_student_work_notify_job.rb index acb7873ac..c4dff264c 100644 --- a/app/jobs/submit_student_work_notify_job.rb +++ b/app/jobs/submit_student_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitStudentWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = homework.student_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/models/applied_message.rb b/app/models/applied_message.rb new file mode 100644 index 000000000..ed02a5445 --- /dev/null +++ b/app/models/applied_message.rb @@ -0,0 +1,5 @@ +class AppliedMessage < ApplicationRecord + belongs_to :user + belongs_to :applied, polymorphic: true + +end \ No newline at end of file diff --git a/app/models/apply_add_department.rb b/app/models/apply_add_department.rb new file mode 100644 index 000000000..3deeaa97e --- /dev/null +++ b/app/models/apply_add_department.rb @@ -0,0 +1,15 @@ +class ApplyAddDepartment < ApplicationRecord + belongs_to :user + belongs_to :school + belongs_to :department + + has_many :applied_messages, as: :applied + has_many :tidings, as: :container, dependent: :destroy + + after_create :send_notify + + private + def send_notify + tidings.create!(user_id: 1, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply', status: 0) + end +end \ No newline at end of file diff --git a/app/models/apply_add_school.rb b/app/models/apply_add_school.rb new file mode 100644 index 000000000..bae65d24f --- /dev/null +++ b/app/models/apply_add_school.rb @@ -0,0 +1,14 @@ +class ApplyAddSchool < ApplicationRecord + belongs_to :school + + has_many :applied_messages, as: :applied + has_many :tidings, as: :container, dependent: :destroy + + after_create :send_notify + + private + + def send_notify + tidings.create!(user_id: 1, status: 0, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply') + end +end \ No newline at end of file diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e7a382a51..ac031c31c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -76,8 +76,9 @@ class Challenge < ApplicationRecord ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = games.last - + # 允许跳关则直接开启 + return 1 if shixun.task_pass + game = games.where(user_id: user_id).take if game.blank? self.position == 1 ? 1 : 0 elsif game.status == 2 diff --git a/app/models/course_member.rb b/app/models/course_member.rb index d9995d463..7db681e67 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -146,11 +146,11 @@ class CourseMember < ApplicationRecord def member_teachers teacher_groups = course.teacher_course_groups if teacher_groups.count > 0 - member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id) + member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact - none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).join(',') : -1 - teachers = course.teachers.where("members.id not in (#{none_group_teachers}) or - members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") + none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 + teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or + course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") else teachers = course.teachers end diff --git a/app/models/user.rb b/app/models/user.rb index 1b3349467..e775af5f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -404,7 +404,6 @@ class User < ApplicationRecord # 用户的真实姓名(不考虑用户是否隐藏了真实姓名,课堂模块都用真实姓名) def real_name return '游客' unless logged? - name = lastname + firstname name.blank? ? (nickname.blank? ? login : nickname) : name name.gsub(/\s+/, '').strip #6.11 -hs diff --git a/app/services/create_add_department_apply_service.rb b/app/services/create_add_department_apply_service.rb new file mode 100644 index 000000000..f1d6cf852 --- /dev/null +++ b/app/services/create_add_department_apply_service.rb @@ -0,0 +1,43 @@ +class CreateAddDepartmentApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + name = params[:name].to_s.strip + raise Error, '名称不能为空' if name.blank? + + school = School.find_by(id: params[:school_id]) + raise Error, '学校/单位不存在' if school.blank? + + department = Department.new + department.name = name + department.school = school + + ActiveRecord::Base.transaction do + department.save! + + attrs = { + user_id: user.id, department: department, school: school, + name: department.name, remarks: params[:remarks], status: 0, + } + apply = ApplyAddDepartment.create!(attrs) + + unless user.professional_certification? + user.user_extension.update!(department_id: department.id) + end + + # 向管理员发送通知 + message = AppliedMessage.new(user_id: 1, status: 0, applied_user_id: user.id, viewed: 0, + applied_id: apply.id, applied_type: 'ApplyAddDepartment', name: department.name) + message.save(validate: false) + end + + school + end +end diff --git a/app/services/create_add_school_apply_service.rb b/app/services/create_add_school_apply_service.rb new file mode 100644 index 000000000..96619c681 --- /dev/null +++ b/app/services/create_add_school_apply_service.rb @@ -0,0 +1,37 @@ +class CreateAddSchoolApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + AddSchoolApplyForm.new(params).validate! + + name = params[:name].to_s.strip + raise Error, '学校/单位已经存在' if name.present? && School.exists?(name: name) + + school = School.new + school.name = name + school.province = params[:province].to_s.strip + school.city = params[:city].to_s.strip + school.address = params[:address].to_s.strip + + ActiveRecord::Base.transaction do + school.save! + + school_attrs = school.as_json(only: %i[name province city address]) + ApplyAddSchool.create!(school_attrs.merge(school: school, user_id: user.id, remarks: params[:remarks])) + + # 向管理员发送通知 + message = AppliedMessage.new(user_id: 1, status: 0, applied_user_id: user.id, viewed: 0, + applied_id: school.id, applied_type: 'ApplyAddSchools', name: school.name) + message.save(validate: false) + end + + school + end +end diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 6b92be411..37ce94305 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,7 +17,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.open_game challenge.open_game(@user.id, @shixun) + #json.open_game challenge.open_game(@user.id, @shixun) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) diff --git a/app/views/homework_commons/_student_btn_check.json.jbuilder b/app/views/homework_commons/_student_btn_check.json.jbuilder index efa89203d..7b34622fa 100644 --- a/app/views/homework_commons/_student_btn_check.json.jbuilder +++ b/app/views/homework_commons/_student_btn_check.json.jbuilder @@ -1,6 +1,8 @@ if identity == Course::STUDENT if homework.homework_type == "practice" - json.task_operation task_operation_url(work.try(:myshixun), homework.shixuns.take) + shixun = homework.shixuns.take + myshixun = work.try(:myshixun) ? work.myshixun : shixun.myshixuns.find_by(user_id: work.user_id) + json.task_operation task_operation_url(myshixun, shixun) json.view_report work.work_status > 0 json.commit_des commit_des_status(work, homework) else diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 6ce00388c..71585dae9 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -8,7 +8,10 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false poll_users_info = %w(序号) + Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}") + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}") poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) @@ -18,13 +21,13 @@ wb.styles do |s| poll_users_info = poll_users_info + user_info + poll_ques_titles poll_questions.each do |q| if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).count #该问题的有效填写量 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_percent = ["比例"] sheet_answer_useful = ["有效填写人次",question_vote_user] q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).count + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) sheet_row.push(a.answer_text) sheet_answer_row.push(answer_users_count) @@ -41,15 +44,15 @@ wb.styles do |s| else #主观题答案 main_show_row = ["第#{q.question_number}题",q.question_title] sheet.add_row main_show_row,:height =>15, :style => blue_cell - q.poll_votes.each do |v| #主观题的答案 - sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all + q.poll_votes.each_with_index do |v,index| #主观题的答案 + sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all end sheet.add_row [], :style => sz_all end end #each_with_index sheet.add_row poll_users_info, :height =>15, :style => blue_cell - poll_users.each_with_index do |u,index| + poll_users.includes(user: :user_extension).each_with_index do |u,index| u_user = u.user user_answer_array = [] poll_questions.each do |q| diff --git a/config/locales/forms/add_school_apply_form.zh-CN.yml b/config/locales/forms/add_school_apply_form.zh-CN.yml new file mode 100644 index 000000000..749578164 --- /dev/null +++ b/config/locales/forms/add_school_apply_form.zh-CN.yml @@ -0,0 +1,8 @@ +'zh-CN': + activemodel: + attributes: + add_school_apply_form: + name: 名称 + province: 省份 + city: 城市 + address: 详细地址 diff --git a/config/routes.rb b/config/routes.rb index d9a6b41a4..1a81f1175 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -596,6 +596,8 @@ Rails.application.routes.draw do resources :ec_major_schools, only: [:index, :create, :destroy] end end + resources :add_school_applies, only: [:create] + resources :add_department_applies, only: [:create] # 为避免url过长以及层级过深,路由定义和controller继承都做了处理 scope module: :ecs do diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb new file mode 100644 index 000000000..693add3e3 --- /dev/null +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -0,0 +1,9 @@ +class AddIndexForShixunServices < ActiveRecord::Migration[5.2] + def change + sql = %Q(delete from shixun_service_configs where (shixun_id, mirror_repository_id) in + (select * from (select shixun_id, mirror_repository_id from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1) a) + and id not in (select * from (select min(id) from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql + add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" + end +end