LaserService.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. package com.fdkankan.ucenter.httpClient.service;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fdkankan.common.exception.BusinessException;
  5. import com.fdkankan.common.util.FileUtils;
  6. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  7. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  8. import com.fdkankan.ucenter.common.Result;
  9. import com.fdkankan.ucenter.common.constants.ResultCodeMsg;
  10. import com.fdkankan.ucenter.entity.Camera;
  11. import com.fdkankan.ucenter.entity.CameraDetail;
  12. import com.fdkankan.ucenter.entity.CameraType;
  13. import com.fdkankan.ucenter.entity.User;
  14. import com.fdkankan.ucenter.httpClient.client.LaserClient;
  15. import com.fdkankan.ucenter.httpClient.param.SSDownSceneParam;
  16. import com.fdkankan.ucenter.httpClient.param.SsBindParam;
  17. import com.fdkankan.ucenter.httpClient.vo.LaserSceneParam;
  18. import com.fdkankan.ucenter.httpClient.vo.SSDownSceneVo;
  19. import com.fdkankan.ucenter.httpClient.vo.SceneStatusInfoDTO;
  20. import com.fdkankan.ucenter.service.ICameraService;
  21. import com.fdkankan.ucenter.service.ICameraTypeService;
  22. import com.fdkankan.ucenter.service.IUserService;
  23. import com.fdkankan.ucenter.vo.SceneBySnCodeVo;
  24. import com.fdkankan.ucenter.vo.response.SceneNumVo;
  25. import com.google.common.collect.Lists;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.beans.factory.annotation.Value;
  29. import org.springframework.http.HttpStatus;
  30. import org.springframework.stereotype.Service;
  31. import java.io.File;
  32. import java.util.ArrayList;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. import java.util.Map;
  36. @Service
  37. @Slf4j
  38. public class LaserService {
  39. @Autowired
  40. private LaserClient laserClient;
  41. @Autowired
  42. private IUserService userService;
  43. @Autowired
  44. ICameraService cameraService;
  45. @Autowired
  46. ICameraTypeService cameraTypeService;
  47. /**
  48. * 根据用户获取激光相机数量
  49. * @param token
  50. */
  51. public SceneNumVo getLaserSceneNumByUser(String token,Integer sceneSource) {
  52. SceneNumVo sceneNumVo = new SceneNumVo();
  53. try {
  54. HashMap<String,Object> param = new HashMap<>();
  55. param.put("sceneSource",sceneSource);
  56. Result sceneNum = laserClient.getSceneNum(token,param);
  57. if(sceneNum != null && sceneNum.getCode() == 200){
  58. sceneNumVo = JSONObject.parseObject(JSONObject.toJSONString(sceneNum.getData()), SceneNumVo.class);
  59. sceneNumVo.setTotalNum(sceneNumVo.getSceneNum() + sceneNumVo.getCooperationSceneNum());
  60. }
  61. }catch (Exception e){
  62. e.printStackTrace();
  63. }
  64. return sceneNumVo ;
  65. }
  66. public Integer getLaserSceneNum(Map<String, String> params){
  67. Result result = laserClient.getSceneNumByCamera(params);
  68. if(result.getCode() == 200 ){
  69. return (Integer) result.getData();
  70. }
  71. return 0;
  72. }
  73. public void disableCooperation(HashMap<Long, CameraDetail> detailMap, HashMap<Long, Camera> cameraMap ){
  74. this.disableCooperation(getCooperationdDisableParam(detailMap,cameraMap));
  75. }
  76. public void enableCameraCooperation(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ,String username){
  77. this.enableCameraCooperation(getCooperationSaveParam(detailMap,cameraMap,username));
  78. }
  79. public void disableCooperation(List<Map<String, String>> params) {
  80. if(params.size() <=0){
  81. return;
  82. }
  83. laserClient.cooperationDisable(params);
  84. }
  85. public List<Map<String, String>> getCooperationdDisableParam(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ){
  86. List<Map<String, String>> laserParams = new ArrayList<>();
  87. List<Long> userIds = new ArrayList<>();
  88. for (Long aLong : detailMap.keySet()) {
  89. if(detailMap.get(aLong).getCooperationUser()!=null){
  90. userIds.add(detailMap.get(aLong).getCooperationUser());
  91. }
  92. }
  93. if(userIds.size() >0){
  94. HashMap<Long, User> userMap = userService.getByIds(userIds);
  95. for (Long cameraId : detailMap.keySet()) {
  96. CameraDetail cameraDetail = detailMap.get(cameraId);
  97. CameraType cameraType = cameraTypeService.getByCameraType(cameraDetail.getType());
  98. if (cameraType.getIsLaser() == 1) {
  99. Camera cameraEntity = cameraMap.get(cameraId);
  100. Map<String, String> param = new HashMap<>();
  101. param.put("snCode", cameraEntity.getSnCode());
  102. String name = userMap.get(cameraDetail.getCooperationUser()) == null ?null : userMap.get(cameraDetail.getCooperationUser()).getUserName();
  103. param.put("cooperationUserName", name);
  104. laserParams.add(param);
  105. }
  106. }
  107. }
  108. return laserParams;
  109. }
  110. public List<Map<String, String>> getCooperationSaveParam(HashMap<Long,CameraDetail> detailMap,HashMap<Long,Camera> cameraMap ,String username){
  111. List<Map<String, String>> laserParams = new ArrayList<>();
  112. for (Long cameraId : detailMap.keySet()) {
  113. CameraDetail cameraDetail = detailMap.get(cameraId);
  114. CameraType cameraType = cameraTypeService.getByCameraType(cameraDetail.getType());
  115. if (cameraType.getIsLaser() == 1) {
  116. Camera cameraEntity = cameraMap.get(cameraId);
  117. Map<String, String> param = new HashMap<>();
  118. param.put("snCode", cameraEntity.getSnCode());
  119. param.put("cooperationUserName", username);
  120. laserParams.add(param);
  121. }
  122. }
  123. return laserParams;
  124. }
  125. public void enableCameraCooperation(List<Map<String, String>> params) {
  126. if(params.size() <=0){
  127. return;
  128. }
  129. laserClient.cooperationCameraSave(params);
  130. }
  131. public JSONObject getSceneByNum(String num) {
  132. Result result = laserClient.getSceneByNum(num);
  133. if(result.getCode() != HttpStatus.OK.value()){
  134. log.error("获取激光转台场景失败!");
  135. return null;
  136. }
  137. return JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
  138. }
  139. public String copyDataSource( String oldDataSource,String dataSource) {
  140. //计算成功 激光转台相机推送
  141. log.info("激光转台相机 同步 请求 ");
  142. try {
  143. //创建目录
  144. if(oldDataSource.lastIndexOf("/")!=-1){
  145. oldDataSource = oldDataSource + "_laserData";
  146. }else{
  147. oldDataSource = oldDataSource.substring(0,oldDataSource.length()-1) + "_laserData";
  148. }
  149. if(dataSource.lastIndexOf("/")!=-1){
  150. dataSource = dataSource + "_laserData";
  151. }else{
  152. dataSource = dataSource.substring(0,dataSource.length()-1) + "_laserData";
  153. }
  154. FileUtils.copyDirectiory(oldDataSource ,dataSource);
  155. return dataSource + File.separator + "laserData";
  156. }catch (Exception e){
  157. e.printStackTrace();
  158. }
  159. return null;
  160. }
  161. public void copy(String oldNum , String newNum, String path,Boolean flag){
  162. Map<String,Object> params = new HashMap<>();
  163. params.put("sceneCode", newNum);
  164. params.put("oldSceneCode", oldNum);
  165. params.put("path",path);
  166. params.put("init",flag);
  167. if(flag){
  168. rabbitMqProducer.sendByWorkQueue(laserInitCopyScene,params);
  169. return;
  170. }
  171. rabbitMqProducer.sendByWorkQueue(laserCopyScene,params);
  172. }
  173. public List<SceneBySnCodeVo> getScenesBySnCode(String snCode, String token) {
  174. List<SceneBySnCodeVo> sceneVo = new ArrayList<>();
  175. try {
  176. HashMap<String ,String> param = new HashMap<>();
  177. param.put("snCode",snCode);
  178. Result responseEntity = laserClient.getScenesBySnCode(param, token);
  179. if( responseEntity.getCode() != HttpStatus.OK.value()){
  180. log.error("根据snCode获取激光转台场景失败!");
  181. return sceneVo;
  182. }
  183. sceneVo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), List.class);
  184. }catch (Exception e){
  185. log.error("根据snCode获取激光转台场景失败!",e);
  186. }
  187. return sceneVo ;
  188. }
  189. public SSDownSceneVo downOfflineSceneStatus(String num) {
  190. try {
  191. SSDownSceneVo vo ;
  192. SSDownSceneParam param = new SSDownSceneParam();
  193. param.setSceneCode(num);
  194. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  195. if( responseEntity.getCode() != HttpStatus.OK.value()){
  196. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  197. return null;
  198. }
  199. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  200. return vo;
  201. }catch (Exception e){
  202. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  203. }
  204. return null ;
  205. }
  206. public SSDownSceneVo downOfflineScene(String num) {
  207. try {
  208. SSDownSceneVo vo ;
  209. SSDownSceneParam param = new SSDownSceneParam();
  210. param.setSceneCode(num);
  211. Result responseEntity = laserClient.downOfflineScene(param);
  212. if( responseEntity.getCode() != HttpStatus.OK.value()){
  213. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  214. return null;
  215. }
  216. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  217. return vo ;
  218. }catch (Exception e){
  219. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  220. }
  221. return null ;
  222. }
  223. public void delete(String num) {
  224. try {
  225. Map<String,Object> params = new HashMap<>();
  226. params.put("sceneCode", num);
  227. params.put("status", -1);
  228. Result result = laserClient.saveOrEdit(num, params);
  229. if(result.getCode() != HttpStatus.OK.value()){
  230. throw new BusinessException(-1,"激光场景状态同步失败");
  231. }
  232. }catch (Exception e){
  233. log.error("激光场景状态同步失败!",e);
  234. throw new BusinessException(-1,e.getMessage());
  235. }
  236. }
  237. @Autowired
  238. private FYunFileServiceInterface fYunFileService;
  239. @Autowired
  240. private RabbitMqProducer rabbitMqProducer;
  241. @Value("${4dkk.laserService.cloud-point-fyun-path:testdata/%s/data/bundle_%s/building/}")
  242. private String cloudPointFyunPath;
  243. @Value("${4dkk.laserService.bucket:laser-data}")
  244. private String bucket;
  245. @Value("${queue.application.laser.cloud-point-build:laser-cloud-point-build}")
  246. private String cloudPointBuild;
  247. @Value("${queue.application.laser.copy-scene:laser-copy-scene}")
  248. private String laserCopyScene;
  249. @Value("${queue.application.laser.copy-scene:laser-copy-scene-init}")
  250. private String laserInitCopyScene;
  251. public void cloudPointBuild(String oldSceneCode,String sceneCode) {
  252. if (!fYunFileService.fileExist(bucket,String.format(cloudPointFyunPath,oldSceneCode,oldSceneCode) +"vision_edit.txt")){
  253. return;
  254. }
  255. log.info("开始同步点云编辑文件");
  256. // 上传点云编辑文件,并通知激光系统
  257. fYunFileService.copyFileBetweenBucket(bucket,String.format(cloudPointFyunPath,oldSceneCode,oldSceneCode) + "vision_edit.txt",
  258. bucket,String.format(cloudPointFyunPath,sceneCode,sceneCode) + "vision_edit.txt");
  259. fYunFileService.copyFileBetweenBucket(bucket,String.format(cloudPointFyunPath,oldSceneCode,oldSceneCode) + "uuidcloud",
  260. bucket,String.format(cloudPointFyunPath,sceneCode,sceneCode) + "uuidcloud");
  261. Map<String, Object> params = new HashMap<>();
  262. params.put("sceneNum", sceneCode);
  263. params.put("businessType", 0);
  264. rabbitMqProducer.sendByWorkQueue(cloudPointBuild, params);
  265. }
  266. public void toBind(Boolean bind,String snCode,String userName,Long userId) {
  267. try {
  268. SsBindParam param = new SsBindParam();
  269. param.setBind(bind);
  270. param.setSnCode(Lists.newArrayList(snCode));
  271. param.setPhone(userName);
  272. param.setUserId(userId);
  273. Result responseEntity = laserClient.toBind(param);
  274. if( responseEntity.getCode() != HttpStatus.OK.value()){
  275. log.error("解绑用户激光转台下载失败:{}",responseEntity);
  276. }
  277. }catch (Exception e){
  278. log.error("解绑用户获取激光转台下载状态失败!",e);
  279. }
  280. }
  281. public void updateStatus(List<String> numList, Integer payStatus) {
  282. Map<String,Object> params = new HashMap<>();
  283. params.put("sceneCodes", numList);
  284. params.put("payStatus", payStatus);
  285. rabbitMqProducer.sendByWorkQueue("update-laser-scene-status" ,params);
  286. //return laserClient.updateStatus( params);
  287. }
  288. public void updatePanoStatus(List<String> numList, Integer payStatus) {
  289. Map<String,Object> params = new HashMap<>();
  290. params.put("sceneCodes", numList);
  291. params.put("payStatus", payStatus);
  292. rabbitMqProducer.sendByWorkQueue("pano-paystatus-scene-queue" ,params);
  293. //return laserClient.updateStatus( params);
  294. }
  295. public HashMap<String, JSONObject> list(List<String> sceneNumList,Integer sceneSource) {
  296. LaserSceneParam newParam = new LaserSceneParam();
  297. newParam.setPageNum(1);
  298. newParam.setSceneSource(sceneSource);
  299. newParam.setPageSize(sceneNumList.size());
  300. newParam.setSceneCodes(sceneNumList);
  301. return this.list(newParam);
  302. }
  303. public HashMap<String, JSONObject> list(List<String> sceneNumList,Integer status,Integer sceneSource) {
  304. LaserSceneParam newParam = new LaserSceneParam();
  305. newParam.setPageNum(1);
  306. newParam.setSceneSource(sceneSource);
  307. newParam.setPageSize(sceneNumList.size());
  308. newParam.setSceneCodes(sceneNumList);
  309. newParam.setStatus(status);
  310. return this.list(newParam);
  311. }
  312. public HashMap<String, JSONObject> list(LaserSceneParam newParam) {
  313. HashMap<String, JSONObject> map = new HashMap<>();
  314. Result fdkkResponse = laserClient.sceneList(newParam);
  315. JSONObject jsonObject = (JSONObject) fdkkResponse.getData();
  316. if(jsonObject == null){
  317. return map;
  318. }
  319. JSONArray list = jsonObject.getJSONArray("list");
  320. for (Object o : list) {
  321. JSONObject obj = (JSONObject) o;
  322. map.put(obj.getString("num"),obj);
  323. }
  324. return map;
  325. }
  326. public SSDownSceneVo downE57Status(String num) {
  327. try {
  328. SSDownSceneVo vo ;
  329. SSDownSceneParam param = new SSDownSceneParam();
  330. param.setSceneCode(num);
  331. Result responseEntity = laserClient.downE57Status(param);
  332. if( responseEntity.getCode() != HttpStatus.OK.value()){
  333. log.error("downE57Status-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  334. return null;
  335. }
  336. if(responseEntity.getCode() == 407){
  337. throw new BusinessException(ResultCodeMsg.FAILURE_CODE_400011, ResultCodeMsg.FAILURE_MSG_400011);
  338. }
  339. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  340. return vo;
  341. }catch (BusinessException e){
  342. throw new BusinessException(ResultCodeMsg.FAILURE_CODE_400011, ResultCodeMsg.FAILURE_MSG_400011);
  343. }catch (Exception e){
  344. log.error("downE57Status-根据场景码获取激光转台下载状态失败!",e);
  345. }
  346. return null ;
  347. }
  348. public SSDownSceneVo downE57(String num) {
  349. try {
  350. SSDownSceneVo vo ;
  351. SSDownSceneParam param = new SSDownSceneParam();
  352. param.setSceneCode(num);
  353. Result responseEntity = laserClient.downE57(param);
  354. if( responseEntity.getCode() != HttpStatus.OK.value()){
  355. log.error("downE57-根据场景码获取激光转台下载失败:{}",responseEntity);
  356. return null;
  357. }
  358. if(responseEntity.getCode() == 407){
  359. throw new BusinessException(ResultCodeMsg.FAILURE_CODE_400011, ResultCodeMsg.FAILURE_MSG_400011);
  360. }
  361. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  362. return vo ;
  363. }catch (BusinessException e){
  364. throw new BusinessException(ResultCodeMsg.FAILURE_CODE_400011, ResultCodeMsg.FAILURE_MSG_400011);
  365. }catch (Exception e){
  366. log.error("downE57-根据场景码获取激光转台下载状态失败!",e);
  367. }
  368. return null ;
  369. }
  370. public SceneStatusInfoDTO laserSceneInfo(String num) {
  371. try {
  372. SceneStatusInfoDTO vo ;
  373. Result responseEntity = laserClient.laserSceneInfo(num);
  374. if( responseEntity.getCode() != HttpStatus.OK.value()){
  375. log.error("LaserSceneInfo-根据场景码获取激光转台下载失败:{}",responseEntity);
  376. return null;
  377. }
  378. if(responseEntity.getCode() == 407){
  379. throw new BusinessException(ResultCodeMsg.FAILURE_CODE_400011, ResultCodeMsg.FAILURE_MSG_400011);
  380. }
  381. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SceneStatusInfoDTO.class);
  382. return vo ;
  383. }catch (BusinessException e){
  384. throw new BusinessException(ResultCodeMsg.FAILURE_CODE_400011, ResultCodeMsg.FAILURE_MSG_400011);
  385. }catch (Exception e){
  386. log.error("LaserSceneInfo-根据场景码获取激光转台下载状态失败!",e);
  387. }
  388. return null ;
  389. }
  390. public void saveBatchCooperation(List<String> numList2,List<String> snCodeList, List<String> userNameList,String type,String operatingMode) {
  391. log.info(numList2.size() +"---------"+snCodeList.size());
  392. if(numList2.isEmpty() && snCodeList.isEmpty()){
  393. return;
  394. }
  395. HashMap<String,Object> map = new HashMap<>();
  396. map.put("numList",numList2);
  397. map.put("type",type);
  398. map.put("snCodeList",snCodeList);
  399. map.put("userNameList",userNameList);
  400. map.put("operatingMode",operatingMode);
  401. rabbitMqProducer.sendByWorkQueue("laser-batch-save-cooperation",map);
  402. }
  403. }