Authored by wujiexiang

优化方法

... ... @@ -216,7 +216,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
couponMapper.insertByCouponSaveUpdateReq(coupon);
int couponId = coupon.getId();
LOGGER.info("{} insert coupon success", couponId);
saveProductLimitItems(couponId, capc.getProductConditions());
saveProductLimitItemsIfNeed(true, couponId, capc.getProductConditions());
LOGGER.info("{} create coupon success", couponId);
return couponId;
}
... ... @@ -228,21 +228,16 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
throw new ServiceException(400, "错误:优惠券信息不存在");
}
Coupon toUpdateCoupon = coupon;
List<ProductCondition> productConditions = capc.getProductConditions();
boolean isCouponAlreadySend = isCouponAlreadySend(couponId);
// 已经有了优惠券的发放记录
if (isCouponAlreadySend) {
LOGGER.info("{} was already sent,name|couponNu|remark only can update", couponId);
toUpdateCoupon = copyFewFieldsFrom(coupon);
productConditions = null;
}
LOGGER.info("{} modifyCoupon#update,coupon:{}", couponId, toUpdateCoupon);
couponMapper.updateByCouponSaveUpdateReq(toUpdateCoupon);
if (!isCouponAlreadySend) {
//发券后,不能修改商品条件
LOGGER.info("{} modifyCoupon#productConditions", couponId);
saveProductLimitItems(couponId, productConditions);
}
//没有发送过券,才需要保存新的商品条件
saveProductLimitItemsIfNeed(!isCouponAlreadySend, couponId, capc.getProductConditions());
LOGGER.info("{} modifyCoupon success", couponId);
return couponId;
}
... ... @@ -306,7 +301,12 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
}
private void saveProductLimitItems(Integer couponId, List<ProductCondition> productConditions) {
private void saveProductLimitItemsIfNeed(boolean save, Integer couponId, List<ProductCondition> productConditions) {
if (!save) {
//不需要
LOGGER.info("{} not need to saveProductLimitItems", couponId);
return;
}
// 清理之前的记录
int deletedCount = couponProductLimitMapper.deleteByCouponId(couponId);
int updateCount = 0;
... ...