BUGFIX:1.design中dislike后排序混乱 2.续订成功通知会再次通知上一次的成功订阅

This commit is contained in:
2025-10-17 17:59:43 +08:00
parent d426fb34a2
commit 1af705592a
3 changed files with 33 additions and 9 deletions

View File

@@ -269,13 +269,17 @@ public class CollectionSortServiceImpl extends ServiceImpl<CollectionSortMapper,
@Transactional(rollbackFor = Exception.class)
public void resort(Long projectId, Long parentId) {
LambdaQueryWrapper<CollectionSort> wrapper = new LambdaQueryWrapper<CollectionSort>()
.eq(CollectionSort::getProjectId, projectId)
.orderByAsc(CollectionSort::getSort);
if (parentId != null) {
wrapper.eq(CollectionSort::getParentId, parentId);
} else {
wrapper.isNull(CollectionSort::getParentId);
}
// 2. 查询同组数据,按原排序升序
List<CollectionSort> list = baseMapper.selectList(
new LambdaQueryWrapper<CollectionSort>()
.eq(CollectionSort::getProjectId, projectId)
.eq(CollectionSort::getParentId, parentId)
.orderByAsc(CollectionSort::getSort)
);
List<CollectionSort> list = baseMapper.selectList(wrapper);
// 3. 重新编号 sort从 1 开始
for (int i = 0; i < list.size(); i++) {

View File

@@ -27,6 +27,7 @@ import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
@@ -224,6 +225,7 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
@Value("${stripe.private-key}")
private String privateKey;
@Transactional(rollbackFor = Exception.class)
public PaymentInfo createOrUpdatePaymentInfoForStripe(Invoice invoice){
Stripe.apiKey = privateKey;
// 获取transactionId,从sessionId更改为invoiceId

View File

@@ -351,6 +351,9 @@ public class StripeServiceImpl implements StripeService {
}
} else if (event.getType().equals("customer.subscription.deleted")){
SubscriptionInfo subscriptionInfo = updateSubscription(subscription);
if (Objects.isNull(subscriptionInfo)){
return true;
}
log.info("用户 {} 取消连续订阅 {}", subscriptionInfo.getAccountId(), subscription.getId());
if (subscriptionInfo.getCancelNotified() == (byte)0){
log.info("取消订阅 邮件通知商家");
@@ -571,6 +574,10 @@ public class StripeServiceImpl implements StripeService {
String description = subscription.getDescription();
String orderNo = description.replace("AiDA - ", "");
OrderInfo orderInfo = orderInfoService.getOrderByOrderNo(orderNo);
if (Objects.isNull(orderInfo)){
log.warn("未知订阅:{}", subscription.getId());
return null;
}
// 从回调信息中获取recurring type
SubscriptionItem subscriptionItem = subscription.getItems().getData().get(0);
@@ -1002,9 +1009,13 @@ public class StripeServiceImpl implements StripeService {
public boolean sendEmail(String subscriptionId, String type, String orderNo) {
SubscriptionInfo subscriptionInfo;
long secondsTimestamp = System.currentTimeMillis() / 1000;
QueryWrapper<SubscriptionInfo> qwSI = new QueryWrapper<>();
if (!StringUtil.isNullOrEmpty(subscriptionId)) {
qwSI.eq("subscription_id", subscriptionId);
// 区分当前订阅的时段,从而确定是新订单还是续订订单的记录
qwSI.lambda().eq(SubscriptionInfo::getSubscriptionId, subscriptionId)
.lt(SubscriptionInfo::getCurrentPeriodStart, secondsTimestamp)
.gt(SubscriptionInfo::getCurrentPeriodEnd, secondsTimestamp);
List<SubscriptionInfo> subscriptionInfoList = subscriptionInfoMapper.selectList(qwSI);
if (subscriptionInfoList.isEmpty()){
@@ -1024,7 +1035,9 @@ public class StripeServiceImpl implements StripeService {
}
}
}else if (!StringUtil.isNullOrEmpty(orderNo)) {
qwSI.eq("order_no", orderNo);
qwSI.lambda().eq(SubscriptionInfo::getOrderNo, orderNo)
.gt(SubscriptionInfo::getCurrentPeriodStart, secondsTimestamp)
.lt(SubscriptionInfo::getCurrentPeriodEnd, secondsTimestamp);
subscriptionInfo = subscriptionInfoMapper.selectOne(qwSI);
if (Objects.isNull(subscriptionInfo)){
log.info("不发送邮件原因【根据order_no{}查询到的subscriptionInfo为空】", orderNo);
@@ -1036,7 +1049,12 @@ public class StripeServiceImpl implements StripeService {
}
QueryWrapper<PaymentInfo> qwPI = new QueryWrapper<>();
qwPI.eq("order_no", subscriptionInfo.getOrderNo()).orderByDesc("id");
String periodStart = DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodStart(), "seconds", CommonConstant.TIME_FORMAT_yyyy_MM_dd_HH_mm_ss);
String periodEnd = DateUtil.changeTimeStampFormat(subscriptionInfo.getCurrentPeriodEnd(), "seconds", CommonConstant.TIME_FORMAT_yyyy_MM_dd_HH_mm_ss);
qwPI.lambda().eq(PaymentInfo::getOrderNo, subscriptionInfo.getOrderNo())
.between(PaymentInfo::getCreateTime, periodStart, periodEnd)
.orderByDesc(PaymentInfo::getId);
List<PaymentInfo> paymentInfos = paymentInfoMapper.selectList(qwPI);
if (paymentInfos.isEmpty()) {
log.info("不发送邮件原因【根据order_no:{},查询到的paymentInfos为空】", orderNo);