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,7 +186,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
186 map.put("lineCode_eq", id); 186 map.put("lineCode_eq", id);
187 Line line ; 187 Line line ;
188 LineInformation lineInformation; 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 if(line == null){ 191 if(line == null){
191 continue; 192 continue;
192 } 193 }
@@ -195,7 +196,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -195,7 +196,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
195 } 196 }
196 map = new HashMap<>(); 197 map = new HashMap<>();
197 map.put("line.id_eq",line.getId()); 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 if(lineInformation == null){ 201 if(lineInformation == null){
200 continue; 202 continue;
201 } 203 }
@@ -599,7 +601,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -599,7 +601,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
599 for(Map<String,Object> schRealInfo:listGroup){ 601 for(Map<String,Object> schRealInfo:listGroup){
600 if(schRealInfo != null){ 602 if(schRealInfo != null){
601 map.put("insideCode_eq", schRealInfo.get("clZbh")+""); 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 * 如果car==null,则说明该车辆是从线调中换车功能中加进去的, 607 * 如果car==null,则说明该车辆是从线调中换车功能中加进去的,
605 * 在cars基础信息中查不到车辆的信息,所以忽略该车辆 608 * 在cars基础信息中查不到车辆的信息,所以忽略该车辆
@@ -921,7 +924,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -921,7 +924,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
921 boolean isLogStation; 924 boolean isLogStation;
922 for (int i = 0; i < idArray.length; i++) { 925 for (int i = 0; i < idArray.length; i++) {
923 ttinfoId = Long.valueOf(idArray[i]); 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 if(ttInfo == null) 929 if(ttInfo == null)
926 continue; 930 continue;
927 ttinfoList.add(ttInfo); // 保存时刻表 931 ttinfoList.add(ttInfo); // 保存时刻表
@@ -941,12 +945,14 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -941,12 +945,14 @@ public class TrafficManageServiceImpl implements TrafficManageService{
941 // 获得lineInformation 945 // 获得lineInformation
942 param = new HashMap(); 946 param = new HashMap();
943 param.put("line.id_eq", ttInfo.getXl().getId()); 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 isLogStation = true; 951 isLogStation = true;
947 if(ttInfoDetailIterator.hasNext()){ 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 if(line == null){ 956 if(line == null){
951 result += "未找到相应的线路信息,请设置线路信息后再上传"; 957 result += "未找到相应的线路信息,请设置线路信息后再上传";
952 return result; 958 return result;