Jelajahi Sumber

feign接口

刘俊驰 1 tahun lalu
induk
melakukan
779a77404a

+ 2 - 1
mec-client-api/src/main/java/com/ym/mec/mall/MallFeignService.java

@@ -6,6 +6,7 @@ import com.ym.mec.common.dto.PmsProductQueryParamDto;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.mall.fallback.MallFeignServiceFallback;
 import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 @FeignClient(name = "${app-config.open-feign.mall-server.name:mall-server}",
@@ -14,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 		configuration = FeignConfiguration.class, fallback = MallFeignServiceFallback.class)
 public interface MallFeignService {
 
-	@RequestMapping(value = "open/product/list")
+	@PostMapping(value = "open/product/list")
 	PageInfo<PmsProductDto> getProductList(PmsProductQueryParamDto productQueryParam);
 
 }

+ 7 - 0
mec-common/common-core/src/main/java/com/ym/mec/common/dto/PmsProductDto.java

@@ -30,9 +30,16 @@ public class PmsProductDto implements Serializable {
     //库存
     private Integer stock;
 
+    private Long brandId;
+
     //品牌名称
     private String brandName;
 
+    private Long productCategoryId;
     //商品分类名称
     private String productCategoryName;
+
+
+    //"商品销售属性,json格式"
+    private String spData;
 }

+ 25 - 5
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/controller/open/OpenController.java

@@ -1,7 +1,12 @@
 package com.yonge.cooleshow.admin.controller.open;
 
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
+import com.ym.mec.common.page.PageInfo;
 import com.yonge.cooleshow.admin.controller.OmsOrderReturnApplyController;
 import com.yonge.cooleshow.admin.service.OmsOrderReturnApplyService;
+import com.yonge.cooleshow.admin.service.PmsProductService;
+import com.yonge.cooleshow.mall.common.api.CommonPage;
 import com.yonge.cooleshow.mall.common.api.CommonResult;
 import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
 import io.swagger.annotations.Api;
@@ -13,11 +18,9 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -26,7 +29,7 @@ import java.util.concurrent.TimeUnit;
  * @author liujunchi
  * @date 2022-07-28
  */
-@Controller
+@RestController
 @RequestMapping("/open")
 public class OpenController {
     @Autowired
@@ -39,6 +42,9 @@ public class OpenController {
     @Autowired
     private RedissonClient redissonClient;
 
+    @Autowired
+    private PmsProductService productService;
+
     private static final Logger log = LoggerFactory.getLogger(OmsOrderReturnApplyController.class);
 
     @ApiOperation("完成退货测试接口")
@@ -66,4 +72,18 @@ public class OpenController {
         return CommonResult.failed();
     }
 
+    @PostMapping(value = "/product/list")
+    public PageInfo<PmsProductDto> getProductList(@RequestBody PmsProductQueryParamDto productQueryParam){
+
+        List<PmsProductDto> feignProductList = productService.getFeignProductList(productQueryParam);
+        CommonPage<PmsProductDto> dtoCommonPage = CommonPage.restPage(feignProductList);
+        PageInfo<PmsProductDto> pageInfo = new PageInfo<>();
+        pageInfo.setRows(feignProductList);
+        pageInfo.setLimit(dtoCommonPage.getPageSize());
+        pageInfo.setOffset(dtoCommonPage.getPageNum());
+        pageInfo.setPageNo(dtoCommonPage.getPageSize());
+        pageInfo.setTotal(dtoCommonPage.getTotal().intValue());
+        return pageInfo;
+
+    }
 }

+ 8 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dao/PmsProductDao.java

@@ -1,5 +1,7 @@
 package com.yonge.cooleshow.admin.dao;
 
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
 import com.yonge.cooleshow.admin.dto.HomeStatistical;
 import com.yonge.cooleshow.admin.dto.PmsProductQueryParam;
 import com.yonge.cooleshow.admin.dto.PmsProductResult;
@@ -24,4 +26,10 @@ public interface PmsProductDao {
     HomeStatistical selectProductShowStatusCount();
 
     List<PmsProduct> list(@Param("param") PmsProductQueryParam productQueryParam);
+
+
+    /**
+     * 获取商品SKU列表
+     */
+    List<PmsProductDto> getFeignProductList(@Param("param") PmsProductQueryParamDto productQueryParam);
 }

+ 2 - 55
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/dto/PmsProductQueryParam.java

@@ -1,12 +1,13 @@
 package com.yonge.cooleshow.admin.dto;
 
 import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
 
 /**
  * 商品查询参数
  * Created by macro on 2018/4/27.
  */
-
+@Data
 public class PmsProductQueryParam {
     @ApiModelProperty("上架状态")
     private Integer publishStatus;
@@ -24,59 +25,5 @@ public class PmsProductQueryParam {
     @ApiModelProperty("是否缺货 0:否,1;是")
     private Integer stock;
 
-    public Integer getStock() {
-        return stock;
-    }
-
-    public void setStock(Integer stock) {
-        this.stock = stock;
-    }
-
-    public Integer getPublishStatus() {
-        return publishStatus;
-    }
-
-    public void setPublishStatus(Integer publishStatus) {
-        this.publishStatus = publishStatus;
-    }
-
-    public Integer getVerifyStatus() {
-        return verifyStatus;
-    }
-
-    public void setVerifyStatus(Integer verifyStatus) {
-        this.verifyStatus = verifyStatus;
-    }
-
-    public String getKeyword() {
-        return keyword;
-    }
-
-    public void setKeyword(String keyword) {
-        this.keyword = keyword;
-    }
-
-    public String getProductSn() {
-        return productSn;
-    }
-
-    public void setProductSn(String productSn) {
-        this.productSn = productSn;
-    }
-
-    public Long getProductCategoryId() {
-        return productCategoryId;
-    }
-
-    public void setProductCategoryId(Long productCategoryId) {
-        this.productCategoryId = productCategoryId;
-    }
-
-    public Long getBrandId() {
-        return brandId;
-    }
 
-    public void setBrandId(Long brandId) {
-        this.brandId = brandId;
-    }
 }

+ 3 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/PmsBrandService.java

@@ -5,6 +5,7 @@ import com.yonge.cooleshow.mbg.model.PmsBrand;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 商品品牌管理Service
@@ -61,4 +62,6 @@ public interface PmsBrandService {
      */
     @Transactional
     int updateFactoryStatus(List<Long> ids, Integer factoryStatus);
+
+    Map<Long,PmsBrand> getMapByIds(List<Long> brandIds);
 }

+ 3 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/PmsProductCategoryService.java

@@ -6,6 +6,7 @@ import com.yonge.cooleshow.mbg.model.PmsProductCategory;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 商品分类管理Service
@@ -56,4 +57,6 @@ public interface PmsProductCategoryService {
      * 以层级形式获取商品分类
      */
     List<PmsProductCategoryWithChildrenItem> listWithChildren();
+
+    Map<Long,PmsProductCategory> getMapByIds(List<Long> categoryIds);
 }

+ 8 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/PmsProductService.java

@@ -1,5 +1,7 @@
 package com.yonge.cooleshow.admin.service;
 
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
 import com.yonge.cooleshow.admin.dto.HomeStatistical;
 import com.yonge.cooleshow.admin.dto.PmsProductParam;
 import com.yonge.cooleshow.admin.dto.PmsProductQueryParam;
@@ -90,4 +92,10 @@ public interface PmsProductService {
     HomeStatistical countProductShowStatus();
 
     Map<Long, PmsProduct> getMapByIds(List<Long> productIds);
+
+    /**
+     * 获取商品SKU列表
+     *
+     */
+    List<PmsProductDto> getFeignProductList(PmsProductQueryParamDto productQueryParam);
 }

+ 36 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/OmsOrderServiceImpl.java

@@ -1,8 +1,11 @@
 package com.yonge.cooleshow.admin.service.impl;
 
 import com.github.pagehelper.PageHelper;
+import com.ym.mec.common.entity.GoodsSubStockModel;
+import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.util.date.DateUtil;
+import com.ym.mec.web.WebFeignService;
 import com.yonge.cooleshow.admin.dao.OmsOrderDao;
 import com.yonge.cooleshow.admin.dao.OmsOrderOperateHistoryDao;
 import com.yonge.cooleshow.admin.dao.PmsProductSkuStockRecordDao;
@@ -11,6 +14,7 @@ import com.yonge.cooleshow.admin.dto.search.OrderStatisticalSearch;
 import com.yonge.cooleshow.admin.dto.search.UserStatisticalSearch;
 import com.yonge.cooleshow.admin.service.OmsOrderReturnApplyService;
 import com.yonge.cooleshow.admin.service.PmsProductService;
+import com.yonge.cooleshow.admin.service.PmsSkuStockService;
 import com.yonge.cooleshow.mbg.mapper.OmsOrderItemMapper;
 import com.yonge.cooleshow.mbg.mapper.OmsOrderMapper;
 import com.yonge.cooleshow.mbg.mapper.OmsOrderOperateHistoryMapper;
@@ -62,6 +66,12 @@ public class OmsOrderServiceImpl implements OmsOrderService {
     @Autowired
     private PmsProductSkuStockRecordMapper pmsProductSkuStockRecordMapper;
 
+    @Autowired
+    private WebFeignService webFeignService;
+
+    @Autowired
+    private PmsSkuStockService pmsSkuStockService;
+
     @Override
     public List<OrderVo> list(OmsOrderQueryParam queryParam, Integer pageSize, Integer pageNum) {
         PageHelper.startPage(pageNum, pageSize);
@@ -183,6 +193,32 @@ public class OmsOrderServiceImpl implements OmsOrderService {
                     return history;
                 }).collect(Collectors.toList());
         orderOperateHistoryDao.insertList(operateHistoryList);
+
+        // 调用三方发货通知接口
+        OmsOrderExample orderExample = new OmsOrderExample();
+        orderExample.createCriteria().andIdIn(orderIds);
+        List<OmsOrder> omsOrders = orderMapper.selectByExample(orderExample);
+        // 订单号
+        List<String> orderSnList = omsOrders.stream().map(OmsOrder::getOrderSn).collect(Collectors.toList());
+        HttpResponseResult httpResponseResult = webFeignService.updateShippedStatus(orderSnList);
+        if (httpResponseResult.getCode() != 200 && !httpResponseResult.getStatus()) {
+            throw new BizException("发货通知失败");
+        }
+
+        // 调用三方库存更新接口
+        Map<Long, PmsSkuStock> skuStockMap = pmsSkuStockService.getMapByIds(skuIds);
+        List<GoodsSubStockModel> modelList = skuStockMap.values().stream().map(skuStock -> {
+            GoodsSubStockModel stockModel = new GoodsSubStockModel();
+            stockModel.setMallGoodsId(skuStock.getProductId().intValue());
+            stockModel.setSku(skuStock.getId().intValue());
+            stockModel.setStock(skuStock.getStock());
+            return stockModel;
+        }).collect(Collectors.toList());
+        HttpResponseResult<Boolean> booleanHttpResponseResult = webFeignService.goodsStockCountSynchronize(modelList);
+        if (booleanHttpResponseResult.getCode() != 200 && !booleanHttpResponseResult.getStatus()) {
+            throw new BizException("库存同步失败");
+        }
+
         return count;
     }
 

+ 16 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/PmsBrandServiceImpl.java

@@ -12,9 +12,14 @@ import com.yonge.cooleshow.admin.service.PmsBrandService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * 商品品牌管理Service实现类
@@ -107,4 +112,15 @@ public class PmsBrandServiceImpl implements PmsBrandService {
         pmsBrandExample.createCriteria().andIdIn(ids);
         return brandMapper.updateByExampleSelective(pmsBrand, pmsBrandExample);
     }
+
+    @Override
+    public Map<Long, PmsBrand> getMapByIds(List<Long> brandIds) {
+        if (CollectionUtils.isEmpty(brandIds)) {
+            return new HashMap<>();
+        }
+        PmsBrandExample pmsBrandExample = new PmsBrandExample();
+        pmsBrandExample.createCriteria().andIdIn(brandIds);
+        List<PmsBrand> pmsBrands = brandMapper.selectByExample(pmsBrandExample);
+        return pmsBrands.stream().collect(Collectors.toMap(PmsBrand::getId, Function.identity()));
+    }
 }

+ 15 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/PmsProductCategoryServiceImpl.java

@@ -16,7 +16,11 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 /**
  * 商品分类管理Service实现类
@@ -134,6 +138,17 @@ public class PmsProductCategoryServiceImpl implements PmsProductCategoryService
         return productCategoryDao.listWithChildren();
     }
 
+    @Override
+    public Map<Long, PmsProductCategory> getMapByIds(List<Long> categoryIds) {
+        if (CollectionUtils.isEmpty(categoryIds)) {
+            return new HashMap<>();
+        }
+        PmsProductCategoryExample example = new PmsProductCategoryExample();
+        example.createCriteria().andIdIn(categoryIds);
+        List<PmsProductCategory> productCategoryList = productCategoryMapper.selectByExample(example);
+        return productCategoryList.stream().collect(Collectors.toMap(PmsProductCategory::getId, Function.identity()));
+    }
+
     /**
      * 根据分类的parentId设置分类的level
      */

+ 44 - 1
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/PmsProductServiceImpl.java

@@ -2,6 +2,8 @@ package com.yonge.cooleshow.admin.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import com.github.pagehelper.PageHelper;
+import com.ym.mec.common.dto.PmsProductDto;
+import com.ym.mec.common.dto.PmsProductQueryParamDto;
 import com.ym.mec.common.entity.GoodsSubModel;
 import com.ym.mec.common.entity.GoodsSubStockModel;
 import com.ym.mec.common.exception.BizException;
@@ -12,6 +14,8 @@ import com.yonge.cooleshow.admin.dto.HomeStatistical;
 import com.yonge.cooleshow.admin.dto.PmsProductParam;
 import com.yonge.cooleshow.admin.dto.PmsProductQueryParam;
 import com.yonge.cooleshow.admin.dto.PmsProductResult;
+import com.yonge.cooleshow.admin.service.PmsBrandService;
+import com.yonge.cooleshow.admin.service.PmsProductCategoryService;
 import com.yonge.cooleshow.admin.service.PmsProductService;
 import com.yonge.cooleshow.mbg.mapper.*;
 import com.yonge.cooleshow.mbg.model.*;
@@ -71,9 +75,15 @@ public class PmsProductServiceImpl implements PmsProductService {
     private PmsProductDao productDao;
     @Autowired
     private PmsProductVertifyRecordDao productVertifyRecordDao;
-    @Resource
+    @Autowired
     private WebFeignService webFeignService;
 
+    @Autowired
+    private PmsBrandService brandService;
+
+    @Autowired
+    private PmsProductCategoryService productCategoryService;
+
     @Override
     public int create(PmsProductParam productParam) {
         if (productParam.getPrice().compareTo(BigDecimal.ZERO) <=0 ) {
@@ -362,6 +372,39 @@ public class PmsProductServiceImpl implements PmsProductService {
         return pmsProducts.stream().collect(Collectors.toMap(PmsProduct::getId, pmsProduct -> pmsProduct));
     }
 
+    @Override
+    public List<PmsProductDto> getFeignProductList(PmsProductQueryParamDto productQueryParam) {
+        PageHelper.startPage(productQueryParam.getPageNum(), productQueryParam.getPageSize());
+        List<PmsProductDto> feignProductList = productDao.getFeignProductList(productQueryParam);
+        if (CollectionUtils.isEmpty(feignProductList)) {
+            return new ArrayList<>();
+        }
+        // 品牌ID集合
+        List<Long> brandIds = feignProductList.stream().map(PmsProductDto::getBrandId).collect(Collectors.toList());
+
+        Map<Long, PmsBrand> brandMap = brandService.getMapByIds(brandIds);
+
+        // 商品分类ID集合
+        List<Long> categoryIds = feignProductList.stream().map(PmsProductDto::getProductCategoryId).collect(Collectors.toList());
+
+        Map<Long, PmsProductCategory> categoryMap = productCategoryService.getMapByIds(categoryIds);
+
+        // merge
+        for (PmsProductDto pmsProductDto : feignProductList) {
+
+            PmsBrand pmsBrand = brandMap.get(pmsProductDto.getBrandId());
+            if (pmsBrand != null) {
+                pmsProductDto.setBrandName(pmsBrand.getName());
+            }
+            PmsProductCategory pmsProductCategory = categoryMap.get(pmsProductDto.getProductCategoryId());
+            if (pmsProductCategory != null) {
+                pmsProductDto.setProductCategoryName(pmsProductCategory.getName());
+            }
+        }
+
+        return feignProductList;
+    }
+
     /**
      * 建立和插入关系表操作
      *

+ 33 - 0
mec-mall/mall-admin/src/main/java/com/yonge/cooleshow/admin/service/impl/PmsSkuStockServiceImpl.java

@@ -80,9 +80,42 @@ public class PmsSkuStockServiceImpl implements PmsSkuStockService {
         PmsSkuStockExample example = new PmsSkuStockExample();
         example.createCriteria().andIdIn(skuIds);
         List<PmsSkuStock> skuStockList = skuStockMapper.selectByExample(example);
+        skuStockList = updateProductSkuStock(skuStockList);
         if (CollectionUtils.isEmpty(skuStockList)) {
             return new HashMap<>();
         }
         return skuStockList.stream().collect(Collectors.toMap(PmsSkuStock::getId, skuStock -> skuStock));
     }
+
+    public List<PmsSkuStock> updateProductSkuStock(List<PmsSkuStock> skuStocks) {
+        if (CollectionUtils.isEmpty(skuStocks)) {
+            return new ArrayList<>();
+        }
+        // 从进货清单中 获取剩余库存数量
+        List<Long> productIds = skuStocks.stream().map(PmsSkuStock::getProductId).distinct().collect(Collectors.toList());
+
+        // 计算库存数据
+        List<PmsSkuStockDto.PmsSkuStockStock> skuStockStocks = skuStockMapper.getSkuStockByProductIds(productIds);
+
+        // Convert to map
+        Map<Long, Map<Long, List<PmsSkuStockDto.PmsSkuStockStock>>> map = skuStockStocks.stream()
+            .collect(Collectors.groupingBy(PmsSkuStockDto.PmsSkuStockStock::getProductId, Collectors.groupingBy(PmsSkuStockDto.PmsSkuStockStock::getId)));
+
+        // Merge
+        for (PmsSkuStock skuStock : skuStocks) {
+            Map<Long, List<PmsSkuStockDto.PmsSkuStockStock>> skuStockStock = map.get(skuStock.getProductId());
+            if (!CollectionUtils.isEmpty(skuStockStock)) {
+                List<PmsSkuStockDto.PmsSkuStockStock> pmsSkuStockStocks = skuStockStock.get(skuStock.getId());
+                if (CollectionUtils.isEmpty(pmsSkuStockStocks)) {
+                    skuStock.setLockStock(0);
+                    skuStock.setStock(0);
+                    continue;
+                }
+                skuStock.setStock(pmsSkuStockStocks.stream().mapToInt(item -> item.getInternalStock() + item.getTaxStock()).sum());
+                skuStock.setLockStock(0);
+            }
+
+        }
+        return skuStocks;
+    }
 }

+ 43 - 0
mec-mall/mall-admin/src/main/resources/config/mybatis/PmsProductDao.xml

@@ -109,4 +109,47 @@
         </where>
         order by pp.sort desc,pp.id desc
     </select>
+
+    <select id="getFeignProductList" resultType="com.ym.mec.common.dto.PmsProductDto">
+        select t1.id as skuStockId,
+        t.id as goodsId,
+        t1.sku_code as skuCode,
+        t.name as name,
+        t.product_sn as productSn,
+        t.delete_status as deleteStatus,
+        t.publish_status as publishStatus,
+        t1.price as price,
+        t.brand_id as brandId,
+        t.product_category_id as productCategoryId,
+        t1.sp_data as spData
+        from pms_product t
+        left join pms_sku_stock t1 on t.id = t1.product_id
+        <where>
+            t.delete_status = 0
+            <if test="param.publishStatus != null">
+                and t.publish_status = #{param.publishStatus}
+            </if>
+            <if test="param.skuStockIds != null and param.skuStockIds != ''">
+                and find_in_set(t1.id,#{param.skuStockIds})
+            </if>
+            <if test="param.keyword != null and param.keyword != ''">
+                and (t.name like concat('%',#{param.keyword},'%') )
+            </if>
+            <if test="param.productSn != null and param.productSn != ''">
+                and t.product_sn like concat('%',#{param.productSn},'%')
+            </if>
+            <if test="param.brandId != null">
+                and t.brand_id = #{param.brandId}
+            </if>
+            <if test="param.productCategoryId != null">
+                and t.product_category_id = #{param.productCategoryId}
+            </if>
+            <if test="param.productIds != null and param.productIds != ''">
+                and find_in_set(t.id,#{param.productIds})
+            </if>
+            <if test="param.excludeProductIds != null and param.excludeProductIds != ''">
+                and find_in_set(t.id,#{param.excludeProductIds}) = 0
+            </if>
+        </where>
+    </select>
 </mapper>