Skip to content

Commit 0ab1c02

Browse files
committed
🔧🔧🔧 ticket_importer
1 parent ddc68a4 commit 0ab1c02

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

ticket_importer.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def start_import
2424
else
2525
ActiveRecord::Base.transaction do
2626
begin
27-
is_valid, value = check_valid(row)
27+
is_valid, value = check_valid(row)
2828
if is_valid
2929
attributes = value
3030
column = column(row)
@@ -39,7 +39,7 @@ def start_import
3939
platform_id: Platform.manual_input.id,
4040
source_channel: 'manual',
4141
owner_group_id: group_id)
42-
customer.update!(cellphone: column.c_email) if customer.id.present? && column.c_email.present?
42+
customer.update!(cellphone: column.c_cellphone) if customer.id.present? && column.c_cellphone.present?
4343
attributes.merge!({user_id: customer.id})
4444
end
4545
ticket = Ticket.new(attributes)
@@ -56,7 +56,6 @@ def start_import
5656
@record.update!(failure_count: @unsuccessful_data.size, treated_count: row_num - 1)
5757
end
5858
save_unsuccessful_data_to_file
59-
Sidekiq.logger.info "==================#{@unsuccessful_data}"
6059
@record.update!(completed: true)
6160
end
6261

@@ -156,14 +155,13 @@ def check_valid(row)
156155
end
157156

158157
def validate_email_cellphone(email, cellphone)
159-
customer_a_id = nil
160-
customer_b_id = nil
158+
customer_a_id, customer_b_id = nil, nil
161159
if email.present?
162160
return [false, "邮件格式错误"] unless email =~ EMAIL_REGEXP
163161
customer_a_id = @company.customers.find_in_emails(email).try(:id)
164162
end
165163
if cellphone.present?
166-
return [false, "电话号码格式错误"] unless PhoneNumber.new(cellphone).valid?
164+
return [false, "电话号码格式错误"] unless ::PhoneNumber.new(cellphone).valid?
167165
customer_b_id = @company.customers.find_in_cellphones(cellphone).try(:id)
168166
end
169167
if customer_a_id && customer_b_id
@@ -185,6 +183,7 @@ def validate_agent_and_owner_group(group_name, agent_email)
185183
unless @company.user_groups.where(name: group_name).exists?
186184
return [false, "受理客服组不存在"]
187185
end
186+
user_group_id = @company.user_groups.find_by(name: group_name).try(:id)
188187
end
189188
if agent_email.present? && group_name.present?
190189
user_id = @company.agents.find_by(email: agent_email).try(:id)
@@ -235,7 +234,7 @@ def validate_custom_fields(template_name, row)
235234
import_fields.each_with_index do |custom_field, i|
236235
title = custom_field.first
237236
field = custom_field.last
238-
_index = field[:index] # field.index is not right
237+
_index = field[:index]
239238
column = row[_index]
240239
return [false, "#{title}为必填字段"] if field.is_require && column.blank?
241240
if field && column.present?
@@ -290,7 +289,7 @@ def get_index_value(values, options)
290289
indexes.join(",")
291290
end
292291

293-
# 根据头部的命名,得到普通字段和列索引之间的map关系,用一个hash存储
292+
# 根据头部的命名,得到普通字段和excel列索引之间的map关系,用一个hash存储
294293
def column_map
295294
column_hash = Hashie::Mash.new
296295
@head_data.each_with_index do |head, index|

0 commit comments

Comments
 (0)