Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crm_java_search
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_server
crm_java_search
Commits
752f2ee6
Commit
752f2ee6
authored
Mar 22, 2019
by
dongfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add search setting
parent
1c78b240
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
302 additions
and
26 deletions
+302
-26
Gemfile.lock
+1
-1
lib/crm_java_search.rb
+4
-24
lib/crm_java_search/relation_duplicate/base_service.rb
+70
-0
lib/crm_java_search/relation_duplicate/contact_service.rb
+13
-0
lib/crm_java_search/relation_duplicate/customer_service.rb
+13
-0
lib/crm_java_search/relation_duplicate/lead_service.rb
+13
-0
lib/crm_java_search/relation_duplicate/relation_service.rb
+187
-0
lib/crm_java_search/version.rb
+1
-1
No files found.
Gemfile.lock
View file @
752f2ee6
PATH
PATH
remote: .
remote: .
specs:
specs:
crm_java_search (0.
3.2
)
crm_java_search (0.
1.3
)
GEM
GEM
remote: https://rubygems.org/
remote: https://rubygems.org/
...
...
lib/crm_java_search.rb
View file @
752f2ee6
require
'crm_java_search/version'
Dir
[
File
.
dirname
(
__FILE__
)
+
'/crm_java_search/**/*.rb'
].
sort
.
each
do
|
path
|
require
'crm_java_search/config'
require
path
require
'crm_java_search/app'
end
require
'crm_java_search/log'
\ No newline at end of file
Dir
[
File
.
dirname
(
__FILE__
)
+
'/crm_java_search/trans/*.rb'
].
sort
.
each
do
|
path
|
filename
=
File
.
basename
(
path
)
require
"crm_java_search/trans/
#{
filename
}
"
end
Dir
[
File
.
dirname
(
__FILE__
)
+
'/crm_java_search/searchers/*.rb'
].
sort
.
each
do
|
path
|
filename
=
File
.
basename
(
path
)
require
"crm_java_search/searchers/
#{
filename
}
"
end
Dir
[
File
.
dirname
(
__FILE__
)
+
'/crm_java_search/checkers/*.rb'
].
sort
.
each
do
|
path
|
filename
=
File
.
basename
(
path
)
require
"crm_java_search/checkers/
#{
filename
}
"
end
Dir
[
File
.
dirname
(
__FILE__
)
+
'/crm_java_search/agents/*.rb'
].
sort
.
each
do
|
path
|
filename
=
File
.
basename
(
path
)
require
"crm_java_search/agents/
#{
filename
}
"
end
lib/crm_java_search/relation_duplicate/base_service.rb
0 → 100644
View file @
752f2ee6
module
CrmJavaSearch
module
RelationDuplicate
class
BaseService
attr_reader
:organization
attr_accessor
:cross
# 子类必须实现duplicate_field_config 方法
# 子类名称必须是实体类名加Service
def
initialize
(
organization
)
@organization
=
organization
@cross
=
false
end
def
system_duplicate_fields
enable_system_custom_fields
=
system_custom_fields
.
select
do
|
column
|
system_duplicate_fields_search
.
include?
(
column
[
:name
])
end
enable_system_custom_fields
.
map
do
|
column
|
confirm_duplicate_field
(
column
)
end
end
def
custom_duplicate_fields
organization
.
allow_duplicate_user_custom_fields
(
entity_model_klass
).
map
do
|
column
|
confirm_duplicate_field
(
column
)
end
end
def
duplicate_fields
system_duplicate_fields
+
custom_duplicate_fields
end
def
cross_fields
duplicate_fields
.
map
do
|
field
|
if
field
[
:checked
]
field
.
delete
(
:checked
)
field
end
end
.
compact
end
private
def
confirm_duplicate_field
(
column
)
if
cross
cross_duplicate_fields_hash
(
column
)
else
duplicate_fields_hash
(
column
)
end
end
def
duplicate_fields_hash
(
column
)
name
=
column
[
:name
].
start_with?
(
'address.'
)
?
column
[:
name
].
split
(
'.'
).
last
:
column
[
:name
]
{
name:
name
,
label:
column
[
:label
],
checked:
duplicate_field_config
.
send
(
name
).
eql?
(
'1'
)
}
end
def
cross_duplicate_fields_hash
(
column
)
name
=
column
[
:name
].
start_with?
(
'address.'
)
?
column
[:
name
].
split
(
'.'
).
last
:
column
[
:name
]
{
name:
column
[
:name
],
label:
column
[
:label
],
checked:
duplicate_field_config
.
send
(
name
).
eql?
(
'1'
)
}
end
def
system_custom_fields
@system_custom_fields
||=
entity_model_klass
.
cache_enabled_custom_fields_by_organization
(
organization
.
id
)
end
def
entity_model_klass
self
.
class
.
name
.
demodulize
.
gsub
(
'Service'
,
''
).
constantize
end
end
end
end
lib/crm_java_search/relation_duplicate/contact_service.rb
0 → 100644
View file @
752f2ee6
module
CrmJavaSearch
module
RelationDuplicate
class
ContactService
<
BaseService
def
system_duplicate_fields_search
@system_duplicate_fields_search
||=
Organization
.
contact_duplicate_field_custom_field_map
.
values
end
def
duplicate_field_config
organization
.
settings
(
:contact_duplicate_field_config
)
end
end
end
end
lib/crm_java_search/relation_duplicate/customer_service.rb
0 → 100644
View file @
752f2ee6
module
CrmJavaSearch
module
RelationDuplicate
class
CustomerService
<
BaseService
def
system_duplicate_fields_search
@system_duplicate_fields_search
||=
Organization
.
customer_duplicate_field_custom_field_map
.
values
end
def
duplicate_field_config
organization
.
settings
(
:customer_duplicate_field_config
)
end
end
end
end
lib/crm_java_search/relation_duplicate/lead_service.rb
0 → 100644
View file @
752f2ee6
module
CrmJavaSearch
module
RelationDuplicate
class
LeadService
<
BaseService
def
system_duplicate_fields_search
@system_duplicate_fields_search
||=
Organization
.
lead_duplicate_field_custom_field_map
.
values
end
def
duplicate_field_config
organization
.
settings
(
:lead_duplicate_field_config
)
end
end
end
end
lib/crm_java_search/relation_duplicate/relation_service.rb
0 → 100644
View file @
752f2ee6
module
CrmJavaSearch
module
RelationDuplicate
class
RelationService
attr_reader
:lead_service
,
:contact_service
,
:customer_service
,
:organization
,
:lead_cross_fields
,
:customer_cross_fields
,
:contact_cross_fields
def
initialize
(
organization
)
@organization
=
organization
@lead_service
=
LeadService
.
new
(
organization
)
@contact_service
=
ContactService
.
new
(
organization
)
@customer_service
=
CustomerService
.
new
(
organization
)
@lead_cross_fields
=
nil
@customer_cross_fields
=
nil
@contact_cross_fields
=
nil
end
def
lead_correlation
{
customer:
duplicate_fields_intersections
(
lead_service
.
duplicate_fields
,
customer_service
.
duplicate_fields
),
contact:
duplicate_fields_intersections
(
lead_service
.
duplicate_fields
,
contact_service
.
duplicate_fields
)
}
end
def
contact_correlation
{
customer:
duplicate_fields_intersections
(
contact_service
.
duplicate_fields
,
customer_service
.
duplicate_fields
),
lead:
duplicate_fields_intersections
(
contact_service
.
duplicate_fields
,
lead_service
.
duplicate_fields
)
}
end
def
customer_correlation
{
lead:
duplicate_fields_intersections
(
customer_service
.
duplicate_fields
,
lead_service
.
duplicate_fields
),
contact:
duplicate_fields_intersections
(
customer_service
.
duplicate_fields
,
contact_service
.
duplicate_fields
)
}
end
def
lead_cross
cross
=
ActiveSupport
::
HashWithIndifferentAccess
.
new
if
lead_cross_enable?
cross_fields_data_prepare
if
cross_lead_customer?
lead_cross_fields
.
each
do
|
field
|
customer_field
=
if
field
[
:name
]
==
'company_name'
customer_cross_fields
.
find
{
|
c_field
|
c_field
[
:name
]
==
'name'
}
else
customer_cross_fields
.
find
{
|
c_field
|
c_field
[
:label
]
==
field
[
:label
]
}
end
cross
[
field
[
:name
]]
||=
{}
cross
[
field
[
:name
]][
:customer
]
=
customer_field
[
:name
]
if
customer_field
end
end
cross
.
deep_merge!
(
cross_fields_hash
(
lead_cross_fields
,
contact_cross_fields
,
:contact
))
if
cross_lead_contact?
cross
=
unenable_cross_duplicate
(
lead_cross_fields
)
if
!
cross_lead_contact?
&&
!
cross_lead_customer?
end
Log
.
logger
.
info
(
"lead_cross:
#{
cross
}
"
)
cross
end
def
customer_cross
cross
=
HashWithIndifferentAccess
.
new
if
customer_cross_enable?
cross_fields_data_prepare
if
cross_customer_lead?
customer_cross_fields
.
each
do
|
field
|
lead_field
=
case
field
[
:name
]
when
'name'
lead_cross_fields
.
find
{
|
c_field
|
c_field
[
:name
]
==
'company_name'
}
when
'company_name'
nil
else
lead_cross_fields
.
find
{
|
c_field
|
c_field
[
:label
]
==
field
[
:label
]
}
end
cross
[
field
[
:name
]]
||=
{}
cross
[
field
[
:name
]][
:lead
]
=
lead_field
[
:name
]
if
lead_field
end
end
cross
.
deep_merge!
(
cross_fields_hash
(
customer_cross_fields
,
contact_cross_fields
,
:contact
))
if
cross_customer_contact?
cross
=
unenable_cross_duplicate
(
customer_cross_fields
)
if
!
cross_customer_contact?
&&
!
cross_customer_lead?
end
Log
.
logger
.
info
(
"customer_cross:
#{
cross
}
"
)
cross
end
def
contact_cross
cross
=
{}
if
lead_cross_enable?
cross_fields_data_prepare
cross
=
cross_fields_hash
(
contact_cross_fields
,
lead_cross_fields
,
:lead
)
if
cross_contact_lead?
cross
.
deep_merge!
(
cross_fields_hash
(
contact_cross_fields
,
customer_cross_fields
,
:customer
))
if
cross_contact_customer?
cross
=
unenable_cross_duplicate
(
contact_cross_fields
)
if
!
cross_contact_customer?
&&
!
cross_contact_lead?
end
Log
.
logger
.
info
(
"contact_cross:
#{
cross
}
"
)
cross
end
private
def
unenable_cross_duplicate
(
fields
)
cross
=
HashWithIndifferentAccess
.
new
fields
.
each
do
|
field
|
cross
[
field
[
:name
]]
=
{}
end
cross
end
def
cross_fields_hash
(
cross_fields1
,
cross_fields2
,
flag
)
cross
=
HashWithIndifferentAccess
.
new
cross_fields1
.
each
do
|
field
|
target_field
=
cross_fields2
.
find
{
|
c_field
|
c_field
[
:label
]
==
field
[
:label
]
}
cross
[
field
[
:name
]]
||=
{}
cross
[
field
[
:name
]][
flag
]
=
target_field
[
:name
]
if
target_field
end
cross
end
def
cross_fields_data_prepare
lead_service
.
cross
=
true
contact_service
.
cross
=
true
customer_service
.
cross
=
true
@lead_cross_fields
=
lead_service
.
cross_fields
@customer_cross_fields
=
customer_service
.
cross_fields
@contact_cross_fields
=
contact_service
.
cross_fields
end
# 线索关联查重相关
def
lead_cross_enable?
cross_setting
.
lead
[
:enabled
].
eql?
(
'1'
)
end
def
cross_lead_customer?
cross_setting
.
lead
[
:customer_also
].
eql?
(
'1'
)
end
def
cross_lead_contact?
cross_setting
.
lead
[
:contact_also
].
eql?
(
'1'
)
end
# 客户关联查重相关
def
customer_cross_enable?
cross_setting
.
customer
[
:enabled
].
eql?
(
'1'
)
end
def
cross_customer_lead?
cross_setting
.
customer
[
:lead_also
].
eql?
(
'1'
)
end
def
cross_customer_contact?
cross_setting
.
customer
[
:contact_also
].
eql?
(
'1'
)
end
# 联系人关联查重相关
def
contact_cross_enable?
cross_setting
.
contact
[
:enabled
].
eql?
(
'1'
)
end
def
cross_contact_lead?
cross_setting
.
contact
[
:lead_also
].
eql?
(
'1'
)
end
def
cross_contact_customer?
cross_setting
.
contact
[
:customer_also
].
eql?
(
'1'
)
end
def
cross_setting
organization
.
settings
(
:check_duplicate_config
)
end
def
duplicate_fields_intersections
(
fields_set1
,
fields_set2
)
fields_set1
.
select
do
|
field1
|
field1
[
:checked
]
&&
fields_set2
.
any?
{
|
field2
|
field2
[
:checked
]
&&
field1
[
:field_type
].
eql?
(
field2
[
:field_type
])
&&
field1
[
:label
].
eql?
(
field2
[
:label
])
}
end
end
end
end
end
lib/crm_java_search/version.rb
View file @
752f2ee6
module
CrmJavaSearch
module
CrmJavaSearch
VERSION
=
"0.3.2"
VERSION
=
'0.3.4'
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment