From 4d9b2cd377ddf20f5a9b543423a8a3e3b23d0da8 Mon Sep 17 00:00:00 2001 From: hupeng Date: Wed, 20 Aug 2025 11:14:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=95=86=E5=93=81=E5=A4=9A?= =?UTF-8?q?=E8=A7=84=E6=A0=BC=E4=B8=AD=E6=96=87=E6=8E=92=E5=BA=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/string/StrUtils.java | 24 +++++++++++++++---- .../StoreProductAttrServiceImpl.java | 3 ++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/yshop-drink-boot3/yshop-framework/yshop-common/src/main/java/co/yixiang/yshop/framework/common/util/string/StrUtils.java b/yshop-drink-boot3/yshop-framework/yshop-common/src/main/java/co/yixiang/yshop/framework/common/util/string/StrUtils.java index d8528d4..bcb3c21 100644 --- a/yshop-drink-boot3/yshop-framework/yshop-common/src/main/java/co/yixiang/yshop/framework/common/util/string/StrUtils.java +++ b/yshop-drink-boot3/yshop-framework/yshop-common/src/main/java/co/yixiang/yshop/framework/common/util/string/StrUtils.java @@ -3,11 +3,10 @@ package co.yixiang.yshop.framework.common.util.string; import cn.hutool.core.text.StrPool; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; +import org.springframework.util.CollectionUtils; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Set; +import java.text.Collator; +import java.util.*; import java.util.stream.Collectors; /** @@ -77,4 +76,21 @@ public class StrUtils { .collect(Collectors.joining("\n")); } + /** + * 数字排在最前,英文字母其次,汉字则按照拼音进行排序 + */ + public static List compareTo(List stringList) { + if (CollectionUtils.isEmpty(stringList)) { + return Collections.emptyList(); + } + Comparator comparator = (text, texts) -> { + Collator collator = Collator.getInstance(java.util.Locale.CHINESE); + return collator.getCollationKey(text).compareTo( + collator.getCollationKey(texts)); + }; + Collections.sort(stringList, comparator); + return stringList; + + } + } diff --git a/yshop-drink-boot3/yshop-module-mall/yshop-module-product-biz/src/main/java/co/yixiang/yshop/module/product/service/storeproductattr/StoreProductAttrServiceImpl.java b/yshop-drink-boot3/yshop-module-mall/yshop-module-product-biz/src/main/java/co/yixiang/yshop/module/product/service/storeproductattr/StoreProductAttrServiceImpl.java index f9045f4..2899bc7 100644 --- a/yshop-drink-boot3/yshop-module-mall/yshop-module-product-biz/src/main/java/co/yixiang/yshop/module/product/service/storeproductattr/StoreProductAttrServiceImpl.java +++ b/yshop-drink-boot3/yshop-module-mall/yshop-module-product-biz/src/main/java/co/yixiang/yshop/module/product/service/storeproductattr/StoreProductAttrServiceImpl.java @@ -3,6 +3,7 @@ package co.yixiang.yshop.module.product.service.storeproductattr; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import co.yixiang.yshop.framework.common.util.string.StrUtils; import co.yixiang.yshop.module.product.dal.dataobject.storeproductattr.StoreProductAttrDO; import co.yixiang.yshop.module.product.dal.dataobject.storeproductattrvalue.StoreProductAttrValueDO; import co.yixiang.yshop.module.product.dal.mysql.storeproductattr.StoreProductAttrMapper; @@ -103,7 +104,7 @@ public class StoreProductAttrServiceImpl extends ServiceImpl stringList = new ArrayList<>(productFormatDto.getDetail().values()); - Collections.sort(stringList); + stringList = StrUtils.compareTo(stringList); StoreProductAttrValueDO oldAttrValue = storeProductAttrValueService.getOne(new LambdaQueryWrapper() .eq(StoreProductAttrValueDO::getSku, productFormatDto.getSku()) .eq(StoreProductAttrValueDO::getProductId, productId));