Преглед изворни кода

Merge branch 'test-transfer' into test-user

* test-transfer:
  用户收支明细自动分表,自动建表
  水平分表用户收支明细
  修复我的职级实时交易额统计
  新增商户表数据同步,实现水平分表功能
  循环机过期添加预扣款, 职级预设记录
  同步押金设置记录,费率设置记录,机具券表,机具券划拨表
  同步押金设置记录,费率设置记录,机具券表,机具券划拨表

# Conflicts:
#	kxs-common/kxs-common-mybatis/src/main/java/com/kxs/common/mybatis/handler/MonthTableNameHandler.java
#	kxs-system/kxs-system-api/src/main/java/com/kxs/system/api/feign/config/KxsOldApFeignClientConfiguration.java
#	kxs-transfer/src/main/java/com/kxs/transfer/api/service/product/impl/KxsMachineRatioServiceImpl.java
mac пре 2 година
родитељ
комит
b500a75f45

+ 14 - 1
kxs-common/kxs-common-mybatis/src/main/java/com/kxs/common/mybatis/MybatisAutoConfiguration.java

@@ -2,7 +2,10 @@ package com.kxs.common.mybatis;
 
 
 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
 import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
 import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
+import com.baomidou.mybatisplus.extension.plugins.inner.DynamicTableNameInnerInterceptor;
 import com.kxs.common.mybatis.config.MybatisPlusMetaObjectHandler;
 import com.kxs.common.mybatis.config.MybatisPlusMetaObjectHandler;
+import com.kxs.common.mybatis.handler.MonthTableNameHandler;
 import com.kxs.common.mybatis.plugins.SkyPaginationInnerInterceptor;
 import com.kxs.common.mybatis.plugins.SkyPaginationInnerInterceptor;
 import com.kxs.common.mybatis.resolver.SqlFilterArgumentResolver;
 import com.kxs.common.mybatis.resolver.SqlFilterArgumentResolver;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Bean;
@@ -32,12 +35,22 @@ public class MybatisAutoConfiguration implements WebMvcConfigurer {
 	}
 	}
 
 
 	/**
 	/**
-	 * 分页插件, 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型
+	 * 1.分页插件, 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型
+	 * 2.针对 update 和 delete 语句 作用: 阻止恶意的全表更新删除
+	 * 3.动态分表
 	 */
 	 */
 	@Bean
 	@Bean
 	public MybatisPlusInterceptor mybatisPlusInterceptor() {
 	public MybatisPlusInterceptor mybatisPlusInterceptor() {
 		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
 		MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
 		interceptor.addInnerInterceptor(new SkyPaginationInnerInterceptor());
 		interceptor.addInnerInterceptor(new SkyPaginationInnerInterceptor());
+		//针对 update 和 delete 语句 作用: 阻止恶意的全表更新删除
+		interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
+		//动态分表
+		DynamicTableNameInnerInterceptor dynamicTableNameInnerInterceptor = new DynamicTableNameInnerInterceptor();
+		dynamicTableNameInnerInterceptor.setTableNameHandler(
+				new MonthTableNameHandler("kxs_user_amount_log")
+		);
+		interceptor.addInnerInterceptor(dynamicTableNameInnerInterceptor);
 		return interceptor;
 		return interceptor;
 	}
 	}
 
 

+ 8 - 2
kxs-common/kxs-common-mybatis/src/main/java/com/kxs/common/mybatis/handler/MonthTableNameHandler.java

@@ -1,7 +1,10 @@
 package com.kxs.common.mybatis.handler;
 package com.kxs.common.mybatis.handler;
 
 
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.LocalDateTimeUtil;
 import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
 import com.baomidou.mybatisplus.extension.plugins.handler.TableNameHandler;
 
 
+import java.time.LocalDate;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 
 
@@ -14,7 +17,7 @@ import java.util.List;
 public class MonthTableNameHandler implements TableNameHandler {
 public class MonthTableNameHandler implements TableNameHandler {
 
 
     //用于记录哪些表可以使用该月份动态表名处理器(即哪些表按月分表)
     //用于记录哪些表可以使用该月份动态表名处理器(即哪些表按月分表)
-    private List<String> tableNames;
+    private final List<String> tableNames;
     //构造函数,构造动态表名处理器的时候,传递tableNames参数
     //构造函数,构造动态表名处理器的时候,传递tableNames参数
     public MonthTableNameHandler(String ...tableNames) {
     public MonthTableNameHandler(String ...tableNames) {
         this.tableNames = Arrays.asList(tableNames);
         this.tableNames = Arrays.asList(tableNames);
@@ -31,11 +34,14 @@ public class MonthTableNameHandler implements TableNameHandler {
         MONTH_DATA.remove();
         MONTH_DATA.remove();
     }
     }
 
 
+    public static String getThisMoth() {
+
+        return LocalDateTimeUtil.format(LocalDate.now(), DatePattern.SIMPLE_MONTH_PATTERN);
+    }
     //动态表名接口实现方法
     //动态表名接口实现方法
     @Override
     @Override
     public String dynamicTableName(String sql, String tableName) {
     public String dynamicTableName(String sql, String tableName) {
         // 删除当前id
         // 删除当前id
-        removeData();
         if (this.tableNames.contains(tableName)){
         if (this.tableNames.contains(tableName)){
             return tableName + "_" + MONTH_DATA.get();  //表名增加月份后缀
             return tableName + "_" + MONTH_DATA.get();  //表名增加月份后缀
         }else{
         }else{

+ 47 - 47
kxs-system/kxs-system-api/src/main/java/com/kxs/system/api/feign/config/KxsOldApFeignClientConfiguration.java

@@ -1,47 +1,47 @@
-//package com.kxs.system.api.feign.config;
-//
-//import com.kxs.system.api.feign.RemoteOldService;
-//import lombok.RequiredArgsConstructor;
-//import org.springframework.beans.factory.annotation.Qualifier;
-//import org.springframework.beans.factory.annotation.Value;
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.web.reactive.function.client.WebClient;
-//import org.springframework.web.reactive.function.client.support.WebClientAdapter;
-//import org.springframework.web.service.invoker.HttpServiceProxyFactory;
-//
-//
-///**
-// * KXS 旧客户端ap 远程调用配置
-// *
-// * @author 没秃顶的码农
-// * @date 2024-03-14
-// */
-//@Configuration
-//@RequiredArgsConstructor
-//public class KxsOldApFeignClientConfiguration {
-//
-//
-//	@Value("${kxs.old.url}")
-//	private String baseUrl;
-//
-//	@Bean("kxsOldFeignClient")
-//	public WebClient oauthRequestInterceptor() {
-//
-//		return WebClient.builder().baseUrl(baseUrl).build();
-//	}
-//
-//	/**
-//	 * 远程老平台接口
-//	 * @param client 客户端
-//	 * @return 远程老平台接口
-//	 */
-//	@Bean
-//	RemoteOldService remoteOldService(@Qualifier("kxsOldFeignClient") WebClient client) {
-//		HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
-//		return factory.createClient(RemoteOldService.class);
-//	}
-//
-//
-//
-//}
+package com.kxs.system.api.feign.config;
+
+import com.kxs.system.api.feign.RemoteOldService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.reactive.function.client.WebClient;
+import org.springframework.web.reactive.function.client.support.WebClientAdapter;
+import org.springframework.web.service.invoker.HttpServiceProxyFactory;
+
+
+/**
+ * KXS 旧客户端ap 远程调用配置
+ *
+ * @author 没秃顶的码农
+ * @date 2024-03-14
+ */
+@Configuration
+@RequiredArgsConstructor
+public class KxsOldApFeignClientConfiguration {
+
+
+	@Value("${kxs.old.url}")
+	private String baseUrl;
+
+	@Bean("kxsOldFeignClient")
+	public WebClient oauthRequestInterceptor() {
+
+		return WebClient.builder().baseUrl(baseUrl).build();
+	}
+
+	/**
+	 * 远程老平台接口
+	 * @param client 客户端
+	 * @return 远程老平台接口
+	 */
+	@Bean
+	RemoteOldService remoteOldService(@Qualifier("kxsOldFeignClient") WebClient client) {
+		HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(client)).build();
+		return factory.createClient(RemoteOldService.class);
+	}
+
+
+
+}

+ 1 - 0
kxs-system/kxs-system-api/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -1 +1,2 @@
 com.kxs.system.api.feign.config.KxsSystemFeignClientConfiguration
 com.kxs.system.api.feign.config.KxsSystemFeignClientConfiguration
+com.kxs.system.api.feign.config.KxsOldApFeignClientConfiguration

+ 4 - 0
kxs-transfer/src/main/java/com/kxs/transfer/api/service/product/impl/KxsMachineRatioServiceImpl.java

@@ -37,6 +37,10 @@ public class KxsMachineRatioServiceImpl extends ServiceImpl<KxsMachineRatioMappe
         machineRatio.setId(id);
         machineRatio.setId(id);
 
 
         OperationType operation = dmlData.getOperation();
         OperationType operation = dmlData.getOperation();
+        if(operation.equals(OperationType.DELETE)){
+            baseMapper.deleteById(id);
+            return;
+        }
 
 
         for (String field : changeFieldList) {
         for (String field : changeFieldList) {
 
 

+ 6 - 1
kxs-transfer/src/main/java/com/kxs/transfer/api/service/user/impl/KxsUserAmountLogServiceImpl.java

@@ -6,6 +6,7 @@ import com.aliyun.dts.subscribe.clients.record.OperationType;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.kxs.common.core.constant.enums.AmountLogChangeTypesEnum;
 import com.kxs.common.core.constant.enums.AmountLogChangeTypesEnum;
 import com.kxs.common.core.constant.enums.KindTypeEnum;
 import com.kxs.common.core.constant.enums.KindTypeEnum;
+import com.kxs.common.mybatis.handler.MonthTableNameHandler;
 import com.kxs.transfer.api.mapper.user.KxsUserAmountLogMapper;
 import com.kxs.transfer.api.mapper.user.KxsUserAmountLogMapper;
 import com.kxs.transfer.api.model.table.DMLData;
 import com.kxs.transfer.api.model.table.DMLData;
 import com.kxs.transfer.api.model.table.FieldData;
 import com.kxs.transfer.api.model.table.FieldData;
@@ -15,6 +16,7 @@ import com.kxs.user.api.model.KxsUserAmountLog;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -97,7 +99,8 @@ public class KxsUserAmountLogServiceImpl extends ServiceImpl<KxsUserAmountLogMap
                     break;
                     break;
             }
             }
         }
         }
-
+        //分表月份
+        MonthTableNameHandler.setData(MonthTableNameHandler.getThisMoth());
         if (operation.equals(OperationType.UPDATE)) {
         if (operation.equals(OperationType.UPDATE)) {
             // 更新数据
             // 更新数据
             baseMapper.updateById(userAmountLog);
             baseMapper.updateById(userAmountLog);
@@ -111,6 +114,8 @@ public class KxsUserAmountLogServiceImpl extends ServiceImpl<KxsUserAmountLogMap
                 baseMapper.updateById(userAmountLog);
                 baseMapper.updateById(userAmountLog);
             }
             }
         }
         }
+        //删除线程,避免线程污染
+        MonthTableNameHandler.removeData();
     }
     }
 }
 }
 
 

+ 1 - 1
kxs-transfer/src/main/resources/import.txt

@@ -53,7 +53,7 @@ FROM UserCashRecord
 
 
 //用户余额记录日志表
 //用户余额记录日志表
 select a.Id as id, a.UserId as user_id,a.CreateDate as create_time, a.UpdateDate as update_time,
 select a.Id as id, a.UserId as user_id,a.CreateDate as create_time, a.UpdateDate as update_time,
-a.ProductType as brand_id, a.ChangeType as variation_type, c.Kind as kind,
+a.ProductType as brand_id, a.ChangeType as variation_type, case c.Kind when 1 then 'add' ELSE 'sub' end kind,
 a.ChangeAmount as amount, a.BeforeTotalAmount as before_total_amount, a.AfterTotalAmount as after_total_amount, a.BeforeBalanceAmount as before_amount, a.AfterBalanceAmount as after_amount, a.Remark as remark
 a.ChangeAmount as amount, a.BeforeTotalAmount as before_total_amount, a.AfterTotalAmount as after_total_amount, a.BeforeBalanceAmount as before_amount, a.AfterBalanceAmount as after_amount, a.Remark as remark
 FROM UserAccountRecord a left join ChangeTypes c on c.id = a.ChangeType
 FROM UserAccountRecord a left join ChangeTypes c on c.id = a.ChangeType
 
 

+ 4 - 0
kxs-user/kxs-user-biz/pom.xml

@@ -75,6 +75,10 @@
             <groupId>cn.hutool</groupId>
             <groupId>cn.hutool</groupId>
             <artifactId>hutool-crypto</artifactId>
             <artifactId>hutool-crypto</artifactId>
         </dependency>
         </dependency>
+        <dependency>
+            <groupId>com.kxs</groupId>
+            <artifactId>kxs-product-api</artifactId>
+        </dependency>
     </dependencies>
     </dependencies>
 
 
     <build>
     <build>

+ 1 - 0
kxs-user/kxs-user-biz/src/main/java/com/kxs/user/biz/mapper/KxsUserAmountLogMapper.java

@@ -21,5 +21,6 @@ public interface KxsUserAmountLogMapper extends BaseMapper<KxsUserAmountLog> {
 
 
     IPage<UserAmountVariationListVO> getByPage(Page<UserAmountVariationListVO> page, @Param("query") UserAmountVariationListDTO param);
     IPage<UserAmountVariationListVO> getByPage(Page<UserAmountVariationListVO> page, @Param("query") UserAmountVariationListDTO param);
 
 
+    void automaticTableCreationTasks(String tableName);
 }
 }
 
 

+ 43 - 0
kxs-user/kxs-user-biz/src/main/java/com/kxs/user/biz/task/KxsUserTaskJob.java

@@ -0,0 +1,43 @@
+package com.kxs.user.biz.task;
+
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.LocalDateTimeUtil;
+import com.kxs.common.mybatis.handler.MonthTableNameHandler;
+import com.kxs.user.biz.mapper.KxsUserAmountLogMapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDate;
+
+/**
+ * 产品模块定时任务
+ *
+ * @author 没秃顶的码农
+ * @date 2024-03-13
+ */
+@Component
+@EnableAsync
+@EnableScheduling
+@RequiredArgsConstructor
+@Slf4j
+public class KxsUserTaskJob {
+
+    private final KxsUserAmountLogMapper kxsUserAmountLogMapper;
+
+
+    /**
+     * 自动表创建任务
+     * 每个月15号建立下个月的收支日志表
+     */
+    @Async(value = "getAsyncExecutor")
+    @Scheduled(cron = "0 15 10 15 * ?")
+    public void automaticTableCreationTasks() {
+        String thisMoth = LocalDateTimeUtil.format(LocalDate.now().plusMonths(1L), DatePattern.SIMPLE_MONTH_PATTERN);
+        kxsUserAmountLogMapper.automaticTableCreationTasks("kxs_user_amount_log_" +thisMoth);
+    }
+}

+ 3 - 0
kxs-user/kxs-user-biz/src/main/resources/mapper/KxsUserAmountLogMapper.xml

@@ -22,6 +22,9 @@
         <result column="brand_id" property="brandId" />
         <result column="brand_id" property="brandId" />
 
 
     </resultMap>
     </resultMap>
+    <update id="automaticTableCreationTasks" parameterType="String">
+        CREATE  TABLE IF NOT EXISTS `${tableName}` LIKE kxs_user_amount_log;
+    </update>
     <select id="getByPage" resultType="com.kxs.user.api.vo.kxsapp.userAccount.UserAmountVariationListVO">
     <select id="getByPage" resultType="com.kxs.user.api.vo.kxsapp.userAccount.UserAmountVariationListVO">
         SELECT * from kxs_user_amount_log
         SELECT * from kxs_user_amount_log
         <where>
         <where>