diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java index 3a6605114..ebac5cc58 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java @@ -19,13 +19,9 @@ public interface WxCouponMapper extends CommonMapper { WxCouponCVo findVoDetail(@Param("id")Long id); - void reduceInventory(@Param("id")Long id,@Param("number")Integer number); + Integer reduceInventory(@Param("id")Long id,@Param("number")Integer number,@Param("remainInventory")Integer remainInventory); - void backInventory(@Param("id")Long id,@Param("remainInventory")Integer remainInventory, @Param("number")Integer number); - - Integer reduceRemainInventory(@Param("id") Long id, @Param("remainInventory") Integer remainInventory, @Param("number") Integer number); - - Integer backRemainInventory(@Param("id") Long id, @Param("remainInventory") Integer remainInventory, @Param("number") Integer number); + Integer backInventory(@Param("id")Long id, @Param("number")Integer number,@Param("remainInventory")Integer remainInventory); void offExpiriedCouponByValidDate(); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index f39754ba5..7ce5b17f4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -29,10 +29,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @@ -331,11 +328,14 @@ import java.util.stream.Collectors; if(record.getInventory() != null && record.getRemainInventory() != null) { // 库存修改检查 WxCoupon oldCoupon = wxCouponMapper.selectByPrimaryKey(record.getId()); - if(oldCoupon.getRemainInventory() == record.getRemainInventory()) { + if (Objects.equals(oldCoupon.getRemainInventory(), record.getRemainInventory())) { // 库存未变, 不更新库存 record.setRemainInventory(null); record.setInventory(null); } else { + // TODO bug记录 + logger.info("设置库存:record.getRemainInventory {},oldCoupon.getRemainInventory {},oldCoupon.getInventory {}", + record.getRemainInventory(), oldCoupon.getRemainInventory(), oldCoupon.getInventory()); // 库存增加,要同时增加, 库存减少,要同时减少 record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory()); } @@ -651,7 +651,7 @@ import java.util.stream.Collectors; @Override @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) public void reduceRemainInventory(Long id, Integer remainInventory, Integer number) { - int num = wxCouponMapper.reduceRemainInventory(id, remainInventory, number); + int num = wxCouponMapper.reduceInventory(id, number, remainInventory); if (num == 0) { throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); } @@ -660,7 +660,7 @@ import java.util.stream.Collectors; @Override @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) public void backRemainInventory(Long id, Integer remainInventory, Integer number) { - int num = wxCouponMapper.backRemainInventory(id, remainInventory, number); + int num = wxCouponMapper.backInventory(id, number, remainInventory); if (num == 0) { throw new MallinkException(ErrorCode.REMAIN_BACK_FAIL); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index 465ea5a92..2f1eea986 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -474,7 +474,7 @@ public class WxOrderServiceImpl implements WxOrderService { try { // 减库存 - wxCouponMapper.reduceInventory(coupon.getId(), 1); + wxCouponMapper.reduceInventory(coupon.getId(), 1, coupon.getRemainInventory()); } catch (RuntimeException e) { logger.error("此券减库存失败, couponId: " + couponIdStr); throw new MallinkException(ErrorCode.ORDER_IS_FAIL); diff --git a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml index 4bd768ceb..6dccc799b 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml @@ -512,18 +512,10 @@ - update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number} - - - - update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory>= #{remainInventory} - - - update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory} - + update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory= #{remainInventory}