diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb index e4a51b26..b766ad07 100644 --- a/app/controllers/managements_controller.rb +++ b/app/controllers/managements_controller.rb @@ -1746,22 +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]) - # 删除学校的用户 - users = UserExtensions.where("department_id = #{applied_department.department_id}") - users.update_all(department_id: nil, profile_completed: false) - applied_department.department.destroy - # 已审批删除 - elsif params[:tip] == "applied" - applied_department.destroy + ActiveRecord::Base.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 } diff --git a/app/helpers/ec_major_schools_helper.rb b/app/helpers/ec_major_schools_helper.rb index 512e1cef..d4e34219 100644 --- a/app/helpers/ec_major_schools_helper.rb +++ b/app/helpers/ec_major_schools_helper.rb @@ -9,9 +9,9 @@ module EcMajorSchoolsHelper subitem_ids = ec_year.ec_graduation_subitems.reorder(nil).pluck(:id) - relations = EcGraduationRequirementCalculation.joins(ec_course_support: :ec_graduation_subitem_courses).where('ec_graduation_subitem_id in (?)', subitem_ids) + relations = EcGraduationRequirementCalculation.joins(ec_course_support: :ec_graduation_subitem_courses).where('ec_graduation_subitem_courses.ec_graduation_subitem_id in (?)', subitem_ids) - reached_map = relations.where(status: true).group('ec_graduation_subitem_id').count + reached_map = relations.where(status: true).group('ec_graduation_subitem_courses.ec_graduation_subitem_id').count reached_map.keys.size end diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb index e2551710..a8f48b3e 100644 --- a/app/models/competition_team.rb +++ b/app/models/competition_team.rb @@ -11,7 +11,8 @@ class CompetitionTeam < ActiveRecord::Base # attr_accessible :invite_code, :name, :team_type def teacher - User.where(:id => self.teacher_id).first + teacher_id = self.teachers.first&.user_id + User.where(id: teacher_id).first end def group_members diff --git a/app/models/course_member.rb b/app/models/course_member.rb index d67994ef..788f87aa 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -15,6 +15,7 @@ class CourseMember < ActiveRecord::Base homeworks = course.homework_commons.includes(:homework_detail_manual).where("homework_type in (1, 3, 4)") if homeworks.count != 0 homeworks.each do |hw| + next if hw.student_works.where(user_id: user_id).any? str += "," if str != "" str += "('#{hw.name}的作品提交',#{hw.id},#{user_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end @@ -34,6 +35,7 @@ class CourseMember < ActiveRecord::Base exercises = course.exercises if exercises.count != 0 exercises.each do |ex| + next if ex.exercise_users.where(user_id: user_id).any? str += "," if str != "" str += "(#{ex.id},#{user_id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end @@ -53,6 +55,7 @@ class CourseMember < ActiveRecord::Base polls = course.polls if polls.count != 0 polls.each do |poll| + next if poll.poll_users.where(user_id: user_id).any? str += "," if str != "" str += "(#{poll.id},#{user_id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end @@ -72,6 +75,7 @@ class CourseMember < ActiveRecord::Base tasks = course.graduation_tasks if tasks.count != 0 tasks.each do |task| + next if task.graduation_works.where(user_id: user_id).any? str += "," if str != "" str += "(#{task.id}, #{user_id}, #{course.id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end diff --git a/app/models/message.rb b/app/models/message.rb index 9e516acb..91fdefac 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -119,6 +119,10 @@ class Message < ActiveRecord::Base message_detail.try(:content) end + def content + message_detail.try(:content) + end + # def content # self.try(:content) # end diff --git a/app/views/files/_tool_settings.html.erb b/app/views/files/_tool_settings.html.erb index 4ebbf852..577030f8 100644 --- a/app/views/files/_tool_settings.html.erb +++ b/app/views/files/_tool_settings.html.erb @@ -5,16 +5,16 @@ <% if User.current.admin? || ((delete_allowed || User.current.id == file.author_id) && file.container_id == project.id && file.container_type == "Project") %>