| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("routeService") |
| | | public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService { |
| | |
| | | private CodeService codeService; |
| | | |
| | | @Override |
| | | public Route createRouteByCode(Code code0, Code code1) { |
| | | return createRouteByCode(code0, code1, 0, null); |
| | | public Route createRouteByCode(Code startCode, Code endCode) { |
| | | return createRouteByCode(startCode, endCode, 0, null); |
| | | } |
| | | |
| | | @Override |
| | | public Route createRouteByCode(Code code0, Code code1, Integer direction, Long userId) { |
| | | if (code0.getData().equals(code1.getData())) { |
| | | public Route createRouteByCode(Code startCode, Code endCode, Integer direction, Long userId) { |
| | | if (startCode.getData().equals(endCode.getData())) { |
| | | return null; |
| | | } |
| | | Route route = this.findByCodeOfBoth(code0.getId(), code1.getId()); |
| | | Route route = this.findByCodeOfBoth(startCode.getId(), endCode.getId()); |
| | | direction = Optional.ofNullable(direction).orElse(0); |
| | | if (null == route) { |
| | | Date now = new Date(); |
| | | route = new Route(); |
| | | route.setUuid(code0.getData() + "-" + code1.getData()); |
| | | route.setStartCode(code0.getId()); |
| | | route.setEndCode(code1.getId()); |
| | | route.setUuid(startCode.getData() + "-" + endCode.getData()); |
| | | route.setStartCode(startCode.getId()); |
| | | route.setEndCode(endCode.getId()); |
| | | route.setDirection(direction); |
| | | route.setCodeArr(GsonUtils.toJson(Arrays.asList(code0.getId(), code1.getId()))); |
| | | route.setCodeArr(GsonUtils.toJson(Arrays.asList(startCode.getId(), endCode.getId()))); |
| | | route.setCreateBy(userId); |
| | | route.setCreateTime(now); |
| | | route.setUpdateBy(userId); |
| | |
| | | List<String> neighborCodeList = new ArrayList<>(); |
| | | |
| | | for (Route route : this.list(new LambdaQueryWrapper<Route>().eq(Route::getStartCode, code))) { |
| | | neighborCodeList.add(codeService.getById(route.getEndCode()).getData()); |
| | | neighborCodeList.add(codeService.getCacheById(route.getEndCode()).getData()); |
| | | } |
| | | for (Route route : this.list(new LambdaQueryWrapper<Route>().eq(Route::getEndCode, code))) { |
| | | neighborCodeList.add(codeService.getById(route.getStartCode()).getData()); |
| | | neighborCodeList.add(codeService.getCacheById(route.getStartCode()).getData()); |
| | | } |
| | | |
| | | return neighborCodeList; |
| | | } |
| | | |
| | | @Override |
| | | public Route findByCodeOfBoth(Long code0, Long code1) { |
| | | Route route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getStartCode, code0).eq(Route::getEndCode, code1).eq(Route::getStatus, 1)); |
| | | public Route findByCodeOfBoth(Long startCode, Long endCode) { |
| | | Route route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getStartCode, startCode).eq(Route::getEndCode, endCode).eq(Route::getStatus, 1)); |
| | | if (null == route) { |
| | | route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getEndCode, code0).eq(Route::getStartCode, code1).eq(Route::getStatus, 1)); |
| | | route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getEndCode, startCode).eq(Route::getStartCode, endCode).eq(Route::getStatus, 1)); |
| | | } |
| | | return route; |
| | | } |
| | | |
| | | @Override |
| | | public List<Long> getAdjacencyNode(Long codeId) { |
| | | |
| | | List<Long> result = new ArrayList<>(); |
| | | |
| | | result.addAll(this.list(new LambdaQueryWrapper<Route>() |
| | | .eq(Route::getStartCode, codeId) |
| | | .in(Route::getDirection, 0, 1) |
| | | .eq(Route::getStatus, 1) |
| | | ).stream().map(Route::getEndCode).distinct().collect(Collectors.toList())); |
| | | |
| | | result.addAll(this.list(new LambdaQueryWrapper<Route>() |
| | | .eq(Route::getEndCode, codeId) |
| | | .in(Route::getDirection, 0, 2) |
| | | .eq(Route::getStatus, 1) |
| | | ).stream().map(Route::getStartCode).distinct().collect(Collectors.toList())); |
| | | |
| | | |
| | | return result.stream().distinct().collect(Collectors.toList()); |
| | | } |
| | | |
| | | } |