lyhzzz 2 년 전
부모
커밋
829cc84c5f
1개의 변경된 파일11개의 추가작업 그리고 5개의 파일을 삭제
  1. 11 5
      src/main/java/com/fdkankan/manage/service/impl/CameraServiceImpl.java

+ 11 - 5
src/main/java/com/fdkankan/manage/service/impl/CameraServiceImpl.java

@@ -279,7 +279,7 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
         return cameraDetailService.saveOrUpdateBatch(cameraDetails) ? cameraDetails.size() : 0;
     }
 
-    private void checkSnCode(List<String> snCodeList) {
+    private void checkSnCode(List<String> snCodeList,List<String> dbSnCode) {
         HashMap<String,Integer> map = new HashMap<>();
         for (String snCode : snCodeList) {
             if(StringUtils.isBlank(snCode)){
@@ -300,6 +300,11 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
         if(errorSnCode.size() >0){
             throw new BusinessException(-1,"存在重复的snCode:"+errorSnCode);
         }
+        for (String snCode : snCodeList) {
+            if(!dbSnCode.contains(snCode)){
+                throw new BusinessException(-1,"snCode:"+snCode+",不存在");
+            }
+        }
 
     }
 
@@ -374,11 +379,12 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
     private HashMap<String, Object> getResultMap(List<CameraInOutParam> params){
         HashMap<String,Object> resultMap = new HashMap<>();
         List<String> snCodeList = params.parallelStream().map(CameraInOutParam::getSnCode).collect(Collectors.toList());
-        checkSnCode(snCodeList);
-        List<Camera> cameraList = this.getBySnCodes(snCodeList);
-        if(cameraList.size() <=0){
-            throw new BusinessException(-1,"snCode不存在");
+        if(snCodeList.size() <=0){
+            throw new BusinessException(-1,"snCode为空");
         }
+        List<Camera> cameraList = this.getBySnCodes(snCodeList);
+        checkSnCode(snCodeList,cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList()));
+
         List<Long> cameraIds = cameraList.parallelStream().map(Camera::getId).collect(Collectors.toList());
         List<CameraDetail> cameraDetails = cameraDetailService.getByCameraIds(cameraIds);
         HashMap<Long,CameraDetail> detailMap = new HashMap<>();