Browse Source

防止商品重复入库

Guos 4 tuần trước cách đây
mục cha
commit
46eb25f62b

+ 8 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/IFsPlatformProductScrmMapper.java

@@ -26,6 +26,14 @@ public interface IFsPlatformProductScrmMapper {
      */
     List<String> getProductNoticeInfo();
 
+
+    /**
+     * 根据店铺商品id去查询商品是否存在
+     * @param
+     * @return
+     */
+   Boolean selectByStoreProductId(@Param("storeProductId") Long storeProductId);
+
     /**
      * 通过商品id获取商品详细信息
      * @param productId

+ 8 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsPlatformProductScrmServiceImpl.java

@@ -18,6 +18,7 @@ import com.fs.hisStore.service.IFsPlatformProductScrmService;
 import com.fs.hisStore.utils.StoreAuditLogUtil;
 import com.fs.hisStore.vo.FsPlatformProductListVO;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -262,6 +263,13 @@ public class FsPlatformProductScrmServiceImpl implements IFsPlatformProductScrmS
         if(copyProductInfo==null){
             return R.error("复制,商品数据不存在!");
         }
+        //这个商品是否已经在我店铺存在了
+        Long storeProductId = copyProductInfo.getStoreProductId();
+        //存在
+        FsStoreProductScrm  ObjectExist = fsStoreProductMapper.selectFsStoreProductById(storeProductId);
+        if(ObjectUtils.isNotEmpty(ObjectExist)){
+            return R.error("这个商品你店铺已经有了,无需重复添加!");
+        }
         //插入复制商品
         Long platformProductId = copyProductInfo.getProductId();
         FsStoreProductScrm fsStoreProductScrm = new FsStoreProductScrm();

+ 5 - 0
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreProductScrmServiceImpl.java

@@ -1323,6 +1323,11 @@ private void addProductAttr(Long productId, List<ProductArrtDTO> items, List<FsS
         if(auditDTO.getIsAudit() == 1){
             //复制一份到平台商品库
             for(Long storeProductId : auditDTO.getProductIds()){
+                //存在的商品不用一直添加到总库
+                Boolean flag = iFsPlatformProductScrmMapper.selectByStoreProductId(storeProductId);
+                if(flag){
+                    continue;
+                }
                 //复制商品
                 FsStoreProductScrm fsStoreProductScrm = fsStoreProductMapper.selectFsStoreProductById(storeProductId);
                 FsPlatformProductScrm fsPlatformProductScrm = new FsPlatformProductScrm();

+ 7 - 0
fs-service/src/main/resources/mapper/hisStore/FsPlatformProductScrmMapper.xml

@@ -289,6 +289,13 @@
         WHERE p.product_id IN <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">#{item}</foreach>
     </select>
 
+    <select id="selectByStoreProductId" resultType="java.lang.Boolean" >
+        SELECT
+           conut(product_id)
+        FROM
+            fs_platform_product_scrm p where p.store_product_id = #{storeProductId}
+    </select>
+
     <delete id="deleteFsPlatFormProductByIds">
         delete from fs_platform_product_scrm where product_id in
         <foreach item="productId" collection="array" open="(" separator="," close=")">