浏览代码

风控体系代码提交

zjy 1 月之前
父节点
当前提交
55611fc1c7

+ 0 - 6
alien-gateway/pom.xml

@@ -189,12 +189,6 @@
             <artifactId>jaxb-api</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>shop.alien</groupId>
-            <artifactId>alien-config</artifactId>
-            <version>1.0.0</version>
-        </dependency>
-
     </dependencies>
 
     <build>

+ 2 - 2
alien-gateway/src/main/java/shop/alien/gateway/AlienGatewayApplication.java

@@ -13,8 +13,8 @@ import org.springframework.context.annotation.ComponentScan;
  * @version 1.0
  * @date 2025/1/21 16:58
  */
-@ComponentScan({"shop.alien.gateway.*", "shop.alien.config.properties"})
-@MapperScan({"shop.alien.gateway.mapper", "shop.alien.mapper"})
+@ComponentScan({"shop.alien.gateway.*"})
+@MapperScan({"shop.alien.gateway.mapper"})
 @EnableFeignClients(basePackages = "shop.alien.gateway.feign")
 @SpringBootApplication
 public class AlienGatewayApplication {

+ 120 - 0
alien-gateway/src/main/java/shop/alien/gateway/config/RiskControlProperties.java

@@ -0,0 +1,120 @@
+package shop.alien.gateway.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@RefreshScope
+@ConfigurationProperties(prefix = "risk-control")
+public class RiskControlProperties {
+
+    /**
+     * 洗钱嫌疑规则配置
+     */
+    private MoneyLaundering moneyLaundering = new MoneyLaundering();
+
+    /**
+     * 账号异常规则配置
+     */
+    private AccountAbnormal accountAbnormal = new AccountAbnormal();
+
+    /**
+     * 交易欺诈规则配置
+     */
+    private TradeFraud tradeFraud = new TradeFraud();
+
+    /**
+     * 异常发布规则配置
+     */
+    private AbnormalPublish abnormalPublish = new AbnormalPublish();
+
+    @Data
+    public static class MoneyLaundering {
+        /**
+         * 每天交易次数阈值
+         */
+        private int dailyCount = 5;
+
+        /**
+         * 每笔交易金额阈值(元)
+         */
+        private double amountThreshold = 200.0;
+
+        /**
+         * 风险类型
+         */
+        private String riskType = "洗钱嫌疑";
+
+        /**
+         * 检测指标
+         */
+        private String detectIndicator = "高频高价交易";
+    }
+
+    @Data
+    public static class AccountAbnormal {
+        /**
+         * 24小时内同一设备/mac注册账号数量阈值
+         */
+        private int regCount24h = 3;
+
+        /**
+         * 风险类型
+         */
+        private String riskType = "账号异常";
+
+        /**
+         * 检测指标
+         */
+        private String detectIndicator = "同一设备24小时内注册超过3个账号";
+    }
+
+    @Data
+    public static class TradeFraud {
+        /**
+         * 24小时内发布成功记录次数阈值
+         */
+        private int publishCount24h = 3;
+
+        /**
+         * 时间窗口(小时)
+         */
+        private int timeWindowHours = 24;
+
+        /**
+         * 风险类型
+         */
+        private String riskType = "交易欺诈";
+
+        /**
+         * 检测指标
+         */
+        private String detectIndicator = "用户频繁修改商品";
+    }
+
+    @Data
+    public static class AbnormalPublish {
+        /**
+         * 24小时内发布同类商品数量阈值
+         */
+        private int sameCategoryCount24h = 10;
+        
+        /**
+         * 时间窗口(小时)
+         */
+        private int timeWindowHours = 24;
+
+        /**
+         * 风险类型
+         */
+        private String riskType = "异常发布";
+
+        /**
+         * 检测指标
+         */
+        private String detectIndicator = "短时间大量发布同类商品";
+    }
+}

+ 40 - 0
alien-gateway/src/main/java/shop/alien/gateway/mapper/SecondRiskControlRecordMapper.java

@@ -0,0 +1,40 @@
+package shop.alien.gateway.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import shop.alien.entity.second.SecondRiskControlRecord;
+import shop.alien.entity.second.vo.SecondRiskControlRecordVo;
+
+import java.util.List;
+
+/**
+ * 二手商品风控记录映射器
+ */
+@Mapper
+public interface SecondRiskControlRecordMapper extends BaseMapper<SecondRiskControlRecord> {
+
+
+    @Select(" select r.*, case when r.rule_type = 1 then '洗钱嫌疑' when r.rule_type = 2 then '账号异常' " +
+            " when r.rule_type = 3 then '交易欺诈' when r.rule_type = 4 then '异常发布' end ruleTypeName,  " +
+            " case when r.rule_type = 1 then '高频高价交易' when r.rule_type = 2 then '同一设备/mac 24小时内注册超过3个账号' " +
+            " when r.rule_type = 3 then '用户频繁修改商品' when r.rule_type = 4 then '短时间大量发布同类商品' end ruleName, " +
+            " case when r.rule_type = 1 or r.rule_type = 2 then '中风险' when r.rule_type = 3 or r.rule_type = 4 then '高风险' end ruleRisk,  " +
+            " case when r.risk_status = 0 then '待处理' when r.risk_status = 1 then '已处理' " +
+            " when r.risk_status = 2 then '已忽略' end riskStatusName,  " +
+            " case when r.rule_type = 1 or r.rule_type = 3 or r.rule_type = 4 then u.user_phone " +
+            " else '--' end userPhone " +
+            " from second_risk_control_record r left join life_user u on r.user_id = u.id " +
+            " ${ew.customSqlSegment} ")
+    IPage<SecondRiskControlRecordVo> queryRiskControlRecords(IPage<SecondRiskControlRecordVo> page, @Param(Constants.WRAPPER) QueryWrapper<SecondRiskControlRecordVo> queryWrapper);
+
+
+    @Select(" select * from second_risk_control_record " +
+            " WHERE created_time BETWEEN DATE_FORMAT(#{starDate}, '%Y-%m-%d %H:%i:%s') " +
+            " AND DATE_FORMAT(#{endDate}, '%Y-%m-%d %H:%i:%s') AND business_id = #{macIp} ")
+    List<SecondRiskControlRecord> selectByBusinessId(@Param("starDate") String starDate, @Param("endDate") String endDate, @Param("macIp") String macIp);
+}

+ 2 - 2
alien-gateway/src/main/java/shop/alien/gateway/service/LifeUserService.java

@@ -8,16 +8,16 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import shop.alien.config.properties.RiskControlProperties;
 import shop.alien.entity.second.LifeUserLog;
 import shop.alien.entity.second.SecondRiskControlRecord;
 import shop.alien.entity.store.LifeUser;
 import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.gateway.config.BaseRedisService;
+import shop.alien.gateway.config.RiskControlProperties;
 import shop.alien.gateway.feign.SecondServiceFeign;
 import shop.alien.gateway.mapper.LifeUserLogMapper;
 import shop.alien.gateway.mapper.LifeUserMapper;
-import shop.alien.mapper.second.SecondRiskControlRecordMapper;
+import shop.alien.gateway.mapper.SecondRiskControlRecordMapper;
 import shop.alien.util.common.JwtUtil;
 
 import java.time.LocalDateTime;