@ -9,14 +9,13 @@ import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil ;
import com.alibaba.fastjson.JSON ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.mapper.BaseMapper ;
import com.jianshui.common.core.domain.entity.Companyservice ;
import com.jianshui.common.utils.StringUtils ;
import com.jianshui.common.utils.spring.SpringUtils ;
import com.jianshui.invoice.constant.aisino.console.AisinoConsoleConstants ;
import com.jianshui.invoice.domain.* ;
import com.jianshui.invoice.domain.dto.ExportVehicleDTO ;
import com.jianshui.invoice.domain.dto.HXResponse ;
import com.jianshui.invoice.enums.InvoiceBackStatusEnum ;
import com.jianshui.invoice.factory.IInvoiceServiceFactory ;
import com.jianshui.invoice.mapper.BillInfoMapper ;
import com.jianshui.invoice.mapper.InvoiceBackMapper ;
@ -61,15 +60,16 @@ public class InvoiceBackTask {
private final String ZQ_BACK_DXHY = "【重汽回调(开票中单据)】" ;
private final String ZQ_BACK = "【重汽回调】" ;
/ * *
/* */ / * *
* @author kk
* @date 9 : 03
* @param : [ params ]
* @return : 开票回调
* /
* //*
public void bkParams ( String params ) {
// TODO: 2023/11/9 回调次数处理
// 默认1次 定时任务控制,补偿机制
@ -172,7 +172,7 @@ public class InvoiceBackTask {
}
log . info ( "[重汽回调定时任务执行结束]---" ) ;
}
* /
/ * *
* @author kk
@ -221,113 +221,133 @@ public class InvoiceBackTask {
public void sdBackInvoice ( ) {
// 发票回调补偿机制。
log . info ( "[重汽回调定时任务开始执行]" ) ;
log . info ( "================================ [重汽回调定时任务开始执行]============================= " ) ;
log . info ( "{}:查询回调表信息,查询条件为:status=0,2,3" , ZQ_BACK ) ;
QueryWrapper < InvoiceBack > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . eq ( "status" , "0" ) . or ( ) . eq ( "status" , "2" ) . or ( ) . eq ( "status" , "3" ) ;
List < InvoiceBack > invoiceBackList = invoiceBackMapper . selectList ( queryWrapper ) ;
log . info ( "【重汽回调】查询到{}条带回调订单" , invoiceBackList . size ( ) ) ;
log . info ( "{}:查询到{}条带回调订单" , ZQ_BACK , invoiceBackList . size ( ) ) ;
for ( InvoiceBack invoiceBack : invoiceBackList ) {
String id = invoiceBack . getSystemOrderno ( ) ;
String identity = invoiceBack . getIdentity ( ) ;
log . info ( "{}:开始处理回调订单,identity={},id={}," , ZQ_BACK , identity , id ) ;
if ( StrUtil . isEmpty ( id ) ) {
log . info ( "【控制台】发票回调,id为空" ) ;
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( "id为空" ) ;
log . info ( "{}:发票回调,回调id为空" , ZQ_BACK ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "运维排查:传入 id为空" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
log . info ( "【重汽回调】订单号{},开始回调" , id ) ;
log . info ( "{}:订单号{},开始回调" , ZQ_BACK , id ) ;
ICompanyservicePropService companyserviceProp = SpringUtils . getBean ( ICompanyservicePropService . class ) ;
CompanyserviceProp secretIdProp = companyserviceProp . selectPropByKey ( Long . valueOf ( identity ) , "aisino_callback_url" ) ;
if ( secretIdProp = = null | | secretIdProp . getValue ( ) = = null | | "" . equals ( secretIdProp . getValue ( ) ) ) {
log . info ( "【重汽回调】 发票回调,未配置回调地址{}" , identity ) ;
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( "未配置回调地址" ) ;
log . info ( "{} 发票回调,未配置回调地址{}" , ZQ_BACK , identity ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "运维排查: 未配置回调地址" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
String callBackUrl = secretIdProp . getValue ( ) ;
log . info ( "【重汽回调】发票回调,订单号{},回调地址{}" , id , callBackUrl ) ;
log . info ( "{}:发票回调,订单号{},回调地址{}" , ZQ_BACK , id , callBackUrl ) ;
Invoice invoice = invoiceMapper . selectBySystemOrderNo ( Long . valueOf ( identity ) , id ) ;
Invoice invoice = invoiceMapper . selectByOutTradeOrderno ( Long . valueOf ( identity ) , id , "0" ) ;
if ( invoice = = null ) {
log . info ( "【重汽回调】发票信息未查询到,id={}" , id ) ;
invoice = new Invoice ( ) ;
invoice . setOutTradeOrderno ( invoiceBack . getSystemOrderno ( ) ) ;
invoice . setState ( 22 ) ;
invoice . setMessage ( ( invoiceBack . getResultMsg ( ) ! = null & & invoiceBack . getResultMsg ( ) . length ( ) > 200 ) ? invoiceBack . getResultMsg ( ) . substring ( 0 , 200 ) : invoiceBack . getResultMsg ( ) ) ;
}
log . info ( "{}:当前发票未查询到Invoice信息,开始请求大象接口获取" , ZQ_BACK ) ;
log . info ( "通过billInfo组装,id为:{}" , id ) ;
BillInfo billInfo = billInfoMapper . selectBySystemOrderNo ( Long . valueOf ( identity ) , id ) ;
if ( BeanUtil . isEmpty ( billInfo ) ) {
log . info ( "{}:billInfo中不存咋,id为:{}" , ZQ_BACK , id ) ;
}
if ( invoice ! = null ) {
// 明细重插
List < InvoiceDetail > invoiceDetailList = invoiceMapper . selectInvoiceIdForInvoiceDetailList ( invoice . getId ( ) ) ;
if ( ! invoiceDetailList . isEmpty ( ) ) {
invoice . setInvoiceDetailList ( invoiceDetailList ) ;
// 发票查询
String messageQhery = getInvoiceQuery ( invoiceBack , billInfo ) ;
invoice = invoiceMapper . selectBySystemOrderNo ( Long . valueOf ( identity ) , id ) ;
log . info ( "{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}" , ZQ_BACK , invoice ! = null , messageQhery ) ;
if ( invoice = = null ) {
log . info ( "{}:查询到Invoice信息,回调后还是未查询到Invoice" , ZQ_BACK ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "k:回调后还是未查询到Invoice" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
}
try {
}
log . info ( "【重汽回调】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}" , id , invoice . getOutTradeOrderno ( ) , callBackUrl , JSONUtil . toJsonStr ( invoice ) ) ;
String result = HttpUtil . post ( callBackUrl , JSONUtil . toJsonStr ( invoice ) ) ;
log . info ( "【重汽回调】发票回调接口,发送数据结束,id={},接口返回信息={}" , id , result ) ;
JSONObject jsonObject = JSONUtil . parseObj ( result ) ;
if ( jsonObject ! = null ) {
String status = jsonObject . get ( "status" ) ! = null ? jsonObject . get ( "status" ) . toString ( ) : "" ;
String message = jsonObject . get ( "message" ) ! = null ? jsonObject . get ( "message" ) . toString ( ) : "" ;
if ( "0000" . equals ( status ) ) {
invoiceBack . setStatus ( "1" ) ;
invoiceBack . setBackMsg ( message ! = null ? message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) : "" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
} else if ( "9999" . equals ( status ) ) {
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( message ! = null ? message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) : "" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
} else {
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( status + message ! = null ? message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) : "" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
}
Integer stateInvoice = invoice . getState ( ) ;
String fpqqlsh = invoice . getFpqqlsh ( ) ;
String ddh = invoice . getOutTradeOrderno ( ) ;
log . info ( "{}:查询到Invoice信息,发票状态为:{}" , ZQ_BACK , stateInvoice ) ;
if ( stateInvoice = = 20 ) {
// 开票中
log . info ( "{}:开具中,调用查询,fpqqlsh={},ddh={}" , ZQ_BACK , fpqqlsh , ddh ) ;
BillInfo billInfo = new BillInfo ( ) ;
billInfo . setFpqqlsh ( invoice . getFpqqlsh ( ) ) ;
billInfo . setOutTradeOrderno ( invoice . getOutTradeOrderno ( ) ) ;
// 发票查询
String messageQhery = getInvoiceQuery ( invoiceBack , billInfo ) ;
invoice = invoiceMapper . selectBySystemOrderNo ( Long . valueOf ( identity ) , id ) ;
log . info ( "{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}" , ZQ_BACK , invoice ! = null , messageQhery ) ;
if ( invoice = = null ) {
log . info ( "{}:查询到Invoice信息,回调后还是未查询到Invoice" , ZQ_BACK ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "k:回调后还是未查询到Invoice" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
} catch ( Exception e ) {
log . info ( "【重汽回调】发票回调接口,发送数据异常,id={},e={}" , id , e . toString ( ) ) ;
invoiceBack . setStatus ( "2" ) ;
invoiceBack . setBackMsg ( "发送数据异常" ) ;
} else if ( stateInvoice = = 22 ) {
// 开票失败
log . info ( "{}:开具失败,递交回调,fpqqlsh={},ddh={}" , ZQ_BACK , fpqqlsh , ddh ) ;
} else if ( stateInvoice = = 2 ) {
// 开票成功
log . info ( "{}:开具成功,递交回调,fpqqlsh={},ddh={}" , ZQ_BACK , fpqqlsh , ddh ) ;
} else {
// 未解析状态
log . info ( "{}:查询到Invoice信息,发票状态为:{},未解析状态" , ZQ_BACK , stateInvoice ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . CALLBACK_FAILED . getCode ( ) ) ;
invoiceBack . setBackMsg ( "发票状态为" + stateInvoice + ",未解析状态" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
}
log . info ( "[重汽回调定时任务执行结束]---" ) ;
}
// 明细重插
List < InvoiceDetail > invoiceDetailList = invoiceMapper . selectInvoiceIdForInvoiceDetailList ( invoice . getId ( ) ) ;
if ( ! invoiceDetailList . isEmpty ( ) ) {
invoice . setInvoiceDetailList ( invoiceDetailList ) ;
}
// 回调重汽
backZq ( id , invoice , callBackUrl , invoiceBack ) ;
}
log . info ( "=======================[重汽回调定时任务执行结束]=================================" ) ;
}
/ * *
* @author kk
* @date 16 : 12
* @param : [ ]
* @return : 开票中发票 查询发票状态并回推 - 重汽
* /
* @author kk
* @date 16 : 12
* @param : [ ]
* @return : 开票中发票 查询发票状态并回推 - 重汽
* /
public void sdBackInvoiceQueryDxhy ( ) {
// 发票回调补偿机制。
log . info ( ZQ_BACK_DXHY + "开始执行]" ) ;
log . info ( "============================{}:开始执行,查询条件-5===================================" , ZQ_BACK_DXHY ) ;
QueryWrapper < InvoiceBack > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . eq ( "status" , "5" ) ;
@ -347,8 +367,8 @@ public class InvoiceBackTask {
long minutesBetween = DateUtil . between ( now , halfAnHourAgo , DateUnit . MINUTE ) ;
// 如果差值大于或等于30分钟,则认为当前时间在半个小时之前
boolean isHalfAnHourAgo = minutesBetween > = 30 ;
if ( ! isHalfAnHourAgo ) {
log . info ( ZQ_BACK_DXHY + "只查询半个小时之前的单据" ) ;
if ( ! isHalfAnHourAgo ) {
log . info ( "{}只查询半个小时之前的单据,之前的交给系统队列,当前单据号:{}暂不回调" , ZQ_BACK_DXHY , invoiceBack . getSystemOrderno ( ) ) ;
continue ;
}
@ -356,7 +376,7 @@ public class InvoiceBackTask {
String identity = invoiceBack . getIdentity ( ) ;
if ( StrUtil . isEmpty ( id ) ) {
log . info ( ZQ_BACK_DXHY + "发票回调,id为空" ) ;
log . info ( "{}:发票回调,id为空" , ZQ_BACK_DXHY ) ;
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( "id为空" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
@ -364,13 +384,13 @@ public class InvoiceBackTask {
continue ;
}
log . info ( ZQ_BACK_DXHY + "订单号{}" , id ) ;
log . info ( "{}:订单号{}" , ZQ_BACK_DXHY , id ) ;
ICompanyservicePropService companyserviceProp = SpringUtils . getBean ( ICompanyservicePropService . class ) ;
CompanyserviceProp secretIdProp = companyserviceProp . selectPropByKey ( Long . valueOf ( identity ) , "aisino_callback_url" ) ;
if ( secretIdProp = = null | | secretIdProp . getValue ( ) = = null | | "" . equals ( secretIdProp . getValue ( ) ) ) {
log . info ( ZQ_BACK_DXHY + "发票回调,未配置回调地址{}" , identity ) ;
log . info ( "{}:发票回调,未配置回调地址{}" , ZQ_BACK_DXHY , identity ) ;
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( "未配置回调地址" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
@ -379,28 +399,22 @@ public class InvoiceBackTask {
}
String callBackUrl = secretIdProp . getValue ( ) ;
log . info ( ZQ_BACK_DXHY + "发票回调,订单号{},回调地址{}" , id , callBackUrl ) ;
log . info ( ZQ_BACK_DXHY + "发票回调,订单号{},回调地址{}" , id , callBackUrl ) ;
Invoice invoice = invoiceMapper . selectByOutTradeOrdernoNoUpdateBy ( Long . valueOf ( identity ) , id ) ;
Invoice invoice = invoiceMapper . selectBySystemOrderNo ( Long . valueOf ( identity ) , id ) ;
if ( invoice ! = null ) {
log . info ( "通过Invoice组装,id为:{}" , id ) ;
// log.info(ZQ_BACK_DXHY + "发票信息未查询到,id={}", id);
// invoice = new Invoice();
// invoice.setOutTradeOrderno(invoiceBack.getSystemOrderno());
// invoice.setState(22);
// invoice.setMessage( (invoiceBack.getResultMsg() != null && invoiceBack.getResultMsg().length() > 200) ? invoiceBack.getResultMsg().substring(0, 200) : invoiceBack.getResultMsg() );
log . info ( "通过Invoice组装,id为:{}" , id ) ;
// 明细重插
List < InvoiceDetail > invoiceDetailList = invoiceMapper . selectInvoiceIdForInvoiceDetailList ( invoice . getId ( ) ) ;
if ( ! invoiceDetailList . isEmpty ( ) ) {
if ( ! invoiceDetailList . isEmpty ( ) ) {
invoice . setInvoiceDetailList ( invoiceDetailList ) ;
}
} else {
log . info ( "通过billInfo组装,id为:{}" , id ) ;
BillInfo billInfo = billInfoMapper . selectByOutTradeOrdern o ( Long . valueOf ( identity ) , id ) ;
if ( BeanUtil . isEmpty ( billInfo ) ) {
log . info ( "billInfo中不存咋,id为:{}" , id ) ;
} else {
log . info ( "通过billInfo组装,id为:{}" , id ) ;
BillInfo billInfo = billInfoMapper . selectBySystemOrderN o ( Long . valueOf ( identity ) , id ) ;
if ( BeanUtil . isEmpty ( billInfo ) ) {
log . info ( "billInfo中不存咋,id为:{}" , id ) ;
}
Invoice invoice1 = new Invoice ( ) ;
invoice1 . setFpqqlsh ( billInfo . getFpqqlsh ( ) ) ;
@ -408,9 +422,9 @@ public class InvoiceBackTask {
invoice1 . setOutTradeOrderno ( billInfo . getOutTradeOrderno ( ) ) ;
}
Integer state = invoice . getState ( ) ! = null ? invoice . getState ( ) : 1 ;
log . info ( ZQ_BACK_DXHY + "id={},state={}" , id , state ) ;
log . info ( ZQ_BACK_DXHY + "请求大象接口更新发票状态,id={},state={}" , id , state ) ;
Integer state = invoice . getState ( ) ! = null ? invoice . getState ( ) : 1 ;
log . info ( ZQ_BACK_DXHY + "id={},state={}" , id , state ) ;
log . info ( ZQ_BACK_DXHY + "请求大象接口更新发票状态,id={},state={}" , id , state ) ;
IInvoiceApiService invoiceService = invoiceServiceFactory . getService ( "elephantV6_invoice" ) ;
Companyservice companyservice = new Companyservice ( ) ;
@ -419,66 +433,221 @@ public class InvoiceBackTask {
BillInfo billInfo = new BillInfo ( ) ;
billInfo . setFpqqlsh ( "[\"" + invoice . getFpqqlsh ( ) + "\"]" ) ;
billInfo . setOutTradeOrderno ( invoice . getOutTradeOrderno ( ) ) ;
log . info ( "发票回调invoice.id={},getOutTradeOrderno()={},invoice.getFpqqlsh()={}" , id , invoice . getOutTradeOrderno ( ) , invoice . getFpqqlsh ( ) ) ;
log . info ( "发票回调invoice.id={},getOutTradeOrderno()={},invoice.getFpqqlsh()={}" , id , invoice . getOutTradeOrderno ( ) , invoice . getFpqqlsh ( ) ) ;
HXResponse resultDxhy = invoiceService . batchQueryInvoices ( billInfo , "fpqqlsh" , companyservice ) ;
log . info ( "发票回调id={}" , id ) ;
invoice = invoiceMapper . selectByOutTradeOrdernoNoUpdateBy ( Long . valueOf ( identity ) , id ) ;
log . info ( "发票回调id={}" , id ) ;
invoice = invoiceMapper . selectBySystemOrderNo ( Long . valueOf ( identity ) , id ) ;
if ( invoice = = null ) {
log . info ( ZQ_BACK_DXHY + "重新拉取结果后,发票信息未查询到,id={}" , id ) ;
invoice = new Invoice ( ) ;
invoice . setOutTradeOrderno ( invoiceBack . getSystemOrderno ( ) ) ;
invoice . setState ( 22 ) ;
invoice . setMessage ( ( invoiceBack . getResultMsg ( ) ! = null & & invoiceBack . getResultMsg ( ) . length ( ) > 200 ) ? invoiceBack . getResultMsg ( ) . substring ( 0 , 200 ) : invoiceBack . getResultMsg ( ) ) ;
invoice . setMessage ( ( invoiceBack . getResultMsg ( ) ! = null & & invoiceBack . getResultMsg ( ) . length ( ) > 200 ) ? invoiceBack . getResultMsg ( ) . substring ( 0 , 200 ) : invoiceBack . getResultMsg ( ) ) ;
continue ;
}
state = invoice . getState ( ) ;
log . info ( ZQ_BACK_DXHY + "拉去后查询状态为,id={},state={}" , id , state ) ;
log . info ( ZQ_BACK_DXHY + "拉去后查询状态为,id={},state={}" , id , state ) ;
if ( state = = 20 ) {
log . info ( ZQ_BACK_DXHY + "20为开票中,不回调,id={},state={}" , id , state ) ;
if ( state = = 20 ) {
log . info ( ZQ_BACK_DXHY + "20为开票中,不回调,id={},state={}" , id , state ) ;
continue ;
}
try {
// 回调重汽
backZq ( id , invoice , callBackUrl , invoiceBack ) ;
log . info ( ZQ_BACK_DXHY + "发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}" , id , invoice . getOutTradeOrderno ( ) , callBackUrl , JSONUtil . toJsonStr ( invoice ) ) ;
String result = HttpUtil . post ( callBackUrl , JSONUtil . toJsonStr ( invoice ) ) ;
log . info ( ZQ_BACK_DXHY + "发票回调接口,发送数据结束,id={},接口返回信息={}" , id , result ) ;
JSONObject jsonObject = JSONUtil . parseObj ( result ) ;
if ( jsonObject ! = null ) {
String status = jsonObject . get ( "status" ) ! = null ? jsonObject . get ( "status" ) . toString ( ) : "" ;
String message = jsonObject . get ( "message" ) ! = null ? jsonObject . get ( "message" ) . toString ( ) : "" ;
if ( "0000" . equals ( status ) ) {
invoiceBack . setStatus ( "1" ) ;
invoiceBack . setBackMsg ( message ! = null ? message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) : "" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
} else if ( "9999" . equals ( status ) ) {
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( message ! = null ? message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) : "" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
} else {
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setBackMsg ( status + message ! = null ? message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) : "" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
}
}
log . info ( ZQ_BACK_DXHY + "定时任务执行结束---" ) ;
}
/** 回调重汽 */
public void backZq ( String id , Invoice invoice , String callBackUrl , InvoiceBack invoiceBack ) {
try {
log . info ( "【重汽回调】发票回调接口,发送数据开始,id={},orderno={},callBackUrl={},param={}" , id , invoice . getOutTradeOrderno ( ) , callBackUrl , JSONUtil . toJsonStr ( invoice ) ) ;
String result = HttpUtil . post ( callBackUrl , JSONUtil . toJsonStr ( invoice ) ) ;
log . info ( "【重汽回调】发票回调接口,发送数据结束,id={},接口返回信息={}" , id , result ) ;
JSONObject jsonObject = JSONUtil . parseObj ( result ) ;
String status = jsonObject . get ( "status" ) ! = null ? jsonObject . get ( "status" ) . toString ( ) : "" ;
String message = jsonObject . get ( "message" ) ! = null ? jsonObject . get ( "message" ) . toString ( ) : "" ;
if ( message . length ( ) > 200 ) {
message = message . substring ( 0 , Math . min ( message . length ( ) , 200 ) ) ;
}
invoiceBack . setBackMsg ( "zq:" + message ) ;
if ( "0000" . equals ( status ) ) {
invoiceBack . setStatus ( "1" ) ;
} else if ( "9999" . equals ( status ) ) {
invoiceBack . setStatus ( "3" ) ;
} else {
invoiceBack . setStatus ( "3" ) ;
invoiceBack . setResultMsg ( "k:客户系统回调异常,status=" + status ) ;
}
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
} catch ( Exception e ) {
log . info ( "{}:发票回调接口,发送数据异常,id={},e={}" , ZQ_BACK , id , e . toString ( ) ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "运维:发送数据异常" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
}
}
/ * *
* 查询发票查询
* /
private String getInvoiceQuery ( InvoiceBack invoiceBack , BillInfo billInfo ) {
IInvoiceApiService invoiceService = invoiceServiceFactory . getService ( "elephantV6_invoice" ) ;
Companyservice companyservice = new Companyservice ( ) ;
companyservice . setCompanyid ( Long . valueOf ( invoiceBack . getIdentity ( ) ) ) ;
companyservice . setSellertax ( billInfo . getSellerTaxnum ( ) ) ;
BillInfo billInfoQuery = new BillInfo ( ) ;
billInfoQuery . setFpqqlsh ( "[\"" + billInfo . getFpqqlsh ( ) + "\"]" ) ;
billInfoQuery . setOutTradeOrderno ( billInfo . getOutTradeOrderno ( ) ) ;
log . info ( "发票回调getOutTradeOrderno()={},invoice.getFpqqlsh()={}" , billInfoQuery . getOutTradeOrderno ( ) , billInfoQuery . getFpqqlsh ( ) ) ;
HXResponse resultDxhy = invoiceService . batchQueryInvoices ( billInfoQuery , "fpqqlsh" , companyservice ) ;
return resultDxhy . getMessage ( ) ;
}
/ * *
* @author kk
* @date 2024 / 4 / 10 20 : 32
* @param : [ ]
* @return : 重汽数电回推补偿机制 。
* /
public void sdBackInvoiceJiuBan ( ) {
// 发票回调补偿机制。
log . info ( "================================[重汽回调定时任务开始执行]=============================" ) ;
log . info ( "{}:查询回调表信息,查询条件为:status=7" , ZQ_BACK ) ;
QueryWrapper < InvoiceBack > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . eq ( "status" , "7" ) ;
List < InvoiceBack > invoiceBackList = invoiceBackMapper . selectList ( queryWrapper ) ;
log . info ( "{}:查询到{}条带回调订单" , ZQ_BACK , invoiceBackList . size ( ) ) ;
for ( InvoiceBack invoiceBack : invoiceBackList ) {
String id = invoiceBack . getSystemOrderno ( ) ;
String identity = invoiceBack . getIdentity ( ) ;
log . info ( "{}:开始处理回调订单,identity={},id={}," , ZQ_BACK , identity , id ) ;
if ( StrUtil . isEmpty ( id ) ) {
log . info ( "{}:发票回调,回调id为空" , ZQ_BACK ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "运维排查:传入id为空" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
log . info ( "{}:订单号{},开始回调" , ZQ_BACK , id ) ;
ICompanyservicePropService companyserviceProp = SpringUtils . getBean ( ICompanyservicePropService . class ) ;
CompanyserviceProp secretIdProp = companyserviceProp . selectPropByKey ( Long . valueOf ( identity ) , "aisino_callback_url" ) ;
if ( secretIdProp = = null | | secretIdProp . getValue ( ) = = null | | "" . equals ( secretIdProp . getValue ( ) ) ) {
log . info ( "{}发票回调,未配置回调地址{}" , ZQ_BACK , identity ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "运维排查:未配置回调地址" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
String callBackUrl = secretIdProp . getValue ( ) ;
log . info ( "{}:发票回调,订单号{},回调地址{}" , ZQ_BACK , id , callBackUrl ) ;
Invoice invoice = invoiceMapper . selectByOutTradeOrdernoNoUpdateBy ( Long . valueOf ( identity ) , id ) ;
if ( invoice = = null ) {
log . info ( "{}:当前发票未查询到Invoice信息,开始请求大象接口获取" , ZQ_BACK ) ;
log . info ( "通过billInfo组装,id为:{}" , id ) ;
BillInfo billInfo = billInfoMapper . selectByOutTradeOrderno ( Long . valueOf ( identity ) , id ) ;
if ( BeanUtil . isEmpty ( billInfo ) ) {
log . info ( "{}:billInfo中不存咋,id为:{}" , ZQ_BACK , id ) ;
}
// 发票查询
String messageQhery = getInvoiceQuery ( invoiceBack , billInfo ) ;
invoice = invoiceMapper . selectByOutTradeOrdernoNoUpdateBy ( Long . valueOf ( identity ) , id ) ;
log . info ( "{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}" , ZQ_BACK , invoice ! = null , messageQhery ) ;
if ( invoice = = null ) {
log . info ( "{}:查询到Invoice信息,回调后还是未查询到Invoice" , ZQ_BACK ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "k:回调后还是未查询到Invoice" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
} catch ( Exception e ) {
log . info ( ZQ_BACK_DXHY + "发票回调接口,发送数据异常,id={},e={}" , id , e . toString ( ) ) ;
invoiceBack . setStatus ( "2" ) ;
invoiceBack . setBackMsg ( "发送数据异常" ) ;
}
Integer stateInvoice = invoice . getState ( ) ;
String fpqqlsh = invoice . getFpqqlsh ( ) ;
String ddh = invoice . getOutTradeOrderno ( ) ;
log . info ( "{}:查询到Invoice信息,发票状态为:{}" , ZQ_BACK , stateInvoice ) ;
if ( stateInvoice = = 20 ) {
// 开票中
log . info ( "{}:开具中,调用查询,fpqqlsh={},ddh={}" , ZQ_BACK , fpqqlsh , ddh ) ;
BillInfo billInfo = new BillInfo ( ) ;
billInfo . setFpqqlsh ( invoice . getFpqqlsh ( ) ) ;
billInfo . setOutTradeOrderno ( invoice . getOutTradeOrderno ( ) ) ;
// 发票查询
String messageQhery = getInvoiceQuery ( invoiceBack , billInfo ) ;
invoice = invoiceMapper . selectByOutTradeOrdernoNoUpdateBy ( Long . valueOf ( identity ) , id ) ;
log . info ( "{}:调用回调接口拉取后,Invoice存在状态为{},回调查询发票结果为:{}" , ZQ_BACK , invoice ! = null , messageQhery ) ;
if ( invoice = = null ) {
log . info ( "{}:查询到Invoice信息,回调后还是未查询到Invoice" , ZQ_BACK ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBack . setBackMsg ( "k:回调后还是未查询到Invoice" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
} else if ( stateInvoice = = 22 ) {
// 开票失败
log . info ( "{}:开具失败,递交回调,fpqqlsh={},ddh={}" , ZQ_BACK , fpqqlsh , ddh ) ;
} else if ( stateInvoice = = 2 ) {
// 开票成功
log . info ( "{}:开具成功,递交回调,fpqqlsh={},ddh={}" , ZQ_BACK , fpqqlsh , ddh ) ;
} else {
// 未解析状态
log . info ( "{}:查询到Invoice信息,发票状态为:{},未解析状态" , ZQ_BACK , stateInvoice ) ;
invoiceBack . setStatus ( InvoiceBackStatusEnum . CALLBACK_FAILED . getCode ( ) ) ;
invoiceBack . setBackMsg ( "发票状态为" + stateInvoice + ",未解析状态" ) ;
invoiceBack . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBack ) ;
continue ;
}
// 明细重插
List < InvoiceDetail > invoiceDetailList = invoiceMapper . selectInvoiceIdForInvoiceDetailList ( invoice . getId ( ) ) ;
if ( ! invoiceDetailList . isEmpty ( ) ) {
invoice . setInvoiceDetailList ( invoiceDetailList ) ;
}
// 回调重汽
backZq ( id , invoice , callBackUrl , invoiceBack ) ;
}
log . info ( ZQ_BACK_DXHY + "定时任务执行结束---" ) ;
log . info ( "=======================[重汽回调定时任务执行结束]================================= ") ;
}
}