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 b7f1560..8055323 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 @@ -66,6 +66,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { + //判断是否数字 public static boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); if(str.indexOf(".")>0){//判断是否有小数点 @@ -79,6 +80,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } } + //上传链接、业务数据和费用数据 @Transactional @Override public HttpResult getlink(String json) { @@ -106,6 +108,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { HttpResult result = parameterFeignClient.getParameter(linkinfo.getCompanyId()); String amount =(String)result.getData(); + //判断开票限额格式和是否存在 if(null == amount){ return HttpResult.error(20060,"linkId="+linkinfo.getLinkId()+",CompanyId="+linkinfo.getCompanyId()+",开票数额不存在,请检查"); }else{ @@ -138,6 +141,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } } + //赋值给链表状态 linkinfo.setStatus("0"); linkinfo.setSendStatus("0"); try { @@ -150,6 +154,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { // JSONArray array = jsonObj.getJSONArray("BillList"); + //生成业务信息 List array = linkinfo.getBillList(); for(int i=0; i feearray = business.getFeeList(); + //重新生成费用信息 for(int j=0; j invoiceIds = invInvoiceSplitMapper.getIdsBylinkdId(linkinfo.getGID()); for(String str : invoiceIds){ @@ -305,6 +315,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } + //重新上传时,删除发票、发票明细、分票情况 public void deleteSplit(InvLinkInfo link){ List list = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID()); @@ -326,7 +337,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } - + //组装发票明细 InvInvoiceDetail getInvInvoiceDetail(InvInvoiceInfo invoice,InvFeeInfo feeinfo,BigDecimal amount){ InvInvoiceDetail detail = new InvInvoiceDetail(); detail.setGID(UUID.randomUUID().toString().replace("-", "")); @@ -358,6 +369,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } + //组装发票分配 InvInvoiceSplit getInvInvoiceSplit(InvInvoiceInfo invoice,InvInvoiceDetail detail,InvFeeInfo feeinfo,InvLinkInfo link,BigDecimal amount){ InvInvoiceSplit split = new InvInvoiceSplit(); split.setGID(UUID.randomUUID().toString().replace("-", "")); @@ -388,6 +400,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { + //开始生成发票、发票明细、发票分配 void invoicepzRmb(List fees,InvLinkInfo link,BigDecimal sumfees){ if(null != fees && fees.size()>0){ @@ -407,7 +420,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { //如果费用总计小于等于最大开票金额 - if(checkinvocie.compareTo(sumfees) == 1){ + if(checkinvocie.compareTo(sumfees) == 1 || checkinvocie.compareTo(sumfees) == 0 ){ InvInvoiceInfo invoice = new InvInvoiceInfo(); BeanUtils.copyProperties(link,invoice); invoice.setStatus(null); @@ -426,20 +439,19 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { InvInvoiceSplit split = getInvInvoiceSplit(invoice,detail,feeinfo,link,feeinfo.getAmount()); invInvoiceSplitMapper.add(split); } - }else{ - + }else{//如果费用总计大于开票限额 BigDecimal amount = new BigDecimal(0); // List details = new ArrayList<>(); List splits = new ArrayList<>(); InvInvoiceInfo invoice = null; for(int i=0;i0){ -// for(InvInvoiceSplit sp : splits){ -// sp.setInvoiceId(invoice.getGID()); -// sp.setInvoiceDetailId(detail.getGID()); -// sp.setGID(UUID.randomUUID().toString().replace("-", "")); -// invInvoiceSplitMapper.add(sp); -// } -// } if(null != splits && splits.size()>0){ for(InvInvoiceSplit sp : splits){ @@ -634,13 +641,9 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { InvInvoiceSplit spl = getInvInvoiceSplit(invoice,det,feeinfo,link,feeinfo.getAmount()); invInvoiceSplitMapper.add(spl); } - - amount = feeinfo.getAmount(); //先清空发票分配 splits = new ArrayList<>(); - - //把当前的发票分配添加进集合 InvInvoiceSplit spl = getInvInvoiceSplit(invoice,detail,feeinfo,link,feeinfo.getAmount()); splits.add(spl); @@ -650,7 +653,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { }else{ //如果amount等于最大开票金额 if(amount.compareTo(checkinvocie)==0){ - //生成发票和发票明细 + //生成发票和发票明细、发票配置 invoice = new InvInvoiceInfo(); BeanUtils.copyProperties(link,invoice); invoice.setStatus(null); @@ -678,11 +681,12 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { } amount = new BigDecimal(0); splits = new ArrayList<>(); - }else{ + }else{//如果amount小于最大开票金额 //生成发票分配 InvInvoiceSplit split = getInvInvoiceSplit(new InvInvoiceInfo(),new InvInvoiceDetail(),feeinfo,link,feeinfo.getAmount()); splits.add(split); + //如果是最后一条记录 if(i==fees.size()-1){ BigDecimal sums = splits.stream().map(InvInvoiceSplit::getAmountTotal).reduce(BigDecimal.ZERO,BigDecimal::add); invoice = new InvInvoiceInfo(); @@ -728,6 +732,7 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { // @Transactional // @Override + //生成发票、发票明细、发票分配 public HttpResult createSplit(InvLinkInfo info) { log.info("连接id====={}",info.getGID()); @@ -747,12 +752,14 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { InvFeeInfo fee = new InvFeeInfo(); fee.setLinkId(info.getGID()); fee.setCurrency("RMB"); + //人民币费用合计 List fees = invFeeInfoMapper.getListBylink(fee); BigDecimal sumfees = fees.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); InvFeeInfo feeNoRmb = new InvFeeInfo(); feeNoRmb.setLinkId(info.getGID()); + //非人民币费用合计 List feesNoRmb = invFeeInfoMapper.getListBylinkNoRmb(feeNoRmb); BigDecimal sumNormbfees = feesNoRmb.stream().map(InvFeeInfo::getAmount).reduce(BigDecimal.ZERO,BigDecimal::add); @@ -761,40 +768,6 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService { invoicepzRmb(fees,link,sumfees); //创建非人民币发票 invoicepzRmb(feesNoRmb,link,sumNormbfees); -// -// List invoiceIds = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID()); -// -//// List list = invInvoiceInfoMapper.getByIds(link.getGID()); -// -// if(null !=invoiceIds && invoiceIds.size()>0){ -// ResponseData data = null; -// for(int i=0;i