|
@@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
@@ -61,28 +62,40 @@ public class AppSceneService {
|
|
|
if(StringUtils.isEmpty(param.getAppUserName()) && StringUtils.isEmpty(param.getPhoneNum()) ){
|
|
|
throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
|
|
|
}
|
|
|
- Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(), param.getAppPassword());
|
|
|
- if(camera == null){
|
|
|
- throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
- }
|
|
|
- CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
- if(cameraDetail == null){
|
|
|
- throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
- }
|
|
|
- User user = userService.getByUserName(param.getPhoneNum());
|
|
|
- if(user == null){
|
|
|
- throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
+ if(!StringUtils.isEmpty(param.getAppUserName()) && !StringUtils.isEmpty(param.getAppPassword())){
|
|
|
+ Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(), param.getAppPassword());
|
|
|
+ if(camera == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
+ }
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
+ if(cameraDetail == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
|
|
|
+ }
|
|
|
+ param.setSnCode(camera.getSnCode());
|
|
|
+ param.setCameraId(camera.getId());
|
|
|
}
|
|
|
- List<String> cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(user.getId()));
|
|
|
- if(cooperationNumList.size() >0){
|
|
|
- String cooperationNums = cooperationNumList.stream().map(num->"'"+num+"'").collect(Collectors.joining(","));
|
|
|
- param.setCooperationNums(cooperationNums );
|
|
|
+
|
|
|
+ List<String> cooperationNumList = new ArrayList<>();
|
|
|
+ if(StringUtils.isNotBlank(param.getPhoneNum())){
|
|
|
+ User user = userService.getByUserName(param.getPhoneNum());
|
|
|
+ if(user == null){
|
|
|
+ throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
|
|
|
+ }
|
|
|
+ cooperationNumList = sceneCooperationService.getNumByUserIds(Arrays.asList(user.getId()));
|
|
|
+ if(cooperationNumList.size() >0){
|
|
|
+ String cooperationNums = cooperationNumList.stream().map(num->"'"+num+"'").collect(Collectors.joining(","));
|
|
|
+ param.setCooperationNums(cooperationNums );
|
|
|
+ }
|
|
|
+ param.setUserId(user.getId());
|
|
|
}
|
|
|
|
|
|
- param.setUserId(user.getId());
|
|
|
- param.setSnCode(camera.getSnCode());
|
|
|
- param.setCameraId(camera.getId());
|
|
|
Page<AppSceneVo> page = scenePlusMapper.pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
|
|
|
+
|
|
|
+ Set<Long> cameraIdSet = page.getRecords().stream().map(AppSceneVo::getCameraId).collect(Collectors.toSet());
|
|
|
+ List<Long> cameraIds = new ArrayList<>(cameraIdSet);
|
|
|
+ HashMap<Long, Camera> cameraHashMap = cameraService.getByIds(cameraIds);
|
|
|
+ HashMap<Long, CameraDetail> detailHashMap = cameraDetailService.getByCameraIds(cameraIds);
|
|
|
+
|
|
|
for (AppSceneVo record : page.getRecords()) {
|
|
|
record.setChildName(record.getSnCode());
|
|
|
if (record.getStatus() == -1) {
|
|
@@ -90,22 +103,41 @@ public class AppSceneService {
|
|
|
} else if (record.getStatus() == 500) {
|
|
|
record.setStatus(-1);
|
|
|
}
|
|
|
- //相机的userId为空,表示相机的场景
|
|
|
- if (cameraDetail.getUserId() == null || user.getId() == null) {
|
|
|
- record.setSceneSourceType(0);
|
|
|
- } else if (cameraDetail.getUserId().longValue() == user.getId().longValue()) {
|
|
|
- //相机用户id等于该用户id,既为用户的场景
|
|
|
- record.setSceneSourceType(1);
|
|
|
- } else if (camera.getId() != null && cameraDetail.getCameraId().longValue() == camera.getId().longValue()) {
|
|
|
- if (cameraDetail.getCooperationUser() == null) {
|
|
|
- //场景相机id等于该相机id
|
|
|
- record.setSceneSourceType(0);
|
|
|
- } else if (cameraDetail.getCooperationUser().longValue() == user.getId().longValue()) {
|
|
|
+ if(record.getCameraId() == null){
|
|
|
+ record.setSceneSourceType(record.getUserId().longValue() ==param.getUserId() ? 1 : 2);
|
|
|
+ }else {
|
|
|
+ Camera camera = cameraHashMap.get(record.getCameraId());
|
|
|
+ if(ObjectUtils.isEmpty(camera)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ record.setChildName(camera.getChildName());
|
|
|
+ record.setSnCode(camera.getSnCode());
|
|
|
+ if(cooperationNumList.contains(record.getNum())){
|
|
|
record.setSceneSourceType(2);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ CameraDetail cameraDetail = detailHashMap.get(camera.getId());
|
|
|
+ if(ObjectUtils.isEmpty(cameraDetail)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //相机的userId为空,表示相机的场景
|
|
|
+ if (cameraDetail.getUserId() == null || param.getUserId() == null) {
|
|
|
+ record.setSceneSourceType(0);
|
|
|
+ } else if (cameraDetail.getUserId().longValue() == param.getUserId().longValue()) {
|
|
|
+ //相机用户id等于该用户id,既为用户的场景
|
|
|
+ record.setSceneSourceType(1);
|
|
|
+ } else if (camera.getId() != null && cameraDetail.getCameraId().longValue() == camera.getId().longValue()) {
|
|
|
+ if (cameraDetail.getCooperationUser() == null) {
|
|
|
+ //场景相机id等于该相机id
|
|
|
+ record.setSceneSourceType(0);
|
|
|
+ } else if (cameraDetail.getCooperationUser().longValue() == param.getUserId().longValue()) {
|
|
|
+ record.setSceneSourceType(2);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ record.setSceneSourceType(0);
|
|
|
}
|
|
|
- } else {
|
|
|
- record.setSceneSourceType(0);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
return PageInfo.PageInfo(page);
|
|
|
}
|