Browse Source

完善删除逻辑

zhangwl 3 weeks ago
parent
commit
1cb65c70e7

+ 10 - 0
src/main/java/zs/payment/controller/EweiShopGoodsController.java

@@ -40,6 +40,16 @@ public class EweiShopGoodsController {
     }
     }
 
 
     /**
     /**
+     * 一键退还
+     * @return
+     */
+    @GetMapping("/deleteAll")
+    public Result deleteAll() {
+        commodityProcureService.deleteAll();
+        return Result.success();
+    }
+
+    /**
      * 供货/停止供货:把本地商品推送到云商城,或停止供货
      * 供货/停止供货:把本地商品推送到云商城,或停止供货
      * issupply=1: 供货  issupply=0: 停止供货
      * issupply=1: 供货  issupply=0: 停止供货
      * 加入Redis分布式锁防止用户多次点击重复提交
      * 加入Redis分布式锁防止用户多次点击重复提交

+ 8 - 8
src/main/java/zs/payment/messages/KafkaConsumer.java

@@ -73,7 +73,7 @@ public class KafkaConsumer {
      * @param messsage
      * @param messsage
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "goods.undercarriage",
+        topics = "goods.undercarriage1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void goodsUndercarriage(String messsage) {
     public void goodsUndercarriage(String messsage) {
@@ -97,7 +97,7 @@ public class KafkaConsumer {
      * @param messsage
      * @param messsage
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "goods.on.sale",
+        topics = "goods.on.sale1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void goodsOnSale(String messsage) {
     public void goodsOnSale(String messsage) {
@@ -121,7 +121,7 @@ public class KafkaConsumer {
      * @param messsage
      * @param messsage
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "goods.delete",
+        topics = "goods.delete1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void goodsDelete(String messsage) {
     public void goodsDelete(String messsage) {
@@ -149,7 +149,7 @@ public class KafkaConsumer {
      * @param messsage
      * @param messsage
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "goods.sync",
+        topics = "goods.sync1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     @Transactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
@@ -375,7 +375,7 @@ public class KafkaConsumer {
      * @param orderSn
      * @param orderSn
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "order.delivery",
+        topics = "order.delivery1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void goodsDelivery(String orderSn) {
     public void goodsDelivery(String orderSn) {
@@ -392,7 +392,7 @@ public class KafkaConsumer {
      * 消息格式:{"uniacid":1, "gdId":123456, "mallid":100, "cates":[1,2,3]}
      * 消息格式:{"uniacid":1, "gdId":123456, "mallid":100, "cates":[1,2,3]}
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "commodity.procure",
+        topics = "commodity.procure1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void commodityProcure(String message) {
     public void commodityProcure(String message) {
@@ -420,7 +420,7 @@ public class KafkaConsumer {
      * 消息格式:{"uniacid":1, "goodsId":12345, "issupply":1, "cate":10, "storeid":789}
      * 消息格式:{"uniacid":1, "goodsId":12345, "issupply":1, "cate":10, "storeid":789}
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "commodity.fulloutput",
+        topics = "commodity.fulloutput1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void fullOutputProcess(String message) {
     public void fullOutputProcess(String message) {
@@ -455,7 +455,7 @@ public class KafkaConsumer {
      * 消息格式:{"total":100000, "pageSize":50}
      * 消息格式:{"total":100000, "pageSize":50}
      */
      */
     @KafkaListener(
     @KafkaListener(
-        topics = "sync.qiyun.remain",
+        topics = "sync.qiyun.remain1",
         groupId = "pay2-group"
         groupId = "pay2-group"
     )
     )
     public void syncQiyunRemain(String message) {
     public void syncQiyunRemain(String message) {

+ 52 - 3
src/main/java/zs/payment/service/Imseweishopgoods/impl/ImsEweiShopGoodsServiceImpl.java

@@ -2,17 +2,33 @@ package zs.payment.service.Imseweishopgoods.impl;
 
 
 
 
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import zs.payment.entity.mysql.ImsEweiShopGoods;
 import zs.payment.entity.mysql.ImsEweiShopGoods;
+import zs.payment.entity.mysql.ImsEweiShopGoodsOption;
+import zs.payment.entity.mysql.ImsEweiShopGoodsParam;
+import zs.payment.entity.mysql.ImsEweiShopGoodsSpec;
 import zs.payment.mapper.primary.ImsEweiShopGoodsMapper;
 import zs.payment.mapper.primary.ImsEweiShopGoodsMapper;
 import zs.payment.service.Imseweishopgoods.ImsEweiShopGoodsService;
 import zs.payment.service.Imseweishopgoods.ImsEweiShopGoodsService;
+import zs.payment.service.imseweishopgoodsoption.ImsEweiShopGoodsOptionService;
+import zs.payment.service.imseweishopgoodsparam.ImsEweiShopGoodsParamService;
+import zs.payment.service.imseweishopgoodsspec.ImsEweiShopGoodsSpecService;
+
+import java.util.Optional;
 
 
 @Service
 @Service
 @Slf4j
 @Slf4j
 public class ImsEweiShopGoodsServiceImpl  extends ServiceImpl<ImsEweiShopGoodsMapper, ImsEweiShopGoods> implements ImsEweiShopGoodsService {
 public class ImsEweiShopGoodsServiceImpl  extends ServiceImpl<ImsEweiShopGoodsMapper, ImsEweiShopGoods> implements ImsEweiShopGoodsService {
-
+    @Autowired
+    private ImsEweiShopGoodsSpecService specService;
+    @Autowired
+    private ImsEweiShopGoodsOptionService optionService;
+    @Autowired
+    private ImsEweiShopGoodsParamService paramService;
 
 
     @Override
     @Override
     public ImsEweiShopGoods getBySupplyId(String supplyId,String supplySource) {
     public ImsEweiShopGoods getBySupplyId(String supplyId,String supplySource) {
@@ -32,9 +48,42 @@ public class ImsEweiShopGoodsServiceImpl  extends ServiceImpl<ImsEweiShopGoodsMa
 
 
     @Override
     @Override
     public Boolean deleteBySupplyId(String supplyId, String supplySource) {
     public Boolean deleteBySupplyId(String supplyId, String supplySource) {
-        return lambdaUpdate().set(ImsEweiShopGoods::getDeleted, 1)
+
+        ImsEweiShopGoods one = lambdaQuery().eq(ImsEweiShopGoods::getUniacid, 463)
+            .eq(ImsEweiShopGoods::getDeleted, 0)
             .eq(ImsEweiShopGoods::getSupplySource, supplySource)
             .eq(ImsEweiShopGoods::getSupplySource, supplySource)
-            .eq(ImsEweiShopGoods::getSupplyId, supplyId).update();
+            .eq(ImsEweiShopGoods::getSupplyId, supplyId).one();
+        if (Optional.ofNullable(one).isPresent()){
+            Long goodsId = one.getId();
+
+            // 3. 检查是否存在订单记录(查询 ims_ewei_shop_order_goods 表)
+            boolean hasOrder = baseMapper.existsOrderByGoodsId(goodsId);
+
+            if (!hasOrder) {
+                // 4a. 无订单记录:物理删除商品及关联数据
+                removeById(goodsId);
+                specService.remove(new LambdaQueryWrapper<ImsEweiShopGoodsSpec>()
+                    .eq(ImsEweiShopGoodsSpec::getGoodsid, goodsId));
+                optionService.remove(new LambdaQueryWrapper<ImsEweiShopGoodsOption>()
+                    .eq(ImsEweiShopGoodsOption::getGoodsid, goodsId));
+                paramService.remove(new LambdaQueryWrapper<ImsEweiShopGoodsParam>()
+                    .eq(ImsEweiShopGoodsParam::getGoodsid, goodsId));
+                log.info("物理删除其他进货商品及关联数据 goodsId={}", goodsId);
+            } else {
+                // 4b. 有订单记录:软删除
+                LambdaUpdateWrapper<ImsEweiShopGoods> updateWrapper = new LambdaUpdateWrapper<>();
+                updateWrapper.eq(ImsEweiShopGoods::getId, goodsId)
+                    .set(ImsEweiShopGoods::getIssupplyRecommend,0)
+                    .set(ImsEweiShopGoods::getDeleted, 1)
+                    .set(ImsEweiShopGoods::getStatus, 0);
+                update(updateWrapper);
+                log.info("软删除其他进货商品 goodsId={}", goodsId);
+            }
+
+        }
+
+
+        return true;
     }
     }
 
 
     @Override
     @Override

+ 2 - 0
src/main/java/zs/payment/service/commodity/CommodityProcureService.java

@@ -34,4 +34,6 @@ public interface CommodityProcureService {
      * 单条供货/停止供货处理(Kafka异步消费调用)
      * 单条供货/停止供货处理(Kafka异步消费调用)
      */
      */
     Result processSupplyItem(Long goodsId, Integer issupply, Integer cate, Integer uniacid, Integer storeid);
     Result processSupplyItem(Long goodsId, Integer issupply, Integer cate, Integer uniacid, Integer storeid);
+
+    void deleteAll();
 }
 }

+ 40 - 0
src/main/java/zs/payment/service/commodity/impl/CommodityProcureServiceImpl.java

@@ -1415,4 +1415,44 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
         try { return Integer.valueOf(val.toString()); } catch (Exception e) { return 0; }
         try { return Integer.valueOf(val.toString()); } catch (Exception e) { return 0; }
     }
     }
 
 
+
+    @Override
+    public void deleteAll() {
+
+        LambdaQueryWrapper<ImsEweiShopGoods> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.isNull(ImsEweiShopGoods::getGdId)
+            .eq(ImsEweiShopGoods::getUniacid, 470)
+            .eq(ImsEweiShopGoods::getDeleted, 0);
+//        queryWrapper.last("limit 1");
+        List<ImsEweiShopGoods> otherGoods = goodsService.list(queryWrapper);
+
+        for (ImsEweiShopGoods otherGood : otherGoods) {
+            Long goodsId = otherGood.getId();
+
+            // 3. 检查是否存在订单记录(查询 ims_ewei_shop_order_goods 表)
+            boolean hasOrder = goodsMapper.existsOrderByGoodsId(goodsId);
+
+            if (!hasOrder) {
+                // 4a. 无订单记录:物理删除商品及关联数据
+                goodsService.removeById(goodsId);
+                specService.remove(new LambdaQueryWrapper<ImsEweiShopGoodsSpec>()
+                    .eq(ImsEweiShopGoodsSpec::getGoodsid, goodsId));
+                optionService.remove(new LambdaQueryWrapper<ImsEweiShopGoodsOption>()
+                    .eq(ImsEweiShopGoodsOption::getGoodsid, goodsId));
+                paramService.remove(new LambdaQueryWrapper<ImsEweiShopGoodsParam>()
+                    .eq(ImsEweiShopGoodsParam::getGoodsid, goodsId));
+                log.info("物理删除其他进货商品及关联数据 goodsId={}", goodsId);
+            } else {
+                // 4b. 有订单记录:软删除
+                LambdaUpdateWrapper<ImsEweiShopGoods> updateWrapper = new LambdaUpdateWrapper<>();
+                updateWrapper.eq(ImsEweiShopGoods::getId, goodsId)
+                    .set(ImsEweiShopGoods::getIssupplyRecommend,0)
+                    .set(ImsEweiShopGoods::getDeleted, 1)
+                    .set(ImsEweiShopGoods::getStatus, 0);
+                goodsService.update(updateWrapper);
+                log.info("软删除其他进货商品 goodsId={}", goodsId);
+            }
+
+        }
+    }
 }
 }