From 614b8d0948e4ecdb3c3c50abd4f5a1275202f26a Mon Sep 17 00:00:00 2001 From: xupei Date: Fri, 21 Feb 2025 17:56:50 +0800 Subject: [PATCH 01/12] to prod --- .../com/ai/da/common/config/MyTaskScheduler.java | 4 ++-- src/main/java/com/ai/da/common/task/AccountTask.java | 12 ++++++------ src/main/java/com/ai/da/common/task/PaymentTask.java | 8 ++++---- src/main/resources/application.properties | 4 ++-- src/main/resources/payment.properties | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java index 9dc8cd13..86d82fd4 100644 --- a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -53,7 +53,7 @@ public class MyTaskScheduler { // 定时任务,每十五天执行一次 // @Scheduled(cron = "0 0 0 ? * MON") -// @Scheduled(cron = "0 0 0 */15 * ?") + @Scheduled(cron = "0 0 0 */15 * ?") public void checkExpiry() { // 检测正式用户是否快要过期 QueryWrapper qw = new QueryWrapper<>(); @@ -87,7 +87,7 @@ public class MyTaskScheduler { } } } -// @Scheduled(cron = "0 0 9 * * ?") + @Scheduled(cron = "0 0 9 * * ?") public void sendTrialOrderExcelToManagements() { // 获取前一天日期 LocalDate yesterday = LocalDate.now().minusDays(1); diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index ec6bd430..1deeb4c2 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -25,20 +25,20 @@ public class AccountTask { * 每个月月初只刷新年付用户的积分 */ // @Scheduled(cron = "59 59 23 * * ?") -// @Scheduled(cron = "0 0 0 1 * ?") + @Scheduled(cron = "0 0 0 1 * ?") public void refreshCreditsMonthly() { log.info("每月1号0点 将年费用户积分重置为 6000"); accountService.refreshCreditsWeekly(); } -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void getPaidUser() { // 获取code-create 表中 指定日期之后 订单状态为wc-processing的订单 accountService.extendValidityForCC(); } // 每天凌晨0点执行一次 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void cancelActivityBenefits() { // 1、查询当前所有参与了活动且过期的用户 List accountList = accountService.getExpiredUserBySystemUser(4); @@ -51,7 +51,7 @@ public class AccountTask { } // 每天检测正式用户到期情况,每天凌晨0点执行 -// @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "0 0 0 * * ?") public void paidUserToVisitor() { // 1、查询当前已过期正式用户或试用用户 List accountList = accountService.getExpiredUserBySystemUser(1); @@ -68,12 +68,12 @@ public class AccountTask { /** * 将Code-Create上注册的用户添加为AiDA的游客 */ -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void registerUserToVisitor() { accountService.registerUserToVisitor(); } -// @Scheduled(cron = "0 0 0 1 * ?") + @Scheduled(cron = "0 0 0 1 * ?") // 每月初刷新所有用户用户名剩余修改次数 public void resetUsernameModifyTimes(){ log.info("重置所有用户的用户名修改次数"); diff --git a/src/main/java/com/ai/da/common/task/PaymentTask.java b/src/main/java/com/ai/da/common/task/PaymentTask.java index cd3b9801..7c148aa5 100644 --- a/src/main/java/com/ai/da/common/task/PaymentTask.java +++ b/src/main/java/com/ai/da/common/task/PaymentTask.java @@ -45,7 +45,7 @@ public class PaymentTask { @Resource private PayPalCheckoutService payPalCheckoutService; -// @Scheduled(cron = "0/30 * * * * ?") + @Scheduled(cron = "0/30 * * * * ?") public void orderConfirmForPaypal() throws SerializeException { // log.info("PayPal orderConfirm 被执行......"); @@ -85,7 +85,7 @@ public class PaymentTask { } // 提前7天向用户发送提醒邮件,每天早上8点执行 -// @Scheduled(cron = "0 0 8 * * ?") + @Scheduled(cron = "0 0 8 * * ?") public void subscriptionReminder(){ stripeService.subscriptionReminder(); } @@ -96,13 +96,13 @@ public class PaymentTask { // } -// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes + @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void updateAffiliateInfoWithPayment(){ // log.info("佣金计算定时器"); affiliateService.updateAffiliateInfoWithPayment(); } -// @Scheduled(cron = "0 0 8 28-31 * ?") + @Scheduled(cron = "0 0 8 28-31 * ?") public void commissionSummaryReminder(){ // 每个月末的最后一天的早上八点执行 LocalDate today = LocalDate.now(); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 974fee23..8550475d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -2,7 +2,7 @@ #spring.profiles.active=test #����application-prod�ļ�(��������) -#spring.profiles.active=prod +spring.profiles.active=prod #����application-dev�ļ�(��������) -spring.profiles.active=dev +#spring.profiles.active=dev diff --git a/src/main/resources/payment.properties b/src/main/resources/payment.properties index bc57019c..f4b98130 100644 --- a/src/main/resources/payment.properties +++ b/src/main/resources/payment.properties @@ -34,17 +34,17 @@ paypal.webhook_id=1D107312EX592781K #stripe.webhook-sign-secret=whsec_TJcMSnAkh4uktrNY1M6Iy8XaVze4Rzqm # kim - test -stripe.private-key=sk_test_51LwPrxH7nPZ8bkrNj67TFD7sxucaTANs1lf0KGSu1QSJfxYXcnigq2wTaZyZzST7y0fMbhhvaJZ4LjjFhr95M83a00eXrmOTL0 +#stripe.private-key=sk_test_51LwPrxH7nPZ8bkrNj67TFD7sxucaTANs1lf0KGSu1QSJfxYXcnigq2wTaZyZzST7y0fMbhhvaJZ4LjjFhr95M83a00eXrmOTL0 # prod 端点 #stripe.webhook-sign-secret=whsec_GoyVEAaBtuGD5Rt55z83JnPnLDAZTN3u # local 端点 #stripe.webhook-sign-secret=whsec_NvwM3hDQiN5GXclYOYekE9IKHLjmROF8 # dev 端点 -stripe.webhook-sign-secret=whsec_pX0pPMQm85PaUSWnFMEzoccb3MGNkjoL +#stripe.webhook-sign-secret=whsec_pX0pPMQm85PaUSWnFMEzoccb3MGNkjoL # kim - live -#stripe.private-key=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 +stripe.private-key=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 # prod 端点 -#stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 +stripe.webhook-sign-secret=whsec_hhGDgdelQRHSg4LmChtQe41crj41eb11 # dev 端点 #stripe.webhook-sign-secret=whsec_cFUtjUOo8wnrIKZmt4GNvt7ZY1bOfrYr From 377c86e39009988df7ee9053b4d7ef2d49957a72 Mon Sep 17 00:00:00 2001 From: xupei Date: Fri, 28 Feb 2025 14:30:35 +0800 Subject: [PATCH 02/12] =?UTF-8?q?Stripe=20=E5=9B=9E=E8=B0=83=E5=88=A4?= =?UTF-8?q?=E7=A9=BA=E5=B9=B6=E7=9B=B4=E6=8E=A5=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/StripeServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java index b157d759..b35b2ff6 100644 --- a/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/StripeServiceImpl.java @@ -394,7 +394,7 @@ public class StripeServiceImpl implements StripeService { OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderNo); if (Objects.isNull(orderInfo)){ // 说明该回调不是从AiDA订阅获得 - response = Boolean.TRUE; + return true; } if (event.getType().equals("charge.failed")){ // 添加支付信息 && 更新支付信息 From 52bafa95e3bb6ad82d02f9a54fe25a083d0314fd Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 3 Mar 2025 21:17:14 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E5=85=B3=E9=97=AD=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E4=BB=8ECode-Create=E5=88=9B=E5=BB=BA=E6=B8=B8=E5=AE=A2?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E7=9A=84=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/common/task/AccountTask.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/common/task/AccountTask.java b/src/main/java/com/ai/da/common/task/AccountTask.java index 1deeb4c2..558c95e7 100644 --- a/src/main/java/com/ai/da/common/task/AccountTask.java +++ b/src/main/java/com/ai/da/common/task/AccountTask.java @@ -66,9 +66,10 @@ public class AccountTask { } /** + * !!关闭此定时器!!不再从Code-Create上默认创建AiDA游客 * 将Code-Create上注册的用户添加为AiDA的游客 */ - @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes +// @Scheduled(cron = "0 */5 * * * *") // Run every 5 minutes public void registerUserToVisitor() { accountService.registerUserToVisitor(); } From 6fc22784b8e57fadcc14b274b72c52e8dc6c8212 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 21:26:24 +0800 Subject: [PATCH 04/12] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/common/utils/MinioUtil.java | 10 +++++ .../service/impl/CollectionServiceImpl.java | 41 ++++++++++++++----- .../ai/da/service/impl/DesignServiceImpl.java | 2 + .../da/service/impl/LibraryServiceImpl.java | 39 ++++++++++-------- 4 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/ai/da/common/utils/MinioUtil.java b/src/main/java/com/ai/da/common/utils/MinioUtil.java index d3cdc76f..f622b66f 100644 --- a/src/main/java/com/ai/da/common/utils/MinioUtil.java +++ b/src/main/java/com/ai/da/common/utils/MinioUtil.java @@ -440,6 +440,16 @@ public class MinioUtil { return getPreSignedUrl(bucketName, String.valueOf(fileName), expiry); } + public boolean doesObjectExist(String path) { + if (!path.contains("/")) { + throw new BusinessException("the.path.is.error"); + } + int index = path.indexOf("/"); + String bucketName = path.substring(0, index); + String objectName = path.substring(index + 1); + return doesObjectExist(bucketName, objectName); + } + public boolean doesObjectExist(String bucketName, String objectName) { try { minioClient.statObject( diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index 5f29b7c9..5999d78c 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -101,8 +101,15 @@ public class CollectionServiceImpl extends ServiceImpl> maps = collectionElements @@ -117,27 +124,41 @@ public class CollectionServiceImpl extends ServiceImpl { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); - d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60)); + String url = o.getUrl(); + if (minioUtil.doesObjectExist(url)) { + d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + } else { + response.getMoodBoards().remove(d); + } })); break; case PRINT_BOARD: response.setPrintBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); - d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60)); + String url = o.getUrl(); + if (minioUtil.doesObjectExist(url)) { + d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + } else { + response.getPrintBoards().remove(d); + } })); break; case SKETCH_BOARD: response.setSketchBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); - d.setUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60)); String url = o.getUrl(); - if (url.contains(".")) { - String[] split = url.split("\\."); - d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(split[0] + "-show." + split[1], 24 * 60)); - }else { - d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(url + "-show", 24 * 60)); + if (minioUtil.doesObjectExist(url)) { + d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + if (url.contains(".")) { + String[] split = url.split("\\."); + d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(split[0] + "-show." + split[1], 24 * 60)); + } else { + d.setUrlWithWhiteSide(minioUtil.getPreSignedUrl(url + "-show", 24 * 60)); + } + } else { + response.getSketchBoards().remove(d); } })); break; diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index 5e8d4023..4c3460a3 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -1346,6 +1346,7 @@ public class DesignServiceImpl extends ServiceImpl impleme throw new BusinessException("design.not.found"); } List designItemDetails = designItemDetailService.selectByDesignItemId(designItemId); + designItemDetails.removeIf(designItemDetail -> !minioUtil.doesObjectExist(designItemDetail.getPath())); if (CollectionUtil.isEmpty(designItemDetails)) { throw new BusinessException("designItemDetails.not.found"); } @@ -1382,6 +1383,7 @@ public class DesignServiceImpl extends ServiceImpl impleme if (!StringUtil.isNullOrEmpty(o.getUndividedLayer())) d.setUndividedLayer(minioUtil.getPreSignedUrl(o.getUndividedLayer(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); // 根据designItemDetailId获取印花 List prints = designItemDetailPrintService.getByDesignItemDetailId(o.getId(), "print"); + prints.removeIf(print -> !minioUtil.doesObjectExist(print.getPath())); // 判断有无印花 if (CollectionUtil.isNotEmpty(prints)) { // 有印花 diff --git a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java index 2c237cf9..c5ce2b79 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -206,25 +206,30 @@ public class LibraryServiceImpl extends ServiceImpl impl QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); libraryPageVO.setMinIOPath(library.getUrl()); - libraryPageVO.setUrl(minioUtil.getPreSignedUrl(library.getUrl(), 24 * 60)); - if (finalMap != null && finalMap.containsKey(library.getId())) { - libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId())); - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) { - if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) { - Position position = Position.getPosition(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name()))); + String url = library.getUrl(); + if (minioUtil.doesObjectExist(url)) { + libraryPageVO.setUrl(minioUtil.getPreSignedUrl(library.getUrl(), 24 * 60)); + if (finalMap != null && finalMap.containsKey(library.getId())) { + libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId())); } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) { + if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) { + Position position = Position.getPosition(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name()))); + } + } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) { + PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson(printboardLevel2TypeEnum.getValue(), printboardLevel2TypeEnum.name(), BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name()))); + } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) { + DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson(designElementsEnum.getValue(), designElementsEnum.name(), BusinessException.getMessageFromResource(designElementsEnum.name()))); + } + return libraryPageVO; + }else { + return null; } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) { - PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(printboardLevel2TypeEnum.getValue(), printboardLevel2TypeEnum.name(), BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name()))); - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) { - DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(designElementsEnum.getValue(), designElementsEnum.name(), BusinessException.getMessageFromResource(designElementsEnum.name()))); - } - return libraryPageVO; }); return PageBaseResponse.success(convert); } From 7839ac33228ee48606b2f4ef727561678d70e3de Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 21:54:23 +0800 Subject: [PATCH 05/12] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/LibraryServiceImpl.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java index c5ce2b79..b57096d8 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -51,6 +51,7 @@ import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -202,6 +203,7 @@ public class LibraryServiceImpl extends ServiceImpl impl } } Map finalMap = map; + AtomicInteger i = new AtomicInteger(); IPage convert = page.convert((Function) library -> { QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); @@ -228,9 +230,25 @@ public class LibraryServiceImpl extends ServiceImpl impl } return libraryPageVO; }else { + i.getAndIncrement(); return null; } - }); + }).getRecords().stream() + .filter(Objects::nonNull) + .collect(Collectors.collectingAndThen( + Collectors.toList(), + list -> new Page(page.getCurrent(), page.getSize(), page.getTotal()) { + @Override + public List getRecords() { + return list; + } + + @Override + public long getTotal() { + return list.size(); + } + } + )); return PageBaseResponse.success(convert); } From 484a8d1d93aab88316f3006260207aa027d4abce Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 22:00:07 +0800 Subject: [PATCH 06/12] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java index b57096d8..ebc9893a 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -245,7 +245,7 @@ public class LibraryServiceImpl extends ServiceImpl impl @Override public long getTotal() { - return list.size(); + return page.getTotal(); } } )); From d3ee0e5f4f0c5288b4bedd37e06a88882f381a82 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 22:06:39 +0800 Subject: [PATCH 07/12] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CollectionServiceImpl.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index 5999d78c..bf598dcd 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -115,6 +115,7 @@ public class CollectionServiceImpl extends ServiceImpl> maps = collectionElements .stream() .collect(Collectors.groupingBy(CollectionElement::getLevel1Type)); + maps.forEach((k, v) -> { CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(k); if (Objects.isNull(level1TypeEnum)) { @@ -122,30 +123,34 @@ public class CollectionServiceImpl extends ServiceImpl { + List moodBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); if (minioUtil.doesObjectExist(url)) { d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); - } else { - response.getMoodBoards().remove(d); } - })); + }); + response.setMoodBoards(moodBoards.stream() + .filter(d -> minioUtil.doesObjectExist(d.getUrl())) + .collect(Collectors.toList())); break; + case PRINT_BOARD: - response.setPrintBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { + List printBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); if (minioUtil.doesObjectExist(url)) { d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); - } else { - response.getPrintBoards().remove(d); } - })); + }); + response.setPrintBoards(printBoards.stream() + .filter(d -> minioUtil.doesObjectExist(d.getUrl())) + .collect(Collectors.toList())); break; + case SKETCH_BOARD: - response.setSketchBoards(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { + List sketchBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setIsPin(o.getHasPin()); d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); @@ -157,22 +162,28 @@ public class CollectionServiceImpl extends ServiceImpl minioUtil.doesObjectExist(d.getUrl())) + .collect(Collectors.toList())); break; + case COLOR_BOARD: response.setColorBoards(resolveColorBoard(v)); break; + case MARKETING_SKETCH: response.setMarketingSketchs(CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); })); break; + default: + break; } }); + if (CollectionUtil.isNotEmpty(response.getColorBoards())) { List collect = response.getColorBoards().stream() .distinct() From a043db2de5a336cddad2ac7cda153c4d05d8b93f Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 12 Mar 2025 22:48:18 +0800 Subject: [PATCH 08/12] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/service/impl/DesignServiceImpl.java | 1 + .../da/service/impl/LibraryServiceImpl.java | 124 ++++++++++-------- 2 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index 4c3460a3..1859094b 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -1408,6 +1408,7 @@ public class DesignServiceImpl extends ServiceImpl impleme d.setMinIOPath(o.getPath()); d.setPrintObject(new DesignPythonItemPrint()); })); + response.getOthers().removeIf(o -> !minioUtil.doesObjectExist(o.getMinIOPath())); return editDesignItemLayer(flag, designPythonOutfit, minioUtil.getPreSignedUrl(designPythonOutfit.getDesignUrl(), 24 * 60), editResponseColor(designItemDetails, response)); diff --git a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java index ebc9893a..0e5df05e 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -183,73 +183,93 @@ public class LibraryServiceImpl extends ServiceImpl impl } } queryWrapper.orderByDesc("id"); - IPage page = getBaseMapper().selectPage( - new Page<>(query.getPage(), query.getSize()), queryWrapper); - if (CollectionUtils.isEmpty(page.getRecords())) { + // 1. 先查询所有符合条件的 Library 数据 + List libraryList = getBaseMapper().selectList(queryWrapper); + if (CollectionUtils.isEmpty(libraryList)) { return PageBaseResponse.success(new Page<>()); } + + // 2. 封装打点内容 Map map = null; - //封装打点内容 - Boolean isExist = page.getRecords().stream() + boolean isExist = libraryList.stream() .anyMatch(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName())); if (isExist) { - List libarayIds = page.getRecords().stream() + List libraryIds = libraryList.stream() .filter(library -> library.getLevel1Type().equals(LibraryLevel1TypeEnum.MODELS.getRealName())) .map(Library::getId) .collect(Collectors.toList()); - List libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libarayIds); + List libraryModelPointVOS = libraryModelPointService.selectByLibraryIds(libraryIds); if (!CollectionUtils.isEmpty(libraryModelPointVOS)) { - map = libraryModelPointVOS.stream().collect(Collectors.toMap(LibraryModelPointVO::getRelationId, v -> v)); + map = libraryModelPointVOS.stream() + .collect(Collectors.toMap(LibraryModelPointVO::getRelationId, v -> v)); } } Map finalMap = map; - AtomicInteger i = new AtomicInteger(); - IPage convert = page.convert((Function) library -> { - QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); - libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); - libraryPageVO.setMinIOPath(library.getUrl()); - String url = library.getUrl(); - if (minioUtil.doesObjectExist(url)) { - libraryPageVO.setUrl(minioUtil.getPreSignedUrl(library.getUrl(), 24 * 60)); - if (finalMap != null && finalMap.containsKey(library.getId())) { - libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId())); - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) { - if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) { - Position position = Position.getPosition(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(position.getValue(), position.name(), BusinessException.getMessageFromResource(position.name()))); - } - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) { - PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(printboardLevel2TypeEnum.getValue(), printboardLevel2TypeEnum.name(), BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name()))); - } - if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) { - DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type()); - libraryPageVO.setLevel2TypeEnum(new BizJson(designElementsEnum.getValue(), designElementsEnum.name(), BusinessException.getMessageFromResource(designElementsEnum.name()))); - } - return libraryPageVO; - }else { - i.getAndIncrement(); - return null; - } - }).getRecords().stream() - .filter(Objects::nonNull) - .collect(Collectors.collectingAndThen( - Collectors.toList(), - list -> new Page(page.getCurrent(), page.getSize(), page.getTotal()) { - @Override - public List getRecords() { - return list; - } - @Override - public long getTotal() { - return page.getTotal(); + // 3. 转换 Library 为 QueryLibraryPageVO,并通过 minioUtil 过滤掉不存在的 URL + List convertedList = libraryList.stream() + .map(library -> { + QueryLibraryPageVO libraryPageVO = CopyUtil.copyObject(library, QueryLibraryPageVO.class); + libraryPageVO.setDesignType(DesignTypeEnum.LIBRARY.getRealName()); + libraryPageVO.setMinIOPath(library.getUrl()); + String url = library.getUrl(); + if (minioUtil.doesObjectExist(url)) { + libraryPageVO.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); + if (finalMap != null && finalMap.containsKey(library.getId())) { + libraryPageVO.setLibraryModelPoint(finalMap.get(library.getId())); + } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) { + if (!StringUtils.isEmpty(libraryPageVO.getLevel2Type())) { + Position position = Position.getPosition(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson( + position.getValue(), + position.name(), + BusinessException.getMessageFromResource(position.name())) + ); } } - )); - return PageBaseResponse.success(convert); + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.PRINT_BOARD.getRealName())) { + PrintboardLevel2TypeEnum printboardLevel2TypeEnum = PrintboardLevel2TypeEnum.fromName(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson( + printboardLevel2TypeEnum.getValue(), + printboardLevel2TypeEnum.name(), + BusinessException.getMessageFromResource(printboardLevel2TypeEnum.name())) + ); + } + if (libraryPageVO.getLevel1Type().equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS.getRealName())) { + DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(libraryPageVO.getLevel2Type()); + libraryPageVO.setLevel2TypeEnum(new BizJson( + designElementsEnum.getValue(), + designElementsEnum.name(), + BusinessException.getMessageFromResource(designElementsEnum.name())) + ); + } + return libraryPageVO; + } else { + // 如果对应的 MinIO 文件不存在,则返回 null,后续过滤掉 + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + // 4. 手动分页 + int total = convertedList.size(); + int currentPage = query.getPage(); // 当前页码(从1开始) + int pageSize = query.getSize(); // 每页大小 + int fromIndex = (currentPage - 1) * pageSize; + int toIndex = Math.min(total, currentPage * pageSize); + List pageList = new ArrayList<>(); + if (fromIndex < total) { + pageList = convertedList.subList(fromIndex, toIndex); + } + + // 5. 构造 IPage 对象(使用 MyBatis-Plus 的 Page 实现) + IPage pageResult = new Page<>(currentPage, pageSize, total); + pageResult.setRecords(pageList); + + // 6. 返回结果 + return PageBaseResponse.success(pageResult); } @Override From 7e55b1f85e7578ed360b5426425001b80a34f9b1 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Thu, 13 Mar 2025 17:53:35 +0800 Subject: [PATCH 09/12] =?UTF-8?q?BUGFIX:=20=E9=9A=90=E8=97=8F=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=8D=E5=87=BAminio=E7=9A=84=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=95=B0=E6=8D=AE;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/model/vo/CollectionElementVO.java | 2 ++ .../com/ai/da/service/impl/CollectionServiceImpl.java | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ai/da/model/vo/CollectionElementVO.java b/src/main/java/com/ai/da/model/vo/CollectionElementVO.java index ff4e5b88..53a1888a 100644 --- a/src/main/java/com/ai/da/model/vo/CollectionElementVO.java +++ b/src/main/java/com/ai/da/model/vo/CollectionElementVO.java @@ -40,4 +40,6 @@ public class CollectionElementVO { private String urlWithWhiteSide; + private String originalUrl; + } diff --git a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java index bf598dcd..a90ba255 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionServiceImpl.java @@ -126,12 +126,13 @@ public class CollectionServiceImpl extends ServiceImpl moodBoards = CopyUtil.copyList(v, CollectionElementVO.class, (o, d) -> { d.setDesignType(DesignTypeEnum.COLLECTION.getRealName()); String url = o.getUrl(); + d.setOriginalUrl(url); if (minioUtil.doesObjectExist(url)) { d.setUrl(minioUtil.getPreSignedUrl(url, 24 * 60)); } }); response.setMoodBoards(moodBoards.stream() - .filter(d -> minioUtil.doesObjectExist(d.getUrl())) + .filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl())) .collect(Collectors.toList())); break; @@ -140,12 +141,13 @@ public class CollectionServiceImpl extends ServiceImpl minioUtil.doesObjectExist(d.getUrl())) + .filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl())) .collect(Collectors.toList())); break; @@ -154,6 +156,7 @@ public class CollectionServiceImpl extends ServiceImpl minioUtil.doesObjectExist(d.getUrl())) + .filter(d -> minioUtil.doesObjectExist(d.getOriginalUrl())) .collect(Collectors.toList())); break; From 8cd4cfb36dcdda553cc4c58a93748c986a58aab3 Mon Sep 17 00:00:00 2001 From: xupei Date: Tue, 18 Mar 2025 15:33:24 +0800 Subject: [PATCH 10/12] =?UTF-8?q?getDetail=20=E6=B7=BB=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=8C=E6=89=93=E5=8D=B0=E5=85=A5=E5=8F=82=E5=9B=9E?= =?UTF-8?q?=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/DesignServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java index 5e8d4023..d343d964 100644 --- a/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignServiceImpl.java @@ -1336,6 +1336,8 @@ public class DesignServiceImpl extends ServiceImpl impleme @Override public DesignItemDetailVO detail(Long designPythonOutfitId, Long designItemId) { + log.info("获取design detail -> 【designPythonOutfitId : {}, designItemId : {}】 ", designPythonOutfitId, designItemId); + // 1、校验 DesignItem designItem = designItemService.getById(designItemId); if (Objects.isNull(designItem)) { @@ -1583,6 +1585,7 @@ public class DesignServiceImpl extends ServiceImpl impleme designItemDetailVO.setDesignItemUrl(designItemUrl); } + log.info("获取DesignDetail, response: {}", JSONObject.toJSONString(designItemDetailVO)); return designItemDetailVO; } From 654a3829c680c5b1b121cb73c7e86b68a62e2209 Mon Sep 17 00:00:00 2001 From: xupei Date: Tue, 18 Mar 2025 17:39:39 +0800 Subject: [PATCH 11/12] =?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; } From 0500557dcacce8d63199dc93f17fcdfdacaaa87b Mon Sep 17 00:00:00 2001 From: xupei Date: Tue, 18 Mar 2025 18:47:05 +0800 Subject: [PATCH 12/12] =?UTF-8?q?BUGFIX:=20=E8=8E=B7=E5=8F=96pantone?= =?UTF-8?q?=E5=80=BC=E4=B8=BA=E7=A9=BA=E6=97=B6=E8=BF=94=E5=9B=9Ergb?= =?UTF-8?q?=E5=92=8Chsv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/common/utils/PantoneUtils.java | 66 +++++++++++++++++++ .../java/com/ai/da/model/vo/PantoneVO.java | 12 +++- .../da/service/impl/PanToneServiceImpl.java | 23 +++++-- 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ai/da/common/utils/PantoneUtils.java b/src/main/java/com/ai/da/common/utils/PantoneUtils.java index 153b3be0..2dd9c3f1 100644 --- a/src/main/java/com/ai/da/common/utils/PantoneUtils.java +++ b/src/main/java/com/ai/da/common/utils/PantoneUtils.java @@ -28,4 +28,70 @@ public class PantoneUtils { return new int[]{Math.round(hsv[0]), Math.round(hsv[1] * 100), Math.round(hsv[2] * 100)}; } + public static int[] hsvToRgb(int h, int s, int v) { + // 确保 h 在 [0, 360) 范围内 + h = h % 360; + if (h < 0) { + h += 360; + } + + // 确保 s 和 v 在 [0, 100] 范围内 + s = Math.max(0, Math.min(100, s)); + v = Math.max(0, Math.min(100, v)); + + // 将 s 和 v 映射到 [0, 1] 范围 + float sNorm = s / 100.0f; + float vNorm = v / 100.0f; + + // 计算色相所在的区间 + int hi = (h / 60) % 6; + float f = (h / 60.0f) - hi; + float p = vNorm * (1 - sNorm); + float q = vNorm * (1 - f * sNorm); + float t = vNorm * (1 - (1 - f) * sNorm); + + float r, g, b; + switch (hi) { + case 0: + r = vNorm; + g = t; + b = p; + break; + case 1: + r = q; + g = vNorm; + b = p; + break; + case 2: + r = p; + g = vNorm; + b = t; + break; + case 3: + r = p; + g = q; + b = vNorm; + break; + case 4: + r = t; + g = p; + b = vNorm; + break; + case 5: + r = vNorm; + g = p; + b = q; + break; + default: + throw new RuntimeException("Invalid HSV values"); + } + + // 将 RGB 值从 [0, 1] 转换为 [0, 255] + int red = Math.round(r * 255); + int green = Math.round(g * 255); + int blue = Math.round(b * 255); + + return new int[]{red, green, blue}; + } + } diff --git a/src/main/java/com/ai/da/model/vo/PantoneVO.java b/src/main/java/com/ai/da/model/vo/PantoneVO.java index cbf09aac..1c3cf218 100644 --- a/src/main/java/com/ai/da/model/vo/PantoneVO.java +++ b/src/main/java/com/ai/da/model/vo/PantoneVO.java @@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.NoArgsConstructor; -import javax.validation.constraints.NotBlank; @NoArgsConstructor @Data @@ -43,4 +42,15 @@ public class PantoneVO { this.name = name; this.tcx = tcx; } + + public PantoneVO(Integer r, Integer g, Integer b, Integer h, Integer s, Integer v) { + this.r = r; + this.g = g; + this.b = b; + this.h = h; + this.s = s; + this.v = v; + this.name = "--"; + this.tcx = "--"; + } } 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 eeb40cb4..a0a98a82 100644 --- a/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/PanToneServiceImpl.java @@ -45,7 +45,7 @@ public class PanToneServiceImpl extends ServiceImpl impl queryWrapper.eq("pantone_index", colorLookupTable.getColorIndex()); PanTone panTone = panToneMapper.selectOne(queryWrapper); if (Objects.isNull(panTone)) { - throw new BusinessException("pantone.not.found"); + return null; } return coverPanToneToVo(panTone); } @@ -176,16 +176,19 @@ public class PanToneServiceImpl extends ServiceImpl impl @Override public PantoneVO getPantoneByRgb(String color) { GetRgbByHsvBatchDTO getRgbByHsvBatchDTO = new GetRgbByHsvBatchDTO(); + int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray(); + int[] hsv = PantoneUtils.rgbToHsv(rgb); if (!StringUtil.isNullOrEmpty(color)) { - int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray(); - int[] hsv = PantoneUtils.rgbToHsv(rgb); getRgbByHsvBatchDTO.setH(hsv[0]); getRgbByHsvBatchDTO.setS(hsv[1]); getRgbByHsvBatchDTO.setV(hsv[2]); } - - return getByHSV(getRgbByHsvBatchDTO.getH(), getRgbByHsvBatchDTO.getS(), getRgbByHsvBatchDTO.getV()); + PantoneVO pantoneVO = getByHSV(getRgbByHsvBatchDTO.getH(), getRgbByHsvBatchDTO.getS(), getRgbByHsvBatchDTO.getV()); + if (Objects.isNull(pantoneVO)) { + pantoneVO = new PantoneVO(rgb[0], rgb[1], rgb[2], hsv[0], hsv[1], hsv[2]); + } + return pantoneVO; } @Override @@ -215,7 +218,12 @@ public class PanToneServiceImpl extends ServiceImpl impl QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.in("pantone_index", colorLookupTables.stream() .map(ColorLookupTable::getColorIndex).collect(Collectors.toList())); - return coverPanToneToVoList(panToneMapper.selectList(queryWrapper), IndexToValue, valueToHsv, hsvBatch); + List pantoneVOS = coverPanToneToVoList(panToneMapper.selectList(queryWrapper), IndexToValue, valueToHsv, hsvBatch); + if (pantoneVOS.isEmpty() && hsvBatch.size() == 1){ + int[] rgb = PantoneUtils.hsvToRgb(hsvBatch.get(0).getH(), hsvBatch.get(0).getS(), hsvBatch.get(0).getV()); + pantoneVOS.add(new PantoneVO(rgb[0], rgb[1], rgb[2], hsvBatch.get(0).getH(), hsvBatch.get(0).getS(), hsvBatch.get(0).getV())); + } + return pantoneVOS; } private PantoneVO coverPanToneToVo(PanTone panTone) { @@ -234,7 +242,8 @@ public class PanToneServiceImpl extends ServiceImpl impl , Map indexToValue, Map valueToHsv, List hsvBatch) { if (CollectionUtil.isEmpty(panTones)) { - throw new BusinessException("panTones.not.found", ResultEnum.PROMPT.getCode()); + return Lists.newArrayList(); +// throw new BusinessException("panTones.not.found", ResultEnum.PROMPT.getCode()); } List templateResposne = CopyUtil.copyList(panTones, PantoneVO.class, (o, d) -> { d.setId(o.getPantoneIndex());