Commit c33b7602 by kk

存储

parent 4d9c948f
......@@ -318,6 +318,111 @@ public class MyTest2 {
}
@Test
public void exportSkuInfringementKeywords() throws Exception {
Path inputPath = Paths.get("2026-06-12_vtot_羊绒商品认证数据确认.xlsx");
Path outputPath = Paths.get("2026-06-12_vtot_羊绒商品认证数据确认-侵权词.xlsx");
DataFormatter dataFormatter = new DataFormatter();
try (InputStream inputStream = Files.newInputStream(inputPath);
Workbook workbook = WorkbookFactory.create(inputStream)) {
Sheet sheet = workbook.getSheetAt(0);
Row headerRow = sheet.getRow(0);
if (Objects.isNull(headerRow)) {
throw new IllegalStateException("Excel第一行表头为空");
}
int skuColumnIndex = getColumnIndex(headerRow, "SKU", dataFormatter);
if (skuColumnIndex < 0) {
throw new IllegalStateException("未找到SKU列");
}
int hasInfringementColumnIndex = getOrCreateColumnIndex(headerRow, "A+页面是否涉及侵权词", dataFormatter);
int infringementKeywordsColumnIndex = getOrCreateColumnIndex(headerRow, "侵权词", dataFormatter);
Set<String> skuSet = new LinkedHashSet<>();
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (Objects.isNull(row)) {
continue;
}
String sku = getCellString(row.getCell(skuColumnIndex), dataFormatter);
if (!StringUtils.isEmpty(sku)) {
skuSet.add(sku);
}
}
Map<String, Set<Long>> skuPlanIdsMap = new HashMap<>();
Set<Long> allPlanIds = new HashSet<>();
Lists.partition(new ArrayList<>(skuSet), 500).forEach(skuList -> {
List<APlusProduct> aPlusProducts = aPlusProductMapper.selectList(Wrappers.<APlusProduct>lambdaQuery()
.in(APlusProduct::getSku, skuList)
.select(APlusProduct::getSku, APlusProduct::getAPlusPlanId));
for (APlusProduct aPlusProduct : aPlusProducts) {
if (Objects.isNull(aPlusProduct.getAPlusPlanId())) {
continue;
}
skuPlanIdsMap.computeIfAbsent(aPlusProduct.getSku(), k -> new HashSet<>()).add(aPlusProduct.getAPlusPlanId());
allPlanIds.add(aPlusProduct.getAPlusPlanId());
}
});
Map<Long, String> planRiskMap = new HashMap<>();
Lists.partition(new ArrayList<>(allPlanIds), 500).forEach(planIdList -> {
List<VisualAPlusPlan> plans = visualAPlusPlanMapper.selectList(Wrappers.<VisualAPlusPlan>lambdaQuery()
.in(VisualAPlusPlan::getId, planIdList)
.select(VisualAPlusPlan::getId, VisualAPlusPlan::getRiskCheckArea));
for (VisualAPlusPlan plan : plans) {
planRiskMap.put(plan.getId(), plan.getRiskCheckArea());
}
});
Map<String, String> skuKeywordsMap = new HashMap<>();
for (Map.Entry<String, Set<Long>> entry : skuPlanIdsMap.entrySet()) {
Set<String> hitKeywords = new LinkedHashSet<>();
for (Long planId : entry.getValue()) {
String keywords = extractRiskKeywords(planRiskMap.get(planId));
if (!StringUtils.isEmpty(keywords)) {
hitKeywords.addAll(Arrays.asList(keywords.split(",")));
}
}
if (!hitKeywords.isEmpty()) {
skuKeywordsMap.put(entry.getKey(), String.join(",", hitKeywords));
}
}
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
if (Objects.isNull(row)) {
continue;
}
String sku = getCellString(row.getCell(skuColumnIndex), dataFormatter);
String keywords = StringUtils.isEmpty(sku) ? "" : skuKeywordsMap.getOrDefault(sku, "");
boolean hasInfringement = !StringUtils.isEmpty(keywords);
Cell hasCell = getOrCreateCell(row, hasInfringementColumnIndex);
if (hasInfringementColumnIndex > 0) {
copyCellStyle(workbook, row.getCell(hasInfringementColumnIndex - 1), hasCell);
}
hasCell.setCellValue(hasInfringement ? "是" : "否");
Cell kwCell = getOrCreateCell(row, infringementKeywordsColumnIndex);
if (infringementKeywordsColumnIndex > 0) {
copyCellStyle(workbook, row.getCell(infringementKeywordsColumnIndex - 1), kwCell);
}
kwCell.setCellValue(keywords == null ? "" : keywords);
}
sheet.autoSizeColumn(hasInfringementColumnIndex);
sheet.autoSizeColumn(infringementKeywordsColumnIndex);
try (OutputStream outputStream = Files.newOutputStream(outputPath)) {
workbook.write(outputStream);
}
}
log.info("导出完成:{}", outputPath.toAbsolutePath());
}
@Test
public void exportSkuIsMakePic() throws Exception {
ExcelUtil<SkuImageDesignDTO> util = new ExcelUtil<>(SkuImageDesignDTO.class);
List<SkuImageDesignDTO> list = util.importExcel(Files.newInputStream(new File("sku-是否作图.xlsx").toPath()));
......@@ -352,6 +457,23 @@ public class MyTest2 {
return -1;
}
private int getOrCreateColumnIndex(Row headerRow, String columnName, DataFormatter dataFormatter) {
int existingIndex = getColumnIndex(headerRow, columnName, dataFormatter);
if (existingIndex >= 0) {
return existingIndex;
}
int newIndex = headerRow.getLastCellNum();
if (newIndex < 0) {
newIndex = 0;
}
Cell headerCell = getOrCreateCell(headerRow, newIndex);
headerCell.setCellValue(columnName);
if (newIndex > 0) {
copyCellStyle(headerRow.getSheet().getWorkbook(), headerRow.getCell(newIndex - 1), headerCell);
}
return newIndex;
}
private String getCellString(Cell cell, DataFormatter dataFormatter) {
if (Objects.isNull(cell)) {
return "";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment