| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.zy.acs.common.utils.GsonUtils; |
| | | import com.zy.acs.common.utils.Utils; |
| | | import com.zy.acs.framework.exception.CoolException; |
| | | import com.zy.acs.manager.manager.entity.Code; |
| | | import com.zy.acs.manager.manager.entity.Route; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("routeService") |
| | | public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService { |
| | |
| | | return null; |
| | | } |
| | | Route route = this.findByCodeOfBoth(startCode.getId(), endCode.getId()); |
| | | boolean created = false; |
| | | direction = Optional.ofNullable(direction).orElse(0); |
| | | if (null == route) { |
| | | Date now = new Date(); |
| | |
| | | if (!this.save(route)) { |
| | | throw new CoolException(route.getCodeArr()+" save fail![Route]"); |
| | | } |
| | | created = true; |
| | | } |
| | | if (created) { |
| | | List<Long> codes = Utils.singletonList(startCode.getId()); |
| | | codes.add(endCode.getId()); |
| | | codeService.refreshCornerByCodeIds(codes); |
| | | } |
| | | return route; |
| | | } |
| | |
| | | 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; |
| | |
| | | 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()); |
| | | } |
| | | |
| | | } |