Commit 9c0c62b3 authored by duanruiming's avatar duanruiming

[add] 干线策略推荐相位差列表

parent 4b5539c8
package net.wanji.opt.config; //package net.wanji.opt.config;
//
import org.springframework.beans.factory.annotation.Value; //import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory; //import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; //import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; //import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer; //import org.springframework.data.redis.serializer.StringRedisSerializer;
//
@Configuration //@Configuration
public class RestTemplateConfig { //public class RestTemplateConfig {
//
@Value("${spring.redis.host}") // @Value("${spring.redis.host}")
private String redisHost; // private String redisHost;
//
@Value("${spring.redis.port}") // @Value("${spring.redis.port}")
private int redisPort; // private int redisPort;
//
@Value("${spring.redis.database}") // @Value("${spring.redis.database}")
private int redisDatabase; // private int redisDatabase;
//
@Value("${spring.redis.password}") // @Value("${spring.redis.password}")
private String redisPassword; // private String redisPassword;
//
//
// 默认使用配置的数据库 // // 默认使用配置的数据库
@Bean // @Bean
public RedisConnectionFactory redisConnectionFactory() { // public RedisConnectionFactory redisConnectionFactory() {
LettuceConnectionFactory factory = new LettuceConnectionFactory(redisHost, redisPort); // LettuceConnectionFactory factory = new LettuceConnectionFactory(redisHost, redisPort);
factory.setPassword(redisPassword); // factory.setPassword(redisPassword);
factory.setDatabase(redisDatabase); // factory.setDatabase(redisDatabase);
return factory; // return factory;
} // }
//
@Bean(name = "redisTemplate") // @Bean(name = "redisTemplate")
public RedisTemplate<String, Object> redisTemplate() { // public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new RedisTemplate<>(); // RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory()); // template.setConnectionFactory(redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer()); // template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer()); // template.setValueSerializer(new StringRedisSerializer());
return template; // return template;
} // }
//
// 使用7号数据库 // // 使用7号数据库
@Bean(name = "redis7ConnectionFactory") // @Bean(name = "redis7ConnectionFactory")
public RedisConnectionFactory redis7ConnectionFactory() { // public RedisConnectionFactory redis7ConnectionFactory() {
LettuceConnectionFactory factory = new LettuceConnectionFactory(redisHost, redisPort); // LettuceConnectionFactory factory = new LettuceConnectionFactory(redisHost, redisPort);
factory.setPassword(redisPassword); // factory.setPassword(redisPassword);
factory.setDatabase(7); // factory.setDatabase(7);
return factory; // return factory;
} // }
//
@Bean(name = "redis7Template") // @Bean(name = "redis7Template")
public RedisTemplate<String, Object> redis7Template() { // public RedisTemplate<String, Object> redis7Template() {
RedisTemplate<String, Object> template = new RedisTemplate<>(); // RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redis7ConnectionFactory()); // template.setConnectionFactory(redis7ConnectionFactory());
template.setKeySerializer(new StringRedisSerializer()); // template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer()); // template.setValueSerializer(new StringRedisSerializer());
return template; // return template;
} // }
//
} //}
\ No newline at end of file \ No newline at end of file
...@@ -231,9 +231,27 @@ public class TrendControllerV2 { ...@@ -231,9 +231,27 @@ public class TrendControllerV2 {
try { try {
result = trendServiceV2.optStrategyResultInfo(id); result = trendServiceV2.optStrategyResultInfo(id);
} catch (Exception e) { } catch (Exception e) {
log.error("态势监测-事件告警-历史列表:", e); log.error("态势监测-策略推荐-优化策略:", e);
JsonViewObject.newInstance().success(result); JsonViewObject.newInstance().success(result);
} }
return JsonViewObject.newInstance().success(result); return JsonViewObject.newInstance().success(result);
} }
@ApiOperation(value = "态势监测-策略推荐-绿波优化相位差", notes = "态势监测-策略推荐-绿波优化相位差",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/optStrategyCrossOffsetList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = OptMonitoringVO.class),
})
public JsonViewObject optStrategyCrossOffsetList(Integer id) throws Exception {
GreenOptCrossOffsetVO greenOptCrossOffsetVO = new GreenOptCrossOffsetVO();
try {
greenOptCrossOffsetVO = trendServiceV2.optStrategyCrossOffsetList(id);
} catch (Exception e) {
log.error("态势监测-策略推荐-绿波优化相位差:", e);
JsonViewObject.newInstance().success(greenOptCrossOffsetVO);
}
return JsonViewObject.newInstance().success(greenOptCrossOffsetVO);
}
} }
\ No newline at end of file
...@@ -31,4 +31,6 @@ public interface TrendServiceV2 { ...@@ -31,4 +31,6 @@ public interface TrendServiceV2 {
String optStrategyResultInfo(String id) throws Exception; String optStrategyResultInfo(String id) throws Exception;
GreenOptCrossOffsetVO optStrategyCrossOffsetList(Integer id) throws Exception;
} }
\ No newline at end of file
package net.wanji.opt.servicev2.implv2; package net.wanji.opt.servicev2.implv2;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.DateUtil; import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.databus.dao.entity.BaseCrossSchemePO;
import net.wanji.databus.dao.entity.GreenwaveCrossPO;
import net.wanji.databus.dao.entity.GreenwaveHistPO; import net.wanji.databus.dao.entity.GreenwaveHistPO;
import net.wanji.databus.dao.mapper.CrossDataHistMapper; import net.wanji.databus.dao.mapper.*;
import net.wanji.databus.dao.mapper.GreenwaveHistMapper;
import net.wanji.databus.po.CrossDataHistPO; import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.vo.LightsStatusVO2;
import net.wanji.opt.common.RedisUtils;
import net.wanji.opt.common.enums.EventInfoTypeEnum; import net.wanji.opt.common.enums.EventInfoTypeEnum;
import net.wanji.opt.common.enums.GreenBeltDirEnum; import net.wanji.opt.common.enums.GreenBeltDirEnum;
import net.wanji.opt.dao.mapper.GreenWaveRealTimeMapperV2Mapper; import net.wanji.opt.dao.mapper.GreenWaveRealTimeMapperV2Mapper;
...@@ -22,7 +28,6 @@ import net.wanji.opt.vo2.dto.CrossLastOptResultDTO; ...@@ -22,7 +28,6 @@ import net.wanji.opt.vo2.dto.CrossLastOptResultDTO;
import net.wanji.opt.vo2.dto.GreenLastOptResultDTO; import net.wanji.opt.vo2.dto.GreenLastOptResultDTO;
import net.wanji.opt.vo2.dto.GreenOptDTO; import net.wanji.opt.vo2.dto.GreenOptDTO;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -52,12 +57,18 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -52,12 +57,18 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
private GreenwaveHistMapper greenwaveHistMapper; private GreenwaveHistMapper greenwaveHistMapper;
@Resource @Resource
private StrategyGreenOptHistMapper greenOptHistMapper; private StrategyGreenOptHistMapper greenOptHistMapper;
@Resource
private GreenwaveCrossMapper greenwaveCrossMapper;
@Resource
private StrategyGreenOptHistMapper strategyGreenOptHistMapper;
@Resource
private RedisUtils redisUtil;
@Resource
private BaseCrossSchemeMapper baseCrossSchemeMapper;
private static List<OptMonitoringVO> greenListCache = new ArrayList<>(10); private static List<OptMonitoringVO> greenListCache = new ArrayList<>(10);
private static List<OptMonitoringVO> crossListCache = new ArrayList<>(80); private static List<OptMonitoringVO> crossListCache = new ArrayList<>(80);
@Autowired
private StrategyGreenOptHistMapper strategyGreenOptHistMapper;
@Override @Override
public List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate() { public List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate() {
...@@ -75,7 +86,7 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -75,7 +86,7 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
} }
} }
return crossGreenStatusTimeRateVOS; return crossGreenStatusTimeRateVOS;
} }
@Override @Override
...@@ -262,7 +273,7 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -262,7 +273,7 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
greenList = greenOptMonitoringList(); greenList = greenOptMonitoringList();
} }
if (!CollectionUtils.isEmpty(crossListCache)) { if (!CollectionUtils.isEmpty(crossListCache)) {
crossList = crossListCache; crossList = crossListCache;
} else { } else {
crossList = crossOptMonitoringList(); crossList = crossOptMonitoringList();
} }
...@@ -287,10 +298,10 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -287,10 +298,10 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
private static void setCountDurationRate(List<StatisticsEventTypeCountTimeVO> currentList, List<StatisticsEventTypeCountTimeVO> lastDayList) { private static void setCountDurationRate(List<StatisticsEventTypeCountTimeVO> currentList, List<StatisticsEventTypeCountTimeVO> lastDayList) {
currentList.forEach(result -> { currentList.forEach(result -> {
for (StatisticsEventTypeCountTimeVO last : lastDayList) { for (StatisticsEventTypeCountTimeVO last : lastDayList) {
String id = result.getId(); String id = result.getId();
String lastId = last.getId(); String lastId = last.getId();
if (StringUtils.endsWithIgnoreCase(id, lastId)) { if (StringUtils.endsWithIgnoreCase(id, lastId)) {
if (last.getCount() == 0 || last.getDuration() == 0) { if (last.getCount() == 0 || last.getDuration() == 0) {
continue; continue;
} }
...@@ -380,4 +391,48 @@ public class TrendServiceV2Impl implements TrendServiceV2 { ...@@ -380,4 +391,48 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
} }
return sb.toString(); return sb.toString();
} }
@Override
public GreenOptCrossOffsetVO optStrategyCrossOffsetList(Integer id) throws Exception {
GreenOptCrossOffsetVO greenOptCrossOffsetVO = new GreenOptCrossOffsetVO();
try {
List<GreenOptCrossOffsetVO.CrossOffsetDetail> oriOffsetDetails = new ArrayList<>();
List<GreenOptCrossOffsetVO.CrossOffsetDetail> curOffsetDetails = new ArrayList<>();
ObjectMapper mapper = JacksonUtils.getInstance();
List<GreenwaveCrossPO> greenwaveCrossPOS = greenwaveCrossMapper.selectByGreenwaveId(id);
for (GreenwaveCrossPO greenwaveCrossPO : greenwaveCrossPOS) {
String crossId = greenwaveCrossPO.getCrossId();
Object lightStr = redisUtil.getHash("utc_light_status", crossId);
if (StringUtils.isEmpty(lightStr)) {
continue;
}
List<LightsStatusVO2> lightsStatusVO2s = mapper.readValue(String.valueOf(lightStr), new TypeReference<List<LightsStatusVO2>>() {});
String schemeId = lightsStatusVO2s.get(0).getSchemeId();
Integer schemeNo = Integer.valueOf(schemeId);
GreenOptCrossOffsetVO.CrossOffsetDetail crossOffsetDetail = new GreenOptCrossOffsetVO.CrossOffsetDetail();
GreenOptCrossOffsetVO.CrossOffsetDetail detail = getOriOffsetDetail(crossId, schemeNo, crossOffsetDetail);
oriOffsetDetails.add(detail);
curOffsetDetails.add(detail);
}
greenOptCrossOffsetVO.setOriCrossOffsets(oriOffsetDetails);
greenOptCrossOffsetVO.setCurCrossOffsets(curOffsetDetails);
} catch (Exception e) {
log.error("态势监测-策略推荐-绿波优化相位差查询失败:{}", e);
throw new RuntimeException(e);
}
return greenOptCrossOffsetVO;
}
private GreenOptCrossOffsetVO.CrossOffsetDetail getOriOffsetDetail(String crossId, Integer schemeNo, GreenOptCrossOffsetVO.CrossOffsetDetail crossOffsetDetail) {
BaseCrossSchemePO baseCrossSchemePO = baseCrossSchemeMapper.selectByCrossIdAndSchemeNo(crossId, schemeNo);
crossOffsetDetail.setOffset(0);
if (Objects.nonNull(baseCrossSchemePO)) {
Integer offset = baseCrossSchemePO.getOffset();
crossOffsetDetail.setCrossId(crossId);
crossOffsetDetail.setSchemeNo(schemeNo);
crossOffsetDetail.setOffset(offset);
}
return crossOffsetDetail;
}
} }
\ No newline at end of file
package net.wanji.opt.vo2;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author duanruiming
* @date 2025/03/18 10:11
*/
@Data
@ApiModel(value = "GreenOptCrossOffsetVO", description = "态势监测-策略推荐-绿波优化相位差实体")
public class GreenOptCrossOffsetVO {
@ApiModelProperty(value = "原始路口相位差列表")
private List<CrossOffsetDetail> oriCrossOffsets;
@ApiModelProperty(value = "当前路口相位差列表")
private List<CrossOffsetDetail> curCrossOffsets;
@Data
@ApiModel(value = "CrossOffsetDetail", description = "")
public static class CrossOffsetDetail {
@ApiModelProperty(value = "路口编号")
private String crossId;
@ApiModelProperty(value = "方案相位差")
private Integer offset;
@ApiModelProperty(value = "方案号")
private Integer schemeNo;
}
}
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