package com.pgmmers.radar.service.impl.engine;
import com.pgmmers.radar.enums.AggregateType;
import com.pgmmers.radar.enums.FieldType;
import com.pgmmers.radar.enums.Operator;
import com.pgmmers.radar.enums.StatusType;
import com.pgmmers.radar.service.dnn.Estimator;
import com.pgmmers.radar.service.engine.AggregateCommand;
import com.pgmmers.radar.service.engine.AntiFraudEngine;
import com.pgmmers.radar.service.engine.vo.AbstractionResult;
import com.pgmmers.radar.service.engine.vo.ActivationResult;
import com.pgmmers.radar.service.engine.vo.AdaptationResult;
import com.pgmmers.radar.service.engine.vo.HitObject;
import com.pgmmers.radar.service.engine.vo.RiskObject;
import com.pgmmers.radar.service.impl.dnn.EstimatorContainer;
import com.pgmmers.radar.service.impl.util.JsonParserUtil;
import com.pgmmers.radar.service.model.AbstractionService;
import com.pgmmers.radar.service.model.ActivationService;
import com.pgmmers.radar.service.model.DataListsService;
import com.pgmmers.radar.service.model.EntityService;
import com.pgmmers.radar.service.model.FieldService;
import com.pgmmers.radar.service.model.ModelService;
import com.pgmmers.radar.service.model.RuleService;
import com.pgmmers.radar.util.DateUtils;
import com.pgmmers.radar.util.GroovyScriptUtil;
import com.pgmmers.radar.vo.model.AbstractionVO;
import com.pgmmers.radar.vo.model.ActivationVO;
import com.pgmmers.radar.vo.model.DataListRecordVO;
import com.pgmmers.radar.vo.model.DataListsVO;
import com.pgmmers.radar.vo.model.FieldVO;
import com.pgmmers.radar.vo.model.ModelVO;
import com.pgmmers.radar.vo.model.RuleVO;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Service
public class AntiFraudEngineImpl implements AntiFraudEngine {
private static Logger logger = LoggerFactory.getLogger(AntiFraudEngineImpl.class);
private static Map<Long, Map<String, Object>> dataListCacheMap = new HashMap<>();
@Value("${sys.conf.machine-learning: true}")
private boolean machineLearning;
@Autowired
private EntityService entityService;
@Autowired
private AbstractionService abstractionService;
@Autowired
private ActivationService activationService;
@Autowired
private FieldService fieldService;
@Autowired
private ModelService modelService;
@Autowired
private DataListsService dataListsService;
@Autowired
private AggregateCommand aggregateCommand;
@Autowired
private RuleService ruleService;
@Autowired
private EstimatorContainer estimatorContainer;
@Override
public AbstractionResult executeAbstraction(Long modelId, Map<String, Map<String, ?>> data) {
AbstractionResult result = new AbstractionResult();
// 1. 解析 参数信息
//JSONObject entity = (JSONObject) data.get("entity");
// 2. list abstraction
List<AbstractionVO> abstractions = abstractionService.listAbstraction(modelId);
// 排除没有的定义 abstraction 的情况。
if (abstractions == null || abstractions.size() == 0) {
data.put("abstractions", result.getAbstractionMap());
result.setSuccess(true);
return result;
}
// 3. 按 script 的条件, 分别统计 abstraction
for (AbstractionVO abs : abstractions) {
if (!abs.getStatus().equals(StatusType.ACTIVE.getKey())) {
continue;
}
// abs get aggregate type
String searchField = abs.getSearchField();
searchField = searchField.replace("fields.", "").replace("preItems.", "");
Integer aggregateType = abs.getAggregateType();
Integer dateType = abs.getSearchIntervalType();
Integer interval = abs.getSearchIntervalValue();
String funcionField = abs.getFunctionField();
funcionField = funcionField.replace("fields.", "").replace("preItems.", "");
FieldType functionFieldType = null;
String ruleScript = abs.getRuleScript();
// 获取预加载的黑/白名单集合
Map<String, Object> dataCollectionMap = dataListsService.getDataListMap(modelId);
boolean matched = checkAbstractionScript(ruleScript, data, dataCollectionMap);
if (!matched) {
// 脚本检查不通过,过滤该 abstraction
//data.put(abs.getName(), 0);
result.getAbstractionMap().put(abs.getName(), -1);
continue;
}
ModelVO model = modelService.getModelById(modelId);
String refDateFieldName = model.getReferenceDate();
Date refDate;
try {
Long refDatetimeMills = (Long) data.get("fields").get(refDateFieldName);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(refDatetimeMills);
refDate = c.getTime();
} catch (Exception e) {
e.printStackTrace();
result.setMsg("时间不正确");
return result;
}
if (refDate == null) {
result.setMsg("时间不正确");
return result;
}
Date beginDate = DateUtils.addDate(refDate, dateType, interval * -1).getTime();
Object calResult = null;
Object searchFieldVal = data.get("fields").get(searchField);
if (searchFieldVal == null) {
searchFieldVal = data.get("preItems").get(searchField);
if (searchFieldVal == null) {
searchFieldVal = JsonParserUtil.value(data.get("preItems"), searchField, null);
}
}
if (searchFieldVal == null) {
result.setMsg("search field value eq null!");
return result;
}
if (!StringUtils.isEmpty(funcionField)) {
List<FieldVO> fields = fieldService.listField(modelId);
if (fields == null || fields.size() == 0) {
result.setMsg("no field found!");
return result;
}
for (FieldVO field : fields) {
if (field.getFieldName().equals(funcionField)) {
functionFieldType = FieldType.valueOf(field.getFieldType());
break;
}
}
if (functionFieldType == null) {
// 因为预处理字段没有字段类型,暂时设置为String
// TODO: 目前只有高级函数使用了 functionFieldType。
//result.setMsg("function field type is null");
//return result;
functionFieldType = FieldType.valueOf("STRING");
}
}
switch (aggregateType) {
case AggregateType.COUNT:
calResult = aggregateCommand.count(modelId.toString(), searchField, searchFieldVal, refDateFieldName,
beginDate, refDate);
break;
case AggregateType.DISTINCT_COUNT:
calResult = aggregateCommand.distinctCount(modelId.toString(), searchField, searchFieldVal,
refDateFieldName, beginDate, refDate, funcionField);
break;
case AggregateType.SUM:
calResult = aggregateCommand.sum(modelId.toString(), searchField, searchFieldVal, refDateFieldName,
beginDate, refDate, funcionField);
break;
没有合适的资源?快使用搜索试试~ 我知道了~
基于Java和JavaScript的实时风控引擎Risk Engine设计源码,支持中文反欺诈应用场景
共322个文件
java:255个
xml:24个
png:13个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 85 浏览量
2024-09-29
15:21:10
上传
评论
收藏 27.65MB ZIP 举报
温馨提示
该实时风控引擎Risk Engine源码,采用Java核心开发,辅以CSS、JavaScript和HTML技术,共计322个文件,其中255个Java文件、24个XML文件、13个PNG文件等。该引擎支持中文环境,特别适用于反欺诈场景,提供开箱即用的解决方案,是移动互联网时代风险管理的重要工具。
资源推荐
资源详情
资源评论
收起资源包目录
基于Java和JavaScript的实时风控引擎Risk Engine设计源码,支持中文反欺诈应用场景 (322个子文件)
index.ba8e3789-2.css 208KB
index.ba8e3789-1.css 189KB
index.ba8e3789-3.css 73KB
moble_info.csv 15.59MB
ip2region.db 6.74MB
spring.factories 587B
.gitignore 486B
index.html 778B
AntiFraudEngineImpl.java 18KB
ModelDalImpl.java 17KB
ModelServiceImpl.java 13KB
EventApiController.java 12KB
EventServiceImpl.java 12KB
DataListsServiceImpl.java 11KB
DataListDalImpl.java 10KB
AggregateCommandImpl.java 10KB
MapStructTest.java 9KB
ExcelImportUtil.java 8KB
RuleServiceImpl.java 8KB
ActivationApiController.java 7KB
SearchEngineServiceImpl.java 7KB
PluginTest.java 6KB
RulePO.java 6KB
UserApiController.java 6KB
AbstractionPO.java 6KB
ReflectUtil.java 6KB
RiskAnalysisEngineServiceImpl.java 6KB
ExcelUtils.java 6KB
AggregateCommand.java 5KB
RuleDalImpl.java 5KB
AbstractionApiController.java 5KB
ModelPO.java 5KB
CacheServiceImpl.java 5KB
PluginServiceImpl.java 5KB
PreItemPO.java 5KB
ActivationServiceImpl.java 5KB
ZipUtils.java 5KB
ModelApiController.java 5KB
AntiFraudServiceImpl.java 5KB
TensorDnnEstimator.java 5KB
JsonParserUtil.java 4KB
ActivationPO.java 4KB
AuthInterceptor.java 4KB
CaptchaUtil.java 4KB
RuleHistoryPO.java 4KB
CommonApiController.java 4KB
RandomValidateCode.java 4KB
MobileInfoServiceImpl.java 4KB
DataListApiController.java 4KB
DataListRecordApiController.java 4KB
AbstractionDalImpl.java 4KB
FieldPO.java 4KB
CryptUtils.java 4KB
RedisTemplateServiceImpl.java 4KB
FieldServiceImpl.java 4KB
AbstractionServiceImpl.java 4KB
ModelConfDalImpl.java 4KB
KafkaReceiver.java 4KB
ValidateServiceImpl.java 4KB
PageVO.java 4KB
PreItemDalImpl.java 3KB
AbstractionVO.java 3KB
DataListsPO.java 3KB
PreItemServiceImpl.java 3KB
AbstractionVO2.java 3KB
GPS2LOCATION.java 3KB
UserPO.java 3KB
FieldDalImpl.java 3KB
DateUtils.java 3KB
JsonWebTokenService.java 3KB
ExcelColumn.java 3KB
RuleVO.java 3KB
SwaggerConfig.java 3KB
ActivationDalImpl.java 3KB
ExportExcelInfo.java 3KB
ModelConfVO.java 3KB
EntityServiceImpl.java 3KB
JsonUtils.java 3KB
MobileLocationUtil.java 3KB
MobileInfoPO.java 3KB
MobileInfoDalImpl.java 3KB
MainController.java 3KB
ModelConfigApiController.java 3KB
ModelVO.java 3KB
RuleApiController.java 3KB
GlobalExceptionHandler.java 3KB
ModelConfPO.java 3KB
DataListMetaPO.java 3KB
PreItemVO.java 3KB
IP2LOCATION.java 3KB
PageResult.java 3KB
EsConfig.java 2KB
EsConfig.java 2KB
ValidateUtil.java 2KB
RedisConfig.java 2KB
RedisConfig.java 2KB
ActivationVO.java 2KB
DataListRecordPO.java 2KB
UserServiceImpl.java 2KB
MD5Utils.java 2KB
共 322 条
- 1
- 2
- 3
- 4
资源评论
wjs2024
- 粉丝: 2089
- 资源: 5429
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功