LaserService.java 13 KB

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