|
|
@ -6,7 +6,6 @@ import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse; |
|
|
|
import com.dxhy.order.protocol.invoke.DxhyInterfaceResponse; |
|
|
@ -31,7 +30,6 @@ import com.jianshui.invoice.mapper.InvoiceBackMapper; |
|
|
|
import com.jianshui.invoice.mapper.InvoiceFileMapper; |
|
|
|
import com.jianshui.invoice.mapper.InvoiceFileMapper; |
|
|
|
import com.jianshui.invoice.mapper.InvoiceMapper; |
|
|
|
import com.jianshui.invoice.mapper.InvoiceMapper; |
|
|
|
import com.jianshui.invoice.service.ElephantInvoiceService; |
|
|
|
import com.jianshui.invoice.service.ElephantInvoiceService; |
|
|
|
import com.jianshui.invoice.service.IBillInfoService; |
|
|
|
|
|
|
|
import com.jianshui.invoice.utils.elephant.ElephantUtils; |
|
|
|
import com.jianshui.invoice.utils.elephant.ElephantUtils; |
|
|
|
import com.jianshui.queue.dto.RedisQueueMessage; |
|
|
|
import com.jianshui.queue.dto.RedisQueueMessage; |
|
|
|
import com.jianshui.queue.utils.RedisQueueUtil; |
|
|
|
import com.jianshui.queue.utils.RedisQueueUtil; |
|
|
@ -42,8 +40,6 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.core.env.Environment; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
@ -197,35 +193,409 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
|
|
|
|
|
|
|
DdfpxxV5 ddfpxx = ddfpzxxV5.getDDFPXX(); |
|
|
|
DdfpxxV5 ddfpxx = ddfpzxxV5.getDDFPXX(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("convertAndSaveInvoice ddfpzxxV5{}", JSONObject.toJSONString(ddfpzxxV5)); |
|
|
|
|
|
|
|
if ("1".equals(ddfpxx.getKPLX())){ |
|
|
|
|
|
|
|
log.info("开始红票推送"); |
|
|
|
|
|
|
|
Invoice invoice = new Invoice(); |
|
|
|
|
|
|
|
// invoice.setBillInfoId(parseLong); // bill_info表的bill_id */
|
|
|
|
|
|
|
|
invoice.setCompanyId(companyservice.getCompanyid()); // "销方ID"
|
|
|
|
|
|
|
|
invoice.setSystemOrderno(ddfpxx.getHZXXBBH()); // "系统订单号"
|
|
|
|
|
|
|
|
invoice.setOutTradeOrderno(ddfpxx.getHZXXBBH()); // "客户订单号"
|
|
|
|
|
|
|
|
invoice.setFpqqlsh(ddfpxx.getDDQQLSH()); // "流水号"
|
|
|
|
|
|
|
|
invoice.setInvoiceType(ElephantUtils.transElephantType(ddfpxx.getFPLXDM(), 2)); // "发票种类"
|
|
|
|
|
|
|
|
invoice.setState(2);//开票状态成功才会推送
|
|
|
|
|
|
|
|
invoice.setcInvoiceid("not used"); // 发票c_invoiceid */
|
|
|
|
|
|
|
|
invoice.setFpdm(ddfpxx.getFPDM()); // "发票代码"
|
|
|
|
|
|
|
|
invoice.setFphm(ddfpxx.getFPHM()); // "发票号码"
|
|
|
|
|
|
|
|
invoice.setHzxxbbh(ddfpxx.getHZXXBBH()); |
|
|
|
|
|
|
|
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(ddfpxx.getGMFDZYX()); // "购方邮箱"
|
|
|
|
|
|
|
|
invoice.setBuyerPhone(ddfpxx.getGMFSJH()); // "购方联系电话,可空"
|
|
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
|
//处理明细
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invoice.setInvoiceDetailList(invoiceDetailList); |
|
|
|
|
|
|
|
log.info("invoice{}", JSONObject.toJSONString(invoice)); |
|
|
|
|
|
|
|
ICompanyservicePropService companyserviceProp = SpringUtils.getBean(ICompanyservicePropService.class); |
|
|
|
|
|
|
|
CompanyserviceProp secretIdProp = companyserviceProp.selectPropByKey(Long.valueOf(companyservice.getIdentity()), "aisino_callback_url"); |
|
|
|
|
|
|
|
String callBackUrl = secretIdProp.getValue(); |
|
|
|
|
|
|
|
log.info("【控制台】发票回调接口,发送数据开始,callBackUrl={},param={}", callBackUrl, JSONUtil.toJsonStr(invoice)); |
|
|
|
|
|
|
|
String result = HttpUtil.post(callBackUrl, JSONUtil.toJsonStr(invoice)); |
|
|
|
|
|
|
|
log.info("【控制台】发票回调接口,发送数据结束,接口返回信息={}", result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject resultObject = JSONObject.parseObject(result); |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(resultObject.getString("status")) && "0000".equals(resultObject.getString("status"))){ |
|
|
|
|
|
|
|
return AjaxResult.success(); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
return AjaxResult.error(resultObject.getString("msg")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
log.info("开始蓝票推送"); |
|
|
|
|
|
|
|
//查询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是否为空,为空则插入,不为空则更新
|
|
|
|
|
|
|
|
boolean isExist = false; |
|
|
|
|
|
|
|
if (invoice.getId() != null) { |
|
|
|
|
|
|
|
invoiceMapper.updateInvoice(invoice); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
AjaxResult result = RedisQueueUtil.build().setData(invoice).onQueue("invoice_add_callback_consumer").retry(0).lrange(); |
|
|
|
|
|
|
|
if (result != null && result.isSuccess()){ |
|
|
|
|
|
|
|
List<String> data = (List<String>) result.getData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String datum : data) { |
|
|
|
|
|
|
|
RedisQueueMessage redisQueueMessage = JSONObject.parseObject(datum, RedisQueueMessage.class); |
|
|
|
|
|
|
|
Invoice invoiceExit = JSONObject.parseObject(JSONObject.toJSONString(redisQueueMessage.getData()), Invoice.class); |
|
|
|
|
|
|
|
if (invoiceExit != null && invoiceExit.getOutTradeOrderno().equals(invoice.getOutTradeOrderno())){ |
|
|
|
|
|
|
|
isExist = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!isExist){ |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!isExist){ |
|
|
|
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invoice.setInvoiceDetailList(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); |
|
|
|
|
|
|
|
|
|
|
|
Invoice invoiceQuery = invoiceMapper.selectByFpdmFphm(companyservice.getCompanyid(),ddfpxx.getYFPHM(),""); |
|
|
|
try { |
|
|
|
if(invoiceQuery == null ){ |
|
|
|
InvoiceBack queryInvoiceBack = new InvoiceBack(); |
|
|
|
log.error("原蓝字发票信息不存在,发票号码为{}",ddfpxx.getYFPHM()); |
|
|
|
queryInvoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); |
|
|
|
return AjaxResult.error("发票信息不存在"); |
|
|
|
queryInvoiceBack.setIdentity(companyservice.getIdentity()); |
|
|
|
|
|
|
|
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectInvoiceBackList(queryInvoiceBack); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(invoiceBackList)){ |
|
|
|
|
|
|
|
InvoiceBack invoiceBack = new InvoiceBack(); |
|
|
|
|
|
|
|
invoiceBack.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
invoiceBack.setCreateTime(new Date()); |
|
|
|
|
|
|
|
invoiceBack.setId(IdUtil.randomUUID()); |
|
|
|
|
|
|
|
invoiceBack.setSystemOrderno(IdUtil.randomUUID()); |
|
|
|
|
|
|
|
invoiceBack.setStatus("1"); |
|
|
|
|
|
|
|
invoiceBack.setIdentity(companyservice.getIdentity()); |
|
|
|
|
|
|
|
invoiceBack.setBackMsg(""); |
|
|
|
|
|
|
|
invoiceBack.setBackUrl(""); |
|
|
|
|
|
|
|
invoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); |
|
|
|
|
|
|
|
invoiceBack.setStatus("0"); |
|
|
|
|
|
|
|
invoiceBack.setCreateTime(new Date()); |
|
|
|
|
|
|
|
invoiceBackMapper.insertInvoiceBack(invoiceBack); |
|
|
|
|
|
|
|
callBackAisino(invoiceBack,"",companyservice.getIdentity(),invoice); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
callBackAisino(invoiceBackList.get(0),"",companyservice.getIdentity(),invoice); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("推送订单信息失败id:{}", originBillInfo.getId(), e); |
|
|
|
|
|
|
|
log.error("推送订单信息失败:{}", e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查询billInfo
|
|
|
|
|
|
|
|
QueryWrapper<BillInfo> queryWrapper = new QueryWrapper<>(); |
|
|
|
return AjaxResult.success(); |
|
|
|
queryWrapper.eq("company_id", companyservice.getCompanyid()); |
|
|
|
} |
|
|
|
queryWrapper.eq("fpqqlsh", invoiceQuery.getFpqqlsh()); |
|
|
|
|
|
|
|
queryWrapper.orderByDesc("id"); |
|
|
|
private List<InvoiceDetail> buildDetail(DdfpzxxV5 ddfpzxxV5,Invoice invoice){ |
|
|
|
queryWrapper.last(" limit 1"); |
|
|
|
List<InvoiceDetail> invoiceDetailList = new ArrayList<>(); |
|
|
|
BillInfo originBillInfo = billInfoMapper.selectOne(queryWrapper); |
|
|
|
List<DdmxxxV5> ddmxxxList = ddfpzxxV5.getDDMXXX(); |
|
|
|
|
|
|
|
DdfpxxV5 ddfpxx = ddfpzxxV5.getDDFPXX(); |
|
|
|
if (originBillInfo == null) { |
|
|
|
for (int i = 0; i < ddmxxxList.size(); i++) { |
|
|
|
log.error("originBillInfo信息不存在"); |
|
|
|
DdmxxxV5 ddmxxx = ddmxxxList.get(i); |
|
|
|
return AjaxResult.error("发票信息不存在"); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return invoiceDetailList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Invoice buildInvoice(DdfpzxxV5 ddfpzxxV5, Companyservice companyservice,BillInfo originBillInfo) { |
|
|
|
|
|
|
|
DdfpxxV5 ddfpxx = ddfpzxxV5.getDDFPXX(); |
|
|
|
|
|
|
|
Invoice invoice; |
|
|
|
|
|
|
|
if ("0".equals(ddfpxx.getKPLX())){ |
|
|
|
|
|
|
|
invoice = invoiceMapper.selectBySystemOrderNo(companyservice.getCompanyid(), originBillInfo.getSystemOrderno()); |
|
|
|
|
|
|
|
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.setBuyerEmail(originBillInfo.getBuyerEmail()); // "购方邮箱"
|
|
|
|
|
|
|
|
invoice.setBuyerPhone(originBillInfo.getBuyerPhone()); // "购方联系电话,可空"
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
invoice = new Invoice(); |
|
|
|
|
|
|
|
invoice.setCompanyId(companyservice.getCompanyid()); // "销方ID"
|
|
|
|
|
|
|
|
invoice.setSystemOrderno(ddfpxx.getHZXXBBH()); // "系统订单号"
|
|
|
|
|
|
|
|
invoice.setOutTradeOrderno(ddfpxx.getHZXXBBH()); // "客户订单号"
|
|
|
|
|
|
|
|
invoice.setFpqqlsh(ddfpxx.getDDQQLSH()); // "流水号"
|
|
|
|
|
|
|
|
invoice.setInvoiceType(ElephantUtils.transElephantType(ddfpxx.getFPLXDM(), 2)); // "发票种类"
|
|
|
|
|
|
|
|
invoice.setHzxxbbh(ddfpxx.getHZXXBBH()); |
|
|
|
|
|
|
|
invoice.setBuyerEmail(ddfpxx.getGMFDZYX()); // "购方邮箱"
|
|
|
|
|
|
|
|
invoice.setBuyerPhone(ddfpxx.getGMFSJH()); // "购方联系电话,可空"
|
|
|
|
} |
|
|
|
} |
|
|
|
Invoice invoice = invoiceMapper.selectBySystemOrderNo(companyservice.getCompanyid(), originBillInfo.getSystemOrderno()); |
|
|
|
|
|
|
|
if (invoice == null) { |
|
|
|
if (invoice == null) { |
|
|
|
invoice = new Invoice(); |
|
|
|
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.setState(2);//开票状态成功才会推送
|
|
|
|
invoice.setcInvoiceid("not used"); // 发票c_invoiceid */
|
|
|
|
invoice.setcInvoiceid("not used"); // 发票c_invoiceid */
|
|
|
|
invoice.setFpdm(ddfpxx.getFPDM()); // "发票代码"
|
|
|
|
invoice.setFpdm(ddfpxx.getFPDM()); // "发票代码"
|
|
|
@ -245,8 +615,6 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
invoice.setBuyerAddress(ddfpxx.getGMFDZ()); // "购方地址"
|
|
|
|
invoice.setBuyerAddress(ddfpxx.getGMFDZ()); // "购方地址"
|
|
|
|
invoice.setBuyerTelephone(ddfpxx.getGMFDH()); // "购方电话"
|
|
|
|
invoice.setBuyerTelephone(ddfpxx.getGMFDH()); // "购方电话"
|
|
|
|
invoice.setBuyerAccount(ddfpxx.getGMFYH() + ddfpxx.getGMFZH()); // "购方开户行及账户"
|
|
|
|
invoice.setBuyerAccount(ddfpxx.getGMFYH() + ddfpxx.getGMFZH()); // "购方开户行及账户"
|
|
|
|
invoice.setBuyerEmail(originBillInfo.getBuyerEmail()); // "购方邮箱"
|
|
|
|
|
|
|
|
invoice.setBuyerPhone(originBillInfo.getBuyerPhone()); // "购方联系电话,可空"
|
|
|
|
|
|
|
|
invoice.setSellerName(ddfpxx.getXHFMC()); // "销方名称"
|
|
|
|
invoice.setSellerName(ddfpxx.getXHFMC()); // "销方名称"
|
|
|
|
invoice.setSellerTaxnum(ddfpxx.getXHFSBH()); // "销方税号"
|
|
|
|
invoice.setSellerTaxnum(ddfpxx.getXHFSBH()); // "销方税号"
|
|
|
|
invoice.setSellerAddress(ddfpxx.getXHFDZ()); // "销方地址"
|
|
|
|
invoice.setSellerAddress(ddfpxx.getXHFDZ()); // "销方地址"
|
|
|
@ -281,131 +649,8 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
invoice.setTerminalNumber(ddfpxx.getKPZD()); // "终端号"
|
|
|
|
invoice.setTerminalNumber(ddfpxx.getKPZD()); // "终端号"
|
|
|
|
invoice.setJqbh(ddfpxx.getKPZD()); |
|
|
|
invoice.setJqbh(ddfpxx.getKPZD()); |
|
|
|
saveFileUseDb(invoice,IdUtils.randomUUID(),invoice.getFphm(),companyservice, ddfpxx); |
|
|
|
saveFileUseDb(invoice,IdUtils.randomUUID(),invoice.getFphm(),companyservice, ddfpxx); |
|
|
|
//判断id是否为空,为空则插入,不为空则更新
|
|
|
|
|
|
|
|
boolean isExist = false; |
|
|
|
|
|
|
|
if (invoice.getId() != null) { |
|
|
|
|
|
|
|
invoiceMapper.updateInvoice(invoice); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
AjaxResult result = RedisQueueUtil.build().setData(invoice).onQueue("invoice_add_callback_consumer").retry(0).lrange(); |
|
|
|
|
|
|
|
if (result != null && result.isSuccess()){ |
|
|
|
|
|
|
|
List<String> data = (List<String>) result.getData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (String datum : data) { |
|
|
|
|
|
|
|
RedisQueueMessage redisQueueMessage = JSONObject.parseObject(datum, RedisQueueMessage.class); |
|
|
|
|
|
|
|
Invoice invoiceExit = JSONObject.parseObject(JSONObject.toJSONString(redisQueueMessage.getData()), Invoice.class); |
|
|
|
|
|
|
|
if (invoiceExit != null && invoiceExit.getOutTradeOrderno().equals(invoice.getOutTradeOrderno())){ |
|
|
|
|
|
|
|
isExist = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!isExist){ |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!isExist){ |
|
|
|
|
|
|
|
invoiceMapper.batchInvoiceDetail(invoiceDetailList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invoice.setInvoiceDetailList(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); |
|
|
|
return invoice; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
InvoiceBack queryInvoiceBack = new InvoiceBack(); |
|
|
|
|
|
|
|
queryInvoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); |
|
|
|
|
|
|
|
queryInvoiceBack.setIdentity(companyservice.getIdentity()); |
|
|
|
|
|
|
|
List<InvoiceBack> invoiceBackList = invoiceBackMapper.selectInvoiceBackList(queryInvoiceBack); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(invoiceBackList)){ |
|
|
|
|
|
|
|
InvoiceBack invoiceBack = new InvoiceBack(); |
|
|
|
|
|
|
|
invoiceBack.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
invoiceBack.setCreateTime(new Date()); |
|
|
|
|
|
|
|
invoiceBack.setId(IdUtil.randomUUID()); |
|
|
|
|
|
|
|
invoiceBack.setSystemOrderno(IdUtil.randomUUID()); |
|
|
|
|
|
|
|
invoiceBack.setStatus("1"); |
|
|
|
|
|
|
|
invoiceBack.setIdentity(companyservice.getIdentity()); |
|
|
|
|
|
|
|
invoiceBack.setBackMsg(""); |
|
|
|
|
|
|
|
invoiceBack.setBackUrl(""); |
|
|
|
|
|
|
|
invoiceBack.setSystemOrderno(invoice.getOutTradeOrderno()); |
|
|
|
|
|
|
|
invoiceBack.setStatus("0"); |
|
|
|
|
|
|
|
invoiceBack.setCreateTime(new Date()); |
|
|
|
|
|
|
|
invoiceBackMapper.insertInvoiceBack(invoiceBack); |
|
|
|
|
|
|
|
callBackAisino(invoiceBack,"",companyservice.getIdentity(),invoice); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
callBackAisino(invoiceBackList.get(0),"",companyservice.getIdentity(),invoice); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("推送订单信息失败id:{}", originBillInfo.getId(), e); |
|
|
|
|
|
|
|
log.error("推送订单信息失败:{}", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return AjaxResult.success(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void saveFileUseLocal(Invoice invoice, DdfpxxV5 ddfpxx) { |
|
|
|
private void saveFileUseLocal(Invoice invoice, DdfpxxV5 ddfpxx) { |
|
|
@ -465,7 +710,6 @@ public class ElephantInvoiceServiceImpl implements ElephantInvoiceService { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void saveFileUseDb(Invoice invoice,String fileId,String fileName,Companyservice companyservice,DdfpxxV5 ddfpxx) { |
|
|
|
private void saveFileUseDb(Invoice invoice,String fileId,String fileName,Companyservice companyservice,DdfpxxV5 ddfpxx) { |
|
|
|
InvoiceFile invoiceFile = new InvoiceFile(); |
|
|
|
InvoiceFile invoiceFile = new InvoiceFile(); |
|
|
|
invoiceFile.setFphm(ddfpxx.getFPHM()); |
|
|
|
invoiceFile.setFphm(ddfpxx.getFPHM()); |
|
|
|