From 654a3829c680c5b1b121cb73c7e86b68a62e2209 Mon Sep 17 00:00:00 2001 From: xupei Date: Tue, 18 Mar 2025 17:39:39 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20=E8=8E=B7=E5=8F=96RGB=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84PanTone=E6=95=B0=E6=8D=AE=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E8=BF=94=E5=9B=9E=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/PanToneServiceImpl.java | 61 +++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java b/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java index 958e4b4e..eeb40cb4 100644 --- a/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java @@ -73,8 +73,7 @@ public class PanToneServiceImpl extends ServiceImpl impl @Override public Map getPantoneByRgbBatch(List colors) { - - HashMap colorValueRgb = new HashMap<>(); + /*HashMap colorValueRgb = new HashMap<>(); HashMap colorIndexRgb = new HashMap<>(); ArrayList values = new ArrayList<>(); colors.forEach(color -> { @@ -91,12 +90,11 @@ public class PanToneServiceImpl extends ServiceImpl impl colorIndexRgb.put(colorValue.getColorIndex(), colorValueRgb.get(colorValue.getColorValue())); }); - List panTones = panToneService.listByIds(colorIndexRgb.keySet()); + List panTones = panToneService.listByIds(colorIndexRgb.keySet()); // pantone数据不完整,导致有的index无对应pantone值 ArrayList pantoneVOS = new ArrayList<>(); panTones.forEach(panTone -> { pantoneVOS.add(coverPanToneToVo(panTone)); }); - HashMap colorPantoneVO = new HashMap<>(); pantoneVOS.forEach(pantoneVO -> { int colorIndex = pantoneVO.getId(); @@ -109,7 +107,6 @@ public class PanToneServiceImpl extends ServiceImpl impl colorPantoneVO.put(colorIndexRgb.get(pantoneVO.getId()), pantoneVO); } }); - // 覆盖pantone中的rgb值,使用前端传过来的rgb值 for (Map.Entry pantoneVOEntry : colorPantoneVO.entrySet()) { int[] rgb = Arrays.stream(pantoneVOEntry.getKey().split("\\s+")).mapToInt(Integer::parseInt).toArray(); @@ -117,6 +114,60 @@ public class PanToneServiceImpl extends ServiceImpl impl pantoneVOEntry.getValue().setG(rgb[1]); pantoneVOEntry.getValue().setB(rgb[2]); } + return colorPantoneVO;*/ + // 用于存储 RGB 值对应的 HSV 计算值 + Map colorValueRgb = new HashMap<>(); + // 用于存储 ColorIndex 对应的 RGB 值 + Map colorIndexRgb = new HashMap<>(); + // 存储所有计算出的 HSV 值 + List values = new ArrayList<>(); + + // 1. 遍历 colors,计算 HSV 值并存储 + colors.forEach(color -> { + int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray(); + int[] hsv = PantoneUtils.rgbToHsv(rgb); + int value = (hsv[0] * 101 * 101) + (hsv[1] * 101) + hsv[2]; + colorValueRgb.put(value, color); + values.add(value); + }); + + // 2. 查询 ColorLookupTable 数据 + List colorValueList = colorLoopUpTableService.getByColorValueList(values); + colorValueList.forEach(colorValue -> { + colorIndexRgb.put(colorValue.getColorIndex(), colorValueRgb.get(colorValue.getColorValue())); + }); + + // 3. 查询 Pantone 数据 + Set colorIndexes = colorIndexRgb.keySet(); + List panTones = panToneService.listByIds(colorIndexes); + + // 4. 将 PanTone 转换为 PantoneVO,并处理缺失的 Pantone 数据 + Map pantoneVOMap = new HashMap<>(); + panTones.forEach(panTone -> { + pantoneVOMap.put(panTone.getPantoneIndex(), coverPanToneToVo(panTone)); + }); + + // 5. 处理缺失的 Pantone 数据,创建默认的 PantoneVO + for (Integer colorIndex : colorIndexes) { + if (!pantoneVOMap.containsKey(colorIndex)) { + String rgbValue = colorIndexRgb.get(colorIndex); + int[] rgb = Arrays.stream(rgbValue.split("\\s+")).mapToInt(Integer::parseInt).toArray(); + PantoneVO defaultPantoneVO = new PantoneVO(); + defaultPantoneVO.setR(rgb[0]); + defaultPantoneVO.setG(rgb[1]); + defaultPantoneVO.setB(rgb[2]); + pantoneVOMap.put(colorIndex, defaultPantoneVO); + } + } + + // 6. 构建最终结果 + Map colorPantoneVO = new HashMap<>(); + for (Map.Entry entry : pantoneVOMap.entrySet()) { + Integer colorIndex = entry.getKey(); + PantoneVO pantoneVO = entry.getValue(); + String rgbValue = colorIndexRgb.get(colorIndex); + colorPantoneVO.put(rgbValue, pantoneVO); + } return colorPantoneVO; }