Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/developer' into developerA

# Conflicts:
#	src/main/java/com/caimei365/commodity/mapper/PriceMapper.java
#	src/main/resources/mapper/PriceMapper.xml
chao 3 rokov pred
rodič
commit
6400723914

+ 19 - 0
src/main/java/com/caimei365/commodity/controller/ProductPriceApi.java

@@ -1,6 +1,7 @@
 package com.caimei365.commodity.controller;
 
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.dto.ProductSalesDto;
 import com.caimei365.commodity.model.vo.LadderPriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
 import com.caimei365.commodity.service.PriceService;
@@ -11,6 +12,7 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -84,4 +86,21 @@ public class ProductPriceApi {
         return priceService.getLadderPrice(productId);
     }
 
+    /**
+     * 更新商品销量
+     * @param productSalesDto {productInfo: [ // 商品id,数量
+     *                                      {"productId": 2789, "productCount": 1},
+     *                                      {"productId": 2790, "productCount": 2}
+     *                                       ]
+     *                        }
+     */
+    @ApiOperation("更新商品销量")
+    @PostMapping("/sales/update")
+    public ResponseJson<Void> productSaleUpdate(ProductSalesDto productSalesDto){
+        if (StringUtils.isEmpty(productSalesDto.getProductInfo())){
+            return ResponseJson.error("商品数据不能为空!", null);
+        }
+        return priceService.productSaleUpdate(productSalesDto.getProductInfo());
+    }
+
 }

+ 9 - 0
src/main/java/com/caimei365/commodity/mapper/PriceMapper.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.mapper;
 
+import com.caimei365.commodity.model.vo.ProductSalesVo;
 import com.caimei365.commodity.model.vo.LadderPriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
 import com.caimei365.commodity.model.vo.TaxVo;
@@ -52,4 +53,12 @@ public interface PriceMapper {
      * 根据用户id查询超级会员用户id
      */
     Integer getSvipUserIdByUserId(Integer userId);
+    /**
+     * 获取商品销量信息
+     */
+    ProductSalesVo getProductSalesInfo(Integer productId);
+
+    void insertProductSales(ProductSalesVo salesVo);
+
+    void updateProductSales(ProductSalesVo salesVo);
 }

+ 4 - 0
src/main/java/com/caimei365/commodity/mapper/ShopMapper.java

@@ -155,4 +155,8 @@ public interface ShopMapper {
      *  获取商品小程序云上美博会活动状态
      */
     Integer getAppletsBeautyStatusById(Integer productId);
+    /**
+     * 获取供应商名称
+     */
+    String getShopNameByShopId(Integer shopId);
 }

+ 27 - 0
src/main/java/com/caimei365/commodity/model/dto/ProductSalesDto.java

@@ -0,0 +1,27 @@
+package com.caimei365.commodity.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/10/11
+ */
+@ApiModel("商品销量")
+@Data
+public class ProductSalesDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 商品信息:[ // 商品id,数量
+     *         {"productId": 2789, "productCount": 1},
+     *         {"productId": 2790, "productCount": 2}
+     *         ]
+     */
+    @ApiModelProperty("商品信息[{\"productId\": 2789, \"productCount\": 1},{}]")
+    private String productInfo;
+}

+ 68 - 0
src/main/java/com/caimei365/commodity/model/vo/ProductSalesVo.java

@@ -0,0 +1,68 @@
+package com.caimei365.commodity.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/10/11
+ */
+@Data
+public class ProductSalesVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private Integer id;
+    /**
+     * 商品ID
+     */
+    private Integer productId;
+    /**
+     * 商品名称
+     */
+    private String productName;
+    /**
+     * 供应商ID
+     */
+    private Integer shopId;
+    /**
+     * 供应商名称
+     */
+    private String shopName;
+    /**
+     * 销量
+     */
+    private Integer productCount;
+    /**
+     * 分类 ‘-’分割
+     */
+    private String property;
+    /**
+     * 商品属性:1产品,2仪器
+     */
+    private Integer commodityType;
+    /**
+     * 一级分类ID
+     */
+    private Integer bigTypeId;
+    /**
+     * 二级分类Id
+     */
+    private Integer smallTypeId;
+    /**
+     * 三级分类Id
+     */
+    private Integer tinyTypeId;
+
+    @Override
+    public String toString() {
+        return "ProductSalesVo{" +
+                "productId=" + productId +
+                ", productName='" + productName + '\'' +
+                ", shopName='" + shopName + '\'' +
+                ", productCount=" + productCount +
+                ", property='" + property + '\'' +
+                '}';
+    }
+}

+ 8 - 0
src/main/java/com/caimei365/commodity/service/PriceService.java

@@ -39,4 +39,12 @@ public interface PriceService {
      * @return LadderPriceVo
      */
     ResponseJson<List<LadderPriceVo>> getLadderPrice(Integer productId);
+    /**
+     * 更新商品销量
+     * @param productInfo [ // 商品id,数量
+     *                   {"productId": 2789, "productCount": 1},
+     *                   {"productId": 2790, "productCount": 2}
+     *                 ]
+     */
+    ResponseJson<Void> productSaleUpdate(String productInfo);
 }

+ 63 - 2
src/main/java/com/caimei365/commodity/service/impl/PriceServiceImpl.java

@@ -1,10 +1,13 @@
 package com.caimei365.commodity.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.aliyun.opensearch.sdk.dependencies.com.google.common.collect.Lists;
 import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.mapper.PriceMapper;
-import com.caimei365.commodity.mapper.PromotionsMapper;
+import com.caimei365.commodity.mapper.ShopMapper;
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.vo.ProductSalesVo;
 import com.caimei365.commodity.model.vo.LadderPriceVo;
 import com.caimei365.commodity.model.vo.PriceVo;
 import com.caimei365.commodity.model.vo.TaxVo;
@@ -13,10 +16,14 @@ import com.caimei365.commodity.service.PriceService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
 import java.util.List;
 
+import static com.alibaba.fastjson.JSON.parseArray;
+import static com.alibaba.fastjson.JSON.parseObject;
+
 /**
  * Description
  *
@@ -29,7 +36,7 @@ public class PriceServiceImpl implements PriceService {
     @Resource
     private PriceMapper priceMapper;
     @Resource
-    private PromotionsMapper promotionsMapper;
+    private ShopMapper shopMapper;
     @Resource
     private PriceUtilService priceUtilService;
     @Resource
@@ -100,4 +107,58 @@ public class PriceServiceImpl implements PriceService {
         }
         return ResponseJson.success(ladderPrices);
     }
+
+    /**
+     * 更新商品销量
+     *
+     * @param productInfo [ // 商品id,数量
+     *                    {"productId": 2789, "productCount": 1},
+     *                    {"productId": 2790, "productCount": 2}
+     *                    ]
+     */
+    @Override
+    public ResponseJson<Void> productSaleUpdate(String productInfo) {
+        JSONArray infoArr = null;
+        try {
+            infoArr = parseArray(productInfo);
+        } catch (Exception e) {
+            log.error("【更新商品销量】商品信息解析异常try-catch:", e);
+            return ResponseJson.error("商品信息解析异常!", null);
+        }
+        if (null == infoArr) {
+            return ResponseJson.error("商品数据异常!", null);
+        }
+        // 遍历所有商品
+        for (Object productObject : infoArr) {
+            JSONObject productTemp = (JSONObject) productObject;
+            Integer productId = (Integer) productTemp.get("productId");
+            Integer productCount = (Integer) productTemp.get("productCount");
+            // 获取商品销量信息
+            ProductSalesVo salesVo = priceMapper.getProductSalesInfo(productId);
+            if (null == salesVo || ObjectUtils.isEmpty(salesVo)){
+                return ResponseJson.error("商品数据异常!", null);
+            }
+            int dbCount = (null == salesVo.getProductCount()) ? 0 : salesVo.getProductCount();
+            salesVo.setProductCount(dbCount + productCount);
+            // 获取供应商名称
+            String shopName = shopMapper.getShopNameByShopId(salesVo.getShopId());
+            salesVo.setShopName(shopName);
+            // 分类名称
+            String typeName = shopMapper.getTypeName(salesVo.getBigTypeId(), salesVo.getSmallTypeId(), salesVo.getTinyTypeId());
+            if (null != salesVo.getCommodityType() && 2 == salesVo.getCommodityType()){
+                salesVo.setProperty("仪器-"+typeName);
+            } else {
+                salesVo.setProperty("产品-"+typeName);
+            }
+            if (null == salesVo.getId()) {
+                // 新商品
+                priceMapper.insertProductSales(salesVo);
+            } else {
+                // 更新销量
+                priceMapper.updateProductSales(salesVo);
+            }
+            log.info("【更新商品销量】:"+salesVo.toString());
+        }
+        return ResponseJson.success(null);
+    }
 }

+ 28 - 0
src/main/resources/mapper/PriceMapper.xml

@@ -109,4 +109,32 @@
           and userId = #{userId}
     </select>
 
+    <select id="getProductSalesInfo" resultType="com.caimei365.commodity.model.vo.ProductSalesVo">
+        select p.productID AS productId,
+               p.name AS productName,
+               p.shopID AS shopId,
+               p.commodityType,
+               p.bigTypeID as bigTypeId,
+               p.smallTypeID as smallTypeId,
+               p.tinyTypeID as tinyTypeId,
+               s.productId AS id,
+               s.shop AS shopName,
+               s.productCount AS productCount,
+               s.property AS property
+        FROM product p
+        LEFT JOIN cm_product_sales s ON p.productID = s.productId
+        where p.productId=#{productId}
+    </select>
+    <insert id="insertProductSales" parameterType="com.caimei365.commodity.model.vo.ProductSalesVo">
+        INSERT INTO cm_product_sales(productId, product, shop, productCount, property)
+        VALUES (#{productId}, #{productName}, #{shopName}, #{productCount}, #{property})
+    </insert>
+    <update id="updateProductSales" parameterType="com.caimei365.commodity.model.vo.ProductSalesVo">
+        UPDATE cm_product_sales
+        SET product=#{productName},
+            shop=#{shopName},
+            productCount=#{productCount},
+            property=#{property}
+        WHERE productId = #{productId}
+    </update>
 </mapper>

+ 1 - 1
src/main/resources/mapper/PromotionsMapper.xml

@@ -94,7 +94,7 @@
     </select>
     <select id="getProductListByPromotions" resultType="com.caimei365.commodity.model.search.ProductListVo">
 		select
-			p.productID as id,
+			p.productID as productId,
 			p.`name` as `name`,
 			p.mainImage as image,
 			p.price1 as price,

+ 3 - 0
src/main/resources/mapper/ShopMapper.xml

@@ -552,4 +552,7 @@
         select i.productId from new_page_floor_image i left join cm_page_centre c on i.centreId = c.id left join cm_page p on c.pageId = p.id
         where i.productId = #{productId} and i.appletsStatus = 1  and p.type = 7 and c.crmEnabledStatus = 1 and p.enabledStatus = 1 limit 1
     </select>
+    <select id="getShopNameByShopId" resultType="java.lang.String">
+        select name from shop where shopID = #{shopId}
+    </select>
 </mapper>