LaserService.java 13 KB

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