From e6958e0f77c9b23985731399f587446a313ce881 Mon Sep 17 00:00:00 2001 From: pangyang <475446853@qq.com> Date: Mon, 13 Jun 2022 17:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E7=A5=A8=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=9F=A5=E8=AF=A2=E7=91=9E=E5=AE=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/mapper/InvInvoiceInfoMapper.java | 2 +- .../model/mapper/InvLinkInfoMapper.java | 3 + .../djy/invoice/service/InvoiceSendTask.java | 2 +- .../com/djy/invoice/service/InvoiceTask.java | 2 +- .../service/impl/InvLinkInfoServiceImpl.java | 219 +++++++++--------- .../resources/mapper/InvInvoiceInfoMapper.xml | 8 +- .../resources/mapper/InvLinkInfoMapper.xml | 4 + 7 files changed, 128 insertions(+), 112 deletions(-) diff --git a/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceInfoMapper.java b/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceInfoMapper.java index 3ec1f9a..8649a32 100644 --- a/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceInfoMapper.java +++ b/invoice/src/main/java/com/djy/invoice/model/mapper/InvInvoiceInfoMapper.java @@ -13,7 +13,7 @@ public interface InvInvoiceInfoMapper extends CommonMapper { List getByIds(String GID); void updateById(InvInvoiceInfo invoice); - List selectcheck(); + List selectcheck(String linkId); void updateBySerinal(InvInvoiceInfo invoice); diff --git a/invoice/src/main/java/com/djy/invoice/model/mapper/InvLinkInfoMapper.java b/invoice/src/main/java/com/djy/invoice/model/mapper/InvLinkInfoMapper.java index 449a3d4..c358bfb 100644 --- a/invoice/src/main/java/com/djy/invoice/model/mapper/InvLinkInfoMapper.java +++ b/invoice/src/main/java/com/djy/invoice/model/mapper/InvLinkInfoMapper.java @@ -19,4 +19,7 @@ public interface InvLinkInfoMapper extends CommonMapper { List selectByStatus(); + List selectLinkInfoByStatus(); + + } diff --git a/invoice/src/main/java/com/djy/invoice/service/InvoiceSendTask.java b/invoice/src/main/java/com/djy/invoice/service/InvoiceSendTask.java index 5be88cf..b50df27 100644 --- a/invoice/src/main/java/com/djy/invoice/service/InvoiceSendTask.java +++ b/invoice/src/main/java/com/djy/invoice/service/InvoiceSendTask.java @@ -44,7 +44,7 @@ public class InvoiceSendTask { @Autowired private InvInvoiceInfoMapper invInvoiceInfoMapper; -// @Scheduled(cron = "*/50 * * * * ?")//每个5秒执行一次任务(方法) + @Scheduled(cron = "*/58 * * * * ?")//每个5秒执行一次任务(方法) public void timeScheduled(){ diff --git a/invoice/src/main/java/com/djy/invoice/service/InvoiceTask.java b/invoice/src/main/java/com/djy/invoice/service/InvoiceTask.java index 8224647..8a403f1 100644 --- a/invoice/src/main/java/com/djy/invoice/service/InvoiceTask.java +++ b/invoice/src/main/java/com/djy/invoice/service/InvoiceTask.java @@ -11,7 +11,7 @@ public class InvoiceTask { @Autowired private InvLinkInfoService invLinkInfoService; - @Scheduled(cron = "*/20 * * * * ?")//每个5秒执行一次任务(方法) + @Scheduled(cron = "*/58 * * * * ?")//每个58秒执行一次任务(方法) public void timeScheduled(){ invLinkInfoService.getInvoice(new InvLinkInfo()); 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 d0d70c9..264f4cb 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 @@ -1098,153 +1098,158 @@ 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){ - - String linkid = invInvoiceSplitMapper.getLinkIdsByinvoiceId(invoice.getGID()); + List linkinfos = invLinkInfoMapper.selectLinkInfoByStatus(); + for(InvLinkInfo invlink : linkinfos){ + List list = invInvoiceInfoMapper.selectcheck(invlink.getGID()); + if(null != list && list.size()>0){ + ResponseData data = null; + for(InvInvoiceInfo invoice : list){ + +// String linkid = invInvoiceSplitMapper.getLinkIdsByinvoiceId(invoice.getGID()); +// +// InvLinkInfo invlink = new InvLinkInfo(); +// invlink.setGID(linkid); +// InvLinkInfo linkinfo = invLinkInfoMapper.selectByGID(invlink); +// if(!"1".equals(linkinfo.getStatus())){ +// continue; +// } - InvLinkInfo invlink = new InvLinkInfo(); - invlink.setGID(linkid); - InvLinkInfo linkinfo = invLinkInfoMapper.selectByGID(invlink); - if(!"1".equals(linkinfo.getStatus())){ - continue; - } + try { + data = new ResponseData(); + log.info(df.format(new Date())+"开始调用瑞宏查询接口"+",invoiceId="+invoice.getGID()); + data = UploadData.doPost(cmdCxName, getCx1Data(invoice)); + if(0 == data.getCode()){ + + ResultInvoice[] invoices = data.getInvoices(); + if(null != invoices && invoices.length>0){ + ResultInvoice result = invoices[0]; + String code = result.getCode(); + invoice.setInvCode(code.substring(0,12)); + invoice.setInvNum(code.substring(12,20)); + invoice.setPdfUrl(result.getPdfUnsignedUrl()); + invoice.setPictureUrl(result.getViewUrl()); + invoice.setApiReadTime(df.parse(df.format(new Date()))); + invoice.setStatus("success"); + invInvoiceInfoMapper.updateBySerinal(invoice); + } - try { - data = new ResponseData(); - log.info(df.format(new Date())+"开始调用瑞宏查询接口"+",invoiceId="+invoice.getGID()); - data = UploadData.doPost(cmdCxName, getCx1Data(invoice)); - if(0 == data.getCode()){ - - ResultInvoice[] invoices = data.getInvoices(); - if(null != invoices && invoices.length>0){ - ResultInvoice result = invoices[0]; - String code = result.getCode(); - invoice.setInvCode(code.substring(0,12)); - invoice.setInvNum(code.substring(12,20)); - invoice.setPdfUrl(result.getPdfUnsignedUrl()); - invoice.setPictureUrl(result.getViewUrl()); - invoice.setApiReadTime(df.parse(df.format(new Date()))); - invoice.setStatus("success"); + }else if(6 == data.getCode()){//正在处理中 + invoice.setStatus("process"); + invoice.setMessage(JSON.toJSONString(data)); + invInvoiceInfoMapper.updateBySerinal(invoice); + }else{ + invoice.setStatus("fail"); + invoice.setMessage(JSON.toJSONString(data)); invInvoiceInfoMapper.updateBySerinal(invoice); - } - }else if(6 == data.getCode()){//正在处理中 - invoice.setStatus("process"); - invoice.setMessage(JSON.toJSONString(data)); - invInvoiceInfoMapper.updateBySerinal(invoice); - }else{ - invoice.setStatus("fail"); - invoice.setMessage(JSON.toJSONString(data)); - invInvoiceInfoMapper.updateBySerinal(invoice); + } + } catch (Exception e) { + e.printStackTrace(); } - } catch (Exception e) { - e.printStackTrace(); } - } + //查询所有发票对应的链接 + List links = new ArrayList<>(); + List lindIds = new ArrayList<>(); - //查询所有发票对应的链接 - List links = new ArrayList<>(); - List lindIds = new ArrayList<>(); + for(InvInvoiceInfo invoice : list){ - for(InvInvoiceInfo invoice : list){ +// String linkid = invInvoiceSplitMapper.getLinkIdsByinvoiceId(invoice.getGID()); +// +// InvLinkInfo invlink = new InvLinkInfo(); +// invlink.setGID(linkid); +// InvLinkInfo invlinkinfo = invLinkInfoMapper.selectByGID(invlink); +// if(!"1".equals(invlinkinfo.getStatus())){ +// continue; +// } - String linkid = invInvoiceSplitMapper.getLinkIdsByinvoiceId(invoice.getGID()); + String likid = invInvoiceSplitMapper.getlinkdId(invoice.getGID()); + //判断是否存在重复的linkid + if(lindIds.contains(likid)){ + continue; + }else{ + lindIds.add(likid); + } - InvLinkInfo invlink = new InvLinkInfo(); - invlink.setGID(linkid); - InvLinkInfo invlinkinfo = invLinkInfoMapper.selectByGID(invlink); - if(!"1".equals(invlinkinfo.getStatus())){ - continue; - } + InvLinkInfo linkinfo = new InvLinkInfo(); + linkinfo.setGID(likid); + InvLinkInfo link = invLinkInfoMapper.selectByGID(linkinfo); + links.add(link); - String likid = invInvoiceSplitMapper.getlinkdId(invoice.getGID()); - //判断是否存在重复的linkid - if(lindIds.contains(likid)){ - continue; - }else{ - lindIds.add(likid); } - InvLinkInfo linkinfo = new InvLinkInfo(); - linkinfo.setGID(likid); - InvLinkInfo link = invLinkInfoMapper.selectByGID(linkinfo); - links.add(link); - - } - - if(null != links && links.size()>0){ + if(null != links && links.size()>0){ - InvLinkTaskDto dto = null; + InvLinkTaskDto dto = null; - for(InvLinkInfo link : links){ + for(InvLinkInfo link : links){ - dto = new InvLinkTaskDto(); + dto = new InvLinkTaskDto(); - //查询当前链表下的所有发票 - List listId = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID()); + //查询当前链表下的所有发票 + List listId = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID()); - if(null !=listId && listId.size()>0){ - List invoices = new ArrayList<>(); - int size = listId.size(); - for(int i=0;i0){ + List invoices = new ArrayList<>(); + int size = listId.size(); + for(int i=0;i开票流水号:"+invoice.getSerialNo()+"&&&"+"
开票失败原因:"+invoice.getMessage()+"
#"; + if("fail".equals(invoice.getStatus())){ + content = content +"
开票流水号:"+invoice.getSerialNo()+"
&&&"+"
开票失败原因:"+invoice.getMessage()+"
#"; - }else{ - content = content +"
发票号码:"+invoice.getInvNum()+"
&&&"+"
发票PDF地址:"+invoice.getPdfUrl()+"
#"; + }else{ + content = content +"
发票号码:"+invoice.getInvNum()+"
&&&"+"
发票PDF地址:"+invoice.getPdfUrl()+"
#"; + } } - } - content = content.substring(0,content.length()-1); + content = content.substring(0,content.length()-1); - SendEmailParams param = new SendEmailParams(); + SendEmailParams param = new SendEmailParams(); - List listEmail = new ArrayList<>(); + List listEmail = new ArrayList<>(); - SendEmail email = new SendEmail(); - email.setSendTo(link.getEmail()); - email.setTitle(subject); - email.setBody(content); - email.setSmtpConfig(SmtpConfig); - listEmail.add(email); - param.setList(listEmail); + SendEmail email = new SendEmail(); + email.setSendTo(link.getEmail()); + email.setTitle(subject); + email.setBody(content); + email.setSmtpConfig(SmtpConfig); + listEmail.add(email); + param.setList(listEmail); - String str = JSONObject.toJSONString(param.getList()); - sendEMail(str); + String str = JSONObject.toJSONString(param.getList()); + sendEMail(str); - }else{ - link.setStatus("3"); - invLinkInfoMapper.updateById(link); - } + }else{ + link.setStatus("3"); + invLinkInfoMapper.updateById(link); + } + } } } - } + } } + + return HttpResult.ok(); } diff --git a/invoice/src/main/resources/mapper/InvInvoiceInfoMapper.xml b/invoice/src/main/resources/mapper/InvInvoiceInfoMapper.xml index e0e6325..9a6e482 100644 --- a/invoice/src/main/resources/mapper/InvInvoiceInfoMapper.xml +++ b/invoice/src/main/resources/mapper/InvInvoiceInfoMapper.xml @@ -81,8 +81,12 @@ select * from InvInvoiceInfo info WHERE GID = #{GID} and (Status='success' or Status='fail') - + + SELECT info.* FROM InvInvoiceInfo info + WHERE info.GID IN (SELECT distinct(split.InvoiceId) from InvInvoiceSplit split LEFT JOIN InvLinkInfo link + ON split.LinkId = link.GID + where split.LinkId = #{linkId}) and info.InvCode is null and (info.Status is null or info.Status='process') diff --git a/invoice/src/main/resources/mapper/InvLinkInfoMapper.xml b/invoice/src/main/resources/mapper/InvLinkInfoMapper.xml index d503e77..85db7c3 100644 --- a/invoice/src/main/resources/mapper/InvLinkInfoMapper.xml +++ b/invoice/src/main/resources/mapper/InvLinkInfoMapper.xml @@ -36,6 +36,10 @@ SELECT * from InvLinkInfo linkinfo where linkinfo.GID = #{GID} + +