Commit edb7744a authored by duanruiming's avatar duanruiming

[add] 优化次数时间优化

parent 77272f20
...@@ -104,6 +104,11 @@ ...@@ -104,6 +104,11 @@
<!-- 依赖声明 --> <!-- 依赖声明 -->
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
<!-- knife4j依赖 --> <!-- knife4j依赖 -->
<dependency> <dependency>
<groupId>com.github.xiaoymin</groupId> <groupId>com.github.xiaoymin</groupId>
......
...@@ -18,6 +18,11 @@ ...@@ -18,6 +18,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
<!--客户端负载均衡loadbalancer--> <!--客户端负载均衡loadbalancer-->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
......
package net.wanji.opt.dto;
import lombok.Data;
/**
* @author duanruiming
* @date 2025/02/07 15:14
*/
@Data
public class StrategyOptCountDTO {
private String message;
private String status;
private Integer code;
private Long timestamp;
private Detail content;
@Data
public static class Detail {
private Integer congestionNum;
private Integer congestionRoadNum;
private Integer emptyPassNum;
private Integer emptyPassNumUp;
private Integer slowlyRoadNum;
private Integer spilloverNum;
private Integer spilloverNumUp;
private Integer unbalanceNum;
private Integer unbalanceNumUp;
}
}
package net.wanji.opt.dto;
import lombok.Data;
import java.util.List;
/**
* @author duanruiming
* @date 2025/02/07 14:42
*/
@Data
public class StrategyOptTimesDTO {
private String message;
private String status;
private Integer code;
private Long timestamp;
private List<Detail> content;
@Data
public static class Detail {
private Integer executeNum;
private Integer executeNumUp;
private Double optimizeTime;
private Integer optimizeTimeUp;
private String strategyType;
}
}
...@@ -64,4 +64,6 @@ public class StrategyCrossResultEntity { ...@@ -64,4 +64,6 @@ public class StrategyCrossResultEntity {
private Integer emptyTurn; private Integer emptyTurn;
@TableField("empty_dir") @TableField("empty_dir")
private String empty_dir; private String empty_dir;
@TableField("dt")
private Integer dt;
} }
...@@ -9,12 +9,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -9,12 +9,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.Constants; import net.wanji.common.framework.Constants;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.OkHttpClientUtil;
import net.wanji.common.utils.tool.DateUtil; import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.JacksonUtils; import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.databus.dao.entity.GreenwaveInfoPO; import net.wanji.databus.dao.entity.GreenwaveInfoPO;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper; import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper; import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper;
import net.wanji.databus.dao.mapper.GreenwaveInfoMapper; import net.wanji.databus.dao.mapper.GreenwaveInfoMapper;
import net.wanji.databus.entity.basedata.ResultView;
import net.wanji.databus.po.BaseCrossInfoPO; import net.wanji.databus.po.BaseCrossInfoPO;
import net.wanji.databus.vo.AbnormalCrossListVO; import net.wanji.databus.vo.AbnormalCrossListVO;
import net.wanji.opt.cache.BaseCrossInfoCache; import net.wanji.opt.cache.BaseCrossInfoCache;
...@@ -22,6 +24,8 @@ import net.wanji.opt.cache.GreenWaveInfoCache; ...@@ -22,6 +24,8 @@ import net.wanji.opt.cache.GreenWaveInfoCache;
import net.wanji.opt.common.enums.EventStatusEnum; import net.wanji.opt.common.enums.EventStatusEnum;
import net.wanji.opt.common.enums.StrategyControlEnum; import net.wanji.opt.common.enums.StrategyControlEnum;
import net.wanji.opt.dao.mapper.*; import net.wanji.opt.dao.mapper.*;
import net.wanji.opt.dto.StrategyOptCountDTO;
import net.wanji.opt.dto.StrategyOptTimesDTO;
import net.wanji.opt.po.StrategyGreenOptHistEntity; import net.wanji.opt.po.StrategyGreenOptHistEntity;
import net.wanji.opt.po.trend.HoloEventInfoPO; import net.wanji.opt.po.trend.HoloEventInfoPO;
import net.wanji.opt.synthesis.enums.StrategyCrossAlgoEnum; import net.wanji.opt.synthesis.enums.StrategyCrossAlgoEnum;
...@@ -30,6 +34,7 @@ import net.wanji.opt.synthesis.pojo.vo.*; ...@@ -30,6 +34,7 @@ import net.wanji.opt.synthesis.pojo.vo.*;
import net.wanji.opt.synthesis.service.PushStrategyControlService; import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService; import net.wanji.opt.synthesis.service.StrategyControlService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.geotools.feature.visitor.CountVisitor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -133,8 +138,13 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -133,8 +138,13 @@ public class StrategyControlServiceImpl implements StrategyControlService {
detailData.setBiz_id(dataVO.getBizId()); detailData.setBiz_id(dataVO.getBizId());
detailData.setBiz_type(dataVO.getBizType()); detailData.setBiz_type(dataVO.getBizType());
detailData.setStrategy(dataVO.getStrategy()); detailData.setStrategy(dataVO.getStrategy());
detailData.setSchedule_start(DateUtil.format(dataVO.getScheduleStart(), Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND)); if (Objects.nonNull(dataVO.getScheduleStart()) && Objects.nonNull(dataVO.getScheduleStart())) {
detailData.setSchedule_end(DateUtil.format(dataVO.getScheduleEnd(), Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND)); detailData.setSchedule_start(DateUtil.format(dataVO.getScheduleStart(), Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND));
detailData.setSchedule_end(DateUtil.format(dataVO.getScheduleEnd(), Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND));
} else {
detailData.setSchedule_start(DateUtil.format(new Date(), Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND));
detailData.setSchedule_end(DateUtil.format(new Date(), Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND));
}
List<StrategyControlDataVO.TimeTable> timeTableList = dataVO.getTime(); List<StrategyControlDataVO.TimeTable> timeTableList = dataVO.getTime();
List<StrategyControlDataReq.Time_table> timeTables = new ArrayList<>(timeTableList.size()); List<StrategyControlDataReq.Time_table> timeTables = new ArrayList<>(timeTableList.size());
timeTableList.forEach(item -> { timeTableList.forEach(item -> {
...@@ -380,36 +390,30 @@ public class StrategyControlServiceImpl implements StrategyControlService { ...@@ -380,36 +390,30 @@ public class StrategyControlServiceImpl implements StrategyControlService {
@Override @Override
public JsonViewObject strategyOptTimes() throws Exception { public JsonViewObject strategyOptTimes() throws Exception {
LocalDate currentDate = LocalDate.now(); String timeUrl = "http://37.12.182.29:15020/decisionPage/MonitorStrategyOptimizationInfo/getData";
LocalTime startTime = LocalTime.MIDNIGHT; String timeResult = OkHttpClientUtil.get(timeUrl);
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime); ObjectMapper mapper = JacksonUtils.getInstance();
LambdaQueryWrapper<StrategyGreenOptHistEntity> greenQuery = new LambdaQueryWrapper<>(); StrategyOptTimesVO strategyOptTimesVO = new StrategyOptTimesVO();
greenQuery.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay); if (StringUtils.isNotBlank(timeResult)) {
List<StrategyGreenOptHistEntity> greenOptList = strategyGreenOptHistMapper.selectList(greenQuery); StrategyOptTimesDTO dto = mapper.readValue(timeResult, StrategyOptTimesDTO.class);
int totalTime = 0; List<StrategyOptTimesDTO.Detail> content = dto.getContent();
int totalCount = 0; if (!CollectionUtils.isEmpty(content)) {
if (!CollectionUtils.isEmpty(greenOptList)) { Double totalTime = 0.0;
for (StrategyGreenOptHistEntity entity : greenOptList) { for (StrategyOptTimesDTO.Detail item : content) {
Integer controlDuration = entity.getControlDuration(); totalTime += item.getOptimizeTime();
totalTime += controlDuration;
totalCount += 1;
}
}
LambdaQueryWrapper<StrategyCrossResultEntity> crossQuery = new LambdaQueryWrapper<>();
crossQuery.ge(StrategyCrossResultEntity::getIssueTime, startOfDay);
List<StrategyCrossResultEntity> crossList = strategyCrossResultMapper.selectList(crossQuery);
if (!CollectionUtils.isEmpty(crossList)) {
for (StrategyCrossResultEntity entity : crossList) {
Integer countDown = entity.getCountDown();
if (Math.abs(countDown) > 1) {
totalTime += countDown;
totalCount += 1;
} }
Double temp = Math.floor(totalTime / 3600);
strategyOptTimesVO.setTimes(temp.intValue());
} }
} }
StrategyOptTimesVO strategyOptTimesVO = new StrategyOptTimesVO(); String countUrl = "http://37.12.182.29:15020/decisionPage/MonitorRadarIndicatorsInfo/getRadarCountData";
strategyOptTimesVO.setCount(totalCount); String countResult = OkHttpClientUtil.get(countUrl);
strategyOptTimesVO.setTimes(totalTime / 3600); if (StringUtils.isNotBlank(countResult)) {
StrategyOptCountDTO strategyOptCountDTO = mapper.readValue(countResult, StrategyOptCountDTO.class);
StrategyOptCountDTO.Detail content = strategyOptCountDTO.getContent();
int count = content.getCongestionNum() + content.getEmptyPassNum() + content.getSpilloverNum() + content.getUnbalanceNum();
strategyOptTimesVO.setCount(count);
}
return JsonViewObject.newInstance().success(strategyOptTimesVO); return JsonViewObject.newInstance().success(strategyOptTimesVO);
} }
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>dom4j</groupId> <groupId>dom4j</groupId>
......
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<!--rest参数校验 start --> <!--rest参数校验 start -->
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
......
package net.wanji.common.utils;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.StringUtils;
import okhttp3.*;
import java.io.IOException;
/**
* @ClassName OkHttpClient
* @Description OkHttpClient
* @Author zhouleilei
* @Date 2024/11/3 18:11
*/
@Slf4j
public class OkHttpClientUtil {
public static String xmlPost(String url, String xmlContent) {
if (StringUtils.isBlank(url) || StringUtils.isBlank(xmlContent)) {
return null;
}
// 创建 OkHttpClient 实例
OkHttpClient client = new OkHttpClient();
// 创建请求体
RequestBody body = RequestBody.create(xmlContent, MediaType.get("application/xml; charset=utf-8"));
// 创建请求
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
// 执行请求
try (Response response = client.newCall(request).execute()) {
// 获取响应体
if (response.code() == 200 && response.body() != null) {
String responseString = response.body().string();
return responseString;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String jsonPost(String url, String json) throws Exception {
if (StringUtils.isBlank(url) || StringUtils.isBlank(json)) {
return null;
}
// 创建 OkHttpClient 实例
OkHttpClient client = new OkHttpClient();
// 创建请求体
RequestBody body = RequestBody.create(json, MediaType.get("application/json; charset=utf-8"));
// 创建请求
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
// 执行请求
try (Response response = client.newCall(request).execute()) {
// 获取响应体
if (response.code() == 200 && response.body() != null) {
String responseString = response.body().string();
log.info("远程服务调用成功,url:{}", url);
return responseString;
}
} catch (Exception e) {
log.error("OkHttpClientUtil远程服务url:{}, 调用异常:{}", url, e.getMessage());
throw new Exception();
}
return null;
}
public static String get(String url) throws Exception {
if (StringUtils.isBlank(url)) {
return null;
}
// 创建 OkHttpClient 客户端
OkHttpClient client = new OkHttpClient();
// 构建请求
Request request = new Request.Builder()
.url(url)
.get()
.build();
// 执行请求
try (Response response = client.newCall(request).execute()) {
// 获取响应体
if (response.isSuccessful()) {
String responseString = response.body().string();
log.info("远程服务调用成功,url:{}", url);
return responseString;
}
} catch (Exception e) {
log.error("OkHttpClientUtil远程服务url:{}, 调用异常:{}", url, e.getMessage());
throw new Exception();
}
return null;
}
}
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