InnerController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package com.fdkankan.ucenter.controller.inner;
  2. import com.fdkankan.common.constant.ErrorCode;
  3. import com.fdkankan.common.exception.BusinessException;
  4. import com.fdkankan.sign.SignUtils;
  5. import com.fdkankan.ucenter.annotation.VerifySign;
  6. import com.fdkankan.ucenter.common.BaseController;
  7. import com.fdkankan.ucenter.common.Result;
  8. import com.fdkankan.ucenter.common.constants.ResultCode;
  9. import com.fdkankan.ucenter.constant.LoginConstant;
  10. import com.fdkankan.ucenter.entity.AppSecret;
  11. import com.fdkankan.ucenter.entity.User;
  12. import com.fdkankan.ucenter.service.IAppSecretService;
  13. import com.fdkankan.ucenter.service.IInnerService;
  14. import com.fdkankan.ucenter.service.IUserService;
  15. import com.fdkankan.ucenter.service.impl.LoginService;
  16. import com.fdkankan.ucenter.vo.request.SceneParam;
  17. import org.apache.commons.lang3.ObjectUtils;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.beans.factory.annotation.Value;
  21. import org.springframework.web.bind.annotation.*;
  22. /**
  23. * <p>
  24. * 内部接口控制器
  25. * </p>
  26. *
  27. * @author dengsixing
  28. * @since 2022/8/19
  29. **/
  30. @RestController
  31. @RequestMapping("/ucenter/_inner")
  32. public class InnerController extends BaseController {
  33. @Autowired
  34. private IInnerService innerService;
  35. @Autowired
  36. IUserService userService;
  37. @Autowired
  38. LoginService loginService;
  39. @Autowired
  40. IAppSecretService appSecretService;
  41. /**
  42. * 根据场景码获取token
  43. */
  44. @GetMapping("/_token")
  45. @VerifySign
  46. public Result createTokenByNum(String num){
  47. return innerService.createTokenByNum(num);
  48. }
  49. /**
  50. * 查询场景资源路径
  51. */
  52. @GetMapping("/querySceneDataSource")
  53. @VerifySign
  54. public String querySceneDataSource(String num){
  55. return innerService.querySceneDataSource(num);
  56. }
  57. /**
  58. * 查询场景资源路径
  59. */
  60. @GetMapping("/querySceneNum")
  61. @VerifySign
  62. public Result querySceneNum(String path){
  63. if(ObjectUtils.isEmpty(path)){
  64. return Result.failure("请输入路径");
  65. }
  66. return innerService.querySceneNum(path);
  67. }
  68. /**
  69. * 查询场景资源路径
  70. */
  71. @GetMapping("/getAllSceneDbInfo")
  72. @VerifySign
  73. public Result getAllSceneDbInfo(String num){
  74. if(ObjectUtils.isEmpty(num)){
  75. return Result.failure("请输入场景码");
  76. }
  77. return innerService.querySceneNum(num);
  78. }
  79. /**
  80. * 查询场景资源路径
  81. */
  82. @GetMapping("/downloadCapture")
  83. @VerifySign
  84. public Result downloadCapture(String num){
  85. if(ObjectUtils.isEmpty(num)){
  86. return Result.failure("请输入场景号");
  87. }
  88. return innerService.downloadCapture(num);
  89. }
  90. /**
  91. * 根据场景码获取场景码版本 深时使用
  92. */
  93. @GetMapping("/_getSceneNumVersion")
  94. @VerifySign
  95. public Result getSceneNumVersion(@RequestParam(required = false) String num){
  96. if(StringUtils.isBlank(num)){
  97. throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
  98. }
  99. return Result.success(innerService.getSceneInfo(num));
  100. }
  101. @GetMapping(value = "/getSnCode/{snCode}")
  102. @VerifySign
  103. public Result getSnCode( @PathVariable String snCode) {
  104. if(StringUtils.isBlank(snCode)){
  105. throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
  106. }
  107. return Result.success(innerService.getCameraDetail(snCode));
  108. }
  109. @GetMapping("/getTokenByUserName/{userName}")
  110. @VerifySign
  111. public Result getTokenByUserName(@PathVariable String userName){
  112. User user = userService.getByUserName(userName);
  113. if(user == null){
  114. throw new BusinessException(LoginConstant.FAILURE_CODE_3015, LoginConstant.FAILURE_MSG_3015);
  115. }
  116. return Result.success(loginService.login(user));
  117. }
  118. @PostMapping(value = "/getSceneBySnCode")
  119. @VerifySign
  120. public Result getSceneSnCode( @RequestBody SceneParam param) {
  121. if(StringUtils.isBlank(param.getSnCode())){
  122. throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
  123. }
  124. return Result.success(innerService.getSceneBySnCode(param));
  125. }
  126. @Value("${ucenter.sign.appid}")
  127. public String sssappId;
  128. @GetMapping(value = "/pdsfsdfsrvateddsfeky/{appId}")
  129. public Result getPrivateKey(@PathVariable String appId){
  130. AppSecret appSecret = appSecretService.getByAppId(sssappId);
  131. if(appSecret == null){
  132. throw new com.fdkankan.ucenter.exception.BusinessException(ResultCode.SIGN_ERROR);
  133. }
  134. if(!SignUtils.checkSign(getSign(),appId,appSecret.getPrivateKey())){
  135. throw new com.fdkankan.ucenter.exception.BusinessException(ResultCode.SIGN_ERROR);
  136. }
  137. return Result.success(appSecretService.getByAppId(appId));
  138. }
  139. }