Просмотр исходного кода

Merge remote-tracking branch 'origin/dev' into dev

lengfaqiang 2 лет назад
Родитель
Сommit
eb39cce9bb

+ 1 - 1
sckw-modules/sckw-product/src/main/java/com/sckw/product/controller/KwpGoodsController.java

@@ -67,7 +67,7 @@ public class KwpGoodsController {
     @GetMapping("/detail")
     @Log(description = "获取商品详情")
     public HttpResult detail(@RequestParam Long id) {
-        return HttpResult.ok(kwpGoodsService.detail(id));
+        return HttpResult.ok(kwpGoodsService.getDetail(id));
     }
 
     /**

+ 0 - 2
sckw-modules/sckw-product/src/main/java/com/sckw/product/model/vo/req/MaxPurchaseNumParam.java

@@ -1,7 +1,6 @@
 package com.sckw.product.model.vo.req;
 
 import jakarta.validation.constraints.DecimalMin;
-import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.Getter;
 import lombok.Setter;
@@ -35,7 +34,6 @@ public class MaxPurchaseNumParam {
     /**
      * 交易方式
      */
-    @NotBlank(message = "交易方式不能为空")
     private String trading;
 
     /**

+ 15 - 0
sckw-modules/sckw-product/src/main/java/com/sckw/product/model/vo/res/GoodsDetail.java

@@ -36,6 +36,16 @@ public class GoodsDetail {
      */
     private String ent;
 
+    /**
+     * 企业主营范围
+     */
+    private String entBusiness;
+
+    /**
+     * 企业地址
+     */
+    private String entAddress;
+
     /**
      * 供应单位id
      */
@@ -183,4 +193,9 @@ public class GoodsDetail {
      */
     private List<GoodsAttributesDetail> attributes;
 
+    /**
+     * 推荐商品
+     */
+    private List<RecommendGoods> recommendGoodsList;
+
 }

+ 33 - 0
sckw-modules/sckw-product/src/main/java/com/sckw/product/model/vo/res/RecommendGoods.java

@@ -0,0 +1,33 @@
+package com.sckw.product.model.vo.res;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+import java.math.BigDecimal;
+
+/**
+ * @desc: 推荐商品
+ * @author: yzc
+ * @date: 2023-08-15 11:25
+ */
+@Getter
+@Setter
+@ToString
+@Accessors(chain = true)
+public class RecommendGoods {
+
+    private Long id;
+
+    private String name;
+
+    private String unit;
+
+    private String unitLabel;
+
+    private String thumb;
+
+    private BigDecimal price;
+
+}

+ 41 - 4
sckw-modules/sckw-product/src/main/java/com/sckw/product/service/KwpGoodsService.java

@@ -166,6 +166,37 @@ public class KwpGoodsService {
         }
     }
 
+    /**
+     * @desc: 获取商品详情
+     * @author: yzc
+     * @date: 2023-08-15 14:28
+     * @Param id:
+     * @return: com.sckw.product.model.vo.res.GoodsDetail
+     */
+    public GoodsDetail getDetail(Long id) {
+        GoodsDetail detail = detail(id);
+        LambdaQueryWrapper<KwpGoods> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(KwpGoods::getGoodsType, detail.getGoodsType()).eq(KwpGoods::getStatus, GoodsStatusEnum.PUT_ON_SHELVES.getCode())
+                .eq(KwpGoods::getDelFlag, Global.NO).ne(KwpGoods::getId, id).last("LIMIT 4");
+        List<KwpGoods> list = kwpGoodsMapper.selectList(wrapper);
+        if (CollectionUtils.isEmpty(list)) {
+            return detail;
+        }
+        List<Long> goodsIds = list.stream().map(KwpGoods::getId).toList();
+        Map<Long, List<KwpGoodsPriceRange>> map = kwpGoodsPriceRangeService.getByGoodsIds(goodsIds).stream()
+                .collect(Collectors.groupingBy(KwpGoodsPriceRange::getGoodsId));
+        List<RecommendGoods> recommendGoodsList = new ArrayList<>();
+        list.forEach(e -> {
+            RecommendGoods recommendGoods = BeanUtils.copyProperties(e, RecommendGoods.class);
+            List<KwpGoodsPriceRange> prices = map.get(recommendGoods.getId());
+            recommendGoods.setUnitLabel(DictEnum.getLabel(DictTypeEnum.UNIT_TYPE.getType(), recommendGoods.getUnit()))
+                    .setPrice(CollectionUtils.isNotEmpty(prices) ? prices.get(0).getPrice() : null);
+            recommendGoodsList.add(recommendGoods);
+        });
+        detail.setRecommendGoodsList(recommendGoodsList);
+        return detail;
+    }
+
     /**
      * @desc: 获取商品详情
      * @author: yzc
@@ -179,9 +210,15 @@ public class KwpGoodsService {
             throw new BusinessException("当前商品不存在!");
         }
         GoodsDetail detail = BeanUtils.copyProperties(goods, GoodsDetail.class);
-        List<EntCacheResDto> entCacheList = remoteSystemService.queryEntCacheByIds(Arrays.asList(detail.getEntId(), detail.getSupplyEntId()));
-        Map<Long, String> entMap = entCacheList.stream().collect(Collectors.toMap(EntCacheResDto::getId, EntCacheResDto::getFirmName, (k1, k2) -> k1));
-        detail.setEnt(entMap.get(detail.getEntId())).setSupplyEnt(entMap.get(detail.getSupplyEntId()));
+        Map<Long, EntCacheResDto> entMap = remoteSystemService.queryEntCacheMapByIds(Arrays.asList(detail.getEntId(), detail.getSupplyEntId()));
+        EntCacheResDto ent = entMap.get(detail.getEntId());
+        if (Objects.nonNull(ent)) {
+            detail.setEnt(ent.getFirmName()).setEntBusiness(ent.getBusiness()).setEntAddress(ent.getCityName());
+        }
+        EntCacheResDto supplyEnt = entMap.get(detail.getSupplyEntId());
+        if (Objects.nonNull(supplyEnt)) {
+            detail.setEntAddress(supplyEnt.getFirmName());
+        }
         UserCacheResDto managerInfo = remoteSystemService.queryUserCacheById(detail.getManager());
         if (Objects.nonNull(managerInfo)) {
             detail.setManagerName(managerInfo.getName()).setManagerPhone(managerInfo.getPhone());
@@ -858,7 +895,7 @@ public class KwpGoodsService {
             throw new BusinessException("商品不存在或已下架!");
         }
         BigDecimal amount = goods.getAmount();
-        if (!param.getTrading().startsWith("1")) {
+        if (Objects.isNull(param.getTrading()) || !param.getTrading().startsWith("1")) {
             return amount;
         }
         if (Objects.isNull(param.getProcureEntId()) || Objects.isNull(param.getSupplyEntId())) {