分享相关代码 注释掉
优惠券 管理端重写 使用的地方 注释
This commit is contained in:
@@ -15,6 +15,9 @@ import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.account.service.SyncNoticeService;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.ShopCouponDTO;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.product.entity.*;
|
||||
import com.czg.product.service.*;
|
||||
import com.czg.product.vo.ProductGroupVo;
|
||||
@@ -73,6 +76,8 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
private ShopUserService shopUserService;
|
||||
@Resource
|
||||
private ShopVendorService vendorService;
|
||||
@Resource
|
||||
private ShopCouponService couponService;
|
||||
@DubboReference
|
||||
private SyncNoticeService syncNoticeService;
|
||||
|
||||
@@ -1284,4 +1289,66 @@ public class ShopSyncServiceImpl implements ShopSyncService {
|
||||
throw new CzgException("主店数据同步方式不是自动同步");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncCouponBySourceShop(Long sourceShopId, Long couponId, Integer type) {
|
||||
AssertUtil.isNull(sourceShopId, "{}不能为空", "源店铺ID");
|
||||
AssertUtil.isNull(couponId, "{}不能为空", "优惠券ID");
|
||||
AssertUtil.isNull(type, "{}不能为空", "操作类型");
|
||||
ShopInfo sourceShop = shopInfoService.getById(sourceShopId);
|
||||
if (StrUtil.isBlank(sourceShop.getShopType()) || "only".equals(sourceShop.getShopType())
|
||||
|| sourceShop.getIsHeadShop() == null || sourceShop.getIsHeadShop() != 1) {
|
||||
// 主店不是主店铺或主店是单店,不进行优惠券同步
|
||||
return;
|
||||
}
|
||||
ShopCoupon couponSource = couponService.getById(couponId);
|
||||
List<Long> ids = new ArrayList<>();
|
||||
if ("all".equals(couponSource.getUseShopType())) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.select(column(ShopConfig::getId));
|
||||
queryWrapper.eq(ShopConfig::getMainId, sourceShopId);
|
||||
ids = shopConfigService.listAs(queryWrapper, Long.class);
|
||||
} else {
|
||||
if (StrUtil.isBlank(couponSource.getUseShops())) {
|
||||
return;
|
||||
}
|
||||
ids = Arrays.stream(couponSource.getUseShops().split(","))
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
couponSource.setId(null);
|
||||
switch (type) {
|
||||
case 1://新增
|
||||
saveCouponsForShops(ids, couponSource, couponId);
|
||||
break;
|
||||
case 2://先删除再新增
|
||||
deleteCouponsBySyncId(couponId);
|
||||
saveCouponsForShops(ids, couponSource, couponId);
|
||||
break;
|
||||
case 3:// 删除
|
||||
deleteCouponsBySyncId(couponId);
|
||||
break;
|
||||
default:
|
||||
// 处理未知类型,可根据业务需求抛出异常或忽略
|
||||
throw new IllegalArgumentException("不支持的操作类型: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveCouponsForShops(List<Long> ids, ShopCoupon coupon, Long couponId) {
|
||||
ids.forEach(id -> {
|
||||
coupon.setShopId(id);
|
||||
coupon.setSyncId(couponId);
|
||||
coupon.setId(null); // 确保是新增操作
|
||||
couponService.save(coupon);
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteCouponsBySyncId(Long couponId) {
|
||||
couponService.remove(new QueryWrapper()
|
||||
.eq(ShopCoupon::getSyncId, couponId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user