Commit 28c74a3b authored by duanruiming's avatar duanruiming

[update] 日计划,调度

parent c86ce934
...@@ -23,7 +23,9 @@ public class Constants { ...@@ -23,7 +23,9 @@ public class Constants {
public static final String COMMAND_LIGHT_CONFIG = "0302"; public static final String COMMAND_LIGHT_CONFIG = "0302";
public static final String COMMAND_PHASE_STAGE_CONFIG = "0602"; public static final String COMMAND_PHASE_STAGE_CONFIG = "0602";
public static final String COMMAND_SCHME_CONFIG = "0902"; public static final String COMMAND_SCHME_CONFIG = "0902";
public static final String COMMAND_DAILYPLAN_CONFIG = "1102"; public static final String COMMAND_DAILYPLAN_CONFIG = "0b02";
public static final String COMMAND_SCHEDULE_CONFIG = "0c02";
public static final String COMMAND_RUNNING_STATUS = "0d02";
......
...@@ -19,9 +19,9 @@ public enum CommandResultSign { ...@@ -19,9 +19,9 @@ public enum CommandResultSign {
GET_STAGE_INFO("060220", "getStageInfoService"), GET_STAGE_INFO("060220", "getStageInfoService"),
GET_PHASE_SECURITY_INFO("2007", "getPhaseSecurityInfoService"), GET_PHASE_SECURITY_INFO("2007", "getPhaseSecurityInfoService"),
GET_SCHEME_INFO("090220", "getSchemeInfoService"), GET_SCHEME_INFO("090220", "getSchemeInfoService"),
GET_DAILY_PLAN_INFO("110220", "getDailyPlanInfoService"), GET_DAILY_PLAN_INFO("0b0220", "getDailyPlanInfoService"),
GET_SCHEDULES_INFO("2012", "getSchedulesInfoService"), GET_SCHEDULES_INFO("0c0220", "getSchedulesInfoService"),
GET_RUNNING_STATE_INFO("2013", "getRunningStateInfoService"), GET_RUNNING_STATE_INFO("0d0220", "getRunningStateInfoService"),
GET_TRAFFIC_DATA_INFO("2014", "getTrafficDataInfoService"), GET_TRAFFIC_DATA_INFO("2014", "getTrafficDataInfoService"),
GET_ALARM_INFO("2015", "getAlarmInfoService"), GET_ALARM_INFO("2015", "getAlarmInfoService"),
GET_FAULT_INFO("2016", "getFaultInfoService"), GET_FAULT_INFO("2016", "getFaultInfoService"),
......
...@@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -22,7 +22,6 @@ 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;
import java.util.Objects; import java.util.Objects;
/** /**
...@@ -96,10 +95,10 @@ public class StaticInfoController { ...@@ -96,10 +95,10 @@ public class StaticInfoController {
// 命令调用 // 命令调用
staticInfoService.crossSchedules(crossSchedulesDTO); staticInfoService.crossSchedules(crossSchedulesDTO);
// 构造返回值 // 构造返回值
List<String> crossIdList = crossSchedulesDTO.getCrossIdList(); // List<String> crossIdList = crossSchedulesDTO.getCrossIdList();
List<CrossSchedulesPO> crossSchedulesPOList = staticInfoService.buildCrossSchedulesResponse(crossIdList); // List<CrossSchedulesPO> crossSchedulesPOList = staticInfoService.buildCrossSchedulesResponse(crossIdList);
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(crossSchedulesPOList); return jsonViewObject.success(null);
} }
} }
package net.wanji.com.pojo.dtconvert;
import lombok.Data;
import java.util.List;
/**
* @author duanruiming
* @date 2023/06/15 15:07
*/
@Data
public class ScheduleInfoPojo {
private Integer scheduleId;
private Integer crossId;
private Integer priority;
private List<Integer> week;
private List<Integer> month;
private List<Integer> day;
private Integer dailyPlanId;
}
...@@ -17,9 +17,9 @@ public interface StaticInfoService extends BeanMarkService { ...@@ -17,9 +17,9 @@ public interface StaticInfoService extends BeanMarkService {
SchemePhaseLightsVO schemePhaseLights(SchemePhaseLightsDTO schemePhaseLightsDTO) throws Exception; SchemePhaseLightsVO schemePhaseLights(SchemePhaseLightsDTO schemePhaseLightsDTO) throws Exception;
void planSection(PlanSectionDTO planSectionDTO) throws Exception; List<PlanSectionVO> planSection(PlanSectionDTO planSectionDTO) throws Exception;
void crossSchedules(CrossSchedulesDTO crossSchedulesDTO) throws Exception; List<CrossSchedulesPO> crossSchedules(CrossSchedulesDTO crossSchedulesDTO) throws Exception;
SchemePhaseLightsVO buildSchemePhaseLightsResponse(SchemePhaseLightsDTO schemePhaseLightsDTO); SchemePhaseLightsVO buildSchemePhaseLightsResponse(SchemePhaseLightsDTO schemePhaseLightsDTO);
......
...@@ -55,24 +55,9 @@ public class DTStaticInfoServiceImpl implements StaticInfoService { ...@@ -55,24 +55,9 @@ public class DTStaticInfoServiceImpl implements StaticInfoService {
List<LightsInfoPojo> lightsInfoPojos = getLightsInfo(crossInfo); List<LightsInfoPojo> lightsInfoPojos = getLightsInfo(crossInfo);
List<PhaseStageInfoPojo> phaseStageInfoPojos = getPhaseStageInfo(crossInfo); List<PhaseStageInfoPojo> phaseStageInfoPojos = getPhaseStageInfo(crossInfo);
List<SchemeInfoPojo> schemeInfoPojos = getSchemeInfo(crossInfo); List<SchemeInfoPojo> schemeInfoPojos = getSchemeInfo(crossInfo);
List<DailyPlanInfoPojo> dailyPlanInfoPojos = getDailyPlanInfo(crossInfo);
return schemePhaseLightsVO; return schemePhaseLightsVO;
} }
private List<DailyPlanInfoPojo> getDailyPlanInfo(CrossInfoPO crossInfo) {
String message = String.format(Constants.COMMAND_COMMON, Constants.COMMAND_QUERY, Constants.COMMAND_DAILYPLAN_CONFIG);
String dailyPlanSign = Constants.COMMAND_DAILYPLAN_CONFIG.concat(Constants.COMMAND_QUERY_REPLY);
String dailyPlanHex = Constants.buildMessage(message);
MessageResultPojo resultPojo = NettyClient.sendMessage(crossInfo.getIp(), crossInfo.getPort(), dailyPlanHex, dailyPlanSign, 300);
return getDailyPlanPojos(resultPojo);
}
private List<DailyPlanInfoPojo> getDailyPlanPojos(MessageResultPojo resultPojo) {
// String body = hexMessageResult.substring(32, hexMessageResult.length() - 2);
// int schemeSize = body.length() / 228;
return null;
}
private List<SchemeInfoPojo> getSchemeInfo(CrossInfoPO crossInfo) { private List<SchemeInfoPojo> getSchemeInfo(CrossInfoPO crossInfo) {
String message = String.format(Constants.COMMAND_COMMON, Constants.COMMAND_QUERY, Constants.COMMAND_SCHME_CONFIG); String message = String.format(Constants.COMMAND_COMMON, Constants.COMMAND_QUERY, Constants.COMMAND_SCHME_CONFIG);
String schemeSign = Constants.COMMAND_SCHME_CONFIG.concat(Constants.COMMAND_QUERY_REPLY); String schemeSign = Constants.COMMAND_SCHME_CONFIG.concat(Constants.COMMAND_QUERY_REPLY);
...@@ -140,33 +125,35 @@ public class DTStaticInfoServiceImpl implements StaticInfoService { ...@@ -140,33 +125,35 @@ public class DTStaticInfoServiceImpl implements StaticInfoService {
} }
private static Map<Integer, List<String>> getSchemeIdParamMap(String hexMessageResult) { private static Map<Integer, List<String>> getSchemeIdParamMap(String hexMessageResult) {
String body = hexMessageResult.substring(32, hexMessageResult.length() - 2);
int schemeSize = body.length() / 228;
String matchStr = "0902%s%s";
int schemeId = 0;
Map<Integer, List<String>> schemeIdParamMap = new HashMap<>(); Map<Integer, List<String>> schemeIdParamMap = new HashMap<>();
for (int i = 0; i < schemeSize; i++) { if (StringUtils.isNotBlank(hexMessageResult)) {
++schemeId; String body = hexMessageResult.substring(32, hexMessageResult.length() - 2);
List<String> paramList = new ArrayList<>(); int schemeSize = body.length() / 228;
// 属性ID数量 String matchStr = "0902%s%s";
for (int j = 2; j < 9; j++) { int schemeId = 0;
String currentMatchStr = String.format(matchStr, String.format("%02x", j), String.format("%02x", schemeId)); for (int i = 0; i < schemeSize; i++) {
int paramStartIndex = body.indexOf(currentMatchStr) + 8; ++schemeId;
String param = null; List<String> paramList = new ArrayList<>();
if (j == 2 || j == 4) { // 属性ID数量
param = body.substring(paramStartIndex, paramStartIndex + 2); for (int j = 2; j < 9; j++) {
} else if (j == 3) { String currentMatchStr = String.format(matchStr, String.format("%02x", j), String.format("%02x", schemeId));
param = body.substring(paramStartIndex, paramStartIndex + 8); int paramStartIndex = body.indexOf(currentMatchStr) + 8;
} else if (j == 5) { String param = null;
param = body.substring(paramStartIndex, paramStartIndex + 4); if (j == 2 || j == 4) {
} else if (j == 6 || j == 8) { param = body.substring(paramStartIndex, paramStartIndex + 2);
param = body.substring(paramStartIndex, paramStartIndex + 32); } else if (j == 3) {
} else if (j == 7) { param = body.substring(paramStartIndex, paramStartIndex + 8);
param = body.substring(paramStartIndex, paramStartIndex + 64); } else if (j == 5) {
param = body.substring(paramStartIndex, paramStartIndex + 4);
} else if (j == 6 || j == 8) {
param = body.substring(paramStartIndex, paramStartIndex + 32);
} else if (j == 7) {
param = body.substring(paramStartIndex, paramStartIndex + 64);
}
paramList.add(param);
} }
paramList.add(param); schemeIdParamMap.put(schemeId, paramList);
} }
schemeIdParamMap.put(schemeId, paramList);
} }
return schemeIdParamMap; return schemeIdParamMap;
} }
...@@ -321,19 +308,177 @@ public class DTStaticInfoServiceImpl implements StaticInfoService { ...@@ -321,19 +308,177 @@ public class DTStaticInfoServiceImpl implements StaticInfoService {
return phaseIdParamsMap; return phaseIdParamsMap;
} }
public static void main(String[] args) { @Override
String body = "030202010102050302020201030503020203020405030202040305050302020501060503020206010705030202070208050302020803090503020209010a050302020a010b050302020b020c050302020c030d050302020d010e050302020e010f050302020f02100503020210031105030202110112050302021201130503020213011405030202140115050302021501160503020216011705030202170118050302021801190503020219011a050302021a011b050302021b011c050302021c011d050302021d011e050302021e011f050302021f01200503020220012105030202210122050302022201230503020223012405030202240125050302022501260503020226012705030202270128050302022801290503020229012a050302022a012b050302022b012c050302022c012d050302022d012e050302022e012f050302022f01300503020230013105030202310132050302023201330503020233013405030202340135050302023501360503020236013705030202370138050302023801390503020239013a050302023a013b050302023b013c050302023c013d050302023d013e050302023e013f050302023f01400503020240010f47"; public List<PlanSectionVO> planSection(PlanSectionDTO planSectionDTO) throws Exception {
String crossId = planSectionDTO.getCrossId();
CrossInfoPO crossInfoPO = crossInfoCache.getCrossInfoCache().get(crossId);
List<DailyPlanInfoPojo> dailyPlanInfoPojos = getDailyPlanInfo(crossInfoPO);
return null;
}
private List<DailyPlanInfoPojo> getDailyPlanInfo(CrossInfoPO crossInfoPO) {
String message = String.format(Constants.COMMAND_COMMON, Constants.COMMAND_QUERY, Constants.COMMAND_DAILYPLAN_CONFIG);
String dailyPlanSign = Constants.COMMAND_DAILYPLAN_CONFIG.concat(Constants.COMMAND_QUERY_REPLY);
String dailyPlanHex = Constants.buildMessage(message);
MessageResultPojo resultPojo = NettyClient.sendMessage(crossInfoPO.getIp(), crossInfoPO.getPort(), dailyPlanHex, dailyPlanSign, 300);
return getDailyPlanPojos(resultPojo);
} }
@Override private List<DailyPlanInfoPojo> getDailyPlanPojos(MessageResultPojo resultPojo) {
public void planSection(PlanSectionDTO planSectionDTO) throws Exception { List<DailyPlanInfoPojo> dailyPlanInfoPojos = new ArrayList<>();
if (Objects.nonNull(resultPojo) && StringUtils.isNotBlank(resultPojo.getHexMessageResult())) {
HashMap<Integer, List<String>> paramMap = new HashMap<>();
String hexMessageResult = resultPojo.getHexMessageResult();
String body = hexMessageResult.substring(32, hexMessageResult.length() - 2);
int dailyPlanSize = body.length() / 434;
String matchStr = "0b02%s%s";
for (int i = 0; i < dailyPlanSize; i++) {
int paramIndex = 0;
// 4个属性
List<String> paramList = new ArrayList<>();
for (int j = 2; j < 6; j++) {
String currentMatchStr = String.format(matchStr, String.format("%02x", j), String.format("%02x", i + 1));
paramIndex = body.indexOf(currentMatchStr) + 8;
String param = "";
if (j == 2) {
param = body.substring(paramIndex, paramIndex + 2);
} else if (j == 3) {
param = body.substring(paramIndex, paramIndex + 192);
} else {
param = body.substring(paramIndex, paramIndex + 96);
}
paramList.add(param);
}
paramMap.put(i + 1, paramList);
}
dailyPlanInfoPojos = convertDailyPlanPojos(paramMap);
}
return dailyPlanInfoPojos;
}
private List<DailyPlanInfoPojo> convertDailyPlanPojos(HashMap<Integer, List<String>> paramMap) {
List<DailyPlanInfoPojo> dailyPlanInfoPojos = new ArrayList<>();
for (Map.Entry<Integer, List<String>> entry : paramMap.entrySet()) {
Integer dailyPlanId = entry.getKey();
List<String> value = entry.getValue();
if (!CollectionUtils.isEmpty(value)) {
DailyPlanInfoPojo dailyPlanInfoPojo = new DailyPlanInfoPojo();
dailyPlanInfoPojo.setDailyPlanId(dailyPlanId);
dailyPlanInfoPojo.setCrossId(HexUtil.hexToInt(value.get(0)));
List<Integer> listFromHex = getListFromHex(value.get(1), 2, "");
Collections.reverse(listFromHex);
List<String> startTimeChain = new ArrayList<>();
for (int i = 0; i < listFromHex.size() / 2; i++) {
int minute = listFromHex.get(i * 2);
int hour = listFromHex.get(i * 2 + 1);
// 只有第一个时段可以为00:00
if ((i != 0 && hour == 0)) {
continue;
}
startTimeChain.add(StringUtils.join(String.format("%02d", hour), ":", String.format("%02d", minute)));
}
dailyPlanInfoPojo.setStartTimeChain(startTimeChain);
List<Integer> schemeIdChain = getListFromHex(value.get(2), 2, "00");
dailyPlanInfoPojo.setSchemeIdChain(schemeIdChain);
// 21 ==> 33 定周期
List<Integer> controlModeChain = getListFromHex(value.get(3), 2, "00");
dailyPlanInfoPojo.setControlModelChain(controlModeChain);
dailyPlanInfoPojos.add(dailyPlanInfoPojo);
}
}
return dailyPlanInfoPojos.stream().filter(dailyPlanInfoPojo -> !CollectionUtils.isEmpty(dailyPlanInfoPojo.getSchemeIdChain())).collect(Collectors.toList());
} }
@Override @Override
public void crossSchedules(CrossSchedulesDTO crossSchedulesDTO) throws Exception { public List<CrossSchedulesPO> crossSchedules(CrossSchedulesDTO crossSchedulesDTO) throws Exception {
String crossId = crossSchedulesDTO.getCrossId();
CrossInfoPO crossInfoPO = crossInfoCache.getCrossInfoCache().get(crossId);
String message = String.format(Constants.COMMAND_COMMON, Constants.COMMAND_QUERY, Constants.COMMAND_SCHEDULE_CONFIG);
String scheduleSign = Constants.COMMAND_SCHEDULE_CONFIG.concat(Constants.COMMAND_QUERY_REPLY);
String scheduleHex = Constants.buildMessage(message);
MessageResultPojo resultPojo = NettyClient.sendMessage(crossInfoPO.getIp(), crossInfoPO.getPort(), scheduleHex, scheduleSign, 300);
List<ScheduleInfoPojo> scheduleInfoPojos = getSchedulePojos(resultPojo);
return null;
}
private List<ScheduleInfoPojo> getSchedulePojos(MessageResultPojo resultPojo) {
List<ScheduleInfoPojo> scheduleInfoPojos = new ArrayList<>();
if (Objects.nonNull(resultPojo) && StringUtils.isNotBlank(resultPojo.getHexMessageResult())) {
HashMap<Integer, List<String>> paramMap = new HashMap<>();
String hexMessageResult = resultPojo.getHexMessageResult();
String body = hexMessageResult.substring(32, hexMessageResult.length() - 2);
int scheduleSize = body.length() / 92;
String matchStr = "0c02%s%s";
int paramIndex = 0;
for (int i = 0; i < scheduleSize; i++) {
List<String> paramList = new ArrayList<>();
for (int j = 2; j < 8; j++) {
String currentMatchStr = String.format(matchStr, String.format("%02x", j), String.format("%02x", i + 1));
paramIndex = body.indexOf(currentMatchStr) + 8;
String param = "";
if (j == 5) {
param = body.substring(paramIndex, paramIndex + 4);
} else if (j == 6) {
param = body.substring(paramIndex, paramIndex + 8);
} else {
param = body.substring(paramIndex, paramIndex + 2);
}
paramList.add(param);
}
paramMap.put(i + 1, paramList);
}
scheduleInfoPojos = convertSchedulePojos(paramMap);
}
return scheduleInfoPojos;
}
private List<ScheduleInfoPojo> convertSchedulePojos(HashMap<Integer, List<String>> paramMap) {
List<ScheduleInfoPojo> scheduleInfoPojos = new ArrayList<>();
for (Map.Entry<Integer, List<String>> entry : paramMap.entrySet()) {
Integer scheduleId = entry.getKey();
List<String> value = entry.getValue();
if (!CollectionUtils.isEmpty(value)) {
ScheduleInfoPojo scheduleInfoPojo = new ScheduleInfoPojo();
scheduleInfoPojo.setScheduleId(scheduleId);
scheduleInfoPojo.setCrossId(HexUtil.hexToInt(value.get(0)));
scheduleInfoPojo.setPriority(HexUtil.hexToInt(value.get(1)));
String weekStr = Integer.toBinaryString(HexUtil.hexToInt(value.get(2)));
List<Integer> weekList = new ArrayList<>();
for (int i = 0; i < weekStr.length(); i++) {
String week = weekStr.substring(i, i + 1);
if (StringUtils.equals("1", week)) {
weekList.add(weekStr.length() - i);
}
}
scheduleInfoPojo.setWeek(weekList);
String monthStr = Integer.toBinaryString(HexUtil.hexToInt(value.get(3)));
List<Integer> monthList = new ArrayList<>();
for (int i = 0; i < monthStr.length(); i++) {
String month = monthStr.substring(i, i + 1);
if (StringUtils.equals("1", month)) {
monthList.add(monthStr.length() - i);
}
}
scheduleInfoPojo.setMonth(monthList);
String dayStr = Integer.toBinaryString(HexUtil.hexToInt(value.get(4)));
List<Integer> dayList = new ArrayList<>();
for (int i = 0; i < dayStr.length(); i++) {
String day = dayStr.substring(i, i + 1);
if (StringUtils.equals("1", day)) {
dayList.add(dayStr.length() - i);
}
}
scheduleInfoPojo.setDay(dayList);
scheduleInfoPojo.setDailyPlanId(HexUtil.hexToInt(value.get(5)));
scheduleInfoPojos.add(scheduleInfoPojo);
}
}
List<ScheduleInfoPojo> filter = scheduleInfoPojos.stream().filter(scheduleInfoPojo -> Objects.nonNull(scheduleInfoPojo.getDailyPlanId())).collect(Collectors.toList());
return filter;
} }
@Override @Override
......
...@@ -5,9 +5,6 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -5,9 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import java.util.List;
/** /**
* @author Kent HAN * @author Kent HAN
...@@ -16,12 +13,7 @@ import java.util.List; ...@@ -16,12 +13,7 @@ import java.util.List;
@Data @Data
@ApiModel(value = "CrossSchedulesDTO", description = "查询时间表数据输入参数") @ApiModel(value = "CrossSchedulesDTO", description = "查询时间表数据输入参数")
public class CrossSchedulesDTO { public class CrossSchedulesDTO {
@ApiModelProperty(value = "厂商代码 HK") @ApiModelProperty(value = "路口编号")
@NotBlank @NotBlank
@Pattern(regexp = "^[A-Z]*$", message = "厂商代码只能包含大写英文字母") private String crossId;
String manufacturerCode;
@ApiModelProperty(value = "路口列表")
@NotEmpty
List<String> crossIdList;
} }
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