InnerController.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package com.fdkankan.manage.inner.controller;
  2. import cn.hutool.extra.servlet.ServletUtil;
  3. import cn.hutool.log.Log;
  4. import com.fdkankan.common.util.SecurityUtil;
  5. import com.fdkankan.manage.common.CacheUtil;
  6. import com.fdkankan.manage.common.ResultCode;
  7. import com.fdkankan.manage.common.ResultData;
  8. import com.fdkankan.manage.controller.BaseController;
  9. import com.fdkankan.manage.entity.RtkAccount;
  10. import com.fdkankan.manage.entity.RtkDevice;
  11. import com.fdkankan.manage.entity.RtkInfo;
  12. import com.fdkankan.manage.entity.RtkUseLog;
  13. import com.fdkankan.manage.exception.BusinessException;
  14. import com.fdkankan.manage.service.*;
  15. import com.fdkankan.manage.util.RsaUtils;
  16. import com.fdkankan.manage.vo.request.SceneParam;
  17. import org.apache.commons.lang3.StringUtils;
  18. import org.springframework.beans.BeanUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.web.bind.annotation.*;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import java.util.Date;
  23. /**
  24. * <p>
  25. * TODO
  26. * </p>
  27. *
  28. * @author dengsixing
  29. * @since 2022/6/7
  30. **/
  31. @RestController
  32. @RequestMapping("/service/manage/inner")
  33. public class InnerController extends BaseController {
  34. @Autowired
  35. private ISceneProService sceneProService;
  36. @Autowired
  37. IServiceUpTipService serviceUpTipService;
  38. @PostMapping("/move")
  39. public ResultData move(@RequestBody SceneParam param){
  40. if(!checkSign()){
  41. return ResultData.error(-1,"签名错误");
  42. }
  43. if(StringUtils.isEmpty(param.getNum()) || StringUtils.isEmpty(param.getSnCode())){
  44. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  45. }
  46. sceneProService.move(param);
  47. return ResultData.ok();
  48. }
  49. @GetMapping("/copyScene")
  50. public ResultData copyScene(@RequestParam(required = false) String num){
  51. if(!checkSign()){
  52. return ResultData.error(-1,"签名错误");
  53. }
  54. if(StringUtils.isEmpty(num)){
  55. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  56. }
  57. sceneProService.copy(num);
  58. return ResultData.ok();
  59. }
  60. @GetMapping("/getServiceUpTip")
  61. public ResultData getServiceUpTip(@RequestParam(required = false) Integer type){
  62. return ResultData.ok( serviceUpTipService.getServiceUpTipByType(type));
  63. }
  64. @GetMapping("/rebuildScene")
  65. public ResultData rebuild(@RequestParam(required = false) String num,@RequestParam(required = false) String from){
  66. sceneProService.rebuildScene(num,from);
  67. return ResultData.ok( );
  68. }
  69. @Autowired
  70. IRtkInfoService rtkInfoService;
  71. @Autowired
  72. IRtkAccountService rtkAccountService;
  73. @Autowired
  74. IRtkDeviceService rtkDeviceService;
  75. @Autowired
  76. IRtkUseLogService rtkUseLogService;
  77. /**
  78. * 相机开启rtk获取账号
  79. */
  80. @GetMapping("/info/{rtkSnCode}")
  81. public synchronized ResultData info(@PathVariable String rtkSnCode,
  82. @RequestParam(value = "cameraSn",required = false) String cameraSn){
  83. if(StringUtils.isBlank(rtkSnCode)){
  84. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  85. }
  86. if("aws".equals(CacheUtil.uploadType)){
  87. RtkInfo rtkInfo = rtkInfoService.getByRtkSnCode(rtkSnCode);
  88. if(rtkInfo == null || rtkInfo.getStatus() == 1 || rtkInfo.getFailureTime().getTime() <= new Date().getTime()){
  89. throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
  90. }
  91. String clientIP = ServletUtil.getClientIP(request);
  92. rtkUseLogService.saveLog(rtkInfo,clientIP,cameraSn,0);
  93. return ResultData.ok(rtkInfo);
  94. }
  95. RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode);
  96. if(rtkDevice == null || rtkDevice.getUseStatus() !=0){
  97. throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
  98. }
  99. RtkInfo rtkInfo = new RtkInfo();
  100. rtkInfo.setRtkSnCode(rtkSnCode);
  101. rtkInfo.setRtkType(rtkDevice.getRtkType());
  102. //rtkDevice.getType() = 0板卡自带账号信息,无需关联
  103. Integer rtkAccountId = null;
  104. if(rtkDevice.getRtkType() != 0){
  105. RtkAccount rtkAccount = rtkAccountService.getOneNotUseAccount(rtkSnCode,rtkDevice.getCameraSn());
  106. rtkAccountId = rtkAccount.getId();
  107. BeanUtils.copyProperties(rtkAccount,rtkInfo);
  108. }
  109. String clientIP = ServletUtil.getClientIP(request);
  110. rtkUseLogService.saveLog(rtkInfo,clientIP,rtkAccountId,cameraSn,rtkDevice);
  111. return ResultData.ok(rtkInfo);
  112. }
  113. /**
  114. * 相机关闭rtk,回收账号
  115. */
  116. @GetMapping("/stop/{rtkSnCode}")
  117. public ResultData stop(@PathVariable String rtkSnCode,
  118. @RequestParam(value = "cameraSn",required = false) String cameraSn){
  119. if(StringUtils.isBlank(rtkSnCode)){
  120. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  121. }
  122. if("aws".equals(CacheUtil.uploadType)){
  123. RtkInfo rtkInfo = rtkInfoService.getByRtkSnCode(rtkSnCode);
  124. if(rtkInfo == null || rtkInfo.getStatus() == 1 || rtkInfo.getFailureTime().getTime() <= new Date().getTime()){
  125. throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
  126. }
  127. String clientIP = ServletUtil.getClientIP(request);
  128. rtkUseLogService.saveLog(rtkInfo,clientIP,cameraSn,1);
  129. return ResultData.ok();
  130. }
  131. RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode);
  132. if(rtkDevice == null){
  133. throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
  134. }
  135. String clientIP = ServletUtil.getClientIP(request);
  136. rtkAccountService.stop(rtkDevice,clientIP,cameraSn);
  137. return ResultData.ok();
  138. }
  139. }