Przeglądaj źródła

修改数据同步逻辑

feature/report-forms
JianShengFei 9 miesięcy temu
rodzic
commit
bc31865cfd

+ 10
- 0
src/main/java/com/qtzl/alterSales/dao/entity/second/AflReportServiceFeeData.java Wyświetl plik

@@ -27,6 +27,16 @@ public class AflReportServiceFeeData extends StringUUIDEntity{
private String cardNo;
private String obuNo;
private LocalDateTime dataSyncTime;
private Integer businessDataDateMonth;

@Column(name = "business_data_date_month")
public Integer getBusinessDataDateMonth() {
return businessDataDateMonth;
}

public void setBusinessDataDateMonth(Integer businessDataDateMonth) {
this.businessDataDateMonth = businessDataDateMonth;
}

@Column(name = "time_end")
public String getTimeEnd() {

+ 1
- 1
src/main/java/com/qtzl/alterSales/manager/handler/DataSyncFor50ServiceFeeHandler.java Wyświetl plik

@@ -31,7 +31,7 @@ public class DataSyncFor50ServiceFeeHandler extends AbstractAfterSalesManager<Da
@Override
public String handleInternal(String filename, DataSyncFor50ServiceFeeRequest request) throws Exception {
try {
dataSyncService.dataSyncForServiceFee(request.getSyncType(), null, request.getIntPage());
dataSyncService.dataSyncForServiceFee(request.getSyncType(), request.getTime());
return new NoAttributeResponse().toJson();
} catch (Exception e) {
if (e instanceof ServiceHandleException) {

+ 4
- 17
src/main/java/com/qtzl/alterSales/manager/model/protocol/sales/DataSyncFor50ServiceFeeRequest.java Wyświetl plik

@@ -1,8 +1,6 @@
package com.qtzl.alterSales.manager.model.protocol.sales;

import cn.com.taiji.common.model.BaseModel;
import com.qtzl.alterSales.manager.service.AfterSalesCmd;
import com.txffp.api.core.manager.comm.annotation.Api;

/***
* <p>
@@ -14,17 +12,14 @@ public class DataSyncFor50ServiceFeeRequest extends BaseModel {
// 1 按月同步 2 按天同步
private Integer syncType;

// 按月同步时间 1-12. 按天同步时间 1-30(这里的按天是当月的某一天)
private Integer time;
// 按月同步时间 1-12. 传1 则数据为 202411 格式 . 按天同步时间 1-30 传2 则数据为 20241130 格式
private String time;

// 重新执行的页码
private Integer intPage;

public Integer getTime() {
public String getTime() {
return time;
}

public void setTime(Integer time) {
public void setTime(String time) {
this.time = time;
}

@@ -35,12 +30,4 @@ public class DataSyncFor50ServiceFeeRequest extends BaseModel {
public void setSyncType(Integer syncType) {
this.syncType = syncType;
}

public Integer getIntPage() {
return intPage;
}

public void setIntPage(Integer intPage) {
this.intPage = intPage;
}
}

+ 13
- 1
src/main/java/com/qtzl/alterSales/manager/quartz/ReportFromDataHandleTask.java Wyświetl plik

@@ -2,20 +2,32 @@ package com.qtzl.alterSales.manager.quartz;

import cn.com.taiji.common.manager.AbstractManager;
import com.qtzl.alterSales.manager.service.DataSyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class ReportFromDataHandleTask extends AbstractManager {

// 日志对象
private static final Logger log = LoggerFactory.getLogger(ReportFromDataHandleTask.class);

@Resource
private DataSyncService dataSyncService;

@Scheduled(cron = "0 0 4 * * ?")
public void execute() throws Exception {
dataSyncService.dataSyncForServiceFee(2, null, null);
// 获取前一天的时间
LocalDateTime localDateTime = LocalDateTime.now().minusDays(1);
String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
log.info("执行数据同步任务开始 同步的目标数据时间:{}", format);
dataSyncService.dataSyncForServiceFee(2, format);
log.info("执行数据同步任务结束");
}



+ 1
- 1
src/main/java/com/qtzl/alterSales/manager/service/DataSyncService.java Wyświetl plik

@@ -2,6 +2,6 @@ package com.qtzl.alterSales.manager.service;

public interface DataSyncService {

void dataSyncForServiceFee(Integer syncType, Integer time, Integer intPage) throws Exception;
void dataSyncForServiceFee(Integer syncType, String time) throws Exception;

}

+ 34
- 32
src/main/java/com/qtzl/alterSales/manager/service/DataSyncServiceImpl.java Wyświetl plik

@@ -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<>() {

Ładowanie…
Anuluj
Zapisz