Commit 981faab1 authored by huyuchen's avatar huyuchen

明细接口改造

parent 834b8d48
......@@ -80,16 +80,16 @@
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-transaction-base-seata-at</artifactId>
<version>4.1.1</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.shardingsphere</groupId>-->
<!-- <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>-->
<!-- <version>5.1.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.shardingsphere</groupId>-->
<!-- <artifactId>sharding-transaction-base-seata-at</artifactId>-->
<!-- <version>4.1.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-core</artifactId>
......
package com.yifu.cloud.plus.v1.ekp.config;
import com.google.common.collect.Range;
import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
import org.springframework.stereotype.Component;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Component
public class OTAStrategyShardingAlgorithm implements StandardShardingAlgorithm<String> {
private static final DateTimeFormatter yyyy = DateTimeFormatter.ofPattern("yyyy");
/**
* 数据插入
* @param collection
* @param preciseShardingValue
* @Author hyc
* @Date 2022-07-21
* @return
*/
@Override
public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
String value = preciseShardingValue.getValue();
String tableSuffix = value.substring(0,4);
String logicTableName = preciseShardingValue.getLogicTableName();
String table = logicTableName.concat("_").concat(tableSuffix);
return collection.stream().filter(s -> s.equals(table)).findFirst().orElseThrow(() -> new RuntimeException("逻辑分表不存在"));
}
/**
* 【范围】数据查询
* @param collection
* @param rangeShardingValue
* @Author hyc
* @Date 2022-07-21
* @return
*/
@Override
public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<String> rangeShardingValue) {
// 逻辑表名
String logicTableName = rangeShardingValue.getLogicTableName();
// 范围参数
Range<String> valueRange = rangeShardingValue.getValueRange();
Set<String> queryRangeTables = extracted(logicTableName, valueRange.lowerEndpoint(), valueRange.upperEndpoint());
ArrayList<String> tables = new ArrayList<>(collection);
tables.retainAll(queryRangeTables);
return tables;
}
/**
* 根据范围计算表名
* @param logicTableName 逻辑表明
* @param lowerEndpoint 范围起点
* @param upperEndpoint 范围终端
* @Author hyc
* @Date 2022-07-21
* @return 物理表名集合
*/
private Set<String> extracted(String logicTableName, String lowerEndpoint, String upperEndpoint) {
Set<String> rangeTable = new HashSet<>();
while (DateUtil.stringToDate(lowerEndpoint + "01").before(DateUtil.stringToDate(upperEndpoint + "01"))) {
String str = getTableNameByDate(lowerEndpoint, logicTableName);
rangeTable.add(str);
lowerEndpoint = DateUtil.dateToString(DateUtil.dateIncreaseByYear(DateUtil.stringToDate(lowerEndpoint + "01"),1),DateUtil.DATETIME_YYYYMM);
}
// 获取物理表明
String tableName = getTableNameByDate(upperEndpoint, logicTableName);
rangeTable.add(tableName);
return rangeTable;
}
/**
* 根据日期获取表明
* @param dateTime 日期
* @param logicTableName 逻辑表名
* @Author hyc
* @Date 2022-07-21
* @return 物理表名
*/
private String getTableNameByDate(String dateTime, String logicTableName) {
String tableSuffix = dateTime.substring(0,4);
return logicTableName.concat("_").concat(tableSuffix);
}
@Override
public Properties getProps() {
return null;
}
@Override
public void init(Properties properties) {
}
}
//package com.yifu.cloud.plus.v1.ekp.config;
//
//import com.google.common.collect.Range;
//import com.yifu.cloud.plus.v1.yifu.common.core.util.DateUtil;
//import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
//import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
//import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
//import org.springframework.stereotype.Component;
//
//import java.time.format.DateTimeFormatter;
//import java.util.*;
//
//@Component
//public class OTAStrategyShardingAlgorithm implements StandardShardingAlgorithm<String> {
//
// private static final DateTimeFormatter yyyy = DateTimeFormatter.ofPattern("yyyy");
//
// /**
// * 数据插入
// * @param collection
// * @param preciseShardingValue
// * @Author hyc
// * @Date 2022-07-21
// * @return
// */
// @Override
// public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
//
// String value = preciseShardingValue.getValue();
// String tableSuffix = value.substring(0,4);
// String logicTableName = preciseShardingValue.getLogicTableName();
// String table = logicTableName.concat("_").concat(tableSuffix);
// return collection.stream().filter(s -> s.equals(table)).findFirst().orElseThrow(() -> new RuntimeException("逻辑分表不存在"));
// }
//
// /**
// * 【范围】数据查询
// * @param collection
// * @param rangeShardingValue
// * @Author hyc
// * @Date 2022-07-21
// * @return
// */
// @Override
// public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<String> rangeShardingValue) {
// // 逻辑表名
// String logicTableName = rangeShardingValue.getLogicTableName();
//
// // 范围参数
// Range<String> valueRange = rangeShardingValue.getValueRange();
// Set<String> queryRangeTables = extracted(logicTableName, valueRange.lowerEndpoint(), valueRange.upperEndpoint());
// ArrayList<String> tables = new ArrayList<>(collection);
// tables.retainAll(queryRangeTables);
// return tables;
// }
//
// /**
// * 根据范围计算表名
// * @param logicTableName 逻辑表明
// * @param lowerEndpoint 范围起点
// * @param upperEndpoint 范围终端
// * @Author hyc
// * @Date 2022-07-21
// * @return 物理表名集合
// */
// private Set<String> extracted(String logicTableName, String lowerEndpoint, String upperEndpoint) {
// Set<String> rangeTable = new HashSet<>();
// while (DateUtil.stringToDate(lowerEndpoint + "01").before(DateUtil.stringToDate(upperEndpoint + "01"))) {
// String str = getTableNameByDate(lowerEndpoint, logicTableName);
// rangeTable.add(str);
// lowerEndpoint = DateUtil.dateToString(DateUtil.dateIncreaseByYear(DateUtil.stringToDate(lowerEndpoint + "01"),1),DateUtil.DATETIME_YYYYMM);
// }
// // 获取物理表明
// String tableName = getTableNameByDate(upperEndpoint, logicTableName);
// rangeTable.add(tableName);
// return rangeTable;
// }
//
// /**
// * 根据日期获取表明
// * @param dateTime 日期
// * @param logicTableName 逻辑表名
// * @Author hyc
// * @Date 2022-07-21
// * @return 物理表名
// */
// private String getTableNameByDate(String dateTime, String logicTableName) {
// String tableSuffix = dateTime.substring(0,4);
// return logicTableName.concat("_").concat(tableSuffix);
// }
//
// @Override
// public Properties getProps() {
// return null;
// }
//
// @Override
// public void init(Properties properties) {
//
// }
//}
......@@ -3,8 +3,6 @@ package com.yifu.cloud.plus.v1.ekp.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.ekp.entity.EkpSalaryInfo;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpSalaryParam;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -18,6 +16,6 @@ import java.util.List;
public interface EkpSalaryInfoService extends IService<EkpSalaryInfo> {
@Transactional
@ShardingTransactionType(TransactionType.BASE)
// @ShardingTransactionType(TransactionType.BASE)
Boolean pushSalaryInfoToEkp(List<EkpSalaryParam> unPushList);
}
......@@ -6,8 +6,6 @@ import com.yifu.cloud.plus.v1.ekp.vo.EkpSocialPushInfoVo;
import com.yifu.cloud.plus.v1.ekp.vo.EkpSocialStatusUpdateVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.ekp.vo.EkpPushSocialParam;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
......@@ -21,7 +19,7 @@ import java.util.List;
public interface EkpSocialInfoService extends IService<EkpSocialInfo> {
@Transactional
@ShardingTransactionType(TransactionType.BASE)
// @ShardingTransactionType(TransactionType.BASE)
EkpSocialPushInfoVo pushSocialInfoToEkp(List<EkpPushSocialParam> unPushList);
R updateScoialStatus(List<EkpSocialStatusUpdateVo> list);
......
## 数据源配置
#spring:
# shardingsphere:
# datasource:
# ds0:
# type: com.zaxxer.hikari.HikariDataSource
# driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://192.168.1.122:33306/ekp?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
# username: root
# password: ll_mysql
# hikari:
# driver-class-name: ${spring.datasource.driver-class-name}
# jdbc-url: ${spring.datasource.url}
# username: ${spring.datasource.username}
# password: ${spring.datasource.password}
# pool-name: AmytangHikariCP
# minimum-idle: 10 # 最小空闲连接数量
# idle-timeout: 60000 # 空闲连接存活最大时间,默认600000(10分钟)
# maximum-pool-size: 12 # 连接池最大连接数,默认是10
# auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
# max-lifetime: 0 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
# names: ds0
# rules:
# sharding:
# key-generators:
# snowflake:
# type: SNOWFLAKE
# sharding-algorithms:
# t-payment-inline:
# props:
# strategy: standard
# algorithmClassName: com.yifu.cloud.plus.v1.ekp.config.OTAStrategyShardingAlgorithm
# type: CLASS_BASED
# tables:
# ekp_social_info:
# actual-data-nodes: ds0.ekp_social_info_20$->{23..24}
# key-generate-strategy:
# column: fd_id
# key-generator-name: snowflake
# table-strategy:
# standard:
# sharding-column: fd_3adfe8cb96c41e
# sharding-algorithm-name: t-payment-inline
#
# mvc:
# pathmatch:
# matching-strategy: ant_path_matcher
# config:
# activate:
# on-profile: test
# redis:
# host: 192.168.1.65
# port: 22379
# password: '@yf_2017'
### spring security 配置
#security:
# oauth2:
# resource:
# loadBalanced: true
# token-info-uri: http://127.0.0.1:3000/oauth/check_token
# # 直接放行URL
# ignore:
# urls:
# - /v3/api-docs
# - /actuator/**
# - /swagger-ui/**
# 数据源配置
spring:
shardingsphere:
datasource:
ds0:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.122:33306/ekp?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
username: root
password: ll_mysql
hikari:
driver-class-name: ${spring.datasource.driver-class-name}
jdbc-url: ${spring.datasource.url}
username: ${spring.datasource.username}
password: ${spring.datasource.password}
pool-name: AmytangHikariCP
minimum-idle: 10 # 最小空闲连接数量
idle-timeout: 60000 # 空闲连接存活最大时间,默认600000(10分钟)
maximum-pool-size: 12 # 连接池最大连接数,默认是10
auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
max-lifetime: 0 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
names: ds0
rules:
sharding:
key-generators:
snowflake:
type: SNOWFLAKE
sharding-algorithms:
t-payment-inline:
props:
strategy: standard
algorithmClassName: com.yifu.cloud.plus.v1.ekp.config.OTAStrategyShardingAlgorithm
type: CLASS_BASED
tables:
ekp_social_info:
actual-data-nodes: ds0.ekp_social_info_20$->{23..24}
key-generate-strategy:
column: fd_id
key-generator-name: snowflake
table-strategy:
standard:
sharding-column: fd_3adfe8cb96c41e
sharding-algorithm-name: t-payment-inline
mvc:
pathmatch:
matching-strategy: ant_path_matcher
......@@ -52,6 +76,22 @@ spring:
host: 192.168.1.65
port: 22379
password: '@yf_2017'
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: ll_mysql
url: jdbc:mysql://192.168.1.122:33306/ekp?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
hikari:
driver-class-name: ${spring.datasource.driver-class-name}
jdbc-url: ${spring.datasource.url}
username: ${spring.datasource.username}
password: ${spring.datasource.password}
minimum-idle: 10 # 最小空闲连接数量
idle-timeout: 60000 # 空闲连接存活最大时间,默认600000(10分钟)
maximum-pool-size: 12 # 连接池最大连接数,默认是10
auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
max-lifetime: 0 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
## spring security 配置
security:
oauth2:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment