Selaa lähdekoodia

[修复]券库存操作后总库存!=(消费+剩余)的问题

release_toaliyun_real
Burce 6 vuotta sitten
vanhempi
commit
3432c0e73e
4 muutettua tiedostoa jossa 11 lisäystä ja 23 poistoa
  1. +2
    -6
      mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java
  2. +7
    -7
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  3. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java
  4. +1
    -9
      mallinkService/src/main/resources/mapper/WxCouponMapper.xml

+ 2
- 6
mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java Näytä tiedosto

@@ -19,13 +19,9 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> {


WxCouponCVo findVoDetail(@Param("id")Long id); 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(); void offExpiriedCouponByValidDate();




+ 7
- 7
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java Näytä tiedosto

@@ -29,10 +29,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;


import java.math.BigDecimal; 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; import java.util.stream.Collectors;




@@ -331,11 +328,14 @@ import java.util.stream.Collectors;
if(record.getInventory() != null && record.getRemainInventory() != null) { if(record.getInventory() != null && record.getRemainInventory() != null) {
// 库存修改检查 // 库存修改检查
WxCoupon oldCoupon = wxCouponMapper.selectByPrimaryKey(record.getId()); WxCoupon oldCoupon = wxCouponMapper.selectByPrimaryKey(record.getId());
if(oldCoupon.getRemainInventory() == record.getRemainInventory()) {
if (Objects.equals(oldCoupon.getRemainInventory(), record.getRemainInventory())) {
// 库存未变, 不更新库存 // 库存未变, 不更新库存
record.setRemainInventory(null); record.setRemainInventory(null);
record.setInventory(null); record.setInventory(null);
} else { } 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()); record.setInventory(oldCoupon.getInventory() + record.getRemainInventory() - oldCoupon.getRemainInventory());
} }
@@ -651,7 +651,7 @@ import java.util.stream.Collectors;
@Override @Override
@Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public void reduceRemainInventory(Long id, Integer remainInventory, Integer number) { 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) { if (num == 0) {
throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); throw new MallinkException(ErrorCode.ORDER_SAVE_ERR);
} }
@@ -660,7 +660,7 @@ import java.util.stream.Collectors;
@Override @Override
@Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) @Transactional(isolation= Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public void backRemainInventory(Long id, Integer remainInventory, Integer number) { 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) { if (num == 0) {
throw new MallinkException(ErrorCode.REMAIN_BACK_FAIL); throw new MallinkException(ErrorCode.REMAIN_BACK_FAIL);
} }


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java Näytä tiedosto

@@ -474,7 +474,7 @@ public class WxOrderServiceImpl implements WxOrderService {


try { try {
// 减库存 // 减库存
wxCouponMapper.reduceInventory(coupon.getId(), 1);
wxCouponMapper.reduceInventory(coupon.getId(), 1, coupon.getRemainInventory());
} catch (RuntimeException e) { } catch (RuntimeException e) {
logger.error("此券减库存失败, couponId: " + couponIdStr); logger.error("此券减库存失败, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); throw new MallinkException(ErrorCode.ORDER_IS_FAIL);


+ 1
- 9
mallinkService/src/main/resources/mapper/WxCouponMapper.xml Näytä tiedosto

@@ -512,18 +512,10 @@




<update id="reduceInventory"> <update id="reduceInventory">
update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number}
</update>

<update id="backInventory">
update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory>= #{remainInventory}
</update>

<update id="reduceRemainInventory">
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> </update>


<update id="backRemainInventory">
<update id="backInventory">
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> </update>




Ladataan…
Peruuta
Tallenna