質問編集履歴
4
コード変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,62 +14,69 @@
|
|
14
14
|
def self.generate_mask_insurance_zip_file
|
15
15
|
ActiveRecord::Base.transaction do
|
16
16
|
SendMaskInsuranceFile.where(created_at: Time.current.yesterday..Time.current).each do |send_mask_insurance_file|
|
17
|
-
|
17
|
+
Tempfile.create(["#{Time.current.to_i}", ".zip"], Rails.root.join('tmp')) do |zip_tempfile|
|
18
|
-
Zip::File.open(zip_tempfile.path, Zip::File::CREATE) do |zipfile|
|
18
|
+
Zip::File.open(zip_tempfile.path, Zip::File::CREATE) do |zipfile|
|
19
|
-
URI.open(send_mask_insurance_file.csv_url.
|
19
|
+
URI.open(send_mask_insurance_file.csv_url.path) do |f|
|
20
|
-
csv = CSV.new(f, headers: :first_row)
|
20
|
+
csv = CSV.new(f, headers: :first_row)
|
21
|
-
csv.each do |row|
|
21
|
+
csv.each do |row|
|
22
|
-
staff_master = StaffMaster.find_by(id: row[5])
|
22
|
+
staff_master = StaffMaster.find_by(id: row[5])
|
23
|
-
employment_file = staff_master.original_insurance_files.where(file_type: :social).order(id: :desc).first
|
23
|
+
employment_file = staff_master.original_insurance_files.where(file_type: :social).order(id: :desc).first
|
24
|
-
social_file = staff_master.original_insurance_files.where(file_type: :employment).order(id: :desc).first
|
24
|
+
social_file = staff_master.original_insurance_files.where(file_type: :employment).order(id: :desc).first
|
25
|
-
if staff_master
|
25
|
+
if staff_master
|
26
|
-
pdf_string = WickedPdf.new.pdf_from_string(
|
26
|
+
pdf_string = WickedPdf.new.pdf_from_string(
|
27
|
-
ActionController::Base.new().render_to_string(
|
27
|
+
ActionController::Base.new().render_to_string(
|
28
|
-
template: '/admins/send_mask_insurance_files/sended.pdf.slim',
|
28
|
+
template: '/admins/send_mask_insurance_files/sended.pdf.slim',
|
29
|
-
layout: 'layouts/pdf.pdf.slim',
|
29
|
+
layout: 'layouts/pdf.pdf.slim',
|
30
|
-
encoding: 'utf-8',
|
30
|
+
encoding: 'utf-8',
|
31
|
-
locals: {
|
31
|
+
locals: {
|
32
|
-
postal_code: row[3],
|
32
|
+
postal_code: row[3],
|
33
|
-
address: row[4],
|
33
|
+
address: row[4],
|
34
|
-
company_name: row[2],
|
34
|
+
company_name: row[2],
|
35
|
-
department_name: row[1],
|
35
|
+
department_name: row[1],
|
36
|
-
employment_file: employment_file.blank? ? nil : embed_remote_image(employment_file.url.
|
36
|
+
employment_file: employment_file.blank? ? nil : embed_remote_image(employment_file.url.path, 'image/jpeg'),
|
37
|
-
social_file: social_file.blank? ? nil : embed_remote_image(social_file.url.
|
37
|
+
social_file: social_file.blank? ? nil : embed_remote_image(social_file.url.path, 'image/jpeg'),
|
38
|
-
}
|
38
|
+
}
|
39
|
-
)
|
39
|
+
)
|
40
|
-
).force_encoding("UTF-8")
|
40
|
+
).force_encoding("UTF-8")
|
41
41
|
|
42
|
-
|
42
|
+
Tempfile.create(["#{staff_master.id}-#{Time.current.to_i}", ".pdf"], Rails.root.join('tmp')) do |mask_insurance_tempfile|
|
43
|
-
mask_insurance_tempfile.binmode
|
44
|
-
mask_insurance_tempfile.write pdf_string
|
43
|
+
mask_insurance_tempfile.write pdf_string
|
45
|
-
|
46
|
-
zipfile.add(File.basename(mask_insurance_tempfile.path), mask_insurance_tempfile.path)
|
44
|
+
zipfile.add(File.basename(mask_insurance_tempfile.path), mask_insurance_tempfile.path)
|
47
|
-
|
45
|
+
end
|
46
|
+
end
|
48
47
|
end
|
49
48
|
end
|
50
49
|
end
|
50
|
+
send_mask_insurance_file.update!(zip_url: zip_tempfile)
|
51
51
|
end
|
52
|
-
send_mask_insurance_file.update!(zip_url: zip_tempfile)
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
56
|
def self.embed_remote_image(url, content_type)
|
58
|
-
asset = URI.open(url, "r:UTF-8", &:read)
|
57
|
+
asset = URI.open(url, "r:UTF-8", &:read)
|
59
58
|
base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
|
60
59
|
"data:#{content_type};base64,#{Rack::Utils.escape(base64)}"
|
61
60
|
end
|
62
61
|
end
|
63
62
|
```
|
63
|
+
### 実行コマンド
|
64
|
+
bundle exec rake cron:generate_mask_insurance_zip_file
|
64
65
|
|
65
66
|
### エラーメッセージ
|
66
67
|
```ここに言語を入力
|
68
|
+
[START] [{:generate_mask_insurance_zip_file=>:environment}] (2022/09/26 09:28)
|
69
|
+
[ERROR] No such file or directory @ rb_sysopen - /Users/●●/Dropbox/sites/app/tmp/02393164-166415211720220926-1793-w6nj56.pdf (2022/09/26 09:28)
|
70
|
+
rake aborted!
|
67
|
-
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/●●/Dropbox/sites/app/tmp/02393164-16641
|
71
|
+
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/●●/Dropbox/sites/app/tmp/02393164-166415211720220926-1793-w6nj56.pdf
|
68
|
-
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:11:in `block (
|
72
|
+
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:11:in `block (3 levels) in generate_mask_insurance_zip_file'
|
73
|
+
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:10:in `block (2 levels) in generate_mask_insurance_zip_file'
|
69
74
|
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:9:in `block in generate_mask_insurance_zip_file'
|
70
75
|
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:8:in `generate_mask_insurance_zip_file'
|
71
76
|
/Users/●●/Dropbox/sites/app/lib/tasks/cron.rake:98:in `block (2 levels) in <main>'
|
72
77
|
/Users/●●/Dropbox/sites/app/lib/tasks/cron.rake:7:in `block in task_with_logger_and_notify'
|
73
78
|
/Users/●●/.rbenv/versions/2.7.6/bin/bundle:23:in `load'
|
74
79
|
/Users/●●/.rbenv/versions/2.7.6/bin/bundle:23:in `<main>'
|
80
|
+
Tasks: TOP => cron:generate_mask_insurance_zip_file
|
81
|
+
(See full trace by running task with --trace)
|
75
82
|
```
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,7 +65,7 @@
|
|
65
65
|
### エラーメッセージ
|
66
66
|
```ここに言語を入力
|
67
67
|
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/●●/Dropbox/sites/app/tmp/02393164-166410115520220925-6791-ba6on1.pdf
|
68
|
-
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:1
|
68
|
+
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:11:in `block (2 levels) in generate_mask_insurance_zip_file'
|
69
69
|
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:9:in `block in generate_mask_insurance_zip_file'
|
70
70
|
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:8:in `generate_mask_insurance_zip_file'
|
71
71
|
/Users/●●/Dropbox/sites/app/lib/tasks/cron.rake:98:in `block (2 levels) in <main>'
|
2
エラーメッセージを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -61,3 +61,15 @@
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
```
|
64
|
+
|
65
|
+
### エラーメッセージ
|
66
|
+
```ここに言語を入力
|
67
|
+
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/●●/Dropbox/sites/app/tmp/02393164-166410115520220925-6791-ba6on1.pdf
|
68
|
+
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:10:in `block (2 levels) in generate_mask_insurance_zip_file'
|
69
|
+
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:9:in `block in generate_mask_insurance_zip_file'
|
70
|
+
/Users/●●/Dropbox/sites/app/app/models/send_mask_insurance_file.rb:8:in `generate_mask_insurance_zip_file'
|
71
|
+
/Users/●●/Dropbox/sites/app/lib/tasks/cron.rake:98:in `block (2 levels) in <main>'
|
72
|
+
/Users/●●/Dropbox/sites/app/lib/tasks/cron.rake:7:in `block in task_with_logger_and_notify'
|
73
|
+
/Users/●●/.rbenv/versions/2.7.6/bin/bundle:23:in `load'
|
74
|
+
/Users/●●/.rbenv/versions/2.7.6/bin/bundle:23:in `<main>'
|
75
|
+
```
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
URI.open(send_mask_insurance_file.csv_url.url) do |f|
|
20
20
|
csv = CSV.new(f, headers: :first_row)
|
21
21
|
csv.each do |row|
|
22
|
-
staff_master = StaffMaster.find_by(
|
22
|
+
staff_master = StaffMaster.find_by(id: row[5])
|
23
23
|
employment_file = staff_master.original_insurance_files.where(file_type: :social).order(id: :desc).first
|
24
24
|
social_file = staff_master.original_insurance_files.where(file_type: :employment).order(id: :desc).first
|
25
25
|
if staff_master
|
@@ -39,7 +39,7 @@
|
|
39
39
|
)
|
40
40
|
).force_encoding("UTF-8")
|
41
41
|
|
42
|
-
mask_insurance_tempfile = Tempfile.new(["#{staff_master.
|
42
|
+
mask_insurance_tempfile = Tempfile.new(["#{staff_master.id}-#{Time.current.to_i}", ".pdf"], Rails.root.join('tmp'))
|
43
43
|
mask_insurance_tempfile.binmode
|
44
44
|
mask_insurance_tempfile.write pdf_string
|
45
45
|
|