refactor(service): 优化车辆功能服务实现代码结构
- 移除不必要的uiKey到TiVehicleUi的映射创建 - 简化HashMap初始化语法移除冗余泛型声明 - 更新注释编号保持与实际逻辑步骤一致 - 删除未使用的uiByKey变量减少内存占用 - 优化代码流程提高执行效率
This commit is contained in:
parent
22463c1763
commit
7ab5a64291
@ -80,18 +80,12 @@ public class ExTiVehicleFunctionServiceImpl implements ExTiVehicleFunctionServic
|
|||||||
List<TiVehicleFunction> funcList = tiVehicleFunctionService.selectTiVehicleFunctionList(
|
List<TiVehicleFunction> funcList = tiVehicleFunctionService.selectTiVehicleFunctionList(
|
||||||
TiVehicleFunctionVO.builder().vehicleConfigId(vehicleConfigId).build());
|
TiVehicleFunctionVO.builder().vehicleConfigId(vehicleConfigId).build());
|
||||||
|
|
||||||
// 2. uiKey → TiVehicleUi
|
// 2. funcKey → TiVehicleFunction
|
||||||
Map<String, TiVehicleUi> uiByKey = new HashMap<String, TiVehicleUi>();
|
Map<Long, TiVehicleFunction> funcById = new HashMap<>();
|
||||||
for (TiVehicleUi ui : uiList) {
|
|
||||||
uiByKey.put(ui.getUiKey(), ui);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. funcKey → TiVehicleFunction
|
|
||||||
Map<Long, TiVehicleFunction> funcById = new HashMap<Long, TiVehicleFunction>();
|
|
||||||
for (TiVehicleFunction f : funcList) {
|
for (TiVehicleFunction f : funcList) {
|
||||||
funcById.put(f.getId(), f);
|
funcById.put(f.getId(), f);
|
||||||
}
|
}
|
||||||
// 4.组装uiMap
|
// 3.组装uiMap
|
||||||
Map<String, CarUi> uiMap = new HashMap<>();
|
Map<String, CarUi> uiMap = new HashMap<>();
|
||||||
List<CarIcon> icons;
|
List<CarIcon> icons;
|
||||||
CarUi carUi;
|
CarUi carUi;
|
||||||
@ -115,12 +109,12 @@ public class ExTiVehicleFunctionServiceImpl implements ExTiVehicleFunctionServic
|
|||||||
);
|
);
|
||||||
uiMap.put(carUi.getUiName(), carUi);
|
uiMap.put(carUi.getUiName(), carUi);
|
||||||
}
|
}
|
||||||
// 5.获取路径
|
// 4.获取路径
|
||||||
List<CarIcon> path = CarPathFinderUtil.findPath(uiMap, startUiName, targetFuncName);
|
List<CarIcon> path = CarPathFinderUtil.findPath(uiMap, startUiName, targetFuncName);
|
||||||
if (CollectionUtils.isEmpty(path)) {
|
if (CollectionUtils.isEmpty(path)) {
|
||||||
throw new GlobalException("没有找到匹配的路径");
|
throw new GlobalException("没有找到匹配的路径");
|
||||||
}
|
}
|
||||||
// 组装结果
|
// 5.组装结果
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("nextLocation", path.get(0).getIconName());
|
map.put("nextLocation", path.get(0).getIconName());
|
||||||
map.put("isEnd", path.size() == 1);
|
map.put("isEnd", path.size() == 1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user