| | |
| | | // 获取出租车需要推送的数据 |
| | | List<Map<String, Object>> mapList = this.baseMapper.getTaxiOrderList(startTime, endTime); |
| | | List<PushEvaluationRequestDTO> taxiRequestList = PushEvaluationRequestDTO.convert(mapList); |
| | | if(CollectionUtils.isNotEmpty(taxiRequestList)) { |
| | | PushEvaluationLog evaluationLog = requestEvaluation(JSON.toJSONString(taxiRequestList)); |
| | | evaluationLog.setSerialNumber("taxi_"+startTime+"_"+endTime); |
| | | // 记录日志 |
| | | this.insert(evaluationLog); |
| | | } |
| | | // 获取专车需要推送的数据 |
| | | List<Map<String, Object>> mapPrivateList = this.baseMapper.getPrivateCarOrderList(startTime, endTime); |
| | | List<PushEvaluationRequestDTO> privateRequestList = PushEvaluationRequestDTO.convert(mapPrivateList); |
| | | // 数据推送 |
| | | List<PushEvaluationLog> logList = new ArrayList<>(); |
| | | taxiRequestList.forEach( taxi -> logList.add(requestEvaluation(taxi))); |
| | | privateRequestList.forEach( privateCar -> logList.add(requestEvaluation(privateCar))); |
| | | // 记录日志 |
| | | if(CollectionUtils.isNotEmpty(logList)) { |
| | | this.insertBatch(logList); |
| | | if(CollectionUtils.isNotEmpty(privateRequestList)) { |
| | | PushEvaluationLog evaluationLog = requestEvaluation(JSON.toJSONString(privateRequestList)); |
| | | evaluationLog.setSerialNumber("privateCar_"+startTime+"_"+endTime); |
| | | // 记录日志 |
| | | this.insert(evaluationLog); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public PushEvaluationLog requestEvaluation(PushEvaluationRequestDTO request) { |
| | | public PushEvaluationLog requestEvaluation(String requestData) { |
| | | // 构建请求头 |
| | | HttpHeaders headers = buildHeaders(); |
| | | String url = properties.getUrl() + API_PATH; |
| | |
| | | String errorMessage = ""; |
| | | try { |
| | | // 发送请求 |
| | | HttpEntity<PushEvaluationRequestDTO> entity = new HttpEntity<>(request, headers); |
| | | HttpEntity<String> entity = new HttpEntity<>(requestData, headers); |
| | | log.info("上报数据到考评系统-请求地址为:{},请求参数为 : {}", url, JSON.toJSONString(entity)); |
| | | ResponseEntity<PushEvaluationResponseDTO> responseEntity = restTemplate.exchange(url, HttpMethod.POST, entity, PushEvaluationResponseDTO.class); |
| | | // 返回数据 |
| | | response = responseEntity.getBody(); |
| | | if (Objects.isNull(response)) { |
| | | status = 0; |
| | | log.error("上报数据到考评系统-调用接口失败,返回为空"); |
| | | log.error("上报数据到考评系统-调用接口-失败,返回为空"); |
| | | } else if(response.getCode() != 200 ) { |
| | | status = 0; |
| | | log.error("上报数据到考评系统-调用接口失败,返回失败数据为:{}", JSON.toJSONString(response)); |
| | | log.error("上报数据到考评系统-调用接口-失败,返回失败数据为:{}", JSON.toJSONString(response)); |
| | | } |
| | | log.info("上报数据到考评系统-推送完成-请求URL:{},返回数据为:{}", url, JSON.toJSONString(response)); |
| | | log.info("上报数据到考评系统-调用接口-成功-请求URL:{},返回数据为:{}", url, JSON.toJSONString(response)); |
| | | } catch (Exception e) { |
| | | status = 0; |
| | | errorMessage = e.getLocalizedMessage(); |
| | |
| | | } |
| | | |
| | | PushEvaluationLog evaluationLog = new PushEvaluationLog(); |
| | | evaluationLog.setSerialNumber(request.getOrderNo()); // 订单号 |
| | | evaluationLog.setRequestUrl(url); |
| | | evaluationLog.setRequestHeader(JSON.toJSONString(headers)); |
| | | evaluationLog.setRequestBody(JSON.toJSONString(request)); |
| | | evaluationLog.setRequestBody(requestData); |
| | | Optional.ofNullable(response).map(JSON::toJSONString).ifPresent( evaluationLog::setResponseBody); |
| | | evaluationLog.setStatus(status); |
| | | evaluationLog.setRetryCount(0); |
| | |
| | | */ |
| | | public HttpHeaders buildHeaders() { |
| | | String timestamp = String.valueOf(System.currentTimeMillis() / 1000); // 时间戳 |
| | | String nonce = RandomStringUtils.randomAlphanumeric(6); // 6位随机数 |
| | | String nonce = RandomStringUtils.randomNumeric(6); // 6位随机数 |
| | | String sign = SignUtil.generateSign("POST", API_PATH, properties.getAccessKey(), properties.getAccessSecret(), timestamp, nonce); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | |
| | | headers.set("sign", sign); |
| | | return headers; |
| | | } |
| | | |
| | | } |