@@ -25,7 +25,6 @@ import java.util.stream.Collectors;
import javax.net.ssl.SSLException ;
import com.ecep.contract.util.FileUtils ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.util.StringUtils ;
@@ -44,6 +43,7 @@ import com.ecep.contract.model.Company;
import com.ecep.contract.model.CompanyBlackReason ;
import com.ecep.contract.model.CompanyContact ;
import com.ecep.contract.model.CompanyOldName ;
import com.ecep.contract.util.FileUtils ;
import com.ecep.contract.util.HttpJsonUtils ;
import com.fasterxml.jackson.databind.JsonMappingException ;
import com.fasterxml.jackson.databind.JsonNode ;
@@ -99,8 +99,7 @@ public class CloudRkCtx extends AbstractCtx {
Proxy . Type proxyType = Proxy . Type . valueOf ( proxyUri . getScheme ( ) . toUpperCase ( ) ) ;
socksProxy = new Proxy (
proxyType ,
new InetSocketAddress ( proxyUri . getHost ( ) , proxyUri . getPort ( ) )
) ;
new InetSocketAddress ( proxyUri . getHost ( ) , proxyUri . getPort ( ) ) ) ;
}
return socksProxy ;
}
@@ -109,7 +108,6 @@ public class CloudRkCtx extends AbstractCtx {
HttpJsonUtils . post ( url , data , consumer , getObjectMapper ( ) , getSocksProxy ( ) ) ;
}
public boolean syncCompany ( Company company , CloudRk cloudRk , MessageHolder holder ) {
if ( ! StringUtils . hasText ( cloudRk . getCloudId ( ) ) ) {
holder . warn ( " 未定义平台编号, 尝试从平台上自动获取 " ) ;
@@ -157,19 +155,17 @@ public class CloudRkCtx extends AbstractCtx {
return updated ;
}
/**
* 更新黑名单列表
*/
public boolean updateBlackList (
Company company , CloudRk cloudRk , MessageHolder holder
) throws IOException {
Instant start = cloudRk . getCloudBlackListUpdated ( ) ;
Company company , CloudRk cloudRk , MessageHolder holder ) throws IOException {
LocalDateTime start = cloudRk . getCloudBlackListUpdated ( ) ;
if ( start ! = null ) {
long elapse = getConfService ( ) . getLong ( CloudRkService . KEY_BLACK_LIST_ELAPSE ) ;
if ( elapse > 0 ) {
Instant next = start . plusSeconds ( elapse ) ;
if ( next . isAfter ( Instant . now ( ) ) ) {
LocalDateTime next = start . plusSeconds ( elapse ) ;
if ( next . isAfter ( LocalDateTime . now ( ) ) ) {
holder . debug ( " 更新时间未到, 上次更新时间 = " + start ) ;
return false ;
}
@@ -179,7 +175,6 @@ public class CloudRkCtx extends AbstractCtx {
String api = getConfService ( ) . getString ( CloudRkService . KEY_BLACK_LIST_URL ) ;
List < String > companyNames = getCompanyService ( ) . getAllNames ( company ) ;
List < CompanyBlackReason > reasonList = new ArrayList < > ( ) ;
List < CompanyBlackReason > dbReasons = getCompanyBlackReasonService ( ) . findAllByCompany ( company ) ;
for ( String name : companyNames ) {
@@ -195,22 +190,21 @@ public class CloudRkCtx extends AbstractCtx {
}
if ( reasonList . isEmpty ( ) ) {
cloudRk . setCloudBlackListUpdated ( Instant . now ( ) ) ;
cloudRk . setCloudBlackListUpdated ( LocalDateTime . now ( ) ) ;
return false ;
}
for ( CompanyBlackReason companyBlackReason : reasonList ) {
getCompanyBlackReasonService ( ) . save ( companyBlackReason ) ;
}
cloudRk . setCloudBlackListUpdated ( Instant . now ( ) ) ;
cloudRk . setCloudBlackListUpdated ( LocalDateTime . now ( ) ) ;
return true ;
}
private boolean applyBlackReason (
JsonNode json , Company company , CloudRk cloudRk ,
List < CompanyBlackReason > reasonList , List < CompanyBlackReason > dbReasons ,
MessageHolder holder
) {
MessageHolder holder ) {
if ( isUnSuccess ( json , holder ) ) {
return false ;
}
@@ -246,11 +240,11 @@ public class CloudRkCtx extends AbstractCtx {
private void toCompanyBlackReasonList (
Company company , BlackReasonType type ,
JsonNode reason , List < CompanyBlackReason > dbReasons ,
List < CompanyBlackReason > reasonList
) throws JsonMappingException {
List < CompanyBlackReason > reasonList ) throws JsonMappingException {
ObjectNode object = ( ObjectNode ) reason ;
String key = " rk- " + object . remove ( " id " ) . asText ( ) ;
CompanyBlackReason cbr = dbReasons . stream ( ) . filter ( r - > r . getKey ( ) . equals ( key ) ) . findAny ( ) . orElseGet ( CompanyBlackReason : : new ) ;
CompanyBlackReason cbr = dbReasons . stream ( ) . filter ( r - > r . getKey ( ) . equals ( key ) ) . findAny ( )
. orElseGet ( CompanyBlackReason : : new ) ;
getObjectMapper ( ) . updateValue ( cbr , reason ) ;
cbr . setCompany ( company ) ;
cbr . setType ( type ) ;
@@ -258,13 +252,11 @@ public class CloudRkCtx extends AbstractCtx {
reasonList . add ( cbr ) ;
}
/**
* 更新评分
*/
public boolean updateEnterpriseCredit (
Company company , CloudRk cloudRk , MessageHolder holder
) throws IOException {
Company company , CloudRk cloudRk , MessageHolder holder ) throws IOException {
String api = getConfService ( ) . getString ( CloudRkService . KEY_ENT_SCORE_URL ) ;
AtomicBoolean modified = new AtomicBoolean ( false ) ;
try {
@@ -332,8 +324,7 @@ public class CloudRkCtx extends AbstractCtx {
* 客户信用
*/
public boolean updateCustomerScore (
Company company , CloudRk cloudRk , MessageHolder holder
) throws IOException {
Company company , CloudRk cloudRk , MessageHolder holder ) throws IOException {
String url = getConfService ( ) . getString ( CloudRkService . KEY_CUSTOMER_REPORT_URL ) ;
AtomicBoolean modified = new AtomicBoolean ( false ) ;
try {
@@ -381,16 +372,15 @@ public class CloudRkCtx extends AbstractCtx {
if ( updateNumber ( cloudRk : : getCustomerScore , cloudRk : : setCustomerScore , score , holder , " 客户信用总分 " ) ) {
modified = true ;
}
if ( updateText ( cloudRk : : getCustomerDescription , cloudRk : : setCustomerDescription , description , holder , " 客户信用评级说明 " ) ) {
if ( updateText ( cloudRk : : getCustomerDescription , cloudRk : : setCustomerDescription , description , holder ,
" 客户信用评级说明 " ) ) {
modified = true ;
}
return modified ;
}
public boolean updateVendorScore (
Company company , CloudRk cloudRk , MessageHolder holder
) throws IOException {
Company company , CloudRk cloudRk , MessageHolder holder ) throws IOException {
String url = getConfService ( ) . getString ( CloudRkService . KEY_VENDOR_REPORT_URL ) ;
AtomicBoolean modified = new AtomicBoolean ( false ) ;
try {
@@ -437,7 +427,8 @@ public class CloudRkCtx extends AbstractCtx {
if ( updateNumber ( cloudRk : : getVendorScore , cloudRk : : setVendorScore , score , holder , " 供应商信用总分 " ) ) {
modified = true ;
}
if ( updateText ( cloudRk : : getVendorDescription , cloudRk : : setVendorDescription , description , holder , " 供应商信用评级说明 " ) ) {
if ( updateText ( cloudRk : : getVendorDescription , cloudRk : : setVendorDescription , description , holder ,
" 供应商信用评级说明 " ) ) {
modified = true ;
}
return modified ;
@@ -451,8 +442,7 @@ public class CloudRkCtx extends AbstractCtx {
* @return true 更新了 cloudId, 否则false
*/
private boolean queryCloudIdAndSelectOne (
Company company , CloudRk cloudRk , MessageHolder holder
) {
Company company , CloudRk cloudRk , MessageHolder holder ) {
try {
List < CloudRkService . EntInfo > entInfos = queryEnterpriseWithFuzzy ( company , cloudRk , holder ) ;
// 返回的查询结果为空时
@@ -464,14 +454,17 @@ public class CloudRkCtx extends AbstractCtx {
}
// 在返回的结果中,找到与公司名字一致的一个
Optional < CloudRkService . EntInfo > optional = entInfos . stream ( ) . filter ( n - > n . getName ( ) . equals ( company . getName ( ) ) ) . findAny ( ) ;
Optional < CloudRkService . EntInfo > optional = entInfos . stream ( )
. filter ( n - > n . getName ( ) . equals ( company . getName ( ) ) ) . findAny ( ) ;
if ( optional . isPresent ( ) ) {
cloudRk . setCloudId ( optional . get ( ) . getId ( ) ) ;
return true ;
}
//
holder . error ( " 在平台中查询到多个匹配 ( " + entInfos . stream ( ) . map ( CloudRkService . EntInfo : : getName ) . collect ( Collectors . joining ( " , " ) ) + " ),请手工同步选择匹配 " ) ;
holder . error ( " 在平台中查询到多个匹配 ( "
+ entInfos . stream ( ) . map ( CloudRkService . EntInfo : : getName ) . collect ( Collectors . joining ( " , " ) )
+ " ),请手工同步选择匹配 " ) ;
return false ;
} catch ( Exception e ) {
@@ -484,13 +477,11 @@ public class CloudRkCtx extends AbstractCtx {
}
}
/**
* 使用模糊查询接口查询相关企业信息
*/
public List < CloudRkService . EntInfo > queryEnterpriseWithFuzzy (
Company company , CloudRk cloudRk , MessageHolder holder
) throws IOException {
Company company , CloudRk cloudRk , MessageHolder holder ) throws IOException {
String url = getConfService ( ) . getString ( CloudRkService . KEY_ENT_FUZZY_URL ) ;
List < CloudRkService . EntInfo > results = new ArrayList < > ( ) ;
ObjectMapper objectMapper = getObjectMapper ( ) ;
@@ -508,7 +499,8 @@ public class CloudRkCtx extends AbstractCtx {
return results ;
}
private boolean applyEnterpriseQuery ( JsonNode json , Company company , CloudRk cloudRk , List < CloudRkService . EntInfo > results , MessageHolder holder ) {
private boolean applyEnterpriseQuery ( JsonNode json , Company company , CloudRk cloudRk ,
List < CloudRkService . EntInfo > results , MessageHolder holder ) {
if ( ! json . has ( " data " ) ) {
// 没有数据
holder . error ( " 数据异常, 返回的json中没有 data 字段 " ) ;
@@ -542,8 +534,7 @@ public class CloudRkCtx extends AbstractCtx {
* 更新企业工商注册信息
*/
public boolean updateEnterpriseInfo (
Company company , CloudRk cloudRk , MessageHolder holder
) throws IOException {
Company company , CloudRk cloudRk , MessageHolder holder ) throws IOException {
String api = getConfService ( ) . getString ( CloudRkService . KEY_ENT_REPORT_URL ) ;
Proxy socksProxy = getSocksProxy ( ) ;
holder . debug ( " 更新企业工商注册信息: " + company . getName ( ) + " @ " + api + " , proxy= " + socksProxy ) ;
@@ -609,10 +600,12 @@ public class CloudRkCtx extends AbstractCtx {
if ( updateText ( company : : getRegisteredCapital , company : : setRegisteredCapital , data , " regcap " , holder , " 注册资金 " ) ) {
modified = true ;
}
if ( updateText ( company : : getRegisteredCapitalCurrency , company : : setRegisteredCapitalCurrency , data , " regcapcur " , holder , " 资本金币种 " ) ) {
if ( updateText ( company : : getRegisteredCapitalCurrency , company : : setRegisteredCapitalCurrency , data , " regcapcur " ,
holder , " 资本金币种 " ) ) {
modified = true ;
}
if ( updateText ( company : : getLegalRepresentative , company : : setLegalRepresentative , data , " frname " , holder , " 法人 " ) ) {
if ( updateText ( company : : getLegalRepresentative , company : : setLegalRepresentative , data , " frname " , holder ,
" 法人 " ) ) {
modified = true ;
}
if ( updateText ( company : : getDistrict , company : : setDistrict , data , " regorgprovince " , holder , " 注册区域 " ) ) {
@@ -636,10 +629,21 @@ public class CloudRkCtx extends AbstractCtx {
updateCompanyNameHistory ( company , data , holder . sub ( " 曾用名 " ) ) ;
updateLegalRepresentativeContact ( company , data , holder . sub ( " 法人联系方式 " ) ) ;
updateInstant ( cloudRk : : getCloudEntUpdate , cloudRk : : setCloudEntUpdate , data , " updated " , holder , " 更新时间 " , false ) ;
updateLocalDateTime ( cloudRk : : getCloudEntUpdate , cloudRk : : setCloudEntUpdate , data , " updated " , holder , " 更新时间 " ) ;
return modified ;
}
public boolean updateLocalDateTime ( Supplier < LocalDateTime > getter , Consumer < LocalDateTime > setter , JsonNode data , String field ,
MessageHolder holder , String topic ) {
JsonNode node = data . get ( field ) ;
if ( node = = null | | node . isNull ( ) ) {
return false ;
}
LocalDateTime updated = getObjectMapper ( ) . convertValue ( node , LocalDateTime . class ) ;
updateLocalDateTime ( getter , setter , updated , holder , topic ) ;
return false ;
}
/**
* 更新法人联系人联系方式
@@ -650,7 +654,6 @@ public class CloudRkCtx extends AbstractCtx {
return ;
}
CompanyContactService contactService = SpringApp . getBean ( CompanyContactService . class ) ;
List < CompanyContact > contactList = contactService . findAllByCompanyAndName ( company , legalRepresentative ) ;
if ( contactList = = null ) {
@@ -660,7 +663,7 @@ public class CloudRkCtx extends AbstractCtx {
CompanyContact contact = null ;
boolean modified = false ;
if ( contactList . isEmpty ( ) ) {
//没有,创建法人联系人
// 没有,创建法人联系人
contact = new CompanyContact ( ) ;
contact . setCompany ( company ) ;
contact . setName ( legalRepresentative ) ;
@@ -705,7 +708,8 @@ public class CloudRkCtx extends AbstractCtx {
}
private boolean updateOperationPeriodBegin ( Company company , JsonNode data , MessageHolder holder ) {
return updateLocalDate ( company : : getOperationPeriodBegin , company : : setOperationPeriodBegin , data , " opfrom " , holder , " 营业期限起始日期 " , true ) ;
return updateLocalDate ( company : : getOperationPeriodBegin , company : : setOperationPeriodBegin , data , " opfrom " ,
holder , " 营业期限起始日期 " , true ) ;
}
private boolean updateOperationPeriodEnd ( Company company , JsonNode data , MessageHolder holder ) {
@@ -716,14 +720,15 @@ public class CloudRkCtx extends AbstractCtx {
String text = node . asText ( ) ;
if ( StringUtils . hasText ( text ) ) {
if ( text . equals ( " - " ) ) {
return updateLocalDate ( company : : getOperationPeriodEnd , company : : setOperationPeriodEnd , ( LocalDate ) null , holder , " 营业期限截至日期 " , true ) ;
return updateLocalDate ( company : : getOperationPeriodEnd , company : : setOperationPeriodEnd , ( LocalDate ) null ,
holder , " 营业期限截至日期 " , true ) ;
}
return updateLocalDate ( company : : getOperationPeriodEnd , company : : setOperationPeriodEnd , data , " opto " , holder , " 营业期限截至日期 " , true ) ;
return updateLocalDate ( company : : getOperationPeriodEnd , company : : setOperationPeriodEnd , data , " opto " , holder ,
" 营业期限截至日期 " , true ) ;
}
return false ;
}
private void updateCompanyNameHistory ( Company company , JsonNode data , MessageHolder holder ) {
JsonNode node = data . get ( " nameHistory " ) ;
if ( node = = null ) {
@@ -754,7 +759,8 @@ public class CloudRkCtx extends AbstractCtx {
}
}
private boolean updateLocalDate ( Supplier < LocalDate > getter , Consumer < LocalDate > setter , JsonNode data , String field , MessageHolder holder , String topic , boolean allowNull ) {
private boolean updateLocalDate ( Supplier < LocalDate > getter , Consumer < LocalDate > setter , JsonNode data , String field ,
MessageHolder holder , String topic , boolean allowNull ) {
JsonNode node = data . get ( field ) ;
if ( node = = null | | node . isNull ( ) ) {
return false ;
@@ -766,11 +772,13 @@ public class CloudRkCtx extends AbstractCtx {
return updateLocalDate ( getter , setter , localDate , holder , topic , allowNull ) ;
}
private boolean updateLocalDate ( Supplier < LocalDate > getter , Consumer < LocalDate > setter , JsonNode data , String field , MessageHolder holder , String topic ) {
private boolean updateLocalDate ( Supplier < LocalDate > getter , Consumer < LocalDate > setter , JsonNode data , String field ,
MessageHolder holder , String topic ) {
return updateLocalDate ( getter , setter , data , field , holder , topic , false ) ;
}
private void updateInstant ( Supplier < Instant > getter , Consumer < Instant > setter , JsonNode data , String field , MessageHolder holder , String topic , boolean allowNull ) {
private void updateInstant ( Supplier < Instant > getter , Consumer < Instant > setter , JsonNode data , String field ,
MessageHolder holder , String topic , boolean allowNull ) {
JsonNode node = data . get ( " updated " ) ;
if ( node = = null ) {
return ;
@@ -787,7 +795,8 @@ public class CloudRkCtx extends AbstractCtx {
updateInstant ( getter , setter , instant , holder , topic ) ;
}
private boolean updateText ( Supplier < String > getter , Consumer < String > setter , JsonNode data , String field , MessageHolder holder , String topic ) {
private boolean updateText ( Supplier < String > getter , Consumer < String > setter , JsonNode data , String field ,
MessageHolder holder , String topic ) {
JsonNode node = data . get ( field ) ;
if ( node = = null | | node . isNull ( ) ) {
return false ;