FdUserCameraController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.fdkankan.ucenter.controller.fire;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fdkankan.common.constant.AppConstant;
  4. import com.fdkankan.common.exception.BusinessException;
  5. import com.fdkankan.common.util.JwtUtil;
  6. import com.fdkankan.ucenter.common.BaseController;
  7. import com.fdkankan.ucenter.common.Result;
  8. import com.fdkankan.ucenter.constant.CameraConstant;
  9. import com.fdkankan.ucenter.constant.LoginConstant;
  10. import com.fdkankan.ucenter.entity.Camera;
  11. import com.fdkankan.ucenter.entity.CameraDetail;
  12. import com.fdkankan.ucenter.entity.User;
  13. import com.fdkankan.ucenter.service.ICameraDetailService;
  14. import com.fdkankan.ucenter.service.ICameraService;
  15. import com.fdkankan.ucenter.service.IUserService;
  16. import com.fdkankan.ucenter.vo.request.CameraDetailParam;
  17. import com.fdkankan.ucenter.vo.response.CameraVo;
  18. import lombok.extern.log4j.Log4j2;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.util.ObjectUtils;
  21. import org.springframework.util.StringUtils;
  22. import org.springframework.web.bind.annotation.*;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.List;
  26. @Log4j2
  27. /**火调-绑定相机*/
  28. @RestController
  29. @RequestMapping("/fd/ucenter/user/camera")
  30. public class FdUserCameraController extends BaseController {
  31. @Autowired
  32. private IUserService userService;
  33. @Autowired
  34. private ICameraService cameraService;
  35. @Autowired
  36. private ICameraDetailService cameraDetailService;
  37. /**
  38. * 用户添加设备
  39. */
  40. @RequestMapping(value = "/add", method = RequestMethod.POST)
  41. public Result addCamera(@RequestBody JSONObject param) throws Exception {
  42. if(ObjectUtils.isEmpty(param.getString("snCode"))){
  43. throw new BusinessException(-1,"缺少必要参数");
  44. }
  45. String snCode = param.getString("snCode");
  46. String userName = param.getString("userName");
  47. String platform = param.getString("platform");
  48. if(StringUtils.isEmpty(userName)){
  49. userName = JwtUtil.getUsername(getToken());
  50. }
  51. Camera cameraEntity = cameraService.getBySnCode(snCode);
  52. if(ObjectUtils.isEmpty(cameraEntity)){
  53. throw new BusinessException(CameraConstant.FAILURE_CODE_6020,CameraConstant.FAILURE_MSG_6020);
  54. }
  55. CameraDetail cameraDetailEntity = cameraDetailService.getByCameraId(cameraEntity.getId());
  56. if(ObjectUtils.isEmpty(cameraDetailEntity)){
  57. throw new BusinessException(CameraConstant.FAILURE_CODE_6020,CameraConstant.FAILURE_MSG_6020);
  58. }
  59. if (ObjectUtils.isEmpty(cameraDetailEntity.getCompanyId()) ) {
  60. throw new BusinessException(CameraConstant.FAILURE_CODE_6005, CameraConstant.FAILURE_MSG_6005);
  61. }
  62. if(!StringUtils.isEmpty(platform) && "fusion".equals(platform) && !cameraDetailEntity.getCompanyId().equals(25L)){
  63. throw new BusinessException(CameraConstant.FAILURE_CODE_6005, CameraConstant.FAILURE_MSG_6005);
  64. }
  65. if(!StringUtils.isEmpty(platform) && "sp".equals(platform) && !cameraDetailEntity.getCompanyId().equals(26L)){
  66. throw new BusinessException(CameraConstant.FAILURE_CODE_6005, CameraConstant.FAILURE_MSG_6005);
  67. }
  68. if(cameraDetailEntity.getUserId() != null){
  69. User user = userService.getByUserName(userName);
  70. if(user != null){
  71. if(cameraDetailEntity.getUserId().equals(user.getId())){
  72. return Result.success();
  73. }
  74. }
  75. throw new BusinessException(AppConstant.FAILURE_CODE_4011, AppConstant.FAILURE_MSG_4011);
  76. }
  77. // 绑定相机
  78. cameraService.bind(cameraDetailEntity.getType(),cameraEntity.getSnCode(), userName);
  79. return Result.success();
  80. }
  81. /**
  82. * 获取用户设备
  83. * @return
  84. */
  85. @PostMapping(value = "/details")
  86. public Result detail(@RequestBody CameraDetailParam param) {
  87. if(StringUtils.isEmpty(param.getChildName()) && param.getChildNames().size() <=0){
  88. return Result.success(new ArrayList<>());
  89. }
  90. if(param.getChildNames().size() <=0){
  91. param.setChildNames(Arrays.asList(param.getChildName()));
  92. }
  93. List<CameraVo> list = new ArrayList<>();
  94. for (String childName : param.getChildNames()) {
  95. CameraVo vo = userService.findCameraDetailByChildName(getToken(), childName);
  96. if(vo == null){
  97. continue;
  98. }
  99. vo.setUsedSpace(null);
  100. vo.setTotalSpace(null);
  101. list.add(vo);
  102. }
  103. return Result.success(list);
  104. }
  105. }