Commit 7abc85bb by dongfeng

初步完成

parent 7d4dbe07
......@@ -6,12 +6,25 @@ PATH
GEM
remote: https://rubygems.org/
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)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
activesupport (~> 5.2)
bundler (~> 1.16)
crm_java_search!
rake (~> 10.0)
......
......@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.add_development_dependency 'activesupport', '~> 5.2'
spec.add_development_dependency 'bundler', '~> 1.16'
spec.add_development_dependency 'rake', '~> 10.0'
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
class App
def self.server
......@@ -5,7 +6,7 @@ module CrmJavaSearch
end
def self.use_java_es?
!server.empty? && !server[:host].to_s.empty? && server[:enabled] == true
server.present? && server[:host].present? && server[:enabled]
end
def self.api_base_url
......
......@@ -15,16 +15,25 @@ module CrmJavaSearch
def check_duplicate_custom_fields(tail = false, &_proc)
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|
Log.logger.info("Checkers::ApiCheckService custom_field: #{custom_field.inspect}")
raw_field_value = custom_field.raw_field_value_from(record)
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?
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.check
Log.logger.info("Checkers::ApiCheckService checker: #{checker.inspect}")
if ['1', '2'].include?(checker.result[:code])
message = checker.result[:remark]
......
......@@ -12,7 +12,6 @@ module CrmJavaSearch
@field_value = params["field_value"]
@exclude_ids = params["exclude_ids"].compact || []
@exclude_ids.push(@entity.id) if @entity && @entity.id
@logger_helper = LoggerHelper.new(@organization)
@id_source = params["id_source"] || ''
end
......@@ -38,9 +37,9 @@ module CrmJavaSearch
def check_service(klass)
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} ")
@res = CrmJavaSearch::Agents.const_get("#{klass.name}Agent").repeat_check(@organization.id, es_query)
@logger_helper.info("microservices es response #{@res}")
Log.logger.info("crm_java_search es request params es_query: #{es_query} ")
@res = CrmJavaSearch::Agents.const_get("#{klass.name}Agent").repeat_check(klass.name.underscore, @organization.id, es_query)
Log.logger.info("crm_java_search es response #{@res}")
return unknown_error unless [0, 500, 502].include? @res['code'].to_i
return system_error if @res['code'].to_i == 500
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 Config
class << self
def init(opts = {})
@settings = opts || default_settings
@settings = opts.with_indifferent_access || default_settings
end
def default_settings
......@@ -12,7 +13,7 @@ module CrmJavaSearch
check_enabled: true,
sync_enabled: true,
host: 'http://dev-pc-search.ikcrm.com'
}
}.with_indifferent_access
end
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 Searchers
class CustomerSearcher < BaseSearcher
def search
data = Agents::CustomerAgent.repeat_search(:customer, @organization.id, @es_query)["data"]
if data
......@@ -10,7 +9,6 @@ module CrmJavaSearch
Customer.none
end
end
end
end
end
......@@ -2,9 +2,8 @@ module CrmJavaSearch
module Searchers
class LeadSearcher < BaseSearcher
def search
repeat_search_data = Agents::LeadAgent.repeat_search(:lead, @organization.id, @es_query)
Log.logger.info("repeat_search_data: #{repeat_search_data}")
if repeat_search_data['data']
data = Agents::LeadAgent.repeat_search(:lead, @organization.id, @es_query)["data"]
if data
Lead.where(organization_id: @organization.id).where(id: data.map{|datai| datai['id']})
else
Lead.none
......
module CrmJavaSearch
VERSION = "0.1.3"
VERSION = "0.2"
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