Commit f1c5a835 by 黄明步

添加识别错误超过次数则停用逻辑

parent 4e830ef5
......@@ -48,5 +48,10 @@ public class RedisConstant {
*/
public static final String SERVER_MONITORING = "server:monitoring";
/**
* redis key 记录每个服务器错误的次数
**/
public static final String SERVER_ERROR_COUNT = "server-error:count:";
}
package com.gxmailu.ocrCloudPlatform.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
......@@ -18,11 +19,11 @@ import com.gxmailu.ocrCloudPlatform.entity.*;
import com.gxmailu.ocrCloudPlatform.excel.handler.ExcelFillCellMergeStrategy;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord8Mapper;
import com.gxmailu.ocrCloudPlatform.mapper.ConfigAbilityMapper;
import com.gxmailu.ocrCloudPlatform.mapper.ConfigApplicationMapper;
import com.gxmailu.ocrCloudPlatform.service.AppAbilityRecordAllService;
import com.gxmailu.ocrCloudPlatform.service.OaCallRecordService;
import com.gxmailu.ocrCloudPlatform.service.impl.ElasticSearchService;
import com.gxmailu.ocrCloudPlatform.vo.AppAbilityRecordVo;
import com.gxmailu.ocrCloudPlatform.vo.Result;
import io.swagger.annotations.Api;
......@@ -67,7 +68,7 @@ public class AppAbilityRecordAllController {
private ConfigAbilityMapper configAbilityMapper;
@Autowired
private AppAbilityRecord8Mapper record8Mapper;
private ElasticSearchService elasticSearchService;
/**
* 导出应用调用记录
......@@ -360,7 +361,8 @@ public class AppAbilityRecordAllController {
record.setCallTime(DateUtil.date());
record.setFileCount(1);
record8Mapper.insert(record);
elasticSearchService.recordDataImport(CollUtil.newArrayList(record));
return Result.success("成功");
} catch (Exception e) {
log.error("执行失败", e);
......
......@@ -148,6 +148,29 @@ public class RetransmissionService {
}
}
@Async
public void recordErrors(String ip) {
String key = RedisConstant.SERVER_ERROR_COUNT + ip;
if (redisService.exists(key)) {
redisService.incr(key, 1);
} else {
redisService.set(key, 1, 1, TimeUnit.MINUTES);
}
// 判断识别错误的次数是否大于3次,若大于则移除服务器2分钟
long count;
Object o = redisService.get(key);
if (ObjUtil.isNotNull(o)) {
count = Long.parseLong(o.toString());
if (count >= 3) {
Object object = redisService.getValue(RedisConstant.OCR_SERVER_LIST);
List<ServerInfo> serverInfos = JSONArray.parseArray(object.toString(), ServerInfo.class);
serverInfos = serverInfos.stream().filter(serverInfo -> !serverInfo.getIp().equals(ip)).collect(Collectors.toList());
redisService.set(RedisConstant.OCR_SERVER_LIST, serverInfos, 2, TimeUnit.MINUTES);
redisService.delete(key);
}
}
}
public OcrResult getClientOcrTask() {
List<Object> result = redisService.getList("clientOcrTask");
List<JSONObject> jsonList = JSONArray.parseArray(result.toString(), JSONObject.class);
......@@ -187,9 +210,18 @@ public class RetransmissionService {
json.set("endTime", DateUtil.format(DateUtil.date(endTime), "yyyy-MM-dd HH:mm:ss.SSS"));
json.set("time", (Double.parseDouble(String.valueOf((endTime - startTime))) / Double.parseDouble("1000.00")) + "秒");
if (ocrResult != null) {
json.set("code", ocrResult.getCode());
String code = ocrResult.getCode();
json.set("code", code);
json.set("message", ocrResult.getMessage());
if ("007500".equals(code)) {
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
}
} else {
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
}
redisService.set(
"clientOcrTask-" + ocrServerAddress.getIp() + "-" + ServletUtil.getClientIP(request) + "-" + startTime,
json,
......@@ -247,6 +279,8 @@ public class RetransmissionService {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
}
}
......@@ -353,6 +387,8 @@ public class RetransmissionService {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
}
}
......@@ -520,6 +556,8 @@ public class RetransmissionService {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
}
}
......@@ -593,6 +631,8 @@ public class RetransmissionService {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount);
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
}
}
......@@ -660,6 +700,8 @@ public class RetransmissionService {
return result;
} catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
// 记录错误次数
recordErrors(ocrServerAddress.getIp());
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally {
FileUtil.del(tempSaveDir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment