#
vincentlu
2025-05-13 ebd2f4397a92c6a5096de1b86d59154363344720
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java
@@ -13,6 +13,7 @@
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service("routeService")
public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService {
@@ -21,22 +22,25 @@
    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) {
        Route route = this.findByCodeOfBoth(code0.getId(), code1.getId());
    public Route createRouteByCode(Code startCode, Code endCode, Integer direction, Long userId) {
        if (startCode.getData().equals(endCode.getData())) {
            return null;
        }
        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);
@@ -53,22 +57,43 @@
        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());
    }
}