refactor(sip): 重构项目订单信息导出功能

- 提取公共方法 addBasicFields 和 processProducts 以简化代码结构
- 使用 Consumer 函数替换重复的添加字段逻辑
- 优化循环结构,提高代码可读性和维护性
master
chenhao 2025-06-26 10:52:33 +08:00
parent 41cdc1fdb6
commit c968dc1d9b
1 changed files with 58 additions and 67 deletions

View File

@ -6,6 +6,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -513,6 +514,102 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService {
for (ProjectOrderInfo info : projectInfos) {
List<String> row = new ArrayList<>();
// 添加基础字段
addBasicFields(info, row);
BigDecimal totalPrice = BigDecimal.ZERO;
BigDecimal maintenancePrice = BigDecimal.ZERO;
OrderExcelNumStaticsDto wssDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto wspDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto lsDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto oneStorDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto nVIDIADto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
List<ProjectProductInfo> maintenanceList = new ArrayList<>();
List<ProjectProductInfo> deployList = new ArrayList<>();
// 添加软件产品列
for (int i = 0; i < maxSoftware; i++) {
if (CollUtil.isNotEmpty(info.getSoftwareProjectProductInfoList()) && i < info.getSoftwareProjectProductInfoList().size()) {
ProjectProductInfo productInfo = info.getSoftwareProjectProductInfoList().get(i);
if (productInfo.getAllPrice() != null) {
totalPrice = totalPrice.add(productInfo.getAllPrice());
}
staticsNum(wssDto, productInfo, WSS_LIST);
staticsNum(wspDto, productInfo, WSP_LIST);
staticsNum(lsDto, productInfo, LS_LIST);
staticsNum(oneStorDto, productInfo, ONE_STOR_LIST);
staticsNum(nVIDIADto, productInfo, N_VIDIA_LIST);
} else {
// addProductRow(null, row, totalPrice);
}
}
// 添加终端产品列
totalPrice = processProducts(info.getHardwareProjectProductInfoList(), maxHardware, row, totalPrice);
int serviceIndex=maxMaintenance;
// 添加服务产品列
for (int maxMaintenanceIndex = 0; serviceIndex >0 ; maxMaintenanceIndex++) {
if (CollUtil.isNotEmpty(info.getMaintenanceProjectProductInfoList()) && maxMaintenanceIndex < info.getMaintenanceProjectProductInfoList().size()) {
ProjectProductInfo productInfo = info.getMaintenanceProjectProductInfoList().get(maxMaintenanceIndex);
if (productInfo != null && StringUtils.isNotEmpty(productInfo.getProductBomCode())
&& MAINTENANCE_SERVICES.contains(productInfo.getProductBomCode())
) {
maintenanceList.add(productInfo);
maintenancePrice = maintenancePrice.add(productInfo.getAllPrice());
continue;
}
if (productInfo != null && StringUtils.isNotEmpty(productInfo.getProductBomCode())
&& DEPLOY_SERVICES.contains(productInfo.getProductBomCode())
) {
deployList.add(productInfo);
continue;
}
totalPrice = addProductRow(productInfo, row, totalPrice);
serviceIndex--;
} else {
addProductRow(null, row, totalPrice);
serviceIndex--;
}
}
//添加部署
totalPrice = processProducts(deployList, maxDeployService, row, totalPrice);
//添加维保
totalPrice = processProducts(maintenanceList, maxMaintenanceService, row, totalPrice);
row.add(8, wssDto.getQuantity().toString());
row.add(9, wssDto.getAllPrice().toString());
row.add(10, wspDto.getQuantity().toString());
row.add(11, wspDto.getAllPrice().toString());
row.add(12, lsDto.getQuantity().toString());
row.add(13, lsDto.getAllPrice().toString());
row.add(14, oneStorDto.getQuantity().toString());
row.add(15, oneStorDto.getAllPrice().toString());
row.add(16, nVIDIADto.getQuantity().toString());
row.add(17, nVIDIADto.getAllPrice().toString());
row.add(info.getShipmentAmount() != null ? info.getShipmentAmount().toString() : "");
row.add(totalPrice.toString());
//维保金额
row.add(maintenancePrice.toString());
dataList.add(row);
}
return dataList;
}
private BigDecimal processProducts(List<ProjectProductInfo> products, int maxCount, List<String> row, BigDecimal currentTotal) {
for (int i = 0; i < maxCount; i++) {
if (CollUtil.isNotEmpty(products) && i < products.size()) {
ProjectProductInfo product = products.get(i);
currentTotal = addProductRow(product, row, currentTotal);
} else {
addProductRow(null, row, currentTotal);
}
}
return currentTotal;
}
private void addBasicFields(ProjectOrderInfo info, List<String> row) {
row.add(info.getProjectCode());
row.add(DateUtil.format(info.getEstimatedOrderTime(), "yyyy-MM-dd"));
row.add(info.getOrderCode());
@ -550,112 +647,6 @@ public class ProjectOrderInfoServiceImpl implements IProjectOrderInfoService {
row.add(info.getPartnerPhone());
// row.add(info.getRemark());
// row.add(DictUtils.getDictLabel("order_status", info.getOrderStatus()));
BigDecimal totalPrice = BigDecimal.ZERO;
BigDecimal maintenancePrice = BigDecimal.ZERO;
OrderExcelNumStaticsDto wssDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto wspDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto lsDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto oneStorDto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
OrderExcelNumStaticsDto nVIDIADto = new OrderExcelNumStaticsDto(BigDecimal.ZERO, 0L);
List<ProjectProductInfo> maintenanceList = new ArrayList<>();
List<ProjectProductInfo> deployList = new ArrayList<>();
// 添加软件产品列
for (int i = 0; i < maxSoftware; i++) {
if (CollUtil.isNotEmpty(info.getSoftwareProjectProductInfoList()) && i < info.getSoftwareProjectProductInfoList().size()) {
ProjectProductInfo productInfo = info.getSoftwareProjectProductInfoList().get(i);
if (productInfo.getAllPrice() != null) {
totalPrice = totalPrice.add(productInfo.getAllPrice());
}
staticsNum(wssDto, productInfo, WSS_LIST);
staticsNum(wspDto, productInfo, WSP_LIST);
staticsNum(lsDto, productInfo, LS_LIST);
staticsNum(oneStorDto, productInfo, ONE_STOR_LIST);
staticsNum(nVIDIADto, productInfo, N_VIDIA_LIST);
} else {
// addProductRow(null, row, totalPrice);
}
}
// 添加终端产品列
for (int i = 0; i < maxHardware; i++) {
if (CollUtil.isNotEmpty(info.getHardwareProjectProductInfoList()) && i < info.getHardwareProjectProductInfoList().size()) {
ProjectProductInfo productInfo = info.getHardwareProjectProductInfoList().get(i);
totalPrice = addProductRow(productInfo, row, totalPrice);
} else {
addProductRow(null, row, totalPrice);
}
}
int serviceIndex=maxMaintenance;
// 添加服务产品列
int maxMaintenanceIndex=-1;
while(serviceIndex>0){
maxMaintenanceIndex++;
if (CollUtil.isNotEmpty(info.getMaintenanceProjectProductInfoList()) && maxMaintenanceIndex < info.getMaintenanceProjectProductInfoList().size()) {
ProjectProductInfo productInfo = info.getMaintenanceProjectProductInfoList().get(maxMaintenanceIndex);
if (productInfo != null && StringUtils.isNotEmpty(productInfo.getProductBomCode())
&& MAINTENANCE_SERVICES.contains(productInfo.getProductBomCode())
) {
maintenanceList.add(productInfo);
maintenancePrice = maintenancePrice.add(productInfo.getAllPrice());
continue;
}
if (productInfo != null && StringUtils.isNotEmpty(productInfo.getProductBomCode())
&& DEPLOY_SERVICES.contains(productInfo.getProductBomCode())
) {
deployList.add(productInfo);
continue;
}
totalPrice = addProductRow(productInfo, row, totalPrice);
serviceIndex--;
} else {
addProductRow(null, row, totalPrice);
serviceIndex--;
}
}
//添加部署
for (int i = 0; i < maxDeployService; i++) {
if (CollUtil.isNotEmpty(deployList) && i < deployList.size()) {
ProjectProductInfo productInfo = deployList.get(i);
totalPrice = addProductRow(productInfo, row, totalPrice);
} else {
addProductRow(null, row, totalPrice);
}
}
//添加维保
for (int i = 0; i < maxMaintenanceService; i++) {
if (CollUtil.isNotEmpty(maintenanceList) && i < maintenanceList.size()) {
ProjectProductInfo productInfo = maintenanceList.get(i);
totalPrice = addProductRow(productInfo, row, totalPrice);
} else {
addProductRow(null, row, totalPrice);
}
}
row.add(8, wssDto.getQuantity().toString());
row.add(9, wssDto.getAllPrice().toString());
row.add(10, wspDto.getQuantity().toString());
row.add(11, wspDto.getAllPrice().toString());
row.add(12, lsDto.getQuantity().toString());
row.add(13, lsDto.getAllPrice().toString());
row.add(14, oneStorDto.getQuantity().toString());
row.add(15, oneStorDto.getAllPrice().toString());
row.add(16, nVIDIADto.getQuantity().toString());
row.add(17, nVIDIADto.getAllPrice().toString());
row.add(info.getShipmentAmount() != null ? info.getShipmentAmount().toString() : "");
row.add(totalPrice.toString());
//维保金额
row.add(maintenancePrice.toString());
dataList.add(row);
}
return dataList;
}