From da1ac94caf87d72bf26cc11eccfb6d9c886829c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Fri, 29 Nov 2024 11:13:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=8D=95=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashierservice/entity/TbProduct.java | 3 ++- .../service/ProductService.java | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java index a0b5fd5..b201125 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbProduct.java @@ -86,7 +86,8 @@ public class TbProduct implements Serializable { private Object groundingSpecInfo; private String specInfo; private String selectSpec; - + @TableField(exist = false) + private TbShopUnit unitName; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index bba096d..24e5943 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -13,6 +13,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.QuerySpecDTO; import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect; +import com.chaozhanggui.system.cashierservice.mapper.MpShopUnitMapper; import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; @@ -25,6 +26,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.*; +import java.util.stream.Collectors; @Service @Slf4j @@ -50,6 +52,10 @@ public class ProductService { private LimitSubmitAspect limitSubmitAspect; private final RabbitProducer producer; + @Autowired + private TbShopUnitMapper tbShopUnitMapper; + @Autowired + private MpShopUnitMapper mpShopUnitMapper; public ProductService(RabbitProducer producer) { this.producer = producer; @@ -123,9 +129,19 @@ public class ProductService { tbProductWithBLOBs=tbProductMapper.selectByShopIdAndShopTypeCheckGrounding(shopId,categoryId,commdityName); } } - + Map shopUnitsMap = new HashMap<>(); + Set unitIds = tbProductWithBLOBs.stream().map(TbProduct::getUnitId).collect(Collectors.toSet()); + if (!unitIds.isEmpty()) { + List shopUnits = mpShopUnitMapper.selectBatchIds(unitIds); + shopUnitsMap = shopUnits.stream() + .collect(Collectors.toMap( + unit -> String.valueOf(unit.getId()), // 将 id 转换为 String 类型 + unit -> unit // 直接使用 TbShopUnit 作为值 + )); + } String day = DateUtils.getDay(); if(ObjectUtil.isNotEmpty(tbProductWithBLOBs)){ + Map finalShopUnitsMap = shopUnitsMap; tbProductWithBLOBs.parallelStream().forEach(it->{ Integer orderCount=tbProductMapper.countOrderByshopIdAndProductId(it.getShopId(),it.getId().toString(),masterId,day, tableId); it.setOrderCount((ObjectUtil.isNull(orderCount)||ObjectUtil.isEmpty(orderCount))?0:orderCount); @@ -142,6 +158,10 @@ public class ProductService { it.setSkuList(skuWithBLOBs); it.setGroundingSpecInfo(querySpec(Integer.valueOf(shopId), it.getId())); + if (it.getUnitId() != null) { + + } + it.setUnitName(finalShopUnitsMap.get(it.getUnitId())); }); } PageInfo pageInfo=new PageInfo(tbProductWithBLOBs);