|
|
@@ -25,10 +25,10 @@ import javax.persistence.criteria.CriteriaBuilder; |
|
|
|
import javax.persistence.criteria.CriteriaQuery; |
|
|
|
import javax.persistence.criteria.Predicate; |
|
|
|
import javax.persistence.criteria.Root; |
|
|
|
import javax.transaction.Transactional; |
|
|
|
import java.io.Serial; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.ArrayList; |
|
|
@@ -58,47 +58,22 @@ public class DataSyncServiceImpl implements DataSyncService { |
|
|
|
/** |
|
|
|
* 执行报表同步任务 |
|
|
|
* @param syncType 1 当月 2 当天 other 全量 |
|
|
|
* @param intPage 开始页码 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackOn = Exception.class) |
|
|
|
@Override |
|
|
|
public void dataSyncForServiceFee(Integer syncType, Integer time, Integer intPage) { |
|
|
|
public void dataSyncForServiceFee(Integer syncType, String time) { |
|
|
|
log.info("执行报表数据同步任务"); |
|
|
|
String date = null; |
|
|
|
syncType = syncType == null ? 1 : syncType; |
|
|
|
|
|
|
|
if(Integer.valueOf(1).equals(syncType)) { |
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
int year = now.getYear(); |
|
|
|
LocalDate syncDate = LocalDate.of(year, time, 1); |
|
|
|
date = syncDate.format(DateTimeFormatter.ofPattern("yyyyMM")); |
|
|
|
} else if(Integer.valueOf(2).equals(syncType)) { |
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
date = now.format(DateTimeFormatter.ofPattern("yyyyMMdd")); |
|
|
|
} else { |
|
|
|
log.info("执行全量报表数据同步任务"); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(date)) { |
|
|
|
// 全量同步之前清空数据 |
|
|
|
aflReportFromServiceFeeDataRepo.deleteAll(); |
|
|
|
} else { |
|
|
|
List<String> ids = aflReportFromServiceFeeDataRepo.findIdsByTimeEndLike(date); |
|
|
|
aflReportFromServiceFeeDataRepo.deleteAllById(ids); |
|
|
|
} |
|
|
|
|
|
|
|
checkDate(syncType, time); |
|
|
|
Pageable pageable = Pageable.ofSize(1000); |
|
|
|
if (intPage != null && intPage > 0) { |
|
|
|
pageable.withPage(intPage - 1); |
|
|
|
} |
|
|
|
boolean blnHaveMore = true; |
|
|
|
|
|
|
|
try { |
|
|
|
while (blnHaveMore) { |
|
|
|
Specification<WechatPayApplyResultLog> specification = getWechatPayApplyResultLogSpecification(date); |
|
|
|
Specification<WechatPayApplyResultLog> specification = getWechatPayApplyResultLogSpecification(time); |
|
|
|
Page<WechatPayApplyResultLog> page = wechatPayApplyResultLogRepo.findAll(specification, pageable); |
|
|
|
List<WechatPayApplyResultLog> wechatPayApplyResultLogs = page.getContent(); |
|
|
|
if(CollUtil.isEmpty(wechatPayApplyResultLogs)) { |
|
|
|
log.info("为查询到需要处理汇总的数据 结束任务"); |
|
|
|
log.info("未查询到需要处理汇总的数据 结束任务"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@@ -148,13 +123,19 @@ public class DataSyncServiceImpl implements DataSyncService { |
|
|
|
}); |
|
|
|
List<AflReportServiceFeeData> collect = excelHead50ServiceFeeVOS.stream().map(e -> { |
|
|
|
AflReportServiceFeeData data = BeanUtil.toBean(e, AflReportServiceFeeData.class); |
|
|
|
data.setDataSyncTime(LocalDateTime.now()); |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
data.setDataSyncTime(now); |
|
|
|
String timeEnd = e.getTimeEnd(); |
|
|
|
if (StringUtils.isNotEmpty(timeEnd)) { |
|
|
|
LocalDateTime timeEndTemp = LocalDateTime.parse(timeEnd, dataSourceDf1); |
|
|
|
data.setBusinessDataDate(timeEndTemp.toLocalDate()); |
|
|
|
} |
|
|
|
|
|
|
|
// 更新一个 202411 格式的数据到数据库 便于数据查询 |
|
|
|
int year = now.getYear(); |
|
|
|
int month = now.getMonth().getValue(); |
|
|
|
data.setBusinessDataDateMonth(Integer.valueOf(String.format("%d%02d", year, month))); |
|
|
|
|
|
|
|
return data; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
@@ -175,6 +156,27 @@ public class DataSyncServiceImpl implements DataSyncService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void checkDate(Integer syncType, String time) { |
|
|
|
syncType = syncType == null ? 1 : syncType; |
|
|
|
|
|
|
|
if(Integer.valueOf(1).equals(syncType)) { |
|
|
|
if (time == null || time.length() != 6) { |
|
|
|
printError(time); |
|
|
|
} |
|
|
|
} else if(Integer.valueOf(2).equals(syncType)) { |
|
|
|
if (time == null || time.length() != 8) { |
|
|
|
printError(time); |
|
|
|
} |
|
|
|
} else { |
|
|
|
log.info("执行全量报表数据同步任务"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void printError(String time) { |
|
|
|
log.error("执行报表数据同步任务 参数错误 {}", time); |
|
|
|
throw new RuntimeException("执行报表数据同步任务 参数错误"); |
|
|
|
} |
|
|
|
|
|
|
|
@NotNull |
|
|
|
private static Specification<WechatPayApplyResultLog> getWechatPayApplyResultLogSpecification(String date) { |
|
|
|
return new Specification<>() { |