结算明细字段映射调整

This commit is contained in:
dengwc 2024-04-11 15:06:21 +08:00
parent a39f3e50af
commit 213e0c9f29
3 changed files with 150 additions and 125 deletions

View File

@ -29,9 +29,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
@Slf4j
@Service
@ -95,11 +93,32 @@ public class LyStatementOrder {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String startTime = startDate.atStartOfDay().format(formatter);
String endTime = LocalDateTime.now().format(formatter);
//创建一个线程池并行执行
ThreadPoolExecutor executor = executeTask(onlineStatementList, startTime, endTime);
try {
// 关闭线程池
executor.shutdown();
// 等待所有任务执行完成或者超时时间到达这里设置为一天
boolean flag = executor.awaitTermination(1, TimeUnit.HOURS);
} catch (InterruptedException e) {
// 处理中断异常
log.error(e.getMessage());
// 强制关闭线程池
executor.shutdownNow();
}
log.info("保存成功!");
}
private ThreadPoolExecutor executeTask(ArrayList<ResStatementList.OnlineStatementList> onlineStatementList, String startTime, String endTime) {
ThreadPoolExecutor executor = new ThreadPoolExecutor(
4, // 核心线程数
4, // 最大线程数
0L, // 空闲线程存活时间
TimeUnit.MILLISECONDS, // 存活时间单位
new LinkedBlockingQueue<>(100) // 任务队列设置一个有限大小的队列
);
for (ResStatementList.OnlineStatementList onlineStatement : onlineStatementList) {
String statementCode = onlineStatement.getStatementCode();//对账单编码
// 提交任务给线程池处理
// 定义线程池可以根据实际情况调整线程数量
ExecutorService executor = Executors.newFixedThreadPool(4); // 创建一个包含4个线程的线程池
//1.查询机票账单详情
executor.submit(() -> flightStatement(statementCode, startTime, endTime));
//2.查询酒店账单详情
@ -108,19 +127,8 @@ public class LyStatementOrder {
executor.submit(() -> trainStatement(statementCode, startTime, endTime));
//4.查询用车账单详情
executor.submit(() -> carStatement(statementCode, startTime, endTime));
// 关闭线程池
executor.shutdown();
try {
// 等待所有任务执行完成或者超时时间到达这里设置为一天
boolean flag = executor.awaitTermination(1, TimeUnit.HOURS);
} catch (InterruptedException e) {
// 处理中断异常
log.error(e.getMessage());
// 强制关闭线程池
executor.shutdownNow();
}
}
log.info("保存成功!");
return executor;
}
/**

View File

@ -2,6 +2,7 @@ package com.chint.domain.service.order_record;
import com.chint.application.commands.LYOrderRecordGenerateCommand;
import com.chint.application.commands.OrderRecordGenerateCommand;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.order_record.OrderCarRecord;
import com.chint.domain.aggregates.order.order_record.OrderFlightRecord;
import com.chint.domain.aggregates.order.order_record.OrderHotelRecord;
@ -19,14 +20,19 @@ import com.chint.infrastructure.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@Component
public class LYOrderRecordDomainService {
@ -50,124 +56,137 @@ public class LYOrderRecordDomainService {
@Autowired
private OrderDetailDomainService orderDetailDomainService;
@Autowired
private DataSourceTransactionManager transactionManager;
@Transactional
@ListenTo(command = "LYOrderRecordGenerateCommand", order = 0)
public List<OrderFlightRecord> generateFlightRecord(LYOrderRecordGenerateCommand command) {
ArrayList<OrderFlightRecord> orderFlightRecordList = new ArrayList<>();
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderFlightRecord> lyOrderFlightRecordPage = jdbcLyOrderFlightRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderFlightRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderFlightRecord> lyOrderFlightRecordPageList = lyOrderFlightRecordPage.toList();
ArrayList<OrderFlightRecord> orderFlightRecords = new ArrayList<>(100);
for (LyOrderFlightRecord lyOrderFlightRecord : lyOrderFlightRecordPageList) {
OrderFlightRecord orderFlightRecord = lyOrderRecordExtensionFactory.createFlightOrderRecord(lyOrderFlightRecord);//转换
orderFlightRecords.add(orderFlightRecord);
}
//保存数据
orderDetailDomainService.saveFlightOrderRecordBatch(orderFlightRecords);
orderFlightRecordList.addAll(orderFlightRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderFlightRecord.updateStatusByNullStatus();
return orderFlightRecordList;
public void generateFlightRecord(LYOrderRecordGenerateCommand command) {
useThread(() -> {
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderFlightRecord> lyOrderFlightRecordPage = jdbcLyOrderFlightRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderFlightRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderFlightRecord> lyOrderFlightRecordPageList = lyOrderFlightRecordPage.toList();
ArrayList<OrderFlightRecord> orderFlightRecords = new ArrayList<>(100);
for (LyOrderFlightRecord lyOrderFlightRecord : lyOrderFlightRecordPageList) {
OrderFlightRecord orderFlightRecord = lyOrderRecordExtensionFactory.createFlightOrderRecord(lyOrderFlightRecord);//转换
orderFlightRecords.add(orderFlightRecord);
}
//保存数据
orderDetailDomainService.saveFlightOrderRecordBatch(orderFlightRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderFlightRecord.updateStatusByNullStatus();
});
}
@Transactional
@ListenTo(command = "LYOrderRecordGenerateCommand", order = 1)
public List<OrderHotelRecord> generateHotelRecord(LYOrderRecordGenerateCommand command) {
ArrayList<OrderHotelRecord> orderHotelRecordList = new ArrayList<>();
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderHotelRecord> lyOrderHotelRecordPage = jdbcLyOrderHotelRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderHotelRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderHotelRecord> lyOrderHotelRecordPageList = lyOrderHotelRecordPage.toList();
ArrayList<OrderHotelRecord> orderHotelRecords = new ArrayList<>(100);
for (LyOrderHotelRecord lyOrderHotelRecord : lyOrderHotelRecordPageList) {
OrderHotelRecord orderHotelRecord = lyOrderRecordExtensionFactory.createHotelOrderRecord(lyOrderHotelRecord);//转换
orderHotelRecords.add(orderHotelRecord);
}
//保存数据
orderDetailDomainService.saveHotelOrderRecordBatch(orderHotelRecords);
orderHotelRecordList.addAll(orderHotelRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderHotelRecord.updateStatusByNullStatus();
return orderHotelRecordList;
public void generateHotelRecord(LYOrderRecordGenerateCommand command) {
useThread(() -> {
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderHotelRecord> lyOrderHotelRecordPage = jdbcLyOrderHotelRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderHotelRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderHotelRecord> lyOrderHotelRecordPageList = lyOrderHotelRecordPage.toList();
ArrayList<OrderHotelRecord> orderHotelRecords = new ArrayList<>(100);
for (LyOrderHotelRecord lyOrderHotelRecord : lyOrderHotelRecordPageList) {
OrderHotelRecord orderHotelRecord = lyOrderRecordExtensionFactory.createHotelOrderRecord(lyOrderHotelRecord);//转换
orderHotelRecords.add(orderHotelRecord);
}
//保存数据
orderDetailDomainService.saveHotelOrderRecordBatch(orderHotelRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderHotelRecord.updateStatusByNullStatus();
});
}
@Transactional
@ListenTo(command = "LYOrderRecordGenerateCommand", order = 2)
public List<OrderTrainRecord> generateTrainRecord(LYOrderRecordGenerateCommand command) {
ArrayList<OrderTrainRecord> orderTrainRecordsList = new ArrayList<>();
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderTrainRecord> lyOrderTrainRecordPage = jdbcLyOrderTrainRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderTrainRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderTrainRecord> lyOrderTrainRecordPageList = lyOrderTrainRecordPage.toList();
ArrayList<OrderTrainRecord> orderTrainRecords = new ArrayList<>(100);
for (LyOrderTrainRecord lyOrderTrainRecord : lyOrderTrainRecordPageList) {
OrderTrainRecord orderTrainRecord = lyOrderRecordExtensionFactory.createTrainOrderRecord(lyOrderTrainRecord);//转换
orderTrainRecords.add(orderTrainRecord);
}
//保存数据
orderDetailDomainService.saveTrainOrderRecordBatch(orderTrainRecords);
orderTrainRecordsList.addAll(orderTrainRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderTrainRecord.updateStatusByNullStatus();
return orderTrainRecordsList;
public void generateTrainRecord(LYOrderRecordGenerateCommand command) {
useThread(() -> {
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderTrainRecord> lyOrderTrainRecordPage = jdbcLyOrderTrainRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderTrainRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderTrainRecord> lyOrderTrainRecordPageList = lyOrderTrainRecordPage.toList();
ArrayList<OrderTrainRecord> orderTrainRecords = new ArrayList<>(100);
for (LyOrderTrainRecord lyOrderTrainRecord : lyOrderTrainRecordPageList) {
OrderTrainRecord orderTrainRecord = lyOrderRecordExtensionFactory.createTrainOrderRecord(lyOrderTrainRecord);//转换
orderTrainRecords.add(orderTrainRecord);
}
//保存数据
orderDetailDomainService.saveTrainOrderRecordBatch(orderTrainRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderTrainRecord.updateStatusByNullStatus();
});
}
@Transactional
@ListenTo(command = "LYOrderRecordGenerateCommand", order = 3)
public List<OrderCarRecord> generateCarRecord(LYOrderRecordGenerateCommand command) {
ArrayList<OrderCarRecord> orderCarRecordsList = new ArrayList<>();
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderCarRecord> lyOrderCarRecordPage = jdbcLyOrderCarRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderCarRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderCarRecord> lyOrderCarRecordPageList = lyOrderCarRecordPage.toList();
ArrayList<OrderCarRecord> orderCarRecords = new ArrayList<>(100);
for (LyOrderCarRecord lyOrderCarRecord : lyOrderCarRecordPageList) {
OrderCarRecord orderCarRecord = lyOrderRecordExtensionFactory.createCarOrderRecord(lyOrderCarRecord);//转换
orderCarRecords.add(orderCarRecord);
public void generateCarRecord(LYOrderRecordGenerateCommand command) {
useThread(() -> {
int count = 0;//初始化变量
int pageSize = 100; // 假设每页大小为10
int LoopNum;//需要的循环数
do {
PageRequest pageResult = PageRequest.of(count, pageSize);
Page<LyOrderCarRecord> lyOrderCarRecordPage = jdbcLyOrderCarRecord.findAllByStatusIsNull(pageResult);
long totalElements = lyOrderCarRecordPage.getTotalElements();//总数
LoopNum = (int) Math.ceil((double) totalElements / pageSize); // 计算总页数并向上取整
//数据
List<LyOrderCarRecord> lyOrderCarRecordPageList = lyOrderCarRecordPage.toList();
ArrayList<OrderCarRecord> orderCarRecords = new ArrayList<>(100);
for (LyOrderCarRecord lyOrderCarRecord : lyOrderCarRecordPageList) {
OrderCarRecord orderCarRecord = lyOrderRecordExtensionFactory.createCarOrderRecord(lyOrderCarRecord);//转换
orderCarRecords.add(orderCarRecord);
}
//保存数据
orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderCarRecord.updateStatusByNullStatus();
});
}
//使用线程并行执行
public void useThread(Runnable runnable) {
new Thread(() -> {
// 开启事务
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = transactionManager.getTransaction(def);
try {
runnable.run();//执行具体方法
// 提交事务
transactionManager.commit(status);
} catch (Exception e) {
// 发生异常时回滚事务
transactionManager.rollback(status);
}
//保存数据
orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecords);
orderCarRecordsList.addAll(orderCarRecords);
count++;
} while (count < LoopNum);
//修改数据将状态为null的设置为1
jdbcLyOrderCarRecord.updateStatusByNullStatus();
return orderCarRecordsList;
}).start();
}
}

View File

@ -34,9 +34,7 @@ public class WebConfig implements WebMvcConfigurer {
//调用bean
registry.addInterceptor(getMyRequestLoggingInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/public/**/pageQuery", "/order/pageQuery", "/OrderDetail/query/**",
"/order/query/**", "/location/**", "/OrderDetail/record/query");
.excludePathPatterns("/location/**", "/**/query/**", "/**/pageQuery/**");
}
@Override