fix: 商品列表返回单位
This commit is contained in:
@@ -86,7 +86,8 @@ public class TbProduct implements Serializable {
|
||||
private Object groundingSpecInfo;
|
||||
private String specInfo;
|
||||
private String selectSpec;
|
||||
|
||||
@TableField(exist = false)
|
||||
private TbShopUnit unitName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String, TbShopUnit> shopUnitsMap = new HashMap<>();
|
||||
Set<String> unitIds = tbProductWithBLOBs.stream().map(TbProduct::getUnitId).collect(Collectors.toSet());
|
||||
if (!unitIds.isEmpty()) {
|
||||
List<TbShopUnit> 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<String, TbShopUnit> 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);
|
||||
|
||||
Reference in New Issue
Block a user