diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/model/PushInfoRecord.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/model/PushInfoRecord.java index b2631339..a7c1915f 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/model/PushInfoRecord.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/model/PushInfoRecord.java @@ -7,18 +7,40 @@ import java.util.Date; @Data public class PushInfoRecord { private Long id; - + /** + * 接口类型 + */ private String interfacePushType; - + /** + * 企业类型 + */ private String qyType; - + /** + * 推送状态 + */ private String pushStatus; - + /** + * 创建时间 + */ private Date createTime; - + /** + * 推送内容 + */ private String pushContent; - + /** + * 结果 + */ private String result; - + /** + * 失败原因 + */ private String failReason; + /** + * 推送路径ID + */ + private String pushInfoId; + /** + * 重试次数 + */ + private Integer retryCount; } \ No newline at end of file diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/PushInvoiceService.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/PushInvoiceService.java index 5dd6cd70..afcf99dd 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/PushInvoiceService.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/PushInvoiceService.java @@ -1,7 +1,9 @@ package com.dxhy.order.consumer.modules.manager.service; +import com.dxhy.order.exception.OrderReceiveException; import com.dxhy.order.model.R; import com.dxhy.order.invoice.module.invoice.model.PushInfo; +import com.dxhy.order.model.queue.CommonTsMqData; import java.util.List; @@ -12,14 +14,14 @@ import java.util.List; * @date :2018年10月17日 下午6:01:48 */ public interface PushInvoiceService { - + /** * 推送近一个月邮箱发送失败的数据 * * @param shList */ void pushInvoiceEmailMonthTask(List shList); - + /** * 推送统一路由 * @@ -27,7 +29,7 @@ public interface PushInvoiceService { * @return */ R pushRouting(String pushMsg); - + /** * 推送地址配置列表 * @@ -36,7 +38,7 @@ public interface PushInvoiceService { * @return */ List queryPushInfoList(PushInfo pushInfo, List shList); - + /** * 查询推送信息 * @@ -44,7 +46,7 @@ public interface PushInvoiceService { * @return */ PushInfo queryPushInfo(PushInfo pushInfo); - + /** * 更新推送信息 * @@ -52,7 +54,7 @@ public interface PushInvoiceService { * @return */ int updatePushInfo(PushInfo pushInfo); - + /** * 新增推送信息 * @@ -60,4 +62,18 @@ public interface PushInvoiceService { * @return */ int addPushInfo(PushInfo insertPushInfo); + + public String getPushContent(CommonTsMqData commonTsMqData, PushInfo pushInfo, List shList) throws OrderReceiveException; + + public String convertToYwxtParam(CommonTsMqData fpTsMqData,String content); + + public void processPushSuccess(CommonTsMqData commonTsMqData, String s, String version); + + public R processPushFail(CommonTsMqData commonTsMqData, String pushUrl, String msg, List shList); + + public void sendImageSys(String content, String pushType, PushInfo pushInfo); + + public void successPush(Long pushInfoRecordId,String content,String result,PushInfo pushInfo,String pushtype); + + public void failPush(Long pushInfoRecordId,String content,String result,String failReason,PushInfo pushInfo,String pushType); } diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/impl/PushInvoiceServiceImpl.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/impl/PushInvoiceServiceImpl.java index ee3836b3..9b5fa69f 100644 --- a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/impl/PushInvoiceServiceImpl.java +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/manager/service/impl/PushInvoiceServiceImpl.java @@ -14,6 +14,8 @@ import com.dxhy.order.baseservice.module.thirdservice.simsback.service.SimsBackS import com.dxhy.order.constant.*; import com.dxhy.order.consumer.config.OpenApiConfig; import com.dxhy.order.consumer.dao.GsClientMapper; +import com.dxhy.order.consumer.dao.PushInfoRecordMapper; +import com.dxhy.order.consumer.model.PushInfoRecord; import com.dxhy.order.consumer.model.protocol.CommonResponse; import com.dxhy.order.consumer.model.protocol.ResponseData; import com.dxhy.order.consumer.model.protocol.ResponseStatus; @@ -60,7 +62,10 @@ import com.dxhy.order.consumer.utils.OpentextUtils; import com.dxhy.order.exception.InterfaceException; import com.dxhy.order.exception.OrderReceiveException; import com.dxhy.order.invoice.config.InvoiceConfig; -import com.dxhy.order.invoice.module.invoice.dao.*; +import com.dxhy.order.invoice.module.invoice.dao.OrderInfoEscMapper; +import com.dxhy.order.invoice.module.invoice.dao.OrderInfoJdcMapper; +import com.dxhy.order.invoice.module.invoice.dao.OrderInfoQdMapper; +import com.dxhy.order.invoice.module.invoice.dao.PushInfoMapper; import com.dxhy.order.invoice.module.invoice.model.FileDownLoad; import com.dxhy.order.invoice.module.invoice.model.PushInfo; import com.dxhy.order.invoice.module.invoice.service.InvalidInvoiceService; @@ -164,6 +169,9 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { @Resource private BaseServiceConfig baseServiceConfig; + @Resource + private PushInfoRecordMapper pushInfoRecordMapper; + @Resource private GsClientMapper gsClientMapper; @Value("${snyx.salt:}") @@ -355,6 +363,56 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { return r; } + public void successPush(Long pushInfoRecordId,String content,String result,PushInfo pushInfo,String pushType){ + PushInfoRecord pushInfoRecord = new PushInfoRecord(); + pushInfoRecord.setId(Long.parseLong(DistributedKeyMaker.generateShotKey())); + pushInfoRecord.setRetryCount(0); + if(pushInfo!=null){ + pushInfoRecord.setPushInfoId(pushInfo.getId()); + pushInfoRecord.setQyType(pushInfo.getByzd1()); + } + if(pushInfoRecordId!=null){ + pushInfoRecord=pushInfoRecordMapper.selectByPrimaryKey(pushInfoRecordId); + pushInfoRecord.setRetryCount(pushInfoRecord.getRetryCount()+1); + pushInfoRecordMapper.updateByPrimaryKeySelective(pushInfoRecord); + } + pushInfoRecord.setPushContent(content); + pushInfoRecord.setInterfacePushType(pushType); + pushInfoRecord.setPushStatus("success"); + pushInfoRecord.setResult(result); + pushInfoRecord.setCreateTime(new Date()); + if(pushInfoRecordId!=null){ + pushInfoRecordMapper.updateByPrimaryKeySelective(pushInfoRecord); + }else { + pushInfoRecordMapper.insert(pushInfoRecord); + } + } + + public void failPush(Long pushInfoRecordId,String content,String result,String failReason,PushInfo pushInfo,String pushType){ + PushInfoRecord pushInfoRecord = new PushInfoRecord(); + pushInfoRecord.setId(Long.parseLong(DistributedKeyMaker.generateShotKey())); + pushInfoRecord.setRetryCount(0); + if(pushInfo!=null){ + pushInfoRecord.setPushInfoId(pushInfo.getId()); + pushInfoRecord.setQyType(pushInfo.getByzd1()); + } + if(pushInfoRecordId!=null){ + pushInfoRecord=pushInfoRecordMapper.selectByPrimaryKey(pushInfoRecordId); + pushInfoRecord.setRetryCount(pushInfoRecord.getRetryCount()+1); + } + pushInfoRecord.setPushContent(content); + pushInfoRecord.setInterfacePushType(pushType); + pushInfoRecord.setPushStatus("fail"); + pushInfoRecord.setResult(result); + pushInfoRecord.setFailReason(failReason); + pushInfoRecord.setCreateTime(new Date()); + if(pushInfoRecordId!=null){ + pushInfoRecordMapper.updateByPrimaryKeySelective(pushInfoRecord); + }else { + pushInfoRecordMapper.insert(pushInfoRecord); + } + } + private R commonPush(CommonTsMqData fpTsMqData) { R r = new R(); List shList = new ArrayList<>(); @@ -382,6 +440,7 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { if (pushInfoList.isEmpty()) { log.warn("{}税号:{},推送地址没有配置", LOGGER_MSG, fpTsMqData.getNsrsbh()); String error = "税号:" + fpTsMqData.getNsrsbh() + ",推送地址没有配置"; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),error,error,null,fpTsMqData.getPushType()); return R.error(error); } @@ -393,23 +452,33 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { for (PushInfo pushInfo : pushInfoList) { if (StringUtils.isBlank(pushInfo.getPushUrl())) { - log.warn("税号:{},推送地址未配置", fpTsMqData.getNsrsbh()); + String error=String.format("税号:%s,推送地址未配置",fpTsMqData.getNsrsbh()); + log.warn(error); + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),error,error,pushInfo,fpTsMqData.getPushType()); continue; } pushUrl = pushInfo.getPushUrl(); //按照接口类型获取对应的报文数据 //推送影像系统 String content = getPushContent(fpTsMqData, pushInfo, shList); + if (StrUtil.isBlank(content)) { + String error=String.format("税号:%s,组装请求报文为空,不进行推送数据",fpTsMqData.getNsrsbh()); + log.warn(error); + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),error,error,pushInfo,fpTsMqData.getPushType()); + continue; + } try { //推送影像系统 - sendImageSys(content); + sendImageSys(content,fpTsMqData.getPushType(),pushInfo); } catch (Exception e) { + String error=String.format("影像推送出现异常%s,推送类型%s",e.getMessage(),fpTsMqData.getPushType()); + log.error(error); + PushInfo pushInfo1 = new PushInfo(); + pushInfo1.setId(pushInfo.getId()); + pushInfo1.setByzd1("yxxt"); + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),error,error,pushInfo,fpTsMqData.getPushType()); e.printStackTrace(); } - if (StrUtil.isBlank(content)) { - log.warn("税号:{},组装请求报文为空,不进行推送数据", fpTsMqData.getNsrsbh()); - continue; - } OrderProcessInfo orderProcessInfo = null; Map requestMap = commonDisposeService.getRequestParameter(pushInfo.getNsrsbh(), pushInfo.getZipCode(), pushInfo.getEncryptCode(), content, pushInfo.getPushUrl(), pushInfo.getInterfaceType(), pushInfo.getVersionIdent()); if (OrderInfoEnum.INTERFACE_TYPE_INVOICE_PUSH_STATUS_1.getKey().equals(fpTsMqData.getPushType())) { @@ -425,10 +494,10 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { } try { - String param = JsonUtils.getInstance().toJsonString(requestMap); - if (param.length() > 500) { - param = param.substring(0, 400); - } +// String param = JsonUtils.getInstance().toJsonString(requestMap); +// if (param.length() > 500) { +// param = param.substring(0, 400); +// } log.info("{}推送企业开始,推送企业url:{},用户:{},密码:{},推送参数:{}", LOGGER_MSG, pushInfo.getPushUrl(),baseServiceConfig.getPoUserName(),baseServiceConfig.getPoPassword(), fptsParam); long startTime = System.currentTimeMillis(); String result = ""; @@ -518,19 +587,22 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { String s = commonDisposeService.commonDecrypt(commonRequestParam1); log.info("解析结果为,{}", s); processPushSuccess(fpTsMqData, s, pushInfo.getVersionIdent()); - + successPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),s,pushInfo,fpTsMqData.getPushType()); } else { - log.error("推送数据返回的状态结果为失败,信息为:{}", dxhyInterfaceResponse.getReturnMessage()); + String error=String.format("推送数据返回的状态结果为失败,信息为:%s",dxhyInterfaceResponse.getReturnMessage()); + log.error(error); errorMsg = dxhyInterfaceResponse.getReturnMessage(); r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),error,error,pushInfo,fpTsMqData.getPushType()); } } else { log.error("推送返回没有接收到状态码!"); errorMsg = "未接收到企业返回推送数据"; r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),errorMsg,errorMsg,pushInfo,fpTsMqData.getPushType()); } } else { CommonResponse commonResponse = JSONObject.parseObject(result, CommonResponse.class); @@ -555,12 +627,14 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { errorMsg = res.getMessage(); r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),errorMsg,errorMsg,pushInfo,fpTsMqData.getPushType()); } } else { log.error("推送返回没有接收到状态码!"); errorMsg = "未接收到企业返回推送数据"; r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),errorMsg,errorMsg,pushInfo,fpTsMqData.getPushType()); } } @@ -571,6 +645,7 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { log.error("{}推送企业失败,失败信息:{}", LOGGER_MSG, errorMsg); r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),errorMsg,errorMsg,pushInfo,fpTsMqData.getPushType()); } } catch (Exception e) { //多路径推送,返回数据异常后继续推送 @@ -578,6 +653,7 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { errorMsg = e.getMessage(); r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),errorMsg,errorMsg,pushInfo,fpTsMqData.getPushType()); } } @@ -586,6 +662,7 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { errorMsg = e.getMessage(); r = processPushFail(fpTsMqData, pushUrl, errorMsg, shList); sendPushDelay = true; + failPush(null,JsonUtils.getInstance().toJsonString(fpTsMqData),errorMsg,errorMsg,null,fpTsMqData.getPushType()); } //如果需要放入延时队列需要存入队列中 if (sendPushDelay) { @@ -594,7 +671,10 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { return r; } - private void sendImageSys(String content){ + public void sendImageSys(String content, String pushType, PushInfo pushInfo){ + PushInfo pushInfo1 = new PushInfo(); + pushInfo1.setId(pushInfo.getId()); + pushInfo1.setByzd1("yxxt"); DdfpzxxV5 ddfpzxxV5 = JsonUtils.getInstance().parseObject(content.substring(1,content.length()-1), DdfpzxxV5.class); DdfpxxV5 ddfpxx = ddfpzxxV5.getDDFPXX(); OutputInvoiceRequest outputInvoiceRequest = buildInvoiceRequest(ddfpxx); @@ -605,7 +685,9 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { || OrderInfoEnum.ORDER_INVOICE_TYPE_026.getKey().equals(fplxdm) || OrderInfoEnum.ORDER_INVOICE_TYPE_028.getKey().equals(fplxdm); if(!b){ - log.info("invoiceNo:{} not eleInvoice do not push",outputInvoiceRequest.getInvoiceList().get(0).getInvoiceNumber()); + String error=String.format("invoiceNo:%s not eleInvoice do not push",outputInvoiceRequest.getInvoiceList().get(0).getInvoiceNumber()); + log.info(error); + failPush(null,content,error,error,pushInfo1,pushType); return; } } @@ -625,9 +707,19 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { String status = jsonObject.getString("status");//200 成功、 500 失败 String message = jsonObject.getString("message"); String data = jsonObject.getString("data"); + if("200".equals(status)){ + //成功 + successPush(null,content,data,pushInfo,pushType); + }else { + //失败 + failPush(null,content,message,data,pushInfo,pushType); + } //暂时不保存状态 } catch (Exception e) { + String error=String.format("影像系统推送数据异常,%s ,推送类型为%s",e.getMessage(),pushType); + log.error(error); e.printStackTrace(); + failPush(null,content,error,error,pushInfo1,pushType); } } @@ -971,7 +1063,7 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { } - private R processPushFail(CommonTsMqData commonTsMqData, String pushUrl, String msg, List shList) { + public R processPushFail(CommonTsMqData commonTsMqData, String pushUrl, String msg, List shList) { if (StrUtil.isNotBlank(pushUrl)) { msg = "推送地址:" + pushUrl + "," + msg; @@ -1062,7 +1154,7 @@ public class PushInvoiceServiceImpl implements PushInvoiceService { } - private void processPushSuccess(CommonTsMqData commonTsMqData, String s, String version) { + public void processPushSuccess(CommonTsMqData commonTsMqData, String s, String version) { //按照接口类型进行执行不同的业务 if (OrderInfoEnum.INTERFACE_TYPE_INVOICE_PUSH_STATUS_1.getKey().equals(commonTsMqData.getPushType())) { //开票推送相关业务处理 diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/controller/InvoicePushController.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/controller/InvoicePushController.java new file mode 100644 index 00000000..b0b16a00 --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/controller/InvoicePushController.java @@ -0,0 +1,36 @@ +package com.dxhy.order.consumer.modules.order.controller; + +import com.dxhy.order.consumer.modules.order.service.InvoicePushService; +import com.dxhy.order.model.R; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * @title: InvoicePushController + * @Author: wrr + * @Date: 2023/7/20 09:44 + * @Description: + */ +@RestController +@Slf4j +@RequestMapping("/invoicePush") +public class InvoicePushController { + + @Resource + private InvoicePushService invoicePushService; + + /** + * 推送重试 + * @author: wrr + * @date: 2023/7/20 09:59 + * @param pushInfoRecordId + * @return R + */ + public R retryPush(@RequestParam Long pushInfoRecordId){ + return R.ok().put("data", invoicePushService.retryPush(pushInfoRecordId)); + } +} diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/service/InvoicePushService.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/service/InvoicePushService.java new file mode 100644 index 00000000..601cb736 --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/service/InvoicePushService.java @@ -0,0 +1,20 @@ +package com.dxhy.order.consumer.modules.order.service; + +import com.dxhy.order.model.R; + +/** + * @title: InvoicePushService + * @Author: wrr + * @Date: 2023/7/20 09:48 + * @Description: + */ +public interface InvoicePushService { + /** + * 重试推送 + * @author: wrr + * @date: 2023/7/20 10:00 + * @param pushInfoRecordId + * @return R + */ + R retryPush(Long pushInfoRecordId); +} diff --git a/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/service/impl/InvoicePushServiceImpl.java b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/service/impl/InvoicePushServiceImpl.java new file mode 100644 index 00000000..e5bbd0f1 --- /dev/null +++ b/order-management-consumer/src/main/java/com/dxhy/order/consumer/modules/order/service/impl/InvoicePushServiceImpl.java @@ -0,0 +1,306 @@ +package com.dxhy.order.consumer.modules.order.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import com.dxhy.order.baseservice.config.BaseServiceConfig; +import com.dxhy.order.constant.*; +import com.dxhy.order.consumer.dao.PushInfoRecordMapper; +import com.dxhy.order.consumer.model.PushInfoRecord; +import com.dxhy.order.consumer.model.protocol.CommonResponse; +import com.dxhy.order.consumer.model.protocol.ResponseData; +import com.dxhy.order.consumer.model.protocol.ResponseStatus; +import com.dxhy.order.consumer.modules.manager.service.PushInvoiceService; +import com.dxhy.order.consumer.modules.order.service.InvoicePushService; +import com.dxhy.order.consumer.modules.order.service.OrderProcessService; +import com.dxhy.order.consumer.openapi.protocol.CommonRequestParam; +import com.dxhy.order.consumer.openapi.protocol.po.EsOutput; +import com.dxhy.order.consumer.openapi.protocol.po.PoCommonResponseParam; +import com.dxhy.order.consumer.openapi.protocol.v4.push.DdfptsV5; +import com.dxhy.order.consumer.openapi.protocol.v5.DxhyInterfaceResponse; +import com.dxhy.order.consumer.openapi.protocol.v5.invalid.ZffpxxV5; +import com.dxhy.order.consumer.openapi.service.CommonDisposeService; +import com.dxhy.order.invoice.module.invoice.dao.PushInfoMapper; +import com.dxhy.order.invoice.module.invoice.model.PushInfo; +import com.dxhy.order.invoice.module.invoice.service.OrderInvoiceInfoService; +import com.dxhy.order.model.OrderInvoiceInfo; +import com.dxhy.order.model.OrderProcessInfo; +import com.dxhy.order.model.R; +import com.dxhy.order.model.queue.CommonTsMqData; +import com.dxhy.order.utils.Base64Encoding; +import com.dxhy.order.utils.HttpUtils; +import com.dxhy.order.utils.JsonUtils; +import com.google.common.collect.Maps; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @title: InvoicePushServiceImpl + * @Author: wrr + * @Date: 2023/7/20 09:48 + * @Description: + */ +@Slf4j +@Service +public class InvoicePushServiceImpl implements InvoicePushService { + private static final String LOGGER_MSG = "(推送重试业务实现类)"; + + @Resource + private PushInfoRecordMapper pushInfoRecordMapper; + @Resource + private PushInfoMapper pushInfoMapper; + + @Resource + private CommonDisposeService commonDisposeService; + + @Resource + private OrderProcessService orderProcessService; + @Resource + private OrderInvoiceInfoService orderInvoiceInfoService; + + @Resource + private BaseServiceConfig baseServiceConfig; + + @Resource + private PushInvoiceService pushInvoiceService; + + + /** + * @param pushInfoRecordId + * @return * @return R + * @author: wrr + * @date: 2023/7/20 10:01 + */ + @Override + public R retryPush(Long pushInfoRecordId) { + R r = new R(); + //查询未推送成功的数据 + PushInfoRecord pushInfoRecord = pushInfoRecordMapper.selectByPrimaryKey(pushInfoRecordId); + if (StringUtils.isBlank(pushInfoRecord.getPushContent())) { + r.put(OrderManagementConstant.CODE, "9999"); + r.put(OrderManagementConstant.ALL_MESSAGE, "推送内容为空"); + return r; + } + CommonTsMqData fpTsMqData = JSONObject.parseObject(pushInfoRecord.getPushContent(), CommonTsMqData.class); + List shList = new ArrayList<>(); + shList.add(fpTsMqData.getNsrsbh()); + //推送地址 + String pushUrl = ""; + String errorMsg = ""; + String xtly = "SAP"; + PushInfo pushInfo = new PushInfo(); + try { + //查询推送地址 + pushInfo.setId(pushInfoRecord.getPushInfoId()); + pushInfo = pushInfoMapper.selectByPushInfo(pushInfo); + log.info("查询到的推送地址信息:{}", JsonUtils.getInstance().toJsonString(pushInfo)); + + if (pushInfo == null) { + log.warn("{}税号:{},推送地址没有配置", LOGGER_MSG, fpTsMqData.getNsrsbh()); + String error = "税号:" + fpTsMqData.getNsrsbh() + ",推送地址没有配置"; + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), error, error, null, fpTsMqData.getPushType()); + r.put(OrderManagementConstant.CODE, "9999"); + r.put(OrderManagementConstant.ALL_MESSAGE, error); + return r; + } + + if (StringUtils.isBlank(pushInfo.getPushUrl())) { + String error = String.format("税号:%s,推送地址未配置", fpTsMqData.getNsrsbh()); + log.warn(error); + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), error, error, pushInfo, fpTsMqData.getPushType()); + r.put(OrderManagementConstant.CODE, "9999"); + r.put(OrderManagementConstant.ALL_MESSAGE, error); + return r; + } + pushUrl = pushInfo.getPushUrl(); + //按照接口类型获取对应的报文数据 + String content = pushInvoiceService.getPushContent(fpTsMqData, pushInfo, shList); + if (StrUtil.isBlank(content)) { + String error = String.format("税号:%s,组装请求报文为空,不进行推送数据", fpTsMqData.getNsrsbh()); + log.warn(error); + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), error, error, pushInfo, fpTsMqData.getPushType()); + r.put(OrderManagementConstant.CODE, "9999"); + r.put(OrderManagementConstant.ALL_MESSAGE, error); + return r; + } + //判断是不是影像的推送 + if ("yxxt".equals(pushInfoRecord.getQyType())) { + try { + //推送影像系统 + pushInvoiceService.sendImageSys(content, fpTsMqData.getPushType(), pushInfo); + return r; + } catch (Exception e) { + String error = String.format("影像推送出现异常%s,推送类型%s", e.getMessage(), fpTsMqData.getPushType()); + log.error(error); + pushInfo.setByzd1("yxxt"); + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), error, error, pushInfo, fpTsMqData.getPushType()); + e.printStackTrace(); + r.put(OrderManagementConstant.CODE, "9999"); + r.put(OrderManagementConstant.ALL_MESSAGE, error); + return r; + } + } + + OrderProcessInfo orderProcessInfo = null; + Map requestMap = commonDisposeService.getRequestParameter(pushInfo.getNsrsbh(), pushInfo.getZipCode(), pushInfo.getEncryptCode(), content, pushInfo.getPushUrl(), pushInfo.getInterfaceType(), pushInfo.getVersionIdent()); + if (OrderInfoEnum.INTERFACE_TYPE_INVOICE_PUSH_STATUS_1.getKey().equals(fpTsMqData.getPushType())) { + orderProcessInfo = orderProcessService.queryOrderProcessInfoByFpqqlsh(fpTsMqData.getFpTsMqData().getFpqqlsh(), null); + } else if (OrderInfoEnum.INTERFACE_TYPE_INVOICE_PUSH_STATUS_2.getKey().equals(fpTsMqData.getPushType())) { + OrderInvoiceInfo orderInvoiceInfo = orderInvoiceInfoService.selectOrderInvoiceInfoByFpdmAndFphm(fpTsMqData.getZfTsMqData().getFpdm(), fpTsMqData.getZfTsMqData().getFphm(), null); + orderProcessInfo = orderProcessService.selectByOrderId(orderInvoiceInfo.getOrderInfoId(), null); + } + String fptsParam = JsonUtils.getInstance().toJsonString(requestMap); + if (StringUtils.isNotBlank(pushInfo.getByzd1())) { + fptsParam = pushInvoiceService.convertToYwxtParam(fpTsMqData, content); + } + + log.info("{}推送企业开始,推送企业url:{},用户:{},密码:{},推送参数:{}", LOGGER_MSG, pushInfo.getPushUrl(), baseServiceConfig.getPoUserName(), baseServiceConfig.getPoPassword(), fptsParam); + long startTime = System.currentTimeMillis(); + String result = ""; + if (ConfigurerInfo.INTERFACE_VERSION_V5.equals(pushInfo.getVersionIdent()) + || ConfigurerInfo.INTERFACE_VERSION_V6.equals(pushInfo.getVersionIdent())) { + if (StringUtils.isNotBlank(pushInfo.getByzd1()) && OrderInfoEnum.SYS_SOURCE_SAP.getKey().equals(pushInfo.getByzd1())) { + result = HttpUtils.sendPo(pushInfo.getPushUrl(), fptsParam, baseServiceConfig.getPoUserName(), baseServiceConfig.getPoPassword()); + } else if (OrderInfoEnum.SYS_SOURCE_DSXT01.getKey().equals(orderProcessInfo.getXtly()) && StringUtils.isNotBlank(pushInfo.getByzd1()) + && pushInfo.getByzd1().equals(orderProcessInfo.getXtly())) { + result = HttpUtils.sendPo(pushInfo.getPushUrl(), fptsParam, baseServiceConfig.getPoUserName(), baseServiceConfig.getPoPassword()); + } else if (OrderInfoEnum.SYS_SOURCE_DSXT02.getKey().equals(orderProcessInfo.getXtly()) && StringUtils.isNotBlank(pushInfo.getByzd1()) + && pushInfo.getByzd1().equals(orderProcessInfo.getXtly())) { + Map map = Maps.newHashMap(); + map.put("ec-key", baseServiceConfig.getEcKey()); + result = HttpUtils.sendPoWithHead(pushInfo.getPushUrl(), fptsParam, baseServiceConfig.getPoUserName(), baseServiceConfig.getPoPassword(), map); + } + } else { + result = HttpUtils.doPost(pushInfo.getPushUrl(), requestMap); + } + long endTime = System.currentTimeMillis(); + log.info("{}推送企业结束,推送企业url:{},企业返回结果:{},推送耗时:{}", LOGGER_MSG, pushInfo.getPushUrl(), result, endTime - startTime); + + if (!StringUtils.isBlank(result)) { + if (ConfigurerInfo.INTERFACE_VERSION_V5.equals(pushInfo.getVersionIdent()) + || ConfigurerInfo.INTERFACE_VERSION_V6.equals(pushInfo.getVersionIdent())) { + DxhyInterfaceResponse dxhyInterfaceResponse = JsonUtils.getInstance().parseObject(result, DxhyInterfaceResponse.class); + if (OrderInfoEnum.INTERFACE_TYPE_INVOICE_PUSH_STATUS_1.getKey().equals(fpTsMqData.getPushType())) { + if (OrderInfoEnum.SYS_SOURCE_SAP.getKey().equals(xtly)) { + PoCommonResponseParam poCommonResponseParam = JsonUtils.getInstance().parseObject(result, PoCommonResponseParam.class); + EsOutput es_output = poCommonResponseParam.getES_OUTPUT(); + String sapkey = es_output.getSAPKEY(); + String ztype = es_output.getZTYPE(); + String zmessage = es_output.getZMESSAGE(); + List resultList = new ArrayList<>(); + DdfptsV5 ddfptsV5 = new DdfptsV5(); + ddfptsV5.setDDQQLSH(fpTsMqData.getFpTsMqData().getFpqqlsh()); + ddfptsV5.setNSRSBH(""); + if (OrderInfoContentEnum.INVOICE_ERROR_CODE_OP_S.getKey().equals(ztype)) { + ddfptsV5.setZTDM(ConfigureConstant.STRING_000000); + } else { + ddfptsV5.setZTDM(ConfigureConstant.STRING_9999); + } + ddfptsV5.setZTXX(zmessage); + dxhyInterfaceResponse.setReturnCode(ConfigureConstant.STRING_000000); + dxhyInterfaceResponse.setReturnMessage("处理成功"); + dxhyInterfaceResponse.setEncryptCode(ConfigurerInfo.ENCRYPTCODE_0); + dxhyInterfaceResponse.setZipCode(ConfigurerInfo.ENCRYPTCODE_0); + resultList.add(ddfptsV5); + dxhyInterfaceResponse.setContent(Base64Encoding.encode(JsonUtils.getInstance().toJsonString(resultList))); + } else { + dxhyInterfaceResponse = JsonUtils.getInstance().parseObject(result, DxhyInterfaceResponse.class); + } + } else if (OrderInfoEnum.INTERFACE_TYPE_INVOICE_PUSH_STATUS_2.getKey().equals(fpTsMqData.getPushType())) { + if (OrderInfoEnum.SYS_SOURCE_SAP.getKey().equals(xtly)) { + PoCommonResponseParam poCommonResponseParam = JsonUtils.getInstance().parseObject(result, PoCommonResponseParam.class); + EsOutput es_output = poCommonResponseParam.getES_OUTPUT(); + String ztype = es_output.getZTYPE(); + String zmessage = es_output.getZMESSAGE(); + ZffpxxV5 zffpxxV5 = new ZffpxxV5(); + zffpxxV5.setXHFSBH(fpTsMqData.getZfTsMqData().getNsrsbh()); + zffpxxV5.setFPDM(fpTsMqData.getZfTsMqData().getFpdm()); + zffpxxV5.setFPHM(fpTsMqData.getZfTsMqData().getFphm()); + if (OrderInfoContentEnum.INVOICE_ERROR_CODE_OP_S.getKey().equals(ztype)) { + zffpxxV5.setZTDM(ConfigureConstant.STRING_000000); + } else { + zffpxxV5.setZTDM(ConfigureConstant.STRING_9999); + } + zffpxxV5.setZTXX(zmessage); + dxhyInterfaceResponse.setReturnCode(ConfigureConstant.STRING_000000); + dxhyInterfaceResponse.setReturnMessage("处理成功"); + dxhyInterfaceResponse.setEncryptCode(ConfigurerInfo.ENCRYPTCODE_0); + dxhyInterfaceResponse.setZipCode(ConfigurerInfo.ENCRYPTCODE_0); + dxhyInterfaceResponse.setContent(Base64Encoding.encode(JsonUtils.getInstance().toJsonString(zffpxxV5))); + } else { + dxhyInterfaceResponse = JsonUtils.getInstance().parseObject(result, DxhyInterfaceResponse.class); + } + } + + if (ObjectUtil.isNotNull(dxhyInterfaceResponse)) { + if (ConfigureConstant.STRING_000000.equals(dxhyInterfaceResponse.getReturnCode())) { + CommonRequestParam commonRequestParam1 = new CommonRequestParam(); + commonRequestParam1.setContent(dxhyInterfaceResponse.getContent()); + commonRequestParam1.setEncryptCode(dxhyInterfaceResponse.getEncryptCode()); + commonRequestParam1.setZipCode(dxhyInterfaceResponse.getZipCode()); + commonRequestParam1.setSecretId(commonDisposeService.getAuthMap(pushInfo.getNsrsbh())); + String s = commonDisposeService.commonDecrypt(commonRequestParam1); + log.info("解析结果为,{}", s); + pushInvoiceService.processPushSuccess(fpTsMqData, s, pushInfo.getVersionIdent()); + pushInvoiceService.successPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), s, pushInfo, fpTsMqData.getPushType()); + + } else { + String error = String.format("推送数据返回的状态结果为失败,信息为:%s", dxhyInterfaceResponse.getReturnMessage()); + log.error(error); + errorMsg = dxhyInterfaceResponse.getReturnMessage(); + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), error, error, pushInfo, fpTsMqData.getPushType()); + } + } else { + log.error("推送返回没有接收到状态码!"); + errorMsg = "未接收到企业返回推送数据"; + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), errorMsg, errorMsg, pushInfo, fpTsMqData.getPushType()); + } + } else { + CommonResponse commonResponse = JSONObject.parseObject(result, CommonResponse.class); + if (commonResponse != null && commonResponse.getResponseStatus() != null) { + + ResponseStatus res = commonResponse.getResponseStatus(); + String code = res.getCode(); + ResponseData responseData = commonResponse.getResponseData(); + + if (ConfigureConstant.STRING_0000.equals(code) || ConfigureConstant.STRING_2000.equals(code)) { + CommonRequestParam commonRequestParam1 = new CommonRequestParam(); + commonRequestParam1.setContent(responseData.getContent()); + commonRequestParam1.setEncryptCode(responseData.getEncryptCode()); + commonRequestParam1.setZipCode(responseData.getZipCode()); + commonRequestParam1.setSecretId(commonDisposeService.getAuthMap(pushInfo.getNsrsbh())); + String s = commonDisposeService.commonDecrypt(commonRequestParam1); + log.info("解析结果为,{}", s); + pushInvoiceService.processPushSuccess(fpTsMqData, s, pushInfo.getVersionIdent()); + + } else { + log.error("推送数据返回的状态结果为失败!"); + errorMsg = res.getMessage(); + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), errorMsg, errorMsg, pushInfo, fpTsMqData.getPushType()); + } + } else { + log.error("推送返回没有接收到状态码!"); + errorMsg = "未接收到企业返回推送数据"; + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), errorMsg, errorMsg, pushInfo, fpTsMqData.getPushType()); + } + + } + } + } catch (Exception e) { + log.error("{}推送异常,异常信息:{}", LOGGER_MSG, e); + errorMsg = e.getMessage(); + } + if (StrUtil.isNotBlank(errorMsg)) { + log.error("{}推送失败,失败信息:{}", LOGGER_MSG, errorMsg); + r = pushInvoiceService.processPushFail(fpTsMqData, pushUrl, errorMsg, shList); + pushInvoiceService.failPush(pushInfoRecordId, JsonUtils.getInstance().toJsonString(fpTsMqData), errorMsg, errorMsg, pushInfo, fpTsMqData.getPushType()); + } + return r; + } +}