Commit f2972a92 authored by duanruiming's avatar duanruiming

[update] 上载调度日计划转换

parent 6d4faa14
package net.wanji.com.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
/**
* @author duanruiming
* @date 2023/06/19 10:07
*/
@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public enum ControlModelEnum {
FIXED_CYCLE(1, "21", "定周期"),
GREEN_WAVE(2, "13", "绿波协调"),
YELLOW_CONTROL(3, "31", "黄闪"),
RED_CONTROL(4, "32", "全红"),
CLOSED_CONTROL(5, "33", "关灯"),
SELF_CONTROL(6, "14", "单点自适应 -> 中心自适应"),
FULL_INDUCTION(7, "22", "全感应 -> 本地感应"),
HALF_INDUCTION(8, "", "半感应");
private Integer wjControl;
private String dtControlHex;
private String message;
public static Integer getWjControlMode(String dtControlHex) {
for (ControlModelEnum value : ControlModelEnum.values()) {
if (StringUtils.equals(dtControlHex, value.getDtControlHex())) {
return value.getWjControl();
}
}
return null;
}
}
...@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.List;
/** /**
* 静态信息接口 * 静态信息接口
...@@ -47,8 +48,7 @@ public class StaticInfoController { ...@@ -47,8 +48,7 @@ public class StaticInfoController {
}) })
public JsonViewObject schemePhaseLights(@RequestBody @Validated SchemePhaseLightsDTO schemePhaseLightsDTO) throws Exception { public JsonViewObject schemePhaseLights(@RequestBody @Validated SchemePhaseLightsDTO schemePhaseLightsDTO) throws Exception {
SchemePhaseLightsVO schemePhaseLightsVO = staticInfoService.schemePhaseLights(schemePhaseLightsDTO); SchemePhaseLightsVO schemePhaseLightsVO = staticInfoService.schemePhaseLights(schemePhaseLightsDTO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); return JsonViewObject.newInstance().success(schemePhaseLightsVO);
return jsonViewObject.success(schemePhaseLightsVO);
} }
@AspectLog(description = "计划数据-计划信息、时段信息", operationType = BaseEnum.OperationTypeEnum.QUERY) @AspectLog(description = "计划数据-计划信息、时段信息", operationType = BaseEnum.OperationTypeEnum.QUERY)
...@@ -60,11 +60,8 @@ public class StaticInfoController { ...@@ -60,11 +60,8 @@ public class StaticInfoController {
@ApiResponse(code = 200, message = "OK", response = PlanSectionVO.class) @ApiResponse(code = 200, message = "OK", response = PlanSectionVO.class)
}) })
public JsonViewObject planSection(@RequestBody @Validated PlanSectionDTO planSectionDTO) throws Exception { public JsonViewObject planSection(@RequestBody @Validated PlanSectionDTO planSectionDTO) throws Exception {
// 命令调用 List<PlanSectionVO> planSectionVOS = staticInfoService.planSection(planSectionDTO);
staticInfoService.planSection(planSectionDTO); return JsonViewObject.newInstance().success(planSectionVOS);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(null);
} }
@AspectLog(description = "时间表数据", operationType = BaseEnum.OperationTypeEnum.QUERY) @AspectLog(description = "时间表数据", operationType = BaseEnum.OperationTypeEnum.QUERY)
...@@ -76,13 +73,7 @@ public class StaticInfoController { ...@@ -76,13 +73,7 @@ public class StaticInfoController {
@ApiResponse(code = 200, message = "OK", response = CrossSchedulesPO.class) @ApiResponse(code = 200, message = "OK", response = CrossSchedulesPO.class)
}) })
public JsonViewObject crossSchedules(@RequestBody @Validated CrossSchedulesDTO crossSchedulesDTO) throws Exception { public JsonViewObject crossSchedules(@RequestBody @Validated CrossSchedulesDTO crossSchedulesDTO) throws Exception {
// 命令调用 List<CrossSchedulesPO> crossSchedulesPOS = staticInfoService.crossSchedules(crossSchedulesDTO);
staticInfoService.crossSchedules(crossSchedulesDTO); return JsonViewObject.newInstance().success(crossSchedulesPOS);
// 构造返回值
// List<String> crossIdList = crossSchedulesDTO.getCrossIdList();
// List<CrossSchedulesPO> crossSchedulesPOList = staticInfoService.buildCrossSchedulesResponse(crossIdList);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(null);
} }
} }
...@@ -5,11 +5,14 @@ import lombok.RequiredArgsConstructor; ...@@ -5,11 +5,14 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.com.cache.CrossInfoCache; import net.wanji.com.cache.CrossInfoCache;
import net.wanji.com.common.constants.Constants; import net.wanji.com.common.constants.Constants;
import net.wanji.com.common.enums.ControlModelEnum;
import net.wanji.com.netty.NettyClient; import net.wanji.com.netty.NettyClient;
import net.wanji.com.pojo.dtconvert.*; import net.wanji.com.pojo.dtconvert.*;
import net.wanji.com.pojo.netty.MessageResultPojo; import net.wanji.com.pojo.netty.MessageResultPojo;
import net.wanji.com.service.controller.StaticInfoService; import net.wanji.com.service.controller.StaticInfoService;
import net.wanji.common.enums.BaseEnum; import net.wanji.common.enums.BaseEnum;
import net.wanji.common.enums.DateStyle;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.databus.dao.entity.*; import net.wanji.databus.dao.entity.*;
import net.wanji.databus.dto.CrossInfoDTO; import net.wanji.databus.dto.CrossInfoDTO;
import net.wanji.databus.dto.CrossSchedulesDTO; import net.wanji.databus.dto.CrossSchedulesDTO;
...@@ -22,6 +25,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -22,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -436,7 +440,46 @@ public class DTStaticInfoServiceImpl implements StaticInfoService { ...@@ -436,7 +440,46 @@ public class DTStaticInfoServiceImpl implements StaticInfoService {
String crossId = planSectionDTO.getCrossId(); String crossId = planSectionDTO.getCrossId();
CrossInfoPO crossInfoPO = crossInfoCache.getCrossInfoCache().get(crossId); CrossInfoPO crossInfoPO = crossInfoCache.getCrossInfoCache().get(crossId);
List<DailyPlanInfoPojo> dailyPlanInfoPojos = getDailyPlanInfo(crossInfoPO); List<DailyPlanInfoPojo> dailyPlanInfoPojos = getDailyPlanInfo(crossInfoPO);
return null; return getPlanSectionVos(crossId, dailyPlanInfoPojos);
}
private static List<PlanSectionVO> getPlanSectionVos(String crossId, List<DailyPlanInfoPojo> dailyPlanInfoPojos) {
List<PlanSectionVO> planSectionVOS = new ArrayList<>();
for (DailyPlanInfoPojo dailyPlanInfoPojo : dailyPlanInfoPojos) {
PlanSectionVO planSectionVO = new PlanSectionVO();
Integer dailyPlanId = dailyPlanInfoPojo.getDailyPlanId();
List<CrossPlanPO> crossPlanPOList = new ArrayList<>();
CrossPlanPO crossPlanPO = new CrossPlanPO();
crossPlanPO.setPlanNo(String.valueOf(dailyPlanId));
crossPlanPO.setName(StringUtils.join("计划", dailyPlanId));
crossPlanPO.setCrossId(crossId);
crossPlanPOList.add(crossPlanPO);
planSectionVO.setCrossPlanPOList(crossPlanPOList);
List<String> startTimeChain = dailyPlanInfoPojo.getStartTimeChain();
if (!CollectionUtils.isEmpty(startTimeChain)) {
List<CrossSectionPO> crossSectionPOList = new ArrayList<>();
for (int i = 0; i < startTimeChain.size(); i++) {
CrossSectionPO crossSectionPO = new CrossSectionPO();
crossSectionPO.setSectionNo(String.valueOf(i + 1));
crossSectionPO.setStartTime(startTimeChain.get(i));
if (i + 1 < startTimeChain.size()) {
crossSectionPO.setEndTime(startTimeChain.get(i + 1));
} else {
crossSectionPO.setEndTime(startTimeChain.get(0));
}
crossSectionPO.setCrossId(crossId);
crossSectionPO.setPlanId(dailyPlanId);
crossSectionPO.setSchemeId(dailyPlanInfoPojo.getSchemeIdChain().get(i));
crossSectionPO.setControlMode(ControlModelEnum.getWjControlMode(HexUtil.toHex(dailyPlanInfoPojo.getControlModelChain().get(i))));
crossSectionPOList.add(crossSectionPO);
}
planSectionVO.setCrossSectionPOList(crossSectionPOList);
planSectionVOS.add(planSectionVO);
}
}
return planSectionVOS;
} }
private List<DailyPlanInfoPojo> getDailyPlanInfo(CrossInfoPO crossInfoPO) { private List<DailyPlanInfoPojo> getDailyPlanInfo(CrossInfoPO crossInfoPO) {
...@@ -523,7 +566,41 @@ public class DTStaticInfoServiceImpl implements StaticInfoService { ...@@ -523,7 +566,41 @@ public class DTStaticInfoServiceImpl implements StaticInfoService {
String scheduleHex = Constants.buildMessage(message); String scheduleHex = Constants.buildMessage(message);
MessageResultPojo resultPojo = NettyClient.sendMessage(crossInfoPO.getIp(), crossInfoPO.getPort(), scheduleHex, scheduleSign, 300); MessageResultPojo resultPojo = NettyClient.sendMessage(crossInfoPO.getIp(), crossInfoPO.getPort(), scheduleHex, scheduleSign, 300);
List<ScheduleInfoPojo> scheduleInfoPojos = getSchedulePojos(resultPojo); List<ScheduleInfoPojo> scheduleInfoPojos = getSchedulePojos(resultPojo);
return null; return getCrossSchedulesPOs(crossId, scheduleInfoPojos);
}
private List<CrossSchedulesPO> getCrossSchedulesPOs(String crossId, List<ScheduleInfoPojo> scheduleInfoPojos) throws Exception{
List<CrossSchedulesPO> crossSchedulesPOS = new ArrayList<>(scheduleInfoPojos.size());
for (ScheduleInfoPojo scheduleInfoPojo : scheduleInfoPojos) {
List<Integer> week = scheduleInfoPojo.getWeek();
for (Integer weekday : week) {
CrossSchedulesPO crossSchedulesPO = new CrossSchedulesPO();
crossSchedulesPO.setScheduleNo(scheduleInfoPojo.getScheduleId());
crossSchedulesPO.setName(StringUtils.join("调度", scheduleInfoPojo.getScheduleId()));
crossSchedulesPO.setCrossId(crossId);
crossSchedulesPO.setPlanId(scheduleInfoPojo.getDailyPlanId());
crossSchedulesPO.setWeek(weekday);
crossSchedulesPOS.add(crossSchedulesPO);
}
if (week.size() != 7) {
List<Integer> month = scheduleInfoPojo.getMonth();
for (Integer currentMonth : month) {
LocalDate currentDate = LocalDate.now();
String currentYear = currentDate.toString().substring(0, 4);
for (Integer day : scheduleInfoPojo.getDay()) {
CrossSchedulesPO crossSchedulesPO = new CrossSchedulesPO();
crossSchedulesPO.setScheduleNo(scheduleInfoPojo.getScheduleId());
crossSchedulesPO.setName(StringUtils.join("调度", scheduleInfoPojo.getScheduleId()));
crossSchedulesPO.setCrossId(crossId);
crossSchedulesPO.setPlanId(scheduleInfoPojo.getDailyPlanId());
Date date = DateUtil.parse(StringUtils.join(currentYear, "-", currentMonth, "-", day), DateStyle.YYYY_MM_DD.getValue());
crossSchedulesPO.setSpecialDate(date);
crossSchedulesPOS.add(crossSchedulesPO);
}
}
}
}
return crossSchedulesPOS;
} }
private List<ScheduleInfoPojo> getSchedulePojos(MessageResultPojo resultPojo) { private List<ScheduleInfoPojo> getSchedulePojos(MessageResultPojo resultPojo) {
......
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