Parcourir la source

用户行为优化1.0.4

huangzhiguo il y a 1 an
Parent
commit
737ccdb883

+ 109 - 3
src/main/java/com/caimei365/user/controller/ShopApi.java

@@ -6,7 +6,6 @@ import com.caimei365.user.model.dto.BaikeProductDto;
 import com.caimei365.user.model.dto.ShopArticleDto;
 import com.caimei365.user.model.dto.ShopBannerDto;
 import com.caimei365.user.model.dto.ShopUpdateDto;
-import com.caimei365.user.model.po.BaikeProductPo;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.ShopService;
 import com.github.pagehelper.PageInfo;
@@ -15,6 +14,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.web.bind.annotation.*;
 
 import java.util.List;
@@ -124,17 +124,123 @@ public class ShopApi {
         return shopService.getShopHomeData(shopId);
     }
 
+    /**
+     * 供应商主页列表配置列表
+     * @param shopId
+     * @param category
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @ApiOperation("供应商主页列表配置列表")
+    @GetMapping("/getShopCategory")
+    public ResponseJson<PaginationVo<CmShopCategoryVo>> getShopCategory(Integer shopId, String category,
+                                                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                        @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        if (null == shopId) {
+            return ResponseJson.error(-1, "供应商Id不能为空", null);
+        }
+        return shopService.getShopCategory(shopId, category, pageNum, pageSize);
+    }
+
+    /**
+     * 一键排序
+     * @param cmShopCategoryList
+     * @return
+     */
+    @ApiOperation("一键排序")
+    @PostMapping("/renewShopCategory")
+    public ResponseJson renewShopCategory(@RequestBody List<CmShopCategoryVo> cmShopCategoryList) {
+        if (null == cmShopCategoryList) {
+            return ResponseJson.error(-1, "供应商类别信息不能为空", null);
+        }
+        return shopService.renewShopCategory(cmShopCategoryList);
+    }
+
+    /**
+     * 供应商商品类别回显
+     * @param id
+     * @return
+     */
+    @ApiOperation("供应商商品类别回显")
+    @GetMapping("/echoShopCategory")
+    public ResponseJson<Map<String, Object>> echoShopCategory(Integer id) {
+        if (null == id) {
+            return ResponseJson.error(-1, "供应商类别id不能为空", null);
+        }
+        return shopService.echoShopCategory(id);
+    }
+
+    /**
+     * 选择商品
+     * @param shopId
+     * @param naem
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @ApiOperation("选择商品")
+    @GetMapping("/getShopProductList")
+    public ResponseJson<PaginationVo<ProductItemVo>> getShopProductList(Integer shopId, String naem,
+                                                                        @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                        @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        if (null == shopId) {
+            return  ResponseJson.error(-1, "供应商Id不能为空", null);
+        }
+         return shopService.getShopProductList(shopId, naem, pageNum, pageSize);
+    }
+
+    /**
+     * 保存供应商类别
+     * @param category
+     * @return
+     */
+    @ApiOperation("保存供应商类别")
+    @PostMapping("/saveShopCategory")
+    public ResponseJson saveShopCategory(@RequestBody CmShopCategoryVo category) {
+
+        if (null == category) {
+            return ResponseJson.error(-1, "类别信息不能为空", null);
+        }
+        if (null == category.getShopId()) {
+            return ResponseJson.error(-1, "供应商Id不能为空", null);
+        }
+        if (StringUtils.isNotBlank(category.getCategory())) {
+            return ResponseJson.error(-1, "类别名称不能为空", null);
+        }
+        if (null == category.getSort()) {
+            return ResponseJson.error(-1, "类别排序不能为空", null);
+        }
+        return shopService.saveShopCategory(category);
+    }
+
+    /**
+     * 删除供应商商品类别
+     * @param id
+     * @return
+     */
+    @ApiOperation("删除供应商商品类别")
+    @GetMapping("/removeCategoryId")
+    public ResponseJson removeCategoryId(Integer id) {
+        if (null == id) {
+            return ResponseJson.error(-1, "供应商类别Id不能为空", null);
+        }
+        return shopService.deleteCategory(id);
+    }
+
     /**
      * 供应商首页-轮播图片
      * @param shopId 供应商Id
      */
     @ApiOperation("供应商首页-轮播图片(旧:/supplier/home/images(supplierId))")
     @GetMapping("/home/images")
-    public ResponseJson<List<ShopBannerVo>> getShopHomeImages(Integer shopId) {
+    public ResponseJson<PaginationVo<ShopBannerVo>> getShopHomeImages(Integer shopId,
+                                                                      @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                      @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
         if (null == shopId) {
             return ResponseJson.error("参数异常:供应商Id不能为空!", null);
         }
-        return shopService.getShopHomeImages(shopId);
+        return shopService.getShopHomeImages(shopId, pageNum, pageSize);
     }
 
     /**

+ 75 - 1
src/main/java/com/caimei365/user/mapper/ShopMapper.java

@@ -1,7 +1,6 @@
 package com.caimei365.user.mapper;
 
 import com.caimei365.user.model.dto.ShopUpdateDto;
-import com.caimei365.user.model.po.ArticlePo;
 import com.caimei365.user.model.po.ShopCertPo;
 import com.caimei365.user.model.po.UserPo;
 import com.caimei365.user.model.vo.*;
@@ -81,6 +80,81 @@ public interface ShopMapper {
      */
     String medicalPracticeLicense(Integer shopId);
 
+    /**
+     * 供应商商品类别
+     * @param shopId
+     * @param category
+     * @return
+     */
+    List<CmShopCategoryVo> getShopCategory(@Param("shopId") Integer shopId, @Param("category") String category);
+
+    /**
+     * 修改排序
+     * @param cmShopCategory
+     */
+    void updateCategorySort(CmShopCategoryVo cmShopCategory);
+
+    /**
+     * 获取供应商商品分类信息
+     * @param id
+     * @return
+     */
+    CmShopCategoryVo getShopCategoryById(@Param("id") Integer id);
+
+    /**
+     * 供应商类别商品
+     * @param categoryId
+     * @return
+     */
+    List<CmShopCategoryProductVo> getCategoryProductById(@Param("categoryId") Integer categoryId);
+
+    /**
+     * 选择商品
+     * @param shopId
+     * @param name
+     * @return
+     */
+    List<ProductItemVo> getShopProductList(@Param("shopId") Integer shopId, @Param("name") String name);
+
+    /**
+     * 添加供应商类别
+     * @param cmShopCategory
+     */
+    void insertCategory(CmShopCategoryVo cmShopCategory);
+
+    /**
+     * 添加供应商类别商品
+     * @param categoryId
+     * @param productId
+     */
+    void insertCategoryProduct(@Param("categoryId") Integer categoryId, @Param("productId") Integer productId);
+
+    /**
+     * 修改类别信息
+     * @param cmShopCategory
+     */
+    void updateCategory(CmShopCategoryVo cmShopCategory);
+
+    /**
+     * 删除类别商品
+     * @param categoryId
+     * @param productIdList
+     */
+    void updateCategoryProduct(@Param("categoryId") Integer categoryId, @Param("productIdList") List<Integer> productIdList);
+
+    /**
+     * 该列别瞎所有商品
+     * @param categoryId
+     * @return
+     */
+    List<Integer> getCategoryProductIds(@Param("categoryId") Integer categoryId);
+
+    /**
+     * 删除供应商商品类别
+     * @param id
+     */
+    void deleteCategory(@Param("id") Integer id);
+
     /**
      * 供应商首页-轮播图片
      */

+ 39 - 0
src/main/java/com/caimei365/user/model/vo/CmShopCategoryProductVo.java

@@ -0,0 +1,39 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2024/1/5
+ */
+@Data
+public class CmShopCategoryProductVo {
+
+    private Integer id;
+    /**
+     * 供应商商品分类Id
+     */
+    private Integer categoryId;
+    /**
+     * 商品Id
+     */
+    private Integer productId;
+    /**
+     * 添加时间
+     */
+    private String addTime;
+    /**
+     * 删除标记:0未删除,1已删除
+     */
+    private Integer delFlag;
+    /**
+     * 商品名称
+     */
+    private String productName;
+    /**
+     * 商品图片
+     */
+    private String mallImage;
+}

+ 42 - 0
src/main/java/com/caimei365/user/model/vo/CmShopCategoryVo.java

@@ -0,0 +1,42 @@
+package com.caimei365.user.model.vo;
+
+import lombok.Data;
+
+/**
+ * Description
+ *
+ * @author : hzg
+ * @date : 2024/1/5
+ */
+@Data
+public class CmShopCategoryVo {
+    private Integer id;
+    /**
+     * 供应商Id
+     */
+    private Integer shopId;
+    /**
+     * 类别名称
+     */
+    private String category;
+    /**
+     * 排序
+     */
+    private Integer sort;
+    /**
+     * 添加时间
+     */
+    private String addTime;
+    /**
+     * 删除标记:0未删除,1已删除
+     */
+    private Integer delFlag;
+    /**
+     * 商品数量
+     */
+    private Integer productNumber;
+    /**
+     * 商品Id集合
+     */
+    private String productIds;
+}

+ 51 - 1
src/main/java/com/caimei365/user/service/ShopService.java

@@ -81,11 +81,61 @@ public interface ShopService {
      */
     ResponseJson<ShopHomeVo> getShopHomeData(Integer shopId);
 
+    /**
+     * 供应商主页列表配置列表
+     * @param shopId
+     * @param category
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    ResponseJson<PaginationVo<CmShopCategoryVo>> getShopCategory(Integer shopId, String category, int pageNum, int pageSize);
+
+    /**
+     * 一键排序
+     * @param cmShopCategoryList
+     * @return
+     */
+    ResponseJson renewShopCategory(List<CmShopCategoryVo> cmShopCategoryList);
+
+    /**
+     * 供应商商品类别回显
+     * @param id
+     * @return
+     */
+    ResponseJson<Map<String, Object>> echoShopCategory(Integer id);
+
+    /**
+     * 选择商品
+     * @param shopId
+     * @param name
+     * @param pageNum
+     * @param paeSize
+     * @return
+     */
+    ResponseJson<PaginationVo<ProductItemVo>> getShopProductList(Integer shopId, String name, int pageNum, int pageSize);
+
+    /**
+     * 保存商品类别
+     * @param category
+     * @return
+     */
+    ResponseJson saveShopCategory(CmShopCategoryVo category);
+
+    /**
+     * 删除供应商商品类别
+     * @param id
+     * @return
+     */
+    ResponseJson deleteCategory(Integer id);
+
     /**
      * 供应商首页-轮播图片
      * @param shopId 供应商Id
+     * @param pageNum
+     * @param pageSize
      */
-    ResponseJson<List<ShopBannerVo>> getShopHomeImages(Integer shopId);
+    ResponseJson<PaginationVo<ShopBannerVo>> getShopHomeImages(Integer shopId, int pageNum, int pageSize);
 
     /**
      * 供应商个人中心数据

+ 131 - 2
src/main/java/com/caimei365/user/service/impl/ShopServiceImpl.java

@@ -329,15 +329,144 @@ public class ShopServiceImpl implements ShopService {
         return ResponseJson.success(supplier);
     }
 
+    /**
+     * 供应商主页列表配置列表
+     *
+     * @param shopId
+     * @param category
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public ResponseJson<PaginationVo<CmShopCategoryVo>> getShopCategory(Integer shopId, String category, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<CmShopCategoryVo> shopCategory = shopMapper.getShopCategory(shopId, category);
+        PaginationVo<CmShopCategoryVo> page = new PaginationVo<>(shopCategory);
+        return ResponseJson.success(page);
+    }
+
+    /**
+     * 一键排序
+     *
+     * @param cmShopCategoryList
+     * @return
+     */
+    @Override
+    public ResponseJson renewShopCategory(List<CmShopCategoryVo> cmShopCategoryList) {
+        cmShopCategoryList.forEach(category -> {
+            shopMapper.updateCategorySort(category);
+        });
+        return ResponseJson.success();
+    }
+
+    /**
+     * 供应商商品类别回显
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public ResponseJson<Map<String, Object>> echoShopCategory(Integer id) {
+        Map<String, Object> map = new HashMap<>();
+        CmShopCategoryVo shopCategoryById = shopMapper.getShopCategoryById(id);
+        map.put("category", shopCategoryById);
+        List<CmShopCategoryProductVo> categoryProductList = shopMapper.getCategoryProductById(id);
+        categoryProductList.forEach(product -> {
+            product.setMallImage(ImageUtils.getImageURL("product", product.getMallImage(), 0 , wwwDomain));
+        });
+        map.put("categorProduct", categoryProductList);
+        return ResponseJson.success(map);
+    }
+
+    /**
+     * 选择商品
+     *
+     * @param shopId
+     * @param name
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @Override
+    public ResponseJson<PaginationVo<ProductItemVo>> getShopProductList(Integer shopId, String name, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
+        List<ProductItemVo> shopProductList = shopMapper.getShopProductList(shopId, name);
+        shopProductList.forEach(product -> {
+            product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0 , wwwDomain));
+        });
+        PaginationVo<ProductItemVo> page = new PaginationVo<>(shopProductList);
+        return ResponseJson.success(page);
+    }
+
+    /**
+     * 保存商品类别
+     *
+     * @param category
+     * @return
+     */
+    @Override
+    public ResponseJson saveShopCategory(CmShopCategoryVo category) {
+        if(null == category.getId()) {
+            // 新增
+            shopMapper.insertCategory(category);
+        } else {
+            // 修改
+            shopMapper.updateCategory(category);
+        }
+        Integer categoryId = category.getId();
+        if (StringUtils.isNotBlank(category.getProductIds())) {
+            // 处理类别商品
+            List<Integer> productIdList = new ArrayList<>();
+            // 该类别下所有商品
+            List<Integer> categoryProductIds = shopMapper.getCategoryProductIds(categoryId);
+            if (category.getProductIds().contains(",")) {
+                String[] productIds = category.getProductIds().split(",");
+                for (String productId : productIds) {
+                    int proId = Integer.parseInt(productId);
+                    productIdList.add(proId);
+                    if (!categoryProductIds.contains(proId)) {
+                        shopMapper.insertCategoryProduct(categoryId, proId);
+                    }
+                }
+            } else {
+                int proId = Integer.parseInt(category.getProductIds());
+                productIdList.add(proId);
+                if (!categoryProductIds.contains(proId)) {
+                    shopMapper.insertCategoryProduct(categoryId, proId);
+                }
+            }
+            // 排除不在该商品类别的商品
+            if(productIdList.size() > 0) {
+                shopMapper.updateCategoryProduct(categoryId, productIdList);
+            }
+        }
+        return ResponseJson.success();
+    }
+
+    /**
+     * 删除供应商商品类别
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public ResponseJson deleteCategory(Integer id) {
+        shopMapper.deleteCategory(id);
+        return ResponseJson.success();
+    }
+
     /**
      * 供应商首页-轮播图片
      *
      * @param shopId 供应商Id
      */
     @Override
-    public ResponseJson<List<ShopBannerVo>> getShopHomeImages(Integer shopId) {
+    public ResponseJson<PaginationVo<ShopBannerVo>> getShopHomeImages(Integer shopId, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum, pageSize);
         List<ShopBannerVo> images = shopMapper.getShopHomeImages(shopId);
-        return ResponseJson.success(images);
+        PaginationVo<ShopBannerVo> page = new PaginationVo<>(images);
+        return ResponseJson.success(page);
     }
 
     /**

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

@@ -153,6 +153,114 @@
     <select id="medicalPracticeLicense" resultType="java.lang.String">
         SELECT medicalPracticeLicenseImg1 FROM shop WHERE shopID = #{shopId}
     </select>
+
+    <select id="getShopCategory" resultType="com.caimei365.user.model.vo.CmShopCategoryVo">
+        SELECT
+            csc.id,
+            csc.shopId,
+            csc.category,
+            csc.sort,
+            csc.addTime,
+            csc.delFlag,
+            (SELECT COUNT(id) FROM cm_shop_category_product WHERE categoryId = csc.id)
+        FROM cm_shop_category csc
+        WHERE csc.delFlag = 0 AND csc.shopId = #{shopId}
+        <if test="category != null and category != ''">
+            and csc.category like concat('%', #{category}, '%')
+        </if>
+        order by csc.sort asc
+    </select>
+
+    <update id="updateCategorySort">
+        update cm_shop_category
+        set sort = #{sort}
+        where id = #{id}
+    </update>
+
+    <select id="getShopCategoryById" resultType="com.caimei365.user.model.vo.CmShopCategoryVo">
+        SELECT
+            id,
+            shopId,
+            category,
+            sort,
+            addTime,
+            delFlag
+        FROM cm_shop_category
+        WHERE delFlag = 0 AND id = #{id}
+        limit 1
+    </select>
+
+    <select id="getCategoryProductById" resultType="com.caimei365.user.model.vo.CmShopCategoryProductVo">
+        SELECT
+            cscp.id,
+            cscp.categoryId,
+            cscp.productId,
+            cscp.addTime,
+            p.name AS productName,
+            p.mainImage
+        FROM cm_shop_category_product cscp
+                 LEFT JOIN product p ON p.productId = cscp.productId
+        WHERE cscp.delFlag = 0 AND cscp.categoryId = #{categoryId}
+    </select>
+
+    <select id="getShopProductList" resultType="com.caimei365.user.model.vo.ProductItemVo">
+        SELECT
+        p.productId,
+        p.name,
+        p.mainImage as image,
+        s.shopId,
+        s.name AS shopName
+        FROM product p
+        LEFT JOIN cm_organize_product_info copi ON copi.productId = p.productId
+        LEFT JOIN shop s ON s.shopId = p.shopId
+        <where>
+            copi.organizeId = 0 AND copi.validFlag = 2
+            and p.shopId = #{shopId}
+            <if test="name != null and name != ''">
+                and p.name like concat('%', #{name}, '%')
+            </if>
+        </where>
+    </select>
+
+    <insert id="insertCategory" keyColumn="id" useGeneratedKeys="true">
+        insert into cm_shop_category(shopId, category, sort, addTime, delFlag)
+        values (#{shopId}, #{category}, #{sort}, now(), 0)
+    </insert>
+
+    <insert id="insertCategoryProduct" keyColumn="id" useGeneratedKeys="true">
+        insert into cm_shop_category_product(categoryId, productId, addTime, delFlag)
+        values (#{categoryId}, #{productId}, now(), 0)
+    </insert>
+
+    <update id="updateCategory">
+        update cm_shop_category
+        set category = #{category},
+            sort = #{sort}
+        where id = #{id}
+    </update>
+
+    <update id="updateCategoryProduct">
+        update cm_shop_category_product
+        set delFlag = 1
+        where categoryId = #{categoryId}
+        <if test="productIdList.size()>0">
+            and productId not in
+            <foreach collection="productIdList" item="productId" open="(" separator="," close=")">
+                #{productId}
+            </foreach>
+        </if>
+    </update>
+
+    <select id="getCategoryProductIds" resultType="java.lang.Integer">
+        select productId from cm_shop_category_product where categoryId = #{categoryId}
+    </select>
+
+    <update id="deleteCategory">
+        update cm_shop_category
+        set delFlag = 1
+        where id = #{id}
+    </update>
+
     <select id="getShopHomeImages" resultType="com.caimei365.user.model.vo.ShopBannerVo">
         select shopBannerID AS id, shopID AS shopId, image, link, title, info
         from shopbanner where shopID = #{shopId}