对接大象红字发票开具查询和红字信息表查询

beta
路明慧 2 years ago
parent c6489bd069
commit 666e024dd6
  1. 34
      jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfo.java
  2. 18
      jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoDetail.java
  3. 10
      jianshui-invoice/src/main/java/com/jianshui/invoice/domain/dto/api/elephant/ElephantRedInfoQueryResultDTO.java
  4. 2
      jianshui-invoice/src/main/java/com/jianshui/invoice/mapper/RedinfoMapper.java
  5. 143
      jianshui-invoice/src/main/java/com/jianshui/invoice/service/impl/api/ElephantInvoiceApiV6ServiceImpl.java
  6. 4
      jianshui-invoice/src/main/resources/mapper/invoice/RedinfoMapper.xml

@ -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<ElephantRedInfoDetail> HZQRXXMXLIST;
}

@ -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;
}

@ -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;
}

@ -93,4 +93,6 @@ public interface RedinfoMapper extends BaseMapper<Redinfo> {
* @return : java.util.List<com.jianshui.invoice.domain.Redinfo>
*/
List<Redinfo> findRedInfoList(FindRedWordDTO dto);
Long getDetailId();
}

@ -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<Redinfo> 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<Invoice> 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<Redinfodetail> 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;
}
}

@ -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})
</foreach>
</insert>
<select id="getDetailId" resultType="java.lang.Long">
select id from redinfodetail order by id desc limit 1
</select>
</mapper>
Loading…
Cancel
Save