优化接收Stripe回调时数据重复存储问题(添加唯一索引)
This commit is contained in:
@@ -93,7 +93,7 @@ public class RequestInfoUtil {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String output;
|
||||
StringBuilder outputBuilder = new StringBuilder();
|
||||
System.out.println("Output from Server .... \n");
|
||||
// System.out.println("Output from Server .... \n");
|
||||
while ((output = br.readLine()) != null) {
|
||||
outputBuilder.append(output);
|
||||
System.out.println(output);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ai.da.mapper.primary.entity.PaymentInfo;
|
||||
import com.ai.da.model.vo.OrderListVO;
|
||||
import com.ai.da.model.vo.PaymentInfoVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -26,4 +27,6 @@ public interface PaymentInfoMapper extends BaseMapper<PaymentInfo> {
|
||||
List<Map<String, String>> getCities();
|
||||
|
||||
List<Map<String, String>> getCountries();
|
||||
|
||||
int insertIgnore(@Param("paymentInfo")PaymentInfo paymentInfo);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@ package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.mapper.primary.entity.SubscriptionInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface SubscriptionInfoMapper extends BaseMapper<SubscriptionInfo> {
|
||||
|
||||
int insertIgnore(@Param("subscriptionInfo") SubscriptionInfo subscriptionInfo);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,8 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
int row = baseMapper.insertIgnore(paymentInfo);
|
||||
log.info("Payment Info insert affect rows:{}", row);
|
||||
}else {
|
||||
paymentInfo.setTradeState(status);
|
||||
paymentInfo.setUpdateTime(LocalDateTime.now());
|
||||
@@ -354,7 +355,8 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
|
||||
paymentInfo.setCity(orderByOrderNo.getCity());
|
||||
paymentInfo.setIpAddress(orderByOrderNo.getIpAddress());
|
||||
}
|
||||
baseMapper.insert(paymentInfo);
|
||||
int row = baseMapper.insertIgnore(paymentInfo);
|
||||
log.info("Payment Info insert affect rows:{}", row);
|
||||
}else {
|
||||
paymentInfo.setTradeState(charge.getStatus());
|
||||
paymentInfo.setPaymentMethod(paymentMethod);
|
||||
|
||||
@@ -482,7 +482,9 @@ public class StripeServiceImpl implements StripeService {
|
||||
subscriptionInfo.setCurrentPeriodStart(subscription.getCurrentPeriodStart());
|
||||
subscriptionInfo.setCurrentPeriodEnd(subscription.getCurrentPeriodEnd());
|
||||
subscriptionInfo.setCreateTime(LocalDateTime.now());
|
||||
subscriptionInfoMapper.insert(subscriptionInfo);
|
||||
|
||||
int rows = subscriptionInfoMapper.insertIgnore(subscriptionInfo);
|
||||
log.info("Subscription info insert affect rows : {}", rows);
|
||||
|
||||
if (subscriptionInfo.getStatus().equals("active")){
|
||||
log.info("创建订阅更新账号信息");
|
||||
|
||||
@@ -163,4 +163,15 @@
|
||||
AND TRIM(country) != ''
|
||||
</select>
|
||||
|
||||
<insert id="insertIgnore" parameterType="com.ai.da.mapper.primary.entity.PaymentInfo">
|
||||
INSERT IGNORE INTO
|
||||
t_payment_info (order_no, transaction_id, payment_type, trade_state, payer_total,
|
||||
type, content, notified, payment_method, last4, hosted_invoice_url,
|
||||
country, city, ip_address, create_time)
|
||||
VALUES (#{paymentInfo.orderNo}, #{paymentInfo.transactionId}, #{paymentInfo.paymentType},
|
||||
#{paymentInfo.tradeState}, #{paymentInfo.payerTotal}, #{paymentInfo.content},#{paymentInfo.type},
|
||||
#{paymentInfo.notified},#{paymentInfo.paymentMethod}, #{paymentInfo.last4},#{paymentInfo.hostedInvoiceUrl},
|
||||
#{paymentInfo.ipAddress},#{paymentInfo.country},#{paymentInfo.city},#{paymentInfo.createTime});
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
||||
13
src/main/resources/mapper/primary/SubscriptionInfoMapper.xml
Normal file
13
src/main/resources/mapper/primary/SubscriptionInfoMapper.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ai.da.mapper.primary.SubscriptionInfoMapper">
|
||||
<insert id="insertIgnore" parameterType="com.ai.da.mapper.primary.entity.SubscriptionInfo">
|
||||
INSERT IGNORE INTO
|
||||
t_subscription_info (account_id, order_no, subscription_id, type, status, cancel_notified,
|
||||
next_pay_date, current_period_start, current_period_end, create_time)
|
||||
VALUES (#{subscriptionInfo.accountId}, #{subscriptionInfo.orderNo}, #{subscriptionInfo.subscriptionId},
|
||||
#{subscriptionInfo.type}, #{subscriptionInfo.status}, #{subscriptionInfo.cancelNotified},
|
||||
#{subscriptionInfo.nextPayDate}, #{subscriptionInfo.currentPeriodStart},
|
||||
#{subscriptionInfo.currentPeriodEnd}, #{subscriptionInfo.createTime});
|
||||
</insert>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user