管理员系统部分优化、stripe异常通知优化

This commit is contained in:
2025-02-21 17:16:44 +08:00
parent c4dbd10a85
commit 68a9b2281a
7 changed files with 38 additions and 9 deletions

View File

@@ -300,4 +300,6 @@ public class RedisUtil {
redisTemplate.delete(keys);
}
}
public final static String STRIPE_EXCEPTION_LOG = "StripeException:";
}

View File

@@ -61,7 +61,7 @@ public class ConvenientInquiryController {
@ApiOperation("获取指定时间区间内所有用户design的使用情况")
@GetMapping("/getDesignStatistic")
public Response<List<UserDesignStatisticDTO>> getDesignStatistic(@RequestParam String startTime, @RequestParam String endTime,
public Response<List<UserDesignStatisticDTO>> getDesignStatistic(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime,
@RequestParam(required = false) List<Long> ids, @RequestParam(required = false) String email) {
Long accountId = UserContext.getUserHolder().getId();
String userEmail = accountService.getById(accountId).getUserEmail();

View File

@@ -1,6 +1,8 @@
package com.ai.da.controller;
import com.ai.da.common.response.Response;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.RedisUtil;
import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.model.dto.ProductPurchaseDTO;
import com.ai.da.service.StripeService;
@@ -20,6 +22,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Date;
import java.util.List;
@Api(tags = "Stripe模块")
@@ -31,6 +34,8 @@ public class StripeController {
@Resource
private StripeService stripeService;
@Resource
private RedisUtil redisUtil;
@ApiOperation("创建支付链接")
@PostMapping("/createOrder")
@@ -54,11 +59,16 @@ public class StripeController {
}catch (Exception e){
log.error("Stripe Controller层异常捕捉, {}", e.getMessage());
e.printStackTrace();
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
String key_1 = RedisUtil.STRIPE_EXCEPTION_LOG + DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD_HH);
String key_2 = key_1 + ":" + DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD_hh_mm_ss);
String stackTrace = stripeService.getStackTrace(e, 10);
redisUtil.addToString(key_2, stackTrace);
Long size = redisUtil.getSize(key_1);
// 给我发送邮件
if (webhookReminderFlag.equals("1")){
if (webhookReminderFlag.equals("1") && size == 3){
SendEmailUtil.commonExceptionReminder("Stripe Webhook 回调", new String[]{"xupei3360@163.com"});
}
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}

View File

@@ -49,4 +49,6 @@ public interface StripeService {
String detachCustomerAllPaymentMethod(String name, String email);
// Map getIp(HttpServletRequest request);
String getStackTrace(Exception e, int maxLines);
}

View File

@@ -7,7 +7,6 @@ import com.ai.da.common.enums.CreditsEventsEnum;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.Questionnaire;
@@ -31,7 +30,6 @@ import io.minio.http.Method;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -421,7 +419,7 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
List<Map<String, Object>> countryCount = trialOrderMapper.selectMaps(queryWrapper);
Map<Object, Object> countryCountMap = countryCount.stream().collect(Collectors.toMap(
map -> map.get("country"),
map -> map.get("country") == null ? "Not provided" : map.get("country"),
map -> map.get("count")
));
HashMap<String, List<Object>> resp = new HashMap<>();

View File

@@ -473,7 +473,7 @@ public class StripeServiceImpl implements StripeService {
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
// 2、确认订单状态为支付失败
boolean resp = true;
if (orderByOrderNo.getOrderStatus().equals(OrderStatusEnum.FAILURE.getType())) {
if (!Objects.isNull(orderByOrderNo) && orderByOrderNo.getOrderStatus().equals(OrderStatusEnum.FAILURE.getType())) {
// 3、判断失败订单之后再无成功的订单
QueryWrapper<OrderInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("account_id", orderByOrderNo.getAccountId());
@@ -1326,4 +1326,20 @@ public class StripeServiceImpl implements StripeService {
//
// return request.getRemoteAddr();
// }
public String getStackTrace(Exception e, int maxLines) {
StringBuilder sb = new StringBuilder();
StackTraceElement[] stackTraceElements = e.getStackTrace();
int lines = Math.min(maxLines, stackTraceElements.length);
for (int i = 0; i < lines; i++) {
sb.append(stackTraceElements[i].toString()).append("\n");
}
// 如果堆栈信息超过 maxLines 行,添加提示
if (stackTraceElements.length > maxLines) {
sb.append("... (More stack trace lines truncated)\n");
}
return sb.toString();
}
}

View File

@@ -27,9 +27,10 @@
</insert>
<select id="getDesignStatistic" resultType="com.ai.da.model.dto.UserDesignStatisticDTO" parameterType="String">
select d.*,c.id trialOrderId, c.title,c.surname,c.given_name,c.country,c.occupation,c.create_time
select d.*,c.id trialOrderId
from (
select b.account_id,count(b.account_id) design_times,a.user_name,a.user_email,a.is_trial,a.credits
select b.account_id,count(b.account_id) design_times,a.user_name,a.user_email,a.is_trial,a.credits,
a.title,a.surname,a.given_name,a.country,a.occupation,a.create_date
from t_account a
left join t_design b on a.id = b.account_id
<where>