package com.nova.sankuai.infra.utils;
|
|
import com.nova.sankuai.domain.entity.*;
|
import com.nova.sankuai.infra.mapper.ChannelInfoMapper;
|
import com.nova.sankuai.service.IApiCompanyRecordService;
|
import com.nova.sankuai.service.IChannelCompanyConfigService;
|
import lombok.AllArgsConstructor;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* @author weikangdi
|
* @create 2022/4/15
|
*/
|
@Component
|
@AllArgsConstructor
|
public class ApiCompanyCheckUtil {
|
|
private final IApiCompanyRecordService recordService;
|
|
private final IChannelCompanyConfigService channelCompanyConfigService;
|
|
private static final Logger log = LoggerFactory.getLogger("apiCompanyInfoLogger");
|
|
private final ChannelInfoMapper channelInfoMapper;
|
|
/**
|
* 筛选客户是否满足城市匹配
|
*
|
* @param apiCompany
|
* @param cityId
|
* @param provinceId
|
* @return
|
*/
|
public boolean checkCity(ApiCompany apiCompany, String cityId, String provinceId) {
|
String deliveryCity = apiCompany.getDeliveryCity();
|
if (deliveryCity.contains(cityId) || deliveryCity.equals(provinceId)
|
|| deliveryCity.contains("," + provinceId + ",")
|
|| deliveryCity.endsWith("," + provinceId)
|
|| deliveryCity.contains(provinceId + ",")) {
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 筛选客户是否满足最低贷款额度
|
*
|
* @param customer
|
* @param apiCompany
|
* @return
|
*/
|
public boolean checkLoanAmount(ApiCompany apiCompany, Customer customer) {
|
Integer companyMinLoanAmount = apiCompany.getMinLoanAmount();
|
Integer customerQuota = customer.parseLoadAmount();
|
if (companyMinLoanAmount != null) {
|
if ((customerQuota == null || customerQuota < companyMinLoanAmount)) {
|
return false;
|
}
|
}
|
return true;
|
}
|
|
/**
|
* 筛选接口公司是否达到达到累计上限
|
*
|
* @param apiCompany
|
* @return
|
*/
|
public boolean checkLimit(ApiCompany apiCompany) {
|
Integer count = recordService.lambdaQuery()
|
.eq(ApiCompanyRecord::getCompanyId, apiCompany.getId())
|
.eq(ApiCompanyRecord::getStatus, ApiCompanyRecord.SUCCESS).count();
|
if (apiCompany.getCustomerNum() == null || count < apiCompany.getCustomerNum()) {
|
return true;
|
}
|
return false;
|
}
|
|
public boolean checkChannelConfig(ApiCompany apiCompany, Long channelId) {
|
//筛选渠道配置匹配的接口公司
|
List<Long> channelIds = channelCompanyConfigService.getChannelsByCompanyId(apiCompany.getId());
|
if (!CollectionUtils.isEmpty(channelIds) && !channelIds.contains(channelId)) {
|
return false;
|
}
|
return true;
|
}
|
|
|
/**
|
* 根据机构筛选条件对推送进行筛选,如果不满足条件,则不推送
|
*
|
* @param customer
|
* @param apiCompany
|
* @return
|
*/
|
public boolean filterCustomer(Customer customer, ApiCompany apiCompany, ChannelInfo channelInfo, String type) {
|
boolean filter = true;
|
boolean bool = assetScreening(apiCompany, customer, type, filter);
|
filter = bool;
|
if (apiCompany.getMinLoanAmount() != null) {
|
if ((customer.parseLoadAmount() == null || customer.parseLoadAmount() < apiCompany.getMinLoanAmount())) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户的最低贷款额度不满足推送条件");
|
}
|
}
|
Integer count = recordService.lambdaQuery()
|
.eq(ApiCompanyRecord::getCompanyId, apiCompany.getId())
|
.eq(ApiCompanyRecord::getStatus, ApiCompanyRecord.SUCCESS).count();
|
if (apiCompany.getCustomerNum() != null && count >= apiCompany.getCustomerNum()) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户的最低贷款额度不满足推送条件");
|
}
|
if (apiCompany.getAgeLowerLimit() != null) {
|
if (customer.getAge() == null || customer.getAge() < apiCompany.getAgeLowerLimit()) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足年龄筛选,年龄过小");
|
}
|
}
|
if (apiCompany.getAgeUpperLimit() != null) {
|
if (customer.getAge() == null || customer.getAge() > apiCompany.getAgeUpperLimit()) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足年龄筛选,年龄过大");
|
}
|
}
|
if (StringUtils.isNotEmpty(apiCompany.getMarriageLimit())) {
|
String[] split = apiCompany.getMarriageLimit().split(",");
|
if (!Arrays.asList(split).contains(customer.getMaritalStatus())) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足婚姻筛选");
|
}
|
}
|
if (apiCompany.getSesameLimit() != null) {
|
if (!Objects.equals(apiCompany.getSesameLimit(), customer.getSesame())) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足芝麻分筛选");
|
}
|
}
|
if (apiCompany.getCreditCardLimit() != null) {
|
if (!Objects.equals(apiCompany.getCreditCardLimit(), customer.getCreditCard())) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足信用卡筛选");
|
}
|
}
|
if (apiCompany.getAmountLowerLimit() != null) {
|
if (customer.getLoanAmount() == null || customer.getLoanAmount() < apiCompany.getAmountLowerLimit()) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足贷款金额筛选,金额过小");
|
}
|
}
|
if (apiCompany.getAmountUpperLimit() != null) {
|
if (customer.getLoanAmount() == null || customer.getLoanAmount() > apiCompany.getAmountUpperLimit()) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足贷款金额筛选,金额过大");
|
}
|
}
|
if (apiCompany.getMonthlyIncomeLimit() != null) {
|
if (!Objects.equals(apiCompany.getMonthlyIncomeLimit(), customer.getMonthlyIncome())) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足月收入筛选");
|
}
|
}
|
if (StringUtils.isNotEmpty(apiCompany.getEducationLimit())) {
|
String[] split = apiCompany.getEducationLimit().split(",");
|
if (!Arrays.asList(split).contains(customer.getEducation())) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足教育筛选");
|
}
|
}
|
Integer sourceChannelCustomer = customer.getSourceChannel();
|
if (sourceChannelCustomer == null) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足渠道筛选,用户渠道为空");
|
} else {
|
List<Long> channelIds = channelCompanyConfigService.getChannelsByCompanyId(apiCompany.getId());
|
if (channelInfo == null) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足渠道筛选,渠道为空");
|
} else {
|
Long sourceChannel = channelInfo.getId();
|
if (ApiCompany.CHANNEL_INCLUDE == apiCompany.getChannelConfig()) {
|
if (channelIds == null || channelIds.isEmpty()) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足渠道筛选,包含渠道列表为空");
|
} else {
|
if (!channelIds.contains(sourceChannel)) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足渠道筛选,未包含用户渠道");
|
}
|
}
|
} else if (ApiCompany.CHANNEL_UNINCLUDE == apiCompany.getChannelConfig()) {
|
if (channelIds != null && !channelIds.isEmpty()) {
|
if (channelIds.contains(sourceChannel)) {
|
filter = false;
|
log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ "错误:该用户不满足渠道筛选,包含用户渠道");
|
}
|
}
|
}
|
}
|
}
|
return filter;
|
}
|
|
private boolean assetScreening(ApiCompany apiCompany, Customer customer, String type, boolean filter) {
|
boolean isAllSatisfy = false;
|
if (StringUtils.isNotEmpty(apiCompany.getSocialSecurityLimit())) {
|
String[] split = apiCompany.getSocialSecurityLimit().split(",");
|
if (customer.getSocialSecurity() == null || !Arrays.asList(split).contains(customer.getSocialSecurity().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(apiCompany.getProvidentFundLimit())) {
|
String[] split = apiCompany.getProvidentFundLimit().split(",");
|
if (customer.getProvidentFund() == null || !Arrays.asList(split).contains(customer.getProvidentFund().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(apiCompany.getHouseLimit())) {
|
String[] split = apiCompany.getHouseLimit().split(",");
|
if (customer.getHouseStatus() == null || !Arrays.asList(split).contains(customer.getHouseStatus().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(apiCompany.getCarLimit())) {
|
String[] split = apiCompany.getCarLimit().split(",");
|
if (customer.getCarStatus() == null || !Arrays.asList(split).contains(customer.getCarStatus().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(apiCompany.getPolicyLimit())) {
|
String[] split = apiCompany.getPolicyLimit().split(",");
|
if (customer.getInsurancePolicy() == null || !Arrays.asList(split).contains(customer.getInsurancePolicy().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (isAllSatisfy) {
|
filter = true;
|
log.info(type + apiCompany.getCompanyName() + "成功,用户手机号" + customer.getPhone()
|
+ ",5个筛选条件满足其一");
|
} else {
|
log.info(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
|
+ ",5个筛选条件均不满足");
|
}
|
return filter;
|
}
|
}
|