Commit 7f5600ff authored by duanruiming's avatar duanruiming

[add] 代码逻辑优化

parent aa0d0e51
...@@ -224,7 +224,7 @@ public class TrendServiceImpl implements TrendService { ...@@ -224,7 +224,7 @@ public class TrendServiceImpl implements TrendService {
wDirVo.setInfoStatus(greenwaveListVO.getInfoStatus()); wDirVo.setInfoStatus(greenwaveListVO.getInfoStatus());
} }
wDirVo.setSpeed(speed / 2); wDirVo.setSpeed(speed / 2);
wDirVo.setStopTimes(stopTimes / 2); wDirVo.setStopTimes((int) (stopTimes / 2));
wDirVo.setTrafficIndex(trafficIndex / 2 < 1 ? 1 : trafficIndex / 2); wDirVo.setTrafficIndex(trafficIndex / 2 < 1 ? 1 : trafficIndex / 2);
wDirVo.setTravelTime(travelTime / 2); wDirVo.setTravelTime(travelTime / 2);
greenwaveListVOList.add(wDirVo); greenwaveListVOList.add(wDirVo);
......
...@@ -5,14 +5,15 @@ import io.swagger.annotations.ApiOperation; ...@@ -5,14 +5,15 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.dao.entity.GreenwaveRealtimePO;
import net.wanji.opt.synthesis.service.impl.StrategyGreenBeltServiceImpl; import net.wanji.opt.synthesis.service.impl.StrategyGreenBeltServiceImpl;
import net.wanji.opt.vo.GreenBeltChartVO; import net.wanji.opt.vo.*;
import net.wanji.opt.vo.GreenBeltInfoVO;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author duanruiming * @author duanruiming
...@@ -38,4 +39,27 @@ public class StrategyGreenBeltController { ...@@ -38,4 +39,27 @@ public class StrategyGreenBeltController {
return JsonViewObject.newInstance().success(greenBeltChartVO); return JsonViewObject.newInstance().success(greenBeltChartVO);
} }
@ApiOperation(value = "绿波停车次数排队长度", notes = "绿波停车次数排队长度", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/greenBeltStopTimeQueueLength")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = HotspotCrossVO.class),
})
public JsonViewObject greenBeltStopTimeQueueLength(Integer greenId) throws Exception {
List<GreenBeltStopTimesQueueLengthVO> results = strategyGreenBeltService.greenBeltStopTimeQueueLength(greenId);
return JsonViewObject.newInstance().success(results);
}
@ApiOperation(value = "绿波子区指标", notes = "绿波子区指标", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/greenBeltAreaIndex")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = HotspotCrossVO.class),
})
public JsonViewObject greenBeltAreaIndex(Integer greenId) throws Exception {
GreenwaveRealtimePO result = strategyGreenBeltService.greenBeltAreaIndex(greenId);
return JsonViewObject.newInstance().success(result);
}
} }
package net.wanji.opt.synthesis.service; package net.wanji.opt.synthesis.service;
import net.wanji.databus.dao.entity.GreenwaveRealtimePO;
import net.wanji.opt.vo.GreenBeltChartVO; import net.wanji.opt.vo.GreenBeltChartVO;
import net.wanji.opt.vo.GreenBeltStopTimesQueueLengthVO;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author duanruiming * @author duanruiming
...@@ -11,4 +14,6 @@ import java.util.Date; ...@@ -11,4 +14,6 @@ import java.util.Date;
public interface StrategyGreenBeltService { public interface StrategyGreenBeltService {
GreenBeltChartVO selectChart(Integer greenId, Date queryDate); GreenBeltChartVO selectChart(Integer greenId, Date queryDate);
List<GreenBeltStopTimesQueueLengthVO> greenBeltStopTimeQueueLength(Integer greenId);
GreenwaveRealtimePO greenBeltAreaIndex(Integer greenId);
} }
package net.wanji.opt.synthesis.service.impl; package net.wanji.opt.synthesis.service.impl;
import com.alibaba.excel.util.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.JacksonUtils; import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.databus.dao.entity.GreenwaveHistPO;
import net.wanji.databus.dao.entity.GreenwaveRealtimePO;
import net.wanji.databus.dao.mapper.GreenwaveHistMapper;
import net.wanji.databus.dao.mapper.GreenwaveRealtimeMapper;
import net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper; import net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper;
import net.wanji.opt.po.StrategyGreenOptHistEntity; import net.wanji.opt.po.StrategyGreenOptHistEntity;
import net.wanji.opt.synthesis.service.StrategyGreenBeltService; import net.wanji.opt.synthesis.service.StrategyGreenBeltService;
import net.wanji.opt.vo.GreenBeltChartVO; import net.wanji.opt.vo.GreenBeltChartVO;
import net.wanji.opt.vo.GreenBeltInfoVO; import net.wanji.opt.vo.GreenBeltInfoVO;
import net.wanji.opt.vo.GreenBeltStopTimesQueueLengthVO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
/** /**
* @author duanruiming * @author duanruiming
...@@ -29,6 +35,42 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService { ...@@ -29,6 +35,42 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService {
@Resource @Resource
StrategyGreenOptHistMapper strategyGreenOptHistMapper; StrategyGreenOptHistMapper strategyGreenOptHistMapper;
@Resource
GreenwaveHistMapper greenwaveHistMapper;
@Resource
GreenwaveRealtimeMapper greenwaveRealtimeMapper;
@Override
public GreenwaveRealtimePO greenBeltAreaIndex(Integer greenId) {
GreenwaveRealtimePO greenwaveRealtimePO = greenwaveRealtimeMapper.selectById(greenId);
return greenwaveRealtimePO;
}
@Override
public List<GreenBeltStopTimesQueueLengthVO> greenBeltStopTimeQueueLength(Integer greenId) {
long currentTimeMillis = System.currentTimeMillis();
LambdaQueryWrapper<GreenwaveHistPO> queryWrapper = new LambdaQueryWrapper();
queryWrapper.eq(GreenwaveHistPO::getGreenId, greenId);
// 查询两个小时之前的
Integer startTime = (int) (currentTimeMillis / 1000) - 3600 * 2;
queryWrapper.ge(GreenwaveHistPO::getStartTime, new Date(startTime * 1000L));
List<GreenwaveHistPO> greenwaveHistPOS = greenwaveHistMapper.selectList(queryWrapper);
List<GreenBeltStopTimesQueueLengthVO> results = new ArrayList<>();
if (!CollectionUtils.isEmpty(greenwaveHistPOS)) {
for (GreenwaveHistPO greenwaveHistPO : greenwaveHistPOS) {
GreenBeltStopTimesQueueLengthVO vo = new GreenBeltStopTimesQueueLengthVO();
vo.setGreenId(greenwaveHistPO.getGreenId());
vo.setTimeStamp(greenwaveHistPO.getStartTime());
vo.setHourMinute(DateUtils.format(greenwaveHistPO.getStartTime(), "HH:mm"));
vo.setStopTimes(greenwaveHistPO.getStopTimes());
vo.setCordQueueRatio(greenwaveHistPO.getCordQueueRatio() * 100);
results.add(vo);
}
}
List<GreenBeltStopTimesQueueLengthVO> distincts = results.stream().distinct().collect(Collectors.toList());
return distincts;
}
@Override @Override
public GreenBeltChartVO selectChart(Integer greenId, Date queryDate) { public GreenBeltChartVO selectChart(Integer greenId, Date queryDate) {
......
package net.wanji.opt.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/12/03 13:58
*/
@Data
@ApiModel(value = "重点路口监测实体", description = "重点路口监测实体")
public class GreenBeltStopTimesQueueLengthVO {
@ApiModelProperty("绿波编号")
private Integer greenId;
@ApiModelProperty("时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date timeStamp;
@ApiModelProperty("时间分钟")
private String hourMinute;
@ApiModelProperty("绿波方向")
private String roadDirection;
@ApiModelProperty("停车次数")
private Double stopTimes;
@ApiModelProperty("空间占比")
private Double cordQueueRatio;
}
...@@ -13,6 +13,7 @@ import net.wanji.databus.po.CrossInfoPO; ...@@ -13,6 +13,7 @@ import net.wanji.databus.po.CrossInfoPO;
import net.wanji.databus.po.ManufacturerInfoPO; import net.wanji.databus.po.ManufacturerInfoPO;
import net.wanji.databus.vo.LightsStatusVO; import net.wanji.databus.vo.LightsStatusVO;
import net.wanji.databus.vo.LightsStatusVO2; import net.wanji.databus.vo.LightsStatusVO2;
import net.wanji.feign.service.EHualuFeignClients;
import net.wanji.feign.service.UtcDTFeignClients; import net.wanji.feign.service.UtcDTFeignClients;
import net.wanji.feign.service.UtcHisenseFeignClients; import net.wanji.feign.service.UtcHisenseFeignClients;
import net.wanji.utc.common.constant.Constants; import net.wanji.utc.common.constant.Constants;
...@@ -78,6 +79,9 @@ public class SignalStatusTask { ...@@ -78,6 +79,9 @@ public class SignalStatusTask {
@Qualifier("net.wanji.feign.service.UtcHisenseFeignClients") @Qualifier("net.wanji.feign.service.UtcHisenseFeignClients")
@Autowired @Autowired
private UtcHisenseFeignClients utcHisenseFeignClients; private UtcHisenseFeignClients utcHisenseFeignClients;
@Qualifier("net.wanji.feign.service.EHualuFeignClients")
@Autowired
private EHualuFeignClients eHualuFeignClients;
private static final ConcurrentHashMap<String, List<LightsStatusVO2>> produceListMap = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, List<LightsStatusVO2>> produceListMap = new ConcurrentHashMap<>();
...@@ -174,6 +178,11 @@ public class SignalStatusTask { ...@@ -174,6 +178,11 @@ public class SignalStatusTask {
return mapper.convertValue(jsonViewObject.getContent(), new TypeReference<List<LightsStatusVO>>() { return mapper.convertValue(jsonViewObject.getContent(), new TypeReference<List<LightsStatusVO>>() {
}); });
} }
if (StringUtils.endsWithIgnoreCase(BasicEnum.ManufacturerEnum.EHULU.getCode(), manufacturerInfoPO.getCode())) {
JsonViewObject jsonViewObject = eHualuFeignClients.lightStatus(crossId);
return mapper.convertValue(jsonViewObject.getContent(), new TypeReference<List<LightsStatusVO>>() {
});
}
if (StringUtils.endsWithIgnoreCase("STATIC", manufacturerInfoPO.getCode())) { if (StringUtils.endsWithIgnoreCase("STATIC", manufacturerInfoPO.getCode())) {
LightsStatusVO lightsStatusVO = SignalStatus4StaticSchemeTask.currentCrossLightStatusCache.get(crossId); LightsStatusVO lightsStatusVO = SignalStatus4StaticSchemeTask.currentCrossLightStatusCache.get(crossId);
List<LightsStatusVO> lightsStatusVOS = new ArrayList<>(); List<LightsStatusVO> lightsStatusVOS = new ArrayList<>();
...@@ -198,6 +207,9 @@ public class SignalStatusTask { ...@@ -198,6 +207,9 @@ public class SignalStatusTask {
Map<String, Object> dirLampGroupMap = lightsStatusVO.getDirLampGroupMap(); Map<String, Object> dirLampGroupMap = lightsStatusVO.getDirLampGroupMap();
List<LightsStatusVO2.DirInfo> dirList = new ArrayList<>(); List<LightsStatusVO2.DirInfo> dirList = new ArrayList<>();
Map<String, Object> phaseMap = lightsStatusVO.getPhaseMap(); Map<String, Object> phaseMap = lightsStatusVO.getPhaseMap();
if (Objects.isNull(phaseMap) || phaseMap.isEmpty()) {
continue;
}
for (Map.Entry<String, Object> groupEntry : dirLampGroupMap.entrySet()) { for (Map.Entry<String, Object> groupEntry : dirLampGroupMap.entrySet()) {
LightsStatusVO2.DirInfo dirInfo = new LightsStatusVO2.DirInfo(); LightsStatusVO2.DirInfo dirInfo = new LightsStatusVO2.DirInfo();
String dir = groupEntry.getKey(); String dir = groupEntry.getKey();
......
...@@ -35,6 +35,8 @@ public class CrossSchedulesPO { ...@@ -35,6 +35,8 @@ public class CrossSchedulesPO {
/** 星期:1周一;2周二,3周三,4周四,5周五,6周六,7周日,0特殊日期 */ /** 星期:1周一;2周二,3周三,4周四,5周五,6周六,7周日,0特殊日期 */
@ApiModelProperty(value = "星期:1周一",notes = "2周二,3周三,4周四,5周五,6周六,7周日,0特殊日期") @ApiModelProperty(value = "星期:1周一",notes = "2周二,3周三,4周四,5周五,6周六,7周日,0特殊日期")
private Integer week ; private Integer week ;
@ApiModelProperty(value = "", notes = "预留,字符串形式星期")
private String weeks;
/** 特殊日期 */ /** 特殊日期 */
@ApiModelProperty(value = "特殊日期",notes = "") @ApiModelProperty(value = "特殊日期",notes = "")
private Date specialDate ; private Date specialDate ;
......
...@@ -11,14 +11,18 @@ ...@@ -11,14 +11,18 @@
<result property="specialDate" column="special_date"/> <result property="specialDate" column="special_date"/>
<result property="gmtCreate" column="gmt_create"/> <result property="gmtCreate" column="gmt_create"/>
<result property="gmtModified" column="gmt_modified"/> <result property="gmtModified" column="gmt_modified"/>
<result property="months" column="months"/>
<result property="weeks" column="weeks"/>
<result property="days" column="days"/>
</resultMap> </resultMap>
<!-- 批量新增数据 --> <!-- 批量新增数据 -->
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true"> <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_cross_schedules(id,schedule_no,name,cross_id,plan_id,week,special_date) insert into t_cross_schedules(id,schedule_no,name,cross_id,plan_id,week,special_date,months,weeks,days)
values values
<foreach collection="entities" item="entity" separator=","> <foreach collection="entities" item="entity" separator=",">
(#{entity.id},#{entity.scheduleNo},#{entity.name},#{entity.crossId},#{entity.planId},#{entity.week},#{entity.specialDate}) (#{entity.id},#{entity.scheduleNo},#{entity.name},#{entity.crossId},#{entity.planId},#{entity.week},
#{entity.specialDate},#{entity.months},#{entity.weeks},#{entity.days})
</foreach> </foreach>
</insert> </insert>
...@@ -29,7 +33,7 @@ ...@@ -29,7 +33,7 @@
<select id="selectByCrossIds" resultMap="BaseResultMap"> <select id="selectByCrossIds" resultMap="BaseResultMap">
select select
id,schedule_no,name,cross_id,plan_id,week,special_date,gmt_create,gmt_modified id,schedule_no,name,cross_id,plan_id,week,special_date,gmt_create,gmt_modified,months,weeks,days
from t_cross_schedules from t_cross_schedules
where cross_id in where cross_id in
<foreach collection="crossIds" item="crossId" separator="," open="(" close=")"> <foreach collection="crossIds" item="crossId" separator="," open="(" close=")">
......
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