LaserService.java 15 KB

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