Commit 705b5a2a by zhouhaibao

feat(excel): 优化批量导入功能支持产品维度数据解析

- 移除 BatchStoreCombinedExcelDTO 中的销售品类相关字段
- 为 BatchStoreProductExcelDTO 添加数据转换注解和填充功能
- 扩展 CreateBusinessApproveExcelListener 支持产品维度解析模式
- 更新上下文对象增加产品详情列表存储功能
- 修改数据访问层删除方法增加流量方ID参数过滤
- 重构 StoreApproveService 支持双重Excel解析流程
- 优化数据库映射配置移除冗余字段并调整删除条件
- 增强服务实现类处理流量方数据更新逻辑
1 parent 2ae6f18d
...@@ -35,25 +35,6 @@ public class BatchStoreCombinedExcelDTO { ...@@ -35,25 +35,6 @@ public class BatchStoreCombinedExcelDTO {
@ExcelProperty(value = "*园区店", index = 8) @ExcelProperty(value = "*园区店", index = 8)
private String parkingStore; private String parkingStore;
@ExcelProperty(value = "*类型", index = 9)
@FillFromPreviousRow
private String productType;
@ExcelProperty(value = "*销售品类", index = 10)
private String productCategory;
@ExcelProperty(value = "*流量结算模式", index = 11)
private String feeSettlementMode;
@ExcelProperty(value = "*渗透率", index = 12, converter = PercentStringConverter.class)
private BigDecimal penetrationRate;
@ExcelProperty(value = "*转化率", index = 13, converter = PercentStringConverter.class)
private BigDecimal conversionRate;
@ExcelProperty(value = "*单车采购产值", index = 14, converter = NumberStringConverter.class)
private BigDecimal revenuePerCar;
@ExcelProperty(value = "*门店单台利润额", index = 15, converter = NumberStringConverter.class) @ExcelProperty(value = "*门店单台利润额", index = 15, converter = NumberStringConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal storeProfitPerCar; private BigDecimal storeProfitPerCar;
...@@ -66,36 +47,6 @@ public class BatchStoreCombinedExcelDTO { ...@@ -66,36 +47,6 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal customerTouchRate; private BigDecimal customerTouchRate;
@ExcelProperty(value = "*转化率", index = 18, converter = PercentStringConverter.class)
private BigDecimal conversionRate2;
@ExcelProperty(value = "*升级客单价", index = 19, converter = NumberStringConverter.class)
private BigDecimal upgradePrice;
@ExcelProperty(value = "*产值", index = 20, converter = NumberStringConverter.class)
private BigDecimal revenue;
@ExcelProperty(value = "*流量费", index = 21, converter = NumberStringConverter.class)
private BigDecimal trafficFee;
@ExcelProperty(value = "*管理层市场费1", index = 22, converter = NumberStringConverter.class)
private BigDecimal marketFee1;
@ExcelProperty(value = "*管理层市场费2", index = 23, converter = NumberStringConverter.class)
private BigDecimal marketFee2;
@ExcelProperty(value = "*一线阳光激励1", index = 24, converter = NumberStringConverter.class)
private BigDecimal incentive1;
@ExcelProperty(value = "*一线阳光激励2", index = 25, converter = NumberStringConverter.class)
private BigDecimal incentive2;
@ExcelProperty(value = "*资源费", index = 26, converter = NumberStringConverter.class)
private BigDecimal resourceFee;
@ExcelProperty(value = "*产品成本", index = 27, converter = NumberStringConverter.class)
private BigDecimal productCost;
@ExcelProperty(value = "*人员成本", index = 28, converter = NumberStringConverter.class) @ExcelProperty(value = "*人员成本", index = 28, converter = NumberStringConverter.class)
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal personnelCost; private BigDecimal personnelCost;
...@@ -112,9 +63,6 @@ public class BatchStoreCombinedExcelDTO { ...@@ -112,9 +63,6 @@ public class BatchStoreCombinedExcelDTO {
@FillFromPreviousRow @FillFromPreviousRow
private BigDecimal otherCost; private BigDecimal otherCost;
@ExcelProperty(value = "*原厂膜回收", index = 32, converter = NumberStringConverter.class)
private BigDecimal recyclingFilm;
@ExcelProperty(value = "*区域运营", index = 33) @ExcelProperty(value = "*区域运营", index = 33)
private String areaOp; private String areaOp;
......
...@@ -9,6 +9,7 @@ public class BatchStoreProductExcelDTO { ...@@ -9,6 +9,7 @@ public class BatchStoreProductExcelDTO {
@ExcelProperty(value = "*类型", index = 9) @ExcelProperty(value = "*类型", index = 9)
@FillFromPreviousRow
private String productType; private String productType;
@ExcelProperty(value = "*销售品类", index = 10) @ExcelProperty(value = "*销售品类", index = 10)
...@@ -17,46 +18,46 @@ public class BatchStoreProductExcelDTO { ...@@ -17,46 +18,46 @@ public class BatchStoreProductExcelDTO {
@ExcelProperty(value = "*流量结算模式", index = 11) @ExcelProperty(value = "*流量结算模式", index = 11)
private String feeSettlementMode; private String feeSettlementMode;
@ExcelProperty(value = "*渗透率", index = 12) @ExcelProperty(value = "*渗透率", index = 12, converter = PercentStringConverter.class)
private BigDecimal penetrationRate; private BigDecimal penetrationRate;
@ExcelProperty(value = "*转化率", index = 13) @ExcelProperty(value = "*转化率", index = 13, converter = PercentStringConverter.class)
private BigDecimal conversionRate; private BigDecimal conversionRate;
@ExcelProperty(value = "*单车采购产值", index = 14) @ExcelProperty(value = "*单车采购产值", index = 14, converter = NumberStringConverter.class)
private BigDecimal revenuePerCar; private BigDecimal revenuePerCar;
@ExcelProperty(value = "*转化率", index = 18) @ExcelProperty(value = "*转化率", index = 18, converter = PercentStringConverter.class)
private BigDecimal conversionRate2; private BigDecimal conversionRate2;
@ExcelProperty(value = "*升级客单价", index = 19) @ExcelProperty(value = "*升级客单价", index = 19, converter = NumberStringConverter.class)
private BigDecimal upgradePrice; private BigDecimal upgradePrice;
@ExcelProperty(value = "*产值", index = 20) @ExcelProperty(value = "*产值", index = 20, converter = NumberStringConverter.class)
private BigDecimal revenue; private BigDecimal revenue;
@ExcelProperty(value = "*流量费", index = 21) @ExcelProperty(value = "*流量费", index = 21, converter = NumberStringConverter.class)
private BigDecimal trafficFee; private BigDecimal trafficFee;
@ExcelProperty(value = "*管理层市场费1", index = 22) @ExcelProperty(value = "*管理层市场费1", index = 22, converter = NumberStringConverter.class)
private BigDecimal marketFee1; private BigDecimal marketFee1;
@ExcelProperty(value = "*管理层市场费2", index = 23) @ExcelProperty(value = "*管理层市场费2", index = 23, converter = NumberStringConverter.class)
private BigDecimal marketFee2; private BigDecimal marketFee2;
@ExcelProperty(value = "*一线阳光激励1", index = 24) @ExcelProperty(value = "*一线阳光激励1", index = 24, converter = NumberStringConverter.class)
private BigDecimal incentive1; private BigDecimal incentive1;
@ExcelProperty(value = "*一线阳光激励2", index = 25) @ExcelProperty(value = "*一线阳光激励2", index = 25, converter = NumberStringConverter.class)
private BigDecimal incentive2; private BigDecimal incentive2;
@ExcelProperty(value = "*资源费", index = 26) @ExcelProperty(value = "*资源费", index = 26, converter = NumberStringConverter.class)
private BigDecimal resourceFee; private BigDecimal resourceFee;
@ExcelProperty(value = "*产品成本", index = 27) @ExcelProperty(value = "*产品成本", index = 27, converter = NumberStringConverter.class)
private BigDecimal productCost; private BigDecimal productCost;
@ExcelProperty(value = "*原厂膜回收", index = 32) @ExcelProperty(value = "*原厂膜回收", index = 32, converter = NumberStringConverter.class)
private BigDecimal recyclingFilm; private BigDecimal recyclingFilm;
} }
...@@ -157,7 +157,11 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob ...@@ -157,7 +157,11 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
if (isSingleStoreMode) { if (isSingleStoreMode) {
processSingleStoreMode((SingleStoreExcelDTO) data, rowIndex); processSingleStoreMode((SingleStoreExcelDTO) data, rowIndex);
} else { } else {
if(data instanceof BatchStoreCombinedExcelDTO) {
processBatchMode((BatchStoreCombinedExcelDTO) data, rowIndex); processBatchMode((BatchStoreCombinedExcelDTO) data, rowIndex);
}else if(data instanceof BatchStoreProductExcelDTO) {
processBatchProductMode((BatchStoreProductExcelDTO) data, rowIndex);
}
} }
} }
...@@ -179,10 +183,15 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob ...@@ -179,10 +183,15 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
@Override @Override
public void doAfterAllAnalysed(AnalysisContext context) { public void doAfterAllAnalysed(AnalysisContext context) {
if (isSingleStoreMode) {
for (StoreWithProductsDTO storeWithProduct : storeWithProducts) { for (StoreWithProductsDTO storeWithProduct : storeWithProducts) {
storeWithProduct.setProductDetails(storeProductDetailDTOList); storeWithProduct.setProductDetails(storeProductDetailDTOList);
} }
this.context.getStoreWithProductsDTOS().addAll(storeWithProducts); this.context.getStoreWithProductsDTOS().addAll(storeWithProducts);
}else{
this.context.getStoreWithProductsDTOS().addAll(storeWithProducts);
this.context.getStoreProductDetailDTOList().addAll(storeProductDetailDTOList);
}
log.info("Excel 解析完成, 总行数: {}, 成功: {}, 失败: {}, 门店数: {}", log.info("Excel 解析完成, 总行数: {}, 成功: {}, 失败: {}, 门店数: {}",
this.context.getTotalRows(), this.context.getTotalRows(),
this.context.getSuccessRows(), this.context.getSuccessRows(),
...@@ -227,10 +236,25 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob ...@@ -227,10 +236,25 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
mergedCellHandler.fillMergedCellValues(data); mergedCellHandler.fillMergedCellValues(data);
BatchStoreExcelDTO storeDTO = parseStoreInfo(data); BatchStoreExcelDTO storeDTO = parseStoreInfo(data);
BatchStoreProductExcelDTO productDTO = parseProductInfo(data);
StoreWithProductsDTO storeWithProductsDTO = createBatchStoreWithProductsDTO(storeDTO); StoreWithProductsDTO storeWithProductsDTO = createBatchStoreWithProductsDTO(storeDTO);
StoreProductDetailDTO productDetailDTO = createBatchStoreProductDetailDTO(productDTO);
storeWithProducts.add(storeWithProductsDTO); storeWithProducts.add(storeWithProductsDTO);
this.context.incrementSuccessRows();
} catch (Exception e) {
String message = String.format("第 %d 行数据转换错误: %s", rowIndex + 1, e.getMessage());
log.error(message);
this.context.addErrorInfo(new ImportErrorInfo(rowIndex + 1, message, data));
this.context.incrementFailRows();
}
}
private void processBatchProductMode(BatchStoreProductExcelDTO data, Integer rowIndex) {
log.info("数据{}", JSONObject.toJSONString(data));
try {
mergedCellHandler.fillMergedCellValues(data);
BatchStoreProductExcelDTO productDTO = parseProductInfo(data);
StoreProductDetailDTO productDetailDTO = createBatchStoreProductDetailDTO(productDTO);
storeProductDetailDTOList.add(productDetailDTO); storeProductDetailDTOList.add(productDetailDTO);
this.context.incrementSuccessRows(); this.context.incrementSuccessRows();
...@@ -256,7 +280,6 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob ...@@ -256,7 +280,6 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
storeDTO.setStoreProfitPerCar(combinedDTO.getStoreProfitPerCar()); storeDTO.setStoreProfitPerCar(combinedDTO.getStoreProfitPerCar());
storeDTO.setDeliveryCount(combinedDTO.getDeliveryCount()); storeDTO.setDeliveryCount(combinedDTO.getDeliveryCount());
storeDTO.setCustomerTouchRate(combinedDTO.getCustomerTouchRate()); storeDTO.setCustomerTouchRate(combinedDTO.getCustomerTouchRate());
storeDTO.setProductCost(combinedDTO.getProductCost());
storeDTO.setPersonnelCost(combinedDTO.getPersonnelCost()); storeDTO.setPersonnelCost(combinedDTO.getPersonnelCost());
storeDTO.setRentCost(combinedDTO.getRentCost()); storeDTO.setRentCost(combinedDTO.getRentCost());
storeDTO.setDepreciation(combinedDTO.getDepreciation()); storeDTO.setDepreciation(combinedDTO.getDepreciation());
...@@ -267,7 +290,7 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob ...@@ -267,7 +290,7 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
return storeDTO; return storeDTO;
} }
private BatchStoreProductExcelDTO parseProductInfo(BatchStoreCombinedExcelDTO combinedDTO) { private BatchStoreProductExcelDTO parseProductInfo(BatchStoreProductExcelDTO combinedDTO) {
BatchStoreProductExcelDTO productDTO = new BatchStoreProductExcelDTO(); BatchStoreProductExcelDTO productDTO = new BatchStoreProductExcelDTO();
productDTO.setProductType(combinedDTO.getProductType()); productDTO.setProductType(combinedDTO.getProductType());
...@@ -311,11 +334,17 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob ...@@ -311,11 +334,17 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
if (dto.getStoreName() != null) { if (dto.getStoreName() != null) {
firstCellStr = dto.getStoreName().trim(); firstCellStr = dto.getStoreName().trim();
} }
} else if (data instanceof BatchStoreProductExcelDTO) {
BatchStoreProductExcelDTO dto = (BatchStoreProductExcelDTO) data;
if (dto.getProductCategory() != null) {
firstCellStr = dto.getProductCategory().trim();
}
} }
log.info("isTailRow: {}", firstCellStr); log.info("isTailRow: {}", firstCellStr);
return StringUtils.isEmpty(firstCellStr) return StringUtils.isEmpty(firstCellStr)
|| firstCellStr.contains("单选项;") || firstCellStr.contains("单选项;")
|| firstCellStr.contains("请输入流量方的系统商户名称,严格按照系统商户名称规范"); || firstCellStr.contains("请输入流量方的系统商户名称,严格按照系统商户名称规范")
|| firstCellStr.contains("请输入上架场景下可销售“类型”和“销售品类”,请严格按照场景下的内容选择填写,不可重复使用");
} }
private StoreWithProductsDTO createStoreWithProductsDTO(SingleStoreExcelDTO data, private StoreWithProductsDTO createStoreWithProductsDTO(SingleStoreExcelDTO data,
......
package cn.com.glsx.dj.oaapproval.service; package cn.com.glsx.dj.oaapproval.service;
import cn.com.glsx.dj.oaapproval.dto.excel.BatchStoreCombinedExcelDTO; import cn.com.glsx.dj.oaapproval.dto.excel.BatchStoreCombinedExcelDTO;
import cn.com.glsx.dj.oaapproval.dto.excel.BatchStoreProductExcelDTO;
import cn.com.glsx.dj.oaapproval.dto.excel.MergedCellHandler; import cn.com.glsx.dj.oaapproval.dto.excel.MergedCellHandler;
import cn.com.glsx.dj.oaapproval.dto.excel.SingleStoreExcelDTO; import cn.com.glsx.dj.oaapproval.dto.excel.SingleStoreExcelDTO;
import cn.com.glsx.dj.oaapproval.dto.store.ExcelImportResult; import cn.com.glsx.dj.oaapproval.dto.store.ExcelImportResult;
import cn.com.glsx.dj.oaapproval.dto.store.StoreApproveDTO; import cn.com.glsx.dj.oaapproval.dto.store.StoreApproveDTO;
import cn.com.glsx.dj.oaapproval.dto.store.StoreProductDetailDTO;
import cn.com.glsx.dj.oaapproval.dto.store.StoreWithProductsDTO; import cn.com.glsx.dj.oaapproval.dto.store.StoreWithProductsDTO;
import cn.com.glsx.dj.oaapproval.dto.store.UpdateStoreApproveDTO; import cn.com.glsx.dj.oaapproval.dto.store.UpdateStoreApproveDTO;
import cn.com.glsx.dj.oaapproval.enums.store.ShelfTypeEnum; import cn.com.glsx.dj.oaapproval.enums.store.ShelfTypeEnum;
...@@ -102,6 +104,11 @@ public class StoreApproveService { ...@@ -102,6 +104,11 @@ public class StoreApproveService {
if (CollectionUtils.isEmpty(storeWithProductsList)) { if (CollectionUtils.isEmpty(storeWithProductsList)) {
throw new RpcServiceException("Excel 解析无数据"); throw new RpcServiceException("Excel 解析无数据");
} }
StoreWithProductsDTO storeWithProductsDTO = storeWithProductsList.get(0);
List<StoreProductDetailDTO> productDetails = storeWithProductsDTO.getProductDetails();
if (CollectionUtils.isEmpty(productDetails)) {
throw new RpcServiceException("Excel 解析无销售品类数据");
}
storeApproveDTO.setStoreWithProductsDTOS(storeWithProductsList); storeApproveDTO.setStoreWithProductsDTOS(storeWithProductsList);
storeApproveDTO.setErrorMessages(globalContext.getErrorMessages()); storeApproveDTO.setErrorMessages(globalContext.getErrorMessages());
...@@ -138,6 +145,34 @@ public class StoreApproveService { ...@@ -138,6 +145,34 @@ public class StoreApproveService {
log.info("Excel 解析完成, 总行数: {}, 成功: {}, 失败: {}", log.info("Excel 解析完成, 总行数: {}, 成功: {}, 失败: {}",
context.getTotalRows(), context.getSuccessRows(), context.getFailRows()); context.getTotalRows(), context.getSuccessRows(), context.getFailRows());
} catch (Exception e) {
if (isExcelHeaderMismatchException(e)) {
log.error("Excel表头校验失败");
throw new ExcelHeaderMismatchException("请上传正确的门店上架表");
}
log.error("读取 Excel 文件失败: {}", e.getMessage(), e);
throw new RpcServiceException("读取 Excel 文件失败: " + e.getMessage());
}
if (!isSingleStoreMode) {
CreateBusinessApproveImportExcelContext context1 = new CreateBusinessApproveImportExcelContext();
try (InputStream inputStream1 = new ByteArrayInputStream(file.getContent())) {
CreateBusinessApproveExcelListener listener1 = new CreateBusinessApproveExcelListener(
context1, isSingleStoreMode, mergedCellHandler);
EasyExcel.read(inputStream1, BatchStoreProductExcelDTO.class, listener1)
.sheet()
.headRowNumber(2)
.doRead();
log.info("Excel 解析完成, 总行数: {}, 成功: {}, 失败: {}",
context1.getTotalRows(), context1.getSuccessRows(), context1.getFailRows());
List<StoreProductDetailDTO> storeProductDetailDTOList = context1.getStoreProductDetailDTOList();
List<StoreWithProductsDTO> storeWithProducts = context.getStoreWithProductsDTOS();
for (StoreWithProductsDTO storeWithProductsDTO : storeWithProducts) {
storeWithProductsDTO.setProductDetails(storeProductDetailDTOList);
}
return context; return context;
} catch (Exception e) { } catch (Exception e) {
if (isExcelHeaderMismatchException(e)) { if (isExcelHeaderMismatchException(e)) {
...@@ -147,6 +182,9 @@ public class StoreApproveService { ...@@ -147,6 +182,9 @@ public class StoreApproveService {
log.error("读取 Excel 文件失败: {}", e.getMessage(), e); log.error("读取 Excel 文件失败: {}", e.getMessage(), e);
throw new RpcServiceException("读取 Excel 文件失败: " + e.getMessage()); throw new RpcServiceException("读取 Excel 文件失败: " + e.getMessage());
} }
}else {
return context;
}
} }
private boolean isExcelHeaderMismatchException(Throwable e) { private boolean isExcelHeaderMismatchException(Throwable e) {
......
package cn.com.glsx.dj.oaapproval.vo; package cn.com.glsx.dj.oaapproval.vo;
import cn.com.glsx.dj.oaapproval.dto.store.ImportErrorInfo; import cn.com.glsx.dj.oaapproval.dto.store.ImportErrorInfo;
import cn.com.glsx.dj.oaapproval.dto.store.StoreProductDetailDTO;
import cn.com.glsx.dj.oaapproval.dto.store.StoreWithProductsDTO; import cn.com.glsx.dj.oaapproval.dto.store.StoreWithProductsDTO;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -13,6 +14,10 @@ public class CreateBusinessApproveImportExcelContext implements Serializable { ...@@ -13,6 +14,10 @@ public class CreateBusinessApproveImportExcelContext implements Serializable {
private List<StoreWithProductsDTO> storeWithProductsDTOS = new ArrayList<>(); private List<StoreWithProductsDTO> storeWithProductsDTOS = new ArrayList<>();
private List<StoreWithProductsDTO> storeWithProducts = new ArrayList<>();
private List<StoreProductDetailDTO> storeProductDetailDTOList = new ArrayList<>();
private List<ImportErrorInfo> errorMessages = new ArrayList<>(); private List<ImportErrorInfo> errorMessages = new ArrayList<>();
private Integer totalRows = 0; private Integer totalRows = 0;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!