Parcourir la source

生成渠道商品价格

wang il y a 1 mois
Parent
commit
611bfb8e3a

+ 6 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/app/dto/SkuDto.java

@@ -13,11 +13,17 @@ package com.yami.shop.bean.app.dto;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.yami.shop.common.serializer.json.ImgJsonSerializer;
 import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 
 @Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
 public class SkuDto implements Serializable {
 
     private static final long serialVersionUID = 6457261945829470666L;

+ 77 - 0
yami-shop-bean/src/main/java/com/yami/shop/bean/model/ChannelProd.java

@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
+ *
+ * https://www.gz-yami.com/
+ *
+ * 未经允许,不可做商业用途!
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.yami.shop.bean.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 渠道对应商品管理
+ * @author lgh on 2024/01/01.
+ */
+@Data
+@TableName("tz_channel_prod")
+public class ChannelProd implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(type = IdType.INPUT)
+    private Long id;
+
+    /**
+     * 渠道ID
+     */
+    private Long shannerId;
+
+    /**
+     * 单品ID
+     */
+    private Long skuId;
+
+    /**
+     * 进货价
+     */
+    private BigDecimal purchasePrice;
+
+    /**
+     * 出货价
+     */
+    private BigDecimal deliveryPrice;
+
+    /**
+     * 渠道对应商品售价
+     */
+    private BigDecimal shannerProdPrice;
+
+    /**
+     * 删除状态(0-正常,1-删除)
+     */
+    private Integer isDelete;
+
+    /**
+     * 修改时间
+     */
+    private Date updateTime;
+
+    /**
+     * 记录时间
+     */
+    private Date recTime;
+}

+ 87 - 0
yami-shop-service/src/main/java/com/yami/shop/dao/ChannelProdMapper.java

@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
+ *
+ * https://www.gz-yami.com/
+ *
+ * 未经允许,不可做商业用途!
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.yami.shop.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.yami.shop.bean.model.ChannelProd;
+import com.yami.shop.common.util.PageParam;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 渠道对应商品管理Mapper接口
+ */
+public interface ChannelProdMapper extends BaseMapper<ChannelProd> {
+
+    /**
+     * 根据渠道ID获取商品列表
+     * @param shannerId 渠道ID
+     * @return 商品列表
+     */
+    List<ChannelProd> getChannelProdsByShannerId(@Param("shannerId") Long shannerId);
+
+    /**
+     * 根据SKU ID获取渠道商品列表
+     * @param skuId SKU ID
+     * @return 渠道商品列表
+     */
+    List<ChannelProd> getChannelProdsBySkuId(@Param("skuId") Long skuId);
+
+    /**
+     * 根据渠道ID和SKU ID获取渠道商品
+     * @param shannerId 渠道ID
+     * @param skuId SKU ID
+     * @return 渠道商品
+     */
+    ChannelProd getChannelProdByShannerIdAndSkuId(@Param("shannerId") Long shannerId, @Param("skuId") Long skuId);
+
+    /**
+     * 分页查询渠道商品
+     * @param page 分页参数
+     * @param channelProd 查询条件
+     * @return 分页结果
+     */
+    IPage<ChannelProd> getChannelProdPage(PageParam<ChannelProd> page, @Param("channelProd") ChannelProd channelProd);
+
+    /**
+     * 根据渠道ID删除渠道商品
+     * @param shannerId 渠道ID
+     */
+    void deleteByShannerId(@Param("shannerId") Long shannerId);
+
+    /**
+     * 根据SKU ID删除渠道商品
+     * @param skuId SKU ID
+     */
+    void deleteBySkuId(@Param("skuId") Long skuId);
+
+    /**
+     * 批量更新渠道商品价格
+     * @param channelProds 渠道商品列表
+     */
+    void updateBatchPrices(@Param("channelProds") List<ChannelProd> channelProds);
+
+    /**
+     * 根据渠道ID统计商品数量
+     * @param shannerId 渠道ID
+     * @return 商品数量
+     */
+    Integer countByShannerId(@Param("shannerId") Long shannerId);
+
+    /**
+     * 根据SKU ID统计渠道数量
+     * @param skuId SKU ID
+     * @return 渠道数量
+     */
+    Integer countBySkuId(@Param("skuId") Long skuId);
+}

+ 113 - 0
yami-shop-service/src/main/java/com/yami/shop/service/ChannelProdService.java

@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
+ *
+ * https://www.gz-yami.com/
+ *
+ * 未经允许,不可做商业用途!
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.yami.shop.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.yami.shop.bean.model.ChannelProd;
+import com.yami.shop.common.util.PageParam;
+
+import java.util.List;
+
+/**
+ * 渠道对应商品管理服务接口
+ * @author lgh on 2024/01/01.
+ */
+public interface ChannelProdService extends IService<ChannelProd> {
+
+    /**
+     * 根据渠道ID获取商品列表
+     * @param shannerId 渠道ID
+     * @return 商品列表
+     */
+    List<ChannelProd> getChannelProdsByShannerId(Long shannerId);
+
+    /**
+     * 根据SKU ID获取渠道商品列表
+     * @param skuId SKU ID
+     * @return 渠道商品列表
+     */
+    List<ChannelProd> getChannelProdsBySkuId(Long skuId);
+
+    /**
+     * 根据渠道ID和SKU ID获取渠道商品
+     * @param shannerId 渠道ID
+     * @param skuId SKU ID
+     * @return 渠道商品
+     */
+    ChannelProd getChannelProdByShannerIdAndSkuId(Long shannerId, Long skuId);
+
+    /**
+     * 分页查询渠道商品
+     * @param page 分页参数
+     * @param channelProd 查询条件
+     * @return 分页结果
+     */
+    IPage<ChannelProd> getChannelProdPage(PageParam<ChannelProd> page, ChannelProd channelProd);
+
+    /**
+     * 保存渠道商品
+     * @param channelProd 渠道商品
+     */
+    void saveChannelProd(ChannelProd channelProd);
+
+    /**
+     * 更新渠道商品
+     * @param channelProd 渠道商品
+     */
+    void updateChannelProd(ChannelProd channelProd);
+
+    /**
+     * 根据ID删除渠道商品
+     * @param id 主键ID
+     */
+    void deleteChannelProdById(Long id);
+
+    /**
+     * 根据渠道ID删除渠道商品
+     * @param shannerId 渠道ID
+     */
+    void deleteChannelProdsByShannerId(Long shannerId);
+
+    /**
+     * 根据SKU ID删除渠道商品
+     * @param skuId SKU ID
+     */
+    void deleteChannelProdsBySkuId(Long skuId);
+
+    /**
+     * 批量更新渠道商品价格
+     * @param channelProds 渠道商品列表
+     */
+    void updateBatchPrices(List<ChannelProd> channelProds);
+
+    /**
+     * 根据渠道ID统计商品数量
+     * @param shannerId 渠道ID
+     * @return 商品数量
+     */
+    Integer countByShannerId(Long shannerId);
+
+    /**
+     * 根据SKU ID统计渠道数量
+     * @param skuId SKU ID
+     * @return 渠道数量
+     */
+    Integer countBySkuId(Long skuId);
+
+    /**
+     * 检查渠道商品是否存在
+     * @param shannerId 渠道ID
+     * @param skuId SKU ID
+     * @return 是否存在
+     */
+    Boolean existsByShannerIdAndSkuId(Long shannerId, Long skuId);
+}

+ 180 - 0
yami-shop-service/src/main/java/com/yami/shop/service/impl/ChannelProdServiceImpl.java

@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
+ *
+ * https://www.gz-yami.com/
+ *
+ * 未经允许,不可做商业用途!
+ *
+ * 版权所有,侵权必究!
+ */
+
+package com.yami.shop.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.yami.shop.bean.model.ChannelProd;
+import com.yami.shop.common.exception.YamiShopBindException;
+import com.yami.shop.common.util.PageParam;
+import com.yami.shop.dao.ChannelProdMapper;
+import com.yami.shop.service.ChannelProdService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 渠道对应商品管理服务实现类
+ * @author lgh on 2024/01/01.
+ */
+@Service
+@AllArgsConstructor
+public class ChannelProdServiceImpl extends ServiceImpl<ChannelProdMapper, ChannelProd> implements ChannelProdService {
+
+    private final ChannelProdMapper channelProdMapper;
+
+    @Override
+    public List<ChannelProd> getChannelProdsByShannerId(Long shannerId) {
+        if (shannerId == null) {
+            throw new YamiShopBindException("渠道ID不能为空");
+        }
+        return channelProdMapper.getChannelProdsByShannerId(shannerId);
+    }
+
+    @Override
+    public List<ChannelProd> getChannelProdsBySkuId(Long skuId) {
+        if (skuId == null) {
+            throw new YamiShopBindException("SKU ID不能为空");
+        }
+        return channelProdMapper.getChannelProdsBySkuId(skuId);
+    }
+
+    @Override
+    public ChannelProd getChannelProdByShannerIdAndSkuId(Long shannerId, Long skuId) {
+        if (shannerId == null) {
+            throw new YamiShopBindException("渠道ID不能为空");
+        }
+        if (skuId == null) {
+            throw new YamiShopBindException("SKU ID不能为空");
+        }
+        return channelProdMapper.getChannelProdByShannerIdAndSkuId(shannerId, skuId);
+    }
+
+    @Override
+    public IPage<ChannelProd> getChannelProdPage(PageParam<ChannelProd> page, ChannelProd channelProd) {
+        return channelProdMapper.getChannelProdPage(page, channelProd);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void saveChannelProd(ChannelProd channelProd) {
+        if (channelProd == null) {
+            throw new YamiShopBindException("渠道商品信息不能为空");
+        }
+        if (channelProd.getShannerId() == null) {
+            throw new YamiShopBindException("渠道ID不能为空");
+        }
+        if (channelProd.getSkuId() == null) {
+            throw new YamiShopBindException("SKU ID不能为空");
+        }
+        if (channelProd.getPurchasePrice() == null) {
+            throw new YamiShopBindException("进货价不能为空");
+        }
+        if (channelProd.getDeliveryPrice() == null) {
+            throw new YamiShopBindException("出货价不能为空");
+        }
+        if (channelProd.getShannerProdPrice() == null) {
+            throw new YamiShopBindException("渠道商品售价不能为空");
+        }
+        
+        // 检查是否已存在
+        ChannelProd existing = getChannelProdByShannerIdAndSkuId(channelProd.getShannerId(), channelProd.getSkuId());
+        if (existing != null) {
+            throw new YamiShopBindException("该渠道下已存在此商品");
+        }
+        
+        channelProd.setIsDelete(0);
+        channelProd.setRecTime(new Date());
+        channelProd.setUpdateTime(new Date());
+        channelProdMapper.insert(channelProd);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateChannelProd(ChannelProd channelProd) {
+        if (channelProd == null) {
+            throw new YamiShopBindException("渠道商品信息不能为空");
+        }
+        if (channelProd.getId() == null) {
+            throw new YamiShopBindException("渠道商品ID不能为空");
+        }
+        
+        channelProd.setUpdateTime(new Date());
+        channelProdMapper.updateById(channelProd);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteChannelProdById(Long id) {
+        if (id == null) {
+            throw new YamiShopBindException("渠道商品ID不能为空");
+        }
+        channelProdMapper.deleteById(id);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteChannelProdsByShannerId(Long shannerId) {
+        if (shannerId == null) {
+            throw new YamiShopBindException("渠道ID不能为空");
+        }
+        channelProdMapper.deleteByShannerId(shannerId);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void deleteChannelProdsBySkuId(Long skuId) {
+        if (skuId == null) {
+            throw new YamiShopBindException("SKU ID不能为空");
+        }
+        channelProdMapper.deleteBySkuId(skuId);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateBatchPrices(List<ChannelProd> channelProds) {
+        if (channelProds == null || channelProds.isEmpty()) {
+            throw new YamiShopBindException("渠道商品列表不能为空");
+        }
+        channelProdMapper.updateBatchPrices(channelProds);
+    }
+
+    @Override
+    public Integer countByShannerId(Long shannerId) {
+        if (shannerId == null) {
+            throw new YamiShopBindException("渠道ID不能为空");
+        }
+        return channelProdMapper.countByShannerId(shannerId);
+    }
+
+    @Override
+    public Integer countBySkuId(Long skuId) {
+        if (skuId == null) {
+            throw new YamiShopBindException("SKU ID不能为空");
+        }
+        return channelProdMapper.countBySkuId(skuId);
+    }
+
+    @Override
+    public Boolean existsByShannerIdAndSkuId(Long shannerId, Long skuId) {
+        if (shannerId == null) {
+            throw new YamiShopBindException("渠道ID不能为空");
+        }
+        if (skuId == null) {
+            throw new YamiShopBindException("SKU ID不能为空");
+        }
+        ChannelProd channelProd = getChannelProdByShannerIdAndSkuId(shannerId, skuId);
+        return channelProd != null;
+    }
+}

+ 4 - 13
yami-shop-service/src/main/java/com/yami/shop/service/impl/ProductServiceImpl.java

@@ -217,19 +217,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
             }
             IPage<SearchProdDto> searchProdDtoPage = productMapper.getSearchProdDtoPageByProdNameNew(page, searchParam, shopIds);
             for (SearchProdDto searchProdDto : searchProdDtoPage.getRecords()) {
-                List<Sku> skus = skuMapper.listByProdId(searchProdDto.getProdId());
-                List<SkuDto> skuList = new ArrayList<>();
-                skus.forEach(sku -> {
-                    SkuDto skuDto = new SkuDto();
-                    skuDto.setSkuName(sku.getSkuName());
-                    skuDto.setPic(sku.getPic());
-                    skuDto.setSkuScore(sku.getSkuScore());
-                    skuDto.setPrice(sku.getPrice());
-                    skuDto.setStocks(sku.getStocks());
-                    skuDto.setProperties(sku.getProperties());
-                    skuDto.setSkuId(sku.getSkuId());
-                    skuList.add(skuDto);
-                });
+                List<SkuDto> skuList = skuMapper.listByProdId(searchProdDto.getProdId()).stream().map((sku) -> SkuDto.builder()
+                        .skuName(sku.getSkuName()).pic(sku.getPic()).skuScore(sku.getSkuScore()).price(sku.getPrice())
+                        .stocks(sku.getStocks()).properties(sku.getProperties()).skuId(sku.getSkuId())
+                        .build()).collect(Collectors.toList());
                 searchProdDto.setSkuList(skuList);
                 //计算出好评率
                 if (searchProdDto.getPraiseNumber() == 0 || searchProdDto.getProdCommNumber() == 0) {

+ 82 - 0
yami-shop-service/src/main/resources/mapper/ChannelProdMapper.xml

@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.yami.shop.dao.ChannelProdMapper">
+    <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.ChannelProd">
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="shanner_id" jdbcType="BIGINT" property="shannerId"/>
+        <result column="sku_id" jdbcType="BIGINT" property="skuId"/>
+        <result column="purchase_price" jdbcType="DECIMAL" property="purchasePrice"/>
+        <result column="delivery_price" jdbcType="DECIMAL" property="deliveryPrice"/>
+        <result column="shanner_prod_price" jdbcType="DECIMAL" property="shannerProdPrice"/>
+        <result column="is_delete" jdbcType="TINYINT" property="isDelete"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="rec_time" jdbcType="TIMESTAMP" property="recTime"/>
+    </resultMap>
+
+    <select id="getChannelProdsByShannerId" resultMap="BaseResultMap">
+        SELECT * FROM tz_channel_prod 
+        WHERE shanner_id = #{shannerId} AND is_delete = 0 
+        ORDER BY rec_time DESC
+    </select>
+
+    <select id="getChannelProdsBySkuId" resultMap="BaseResultMap">
+        SELECT * FROM tz_channel_prod 
+        WHERE sku_id = #{skuId} AND is_delete = 0 
+        ORDER BY rec_time DESC
+    </select>
+
+    <select id="getChannelProdByShannerIdAndSkuId" resultMap="BaseResultMap">
+        SELECT * FROM tz_channel_prod 
+        WHERE shanner_id = #{shannerId} AND sku_id = #{skuId} AND is_delete = 0
+    </select>
+
+    <select id="getChannelProdPage" resultMap="BaseResultMap">
+        SELECT * FROM tz_channel_prod
+        <where>
+            is_delete = 0
+            <if test="channelProd.shannerId != null">
+                AND shanner_id = #{channelProd.shannerId}
+            </if>
+            <if test="channelProd.skuId != null">
+                AND sku_id = #{channelProd.skuId}
+            </if>
+            <if test="channelProd.purchasePrice != null">
+                AND purchase_price = #{channelProd.purchasePrice}
+            </if>
+            <if test="channelProd.deliveryPrice != null">
+                AND delivery_price = #{channelProd.deliveryPrice}
+            </if>
+            <if test="channelProd.shannerProdPrice != null">
+                AND shanner_prod_price = #{channelProd.shannerProdPrice}
+            </if>
+        </where>
+        ORDER BY rec_time DESC
+    </select>
+
+    <update id="deleteByShannerId">
+        UPDATE tz_channel_prod SET is_delete = 1, update_time = NOW() WHERE shanner_id = #{shannerId}
+    </update>
+
+    <update id="deleteBySkuId">
+        UPDATE tz_channel_prod SET is_delete = 1, update_time = NOW() WHERE sku_id = #{skuId}
+    </update>
+
+    <update id="updateBatchPrices">
+        <foreach collection="channelProds" item="channelProd" separator=";">
+            UPDATE tz_channel_prod 
+            SET purchase_price = #{channelProd.purchasePrice},
+                delivery_price = #{channelProd.deliveryPrice},
+                shanner_prod_price = #{channelProd.shannerProdPrice},
+                update_time = NOW()
+            WHERE id = #{channelProd.id}
+        </foreach>
+    </update>
+
+    <select id="countByShannerId" resultType="java.lang.Integer">
+        SELECT COUNT(*) FROM tz_channel_prod WHERE shanner_id = #{shannerId} AND is_delete = 0
+    </select>
+
+    <select id="countBySkuId" resultType="java.lang.Integer">
+        SELECT COUNT(*) FROM tz_channel_prod WHERE sku_id = #{skuId} AND is_delete = 0
+    </select>
+</mapper>