|
|
|
@ -1,7 +1,12 @@ |
|
|
|
|
package com.jianshui.invoice.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.codec.Base64; |
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse; |
|
|
|
@ -20,22 +25,25 @@ import com.jianshui.common.utils.file.FileUtils; |
|
|
|
|
import com.jianshui.common.utils.spring.SpringUtils; |
|
|
|
|
import com.jianshui.common.utils.uuid.IdUtils; |
|
|
|
|
import com.jianshui.invoice.constant.elephant.ElephantConstantsV6; |
|
|
|
|
import com.jianshui.invoice.domain.BillInfo; |
|
|
|
|
import com.jianshui.invoice.domain.Invoice; |
|
|
|
|
import com.jianshui.invoice.domain.InvoiceDetail; |
|
|
|
|
import com.jianshui.invoice.domain.InvoiceFile; |
|
|
|
|
import com.jianshui.invoice.domain.*; |
|
|
|
|
import com.jianshui.invoice.mapper.BillInfoMapper; |
|
|
|
|
import com.jianshui.invoice.mapper.InvoiceBackMapper; |
|
|
|
|
import com.jianshui.invoice.mapper.InvoiceFileMapper; |
|
|
|
|
import com.jianshui.invoice.mapper.InvoiceMapper; |
|
|
|
|
import com.jianshui.invoice.service.ElephantInvoiceService; |
|
|
|
|
import com.jianshui.invoice.service.IBillInfoService; |
|
|
|
|
import com.jianshui.invoice.utils.elephant.ElephantUtils; |
|
|
|
|
import com.jianshui.queue.dto.RedisQueueMessage; |
|
|
|
|
import com.jianshui.queue.utils.RedisQueueUtil; |
|
|
|
|
import com.jianshui.system.domain.CompanyserviceProp; |
|
|
|
|
import com.jianshui.system.service.ICompanyservicePropService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
@ -57,10 +65,10 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
private InvoiceMapper invoiceMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IBillInfoService billInfoService; |
|
|
|
|
private InvoiceFileMapper invoiceFileMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private InvoiceFileMapper invoiceFileMapper; |
|
|
|
|
private InvoiceBackMapper invoiceBackMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//调用大象获取电子税局账号
|
|
|
|
@ -266,10 +274,26 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
invoice.setJqbh(ddfpxx.getKPZD()); |
|
|
|
|
saveFileUseDb(invoice,IdUtils.randomUUID(),invoice.getFphm(),companyservice, ddfpxx); |
|
|
|
|
//判断id是否为空,为空则插入,不为空则更新
|
|
|
|
|
boolean isExist = false; |
|
|
|
|
if (invoice.getId() != null) { |
|
|
|
|
invoiceMapper.updateInvoice(invoice); |
|
|
|
|
} else { |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
AjaxResult result = RedisQueueUtil.build().setData(invoice).onQueue("invoice_add_callback_consumer").retry(0).lrange(); |
|
|
|
|
if (result != null && result.isSuccess()){ |
|
|
|
|
List<String> data = (List<String>) result.getData(); |
|
|
|
|
|
|
|
|
|
for (String datum : data) { |
|
|
|
|
RedisQueueMessage redisQueueMessage = JSONObject.parseObject(datum, RedisQueueMessage.class); |
|
|
|
|
Invoice invoiceExit = JSONObject.parseObject(JSONObject.toJSONString(redisQueueMessage.getData()), Invoice.class); |
|
|
|
|
if (invoiceExit != null && invoiceExit.getOutTradeOrderno().equals(invoice.getOutTradeOrderno())){ |
|
|
|
|
isExist = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (!isExist){ |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//发票明细先删除再插入
|
|
|
|
|
|
|
|
|
@ -314,8 +338,10 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
|
|
|
|
|
invoiceDetailList.add(tempDetail); |
|
|
|
|
} |
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
|
|
|
|
|
if (!isExist){ |
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
} |
|
|
|
|
invoice.setInvoiceDetailList(invoiceDetailList); |
|
|
|
|
//更新原来的billInfo
|
|
|
|
|
originBillInfo.setState(invoice.getState()); |
|
|
|
|
if (StringUtils.equals(originBillInfo.getKptype(), "2")) { |
|
|
|
@ -343,9 +369,28 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
billInfoMapper.updateBillInfo(originBillInfo); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
log.info("推送订单信息,id:{}", originBillInfo.getId()); |
|
|
|
|
billInfoService.pushBillInfo(originBillInfo.getId()); |
|
|
|
|
InvoiceBack queryInvoiceBack = new InvoiceBack(); |
|
|
|
|
queryInvoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); |
|
|
|
|
queryInvoiceBack.setIdentity(companyservice.getIdentity()); |
|
|
|
|
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectInvoiceBackList(queryInvoiceBack); |
|
|
|
|
if (CollectionUtils.isEmpty(invoiceBackList)){ |
|
|
|
|
InvoiceBack invoiceBack = new InvoiceBack(); |
|
|
|
|
invoiceBack.setUpdateTime(new Date()); |
|
|
|
|
invoiceBack.setCreateTime(new Date()); |
|
|
|
|
invoiceBack.setId(IdUtil.randomUUID()); |
|
|
|
|
invoiceBack.setSystemOrderno(IdUtil.randomUUID()); |
|
|
|
|
invoiceBack.setStatus("1"); |
|
|
|
|
invoiceBack.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceBack.setBackMsg(""); |
|
|
|
|
invoiceBack.setBackUrl(""); |
|
|
|
|
invoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); |
|
|
|
|
invoiceBack.setStatus("0"); |
|
|
|
|
invoiceBack.setCreateTime(new Date()); |
|
|
|
|
invoiceBackMapper.insertInvoiceBack(invoiceBack); |
|
|
|
|
callBackAisino(invoiceBack,"",companyservice.getIdentity(),invoice); |
|
|
|
|
}else { |
|
|
|
|
callBackAisino(invoiceBackList.get(0),"",companyservice.getIdentity(),invoice); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("推送订单信息失败id:{}", originBillInfo.getId(), e); |
|
|
|
@ -446,4 +491,53 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void callBackAisino(InvoiceBack invoiceBack, String callBackUrl, String identity,Invoice invoice) { |
|
|
|
|
|
|
|
|
|
Long id = invoice.getId(); |
|
|
|
|
|
|
|
|
|
// 回调地址获取
|
|
|
|
|
if (StrUtil.isEmpty(callBackUrl)) { |
|
|
|
|
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())) { |
|
|
|
|
callBackUrl = secretIdProp.getValue(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
log.info("【控制台】发票回调接口,发送数据开始,id={},callBackUrl={},param={}", id, callBackUrl, JSONUtil.toJsonStr(invoice)); |
|
|
|
|
String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice)); |
|
|
|
|
log.info("【控制台】发票回调接口,发送数据结束,id={},接口返回信息={}", id, result); |
|
|
|
|
|
|
|
|
|
cn.hutool.json.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("2"); |
|
|
|
|
invoiceBack.setUpdateTime(new Date()); |
|
|
|
|
invoiceBack.setBackMsg(status + message != null ? message.substring(0, Math.min(message.length(), 200)) : ""); |
|
|
|
|
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("【控制台】发票回调接口,发送数据异常,id={},e={}", id,e); |
|
|
|
|
invoiceBack.setStatus("2"); |
|
|
|
|
invoiceBack.setBackMsg("发送数据异常!"); |
|
|
|
|
invoiceBackMapper.updateInvoiceBack(invoiceBack); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|