LaserService.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. package com.fdkankan.manage.httpClient.service;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.fdkankan.manage.entity.*;
  4. import com.fdkankan.manage.mq.common.MqQueueUtil;
  5. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  6. import com.fdkankan.redis.util.RedisUtil;
  7. import com.google.common.collect.Lists;
  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.common.*;
  12. import com.fdkankan.manage.exception.BusinessException;
  13. import com.fdkankan.manage.httpClient.client.LaserClient;
  14. import com.fdkankan.manage.httpClient.param.LaserSceneMoveParam;
  15. import com.fdkankan.manage.httpClient.param.LaserSceneParam;
  16. import com.fdkankan.manage.httpClient.param.SSDownSceneParam;
  17. import com.fdkankan.manage.httpClient.param.SsBindParam;
  18. import com.fdkankan.manage.httpClient.vo.FdkkResponse;
  19. import com.fdkankan.manage.service.*;
  20. import com.fdkankan.manage.vo.request.SceneParam;
  21. import com.fdkankan.manage.vo.response.SSDownSceneVo;
  22. import com.fdkankan.manage.vo.response.SceneVo;
  23. import lombok.extern.slf4j.Slf4j;
  24. import org.apache.commons.lang3.StringUtils;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.beans.factory.annotation.Value;
  28. import org.springframework.http.HttpStatus;
  29. import org.springframework.stereotype.Service;
  30. import javax.annotation.Resource;
  31. import java.util.*;
  32. import java.util.stream.Collectors;
  33. @Service
  34. @Slf4j
  35. public class LaserService {
  36. @Autowired
  37. LaserClient laserClient;
  38. @Value("${4dkk.laserService.basePath}")
  39. private String basePath;
  40. @Autowired
  41. IUserService userService;
  42. @Autowired
  43. ICameraDetailService cameraDetailService;
  44. @Autowired
  45. ICameraService cameraService;
  46. @Autowired
  47. ISceneBuildProcessLogService sceneBuildProcessLogService;
  48. @Autowired
  49. IScenePlusService scenePlusService;
  50. @Autowired
  51. IScenePlusExtService scenePlusExtService;
  52. @Autowired
  53. RabbitMqProducer rabbitMqProducer;
  54. @Autowired
  55. ICommonService commonService;
  56. @Autowired
  57. ISceneProService sceneProService;
  58. @Autowired
  59. RedisUtil redisUtil;
  60. @Autowired
  61. ISceneColdStorageService sceneColdStorageService;
  62. @Autowired
  63. ICameraTypeService cameraTypeService;
  64. public PageInfo pageList(SceneParam param) {
  65. try {
  66. LaserSceneParam laserSceneParam = getLaserSceneParam(param);
  67. if(laserSceneParam == null ){
  68. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  69. }
  70. FdkkResponse response = laserClient.sceneList(laserSceneParam);
  71. JSONObject jsonObject =response.getData();
  72. if(jsonObject == null){
  73. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  74. }
  75. JSONArray list = jsonObject.getJSONArray("list");
  76. long total =jsonObject.getLong("total");
  77. List<SceneVo> sceneVoList = new ArrayList<>();
  78. for (Object o : list) {
  79. String res = JSONObject.toJSONString(o);
  80. SceneVo vo = JSONObject.parseObject(res,SceneVo.class);
  81. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  82. JSONObject obj = (JSONObject) o;
  83. vo.setStatusString(getLaserStatus(vo.getStatus(),vo.getPayStatus()));
  84. vo.setStatus(toFdStatus(vo.getStatus()));
  85. vo.setSceneName(obj.getString("title"));
  86. vo.setUserName(obj.getString("phone"));
  87. vo.setThumb(obj.getString("thumb"));
  88. vo.setWebSite(obj.getString("webSite"));
  89. vo.setIsObj(obj.getInteger("buildObjStatus"));
  90. if(vo.getStatus() == -1){ //计算失败
  91. SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(vo.getNum());
  92. String process = null;
  93. if(sceneBuildProcessLog !=null){
  94. process = sceneBuildProcessLog.getProcess();
  95. }
  96. vo.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(process));
  97. vo.setDataSource(scenePlusService.getDataSourceByNum(vo.getNum()));
  98. }
  99. this.getLaserSceneGps(vo);
  100. vo.setAddressComponent(commonService.getAddressComponent(vo.getGps()));
  101. if( vo.getMixture() == 0 && vo.getLocation() != null && vo.getLocation().equals(6)){
  102. vo.setShootCount(0);
  103. }
  104. sceneVoList.add(vo);
  105. }
  106. HashMap<String,SceneColdStorage> coldStorageMap = null;
  107. if(sceneVoList.size() >0){
  108. List<String> numList = sceneVoList.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  109. coldStorageMap = sceneColdStorageService.getByNumList(numList);
  110. }
  111. Set<String> snCodes = sceneVoList.parallelStream().map(SceneVo::getSnCode).collect(Collectors.toSet());
  112. HashMap<String,User> snUserMap = userService.getUserBySn(snCodes);
  113. for (SceneVo sceneVo : sceneVoList) {
  114. if(coldStorageMap != null){
  115. SceneColdStorage sceneColdStorage = coldStorageMap.get(sceneVo.getNum());
  116. if(sceneColdStorage != null){
  117. sceneVo.setIsColdStorage(true);
  118. }
  119. }
  120. User user = snUserMap.get(sceneVo.getSnCode());
  121. if(user != null){
  122. sceneVo.setUserId(user.getId());
  123. sceneVo.setUserName(user.getUserName());
  124. }
  125. }
  126. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  127. voPage.setRecords(sceneVoList);
  128. voPage.setTotal(total);
  129. return PageInfo.PageInfo(voPage);
  130. }catch (Exception e){
  131. log.error("访问深时失败:",e);
  132. //throw new BusinessException(ResultCode.SS_GET_ERROR);
  133. }
  134. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  135. return PageInfo.PageInfo(voPage);
  136. }
  137. private void getLaserSceneGps(SceneVo vo) {
  138. // String redisKey = String.format(RedisKeyUtil.numGpsKey, vo.getNum());
  139. // String redisKey2 = String.format(RedisKeyUtil.numShootKey, vo.getNum());
  140. // if(redisUtil.hasKey(redisKey) && redisUtil.hasKey(redisKey2)){
  141. // String gps = redisUtil.get(redisKey);
  142. // String shootNum = redisUtil.get(redisKey2);
  143. // vo.setGps(gps);
  144. // vo.setShootCount(Integer.valueOf(shootNum));
  145. // return;
  146. // }
  147. ScenePro pro = sceneProService.getByNum(vo.getNum());
  148. if(pro != null){
  149. //redisUtil.set(redisKey,pro.getGps()== null ?"":pro.getGps());
  150. //redisUtil.set(redisKey2,String.valueOf(pro.getShootCount()== null ? 0 :pro.getShootCount()));
  151. vo.setGps(pro.getGps());
  152. vo.setShootCount(pro.getShootCount());
  153. }
  154. ScenePlus plus = scenePlusService.getByNum(vo.getNum());
  155. if(plus != null){
  156. ScenePlusExt ext = scenePlusExtService.getByPlusId(plus.getId());
  157. if(ext != null){
  158. //redisUtil.set(redisKey,ext.getGps()== null?"":ext.getGps());
  159. // redisUtil.set(redisKey2,String.valueOf(ext.getShootCount()== null ? 0 :ext.getShootCount()));
  160. vo.setGps(ext.getGps());
  161. vo.setShootCount(ext.getShootCount());
  162. }
  163. }
  164. }
  165. private LaserSceneParam getLaserSceneParam(SceneParam param) {
  166. LaserSceneParam newParam = new LaserSceneParam();
  167. if(param.getCompanyId()!= null){ //客户场景
  168. List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyId(param.getCompanyId());
  169. param.setSnCodes(this.setSnCodes(cameraDetails));
  170. if(param.getSnCodes() == null || param.getSnCodes().size() <=0){
  171. return null;
  172. }
  173. }
  174. if(StringUtils.isNotBlank(param.getUserName())){
  175. List<CameraDetail> cameraDetails = cameraDetailService.getByUserName(param.getUserName());
  176. List<String> snCodes = this.setSnCodes(cameraDetails);
  177. if(param.getCompanyId() == null){
  178. param.setSnCodes(snCodes);
  179. }else {
  180. if(snCodes == null || snCodes.size() <=0){
  181. return null;
  182. }
  183. //取交集
  184. List<String> intersection = param.getSnCodes().stream().filter(snCodes::contains).collect(Collectors.toList());
  185. param.setSnCodes(intersection);
  186. }
  187. }
  188. if(StringUtils.isNotBlank(param.getUserName()) && StringUtils.isBlank(param.getSnCode()) &&
  189. (param.getSnCodes() == null || param.getSnCodes().size() <=0)){
  190. param.setSnCode("phoneEmptySelect");
  191. }
  192. if(StringUtils.isNotBlank(param.getNum())){
  193. newParam.setSceneCode(param.getNum());
  194. }
  195. BeanUtils.copyProperties(param,newParam);
  196. newParam.setTitle(param.getSceneName());
  197. if(StringUtils.isNotBlank(param.getField()) && param.getField().equals("create_time")){
  198. newParam.setOrderBy("shoot_time");
  199. }else {
  200. newParam.setOrderBy(param.getField());
  201. }
  202. newParam.setSortBy(param.getOrder());
  203. if(param.getType() == 6){
  204. newParam.setSceneSource(5);
  205. }
  206. return newParam;
  207. }
  208. private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
  209. if(cameraDetails != null && cameraDetails.size() >0){
  210. Set<Long> cameraIds = cameraDetails.stream()
  211. .filter(entity -> cameraTypeService.isLaser(entity.getType())).map(CameraDetail::getCameraId).collect(Collectors.toSet());
  212. if(cameraIds.size() >0){
  213. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  214. return cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  215. }
  216. }
  217. return null;
  218. }
  219. private Integer toFdStatus(Integer status) {
  220. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  221. switch (status){
  222. case 0 :
  223. case 4 :
  224. return 0;
  225. case 2 : return -2;
  226. case 3 : return -3;
  227. default: return -1;
  228. }
  229. }
  230. public static String getLaserStatus(Integer status,Integer payStatus){
  231. if(payStatus != null && payStatus == -2){
  232. return "封存";
  233. }
  234. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  235. switch (status){
  236. case -1 : return "场景已删除";
  237. case 0 :
  238. case 4 :
  239. return "计算中";
  240. case 1 : return "计算失败";
  241. case 2 : return "计算成功";
  242. case 3 : return "封存";
  243. default: return "";
  244. }
  245. }
  246. public void move(String num, String snCode, String toSnCode,Long userId,String newDataSource) {
  247. LaserSceneMoveParam param = new LaserSceneMoveParam();
  248. param.setSceneCode(num);
  249. //param.setSnCode(snCode);
  250. param.setToSnCode(toSnCode);
  251. param.setUserId(userId);
  252. param.setDataSource(newDataSource+"_laserData/laserData");
  253. if(userId != null){
  254. User user = userService.getById(userId);
  255. if(user != null){
  256. param.setPhone(user.getUserName());
  257. }
  258. }
  259. Map<String, Object> map = BeanUtil.beanToMap(param);
  260. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserMoveQueue,map);
  261. //laserClient.migrate(param);
  262. }
  263. public void moveWenBao(String num, String snCode, String toSnCode,Long userId,String newDataSource) {
  264. LaserSceneMoveParam param = new LaserSceneMoveParam();
  265. param.setSceneCode(num);
  266. //param.setSnCode(snCode);
  267. param.setToSnCode(toSnCode);
  268. param.setUserId(userId);
  269. param.setDataSource(newDataSource+"_laserData/laserData");
  270. if(userId != null){
  271. User user = userService.getById(userId);
  272. if(user != null){
  273. param.setPhone(user.getUserName());
  274. }
  275. }
  276. Map<String, Object> map = BeanUtil.beanToMap(param);
  277. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserMoveWenBaoQueue,map);
  278. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserMoveWenBaoQueue2,map);
  279. //laserClient.migrate(param);
  280. }
  281. public void copy(String snCode, String createTime, String newNum, Integer status, String sceneKey, String sceneName, Long userId){
  282. String phone = null;
  283. if(userId != null){
  284. User user = userService.getById(userId);
  285. if(user != null){
  286. phone = user.getUserName();
  287. }
  288. }
  289. Map<String,Object> params = new HashMap<>();
  290. params.put("childName",snCode);
  291. params.put("createTime", createTime);
  292. params.put("phone", phone);
  293. params.put("sceneCode", newNum);
  294. params.put("snCode",snCode);
  295. params.put("status", status);
  296. params.put("password", sceneKey);
  297. params.put("title", sceneName);
  298. params.put("userId", userId);
  299. params.put("copy", true);
  300. Result result = laserClient.saveOrEdit(newNum, params);
  301. if( result.getCode() != HttpStatus.OK.value()){
  302. log.error("激光场景状态同步失败!");
  303. }
  304. }
  305. public void delete(String num) {
  306. try {
  307. Map<String,Object> params = new HashMap<>();
  308. params.put("sceneCode", num);
  309. params.put("status", -1);
  310. Result result = laserClient.saveOrEdit(num, params);
  311. if(result.getCode() != HttpStatus.OK.value()){
  312. log.error("激光场景状态同步失败!");
  313. }
  314. }catch (Exception e){
  315. log.error("激光场景状态同步失败!",e);
  316. }
  317. }
  318. public void disableCooperation(String snCode, String cooperationUserName){
  319. List<Map<String, String>> laserParams = new ArrayList<>();
  320. Map<String, String> param = new HashMap<>();
  321. param.put("snCode", snCode);
  322. param.put("cooperationUserName", cooperationUserName);
  323. laserParams.add(param);
  324. this.disableCooperation(laserParams);
  325. }
  326. public void disableCooperation(List<Map<String, String>> params) {
  327. if(params.size() <=0){
  328. return;
  329. }
  330. laserClient.cooperationDisable(params);
  331. }
  332. public SSDownSceneVo downOfflineSceneStatus(String num) {
  333. try {
  334. SSDownSceneVo vo ;
  335. SSDownSceneParam param = new SSDownSceneParam();
  336. param.setSceneCode(num);
  337. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  338. if( responseEntity.getCode() != HttpStatus.OK.value()){
  339. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  340. return null;
  341. }
  342. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  343. return vo;
  344. }catch (Exception e){
  345. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  346. }
  347. return null ;
  348. }
  349. public SSDownSceneVo downOfflineScene(String num) {
  350. try {
  351. SSDownSceneVo vo ;
  352. SSDownSceneParam param = new SSDownSceneParam();
  353. param.setSceneCode(num);
  354. Result responseEntity = laserClient.downOfflineScene(param);
  355. if( responseEntity.getCode() != HttpStatus.OK.value()){
  356. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  357. return null;
  358. }
  359. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  360. return vo ;
  361. }catch (Exception e){
  362. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  363. }
  364. return null ;
  365. }
  366. public SSDownSceneVo downE57Status(String num) {
  367. try {
  368. SSDownSceneVo vo ;
  369. SSDownSceneParam param = new SSDownSceneParam();
  370. param.setSceneCode(num);
  371. Result responseEntity = laserClient.downE57Status(param);
  372. if( responseEntity.getCode() != HttpStatus.OK.value()){
  373. log.error("downE57Status-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  374. return null;
  375. }
  376. if(responseEntity.getCode() == 407){
  377. throw new BusinessException(ResultCode.SCENE_NOT_EXIST_E57);
  378. }
  379. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  380. return vo;
  381. }catch (BusinessException e){
  382. throw new BusinessException(ResultCode.SCENE_NOT_EXIST_E57);
  383. }catch (Exception e){
  384. log.error("downE57Status-根据场景码获取激光转台下载状态失败!",e);
  385. }
  386. return null ;
  387. }
  388. public SSDownSceneVo downE57(String num) {
  389. try {
  390. SSDownSceneVo vo ;
  391. SSDownSceneParam param = new SSDownSceneParam();
  392. param.setSceneCode(num);
  393. Result responseEntity = laserClient.downE57(param);
  394. if( responseEntity.getCode() != HttpStatus.OK.value()){
  395. log.error("downE57-根据场景码获取激光转台下载失败:{}",responseEntity);
  396. return null;
  397. }
  398. if(responseEntity.getCode() == 407){
  399. throw new BusinessException(ResultCode.SCENE_NOT_EXIST_E57);
  400. }
  401. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  402. return vo ;
  403. }catch (BusinessException e){
  404. throw new BusinessException(ResultCode.SCENE_NOT_EXIST_E57);
  405. }catch (Exception e){
  406. log.error("downE57-根据场景码获取激光转台下载状态失败!",e);
  407. }
  408. return null ;
  409. }
  410. public void toBind(String snCode) {
  411. try {
  412. SsBindParam param = new SsBindParam();
  413. param.setBind(false);
  414. param.setSnCode(Lists.newArrayList(snCode));
  415. Result responseEntity = laserClient.toBind(param);
  416. if( responseEntity.getCode() != HttpStatus.OK.value()){
  417. log.error("解绑用户激光转台下载失败:{}",responseEntity);
  418. }
  419. }catch (Exception e){
  420. log.error("解绑用户获取激光转台下载状态失败!",e);
  421. }
  422. }
  423. public HashMap<String, JSONObject> list(List<String> sceneNumList,Integer sceneSource) {
  424. LaserSceneParam newParam = new LaserSceneParam();
  425. newParam.setPageNum(1);
  426. newParam.setPageSize(sceneNumList.size());
  427. newParam.setSceneCodes(sceneNumList);
  428. newParam.setSceneSource(sceneSource);
  429. return this.list(newParam);
  430. }
  431. public HashMap<String, JSONObject> list(String sceneName,Integer sceneSource) {
  432. LaserSceneParam newParam = new LaserSceneParam();
  433. newParam.setPageNum(1);
  434. newParam.setPageSize(9999);
  435. newParam.setTitle(sceneName);
  436. newParam.setSceneSource(sceneSource);
  437. return this.list(newParam);
  438. }
  439. public HashMap<String, JSONObject> list(LaserSceneParam newParam) {
  440. HashMap<String, JSONObject> map = new HashMap<>();
  441. try {
  442. FdkkResponse fdkkResponse = laserClient.sceneList(newParam);
  443. JSONObject jsonObject = fdkkResponse.getData();
  444. if(jsonObject == null){
  445. return map;
  446. }
  447. JSONArray list = jsonObject.getJSONArray("list");
  448. for (Object o : list) {
  449. JSONObject obj = (JSONObject) o;
  450. map.put(obj.getString("num"),obj);
  451. }
  452. }catch (Exception e){
  453. log.info("激光系统访问失败:{}",e);
  454. throw new BusinessException(ResultCode.LASER_VIEW_ERROR);
  455. }
  456. return map;
  457. }
  458. }