package com.nova.sankuai.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.nova.sankuai.domain.entity.*;
|
import com.nova.sankuai.domain.enums.capitalInfo.CapitalFundTypeEnum;
|
import com.nova.sankuai.domain.enums.capitalInfo.CapitalInfoIsLenderEnum;
|
import com.nova.sankuai.domain.enums.capitalInfo.CapitalInfoStatusEnum;
|
import com.nova.sankuai.infra.config.CommonException;
|
import com.nova.sankuai.infra.mapper.CustomerCapitalResultMapper;
|
import com.nova.sankuai.infra.mapper.CustomerUserMapper;
|
import com.nova.sankuai.infra.utils.UserUtil;
|
import com.nova.sankuai.security.UserDetail;
|
import com.nova.sankuai.service.ICapitalResultCommonService;
|
import com.nova.sankuai.service.IChannelInfoService;
|
import com.nova.sankuai.service.ICityService;
|
import lombok.AllArgsConstructor;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.Objects;
|
|
/**
|
* @author weikangdi
|
* @create 2022/7/1
|
*/
|
@Service
|
@AllArgsConstructor
|
public class CapitalResultCommonServiceImpl implements ICapitalResultCommonService {
|
|
private final ICityService cityService;
|
|
private final CustomerCapitalResultMapper capitalResultMapper;
|
|
private final IChannelInfoService channelInfoService;
|
|
private static final Logger log = LoggerFactory.getLogger("capitalLogger");
|
|
private final CustomerUserMapper customerUserMapper;
|
|
@Override
|
public LambdaUpdateWrapper<CustomerCapitalResult> getWrapper(CapitalInfo capitalInfo, CustomerCapitalResult capitalResult) {
|
LambdaUpdateWrapper<CustomerCapitalResult> wrapper = Wrappers.<CustomerCapitalResult>lambdaUpdate()
|
.set(CustomerCapitalResult::getApprovalResult, capitalResult.getApprovalResult())
|
.set(CustomerCapitalResult::getStatus, capitalResult.getStatus())
|
.set(CustomerCapitalResult::getLastUpdatedDate, new Date())
|
.set(CustomerCapitalResult::getThirdOrderStatus,capitalResult.getThirdOrderStatus());
|
if (Objects.equals(CapitalFundTypeEnum.ONLINE.getCode(), capitalInfo.getFundType()) && capitalResult.getApprovalInnerResult() == null) {
|
wrapper.set(CustomerCapitalResult::getApprovalInnerResult, CapitalInfoStatusEnum.FIRST_APPROVAL.getCode());
|
}
|
wrapper.eq(CustomerCapitalResult::getId, capitalResult.getId());
|
return wrapper;
|
}
|
|
|
/**
|
* 根据资方信息筛选条件对申请记录进行筛选,如果不满足条件,视为撞库失败
|
*
|
* @param customer
|
* @param capitalInfo
|
* @param capitalResult
|
* @return
|
*/
|
@Override
|
public CustomerCapitalResult filterCustomer(Customer customer, CapitalInfo
|
capitalInfo, CustomerCapitalResult capitalResult, String logNumber) {
|
boolean filter = true;
|
boolean bool = assetScreening(capitalInfo, customer, logNumber, filter);
|
filter = bool;
|
if (customer.getIsDistinguishOcr() != null && customer.getIsDistinguishOcr().equals(0) &&
|
CapitalInfoIsLenderEnum.OCR_REQUIRED.getCode().equals(capitalInfo.getIsOcrRequired())) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "ocr识别失败");
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getCityLimit())) {
|
String cityId = customer.getCity();
|
City city = cityService.lambdaQuery().eq(City::getCityId, cityId).one();
|
if (StringUtils.isEmpty(customer.getCity()) || city == null) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足城市筛选,撞库失败");
|
} else {
|
String deliveryCity = capitalInfo.getCityLimit();
|
String provinceId = city.getProvinceId();
|
if (!deliveryCity.contains(cityId) && !deliveryCity.equals(provinceId)
|
&& !deliveryCity.contains("," + provinceId + ",")
|
&& !deliveryCity.endsWith("," + provinceId)
|
&& !deliveryCity.contains(provinceId + ",")) {
|
// if (!deliveryCity.contains(provinceId)) {
|
filter = false;
|
}
|
}
|
}
|
if (capitalInfo.getAgeLowerLimit() != null) {
|
if (customer.getAge() == null || customer.getAge() < capitalInfo.getAgeLowerLimit()) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足年龄筛选,年龄过小,撞库失败");
|
}
|
}
|
if (capitalInfo.getAgeUpperLimit() != null) {
|
if (customer.getAge() == null || customer.getAge() > capitalInfo.getAgeUpperLimit()) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足年龄筛选,年龄过大,撞库失败");
|
}
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getMarriageLimit())) {
|
String[] split = capitalInfo.getMarriageLimit().split(",");
|
if (!Arrays.asList(split).contains(customer.getMaritalStatus())) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足婚姻筛选,撞库失败");
|
}
|
}
|
if (capitalInfo.getSesameLimit() != null) {
|
if (!Objects.equals(capitalInfo.getSesameLimit(), customer.getSesame())) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足芝麻分筛选,撞库失败");
|
}
|
}
|
if (capitalInfo.getCreditCardLimit() != null) {
|
if (!Objects.equals(capitalInfo.getCreditCardLimit(), customer.getCreditCard())) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足信用卡筛选,撞库失败");
|
}
|
}
|
if (capitalInfo.getAmountLowerLimit() != null) {
|
if (customer.getLoanAmount() == null || customer.getLoanAmount() < capitalInfo.getAmountLowerLimit()) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足贷款金额筛选,金额过小,撞库失败");
|
}
|
}
|
if (capitalInfo.getAmountUpperLimit() != null) {
|
if (customer.getLoanAmount() == null || customer.getLoanAmount() > capitalInfo.getAmountUpperLimit()) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足贷款金额筛选,金额过大,撞库失败");
|
}
|
}
|
if (capitalInfo.getMonthlyIncomeLimit() != null) {
|
if (!Objects.equals(capitalInfo.getMonthlyIncomeLimit(), customer.getMonthlyIncome())) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足月收入筛选,撞库失败");
|
}
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getEducationLimit())) {
|
String[] split = capitalInfo.getEducationLimit().split(",");
|
if (!Arrays.asList(split).contains(customer.getEducation())) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足教育筛选,撞库失败");
|
}
|
}
|
Integer sourceChannelCustomer = customer.getSourceChannel();
|
if (sourceChannelCustomer == null) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足渠道筛选,用户渠道为空,撞库失败");
|
} else {
|
ChannelInfo channelInfo = channelInfoService.getOne(new LambdaQueryWrapper<ChannelInfo>().eq(ChannelInfo::getCode, sourceChannelCustomer)
|
.eq(ChannelInfo::getStatus, 1));
|
if (channelInfo == null) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足渠道筛选,渠道为空,撞库失败");
|
} else {
|
String sourceChannel = channelInfo.getId().toString();
|
if (CapitalInfo.CHANNEL_INCLUDE == capitalInfo.getChannelConfig()) {
|
if (StringUtils.isEmpty(capitalInfo.getChannelIds()) || StringUtils.isEmpty(sourceChannel)) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足渠道筛选,包含渠道列表为空,撞库失败");
|
} else {
|
if (!capitalInfo.getChannelIds().contains(sourceChannel)) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足渠道筛选,未包含用户渠道,撞库失败");
|
}
|
}
|
} else if (CapitalInfo.CHANNEL_UNINCLUDE == capitalInfo.getChannelConfig()) {
|
if (!StringUtils.isEmpty(capitalInfo.getChannelIds()) && !StringUtils.isEmpty(sourceChannel)) {
|
if (capitalInfo.getChannelIds().contains(sourceChannel)) {
|
filter = false;
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时不满足渠道筛选,包含用户渠道,撞库失败");
|
}
|
}
|
}
|
}
|
}
|
|
if (filter) {
|
return null;
|
} else {
|
capitalResult.setCheckResult(CustomerCapitalResult.CHECK_FAIL);
|
capitalResultMapper.insert(capitalResult);
|
return capitalResult;
|
}
|
}
|
|
|
private boolean assetScreening(CapitalInfo capitalInfo, Customer customer, String logNumber, boolean filter) {
|
boolean isAllSatisfy = false;
|
if (StringUtils.isNotEmpty(capitalInfo.getSocialSecurityLimit())) {
|
String[] split = capitalInfo.getSocialSecurityLimit().split(",");
|
if (customer.getSocialSecurity() == null || !Arrays.asList(split).contains(customer.getSocialSecurity().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getProvidentFundLimit())) {
|
String[] split = capitalInfo.getProvidentFundLimit().split(",");
|
if (customer.getProvidentFund() == null || !Arrays.asList(split).contains(customer.getProvidentFund().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getHouseLimit())) {
|
String[] split = capitalInfo.getHouseLimit().split(",");
|
if (customer.getHouseStatus() == null || !Arrays.asList(split).contains(customer.getHouseStatus().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getCarLimit())) {
|
String[] split = capitalInfo.getCarLimit().split(",");
|
if (customer.getCarStatus() == null || !Arrays.asList(split).contains(customer.getCarStatus().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (StringUtils.isNotEmpty(capitalInfo.getPolicyLimit())) {
|
String[] split = capitalInfo.getPolicyLimit().split(",");
|
if (customer.getInsurancePolicy() == null || !Arrays.asList(split).contains(customer.getInsurancePolicy().toString())) {
|
filter = false;
|
} else {
|
isAllSatisfy = true;
|
}
|
}
|
if (isAllSatisfy) {
|
filter = true;
|
if (filter) {
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时5个筛选条件满足其一");
|
} else {
|
log.info("日志编号:" + logNumber + capitalInfo.getName() + "撞库时5个筛选条件都不满足");
|
}
|
}
|
return filter;
|
}
|
|
@Override
|
public CustomerUser checkUser(HttpServletRequest request) {
|
String token = request.getHeader("Authorization");
|
UserDetail user = UserUtil.getUser(token);
|
if (user == null) {
|
throw new CommonException("用户Token无效");
|
}
|
CustomerUser customerUser = customerUserMapper.selectById(user.getId());
|
if (customerUser == null) {
|
throw new CommonException("用户不存在");
|
}
|
return customerUser;
|
}
|
}
|