|
|
|
@ -1291,13 +1291,140 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
} |
|
|
|
|
DDFPZXX ddfpzxx = ddfpzxxes.get(0); |
|
|
|
|
DDFPXX ddfpxx = ddfpzxx.getDDFPXX(); |
|
|
|
|
|
|
|
|
|
// billinfo插入
|
|
|
|
|
QueryWrapper<BillInfo> myQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
myQueryWrapper.eq("company_id", companyservice.getCompanyid()); |
|
|
|
|
myQueryWrapper.eq("system_orderno", ddfpxx.getDDH()); |
|
|
|
|
BillInfo originBlueBillInfo = billInfoMapper.selectOne(myQueryWrapper); |
|
|
|
|
if (originBlueBillInfo != null){ |
|
|
|
|
originBlueBillInfo = new BillInfo(); |
|
|
|
|
originBlueBillInfo.setCompanyId(companyservice.getCompanyid()); |
|
|
|
|
originBlueBillInfo.setSystemOrderno(ddfpxx.getDDH()); |
|
|
|
|
originBlueBillInfo.setOutTradeOrderno(ddfpxx.getDDH()); |
|
|
|
|
originBlueBillInfo.setFpqqlsh(ddfpxx.getDDQQLSH()); |
|
|
|
|
originBlueBillInfo.setInvoiceType(getInvoiceTypeNew(ddfpxx.getFPLXDM())); |
|
|
|
|
originBlueBillInfo.setBuyerName(ddfpxx.getGMFMC()); |
|
|
|
|
originBlueBillInfo.setSellerName(ddfpxx.getXHFMC()); |
|
|
|
|
originBlueBillInfo.setSellerTaxnum(ddfpxx.getXHFSBH()); |
|
|
|
|
originBlueBillInfo.setMessage(ddfpxx.getBZ()); |
|
|
|
|
originBlueBillInfo.setClerk(ddfpxx.getKPR()); |
|
|
|
|
originBlueBillInfo.setSource("2"); |
|
|
|
|
originBlueBillInfo.setServiceSupplierKey("服务公司"); |
|
|
|
|
billInfoMapper.updateBillInfo(originBlueBillInfo); |
|
|
|
|
}else { |
|
|
|
|
originBlueBillInfo = new BillInfo(); |
|
|
|
|
originBlueBillInfo.setCompanyId(companyservice.getCompanyid()); |
|
|
|
|
originBlueBillInfo.setSystemOrderno(ddfpxx.getDDH()); |
|
|
|
|
originBlueBillInfo.setOutTradeOrderno(ddfpxx.getDDH()); |
|
|
|
|
originBlueBillInfo.setFpqqlsh(ddfpxx.getDDQQLSH()); |
|
|
|
|
originBlueBillInfo.setInvoiceType(getInvoiceTypeNew(ddfpxx.getFPLXDM())); |
|
|
|
|
originBlueBillInfo.setBuyerName(ddfpxx.getGMFMC()); |
|
|
|
|
originBlueBillInfo.setSellerName(ddfpxx.getXHFMC()); |
|
|
|
|
originBlueBillInfo.setSellerTaxnum(ddfpxx.getXHFSBH()); |
|
|
|
|
originBlueBillInfo.setMessage(ddfpxx.getBZ()); |
|
|
|
|
originBlueBillInfo.setClerk(ddfpxx.getKPR()); |
|
|
|
|
originBlueBillInfo.setSource("2"); |
|
|
|
|
originBlueBillInfo.setServiceSupplierKey("服务公司"); |
|
|
|
|
billInfoMapper.insertBillInfo(originBlueBillInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Invoice invoice = invoiceMapper.selectByFpdmFphm(companyservice.getCompanyid(), ddfpxx.getFPDM(), ddfpxx.getFPHM()); |
|
|
|
|
if (invoice == null){ |
|
|
|
|
throw new JianshuiServiceException("返回结果未在该系统中查询到发票信息"); |
|
|
|
|
if (invoice == null) { |
|
|
|
|
invoice = new Invoice(); |
|
|
|
|
} |
|
|
|
|
invoice.setBillInfoId(originBlueBillInfo.getId()); |
|
|
|
|
// "销方ID"
|
|
|
|
|
invoice.setCompanyId(companyservice.getCompanyid()); |
|
|
|
|
// "系统订单号"
|
|
|
|
|
invoice.setSystemOrderno(ddfpxx.getDDH()); |
|
|
|
|
invoice.setOutTradeOrderno(ddfpxx.getDDH()); // "客户订单号"
|
|
|
|
|
invoice.setFpqqlsh(ddfpxx.getDDQQLSH()); // "流水号"
|
|
|
|
|
invoice.setInvoiceType(originBlueBillInfo.getInvoiceType()); // "发票种类"
|
|
|
|
|
|
|
|
|
|
// 处理开票信息
|
|
|
|
|
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(); // "开票状态" TODO 处理开票状态
|
|
|
|
|
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(); |
|
|
|
|
log.error("【销项发票】【大象接口】【订单查询】 发票格式化日期错误。请求报文{},大象返回报文{},原始报文{}", queryBody.toJSONString(), queryResult.toString(), JSONObject.toJSONString(billInfo)); |
|
|
|
|
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(); |
|
|
|
@ -1328,7 +1455,6 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
} else { |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO 处理发票详情
|
|
|
|
|
invoiceMapper.deleteInvoiceDetailByInvoiceId(invoice.getId()); // 删除发票明细
|
|
|
|
|
List<InvoiceDetail> invoiceDetailList = new ArrayList<>(); |
|
|
|
@ -1365,6 +1491,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
tempDetail.setTaxamt(new BigDecimal(ddmxxx.getJE())); // 含税金额
|
|
|
|
|
tempDetail.setTaxfreeamt(tempDetail.getTaxamt().subtract(tempDetail.getTax())); // 计算不含税金额
|
|
|
|
|
} |
|
|
|
|
// tempDetail.setTspz(ddmxxx.getts); // 特殊票种
|
|
|
|
|
|
|
|
|
|
invoiceDetailList.add(tempDetail); |
|
|
|
|
} |
|
|
|
@ -1377,6 +1504,32 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 简税和金财数科 发票类型互换 |
|
|
|
|
* |
|
|
|
|
* @param invoiceType 发票种类 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private String getInvoiceTypeNew(String invoiceType) { |
|
|
|
|
// 非一下种类发票
|
|
|
|
|
String result = "p"; |
|
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
|
map.put("10", "p"); //电子增值税普通发票 10
|
|
|
|
|
map.put("04", "c"); //增值税普通发票 04
|
|
|
|
|
map.put("01", "s"); //增值税专用发票 01
|
|
|
|
|
map.put("08", "b"); //增值税电子专用发票 08
|
|
|
|
|
map.put("87", "j"); //机动车发票 87
|
|
|
|
|
map.put("88", "u"); //二手车发票 88
|
|
|
|
|
|
|
|
|
|
map.put("82", "q"); //全电普票
|
|
|
|
|
map.put("81", "r"); //全电专票
|
|
|
|
|
String resp = map.get(invoiceType); |
|
|
|
|
result = StringUtils.isNotEmpty(resp) ? resp : result; |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 红字确认单列表查询(数电专用) |
|
|
|
|
*/ |
|
|
|
|