代码优化,添加接口记录请求重调

release
xuliangwei 2 years ago
parent 470a0ecf5f
commit d1f043fad7
  1. 32
      dxhy-erp/src/main/java/com/dxhy/erp/controller/InterfaceController.java
  2. 74
      dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java
  3. 22
      dxhy-erp/src/main/java/com/dxhy/erp/entity/RequestRecord.java
  4. 58
      dxhy-erp/src/main/java/com/dxhy/erp/enums/RequestRecordEnum.java
  5. 12
      dxhy-erp/src/main/java/com/dxhy/erp/service/RequestRecordService.java
  6. 167
      dxhy-erp/src/main/java/com/dxhy/erp/service/impl/RequestRecordServiceImpl.java

@ -1222,9 +1222,10 @@ public class InterfaceController extends AbstractController {
try {
if (esOutPutResp.getZMESSAGE().contains("不存在")) {
requestRecordService.saveRecord(receiveErpInvoiceMessageRecord, 1,1, JsonUtils.getInstance().toJsonString(outPut),0);
requestRecordService.saveFailedRequestRecord(receiveErpInvoiceMessageRecord, 0, JsonUtils.getInstance().toJsonString(outPut),
esOutPutResp.getZMESSAGE());
} else {
requestRecordService.saveRecord(receiveErpInvoiceMessageRecord, 0,0, JsonUtils.getInstance().toJsonString(outPut));
requestRecordService.saveSuccessfulRequestRecord(receiveErpInvoiceMessageRecord, JsonUtils.getInstance().toJsonString(outPut));
}
} catch (Exception e) {
log.error("FI847接口记录保存失败,errormsg:{}",e.getMessage());
@ -1242,7 +1243,13 @@ public class InterfaceController extends AbstractController {
esOutPutResp.setZMESSAGE("程序内部错误");
outPut.setES_OUTPUT(esOutPutResp);
requestRecordService.saveRecord(receiveErpInvoiceMessageRecord, 1,1, JsonUtils.getInstance().toJsonString(outPut), 1);
try {
requestRecordService.saveFailedRequestRecord(receiveErpInvoiceMessageRecord, 1, JsonUtils.getInstance().toJsonString(outPut),
"FI847接口接收erp发票数据出错,异常信息:"+"{"+JSONObject.toJSONString(e)+"}");
} catch (Exception exception) {
log.error("FI847接口记录保存失败,errormsg:{}",e.getMessage());
exception.printStackTrace();
}
return JsonUtils.getInstance().toJsonString(outPut);
}
@ -1255,12 +1262,17 @@ public class InterfaceController extends AbstractController {
List<String> fpdms = new ArrayList<>();
List<String> fphms = new ArrayList<>();
List<String> bzdhs = new ArrayList<>();
for (Map<String ,Object> map:list) {
String invoiceCode =(String) map.get("ZFPDM");
String invoiceNo = (String)map.get("ZFPHM");
String bzdh = (String)map.get("ZBZDH");
fpdms.add(invoiceCode);
fphms.add(invoiceNo);
bzdhs.add(bzdh);
}
log.info("进项税转出(FI849)接收到的发票号码为:{}\n进项税转出(FI849)接收到的发票代码为:{}\n进项税转出(FI849)接收到的报账单号为:{}\n",
JSONObject.toJSONString(fphms),JSONObject.toJSONString(fpdms),JSONObject.toJSONString(bzdhs));
RequestRecord transferOutRecord =requestRecordService.getBaseRequestRecord(JSONObject.toJSONString(erpInvoiceData),
"/po", JSONObject.toJSONString(fpdms),JSONObject.toJSONString(fphms), "transferOut");
@ -1283,7 +1295,8 @@ public class InterfaceController extends AbstractController {
outPut.setES_OUTPUT(es);
try {
requestRecordService.saveRecord(transferOutRecord, 1, 1, JsonUtils.getInstance().toJsonString(outPut), 0);
requestRecordService.saveFailedRequestRecord(transferOutRecord, 0, JsonUtils.getInstance().toJsonString(outPut),
es.getZMESSAGE());
} catch (Exception e) {
log.error("FI849接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -1335,7 +1348,7 @@ public class InterfaceController extends AbstractController {
}
try {
requestRecordService.saveRecord(transferOutRecord,0, 0, transfer);
requestRecordService.saveSuccessfulRequestRecord(transferOutRecord, transfer);
} catch (Exception e) {
log.error("FI849接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -1352,7 +1365,14 @@ public class InterfaceController extends AbstractController {
es.setZMESSAGE("系统内部错误");
outPut.setES_OUTPUT(es);
requestRecordService.saveRecord(transferOutRecord,1, 1, JsonUtils.getInstance().toJsonString(outPut), 1);
try {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
requestRecordService.saveFailedRequestRecord(transferOutRecord,1, JsonUtils.getInstance().toJsonString(outPut),
"进项税转出(FI849)处理出现异常,异常信息:"+"{"+JSONObject.toJSONString(e)+"}");
} catch (Exception exception) {
log.error("FI849接口记录保存失败,errormsg:{}",e.getMessage());
exception.printStackTrace();
}
return JsonUtils.getInstance().toJsonString(outPut);
}

@ -11,6 +11,7 @@ import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.controller.AbstractController;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.SNFplxEnum;
import com.dxhy.common.exception.BaseException;
import com.dxhy.common.util.InvoiceUtil;
import com.dxhy.common.utils.Base64Encoding;
import com.dxhy.common.utils.R;
@ -135,7 +136,7 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", checkInvoiceResult);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord, 0,0, JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -154,7 +155,7 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("invoiceNumber"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("发票号码不能为空!")),0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,JSONObject.toJSONString(R.error("发票号码不能为空!")), "发票号码不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -173,7 +174,8 @@ public class SDNYMainProcessController extends AbstractController {
} else {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("开票日期不能为空!")), 0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("开票日期不能为空!")), "开票日期不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -185,8 +187,9 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("invoiceType"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("发票类型不能为空!")), 0);
} catch (Exception e) {
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("发票类型不能为空!")), "发票类型不能为空!");
} catch (BaseException e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
}
@ -203,7 +206,8 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("totalAmount"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("金额不能为空!")), 0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("金额不能为空!")), "金额不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -215,7 +219,8 @@ public class SDNYMainProcessController extends AbstractController {
if (StringUtils.isBlank(pramsMap.get("checkCode"))) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("校验码不能为空!")), 0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error("校验码不能为空!")), "校验码不能为空!");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -237,7 +242,8 @@ public class SDNYMainProcessController extends AbstractController {
if (notes != null) {
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error(notes)), 0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,
JSONObject.toJSONString(R.error(notes)), notes);
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -293,14 +299,18 @@ public class SDNYMainProcessController extends AbstractController {
// saveCheckLog(pramsMap, checkInvoice);
try {
if (checkInvoiceResult!=null && checkInvoiceResult.containsKey("code")) {
if (checkInvoiceResult.containsKey("cyjg")) {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(data), 0);
if (checkInvoiceResult.containsKey("code")) {
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord, 0,JSONObject.toJSONString(data),
(String) checkInvoiceResult.get("message"));
}
} else {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
if (checkInvoiceResult.containsKey("cyjg") && !"0001".equals(checkInvoiceResult.getString("cyjg"))) {
log.info("进项票池已存在发票,查验结果:{}",JSONObject.toJSON(checkInvoiceResult));
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord, 0,JSONObject.toJSONString(data),
(String) checkInvoiceResult.get("cyjgxx"));
} else {
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord,JSONObject.toJSONString(data));
}
}
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
@ -332,7 +342,7 @@ public class SDNYMainProcessController extends AbstractController {
// saveCheckLog(pramsMap,checkInvoice);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -354,7 +364,8 @@ public class SDNYMainProcessController extends AbstractController {
log.error("查验失败,errormsg:{}",e.getMessage());
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error("查验失败,"+e.getMessage())), 1);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,1,JSONObject.toJSONString(R.error("查验失败,"+e.getMessage())),
"查验失败,异常信息:{}"+JSONObject.toJSONString(e.getMessage()));
} catch (Exception exception) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
exception.printStackTrace();
@ -370,7 +381,8 @@ public class SDNYMainProcessController extends AbstractController {
data = errorInfo(checkInvoiceResult, data);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(data), 0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord, 0,JSONObject.toJSONString(data),
(String) checkInvoiceResult.get("cyjgxx"));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -390,7 +402,7 @@ public class SDNYMainProcessController extends AbstractController {
signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, userid, "1", dbName);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord,JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -428,7 +440,7 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", checkInvoiceResult);
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,0,0,JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(singleInvoiceCheckRecord,JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -439,7 +451,8 @@ public class SDNYMainProcessController extends AbstractController {
}
try {
requestRecordService.saveRecord(singleInvoiceCheckRecord,1,1,JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)),0);
requestRecordService.saveFailedRequestRecord(singleInvoiceCheckRecord,0,JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)),
"未知异常,请联系管理员");
} catch (Exception e) {
log.error("发票查验接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -777,7 +790,7 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", result);
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(R.error(result)));
requestRecordService.saveFailedRequestRecord(record,0, JSONObject.toJSONString(R.error(result)), result);
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -801,6 +814,7 @@ public class SDNYMainProcessController extends AbstractController {
// JSONObject.toJSONString(invoiceNos),
// "pushCheckResultToSAP", 1);
try {
record.setActiveCallRequestDetail(request.toJSONString());
record.setActiveCall("pushCheckResultToSAP");
//将信息推送到影像系统
result = snPushCheckRecordService.pushCheckResultToSAP(request.toJSONString());
@ -811,7 +825,7 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", result);
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(record, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -824,7 +838,8 @@ public class SDNYMainProcessController extends AbstractController {
// requestRecordService.saveRecord(pushCheckResultToSAPRecord,1, 1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)), 1);
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)), 1);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)),
"推送sap失败,失败原因:"+"{"+JSONObject.toJSONString(e)+"}");
} catch (Exception exception) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
exception.printStackTrace();
@ -851,7 +866,7 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", "");
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(record, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -876,7 +891,7 @@ public class SDNYMainProcessController extends AbstractController {
data.put("data", "");
try {
requestRecordService.saveRecord(record,0, 0, JSONObject.toJSONString(data));
requestRecordService.saveSuccessfulRequestRecord(record, JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -891,7 +906,8 @@ public class SDNYMainProcessController extends AbstractController {
exception.printStackTrace();
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.CONNECT_TIMEOUT)),1);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.CONNECT_TIMEOUT)),
"同步SAP失败,报错信息为:"+"{"+JSONObject.toJSONString(exception)+"}");
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -903,7 +919,8 @@ public class SDNYMainProcessController extends AbstractController {
exception.printStackTrace();
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.NULL_POINTER_TIMEOUT)), 1);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.NULL_POINTER_TIMEOUT)),
"同步SAP失败,报错信息为:"+"{"+JSONObject.toJSONString(exception)+"}");
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();
@ -915,7 +932,8 @@ public class SDNYMainProcessController extends AbstractController {
exception.printStackTrace();
try {
requestRecordService.saveRecord(record,1, 1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)),1);
requestRecordService.saveFailedRequestRecord(record,1, JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_DEFAULT)),
"同步SAP失败,报错信息为:"+"{"+JSONObject.toJSONString(exception)+"}");
} catch (Exception e) {
log.error("发票同步接口记录保存失败,errormsg:{}",e.getMessage());
e.printStackTrace();

@ -105,10 +105,22 @@ public class RequestRecord {
private String activeCall;
/**
* 失败原因0参数校验未通过1其他原因
* 主动调用其它系统的接口参数
*/
@TableField("active_call_request_detail")
private String activeCallRequestDetail;
/**
* 失败原因
*/
@TableField("failed_reason")
private Integer failedReason;
private String failedReason;
/**
* 是否可重调0不可重调1可重调
*/
@TableField("is_recall")
private Integer isRecall;
/**
* 重调用后的返回参数
@ -122,4 +134,10 @@ public class RequestRecord {
@TableField("active_call_response")
private String activeCallResponse;
/**
* 主动调用其它系统的返回参数重调用
*/
@TableField("active_call_recall_response")
private String activeCallRecallResponse;
}

@ -1,44 +1,50 @@
package com.dxhy.erp.enums;
import com.dxhy.erp.controller.InterfaceController;
import com.dxhy.erp.controller.SDNYMainProcessController;
import com.dxhy.erp.service.SNPushCheckRecordService;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.erp.entity.sdny.SNRequestObject;
import org.springframework.http.ResponseEntity;
import java.util.Map;
public enum RequestRecordEnum {
SYNC_INVOICE_INFO("/syncInvoiceInfo", "syncInvoiceInfo", SDNYMainProcessController.class),
SYNC_INVOICE_INFO("/sn/syncInvoiceInfo", "syncInvoiceInfo", Map.class, ResponseEntity.class,"SDNYMainProcessController"),
SINGLE_INVOICE_CHECK("/singleInvoiceCheck", "singleInvoiceCheck", SDNYMainProcessController.class),
SINGLE_INVOICE_CHECK("/sn/singleInvoiceCheck", "singleInvoiceCheck", SNRequestObject.class, ResponseEntity.class, "SDNYMainProcessController"),
RECEIVE_ERP_INVOICE_MESSAGE("/po", "receiveErpInvoiceMessage", InterfaceController.class),
SINGLE_CHECK_INVOICE("singleCheckInvoice", Map.class, JSONObject.class, "SNPushCheckRecordService"),
TRANSFER_OUT("/po", "transferOut", InterfaceController.class),
INSERT_VOUNCHER_RECORD("/po", "insertVouncherRecord", InterfaceController.class),
PUSH_CHECK_RESULT_TO_SAP("pushCheckResultToSAP", SNPushCheckRecordService.class, String.class),
SING_CHECK_INVOICE("singleCheckInvoice",SNPushCheckRecordService.class, Map.class);
PUSH_CHECK_RESULT_TO_SAP("pushCheckResultToSAP", String.class, String.class, "SNPushCheckRecordService");
private String className;
private String portName;
private String methodName;
private Class<?> argClass;
private Class<?> controllerName;
private Class<?> responseEntityClass;
RequestRecordEnum(String portName, String methodName, Class<?> controllerClass) {
RequestRecordEnum(String portName, String methodName, Class<?> argClass, Class<?> responseEntityClass, String className) {
this.className = className;
this.portName = portName;
this.methodName = methodName;
this.controllerName = controllerClass;
this.argClass = argClass;
this.responseEntityClass = responseEntityClass;
}
RequestRecordEnum(String methodName, Class<?> controllerClass, Class<?> argClass) {
RequestRecordEnum(String methodName, Class<?> argClass, Class<?> responseEntityClass, String className) {
this.className = className;
this.methodName = methodName;
this.controllerName = controllerClass;
this.argClass = argClass;
this.responseEntityClass = responseEntityClass;
}
public void setResponseEntityClass(Class<?> responseEntityClass) {
this.responseEntityClass = responseEntityClass;
}
public Class<?> getResponseEntityClass() {
return responseEntityClass;
}
public void setPortName(String portName) {
@ -49,10 +55,6 @@ public enum RequestRecordEnum {
this.methodName = methodName;
}
public void setControllerName(Class<?> controllerName) {
this.controllerName = controllerName;
}
public String getPortName() {
return portName;
}
@ -61,10 +63,6 @@ public enum RequestRecordEnum {
return methodName;
}
public Class<?> getControllerName() {
return controllerName;
}
public Class<?> getArgClass() {
return argClass;
}
@ -72,4 +70,12 @@ public enum RequestRecordEnum {
public void setArgClass(Class<?> argClass) {
this.argClass = argClass;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
}

@ -9,7 +9,11 @@ import java.util.List;
public interface RequestRecordService extends MpBaseService<RequestRecord> {
int saveRecord(RequestRecord requestRecord,Integer failedTimes, Integer status, String responseDetail,Integer... failedReason);
int saveSuccessfulRequestRecord(RequestRecord record, String responseDetail);
// int saveRecord(RequestRecord requestRecord,Integer failedTimes, Integer status, String responseDetail,Integer... failedReason);
int saveFailedRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason);
List<RequestRecord> getRecordList(String portName, Date startTime, Date endTime, Integer status, String methodName, Integer pageNumber, Integer PageSize);
@ -19,5 +23,11 @@ public interface RequestRecordService extends MpBaseService<RequestRecord> {
RequestRecord getBaseRequestRecord(String requestDetail, String portName, String invoiceNo, String methodName);
// int updateSuccessfulRecallRecord(RequestRecord record, Integer status, String activeCallRequestDetail, String recallResponseDetail);
//
// int updateFailedRecallRecord(RequestRecord record, Integer status, String activeCallResponse, String recallResponseDetail, String failedReason, Integer isRecall);
ResponseEntity<?> reCall(RequestRecord requestRecord);
// int saveTestRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason);
}

@ -2,8 +2,11 @@ package com.dxhy.erp.service.impl;
import cn.hutool.core.util.ReflectUtil;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.annotation.DataSource;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.exception.BaseException;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.utils.R;
import com.dxhy.erp.dao.RequestRecordDao;
@ -13,46 +16,65 @@ import com.dxhy.erp.service.RequestRecordService;
import com.dxhy.erp.service.SNPushCheckRecordService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import org.springframework.http.HttpHeaders;
import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;
import java.util.*;
@Slf4j
@Service
public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao, RequestRecord> implements RequestRecordService {
private final Integer MAX_TIMES = 10;
private SNPushCheckRecordService snPushCheckRecordService;
private final String dbname = "business";
@Resource
RequestRecordDao requestRecordDao;
@Resource
private SNPushCheckRecordService snPushCheckRecordService;
@Autowired
private ApplicationContext applicationContext;
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public int saveRecord(RequestRecord record, Integer failedTimes, Integer status, String responseDetail, Integer... failedReason) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
record.setFailedTimes(failedTimes);
record.setStatus(status);
@DataSource(name = "business_business_write")
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public int saveSuccessfulRequestRecord(RequestRecord record, String responseDetail) {
record.setFailedTimes(0);
record.setStatus(0);
record.setResponseDetail(responseDetail);
if (failedReason.length > 0) {
record.setFailedReason(failedReason[0]);
log.info("接口调用记录正在保存,调用记录详情:{}",JSONObject.toJSONString(record));
int insert = requestRecordDao.insert(record);
return insert;
}
@Override
@DataSource(name = "business_business_write")
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public int saveFailedRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason) {
record.setFailedTimes(1);
record.setStatus(1);
record.setResponseDetail(responseDetail);
record.setFailedReason(failedReason);
record.setIsRecall(isRecall);
log.info("接口调用记录正在保存,调用记录详情:{}",JSONObject.toJSONString(record));
int insert = super.getBaseMapper().insert(record);
int insert = requestRecordDao.insert(record);
return insert;
}
@Override
@DataSource(name = "business_business_read")
public List<RequestRecord> getRecordList(String portName, Date startTime, Date endTime, Integer status, String methodName, Integer pageNumber, Integer PageSize) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
PageHelper.startPage(pageNumber, PageSize);
List<RequestRecord> recordList = requestRecordDao.selectRecordList(portName, startTime, endTime, status, methodName);
return recordList;
@ -91,59 +113,122 @@ public class RequestRecordServiceImpl extends MpBaseServiceImpl<RequestRecordDao
.build();
}
@Override
public ResponseEntity<?> reCall(RequestRecord requestRecord) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
DynamicContextHolder.push(dbname+DbConstant.BUSINESS_READ);
RequestRecord dbRecord = requestRecordDao.selectById(requestRecord.getId());
if (!dbRecord.getRequestDetail().equals(requestRecord.getRequestDetail())
|| !dbRecord.getResponseDetail().equals(requestRecord.getResponseDetail())
|| !dbRecord.getMethodName().equals(dbRecord.getMethodName())) {
if (dbRecord != null && !dbRecord.getRequestDetail().equals(requestRecord.getRequestDetail())
&& !dbRecord.getResponseDetail().equals(requestRecord.getResponseDetail())
&& !dbRecord.getMethodName().equals(dbRecord.getMethodName())) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("请求信息错误,请确认后再发送!")));
}
if (dbRecord.getFailedReason() == 0) {
if (dbRecord.getIsRecall() == 0) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("该请求参数不符合标准,无法进行重调,请校验参数后再申请!")));
}
if (dbRecord.getFailedTimes() > MAX_TIMES) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("该请求已达到最大重调用次数,无法再重新请求!")));
}
RequestRecordEnum[] RequestRecordEnums = RequestRecordEnum.values();
for (RequestRecordEnum recordenum : RequestRecordEnums) {
if (recordenum.getMethodName().equals(dbRecord.getMethodName())) {
if (recordenum.getPortName() == null) {
Method method = ReflectUtil.getMethod(recordenum.getControllerName(), recordenum.getMethodName());
Object invokeResponse;
try {
invokeResponse = method.invoke(snPushCheckRecordService, JSONObject.parseObject(dbRecord.getRequestDetail(), recordenum.getArgClass()));
updateRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse));
if (recordenum.getMethodName().equals(dbRecord.getActiveCall())) {
snPushCheckRecordService = (SNPushCheckRecordService)applicationContext.getBean(recordenum.getClassName());
Method method = ReflectUtil.getMethod(recordenum.getClass(), recordenum.getMethodName(), recordenum.getArgClass());
Object invokeResponse = null;
R data = new R(1000, "default success");
try {
DynamicContextHolder.push(dbname+DbConstant.BUSINESS_WRITE);
invokeResponse = method.invoke(snPushCheckRecordService, JSONObject.parseObject(dbRecord.getActiveCallRequestDetail(), recordenum.getArgClass()));
Map<String,String> map = JSONObject.parseObject(JSONObject.toJSONString(invokeResponse), Map.class);
data.put("data", invokeResponse);
if (map.containsKey("SAPKEY")) {
if (!map.containsValue("处理成功")) {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse), JSONObject.toJSONString(data), map.get("ZMESSAGE"), 0);
return ResponseEntity.ok(JSONObject.toJSONString(data));
}
}
if (map.containsKey("code")) {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse), JSONObject.toJSONString(data), map.get("message"), 0);
return ResponseEntity.ok(JSONObject.toJSONString(data));
} else {
if (map.containsKey("cyjg")) {
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse), JSONObject.toJSONString(data), map.get("cyjgxx"), 0);
return ResponseEntity.ok(JSONObject.toJSONString(data));
} catch (Exception e) {
log.error("重调用失败,错误信息:{}", e);
updateRecord(dbRecord, 1);
e.printStackTrace();
if (recordenum.getMethodName().equals("singleCheckInvoice")) {
return ResponseEntity.ok(JSONObject.toJSONString(R.error("查验失败,错误信息:" + e.getMessage())));
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("推送失败,错误信息:" + e.getMessage())));
}
updateSuccessfulRecallRecord(dbRecord, 0, JSONObject.toJSONString(invokeResponse), JSONObject.toJSONString(data));
return ResponseEntity.ok(JSONObject.toJSONString(data));
}
catch (IllegalAccessException e) {
log.info("重调用出现异常,异常信息:{}",e);
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse), JSONObject.toJSONString(data), JSONObject.toJSONString(e), 1);
e.printStackTrace();
return ResponseEntity.ok(JSONObject.toJSONString(R.error("重调用出现异常,请稍后重试")));
} catch (InvocationTargetException e) {
log.info("重调用出现异常,异常信息:{}",e);
updateFailedRecallRecord(dbRecord, 1, JSONObject.toJSONString(invokeResponse), JSONObject.toJSONString(data), JSONObject.toJSONString(e), 1);
e.printStackTrace();
return ResponseEntity.ok(JSONObject.toJSONString(R.error("重调用出现异常,请稍后重试")));
}
}
}
return ResponseEntity.ok(JSONObject.toJSONString(R.error("未找到相应信息!")));
return ResponseEntity.ok(JSONObject.toJSONString(R.error("未找到相应信息!")));
}
private int updateRecord(RequestRecord record, Integer status, String... responseDetail) {
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE);
private int updateSuccessfulRecallRecord(RequestRecord record, Integer status, String activeCallRecallResponse, String recallResponseDetail) {
setResponse(record, activeCallRecallResponse, recallResponseDetail);
record.setLastRetryTime(new Date());
record.setRetryTimes(record.getRetryTimes() + 1);
record.setStatus(status);
record.setIsRecall(null);
return requestRecordDao.updateById(record);
}
private int updateFailedRecallRecord(RequestRecord record, Integer status, String activeCallResponse, String recallResponseDetail, String failedReason, Integer isRecall) {
setResponse(record, activeCallResponse, recallResponseDetail);
record.setLastRetryTime(new Date());
record.setRetryTimes(record.getRetryTimes() + 1);
record.setStatus(status);
record.setRecallResponseDetail(responseDetail[0]);
requestRecordDao.updateById(record);
record.setFailedReason(failedReason);
record.setIsRecall(isRecall);
return requestRecordDao.updateById(record);
}
private void setResponse(RequestRecord record, String activeCallRecallResponse, String recallResponseDetail) {
if (record.getRetryTimes() == 0) {
HashMap<String, String> recallMap = new LinkedHashMap<>();
HashMap<String, String> activeCallrecallMap = new LinkedHashMap<>();
recallMap.put("第1次重调结果", recallResponseDetail);
activeCallrecallMap.put("第1次主动调用重调返回结果", activeCallRecallResponse);
record.setRecallResponseDetail(JSONObject.toJSONString(recallMap));
} else {
JSONObject.parseObject(record.getRecallResponseDetail(),LinkedHashMap.class).put("第"+ record.getRetryTimes() + 1+"次重调结果", recallResponseDetail);
JSONObject.parseObject(record.getActiveCallRecallResponse(),LinkedHashMap.class).put("第"+ record.getRetryTimes() + 1+"次主动调用重调返回结果", activeCallRecallResponse);
}
}
// @Override
// @DataSource(name = "business_business_write")
// @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = BaseException.class)
// public int saveTestRequestRecord(RequestRecord record, Integer isRecall, String responseDetail, String failedReason) throws BaseException{
// record.setFailedTimes(1);
// record.setStatus(1);
// record.setResponseDetail(responseDetail);
// record.setFailedReason(failedReason);
// record.setIsRecall(isRecall);
// log.info("接口调用记录正在保存,调用记录详情:{}",JSONObject.toJSONString(record));
//
// int insert = super.getBaseMapper().insert(record);
// throw new BaseException("测试用");
// }
}

Loading…
Cancel
Save