|
|
|
@ -30,6 +30,9 @@ import java.nio.charset.StandardCharsets; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -267,11 +270,15 @@ public class BankServiceImpl implements BankService { |
|
|
|
try { |
|
|
|
// 设置Stripe API密钥 |
|
|
|
Stripe.apiKey = "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"; |
|
|
|
|
|
|
|
if(bankDTO.getSum() <= 0){ |
|
|
|
return Result.error("最大条数不能小于等于0"); |
|
|
|
} |
|
|
|
// 收集处理信息 |
|
|
|
List<String> messages = new ArrayList<>(); |
|
|
|
// 从Stripe获取最近的收费记录(最多200条) |
|
|
|
List<Charge> allCharges = new ArrayList<>(); |
|
|
|
String startingAfter = null; |
|
|
|
int totalLimit = 200; // 目标获取条数 |
|
|
|
int totalLimit = bankDTO.getSum(); // 目标获取条数 |
|
|
|
int pageSize = 100; // 单次最大获取条数 |
|
|
|
|
|
|
|
do { |
|
|
|
@ -280,11 +287,16 @@ public class BankServiceImpl implements BankService { |
|
|
|
if (currentPageSize <= 0) { |
|
|
|
break; // 已获取足够条数,停止 |
|
|
|
} |
|
|
|
|
|
|
|
// 构建分页参数 |
|
|
|
Long startTime = LocalDate.parse(bankDTO.getStartTime(), DateTimeFormatter.ofPattern("yyyyMMdd")).atStartOfDay(ZoneId.of("Asia/Shanghai")).toEpochSecond(); |
|
|
|
Long endTime = LocalDate.parse(bankDTO.getEndTime(), DateTimeFormatter.ofPattern("yyyyMMdd")).atStartOfDay(ZoneId.of("Asia/Shanghai")).toEpochSecond(); |
|
|
|
ChargeListParams.Created createdCondition = ChargeListParams.Created.builder() |
|
|
|
.setGte(startTime) // 大于等于开始时间 |
|
|
|
.setLt(endTime) // 小于结束时间 |
|
|
|
.build(); |
|
|
|
ChargeListParams params = ChargeListParams.builder() |
|
|
|
.setLimit((long) currentPageSize) |
|
|
|
.setStartingAfter(startingAfter) |
|
|
|
.setCreated(createdCondition) // 加入时间筛选 |
|
|
|
.build(); |
|
|
|
|
|
|
|
try { |
|
|
|
@ -329,7 +341,7 @@ public class BankServiceImpl implements BankService { |
|
|
|
|
|
|
|
// 设置付款币种和金额(来自charge) |
|
|
|
stripeDTO.setCurrency(charge.getCurrency().toUpperCase()); |
|
|
|
stripeDTO.setAmount(String.valueOf(charge.getAmount())); |
|
|
|
stripeDTO.setAmount(String.valueOf(balanceTransaction.getAmount())); |
|
|
|
|
|
|
|
// 设置收款币种(来自charge) |
|
|
|
stripeDTO.setChargeCurrency(charge.getCurrency().toUpperCase()); |
|
|
|
@ -359,6 +371,7 @@ public class BankServiceImpl implements BankService { |
|
|
|
cashCollectionMapper.updateByGoldCoinOrderCodeByStripe(stripeDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
messages.add("成功处理订单: " + stripeDTO.getOrderNo()); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("处理Stripe数据失败,chargeId: " + charge.getId(), e); |
|
|
|
// 继续处理其他数据,不中断整个流程 |
|
|
|
@ -368,6 +381,7 @@ public class BankServiceImpl implements BankService { |
|
|
|
// 创建响应VO对象 |
|
|
|
BankVO bankVO = new BankVO(); |
|
|
|
bankVO.setStripeDTOList(stripeDTOList); |
|
|
|
bankVO.setMessage(messages); |
|
|
|
|
|
|
|
return Result.success(bankVO); |
|
|
|
} catch (Exception e) { |
|
|
|
@ -386,14 +400,14 @@ public class BankServiceImpl implements BankService { |
|
|
|
// 方式一:通过订单号查找最近数据 |
|
|
|
String orderNo = bankDTO.getOrderNo(); |
|
|
|
|
|
|
|
if (orderNo == null || orderNo.isEmpty()) { |
|
|
|
return Result.error("订单号为空"); |
|
|
|
if(bankDTO.getSum() <= 0){ |
|
|
|
return Result.error("最大条数不能小于等于0"); |
|
|
|
} |
|
|
|
|
|
|
|
// 从Stripe获取最近的收费记录(最多200条) |
|
|
|
List<Charge> allCharges = new ArrayList<>(); |
|
|
|
String startingAfter = null; |
|
|
|
int totalLimit = 200; // 目标获取条数 |
|
|
|
int totalLimit = bankDTO.getSum(); // 目标获取条数 |
|
|
|
int pageSize = 100; // 单次最大获取条数 |
|
|
|
|
|
|
|
do { |
|
|
|
@ -402,15 +416,17 @@ public class BankServiceImpl implements BankService { |
|
|
|
if (currentPageSize <= 0) { |
|
|
|
break; // 已获取足够条数,停止 |
|
|
|
} |
|
|
|
|
|
|
|
// 构建分页参数 |
|
|
|
Long startTime = LocalDate.parse(bankDTO.getStartTime(), DateTimeFormatter.ofPattern("yyyyMMdd")).atStartOfDay(ZoneId.of("Asia/Shanghai")).toEpochSecond(); |
|
|
|
Long endTime = LocalDate.parse(bankDTO.getEndTime(), DateTimeFormatter.ofPattern("yyyyMMdd")).atStartOfDay(ZoneId.of("Asia/Shanghai")).toEpochSecond(); |
|
|
|
ChargeListParams.Created createdCondition = ChargeListParams.Created.builder() |
|
|
|
.setGte(startTime) // 大于等于开始时间 |
|
|
|
.setLt(endTime) // 小于结束时间 |
|
|
|
.build(); |
|
|
|
ChargeListParams params = ChargeListParams.builder() |
|
|
|
.setLimit((long) currentPageSize) |
|
|
|
.setStartingAfter(startingAfter) |
|
|
|
.setCreated(1764738449L) |
|
|
|
.setCreated(createdCondition) // 加入时间筛选 |
|
|
|
.build(); |
|
|
|
// 加时间过滤:大于等于2024-12-04 00:00:00的时间戳 |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 执行分页查询 |
|
|
|
@ -431,6 +447,7 @@ public class BankServiceImpl implements BankService { |
|
|
|
|
|
|
|
// 在获取的所有记录中查找匹配订单号的记录 |
|
|
|
Charge matchedCharge = null; |
|
|
|
System.out.println(allCharges); |
|
|
|
for (Charge charge : allCharges) { |
|
|
|
// 从metadata中获取订单号进行匹配 |
|
|
|
if (charge.getMetadata() != null) { |
|
|
|
@ -460,9 +477,9 @@ public class BankServiceImpl implements BankService { |
|
|
|
// 设置余额交易ID |
|
|
|
stripeDTO.setBalanceTransaction(matchedCharge.getBalanceTransaction()); |
|
|
|
|
|
|
|
// 设置付款币种和金额(来自charge) |
|
|
|
// 设置付款币种和金额(来自charge和来自balanceTransaction) |
|
|
|
stripeDTO.setCurrency(matchedCharge.getCurrency().toUpperCase()); |
|
|
|
stripeDTO.setAmount(String.valueOf(matchedCharge.getAmount())); |
|
|
|
stripeDTO.setAmount(String.valueOf(balanceTransaction.getAmount())); |
|
|
|
|
|
|
|
// 设置收款币种(来自charge) |
|
|
|
stripeDTO.setChargeCurrency(matchedCharge.getCurrency().toUpperCase()); |
|
|
|
|