AppCameraController.java 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. if(cameraType == 4){
  24. cameraType = 1;
  25. }
  26. return Result.success(appCameraService.getCameraForUser(userName,cameraType));
  27. }
  28. /**
  29. * 绑定相机
  30. */
  31. @PostMapping("/bindCamera")
  32. public Result bindCamera(@RequestBody JSONObject param ){
  33. String userName = param.get("userName") == null ? null : param.getString("userName");
  34. String snCode = param.get("snCode") == null ? null : param.getString("snCode");
  35. return Result.success(appCameraService.bindCamera(userName,snCode));
  36. }
  37. /**
  38. * 解绑相机
  39. */
  40. @PostMapping("/unbind")
  41. public Result unbind(@RequestBody JSONObject param ){
  42. String userName = param.get("userName") == null ? null : param.getString("userName");
  43. String childName = param.get("childName") == null ? null : param.getString("childName");
  44. appCameraService.unbindCamera(userName,childName);
  45. return Result.success();
  46. }
  47. /**
  48. * 获取相机信息
  49. */
  50. @PostMapping("/getCameraInfo")
  51. public Result getCameraInfo(@RequestBody JSONObject param ){
  52. String childName = param.get("childName") == null ? null : param.getString("childName");
  53. String childPassword = param.get("childPassword") == null ? null : param.getString("childPassword");
  54. return Result.success(appCameraService.getCameraInfo(childName,childPassword));
  55. }
  56. /**
  57. * 用户相机信息上报 app 需要调用
  58. */
  59. @RequestMapping(value = "/uploadUserCameraInfo", method = RequestMethod.POST)
  60. public Result uploadUserCameraInfo(@RequestBody Map<String,String> param) throws Exception {
  61. if (ObjectUtils.isEmpty(param) || !param.containsKey("snCode") || !param.containsKey("cameraVersion")
  62. || !param.containsKey("appVersion")) {
  63. return Result.failure(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
  64. }
  65. try {
  66. appCameraService.uploadUserCameraInfo(param.get("snCode"),param.get("cameraVersion"),param.get("appVersion"));
  67. }catch ( Exception e){
  68. log.error("uploadUserCameraInfo--snCode:{},cameraVersion:{},appVersion:{},error:{}",
  69. param.get("snCode"),param.get("cameraVersion"),param.get("appVersion"),e);
  70. }
  71. return Result.success();
  72. }
  73. @GetMapping("/checkCameraSpace")
  74. public Result checkCameraSpace(@RequestParam(required = false) String snCode,
  75. @RequestParam(required = false) String unicode){
  76. return Result.success( appCameraService.checkCameraSpace(snCode,unicode));
  77. }
  78. }