From 84acedfff6b0dcc4b74cf9c08e9921f06b41e47b Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 17 Sep 2025 15:54:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=8D=95=E5=BA=97?= =?UTF-8?q?=E6=97=B6=20=E7=A7=BB=E9=99=A4=E5=AD=90=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E7=9A=84=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ShopSyncServiceImpl.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java index 832a4445..c2cf2f31 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ShopSyncServiceImpl.java @@ -1305,7 +1305,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { return; } if ("only".equals(couponSource.getUseShopType())) { - deleteCouponsBySyncId(couponId); + upIsDel(couponId); return; } List ids = new ArrayList<>(); @@ -1328,14 +1328,16 @@ public class ShopSyncServiceImpl implements ShopSyncService { couponSource.setId(null); switch (type) { case 1://新增 - saveCouponsForShops(ids, couponSource, couponId); + saveCouponsForShops(null, ids, couponSource, couponId); break; case 2://先删除再新增 + List couponList = couponService.list(new QueryWrapper().eq(ShopCoupon::getSyncId, couponId)); + Map map = couponList.stream().collect(Collectors.toMap(ShopCoupon::getShopId, ShopCoupon::getId)); deleteCouponsBySyncId(couponId); - saveCouponsForShops(ids, couponSource, couponId); + saveCouponsForShops(map, ids, couponSource, couponId); break; case 3:// 删除 - deleteCouponsBySyncId(couponId); + upIsDel(couponId); break; default: // 处理未知类型,可根据业务需求抛出异常或忽略 @@ -1343,7 +1345,7 @@ public class ShopSyncServiceImpl implements ShopSyncService { } } - private void saveCouponsForShops(List ids, ShopCoupon coupon, Long couponId) { + private void saveCouponsForShops(Map map, List ids, ShopCoupon coupon, Long couponId) { List couponFoodIds = new ArrayList<>(); if (StrUtil.isNotBlank(coupon.getFoods()) && ",".equals(coupon.getFoods())) { if (StrUtil.isNotBlank(coupon.getFoods()) && !",".equals(coupon.getFoods())) { @@ -1362,12 +1364,19 @@ public class ShopSyncServiceImpl implements ShopSyncService { coupon.setShopId(id); coupon.setSyncId(couponId); coupon.setId(null); + if (CollUtil.isNotEmpty(map) && map.containsKey(id)) { + coupon.setId(map.get(id)); + } couponService.save(coupon); } } - private void deleteCouponsBySyncId(Long couponId) { + private void upIsDel(Long couponId) { couponService.update(new ShopCoupon().setIsDel(1), new QueryWrapper() .eq(ShopCoupon::getSyncId, couponId)); } + + private void deleteCouponsBySyncId(Long couponId) { + couponService.remove(new QueryWrapper().eq(ShopCoupon::getSyncId, couponId)); + } }