部门的删除

dev_aliyun
cxt 5 years ago
parent 6e322a5630
commit 7da238def9

@ -1746,24 +1746,26 @@ end
# 删除
def delete_applied_departments
applied_department = ApplyAddDepartment.find params[:depart_id]
applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment")
applied_message.update_all(:status => 3)
applied_department.update_attribute(:status, 3)
# 未审批删除
if params[:tip] == "unapplied"
# AppliedMessage.create(:user_id => applied_department.user_id, :status => 3, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name )
Tiding.where(:user_id => 1, :trigger_user_id => applied_department.user_id, :container_id => applied_department.id, :container_type => 'ApplyAddDepartment', :status => 0, :tiding_type => "Apply").update_all(:status => 1)
Tiding.create(:user_id => applied_department.user_id, :trigger_user_id => 0, :container_id => applied_department.id, :container_type =>'ApplyAddDepartment', :belong_container_id => applied_department.department.school_id, :belong_container_type=> 'School', :tiding_type => "System", :status => 2, :extra => params[:reason])
# 删除学校的用户
user_exs = UserExtensions.where("department_id = #{applied_department.department_id}")
users = User.where(id: user_exs.pluck(:user_id))
user_exs.update_all(department_id: nil)
users.update_all(profile_completed: false)
applied_department.department.destroy
# 已审批删除
elsif params[:tip] == "applied"
applied_department.destroy
transaction do
applied_department = ApplyAddDepartment.find params[:depart_id]
applied_message = AppliedMessage.where(:applied_id => applied_department.id, :applied_type => "ApplyAddDepartment")
applied_message.update_all(:status => 3)
applied_department.update_attribute(:status, 3)
# 未审批删除
if params[:tip] == "unapplied"
# AppliedMessage.create(:user_id => applied_department.user_id, :status => 3, :viewed => 0, :applied_id => applied_department.id, :applied_type => "ApplyAddDepartment", :name => applied_department.name )
Tiding.where(:user_id => 1, :trigger_user_id => applied_department.user_id, :container_id => applied_department.id, :container_type => 'ApplyAddDepartment', :status => 0, :tiding_type => "Apply").update_all(:status => 1)
Tiding.create(:user_id => applied_department.user_id, :trigger_user_id => 0, :container_id => applied_department.id, :container_type =>'ApplyAddDepartment', :belong_container_id => applied_department.department.school_id, :belong_container_type=> 'School', :tiding_type => "System", :status => 2, :extra => params[:reason])
# 删除学校的用户
user_exs = UserExtensions.where("department_id = #{applied_department.department_id}")
users = User.where(id: user_exs.pluck(:user_id))
user_exs.update_all(department_id: nil)
users.update_all(profile_completed: false)
applied_department.department.destroy
# 已审批删除
elsif params[:tip] == "applied"
applied_department.destroy
end
end
respond_to do |format|
format.html{ redirect_to depart_managements_path }

@ -0,0 +1,16 @@
class MigrateDeleteDepartment < ActiveRecord::Migration
def up
ApplyAddDepartment.where("status= 3 and created_at > '2019-07-25 00:00:00'").each do |apply|
if apply.department.present? && !apply.department.is_auth
user_exs = UserExtensions.where("department_id = #{apply.department_id}")
users = User.where(id: user_exs.pluck(:user_id))
user_exs.update_all(department_id: nil)
users.update_all(profile_completed: false)
apply.department.destroy
end
end
end
def down
end
end
Loading…
Cancel
Save