Commit b2ddb31b6cc8963f7b15686b35fcbb2656fc91f1

Authored by 王通
1 parent 6fb6a87a

1.运管处上传Optional<T>紧急处理

src/main/java/com/bsth/service/impl/TrafficManageServiceImpl.java
... ... @@ -186,7 +186,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
186 186 map.put("lineCode_eq", id);
187 187 Line line ;
188 188 LineInformation lineInformation;
189   - line = lineRepository.findOne(new CustomerSpecs<Line>(map)).get();
  189 + Optional<Line> optionalLine = lineRepository.findOne(new CustomerSpecs<Line>(map));
  190 + line = optionalLine.isPresent() ? optionalLine.get() : null;
190 191 if(line == null){
191 192 continue;
192 193 }
... ... @@ -195,7 +196,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
195 196 }
196 197 map = new HashMap<>();
197 198 map.put("line.id_eq",line.getId());
198   - lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(map)).get();
  199 + Optional<LineInformation> optionalLineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(map));
  200 + lineInformation = optionalLineInformation.isPresent() ? optionalLineInformation.get() : null;
199 201 if(lineInformation == null){
200 202 continue;
201 203 }
... ... @@ -599,7 +601,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
599 601 for(Map<String,Object> schRealInfo:listGroup){
600 602 if(schRealInfo != null){
601 603 map.put("insideCode_eq", schRealInfo.get("clZbh")+"");
602   - Cars car = carsRepository.findOne(new CustomerSpecs<Cars>(map)).get();
  604 + Optional<Cars> optionalCars = carsRepository.findOne(new CustomerSpecs<Cars>(map));
  605 + Cars car = optionalCars.isPresent() ? optionalCars.get() : null;
603 606 /**
604 607 * 如果car==null,则说明该车辆是从线调中换车功能中加进去的,
605 608 * 在cars基础信息中查不到车辆的信息,所以忽略该车辆
... ... @@ -921,7 +924,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
921 924 boolean isLogStation;
922 925 for (int i = 0; i < idArray.length; i++) {
923 926 ttinfoId = Long.valueOf(idArray[i]);
924   - ttInfo = ttInfoRepository.findById(ttinfoId).get();
  927 + Optional<TTInfo> optionalTTInfo = ttInfoRepository.findById(ttinfoId);
  928 + ttInfo = optionalTTInfo.isPresent() ? optionalTTInfo.get() : null;
925 929 if(ttInfo == null)
926 930 continue;
927 931 ttinfoList.add(ttInfo); // 保存时刻表
... ... @@ -941,12 +945,14 @@ public class TrafficManageServiceImpl implements TrafficManageService{
941 945 // 获得lineInformation
942 946 param = new HashMap();
943 947 param.put("line.id_eq", ttInfo.getXl().getId());
944   - lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(param)).get();
  948 + Optional<LineInformation> optionalLineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(param));
  949 + lineInformation = optionalLineInformation.isPresent() ? optionalLineInformation.get() : null;
945 950 // 初始化
946 951 isLogStation = true;
947 952 if(ttInfoDetailIterator.hasNext()){
948 953 // 得到线路信息
949   - Line line = lineRepository.findById(ttInfo.getXl().getId()).get();
  954 + Optional<Line> optionalLine = lineRepository.findById(ttInfo.getXl().getId());
  955 + Line line = optionalLine.isPresent() ? optionalLine.get() : null;
950 956 if(line == null){
951 957 result += "未找到相应的线路信息,请设置线路信息后再上传";
952 958 return result;
... ...