|
|
@@ -111,7 +111,8 @@ public class HuapiaoerInvoiceService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 将已开具的电子发票插入用户微信卡包(通过微信支付 v3 API)
|
|
|
+ * 将已开具的电子发票插入用户微信卡包(通过微信支付 v3 API)。
|
|
|
+ * 先检查是否已有卡包记录,避免重复插入。
|
|
|
*/
|
|
|
public void insertToCardPackage(Invoice invoice, InvoiceInfo result) {
|
|
|
if (invoice.getOpenid() == null || invoice.getOpenid().isBlank()) {
|
|
|
@@ -119,6 +120,22 @@ public class HuapiaoerInvoiceService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ try {
|
|
|
+ DynamicDataSourceContextHolder.push("db-admin");
|
|
|
+ var detail = invoiceDetailService.lambdaQuery()
|
|
|
+ .eq(InvoiceDetail::getApplyId, invoice.getApplyId()).one();
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+
|
|
|
+ if (detail != null && detail.getCardInformation() != null) {
|
|
|
+ log.info("卡包已插入过,跳过, applyId:{}", invoice.getApplyId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+ log.error("查询卡包记录异常, applyId:{}", invoice.getApplyId(), e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
boolean success = wechatPayFapiaoService.insertToCard(invoice, result, properties.getNsrsbh());
|
|
|
|
|
|
if (success) {
|