Skip to content

Commit

Permalink
Merge pull request #76 from wfh45678/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
wfh45678 authored Mar 12, 2021
2 parents 0eff0f3 + d973738 commit f848a8f
Show file tree
Hide file tree
Showing 42 changed files with 377 additions and 78 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ webapp/node_modules/
.settings
.classpath
.factorypath
/radar-kafka-demo/target/
74 changes: 74 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Risk Engine(Radar)
## Introduction

A real-time risk analysis engine,which can update risk rule in real-time and make it effective immediately.
It applies to the anti-fraud application perfectly.
The project code called Radar, like the code, monitor the transaction at the back.

## FEATURE

* real-time
* visual rule editor
* plugin design
* nosql, easy extended
* simple configuration
* out-of-the-box

## Relation Site
Gitee: https://gitee.com/freshday/radar
Github: https://github.com/wfh45678/radar
Official Site: https://www.91risk.com
Wiki: https://gitee.com/freshday/radar/wikis/home


## Architecture


Server-end: SpringBoot + Mybatis + tkMapper + Mysql + MongoDB + Redis + Groovy + ES + Swagger

Front-end: React(SPA)

### System Component Diagram
![Architecture](https://www.91risk.com/radar/sys_model_arch.png)

## Technology stack
* Springboot:base spring boot 2.x framework.

* Mybatis + tkMapper: data persistence layer framework.

* Mysql : model meta data storage.

* MongoDB: for event data storage.

* ES: risk result data analysis.

* Redis: cache, pub sub when model meta data change.

* Groovy: rule engine.

* Swagger: Rest API.


---

## [manual](https://gitee.com/freshday/radar/wikis/manual)
https://gitee.com/freshday/radar/wikis/manual


## Demo site
[Demo URL:](http://121.36.168.6:6580/) http://121.36.168.6:6580/

## wiki
[WIKI:](https://gitee.com/freshday/radar/wikis/home?sort_id=1637444) https://gitee.com/freshday/radar/wikis/home?sort_id=1637444



## Thanks

千面怪, 烈日下的从容, DerekDingLu, king, sanying2012, 紫泉夜, 玄梦
成书平, 徐帅,郭锐, 王成,马兆永...



## Statement
Copyright © 2019-2021 WangFeiHu
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</parent>
<groupId>com.pgmmers</groupId>
<artifactId>radar</artifactId>
<version>1.0.7-SNAPSHOT</version>
<version>1.0.8-SNAPSHOT</version>
<name>radar</name>
<description>Demo project for Spring Boot</description>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion radar-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>radar</artifactId>
<groupId>com.pgmmers</groupId>
<version>1.0.7-SNAPSHOT</version>
<version>1.0.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>radar-admin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public CommonResult query(@RequestBody ActivationQuery query) {
return activationService.query(query);
}

@GetMapping("/datacolumns/{modelId}")
@GetMapping("/feature/columns/{modelId}")
public CommonResult getDataColumns(@PathVariable Long modelId) {
List<DataColumnInfo> list = new ArrayList<DataColumnInfo>();
// 1、Data
Expand Down Expand Up @@ -124,7 +124,7 @@ public CommonResult getDataColumns(@PathVariable Long modelId) {
return result;
}

@GetMapping("/absColumns/{modelId}")
@GetMapping("/abstraction/columns/{modelId}")
public CommonResult getAbstractionColumns(@PathVariable Long modelId) {
CommonResult result = new CommonResult();
result.setSuccess(true);
Expand All @@ -140,7 +140,7 @@ public CommonResult getAbstractionColumns(@PathVariable Long modelId) {
return result;
}

@GetMapping("/rulecolumns/{modelId}")
@GetMapping("/rule/columns/{modelId}")
public CommonResult getRuleColumns(@PathVariable Long modelId) {
List<DataColumnInfo> list = new ArrayList<>();
List<ActivationVO> listActivation=activationService.listActivation(modelId);
Expand Down Expand Up @@ -185,4 +185,14 @@ private void extractMetaColumn(DataColumnInfo ds, PreItemVO preItem, String json
}
ds.addChildren(preItem.getLabel(), preItem.getDestField(), children);
}

@PostMapping("/disable/{activationId}")
public CommonResult disable(@PathVariable Long activationId) {
return activationService.updateStatus(activationId, 0);
}

@PostMapping("/enable/{activationId}")
public CommonResult enable(@PathVariable Long activationId) {
return activationService.updateStatus(activationId, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ public CommonResult get(@PathVariable Long id) {

@GetMapping("/list")
public CommonResult list(HttpServletRequest request) {
// HttpSession session = request.getSession();
// UserVO user = (UserVO) session.getAttribute("user");
CommonResult result = new CommonResult();
// if (user == null) {
// result.setMsg("session已过期");
// return result;
// }
result.setSuccess(true);
result.getData().put("modelList", modelService.listModel(contextHolder.getContext().getCode(), null));
return result;
Expand All @@ -79,24 +73,13 @@ public CommonResult list(@PathVariable String merchantCode) {
@PostMapping
public CommonResult query(@RequestBody ModelQuery query, HttpServletRequest request) {
CommonResult result = new CommonResult();

// HttpSession session = request.getSession();
// UserVO user = (UserVO) session.getAttribute("user");
// if (user == null) {
// result.setMsg("session已过期");
// return result;
// }
// query.setMerchantCode(user.getCode());
query.setMerchantCode(contextHolder.getContext().getCode());
return modelService.query(query);
}


@PutMapping
public CommonResult save(@RequestBody ModelVO model, HttpServletRequest request) {
// HttpSession session = request.getSession();
// UserVO user = (UserVO) session.getAttribute("user");
// model.setCode(user.getCode());
model.setCode(contextHolder.getContext().getCode());
return modelService.save(model);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public CommonResult query(@RequestBody RuleQuery query) {
}

@PutMapping
public CommonResult save(@RequestBody RuleVO rule, HttpServletRequest request) {
public CommonResult save(@RequestBody RuleVO rule) {
return ruleService.save(rule, contextHolder.getContext().getUsername());
}

Expand Down
2 changes: 1 addition & 1 deletion radar-admin/src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>风控引擎管理平台</title> <link rel="shortcut icon" href="/images/anquan.png"> <!--[if lt IE 10]>
<script src="https://as.alipayobjects.com/g/component/??console-polyfill/0.2.2/index.js,es5-shim/4.5.7/es5-shim.min.js,es5-shim/4.5.7/es5-sham.min.js,html5shiv/3.7.2/html5shiv.min.js,media-match/2.0.2/media.match.min.js"></script>
<![endif]--> <link href="./index.fd241aec-1.css" rel="stylesheet"><link href="./index.fd241aec-2.css" rel="stylesheet"><link href="./index.fd241aec-3.css" rel="stylesheet"></head> <body> <div id="react-content"></div> <script type="text/javascript" src="./main.fd241aec.js"></script></body> </html>
<![endif]--> <link href="./index.da6b2009-1.css" rel="stylesheet"><link href="./index.da6b2009-2.css" rel="stylesheet"><link href="./index.da6b2009-3.css" rel="stylesheet"></head> <body> <div id="react-content"></div> <script type="text/javascript" src="./main.da6b2009.js"></script></body> </html>

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion radar-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>radar</artifactId>
<groupId>com.pgmmers</groupId>
<version>1.0.7-SNAPSHOT</version>
<version>1.0.8-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
public class CryptUtils {

private final static String DES = "DES";
//private final static String MD5 = "MD5";
private final static String MD5 = "MD5";
private final static String SHA = "SHA1";

public static void main(String args[]){
// System.out.println( md5("123") );
System.out.println( md5("123") );
System.out.println( sha("222222") );
}
//
// public static String md5(String source) {
// return encryption(source, MD5);
// }

public static String md5(String source) {
return encryption(source, MD5);
}

public static String sha(String source) {
return encryption(source, SHA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public class GroovyScriptUtil {
* 2016年8月2日
*/
public static GroovyObject loadScript(String script) {
GroovyObject groovyObject = passedClassMap.get(script.hashCode() + "");
GroovyObject groovyObject = passedClassMap.get(CryptUtils.md5(script));
if (groovyObject == null) {
Class groovyClass = groovyClassLoader.parseClass(script);
try {
groovyObject = (GroovyObject) groovyClass.newInstance();
passedClassMap.put(script.hashCode() + "", groovyObject);
passedClassMap.put(CryptUtils.md5(script), groovyObject);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
Expand Down Expand Up @@ -62,6 +62,6 @@ public static Object invokeMethod(String script, String method, Object[] args) {
* 删除不在使用的脚本关联的groovy object, 不然内存有溢出风险。
*/
public static void removeInactiveScript(String script){
passedClassMap.remove(script.hashCode() + "");
passedClassMap.remove(CryptUtils.md5(script));
}
}
2 changes: 1 addition & 1 deletion radar-dal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>radar</artifactId>
<groupId>com.pgmmers</groupId>
<version>1.0.7-SNAPSHOT</version>
<version>1.0.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface ModelDal {

List<ModelVO> listModel(String merchantCode,Integer status);

List<ModelVO> listModel(String merchantCode,Integer status, Boolean isTemplate);
List<ModelVO> listModel(String code,Integer status, Boolean isTemplate);

List<ModelVO> listModel(Integer status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,12 @@ public int copy(ModelVO model) {
}

@Override
public List<ModelVO> listModel(String merchantCode, Integer status,
public List<ModelVO> listModel(String code, Integer status,
Boolean isTemplate) {
Example example = new Example(ModelPO.class);
Example.Criteria criteria = example.createCriteria();
if (!StringUtils.isEmpty(merchantCode)) {
criteria.andEqualTo("code", merchantCode);
if (!StringUtils.isEmpty(code)) {
criteria.andEqualTo("code", code);
}
if (status != null) {
criteria.andEqualTo("status", status);
Expand Down
15 changes: 13 additions & 2 deletions radar-dal/src/main/java/com/pgmmers/radar/vo/model/RuleVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class RuleVO implements Serializable{

private Integer rate;

/**
* 最大得分值.
*/
private Integer max;

@JsonProperty
private JsonNode ruleDefinition;

Expand Down Expand Up @@ -197,6 +202,12 @@ public String getLabel() {
public void setLabel(String label) {
this.label = label;
}



public Integer getMax() {
return max;
}

public void setMax(Integer max) {
this.max = max;
}
}
4 changes: 2 additions & 2 deletions radar-dao/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>radar</artifactId>
<groupId>com.pgmmers</groupId>
<version>1.0.7-SNAPSHOT</version>
<version>1.0.8-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>radar-dao</artifactId>
Expand Down Expand Up @@ -44,7 +44,7 @@
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<version>1.3.7</version>
<configuration>
<configurationFile>
${basedir}/src/main/resources/generator/generatorConfig.xml
Expand Down
11 changes: 9 additions & 2 deletions radar-dao/src/main/java/com/pgmmers/radar/model/PreItemPO.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class PreItemPO {
@Column(name = "PLUGIN")
private String plugin;

/**
* 响应字段配置信息
*/
@Column(name = "CONFIG_JSON")
private String configJson;

Expand Down Expand Up @@ -204,14 +207,18 @@ public void setPlugin(String plugin) {
}

/**
* @return CONFIG_JSON
* 获取响应字段配置信息
*
* @return CONFIG_JSON - 响应字段配置信息
*/
public String getConfigJson() {
return configJson;
}

/**
* @param configJson
* 设置响应字段配置信息
*
* @param configJson 响应字段配置信息
*/
public void setConfigJson(String configJson) {
this.configJson = configJson;
Expand Down
24 changes: 24 additions & 0 deletions radar-dao/src/main/java/com/pgmmers/radar/model/RulePO.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public class RulePO {
@Column(name = "RATE")
private Integer rate;

/**
* 最大值
*/
@Column(name = "MAX")
private Integer max;

/**
* 状态
*/
Expand Down Expand Up @@ -279,6 +285,24 @@ public void setRate(Integer rate) {
this.rate = rate;
}

/**
* 获取最大值
*
* @return MAX - 最大值
*/
public Integer getMax() {
return max;
}

/**
* 设置最大值
*
* @param max 最大值
*/
public void setMax(Integer max) {
this.max = max;
}

/**
* 获取状态
*
Expand Down
Loading

0 comments on commit f848a8f

Please sign in to comment.