Commit 221db772 LN

异常接口发送成功后自动删除。

1 个父辈 4045ca25
...@@ -117,6 +117,14 @@ public class InterfaceExceptionController { ...@@ -117,6 +117,14 @@ public class InterfaceExceptionController {
if (request == null) { if (request == null) {
throw new ValidateException("smfcore.error.interfaceEx.invalid", "未找到异常接口{0}", new String[]{reqCode}); throw new ValidateException("smfcore.error.interfaceEx.invalid", "未找到异常接口{0}", new String[]{reqCode});
} }
//如果上次返回成功,直接删除
if(request.getResponseParam().getCode().equals(0)){
log.info("重发接口["+reqCode+"]时发现上次返回值为0,删除接口异常");
HikApiCache.removeFailedRequest(request);
throw new ValidateException("smfcore.error.interfaceEx.invalid", "此接口已返回成功,不需要重发", new String[]{reqCode});
}
ResponseParam responseParam = HikApiCache.reSendRequest(request); ResponseParam responseParam = HikApiCache.reSendRequest(request);
if (responseParam.getCode().equals(0)) { if (responseParam.getCode().equals(0)) {
......
...@@ -21,18 +21,18 @@ public class HikApiCache { ...@@ -21,18 +21,18 @@ public class HikApiCache {
private static DataCache dataCache; private static DataCache dataCache;
@Autowired @Autowired
public void setDataCache(DataCache dataCache){ public void setDataCache(DataCache dataCache) {
HikApiCache.dataCache=dataCache; HikApiCache.dataCache = dataCache;
} }
/** /**
* 需要重发的指令列表 * 需要重发的指令列表
*/ */
private static Map<String, HikApiRequest> failedRequestMap=new HashMap<>(); private static Map<String, HikApiRequest> failedRequestMap = new HashMap<>();
private static boolean isProcessTimer = false; private static boolean isProcessTimer = false;
@PostConstruct @PostConstruct
public void Init(){ public void Init() {
initApiRequestMap(); initApiRequestMap();
} }
/** /**
...@@ -63,10 +63,10 @@ public class HikApiCache { ...@@ -63,10 +63,10 @@ public class HikApiCache {
} }
} }
public static List<HikApiRequest> getAllRequestList(){ public static List<HikApiRequest> getAllRequestList() {
return new ArrayList<>(failedRequestMap.values()); return new ArrayList<>(failedRequestMap.values());
} }
public static HikApiRequest getRequest(String req){ public static HikApiRequest getRequest(String req) {
return failedRequestMap.get(req); return failedRequestMap.get(req);
} }
...@@ -93,7 +93,6 @@ public class HikApiCache { ...@@ -93,7 +93,6 @@ public class HikApiCache {
} }
/** /**
* 获取失败列表,进行定时发送 * 获取失败列表,进行定时发送
*/ */
...@@ -118,7 +117,7 @@ public class HikApiCache { ...@@ -118,7 +117,7 @@ public class HikApiCache {
} }
public static ResponseParam reSendRequest(HikApiRequest apiRequest) { public static ResponseParam reSendRequest(HikApiRequest apiRequest) {
ResponseParam responseParam =null; ResponseParam responseParam = null;
try { try {
String interName = "Hik 接口" + apiRequest.getApiType() + " 重发:"; String interName = "Hik 接口" + apiRequest.getApiType() + " 重发:";
responseParam = HttpHelper.post(apiRequest); responseParam = HttpHelper.post(apiRequest);
...@@ -134,6 +133,7 @@ public class HikApiCache { ...@@ -134,6 +133,7 @@ public class HikApiCache {
if (responseParam.getCode().equals(0)) { if (responseParam.getCode().equals(0)) {
log.info(interName + ",发送成功,删除接口异常,返回" + JsonUtil.toJsonStr(responseParam)); log.info(interName + ",发送成功,删除接口异常,返回" + JsonUtil.toJsonStr(responseParam));
removeFailedRequest(apiRequest); removeFailedRequest(apiRequest);
return responseParam;
} else { } else {
log.info(interName + ",返回" + JsonUtil.toJsonStr(responseParam)); log.info(interName + ",返回" + JsonUtil.toJsonStr(responseParam));
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!