|
@@ -2,6 +2,7 @@ package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.model.SSOUser;
|
|
@@ -9,12 +10,28 @@ import com.fdkankan.common.response.ResultData;
|
|
|
import com.fdkankan.common.user.SSOLoginHelper;
|
|
|
import com.fdkankan.common.util.DateUtil;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.scene.entity.Camera;
|
|
|
+import com.fdkankan.scene.entity.CameraDetail;
|
|
|
+import com.fdkankan.scene.entity.SceneCooperation;
|
|
|
+import com.fdkankan.scene.entity.ScenePro;
|
|
|
+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.ISceneProService;
|
|
|
+import com.fdkankan.scene.service.ISceneResourceService;
|
|
|
import com.fdkankan.scene.service.ISceneService;
|
|
|
+import com.fdkankan.scene.service.IUserIncrementService;
|
|
|
+import com.fdkankan.scene.service.IUserService;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
/**
|
|
@@ -25,147 +42,162 @@ import org.springframework.stereotype.Service;
|
|
|
* @author dengsixing
|
|
|
* @since 2022/7/4
|
|
|
**/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class SceneServiceImpl implements ISceneService {
|
|
|
|
|
|
@Autowired
|
|
|
- private SSOLoginHelper ssoLoginHelper;
|
|
|
+ private ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraService cameraService;
|
|
|
+ @Autowired
|
|
|
+ private IUserIncrementService userIncrementService;
|
|
|
+ @Autowired
|
|
|
+ private ICameraDetailService cameraDetailService;
|
|
|
+ @Autowired
|
|
|
+ private IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneCooperationService sceneCooperationService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneResourceService sceneResourceService;
|
|
|
|
|
|
- @Override
|
|
|
- public ResultData isLogin(String num, String token) throws Exception {
|
|
|
+ @Value("${expected.time}")
|
|
|
+ private String expectedTime;
|
|
|
|
|
|
- SSOUser ssoUser = ssoLoginHelper.loginCheckV3(token);
|
|
|
+ @Override
|
|
|
+ public ResultData isLogin(String num, SSOUser ssoUser) throws Exception {
|
|
|
|
|
|
// 解密获得username,用于和数据库进行对比
|
|
|
- String username = JwtUtil.getUsername(token);
|
|
|
-
|
|
|
-// SceneProEntity sceneProEntity = sceneProService.findBySceneNum(num);
|
|
|
-// if(sceneProEntity == null){
|
|
|
-// throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
-// }
|
|
|
-// if(sceneProEntity.getPayStatus() != 1){
|
|
|
-// throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
-// }
|
|
|
-// if(sceneProEntity.getStatus() != 1 && sceneProEntity.getStatus() != -2){
|
|
|
-// throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
-// }
|
|
|
-//
|
|
|
-// JSONObject jsonObject = new JSONObject();
|
|
|
-//
|
|
|
-// List<SceneResourceEntity> exclude = new ArrayList<>();
|
|
|
-// SceneResourceEntity excludeEntity = new SceneResourceEntity();
|
|
|
-// excludeEntity.setKeyWord("data");
|
|
|
-// exclude.add(excludeEntity);
|
|
|
-//
|
|
|
-// CameraEntity cameraEntity = goodsService.findByChildName(username);
|
|
|
-// jsonObject.put("exclude", exclude);
|
|
|
-// jsonObject.put("include", new ArrayList<>());
|
|
|
-// jsonObject.put("company", null);
|
|
|
-// Result result = Result.success(jsonObject);
|
|
|
-//
|
|
|
-// //判断该场景是否属于增值权益
|
|
|
-// boolean isIncrement = false;
|
|
|
-// //获取该相机是否有权益
|
|
|
-// boolean isExpired = false;
|
|
|
-// CameraEntity sceneCamera = goodsService.findCameraById(sceneProEntity.getCameraId());
|
|
|
-// if(sceneCamera != null){
|
|
|
-// UserIncrementEntity userIncrementEntity = userIncrementService.findByCameraId(sceneCamera.getId());
|
|
|
-//
|
|
|
-// if(userIncrementEntity != null){
|
|
|
-// if( userIncrementEntity.getIsExpired().intValue() == 0){
|
|
|
-// isIncrement = true;
|
|
|
-// }
|
|
|
-// if(userIncrementEntity.getIsExpired().intValue() == 1){
|
|
|
-// isExpired = true;
|
|
|
-// }
|
|
|
-// }else{
|
|
|
-// try {
|
|
|
-// Date date = DateUtil.string2Date("2021-09-09 00:00:00",null);
|
|
|
-//
|
|
|
-// //非07批次的放开
|
|
|
-// String pc = sceneCamera.getSnCode().substring(0,2);
|
|
|
-// if(!pc.equals("07") ){
|
|
|
-// if(sceneCamera.getCreateTime()!=null && date.after(sceneCamera.getCreateTime())){
|
|
|
-//
|
|
|
-// isIncrement = true;
|
|
|
-// isExpired = false;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }catch (Exception e){
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// jsonObject.put("isExpired", isExpired );
|
|
|
-// jsonObject.put("isIncrement", isIncrement);
|
|
|
-//
|
|
|
-// //判断过期时间
|
|
|
-// Date date = DateUtil.string2Date(expectedTime,null);
|
|
|
-//
|
|
|
-// jsonObject.put("isTransition",DateUtil.isBeforeNow2(date));
|
|
|
-//
|
|
|
-//
|
|
|
-// if(cameraEntity != null){
|
|
|
-// if(!sceneProEntity.getCameraId().equals(cameraEntity.getId())){
|
|
|
-// throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5014, SceneConstant.FAILURE_MSG_5014);
|
|
|
-// }
|
|
|
-//
|
|
|
-// CameraDetailEntity cameraDetailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
|
|
|
-// if(cameraDetailEntity.getCompanyId() != null){
|
|
|
-// if(cameraDetailEntity.getCompanyId().longValue() == 1 || cameraDetailEntity.getCompanyId().longValue() == 14){
|
|
|
-// jsonObject.put("exclude", new ArrayList<>());
|
|
|
-// jsonObject.put("company", cameraDetailEntity.getCompanyId().longValue());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-//
|
|
|
-// UserEntity userEntity = userService.findUserByUserName(username);
|
|
|
-// if("18750226207".equals(username)){
|
|
|
-// log.info("18750226207该账号默认超级管理员,可以操作所有场景");
|
|
|
-// }
|
|
|
-// else if(userEntity == null || sceneProEntity.getUserId() == null || userEntity.getId().longValue() != sceneProEntity.getUserId().longValue()){
|
|
|
-// log.info("user:" + userEntity.getId() + ",scene:" + sceneProEntity.getUserId());
|
|
|
-//
|
|
|
-// Condition condition = new Condition(SceneCooperationEntity.class);
|
|
|
-// condition.and().andEqualTo("sceneNum", num);
|
|
|
-// List<SceneCooperationEntity> list = sceneCooperationService.findAll(condition);
|
|
|
-// if(list != null && list.size() > 0){
|
|
|
-// if(list.get(0).getUserId().longValue() != userEntity.getId().longValue()){
|
|
|
-// throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5014, SceneConstant.FAILURE_MSG_5014);
|
|
|
-// }
|
|
|
-// }else {
|
|
|
-// throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5014, SceneConstant.FAILURE_MSG_5014);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(sceneProEntity.getCameraId() != null){
|
|
|
-// cameraEntity = goodsService.findCameraById(sceneProEntity.getCameraId());
|
|
|
-// if(cameraEntity != null){
|
|
|
-// CameraDetailEntity cameraDetailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
|
|
|
-// if(cameraDetailEntity.getCompanyId() != null){
|
|
|
-// if(cameraDetailEntity.getCompanyId().longValue() == 1 || cameraDetailEntity.getCompanyId().longValue() == 14){
|
|
|
-// jsonObject.put("exclude", new ArrayList<>());
|
|
|
-// jsonObject.put("company", cameraDetailEntity.getCompanyId().longValue());
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //权限控制完后判断若是协作账号,获取协作权限
|
|
|
-// SceneCooperationEntity sceneCooperationEntity = sceneCooperationService.findBySceneNum(num);
|
|
|
-// //若数据为空表示可操作全部资源
|
|
|
-// if(sceneCooperationEntity == null || sceneCooperationEntity.getUserId().longValue() != ssoUser.getId().longValue()){
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-//
|
|
|
-// if(sceneProEntity.getUserId()!= null && sceneCooperationEntity.getUserId()!= null &&
|
|
|
-// sceneProEntity.getUserId().equals(sceneCooperationEntity.getUserId())){
|
|
|
-// return result;
|
|
|
-// }
|
|
|
-
|
|
|
-// jsonObject.put("include", sceneResourceService.findByCooperationId(sceneCooperationEntity.getId()));
|
|
|
+ String username = ssoUser.getUserName();
|
|
|
+
|
|
|
+ ScenePro sceneProEntity = sceneProService.findBySceneNum(num);
|
|
|
+ if(sceneProEntity == null){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ if(sceneProEntity.getPayStatus() != 1){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ if(sceneProEntity.getStatus() != 1 && sceneProEntity.getStatus() != -2){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+
|
|
|
+ List<SceneResource> exclude = new ArrayList<>();
|
|
|
+ SceneResource excludeEntity = new SceneResource();
|
|
|
+ excludeEntity.setKeyWord("data");
|
|
|
+ exclude.add(excludeEntity);
|
|
|
+
|
|
|
+ Camera camera = cameraService.findByChildName(username);
|
|
|
+ jsonObject.put("exclude", exclude);
|
|
|
+ jsonObject.put("include", new ArrayList<>());
|
|
|
+ jsonObject.put("company", null);
|
|
|
+ ResultData result = ResultData.ok(jsonObject);
|
|
|
+
|
|
|
+ //判断该场景是否属于增值权益
|
|
|
+ boolean isIncrement = false;
|
|
|
+ //获取该相机是否有权益
|
|
|
+ boolean isExpired = false;
|
|
|
+ Camera sceneCamera = cameraService.getById(sceneProEntity.getCameraId());
|
|
|
+ if(sceneCamera != null){
|
|
|
+ UserIncrement userIncrementEntity = userIncrementService.findByCameraId(sceneCamera.getId());
|
|
|
+
|
|
|
+ if(userIncrementEntity != null){
|
|
|
+ if( userIncrementEntity.getIsExpired().intValue() == 0){
|
|
|
+ isIncrement = true;
|
|
|
+ }
|
|
|
+ if(userIncrementEntity.getIsExpired().intValue() == 1){
|
|
|
+ isExpired = true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ Date date = DateUtil.string2Date("2021-09-09 00:00:00",null);
|
|
|
+
|
|
|
+ //非07批次的放开
|
|
|
+ String pc = sceneCamera.getSnCode().substring(0,2);
|
|
|
+ if(!pc.equals("07") ){
|
|
|
+ if(sceneCamera.getCreateTime()!=null && date.after(sceneCamera.getCreateTime())){
|
|
|
+
|
|
|
+ isIncrement = true;
|
|
|
+ isExpired = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ jsonObject.put("isExpired", isExpired );
|
|
|
+ jsonObject.put("isIncrement", isIncrement);
|
|
|
+
|
|
|
+ //判断过期时间
|
|
|
+ Date date = DateUtil.string2Date(expectedTime,null);
|
|
|
+
|
|
|
+ jsonObject.put("isTransition",DateUtil.isBeforeNow2(date));
|
|
|
+
|
|
|
+
|
|
|
+ if(camera != null){
|
|
|
+ if(!sceneProEntity.getCameraId().equals(camera.getId())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5014);
|
|
|
+ }
|
|
|
+
|
|
|
+ CameraDetail cameraDetailEntity = cameraDetailService.findByCameraId(camera.getId());
|
|
|
+ if(cameraDetailEntity.getCompanyId() != null){
|
|
|
+ if(cameraDetailEntity.getCompanyId().longValue() == 1 || cameraDetailEntity.getCompanyId().longValue() == 14){
|
|
|
+ jsonObject.put("exclude", new ArrayList<>());
|
|
|
+ jsonObject.put("company", cameraDetailEntity.getCompanyId().longValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ User user = userService.findByUserName(username);
|
|
|
+ if("18750226207".equals(username)){
|
|
|
+ log.info("18750226207该账号默认超级管理员,可以操作所有场景");
|
|
|
+ }
|
|
|
+ else if(user == null || sceneProEntity.getUserId() == null || user.getId().longValue() != sceneProEntity.getUserId().longValue()){
|
|
|
+ log.info("user:" + user.getId() + ",scene:" + sceneProEntity.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(sceneProEntity.getCameraId() != null){
|
|
|
+ camera = cameraService.getById(sceneProEntity.getCameraId());
|
|
|
+ if(camera != null){
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.findByCameraId(camera.getId());
|
|
|
+ if(cameraDetail.getCompanyId() != null){
|
|
|
+ if(cameraDetail.getCompanyId().longValue() == 1 || cameraDetail.getCompanyId().longValue() == 14){
|
|
|
+ jsonObject.put("exclude", new ArrayList<>());
|
|
|
+ jsonObject.put("company", cameraDetail.getCompanyId().longValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //权限控制完后判断若是协作账号,获取协作权限
|
|
|
+ SceneCooperation sceneCooperation = sceneCooperationService.getByNum(num);
|
|
|
+ //若数据为空表示可操作全部资源
|
|
|
+ if(sceneCooperation == null || sceneCooperation.getUserId().longValue() != ssoUser.getId().longValue()){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(sceneProEntity.getUserId()!= null && sceneCooperation.getUserId()!= null &&
|
|
|
+ sceneProEntity.getUserId().equals(sceneCooperation.getUserId())){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ jsonObject.put("include", sceneResourceService.findByCooperationId(sceneCooperation.getId()));
|
|
|
|
|
|
return ResultData.ok();
|
|
|
}
|