Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
903b1337fd
@ -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
|
@ -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
|
@ -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
|
@ -0,0 +1,5 @@
|
|||||||
|
class AppliedMessage < ApplicationRecord
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :applied, polymorphic: true
|
||||||
|
|
||||||
|
end
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -0,0 +1,8 @@
|
|||||||
|
'zh-CN':
|
||||||
|
activemodel:
|
||||||
|
attributes:
|
||||||
|
add_school_apply_form:
|
||||||
|
name: 名称
|
||||||
|
province: 省份
|
||||||
|
city: 城市
|
||||||
|
address: 详细地址
|
@ -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
|
Loading…
Reference in new issue