소스 검색

商品详情

chao 4 년 전
부모
커밋
508f75d842

+ 54 - 0
src/main/java/com/caimei365/commodity/controller/ProductPageApi.java

@@ -1,6 +1,8 @@
 package com.caimei365.commodity.controller;
 
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.po.ProductParameterPo;
+import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.PageService;
 import io.swagger.annotations.Api;
@@ -134,4 +136,56 @@ public class ProductPageApi {
         return pageService.getEquipmentDetails(equipmentId);
     }
 
+
+    /**
+     * 商品详情页-图片
+     *
+     * @param productId 商品Id
+     */
+    @ApiOperation("商品详情-图片(旧:/product/detail/images)")
+    @ApiImplicitParam(required = false, name = "productId", value = "商品Id")
+    @GetMapping("/product/detail/images")
+    public ResponseJson<List<String>> getProductDetailImages(Integer productId) {
+        return pageService.getProductDetailImages(productId);
+    }
+
+    /**
+     * 商品详情页-相关参数
+     *
+     * @param productId 商品Id
+     */
+    @ApiOperation("商品详情-相关参数(旧:/product/detail/parameter)")
+    @ApiImplicitParam(required = false, name = "productId", value = "商品Id")
+    @GetMapping("/detail/params")
+    public ResponseJson<List<ProductParameterPo>> getProductParameters(Integer productId) {
+        return pageService.getProductParameters(productId);
+    }
+
+    /**
+     * 商品详情页-相关推荐
+     *
+     * @param productId 商品Id
+     * @param recommendType 相关推荐类型: 0自动选择, 1手动推荐
+     * @param userId    用户Id
+     */
+    @ApiOperation("商品详情页(旧:/product/detail/recommend)")
+    @ApiImplicitParams({
+        @ApiImplicitParam(required = false, name = "productId", value = "商品Id"),
+        @ApiImplicitParam(required = false, name = "recommendType", value = "相关推荐类型: 0自动选择, 1手动推荐"),
+        @ApiImplicitParam(required = false, name = "userId", value = "用户id")
+    })
+    @GetMapping("/detail/recommend")
+    public ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId) {
+        return pageService.getProductDetailRecommends(productId, recommendType, userId);
+    }
+
+
+
+
+
+
+
+
+
+
 }

+ 2 - 0
src/main/java/com/caimei365/commodity/controller/SecondHandApi.java

@@ -12,6 +12,7 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.http.HttpHeaders;
 import org.springframework.web.bind.annotation.*;
 
@@ -95,4 +96,5 @@ public class SecondHandApi {
     }
 
 
+
 }

+ 6 - 1
src/main/java/com/caimei365/commodity/mapper/PageMapper.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.mapper;
 
+import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 
@@ -91,9 +92,13 @@ public interface PageMapper {
      * 根据仪器id和类型id获取仪器参数
      */
     List<EquipmentParameterVo> getEquipmentParametersByType(Integer equipmentId, Integer typeId);
-
     /**
      * 二级专题楼层下的数据
      */
     List<ImageLinkVo> getImageLinkByFloorId(Integer floorId);
+    /**
+     * 详情-相关推荐
+     */
+    List<ProductListVo> getProductRecommendsById(Integer productId);
+    List<ProductListVo> getAutoProductRecommends(Integer productId);
 }

+ 5 - 0
src/main/java/com/caimei365/commodity/model/dto/ProductDto.java

@@ -156,6 +156,11 @@ public class ProductDto implements Serializable {
      */
     @ApiModelProperty("指定的销售区域")
     private String provinceIds;
+    /**
+     * 商品详情Id
+     */
+    @ApiModelProperty("商品详情Id")
+    private Integer productDetailInfoId;
     /**
      * 商品详情信息
      */

+ 2 - 0
src/main/java/com/caimei365/commodity/model/search/ProductListVo.java

@@ -38,6 +38,8 @@ public class ProductListVo implements Serializable {
     private String keyword;
     /** 美博会商品活动状态 */
     private Integer beautyActFlag;
+    /** 商品可见度: 3:所有人可见,2:普通机构可见,1:会员机构可见 */
+    private Integer visibility;
 
     private static final long serialVersionUID = 1L;
 

+ 25 - 0
src/main/java/com/caimei365/commodity/service/PageService.java

@@ -1,6 +1,8 @@
 package com.caimei365.commodity.service;
 
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.po.ProductParameterPo;
+import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.*;
 
 import java.util.List;
@@ -63,4 +65,27 @@ public interface PageService {
      * @param equipmentId 项目仪器Id
      */
     ResponseJson<EquipmentVo> getEquipmentDetails(Integer equipmentId);
+
+    /**
+     * 商品详情页-图片
+     *
+     * @param productId 商品Id
+     */
+    ResponseJson<List<String>> getProductDetailImages(Integer productId);
+
+    /**
+     * 商品详情页-相关参数
+     *
+     * @param productId 商品Id
+     */
+    ResponseJson<List<ProductParameterPo>> getProductParameters(Integer productId);
+
+    /**
+     * 商品详情页-相关推荐
+     *
+     * @param productId 商品Id
+     * @param recommendType 相关推荐类型: 0自动选择, 1手动推荐
+     * @param userId    用户Id
+     */
+    ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId);
 }

+ 77 - 0
src/main/java/com/caimei365/commodity/service/impl/PageServiceImpl.java

@@ -8,6 +8,7 @@ import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.po.ProductDetailInfoPo;
 import com.caimei365.commodity.model.po.ProductImagePo;
 import com.caimei365.commodity.model.po.ProductParameterPo;
+import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.PageService;
 import com.caimei365.commodity.utils.AppletsLinkUtil;
@@ -366,6 +367,82 @@ public class PageServiceImpl implements PageService {
         return ResponseJson.success(equipment);
     }
 
+    /**
+     * 商品详情页-图片
+     *
+     * @param productId 商品Id
+     */
+    @Override
+    public ResponseJson<List<String>> getProductDetailImages(Integer productId) {
+        if (productId == null) {
+            return ResponseJson.error("参数错误:商品Id不能为空!", null);
+        }
+        List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
+        List<String> newList = new ArrayList<>();
+        if (imageList.size() > 0) {
+            // 设置老图片路径
+            imageList.forEach(image -> {
+                newList.add(ImageUtils.getImageURL("product", image.getImage(), 0, domain));
+            });
+        }
+        return ResponseJson.success(newList);
+    }
+
+    /**
+     * 商品详情页-相关参数
+     *
+     * @param productId 商品Id
+     */
+    @Override
+    public ResponseJson<List<ProductParameterPo>> getProductParameters(Integer productId) {
+        if (productId == null) {
+            return ResponseJson.error("参数错误:商品Id不能为空!", null);
+        }
+        List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
+        return ResponseJson.success(parametersList);
+    }
+
+    /**
+     * 商品详情页-相关推荐
+     *
+     * @param productId     商品Id
+     * @param recommendType 相关推荐类型: 0自动选择, 1手动推荐
+     * @param userId        用户Id
+     */
+    @Override
+    public ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId) {
+        // 根据用户Id查询用户身份
+        Integer identity = 0;
+        if (null != userId) {
+            identity = priceMapper.getIdentityByUserId(userId);
+        }
+        List<ProductListVo> list = null;
+        //相关推荐类型 0自动选择; 1手动推荐
+        if (1 == recommendType) {
+            list = pageMapper.getProductRecommendsById(productId);
+        } else {
+            list = pageMapper.getAutoProductRecommends(productId);
+        }
+        //使用迭代器判断删除列表中的不满足条件的商品
+        Iterator<ProductListVo> iterator=list.iterator();
+        while (iterator.hasNext()){
+            //多线程情况下加锁
+            synchronized (list){
+                ProductListVo product = iterator.next();
+                // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
+                // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
+                boolean passFlag =identity ==1 || identity == 2 || product.getVisibility()==3 || (identity == 4 && product.getVisibility()==2);
+                if(!passFlag){
+                    iterator.remove();
+                } else {
+                    // 设置 图片路径
+                    product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
+                }
+            }
+        }
+        return ResponseJson.success(list);
+    }
+
     /**
      * 设置跳转参数
      * @param floorContent FloorContentVo

+ 6 - 1
src/main/java/com/caimei365/commodity/service/impl/ShopServiceImpl.java

@@ -215,7 +215,9 @@ public class ShopServiceImpl implements ShopService {
         String current = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
         //保存或修改商品
         ProductPo product = new ProductPo();
-        product.setProductId(productDto.getProductId());
+        if (null != product.getProductId()) {
+            product.setProductId(productDto.getProductId());
+        }
         product.setShopId(productDto.getShopId());
         product.setName(productDto.getName());
         product.setAliasName(productDto.getAliasName());
@@ -322,8 +324,11 @@ public class ShopServiceImpl implements ShopService {
         }
         //保存修改商品详情
         ProductDetailInfoPo productDetail = new ProductDetailInfoPo();
+        productDetail.setProductDetailInfoId(productDto.getProductDetailInfoId());
         productDetail.setProductId(product.getProductId());
         productDetail.setDetailInfo(productDto.getDetailInfo());
+        productDetail.setServiceInfo(productDto.getServiceInfo());
+        productDetail.setOrderInfo(productDto.getOrderInfo());
         if (null == productDetail.getProductDetailInfoId()) {
             shopMapper.insertProductDetailInfo(productDetail);
         } else {

+ 24 - 0
src/main/resources/mapper/PageMapper.xml

@@ -211,6 +211,30 @@
         where b.centreId=#{floorId} and  a.enabledStatus=1
         order  by a.sort desc,a.createDate desc
     </select>
+    <select id="getProductRecommendsById" resultType="com.caimei365.commodity.model.search.ProductListVo">
+        select
+			p.productID as productId,
+			p.`name` as `name`,
+			p.mainImage as image,
+            IFNULL(p.visibility,3) as visibility
+        from product as p
+        left join cm_product_recommend as pr on pr.recommendProductID = p.productID
+        where
+            pr.productID = #{productId} and p.validFlag  = 2
+        order by pr.sort desc
+    </select>
+    <select id="getAutoProductRecommends" resultType="com.caimei365.commodity.model.search.ProductListVo">
+        select
+			p.productID as productId,
+			p.`name` as `name`,
+			p.mainImage as image,
+            IFNULL(p.visibility,3) as visibility
+        from product as p
+        where
+			p.validFlag  = 2 and
+			p.tinyTypeID = (select tinyTypeID from product as p1 where p1.productID = #{productId})
+        order by p.sellNumber desc limit 0,7
+    </select>
 
 
 </mapper>

+ 5 - 7
src/main/resources/mapper/ShopMapper.xml

@@ -239,15 +239,13 @@
     <insert id="insertProductDetailInfo">
         insert into productdetailinfo (
           productID, propValueAlias, propValueImages,
-          detailInfo, detailInfoTxt, seoTitle,
-          seoKeyword, seoDes, serviceInfo,
-          orderInfo
+          detailInfo, serviceInfo, orderInfo, detailInfoTxt, seoTitle,
+          seoKeyword, seoDes
         ) values (
             #{productId}, #{propValueAlias}, #{propValueImages},
-            #{detailInfo}, #{detailInfoTxt}, #{seoTitle},
-            #{seoKeyword}, #{seoDes}, #{serviceInfo},
-            #{orderInfo}
-          )
+            #{detailInfo}, #{serviceInfo}, #{orderInfo}, #{detailInfoTxt}, #{seoTitle},
+            #{seoKeyword}, #{seoDes}
+        )
     </insert>
     <insert id="insertBrand">
         insert into cm_brand (name, source, userID, status, delFlag, createDate, updateDate, logo, description)