|
|
@@ -1,6 +1,7 @@
|
|
|
package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
@@ -8,25 +9,32 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.CommonStatus;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
-import com.fdkankan.common.constant.PayStatus;
|
|
|
-import com.fdkankan.common.constant.SceneStatus;
|
|
|
import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
-import com.fdkankan.common.response.Result;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
|
+import com.fdkankan.common.user.SSOUser;
|
|
|
+import com.fdkankan.common.util.DateExtUtil;
|
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
import com.fdkankan.platform.api.feign.PlatformGoodsClient;
|
|
|
import com.fdkankan.platform.api.feign.PlatformUserClient;
|
|
|
-import com.fdkankan.scene.callback.FdkkMiniReqErrorCallback;
|
|
|
-import com.fdkankan.scene.callback.FdkkMiniReqSuccessCallback;
|
|
|
+import com.fdkankan.scene.entity.Camera;
|
|
|
+import com.fdkankan.scene.entity.CameraDetail;
|
|
|
+import com.fdkankan.scene.entity.SceneCooperation;
|
|
|
import com.fdkankan.scene.entity.ScenePlus;
|
|
|
-import com.fdkankan.scene.entity.SceneProV3;
|
|
|
-import com.fdkankan.scene.httpclient.FdkankanMiniClient;
|
|
|
+import com.fdkankan.scene.entity.SceneResource;
|
|
|
+import com.fdkankan.scene.entity.User;
|
|
|
+import com.fdkankan.scene.entity.UserIncrement;
|
|
|
+import com.fdkankan.scene.service.ICameraDetailService;
|
|
|
+import com.fdkankan.scene.service.ICameraService;
|
|
|
+import com.fdkankan.scene.service.ISceneCooperationService;
|
|
|
import com.fdkankan.scene.service.ISceneEditInfoExtService;
|
|
|
import com.fdkankan.scene.service.ISceneEditInfoService;
|
|
|
import com.fdkankan.scene.service.ISceneEditService;
|
|
|
import com.fdkankan.scene.service.IScenePlusService;
|
|
|
+import com.fdkankan.scene.service.ISceneResourceService;
|
|
|
import com.fdkankan.scene.service.ISceneUploadService;
|
|
|
+import com.fdkankan.scene.service.IUserIncrementService;
|
|
|
+import com.fdkankan.scene.service.IUserService;
|
|
|
import com.fdkankan.scene.vo.BaseDataParamVO;
|
|
|
import com.fdkankan.scene.vo.BaseSceneParamVO;
|
|
|
import com.fdkankan.scene.vo.DeleteFileParamVO;
|
|
|
@@ -35,9 +43,10 @@ import com.fdkankan.scene.vo.SceneAuthVO;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
@@ -51,6 +60,7 @@ import org.springframework.stereotype.Service;
|
|
|
* @author dengsixing
|
|
|
* @since 2022/3/11
|
|
|
**/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@RefreshScope
|
|
|
public class SceneEditServiceImpl implements ISceneEditService {
|
|
|
@@ -78,96 +88,142 @@ public class SceneEditServiceImpl implements ISceneEditService {
|
|
|
@Autowired
|
|
|
private ISceneEditInfoExtService sceneEditInfoExtService;
|
|
|
@Autowired
|
|
|
- private FdkankanMiniClient fdkankanMiniClient;
|
|
|
+ private ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ private IUserIncrementService userIncrementService;
|
|
|
+ @Value("${expected.time}")
|
|
|
+ private String expectedTime;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneCooperationService sceneCooperationService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneResourceService sceneResourceService;
|
|
|
|
|
|
@Override
|
|
|
- public SceneAuthVO getAuth(String num, String token) throws Exception{
|
|
|
-
|
|
|
- // TODO: 2022/5/19 请求v3的接口,获取场景的状态 待v3停机后要换成v4d的逻辑-------------------------start
|
|
|
- String url = fkankanMiniHost + URL_GET_SCENEPRO_BY_NUM + num;
|
|
|
- Result<SceneProV3> result = fdkankanMiniClient
|
|
|
- .getSceneProByNum(url, new FdkkMiniReqSuccessCallback(),
|
|
|
- new FdkkMiniReqErrorCallback());
|
|
|
- SceneProV3 sceneProV3 = result.getData();
|
|
|
- if(sceneProV3 == null || sceneProV3.getId() == null){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ public SceneAuthVO getAuth(String num, SSOUser ssoUser) throws Exception{
|
|
|
+
|
|
|
+ // 解密获得username,用于和数据库进行对比
|
|
|
+ String username = ssoUser.getUserName();
|
|
|
+
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+
|
|
|
+ SceneAuthVO sceneAuthVO = new SceneAuthVO();
|
|
|
+
|
|
|
+ List<SceneResource> exclude = new ArrayList<>();
|
|
|
+ SceneResource excludeEntity = new SceneResource();
|
|
|
+ excludeEntity.setKeyWord("data");
|
|
|
+ exclude.add(excludeEntity);
|
|
|
+
|
|
|
+ Camera camera = cameraService.findByChildName(username);
|
|
|
+ sceneAuthVO.setExclude(exclude);
|
|
|
+ sceneAuthVO.setInclude(new ArrayList<>());
|
|
|
+ sceneAuthVO.setCompany(null);
|
|
|
+
|
|
|
+ //判断该场景是否属于增值权益
|
|
|
+ boolean isVip = false;
|
|
|
+ //获取该相机是否有权益
|
|
|
+ boolean isExpired = false;
|
|
|
+ Camera sceneCamera = cameraService.getById(scenePlus.getCameraId());
|
|
|
+ if(sceneCamera != null){
|
|
|
+ UserIncrement userIncrementEntity = userIncrementService.findByCameraId(sceneCamera.getId());
|
|
|
+
|
|
|
+ if(userIncrementEntity != null){
|
|
|
+ if( userIncrementEntity.getIsExpired().intValue() == 0){
|
|
|
+ isVip = true;
|
|
|
+ }
|
|
|
+ if(userIncrementEntity.getIsExpired().intValue() == 1){
|
|
|
+ isExpired = true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ Date date = DateUtil.parse("2021-09-09 00:00:00", DateExtUtil.dateStyle);
|
|
|
+
|
|
|
+ //非07批次的放开
|
|
|
+ String pc = sceneCamera.getSnCode().substring(0,2);
|
|
|
+ if(!pc.equals("07") ){
|
|
|
+ if(sceneCamera.getCreateTime()!=null && date.after(sceneCamera.getCreateTime())){
|
|
|
+ isVip = true;
|
|
|
+ isExpired = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sceneAuthVO.setIsExpired(isExpired);
|
|
|
+ sceneAuthVO.setIsVip(isVip);
|
|
|
+
|
|
|
+ //判断过期时间
|
|
|
+ Date date = DateUtil.parse(expectedTime, DateExtUtil.dateStyle);
|
|
|
+
|
|
|
+ if(camera != null){
|
|
|
+ if(!scenePlus.getCameraId().equals(camera.getId())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ }
|
|
|
+
|
|
|
+ CameraDetail cameraDetailEntity = cameraDetailService.getByCameraId(camera.getId());
|
|
|
+ if(cameraDetailEntity.getCompanyId() != null){
|
|
|
+ if(cameraDetailEntity.getCompanyId().longValue() == 1 || cameraDetailEntity.getCompanyId().longValue() == 14){
|
|
|
+ sceneAuthVO.setExclude(new ArrayList<>());
|
|
|
+ sceneAuthVO.setCompany(cameraDetailEntity.getCompanyId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sceneAuthVO;
|
|
|
}
|
|
|
- if(sceneProV3.getRecStatus().equals("I")){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5009);
|
|
|
+
|
|
|
+ User user = userService.getByUserName(username);
|
|
|
+ if("18750226207".equals(username)){
|
|
|
+ log.info("18750226207该账号默认超级管理员,可以操作所有场景");
|
|
|
}
|
|
|
- if(SceneStatus.SUCCESS.code() != sceneProV3.getStatus()
|
|
|
- && SceneStatus.NO_DISPLAY.code() != sceneProV3.getStatus()){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
|
|
|
+ else if(user == null || scenePlus.getUserId() == null || user.getId().longValue() != scenePlus.getUserId().longValue()){
|
|
|
+ log.info("user:" + user.getId() + ",scene:" + scenePlus.getUserId());
|
|
|
+
|
|
|
+ List<SceneCooperation> list =
|
|
|
+ sceneCooperationService.list(
|
|
|
+ new LambdaQueryWrapper<SceneCooperation>()
|
|
|
+ .eq(SceneCooperation::getSceneNum, num));
|
|
|
+ if(list != null && list.size() > 0){
|
|
|
+ if(list.get(0).getUserId().longValue() != user.getId().longValue()){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ }
|
|
|
}
|
|
|
- if(PayStatus.PAY.code() != sceneProV3.getPayStatus()){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5034);
|
|
|
+
|
|
|
+ if(scenePlus.getCameraId() != null){
|
|
|
+ camera = cameraService.getById(scenePlus.getCameraId());
|
|
|
+ if(camera != null){
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
|
|
|
+ if(cameraDetail.getCompanyId() != null){
|
|
|
+ if(cameraDetail.getCompanyId().longValue() == 1 || cameraDetail.getCompanyId().longValue() == 14){
|
|
|
+ sceneAuthVO.setExclude(new ArrayList<>());
|
|
|
+ sceneAuthVO.setCompany(cameraDetail.getCompanyId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- // TODO: 2022/5/19 请求v3的接口,获取场景的状态 待v3停机后要换成v4d的逻辑-------------------------send
|
|
|
-
|
|
|
- ScenePlus scenePlus = scenePlusService.getOne(
|
|
|
- new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num)
|
|
|
- .eq(ScenePlus::getPayStatus, PayStatus.PAY.code()));
|
|
|
-// .in(ScenePlus::getSceneStatus, SceneStatus.SUCCESS.code(), SceneStatus.NO_DISPLAY.code()));
|
|
|
- if(scenePlus == null){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+
|
|
|
+ //权限控制完后判断若是协作账号,获取协作权限
|
|
|
+ SceneCooperation sceneCooperation = sceneCooperationService.getByNum(num);
|
|
|
+ //若数据为空表示可操作全部资源
|
|
|
+ if(sceneCooperation == null || sceneCooperation.getUserId().longValue() != ssoUser.getId().longValue()){
|
|
|
+ return sceneAuthVO;
|
|
|
}
|
|
|
- if(scenePlus.getSceneStatus() == SceneStatus.FAILD.code()
|
|
|
- || scenePlus.getSceneStatus() == SceneStatus.wait.code()){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
|
|
|
+
|
|
|
+ if(scenePlus.getUserId()!= null && sceneCooperation.getUserId()!= null &&
|
|
|
+ scenePlus.getUserId().equals(sceneCooperation.getUserId())){
|
|
|
+ return sceneAuthVO;
|
|
|
}
|
|
|
- //判断该场景是否属于增值权益
|
|
|
- boolean isVip = false;
|
|
|
- //获取该相机是否有权益
|
|
|
- boolean isExpired = false;
|
|
|
-// ResultData<Camera> cameraResultData = platformGoodsClient.getCameraById(scenePlus.getCameraId());
|
|
|
-// if(!cameraResultData.getSuccess()){
|
|
|
-// throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
-// }
|
|
|
-// Camera camera = cameraResultData.getData();
|
|
|
-// if(camera != null){
|
|
|
-// ResultData<UserIncrement> incrementResultData = platformUserClient
|
|
|
-// .getUserIncrementByCameraId(camera.getId());
|
|
|
-// if(!incrementResultData.getSuccess()){
|
|
|
-// throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
-// }
|
|
|
-// UserIncrement userIncrement = incrementResultData.getData();
|
|
|
-// if(userIncrement != null){
|
|
|
-// if( userIncrement.getIsExpired().intValue() == 0){
|
|
|
-// isVip = true;
|
|
|
-// }
|
|
|
-// if(userIncrement.getIsExpired().intValue() == 1){
|
|
|
-// isExpired = true;
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// Date date = DateUtil.parse("2021-09-09 00:00:00", DateExtUtil.dateStyle);
|
|
|
-//
|
|
|
-// //非07批次的放开
|
|
|
-// String pc = camera.getSnCode().substring(0,2);
|
|
|
-// if(!pc.equals("07") ){
|
|
|
-// if(camera.getCreateTime()!=null && date.after(camera.getCreateTime())){
|
|
|
-// isVip = true;
|
|
|
-// isExpired = false;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
- // TODO: 2022/4/25 v3v4共存过渡期结束需要删除,恢复上面注释内容 ------------------------------------------start
|
|
|
- url = fkankanMiniHost + URL_ISLOGIN + num;
|
|
|
- Result<Map<String, Object>> isLoginResult = fdkankanMiniClient
|
|
|
- .getIsLogin(url, token, new FdkkMiniReqSuccessCallback(),
|
|
|
- new FdkkMiniReqErrorCallback());
|
|
|
- Map<String, Object> data = isLoginResult.getData();
|
|
|
- isVip = (boolean)data.get("isIncrement");
|
|
|
- isExpired = (boolean)data.get("isExpired");
|
|
|
- Integer company = data.get("company") == null ? null : (int)data.get("company");
|
|
|
- // TODO: 2022/4/25 v3v4共存过渡期结束需要删除,恢复上面注释内容 ------------------------------------------end
|
|
|
-
|
|
|
- return SceneAuthVO.builder()
|
|
|
- .isExpired(isExpired).isVip(isVip)
|
|
|
- .company(company)
|
|
|
- .exclude(data.get("exclude"))
|
|
|
- .include(data.get("include"))
|
|
|
- .build();
|
|
|
+
|
|
|
+ sceneAuthVO.setInclude(sceneResourceService.findByCooperationId(sceneCooperation.getId()));
|
|
|
+
|
|
|
+ return sceneAuthVO;
|
|
|
}
|
|
|
|
|
|
@Override
|