Commit a11bc16b139084a68af9c109f86ec33b05b80cb8

Authored by boyang
1 parent 3989db1b

fix: 添加判断cateId2Relevance是否为空

shop/src/main/java/com/canrd/shop/service/impl/ProductServiceImpl.java
@@ -178,19 +178,20 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im @@ -178,19 +178,20 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
178 TreeMap<String, Integer> cateId2Relevance = new TreeMap<>(relatedCateId2Relevance); 178 TreeMap<String, Integer> cateId2Relevance = new TreeMap<>(relatedCateId2Relevance);
179 StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pc.id when "," else 0 end "); 179 StringJoiner orderByJoiner = new StringJoiner(" when "," order by case pc.id when "," else 0 end ");
180 cateId2Relevance.forEach((k,v)->orderByJoiner.add("'"+k+"'"+" then "+v)); 180 cateId2Relevance.forEach((k,v)->orderByJoiner.add("'"+k+"'"+" then "+v));
181 - QueryWrapper<ProductDO> objectQueryWrapper = new QueryWrapper<ProductDO>()  
182 - .in("pc.id", cateId2Relevance.keySet())  
183 - .select("distinct p.id","pc.id")  
184 - .last(orderByJoiner.toString());  
185 - List<ProductDO> relatedProducts = this  
186 - .list(objectQueryWrapper);  
187 - List<String> relatedProductIds = relatedProducts.stream()  
188 - .map(ProductDO::getId)  
189 - .distinct()  
190 - .limit(10)  
191 - .collect(Collectors.toList());  
192 - productVO.setRelatedProductIds(relatedProductIds);  
193 - 181 + if(CollUtil.isNotEmpty(cateId2Relevance)) {
  182 + QueryWrapper<ProductDO> objectQueryWrapper = new QueryWrapper<ProductDO>()
  183 + .in("pc.id", cateId2Relevance.keySet())
  184 + .select("distinct p.id", "pc.id")
  185 + .last(orderByJoiner.toString());
  186 + List<ProductDO> relatedProducts = this
  187 + .list(objectQueryWrapper);
  188 + List<String> relatedProductIds = relatedProducts.stream()
  189 + .map(ProductDO::getId)
  190 + .distinct()
  191 + .limit(10)
  192 + .collect(Collectors.toList());
  193 + productVO.setRelatedProductIds(relatedProductIds);
  194 + }
194 productVO.setPriceShow(productPriceShow); 195 productVO.setPriceShow(productPriceShow);
195 196
196 197
shop/src/main/resources/application-local.yml
@@ -59,7 +59,7 @@ spring: @@ -59,7 +59,7 @@ spring:
59 testOnReturn: true 59 testOnReturn: true
60 password: 123456 60 password: 123456
61 time-between-eviction-runs-millis: 1000 61 time-between-eviction-runs-millis: 1000
62 - url: jdbc:mysql://127.0.0.1:3306/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true 62 + url: jdbc:mysql://192.168.31.242:13306/canrd_overseas?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true&useAffectedRows=true&autoReconnectForPools=true
63 username: root 63 username: root
64 64
65 65
shop/src/main/resources/application.yml
@@ -3,7 +3,7 @@ server: @@ -3,7 +3,7 @@ server:
3 3
4 spring: 4 spring:
5 profiles: 5 profiles:
6 - active: test 6 + active: prod
7 mvc: 7 mvc:
8 throw-exception-if-no-handler-found: true 8 throw-exception-if-no-handler-found: true
9 resources: 9 resources: