SceneController.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package com.fdkankan.manage.controller;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fdkankan.manage.common.ResultCode;
  5. import com.fdkankan.manage.entity.*;
  6. import com.fdkankan.manage.exception.BusinessException;
  7. import com.fdkankan.manage.common.ResultData;
  8. import com.fdkankan.manage.httpClient.client.FdKKClient;
  9. import com.fdkankan.manage.httpClient.client.LaserClient;
  10. import com.fdkankan.manage.httpClient.param.LaserSceneParam;
  11. import com.fdkankan.manage.httpClient.vo.FdkkResponse;
  12. import com.fdkankan.manage.service.*;
  13. import com.fdkankan.manage.vo.request.SceneParam;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import javax.annotation.Resource;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.stream.Collectors;
  22. /**
  23. * 相机场景管理
  24. */
  25. @RestController
  26. @RequestMapping("/service/manage/scene")
  27. @Slf4j
  28. public class SceneController {
  29. @Autowired
  30. ISceneProService sceneProService;
  31. @Autowired
  32. IScenePlusService scenePlusService;
  33. @Autowired
  34. IDownService downService;
  35. @Autowired
  36. FdKKClient fdKKClient;
  37. @Autowired
  38. LaserClient laserClient;
  39. @Autowired
  40. IJySceneUserAuthService jySceneUserAuthService;
  41. @Autowired
  42. ISysUserService sysUserService;
  43. @Autowired
  44. IJyUserService jyUserService;
  45. @Autowired
  46. ISceneCopyLogService sceneCopyLogService;
  47. @PostMapping("/list")
  48. public ResultData list(@RequestBody SceneParam param){
  49. return ResultData.ok(sceneProService.pageList(param));
  50. }
  51. @PostMapping("/authNumList")
  52. public ResultData authNumList(){
  53. SysUser byId = sysUserService.getById(Long.valueOf(StpUtil.getLoginId().toString()));
  54. JyUser loginUser = jyUserService.getBySysId(byId.getId());
  55. List<JySceneUserAuth> byJyUserId = jySceneUserAuthService.getByJyUserId(loginUser.getId());
  56. List<String> collect = byJyUserId.stream().map(JySceneUserAuth::getNum).collect(Collectors.toList());
  57. return ResultData.ok(collect);
  58. }
  59. /**
  60. * 场景迁移
  61. * num 迁移场景码
  62. * snCode 迁移至相机snCode
  63. */
  64. @PostMapping("/move")
  65. public ResultData move(@RequestBody SceneParam param){
  66. if(StringUtils.isEmpty(param.getNum()) || StringUtils.isEmpty(param.getSnCode())){
  67. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  68. }
  69. sceneProService.move(param);
  70. return ResultData.ok();
  71. }
  72. /**
  73. * 场景复制
  74. * num 场景码
  75. */
  76. @PostMapping("/copy")
  77. public ResultData copy(@RequestBody SceneParam param) throws Exception {
  78. if(StringUtils.isEmpty(param.getNum())){
  79. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  80. }
  81. sceneProService.copy(param.getNum());
  82. return ResultData.ok();
  83. }
  84. /**
  85. * 场景删除
  86. * num 场景码
  87. */
  88. @PostMapping("/delete")
  89. public ResultData delete(@RequestBody SceneParam param){
  90. if(StringUtils.isEmpty(param.getNum())){
  91. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  92. }
  93. sceneProService.deleteByNum(param.getNum());
  94. return ResultData.ok();
  95. }
  96. /**
  97. * 检查下载
  98. * num 场景码
  99. */
  100. @GetMapping("/checkDownLoad")
  101. public ResultData checkDownLoad(@RequestParam(required = false) String num,
  102. @RequestParam(required = false,defaultValue = "0") Integer isObj){
  103. return ResultData.ok(downService.checkDownLoad(num,isObj));
  104. }
  105. /**
  106. * 下载场景
  107. * num 场景码
  108. */
  109. @GetMapping("/downScene")
  110. public ResultData downScene(@RequestParam(required = false) String num,
  111. @RequestParam(required = false,defaultValue = "0") Integer isObj){
  112. return ResultData.ok(downService.down(num,isObj));
  113. }
  114. /**
  115. * 下载场景进度条
  116. * num 场景码
  117. */
  118. @GetMapping("/downloadProcess")
  119. public ResultData downloadProcess(@RequestParam(required = false) String num,
  120. @RequestParam(required = false,defaultValue = "0") Integer isObj){
  121. return ResultData.ok(downService.downloadProcess(num,isObj));
  122. }
  123. /**
  124. * 场景重算
  125. * num 场景码
  126. */
  127. @GetMapping("/rebuildScene")
  128. public ResultData rebuild(@RequestParam(required = false) String num){
  129. ScenePro scenePro = sceneProService.getByNum(num);
  130. if(scenePro!=null && scenePro.getSceneSource() != 4){
  131. throw new BusinessException(ResultCode.V3_SCENE_REBUILD);
  132. }
  133. ScenePlus scenePlus = scenePlusService.getByNum(num);
  134. if(scenePlus == null && scenePro == null){
  135. throw new BusinessException(ResultCode.SCENE_NOT_EXIST);
  136. }
  137. HashMap<String,Object> paramMap = new HashMap<>();
  138. paramMap.put("num",num);
  139. try {
  140. JSONObject jsonObject = fdKKClient.rebuildScene(paramMap);
  141. Integer code = jsonObject.getInteger("code");
  142. if(code != 0){
  143. log.error("场景重算失败:{},{}",num,jsonObject);
  144. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
  145. }
  146. }catch (Exception e){
  147. throw new BusinessException(ResultCode.SCENE_REBUILD_ERROR);
  148. }
  149. return ResultData.ok();
  150. }
  151. @PostMapping("/sceneDetail")
  152. public ResultData sceneDetail(@RequestBody LaserSceneParam param){
  153. if(param.getId() == null){
  154. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  155. }
  156. FdkkResponse fdkkResponse = laserClient.sceneDetail(param, StpUtil.getTokenValue());
  157. if(fdkkResponse.getCode() != 200){
  158. throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
  159. }
  160. return ResultData.ok(fdkkResponse.getData());
  161. }
  162. @PostMapping("/buildSceneObj")
  163. public ResultData buildSceneObj(@RequestBody LaserSceneParam param){
  164. if(param.getId() == null){
  165. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  166. }
  167. if(StringUtils.isNotBlank(param.getSceneNum())){
  168. List<SceneCopyLog> byNewNum = sceneCopyLogService.getByNewNum(param.getSceneNum());
  169. if(byNewNum!=null && !byNewNum.isEmpty()){
  170. throw new BusinessException(ResultCode.COPY_NUM_NOT_GEN_OBJ);
  171. }
  172. }
  173. FdkkResponse fdkkResponse = laserClient.buildSceneObj(param, StpUtil.getTokenValue());
  174. if(fdkkResponse.getCode() != 200){
  175. throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
  176. }
  177. return ResultData.ok();
  178. }
  179. }