task-284(收尾/在途批次): 页头按钮归位卡内toolbar+店铺数据记录改名+弹窗报错清除; Java page_size配对/按角色数据范围过滤/撞款导出XLSX/Excel图改WPS DISPIMG/V110查询索引
This commit is contained in:
+9
-10
@@ -41,7 +41,7 @@ import com.nanri.aiimage.modules.similarasin.service.support.SimilarAsinExcelPar
|
||||
import com.nanri.aiimage.modules.similarasin.service.support.SimilarAsinGroupingConverter;
|
||||
import com.nanri.aiimage.modules.similarasin.service.support.SimilarAsinHistoryAssembler;
|
||||
import com.nanri.aiimage.modules.similarasin.util.BoundedImageCache;
|
||||
import com.nanri.aiimage.modules.similarasin.util.ExcelCellImageWriter;
|
||||
import com.nanri.aiimage.modules.similarasin.util.WpsCellImageWriter;
|
||||
import com.nanri.aiimage.modules.similarasin.util.SimilarAsinImageEmbedder;
|
||||
import com.nanri.aiimage.modules.similarasin.util.SimilarAsinLogSupport;
|
||||
import com.nanri.aiimage.modules.file.service.LocalFileStorageService;
|
||||
@@ -4539,9 +4539,8 @@ public class SimilarAsinTaskService {
|
||||
Map<String, SimilarAsinResultRowDto> resultMap,
|
||||
Map<String, SimilarAsinImageEmbedder.ResizedImage> taskImageCache) {
|
||||
ensureResultAssemblyNotInterrupted();
|
||||
// Excel 365 "Place in Cell" 图片:写完 workbook 后 patch richData 单元格图片结构。
|
||||
// 这不是浮动 Drawing,因此点击图片区域会选中单元格,图片不能被拖到任意位置,也不需要工作表保护。
|
||||
ExcelCellImageWriter.Session excelCellImageSession = ExcelCellImageWriter.createSession();
|
||||
// 单元格内嵌图片:写完 workbook 后 patch WPS DISPIMG 结构(WPS/钉钉/飞书/Excel365 均可显示)。
|
||||
WpsCellImageWriter.Session cellImageSession = WpsCellImageWriter.createSession();
|
||||
SimilarAsinImageEmbedder.ImageSpool imageSpool;
|
||||
try {
|
||||
Path spoolDir = Files.createTempDirectory(xlsx.getParentFile().toPath(), "similar-asin-images-");
|
||||
@@ -4642,11 +4641,11 @@ public class SimilarAsinTaskService {
|
||||
// 行高固定到 IMAGE_ROW_HEIGHT_POINTS(Excel 上限 409pt):
|
||||
row.setHeightInPoints(SimilarAsinImageEmbedder.IMAGE_ROW_HEIGHT_POINTS);
|
||||
imageEmbedder.embedAsExcelCellImage(rowIndex, IMG_COL_MAIN,
|
||||
resultRow.getMainUrl(), row, taskImageCache, excelCellImageSession, imageSpool);
|
||||
resultRow.getMainUrl(), row, taskImageCache, cellImageSession, imageSpool);
|
||||
imageEmbedder.embedAsExcelCellImage(rowIndex, IMG_COL_PUZZLE1,
|
||||
resultRow.getPuzzleImg1(), row, taskImageCache, excelCellImageSession, imageSpool);
|
||||
resultRow.getPuzzleImg1(), row, taskImageCache, cellImageSession, imageSpool);
|
||||
imageEmbedder.embedAsExcelCellImage(rowIndex, IMG_COL_PUZZLE2,
|
||||
resultRow.getPuzzleImg2(), row, taskImageCache, excelCellImageSession, imageSpool);
|
||||
resultRow.getPuzzleImg2(), row, taskImageCache, cellImageSession, imageSpool);
|
||||
}
|
||||
rowIndex++;
|
||||
}
|
||||
@@ -4654,14 +4653,14 @@ public class SimilarAsinTaskService {
|
||||
workbook.write(fos);
|
||||
workbook.dispose();
|
||||
}
|
||||
if (!excelCellImageSession.isEmpty()) {
|
||||
if (!cellImageSession.isEmpty()) {
|
||||
try {
|
||||
ensureResultAssemblyNotInterrupted();
|
||||
ExcelCellImageWriter.patchXlsxFile(xlsx, excelCellImageSession);
|
||||
WpsCellImageWriter.patchXlsxFile(xlsx, cellImageSession);
|
||||
} catch (IOException ex) {
|
||||
String cause = ex.toString();
|
||||
log.error("[similar-asin] excel cell image patch failed xlsx={} images={} err={}",
|
||||
xlsx.getAbsolutePath(), excelCellImageSession.size(), cause, ex);
|
||||
xlsx.getAbsolutePath(), cellImageSession.size(), cause, ex);
|
||||
throw new BusinessException("写入相似ASIN结果 Excel 单元格图片失败: " + cause, ex);
|
||||
}
|
||||
}
|
||||
|
||||
+23
-33
@@ -569,8 +569,6 @@ public class SimilarAsinImageEmbedder {
|
||||
* 失败时返回 null;成功返回缩略图。给 Excel richData 单元格图片写入路径使用。
|
||||
*/
|
||||
private ResizedImage downloadAndResize(String trimmedUrl,
|
||||
int colIdx,
|
||||
Row row,
|
||||
Map<String, ResizedImage> taskImageCache) {
|
||||
long startedNanos = System.nanoTime();
|
||||
try {
|
||||
@@ -605,7 +603,6 @@ public class SimilarAsinImageEmbedder {
|
||||
log.warn("[similar-asin][image] embed-fail url={} elapsedMs={} err={}",
|
||||
trimmedUrl, elapsedMs(startedNanos), errorSummary(ex));
|
||||
}
|
||||
row.createCell(colIdx).setCellValue(trimmedUrl);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -614,7 +611,7 @@ public class SimilarAsinImageEmbedder {
|
||||
String url,
|
||||
Row row,
|
||||
Map<String, ResizedImage> taskImageCache,
|
||||
ExcelCellImageWriter.Session excelCellImageSession) {
|
||||
WpsCellImageWriter.Session excelCellImageSession) {
|
||||
return embedAsExcelCellImage(rowIdx, colIdx, url, row, taskImageCache, excelCellImageSession, null);
|
||||
}
|
||||
|
||||
@@ -623,46 +620,39 @@ public class SimilarAsinImageEmbedder {
|
||||
String url,
|
||||
Row row,
|
||||
Map<String, ResizedImage> taskImageCache,
|
||||
ExcelCellImageWriter.Session excelCellImageSession,
|
||||
WpsCellImageWriter.Session excelCellImageSession,
|
||||
ImageSpool imageSpool) {
|
||||
if (url == null || url.isBlank() || excelCellImageSession == null) {
|
||||
return null;
|
||||
}
|
||||
String trimmedUrl = url.trim();
|
||||
SpoolImage spooled = imageSpool == null ? null : imageSpool.get(trimmedUrl);
|
||||
String imageId = null;
|
||||
ImageDim dim = null;
|
||||
if (spooled != null) {
|
||||
Cell cell = row.createCell(colIdx);
|
||||
cell.setCellValue("#VALUE!");
|
||||
excelCellImageSession.registerImage(rowIdx, colIdx, spooled.path());
|
||||
return new ImageDim(spooled.width(), spooled.height());
|
||||
}
|
||||
if (imageSpool != null) {
|
||||
row.createCell(colIdx).setCellValue(trimmedUrl);
|
||||
// 预取已落盘:按路径注册,patch 阶段再读文件,避免整份图片字节驻留堆内存。
|
||||
imageId = excelCellImageSession.registerImageByPath(spooled.path());
|
||||
dim = new ImageDim(spooled.width(), spooled.height());
|
||||
} else if (imageSpool != null) {
|
||||
// 预取未命中说明该 URL 下载失败:不重试、不把 URL 文本写进单元格,留空并打日志。
|
||||
log.warn("[similar-asin][image] cell-image-miss url={} colIdx={} (prefetch did not spool), leave blank",
|
||||
trimmedUrl, colIdx);
|
||||
return null;
|
||||
}
|
||||
ResizedImage thumb = downloadAndResize(trimmedUrl, colIdx, row, taskImageCache);
|
||||
if (thumb == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Cell cell = row.createCell(colIdx);
|
||||
cell.setCellValue("#VALUE!");
|
||||
if (imageSpool == null) {
|
||||
excelCellImageSession.registerImage(rowIdx, colIdx, thumb.bytes());
|
||||
} else {
|
||||
spooled = imageSpool.put(trimmedUrl, thumb);
|
||||
excelCellImageSession.registerImage(rowIdx, colIdx, spooled.path());
|
||||
} else {
|
||||
ResizedImage thumb = downloadAndResize(trimmedUrl, taskImageCache);
|
||||
if (thumb == null) {
|
||||
log.warn("[similar-asin][image] cell-image-miss url={} colIdx={} (download failed), leave blank",
|
||||
trimmedUrl, colIdx);
|
||||
return null;
|
||||
}
|
||||
imageId = excelCellImageSession.registerImage(thumb.bytes());
|
||||
taskImageCache.remove(trimmedUrl);
|
||||
return spooled == null
|
||||
? new ImageDim(thumb.width(), thumb.height())
|
||||
: new ImageDim(spooled.width(), spooled.height());
|
||||
} catch (IOException | RuntimeException ex) {
|
||||
taskImageCache.remove(trimmedUrl);
|
||||
log.warn("[similar-asin][image] excel-cell-image-fail url={} err={}", trimmedUrl, ex.getMessage());
|
||||
row.createCell(colIdx).setCellValue(trimmedUrl);
|
||||
return null;
|
||||
dim = new ImageDim(thumb.width(), thumb.height());
|
||||
}
|
||||
if (imageId != null) {
|
||||
row.createCell(colIdx).setCellFormula(WpsCellImageWriter.dispImgFormula(imageId));
|
||||
}
|
||||
return dim;
|
||||
}
|
||||
|
||||
private boolean hasLocalCachedThumb(String url) {
|
||||
|
||||
+31
-1
@@ -136,7 +136,7 @@ public final class WpsCellImageWriter {
|
||||
buildCellImagesRelsXml(session).getBytes(StandardCharsets.UTF_8));
|
||||
int idx = 1;
|
||||
for (RegisteredImage img : session.images) {
|
||||
writeEntry(zout, "xl/media/cellimage" + idx + ".jpeg", img.bytes);
|
||||
writeEntry(zout, "xl/media/cellimage" + idx + ".jpeg", img.bytes());
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
@@ -299,6 +299,8 @@ public final class WpsCellImageWriter {
|
||||
final List<RegisteredImage> images = new ArrayList<>();
|
||||
// 字节级去重:相同图片只写一次 cellimage{N}.jpeg,节省 xlsx 体积。
|
||||
private final Map<String, String> bytesHashToId = new LinkedHashMap<>();
|
||||
// 磁盘路径去重:同一任务内相同源文件(预取 spool 同一份)只写一次 media,避免内存/体积膨胀。
|
||||
private final Map<String, String> pathHashToId = new LinkedHashMap<>();
|
||||
|
||||
public synchronized String registerImage(byte[] jpegBytes) {
|
||||
if (jpegBytes == null || jpegBytes.length == 0) {
|
||||
@@ -315,6 +317,22 @@ public final class WpsCellImageWriter {
|
||||
return id;
|
||||
}
|
||||
|
||||
/** 按磁盘路径注册(预取 spool 已落盘,避免整份字节驻留内存);按绝对路径去重,重复路径复用同一 media。 */
|
||||
public synchronized String registerImageByPath(Path path) {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
String normalized = path.toAbsolutePath().normalize().toString();
|
||||
String existingId = pathHashToId.get(normalized);
|
||||
if (existingId != null) {
|
||||
return existingId;
|
||||
}
|
||||
String id = newImageId();
|
||||
images.add(new RegisteredImage(id, path));
|
||||
pathHashToId.put(normalized, id);
|
||||
return id;
|
||||
}
|
||||
|
||||
public synchronized boolean isEmpty() {
|
||||
return images.isEmpty();
|
||||
}
|
||||
@@ -347,10 +365,22 @@ public final class WpsCellImageWriter {
|
||||
static final class RegisteredImage {
|
||||
final String id;
|
||||
final byte[] bytes;
|
||||
final Path sourcePath;
|
||||
|
||||
RegisteredImage(String id, byte[] bytes) {
|
||||
this.id = id;
|
||||
this.bytes = bytes;
|
||||
this.sourcePath = null;
|
||||
}
|
||||
|
||||
RegisteredImage(String id, Path sourcePath) {
|
||||
this.id = id;
|
||||
this.bytes = null;
|
||||
this.sourcePath = sourcePath;
|
||||
}
|
||||
|
||||
byte[] bytes() throws IOException {
|
||||
return sourcePath != null ? Files.readAllBytes(sourcePath) : bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user