Commit 221db772 LN

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

1 个父辈 4045ca25
......@@ -117,6 +117,14 @@ public class InterfaceExceptionController {
if (request == null) {
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);
if (responseParam.getCode().equals(0)) {
......
......@@ -21,18 +21,18 @@ public class HikApiCache {
private static DataCache dataCache;
@Autowired
public void setDataCache(DataCache dataCache){
HikApiCache.dataCache=dataCache;
public void setDataCache(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;
@PostConstruct
public void Init(){
public void Init() {
initApiRequestMap();
}
/**
......@@ -63,10 +63,10 @@ public class HikApiCache {
}
}
public static List<HikApiRequest> getAllRequestList(){
public static List<HikApiRequest> getAllRequestList() {
return new ArrayList<>(failedRequestMap.values());
}
public static HikApiRequest getRequest(String req){
public static HikApiRequest getRequest(String req) {
return failedRequestMap.get(req);
}
......@@ -93,11 +93,10 @@ public class HikApiCache {
}
/**
* 获取失败列表,进行定时发送
*/
public static void sendFailedRequest() {
public static void sendFailedRequest() {
if (failedRequestMap == null) {
initApiRequestMap();
......@@ -118,7 +117,7 @@ public class HikApiCache {
}
public static ResponseParam reSendRequest(HikApiRequest apiRequest) {
ResponseParam responseParam =null;
ResponseParam responseParam = null;
try {
String interName = "Hik 接口" + apiRequest.getApiType() + " 重发:";
responseParam = HttpHelper.post(apiRequest);
......@@ -134,6 +133,7 @@ public class HikApiCache {
if (responseParam.getCode().equals(0)) {
log.info(interName + ",发送成功,删除接口异常,返回" + JsonUtil.toJsonStr(responseParam));
removeFailedRequest(apiRequest);
return responseParam;
} else {
log.info(interName + ",返回" + JsonUtil.toJsonStr(responseParam));
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!