parent
be0dabc7ec
commit
ddf20eea84
@ -0,0 +1,5 @@
|
||||
module PdfkitHelper
|
||||
def download_image(url)
|
||||
'data:image/png;base64,' + Base64.encode64(open(url) { |io| io.read })
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
# 生成竞赛个人证书Job
|
||||
class GenerateCompetitionPersonalCertificateJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(prize_user_id)
|
||||
@prize_user = CompetitionPrizeUser.find_by(id: prize_user_id)
|
||||
return if @prize_user.blank? || @prize_user.certificate_exist?
|
||||
|
||||
template = @prize_user.user.is_teacher? ? 'teacher' : 'personal'
|
||||
file = File.open(Rails.root.join("app/templates/competition_certificates/#{template}.html.erb"))
|
||||
html = ERB.new(file.read).result(binding)
|
||||
kit = PDFKit.new(html, page_width: 842, page_height: 595)
|
||||
|
||||
path = @prize_user.certificate_path
|
||||
dir = File.dirname(path)
|
||||
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
||||
kit.to_pdf(path)
|
||||
end
|
||||
end
|
@ -0,0 +1,24 @@
|
||||
# 生成竞赛团体证书Job
|
||||
class GenerateCompetitionTeamCertificateJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(competition_team_id)
|
||||
@team = CompetitionTeam.find_by(id: competition_team_id)
|
||||
@prize = @team&.competition_prize_users&.first&.competition_prize
|
||||
return if @team.blank? || !@prize.team_certificate_exists? || @team.certificate_exists?
|
||||
|
||||
members = @team.team_members.includes(user: :user_extension).to_a
|
||||
|
||||
@member_names = members.select { |m| !m.user.is_teacher? }.map(&:user_name).join('、')
|
||||
@teacher_names = members.select { |m| m.user.is_teacher? }.map(&:user_name).join('、')
|
||||
|
||||
file = File.open(Rails.root.join("app/templates/competition_certificates/team.html.erb"))
|
||||
html = ERB.new(file.read).result(binding)
|
||||
kit = PDFKit.new(html, page_width: 842, page_height: 595)
|
||||
|
||||
path = @team.certificate_path
|
||||
dir = File.dirname(path)
|
||||
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
||||
kit.to_pdf(path)
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="competition-certificate" style="position: absolute;font-size: 85px;font-family: SimSun;">
|
||||
<img src="<%= ApplicationController.helpers.download_image(@prize_user.competition_prize.teacher_certificate_path) %>"/>
|
||||
<div class="competition-certificate-body" style="position: absolute;width: 82%;top: 35%;left: 9%;">
|
||||
<p><%= @prize_user.user.school_name %> <%= @prize_user.user.real_name %> 老师:</p>
|
||||
<p style="text-indent:2em;line-height: 1.8;margin-bottom: 0px;">
|
||||
在第二届“<b>全国高校绿色计算大赛</b>”(<%= @prize_user.competition.sub_title %>)中,带领学生团队 表现突出,成绩优异,荣获“<b>优秀指导教师</b>”称号。
|
||||
</p>
|
||||
<p style="text-indent:2em;line-height: 1.8;margin-top: 0px;">特发此证,以资鼓励。</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in new issue