|
|
|
@ -1165,7 +1165,25 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return new HXResponse("009999", "系统异常!"); |
|
|
|
|
} |
|
|
|
|
HXResponse hxResponse = parseResult(dxhyInterfaceResponse); |
|
|
|
|
|
|
|
|
|
if("000000".equals(hxResponse.get("code"))){ |
|
|
|
|
cn.hutool.json.JSONObject data = JSONUtil.parseObj(hxResponse.getData()); |
|
|
|
|
String bh = data.get("hzfpxxqrdbh") != null ? data.get("hzfpxxqrdbh").toString() : ""; |
|
|
|
|
if(StrUtil.isNotEmpty(bh)){ |
|
|
|
|
InvoiceAllApiLog allApiLog = new InvoiceAllApiLog(); |
|
|
|
|
allApiLog.setUrl(WebServiceConstant.ADD_RED_INVOICE_QRD); |
|
|
|
|
allApiLog.setSendMsg(JSONUtil.toJsonStr(decryptResult)); |
|
|
|
|
// 添加对应uuid
|
|
|
|
|
allApiLog.setResultMsg(JSONUtil.toJsonStr(data)); |
|
|
|
|
allApiLog.setCompany(companyservice.getSellertax()); |
|
|
|
|
allApiLog.setIdentityId(companyservice.getIdentity()); |
|
|
|
|
allApiLog.setRequestId(bh); |
|
|
|
|
allApiLog.setCreateTime(new Date()); |
|
|
|
|
allApiLog.setCompanyName("大象V6"); |
|
|
|
|
allApiLogMapper.insertInvoiceAllApiLog(allApiLog); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return parseResult(dxhyInterfaceResponse); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2301,6 +2319,27 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
|
|
|
|
|
return response; |
|
|
|
|
|
|
|
|
|
}else if (WebServiceConstant.ADD_RED_INVOICE_QRD.equals(finalServiceId)) { |
|
|
|
|
// 红字发票开具-确认单编号方式
|
|
|
|
|
// TODO kk:2024/2/26 调用订单查询接口-不入库
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put("HZQRDBH",requestId); |
|
|
|
|
jsonObject.put("NSRSBH",allApiLog.getCompany()); |
|
|
|
|
|
|
|
|
|
DxhyInterfaceResponse dxhyInterfaceResponse = null; |
|
|
|
|
try { |
|
|
|
|
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_INVOICE_LOCALHOST |
|
|
|
|
, ElephantConstantsV6.QUERY_INVOICE_METHOD, JSONUtil.parse(jsonObject), companyservice); |
|
|
|
|
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { |
|
|
|
|
log.error("【销项发票】【大象接口】【数电】【红字确认单申请-查询红票信息】发票请求异常,请求报文{},销方信息{}", JSONUtil.parse(jsonObject), JSONObject.toJSONString(companyservice)); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return new HXResponse("009999", "系统异常!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HXResponse hxResponse = parseResult(dxhyInterfaceResponse); |
|
|
|
|
hxResponse = parseDxhyRes(hxResponse,companyservice); |
|
|
|
|
return hxResponse; |
|
|
|
|
|
|
|
|
|
}else if (WebServiceConstant.CXHZFPXXQRD.equals(finalServiceId)) { |
|
|
|
|
// 查询红字信息表
|
|
|
|
|
|
|
|
|
@ -2358,6 +2397,200 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 转换大象返回报文为简税报文 */ |
|
|
|
|
private HXResponse parseDxhyRes(HXResponse hxResponse,Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
// 判断外层报文是否成功
|
|
|
|
|
if (!hxResponse.getCode().equals("000000")) { |
|
|
|
|
throw new JianshuiServiceException(hxResponse.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONObject contentJson = JSONObject.parseObject(hxResponse.getData().toString()); |
|
|
|
|
|
|
|
|
|
String ztdm = hxResponse.getCode(); |
|
|
|
|
if (!StringUtils.equals("000000", ztdm) && !StringUtils.equals("002000", ztdm)) { |
|
|
|
|
return new HXResponse(hxResponse.getCode(), hxResponse.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ElephantInvoiceQueryResultDTO queryResultDTO = contentJson.toJavaObject(ElephantInvoiceQueryResultDTO.class); |
|
|
|
|
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 = new Invoice(); |
|
|
|
|
|
|
|
|
|
// 处理开票信息
|
|
|
|
|
String ddzt = ddfpxx.getDDZT(); // 000000 成功,001000 订单处理成功 001999开票失败
|
|
|
|
|
// 021002 020111
|
|
|
|
|
// 开票状态: 2 :开票完成( 最终状态),其他状态分别为: 20:开票中; 21:开票成功签章中;22:开票失败;24: 开票成功签章失败;3: 发票已作废31
|
|
|
|
|
if (StringUtils.equals(ddzt, "030000")) { |
|
|
|
|
invoice.setState(2); // "开票状态"
|
|
|
|
|
} else if (StringUtils.equals(ddzt, "031999")) { |
|
|
|
|
invoice.setState(22); // "开票状态"
|
|
|
|
|
} else if (StringUtils.equals(ddzt, "032000")) { |
|
|
|
|
invoice.setState(20); // "开票状态"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (StringUtils.equals(ddzt, "003000")) { |
|
|
|
|
invoice.setState(3); // "开票状态"
|
|
|
|
|
} else if (StringUtils.equals(ddzt, "004000")) { |
|
|
|
|
invoice.setState(99); // "开票状态"
|
|
|
|
|
} else if (StringUtils.equals(ddzt, "005000")) { |
|
|
|
|
invoice.setState(25); // "开票状态"
|
|
|
|
|
} else if (StringUtils.equals(ddzt, "001999")) { |
|
|
|
|
invoice.setState(22); // "开票状态"
|
|
|
|
|
} else { |
|
|
|
|
invoice.setState(20); // "开票状态"
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// invoice.setState(); // "开票状态"
|
|
|
|
|
invoice.setcInvoiceid("not used"); // 发票c_invoiceid */
|
|
|
|
|
invoice.setFpdm(ddfpxx.getFPDM()); // "发票代码"
|
|
|
|
|
invoice.setFphm(ddfpxx.getFPHM()); // "发票号码"
|
|
|
|
|
try { |
|
|
|
|
String kprq = ddfpxx.getKPRQ(); |
|
|
|
|
if (StringUtils.isNotEmpty(kprq)) { |
|
|
|
|
invoice.setKprq(DateUtils.parseDate(kprq, "yyyy-MM-dd HH:mm:ss")); // "开票日期", width = 30, dateFormat = "yyyy-MM-dd"
|
|
|
|
|
} |
|
|
|
|
} catch (ParseException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
throw new JianshuiServiceException("日期处理错误,请联系管理员!"); |
|
|
|
|
} |
|
|
|
|
invoice.setBuyerName(ddfpxx.getGMFMC()); // "购方名称"
|
|
|
|
|
invoice.setBuyerTaxnum(ddfpxx.getGMFSBH()); // "购方税号"
|
|
|
|
|
invoice.setBuyerAddress(ddfpxx.getGMFDZ()); // "购方地址"
|
|
|
|
|
invoice.setBuyerTelephone(ddfpxx.getGMFDH()); // "购方电话"
|
|
|
|
|
invoice.setBuyerAccount(ddfpxx.getGMFYH() + ddfpxx.getGMFZH()); // "购方开户行及账户"
|
|
|
|
|
invoice.setSellerName(ddfpxx.getXHFMC()); // "销方名称"
|
|
|
|
|
invoice.setSellerTaxnum(ddfpxx.getXHFSBH()); // "销方税号"
|
|
|
|
|
invoice.setSellerAddress(ddfpxx.getXHFDZ()); // "销方地址"
|
|
|
|
|
invoice.setSellerTelephone(ddfpxx.getXHFDH()); // "销方电话"
|
|
|
|
|
invoice.setSellerAccount(ddfpxx.getXHFYH() + ddfpxx.getXHFZH()); // "销方开户行及账户"
|
|
|
|
|
invoice.setMessage(ddfpxx.getBZ()); // "备注"
|
|
|
|
|
invoice.setClerk(ddfpxx.getKPR()); // "开票人"
|
|
|
|
|
invoice.setPayee(ddfpxx.getSKR()); // "收款人"
|
|
|
|
|
invoice.setChecker(ddfpxx.getFHR()); // "复核人"
|
|
|
|
|
invoice.setTaxfreeamt(new BigDecimal(ddfpxx.getHJJE())); // "不含税金额"
|
|
|
|
|
invoice.setTax(new BigDecimal(ddfpxx.getHJSE())); // "税额"
|
|
|
|
|
invoice.setTaxamt(new BigDecimal(ddfpxx.getJSHJ())); // "含税金额"
|
|
|
|
|
invoice.setOriginFpdm(ddfpxx.getYFPDM()); // "原发票代码"
|
|
|
|
|
invoice.setOriginFphm(ddfpxx.getYFPHM()); // "原发票号码"
|
|
|
|
|
invoice.setJym(ddfpxx.getJYM()); // "校验码"
|
|
|
|
|
invoice.setQrCode(ddfpxx.getDTM()); // "二维码" 动态码是二维码吗?
|
|
|
|
|
invoice.setMachineCode(ddfpxx.getJQBH()); // "税控设备号"
|
|
|
|
|
// invoice.setCipherText(); // "发票密文"
|
|
|
|
|
// invoice.setInvoicePdfUrl(); // "发票 pdf 地址"
|
|
|
|
|
// invoice.setInvoiceJpgUrl(); // "发票详情地址"
|
|
|
|
|
invoice.setInvoiceMsg(ddfpxx.getDDZTXX()); // "开票信息,成功或者失败的信息"
|
|
|
|
|
invoice.setInvoiceResultMsg(ddfpxx.getDDZTXX()); // "结果信息"
|
|
|
|
|
String oilFlag = "0"; |
|
|
|
|
String qdbz = "0"; |
|
|
|
|
if (StringUtils.equals(ddfpxx.getQDBZ(), "4")) { |
|
|
|
|
oilFlag = "1"; |
|
|
|
|
} |
|
|
|
|
if (StringUtils.equals(ddfpxx.getQDBZ(), "1")) { |
|
|
|
|
qdbz = "1"; |
|
|
|
|
} |
|
|
|
|
invoice.setProductOilFlag(oilFlag); // "成品油标志"
|
|
|
|
|
invoice.setQdbz(qdbz); // "清单标志"
|
|
|
|
|
// invoice.setcOfdUrl(); // "ofdUrl"
|
|
|
|
|
invoice.setFjh(ddfpxx.getKPJH()); // "分机号"
|
|
|
|
|
invoice.setTerminalNumber(ddfpxx.getKPZD()); // "终端号"
|
|
|
|
|
invoice.setJqbh(ddfpxx.getKPZD()); |
|
|
|
|
// 上传文件到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)){ |
|
|
|
|
InvoiceFile invoiceFile = new InvoiceFile(); |
|
|
|
|
invoiceFile.setFphm(ddfpxx.getFPHM()); |
|
|
|
|
List<InvoiceFile> invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); |
|
|
|
|
if(invoiceFileList != null && invoiceFileList.size() > 0){ |
|
|
|
|
invoiceFile = invoiceFileList.get(0); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileName(fileName); |
|
|
|
|
invoiceFile.setCreateTime(new Date()); |
|
|
|
|
invoiceFile.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceFile.setTax(companyservice.getSellertax()); |
|
|
|
|
fileId = invoiceFile.getFileId(); |
|
|
|
|
fileName = invoiceFile.getFileName(); |
|
|
|
|
invoiceFileMapper.updateInvoiceFile(invoiceFile); |
|
|
|
|
}else{ |
|
|
|
|
invoiceFile.setId(fileId); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileId(fileId); |
|
|
|
|
invoiceFile.setFileName(fileName); |
|
|
|
|
invoiceFile.setCreateTime(new Date()); |
|
|
|
|
invoiceFile.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceFile.setTax(companyservice.getSellertax()); |
|
|
|
|
invoiceFileMapper.insertInvoiceFile(invoiceFile); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流
|
|
|
|
|
invoice.setInvoicePdfUrl(ELE_File_URL + fileId); |
|
|
|
|
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); |
|
|
|
|
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); |
|
|
|
|
if (secretIdProp != null) { |
|
|
|
|
invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// end
|
|
|
|
|
|
|
|
|
|
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())); // 计算不含税金额
|
|
|
|
|
} |
|
|
|
|
// tempDetail.setTspz(ddmxxx.getts); // 特殊票种
|
|
|
|
|
|
|
|
|
|
invoiceDetailList.add(tempDetail); |
|
|
|
|
} |
|
|
|
|
invoice.setInvoiceDetailList(invoiceDetailList); |
|
|
|
|
HXResponse response = new HXResponse("0000", "查询成功", invoice); |
|
|
|
|
return response; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private HXResponse convertToJcData(HZXXLIST hzxxlist) { |
|
|
|
|
HZQRXXLIST hzqrxxlist = hzxxlist.getHZQRXXLIST(); |
|
|
|
|
List<Redinfo> redinfos = new ArrayList<>(hzqrxxlist.getTOTAL()); |
|
|
|
|