LaserService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. package com.fdkankan.manage.httpClient.service;
  2. import com.fdkankan.manage.mq.common.MqQueueUtil;
  3. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  4. import com.google.common.collect.Lists;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.fdkankan.manage.common.*;
  9. import com.fdkankan.manage.entity.Camera;
  10. import com.fdkankan.manage.entity.CameraDetail;
  11. import com.fdkankan.manage.entity.SceneBuildProcessLog;
  12. import com.fdkankan.manage.entity.User;
  13. import com.fdkankan.manage.exception.BusinessException;
  14. import com.fdkankan.manage.httpClient.client.LaserClient;
  15. import com.fdkankan.manage.httpClient.param.LaserSceneMoveParam;
  16. import com.fdkankan.manage.httpClient.param.LaserSceneParam;
  17. import com.fdkankan.manage.httpClient.param.SSDownSceneParam;
  18. import com.fdkankan.manage.httpClient.param.SsBindParam;
  19. import com.fdkankan.manage.httpClient.vo.FdkkResponse;
  20. import com.fdkankan.manage.service.*;
  21. import com.fdkankan.manage.vo.request.SceneParam;
  22. import com.fdkankan.manage.vo.response.SSDownSceneVo;
  23. import com.fdkankan.manage.vo.response.SceneVo;
  24. import lombok.extern.slf4j.Slf4j;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.BeanUtils;
  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 javax.annotation.Resource;
  32. import java.util.*;
  33. import java.util.stream.Collectors;
  34. @Service
  35. @Slf4j
  36. public class LaserService {
  37. @Autowired
  38. LaserClient laserClient;
  39. @Value("${4dkk.laserService.basePath}")
  40. private String basePath;
  41. @Autowired
  42. IUserService userService;
  43. @Autowired
  44. ICameraDetailService cameraDetailService;
  45. @Autowired
  46. ICameraService cameraService;
  47. @Autowired
  48. ISceneBuildProcessLogService sceneBuildProcessLogService;
  49. @Autowired
  50. IScenePlusService scenePlusService;
  51. @Autowired
  52. RabbitMqProducer rabbitMqProducer;
  53. public PageInfo pageList(SceneParam param) {
  54. try {
  55. LaserSceneParam laserSceneParam = getLaserSceneParam(param);
  56. if(laserSceneParam == null ){
  57. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  58. }
  59. FdkkResponse response = laserClient.sceneList(laserSceneParam);
  60. JSONObject jsonObject =response.getData();
  61. if(jsonObject == null){
  62. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  63. }
  64. JSONArray list = jsonObject.getJSONArray("list");
  65. long total =jsonObject.getLong("total");
  66. List<SceneVo> sceneVoList = new ArrayList<>();
  67. for (Object o : list) {
  68. String res = JSONObject.toJSONString(o);
  69. SceneVo vo = JSONObject.parseObject(res,SceneVo.class);
  70. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  71. JSONObject obj = (JSONObject) o;
  72. vo.setStatusString(getLaserStatus(vo.getStatus()));
  73. vo.setStatus(toFdStatus(vo.getStatus()));
  74. if(vo.getStatus() == -3){
  75. vo.setPayStatus(-1);
  76. }else {
  77. vo.setPayStatus(1);
  78. }
  79. vo.setSceneName(obj.getString("title"));
  80. vo.setUserName(obj.getString("phone"));
  81. vo.setThumb(obj.getString("thumb"));
  82. vo.setWebSite(obj.getString("webSite"));
  83. vo.setPayStatus(1);
  84. vo.setIsObj(obj.getInteger("buildObjStatus"));
  85. if(vo.getStatus() == -1){ //计算失败
  86. SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(vo.getNum());
  87. if(sceneBuildProcessLog != null){
  88. vo.setSceneBuildProcessLog(sceneBuildProcessLog);
  89. vo.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(sceneBuildProcessLog.getProcess()));
  90. vo.setDataSource(scenePlusService.getDataSourceByNum(vo.getNum()));
  91. }
  92. }
  93. sceneVoList.add(vo);
  94. }
  95. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  96. voPage.setRecords(sceneVoList);
  97. voPage.setTotal(total);
  98. return PageInfo.PageInfo(voPage);
  99. }catch (Exception e){
  100. log.error("访问深时失败:",e);
  101. //throw new BusinessException(ResultCode.SS_GET_ERROR);
  102. }
  103. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  104. return PageInfo.PageInfo(voPage);
  105. }
  106. private LaserSceneParam getLaserSceneParam(SceneParam param) {
  107. LaserSceneParam newParam = new LaserSceneParam();
  108. if(param.getCompanyId()!= null){ //客户场景
  109. List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyId(param.getCompanyId());
  110. param.setSnCodes(this.setSnCodes(cameraDetails));
  111. if(param.getSnCodes() == null || param.getSnCodes().size() <=0){
  112. return null;
  113. }
  114. }
  115. if(StringUtils.isNotBlank(param.getUserName())){
  116. List<CameraDetail> cameraDetails = cameraDetailService.getByUserName(param.getUserName());
  117. List<String> snCodes = this.setSnCodes(cameraDetails);
  118. if(param.getCompanyId() == null){
  119. param.setSnCodes(snCodes);
  120. }else {
  121. if(snCodes == null || snCodes.size() <=0){
  122. return null;
  123. }
  124. //取交集
  125. List<String> intersection = param.getSnCodes().stream().filter(snCodes::contains).collect(Collectors.toList());
  126. param.setSnCodes(intersection);
  127. }
  128. }
  129. if(StringUtils.isNotBlank(param.getUserName()) && StringUtils.isBlank(param.getSnCode()) &&
  130. (param.getSnCodes() == null || param.getSnCodes().size() <=0)){
  131. param.setSnCode("phoneEmptySelect");
  132. }
  133. if(StringUtils.isNotBlank(param.getNum())){
  134. newParam.setSceneCode(param.getNum());
  135. }
  136. BeanUtils.copyProperties(param,newParam);
  137. newParam.setTitle(param.getSceneName());
  138. if(StringUtils.isNotBlank(param.getField()) && param.getField().equals("create_time")){
  139. newParam.setOrderBy("shoot_time");
  140. }else {
  141. newParam.setOrderBy(param.getField());
  142. }
  143. newParam.setSortBy(param.getOrder());
  144. if(param.getType() == 6){
  145. newParam.setSceneSource(5);
  146. }
  147. return newParam;
  148. }
  149. private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
  150. if(cameraDetails != null && cameraDetails.size() >0){
  151. Set<Long> cameraIds = cameraDetails.stream()
  152. .filter(entity -> entity.getType() == 10).map(CameraDetail::getCameraId).collect(Collectors.toSet());
  153. if(cameraIds.size() >0){
  154. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  155. return cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  156. }
  157. }
  158. return null;
  159. }
  160. private Integer toFdStatus(Integer status) {
  161. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  162. switch (status){
  163. case 0 :
  164. case 4 :
  165. return 0;
  166. case 2 : return -2;
  167. case 3 : return -3;
  168. default: return -1;
  169. }
  170. }
  171. public static String getLaserStatus(Integer status){
  172. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  173. switch (status){
  174. case -1 : return "场景已删除";
  175. case 0 : return "计算中";
  176. case 1 : return "计算失败";
  177. case 2 : return "计算成功";
  178. case 3 : return "封存";
  179. case 4 : return "生成OBJ中";
  180. default: return "";
  181. }
  182. }
  183. public void move(String num, String snCode, String toSnCode,Long userId,String newDataSource) {
  184. LaserSceneMoveParam param = new LaserSceneMoveParam();
  185. param.setSceneCode(num);
  186. //param.setSnCode(snCode);
  187. param.setToSnCode(toSnCode);
  188. param.setUserId(userId);
  189. param.setDataSource(newDataSource+"_laserData/laserData");
  190. if(userId != null){
  191. User user = userService.getById(userId);
  192. if(user != null){
  193. param.setPhone(user.getUserName());
  194. }
  195. }
  196. rabbitMqProducer.sendByWorkQueue(MqQueueUtil.laserMoveQueue,JSONObject.toJSONString(param));
  197. //laserClient.migrate(param);
  198. }
  199. public void copy(String snCode, String createTime, String newNum, Integer status, String sceneKey, String sceneName, Long userId){
  200. String phone = null;
  201. if(userId != null){
  202. User user = userService.getById(userId);
  203. if(user != null){
  204. phone = user.getUserName();
  205. }
  206. }
  207. Map<String,Object> params = new HashMap<>();
  208. params.put("childName",snCode);
  209. params.put("createTime", createTime);
  210. params.put("phone", phone);
  211. params.put("sceneCode", newNum);
  212. params.put("snCode",snCode);
  213. params.put("status", status);
  214. params.put("password", sceneKey);
  215. params.put("title", sceneName);
  216. params.put("userId", userId);
  217. params.put("copy", true);
  218. Result result = laserClient.saveOrEdit(newNum, params);
  219. if( result.getCode() != HttpStatus.OK.value()){
  220. log.error("激光场景状态同步失败!");
  221. }
  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. log.error("激光场景状态同步失败!");
  231. }
  232. }catch (Exception e){
  233. log.error("激光场景状态同步失败!",e);
  234. }
  235. }
  236. public void disableCooperation(String snCode, String cooperationUserName){
  237. List<Map<String, String>> laserParams = new ArrayList<>();
  238. Map<String, String> param = new HashMap<>();
  239. param.put("snCode", snCode);
  240. param.put("cooperationUserName", cooperationUserName);
  241. laserParams.add(param);
  242. this.disableCooperation(laserParams);
  243. }
  244. public void disableCooperation(List<Map<String, String>> params) {
  245. if(params.size() <=0){
  246. return;
  247. }
  248. laserClient.cooperationDisable(params);
  249. }
  250. public SSDownSceneVo downOfflineSceneStatus(String num) {
  251. try {
  252. SSDownSceneVo vo ;
  253. SSDownSceneParam param = new SSDownSceneParam();
  254. param.setSceneCode(num);
  255. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  256. if( responseEntity.getCode() != HttpStatus.OK.value()){
  257. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  258. return null;
  259. }
  260. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  261. return vo;
  262. }catch (Exception e){
  263. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  264. }
  265. return null ;
  266. }
  267. public SSDownSceneVo downOfflineScene(String num) {
  268. try {
  269. SSDownSceneVo vo ;
  270. SSDownSceneParam param = new SSDownSceneParam();
  271. param.setSceneCode(num);
  272. Result responseEntity = laserClient.downOfflineScene(param);
  273. if( responseEntity.getCode() != HttpStatus.OK.value()){
  274. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  275. return null;
  276. }
  277. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  278. return vo ;
  279. }catch (Exception e){
  280. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  281. }
  282. return null ;
  283. }
  284. public void toBind(String snCode) {
  285. try {
  286. SsBindParam param = new SsBindParam();
  287. param.setBind(false);
  288. param.setSnCode(Lists.newArrayList(snCode));
  289. Result responseEntity = laserClient.toBind(param);
  290. if( responseEntity.getCode() != HttpStatus.OK.value()){
  291. log.error("解绑用户激光转台下载失败:{}",responseEntity);
  292. }
  293. }catch (Exception e){
  294. log.error("解绑用户获取激光转台下载状态失败!",e);
  295. }
  296. }
  297. }