Commit b2f9a0d5 by liangyuzhe

add custom_field_template to import

parent 50e6fd68
......@@ -4,6 +4,7 @@ module CrmJavaSearch
def initialize(user:, entity:, params:)
params = params.with_indifferent_access
Log.logger.info("crm_java_search es initialize params #{params.to_json}")
@user = user
@entity = entity
......@@ -13,6 +14,8 @@ module CrmJavaSearch
@exclude_ids = params["exclude_ids"].compact || []
@exclude_ids.push(@entity.id) if @entity && @entity.id
@id_source = params["id_source"] || ''
@custom_field_template_id = params["custom_field_template_id"]
@no_custom_field_template = -1
end
def es_check(klass)
......@@ -46,14 +49,64 @@ module CrmJavaSearch
if @res["data"]['repeat'] && @res["data"]['entities'].present?
@res["data"]['entities'].select{ |entity_hash|
return duplicate_in_owns(entity_hash['cross_fields']) if entity_hash['user_id'].to_i == @user.id
duplicate_in_org(entity_hash['cross_fields'])
Log.logger.info("crm_java_search es entity_hash is #{entity_hash.to_json}")
if klass.name == 'Customer' && @custom_field_template_id.present? && @organization.customers.find(entity_hash['id'].to_i).custom_field_template_id == @custom_field_template_id.to_i && check_by_custom_field_template
Log.logger.info("crm_java_search es 客户业务模板内查重")
#TODO 客户业务模板内查重
check_in_custom_field_template
elsif klass.name == 'Customer' && @organization.customers.find(entity_hash['id'].to_i).custom_field_template_id.blank? && check_by_custom_field_template
Log.logger.info("crm_java_search es 客户无业务模板,查重以前数据")
#TODO 客户无业务模板,查重以前数据
check_in_no_custom_field_template
elsif klass.name == 'Contact' && @custom_field_template_id.present? && @organization.contacts.find(entity_hash['id'].to_i).customer.custom_field_template_id == @custom_field_template_id.to_i && check_by_custom_field_template
Log.logger.info("crm_java_search es 联系人业务模板内查重")
#TODO 联系人业务模板内查重
check_in_custom_field_template
elsif klass.name == 'Contact' && @organization.contacts.find(entity_hash['id'].to_i).customer.custom_field_template_id.blank? && check_by_custom_field_template
Log.logger.info("crm_java_search es 联系人无业务模板,查重以前数据")
#TODO 联系人无业务模板,查重以前数据
check_in_no_custom_field_template
elsif (@organization.settings(:customer_duplicate_scope_config).type == 'all') || (%w(Contact Customer).exclude? klass.name)
duplicate_in_owns_or_org(entity_hash)
else
no_duplicates
end
}
else
no_duplicates
end
end
def check_in_custom_field_template
if @organization.settings(:customer_duplicate_scope_config).custom_template_scopes.include? @custom_field_template_id.to_s
return duplicate_in_custom_template
else
return no_duplicate_in_custom_template
end
end
def check_in_no_custom_field_template
if @organization.settings(:customer_duplicate_scope_config).custom_template_scopes.include? @no_custom_field_template.to_s
return duplicate_in_no_custom_template
else
return no_duplicate_in_no_custom_template
end
end
def check_by_custom_field_template
!!(@organization.settings(:customer_duplicate_scope_config).type == 'by_custom_template')
end
def duplicate_in_owns_or_org(entity_hash)
return duplicate_in_owns(entity_hash['cross_fields']) if entity_hash['user_id'].to_i == @user.id
duplicate_in_org(entity_hash['cross_fields'])
end
def cross_field_from_setting
RelationDuplicate::RelationService.new(@organization).send("#{@entity.class.name.underscore}_cross")[@custom_field.name]
end
......@@ -82,6 +135,30 @@ module CrmJavaSearch
@remark = "未发现相同#{@field_label}#{@model_human_name}"
end
def duplicate_in_no_custom_template
@code = "1"
@remark = "你已经有相同#{@field_label}#{@model_human_name}在无业务模板里面"
@duplicated = true
end
def no_duplicate_in_no_custom_template
@code = "0"
@remark = "未发现相同#{@field_label}#{@model_human_name}在无业务模板里面"
@duplicated = false
end
def no_duplicate_in_custom_template
@code = "0"
@remark = "未发现相同#{@field_label}#{@model_human_name}在业务模板里面"
@duplicated = false
end
def duplicate_in_custom_template
@code = "1"
@remark = "你已经有相同#{@field_label}#{@model_human_name}在业务模板里面"
@duplicated = true
end
def duplicate_in_owns(cross_field=nil)
@code = "1"
if cross_field.present?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment