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/files_controller.rb b/app/controllers/files_controller.rb index 2af178e47..05a9ab841 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -3,7 +3,7 @@ class FilesController < ApplicationController before_action :require_login, except: %i[index] before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] - before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public] + before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish] before_action :file_validate_sort_type, only: :index before_action :validate_send_message_to_course_params, only: :bulk_send before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] @@ -40,6 +40,12 @@ class FilesController < ApplicationController @attachments = @attachments.page(@page).per(@page_size) end + def bulk_publish + return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5 + @course.attachments.by_ids(@attachment_ids).unpublish.update_all(is_publish: 1, publish_time: Time.now) + render_ok + end + def bulk_delete ActiveRecord::Base.transaction do begin diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4474d47c8..018218799 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -108,7 +108,7 @@ class HomeworkCommonsController < ApplicationController @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 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.where("work_status > 0").size + complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -216,8 +216,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.exist? + 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..3dfb739d0 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? diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5a1773a10..2c4f2a7d1 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, 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/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/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/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 01e301c3c..1a81f1175 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -256,6 +256,7 @@ Rails.application.routes.draw do get :mine_with_course_and_project post :import post :upload + put :bulk_publish end member do get :histories @@ -595,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..3e6dd3703 --- /dev/null +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -0,0 +1,5 @@ +class AddIndexForShixunServices < ActiveRecord::Migration[5.2] + def change + add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" + end +end