Commit 5aafef49 by zhouhaibao

refactor(excel): 优化Excel解析中的对象复制逻辑

- 导入ProductCategoryRuleDTO类以支持产品分类规则处理
- 添加BeanUtils依赖用于对象属性复制
- 使用Stream API和BeanUtils替代直接赋值实现深拷贝
- 避免原始数据被意外修改确保数据完整性
1 parent c6b30649
......@@ -5,6 +5,7 @@ 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.store.ImportErrorInfo;
import cn.com.glsx.dj.oaapproval.dto.store.StoreWithProductsDTO;
import cn.com.glsx.dj.oaapproval.dto.store.StoreWithProductsDTO.ProductCategoryRuleDTO;
import cn.com.glsx.dj.oaapproval.vo.CreateBusinessApproveImportExcelContext;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
......@@ -19,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@Slf4j
public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Object> {
......@@ -174,7 +176,13 @@ public class CreateBusinessApproveExcelListener extends AnalysisEventListener<Ob
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
for (StoreWithProductsDTO storeWithProduct : storeWithProducts) {
storeWithProduct.setProductCategoryRules(ruleDTOS);
List<ProductCategoryRuleDTO> newRuleList = ruleDTOS.stream().map(ruleDTO -> {
ProductCategoryRuleDTO newRule = new ProductCategoryRuleDTO();
BeanUtils.copyProperties(ruleDTO, newRule);
return newRule;
}).collect(Collectors.toList());
storeWithProduct.setProductCategoryRules(newRuleList);
}
this.context.getStoreWithProductsDTOS().addAll(storeWithProducts);
log.info("Excel 解析完成, 总行数: {}, 成功: {}, 失败: {}, 门店数: {}",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!