From 666e024dd6be6622c08c0648a093735a03a10d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E6=98=8E=E6=85=A7?= <1191093413@qq.com> Date: Tue, 31 Oct 2023 19:54:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=A4=A7=E8=B1=A1=E7=BA=A2?= =?UTF-8?q?=E5=AD=97=E5=8F=91=E7=A5=A8=E5=BC=80=E5=85=B7=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=92=8C=E7=BA=A2=E5=AD=97=E4=BF=A1=E6=81=AF=E8=A1=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/api/elephant/ElephantRedInfo.java | 34 +++++ .../api/elephant/ElephantRedInfoDetail.java | 18 +++ .../ElephantRedInfoQueryResultDTO.java | 10 ++ .../invoice/mapper/RedinfoMapper.java | 2 + .../api/ElephantInvoiceApiV6ServiceImpl.java | 143 +++++++++++++++++- .../mapper/invoice/RedinfoMapper.xml | 4 + 6 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfo.java create mode 100644 jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoDetail.java create mode 100644 jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoQueryResultDTO.java diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfo.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfo.java new file mode 100644 index 0000000..0290c2b --- /dev/null +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfo.java @@ -0,0 +1,34 @@ +package com.jianshui.invoice.domain.dto.api.elephant; + +import lombok.Data; + +import java.util.List; + +@Data +public class ElephantRedInfo { + private String UUID; + private String HZFPXXQRDBH; + private Integer LRFSF; + private String XSFNSRSBH; + private String XSFMC; + private String GMFNSRSBH; + private String GMFMC; + private String LZFPDM; + private String LZFPHM; + private String SFZZFPBZ; + private String LZKPRQ; + private String LZHJJE; + private String LZHJSE; + private String LZFPPZDM; + private String LZFPTDYSLXDM; + private String HZCXJE; + private String HZCXSE; + private String CHYYDM; + private String HZQRXXZTDM; + private String QRRQ; + private String YKJHZFPBZ; + private String HZFPHM; + private String HZKPRQ; + private String YXBZ; + private List HZQRXXMXLIST; +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoDetail.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoDetail.java new file mode 100644 index 0000000..94b86af --- /dev/null +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoDetail.java @@ -0,0 +1,18 @@ +package com.jianshui.invoice.domain.dto.api.elephant; + +import lombok.Data; + +@Data +public class ElephantRedInfoDetail { + private Integer XH; + private String LZMXXH; + private String SPHFWSSFLHBBM; + private String XMMC; + private String GGXH; + private String DW; + private String FPSPDJ; + private String FPSPSL; + private String JE; + private String SLV; + private String SE; +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoQueryResultDTO.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoQueryResultDTO.java new file mode 100644 index 0000000..beceb45 --- /dev/null +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoQueryResultDTO.java @@ -0,0 +1,10 @@ +package com.jianshui.invoice.domain.dto.api.elephant; + +import lombok.Data; + +@Data +public class ElephantRedInfoQueryResultDTO { + private String ZTDM; + private String ZTXX; + private ElephantRedInfo DATA; +} diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/RedinfoMapper.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/RedinfoMapper.java index 00cdbc0..bfffde6 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/RedinfoMapper.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/RedinfoMapper.java @@ -93,4 +93,6 @@ public interface RedinfoMapper extends BaseMapper { * @return : java.util.List */ List findRedInfoList(FindRedWordDTO dto); + + Long getDetailId(); } diff --git a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java index 84162f9..d36b554 100644 --- a/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java +++ b/jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java @@ -10,6 +10,7 @@ import cn.hutool.json.JSONConfig; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse; import com.google.gson.Gson; @@ -60,9 +61,12 @@ import com.jianshui.system.mapper.InvoiceAllApiLogMapper; import com.jianshui.system.service.ISysConfigService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.ibatis.annotations.Lang; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; @@ -510,7 +514,7 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { debugLog("断点12", uuid, timestamp); // 上传文件到oss String defaultStorage = configService.selectConfigByKey("default_storage"); - // TODO: 2023/10/23 中交建暂时关闭 + // TODO: 2023/10/23 中交建暂时关闭 /*if (StringUtils.isNotEmpty(defaultStorage) && StringUtils.isEmpty(invoice.getInvoicePdfUrl())) { try { IStorageService service = storageFactory.getStorageInstance(defaultStorage); @@ -1067,9 +1071,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { @Override public HXResponse uploadRedInfo(Redinfo redinfo, Companyservice companyservice) { - // TODO: 2023/10/23 一步的红字上传接口 - - + // TODO: 2023/10/23 一步的红字上传接口 + + // 处理redinfo redinfo.setCompanyId(companyservice.getCompanyid()); redinfo.setSystemOrderno(IdUtils.randomSystemOrderno()); @@ -1990,10 +1994,35 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { }else if (WebServiceConstant.SQHZFPXXQRD.equals(finalServiceId)) { // 申请红字信息表 + //查询红字信息表入库信息 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Redinfo::getFpqqlsh,requestId); + Redinfo redinfo = redinfoMapper.selectOne(queryWrapper); + HXResponse hxResponse = queryRedInfoByElepant(redinfo,companyservice); + }else if (WebServiceConstant.ADD_RED_INVOICE.equals(finalServiceId)) { // 红字发票开具 + //调用大象接口获取数据入库 + QueryBillInfoDTO queryBillInfoDTO = new QueryBillInfoDTO(); + queryBillInfoDTO.setFpqqlsh(requestId); + HXResponse hxResponse = queryInvoice(queryBillInfoDTO, companyservice); + + if(StringUtils.equals("0000",hxResponse.getCode())){ + return hxResponse; + } + + //查询数据库信息并返回 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Invoice::getFpqqlsh,requestId); + queryWrapper.orderByDesc(Invoice::getId).last("limit 1"); + Invoice invoice = invoiceMapper.selectOne(queryWrapper); + + response.put("data",invoice); + + return response; + }else if (WebServiceConstant.CXHZFPXXQRD.equals(finalServiceId)) { // 查询红字信息表 @@ -2019,8 +2048,114 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { } + @Transactional(rollbackFor = Exception.class) + private HXResponse queryRedInfoByElepant(Redinfo redinfo, Companyservice companyservice) { + //返回信息 + + if (ObjectUtils.isEmpty(redinfo)){ + return new HXResponse("9998","红字信息未查询到"); + } + + //日志uuid + String uuid = UUID.randomUUID().toString(); + + //封装请求参数 + JSONObject param = new JSONObject(); + param.put("NSRSBH",companyservice.getSellertax()); + //TODO 上传红字信息表需要存入uuid + param.put("UUID",""); + param.put("XSFNSRSBH",companyservice.getSellertax()); + debugLog("红字信息表申请查询断点1",uuid,System.currentTimeMillis()); + //调用大象接口查询红字信息表明细 + AjaxResult queryResult = null; + try { + queryResult = ElephantUtils.sendRequestWithoutTokenV6New(ElephantConstantsV6.QUERY_INVOICE_LOCALHOST, ElephantConstantsV6.QUERY_INVOICE_METHOD, JSONUtil.parse(param), companyservice); + } catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { + log.error("【销项发票】【大象接口】【红字信息表申请】发票请求异常,请求报文{},销方信息{}", JSONUtil.parse(param).toString(), JSONObject.toJSONString(companyservice)); + e.printStackTrace(); + throw new JianshuiServiceException("系统异常!"); + } + debugLog("断点5", uuid, System.currentTimeMillis()); + // 判断外层报文是否成功 + if (queryResult.isError()) { + throw new JianshuiServiceException(queryResult.getMsg()); + } + debugLog("断点6", uuid, System.currentTimeMillis()); + + JSONObject contentJson = queryResult.getJsonData(); + debugLog("断点7", uuid, System.currentTimeMillis()); + + ElephantRedInfoQueryResultDTO queryResultDTO = contentJson.toJavaObject(ElephantRedInfoQueryResultDTO.class); + debugLog("断点8", uuid, System.currentTimeMillis()); + + ElephantRedInfo elephantRedInfo = queryResultDTO.getDATA(); + //红字信息表主信息封装 + redinfo.setRedInfoNo(elephantRedInfo.getHZFPXXQRDBH()); + redinfo.setSqlb(elephantRedInfo.getLRFSF()); + redinfo.setSellerTaxnum(elephantRedInfo.getXSFNSRSBH()); + redinfo.setSellerName(elephantRedInfo.getXSFMC()); + redinfo.setBuyerTaxnum(elephantRedInfo.getGMFNSRSBH()); + redinfo.setBuyerName(elephantRedInfo.getGMFMC()); + redinfo.setOriginFpdm(elephantRedInfo.getLZFPDM()); + redinfo.setOriginFphm(elephantRedInfo.getLZFPHM()); + redinfo.setOriginKprq(elephantRedInfo.getLZKPRQ()); + //todo 返回信息中不知道金额含税不含税 + redinfo.setTaxamt(new BigDecimal(elephantRedInfo.getHZCXJE())); + redinfo.setTax(new BigDecimal(elephantRedInfo.getHZCXSE())); + redinfo.setTaxfreeamt(redinfo.getTaxamt().subtract(redinfo.getTaxamt())); + + redinfo.setRedInfoStatus(elephantRedInfo.getHZQRXXZTDM()); + redinfo.setBillInputTime(elephantRedInfo.getHZKPRQ()); + + int i = redinfoMapper.updateRedinfo(redinfo); + if (i<1){ + return new HXResponse("9992","返回红字信息更新失败"); + debugLog("红字订单更新主表信息失败",uuid,System.currentTimeMillis()); + throw new JianshuiServiceException("红字订单更新主表信息失败"); + } + //删除红字信息明细 + redinfoMapper.deleteRedinfodetailByRedinfoId(redinfo.getId()); + + long id = redinfoMapper.getDetailId(); + + List redinfodetailList = new ArrayList<>(); + + for (ElephantRedInfoDetail elephantRedInfoDetail : elephantRedInfo.getHZQRXXMXLIST()) { + id++; + Redinfodetail redinfodetail = new Redinfodetail(); + redinfodetail.setId(id); + redinfodetail.setBillno(redinfo.getRedInfoNo()); + redinfodetail.setRedinfoId(redinfo.getId()); + redinfodetail.setIndex(elephantRedInfoDetail.getXH()); + redinfodetail.setGoodName(elephantRedInfoDetail.getXMMC()); + redinfodetail.setSpec(elephantRedInfoDetail.getGGXH()); + redinfodetail.setUnit(elephantRedInfoDetail.getDW()); + redinfodetail.setPrice(new BigDecimal(elephantRedInfoDetail.getFPSPDJ())); + // TODO 不确定金额是否为含税金额 + redinfodetail.setTaxamt(new BigDecimal(elephantRedInfoDetail.getJE())); + redinfodetail.setTax(new BigDecimal(elephantRedInfoDetail.getSE())); + redinfodetail.setTaxfreeamt(redinfodetail.getTaxamt().subtract(redinfodetail.getTax())); + + redinfodetail.setTaxrate(new BigDecimal(elephantRedInfoDetail.getSLV())); + redinfodetail.setCreateTime(new Date()); + redinfodetailList.add(redinfodetail); + } + + int count = redinfoMapper.batchRedinfodetail(redinfodetailList); + if(count <1){ + return new HXResponse("9992","返回红字信息更新失败"); + debugLog("红字订单更新明细信息失败",uuid,System.currentTimeMillis()); + throw new JianshuiServiceException("红字订单更新明细信息失败"); + } + + //TODO 返回啥看看文档 + + + + return null; + } } diff --git a/jianshui-invoice/src/main/resources/mapper/invoice/RedinfoMapper.xml b/jianshui-invoice/src/main/resources/mapper/invoice/RedinfoMapper.xml index 6c98da1..e0883d6 100644 --- a/jianshui-invoice/src/main/resources/mapper/invoice/RedinfoMapper.xml +++ b/jianshui-invoice/src/main/resources/mapper/invoice/RedinfoMapper.xml @@ -358,4 +358,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ( #{item.id}, #{item.redinfoId}, #{item.billno}, #{item.index}, #{item.goodName}, #{item.unit}, #{item.spec}, #{item.num}, #{item.price}, #{item.taxfreeamt}, #{item.taxrate}, #{item.tax}, #{item.taxamt}, #{item.spbm}, #{item.bmbbh}, #{item.yhzcbs}, #{item.zzstsgl}, #{item.lslbs}, #{item.goodAbbreviation}, #{item.fphxz}, #{item.createBy}, #{item.kce}, #{item.createTime}, #{item.updateBy}, #{item.updatedTime}) + + \ No newline at end of file