|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
package com.jianshui.invoice.service.impl.api; |
|
|
|
|
|
|
|
|
|
import ch.qos.logback.core.joran.spi.ElementPath; |
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
|
import cn.hutool.core.codec.Base64; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
@ -7,6 +8,7 @@ import cn.hutool.core.util.ObjUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.json.JSONConfig; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.alibaba.druid.support.json.JSONUtils; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
@ -29,6 +31,7 @@ import com.jianshui.common.utils.TimeUtil; |
|
|
|
|
import com.jianshui.common.utils.http.HttpHelper; |
|
|
|
|
import com.jianshui.common.utils.uuid.IdUtils; |
|
|
|
|
import com.jianshui.framework.manager.AsyncManager; |
|
|
|
|
import com.jianshui.invoice.constant.elephant.ElephantConstants; |
|
|
|
|
import com.jianshui.invoice.constant.elephant.ElephantConstantsV6; |
|
|
|
|
import com.jianshui.invoice.domain.*; |
|
|
|
|
import com.jianshui.invoice.domain.dto.*; |
|
|
|
@ -38,9 +41,7 @@ import com.jianshui.invoice.domain.dto.api.elephant.sd.GetRpaAuthStatusDTO; |
|
|
|
|
import com.jianshui.invoice.domain.dto.api.elephant.sd.HZQRDMXLIST; |
|
|
|
|
import com.jianshui.invoice.domain.dto.api.elephant.sd.RedDownload; |
|
|
|
|
import com.jianshui.invoice.domain.dto.api.elephant.sd.RedUpload; |
|
|
|
|
import com.jianshui.invoice.domain.ele.EleNewMessage; |
|
|
|
|
import com.jianshui.invoice.domain.ele.EleOuterMessage; |
|
|
|
|
import com.jianshui.invoice.domain.ele.HZSQDMessage; |
|
|
|
|
import com.jianshui.invoice.domain.ele.*; |
|
|
|
|
import com.jianshui.invoice.domain.vo.InvoiceAllQycodeResultElEVO; |
|
|
|
|
import com.jianshui.invoice.domain.vo.jcsk.*; |
|
|
|
|
import com.jianshui.invoice.mapper.BillInfoMapper; |
|
|
|
@ -64,8 +65,10 @@ 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.joda.time.format.DateTimeFormat; |
|
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.scheduling.annotation.Async; |
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
@ -75,6 +78,8 @@ import java.math.BigDecimal; |
|
|
|
|
import java.security.InvalidKeyException; |
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -1999,26 +2004,23 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
|
|
|
|
|
//获取税局用户名称
|
|
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
|
param.put("NSRSBH",companyservice.getSellertax()); |
|
|
|
|
param.put(ElephantConstants.NSRSBH,companyservice.getSellertax()); |
|
|
|
|
HXResponse hxResponse = queryRpaTaxAccount(param, companyservice); |
|
|
|
|
if (!StringUtils.equals("000000",hxResponse.getCode())){ |
|
|
|
|
return hxResponse; |
|
|
|
|
} |
|
|
|
|
JSONObject resp = JSONObject.parseObject(JSON.toJSONString(hxResponse.getData())); |
|
|
|
|
|
|
|
|
|
Map<String,Object> reqParam = new HashMap<>(); |
|
|
|
|
reqParam.put("NSRSBH",companyservice.getSellertax()); |
|
|
|
|
reqParam.put("YHM",resp.getString("YHM")); |
|
|
|
|
reqParam.put("RZID",allApiLog.getResultMsg()); |
|
|
|
|
param.put(ElephantConstants.YHM,resp.getString(ElephantConstants.YHM)); |
|
|
|
|
|
|
|
|
|
HXResponse rpaAuthStatus = getRpaAuthStatus(new JSONObject(reqParam), companyservice); |
|
|
|
|
HXResponse rpaAuthStatus = qrcode(param, companyservice); |
|
|
|
|
|
|
|
|
|
if (StringUtils.equals("000000",rpaAuthStatus.getCode())){ |
|
|
|
|
rpaAuthStatus.setCode("200"); |
|
|
|
|
rpaAuthStatus.setMessage("处理成功"); |
|
|
|
|
JSONObject data = JSONObject.parseObject(JSON.toJSONString(rpaAuthStatus.getData())); |
|
|
|
|
String ewm = data.getString("EWM"); |
|
|
|
|
rpaAuthStatus.setData(new HashMap<>().put("ewm",ewm)); |
|
|
|
|
String ewm = data.getString(ElephantConstants.EWM); |
|
|
|
|
rpaAuthStatus.setData(new HashMap<>().put(ElephantConstants.EWM.toLowerCase(),ewm)); |
|
|
|
|
} |
|
|
|
|
return rpaAuthStatus; |
|
|
|
|
|
|
|
|
@ -2058,9 +2060,27 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
}else if (WebServiceConstant.CXHZFPXXQRD.equals(finalServiceId)) { |
|
|
|
|
// 查询红字信息表
|
|
|
|
|
|
|
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
|
param.put(ElephantConstants.YHJSLX,ElephantConstants.STRING_0); |
|
|
|
|
param.put(ElephantConstants.XSFNSRSBH,companyservice.getSellertax()); |
|
|
|
|
param.put(ElephantConstants.XSFMC,companyservice.getSellername()); |
|
|
|
|
param.put(ElephantConstants.LRFSF,ElephantConstants.STRING_0); |
|
|
|
|
//录入日期起始值
|
|
|
|
|
HXResponse hxResponse = queryRedConfirmationList(param, companyservice); |
|
|
|
|
|
|
|
|
|
HZXXLIST hzxxlist = JSONObject.parseObject(JSONObject.toJSONString(hxResponse.getData()), HZXXLIST.class); |
|
|
|
|
|
|
|
|
|
return convertToJcData(hzxxlist); |
|
|
|
|
|
|
|
|
|
} else if (WebServiceConstant.SHHZFPXXQRD.equals(finalServiceId)) { |
|
|
|
|
// 审核红字信息表
|
|
|
|
|
LambdaQueryWrapper<Redinfo> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
queryWrapper.eq(Redinfo::getFpqqlsh,requestId); |
|
|
|
|
queryWrapper.orderByDesc(Redinfo::getId).last("limit 1"); |
|
|
|
|
|
|
|
|
|
Redinfo redinfo = redinfoMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
|
|
return auditRedInfoResult(allApiLog.getResultMsg(),redinfo,companyservice); |
|
|
|
|
|
|
|
|
|
} else if (WebServiceConstant.FPEWMXZ.equals(finalServiceId)) { |
|
|
|
|
// 获取发票下载地址
|
|
|
|
@ -2081,7 +2101,99 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
private HXResponse convertToJcData(HZXXLIST hzxxlist) { |
|
|
|
|
HZQRXXLIST hzqrxxlist = hzxxlist.getHZQRXXLIST(); |
|
|
|
|
List<Redinfo> redinfos = new ArrayList<>(hzqrxxlist.getTOTAL()); |
|
|
|
|
|
|
|
|
|
List<HZXXDATA> list = hzqrxxlist.getLIST(); |
|
|
|
|
|
|
|
|
|
for (HZXXDATA hzxxdata : list) { |
|
|
|
|
LambdaQueryWrapper<Redinfo> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
queryWrapper.eq(Redinfo::getRedInfoNo,hzxxdata.getHZFPXXQRDBH()); |
|
|
|
|
queryWrapper.orderByDesc(Redinfo::getId).last("limit 1"); |
|
|
|
|
//根据红字信息表编号查询红字信息
|
|
|
|
|
Redinfo redinfo = redinfoMapper.selectOne(queryWrapper); |
|
|
|
|
//不存在就创建对象
|
|
|
|
|
if (ObjectUtils.isEmpty(redinfo)){ |
|
|
|
|
redinfo = new Redinfo(); |
|
|
|
|
} |
|
|
|
|
redinfo.setRedInfoNo(hzxxdata.getHZFPXXQRDBH()); |
|
|
|
|
redinfo.setSellerTaxnum(hzxxdata.getXSFNSRSBH()); |
|
|
|
|
redinfo.setSellerName(hzxxdata.getXSFMC()); |
|
|
|
|
redinfo.setBuyerName(hzxxdata.getGMFMC()); |
|
|
|
|
redinfo.setBuyerTaxnum(hzxxdata.getGMFNSRSBH()); |
|
|
|
|
redinfo.setOriginFpdm(hzxxdata.getLZFPDM()); |
|
|
|
|
redinfo.setOriginFphm(hzxxdata.getLZFPHM()); |
|
|
|
|
redinfo.setOriginKprq(hzxxdata.getLZKPRQ()); |
|
|
|
|
redinfo.setReqnsrsbh(hzxxdata.getXSFNSRSBH()); |
|
|
|
|
redinfos.add(redinfo); |
|
|
|
|
//判断是否存在红字信息,存在执行更新
|
|
|
|
|
if (ObjectUtils.isEmpty(redinfo.getId())){ |
|
|
|
|
//处理发票表和红字信息表
|
|
|
|
|
redInfoAndInvoiceUpdate(hzxxdata, redinfo); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new HXResponse("200","查询成功",redinfos); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Async |
|
|
|
|
public void redInfoAndInvoiceUpdate(HZXXDATA hzxxdata, Redinfo redinfo) { |
|
|
|
|
redinfoMapper.updateRedinfo(redinfo); |
|
|
|
|
QueryWrapper<Invoice> invoiceQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
invoiceQueryWrapper.eq("fphm", redinfo.getOriginFphm()); |
|
|
|
|
Invoice invoice = invoiceMapper.selectOne(invoiceQueryWrapper); |
|
|
|
|
//更新蓝字发票状态为冲红 99
|
|
|
|
|
invoice.setState(99); |
|
|
|
|
invoiceMapper.updateInvoice(invoice); |
|
|
|
|
invoice.setId(null); |
|
|
|
|
invoice.setOriginFphm(invoice.getFphm()); |
|
|
|
|
invoice.setFphm(hzxxdata.getHZFPHM()); |
|
|
|
|
invoice.setBillInfoId(redinfo.getId()); |
|
|
|
|
invoice.setSystemOrderno(redinfo.getSystemOrderno()); |
|
|
|
|
invoice.setOutTradeOrderno(redinfo.getOutTradeOrderno()); |
|
|
|
|
invoice.setFpqqlsh(redinfo.getFpqqlsh()); |
|
|
|
|
invoice.setKprq(DateUtil.parse(hzxxdata.getHZKPRQ())); |
|
|
|
|
invoice.setState(2); |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private HXResponse auditRedInfoResult(String uuid,Redinfo redinfo, Companyservice companyservice) { |
|
|
|
|
if (ObjectUtils.isEmpty(companyservice)){ |
|
|
|
|
log.info("请求日志为空或者企业服务为空"); |
|
|
|
|
return new HXResponse("9998","请求日志为空或者企业服务为空"); |
|
|
|
|
} |
|
|
|
|
if (ObjectUtils.isEmpty(redinfo)){ |
|
|
|
|
log.info("不存在该红字信息"); |
|
|
|
|
return new HXResponse("9998","不存在该红字信息"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(uuid)){ |
|
|
|
|
log.info("红字确认单UUID不能为空"); |
|
|
|
|
return new HXResponse("9998","红字确认单UUID不能为空"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
|
param.put(ElephantConstants.NSRSBH,companyservice.getSellertax()); |
|
|
|
|
param.put(ElephantConstants.UUID,uuid); |
|
|
|
|
param.put(ElephantConstants.HZQRDBH,redinfo.getRedInfoNo()); |
|
|
|
|
param.put(ElephantConstants.QRLX,ElephantConstants.QRLX_Y); |
|
|
|
|
|
|
|
|
|
//调用大象接口获取确认日期
|
|
|
|
|
|
|
|
|
|
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("【销项发票】【大象接口】【发票开具】发票请求异常,请求报文{},销方信息{}", param.toJSONString(), JSONObject.toJSONString(companyservice)); |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
throw new JianshuiServiceException("系统异常!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new HXResponse(String.valueOf(queryResult.getCode()),queryResult.getMsg(),queryResult.getData()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public HXResponse queryRedInfoByElepant(Redinfo redinfo, Companyservice companyservice,InvoiceAllApiLog apiLog) { |
|
|
|
|
//返回信息
|
|
|
|
|
|
|
|
|
@ -2094,9 +2206,9 @@ public class ElephantInvoiceApiV6ServiceImpl implements IInvoiceApiService { |
|
|
|
|
|
|
|
|
|
//封装请求参数
|
|
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
|
param.put("NSRSBH",companyservice.getSellertax()); |
|
|
|
|
param.put("UUID",apiLog.getResultMsg()); |
|
|
|
|
param.put("XSFNSRSBH",companyservice.getSellertax()); |
|
|
|
|
param.put(ElephantConstants.NSRSBH,companyservice.getSellertax()); |
|
|
|
|
param.put(ElephantConstants.UUID,apiLog.getResultMsg()); |
|
|
|
|
param.put(ElephantConstants.XSFNSRSBH,companyservice.getSellertax()); |
|
|
|
|
|
|
|
|
|
debugLog("红字信息表申请查询断点1",uuid,System.currentTimeMillis()); |
|
|
|
|
//调用大象接口查询红字信息表明细
|
|
|
|
|