Commit 02e0e6fc authored by duanruiming's avatar duanruiming

[update] 解决步进

parent 1b5999eb
package net.wanji.utc.dt.service.impl; package net.wanji.utc.dt.service.impl;
import cn.hutool.core.util.HexUtil; import cn.hutool.core.util.HexUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.common.utils.tool.DateUtil; import net.wanji.common.utils.tool.DateUtil;
...@@ -15,11 +14,14 @@ import net.wanji.utc.dt.common.enums.SectionControlModeEnum; ...@@ -15,11 +14,14 @@ import net.wanji.utc.dt.common.enums.SectionControlModeEnum;
import net.wanji.utc.dt.netty.NettyClient; import net.wanji.utc.dt.netty.NettyClient;
import net.wanji.utc.dt.pojo.dtconvert.LightsInfoPojo; import net.wanji.utc.dt.pojo.dtconvert.LightsInfoPojo;
import net.wanji.utc.dt.pojo.dtconvert.PhaseInfoPojo; import net.wanji.utc.dt.pojo.dtconvert.PhaseInfoPojo;
import net.wanji.utc.dt.pojo.dtconvert.SchemeInfoPojo;
import net.wanji.utc.dt.pojo.netty.MessageResultPojo; import net.wanji.utc.dt.pojo.netty.MessageResultPojo;
import net.wanji.utc.dt.service.ControlCommandService; import net.wanji.utc.dt.service.ControlCommandService;
import net.wanji.utc.dt.service.SignalStatusService;
import net.wanji.utc.dt.util.CommonUtils; import net.wanji.utc.dt.util.CommonUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
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;
...@@ -31,11 +33,13 @@ import java.util.stream.Collectors; ...@@ -31,11 +33,13 @@ import java.util.stream.Collectors;
* @date 2023/05/08 10:43 * @date 2023/05/08 10:43
*/ */
@Service @Service
@RequiredArgsConstructor
@Slf4j @Slf4j
@SuppressWarnings("all") @SuppressWarnings("all")
public class DTControlCommandServiceImpl implements ControlCommandService { public class DTControlCommandServiceImpl implements ControlCommandService {
@Autowired
private SignalStatusService dtSignalStatusService;
/** /**
* 东土相位灯组固定,万集下发相位就是下发东土阶段关联相位关系, * 东土相位灯组固定,万集下发相位就是下发东土阶段关联相位关系,
* *
...@@ -337,7 +341,54 @@ public class DTControlCommandServiceImpl implements ControlCommandService { ...@@ -337,7 +341,54 @@ public class DTControlCommandServiceImpl implements ControlCommandService {
@Override @Override
public JsonViewObject stepControl(String code, Integer command, Integer stepNum) throws Exception { public JsonViewObject stepControl(String code, Integer command, Integer stepNum) throws Exception {
return null; Integer nextStageId = getNextStageId(code);
ControlCommandVO controlCommandVO = new ControlCommandVO();
controlCommandVO.setCommand(command);
controlCommandVO.setCrossCode(code);
controlCommandVO.setPhaseList(Arrays.asList(nextStageId));
JsonViewObject jsonViewObject = lockControl(controlCommandVO);
return jsonViewObject;
}
/**
* @description 通过路口编号,获取路口实时阶段方案,计算下一个阶段号
* @param [code]
* @return java.lang.Integer
*/
private Integer getNextStageId(String code) throws Exception {
Integer nextStageId = null;
List<LightsStatusVO> lightsStatusVOS = dtSignalStatusService.lightStatus(code);
if (!CollectionUtils.isEmpty(lightsStatusVOS)) {
LightsStatusVO lightsStatusVO = lightsStatusVOS.get(0);
if (Objects.nonNull(lightsStatusVO)) {
String currentStageId = lightsStatusVO.getPhaseId();
String currentSchemeId = lightsStatusVO.getSchemeId();
List<SchemeInfoPojo> schemeInfoPojos = SignalDataCache.schemeInfoCache.get(code);
if (!CollectionUtils.isEmpty(schemeInfoPojos)) {
for (SchemeInfoPojo schemeInfoPojo : schemeInfoPojos) {
if (Objects.equals(schemeInfoPojo.getSchemeId(), Integer.valueOf(currentSchemeId))) {
List<Integer> phaseStageChain = schemeInfoPojo.getPhaseStageChain();
if (!CollectionUtils.isEmpty(phaseStageChain)) {
for (int i = 0; i < phaseStageChain.size(); i++) {
if (Objects.equals(Integer.valueOf(currentStageId), phaseStageChain.get(i))) {
int index = phaseStageChain.indexOf(Integer.valueOf(currentStageId));
if (index == phaseStageChain.size() - 1) {
nextStageId = phaseStageChain.get(0);
break;
} else {
nextStageId = phaseStageChain.get(i + 1);
break;
}
}
}
}
}
}
}
}
}
return nextStageId;
} }
@Override @Override
......
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