Mr.qian hace 1 mes
padre
commit
7012e2e6df

+ 1 - 1
cif-service/src/main/java/com/txz/cif/configurer/ShardingSphereConfig.java → cif-service/src/main/java/com/txz/cif/configurer/sharding/ShardingSphereConfig.java

@@ -1,4 +1,4 @@
-package com.txz.cif.configurer;
+package com.txz.cif.configurer.sharding;
 
 import com.zaxxer.hikari.HikariDataSource;
 import org.apache.shardingsphere.api.config.sharding.ShardingRuleConfiguration;

+ 1 - 2
cif-service/src/main/java/com/txz/cif/configurer/TimeShardingAlg.java → cif-service/src/main/java/com/txz/cif/configurer/sharding/TimeShardingAlg.java

@@ -1,4 +1,4 @@
-package com.txz.cif.configurer;
+package com.txz.cif.configurer.sharding;
 
 import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
@@ -14,7 +14,6 @@ public class TimeShardingAlg implements PreciseShardingAlgorithm<Date> {
         java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMM");
         String tableSuffix = sdf.format(dateValue);
         
-        // 查找匹配的表名
         for (String tableName : availableTargetNames) {
             if (tableName.endsWith(tableSuffix)) {
                 return tableName;

+ 6 - 7
cif-service/src/main/java/com/txz/cif/configurer/UserIdShardingAlg.java → cif-service/src/main/java/com/txz/cif/configurer/sharding/UserIdShardingAlg.java

@@ -1,18 +1,17 @@
-package com.txz.cif.configurer;
+package com.txz.cif.configurer.sharding;
 
 import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
 import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
 
 import java.util.Collection;
 
-public class UserIdShardingAlg implements PreciseShardingAlgorithm<String> {
+public class UserIdShardingAlg implements PreciseShardingAlgorithm<Long> {
     
     @Override
-    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<String> shardingValue) {
-        String userId = String.valueOf(shardingValue.getValue());
-        String last4Digits = userId;
-        if (userId.length() >= 4) {
-            last4Digits = userId.substring(userId.length() - 4);
+    public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
+        String last4Digits = String.valueOf(shardingValue.getValue());
+        if (last4Digits.length() >= 4) {
+            last4Digits = last4Digits.substring(last4Digits.length() - 4);
         }
         
         long shardValue = Long.parseLong(last4Digits);

+ 16 - 0
cif-service/src/main/java/com/txz/cif/dao/ShardingMapper.java

@@ -0,0 +1,16 @@
+package com.txz.cif.dao;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Update;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/10/9
+ */
+@Mapper
+public interface ShardingMapper {
+    
+    @Update("${sql}")
+    void createTable(@Param("sql") String sql);
+}

+ 21 - 54
cif-service/src/main/java/com/txz/cif/task/GeneralJob.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import com.txz.cif.configurer.Parameters;
+import com.txz.cif.dao.ShardingMapper;
 import com.txz.cif.dubbo.client.OrderDubboServiceClient;
 import com.txz.cif.model.RedEnvelope;
 import com.txz.cif.service.DayCutService;
@@ -49,10 +50,13 @@ public class GeneralJob {
     
     @Resource
     private RechargeRecordService rechargeRecordService;
-
+    
     @Resource
     private RedEnvelopeService redEnvelopeService;
     
+    @Resource
+    private ShardingMapper shardingMapper;
+    
     /**
      * 日切
      */
@@ -68,11 +72,14 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
+    
     /**
      * 结算
+     *
      * @param param
+     *
      * @return
+     *
      * @throws Exception
      */
     @XxlJob("settle")
@@ -80,13 +87,13 @@ public class GeneralJob {
         try {
             logger.info("【执行结算】开始");
             Condition c = new Condition(RedEnvelope.class);
-            c.createCriteria().andEqualTo("status",1).andLessThanOrEqualTo("settleTime", DateUtil.now());
+            c.createCriteria().andEqualTo("status", 1).andLessThanOrEqualTo("settleTime", DateUtil.now());
             List<RedEnvelope> redEnvelopes = redEnvelopeService.findByCondition(c);
-            if (CollUtil.isNotEmpty(redEnvelopes)){
-                for (RedEnvelope r: redEnvelopes){
+            if (CollUtil.isNotEmpty(redEnvelopes)) {
+                for (RedEnvelope r : redEnvelopes) {
                     try {
                         redEnvelopeService.settle(r);
-                    }catch (Exception e) {
+                    } catch (Exception e) {
                         logger.error("【执行结算】异常:e{}", e);
                         return ReturnT.FAIL;
                     }
@@ -112,7 +119,7 @@ public class GeneralJob {
         String ret = HttpRequest.post("https://chynet01.azureedge.net/user/checkin").cookie(cookie).timeout(-1).execute().body();
         logger.error("[checkin]:" + ret);
         
-
+        
         return ReturnT.SUCCESS;
     }
     
@@ -156,7 +163,7 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
+    
     @XxlJob("activityStatusJudgmentTimedTask")
     public ReturnT<String> activityStatusJudgmentTimedTask(String param) throws Exception {
         try {
@@ -169,8 +176,8 @@ public class GeneralJob {
         }
         return ReturnT.SUCCESS;
     }
-
-
+    
+    
     @XxlJob("closeRecharge")
     public ReturnT<String> closeRecharge() throws Exception {
         try {
@@ -186,42 +193,22 @@ public class GeneralJob {
     
     /**
      * 定时创建分表任务
-     * 用于创建未来3个月的分表,确保分表在使用前已经创建好
      */
     @XxlJob("createFutureTables")
     public ReturnT<String> createFutureTables(String param) throws Exception {
         try {
             logger.info("【创建未来分表任务】开始");
             
-            // 获取当前日期和未来3个月的日期
-            Date now = new Date();
-            Date nextMonth = DateUtil.offsetMonth(now, 1);
-            Date nextTwoMonths = DateUtil.offsetMonth(now, 2);
-            Date nextThreeMonths = DateUtil.offsetMonth(now, 3);
+            String currentMonthSuffix = DateUtil.format(new Date(), "yyyyMM");
             
-            // 构造表名后缀
-            String currentMonthSuffix = DateUtil.format(now, "yyyyMM");
-            String nextMonthSuffix = DateUtil.format(nextMonth, "yyyyMM");
-            String nextTwoMonthsSuffix = DateUtil.format(nextTwoMonths, "yyyyMM");
-            String nextThreeMonthsSuffix = DateUtil.format(nextThreeMonths, "yyyyMM");
-            
-            // 需要创建的表名列表
-            String[] tableSuffixes = {currentMonthSuffix, nextMonthSuffix, nextTwoMonthsSuffix, nextThreeMonthsSuffix};
-            
-            // 表名前缀
             String[] tablePrefixes = {"c_account_flow_", "c_flow_", "c_red_envelope_"};
             
-            // 数据源
-            String[] dataSources = {"ds0", "ds1"};
+            String[] dataSources = {"cif_0", "cif_1"};
             
-            // 创建表的逻辑
             for (String dataSource : dataSources) {
                 for (String tablePrefix : tablePrefixes) {
-                    for (String tableSuffix : tableSuffixes) {
-                        String tableName = tablePrefix + tableSuffix;
-                        // 这里应该调用实际的建表方法
-                        createTableIfNotExists(dataSource, tableName);
-                    }
+                    String sql = "CREATE TABLE IF NOT EXISTS " + dataSource + "." + tablePrefix + currentMonthSuffix + " LIKE cif.c_account_flow";
+                    shardingMapper.createTable(sql);
                 }
             }
             
@@ -233,26 +220,6 @@ public class GeneralJob {
         return ReturnT.SUCCESS;
     }
     
-    /**
-     * 创建表(如果不存在)
-     * @param dataSource 数据源名称
-     * @param tableName 表名
-     */
-    private void createTableIfNotExists(String dataSource, String tableName) {
-        // 这里应该实现实际的建表逻辑
-        // 可以通过JDBC或者调用数据库管理服务来创建表
-        logger.info("检查并创建表: {} 在数据源: {}", tableName, dataSource);
-        
-        // 示例建表SQL(根据实际表结构调整)
-        /*
-        CREATE TABLE IF NOT EXISTS table_name (
-            id BIGINT AUTO_INCREMENT PRIMARY KEY,
-            ...
-        )
-        */
-        
-        // 实际实现应该连接到对应数据源执行建表语句
-    }
     
     public static void main(String[] args) {
         //        int quhao = 154;

+ 0 - 52
cif-service/src/main/java/com/txz/cif/web/ro/TFPayNotifyDTO.java

@@ -1,52 +0,0 @@
-package com.txz.cif.web.ro;
-
-import lombok.Data;
-
-/**
- * @author: MTD®️
- * @date: 2025/9/1
- */
-
-@Data
-public class TFPayNotifyDTO {
-    
-    /**
-     * 商户编号 - 平台分配商户号
-     */
-    private String memberid;
-    
-    /**
-     * 商户订单号 - 订单号唯一, 字符长度20
-     */
-    private String orderid;
-    
-    /**
-     * 订单最终金额 - 订单金额 单位:元
-     */
-    private String amount;
-    
-    /**
-     * 平台订单号
-     */
-    private String transaction_id;
-    
-    /**
-     * 交易成功时间 - 时间格式:Y-m-d H:i:s
-     */
-    private String datetime;
-    
-    /**
-     * 交易状态 - "00" 为成功
-     */
-    private String returncode;
-    
-    /**
-     * 扩展返回 - 商户附加数据返回
-     */
-    private String attach;
-    
-    /**
-     * 签名
-     */
-    private String sign;
-}

+ 0 - 71
cif-service/src/main/java/com/txz/cif/web/ro/TFWithdrawCallbackDTO.java

@@ -1,71 +0,0 @@
-package com.txz.cif.web.ro;
-
-import lombok.Data;
-
-/**
- * @author: MTD®️
- * @date: 2025/9/3
- */
-@Data
-public class TFWithdrawCallbackDTO {
-    
-    /**
-     * 商户编号 - 平台分配商户号
-     */
-    private String memberid;
-    
-    /**
-     * 商户订单号 - 订单号唯一, 字符长度20
-     */
-    private String orderid;
-    
-    /**
-     * 订单金额 - 订单金额 单位:元
-     */
-    private String amount;
-    
-    /**
-     * 平台订单号
-     */
-    private String transaction_id;
-    
-    /**
-     * 用户姓名 - 如:张三
-     */
-    private String pay_username;
-    
-    /**
-     * 银行账号 - 如:银行卡号码
-     */
-    private String pay_banknumber;
-    
-    /**
-     * 银行名称 - 如:工商银行
-     */
-    private String pay_bankname;
-    
-    /**
-     * 交易成功时间 - 时间格式:Y-m-d H:i:s
-     */
-    private String datetime;
-    
-    /**
-     * 交易状态 - 1为成功,-1失败,0处理中
-     */
-    private String returncode;
-    
-    /**
-     * 订单描述 - 如:失败原因
-     */
-    private String remark;
-    
-    /**
-     * 扩展返回 - 商户附加数据返回
-     */
-    private String attach;
-    
-    /**
-     * 签名
-     */
-    private String sign;
-}

+ 14 - 1
cif-service/src/main/resources/logback.xml

@@ -18,7 +18,7 @@
             <!-- rollover daily -->
             <fileNamePattern>${LOG_HOME}/log.cif.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
             <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
-            <maxFileSize>2GB</maxFileSize>
+            <maxFileSize>50MB</maxFileSize>
             <maxHistory>2</maxHistory>
         </rollingPolicy>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
@@ -73,6 +73,19 @@
         <appender-ref ref="ASYNC_ERROR" />
     </root>
 
+
+
+    <!-- 关闭Netty日志 -->
+    <logger name="io.netty" level="OFF" additivity="false"/>
+    <!-- 其他日志配置,比如设置根日志级别、日志输出目的地等 -->
+    <root level="info">
+        <appender-ref ref="STDOUT"/>
+    </root>
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
     <!--日志异步到数据库 -->
     <!--<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">-->
     <!--&lt;!&ndash;日志异步到数据库 &ndash;&gt;-->

+ 2 - 3
cif-service/src/main/resources/mapper/FlowMapper.xml

@@ -23,12 +23,11 @@
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
   </resultMap>
   
-  <!-- 确保查询中包含分片键user_id -->
   <select id="countByUserId" resultType="java.lang.Integer">
     SELECT COUNT(DISTINCT user_id) from  c_flow 
     WHERE type = #{type} 
-    and create_time > #{startTime} 
-    and create_time < #{endTime}
+    and create_time &gt; #{startTime} 
+    and create_time &lt; #{endTime}
     and user_id = #{userId}
   </select>
 </mapper>

+ 70 - 0
cif-service/src/test/java/com/txz/cif/service/AccountFlowServiceTest.java

@@ -0,0 +1,70 @@
+package com.txz.cif.service;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.model.AccountFlow;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class AccountFlowServiceTest {
+
+    @Resource
+    private AccountFlowService accountFlowService;
+
+    @Test
+    public void testSumOccur() {
+        String aliases = "101";
+        int type = 1;
+        String startTime = "2025-10-01 00:00:00";
+        String endTime = "2025-10-10 23:59:59";
+        Long userId = 1L;
+        
+        BigDecimal result = accountFlowService.sumOccur(aliases, type, startTime, endTime, userId);
+        assertNotNull(result);
+    }
+
+    @Test
+    public void testSaveAccountFlow() {
+        AccountFlow accountFlow = new AccountFlow();
+        accountFlow.setAliases("101");
+        accountFlow.setBizNo("TEST001");
+        accountFlow.setAccountId(10001L);
+        accountFlow.setUserId(1L);
+        accountFlow.setAmount(new BigDecimal("100.00"));
+        accountFlow.setBalance(new BigDecimal("500.00"));
+        accountFlow.setFreezeAmount(new BigDecimal("50.00"));
+        accountFlow.setType(1);
+        accountFlow.setBizType(1001);
+        accountFlow.setFlowType(1);
+        
+        accountFlowService.save(accountFlow);
+        assertNotNull(accountFlow.getId());
+    }
+
+    @Test
+    public void testFindAccountFlow() {
+        AccountFlow accountFlow = accountFlowService.findById(1L);
+        if (accountFlow != null) {
+            assertNotNull(accountFlow.getId());
+            assertNotNull(accountFlow.getAliases());
+        }
+    }
+}

+ 76 - 0
cif-service/src/test/java/com/txz/cif/service/FlowServiceTest.java

@@ -0,0 +1,76 @@
+package com.txz.cif.service;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.dto.Result;
+import com.txz.cif.model.Flow;
+import com.txz.cif.param.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class FlowServiceTest {
+
+    @Resource
+    private FlowService flowService;
+
+    @Test
+    public void testCountByUserId() {
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("type", 1);
+        map.put("startTime", "2025-10-01 00:00:00");
+        map.put("endTime", "2025-10-10 23:59:59");
+        map.put("userId", 1L);
+        
+        Integer count = flowService.countByUserId(map);
+        assertNotNull(count);
+    }
+
+    @Test
+    public void testSaveFlow() {
+        Flow flow = new Flow();
+        flow.setBizNo("TEST001");
+        flow.setBizId("BIZ001");
+        flow.setDebitAccount(10001L);
+        flow.setUserId(1L);
+        flow.setCreditAccount(10002L);
+        flow.setAmount(new BigDecimal("100.00"));
+        flow.setBalance(new BigDecimal("500.00"));
+        flow.setType(1);
+        flow.setBizType(1001);
+        flow.setTransTime(new Date());
+        flow.setCreateTime(new Date());
+        flow.setUpdateTime(new Date());
+        
+        flowService.save(flow);
+        assertNotNull(flow.getId());
+    }
+
+    @Test
+    public void testFindFlow() {
+        Flow flow = flowService.findById(1L);
+        if (flow != null) {
+            assertNotNull(flow.getId());
+            assertNotNull(flow.getBizNo());
+        }
+    }
+}

+ 96 - 0
cif-service/src/test/java/com/txz/cif/service/RedEnvelopeServiceTest.java

@@ -0,0 +1,96 @@
+package com.txz.cif.service;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.dto.EarningsDTO;
+import com.txz.cif.dto.Result;
+import com.txz.cif.model.RedEnvelope;
+import com.txz.cif.web.bo.UserTopBo;
+import com.txz.cif.web.para.RedEnvelopeParam;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class RedEnvelopeServiceTest {
+
+    @Resource
+    private RedEnvelopeService redEnvelopeService;
+
+    @Test
+    public void testSumWithDay() {
+        String day = "2025-10-01 00:00:00";
+        Long userId = 1L;
+        Integer type = 1;
+        
+        BigDecimal result = redEnvelopeService.sumWithDay(day, userId, type);
+        assertNotNull(result);
+    }
+
+    @Test
+    public void testSumByStatus() {
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("status", 1);
+        map.put("bizType", 5001);
+        map.put("startTime", "2025-10-01 00:00:00");
+        map.put("endTime", "2025-10-10 23:59:59");
+        map.put("userId", 1L);
+        
+        BigDecimal result = redEnvelopeService.sumByStatus(map);
+        assertNotNull(result);
+    }
+
+    @Test
+    public void testSaveRedEnvelope() {
+        RedEnvelope redEnvelope = new RedEnvelope();
+        redEnvelope.setOrderNo("ORDER001");
+        redEnvelope.setTranNo("TRAN001");
+        redEnvelope.setUserId(1L);
+        redEnvelope.setAmount(new BigDecimal("100.00"));
+        redEnvelope.setBalance(new BigDecimal("500.00"));
+        redEnvelope.setDebitAccount(10001L);
+        redEnvelope.setCreditAccount(10002L);
+        redEnvelope.setStatus(1);
+        redEnvelope.setBizType(5001);
+        redEnvelope.setTransTime(new Date());
+        redEnvelope.setSettleTime(new Date());
+        redEnvelope.setCreateUser("testUser");
+        redEnvelope.setUpdateUser("testUser");
+        redEnvelope.setUpdateTime(new Date());
+        redEnvelope.setCreateTime(new Date());
+        redEnvelope.setName("Test User");
+        redEnvelope.setPhoneNo("13800138000");
+        redEnvelope.setMemo("Test memo");
+        
+        redEnvelopeService.save(redEnvelope);
+        assertNotNull(redEnvelope.getId());
+    }
+
+    @Test
+    public void testFindRedEnvelope() {
+        RedEnvelope redEnvelope = redEnvelopeService.findById(1L);
+        if (redEnvelope != null) {
+            assertNotNull(redEnvelope.getId());
+            assertNotNull(redEnvelope.getOrderNo());
+        }
+    }
+}

+ 81 - 0
cif-service/src/test/java/com/txz/cif/sharding/AccountFlowMapperTest.java

@@ -0,0 +1,81 @@
+package com.txz.cif.sharding;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.dao.AccountFlowMapper;
+import com.txz.cif.model.AccountFlow;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class AccountFlowMapperTest {
+    
+    @Resource
+    private AccountFlowMapper accountFlowMapper;
+    
+    @Test
+    public void testSumOccur() {
+        Map<String, Object> map = new HashMap<>();
+        map.put("aliases", "101");
+        map.put("type", 1);
+        map.put("startTime", "2025-10-01 00:00:00");
+        map.put("endTime", "2025-10-10 23:59:59");
+        map.put("userId", 1L);
+        
+        BigDecimal result = accountFlowMapper.sumOccur(map);
+        assertNotNull(result);
+    }
+    
+    @Test
+    public void testInsertAccountFlow() {
+        AccountFlow accountFlow = AccountFlow.builder()
+                .aliases("101")
+                .transTime(new Date())
+                .bizNo("TEST001")
+                .flowId(1001L)
+                .bizId("BIZ001")
+                .accountId(10001L)
+                .userId(1L)
+                .amount(new BigDecimal("100.00"))
+                .balance(new BigDecimal("500.00"))
+                .freezeAmount(new BigDecimal("50.00"))
+                .type(1)
+                .bizType(1001)
+                .flowType(1)
+                .createTime(new Date())
+                .build();
+        
+        accountFlowMapper.insert(accountFlow);
+        accountFlow.setUserId(2L);
+        accountFlowMapper.insert(accountFlow);
+    }
+    
+    @Test
+    public void testSelectAccountFlow() {
+        AccountFlow accountFlow = accountFlowMapper.selectByPrimaryKey(1L);
+        if (accountFlow != null) {
+            assertNotNull(accountFlow.getId());
+            assertNotNull(accountFlow.getAliases());
+        }
+    }
+}

+ 79 - 0
cif-service/src/test/java/com/txz/cif/sharding/FlowMapperTest.java

@@ -0,0 +1,79 @@
+package com.txz.cif.sharding;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.dao.FlowMapper;
+import com.txz.cif.model.Flow;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class FlowMapperTest {
+
+    @Resource
+    private FlowMapper flowMapper;
+
+    @Test
+    public void testCountByUserId() {
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("type", 1);
+        map.put("startTime", "2025-10-01 00:00:00");
+        map.put("endTime", "2025-10-10 23:59:59");
+        map.put("userId", 1L);
+        
+        Integer count = flowMapper.countByUserId(map);
+        assertNotNull(count);
+    }
+
+    @Test
+    public void testInsertFlow() {
+        Flow flow = Flow.builder()
+                .freezdId("F001")
+                .createUser("testUser")
+                .bizNo("TEST001")
+                .bizId("BIZ001")
+                .debitAccount(10001L)
+                .userId(1L)
+                .creditAccount(10002L)
+                .freezeAmount(new BigDecimal("50.00"))
+                .balance(new BigDecimal("500.00"))
+                .type(1)
+                .amount(new BigDecimal("100.00"))
+                .bizType(1001)
+                .transTime(new Date())
+                .createTime(new Date())
+                .updateTime(new Date())
+                .build();
+        
+        flowMapper.insert(flow);
+        assertNotNull(flow.getId());
+    }
+
+    @Test
+    public void testSelectFlow() {
+        Flow flow = flowMapper.selectByPrimaryKey(1L);
+        if (flow != null) {
+            assertNotNull(flow.getId());
+            assertNotNull(flow.getBizNo());
+        }
+    }
+}

+ 33 - 0
cif-service/src/test/java/com/txz/cif/sharding/GeneralJobTest.java

@@ -0,0 +1,33 @@
+package com.txz.cif.sharding;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.task.GeneralJob;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class GeneralJobTest {
+    
+    @Autowired
+    private GeneralJob generalJob;
+    
+    @Test
+    public void testCreateFutureTables() throws Exception {
+        generalJob.createFutureTables("");
+    }
+    
+}

+ 94 - 0
cif-service/src/test/java/com/txz/cif/sharding/RedEnvelopeMapperTest.java

@@ -0,0 +1,94 @@
+package com.txz.cif.sharding;
+
+import com.txz.cif.CifApplication;
+import com.txz.cif.dao.RedEnvelopeMapper;
+import com.txz.cif.model.RedEnvelope;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.HashMap;
+
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = CifApplication.class)
+@WebAppConfiguration
+@TestPropertySource(properties = {
+        "spring.cloud.nacos.discovery.group=qly",
+        "dubbo.registry.group=qly",
+        "dev.nacos=124.222.152.234:8848",
+        "mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl",
+        "mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl"
+})
+public class RedEnvelopeMapperTest {
+
+    @Resource
+    private RedEnvelopeMapper redEnvelopeMapper;
+
+    @Test
+    public void testSumWithDay() {
+        String day = "2025-10-01 00:00:00";
+        Long userId = 1L;
+        Integer type = 1;
+        
+        BigDecimal result = redEnvelopeMapper.sumWithDay(day, userId, type);
+        assertNotNull(result);
+    }
+
+    @Test
+    public void testSumByStatus() {
+        HashMap<String, Object> map = new HashMap<>();
+        map.put("status", 1);
+        map.put("bizType", 5001);
+        map.put("startTime", "2025-10-01 00:00:00");
+        map.put("endTime", "2025-10-10 23:59:59");
+        map.put("userId", 1L);
+        
+        BigDecimal result = redEnvelopeMapper.sumByStatus(map);
+        assertNotNull(result);
+    }
+
+    @Test
+    public void testInsertRedEnvelope() {
+        RedEnvelope redEnvelope = RedEnvelope.builder()
+                .orderNo("ORDER001")
+                .tranNo("TRAN001")
+                .userId(1L)
+                .amount(new BigDecimal("100.00"))
+                .balance(new BigDecimal("500.00"))
+                .debitAccount(10001L)
+                .creditAccount(10002L)
+                .status(1)
+                .bizType(5001)
+                .transTime(new Date())
+                .settleTime(new Date())
+                .createUser("testUser")
+                .updateUser("testUser")
+                .updateTime(new Date())
+                .createTime(new Date())
+                .version("1.0")
+                .name("Test User")
+                .phoneNo("13800138000")
+                .memo("Test memo")
+                .build();
+        
+        redEnvelopeMapper.insert(redEnvelope);
+        assertNotNull(redEnvelope.getId());
+    }
+
+    @Test
+    public void testSelectRedEnvelope() {
+        RedEnvelope redEnvelope = redEnvelopeMapper.selectByPrimaryKey(1L);
+        if (redEnvelope != null) {
+            assertNotNull(redEnvelope.getId());
+            assertNotNull(redEnvelope.getOrderNo());
+        }
+    }
+}