AppCameraController.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.fdkankan.ucenter.controller.app;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fdkankan.ucenter.common.Result;
  4. import com.fdkankan.ucenter.common.ResultData;
  5. import com.fdkankan.ucenter.constant.LoginConstant;
  6. import com.fdkankan.ucenter.service.impl.AppCameraService;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.util.ObjectUtils;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.Map;
  12. import java.util.concurrent.CompletableFuture;
  13. @RestController
  14. @RequestMapping("/ucenter/app/camera")
  15. @Slf4j
  16. public class AppCameraController {
  17. @Autowired
  18. private AppCameraService appCameraService;
  19. @PostMapping("/getCamerasForUser")
  20. public Result getCamerasForUser(@RequestBody JSONObject param ){
  21. String userName = param.get("userName") == null ? null : param.getString("userName");
  22. Integer cameraType = param.get("cameraType") == null ? 4 : param.getInteger("cameraType");
  23. return Result.success(appCameraService.getCameraForUser(userName,cameraType));
  24. }
  25. /**
  26. * 绑定相机
  27. */
  28. @PostMapping("/bindCamera")
  29. public Result bindCamera(@RequestBody JSONObject param ){
  30. String userName = param.get("userName") == null ? null : param.getString("userName");
  31. String snCode = param.get("snCode") == null ? null : param.getString("snCode");
  32. return Result.success(appCameraService.bindCamera(userName,snCode));
  33. }
  34. /**
  35. * 解绑相机
  36. */
  37. @PostMapping("/unbind")
  38. public Result unbind(@RequestBody JSONObject param ){
  39. String userName = param.get("userName") == null ? null : param.getString("userName");
  40. String childName = param.get("childName") == null ? null : param.getString("childName");
  41. appCameraService.unbindCamera(userName,childName);
  42. return Result.success();
  43. }
  44. /**
  45. * 获取相机信息
  46. */
  47. @PostMapping("/getCameraInfo")
  48. public Result getCameraInfo(@RequestBody JSONObject param ){
  49. String childName = param.get("childName") == null ? null : param.getString("childName");
  50. String childPassword = param.get("childPassword") == null ? null : param.getString("childPassword");
  51. return Result.success(appCameraService.getCameraInfo(childName,childPassword));
  52. }
  53. /**
  54. * 用户相机信息上报 app 需要调用
  55. */
  56. @RequestMapping(value = "/uploadUserCameraInfo", method = RequestMethod.POST)
  57. public Result uploadUserCameraInfo(@RequestBody Map<String,String> param) throws Exception {
  58. if (ObjectUtils.isEmpty(param) || !param.containsKey("snCode") || !param.containsKey("cameraVersion")
  59. || !param.containsKey("appVersion")) {
  60. return Result.failure(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  61. }
  62. try {
  63. appCameraService.uploadUserCameraInfo(param.get("snCode"),param.get("cameraVersion"),param.get("appVersion"));
  64. }catch ( Exception e){
  65. log.error("uploadUserCameraInfo--snCode:{},cameraVersion:{},appVersion:{},error:{}",
  66. param.get("snCode"),param.get("cameraVersion"),param.get("appVersion"),e);
  67. }
  68. return Result.success();
  69. }
  70. @GetMapping("/checkCameraSpace")
  71. public Result checkCameraSpace(@RequestParam(required = false) String snCode,
  72. @RequestParam(required = false) String unicode){
  73. return Result.success( appCameraService.checkCameraSpace(snCode,unicode));
  74. }
  75. }