Commit d02710d9 authored by huyuchen's avatar huyuchen

缴费库修改

parent 1440d7e7
...@@ -16,13 +16,7 @@ ...@@ -16,13 +16,7 @@
<description>yifu-social 业务模块</description> <description>yifu-social 业务模块</description>
<dependencies> <dependencies>
<!-- seata 依赖 -->
<dependency>
<groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-common-seata</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.yifu.cloud.plus.v1</groupId> <groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-social-api</artifactId> <artifactId>yifu-social-api</artifactId>
...@@ -73,11 +67,6 @@ ...@@ -73,11 +67,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId> <artifactId>spring-boot-starter-undertow</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<version>5.8.0</version>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency> <dependency>
<groupId>com.yifu.cloud.plus.v1</groupId> <groupId>com.yifu.cloud.plus.v1</groupId>
<artifactId>yifu-archives-api</artifactId> <artifactId>yifu-archives-api</artifactId>
...@@ -90,6 +79,20 @@ ...@@ -90,6 +79,20 @@
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </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>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package com.yifu.cloud.plus.v1.yifu.social.config;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Range;
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.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Component
public class OTAStrategyShardingAlgorithm implements StandardShardingAlgorithm<LocalDateTime> {
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<LocalDateTime> preciseShardingValue) {
LocalDateTime value = preciseShardingValue.getValue();
String tableSuffix = value.format(yyyy);
String logicTableName = preciseShardingValue.getLogicTableName();
String table = logicTableName.concat("_").concat(tableSuffix);
System.out.println("OrderStrategy.doSharding table name: " + table);
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<LocalDateTime> rangeShardingValue) {
// 逻辑表名
String logicTableName = rangeShardingValue.getLogicTableName();
// 范围参数
Range<LocalDateTime> valueRange = rangeShardingValue.getValueRange();
Set<String> queryRangeTables = extracted(logicTableName, valueRange.lowerEndpoint(), valueRange.upperEndpoint());
ArrayList<String> tables = new ArrayList<>(collection);
tables.retainAll(queryRangeTables);
System.out.println(JSON.toJSONString(tables));
return tables;
}
/**
* 根据范围计算表名
* @param logicTableName 逻辑表明
* @param lowerEndpoint 范围起点
* @param upperEndpoint 范围终端
* @Author hyc
* @Date 2022-07-21
* @return 物理表名集合
*/
private Set<String> extracted(String logicTableName, LocalDateTime lowerEndpoint, LocalDateTime upperEndpoint) {
Set<String> rangeTable = new HashSet<>();
while (lowerEndpoint.isBefore(upperEndpoint)) {
String str = getTableNameByDate(lowerEndpoint, logicTableName);
rangeTable.add(str);
lowerEndpoint = lowerEndpoint.plusYears(1);
}
// 获取物理表明
String tableName = getTableNameByDate(upperEndpoint, logicTableName);
rangeTable.add(tableName);
return rangeTable;
}
/**
* 根据日期获取表明
* @param dateTime 日期
* @param logicTableName 逻辑表名
* @Author hyc
* @Date 2022-07-21
* @return 物理表名
*/
private String getTableNameByDate(LocalDateTime dateTime, String logicTableName) {
String tableSuffix = dateTime.format(yyyy);
return logicTableName.concat("_").concat(tableSuffix);
}
@Override
public Properties getProps() {
return null;
}
@Override
public void init(Properties properties) {
}
}
...@@ -25,7 +25,9 @@ import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser; ...@@ -25,7 +25,9 @@ import com.yifu.cloud.plus.v1.yifu.common.core.vo.YifuUser;
import com.yifu.cloud.plus.v1.yifu.social.entity.TDispatchInfo; import com.yifu.cloud.plus.v1.yifu.social.entity.TDispatchInfo;
import com.yifu.cloud.plus.v1.yifu.social.vo.*; import com.yifu.cloud.plus.v1.yifu.social.vo.*;
import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage; import com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage;
import io.seata.spring.annotation.GlobalTransactional; import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.InputStream; import java.io.InputStream;
...@@ -50,14 +52,16 @@ public interface TDispatchInfoService extends IService<TDispatchInfo> { ...@@ -50,14 +52,16 @@ public interface TDispatchInfoService extends IService<TDispatchInfo> {
List<TDispatchInfo> noPageDiy(TDispatchInfoSearchVo searchVo); List<TDispatchInfo> noPageDiy(TDispatchInfoSearchVo searchVo);
@GlobalTransactional @Transactional
@ShardingTransactionType(TransactionType.BASE)
void importTDispatchInfo(List<TDispatchImportVo> excelVOList, void importTDispatchInfo(List<TDispatchImportVo> excelVOList,
List<ErrorMessage> errorMessageList, List<ErrorMessage> errorMessageList,
YifuUser user); YifuUser user);
R<List<ErrorMessage>> importReduceDiy(InputStream inputStream); R<List<ErrorMessage>> importReduceDiy(InputStream inputStream);
@GlobalTransactional @Transactional
@ShardingTransactionType(TransactionType.BASE)
void batchReduceDispatch(List<TDispatchReduceVo> excelVOList, List<ErrorMessage> errorMessageList, YifuUser user); void batchReduceDispatch(List<TDispatchReduceVo> excelVOList, List<ErrorMessage> errorMessageList, YifuUser user);
R<Boolean> removeByIdDiy(String id); R<Boolean> removeByIdDiy(String id);
......
...@@ -50,9 +50,10 @@ import com.yifu.cloud.plus.v1.yifu.social.service.TDispatchInfoService; ...@@ -50,9 +50,10 @@ import com.yifu.cloud.plus.v1.yifu.social.service.TDispatchInfoService;
import com.yifu.cloud.plus.v1.yifu.social.service.TForecastLibraryService; import com.yifu.cloud.plus.v1.yifu.social.service.TForecastLibraryService;
import com.yifu.cloud.plus.v1.yifu.social.util.ServiceUtil; import com.yifu.cloud.plus.v1.yifu.social.util.ServiceUtil;
import com.yifu.cloud.plus.v1.yifu.social.vo.*; import com.yifu.cloud.plus.v1.yifu.social.vo.*;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
...@@ -294,8 +295,8 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -294,8 +295,8 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
return R.ok(errorMessageList); return R.ok(errorMessageList);
} }
@Override @Override
@GlobalTransactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(TransactionType.BASE)
public void importTDispatchInfo(List<TDispatchImportVo> excelVOList, public void importTDispatchInfo(List<TDispatchImportVo> excelVOList,
List<ErrorMessage> errorMessageList, List<ErrorMessage> errorMessageList,
YifuUser user) { YifuUser user) {
...@@ -2365,9 +2366,9 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -2365,9 +2366,9 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
return R.ok(errorMessageList); return R.ok(errorMessageList);
} }
@GlobalTransactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class)
@Override @Override
@Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(TransactionType.BASE)
public void batchReduceDispatch(List<TDispatchReduceVo> excelVOList, List<ErrorMessage> errorMessageList, YifuUser user) { public void batchReduceDispatch(List<TDispatchReduceVo> excelVOList, List<ErrorMessage> errorMessageList, YifuUser user) {
if (!Common.isNotNull(excelVOList)){ if (!Common.isNotNull(excelVOList)){
return; return;
...@@ -2679,8 +2680,8 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -2679,8 +2680,8 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
* @Param * @Param
* @return * @return
**/ **/
@GlobalTransactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(TransactionType.BASE)
@Override @Override
public List<ErrorMessage> addBatchApplyAudit(List<String> idsList, YifuUser user, int flag, String auditStatus, String auditRemark, String remark) { public List<ErrorMessage> addBatchApplyAudit(List<String> idsList, YifuUser user, int flag, String auditStatus, String auditRemark, String remark) {
List<ErrorMessage> errorList = new ArrayList<>(); List<ErrorMessage> errorList = new ArrayList<>();
...@@ -3008,8 +3009,8 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T ...@@ -3008,8 +3009,8 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
* @Author fxj * @Author fxj
* @Date 2022-07-26 * @Date 2022-07-26
**/ **/
@GlobalTransactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ShardingTransactionType(TransactionType.BASE)
public List<ErrorMessage> addBatchApplyHandle(List<String> idsList, String typeSub, YifuUser user public List<ErrorMessage> addBatchApplyHandle(List<String> idsList, String typeSub, YifuUser user
, int flag, String handleStatus, String handleRemark, String socialType, String remark) { , int flag, String handleStatus, String handleRemark, String socialType, String remark) {
List<ErrorMessage> errorList = new ArrayList<>(); List<ErrorMessage> errorList = new ArrayList<>();
......
...@@ -320,7 +320,9 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -320,7 +320,9 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
/** /**
* 单次缓存的数据量 * 单次缓存的数据量
*/ */
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT1; public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
//所有行数
Integer rowNumber;
/** /**
*临时存储 *临时存储
*/ */
...@@ -329,6 +331,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -329,6 +331,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
@Override @Override
public void invoke(TPaymentInfoVo data, AnalysisContext context) { public void invoke(TPaymentInfoVo data, AnalysisContext context) {
ReadRowHolder readRowHolder = context.readRowHolder(); ReadRowHolder readRowHolder = context.readRowHolder();
// 获取总行数(含表头)
rowNumber = context.readSheetHolder().getApproximateTotalRowNumber();
Integer rowIndex = readRowHolder.getRowIndex(); Integer rowIndex = readRowHolder.getRowIndex();
data.setRowIndex(rowIndex + 1); data.setRowIndex(rowIndex + 1);
ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex()); ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex());
...@@ -354,7 +358,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -354,7 +358,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
*/ */
private void saveData() { private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size()); log.info("{}条数据,开始存储数据库!", cachedDataList.size());
importTPaymentSocialInfo(cachedDataList, errorMessageList, random, user); importTPaymentSocialInfo(cachedDataList, errorMessageList, random, user, rowNumber);
log.info("存储数据库成功!"); log.info("存储数据库成功!");
} }
}).sheet().doRead(); }).sheet().doRead();
...@@ -366,7 +370,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -366,7 +370,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
} }
private void importTPaymentSocialInfo(List<TPaymentInfoVo> list, List<ErrorMessage> errorMessageList, private void importTPaymentSocialInfo(List<TPaymentInfoVo> list, List<ErrorMessage> errorMessageList,
String random, YifuUser user) { String random, YifuUser user, Integer rowNumber) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
HashMap<String, String> areaMap = new HashMap<String, String>(); HashMap<String, String> areaMap = new HashMap<String, String>();
...@@ -390,7 +394,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -390,7 +394,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
errorMessageList.add(new ErrorMessage(-1, "当前用户数据导入中,请稍后重试!")); errorMessageList.add(new ErrorMessage(-1, "当前用户数据导入中,请稍后重试!"));
redisUtil.remove(key); redisUtil.remove(key);
} else { } else {
redisUtil.set(key, user.getId(), 1800L); redisUtil.set(key, user.getId(), 360L);
// 导入前做队列空闲判断,防止队列不足出现数据丢失的场景 // 导入前做队列空闲判断,防止队列不足出现数据丢失的场景
if (CollUtil.isNotEmpty(list)) { if (CollUtil.isNotEmpty(list)) {
...@@ -509,6 +513,32 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -509,6 +513,32 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
AtomicInteger atomicLine = new AtomicInteger(CommonConstants.ZERO_INT); AtomicInteger atomicLine = new AtomicInteger(CommonConstants.ZERO_INT);
List<CompletableFuture<List<ErrorMessage>>> completableFutureList = new ArrayList<>(); List<CompletableFuture<List<ErrorMessage>>> completableFutureList = new ArrayList<>();
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String maerialRatio = "";
String sumNumKey = user.getId() + CommonConstants.DOWN_LINE_STRING + "sum_key";
Integer bfInt = (Integer) redisUtil.get(sumNumKey);
if (Common.isNotNull(bfInt)) {
if (bfInt <= rowNumber.intValue()) {
maerialRatio = numberFormat.format((float) bfInt.intValue() / (float) rowNumber.intValue() * 100);
bfInt = bfInt + 100;
} else {
maerialRatio = "100";
}
}else {
if (100 <= rowNumber.intValue()) {
maerialRatio = numberFormat.format((float) 100 / (float) rowNumber.intValue() * 100);
bfInt = 100;
} else {
maerialRatio = "100";
}
}
redisUtil.set(sumNumKey, bfInt, 360L);
redisUtil.set(importSuccessKey, maerialRatio, 360L);
try { try {
// 1.list.size()不足partSize,直接执行 // 1.list.size()不足partSize,直接执行
if (list.size() < partSize) { if (list.size() < partSize) {
...@@ -518,12 +548,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -518,12 +548,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
paymentInfoMedicalMap, paymentInfoUnEmpMap, paymentInfoInjuryMap, paymentInfoMedicalMap, paymentInfoUnEmpMap, paymentInfoInjuryMap,
CommonConstants.ONE_INT, errorMessageList), yfSocialImportThreadPoolExecutor); CommonConstants.ONE_INT, errorMessageList), yfSocialImportThreadPoolExecutor);
completableFutureList.add(listCompletableFuture); completableFutureList.add(listCompletableFuture);
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String maerialRatio = numberFormat.format((float)atomicLine.get()/(float)list.size()*100);
redisUtil.set(importSuccessKey, maerialRatio, 180L);
} }
// 2.list.size()大于partSize,循环分批执行 // 2.list.size()大于partSize,循环分批执行
...@@ -554,12 +578,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -554,12 +578,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
tempList = new ArrayList<>(); tempList = new ArrayList<>();
} }
} }
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String maerialRatio = numberFormat.format((float)atomicLine.get()/(float)list.size()*100);
redisUtil.set(importSuccessKey, maerialRatio, 180L);
} }
// 3.第2种方式执行完后,有余数的情况下,执行3 // 3.第2种方式执行完后,有余数的情况下,执行3
...@@ -584,12 +602,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -584,12 +602,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
paymentInfoMedicalMap, paymentInfoUnEmpMap, paymentInfoInjuryMap, paymentInfoMedicalMap, paymentInfoUnEmpMap, paymentInfoInjuryMap,
finalLastIdx, errorMessageList), yfSocialImportThreadPoolExecutor); finalLastIdx, errorMessageList), yfSocialImportThreadPoolExecutor);
completableFutureList.add(listCompletableFuture); completableFutureList.add(listCompletableFuture);
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String maerialRatio = numberFormat.format((float)atomicLine.get()/(float)list.size()*100);
redisUtil.set(importSuccessKey, maerialRatio, 180L);
} }
// 阻塞当前线程,等待所有的线程执行完毕 // 阻塞当前线程,等待所有的线程执行完毕
...@@ -1202,6 +1214,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1202,6 +1214,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
* 单次缓存的数据量 * 单次缓存的数据量
*/ */
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT; public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
Integer rowNumber;
/** /**
*临时存储 *临时存储
*/ */
...@@ -1209,6 +1222,9 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1209,6 +1222,9 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
@Override @Override
public void invoke(TPaymentHeFeiVo data, AnalysisContext context) { public void invoke(TPaymentHeFeiVo data, AnalysisContext context) {
// 获取总行数(含表头)
rowNumber = context.readSheetHolder().getApproximateTotalRowNumber();
ReadRowHolder readRowHolder = context.readRowHolder(); ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex(); Integer rowIndex = readRowHolder.getRowIndex();
data.setRowIndex(rowIndex + 1); data.setRowIndex(rowIndex + 1);
...@@ -1235,7 +1251,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1235,7 +1251,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
*/ */
private void saveData() { private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size()); log.info("{}条数据,开始存储数据库!", cachedDataList.size());
importTPaymentSocialHeFei(cachedDataList, errorMessageList, random, user, type); importTPaymentSocialHeFei(cachedDataList, errorMessageList, random, user, type,rowNumber);
log.info("存储数据库成功!"); log.info("存储数据库成功!");
} }
}).sheet().doRead(); }).sheet().doRead();
...@@ -1589,7 +1605,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1589,7 +1605,7 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
} }
private void importTPaymentSocialHeFei(List<TPaymentHeFeiVo> list, List<ErrorMessage> errorMessageList, private void importTPaymentSocialHeFei(List<TPaymentHeFeiVo> list, List<ErrorMessage> errorMessageList,
String random, YifuUser user, String type) { String random, YifuUser user, String type, Integer rowNumber) {
HashMap<String, String> areaMap = new HashMap<String, String>(); HashMap<String, String> areaMap = new HashMap<String, String>();
HashMap<String, String> areaMap2 = new HashMap<String, String>(); HashMap<String, String> areaMap2 = new HashMap<String, String>();
...@@ -1606,9 +1622,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1606,9 +1622,6 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
} }
} }
// 判断是否有相同的用户在导入社保费用 存在提示稍后重试
String key = user.getId() + CommonConstants.DOWN_LINE_STRING + CommonConstants.PAYMENT_SOCIAL_IMPORT;
// 将以下代码提取出来,使用paymentInfoMap提升性能,避免list多次循环查询数据库浪费性能 // 将以下代码提取出来,使用paymentInfoMap提升性能,避免list多次循环查询数据库浪费性能
// 导入前做队列空闲判断,防止队列不足出现数据丢失的场景 // 导入前做队列空闲判断,防止队列不足出现数据丢失的场景
if (CollUtil.isNotEmpty(list)) { if (CollUtil.isNotEmpty(list)) {
...@@ -1713,6 +1726,34 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1713,6 +1726,34 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
List<TPaymentHeFeiVo> tempList = new ArrayList<>(); List<TPaymentHeFeiVo> tempList = new ArrayList<>();
AtomicInteger atomicLine = new AtomicInteger(CommonConstants.ZERO_INT); AtomicInteger atomicLine = new AtomicInteger(CommonConstants.ZERO_INT);
List<CompletableFuture<List<ErrorMessage>>> completableFutureList = new ArrayList<>(); List<CompletableFuture<List<ErrorMessage>>> completableFutureList = new ArrayList<>();
String importSuccessKey = user.getId() + CommonConstants.DOWN_LINE_STRING + CommonConstants.PAYMENT_SOCIAL_WAIT_EXPORT;
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String maerialRatio = "";
String sumNumKey = user.getId() + CommonConstants.DOWN_LINE_STRING + "sum_key";
Integer bfInt = (Integer) redisUtil.get(sumNumKey);
if (Common.isNotNull(bfInt)) {
if (bfInt <= rowNumber.intValue()) {
maerialRatio = numberFormat.format((float) bfInt.intValue() / (float) rowNumber.intValue() * 100);
bfInt = bfInt + 100;
} else {
maerialRatio = "100";
}
}else {
if (100 <= rowNumber.intValue()) {
maerialRatio = numberFormat.format((float) 100 / (float) rowNumber.intValue() * 100);
bfInt = 100;
} else {
maerialRatio = "100";
}
}
redisUtil.set(sumNumKey, bfInt, 360L);
redisUtil.set(importSuccessKey, maerialRatio, 360L);
try { try {
// 1.list.size()不足partSize,直接执行 // 1.list.size()不足partSize,直接执行
if (list.size() < partSize) { if (list.size() < partSize) {
...@@ -1789,19 +1830,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa ...@@ -1789,19 +1830,8 @@ public class TPaymentInfoServiceImpl extends ServiceImpl<TPaymentInfoMapper, TPa
} }
} while (computeFlag); } while (computeFlag);
String importSuccessKey = user.getId() + CommonConstants.DOWN_LINE_STRING + CommonConstants.PAYMENT_SOCIAL_WAIT_EXPORT;
// 创建一个数值格式化对象
NumberFormat numberFormat = NumberFormat.getInstance();
// 设置精确到小数点后2位
numberFormat.setMaximumFractionDigits(2);
String maerialRatio = numberFormat.format((float)atomicLine.get()/(float)list.size()*100);
redisUtil.set(importSuccessKey, maerialRatio, 1800L);
} catch (Exception e) { } catch (Exception e) {
log.error("社保缴费库数据批量导入异常:" + e); log.error("社保缴费库数据批量导入异常:" + e);
redisUtil.remove(key);
} finally { } finally {
paymentInfoPensionMap.clear(); paymentInfoPensionMap.clear();
paymentInfoBigMap.clear(); paymentInfoBigMap.clear();
......
spring: spring:
mvc: shardingsphere:
pathmatch:
matching-strategy: ant_path_matcher
config:
activate:
on-profile: test
redis:
host: 192.168.1.65
port: 22379
password: '@yf_2017'
datasource: datasource:
ds0:
type: com.zaxxer.hikari.HikariDataSource type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.1.65:22306/mvp_social?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
username: root username: root
password: yf_zsk password: yf_zsk
url: jdbc:mysql://192.168.1.65:22306/mvp_social?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
hikari: hikari:
driver-class-name: ${spring.datasource.driver-class-name} driver-class-name: ${spring.datasource.driver-class-name}
jdbc-url: ${spring.datasource.url} jdbc-url: ${spring.datasource.url}
...@@ -26,3 +18,36 @@ spring: ...@@ -26,3 +18,36 @@ spring:
maximum-pool-size: 12 # 连接池最大连接数,默认是10 maximum-pool-size: 12 # 连接池最大连接数,默认是10
auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true auto-commit: true #此属性控制从池返回的连接的默认自动提交行为,默认值:true
max-lifetime: 0 #此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟 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.yifu.social.config.OTAStrategyShardingAlgorithm
type: CLASS_BASED
tables:
t_payment_info:
actual-data-nodes: ds0.t_payment_info_20$->{17..22}
key-generate-strategy:
column: ID
key-generator-name: snowflake
table-strategy:
standard:
sharding-column: CREATE_TIME
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'
\ No newline at end of file
...@@ -103,3 +103,61 @@ springdoc: ...@@ -103,3 +103,61 @@ springdoc:
- group: social - group: social
#按包路径匹配 #按包路径匹配
packagesToScan: com.yifu.cloud.plus.v1.yifu.social.controller packagesToScan: com.yifu.cloud.plus.v1.yifu.social.controller
seata:
enabled: true
application-id: seata-server
tx-service-group: yifu_tx_group # 事务群组(可以每个应用独立取名,也可以使用相同的名字)
client:
rm-report-success-enable: true
rm-table-meta-check-enable: false # 自动刷新缓存中的表结构(默认false)
rm-report-retry-count: 5 # 一阶段结果上报TC重试次数(默认5)
rm-async-commit-buffer-limit: 10000 # 异步提交缓存队列长度(默认10000)
rm:
lock:
lock-retry-internal: 10 # 校验或占用全局锁重试间隔(默认10ms)
lock-retry-times: 30 # 校验或占用全局锁重试次数(默认30)
lock-retry-policy-branch-rollback-on-conflict: true # 分支事务与其它全局回滚事务冲突时锁策略(优先释放本地锁让回滚成功)
tm-commit-retry-count: 3 # 一阶段全局提交结果上报TC重试次数(默认1次,建议大于1)
tm-rollback-retry-count: 3 # 一阶段全局回滚结果上报TC重试次数(默认1次,建议大于1)
undo:
data-validation: true # 二阶段回滚镜像校验(默认true开启)
log-serialization: kryo # undo序列化方式(默认jackson 不支持 LocalDateTime)
log-table: undo_log # 自定义undo表名(默认undo_log)
log:
exceptionRate: 100 # 日志异常输出概率(默认100)
support:
spring:
datasource-autoproxy: true
service:
vgroup-mapping:
yifu_tx_group: default # TC 集群(必须与seata-server保持一致)
enable-degrade: false # 降级开关
disable-global-transaction: false # 禁用全局事务(默认false)
grouplist:
default: 192.168.1.65:33091
transport:
shutdown:
wait: 3
thread-factory:
boss-thread-prefix: NettyBoss
worker-thread-prefix: NettyServerNIOWorker
server-executor-thread-prefix: NettyServerBizHandler
share-boss-worker: false
client-selector-thread-prefix: NettyClientSelector
client-selector-thread-size: 1
client-worker-thread-prefix: NettyClientWorkerThread
type: TCP
server: NIO
heartbeat: true
serialization: seata
compressor: none
enable-client-batch-send-request: true # 客户端事务消息请求是否批量合并发送(默认true)
registry:
file:
name: file.conf
type: file
config:
file:
name: file.conf
type: file
client {
application.id = seata-server ## 应用唯一id
transaction.service.group = yifu_tx_group ## 所属事务组
}
\ No newline at end of file
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