|
|
|
@ -457,6 +457,118 @@ public class AisinoConsoleInvoiceApiZhongQiServiceImpl implements IInvoiceApiSer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 保存invoice表 */ |
|
|
|
|
public HXResponse saveInvoice(String billInfoId,String identity,JSONObject resultJSON){ |
|
|
|
|
|
|
|
|
|
if(StrUtil.isEmpty(billInfoId)){ |
|
|
|
|
return new HXResponse("billInfoId不存在"); |
|
|
|
|
} |
|
|
|
|
BillInfo billInfo = billInfoMapper.selectBillInfoById(Long.valueOf(billInfoId)); |
|
|
|
|
|
|
|
|
|
String retcode = resultJSON.get("retcode") != null ? resultJSON.get("retcode").toString() : ""; |
|
|
|
|
String retmsg = resultJSON.get("retmsg") != null ? resultJSON.get("retmsg").toString() : ""; |
|
|
|
|
if ("4011".equals(retcode)) { |
|
|
|
|
//回写发票代码、发票号码信息
|
|
|
|
|
if (StrUtil.isEmpty(retmsg)) { |
|
|
|
|
return new HXResponse(retcode); |
|
|
|
|
} |
|
|
|
|
AisinoConsoleInvoiceAddVO aisinoConsoleInvoiceAddVO = BeanUtil.copyProperties(resultJSON, AisinoConsoleInvoiceAddVO.class); |
|
|
|
|
if (StrUtil.isEmpty(aisinoConsoleInvoiceAddVO.getInfoNumber())) { |
|
|
|
|
return new HXResponse("开具的发票号码不存在!"); |
|
|
|
|
} |
|
|
|
|
//更新发票状态
|
|
|
|
|
billInfo.setState(2); |
|
|
|
|
billInfoMapper.updateBillInfo(billInfo); |
|
|
|
|
|
|
|
|
|
//插入invoice
|
|
|
|
|
Invoice invoice = BeanUtil.copyProperties(billInfo, Invoice.class); |
|
|
|
|
List<InvoiceDetail> invoiceDetailList = BeanUtil.copyToList(billInfo.getBillDetailList(), InvoiceDetail.class); |
|
|
|
|
invoice.setInvoiceDetailList(invoiceDetailList); |
|
|
|
|
|
|
|
|
|
//发票代码
|
|
|
|
|
invoice.setFpdm(aisinoConsoleInvoiceAddVO.getInfoTypeCode()); |
|
|
|
|
//发票号码
|
|
|
|
|
invoice.setFphm(aisinoConsoleInvoiceAddVO.getInfoNumber()); |
|
|
|
|
//上一张发票代码
|
|
|
|
|
invoice.setOriginFpdm(aisinoConsoleInvoiceAddVO.getHisInfoTypeCode()); |
|
|
|
|
//上一张发票号码
|
|
|
|
|
invoice.setOriginFphm(aisinoConsoleInvoiceAddVO.getHisInfoNumber()); |
|
|
|
|
//发票种类
|
|
|
|
|
invoice.setInvoiceType(billInfo.getInvoiceType()); |
|
|
|
|
invoice.setBillInfoId(billInfo.getId()); |
|
|
|
|
invoice.setKprq(aisinoConsoleInvoiceAddVO.getInfoDate()); |
|
|
|
|
invoice.setTaxfreeamt(BigDecimal.valueOf(aisinoConsoleInvoiceAddVO.getInfoAmount())); |
|
|
|
|
invoice.setTax(BigDecimal.valueOf(aisinoConsoleInvoiceAddVO.getInfoTaxAmount())); |
|
|
|
|
|
|
|
|
|
long id = 0L; |
|
|
|
|
QueryWrapper<Invoice> invoiceQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
invoiceQueryWrapper.eq("fpdm", invoice.getFpdm()).eq("fphm", invoice.getFphm()); |
|
|
|
|
List<Invoice> invoices = invoiceMapper.selectList(invoiceQueryWrapper); |
|
|
|
|
if (CollectionUtils.isEmpty(invoices)) { |
|
|
|
|
invoice.setUpdateBy("0"); |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
invoices = invoiceMapper.selectList(invoiceQueryWrapper); |
|
|
|
|
id = invoices.get(0).getId(); |
|
|
|
|
} else { |
|
|
|
|
Invoice invoiceT = invoices.get(0); |
|
|
|
|
invoiceT = BeanUtil.copyProperties(invoice, Invoice.class); |
|
|
|
|
invoiceT.setUpdateBy("0"); |
|
|
|
|
invoiceMapper.updateInvoice(invoiceT); |
|
|
|
|
id = invoiceT.getId(); |
|
|
|
|
} |
|
|
|
|
invoiceDetailList.forEach(i -> i.setInvoiceId(invoice.getId())); |
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 增加主动回调方式,可配置
|
|
|
|
|
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); |
|
|
|
|
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(identity), "aisino_callback_url"); |
|
|
|
|
if (BeanUtil.isNotEmpty(secretIdProp) && secretIdProp.getValue() != null && !"".equals(secretIdProp.getValue())) { |
|
|
|
|
|
|
|
|
|
String callBackUrl = secretIdProp.getValue(); |
|
|
|
|
|
|
|
|
|
InvoiceBack queryInvoiceBack = new InvoiceBack(); |
|
|
|
|
queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); |
|
|
|
|
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectInvoiceBackList(queryInvoiceBack); |
|
|
|
|
if (CollectionUtils.isEmpty(invoiceBackList)) { |
|
|
|
|
queryInvoiceBack.setId(IdUtils.randomUUID()); |
|
|
|
|
queryInvoiceBack.setIdentity( identity ); |
|
|
|
|
queryInvoiceBack.setBackUrl(callBackUrl); |
|
|
|
|
queryInvoiceBack.setStatus("0"); |
|
|
|
|
queryInvoiceBack.setCreateTime(new Date()); |
|
|
|
|
queryInvoiceBack.setSystemOrderno(billInfo.getOutTradeOrderno()); |
|
|
|
|
queryInvoiceBack.setBackMsg(""); |
|
|
|
|
queryInvoiceBack.setResultCode("0000"); |
|
|
|
|
queryInvoiceBack.setResultMsg("开票成功!"); |
|
|
|
|
queryInvoiceBack.setUpdateTime(new Date()); |
|
|
|
|
invoiceBackMapper.insertInvoiceBack(queryInvoiceBack); |
|
|
|
|
} else { |
|
|
|
|
queryInvoiceBack = invoiceBackList.get(0); |
|
|
|
|
queryInvoiceBack.setResultCode("0000"); |
|
|
|
|
queryInvoiceBack.setResultMsg("开票成功!"); |
|
|
|
|
queryInvoiceBack.setUpdateTime(new Date()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 回调,失败的交给定时任务
|
|
|
|
|
InvoiceBack finalQueryInvoiceBack = queryInvoiceBack; |
|
|
|
|
try { |
|
|
|
|
callBackAisino(finalQueryInvoiceBack, callBackUrl, "", invoice.getId()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("【重汽批量开票】发票回调失败!invoiceId={}", invoice.getId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HXResponse response = new HXResponse("0000", "同步成功"); |
|
|
|
|
response.put("fpqqlsh", billInfo.getSystemOrderno()); |
|
|
|
|
return response; |
|
|
|
|
} else { |
|
|
|
|
return new HXResponse(retmsg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 开票接口回调-重汽 |
|
|
|
|
* 2023-09-26 |
|
|
|
|