Browse Source

修改交通流监测相关代码

develop
Mr.Wang 5 months ago
parent
commit
058c64257f
  1. 2
      zc-business/src/main/java/com/zc/business/domain/ExternalInterfaceMonitoring.java
  2. 35
      zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java

2
zc-business/src/main/java/com/zc/business/domain/ExternalInterfaceMonitoring.java

@ -1,5 +1,6 @@
package com.zc.business.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
@ -41,6 +42,7 @@ public class ExternalInterfaceMonitoring {
@ApiModelProperty("操作结果")
private String operationResult;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
@ApiModelProperty("操作时间")
private Date operationTime;
}

35
zc-business/src/main/java/com/zc/business/task/ExternalInterfaceMonitoringTask.java

@ -7,6 +7,9 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
@ -71,8 +74,7 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
*/
@ApiOperation("外部接口监控信息列表")
@GetMapping("/list")
public TableDataInfo list(ExternalInterfaceMonitoring externalInterfaceMonitoring)
{
public TableDataInfo list(ExternalInterfaceMonitoring externalInterfaceMonitoring) {
startPage();
LambdaQueryWrapper<ExternalInterfaceMonitoring> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (externalInterfaceMonitoring.getInterfaceOwnership() != null) {
@ -578,10 +580,10 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
externalInterfaceMonitoring.setOperationResult(response.toString());
}
}catch (Exception e) {
} catch (Exception e) {
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
externalInterfaceMonitoring.setOperationResult(e.toString());
}finally {
} finally {
externalInterfaceMonitoring.setId(IdUtils.fastSimpleUUID());
externalInterfaceMonitoring.setOperatorName("系统");
externalInterfaceMonitoring.setOperationTime(new Date());
@ -594,15 +596,30 @@ public class ExternalInterfaceMonitoringTask extends BaseController {
* 交通流结果处理
*/
public void trafficFlowResultProcessing(ExternalInterfaceMonitoring externalInterfaceMonitoring, Response response) throws Exception {
ResponseBody body = response.body();
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
if (response.code() == UniversalEnum.TWO_HUNDRED.getNumber()) {
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber());
} else {
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
}
if (body != null) {
JSONObject jsonResult = JSONObject.parseObject(body.string());
if (jsonResult.containsKey("code") && jsonResult.get("code").equals(UniversalEnum.TWO_HUNDRED.getNumber())) {
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ONE.getNumber());
String bodyString = body.string();
JsonObject jsonResult = null;
// 使用JsonElement解析数据
JsonElement jsonElement = JsonParser.parseString(bodyString);
// 检查数据类型并相应处理
if (jsonElement.isJsonObject()) {
// 如果是对象,进行对象处理
jsonResult = jsonElement.getAsJsonObject();
if (!jsonResult.get("code").toString().equals(UniversalEnum.TWO_HUNDRED.getValue())) {
externalInterfaceMonitoring.setOperationStatus(UniversalEnum.ZERO.getNumber());
}
}
externalInterfaceMonitoring.setOperationResult(body.string());
externalInterfaceMonitoring.setOperationResult(bodyString);
} else {
externalInterfaceMonitoring.setOperationResult(response.toString());
}

Loading…
Cancel
Save