|
|
|
@ -1247,6 +1247,135 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
return parseResult(dxhyInterfaceResponse); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HXResponse findReadInfoByHzqrdbh(BillInfo billInfo, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
JSONObject queryBody = new JSONObject(); |
|
|
|
|
queryBody.put("NSRSBH", companyservice.getSellertax()); |
|
|
|
|
queryBody.put("HZQRDBH", billInfo.getRequestId()); |
|
|
|
|
|
|
|
|
|
AjaxResult queryResult = null; |
|
|
|
|
try { |
|
|
|
|
queryResult = ElephantUtils.sendRequestWithoutTokenV6New(ElephantConstantsV6.QUERY_INVOICE_LOCALHOST, ElephantConstantsV6.QUERY_INVOICE_METHOD, JSONUtil.parse(queryBody), companyservice); |
|
|
|
|
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { |
|
|
|
|
log.error("【销项发票】【大象接口】【发票开具】发票请求异常,请求报文{},销方信息{}", JSONUtil.parse(queryBody).toString(), JSONObject.toJSONString(companyservice)); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
throw new JianshuiServiceException("系统异常!"); |
|
|
|
|
} |
|
|
|
|
// 判断外层报文是否成功
|
|
|
|
|
if (queryResult.isError()) { |
|
|
|
|
throw new JianshuiServiceException(queryResult.getMsg()); |
|
|
|
|
} |
|
|
|
|
JSONObject contentJson = queryResult.getJsonData(); |
|
|
|
|
ElephantInvoiceQueryResultDTO queryResultDTO = contentJson.toJavaObject(ElephantInvoiceQueryResultDTO.class); |
|
|
|
|
String ztdm = queryResultDTO.getZTDM(); |
|
|
|
|
if (!StringUtils.equals("000000", ztdm) && !StringUtils.equals("002000", ztdm)) { |
|
|
|
|
Invoice tempInvoice = new Invoice(); |
|
|
|
|
tempInvoice.setInvoiceMsg(queryResultDTO.getZTXX()); |
|
|
|
|
if (billInfo.getSystemOrderno() != null) { |
|
|
|
|
tempInvoice.setSystemOrderno(billInfo.getSystemOrderno()); |
|
|
|
|
} |
|
|
|
|
if (billInfo.getOutTradeOrderno() != null) { |
|
|
|
|
tempInvoice.setOutTradeOrderno(billInfo.getOutTradeOrderno()); |
|
|
|
|
} |
|
|
|
|
if (billInfo.getFpqqlsh() != null) { |
|
|
|
|
tempInvoice.setFpqqlsh(billInfo.getFpqqlsh()); |
|
|
|
|
} |
|
|
|
|
return new HXResponse(queryResultDTO.getZTXX(), tempInvoice); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<DDFPZXX> ddfpzxxes = queryResultDTO.getDDFPZXX(); |
|
|
|
|
if (ddfpzxxes.size() > 1) { |
|
|
|
|
HXResponse response = new HXResponse("9996", "一次只能查询一张发票"); |
|
|
|
|
return response; |
|
|
|
|
} |
|
|
|
|
DDFPZXX ddfpzxx = ddfpzxxes.get(0); |
|
|
|
|
DDFPXX ddfpxx = ddfpzxx.getDDFPXX(); |
|
|
|
|
Invoice invoice = invoiceMapper.selectByFpdmFphm(companyservice.getCompanyid(), ddfpxx.getFPDM(), ddfpxx.getFPHM()); |
|
|
|
|
if (invoice == null){ |
|
|
|
|
throw new JianshuiServiceException("返回结果未在该系统中查询到发票信息"); |
|
|
|
|
} |
|
|
|
|
// 上传文件到oss
|
|
|
|
|
String defaultStorage = configService.selectConfigByKey("default_storage"); |
|
|
|
|
|
|
|
|
|
// 2023/12/4 存储文件流至数据库,方便迁移,提供文件下载接口。 start
|
|
|
|
|
// invoiceFileMapper
|
|
|
|
|
String fileId = IdUtils.randomUUID(); |
|
|
|
|
String fileName = invoice.getFphm(); |
|
|
|
|
|
|
|
|
|
if (ddfpxx.getPDFZJL() != null && StrUtil.isNotEmpty(ddfpxx.getPDFZJL())) { |
|
|
|
|
String fphm = ddfpxx.getFPHM(); |
|
|
|
|
if (StrUtil.isNotEmpty(fphm)) { |
|
|
|
|
Environment environment = SpringUtils.getBean(Environment.class); |
|
|
|
|
|
|
|
|
|
String type = environment.getProperty(Constants.INVOICE_FILE_SAVE_TYPE); |
|
|
|
|
|
|
|
|
|
//配置文件存储类型0为数据库存储
|
|
|
|
|
if (Constants.STRING_0.equals(type)) { |
|
|
|
|
saveFileUseDb(invoice, fileId, fileName, companyservice, ddfpxx); |
|
|
|
|
//配置文件存储类型1为oss存储
|
|
|
|
|
} else if (Constants.STRING_1.equals(type)) { |
|
|
|
|
saveFileUseOss(defaultStorage, invoice, ddfpxx); |
|
|
|
|
//配置文件存储类型2为本地存储
|
|
|
|
|
} else if (Constants.STRING_2.equals(type)) { |
|
|
|
|
saveFileUseLocal(invoice, ddfpxx); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (invoice.getId() != null) { |
|
|
|
|
invoiceMapper.updateInvoice(invoice); |
|
|
|
|
} else { |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO 处理发票详情
|
|
|
|
|
invoiceMapper.deleteInvoiceDetailByInvoiceId(invoice.getId()); // 删除发票明细
|
|
|
|
|
List<InvoiceDetail> invoiceDetailList = new ArrayList<>(); |
|
|
|
|
List<DDMXXX> ddmxxxList = ddfpzxx.getDDMXXX(); |
|
|
|
|
for (int i = 0; i < ddmxxxList.size(); i++) { |
|
|
|
|
DDMXXX ddmxxx = ddmxxxList.get(i); |
|
|
|
|
InvoiceDetail tempDetail = new InvoiceDetail(); |
|
|
|
|
// tempDetail.setId(); // id
|
|
|
|
|
tempDetail.setInvoiceId(invoice.getId()); // 发票主键
|
|
|
|
|
tempDetail.setIndex(Long.parseLong(StringUtils.isEmpty(ddmxxx.getXH()) ? "" : ddmxxx.getXH())); // 顺序
|
|
|
|
|
tempDetail.setGoodName(StringUtils.isEmpty(ddmxxx.getXMMC()) ? "" : ddmxxx.getXMMC()); // 商品名称
|
|
|
|
|
tempDetail.setNum(ddmxxx.getSPSL()); // 商品数量
|
|
|
|
|
tempDetail.setPrice(new BigDecimal(StringUtils.isEmpty(ddmxxx.getDJ()) ? "0" : ddmxxx.getDJ())); // 商品单价
|
|
|
|
|
tempDetail.setHsbz(Integer.parseInt(StringUtils.isEmpty(ddmxxx.getHSBZ()) ? "0" : ddmxxx.getHSBZ())); // 含税标志
|
|
|
|
|
tempDetail.setTaxrate(new BigDecimal(StringUtils.isEmpty(ddmxxx.getSL()) ? "0" : ddmxxx.getSL())); // 税率
|
|
|
|
|
tempDetail.setSpec(StringUtils.isEmpty(ddmxxx.getGGXH()) ? "" : ddmxxx.getGGXH()); // 规格型号
|
|
|
|
|
tempDetail.setUnit(StringUtils.isEmpty(ddmxxx.getDW()) ? "" : ddmxxx.getDW()); // 单位
|
|
|
|
|
tempDetail.setSpbm(StringUtils.isEmpty(ddmxxx.getSPBM()) ? "" : ddmxxx.getSPBM()); // 税收分类编码
|
|
|
|
|
tempDetail.setBmbbh(ddfpxx.getBMBBBH()); // 商品编码版本号
|
|
|
|
|
tempDetail.setZsbm(StringUtils.isEmpty(ddmxxx.getZXBM()) ? "" : ddmxxx.getZXBM()); // 自行编码
|
|
|
|
|
tempDetail.setFphxz(Integer.parseInt(StringUtils.isEmpty(ddmxxx.getFPHXZ()) ? "0" : ddmxxx.getFPHXZ())); // 发票行性质
|
|
|
|
|
tempDetail.setYhzcbs(Integer.parseInt(StringUtils.isEmpty(ddmxxx.getYHZCBS()) ? "0" : ddmxxx.getYHZCBS())); // 优惠政策标识
|
|
|
|
|
tempDetail.setZzstsgl(StringUtils.isEmpty(ddmxxx.getZZSTSGL()) ? "" : ddmxxx.getZZSTSGL()); // 增值税特殊管理
|
|
|
|
|
tempDetail.setLslbs(StringUtils.isEmpty(ddmxxx.getLSLBS()) ? "" : ddmxxx.getLSLBS()); // 零税率标识
|
|
|
|
|
if (ddmxxx.getKCE() != null && !"".equals(ddmxxx.getKCE())) { |
|
|
|
|
tempDetail.setKce(new BigDecimal(ddmxxx.getKCE())); // 扣除额
|
|
|
|
|
} |
|
|
|
|
tempDetail.setTax(new BigDecimal(ddmxxx.getSE())); // 税额
|
|
|
|
|
if (tempDetail.getHsbz() == 0) { |
|
|
|
|
tempDetail.setTaxfreeamt(new BigDecimal(ddmxxx.getJE())); // 不含税金额
|
|
|
|
|
// 计算含税金额
|
|
|
|
|
tempDetail.setTaxamt(tempDetail.getTaxfreeamt().add(tempDetail.getTax())); |
|
|
|
|
} else { |
|
|
|
|
tempDetail.setTaxamt(new BigDecimal(ddmxxx.getJE())); // 含税金额
|
|
|
|
|
tempDetail.setTaxfreeamt(tempDetail.getTaxamt().subtract(tempDetail.getTax())); // 计算不含税金额
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
invoiceDetailList.add(tempDetail); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
invoice.setInvoiceDetailList(invoiceDetailList); |
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
|
|
|
|
|
HXResponse response = new HXResponse("0000", "查询成功", invoice); |
|
|
|
|
return response; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 红字确认单列表查询(数电专用) |
|
|
|
|