|
|
|
@ -121,16 +121,24 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
item.setImageId(params.getImageId()); |
|
|
|
|
item.setBzdh(params.getBillNum()); |
|
|
|
|
item.setBzr(params.getJbrUserName()); |
|
|
|
|
item.setCompCode(params.getCompCode()); |
|
|
|
|
}); |
|
|
|
|
List<SdnyTDxSaleRecordInvoice> salesInvoiceList = new ArrayList<>(); |
|
|
|
|
invoicesList.stream().forEach(invoice -> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SdnyTDxSaleRecordInvoice saleRecordInvoice = sdnyTDxSaleRecordInvoiceDao.selectOne(new QueryWrapper<SdnyTDxSaleRecordInvoice>().eq("uuid", invoice.getUuid())); |
|
|
|
|
List<SdnyTDxSaleRecordInvoice> saleRecordInvoices = sdnyTDxSaleRecordInvoiceDao.selectList(new QueryWrapper<SdnyTDxSaleRecordInvoice>().eq("uuid", invoice.getUuid())); |
|
|
|
|
SdnyTDxSaleRecordInvoice saleRecordInvoice = null; |
|
|
|
|
if (saleRecordInvoices!=null && saleRecordInvoices.size()>0) { |
|
|
|
|
saleRecordInvoice = saleRecordInvoices.get(0); |
|
|
|
|
} |
|
|
|
|
List<SdnyTDxRecordInvoiceDetailSales> salesDetailList = new ArrayList<>(); |
|
|
|
|
detailiMap.get(invoice.getUuid()).stream().forEach(item -> { |
|
|
|
|
log.info("进项表明细行:{}",JSONObject.toJSONString(item)); |
|
|
|
|
SdnyTDxRecordInvoiceDetailSales salesDetail = JsonUtils.getInstance().parseObject(JSONObject.toJSONString(item), SdnyTDxRecordInvoiceDetailSales.class); |
|
|
|
|
log.info("销项表明细行:{}",JSONObject.toJSONString(salesDetail)); |
|
|
|
|
salesDetail.setId(null); |
|
|
|
|
salesDetail.setTaxRate(item.getTaxRate()); |
|
|
|
|
salesDetailList.add(salesDetail); |
|
|
|
|
}); |
|
|
|
|
if (saleRecordInvoice == null) { |
|
|
|
@ -138,18 +146,22 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
saleRecordInvoice = JsonUtils.getInstance().parseObject(JSONObject.toJSONString(invoice), SdnyTDxSaleRecordInvoice.class); |
|
|
|
|
saleRecordInvoice.setId(null); |
|
|
|
|
sdnyTDxSaleRecordInvoiceDao.insert(saleRecordInvoice); |
|
|
|
|
detailSalesDao.deleteByUUid(invoice.getUuid()); |
|
|
|
|
detailSalesDao.batchInsert(salesDetailList); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// 修改
|
|
|
|
|
saleRecordInvoice.setImageId(invoice.getImageId()); |
|
|
|
|
saleRecordInvoice.setBzdh(invoice.getBzdh()); |
|
|
|
|
saleRecordInvoice.setBzr(invoice.getBzr()); |
|
|
|
|
saleRecordInvoice.setCompCode(invoice.getCompCode()); |
|
|
|
|
sdnyTDxSaleRecordInvoiceDao.updateById(saleRecordInvoice); |
|
|
|
|
} |
|
|
|
|
detailSalesDao.deleteByUUid(invoice.getUuid()); |
|
|
|
|
detailSalesDao.batchInsert(salesDetailList); |
|
|
|
|
|
|
|
|
|
saleRecordInvoice.setDetailList(salesDetailList); |
|
|
|
|
saleRecordInvoice.setSort(paramsInvoiceMap.get(invoice.getUuid()).getSort()); |
|
|
|
|
saleRecordInvoice.setFileId(paramsInvoiceMap.get(invoice.getUuid()).getFileId()); |
|
|
|
|
saleRecordInvoice.setFileName(paramsInvoiceMap.get(invoice.getUuid()).getFileName()); |
|
|
|
|
salesInvoiceList.add(saleRecordInvoice); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -183,6 +195,7 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public R pushSap(List<SdnyTDxSaleRecordInvoice> invoiceList, SNRequestObject params) { |
|
|
|
|
log.info("销项发票推送SAP准备数据:{},影像参数:{}", invoiceList, params); |
|
|
|
|
String dt = DateUtil.now(); |
|
|
|
|
List<ZData> zDataList = new ArrayList<>(); |
|
|
|
|
if (invoiceList != null) { |
|
|
|
@ -192,6 +205,7 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
if (StringUtils.isBlank(invoiceType)) { |
|
|
|
|
throw new RuntimeException("推送SAP失败,推导发票类型错误,发票代码:"+item.getInvoiceCode()+",发票代码:"+item.getInvoiceNo()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ZData zdata = new ZData(); |
|
|
|
|
zdata.setZFPDM(StringUtils.isBlank(item.getInvoiceCode())?"":item.getInvoiceCode()); |
|
|
|
|
zdata.setZFPHM(item.getInvoiceNo()); |
|
|
|
@ -203,7 +217,7 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
zdata.setZZSE_DIF("0"); |
|
|
|
|
zdata.setZHSJE_DIF("0"); |
|
|
|
|
zdata.setZZBZ(item.getRemark()); |
|
|
|
|
zdata.setZFPZT("0"); |
|
|
|
|
zdata.setZFPZT("0".equals(item.getInvoiceStatus())?"0":"1"); |
|
|
|
|
zdata.setZKPRQ(DateUtils.dateToStr(item.getInvoiceDate(),DateUtils.YYYYMMDD)); |
|
|
|
|
zdata.setMANDT(params.getClientNum()); |
|
|
|
|
zdata.setZGFMC(item.getGfName()); |
|
|
|
@ -243,11 +257,15 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
zdata.setFPYXBH(item.getFileId()); |
|
|
|
|
zdata.setIMG_ID(params.getImageId()); |
|
|
|
|
zdata.setSORT(String.valueOf(item.getSort())); |
|
|
|
|
// 增加文件名
|
|
|
|
|
zdata.setZWJMC(item.getFileName()); |
|
|
|
|
|
|
|
|
|
// 处理明细行
|
|
|
|
|
List<ZData> zDatas=new ArrayList<>(); |
|
|
|
|
for (SdnyTDxRecordInvoiceDetailSales detail : item.getDetailList()) { |
|
|
|
|
detail.setTaxRateOfSap(getTaxRate(detail.getTaxRate())); |
|
|
|
|
detail.setTaxRate(detail.getTaxRateOfSap().multiply(new BigDecimal(100)).stripTrailingZeros().toPlainString()); |
|
|
|
|
detail.setTaxRate(detail.getTaxRateOfSap().multiply(new BigDecimal(100)).setScale(4,BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString()); |
|
|
|
|
log.info("明细行数据:{}",JSONObject.toJSONString(detail)); |
|
|
|
|
BigDecimal totalAmount = new BigDecimal(detail.getDetailAmount()).add(new BigDecimal(detail.getTaxAmount())); |
|
|
|
|
zDatas.add(ZData.builder() |
|
|
|
|
.ZBHSJE(detail.getDetailAmount()) |
|
|
|
@ -312,14 +330,14 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
* @param taxRate |
|
|
|
|
* @return 去掉%的小数 |
|
|
|
|
*/ |
|
|
|
|
public BigDecimal getTaxRate(String taxRate) { |
|
|
|
|
public static BigDecimal getTaxRate(String taxRate) { |
|
|
|
|
if (StringUtils.isBlank(taxRate) || Constant.ZERO_TAXRATE_VALUE.contains(taxRate)) { |
|
|
|
|
taxRate = "0"; |
|
|
|
|
} else { |
|
|
|
|
taxRate = taxRate.replace("%", ""); |
|
|
|
|
// 判断是不是数字 不是数字的就给0
|
|
|
|
|
if (!isNumeric(taxRate)) { |
|
|
|
|
taxRate = "0.00"; |
|
|
|
|
taxRate = "0"; |
|
|
|
|
} else { |
|
|
|
|
// 不知道库里存的是13% 还是0.13 所以加一个判断
|
|
|
|
|
if (new BigDecimal(taxRate).compareTo(BigDecimal.ONE) >= 0) { |
|
|
|
@ -334,17 +352,21 @@ public class ImageSubmitServiceImpl implements ImageSubmitService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean isNumeric(String str){ |
|
|
|
|
for (int i = str.length();--i>=0;){ |
|
|
|
|
if (!Character.isDigit(str.charAt(i))){ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
Double.parseDouble(str); |
|
|
|
|
return true; |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
BigDecimal a = new BigDecimal(13); |
|
|
|
|
System.out.println(a.stripTrailingZeros().toPlainString()); |
|
|
|
|
BigDecimal a = new BigDecimal(0.13); |
|
|
|
|
String tax = a.multiply(new BigDecimal(100)).setScale(4,BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); |
|
|
|
|
System.out.println(StringUtils.isNumeric("13.00")); |
|
|
|
|
System.out.println(isNumeric("1e1")); |
|
|
|
|
System.out.println(getTaxRate("13.00")); |
|
|
|
|
System.out.println(TaxRateCodeEnum.getCode(tax)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|