fix export excel bug caused by related to more than one members and year in mongo's data-type is string not Fixnum.

This commit is contained in:
BOHUNG 2020-02-24 14:26:25 +08:00
parent d36fd9daf6
commit 4503bc8200
2 changed files with 7 additions and 7 deletions

View File

@ -120,7 +120,7 @@ module Admin::PersonalPatentsHelper
mps = role.member_profile_ids
# d1 = DateTime.new(year_start,1,1,0,0)
# d2 = DateTime.new(year_end,12,31,23,59)
d["data"] = Patent.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
d["data"] = Patent.where(:year.gte => year_start.to_s, :year.lte => year_end.to_s, :member_profile_id.in => mps) rescue []
data << d
end
return data
@ -147,7 +147,7 @@ module Admin::PersonalPatentsHelper
(year_start..year_end).each do |year|
# d1 = DateTime.new(year,1,1,0,0)
# d2 = DateTime.new(year,12,31,23,59)
t = jl.patents.where(:year => year, :member_profile_id.in => mps).count rescue 0
t = jl.patents.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0
data["data"][year.to_s] = t
end
finaldata << data
@ -158,9 +158,9 @@ module Admin::PersonalPatentsHelper
# d2 = DateTime.new(year,12,31,23,59)
case type
when "category"
t = Patent.where(:year => year, :member_profile_id.in => mps, :patent_type_ids => nil).count rescue 0
t = Patent.where(:year => year.to_s, :member_profile_id.in => mps, :patent_type_ids => nil).count rescue 0
when "author_type"
t = Patent.where(:year => year, :member_profile_id.in => mps, :patent_author_type_ids => nil).count rescue 0
t = Patent.where(:year => year.to_s, :member_profile_id.in => mps, :patent_author_type_ids => nil).count rescue 0
end
data["data"][year.to_s] = t

View File

@ -27,7 +27,7 @@ wb = xlsx_package.workbook
row << t("personal_patent.patent_category")
row << t("personal_patent.issue_no")
row << t("personal_patent.patent_no")
row << t("personal_patent.publication_date")
@ -40,7 +40,7 @@ wb = xlsx_package.workbook
sheet.add_row row, :style => heading
data.each do |patent|
row = [patent.member_profile.name]
row = [(patent.member_profile_id.class == Array ? patent.member_profile_id.map{|member_id| MemberProfile.find(member_id).name rescue ""} : [patent.member_profile.name])]
@site_in_use_locales.each do |locale|
row << patent.patent_title_translations[locale.to_s]
end
@ -54,7 +54,7 @@ wb = xlsx_package.workbook
row << patent.year
row << patent.language
row << patent.patent_types.map{|pt| pt.title}.join(", ") rescue ""
row << patent.issue_no
row << patent.patent_no
row << patent.publication_date.strftime("%Y-%m-%d") rescue ""
row << patent.url
row << patent.keywords