|
|
|
@ -1,55 +1,92 @@ |
|
|
|
|
package com.jianshui.invoice.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.codec.Base64; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse; |
|
|
|
|
import com.jianshui.common.config.JianshuiConfig; |
|
|
|
|
import com.jianshui.common.constant.Constants; |
|
|
|
|
import com.jianshui.common.constant.PersonList; |
|
|
|
|
import com.jianshui.common.core.domain.AjaxResult; |
|
|
|
|
import com.jianshui.common.core.domain.entity.Companyservice; |
|
|
|
|
import com.jianshui.common.core.domain.entity.ele.DdfpxxV5; |
|
|
|
|
import com.jianshui.common.core.domain.entity.ele.DdfpzxxV5; |
|
|
|
|
import com.jianshui.common.core.domain.entity.ele.DdmxxxV5; |
|
|
|
|
import com.jianshui.common.utils.DateUtils; |
|
|
|
|
import com.jianshui.common.utils.JsonKeyCase; |
|
|
|
|
import com.jianshui.common.utils.StringUtils; |
|
|
|
|
import com.jianshui.common.utils.file.FileUtils; |
|
|
|
|
import com.jianshui.common.utils.spring.SpringUtils; |
|
|
|
|
import com.jianshui.common.utils.uuid.IdUtils; |
|
|
|
|
import com.jianshui.invoice.constant.elephant.ElephantConstantsV6; |
|
|
|
|
import com.jianshui.invoice.domain.dto.HXResponse; |
|
|
|
|
import com.jianshui.invoice.domain.BillInfo; |
|
|
|
|
import com.jianshui.invoice.domain.Invoice; |
|
|
|
|
import com.jianshui.invoice.domain.InvoiceDetail; |
|
|
|
|
import com.jianshui.invoice.domain.InvoiceFile; |
|
|
|
|
import com.jianshui.invoice.mapper.BillInfoMapper; |
|
|
|
|
import com.jianshui.invoice.mapper.InvoiceFileMapper; |
|
|
|
|
import com.jianshui.invoice.mapper.InvoiceMapper; |
|
|
|
|
import com.jianshui.invoice.service.ElephantInvoiceService; |
|
|
|
|
import com.jianshui.invoice.service.IBillInfoService; |
|
|
|
|
import com.jianshui.invoice.utils.elephant.ElephantUtils; |
|
|
|
|
import com.jianshui.system.domain.CompanyserviceProp; |
|
|
|
|
import com.jianshui.system.service.ICompanyservicePropService; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.security.InvalidKeyException; |
|
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
@Service |
|
|
|
|
public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private BillInfoMapper billInfoMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private InvoiceMapper invoiceMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private IBillInfoService billInfoService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private InvoiceFileMapper invoiceFileMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//调用大象获取电子税局账号
|
|
|
|
|
@Override |
|
|
|
|
public AjaxResult queryRpaTaxAccount(String sellertax, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
Map<String,String> param = new HashMap<>(); |
|
|
|
|
param.put("NSRSBH",sellertax); |
|
|
|
|
Map<String, String> param = new HashMap<>(); |
|
|
|
|
param.put("NSRSBH", sellertax); |
|
|
|
|
|
|
|
|
|
DxhyInterfaceResponse dxhyInterfaceResponse = null; |
|
|
|
|
try { |
|
|
|
|
log.info("front queryRpaTaxAccount param{}",JSONObject.toJSONString(param)); |
|
|
|
|
log.info("front queryRpaTaxAccount param{}", JSONObject.toJSONString(param)); |
|
|
|
|
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.QUERY_RPA_TAX_ACCOUNT_LOCALHOST, ElephantConstantsV6.QUERY_RPA_TAX_ACCOUNT_METHOD, JSONUtil.parse(param), companyservice); |
|
|
|
|
log.info("front queryRpaTaxAccount response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
log.info("front queryRpaTaxAccount response{}", JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { |
|
|
|
|
log.error("获取电子税局账号失败{}",e); |
|
|
|
|
log.error("获取电子税局账号失败{}", e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())){ |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())) { |
|
|
|
|
return AjaxResult.error(dxhyInterfaceResponse.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson,1); |
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))){ |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson, 1); |
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))) { |
|
|
|
|
return AjaxResult.error(responJson.getString("ztxx")); |
|
|
|
|
} |
|
|
|
|
return AjaxResult.success(responJson.getJSONArray("data")); |
|
|
|
@ -59,36 +96,36 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
@Override |
|
|
|
|
public AjaxResult rpaLogin(JSONObject paramJson, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
paramJson.put("NSRSBH",companyservice.getSellertax()); |
|
|
|
|
paramJson.put("NSRSBH", companyservice.getSellertax()); |
|
|
|
|
DxhyInterfaceResponse dxhyInterfaceResponse = null; |
|
|
|
|
try { |
|
|
|
|
paramJson = JsonKeyCase.JsonKeyCase(paramJson); |
|
|
|
|
log.info("front rpaLogin param{}",paramJson); |
|
|
|
|
log.info("front rpaLogin param{}", paramJson); |
|
|
|
|
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.RPA_LOGIN_LOCALHOST, ElephantConstantsV6.RPA_LOGIN_METHOD, JSONUtil.parse(paramJson), companyservice); |
|
|
|
|
log.info("front rpaLogin response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
log.info("front rpaLogin response{}", JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { |
|
|
|
|
log.error("电子税局登陆失败{}",e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
log.error("电子税局登陆失败{}", e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
} |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())){ |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())) { |
|
|
|
|
return AjaxResult.error(dxhyInterfaceResponse.getMessage()); |
|
|
|
|
} |
|
|
|
|
//获取返回数据
|
|
|
|
|
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); |
|
|
|
|
//key转成小写
|
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson,1); |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson, 1); |
|
|
|
|
|
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))){ |
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))) { |
|
|
|
|
return AjaxResult.error(responJson.getString("ztxx")); |
|
|
|
|
} |
|
|
|
|
//判断后续方法是否为3
|
|
|
|
|
JSONObject dataJson = responJson.getJSONObject("data"); |
|
|
|
|
if ("2".equals(dataJson.getString("hxff"))){ |
|
|
|
|
if ("2".equals(dataJson.getString("hxff"))) { |
|
|
|
|
JSONObject sj = dataJson.getJSONObject("sj"); |
|
|
|
|
List<String> personList = sj.getJSONArray("personList").toJavaList(String.class); |
|
|
|
|
Map<String,String> personTypes = new HashMap<>(); |
|
|
|
|
personList.forEach(e->personTypes.put(e, PersonList.getName(e))); |
|
|
|
|
dataJson.put("personList",personTypes); |
|
|
|
|
Map<String, String> personTypes = new HashMap<>(); |
|
|
|
|
personList.forEach(e -> personTypes.put(e, PersonList.getName(e))); |
|
|
|
|
dataJson.put("personList", personTypes); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return AjaxResult.success(dataJson); |
|
|
|
@ -98,24 +135,24 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
@Override |
|
|
|
|
public AjaxResult getRpaQrCode(JSONObject paramJson, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
paramJson.put("NSRSBH",companyservice.getSellertax()); |
|
|
|
|
paramJson.put("NSRSBH", companyservice.getSellertax()); |
|
|
|
|
DxhyInterfaceResponse dxhyInterfaceResponse = null; |
|
|
|
|
try { |
|
|
|
|
paramJson = JsonKeyCase.JsonKeyCase(paramJson); |
|
|
|
|
log.info("front getRpaQrCode param{}",JSONObject.toJSONString(paramJson)); |
|
|
|
|
log.info("front getRpaQrCode param{}", JSONObject.toJSONString(paramJson)); |
|
|
|
|
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_QY_CODE_LOCALHOST, ElephantConstantsV6.GET_RPA_QY_CODE_METHOD, JSONUtil.parse(paramJson), companyservice); |
|
|
|
|
log.info("front getRpaQrCode response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
log.info("front getRpaQrCode response{}", JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { |
|
|
|
|
log.error("电子税局登陆失败{}",e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
log.error("电子税局登陆失败{}", e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
} |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())){ |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())) { |
|
|
|
|
return AjaxResult.error(dxhyInterfaceResponse.getMessage()); |
|
|
|
|
} |
|
|
|
|
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson,1); |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson, 1); |
|
|
|
|
|
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))){ |
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))) { |
|
|
|
|
return AjaxResult.error(responJson.getString("ztxx")); |
|
|
|
|
} |
|
|
|
|
return AjaxResult.success(responJson.getJSONObject("data")); |
|
|
|
@ -124,26 +161,289 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
//数电实名认证状态
|
|
|
|
|
@Override |
|
|
|
|
public AjaxResult getRpaAuthStatus(JSONObject paramJson, Companyservice companyservice) { |
|
|
|
|
paramJson.put("NSRSBH",companyservice.getSellertax()); |
|
|
|
|
paramJson.put("NSRSBH", companyservice.getSellertax()); |
|
|
|
|
DxhyInterfaceResponse dxhyInterfaceResponse = null; |
|
|
|
|
try { |
|
|
|
|
paramJson = JsonKeyCase.JsonKeyCase(paramJson); |
|
|
|
|
log.info("front getRpaAuthStatus param{}",paramJson); |
|
|
|
|
log.info("front getRpaAuthStatus param{}", paramJson); |
|
|
|
|
dxhyInterfaceResponse = ElephantUtils.sendRequestWithoutTokenV6(ElephantConstantsV6.GET_RPA_AUTH_STATUS_LOCALHOST, ElephantConstantsV6.GET_RPA_AUTH_STATUS_METHOD, JSONUtil.parse(paramJson), companyservice); |
|
|
|
|
log.info("front getRpaAuthStatus response{}",JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
log.info("front getRpaAuthStatus response{}", JSONObject.toJSONString(dxhyInterfaceResponse)); |
|
|
|
|
} catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException e) { |
|
|
|
|
log.error("电子税局登陆失败{}",e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
log.error("电子税局登陆失败{}", e); |
|
|
|
|
return AjaxResult.error("009999", "系统异常!"); |
|
|
|
|
} |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())){ |
|
|
|
|
if (!"000000".equals(dxhyInterfaceResponse.getCode())) { |
|
|
|
|
return AjaxResult.error(dxhyInterfaceResponse.getMessage()); |
|
|
|
|
} |
|
|
|
|
JSONObject responJson = JSONObject.parseObject(dxhyInterfaceResponse.getData()); |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson,1); |
|
|
|
|
responJson = JsonKeyCase.JsonKeyCase(responJson, 1); |
|
|
|
|
|
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))){ |
|
|
|
|
if (!"000000".equals(responJson.getString("ztdm"))) { |
|
|
|
|
return AjaxResult.error(responJson.getString("ztxx")); |
|
|
|
|
} |
|
|
|
|
return AjaxResult.success(responJson.getJSONObject("data")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public AjaxResult convertAndSaveInvoice(DdfpzxxV5 ddfpzxxV5, Companyservice companyservice) { |
|
|
|
|
|
|
|
|
|
DdfpxxV5 ddfpxx = ddfpzxxV5.getDDFPXX(); |
|
|
|
|
//查询billInfo
|
|
|
|
|
QueryWrapper<BillInfo> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("company_id", companyservice.getCompanyid()); |
|
|
|
|
queryWrapper.eq("fpqqlsh", ddfpxx.getDDQQLSH()); |
|
|
|
|
queryWrapper.orderByDesc("id"); |
|
|
|
|
queryWrapper.last(" limit 1"); |
|
|
|
|
BillInfo originBillInfo = billInfoMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
|
|
if (originBillInfo == null) { |
|
|
|
|
log.error("originBillInfo信息不存在"); |
|
|
|
|
return AjaxResult.error("发票信息不存在"); |
|
|
|
|
} |
|
|
|
|
Invoice invoice = invoiceMapper.selectBySystemOrderNo(companyservice.getCompanyid(), originBillInfo.getSystemOrderno()); |
|
|
|
|
if (invoice == null) { |
|
|
|
|
invoice = new Invoice(); |
|
|
|
|
} |
|
|
|
|
invoice.setBillInfoId(originBillInfo.getId()); // bill_info表的bill_id */
|
|
|
|
|
invoice.setCompanyId(companyservice.getCompanyid()); // "销方ID"
|
|
|
|
|
invoice.setSystemOrderno(originBillInfo.getSystemOrderno()); // "系统订单号"
|
|
|
|
|
invoice.setOutTradeOrderno(originBillInfo.getOutTradeOrderno()); // "客户订单号"
|
|
|
|
|
invoice.setFpqqlsh(originBillInfo.getFpqqlsh()); // "流水号"
|
|
|
|
|
invoice.setInvoiceType(originBillInfo.getInvoiceType()); // "发票种类"
|
|
|
|
|
invoice.setState(2);//开票状态成功才会推送
|
|
|
|
|
invoice.setcInvoiceid("not used"); // 发票c_invoiceid */
|
|
|
|
|
invoice.setFpdm(ddfpxx.getFPDM()); // "发票代码"
|
|
|
|
|
invoice.setFphm(ddfpxx.getFPHM()); // "发票号码"
|
|
|
|
|
//TODO
|
|
|
|
|
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) { |
|
|
|
|
log.error("{}日期处理错误",ddfpxx.getDDQQLSH()); |
|
|
|
|
throw new RuntimeException(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
invoice.setBuyerName(ddfpxx.getGMFMC()); // "购方名称"
|
|
|
|
|
invoice.setBuyerTaxnum(ddfpxx.getGMFSBH()); // "购方税号"
|
|
|
|
|
invoice.setBuyerAddress(ddfpxx.getGMFDZ()); // "购方地址"
|
|
|
|
|
invoice.setBuyerTelephone(ddfpxx.getGMFDH()); // "购方电话"
|
|
|
|
|
invoice.setBuyerAccount(ddfpxx.getGMFYH() + ddfpxx.getGMFZH()); // "购方开户行及账户"
|
|
|
|
|
invoice.setBuyerEmail(originBillInfo.getBuyerEmail()); // "购方邮箱"
|
|
|
|
|
invoice.setBuyerPhone(originBillInfo.getBuyerPhone()); // "购方联系电话,可空"
|
|
|
|
|
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.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()); |
|
|
|
|
saveFileUseDb(invoice,IdUtils.randomUUID(),invoice.getFphm(),companyservice, ddfpxx); |
|
|
|
|
//判断id是否为空,为空则插入,不为空则更新
|
|
|
|
|
if (invoice.getId() != null) { |
|
|
|
|
invoiceMapper.updateInvoice(invoice); |
|
|
|
|
} else { |
|
|
|
|
invoiceMapper.insertInvoice(invoice); |
|
|
|
|
} |
|
|
|
|
//发票明细先删除再插入
|
|
|
|
|
|
|
|
|
|
invoiceMapper.deleteInvoiceDetailByInvoiceId(invoice.getId()); |
|
|
|
|
List<InvoiceDetail> invoiceDetailList = new ArrayList<>(); |
|
|
|
|
List<DdmxxxV5> ddmxxxList = ddfpzxxV5.getDDMXXX(); |
|
|
|
|
for (int i = 0; i < ddmxxxList.size(); i++) { |
|
|
|
|
DdmxxxV5 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()); // 商品名称
|
|
|
|
|
//TODO
|
|
|
|
|
if (StringUtils.isNotBlank(ddmxxx.getSPSL())){ |
|
|
|
|
tempDetail.setNum(new BigDecimal(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); |
|
|
|
|
} |
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
|
|
|
|
|
//更新原来的billInfo
|
|
|
|
|
originBillInfo.setState(invoice.getState()); |
|
|
|
|
if (StringUtils.equals(originBillInfo.getKptype(), "2")) { |
|
|
|
|
originBillInfo.setOriginFpdm(invoice.getOriginFpdm()); |
|
|
|
|
originBillInfo.setOriginFphm(invoice.getOriginFphm()); |
|
|
|
|
// 如果是红票,开票状态为成功,还需要对原来的蓝票进行状态修改
|
|
|
|
|
if (invoice.getState() == 2) { |
|
|
|
|
Invoice originInvoice = invoiceMapper.selectByFpdmFphm(companyservice.getCompanyid(), invoice.getOriginFpdm(), invoice.getOriginFphm()); |
|
|
|
|
if (originInvoice != null) { |
|
|
|
|
originBillInfo.setOriginSystemOrderno(originInvoice.getSystemOrderno()); |
|
|
|
|
QueryWrapper<BillInfo> myQueryWrapper = new QueryWrapper<>(); |
|
|
|
|
myQueryWrapper.eq("company_id", companyservice.getCompanyid()); |
|
|
|
|
myQueryWrapper.eq("system_orderno", originInvoice.getSystemOrderno()); |
|
|
|
|
BillInfo originBlueBillInfo = billInfoMapper.selectOne(myQueryWrapper); |
|
|
|
|
if (originBlueBillInfo != null) { |
|
|
|
|
originBlueBillInfo.setState(99); |
|
|
|
|
billInfoMapper.updateBillInfo(originBlueBillInfo); |
|
|
|
|
} |
|
|
|
|
originInvoice.setState(99); |
|
|
|
|
invoiceMapper.updateInvoice(originInvoice); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
billInfoMapper.updateBillInfo(originBillInfo); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
log.info("推送订单信息,id:{}", originBillInfo.getId()); |
|
|
|
|
billInfoService.pushBillInfo(originBillInfo.getId()); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("推送订单信息失败id:{}", originBillInfo.getId(), e); |
|
|
|
|
log.error("推送订单信息失败:{}", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return AjaxResult.success(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void saveFileUseLocal(Invoice invoice, DdfpxxV5 ddfpxx) { |
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
byte[] pdfBytes = Base64.decode(ddfpxx.getPDFZJL()); |
|
|
|
|
String key = IdUtils.fastSimpleUUID(); |
|
|
|
|
String fileName = key + "."+ddfpxx.getZJLLX().toLowerCase(); |
|
|
|
|
String fileDir = JianshuiConfig.getDownloadPath() + "/storage/"; |
|
|
|
|
// 判断fileDir是否存在,不存在则创建
|
|
|
|
|
File fileDirInst = new File(fileDir); |
|
|
|
|
if (!fileDirInst.exists()) { |
|
|
|
|
fileDirInst.mkdirs(); |
|
|
|
|
} |
|
|
|
|
String realPath = fileDir + fileName; |
|
|
|
|
FileUtils.byteToFile(pdfBytes, realPath); |
|
|
|
|
|
|
|
|
|
// IStorageService service = storageFactory.getStorageInstance(Constants.LOCAL);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// AjaxResult upload = service.upload(pdfBytes, "");
|
|
|
|
|
|
|
|
|
|
//文件名称
|
|
|
|
|
// fileName = fileName+ Constants.POINT + (StringUtils.equals(ddfpxx.getZJLLX(), Constants.PDF_UPCASE) ? Constants.PDF : Constants.OFD);
|
|
|
|
|
//文件写入路径
|
|
|
|
|
// String targetFilePath = environment.getProperty(Constants.INVOICE_FILE_SAVE_PATH) + fileName;
|
|
|
|
|
// 创建一个输出流对象,用于将数据写入到本地文件,如果文件存在则会覆盖
|
|
|
|
|
FileOutputStream fileOutputStream = new FileOutputStream(realPath, false); |
|
|
|
|
|
|
|
|
|
// 直接将字节数组写入到输出流(即本地文件)
|
|
|
|
|
fileOutputStream.write(pdfBytes); |
|
|
|
|
|
|
|
|
|
// 完成写入后关闭流
|
|
|
|
|
fileOutputStream.close(); |
|
|
|
|
//拼接url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// StorageUrlDTO uploadResultDTO = (StorageUrlDTO) upload.get(Constants.DATA);
|
|
|
|
|
|
|
|
|
|
// String fileUrl = configService.selectConfigByKey(Constants.FILE_URL);
|
|
|
|
|
|
|
|
|
|
// uploadResultDTO.setStoragePath(targetFilePath);
|
|
|
|
|
// uploadResultDTO.setContentType(ddfpxx.getZJLLX().toLowerCase());
|
|
|
|
|
|
|
|
|
|
// Base64.encode(JSONObject.toJSONString(uploadResultDTO));
|
|
|
|
|
|
|
|
|
|
// String pdfUrl = fileUrl + Constants.ESCAPE + Base64.encode(JSONObject.toJSONString(uploadResultDTO));
|
|
|
|
|
invoice.setInvoicePdfUrl(realPath); |
|
|
|
|
invoice.setInvoiceFileStorage("local"); |
|
|
|
|
if (StringUtils.equals(ddfpxx.getZJLLX(), Constants.OFD_UPCASE)) { |
|
|
|
|
invoice.setcOfdUrl(realPath); |
|
|
|
|
} |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
log.error("文件保存异常",e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void saveFileUseDb(Invoice invoice,String fileId,String fileName,Companyservice companyservice,DdfpxxV5 ddfpxx) { |
|
|
|
|
InvoiceFile invoiceFile = new InvoiceFile(); |
|
|
|
|
invoiceFile.setFphm(ddfpxx.getFPHM()); |
|
|
|
|
List<InvoiceFile> invoiceFileList = invoiceFileMapper.selectInvoiceFileList(invoiceFile); |
|
|
|
|
if(invoiceFileList != null && invoiceFileList.size() > 0){ |
|
|
|
|
invoiceFile = invoiceFileList.get(0); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileName(fileName); |
|
|
|
|
invoiceFile.setCreateTime(new Date()); |
|
|
|
|
invoiceFile.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceFile.setTax(companyservice.getSellertax()); |
|
|
|
|
fileId = invoiceFile.getFileId(); |
|
|
|
|
fileName = invoiceFile.getFileName(); |
|
|
|
|
invoiceFileMapper.updateInvoiceFile(invoiceFile); |
|
|
|
|
}else{ |
|
|
|
|
invoiceFile.setId(fileId); |
|
|
|
|
invoiceFile.setFileContent(ddfpxx.getPDFZJL()); |
|
|
|
|
invoiceFile.setFileId(fileId); |
|
|
|
|
invoiceFile.setFileName(fileName); |
|
|
|
|
invoiceFile.setCreateTime(new Date()); |
|
|
|
|
invoiceFile.setIdentity(companyservice.getIdentity()); |
|
|
|
|
invoiceFile.setTax(companyservice.getSellertax()); |
|
|
|
|
invoiceFileMapper.insertInvoiceFile(invoiceFile); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2023/11/16 kk:上传OSS转下载地址关闭,改为直接返回大象的文件流
|
|
|
|
|
invoice.setInvoicePdfUrl(SpringUtils.getBean(Environment.class).getProperty("elephant_invoice_file") + fileId); |
|
|
|
|
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); |
|
|
|
|
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(companyservice.getCompanyid(), "elephant_invoice_file_dc"); |
|
|
|
|
if (secretIdProp != null) { |
|
|
|
|
invoice.setInvoicePdfUrl(secretIdProp.getValue() + fileId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|