LaserService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. package com.fdkankan.manage_jp.httpClient.service;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.fdkankan.common.util.FileUtils;
  4. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  5. import com.fdkankan.manage_jp.httpClient.param.LaserSceneMoveParam;
  6. import com.fdkankan.manage_jp.service.*;
  7. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  11. import com.fdkankan.manage_jp.common.PageInfo;
  12. import com.fdkankan.manage_jp.common.Result;
  13. import com.fdkankan.manage_jp.entity.Camera;
  14. import com.fdkankan.manage_jp.entity.CameraDetail;
  15. import com.fdkankan.manage_jp.entity.Company;
  16. import com.fdkankan.manage_jp.entity.User;
  17. import com.fdkankan.manage_jp.httpClient.client.LaserClient;
  18. import com.fdkankan.manage_jp.httpClient.param.LaserSceneParam;
  19. import com.fdkankan.manage_jp.httpClient.param.SSDownSceneParam;
  20. import com.fdkankan.manage_jp.httpClient.param.SSToBind;
  21. import com.fdkankan.manage_jp.httpClient.vo.FdkkResponse;
  22. import com.fdkankan.manage_jp.httpClient.vo.SSDownSceneVo;
  23. import com.fdkankan.manage_jp.vo.request.SceneParam;
  24. import com.fdkankan.manage_jp.vo.response.SceneVo;
  25. import lombok.extern.slf4j.Slf4j;
  26. import org.apache.commons.lang3.StringUtils;
  27. import org.apache.ibatis.annotations.Param;
  28. import org.springframework.beans.BeanUtils;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.beans.factory.annotation.Value;
  31. import org.springframework.http.HttpStatus;
  32. import org.springframework.stereotype.Service;
  33. import java.io.File;
  34. import java.util.*;
  35. import java.util.stream.Collectors;
  36. @Service
  37. @Slf4j
  38. public class LaserService {
  39. @Autowired
  40. LaserClient laserClient;
  41. @Value("${4dkk.laserService.basePath}")
  42. private String basePath;
  43. @Autowired
  44. IUserService userService;
  45. @Autowired
  46. ICameraDetailService cameraDetailService;
  47. @Autowired
  48. ICameraService cameraService;
  49. @Autowired
  50. ICompanyService companyService;
  51. @Autowired
  52. ITmColdStorageService tmColdStorageService;
  53. public SSDownSceneVo downOfflineSceneStatus(String num,String lang) {
  54. try {
  55. SSDownSceneVo vo ;
  56. SSDownSceneParam param = new SSDownSceneParam();
  57. param.setSceneCode(num);
  58. param.setLang(lang);
  59. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  60. if( responseEntity.getCode() != HttpStatus.OK.value()){
  61. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  62. return null;
  63. }
  64. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  65. return vo;
  66. }catch (Exception e){
  67. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  68. }
  69. return null ;
  70. }
  71. public SSDownSceneVo downOfflineScene(String num,String lang) {
  72. try {
  73. SSDownSceneVo vo ;
  74. SSDownSceneParam param = new SSDownSceneParam();
  75. param.setSceneCode(num);
  76. param.setLang(lang);
  77. Result responseEntity = laserClient.downOfflineScene(param);
  78. if( responseEntity.getCode() != HttpStatus.OK.value()){
  79. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  80. return null;
  81. }
  82. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  83. return vo ;
  84. }catch (Exception e){
  85. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  86. }
  87. return null ;
  88. }
  89. public void updateStatus(String num,Integer status) {
  90. Map<String,Object> params = new HashMap<>();
  91. params.put("sceneCodes", Arrays.asList(num));
  92. params.put("status", status);
  93. //return laserClient.updateStatus( params);
  94. rabbitMqProducer.sendByWorkQueue("update-build-status",params);
  95. }
  96. public void updateBuildObjStatus(String num,Integer status) {
  97. //生成OBJ状态,0,未生成 1完成,2计算中
  98. Map<String,Object> params = new HashMap<>();
  99. params.put("sceneCodes", Arrays.asList(num));
  100. params.put("buildObjStatus", status);
  101. //return laserClient.updateStatus( params);
  102. rabbitMqProducer.sendByWorkQueue("update-build-status",params);
  103. }
  104. public void toBind(List<String> snCodes,Boolean bind,String phone) {
  105. try {
  106. SSToBind param = new SSToBind();
  107. param.setBind(bind);
  108. param.setSnCode(snCodes);
  109. Result result = laserClient.toBind(param);
  110. if(result.getCode() != HttpStatus.OK.value()){
  111. log.error("激光场景状态同步失败!");
  112. }
  113. }catch (Exception e){
  114. log.error("激光场景状态同步失败!",e);
  115. }
  116. }
  117. public void copy(Long camaraId, String createTime, String newNum, Integer status,
  118. String path, String sceneKey, Long userId,String version,
  119. String oldNum,String algorithmTime,Integer sceneSource,Integer shootCount,Integer location,Integer isObj ){
  120. String phone = null;
  121. String snCode = null;
  122. if(userId != null){
  123. User user = userService.getById(userId);
  124. phone = user == null ? null :user.getUserName();
  125. }
  126. if(camaraId != null){
  127. Camera camera = cameraService.getById(camaraId);
  128. snCode = camera == null ? null :camera.getSnCode();
  129. }
  130. Map<String,Object> params = new HashMap<>();
  131. params.put("childName",snCode);
  132. params.put("createTime", createTime);
  133. params.put("phone", phone);
  134. params.put("sceneCode", newNum);
  135. params.put("oldSceneCode", oldNum);
  136. params.put("snCode",snCode);
  137. params.put("status", status);
  138. params.put("password", sceneKey);
  139. //params.put("title", sceneName);
  140. params.put("userId", userId);
  141. params.put("isCopy", true);
  142. params.put("path",path);
  143. params.put("version",version);
  144. params.put("sceneSource",sceneSource);
  145. params.put("algorithmTime",algorithmTime);
  146. params.put("shootCount",shootCount);
  147. if(location != null){
  148. params.put("location",location);
  149. }
  150. if(isObj == 1){
  151. params.put("buildObjStatus",isObj);
  152. }
  153. rabbitMqProducer.sendByWorkQueue("laser-update-scene",params);
  154. }
  155. public void copy(String oldNum , String newNum, String path,Boolean flag){
  156. Map<String,Object> params = new HashMap<>();
  157. params.put("sceneCode", newNum);
  158. params.put("oldSceneCode", oldNum);
  159. params.put("path",path);
  160. params.put("init",flag);
  161. rabbitMqProducer.sendByWorkQueue("laser-copy-scene",params);
  162. }
  163. public String copyDataSource( String oldDataSource,String dataSource) {
  164. //计算成功 激光转台相机推送
  165. log.info("激光转台相机 同步 请求 ");
  166. try {
  167. //创建目录
  168. if(oldDataSource.lastIndexOf("/")!=-1){
  169. oldDataSource = oldDataSource + "_laserData";
  170. }else{
  171. oldDataSource = oldDataSource.substring(0,oldDataSource.length()-1) + "_laserData";
  172. }
  173. if(dataSource.lastIndexOf("/")!=-1){
  174. dataSource = dataSource + "_laserData";
  175. }else{
  176. dataSource = dataSource.substring(0,dataSource.length()-1) + "_laserData";
  177. }
  178. FileUtils.copyDirectiory(oldDataSource ,dataSource);
  179. return dataSource + File.separator + "laserData";
  180. }catch (Exception e){
  181. e.printStackTrace();
  182. }
  183. return null;
  184. }
  185. public void move(String num, String snCode, String toSnCode, Long userId, String newDataSource) {
  186. LaserSceneMoveParam param = new LaserSceneMoveParam();
  187. param.setSceneCode(num);
  188. //param.setSnCode(snCode);
  189. param.setToSnCode(toSnCode);
  190. param.setUserId(userId);
  191. param.setDataSource(newDataSource+"_laserData/laserData");
  192. if(userId != null){
  193. User user = userService.getById(userId);
  194. if(user != null){
  195. param.setPhone(user.getUserName());
  196. }
  197. }
  198. Map<String, Object> map = BeanUtil.beanToMap(param);
  199. rabbitMqProducer.sendByWorkQueue("laser-migrate-scene",map);
  200. //return laserClient.migrate(param);
  201. }
  202. @Autowired
  203. private FYunFileServiceInterface fYunFileService;
  204. @Autowired
  205. private RabbitMqProducer rabbitMqProducer;
  206. @Value("${4dkk.laserService.cloud-point-fyun-path:laser_u_data/%s/data/bundle_%s/building/}")
  207. private String cloudPointFyunPath;
  208. @Value("${4dkk.laserService.bucket:geosign-4dkk}")
  209. private String bucket;
  210. @Value("${queue.application.laser.cloud-point-build:laser-cloud-point-build}")
  211. private String cloudPointBuild;
  212. public void cloudPointBuild(String oldSceneCode,String sceneCode) {
  213. if (!fYunFileService.fileExist(bucket,String.format(cloudPointFyunPath,oldSceneCode,oldSceneCode) +"vision_edit.txt")){
  214. return;
  215. }
  216. log.info("开始同步点云编辑文件");
  217. // 上传点云编辑文件,并通知激光系统
  218. fYunFileService.copyFileBetweenBucket(bucket,String.format(cloudPointFyunPath,oldSceneCode,oldSceneCode) + "vision_edit.txt",
  219. bucket,String.format(cloudPointFyunPath,sceneCode,sceneCode) + "vision_edit.txt");
  220. fYunFileService.copyFileBetweenBucket(bucket,String.format(cloudPointFyunPath,oldSceneCode,oldSceneCode) + "uuidcloud",
  221. bucket,String.format(cloudPointFyunPath,sceneCode,sceneCode) + "uuidcloud");
  222. Map<String, Object> params = new HashMap<>();
  223. params.put("sceneNum", sceneCode);
  224. params.put("businessType", 0);
  225. rabbitMqProducer.sendByWorkQueue(cloudPointBuild, params);
  226. }
  227. public HashMap<String, JSONObject> list(List<String> sceneNumList,Integer sceneSource,String lang) {
  228. LaserSceneParam newParam = new LaserSceneParam();
  229. newParam.setPageNum(1);
  230. newParam.setPageSize(sceneNumList.size());
  231. newParam.setSceneCodes(sceneNumList);
  232. newParam.setSceneSource(sceneSource);
  233. newParam.setLang(lang);
  234. return this.list(newParam);
  235. }
  236. public HashMap<String, JSONObject> list(List<String> sceneNumList,Integer status,Integer sceneSource,String lang) {
  237. LaserSceneParam newParam = new LaserSceneParam();
  238. newParam.setPageNum(1);
  239. newParam.setPageSize(sceneNumList.size());
  240. newParam.setSceneCodes(sceneNumList);
  241. newParam.setStatus(status);
  242. newParam.setSceneSource(sceneSource);
  243. newParam.setLang(lang);
  244. return this.list(newParam);
  245. }
  246. public HashMap<String, JSONObject> list(LaserSceneParam newParam) {
  247. HashMap<String, JSONObject> map = new HashMap<>();
  248. FdkkResponse fdkkResponse = laserClient.sceneList(newParam);
  249. JSONObject jsonObject = fdkkResponse.getData();
  250. if(jsonObject == null){
  251. return map;
  252. }
  253. JSONArray list = jsonObject.getJSONArray("list");
  254. for (Object o : list) {
  255. JSONObject obj = (JSONObject) o;
  256. map.put(obj.getString("num"),obj);
  257. }
  258. return map;
  259. }
  260. public JSONObject getSceneByNum(String num) {
  261. Result result = laserClient.getSceneByNum(num);
  262. if(result.getCode() != HttpStatus.OK.value()){
  263. log.error("获取激光转台场景失败!");
  264. return null;
  265. }
  266. return JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
  267. }
  268. }