Commit d4daf21b by 黄明步

.

parent 78d91a2e
......@@ -34,6 +34,10 @@ public class RedisConstant {
* redis key 能力配置信息
**/
public static final String CONFIG_ABILITY_ALL = "configAbility:all";
/**
* redis key 记录每个服务器识别时间超过10s的次数
**/
public static final String SLOW_CALL_COUNT = "slow-call:count:";
}
......@@ -33,7 +33,6 @@ import com.gxmailu.ocrCloudPlatform.service.CourtService;
import com.gxmailu.ocrCloudPlatform.utils.IpUtils;
import com.gxmailu.ocrCloudPlatform.vo.BrokenLineData;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -148,10 +147,6 @@ public class ElasticSearchService {
JSONObject object = new JSONObject();
SearchResponse<Void> searchResponse;
try {
// 获取法院ip段
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-");
List<String> ipRange = ipScopes.size() != 2 ? Arrays.asList("255.255.255.255", "255.255.255.255") : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3);
searchResponse = client.search(srBuilder -> srBuilder
.index(APP_ABILITY_RECORD_INDEX)
.query(queryBuilder -> queryBuilder.bool(boolQuery -> {
......@@ -160,11 +155,20 @@ public class ElasticSearchService {
.field("callTime")
.gte(JsonData.of(start.toString()))
.lte(JsonData.of(end.toString()))));
if (ObjUtil.isNotNull(court)) {
// 获取法院ip段
List<String> ipScopes = StrUtil.splitTrim(court.getIpScope(), "-");
try {
List<String> ipRange = ipScopes.size() != 2 ? Arrays.asList("255.255.255.255", "255.255.255.255") : IpUtils.getIPRange(ipScopes.get(0), ipScopes.get(1), 3);
// 多个ip前缀过滤
boolQuery.must(mustQuery -> mustQuery.bool(bq -> {
ipRange.forEach(ip -> bq.should(q -> q.prefix(pq -> pq.field("ip.keyword").value(ip))));
return bq;
}));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return boolQuery;
}))
// 总命中数,与hits.size()不同的是trackTotalHits不会限制10000
......
......@@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.*;
import cn.hutool.http.ContentType;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
......@@ -69,8 +71,7 @@ public class RetransmissionService {
private AppAbilityRecord8Mapper record8Mapper;
@Autowired
private AppAbilityRecord9Mapper record9Mapper;
@Autowired
private AppAbilityRecordAllMapper recordAllMapper;
@Autowired
private TmpRecordByTriggerMapper tmpRecordByTriggerMapper;
......@@ -106,7 +107,6 @@ public class RetransmissionService {
private static final int MAX_RETRIES = 5;
@PostConstruct
public void init() {
// 创建临时文件夹
......@@ -221,7 +221,6 @@ public class RetransmissionService {
}
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
this.setRequestToRedis(2, startTime, endTime, result, ocrServerAddress, request);
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result;
} catch (Exception e) {
......@@ -236,13 +235,6 @@ public class RetransmissionService {
}
public Map<String, String> getHeaderMap(HttpServletRequest request) {
// Map<String, String> headerMap = new HashMap<>();
// headerMap.put("Authorization", request.getHeader("Authorization"));
// headerMap.put("X-Timestamp", request.getHeader("X-Timestamp"));
// headerMap.put("X-Checksum", request.getHeader("X-Checksum"));
// headerMap.put("Accept", request.getHeader("Accept"));
// headerMap.put("User-Agent", request.getHeader("User-Agent"));
// return headerMap;
Map<String, String> map = new HashMap<>();
Enumeration<String> headerNames = request.getHeaderNames();
......@@ -346,36 +338,6 @@ public class RetransmissionService {
}
}
public void downloadDoubleDeckPdf(JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try {
ServerInfo ocrServerAddress = getServerAddressByRequestCount();
if (ocrServerAddress == null) {
returnError(response, 500, "OCR云平台未配置服务器信息");
return;
}
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/pdf")
.headerMap(getHeaderMap(request), true)
.contentType("application/json;charset=UTF-8")
.setConnectionTimeout(10 * 1000)
.body(body.toJSONString(0)).execute();
Map<String, List<String>> headers = httpResponse.headers();
if (!headers.isEmpty()) {
// 遍历赋值header
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
response.setHeader(entry.getKey(), entry.getValue().get(0));
}
}
// 赋值body
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (Exception e) {
log.error("OCR云平台接口异常", e);
returnError(response, 500, "OCR云平台接口异常");
}
}
public void downloadPdfNew(JSONObject body, HttpServletResponse response) {
Long id = body.getLong("sid");
try {
......@@ -383,9 +345,8 @@ public class RetransmissionService {
log.error("请求体中缺少 'sid' 字段,无法进行后续处理");
return;
}
AppAbilityRecordAll appAbilityRecordAll = elasticSearchService.getDocumentById(id.toString());
// 如果 appAbilityRecordAll 为空,或者相关字段为空,则直接查询数据库
// 如果 appAbilityRecordAll 为空,或者相关字段为空,再次查询数据库
if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp())
|| StrUtil.isBlank(appAbilityRecordAll.getDstUrl())
|| StrUtil.isBlank(appAbilityRecordAll.getPdf())) {
......@@ -423,32 +384,6 @@ public class RetransmissionService {
}
}
public void downloadDoubleDeckOfd(JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try {
ServerInfo ocrServerAddress = getServerAddressByRequestCount();
if (ocrServerAddress == null) {
returnError(response, 500, "OCR云平台未配置服务器信息");
return;
}
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ofd")
.headerMap(getHeaderMap(request), true)
.contentType("application/json;charset=UTF-8")
.setConnectionTimeout(10 * 1000)
.body(body.toJSONString(0)).execute();
Map<String, List<String>> headers = httpResponse.headers();
if (!headers.isEmpty()) {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
response.setHeader(entry.getKey(), entry.getValue().get(0));
}
}
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (Exception e) {
log.error("OCR云平台接口异常", e);
returnError(response, 500, "OCR云平台接口异常");
}
}
public void downloadOfdNew(JSONObject body, HttpServletResponse response) {
Long id = body.getLong("sid");
......@@ -854,29 +789,6 @@ public class RetransmissionService {
mapper.updateById(record);
// 保存到ES
elasticSearchService.recordDataImport(Collections.singletonList(record));
// // log.info("修改id:{}的真实客户端请求ip结果:{}", id, mapper.updateById(record));
// AppAbilityRecordAll recordAll = recordAllMapper.selectById(id);
// if (recordAll == null) {
// recordAll = new AppAbilityRecordAll();
// BeanUtils.copyProperties(record, recordAll, AppAbilityRecordAll.class);
// recordAll.setCreatedTime(DateUtil.date());
// recordAll.setUpdatedTime(DateUtil.date());
// if (StrUtil.isEmpty(recordAll.getServerIp())) {
// recordAll.setServerIp(serverIp);
// }
// recordAllMapper.insert(recordAll);
// // log.info("添加id:{} 的数据到recordAll持久化保存结果:{}", recordAll.getId(), recordAllMapper.insert(recordAll));
// } else {
// AppAbilityRecordAll newRecordAll = new AppAbilityRecordAll();
// BeanUtils.copyProperties(record, newRecordAll, AppAbilityRecordAll.class);
// newRecordAll.setUpdatedTime(DateUtil.date());
// if (StrUtil.isEmpty(newRecordAll.getServerIp())) {
// newRecordAll.setServerIp(serverIp);
// }
// recordAllMapper.updateById(newRecordAll);
// // log.info("修改recordAll中id:{} 的数据结果:{}", newRecordAll.getId(), recordAllMapper.updateById(newRecordAll));
// }
}
......@@ -991,7 +903,7 @@ public class RetransmissionService {
})).orElse(null);
}
// 如果没有选择到服务器,则从服务器列表中简单轮询选择一个服务器,而不是随机选择
// 如果没有选择到服务器,则从服务器列表中简单轮询选择一个服务器
if (serverInfo == null && CollUtil.isNotEmpty(ocrServerList)) {
int index = Math.abs(counter.getAndIncrement()) % ocrServerList.size();
serverInfo = ocrServerList.get(index);
......
......@@ -302,7 +302,7 @@ public class ServerInfoServiceImpl implements ServerInfoService {
* @param serverInfo 服务器信息
*/
private ServerVo getTaskCount(ServerInfo serverInfo) {
Object count = redisService.getValue("server-request-task-" + serverInfo.getIp());
Object count = redisService.getValue(RedisConstant.SERVER_REQUEST_TASK + serverInfo.getIp());
ServerVo ocrServerVo = new ServerVo();
BeanUtils.copyProperties(serverInfo, ocrServerVo, ServerVo.class);
ocrServerVo.setOcrTask(ObjUtil.isNull(count) ? 0L : Long.parseLong(count.toString()));
......
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