@ -1,15 +1,12 @@
package com.jianshui.invoice.service.impl.api ;
import ch.qos.logback.core.joran.spi.ElementPath ;
import cn.hutool.core.bean.BeanUtil ;
import cn.hutool.core.codec.Base64 ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.ObjUtil ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.http.HttpUtil ;
import cn.hutool.json.JSONConfig ;
import cn.hutool.json.JSONUtil ;
import com.alibaba.druid.support.json.JSONUtils ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
@ -55,7 +52,6 @@ import com.jianshui.invoice.service.IBillInfoService;
import com.jianshui.invoice.service.IInvoiceApiService ;
import com.jianshui.invoice.task.QueryInvoiceTask ;
import com.jianshui.invoice.utils.BillInfoUtils ;
import com.jianshui.invoice.utils.JsonCaseUtils ;
import com.jianshui.invoice.utils.elephant.ElephantUtils ;
import com.jianshui.queue.utils.RedisQueueUtil ;
import com.jianshui.storage.domain.StorageUrlDTO ;
@ -71,28 +67,21 @@ import com.jianshui.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.ObjectUtils ;
import org.apache.ibatis.annotations.Lang ;
import org.joda.time.format.DateTimeFormat ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.core.env.Environment ;
import org.springframework.scheduling.annotation.Async ;
import org.springframework.stereotype.Component ;
import org.springframework.transaction.annotation.Transactional ;
import javax.servlet.http.HttpServletRequest ;
import java.io.File ;
import java.io.FileOutputStream ;
import java.io.IOException ;
import java.io.UnsupportedEncodingException ;
import java.math.BigDecimal ;
import java.security.InvalidKeyException ;
import java.security.NoSuchAlgorithmException ;
import java.text.ParseException ;
import java.text.SimpleDateFormat ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
* 销项实现
@ -149,6 +138,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
/ * *
* 发票开具
* v6
*
* @param billInfo
* @return
* /
@ -342,7 +332,8 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
e . printStackTrace ( ) ;
throw new JianshuiServiceException ( "系统异常!" ) ;
}
log . info ( "【销项发票】【大象发票】发票开具请求结果{}" , queryResult . toString ( ) ) ;
// log.info("【销项发票】【大象发票】发票开具请求结果{}", queryResult.toString());
log . info ( "【销项发票】【大象发票】发票开具请求结果" ) ;
// 判断外层报文是否成功
if ( queryResult . isError ( ) ) {
@ -385,6 +376,12 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
queryBody . put ( "DDRQQ" , "0" ) ;
// 订单日期止
queryBody . put ( "DDRQZ" , "0" ) ; * /
CompanyserviceProp companyservicePropBSWJ = companyservicePropMapper . selectPropByKey ( companyservice . getCompanyid ( ) , "BSWJ" ) ;
if ( companyservicePropBSWJ ! = null & & StrUtil . isNotEmpty ( companyservicePropBSWJ . getValue ( ) ) ) {
queryBody . put ( "BSWJ" , companyservicePropBSWJ . getValue ( ) ) ;
} else {
queryBody . put ( "BSWJ" , "1" ) ;
}
// queryResult = ElephantUtils.sendRequest(ElephantConstantsV6.ADD_INVOICE_RESULT, JSONUtil.parse(queryBody));
try {
queryResult = ElephantUtils . sendRequestWithoutTokenV6New ( ElephantConstantsV6 . ADD_INVOICE_RESULT_LOCALHOST , ElephantConstantsV6 . ADD_INVOICE_RESULT_METHOD , JSONUtil . parse ( queryBody ) , companyservice ) ;
@ -471,6 +468,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
/ * *
* 单个发票查询接口
* V6
*
* @param billInfo
* @return
* /
@ -515,7 +513,14 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
JSONObject queryBody = new JSONObject ( ) ;
queryBody . put ( "NSRSBH" , companyservice . getSellertax ( ) ) ;
queryBody . put ( "DDQQLSH" , originBillInfo . getSystemOrderno ( ) ) ;
queryBody . put ( "BSWJ" , "0" ) ;
CompanyserviceProp companyservicePropBSWJ = companyservicePropMapper . selectPropByKey ( companyservice . getCompanyid ( ) , "BSWJ" ) ;
if ( companyservicePropBSWJ ! = null & & StrUtil . isNotEmpty ( companyservicePropBSWJ . getValue ( ) ) ) {
queryBody . put ( "BSWJ" , companyservicePropBSWJ . getValue ( ) ) ;
} else {
queryBody . put ( "BSWJ" , "1" ) ;
}
debugLog ( "断点4" , uuid , timestamp ) ;
AjaxResult queryResult = null ;
@ -1105,7 +1110,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
return null ;
}
/** 获取人脸识别结果*/
/ * *
* 获取人脸识别结果
* /
@Override
public HXResponse qrcodeResult ( JSONObject decryptResult , Companyservice companyservice ) {
@ -1145,8 +1152,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
/** 邮箱交付 */
/ * *
* 邮箱交付
* /
@Override
public HXResponse mailDelivery ( InvoiceMailDeliveryDTO mailDeliveryDTO , Companyservice companyservice ) {
@ -1231,6 +1239,21 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
return null ;
}
@Override
public HXResponse queryInvoiceList ( QueryInvoiceListDTO queryInvoiceList , Companyservice companyservice ) {
log . info ( "发票列表查询接口,传入信息" , JSONUtil . toJsonStr ( queryInvoiceList ) ) ;
DxhyInterfaceResponse dxhyInterfaceResponse = null ;
try {
dxhyInterfaceResponse = ElephantUtils . sendRequestWithoutTokenV6 ( ElephantConstantsV6 . INVOICE_LIST_INFO_URL , ElephantConstantsV6 . INVOICE_LIST_METHOD , JSONUtil . parse ( queryInvoiceList ) , companyservice ) ;
} catch ( UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e ) {
log . error ( "【销项发票】【大象接口】【发票列表查询】发票请求异常,请求报文{},销方信息{}" , JSONUtil . parse ( queryInvoiceList ) . toString ( ) , JSONObject . toJSONString ( companyservice ) ) ;
e . printStackTrace ( ) ;
throw new JianshuiServiceException ( "系统异常!" ) ;
}
return parseResult ( dxhyInterfaceResponse ) ;
}
/ * *
* 红字确认单列表查询 ( 数电专用 )
@ -1472,7 +1495,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
/ * *
* 申请 / 上传 红字发票
*
@ -2540,7 +2562,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
/** 转换大象返回报文为简税报文 */
/ * *
* 转换大象返回报文为简税报文
* /
private HXResponse parseDxhyRes ( HXResponse hxResponse , Companyservice companyservice ) {
// 判断外层报文是否成功
@ -3055,9 +3079,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
/** 批量开票接口 * /
/ * *
* 批量开票接口
* /
@Override
public HXResponse addInvoiceBeatch ( BillInfo billInfo , Companyservice companyservice ) throws IllegalAccessException , InstantiationException {
@ -3141,7 +3165,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
/ * *
* @author kk
* @date 2024 / 4 / 8 14 : 55
@ -3153,6 +3176,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
// 1.订单唯一校验。新增历史订单部分(删除)。
// 订单号唯一校验 start
String outNO = billInfo . getOutTradeOrderno ( ) ! = null ? billInfo . getOutTradeOrderno ( ) : "" ;
String fpqqlsh = billInfo . getFpqqlsh ( ) ! = null ? billInfo . getFpqqlsh ( ) : "" ;
if ( StrUtil . isEmpty ( outNO ) ) {
return new HXResponse ( "批量开票:订单号为空,请检查报文!" ) ;
}
@ -3177,49 +3201,74 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
}
Invoice invoiceValidateTemp = new Invoice ( ) ;
List < Invoice > invoicesValidate = invoiceMapper . selectByOutTradeOrdernoList ( companyservice . getCompanyid ( ) , outNO , "0" ) ;
Invoice invoice = invoiceMapper . selectBySystemOrderNo ( companyservice . getCompanyid ( ) , fpqqlsh ) ;
// 开票回调失败防重复处理 start
if ( ! org . springframework . util . CollectionUtils . isEmpty ( invoicesValidate ) ) {
for ( Invoice invoice : invoicesValidate ) {
if ( invoice ! = null ) {
boolean con = true ;
QueryWrapper < InvoiceBack > invoiceBackQueryWrapper = new QueryWrapper < > ( ) ;
invoiceBackQueryWrapper . eq ( "system_orderno" , invoice . getOutTradeOrderno ( ) ) ;
InvoiceBack invoiceBackVali = invoiceBackMapper . selectOne ( invoiceBackQueryWrapper ) ;
if ( BeanUtil . isEmpty ( invoiceBackVali ) ) {
invoiceBackVali = new InvoiceBack ( ) ;
invoiceBackVali . setSystemOrderno ( invoice . getOutTradeOrderno ( ) ) ;
invoiceBackVali . setSystemOrderno ( invoice . getFpqqlsh ( ) ) ;
invoiceBackVali . setCreateTime ( new Date ( ) ) ;
invoiceBackVali . setId ( IdUtils . randomUUID ( ) ) ;
invoiceBackVali . setIdentity ( companyservice . getIdentity ( ) ) ;
invoiceBackVali . setBackUrl ( "" ) ;
invoiceBackVali . setStatus ( "0" ) ;
invoiceBackVali . setCreateTime ( new Date ( ) ) ;
invoiceBackVali . setSystemOrderno ( invoice . getOutTradeOrderno ( ) ) ;
invoiceBackVali . setBackMsg ( "" ) ;
invoiceBackVali . setResultCode ( "0000" ) ;
invoiceBackVali . setResultMsg ( "开票成功!" ) ;
invoiceBackVali . setStatus ( "3" ) ;
invoiceBackVali . setBackMsg ( "k:数据为空,初始化数据" ) ;
invoiceBackVali . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . insertInvoiceBack ( invoiceBackVali ) ;
}
} else {
Integer state = invoice . getState ( ) ;
if ( state = = 20 ) {
// 开票中
BillInfo billInfoQuery = new BillInfo ( ) ;
billInfoQuery . setFpqqlsh ( "[\"" + billInfo . getFpqqlsh ( ) + "\"]" ) ;
billInfoQuery . setOutTradeOrderno ( billInfo . getOutTradeOrderno ( ) ) ;
log . info ( "发票回调getOutTradeOrderno()={},invoice.getFpqqlsh()={}" , billInfoQuery . getOutTradeOrderno ( ) , billInfoQuery . getFpqqlsh ( ) ) ;
HXResponse resultDxhy = batchQueryInvoices ( billInfoQuery , "fpqqlsh" , companyservice ) ;
invoice = invoiceMapper . selectBySystemOrderNo ( companyservice . getCompanyid ( ) , fpqqlsh ) ;
if ( invoice = = null ) {
log . info ( "查询到Invoice信息,回调后还是未查询到Invoice" ) ;
invoiceBackVali . setStatus ( InvoiceBackStatusEnum . MULTIPLE_FAILURES . getCode ( ) ) ;
invoiceBackVali . setBackMsg ( "k:回调后还是未查询到Invoice" ) ;
invoiceBackVali . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBackVali ) ;
return new HXResponse ( "9999" , "已开票,开具状态不存在!" ) ;
}
} else if ( state = = 22 ) {
// 开票失败
invoiceBackVali . setResultCode ( "9999" ) ;
invoiceBackVali . setResultMsg ( "开票失败!" ) ;
invoiceBackVali . setStatus ( "0" ) ;
invoiceBackVali . setUpdateTime ( new Date ( ) ) ;
con = false ;
} else if ( state = = 2 ) {
// 开票成功
invoiceBackVali . setResultCode ( "0000" ) ;
invoiceBackVali . setResultMsg ( "开票成功!" ) ;
invoiceBackVali . setStatus ( "0" ) ;
invoiceBackVali . setUpdateTime ( new Date ( ) ) ;
invoiceBackMapper . updateInvoiceBack ( invoiceBackVali ) ;
} else {
log . info ( "未识别状态state={}" , state ) ;
return new HXResponse ( "9999" , "开票:未识别状态!" ) ;
}
invoiceBackMapper . updateInvoiceBack ( invoiceBackVali ) ;
// 再次推送
if ( con ) {
try {
callBackAisino ( invoiceBackVali , "" , companyservice . getIdentity ( ) , invoice . getId ( ) ) ;
} catch ( Exception e ) {
log . info ( "【批量开票】发票回调失败!invoiceId={}" , invoice . getId ( ) ) ;
}
return new HXResponse ( "0000" , "开票:发票已开具!" ) ;
}
return new HXResponse ( "0000" , "批量开票:重复订单已推送!" ) ;
}
// end
@ -3343,7 +3392,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
// 开始封装请求报文
ElephantInvoiceAddDTO elephantInvoiceAddDTO = new ElephantInvoiceAddDTO ( ) ;
elephantInvoiceAddDTO . setDDPCXX ( ddpcxx ) ;
@ -3357,7 +3405,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
elephantInvoiceAddDTO . setDDZXX ( ddzxxes ) ;
AjaxResult queryResult = null ;
try {
queryResult = ElephantUtils . sendRequestWithoutTokenV6New ( url , "" , JSONUtil . parse ( elephantInvoiceAddDTO ) , companyservice ) ;
@ -3365,7 +3412,8 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
log . error ( "【销项发票】【大象接口】【发票开具】发票请求异常,请求报文{},销方信息{}" , JSONUtil . parse ( elephantInvoiceAddDTO ) . toString ( ) , JSONObject . toJSONString ( companyservice ) ) ;
return new HXResponse ( "系统异常!" ) ;
}
log . info ( "【销项发票】【大象发票】发票开具请求结果{}" , queryResult . toString ( ) ) ;
// log.info("【销项发票】【大象发票】发票开具请求结果{}", queryResult.toString());
log . info ( "【销项发票】【大象发票】发票开具请求结果" ) ;
// 判断外层报文是否成功
if ( queryResult . isError ( ) ) {
@ -3408,6 +3456,12 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
queryBody . put ( "DDRQQ" , "0" ) ;
// 订单日期止
queryBody . put ( "DDRQZ" , "0" ) ; * /
CompanyserviceProp companyservicePropBSWJ = companyservicePropMapper . selectPropByKey ( companyservice . getCompanyid ( ) , "BSWJ" ) ;
if ( companyservicePropBSWJ ! = null & & StrUtil . isNotEmpty ( companyservicePropBSWJ . getValue ( ) ) ) {
queryBody . put ( "BSWJ" , companyservicePropBSWJ . getValue ( ) ) ;
} else {
queryBody . put ( "BSWJ" , "1" ) ;
}
// queryResult = ElephantUtils.sendRequest(ElephantConstantsV6.ADD_INVOICE_RESULT, JSONUtil.parse(queryBody));
try {
queryResult = ElephantUtils . sendRequestWithoutTokenV6New ( ElephantConstantsV6 . ADD_INVOICE_RESULT_LOCALHOST , ElephantConstantsV6 . ADD_INVOICE_RESULT_METHOD , JSONUtil . parse ( queryBody ) , companyservice ) ;
@ -3471,7 +3525,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
queryInvoiceBack . setBackUrl ( callBackUrl ) ;
queryInvoiceBack . setStatus ( InvoiceBackStatusEnum . IN_PROCESS . getCode ( ) ) ;
queryInvoiceBack . setCreateTime ( new Date ( ) ) ;
queryInvoiceBack . setSystemOrderno ( billInfo . getOutTradeOrderno ( ) ) ;
queryInvoiceBack . setSystemOrderno ( billInfo . getFpqqlsh ( ) ) ;
queryInvoiceBack . setBackMsg ( "" ) ;
queryInvoiceBack . setResultCode ( "0000" ) ;
queryInvoiceBack . setResultMsg ( "开票中,进入队列" ) ;
@ -3502,18 +3556,4 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService {
}
}