Commit e14a908d authored by shihuajun's avatar shihuajun

资金路由第2版提交代码

parent 3aa8f453
...@@ -16,7 +16,7 @@ import java.util.ArrayList; ...@@ -16,7 +16,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@Component // @Component
@Data @Data
public class InitAreaCode { public class InitAreaCode {
...@@ -24,7 +24,7 @@ public class InitAreaCode { ...@@ -24,7 +24,7 @@ public class InitAreaCode {
public ConcurrentHashMap<String,AreaCode> concurrentHashMap=new ConcurrentHashMap<String,AreaCode>(); public ConcurrentHashMap<String,AreaCode> concurrentHashMap=new ConcurrentHashMap<String,AreaCode>();
public ConcurrentHashMap<String,AreaCode> concurrentNameHashMap=new ConcurrentHashMap<String,AreaCode>(); public ConcurrentHashMap<String,AreaCode> concurrentNameHashMap=new ConcurrentHashMap<String,AreaCode>();
@PostConstruct // @PostConstruct
public void init() throws Exception{ public void init() throws Exception{
logger.info("初始化区域码"); logger.info("初始化区域码");
InputStream in = this.getClass().getResourceAsStream("phone/gbt.txt"); InputStream in = this.getClass().getResourceAsStream("phone/gbt.txt");
......
package com.quantgroup.asset.distribution.constant;
/**
* Created by renfeng on 2019/7/22.
*/
public class CommonConstants {
/**
* 特殊字符start
*/
public static final String COMMA = ",";
public static final String HORIZONTAL_LINE = "-";
public static final String WAVE_LINE= "~";
public static final char NEW_LINE = '\n';
public static final String COLON = ":";
public static final String PERCENT = "%";
public static final char FIELD_DELIMITER = ',';
// 特殊字符end
}
package com.quantgroup.asset.distribution.constant;
/**
* Created by renfeng on 2019/7/22.
*/
public class CommonStants {
}
package com.quantgroup.asset.distribution.service.feature; package com.quantgroup.asset.distribution.service.feature;
import com.quantgroup.asset.distribution.model.form.AssetForm; import com.quantgroup.asset.distribution.model.form.AssetForm;
import com.quantgroup.asset.distribution.service.feature.bo.IdCardInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -21,4 +23,6 @@ public interface IFeatureService { ...@@ -21,4 +23,6 @@ public interface IFeatureService {
* @return * @return
*/ */
Map<String, Object> getFeatureData(Set<String> keys, AssetForm assetForm, int type); Map<String, Object> getFeatureData(Set<String> keys, AssetForm assetForm, int type);
IdCardInfo getIdCardInfo(String uuid);
} }
package com.quantgroup.asset.distribution.service.feature.bo;
import lombok.Data;
/**
* @author shihuajun
* @date 2021/9/7 12:57
* @ describing
*/
@Data
public class IdCardInfo {
private String name;
private String gender;//性别 男/女
private String nation;//民族
private String birthday;//出生日期 格式 :1990.02.14
private String citizen_id;//身份证号
private String address;
private String agency;//签发机关
private String valid_date_begin;//有效日期之起始日期 格式:20131022
private String valid_date_end;//有效日期之结束日期 格式:20231022
private String side;//正面-front 反面-back
private String img_base64;
private String error_message;//身份证识别错误提示
private String bizId;//腾讯识别订单号
private Boolean success;
private String responseCode;
private String compareType;//OCR类型 h5或sdk
}
...@@ -7,7 +7,9 @@ import com.quantgroup.asset.distribution.exception.QGExceptionType; ...@@ -7,7 +7,9 @@ import com.quantgroup.asset.distribution.exception.QGExceptionType;
import com.quantgroup.asset.distribution.exception.QGPreconditions; import com.quantgroup.asset.distribution.exception.QGPreconditions;
import com.quantgroup.asset.distribution.model.form.AssetForm; import com.quantgroup.asset.distribution.model.form.AssetForm;
import com.quantgroup.asset.distribution.service.feature.IFeatureService; import com.quantgroup.asset.distribution.service.feature.IFeatureService;
import com.quantgroup.asset.distribution.service.feature.bo.IdCardInfo;
import com.quantgroup.asset.distribution.service.httpclient.IHttpService; import com.quantgroup.asset.distribution.service.httpclient.IHttpService;
import com.quantgroup.asset.distribution.util.JacksonUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
...@@ -16,9 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,9 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
...@@ -56,4 +56,21 @@ public class FeatureServiceImpl implements IFeatureService { ...@@ -56,4 +56,21 @@ public class FeatureServiceImpl implements IFeatureService {
log.info("决策特征属性获取完成, uuid : {}, assetNo : {}, bizChannel : {}, bizNo : {}, bizType : {}, type : {}, data : {}, 耗时 : {}", assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizChannel(), assetForm.getBizNo(), assetForm.getBizType(), type, JSON.toJSONString(data), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); log.info("决策特征属性获取完成, uuid : {}, assetNo : {}, bizChannel : {}, bizNo : {}, bizType : {}, type : {}, data : {}, 耗时 : {}", assetForm.getUuid(), assetForm.getAssetNo(), assetForm.getBizChannel(), assetForm.getBizNo(), assetForm.getBizType(), type, JSON.toJSONString(data), stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return data; return data;
} }
@Override
public IdCardInfo getIdCardInfo(String uuid) {
if (StringUtils.isBlank(uuid)){
throw new RuntimeException("获取身份证信息参数为空");
}
Map<String,String> map = new HashMap<>();
map.put("uuid", uuid);
// todo 此处需要更改
String responce = httpService.get(ruleEngineURL, map);
List<IdCardInfo> idCardInfoList = JacksonUtil.deserializeList(responce, IdCardInfo.class);
Optional<IdCardInfo> cardInfo = idCardInfoList.stream().filter(d -> d.getSide().equals("back")).findFirst();
if (!cardInfo.isPresent()){
throw new RuntimeException("调用第三方服务返回有问题");
}
return cardInfo.get();
}
} }
...@@ -6,7 +6,7 @@ import java.util.Objects; ...@@ -6,7 +6,7 @@ import java.util.Objects;
/** /**
* @author shihuajun * @author shihuajun
* @date 2021/9/2 16:20 * @date 2021/9/7 15:57
* @ describing * @ describing
*/ */
@Entity @Entity
...@@ -22,6 +22,7 @@ public class FundProductEntity { ...@@ -22,6 +22,7 @@ public class FundProductEntity {
private String systermType; private String systermType;
private String basicRule; private String basicRule;
private int areaTerm; private int areaTerm;
private int cardLimit;
private String areaRule; private String areaRule;
private String ruleList; private String ruleList;
private Byte enable; private Byte enable;
...@@ -128,6 +129,16 @@ public class FundProductEntity { ...@@ -128,6 +129,16 @@ public class FundProductEntity {
this.areaTerm = areaTerm; this.areaTerm = areaTerm;
} }
@Basic
@Column(name = "card_limit", nullable = false)
public int getCardLimit() {
return cardLimit;
}
public void setCardLimit(int cardLimit) {
this.cardLimit = cardLimit;
}
@Basic @Basic
@Column(name = "area_rule", nullable = false, length = 500) @Column(name = "area_rule", nullable = false, length = 500)
public String getAreaRule() { public String getAreaRule() {
...@@ -183,11 +194,11 @@ public class FundProductEntity { ...@@ -183,11 +194,11 @@ public class FundProductEntity {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
FundProductEntity that = (FundProductEntity) o; FundProductEntity that = (FundProductEntity) o;
return id == that.id && fundId == that.fundId && fundProId == that.fundProId && areaTerm == that.areaTerm && Objects.equals(fundName, that.fundName) && Objects.equals(fundType, that.fundType) && Objects.equals(orgType, that.orgType) && Objects.equals(businessType, that.businessType) && Objects.equals(systermType, that.systermType) && Objects.equals(basicRule, that.basicRule) && Objects.equals(areaRule, that.areaRule) && Objects.equals(ruleList, that.ruleList) && Objects.equals(enable, that.enable) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt); return id == that.id && fundId == that.fundId && fundProId == that.fundProId && areaTerm == that.areaTerm && cardLimit == that.cardLimit && Objects.equals(fundName, that.fundName) && Objects.equals(fundType, that.fundType) && Objects.equals(orgType, that.orgType) && Objects.equals(businessType, that.businessType) && Objects.equals(systermType, that.systermType) && Objects.equals(basicRule, that.basicRule) && Objects.equals(areaRule, that.areaRule) && Objects.equals(ruleList, that.ruleList) && Objects.equals(enable, that.enable) && Objects.equals(createdAt, that.createdAt) && Objects.equals(updatedAt, that.updatedAt);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, fundId, fundProId, fundName, fundType, orgType, businessType, systermType, basicRule, areaTerm, areaRule, ruleList, enable, createdAt, updatedAt); return Objects.hash(id, fundId, fundProId, fundName, fundType, orgType, businessType, systermType, basicRule, areaTerm, cardLimit, areaRule, ruleList, enable, createdAt, updatedAt);
} }
} }
...@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
public interface IFundProductRepository extends JpaRepository<FundProductEntity, Long>{ public interface IFundProductRepository extends JpaRepository<FundProductEntity, Long>{
FundProductEntity getByIdEquals(Long id);
} }
...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression; import com.googlecode.aviator.Expression;
import com.quantgroup.asset.distribution.constant.CommonConstants;
import com.quantgroup.asset.distribution.exception.QGException; import com.quantgroup.asset.distribution.exception.QGException;
import com.quantgroup.asset.distribution.exception.QGExceptionType; import com.quantgroup.asset.distribution.exception.QGExceptionType;
import com.quantgroup.asset.distribution.service.alarm.IAlarmService; import com.quantgroup.asset.distribution.service.alarm.IAlarmService;
...@@ -20,6 +21,7 @@ import com.quantgroup.asset.distribution.service.newrule.pojo.RoutingRecordVO; ...@@ -20,6 +21,7 @@ import com.quantgroup.asset.distribution.service.newrule.pojo.RoutingRecordVO;
import com.quantgroup.asset.distribution.service.newrule.pojo.RuleConstant; import com.quantgroup.asset.distribution.service.newrule.pojo.RuleConstant;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.AreaEnum; import com.quantgroup.asset.distribution.service.newrule.pojo.enums.AreaEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.CooperationEnum; import com.quantgroup.asset.distribution.service.newrule.pojo.enums.CooperationEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.IdCardExpireEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.funds.*; import com.quantgroup.asset.distribution.service.newrule.pojo.funds.*;
import com.quantgroup.asset.distribution.service.newrule.service.IProductRuleService; import com.quantgroup.asset.distribution.service.newrule.service.IProductRuleService;
import com.quantgroup.asset.distribution.service.newrule.third.AuditResponce; import com.quantgroup.asset.distribution.service.newrule.third.AuditResponce;
...@@ -31,6 +33,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -31,6 +33,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import shaded.com.google.common.collect.Lists; import shaded.com.google.common.collect.Lists;
...@@ -70,6 +73,7 @@ public class CoreFilter { ...@@ -70,6 +73,7 @@ public class CoreFilter {
@Resource @Resource
private IRoutingRecordRepository routingRecordRepository; private IRoutingRecordRepository routingRecordRepository;
@Transactional(rollbackFor = Exception.class)
public void coreHandle(AuditResponce auditResponce){ public void coreHandle(AuditResponce auditResponce){
List<ChannelRuleEntity> channelRuleEntityList = channelRuleRepository.getByChannelId(Long.parseLong(auditResponce.getBizChannel())); List<ChannelRuleEntity> channelRuleEntityList = channelRuleRepository.getByChannelId(Long.parseLong(auditResponce.getBizChannel()));
if (CollectionUtils.isEmpty(channelRuleEntityList)){ if (CollectionUtils.isEmpty(channelRuleEntityList)){
...@@ -79,7 +83,7 @@ public class CoreFilter { ...@@ -79,7 +83,7 @@ public class CoreFilter {
List<FinanceProduct> financeProducts = new ArrayList<>(); List<FinanceProduct> financeProducts = new ArrayList<>();
List<RoutingRecordVO> routingRecordList = new ArrayList<>(); List<RoutingRecordVO> routingRecordList = new ArrayList<>();
for (ChannelRuleEntity channelRuleEntity : channelRuleEntityList) { for (ChannelRuleEntity channelRuleEntity : channelRuleEntityList) {
FundProductEntity fundProduct = fundProductRepository.getOne(channelRuleEntity.getFundProductId()); FundProductEntity fundProduct = fundProductRepository.getByIdEquals(channelRuleEntity.getFundProductId());
if (fundProduct == null){ if (fundProduct == null){
log.error("这种情况不可能出现,需要看下原因 {}",JSON.toJSONString(channelRuleEntity)); log.error("这种情况不可能出现,需要看下原因 {}",JSON.toJSONString(channelRuleEntity));
continue; continue;
...@@ -126,7 +130,7 @@ public class CoreFilter { ...@@ -126,7 +130,7 @@ public class CoreFilter {
FundInfo fundInfo = new FundInfo(); FundInfo fundInfo = new FundInfo();
fundInfo.setFundId(fundProduct.getFundId()); fundInfo.setFundId(fundProduct.getFundId());
fundInfo.setFundProductId(fundProduct.getFundProId() + ""); fundInfo.setFundProductId(fundProduct.getFundProId() + "");
fundInfo.setCooperation(CooperationEnum.ASSISTANCE); fundInfo.setCooperation(CooperationEnum.parse(fundProduct.getOrgType()));
Terms term = new Terms(); Terms term = new Terms();
term.setTerm(Integer.parseInt(auditResponce.getTerm())); term.setTerm(Integer.parseInt(auditResponce.getTerm()));
term.setFundInfos(Lists.newArrayList(fundInfo)); term.setFundInfos(Lists.newArrayList(fundInfo));
...@@ -161,12 +165,12 @@ public class CoreFilter { ...@@ -161,12 +165,12 @@ public class CoreFilter {
if (channelId != Long.parseLong(auditResponce.getBizChannel())){ if (channelId != Long.parseLong(auditResponce.getBizChannel())){
return Boolean.FALSE; return Boolean.FALSE;
} }
if (StringUtils.isNotBlank(auditResponce.getCreditLevel()) || if (StringUtils.isNotBlank(auditResponce.getCreditLevel()) || (StringUtils.isNotBlank(auditResponce.getCreditLevel())
!channelRuleEntity.getUserLevel().contains(auditResponce.getCreditLevel())){ && !channelRuleEntity.getUserLevel().contains(auditResponce.getCreditLevel()))) {
return Boolean.FALSE; return Boolean.FALSE;
} }
if (StringUtils.isNotBlank(auditResponce.getUserTag()) || if (StringUtils.isNotBlank(auditResponce.getUserTag()) || (StringUtils.isNotBlank(auditResponce.getUserTag())
!channelRuleEntity.getUserTag().contains(auditResponce.getUserTag())){ && !channelRuleEntity.getUserTag().contains(auditResponce.getUserTag()))){
return Boolean.FALSE; return Boolean.FALSE;
} }
String basicRule = fundProduct.getBasicRule(); String basicRule = fundProduct.getBasicRule();
...@@ -192,27 +196,25 @@ public class CoreFilter { ...@@ -192,27 +196,25 @@ public class CoreFilter {
if (currentRuleVal.equals(RuleConstant.NOT_PERMIT_TELS)){ if (currentRuleVal.equals(RuleConstant.NOT_PERMIT_TELS)){
env.put(currentRuleVal,StringUtils.substring(associationBean.getPhoneNo(),0,3)); env.put(currentRuleVal,StringUtils.substring(associationBean.getPhoneNo(),0,3));
} }
// todo 身份证
} }
Boolean execute = (Boolean) compiledExp.execute(env); Boolean execute = (Boolean) compiledExp.execute(env);
log.info("基础校验结果 {}",execute); log.info("基础校验结果 {}",execute);
if (execute){ if (execute){
execute = areaVerify(fundProduct,associationBean); execute = commonVerify(fundProduct,associationBean,auditResponce);
} }
log.info("区域校验结果 {}",execute); log.info("公共校验结果 {}",execute);
return execute; return execute;
} }
private Boolean areaVerify(FundProductEntity fundProduct,UserAssociationBean associationBean){ private Boolean commonVerify(FundProductEntity fundProduct,UserAssociationBean associationBean,AuditResponce auditResponce){
if (fundProduct.getAreaTerm() != AreaEnum.NO_DEMAND.getCode()){ for (IRuleVerifyService ruleService : RuleHandleFactory.COMMON_VERIFY) {
ProductRuleEntity productRuleEntity = productRuleService.getProductRuleEntityById(fundProduct.getId());
IRuleVerifyService ruleVerifyService = ruleHandleFactory.getRuleVerifyServiceMap(productRuleEntity.getRuleEngine());
RuleParam ruleParam = new RuleParam(); RuleParam ruleParam = new RuleParam();
ruleParam.setUserInfo(associationBean); ruleParam.setUserInfo(associationBean);
ruleParam.setAreaNum(AreaEnum.parse(fundProduct.getAreaTerm())); ruleParam.setAreaNum(AreaEnum.parse(fundProduct.getAreaTerm()));
ruleParam.setArea(fundProduct.getAreaRule()); ruleParam.setArea(fundProduct.getAreaRule());
if (!ruleVerifyService.pass(ruleParam)){ ruleParam.setUuid(auditResponce.getUuid());
ruleParam.setCardExpireEnum(IdCardExpireEnum.parse(fundProduct.getCardLimit()));
if (!ruleService.pass(ruleParam)){
log.info("当前用户区域校验不通过 {}", JSON.toJSONString(associationBean)); log.info("当前用户区域校验不通过 {}", JSON.toJSONString(associationBean));
return Boolean.FALSE; return Boolean.FALSE;
} }
...@@ -225,7 +227,7 @@ public class CoreFilter { ...@@ -225,7 +227,7 @@ public class CoreFilter {
if (StringUtils.isBlank(ruleList)){ if (StringUtils.isBlank(ruleList)){
return Boolean.TRUE; return Boolean.TRUE;
} }
String[] rules = ruleList.split(","); String[] rules = ruleList.split(CommonConstants.COMMA);
for (String id : rules) { for (String id : rules) {
ProductRuleEntity productRuleEntity = productRuleService.getProductRuleEntityById(Long.parseLong(id)); ProductRuleEntity productRuleEntity = productRuleService.getProductRuleEntityById(Long.parseLong(id));
IRuleVerifyService ruleVerifyService = ruleHandleFactory.getRuleVerifyServiceMap(productRuleEntity.getRuleEngine()); IRuleVerifyService ruleVerifyService = ruleHandleFactory.getRuleVerifyServiceMap(productRuleEntity.getRuleEngine());
......
package com.quantgroup.asset.distribution.service.newrule; package com.quantgroup.asset.distribution.service.newrule;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -11,11 +15,14 @@ import java.util.Map; ...@@ -11,11 +15,14 @@ import java.util.Map;
* @date 2021/8/27 10:58 * @date 2021/8/27 10:58
* @ describing * @ describing
*/ */
@Slf4j
@Component @Component
public class RuleHandleFactory { public class RuleHandleFactory {
@Resource @Resource
private Map<String, IRuleVerifyService> ruleVerifyServiceMap; private Map<String, IRuleVerifyService> ruleVerifyServiceMap;
public final static List<IRuleVerifyService> COMMON_VERIFY = Lists.newArrayList();
public IRuleVerifyService getRuleVerifyServiceMap(String className) { public IRuleVerifyService getRuleVerifyServiceMap(String className) {
if (StringUtils.isBlank(className)){ if (StringUtils.isBlank(className)){
throw new RuntimeException("获取IRuleVerifyService入参有问题"); throw new RuntimeException("获取IRuleVerifyService入参有问题");
...@@ -26,4 +33,14 @@ public class RuleHandleFactory { ...@@ -26,4 +33,14 @@ public class RuleHandleFactory {
throw new RuntimeException("获取IRuleVerifyService入参有问题,没有对应的实现类"); throw new RuntimeException("获取IRuleVerifyService入参有问题,没有对应的实现类");
} }
} }
@PostConstruct
public void init(){
for (IRuleVerifyService ruleVerifyService : ruleVerifyServiceMap.values()) {
if (ruleVerifyService.getClass().getName().contains("common")){
COMMON_VERIFY.add(ruleVerifyService);
}
}
}
} }
package com.quantgroup.asset.distribution.service.newrule.specialrules; package com.quantgroup.asset.distribution.service.newrule.common;
import com.quantgroup.asset.distribution.service.jpa.entity.ProductRuleEntity; import com.quantgroup.asset.distribution.service.jpa.entity.ProductRuleEntity;
import com.quantgroup.asset.distribution.service.newrule.IRuleVerifyService; import com.quantgroup.asset.distribution.service.newrule.IRuleVerifyService;
......
package com.quantgroup.asset.distribution.service.newrule.specialrules; package com.quantgroup.asset.distribution.service.newrule.common;
import cn.quantgroup.motan.bean.UserAssociationBean; import cn.quantgroup.motan.bean.UserAssociationBean;
import com.quantgroup.asset.distribution.model.entity.user.SDKUserInfo; import com.quantgroup.asset.distribution.model.entity.user.SDKUserInfo;
...@@ -28,8 +28,8 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -28,8 +28,8 @@ import java.util.concurrent.atomic.AtomicInteger;
* @ describing * @ describing
*/ */
@Slf4j @Slf4j
@Component @Component("commonAreaVerifyImpl")
public class AreaVerifyImpl extends AbstractProductRuleVerifyImpl{ public class AreaVerifyImpl extends AbstractProductRuleVerifyImpl {
private static final String PROVINCE = "省"; private static final String PROVINCE = "省";
private static final String TEL_ALERM_TEXT = "用户的手机号是 %s"; private static final String TEL_ALERM_TEXT = "用户的手机号是 %s";
......
package com.quantgroup.asset.distribution.service.newrule.common;
import com.quantgroup.asset.distribution.constant.CommonConstants;
import com.quantgroup.asset.distribution.service.feature.IFeatureService;
import com.quantgroup.asset.distribution.service.feature.bo.IdCardInfo;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.IdCardExpireEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam;
import com.quantgroup.asset.distribution.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
/**
* @author shihuajun
* @date 2021/9/6 20:04
* @ describing
*/
@Slf4j
@Component("commonIdCardVerifyImpl")
public class IdCardVerifyImpl extends AbstractProductRuleVerifyImpl{
private static final Integer YEAR = 365;
@Resource
private IFeatureService featureService;
@Override
public boolean pass(RuleParam param) {
IdCardInfo idCardInfo = featureService.getIdCardInfo(param.getUuid());
String validDateEnd = idCardInfo.getValid_date_end();
if (StringUtils.isBlank(validDateEnd)){
throw new RuntimeException("从第三方服务获取的身份证valid_date_end结束日期有问题");
}
if (IdCardExpireEnum.CURRENT.equals(param.getCardExpireEnum())){
return DateUtil.between(idCardInfo.getValid_date_begin(),validDateEnd);
}else if (IdCardExpireEnum.EXPIRE_BIG_ONE.equals(param.getCardExpireEnum())){
return calcTermValidity(validDateEnd) >= 1;
}else if (IdCardExpireEnum.EXPIRE_BIG_LOAN.equals(param.getCardExpireEnum())){
String dateEnd = validDateEnd.substring(0,4) + CommonConstants.HORIZONTAL_LINE +
validDateEnd.substring(4,6) + CommonConstants.HORIZONTAL_LINE + validDateEnd.substring(6,8);
int monthDiff = DateUtil.getMonthDiff(DateUtil.getDay(), dateEnd);
return monthDiff > Integer.parseInt(param.getAuditResponce().getTerm());
}
return false;
}
@Override
public SpecialRuleEnum specialRuleName() {
return SpecialRuleEnum.ID_CARD_VERIFY;
}
private int calcTermValidity(String data){
Date date = new Date(Integer.parseInt(data.substring(0,4)) - 1900 ,
Integer.parseInt(data.substring(4,6)) - 1,
Integer.parseInt(data.substring(6,8)));
int days = DateUtil.getDays(date);
return days / YEAR;
}
}
...@@ -13,4 +13,6 @@ public class RuleConstant { ...@@ -13,4 +13,6 @@ public class RuleConstant {
public final static String AGE = "age"; public final static String AGE = "age";
public final static String NOT_PERMIT_TELS = "tel"; public final static String NOT_PERMIT_TELS = "tel";
public final static String IDCARD_EXPIRE = "idcard_expire";
} }
package com.quantgroup.asset.distribution.service.newrule.pojo.enums; package com.quantgroup.asset.distribution.service.newrule.pojo.enums;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
/** /**
* @author shihuajun * @author shihuajun
* @date 2021/8/27 14:33 * @date 2021/8/27 14:33
* @ describing * @ describing
*/ */
@Getter
public enum CooperationEnum { public enum CooperationEnum {
/** /**
* 助贷 * 助贷
...@@ -13,5 +17,17 @@ public enum CooperationEnum { ...@@ -13,5 +17,17 @@ public enum CooperationEnum {
/** /**
* 导流 * 导流
*/ */
ASSISTANCE ASSISTANCE;
public static CooperationEnum parse(String name){
if (StringUtils.isBlank(name)){
throw new RuntimeException("解析CooperationEnum入参为空");
}
for (CooperationEnum cooperation : CooperationEnum.values()) {
if (name.equals(cooperation.name())){
return cooperation;
}
}
throw new RuntimeException("解析CooperationEnum出问题了");
}
} }
package com.quantgroup.asset.distribution.service.newrule.pojo.enums;
import lombok.Getter;
/**
* @author shihuajun
* @date 2021/9/7 14:23
* @ describing
*/
@Getter
public enum IdCardExpireEnum {
CURRENT(0,"范围当前有效"),
EXPIRE_BIG_ONE(1,"有效期大于1年"),
EXPIRE_BIG_LOAN(2,"有效期大于借款期限");
private final Integer code;
private final String desc;
IdCardExpireEnum(Integer code,String desc){
this.code = code;
this.desc = desc;
}
public static IdCardExpireEnum parse(int code){
for (IdCardExpireEnum ae : IdCardExpireEnum.values()) {
if (code == ae.getCode()){
return ae;
}
}
throw new RuntimeException("解析IdCardExpireEnum出问题了,没有对应的枚举类型");
}
}
...@@ -9,15 +9,17 @@ import lombok.Getter; ...@@ -9,15 +9,17 @@ import lombok.Getter;
*/ */
@Getter @Getter
public enum SpecialRuleEnum { public enum SpecialRuleEnum {
CONTACT_NAME_SAME_VERIFY("联系人姓名相同"), CONTACT_NAME_SAME_VERIFY("联系人姓名相同",""),
CONTACT_TEL_SAME_VERIFY("联系人手机号相同"), CONTACT_TEL_SAME_VERIFY("联系人手机号相同",""),
AREA_VERIFY("各种区域的组合校验"), AREA_VERIFY("各种区域的组合校验",""),
CONTACT_TEL_ERROR_VERIFY("联系人手机号不正确"); ID_CARD_VERIFY("身份证有效期的校验",""),
CONTACT_TEL_ERROR_VERIFY("联系人手机号不正确","");
private String desc; private String desc;
private String ruleEngine;
SpecialRuleEnum(String desc){ SpecialRuleEnum(String desc, String ruleEngine){
this.ruleEngine = ruleEngine;
this.desc = desc; this.desc = desc;
} }
} }
package com.quantgroup.asset.distribution.service.newrule.pojo.funds;
import com.google.common.collect.Lists;
import com.quantgroup.asset.distribution.util.JacksonUtil;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author shihuajun
* @date 2021/9/7 16:54
* @ describing
*/
@Data
public class FundCallBackParam implements Serializable {
private static final long serialVersionUID = -4913944253732857699L;
private String bizNo;
private List<BaseParam> result;
public static void main(String[] args) {
/*BaseParam baseParam = new BaseParam();
baseParam.setFundId(11L);
baseParam.setDistributeStatus(21323 + "");
FundCallBackParam backParam = new FundCallBackParam();
backParam.setBizNo("fwef");
backParam.setResult(Lists.newArrayList(baseParam));
System.out.println(JacksonUtil.serialize(backParam));*/
List<String> list = Lists.newArrayList("level1","level2","level3");
System.out.println(list);
}
/**
* @author shihuajun
* @date 2021/9/7 19:06
* @ describing
*/
@Data
public static class BaseParam implements Serializable {
private static final long serialVersionUID = -1358066235935716831L;
private Long fundId;
private String distributeStatus;
}
}
package com.quantgroup.asset.distribution.service.newrule.pojo.funds; package com.quantgroup.asset.distribution.service.newrule.pojo.funds;
import cn.quantgroup.motan.bean.UserAssociationBean; import cn.quantgroup.motan.bean.UserAssociationBean;
import com.alibaba.fastjson.JSON;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.AreaEnum; import com.quantgroup.asset.distribution.service.newrule.pojo.enums.AreaEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.IdCardExpireEnum;
import com.quantgroup.asset.distribution.service.newrule.third.AuditResponce;
import lombok.Data; import lombok.Data;
...@@ -15,6 +18,9 @@ public class RuleParam { ...@@ -15,6 +18,9 @@ public class RuleParam {
private UserAssociationBean userInfo; private UserAssociationBean userInfo;
private AreaEnum areaNum; private AreaEnum areaNum;
private String area; private String area;
private String uuid;
private IdCardExpireEnum cardExpireEnum;
private AuditResponce auditResponce;
/** /**
* @author shihuajun * @author shihuajun
...@@ -30,4 +36,13 @@ public class RuleParam { ...@@ -30,4 +36,13 @@ public class RuleParam {
// 籍贯 // 籍贯
private String nativeList; private String nativeList;
} }
public static void main(String[] args) {
AreaRuleConcrete concrete = new AreaRuleConcrete();
concrete.setNativeList("[110119,100000]");
concrete.setTelAreaNameList("[100000]");
concrete.setResidenceList("[100000]");
System.out.println(JSON.toJSONString(concrete));
}
} }
...@@ -5,6 +5,7 @@ import cn.quantgroup.motan.retbean.XContactInfo; ...@@ -5,6 +5,7 @@ import cn.quantgroup.motan.retbean.XContactInfo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum; import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam; import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam;
import com.quantgroup.asset.distribution.service.newrule.common.AbstractProductRuleVerifyImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
......
...@@ -5,6 +5,7 @@ import cn.quantgroup.motan.retbean.XContactInfo; ...@@ -5,6 +5,7 @@ import cn.quantgroup.motan.retbean.XContactInfo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum; import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam; import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam;
import com.quantgroup.asset.distribution.service.newrule.common.AbstractProductRuleVerifyImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -19,7 +20,9 @@ import java.util.List; ...@@ -19,7 +20,9 @@ import java.util.List;
*/ */
@Slf4j @Slf4j
@Component @Component
public class ContactsTelErrorVerifyImpl extends AbstractProductRuleVerifyImpl{ public class ContactsTelErrorVerifyImpl extends AbstractProductRuleVerifyImpl {
private static final int TEL_LENGTH = 11;
@Override @Override
public boolean pass(RuleParam param) { public boolean pass(RuleParam param) {
if (param == null){ if (param == null){
...@@ -53,15 +56,12 @@ public class ContactsTelErrorVerifyImpl extends AbstractProductRuleVerifyImpl{ ...@@ -53,15 +56,12 @@ public class ContactsTelErrorVerifyImpl extends AbstractProductRuleVerifyImpl{
} }
private boolean telVerify(String tel){ private boolean telVerify(String tel){
if (tel.length() != 11){ if (tel.length() != TEL_LENGTH){
return false; return false;
} }
if (!tel.startsWith("1")){ if (!tel.startsWith("1")){
return false; return false;
} }
if (tel.startsWith("170") || tel.startsWith("171")){ return !tel.startsWith("170") && !tel.startsWith("171");
return false;
}
return true;
} }
} }
...@@ -5,6 +5,7 @@ import cn.quantgroup.motan.retbean.XContactInfo; ...@@ -5,6 +5,7 @@ import cn.quantgroup.motan.retbean.XContactInfo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum; import com.quantgroup.asset.distribution.service.newrule.pojo.enums.SpecialRuleEnum;
import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam; import com.quantgroup.asset.distribution.service.newrule.pojo.funds.RuleParam;
import com.quantgroup.asset.distribution.service.newrule.common.AbstractProductRuleVerifyImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -19,7 +20,7 @@ import java.util.List; ...@@ -19,7 +20,7 @@ import java.util.List;
*/ */
@Slf4j @Slf4j
@Component @Component
public class ContactsTelSameVerifyImpl extends AbstractProductRuleVerifyImpl{ public class ContactsTelSameVerifyImpl extends AbstractProductRuleVerifyImpl {
@Override @Override
public boolean pass(RuleParam param) { public boolean pass(RuleParam param) {
if (param == null){ if (param == null){
......
...@@ -97,7 +97,7 @@ public class AuditResponce { ...@@ -97,7 +97,7 @@ public class AuditResponce {
* 6-vcc贷中交易反欺诈审核 * 6-vcc贷中交易反欺诈审核
* ... * ...
*/ */
@NotNull @NotNull(message = "method不能为空")
private Integer method; private Integer method;
private String isWhiteBlackListHit; private String isWhiteBlackListHit;
......
...@@ -6,8 +6,13 @@ import org.joda.time.format.DateTimeFormat; ...@@ -6,8 +6,13 @@ import org.joda.time.format.DateTimeFormat;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.util.Date; import java.util.Date;
/** /**
...@@ -90,4 +95,66 @@ public class DateUtil { ...@@ -90,4 +95,66 @@ public class DateUtil {
public static DateTime toDateTime(String dateTime, DateTimeUtilFormat dateTimeUtilFormat) { public static DateTime toDateTime(String dateTime, DateTimeUtilFormat dateTimeUtilFormat) {
return DateTimeFormat.forPattern(dateTimeUtilFormat.format).parseLocalDate(dateTime).toDateTimeAtStartOfDay(); return DateTimeFormat.forPattern(dateTimeUtilFormat.format).parseLocalDate(dateTime).toDateTimeAtStartOfDay();
} }
public static Date localDateTimeToDate(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
public static int getDays(Date time) {
long days = ChronoUnit.DAYS.between(
new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(),
time.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
return (int) days;
}
public static boolean between(String startData,String endData){
LocalDate start = LocalDate.of(Integer.parseInt(startData.substring(0,4)) ,
Integer.parseInt(startData.substring(4,6)),
Integer.parseInt(startData.substring(6,8)));
LocalDate end = LocalDate.of(Integer.parseInt(endData.substring(0,4)) ,
Integer.parseInt(endData.substring(4,6)),
Integer.parseInt(endData.substring(6,8)));
return LocalDate.now().isBefore(end) && LocalDate.now().isAfter(start);
}
/**
* 获取两个日期相差的月数
*/
public static int getMonthDiff(String d1, String d2) {
/*Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
c1.setTime(d1);
c2.setTime(d2);
int year1 = c1.get(Calendar.YEAR);
int year2 = c2.get(Calendar.YEAR);
int month1 = c1.get(Calendar.MONTH);
int month2 = c2.get(Calendar.MONTH);
int day1 = c1.get(Calendar.DAY_OF_MONTH);
int day2 = c2.get(Calendar.DAY_OF_MONTH);
// 获取年的差值
int yearInterval = year1 - year2;
// 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数
if (month1 < month2 || month1 == month2 && day1 < day2) {
yearInterval--;
}
// 获取月数差值
int monthInterval = (month1 + 12) - month2;
if (day1 < day2) {
monthInterval--;
}
monthInterval %= 12;
return yearInterval * 12 + monthInterval;*/
String text1 = "2020-08-02";
Temporal temporal1 = LocalDate.parse(d1);
String text2 = "2020-09-03";
Temporal temporal2 = LocalDate.parse(d2);
// 方法返回为相差月份
return (int)ChronoUnit.MONTHS.between(temporal1, temporal2);
}
public static void main(String[] args) {
System.out.println(between("20210722","20310722"));
}
} }
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