|
@@ -250,32 +250,25 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
|
|
|
public void bind(Integer cameraType, String snCodes, String username) {
|
|
|
User user = userService.getByUserName(username);
|
|
|
String[] snCodeArr = snCodes.split(",");
|
|
|
- List<String> snCodeList = new ArrayList<>();
|
|
|
- for (String snCode : snCodeArr) {
|
|
|
- if(snCode.contains("_")){
|
|
|
- snCode = snCode.split("_")[1];
|
|
|
+ List<Long> cameraIds = new ArrayList<>();
|
|
|
+ for (String wifiName : snCodeArr) {
|
|
|
+ String snCode = null;
|
|
|
+ if(wifiName.contains("_")){
|
|
|
+ snCode = wifiName.split("_")[1];
|
|
|
}
|
|
|
- snCodeList.add(snCode);
|
|
|
- }
|
|
|
- LambdaUpdateWrapper<Camera> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.in(Camera::getSnCode,snCodeList);
|
|
|
- List<Camera> list = this.list(wrapper);
|
|
|
- if(list.size() <=0){
|
|
|
- throw new BusinessException(AppConstant.FAILURE_CODE_4010, snCodes +"-"+ AppConstant.FAILURE_MSG_4010);
|
|
|
- }
|
|
|
- List<String> dbSnCode = list.stream().map(Camera::getSnCode).collect(Collectors.toList());
|
|
|
- for (String code : snCodeList) {
|
|
|
- if(!dbSnCode.contains(code)){
|
|
|
- throw new BusinessException(AppConstant.FAILURE_CODE_4010, code +"-"+ AppConstant.FAILURE_MSG_4010);
|
|
|
+
|
|
|
+ Camera camera = this.getBySnCode(snCode);
|
|
|
+ if(camera == null){
|
|
|
+ throw new BusinessException(AppConstant.FAILURE_CODE_4010, wifiName +"-"+ AppConstant.FAILURE_MSG_4010);
|
|
|
}
|
|
|
- }
|
|
|
- Map<Long, Camera> cameraHashMap = list.stream().collect(Collectors.toMap(Camera::getId, camera -> camera, (o1, o2) -> o1));
|
|
|
- List<Long> cameraIds = new ArrayList<>(cameraHashMap.keySet());
|
|
|
- HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
|
|
|
- for (CameraDetail detail : detailHashMap.values()) {
|
|
|
- if(detail.getUserId() != null){
|
|
|
- throw new BusinessException(CameraConstant.FAILURE_CODE_6010, cameraHashMap.get(detail.getCameraId()).getSnCode() +"-"+ CameraConstant.FAILURE_MSG_6010);
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
+ if(cameraDetail == null){
|
|
|
+ throw new BusinessException(AppConstant.FAILURE_CODE_4010, wifiName +"-"+ AppConstant.FAILURE_MSG_4010);
|
|
|
+ }
|
|
|
+ if( cameraDetail.getUserId() != null){
|
|
|
+ throw new BusinessException(CameraConstant.FAILURE_CODE_6010, wifiName +"-"+ CameraConstant.FAILURE_MSG_6010);
|
|
|
}
|
|
|
+ cameraIds.add(camera.getId());
|
|
|
}
|
|
|
|
|
|
cameraIncrementLogService.saveLog(cameraIds,null,user.getId(),2);
|