|
@@ -1,8 +1,11 @@
|
|
|
package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpStatus;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -10,8 +13,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.*;
|
|
|
import com.fdkankan.common.response.PageInfo;
|
|
|
import com.fdkankan.common.util.*;
|
|
|
+import com.fdkankan.platform.api.feign.PlatformGoodsClient;
|
|
|
+import com.fdkankan.platform.api.feign.PlatformUserClient;
|
|
|
import com.fdkankan.platform.api.vo.Camera;
|
|
|
import com.fdkankan.platform.api.vo.CameraDetail;
|
|
|
+import com.fdkankan.platform.api.vo.User;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.constant.RedisLockKey;
|
|
|
import com.fdkankan.redis.util.RedisLockUtil;
|
|
@@ -20,10 +26,7 @@ import com.fdkankan.scene.entity.ScenePro;
|
|
|
import com.fdkankan.scene.entity.SceneProEdit;
|
|
|
import com.fdkankan.scene.entity.SceneProEditExt;
|
|
|
import com.fdkankan.scene.mapper.ISceneProMapper;
|
|
|
-import com.fdkankan.scene.service.ISceneProAppService;
|
|
|
-import com.fdkankan.scene.service.ISceneProEditExtService;
|
|
|
-import com.fdkankan.scene.service.ISceneProEditService;
|
|
|
-import com.fdkankan.scene.service.ISceneProService;
|
|
|
+import com.fdkankan.scene.service.*;
|
|
|
import com.fdkankan.scene.vo.SceneEditVO;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
@@ -50,6 +53,7 @@ import java.io.StringWriter;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -86,6 +90,12 @@ public class SceneProAppServiceImpl extends ServiceImpl<ISceneProMapper, ScenePr
|
|
|
RedisLockUtil redisLockUtil;
|
|
|
@Autowired
|
|
|
ISceneProEditExtService sceneProEditExtService;
|
|
|
+ @Autowired
|
|
|
+ private PlatformGoodsClient platformGoodsClient;
|
|
|
+ @Autowired
|
|
|
+ private PlatformUserClient platformUserClient;
|
|
|
+ @Autowired
|
|
|
+ private ISceneCooperationService sceneCooperationService;
|
|
|
|
|
|
@Override
|
|
|
public ResultData saveInitialPage(SceneEditVO base) throws Exception {
|
|
@@ -1933,6 +1943,7 @@ public class SceneProAppServiceImpl extends ServiceImpl<ISceneProMapper, ScenePr
|
|
|
return sid;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public Page<SceneVO> getAllSceneByPage(@RequestBody UserParamVO param) {
|
|
|
if(StrUtil.isEmpty(param.getAppUserName()) && StrUtil.isEmpty(param.getPhoneNum()) ){
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
@@ -1941,47 +1952,38 @@ public class SceneProAppServiceImpl extends ServiceImpl<ISceneProMapper, ScenePr
|
|
|
Long cameraId = null;
|
|
|
Long userId = null;
|
|
|
Integer cameraType = null;
|
|
|
+
|
|
|
//获取相机id
|
|
|
if(!StrUtil.isEmpty(param.getAppUserName()) && !StrUtil.isEmpty(param.getAppPassword())){
|
|
|
- Result result = goodsService.findByChildNameAndChildPassword(param.getAppUserName(), param.getAppPassword());
|
|
|
- if (result.getCode() == Result.CODE_FAILURE){
|
|
|
- return result;
|
|
|
- }
|
|
|
- CameraEntity cameraEntity = mapper.convertValue(result.getData(), CameraEntity.class);
|
|
|
- if(cameraEntity == null){
|
|
|
+ ResultData<Camera> cameraResult = platformGoodsClient.getByChildNameAndChildPassword(param.getAppUserName(), param.getAppPassword());
|
|
|
+ Camera camera = cameraResult.getData();
|
|
|
+ if (camera == null) {
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
|
|
|
}
|
|
|
-
|
|
|
- cameraId = cameraEntity.getId();
|
|
|
+ cameraId = camera.getId();
|
|
|
}
|
|
|
|
|
|
//获取该用户id协作者的场景码集合
|
|
|
List<String> sceneCodeList = null;
|
|
|
if (StrUtil.isNotEmpty(param.getPhoneNum())) {
|
|
|
- paramEntity paramEntity = paramService.findparamByparamName(param.getPhoneNum());
|
|
|
-
|
|
|
- if (paramEntity == null) {
|
|
|
+ ResultData<User> userResult = platformUserClient.getUserByName(param.getPhoneNum());
|
|
|
+ User user = userResult.getData();
|
|
|
+ if (user == null) {
|
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_3015);
|
|
|
}
|
|
|
- userId = paramEntity.getId();
|
|
|
-
|
|
|
- Condition condition = new Condition(SceneCooperationEntity.class);
|
|
|
- condition.and().andEqualTo("userId", userId);
|
|
|
- condition.orderBy("id").desc();
|
|
|
- List<SceneCooperationEntity> list = sceneCooperationService.findAll(condition);
|
|
|
-
|
|
|
- if(list == null || list.size() > 0){
|
|
|
- sceneCodeList = Lists.newArrayList();
|
|
|
- SceneCooperation cooperation = null;
|
|
|
- list.parallelStream().map()
|
|
|
- for(int i = 0, len = list.size(); i < len; i++){
|
|
|
- cooperation = list.get(i);
|
|
|
- if(i != len - 1){
|
|
|
- sceneCodeList.add(cooperation.getSceneCode())
|
|
|
- }else {
|
|
|
- nums.append("'").append(cooperation.getSceneCode()).append("'");
|
|
|
- }
|
|
|
- }
|
|
|
+ userId = user.getId();
|
|
|
+
|
|
|
+ List<SceneCooperation> list = sceneCooperationService.list(
|
|
|
+ new LambdaQueryWrapper<SceneCooperation>()
|
|
|
+ .eq(SceneCooperation::getTbStatus, TbStatus.VALID.code())
|
|
|
+ .eq(SceneCooperation::getRecStatus, RecStatus.VALID.code())
|
|
|
+ .eq(SceneCooperation::getUserId, userId)
|
|
|
+ .orderByDesc(SceneCooperation::getId));
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(list)){
|
|
|
+ sceneCodeList = list.parallelStream().map(co -> {
|
|
|
+ return co.getSceneCode();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1990,63 +1992,95 @@ public class SceneProAppServiceImpl extends ServiceImpl<ISceneProMapper, ScenePr
|
|
|
}
|
|
|
|
|
|
Camera camera = null;
|
|
|
- CameraDetail cameraDetailEntity = null;
|
|
|
- Page<SceneVO> sceneVOIPage = sceneProService.getAppAllSceneByPage(cameraId, userId, cameraType, param.getPageNum(), param.getPageSize(), param.getOrderBy(), param.getSceneType(), nums.toString(), param.getSceneName());
|
|
|
- if(sceneVOIPage.getCurrent() == 0){
|
|
|
- return sceneVOIPage;
|
|
|
- }
|
|
|
- for(ResponseScene responseScene : sceneVOIPage.getList()){
|
|
|
+ CameraDetail cameraDetail = null;
|
|
|
+ Page<SceneVO> sceneVOPage =
|
|
|
+ sceneProService.getAppAllSceneByPage(cameraId, userId, cameraType,
|
|
|
+ param.getPageNum(), param.getPageSize(), param.getOrderBy(),
|
|
|
+ param.getSceneType(), sceneCodeList, param.getSceneName());
|
|
|
+ if(sceneVOPage.getCurrent() == 0){
|
|
|
+ return sceneVOPage;
|
|
|
+ }
|
|
|
+ for(SceneVO sceneVO : sceneVOPage.getRecords()){
|
|
|
// 当计算时,返回给前端的状态为计算中
|
|
|
- if (!ObjectUtils.isEmpty(responseScene)) {
|
|
|
- if (responseScene.getStatus() == -1) {
|
|
|
- responseScene.setStatus(0);
|
|
|
- } else if (responseScene.getStatus() == 500) {
|
|
|
- responseScene.setStatus(-1);
|
|
|
+ if (!ObjectUtils.isEmpty(sceneVO)) {
|
|
|
+ if (sceneVO.getStatus() == -1) {
|
|
|
+ sceneVO.setStatus(0);
|
|
|
+ } else if (sceneVO.getStatus() == 500) {
|
|
|
+ sceneVO.setStatus(-1);
|
|
|
}
|
|
|
}
|
|
|
//相机id为空是123看房的场景
|
|
|
- if(responseScene.getCameraId() == null){
|
|
|
+ if(sceneVO.getCameraId() == null){
|
|
|
//当场景用户id等于该用户id,为用户场景,其余未协作场景
|
|
|
- if(responseScene.getUserId().longValue() == userId.longValue()){
|
|
|
- responseScene.setSceneSourceType(1);
|
|
|
+ if(sceneVO.getUserId().longValue() == userId.longValue()){
|
|
|
+ sceneVO.setSceneSourceType(1);
|
|
|
}else {
|
|
|
- responseScene.setSceneSourceType(2);
|
|
|
+ sceneVO.setSceneSourceType(2);
|
|
|
}
|
|
|
}else {
|
|
|
- camera = goodsService.findCameraById(responseScene.getCameraId());
|
|
|
- if(camera != null){
|
|
|
- responseScene.setChildName(camera.getChildName());
|
|
|
- responseScene.setSnCode(camera.getSnCode());
|
|
|
-
|
|
|
- cameraDetailEntity = goodsService.findCameraDetailByCameraId(camera.getId());
|
|
|
- if(cameraDetailEntity != null){
|
|
|
- //相机的userId为空,表示相机的场景
|
|
|
- if(cameraDetailEntity.getUserId() == null || userId == null){
|
|
|
- responseScene.setSceneSourceType(0);
|
|
|
- }else if(userId != null && cameraDetailEntity.getUserId().longValue() == userId.longValue()){
|
|
|
- //相机用户id等于该用户id,既为用户的场景
|
|
|
- responseScene.setSceneSourceType(1);
|
|
|
- }else if(cameraId != null && cameraDetailEntity.getCameraId() != null && cameraDetailEntity.getCameraId().longValue() == cameraId.longValue()
|
|
|
- && cameraDetailEntity.getCooperationparam() == null){
|
|
|
- //场景相机id等于该相机id
|
|
|
- responseScene.setSceneSourceType(0);
|
|
|
- }else if(cameraId != null && cameraDetailEntity.getCameraId().longValue() == cameraId.longValue()
|
|
|
- && cameraDetailEntity.getCooperationparam() != null){
|
|
|
- if(userId != null && cameraDetailEntity.getCooperationparam().longValue() == userId.longValue()){
|
|
|
- responseScene.setSceneSourceType(2);
|
|
|
- }else {
|
|
|
- responseScene.setSceneSourceType(0);
|
|
|
- }
|
|
|
+ ResultData<Camera> cameraResult = platformGoodsClient.getCameraById(sceneVO.getCameraId());
|
|
|
+ camera = cameraResult.getData();
|
|
|
+ if(Objects.isNull(camera)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sceneVO.setChildName(camera.getChildName());
|
|
|
+ sceneVO.setSnCode(camera.getSnCode());
|
|
|
+
|
|
|
+ ResultData<CameraDetail> cameraDetailResult = platformGoodsClient.getCameraDetailByCameraId(camera.getId());
|
|
|
+ cameraDetail = cameraDetailResult.getData();
|
|
|
+ if(cameraDetail != null){
|
|
|
+ //相机的userId为空,表示相机的场景
|
|
|
+ if(cameraDetail.getUserId() == null || userId == null){
|
|
|
+ sceneVO.setSceneSourceType(0);
|
|
|
+ }else if(userId != null && cameraDetail.getUserId().longValue() == userId.longValue()){
|
|
|
+ //相机用户id等于该用户id,既为用户的场景
|
|
|
+ sceneVO.setSceneSourceType(1);
|
|
|
+ }else if(cameraId != null && cameraDetail.getCameraId() != null && cameraDetail.getCameraId().longValue() == cameraId.longValue()
|
|
|
+ && cameraDetail.getCooperationUser() == null){
|
|
|
+ //场景相机id等于该相机id
|
|
|
+ sceneVO.setSceneSourceType(0);
|
|
|
+ }else if(cameraId != null && cameraDetail.getCameraId().longValue() == cameraId.longValue()
|
|
|
+ && cameraDetail.getCooperationUser() != null){
|
|
|
+ if(userId != null && cameraDetail.getCooperationUser().longValue() == userId.longValue()){
|
|
|
+ sceneVO.setSceneSourceType(2);
|
|
|
}else {
|
|
|
- //最后不等于则为协作者场景
|
|
|
- responseScene.setSceneSourceType(2);
|
|
|
+ sceneVO.setSceneSourceType(0);
|
|
|
}
|
|
|
+ }else {
|
|
|
+ //最后不等于则为协作者场景
|
|
|
+ sceneVO.setSceneSourceType(2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return ResultData.ok(pageInfo);
|
|
|
+ return sceneVOPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SceneVO> getAllForCameraName(@RequestBody UserParamVO user){
|
|
|
+ if(StrUtil.isEmpty(user.getAppUserName()) || StrUtil.isEmpty(user.getAppPassword())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
+ }
|
|
|
+ ResultData<Camera> cameraResult = platformGoodsClient.getByChildNameAndChildPassword(user.getAppUserName(), user.getAppPassword());
|
|
|
+ Camera camera = cameraResult.getData();
|
|
|
+ if (camera == null) {
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3014);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ScenePro> list = sceneProService.list(
|
|
|
+ new LambdaQueryWrapper<ScenePro>()
|
|
|
+ .eq(ScenePro::getTbStatus, TbStatus.VALID.code())
|
|
|
+ .eq(ScenePro::getRecStatus, RecStatus.VALID.code())
|
|
|
+ .eq(ScenePro::getCameraId, camera.getId())
|
|
|
+ .ne(ScenePro::getSceneType, SceneType.YJHZXNFY.code())
|
|
|
+ .in(ScenePro::getSceneStatus, SceneStatus.SUCCESS, SceneStatus.NO_DISPLAY).orderByDesc(ScenePro::getId));
|
|
|
+
|
|
|
+ List<SceneVO> sceneList = sceneProService.convert(list);
|
|
|
+ for(SceneVO sceneVO : sceneList){
|
|
|
+ sceneVO.setChildName(user.getAppUserName());
|
|
|
+ }
|
|
|
+ return sceneList;
|
|
|
}
|
|
|
|
|
|
|