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);