LaserService.java 13 KB

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