LaserService.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. public PageInfo pageList(SceneParam param) {
  63. try {
  64. LaserSceneParam laserSceneParam = getLaserSceneParam(param);
  65. if(laserSceneParam == null ){
  66. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  67. }
  68. FdkkResponse response = laserClient.sceneList(laserSceneParam);
  69. JSONObject jsonObject =response.getData();
  70. if(jsonObject == null){
  71. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  72. }
  73. JSONArray list = jsonObject.getJSONArray("list");
  74. long total =jsonObject.getLong("total");
  75. List<SceneVo> sceneVoList = new ArrayList<>();
  76. for (Object o : list) {
  77. String res = JSONObject.toJSONString(o);
  78. SceneVo vo = JSONObject.parseObject(res,SceneVo.class);
  79. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  80. JSONObject obj = (JSONObject) o;
  81. vo.setStatusString(getLaserStatus(vo.getStatus(),vo.getPayStatus()));
  82. vo.setStatus(toFdStatus(vo.getStatus()));
  83. vo.setSceneName(obj.getString("title"));
  84. vo.setUserName(obj.getString("phone"));
  85. vo.setThumb(obj.getString("thumb"));
  86. vo.setWebSite(obj.getString("webSite"));
  87. vo.setIsObj(obj.getInteger("buildObjStatus"));
  88. if(vo.getStatus() == -1){ //计算失败
  89. SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(vo.getNum());
  90. if(sceneBuildProcessLog != null){
  91. vo.setSceneBuildProcessLog(sceneBuildProcessLog);
  92. vo.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(sceneBuildProcessLog.getProcess()));
  93. vo.setDataSource(scenePlusService.getDataSourceByNum(vo.getNum()));
  94. }
  95. }
  96. this.getLaserSceneGps(vo);
  97. vo.setAddressComponent(commonService.getAddressComponent(vo.getGps()));
  98. if( vo.getMixture() == 0 && vo.getLocation() != null && vo.getLocation().equals(6)){
  99. vo.setShootCount(0);
  100. }
  101. sceneVoList.add(vo);
  102. }
  103. HashMap<String,SceneColdStorage> coldStorageMap = null;
  104. if(sceneVoList.size() >0){
  105. List<String> numList = sceneVoList.parallelStream().map(SceneVo::getNum).collect(Collectors.toList());
  106. coldStorageMap = sceneColdStorageService.getByNumList(numList);
  107. }
  108. Set<String> snCodes = sceneVoList.parallelStream().map(SceneVo::getSnCode).collect(Collectors.toSet());
  109. HashMap<String,User> snUserMap = userService.getUserBySn(snCodes);
  110. for (SceneVo sceneVo : sceneVoList) {
  111. if(coldStorageMap != null){
  112. SceneColdStorage sceneColdStorage = coldStorageMap.get(sceneVo.getNum());
  113. if(sceneColdStorage != null){
  114. sceneVo.setIsColdStorage(true);
  115. }
  116. }
  117. User user = snUserMap.get(sceneVo.getSnCode());
  118. if(user != null){
  119. sceneVo.setUserId(user.getId());
  120. sceneVo.setUserName(user.getUserName());
  121. }
  122. }
  123. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  124. voPage.setRecords(sceneVoList);
  125. voPage.setTotal(total);
  126. return PageInfo.PageInfo(voPage);
  127. }catch (Exception e){
  128. log.error("访问深时失败:",e);
  129. //throw new BusinessException(ResultCode.SS_GET_ERROR);
  130. }
  131. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  132. return PageInfo.PageInfo(voPage);
  133. }
  134. private void getLaserSceneGps(SceneVo vo) {
  135. // String redisKey = String.format(RedisKeyUtil.numGpsKey, vo.getNum());
  136. // String redisKey2 = String.format(RedisKeyUtil.numShootKey, vo.getNum());
  137. // if(redisUtil.hasKey(redisKey) && redisUtil.hasKey(redisKey2)){
  138. // String gps = redisUtil.get(redisKey);
  139. // String shootNum = redisUtil.get(redisKey2);
  140. // vo.setGps(gps);
  141. // vo.setShootCount(Integer.valueOf(shootNum));
  142. // return;
  143. // }
  144. ScenePro pro = sceneProService.getByNum(vo.getNum());
  145. if(pro != null){
  146. //redisUtil.set(redisKey,pro.getGps()== null ?"":pro.getGps());
  147. //redisUtil.set(redisKey2,String.valueOf(pro.getShootCount()== null ? 0 :pro.getShootCount()));
  148. vo.setGps(pro.getGps());
  149. vo.setShootCount(pro.getShootCount());
  150. }
  151. ScenePlus plus = scenePlusService.getByNum(vo.getNum());
  152. if(plus != null){
  153. ScenePlusExt ext = scenePlusExtService.getByPlusId(plus.getId());
  154. if(ext != null){
  155. //redisUtil.set(redisKey,ext.getGps()== null?"":ext.getGps());
  156. // redisUtil.set(redisKey2,String.valueOf(ext.getShootCount()== null ? 0 :ext.getShootCount()));
  157. vo.setGps(ext.getGps());
  158. vo.setShootCount(ext.getShootCount());
  159. }
  160. }
  161. }
  162. private LaserSceneParam getLaserSceneParam(SceneParam param) {
  163. LaserSceneParam newParam = new LaserSceneParam();
  164. if(param.getCompanyId()!= null){ //客户场景
  165. List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyId(param.getCompanyId());
  166. param.setSnCodes(this.setSnCodes(cameraDetails));
  167. if(param.getSnCodes() == null || param.getSnCodes().size() <=0){
  168. return null;
  169. }
  170. }
  171. if(StringUtils.isNotBlank(param.getUserName())){
  172. List<CameraDetail> cameraDetails = cameraDetailService.getByUserName(param.getUserName());
  173. List<String> snCodes = this.setSnCodes(cameraDetails);
  174. if(param.getCompanyId() == null){
  175. param.setSnCodes(snCodes);
  176. }else {
  177. if(snCodes == null || snCodes.size() <=0){
  178. return null;
  179. }
  180. //取交集
  181. List<String> intersection = param.getSnCodes().stream().filter(snCodes::contains).collect(Collectors.toList());
  182. param.setSnCodes(intersection);
  183. }
  184. }
  185. if(StringUtils.isNotBlank(param.getUserName()) && StringUtils.isBlank(param.getSnCode()) &&
  186. (param.getSnCodes() == null || param.getSnCodes().size() <=0)){
  187. param.setSnCode("phoneEmptySelect");
  188. }
  189. if(StringUtils.isNotBlank(param.getNum())){
  190. newParam.setSceneCode(param.getNum());
  191. }
  192. BeanUtils.copyProperties(param,newParam);
  193. newParam.setTitle(param.getSceneName());
  194. if(StringUtils.isNotBlank(param.getField()) && param.getField().equals("create_time")){
  195. newParam.setOrderBy("shoot_time");
  196. }else {
  197. newParam.setOrderBy(param.getField());
  198. }
  199. newParam.setSortBy(param.getOrder());
  200. if(param.getType() == 6){
  201. newParam.setSceneSource(5);
  202. }
  203. return newParam;
  204. }
  205. private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
  206. if(cameraDetails != null && cameraDetails.size() >0){
  207. Set<Long> cameraIds = cameraDetails.stream()
  208. .filter(entity -> entity.getType() == 10 || entity.getType() == 11).map(CameraDetail::getCameraId).collect(Collectors.toSet());
  209. if(cameraIds.size() >0){
  210. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  211. return cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  212. }
  213. }
  214. return null;
  215. }
  216. private Integer toFdStatus(Integer status) {
  217. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  218. switch (status){
  219. case 0 :
  220. case 4 :
  221. return 0;
  222. case 2 : return -2;
  223. case 3 : return -3;
  224. default: return -1;
  225. }
  226. }
  227. public static String getLaserStatus(Integer status,Integer payStatus){
  228. if(payStatus != null && payStatus == -2){
  229. return "封存";
  230. }
  231. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  232. switch (status){
  233. case -1 : return "场景已删除";
  234. case 0 :
  235. case 4 :
  236. return "计算中";
  237. case 1 : return "计算失败";
  238. case 2 : return "计算成功";
  239. case 3 : return "封存";
  240. default: return "";
  241. }
  242. }
  243. public void move(String num, String snCode, String toSnCode,Long userId,String newDataSource) {
  244. LaserSceneMoveParam param = new LaserSceneMoveParam();
  245. param.setSceneCode(num);
  246. //param.setSnCode(snCode);
  247. param.setToSnCode(toSnCode);
  248. param.setUserId(userId);
  249. param.setDataSource(newDataSource+"_laserData/laserData");
  250. if(userId != null){
  251. User user = userService.getById(userId);
  252. if(user != null){
  253. param.setPhone(user.getUserName());
  254. }
  255. }
  256. Map<String, Object> map = BeanUtil.beanToMap(param);
  257. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserMoveQueue,map);
  258. //laserClient.migrate(param);
  259. }
  260. public void moveWenBao(String num, String snCode, String toSnCode,Long userId,String newDataSource) {
  261. LaserSceneMoveParam param = new LaserSceneMoveParam();
  262. param.setSceneCode(num);
  263. //param.setSnCode(snCode);
  264. param.setToSnCode(toSnCode);
  265. param.setUserId(userId);
  266. param.setDataSource(newDataSource+"_laserData/laserData");
  267. if(userId != null){
  268. User user = userService.getById(userId);
  269. if(user != null){
  270. param.setPhone(user.getUserName());
  271. }
  272. }
  273. Map<String, Object> map = BeanUtil.beanToMap(param);
  274. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserMoveWenBaoQueue,map);
  275. //laserClient.migrate(param);
  276. }
  277. public void copy(String snCode, String createTime, String newNum, Integer status, String sceneKey, String sceneName, Long userId){
  278. String phone = null;
  279. if(userId != null){
  280. User user = userService.getById(userId);
  281. if(user != null){
  282. phone = user.getUserName();
  283. }
  284. }
  285. Map<String,Object> params = new HashMap<>();
  286. params.put("childName",snCode);
  287. params.put("createTime", createTime);
  288. params.put("phone", phone);
  289. params.put("sceneCode", newNum);
  290. params.put("snCode",snCode);
  291. params.put("status", status);
  292. params.put("password", sceneKey);
  293. params.put("title", sceneName);
  294. params.put("userId", userId);
  295. params.put("copy", true);
  296. Result result = laserClient.saveOrEdit(newNum, params);
  297. if( result.getCode() != HttpStatus.OK.value()){
  298. log.error("激光场景状态同步失败!");
  299. }
  300. }
  301. public void delete(String num) {
  302. try {
  303. Map<String,Object> params = new HashMap<>();
  304. params.put("sceneCode", num);
  305. params.put("status", -1);
  306. Result result = laserClient.saveOrEdit(num, params);
  307. if(result.getCode() != HttpStatus.OK.value()){
  308. log.error("激光场景状态同步失败!");
  309. }
  310. }catch (Exception e){
  311. log.error("激光场景状态同步失败!",e);
  312. }
  313. }
  314. public void disableCooperation(String snCode, String cooperationUserName){
  315. List<Map<String, String>> laserParams = new ArrayList<>();
  316. Map<String, String> param = new HashMap<>();
  317. param.put("snCode", snCode);
  318. param.put("cooperationUserName", cooperationUserName);
  319. laserParams.add(param);
  320. this.disableCooperation(laserParams);
  321. }
  322. public void disableCooperation(List<Map<String, String>> params) {
  323. if(params.size() <=0){
  324. return;
  325. }
  326. laserClient.cooperationDisable(params);
  327. }
  328. public SSDownSceneVo downOfflineSceneStatus(String num) {
  329. try {
  330. SSDownSceneVo vo ;
  331. SSDownSceneParam param = new SSDownSceneParam();
  332. param.setSceneCode(num);
  333. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  334. if( responseEntity.getCode() != HttpStatus.OK.value()){
  335. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  336. return null;
  337. }
  338. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  339. return vo;
  340. }catch (Exception e){
  341. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  342. }
  343. return null ;
  344. }
  345. public SSDownSceneVo downOfflineScene(String num) {
  346. try {
  347. SSDownSceneVo vo ;
  348. SSDownSceneParam param = new SSDownSceneParam();
  349. param.setSceneCode(num);
  350. Result responseEntity = laserClient.downOfflineScene(param);
  351. if( responseEntity.getCode() != HttpStatus.OK.value()){
  352. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  353. return null;
  354. }
  355. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  356. return vo ;
  357. }catch (Exception e){
  358. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  359. }
  360. return null ;
  361. }
  362. public void toBind(String snCode) {
  363. try {
  364. SsBindParam param = new SsBindParam();
  365. param.setBind(false);
  366. param.setSnCode(Lists.newArrayList(snCode));
  367. Result responseEntity = laserClient.toBind(param);
  368. if( responseEntity.getCode() != HttpStatus.OK.value()){
  369. log.error("解绑用户激光转台下载失败:{}",responseEntity);
  370. }
  371. }catch (Exception e){
  372. log.error("解绑用户获取激光转台下载状态失败!",e);
  373. }
  374. }
  375. }