Просмотр исходного кода

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

release_toaliyun_real
Burce 6 лет назад
Родитель
Сommit
3432c0e73e
4 измененных файлов: 11 добавлений и 23 удалений
  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 Просмотреть файл

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

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();



+ 7
- 7
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);
}


+ 1
- 1
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);


+ 1
- 9
mallinkService/src/main/resources/mapper/WxCouponMapper.xml Просмотреть файл

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


<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>

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



Загрузка…
Отмена
Сохранить