AppCameraController.java 2.9 KB

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