diff --git a/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java b/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java index f25aad0..9cc2d09 100644 --- a/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java +++ b/invoice/src/main/java/com/djy/invoice/controller/InvLinkInfoController.java @@ -19,7 +19,7 @@ public class InvLinkInfoController { @Operation(description = "外部调用接口") @PostMapping("getlink") - public HttpResult getlink(@RequestBody InvLinkInfo info) { + public HttpResult getlink(InvLinkInfo info) { return invLinkInfoService.getlink(info); } @@ -46,9 +46,8 @@ public class InvLinkInfoController { @PostMapping("uploadInvoice") public HttpResult uploadInvoice(InvLinkInfo info) { - invLinkInfoService.uploadInvoice(info); + return invLinkInfoService.uploadInvoice(info); - return HttpResult.ok(); } @Operation(description = "查询发票") diff --git a/invoice/src/main/java/com/djy/invoice/model/InvLinkInfo.java b/invoice/src/main/java/com/djy/invoice/model/InvLinkInfo.java index 0528f36..a2f0317 100644 --- a/invoice/src/main/java/com/djy/invoice/model/InvLinkInfo.java +++ b/invoice/src/main/java/com/djy/invoice/model/InvLinkInfo.java @@ -88,5 +88,10 @@ public class InvLinkInfo { //发送状态 0:未发送 1:已发送 private String SendStatus; + //人民币拆分金额 + private String rmbsplits; + //usd拆分金额 + private String usdsplits; + } diff --git a/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceDetailMapper.java b/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceDetailMapper.java index 3de17b9..6698322 100644 --- a/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceDetailMapper.java +++ b/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceDetailMapper.java @@ -11,6 +11,9 @@ public interface InvInvoiceDetailMapper extends CommonMapper { InvInvoiceDetail getByInvoiceGId(String GID); + InvInvoiceDetail getByGId(String GID); + + void deleteByGID(InvInvoiceDetail info); } diff --git a/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceSplitMapper.java b/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceSplitMapper.java index 32dfe95..1652c64 100644 --- a/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceSplitMapper.java +++ b/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceSplitMapper.java @@ -19,6 +19,12 @@ public interface InvInvoiceSplitMapper extends CommonMapper { String getlinkdId(String GID); + List getDetailIdsBylinkdIdAndCurrency(InvInvoiceSplit info); + + List getBydetailId(String detailId); + + + } diff --git a/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java b/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java index 64aeef4..c7b573a 100644 --- a/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java +++ b/invoice/src/main/java/com/djy/invoice/service/impl/InvLinkInfoServiceImpl.java @@ -890,19 +890,43 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { businesses.add(business); } + InvInvoiceSplit split = new InvInvoiceSplit(); + split.setCurrency("RMB"); + split.setLinkId(link.getGID()); + List detailIds = invInvoiceSplitMapper.getDetailIdsBylinkdIdAndCurrency(split); - fee = new InvFeeInfo(); - fee.setLinkId(info.getGID()); - fee.setCurrency("RMB"); - List fees = invFeeInfoMapper.getListBylink(fee); + + //获取人民币的发票明细 + List details = getDetails(detailIds); + + +// fee = new InvFeeInfo(); +// fee.setLinkId(info.getGID()); +// fee.setCurrency("RMB"); +// List fees = invFeeInfoMapper.getListBylink(fee); int rmbamount =0; BigDecimal sumfees = new BigDecimal(0); - if(null != fees && fees.size()>0){ - sumfees = fees.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); - rmbamount = getInvoiceAmount(fees,link,sumfees); + String rmbsplits = ""; + + if(null != details && details.size()>0){ + sumfees = details.stream().map(InvInvoiceDetail::getTaxExcludedAmount).reduce(BigDecimal.ZERO,BigDecimal::add); + rmbamount = details.size(); + rmbsplits = getSplits(details); + } + + + + InvInvoiceSplit splitusd = new InvInvoiceSplit(); + splitusd.setCurrency("USD"); + splitusd.setLinkId(link.getGID()); + List detailIdusds = invInvoiceSplitMapper.getDetailIdsBylinkdIdAndCurrency(splitusd); + + //获取USD的发票明细 + List detailusds = getDetails(detailIdusds); + InvFeeInfo feeNoRmb = new InvFeeInfo(); feeNoRmb.setLinkId(info.getGID()); List feesNoRmb = invFeeInfoMapper.getListBylinkNoRmb(feeNoRmb); @@ -910,18 +934,26 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { int usdamount =0; BigDecimal usdInvoiceAmount = new BigDecimal(0); BigDecimal usdfees = new BigDecimal(0); - if(null != feesNoRmb && feesNoRmb.size()>0){ - usdfees = feesNoRmb.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); - usdamount = getInvoiceAmount(feesNoRmb,link,usdfees); - usdInvoiceAmount = usdfees.multiply(feesNoRmb.get(0).getExchangeRate()).setScale(2,BigDecimal.ROUND_HALF_UP); + + String usdsplits=""; + if(null != detailusds && detailusds.size()>0){ + //usd转为人民币金额 + usdInvoiceAmount = detailusds.stream().map(InvInvoiceDetail::getTaxExcludedAmount).reduce(BigDecimal.ZERO,BigDecimal::add); + usdamount = detailusds.size(); + //usd原币金额 + usdfees = usdInvoiceAmount.divide(feesNoRmb.get(0).getExchangeRate()).setScale(2,BigDecimal.ROUND_HALF_UP); + usdsplits = getSplits(detailusds); } + link.setUsdInvoiceAmount(usdInvoiceAmount); link.setRmbAmount(rmbamount); link.setUsdAmount(usdamount); link.setRmbFees(sumfees); link.setUsdFess(usdfees); + link.setRmbsplits(rmbsplits); + link.setUsdsplits(usdsplits); if(usdInvoiceAmount.compareTo(invoiceAmount)==1 && sumfees.compareTo(invoiceAmount)==1){ link.setInvoiceAmount(rmbamount+usdamount); @@ -935,14 +967,45 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } - - link.setBillList(businesses); return link; } + public List getDetails(List detail){ + List details = new ArrayList<>(); + + if(null != detail && detail.size()>0){ + for(String str : detail){ + InvInvoiceDetail det = invInvoiceDetailMapper.getByGId(str); + if(null != det){ + details.add(det); + } + } + } + + return details; + } + + public String getSplits(List details){ + String split = ""; + for(InvInvoiceDetail usd : details){ + List splits = invInvoiceSplitMapper.getBydetailId(usd.getGID()); + if(null != splits && splits.size()>0){ + for(InvInvoiceSplit spl : splits){ + split = split+spl.getSplitAmountRMB()+"元,"; + } + + } + } + + split = split.substring(0, split.length()-1); + return split; + + } + + @Override @Transactional public HttpResult uploadInvoice(InvLinkInfo info) { @@ -967,6 +1030,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { InvInvoiceInfo invoice = invInvoiceInfoMapper.getByGid(invoiceIds.get(i)); try { data = new ResponseData(); + log.info(df.format(new Date())+"开始调用瑞宏开票接口"+",invoiceId="+invoice.getGID()); data = UploadData.doPost(cmdName, getKpData(invoice)); invoice.setSerialNo(data.getSerialNo()); invoice.setApiSendTime(df.parse(df.format(new Date()))); @@ -988,14 +1052,13 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { public HttpResult getInvoice(InvLinkInfo info) { - - List list = invInvoiceInfoMapper.selectcheck(); if(null != list && list.size()>0){ ResponseData data = null; for(InvInvoiceInfo invoice : list){ try { data = new ResponseData(); + log.info(df.format(new Date())+"开始调用瑞宏查询接口"+",invoiceId="+invoice.getGID()); data = UploadData.doPost(cmdCxName, getCx1Data(invoice)); if(0 == data.getCode()){ diff --git a/invoice/src/main/resources/mapper/InvInvoiceDetailMapper.xml b/invoice/src/main/resources/mapper/InvInvoiceDetailMapper.xml index 0279de2..51b81f6 100644 --- a/invoice/src/main/resources/mapper/InvInvoiceDetailMapper.xml +++ b/invoice/src/main/resources/mapper/InvInvoiceDetailMapper.xml @@ -39,6 +39,10 @@ select * from InvInvoiceDetail info WHERE InvId = #{GID} + + diff --git a/invoice/src/main/resources/mapper/InvInvoiceSplitMapper.xml b/invoice/src/main/resources/mapper/InvInvoiceSplitMapper.xml index 5e9a8f7..16a05ac 100644 --- a/invoice/src/main/resources/mapper/InvInvoiceSplitMapper.xml +++ b/invoice/src/main/resources/mapper/InvInvoiceSplitMapper.xml @@ -38,6 +38,19 @@ + + + @@ -47,6 +60,10 @@ SELECT * ,info.BSNO AS 'BSNO' from InvInvoiceSplit split left join InvBusinessInfo info on split.BusinessId = info.GID where split.LinkId = #{GID} + + delete from InvInvoiceSplit where LinkId=#{GID}