LaserService.java 12 KB

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