Commit 7abc85bb by dongfeng

初步完成

parent 7d4dbe07
...@@ -6,12 +6,25 @@ PATH ...@@ -6,12 +6,25 @@ PATH
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
activesupport (5.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
concurrent-ruby (1.1.5)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
rake (10.4.2) rake (10.4.2)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
PLATFORMS PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
activesupport (~> 5.2)
bundler (~> 1.16) bundler (~> 1.16)
crm_java_search! crm_java_search!
rake (~> 10.0) rake (~> 10.0)
......
...@@ -34,6 +34,7 @@ Gem::Specification.new do |spec| ...@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib'] spec.require_paths = ['lib']
spec.add_development_dependency 'activesupport', '~> 5.2'
spec.add_development_dependency 'bundler', '~> 1.16' spec.add_development_dependency 'bundler', '~> 1.16'
spec.add_development_dependency 'rake', '~> 10.0' spec.add_development_dependency 'rake', '~> 10.0'
end end
module CrmJavaSearch
module Agents
class ContractAgent < BaseAgent
def url
Trans::Router.sync_url(:contract)
end
end
end
end
require 'active_support/core_ext/object/blank'
module CrmJavaSearch module CrmJavaSearch
class App class App
def self.server def self.server
...@@ -5,7 +6,7 @@ module CrmJavaSearch ...@@ -5,7 +6,7 @@ module CrmJavaSearch
end end
def self.use_java_es? def self.use_java_es?
!server.empty? && !server[:host].to_s.empty? && server[:enabled] == true server.present? && server[:host].present? && server[:enabled]
end end
def self.api_base_url def self.api_base_url
......
...@@ -15,16 +15,25 @@ module CrmJavaSearch ...@@ -15,16 +15,25 @@ module CrmJavaSearch
def check_duplicate_custom_fields(tail = false, &_proc) def check_duplicate_custom_fields(tail = false, &_proc)
return unless organization.duplicate_check_enabled?(key: @klass.underscore) return unless organization.duplicate_check_enabled?(key: @klass.underscore)
Log.logger.info("Checkers::ApiCheckService @klass: #{@klass}")
organization.send("#{@klass.underscore}_duplicate_custom_fields").each do |custom_field| organization.send("#{@klass.underscore}_duplicate_custom_fields").each do |custom_field|
Log.logger.info("Checkers::ApiCheckService custom_field: #{custom_field.inspect}")
raw_field_value = custom_field.raw_field_value_from(record) raw_field_value = custom_field.raw_field_value_from(record)
field = organization.send("#{@klass.underscore}_duplicate_field_custom_field_map").invert[custom_field.name] field = organization.send("#{@klass.underscore}_duplicate_field_custom_field_map").invert[custom_field.name]
Log.logger.info("Checkers::ApiCheckService raw_field_value: #{raw_field_value.inspect}")
Log.logger.info("Checkers::ApiCheckService field: #{field.inspect}")
next if field.blank? || raw_field_value.blank? next if field.blank? || raw_field_value.blank?
dup_params = {field: field, field_value: raw_field_value, exclude_ids: exclude_ids, id_source: id_source }.stringify_keys dup_params = {field: field, field_value: raw_field_value, exclude_ids: exclude_ids, id_source: id_source }.stringify_keys
Log.logger.info("Checkers::ApiCheckService dup_params: #{dup_params}")
checker = "CrmJavaSearch::Checkers::#{@klass}Checker".constantize.new(user: user, entity: record, params: dup_params) checker = "CrmJavaSearch::Checkers::#{@klass}Checker".constantize.new(user: user, entity: record, params: dup_params)
checker.check checker.check
Log.logger.info("Checkers::ApiCheckService checker: #{checker.inspect}")
if ['1', '2'].include?(checker.result[:code]) if ['1', '2'].include?(checker.result[:code])
message = checker.result[:remark] message = checker.result[:remark]
......
...@@ -12,7 +12,6 @@ module CrmJavaSearch ...@@ -12,7 +12,6 @@ module CrmJavaSearch
@field_value = params["field_value"] @field_value = params["field_value"]
@exclude_ids = params["exclude_ids"].compact || [] @exclude_ids = params["exclude_ids"].compact || []
@exclude_ids.push(@entity.id) if @entity && @entity.id @exclude_ids.push(@entity.id) if @entity && @entity.id
@logger_helper = LoggerHelper.new(@organization)
@id_source = params["id_source"] || '' @id_source = params["id_source"] || ''
end end
...@@ -38,9 +37,9 @@ module CrmJavaSearch ...@@ -38,9 +37,9 @@ module CrmJavaSearch
def check_service(klass) def check_service(klass)
es_query = {@custom_field.name => @field_value, "exclude_ids" => @exclude_ids, "cross_fields" => @cross_fields, "id_source" => @id_source} es_query = {@custom_field.name => @field_value, "exclude_ids" => @exclude_ids, "cross_fields" => @cross_fields, "id_source" => @id_source}
@logger_helper.info("microservices es request params es_query: #{es_query} ") Log.logger.info("crm_java_search es request params es_query: #{es_query} ")
@res = CrmJavaSearch::Agents.const_get("#{klass.name}Agent").repeat_check(@organization.id, es_query) @res = CrmJavaSearch::Agents.const_get("#{klass.name}Agent").repeat_check(klass.name.underscore, @organization.id, es_query)
@logger_helper.info("microservices es response #{@res}") Log.logger.info("crm_java_search es response #{@res}")
return unknown_error unless [0, 500, 502].include? @res['code'].to_i return unknown_error unless [0, 500, 502].include? @res['code'].to_i
return system_error if @res['code'].to_i == 500 return system_error if @res['code'].to_i == 500
return parameter_error if @res['code'].to_i == 502 return parameter_error if @res['code'].to_i == 502
......
module CrmJavaSearch
module Checkers
class ContractChecker < BaseChecker
def check
es_check(Contract)
end
end
end
end
require 'active_support/hash_with_indifferent_access'
module CrmJavaSearch module CrmJavaSearch
module Config module Config
class << self class << self
def init(opts = {}) def init(opts = {})
@settings = opts || default_settings @settings = opts.with_indifferent_access || default_settings
end end
def default_settings def default_settings
...@@ -12,7 +13,7 @@ module CrmJavaSearch ...@@ -12,7 +13,7 @@ module CrmJavaSearch
check_enabled: true, check_enabled: true,
sync_enabled: true, sync_enabled: true,
host: 'http://dev-pc-search.ikcrm.com' host: 'http://dev-pc-search.ikcrm.com'
} }.with_indifferent_access
end end
def settings def settings
......
module CrmJavaSearch
module Searchers
class ContractSearcher < BaseSearcher
def search
data = Agents::ContractAgent.repeat_search(:contract, @organization.id, @es_query)["data"]
if data
Contract.where(organization_id: @organization.id).where(id: data.map{|datai| datai['id']})
else
Contract.none
end
end
end
end
end
module CrmJavaSearch module CrmJavaSearch
module Searchers module Searchers
class CustomerSearcher < BaseSearcher class CustomerSearcher < BaseSearcher
def search def search
data = Agents::CustomerAgent.repeat_search(:customer, @organization.id, @es_query)["data"] data = Agents::CustomerAgent.repeat_search(:customer, @organization.id, @es_query)["data"]
if data if data
...@@ -10,7 +9,6 @@ module CrmJavaSearch ...@@ -10,7 +9,6 @@ module CrmJavaSearch
Customer.none Customer.none
end end
end end
end end
end end
end end
...@@ -2,9 +2,8 @@ module CrmJavaSearch ...@@ -2,9 +2,8 @@ module CrmJavaSearch
module Searchers module Searchers
class LeadSearcher < BaseSearcher class LeadSearcher < BaseSearcher
def search def search
repeat_search_data = Agents::LeadAgent.repeat_search(:lead, @organization.id, @es_query) data = Agents::LeadAgent.repeat_search(:lead, @organization.id, @es_query)["data"]
Log.logger.info("repeat_search_data: #{repeat_search_data}") if data
if repeat_search_data['data']
Lead.where(organization_id: @organization.id).where(id: data.map{|datai| datai['id']}) Lead.where(organization_id: @organization.id).where(id: data.map{|datai| datai['id']})
else else
Lead.none Lead.none
......
module CrmJavaSearch module CrmJavaSearch
VERSION = "0.1.3" VERSION = "0.2"
end end
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