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

master
pangyang 2 years ago
parent 2ee0c22970
commit e6958e0f77

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

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

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

@ -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());

@ -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();
}

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

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

Loading…
Cancel
Save