|
|
|
@ -1098,153 +1098,158 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
|
|
|
|
|
public HttpResult getInvoice(InvLinkInfo info) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<InvInvoiceInfo> list = invInvoiceInfoMapper.selectcheck();
|
|
|
|
|
if(null != list && list.size()>0){
|
|
|
|
|
ResponseData data = null;
|
|
|
|
|
for(InvInvoiceInfo invoice : list){
|
|
|
|
|
|
|
|
|
|
String linkid = invInvoiceSplitMapper.getLinkIdsByinvoiceId(invoice.getGID());
|
|
|
|
|
List<InvLinkInfo> linkinfos = invLinkInfoMapper.selectLinkInfoByStatus();
|
|
|
|
|
for(InvLinkInfo invlink : linkinfos){
|
|
|
|
|
List<InvInvoiceInfo> 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<InvLinkInfo> links = new ArrayList<>();
|
|
|
|
|
List<String> lindIds = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
//查询所有发票对应的链接
|
|
|
|
|
List<InvLinkInfo> links = new ArrayList<>();
|
|
|
|
|
List<String> 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<String> listId = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID());
|
|
|
|
|
//查询当前链表下的所有发票
|
|
|
|
|
List<String> listId = invInvoiceSplitMapper.getIdsBylinkdId(link.getGID());
|
|
|
|
|
|
|
|
|
|
if(null !=listId && listId.size()>0){
|
|
|
|
|
List<InvInvoiceInfo> invoices = new ArrayList<>();
|
|
|
|
|
int size = listId.size();
|
|
|
|
|
for(int i=0;i<listId.size();i++){
|
|
|
|
|
//如果状态Status是success 或fail
|
|
|
|
|
InvInvoiceInfo invoice = invInvoiceInfoMapper.getByGidAndStatus(listId.get(i));
|
|
|
|
|
if(null != invoice && null != invoice.getGID()){
|
|
|
|
|
invoices.add(invoice);
|
|
|
|
|
if(null !=listId && listId.size()>0){
|
|
|
|
|
List<InvInvoiceInfo> invoices = new ArrayList<>();
|
|
|
|
|
int size = listId.size();
|
|
|
|
|
for(int i=0;i<listId.size();i++){
|
|
|
|
|
//如果状态Status是success 或fail
|
|
|
|
|
InvInvoiceInfo invoice = invInvoiceInfoMapper.getByGidAndStatus(listId.get(i));
|
|
|
|
|
if(null != invoice && null != invoice.getGID()){
|
|
|
|
|
invoices.add(invoice);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//判断改链接底下的查询出的发票success 或fail是否与总数相等
|
|
|
|
|
if(size == invoices.size()){
|
|
|
|
|
link.setStatus("2");
|
|
|
|
|
invLinkInfoMapper.updateById(link);
|
|
|
|
|
String content ="";
|
|
|
|
|
//判断改链接底下的查询出的发票success 或fail是否与总数相等
|
|
|
|
|
if(size == invoices.size()){
|
|
|
|
|
link.setStatus("2");
|
|
|
|
|
invLinkInfoMapper.updateById(link);
|
|
|
|
|
String content ="";
|
|
|
|
|
// String subject = "发票信息";
|
|
|
|
|
for(InvInvoiceInfo invoice : invoices){
|
|
|
|
|
for(InvInvoiceInfo invoice : invoices){
|
|
|
|
|
|
|
|
|
|
if("fail".equals(invoice.getStatus())){
|
|
|
|
|
content = content +"<div>开票流水号:"+invoice.getSerialNo()+"</div>&&&"+"<div>开票失败原因:"+invoice.getMessage()+"</div>#";
|
|
|
|
|
if("fail".equals(invoice.getStatus())){
|
|
|
|
|
content = content +"<div>开票流水号:"+invoice.getSerialNo()+"</div>&&&"+"<div>开票失败原因:"+invoice.getMessage()+"</div>#";
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
content = content +"<div>发票号码:"+invoice.getInvNum()+"</div>&&&"+"<div>发票PDF地址:"+invoice.getPdfUrl()+"</div>#";
|
|
|
|
|
}else{
|
|
|
|
|
content = content +"<div>发票号码:"+invoice.getInvNum()+"</div>&&&"+"<div>发票PDF地址:"+invoice.getPdfUrl()+"</div>#";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
content = content.substring(0,content.length()-1);
|
|
|
|
|
content = content.substring(0,content.length()-1);
|
|
|
|
|
|
|
|
|
|
SendEmailParams param = new SendEmailParams();
|
|
|
|
|
SendEmailParams param = new SendEmailParams();
|
|
|
|
|
|
|
|
|
|
List<SendEmail> listEmail = new ArrayList<>();
|
|
|
|
|
List<SendEmail> 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|