Commit 023c4b35 authored by duanruiming's avatar duanruiming

[add] 策略库管理保存添加策略编号唯一校验

parent 0711ba8f
......@@ -9,6 +9,7 @@ import net.wanji.opt.synthesis.pojo.StrategyFactoryEntity;
import net.wanji.opt.synthesis.pojo.vo.StrategyControlVO;
import net.wanji.opt.synthesis.pojo.vo.StrategyFactoryQueryVO;
import net.wanji.opt.synthesis.service.StrategyControlService;
import net.wanji.opt.vo.StrategyNameCrossVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
......@@ -152,6 +153,17 @@ public class StrategyControlController {
return strategyControlService.strategyFactoryList(vo);
}
@ApiOperation(value = "策略管理-路口详情-优化策略查询", notes = "策略管理-路口详情-优化策略查询",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/strategyNameCrossInfo")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = StrategyNameCrossVO.class),
})
public JsonViewObject strategyNameCrossInfo(@RequestParam String crossId) throws Exception {
return strategyControlService.strategyNameCrossInfo(crossId);
}
@ApiOperation(value = "策略库查询列表", notes = "策略库分页查询列表",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
......
......@@ -52,6 +52,7 @@ public class StrategyControlDetailList {
public static class DailyPlanDetail {
private Integer strategy;
private String strategyName;
private String strategyNo;
private List<String> times;
}
}
......
......@@ -37,4 +37,6 @@ public interface StrategyControlService {
JsonViewObject strategyFactorySave(StrategyFactoryEntity entity) throws Exception;
JsonViewObject strategyFactoryDel(List<Integer> ids) throws Exception;
JsonViewObject strategyNameCrossInfo(String crossId) throws Exception;
}
......@@ -28,6 +28,7 @@ import net.wanji.opt.synthesis.pojo.*;
import net.wanji.opt.synthesis.pojo.vo.*;
import net.wanji.opt.synthesis.service.PushStrategyControlService;
import net.wanji.opt.synthesis.service.StrategyControlService;
import net.wanji.opt.vo.StrategyNameCrossVO;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
......@@ -347,7 +348,6 @@ public class StrategyControlServiceImpl implements StrategyControlService {
// 转化成 0 畅通 1失衡 2拥堵 3溢出 4死锁 5空放 6干线拥堵 7干线缓行 8干线畅通
Integer status = baseCrossInfoPO.getRealtimeStatus();
strategyControlDataEntity.setStrategy(status);
strategyControlDataEntity.setOptMethod(Objects.equals(1, status) ? "均衡调控" : "效率提升");
strategyControlDataEntity.setTime(null);
strategyControlDataEntity.setStatus(status);
strategyControlDataEntity.setCrossName(baseCrossInfoPO.getName());
......@@ -1100,4 +1100,98 @@ public class StrategyControlServiceImpl implements StrategyControlService {
}
return jsonViewObject.success("策略库删除成功");
}
@Override
public JsonViewObject strategyNameCrossInfo(String crossId) throws Exception {
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
try {
ObjectMapper instance = JacksonUtils.getInstance();
// 通过当前时间获取当前日计划编号
Integer currentDailyPlanId = 1;
String currentStrategyNo = "";
List<String> strategyNoList = new ArrayList<>();
LambdaQueryWrapper<StrategyPlanInfoEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyPlanInfoEntity::getCrossId, crossId);
Date currentDate = new Date();
queryWrapper.le(StrategyPlanInfoEntity::getStartTime, currentDate);
queryWrapper.ge(StrategyPlanInfoEntity::getEndTime, currentDate);
List<StrategyPlanInfoEntity> planInfoEntities = strategyPlanInfoMapper.selectList(queryWrapper);
for (StrategyPlanInfoEntity planInfoEntity : planInfoEntities) {
String planDetailStr = planInfoEntity.getPlanDetails();
List<StrategyControlDetailList.ExecutePlan.PlanDetail> planDetails = instance.readValue(planDetailStr, new TypeReference<List<StrategyControlDetailList.ExecutePlan.PlanDetail>>() {});
if (!CollectionUtils.isEmpty(planDetails)) {
for (StrategyControlDetailList.ExecutePlan.PlanDetail planDetail : planDetails) {
int week = DateUtil.getWeek(currentDate) == 0 ? 7 : DateUtil.getWeek(currentDate);
List<Integer> weeks = planDetail.getWeeks();
Integer dailyPlanId = planDetail.getDailyPlanId();
if (weeks.contains(week)) {
currentDailyPlanId = dailyPlanId;
}
}
}
}
LambdaQueryWrapper<StrategyDailyPlanInfoEntity> dailyQuery = new LambdaQueryWrapper<>();
dailyQuery.eq(StrategyDailyPlanInfoEntity::getCrossId, crossId);
List<StrategyDailyPlanInfoEntity> dailyEntities = strategyDailyPlanInfoMapper.selectList(dailyQuery);
if (!CollectionUtils.isEmpty(dailyEntities)) {
for (StrategyDailyPlanInfoEntity dailyEntity : dailyEntities) {
Integer dailyPlanId = dailyEntity.getDailyPlanId();
if (Objects.equals(dailyPlanId, currentDailyPlanId)) {
String dailyPlanDetailStr = dailyEntity.getDailyPlanDetails();
List<StrategyControlDetailList.DailyPlan.DailyPlanDetail> dailyPlanDetails = instance.readValue(dailyPlanDetailStr, new TypeReference<List<StrategyControlDetailList.DailyPlan.DailyPlanDetail>>() {});
if (!CollectionUtils.isEmpty(dailyPlanDetails)) {
for (StrategyControlDetailList.DailyPlan.DailyPlanDetail dailyPlanDetail : dailyPlanDetails) {
String strategyNo = dailyPlanDetail.getStrategyNo();
List<String> times = dailyPlanDetail.getTimes();
if (!CollectionUtils.isEmpty(times)) {
String startTime = times.get(0);
String endTime = times.get(1);
if (StringUtils.equals("24:00", endTime)) {
endTime = "23:59";
}
String format = DateUtil.format(currentDate, Constants.DATE_FORMAT.E_DATE_FORMAT_HOUR_MINUTE);
Date currentTime = DateUtil.parse(format, "HH:mm");
Date startHourDate = DateUtil.parse(startTime, "HH:mm");
Date endHourDate = DateUtil.parse(endTime, "HH:mm");
if (currentTime.after(startHourDate) && currentTime.before(endHourDate)) {
currentStrategyNo = strategyNo;
}
strategyNoList.add(strategyNo);
}
}
}
}
}
// 通过策略编号获取策略名称
LambdaQueryWrapper<StrategyFactoryEntity> factoryQuery = new LambdaQueryWrapper<>();
factoryQuery.in(StrategyFactoryEntity::getStrategyNo, strategyNoList);
List<StrategyFactoryEntity> factoryEntities = strategyFactoryMapper.selectList(factoryQuery);
String currentName = "";
List<String> strategyNames = new ArrayList<>();
for (StrategyFactoryEntity factoryEntity : factoryEntities) {
String company = factoryEntity.getCompany();
String strategyName = factoryEntity.getStrategyName();
String method = factoryEntity.getMethod();
String strategyNo = factoryEntity.getStrategyNo();
String name = String.join("-", company, method, strategyName);
strategyNames.add(name);
if (StringUtils.equals(strategyNo, currentStrategyNo)) {
currentName = name;
}
}
StrategyNameCrossVO strategyNameCrossVO = new StrategyNameCrossVO();
strategyNameCrossVO.setCurrentName(currentName);
strategyNameCrossVO.setStrategyNames(strategyNames);
return jsonViewObject.success(strategyNameCrossVO);
}
} catch (Exception e) {
log.error("策略管理-路口详情-优化策略查询, {}", e);
return jsonViewObject.fail("策略管理-路口详情-优化策略查询失败");
}
return jsonViewObject.fail("策略管理-路口详情-优化策略查询失败");
}
}
package net.wanji.opt.vo;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.List;
/**
* @author duanruiming
* @date 2025/02/14 15:11
* @description 策略管理-路口详情-优化策略返回实体
*/
@Data
@ApiModel(value = "StrategyNameCrossVO", description = "策略管理-路口详情-优化策略返回实体")
public class StrategyNameCrossVO {
private String currentName;
private List<String> strategyNames;
}
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