| @ -1,93 +0,0 @@ | |||
| package com.inspect.analysis.service.impl; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.inspect.analysis.constant.AnalyseConstants; | |||
| import com.inspect.analysis.domain.AnalyseLog; | |||
| import com.inspect.analysis.service.IAnalysisLogService; | |||
| import com.inspect.base.core.utils.HttpClientUtils; | |||
| import com.inspect.base.core.utils.StringUtils; | |||
| import com.inspect.base.redis.service.RedisService; | |||
| import com.inspect.partrolresult.domain.AnalyseReqItem; | |||
| import com.inspect.partrolresult.domain.AnalyseRequest; | |||
| import com.inspect.task.service.IPatrolTaskService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.stereotype.Component; | |||
| import javax.annotation.Resource; | |||
| import java.util.Collections; | |||
| import java.util.UUID; | |||
| import java.util.concurrent.TimeUnit; | |||
| @Component | |||
| public class IspAlgorithmRequestService { | |||
| private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||
| @Value("${server.port}") | |||
| private String port; | |||
| @Resource | |||
| private RedisService redisService; | |||
| @Resource | |||
| private IAnalysisLogService analysisLogService; | |||
| @Resource | |||
| private IPatrolTaskService patrolTaskService; | |||
| public void sendRequest(AnalyseRequest analyseReq, boolean isFilter) { | |||
| String requestId = UUID.randomUUID().toString().trim().replaceAll(StringUtils.DASH, StringUtils.EMPTY); | |||
| String taskPatrolId = analyseReq.getTaskPatrolId(); | |||
| analyseReq.setRequestId(requestId); | |||
| String taskSetKey = AnalyseConstants.ANALYSE_TASK_REQUEST.concat(taskPatrolId); | |||
| String requestSetKey = AnalyseConstants.ANALYSE_REQUEST_ALG.concat(requestId); | |||
| redisService.setCacheObject(AnalyseConstants.ANALYSE_REQUEST_ID.concat(requestId), taskPatrolId, 20L, TimeUnit.MINUTES); | |||
| redisService.redisTemplate.opsForSet().add(taskSetKey, requestId); | |||
| redisService.expire(taskSetKey, 20L, TimeUnit.MINUTES); | |||
| String analyseFilter = patrolTaskService.selectConfigByKey(AnalyseConstants.ANALYSE_IS_FILTER); | |||
| String filter = "0"; | |||
| String requestUrl; | |||
| if ("1".equals(analyseFilter) && isFilter) { | |||
| final String analyzeFilterRequestIdRedisKey = AnalyseConstants.ANALYSE_FILTER_REQUEST.concat(requestId); | |||
| log.info("[ALG] sendRequest analyseFilterRequestIdRedisKey: {}, analyseReq: {}", analyzeFilterRequestIdRedisKey, analyseReq); | |||
| redisService.setCacheObject(analyzeFilterRequestIdRedisKey, analyseReq.clone(), 1L, TimeUnit.HOURS); | |||
| AnalyseReqItem analyseReqItem = analyseReq.getObjectList().get(0); | |||
| analyseReqItem.setTypeList(new String[]{"tx_pb"}); | |||
| analyseReq.setObjectList(Collections.singletonList(analyseReqItem)); | |||
| filter = "1"; | |||
| requestUrl = patrolTaskService.selectConfigByKey(AnalyseConstants.ANALYSE_FILTER_URL); | |||
| } else { | |||
| analyseReq.getObjectList().forEach((item) -> { | |||
| for (String type : item.getTypeList()) { | |||
| redisService.redisTemplate.opsForSet().add(requestSetKey, item.toResultValue(type)); | |||
| } | |||
| }); | |||
| requestUrl = patrolTaskService.selectConfigByKey(AnalyseConstants.ANALYSIS_BIG_URL); | |||
| } | |||
| analysisLogService.log(new AnalyseLog(analyseReq.toString(), "0", taskPatrolId, filter, requestId)); | |||
| try { | |||
| log.info("[ANALYSE REMOTE REQ] REMOTE_URL={}\n REMOTE_PARAMS={}", requestUrl, analyseReq); | |||
| String result = HttpClientUtils.sendPostAgain(requestUrl.concat("/picAnalyse"), analyseReq.toString()); | |||
| final String resultCode = JSONObject.parseObject(result).getString(AnalyseConstants.ANALYSE_CODE); | |||
| log.info("[ANALYSE REMOTE REQ] RESULT_CODE={}\n RESULT={}", resultCode, result); | |||
| if (!"200".equals(resultCode)) { | |||
| log.error("[ANALYSE REMOTE REQ] BAD RESULT={}", result); | |||
| } | |||
| } catch (Exception e) { | |||
| log.error("[ANALYSE REMOTE REQ] REMOTE ISP ALGORITHM SERVER EXCEPTION: {}", e.getMessage()); | |||
| HttpClientUtils.sendPostAgain("http://localhost:" + this.port + "/picAnalyseRetNotify", analyseReq.toErrorResultStr()); | |||
| } | |||
| } | |||
| public void sendRequest(AnalyseRequest analyseReq) { | |||
| this.sendRequest(analyseReq, Boolean.FALSE); | |||
| } | |||
| public static void main(String[] args) { | |||
| String result = AnalyseConstants.ANALYSE_REQUEST_ID.concat("1234"); | |||
| System.out.println(result); | |||
| } | |||
| } | |||