开票定时任务查询瑞宏接口

master
pangyang 2 years ago
parent 2ee0c22970
commit e6958e0f77

@ -13,7 +13,7 @@ public interface InvInvoiceInfoMapper extends CommonMapper<InvInvoiceInfo> {
List<InvInvoiceInfo> getByIds(String GID); List<InvInvoiceInfo> getByIds(String GID);
void updateById(InvInvoiceInfo invoice); void updateById(InvInvoiceInfo invoice);
List<InvInvoiceInfo> selectcheck(); List<InvInvoiceInfo> selectcheck(String linkId);
void updateBySerinal(InvInvoiceInfo invoice); void updateBySerinal(InvInvoiceInfo invoice);

@ -19,4 +19,7 @@ public interface InvLinkInfoMapper extends CommonMapper<InvLinkInfo> {
List<InvLinkInfo> selectByStatus(); List<InvLinkInfo> selectByStatus();
List<InvLinkInfo> selectLinkInfoByStatus();
} }

@ -44,7 +44,7 @@ public class InvoiceSendTask {
@Autowired @Autowired
private InvInvoiceInfoMapper invInvoiceInfoMapper; private InvInvoiceInfoMapper invInvoiceInfoMapper;
// @Scheduled(cron = "*/50 * * * * ?")//每个5秒执行一次任务(方法) @Scheduled(cron = "*/58 * * * * ?")//每个5秒执行一次任务(方法)
public void timeScheduled(){ public void timeScheduled(){

@ -11,7 +11,7 @@ public class InvoiceTask {
@Autowired @Autowired
private InvLinkInfoService invLinkInfoService; private InvLinkInfoService invLinkInfoService;
@Scheduled(cron = "*/20 * * * * ?")//每个5秒执行一次任务(方法) @Scheduled(cron = "*/58 * * * * ?")//每个58秒执行一次任务(方法)
public void timeScheduled(){ public void timeScheduled(){
invLinkInfoService.getInvoice(new InvLinkInfo()); invLinkInfoService.getInvoice(new InvLinkInfo());

@ -1098,153 +1098,158 @@ public class InvLinkInfoServiceImpl implements InvLinkInfoService {
public HttpResult getInvoice(InvLinkInfo info) { public HttpResult getInvoice(InvLinkInfo info) {
List<InvInvoiceInfo> list = invInvoiceInfoMapper.selectcheck(); List<InvLinkInfo> linkinfos = invLinkInfoMapper.selectLinkInfoByStatus();
if(null != list && list.size()>0){ for(InvLinkInfo invlink : linkinfos){
ResponseData data = null; List<InvInvoiceInfo> list = invInvoiceInfoMapper.selectcheck(invlink.getGID());
for(InvInvoiceInfo invoice : list){ if(null != list && list.size()>0){
ResponseData data = null;
String linkid = invInvoiceSplitMapper.getLinkIdsByinvoiceId(invoice.getGID()); 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(); try {
invlink.setGID(linkid); data = new ResponseData();
InvLinkInfo linkinfo = invLinkInfoMapper.selectByGID(invlink); log.info(df.format(new Date())+"开始调用瑞宏查询接口"+",invoiceId="+invoice.getGID());
if(!"1".equals(linkinfo.getStatus())){ data = UploadData.doPost(cmdCxName, getCx1Data(invoice));
continue; 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 { }else if(6 == data.getCode()){//正在处理中
data = new ResponseData(); invoice.setStatus("process");
log.info(df.format(new Date())+"开始调用瑞宏查询接口"+",invoiceId="+invoice.getGID()); invoice.setMessage(JSON.toJSONString(data));
data = UploadData.doPost(cmdCxName, getCx1Data(invoice)); invInvoiceInfoMapper.updateBySerinal(invoice);
if(0 == data.getCode()){ }else{
invoice.setStatus("fail");
ResultInvoice[] invoices = data.getInvoices(); invoice.setMessage(JSON.toJSONString(data));
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); 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<>();
//查询所有发票对应的链接 for(InvInvoiceInfo invoice : list){
List<InvLinkInfo> links = new ArrayList<>();
List<String> lindIds = new ArrayList<>();
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(); InvLinkInfo linkinfo = new InvLinkInfo();
invlink.setGID(linkid); linkinfo.setGID(likid);
InvLinkInfo invlinkinfo = invLinkInfoMapper.selectByGID(invlink); InvLinkInfo link = invLinkInfoMapper.selectByGID(linkinfo);
if(!"1".equals(invlinkinfo.getStatus())){ links.add(link);
continue;
}
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){ if(null !=listId && listId.size()>0){
List<InvInvoiceInfo> invoices = new ArrayList<>(); List<InvInvoiceInfo> invoices = new ArrayList<>();
int size = listId.size(); int size = listId.size();
for(int i=0;i<listId.size();i++){ for(int i=0;i<listId.size();i++){
//如果状态Status是success 或fail //如果状态Status是success 或fail
InvInvoiceInfo invoice = invInvoiceInfoMapper.getByGidAndStatus(listId.get(i)); InvInvoiceInfo invoice = invInvoiceInfoMapper.getByGidAndStatus(listId.get(i));
if(null != invoice && null != invoice.getGID()){ if(null != invoice && null != invoice.getGID()){
invoices.add(invoice); invoices.add(invoice);
}
} }
} //判断改链接底下的查询出的发票success 或fail是否与总数相等
//判断改链接底下的查询出的发票success 或fail是否与总数相等 if(size == invoices.size()){
if(size == invoices.size()){ link.setStatus("2");
link.setStatus("2"); invLinkInfoMapper.updateById(link);
invLinkInfoMapper.updateById(link); String content ="";
String content ="";
// String subject = "发票信息"; // String subject = "发票信息";
for(InvInvoiceInfo invoice : invoices){ for(InvInvoiceInfo invoice : invoices){
if("fail".equals(invoice.getStatus())){ if("fail".equals(invoice.getStatus())){
content = content +"<div>开票流水号:"+invoice.getSerialNo()+"</div>&&&"+"<div>开票失败原因:"+invoice.getMessage()+"</div>#"; content = content +"<div>开票流水号:"+invoice.getSerialNo()+"</div>&&&"+"<div>开票失败原因:"+invoice.getMessage()+"</div>#";
}else{ }else{
content = content +"<div>发票号码:"+invoice.getInvNum()+"</div>&&&"+"<div>发票PDF地址:"+invoice.getPdfUrl()+"</div>#"; 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(); SendEmail email = new SendEmail();
email.setSendTo(link.getEmail()); email.setSendTo(link.getEmail());
email.setTitle(subject); email.setTitle(subject);
email.setBody(content); email.setBody(content);
email.setSmtpConfig(SmtpConfig); email.setSmtpConfig(SmtpConfig);
listEmail.add(email); listEmail.add(email);
param.setList(listEmail); param.setList(listEmail);
String str = JSONObject.toJSONString(param.getList()); String str = JSONObject.toJSONString(param.getList());
sendEMail(str); sendEMail(str);
}else{ }else{
link.setStatus("3"); link.setStatus("3");
invLinkInfoMapper.updateById(link); invLinkInfoMapper.updateById(link);
} }
}
} }
} }
}
}
} }
return HttpResult.ok(); return HttpResult.ok();
} }

@ -81,8 +81,12 @@
select * from InvInvoiceInfo info WHERE GID = #{GID} and (Status='success' or Status='fail') select * from InvInvoiceInfo info WHERE GID = #{GID} and (Status='success' or Status='fail')
</select> </select>
<select id="selectcheck" resultMap="invInvoiceInfoMap" > <select id="selectcheck" resultMap="invInvoiceInfoMap" parameterType="String">
select * from InvInvoiceInfo info WHERE info.InvCode is null and (info.Status is null or info.Status='process')
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')
</select> </select>

@ -36,6 +36,10 @@
SELECT * from InvLinkInfo linkinfo where linkinfo.GID = #{GID} SELECT * from InvLinkInfo linkinfo where linkinfo.GID = #{GID}
</select> </select>
<select id="selectLinkInfoByStatus" resultMap="invLinkInfoMap" >
SELECT * from InvLinkInfo linkinfo where linkinfo.Status='1'
</select>
<select id="selectByStatus" resultMap="invLinkInfoMap" parameterType="String"> <select id="selectByStatus" resultMap="invLinkInfoMap" parameterType="String">
SELECT * from InvLinkInfo linkinfo where linkinfo.Status = '2' and linkinfo.SendStatus='0' SELECT * from InvLinkInfo linkinfo where linkinfo.Status = '2' and linkinfo.SendStatus='0'
</select> </select>

Loading…
Cancel
Save