Compare commits

..

2 Commits

  1. 293
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ByInspurServiceImpl.java

@ -327,9 +327,9 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi
// TODO: 2023/10/8 数电
// TODO kk:2024/7/8 寿仙谷定制 去掉文件流
// 订单请求流水号
queryBody.put("DDQQLSH", billInfo.getSystemOrderno());
/*// 提取码
@ -475,7 +475,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi
queryBody.put("NSRSBH", companyservice.getSellertax());
queryBody.put("DDQQLSH", originBillInfo.getSystemOrderno());
// TODO kk:2024/7/8 寿仙谷定制 不需要文件流
@ -653,7 +653,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi
}
}
// end
debugLog("断点13", uuid, timestamp);
if (invoice.getId() != null) {
@ -1197,14 +1197,293 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi
@Override
public HXResponse queryInvoiceList(QueryInvoiceListDTO queryInvoiceList, Companyservice companyservice) {
return null;
}
@Override
public HXResponse findReadInfoByHzqrdbh(BillInfo billInfo, Companyservice companyservice) {
return null;
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();
return new HXResponse("9999", "系统异常!");
}
// 判断外层报文是否成功
if (queryResult.isError()) {
return new HXResponse("9999", "未查询到发票结果");
}
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("9999", queryResultDTO.getZTXX());
}
List<DDFPZXX> ddfpzxxes = queryResultDTO.getDDFPZXX();
if (ddfpzxxes.size() > 1) {
return new HXResponse("9999", "一次只能查询一张发票");
}
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) {
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));
return new HXResponse("9999", "日期处理错误,请联系管理员!");
}
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)) {
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())); // 计算不含税金额
}
// tempDetail.setTspz(ddmxxx.getts); // 特殊票种
invoiceDetailList.add(tempDetail);
}
invoice.setInvoiceDetailList(invoiceDetailList);
invoiceMapper.batchInvoiceDetail(invoiceDetailList);
HXResponse response = new HXResponse("0000", "查询成功");
response.put("data", invoice);
return response;
}
/**
* 简税和金财数科 发票类型互换
*
* @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;
}
@Override
public HXResponse queryInvoiceUseInfo(JSONObject decryptResult, Companyservice companyservice) {
return null;
@ -3348,7 +3627,7 @@ public class ElephantInvoiceApiV6ByInspurServiceImpl implements IInvoiceApiServi
// 订单请求流水号
queryBody.put("DDQQLSH", billInfo.getSystemOrderno());
/*// 提取码
queryBody.put("TQM", "0");

Loading…
Cancel
Save