feature: 红票查询

jianshui-ui
xingze 11 months ago
parent cee4cf640c
commit a885ece097
  1. 53
      jianshui-admin/src/main/java/com/jianshui/api/controller/http/invoice/v1/InvoiceController.java
  2. 10
      jianshui-invoice/src/main/java/com/jianshui/invoice/domain/BillInfo.java
  3. 4
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/IInvoiceApiService.java
  4. 129
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java

@ -340,6 +340,59 @@ public class InvoiceController {
return invoiceResponseService.response(result, companyservice, "query");
}
/**
* 红票查询
* @param request
* @param identity
* @return
* @throws Exception
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.Void", example = "1130", required = true),
@ApiImplicitParam(name = "order", value = "请求体", dataType = "java.lang.Void", required = true)})
@PostMapping({"/api/invoice/v1/queryRed", "/api/invoice/v1/queryRed/{identity}", "/invoice/queryRedInvoice"})
public Object queryReadInvoice(HttpServletRequest request, String identity) throws Exception {
if (StringUtils.isEmpty(identity)) {
return AjaxResult.error(ErrorCode.EMPTY_IDENTITY);
}
Companyservice companyservice = iCompanyserviceService.selectCompanyserviceByIdentity(identity);
if (companyservice == null) {
return AjaxResult.error(ErrorCode.COMPANY_NOT_FOUND);
}
// 获得入口报文适配器
String requestAdapterKey = serviceManageService.getRequestAdapterKey("invoice", companyservice.getCompanyid());
IInvoiceRequestService invoiceRequestService = invoiceRequestFactory.getService(requestAdapterKey);
JSONObject decryptResult = invoiceRequestService.decrypt(request, companyservice, "");
BillInfo billInfo = decryptResult.toJavaObject(BillInfo.class);
if (billInfo == null) {
throw new JianshuiParamErrorException(ErrorCode.ERROR_PARAMS, companyservice, "invoice");
}
// 获得请求实例,并且进行扣费
List<Object> result = new ArrayList<>();
String serviceKey = serviceManageService.getCompanyServiceSupplier("invoice", companyservice.getCompanyid());
serviceManageService.companyConsume("invoice", companyservice.getCompanyid());
billInfo.setServiceSupplierKey(serviceKey);
IInvoiceApiService invoiceService = invoiceServiceFactory.getService(serviceKey);
HXResponse tempResult = invoiceService.findReadInfoByHzqrdbh(billInfo, companyservice);
result.add(tempResult.getData());
HXResponse hxResponse = new HXResponse("0000", "查询成功", result);
String responseAdapterKey = serviceManageService.getResponseAdapterKey("invoice", companyservice.getCompanyid());
IInvoiceResponseService invoiceResponseService = invoiceResponseFactory.getService(responseAdapterKey);
return invoiceResponseService.response(hxResponse, companyservice, "query");
}
@ApiImplicitParams({
@ApiImplicitParam(name = "identity", value = "身份认证", dataType = "java.lang.Void", example = "1130", required = true),
@ApiImplicitParam(name = "order", value = "请求体", dataType = "java.lang.Void", required = true)})

@ -475,6 +475,8 @@ public class BillInfo extends BaseEntity
private String sfzsgfyhzh;
// 是否展示销方银行账号
private String sfzsxfyhzh;
// 红冲查询接口(红字确认单编号)
private String requestId;
/** 推送系统 */
@ -482,6 +484,14 @@ public class BillInfo extends BaseEntity
private String tsxt;
public String getRequestId() {
return requestId;
}
public void setRequestId(String requestId) {
this.requestId = requestId;
}
public String getSfzsgfyhzh() {
return sfzsgfyhzh;
}

@ -374,4 +374,8 @@ public interface IInvoiceApiService {
/** 查询发票列表 */
HXResponse queryInvoiceList(QueryInvoiceListDTO queryInvoiceList, Companyservice companyservice);
HXResponse findReadInfoByHzqrdbh(BillInfo billInfo, Companyservice companyservice);
}

@ -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;
}
/**
* 红字确认单列表查询数电专用

Loading…
Cancel
Save