Commit b141f49a authored by zhoushiguang's avatar zhoushiguang

Merge remote-tracking branch 'origin/master'

parents 44072d46 3623304e
package net.wanji.opt.synthesis.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.*;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.synthesis.pojo.StrategyControlDataEntity;
import net.wanji.opt.synthesis.pojo.StrategyControlDetailList;
import net.wanji.opt.synthesis.pojo.StrategyFactoryEntity;
......@@ -53,15 +51,19 @@ public class StrategyControlController {
return strategyControlService.strategyInfoPageList(entity);
}
@ApiOperation(value = "策略控制查询列表", notes = "策略控制查询列表",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossStrategyHistList")
@GetMapping("/crossStrategyHistList")
@ApiOperation(httpMethod="GET",value="策略执行记录历史->路口/干线,时间粒度, 策略成功失败类型", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "strategyType", value = "策略类型 0-路口 1-干线 空-查所有", required = false, dataType = "Integer"),
@ApiImplicitParam(name = "groupType", value = "时间粒度类型 0-1小时 1-1天", required = false, dataType = "Integer", defaultValue = "1"),
@ApiImplicitParam(name = "resultType", value = "时间粒度类型 0-失败 1-成功 空-查所有", required = false, dataType = "Integer"),
})
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyControlDataEntity.class),
@ApiResponse(code = 200, message = "成功", response = GreenwaveHist.class,
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
})
public JsonViewObject crossStrategyHistList() throws Exception {
return strategyControlService.crossStrategyHistList();
public JsonViewObject crossStrategyHistList(Integer strategyType, Integer groupType, Integer resultType) throws Exception {
return strategyControlService.crossStrategyHistList(strategyType, groupType, resultType);
}
......
......@@ -16,7 +16,7 @@ public interface StrategyControlService {
JsonViewObject strategyInfoPageList(StrategyControlDataEntity entity) throws Exception;
JsonViewObject crossStrategyInfoList(Integer type) throws Exception;
JsonViewObject strategyOptTimes() throws Exception;
JsonViewObject crossStrategyHistList() throws Exception;
JsonViewObject crossStrategyHistList(Integer strategyType, Integer groupType, Integer resultType) throws Exception;
JsonViewObject crossOptInfoList(Integer type) throws Exception;
JsonViewObject strategyPlanDetail(String crossId) throws Exception;
......
package net.wanji.opt.synthesis.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.util.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
......@@ -12,6 +9,7 @@ import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.DateStyle;
import net.wanji.common.framework.Constants;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.databus.dao.entity.GreenwaveInfoPO;
import net.wanji.databus.dao.mapper.BaseCrossInfoMapper;
......@@ -34,7 +32,6 @@ import net.wanji.opt.synthesis.pojo.vo.StrategyControlVO;
import net.wanji.opt.synthesis.pojo.vo.StrategyOptTimesVO;
import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService;
import net.wanji.opt.vo.AIOptResultVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
......@@ -138,8 +135,8 @@ public class StrategyControlServiceImpl implements StrategyControlService {
detailData.setBiz_id(dataVO.getBizId());
detailData.setBiz_type(dataVO.getBizType());
detailData.setStrategy(dataVO.getStrategy());
detailData.setSchedule_start(DateUtil.format(dataVO.getScheduleStart(), DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
detailData.setSchedule_end(DateUtil.format(dataVO.getScheduleEnd(), DateStyle.YYYY_MM_DD_HH_MM_SS.getValue()));
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));
List<StrategyControlDataVO.TimeTable> timeTableList = dataVO.getTime();
List<StrategyControlDataReq.Time_table> timeTables = new ArrayList<>(timeTableList.size());
timeTableList.forEach(item -> {
......@@ -185,16 +182,26 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
@Override
public JsonViewObject crossStrategyHistList() throws Exception {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public JsonViewObject crossStrategyHistList(Integer strategyType, Integer groupType, Integer resultType) throws Exception {
List<StrategyControlHistVO> results = new ArrayList<>();
LocalDate currentDate = LocalDate.now();
LocalDateTime midnight = currentDate.atStartOfDay();
try {
// 查询当前绿波历史记录
setGreenOptHist(results, midnight, format);
setCrossOptHist(results, midnight);
} catch (ParseException e) {
if (Objects.isNull(groupType)) {
groupType = 1;
}
LocalDateTime localDateTime = Objects.equals(0, groupType) ? DateUtil.getPlusHour(-1) : DateUtil.getMidNight();
// 查询干线和路口
if (Objects.isNull(strategyType)) {
setGreenOptHist(results, localDateTime, resultType);
setCrossOptHist(results, localDateTime, resultType);
} // 路口
if (Objects.equals(0, strategyType)) {
setCrossOptHist(results, localDateTime, resultType);
}
// 绿波历史记录
if (Objects.equals(1, strategyType)) {
setGreenOptHist(results, localDateTime, resultType);
}
} catch (Exception e) {
log.error("优化策略查询失败:", e);
JsonViewObject.newInstance().fail("优化策略查询失败");
}
......@@ -202,9 +209,15 @@ public class StrategyControlServiceImpl implements StrategyControlService {
return JsonViewObject.newInstance().success(sorted);
}
private void setCrossOptHist(List<StrategyControlHistVO> results, LocalDateTime midnight) {
private void setCrossOptHist(List<StrategyControlHistVO> results, LocalDateTime midnight, Integer resultType) {
LambdaQueryWrapper<StrategyCrossResultEntity> queryWrapper = new LambdaQueryWrapper<>();
if (Objects.nonNull(midnight)) {
queryWrapper.ge(StrategyCrossResultEntity::getIssueTime, midnight);
}
if (Objects.nonNull(resultType)) {
Integer resCode = Objects.equals(1, resultType) ? 200 : 500;
queryWrapper.ge(StrategyCrossResultEntity::getResponseCode, resCode);
}
List<StrategyCrossResultEntity> resultEntities = strategyCrossResultMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(resultEntities)) {
for (StrategyCrossResultEntity resultEntity : resultEntities) {
......@@ -217,7 +230,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
histVO.setStrategy(resultEntity.getCurrentAlgo());
histVO.setStrategyName(StrategyCrossAlgoEnum.getDescByCode(resultEntity.getCurrentAlgo()));
Date issueTime = resultEntity.getIssueTime();
String format = DateUtils.format(issueTime, "yyyy-MM-dd HH:mm:ss");
String format = DateUtil.format(issueTime, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND);
histVO.setOptTime(format);
if (resultEntity.getCurrentAlgo() != 1) {
histVO.setResult(Objects.equals(200, resultEntity.getResponseCode()) ? "成功" : "失败");
......@@ -229,9 +242,15 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
}
private void setGreenOptHist(List<StrategyControlHistVO> results, LocalDateTime midnight, SimpleDateFormat format) throws ParseException {
private void setGreenOptHist(List<StrategyControlHistVO> results, LocalDateTime midnight, Integer resultType) throws ParseException {
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
if (Objects.nonNull(midnight)) {
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, midnight);
}
if (Objects.nonNull(resultType)) {
Integer controlMethod = Objects.equals(1, resultType) ? 1 : 0;
queryWrapper.ge(StrategyGreenOptHistEntity::getControlMethod, controlMethod);
}
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(entities)) {
Map<Integer, GreenwaveInfoPO> greenWaveMap = GreenWaveInfoCache.greenWaveMap;
......@@ -242,7 +261,7 @@ public class StrategyControlServiceImpl implements StrategyControlService {
continue;
}
String controlTime = entity.getControlTime();
Date parse = format.parse(controlTime);
Date parse = DateUtil.parse(controlTime, "yyyy-MM-dd HH:mm:ss");
GreenwaveInfoPO greenwaveInfoPO = greenWaveMap.get(entity.getGreenId());
if (Objects.nonNull(greenwaveInfoPO)) {
histVO.setName(greenwaveInfoPO.getName());
......@@ -389,11 +408,11 @@ public class StrategyControlServiceImpl implements StrategyControlService {
if (StringUtils.equals("24:00", entHour)) {
entHour = "23:59";
}
String format = DateUtil.format(current, "HH:mm");
DateTime currentTime = DateUtil.parse(format, "HH:mm");
DateTime startHourDate = DateUtil.parse(startHour, "HH:mm");
DateTime endHourDate = DateUtil.parse(entHour, "HH:mm");
if (currentTime.isAfter(startHourDate) && currentTime.isBefore(endHourDate)) {
String format = DateUtil.format(current, Constants.DATE_FORMAT.E_DATE_FORMAT_MINUTE);
Date currentTime = DateUtil.parse(format, "HH:mm");
Date startHourDate = DateUtil.parse(startHour, "HH:mm");
Date endHourDate = DateUtil.parse(entHour, "HH:mm");
if (currentTime.after(startHourDate) && currentTime.before(endHourDate)) {
result.setTime(hour);
result.setStatus(1);
} else {
......
......@@ -631,6 +631,7 @@ public final class Constants {
private static final String DATE_FORMAT_SECOND = "yyyy-MM-dd HH:mm:ss";
private static final String DATE_FORMAT_MILLIS = "yyyy-MM-dd HH:mm:ss.SSS";
private static final String DATE_FORMAT_TIME = "HH:mm:ss";
private static final String DATE_FORMAT_HOUR_MINUTE = "HH:mm";
private static final String DATE_FORMAT_WEEKDAY = "EEEE";
public enum DATE_FORMAT {
......@@ -641,6 +642,7 @@ public final class Constants {
E_DATE_FORMAT_SECOND(DATE_FORMAT_SECOND),
E_DATE_FORMAT_MILLIS(DATE_FORMAT_MILLIS),
E_DATE_FORMAT_TIME(DATE_FORMAT_TIME),
E_DATE_FORMAT_HOUR_MINUTE(DATE_FORMAT_HOUR_MINUTE),
E_DATE_FORMAT_WEEKDAY(DATE_FORMAT_WEEKDAY);
private final String strFormat;
......
......@@ -6,10 +6,7 @@ import net.wanji.common.framework.Constants;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.*;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
......@@ -41,15 +38,6 @@ public class DateUtil {
return sdf.format(date);
}
public static void main(String[] args) throws ParseException {
// DateToString(new Date());
// System.out.println(longToDate(1566144240000L));
Random r = new Random();
for(int i=0;i<10;i++){
System.out.println(getId());
}
}
public static String getRandom(int i) {
Random jjj = new Random();
......@@ -561,4 +549,22 @@ public class DateUtil {
localDateTime.toEpochSecond(ZoneOffset.of("+8"));
return localDateTime;
}
/**
* 获取当前日期的yyyy-MM-dd 00:00:00
* @return
*/
public static LocalDateTime getMidNight() {
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime midNight = LocalDateTime.of(currentDate, startTime);
return midNight;
}
public static LocalDateTime getPlusHour(Integer offset) {
LocalDateTime now = LocalDateTime.now();
LocalDateTime localDateTime = now.plusHours(offset);
return localDateTime;
}
}
......@@ -238,7 +238,7 @@ public class CrossDataRealtimePO {
* add 20250107 事件
*/
@ApiModelProperty(value = "事件方向", notes = "")
private Integer direction;
private String direction;
@ApiModelProperty(value = "事件转向", notes = "")
private Integer turn;
private String turn;
}
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