1.支付完成清除缓存

This commit is contained in:
SongZhang 2024-09-05 16:06:22 +08:00
parent e1bd478ae5
commit c7626c352a
1 changed files with 27 additions and 0 deletions

View File

@ -28,6 +28,7 @@ import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -37,6 +38,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.ACCOUNTEIXST;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
@ -132,11 +134,23 @@ public class PayService {
@Autowired
private MpShopTableMapper mpShopTableMapper;
private final RedisTemplate<String, Object> redisTemplate;
public PayService(RedisTemplate<String, Object> redisTemplate) {
this.redisTemplate = redisTemplate;
}
public Result queryPayType(String shopId) {
return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId));
}
private void clearTableInfoCache(TbOrderInfo orderInfo) {
String printKey = RedisCst.ORDER_PRINT_PRO + orderInfo.getId();
// 重置打印数据
redisTemplate.delete(printKey);
}
@Transactional(rollbackFor = Exception.class)
public Result scanPay(String orderId, String authCode, String ip, String token, BigDecimal payAmount, BigDecimal discountAmount) {
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(authCode) || ObjectUtil.isEmpty(ip)) {
@ -304,6 +318,7 @@ public class PayService {
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
} else {
String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
@ -326,6 +341,8 @@ public class PayService {
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.PAYING);
}
// orderInfo.setStatus("fail");
@ -382,6 +399,7 @@ public class PayService {
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS, mainScanResp);
} else if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
@ -401,6 +419,8 @@ public class PayService {
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.PAYING);
}
}
@ -650,6 +670,7 @@ public class PayService {
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS);
}
@ -774,6 +795,7 @@ public class PayService {
baObj.put("type","消费");
baObj.put("time",flow.getCreateTime());
producer.balance(baObj.toString());
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS);
}
@ -873,6 +895,8 @@ public class PayService {
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS);
}
@ -960,6 +984,7 @@ public class PayService {
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
orderInfo.getShopId());
redisUtil.del(tableCartKey);
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS);
}
@ -1041,6 +1066,8 @@ public class PayService {
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
.eq(TbShopTable::getQrcode, orderInfo.getTableId())
.set(TbShopTable::getStatus, TableStateEnum.IDLE.getState()));
clearTableInfoCache(orderInfo);
return Result.success(CodeEnum.SUCCESS);
}