From 8c61d0d819f34d71a0aca845a4edaeefa05e1f5c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 29 Jul 2019 10:17:03 +0800 Subject: [PATCH] fix ec bug --- app/helpers/ec_major_schools_helper.rb | 31 ++++++++++++------- app/models/ec_year.rb | 1 + .../ec_major_schools/_year_list.html.erb | 24 +++++++++----- app/views/ec_majors/show.html.erb | 16 +++++++--- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/app/helpers/ec_major_schools_helper.rb b/app/helpers/ec_major_schools_helper.rb index 4f39913a..512e1cef 100644 --- a/app/helpers/ec_major_schools_helper.rb +++ b/app/helpers/ec_major_schools_helper.rb @@ -1,22 +1,31 @@ module EcMajorSchoolsHelper - def total_graduation_count year - g_count = EcGraduationSubitem.where(:ec_graduation_requirement_id => year.ec_graduation_requirements).count + def total_graduation_count(year) + g_count = year.ec_graduation_subitems.count g_count == 0 ? "--" : g_count - # 36 end - def sigle_graduation_count - '--' - # 30 + def sigle_graduation_count(ec_year) + return '--' if ec_year.ec_graduation_subitems.count.zero? + + 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) + + reached_map = relations.where(status: true).group('ec_graduation_subitem_id').count + + reached_map.keys.size end def total_graduation_course_count ec_year - ec_year.ec_courses.count == 0 ? '--' : ec_year.ec_courses.count - # 64 + ec_year.ec_courses.count.zero? ? '--' : ec_year.ec_courses.count end - def sigle_graduation_course_count - '--' - # 60 + def sigle_graduation_course_count(ec_year) + return '--' if ec_year.ec_courses.count.zero? + + course_ids = ec_year.ec_courses.map(&:id) + target_count_map = EcCourseTarget.where(ec_course_id: course_ids).group(:ec_course_id).count + + ec_year.ec_courses.sum { |course| course.complete_target_count == target_count_map[course.id] ? 1 : 0 } end end diff --git a/app/models/ec_year.rb b/app/models/ec_year.rb index 5f9aa00b..91e2fc02 100644 --- a/app/models/ec_year.rb +++ b/app/models/ec_year.rb @@ -9,6 +9,7 @@ class EcYear < ActiveRecord::Base # 毕业要求 has_many :ec_graduation_requirements, :dependent => :destroy + has_many :ec_graduation_subitems, through: :ec_graduation_requirements # 培养目标 has_one :ec_training_objective, :dependent => :destroy diff --git a/app/views/ec_major_schools/_year_list.html.erb b/app/views/ec_major_schools/_year_list.html.erb index 5755d3f6..ef0bb23d 100644 --- a/app/views/ec_major_schools/_year_list.html.erb +++ b/app/views/ec_major_schools/_year_list.html.erb @@ -27,22 +27,30 @@ <%= courses > 0 ? courses : @btn_text %> + <% + reached_graduation_count = sigle_graduation_count(year) + graduation_count = total_graduation_count(year) + graduation_reached = reached_graduation_count.to_i == graduation_count.to_i + + reached_course_count = sigle_graduation_course_count(year) + course_count = total_graduation_course_count(year) + %> - <%= sigle_graduation_course_count %> / <%= total_graduation_course_count(year) %> + <%= reached_course_count %> / <%= course_count %> - - <%= sigle_graduation_count %> / <%= total_graduation_count(year) %> + "> + <%= reached_graduation_count %> / <%= graduation_count %> - "> - <% if year.ec_courses.count == 0 %> - -- + "> + <% if year.ec_courses.count == 0 || graduation_count == "--" %> + -- <% else %> - <%= sigle_graduation_count == total_graduation_count(year) ? '已达成' : '未达成' %> + <%= graduation_reached ? '已达成' : '未达成' %> <% end %> - "> + "> diff --git a/app/views/ec_majors/show.html.erb b/app/views/ec_majors/show.html.erb index 29edffa8..1bfac3a9 100644 --- a/app/views/ec_majors/show.html.erb +++ b/app/views/ec_majors/show.html.erb @@ -28,21 +28,29 @@

<% @years.each do |year| %> + <% + reached_graduation_count = sigle_graduation_count(year) + graduation_count = total_graduation_count(year) + graduation_reached = reached_graduation_count.to_i == graduation_count.to_i + + reached_course_count = sigle_graduation_course_count(year) + course_count = total_graduation_course_count(year) + %>
  • <%= year.year %>年份 - <%= sigle_graduation_course_count %>/<%= total_graduation_course_count %> + <%= reached_course_count %>/<%= course_count %> - - <%= sigle_graduation_count %>/<%= total_graduation_count %> + + <%= reached_graduation_count %>/<%= graduation_count %> <%= link_to '删除', ec_major_ec_year_path(year, :ec_major_id => @ec_major), method: :delete, :class => "mr15 color-grey-c", data: { confirm: '您确定要删除吗' } %> 导出 <%= link_to "查看详情", training_objectives_ec_major_ec_year_path(year, :ec_major_id => @ec_major) %> - <%= sigle_graduation_count == total_graduation_count ? '已达成' : '未达成' %> + <%= graduation_reached ? '已达成' : '未达成' %>
  • <% end %>