| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | |
| | | private final StandardTemplateService standardTemplateService; |
| | | |
| | | // 新增:内存去重集合(记录唯一键) |
| | | private Set<String> uniqueKeys = new HashSet<>(); |
| | | |
| | | public MultiSheetImportListener(StructureItemParameterService parameterService, StandardTemplateService standardTemplateService, |
| | | ISysDictTypeService dictTypeService) { |
| | | this.parameterService = parameterService; |
| | |
| | | |
| | | @Override |
| | | public void invoke(StructureItemParameter data, AnalysisContext context) { |
| | | |
| | | String uniqueKey = buildUniqueKey(data); |
| | | if (uniqueKeys.contains(uniqueKey)) { |
| | | log.warn("发现重复数据,已跳过: {} (Sheet: {}, 行号: {})", |
| | | uniqueKey, |
| | | currentSheetName, |
| | | context.readRowHolder().getRowIndex() + 1 |
| | | ); |
| | | return; |
| | | } |
| | | uniqueKeys.add(uniqueKey); |
| | | |
| | | data.setId(null); |
| | | // 测试对象 |
| | | if (data.getSample() == null) { |
| | |
| | | // 打印完整错误堆栈(调试时开启) |
| | | log.error("Sheet[{}] 第{}行第{}列解析失败: {}", sheetName, rowIndex, columnIndex, errorMsg); |
| | | } |
| | | |
| | | private String buildUniqueKey(StructureItemParameter data) { |
| | | return String.join("|", |
| | | ObjectUtils.defaultIfNull(data.getInspectionItem(), ""), |
| | | ObjectUtils.defaultIfNull(data.getInspectionItemEn(),""), |
| | | ObjectUtils.defaultIfNull(data.getProduct(),""), |
| | | ObjectUtils.defaultIfNull(data.getInspectionItemSubclass(), ""), |
| | | ObjectUtils.defaultIfNull(data.getSample(), ""), |
| | | ObjectUtils.defaultIfNull(data.getInspectionItemClass(), "") |
| | | ); |
| | | } |
| | | } |