Browse Source

拆分商品表里的大容量字段到另一表里存储

FengChaoYu 2 weeks ago
parent
commit
237daed2ba

+ 9 - 0
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/bean/goods/GoodsBean.java

@@ -17,6 +17,15 @@ import java.util.List;
 @Data
 public class GoodsBean extends Goods {
 
+    @ApiModelProperty(value = "商品详情")
+    private String content;
+
+    @ApiModelProperty(value = "主图")
+    private String imgUrl;
+
+    @ApiModelProperty(value = "视频")
+    private String vedio;
+
     @ApiModelProperty("商品库存")
     private Integer stock;
 

+ 9 - 1
mall-miniapp-service/src/main/java/com/gree/mall/miniapp/logic/goods/GoodsLogic.java

@@ -60,6 +60,8 @@ public class GoodsLogic {
     GoodsTagRelaService goodsTagRelaService;
     @Resource
     GoodsMaterialStorageService goodsMaterialStorageService;
+    @Resource
+    GoodsDetailService goodsDetailService;
 
     /**
      * 商品列表
@@ -175,6 +177,8 @@ public class GoodsLogic {
         if (goods == null) {
             throw new RemoteServiceException("商品不存在或已下架");
         }
+        final GoodsDetail goodsDetail = goodsDetailService.getById(goodsId);
+
         //商品规格
         List<GoodsSpecSecBean> goodsSpecs = goodsSpecDetailMapper.querySpecSec(goodsId);
         final List<String> goodsMaterialIds = goodsSpecs.stream().map(GoodsSpecSecBean::getGoodsCode).collect(Collectors.toList());
@@ -206,7 +210,11 @@ public class GoodsLogic {
         GoodsBean goodsBean = new GoodsBean();
         BeanUtils.copyProperties(goods, goodsBean);
 
-
+        if (Objects.nonNull(goodsDetail)) {
+            goodsBean.setContent(goodsDetail.getContent());
+            goodsBean.setImgUrl(goodsDetail.getImgUrl());
+            goodsBean.setVedio(goodsDetail.getVedio());
+        }
         goodsBean.setGoodsSpecs(goodsSpecs);
         goodsBean.setImages(commonLogic.queryFileByObjId(goods.getGoodsId(), Constant.Img.GOODS_IMG));
         goodsBean.setFavorite(goodsFavoritesCount > 0);

+ 9 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsBean.java

@@ -13,6 +13,15 @@ import java.util.List;
 @Data
 public class GoodsBean extends Goods {
 
+    @ApiModelProperty(value = "商品详情")
+    private String content;
+
+    @ApiModelProperty(value = "主图")
+    private String imgUrl;
+
+    @ApiModelProperty(value = "视频")
+    private String vedio;
+
     @ApiModelProperty("商品规格")
     private List<GoodsSpec> goodsSpecs;
 

+ 9 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/goods/GoodsSpecBean.java

@@ -14,6 +14,15 @@ import java.util.List;
 @Data
 public class GoodsSpecBean extends Goods {
 
+    @ApiModelProperty(value = "商品详情")
+    private String content;
+
+    @ApiModelProperty(value = "主图")
+    private String imgUrl;
+
+    @ApiModelProperty(value = "视频")
+    private String vedio;
+
     @ApiModelProperty(value = "商品规格id")
     private String goodsSpecId;
 

+ 0 - 1
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CustomGoodsMapper.java

@@ -39,7 +39,6 @@ public interface CustomGoodsMapper {
                                   @Param("sortStr") String sortStr,
                                   @Param("categoryId") List<String> categoryId,
                                   @Param("status") Boolean status,
-                                  @Param("goodsTypes") List<String> goodsTypes,
                                   @Param("companyWechatIds")List<String> companyWechatIds);
 
     @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")

+ 1 - 3
mall-server-api/src/main/java/com/gree/mall/manager/controller/goods/GoodsController.java

@@ -52,14 +52,12 @@ public class GoodsController {
             @RequestParam(required = false) String sortJson,
             @ApiParam(value = "商品分类 传入商品小类") @RequestParam(required = false) String categoryId,
             @ApiParam(value = "商品状态 true:上架  false:下架") @RequestParam(required = false) Boolean status,
-            @ApiParam(value = "商品类型:COMMON=普通商品 PACKAGE=套购商品,不传默认为普通商品,支持传多个",required = false)
-            @RequestParam(required = false) List<String> goodsTypes,
             @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
             @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize,
             HttpServletRequest request
     ) throws Exception {
         IPage<GoodsSpecBean> goodsSpecBeanIPage = goodsLogic.page(flag, keyword, startPrice, endPrice,
-                sortJson, categoryId, status,goodsTypes, pageNum, pageSize , request);
+                sortJson, categoryId, status, pageNum, pageSize , request);
         return ResponseHelper.success(goodsSpecBeanIPage);
     }
 

+ 48 - 33
mall-server-api/src/main/java/com/gree/mall/manager/logic/goods/GoodsLogic.java

@@ -1,6 +1,8 @@
 package com.gree.mall.manager.logic.goods;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -19,6 +21,7 @@ import com.gree.mall.manager.logic.user.UserLogic;
 import com.gree.mall.manager.plus.entity.*;
 import com.gree.mall.manager.plus.service.*;
 import com.gree.mall.manager.utils.DateUtils;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -32,34 +35,27 @@ import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.text.ParseException;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Slf4j
 @Component
+@RequiredArgsConstructor
 public class GoodsLogic {
-    @Resource
-    CommonLogic commonLogic;
-
-    @Resource
-    CustomGoodsMapper customGoodsMapper;
-    @Resource
-    GoodsService goodsService;
-    @Resource
-    GoodsSpecService goodsSpecService;
-    @Autowired
-    GoodsTagRelaService goodsTagRelaService;
-    @Autowired
-    private CarouselMapService carouselMapService;
-    @Autowired
-    private GoodsTemplateService goodsTemplateService;
-    @Autowired
-    private CommonFileService commonFileService;
-    @Autowired
-    GoodsMaterialService goodsMaterialService;
-    @Autowired
-    UserLogic userLogic;
-    @Autowired
-    GoodsMaterialStorageService goodsMaterialStorageService;
+
+    private final CommonLogic commonLogic;
+    private final CustomGoodsMapper customGoodsMapper;
+    private final GoodsService goodsService;
+    private final GoodsDetailService goodsDetailService;
+    private final GoodsSpecService goodsSpecService;
+    private final GoodsCategoryService goodsCategoryService;
+    private final GoodsTagRelaService goodsTagRelaService;
+    private final CarouselMapService carouselMapService;
+    private final GoodsTemplateService goodsTemplateService;
+    private final CommonFileService commonFileService;
+    private final GoodsMaterialService goodsMaterialService;
+    private final UserLogic userLogic;
+    private final GoodsMaterialStorageService goodsMaterialStorageService;
 
     /**
      * 商品列表
@@ -76,9 +72,9 @@ public class GoodsLogic {
      * @return
      */
     public IPage<GoodsSpecBean> page(String flag, String keyword, BigDecimal startPrice, BigDecimal endPrice,
-                                     String goodsSortJson, String categoryId, Boolean status, List<String> goodsTypes,
+                                     String goodsSortJson, String categoryId, Boolean status,
                                      Integer pageNum, Integer pageSize, HttpServletRequest request) {
-
+        System.out.println("开始" + DateUtil.formatDateTime(DateUtil.date()));
         //获取当前登录微信企业微信id
         AdminUserCom adminUser = commonLogic.getAdminUser(request);
         List<String> companyWechatIds = adminUser.getCompanyWechatIds();
@@ -92,14 +88,10 @@ public class GoodsLogic {
         if (StringUtils.isNotBlank(categoryId)) {
             categoryIds.add(categoryId);
         }
-        if (CollectionUtils.isEmpty(goodsTypes)) {
-            goodsTypes = new ArrayList<>();
-            goodsTypes.add(GoodsTypeEnum.COMMON.toString());
-        }
 
-        IPage<GoodsSpecBean> goodsSpecBeanIPage = customGoodsMapper.pageList(new Page<>(pageNum, pageSize), flag, keyword, startPrice,
-                endPrice, sortStr, categoryIds, status, goodsTypes, companyWechatIds);
 
+        IPage<GoodsSpecBean> goodsSpecBeanIPage = customGoodsMapper.pageList(new Page<>(pageNum, pageSize), flag, keyword, startPrice,
+                endPrice, sortStr, categoryIds, status, companyWechatIds);
         //商品规格
         List<GoodsSpecBean> records = new ArrayList<>();
         for (GoodsSpecBean goodsSpecBean : goodsSpecBeanIPage.getRecords()) {
@@ -143,7 +135,7 @@ public class GoodsLogic {
 
 
         IPage<GoodsSpecBean> goodsSpecBeanIPage = customGoodsMapper.pageList(new Page<>(1, -1), null, null, null, null,
-                null,  categoryIds, null, null, companyWechatIds);
+                null,  categoryIds, null, companyWechatIds);
         //添加规格
         List<GoodsSpecBean> records = goodsSpecBeanIPage.getRecords();
         for (GoodsSpecBean record : records) {
@@ -217,12 +209,12 @@ public class GoodsLogic {
      */
     public GoodsSpecBean detail(String goodsId) throws RemoteServiceException {
         Goods goods = goodsService.getById(goodsId);
+        final GoodsDetail goodsDetail = goodsDetailService.getById(goodsId);
         List<GoodsSpec> goodsSpecs = goodsSpecService.lambdaQuery()
                 .eq(GoodsSpec::getGoodsId, goodsId)
                 .eq(GoodsSpec::getDel, false)
                 .list();
 
-
         //商品库存
         Integer goodsStock = goodsSpecs.stream().collect(Collectors.summingInt(x -> x.getStockNum()));
 
@@ -232,6 +224,11 @@ public class GoodsLogic {
         }
         BeanUtils.copyProperties(goods, goodsBean);
 
+        if (Objects.nonNull(goodsDetail)) {
+            goodsBean.setContent(goodsDetail.getContent());
+            goodsBean.setImgUrl(goodsDetail.getImgUrl());
+            goodsBean.setVedio(goodsDetail.getVedio());
+        }
 
         List<GoodsSpecVO> goodsSpecVOS = BeanUtil.copyToList(goodsSpecs, GoodsSpecVO.class);
         for (GoodsSpecVO goodsSpecVO : goodsSpecVOS) {
@@ -331,6 +328,13 @@ public class GoodsLogic {
 
         goodsService.save(goodsBean);
 
+        GoodsDetail goodsDetail = new GoodsDetail();
+        goodsDetail.setGoodsId(goodsBean.getGoodsId())
+                .setContent(goodsBean.getContent())
+                .setImgUrl(goodsBean.getImgUrl())
+                .setVedio(goodsBean.getVedio())
+                .insert();
+
         if (StringUtils.isNotBlank(goodsBean.getTemplateId())) {
             GoodsTemplate goodsTemplate = new GoodsTemplate();
             goodsTemplate.setGoodsId(goodsBean.getGoodsId());
@@ -427,6 +431,17 @@ public class GoodsLogic {
         }
         goodsService.updateById(goodsBean);
 
+        GoodsDetail goodsDetail = goodsDetailService.getById(goodsBean.getGoodsId());
+        if (Objects.isNull(goodsDetail)) {
+            goodsDetail = new GoodsDetail();
+        }
+        goodsDetail.setGoodsId(goodsBean.getGoodsId())
+                .setContent(goodsBean.getContent())
+                .setImgUrl(goodsBean.getImgUrl())
+                .setVedio(goodsBean.getVedio())
+                .insertOrUpdate();
+
+
         //未删除的规格id
         List<String> goodsSpecIds = notRemoveList.stream().map(GoodsSpec::getGoodsSpecId).collect(Collectors.toList());
 

+ 23 - 31
mall-server-api/src/main/resources/mapper/CustomGoodsMapper.xml

@@ -4,29 +4,29 @@
 
     <select id="pageList" resultType="com.gree.mall.manager.bean.goods.GoodsSpecBean">
         SELECT
-        t1.*,
-        t1.goods_name AS goodsName,
-        <!--sum(if(t2.del=0 and t2.sold_num is NOT NULL,t2.sold_num,0)) AS soldNum,-->
-        sum(if(t2.del=0 and t2.stock_num is NOT NULL,t2.stock_num,0)) AS stockNum,
-        t3.`name` AS categoryName
+            t1.*,
+            t4.content,
+            t4.img_url,
+            t4.vedio,
+            t3.name AS categoryName
         FROM
-        goods t1
-        left join goods_spec t2 on t1.goods_id = t2.goods_id         and t2.del = 0
-        left join goods_category t3 on t3.category_id = t1.category_id
-        WHERE
-        t1.del = 0
+            goods t1
+            LEFT JOIN goods_detail t4 ON t1.goods_id = t4.goods_id
+            LEFT JOIN goods_category t3 ON t1.category_id = t3.category_id
+        WHERE t1.del = 0
+        AND EXISTS (
+            SELECT 1 FROM goods_spec t2 WHERE t2.goods_id = t1.goods_id AND t2.del = 0
+            <if test="startPrice != null and endPrice != null">
+                AND
+                t2.price BETWEEN #{startPrice} AND #{endPrice}
+            </if>
+        )
         <if test='companyWechatIds != null and companyWechatIds.size > 0' >
-            AND t1.company_wechat_id  in
+            AND t1.company_wechat_id IN
             <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
                 #{companyWechatId}
             </foreach>
         </if>
-        <if test='goodsTypes != null and goodsTypes.size > 0' >
-            AND t1.goods_type  in
-            <foreach collection="goodsTypes" open="(" close=")" item="item" separator=",">
-                #{item}
-            </foreach>
-        </if>
         <if test="flag != null">
             <choose>
                 <when test="flag == 'S'.toString()">AND t1.status = 1</when>
@@ -36,18 +36,13 @@
         </if>
         <if test="keyword != null and keyword != ''">
             AND
-            (t1.goods_id like CONCAT('%', #{keyword},'%') OR t1.goods_name like CONCAT('%',#{keyword},'%') OR t3.`name`
-            like CONCAT('%',#{keyword},'%') OR CONCAT(t1.goods_name, '(', t2.`name`,')') like
-            CONCAT('%',#{keyword},'%'))
-        </if>
-        <if test="startPrice != null and endPrice != null">
-            AND
-            t2.price BETWEEN #{startPrice} AND #{endPrice}
+            (t1.goods_id LIKE CONCAT('%', #{keyword},'%') OR t1.goods_name LIKE CONCAT('%',#{keyword},'%') OR t3.`name`
+            LIKE CONCAT('%',#{keyword},'%'))
         </if>
 
         <if test="categoryId != null and categoryId.size() != 0">
             AND
-            t3.category_id in
+            t3.category_id IN
             <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
                 #{item}
             </foreach>
@@ -56,16 +51,13 @@
             AND
             t1.status = #{status}
         </if>
-        group by t1.goods_id
-        <if test="flag == 'O'.toString()">
-            having sum(t2.stock_num) = 0
-        </if>
+        GROUP BY t1.goods_id
         <choose>
             <when test="sortStr == null">
-                ORDER BY t1.sort_num desc,t1.create_time desc
+                ORDER BY t1.sort_num DESC,t1.create_time DESC
             </when>
             <otherwise>
-                ORDER BY t1.sort_num desc,${sortStr},t1.create_time desc
+                ORDER BY t1.sort_num DESC, ${sortStr}, t1.create_time DESC
             </otherwise>
         </choose>
     </select>