parent
d92f547e93
commit
265b1816c3
@ -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)); |
||||
} |
||||
} |
@ -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); |
||||
} |
@ -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<String> 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<String, String> 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<DdfptsV5> 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; |
||||
} |
||||
} |
Loading…
Reference in new issue