|
@@ -41,7 +41,8 @@ public class HuapiaoerInvoiceService {
|
|
|
private final InvoiceDetailService invoiceDetailService;
|
|
private final InvoiceDetailService invoiceDetailService;
|
|
|
|
|
|
|
|
private HuapiaoerClient client;
|
|
private HuapiaoerClient client;
|
|
|
- private String issuerId;
|
|
|
|
|
|
|
+ private volatile String issuerId;
|
|
|
|
|
+ private volatile boolean issuerIdTried;
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
public void init() {
|
|
public void init() {
|
|
@@ -51,15 +52,26 @@ public class HuapiaoerInvoiceService {
|
|
|
.appSecret(properties.getAppSecret())
|
|
.appSecret(properties.getAppSecret())
|
|
|
.build()
|
|
.build()
|
|
|
);
|
|
);
|
|
|
- try {
|
|
|
|
|
- var drawers = client.getDrawerIdList(properties.getNsrsbh());
|
|
|
|
|
- if (!drawers.isEmpty()) {
|
|
|
|
|
- this.issuerId = drawers.get(0).getIssuerid();
|
|
|
|
|
- log.info("航信开票人初始化完成, issuerId:{}", this.issuerId);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getIssuerId() {
|
|
|
|
|
+ if (!issuerIdTried) {
|
|
|
|
|
+ synchronized (this) {
|
|
|
|
|
+ if (!issuerIdTried) {
|
|
|
|
|
+ issuerIdTried = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ var drawers = client.getDrawerIdList(properties.getNsrsbh());
|
|
|
|
|
+ if (!drawers.isEmpty()) {
|
|
|
|
|
+ issuerId = drawers.get(0).getIssuerid();
|
|
|
|
|
+ log.info("航信开票人获取成功, nsrsbh:{}, issuerId:{}", properties.getNsrsbh(), issuerId);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("获取航信开票人列表失败, nsrsbh:{}, msg:{}", properties.getNsrsbh(), e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("获取航信开票人列表失败", e);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ return issuerId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -171,7 +183,13 @@ public class HuapiaoerInvoiceService {
|
|
|
try {
|
|
try {
|
|
|
DynamicDataSourceContextHolder.push("db-admin");
|
|
DynamicDataSourceContextHolder.push("db-admin");
|
|
|
|
|
|
|
|
- var fapiaoTime = DateUtil.parse(result.getTicketDate(), "yyyy-MM-dd HH:mm:ss").toLocalDateTime();
|
|
|
|
|
|
|
+ var ticketDate = result.getTicketDate();
|
|
|
|
|
+ if (ticketDate != null && ticketDate.length() == 16) { // "yyyy-MM-dd HH:mm" = 16 chars, pad to 19
|
|
|
|
|
+ ticketDate += ":00";
|
|
|
|
|
+ }
|
|
|
|
|
+ var fapiaoTime = ticketDate != null
|
|
|
|
|
+ ? DateUtil.parse(ticketDate, "yyyy-MM-dd HH:mm:ss").toLocalDateTime()
|
|
|
|
|
+ : LocalDateTime.now();
|
|
|
var totalAmount = (int) (Double.parseDouble(result.getTicketTotalAmountHasTax()) * 100);
|
|
var totalAmount = (int) (Double.parseDouble(result.getTicketTotalAmountHasTax()) * 100);
|
|
|
|
|
|
|
|
var blueFapiao = new FapiaoApplications.FapiaoInfo();
|
|
var blueFapiao = new FapiaoApplications.FapiaoInfo();
|
|
@@ -266,7 +284,7 @@ public class HuapiaoerInvoiceService {
|
|
|
.setInvoiceTypeCode(invoiceTypeCode);
|
|
.setInvoiceTypeCode(invoiceTypeCode);
|
|
|
|
|
|
|
|
return new OpenBlueInvoiceRequest()
|
|
return new OpenBlueInvoiceRequest()
|
|
|
- .setIssuerid(issuerId)
|
|
|
|
|
|
|
+ .setIssuerid(getIssuerId())
|
|
|
.setHead(head)
|
|
.setHead(head)
|
|
|
.setDetails(details)
|
|
.setDetails(details)
|
|
|
.setTradeinfo(new OpenBlueInvoiceRequest.TradeInfo()
|
|
.setTradeinfo(new OpenBlueInvoiceRequest.TradeInfo()
|