LaserService.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package com.fdkankan.manage_jp.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_jp.common.PageInfo;
  6. import com.fdkankan.manage_jp.common.Result;
  7. import com.fdkankan.manage_jp.entity.Camera;
  8. import com.fdkankan.manage_jp.entity.CameraDetail;
  9. import com.fdkankan.manage_jp.entity.Company;
  10. import com.fdkankan.manage_jp.entity.User;
  11. import com.fdkankan.manage_jp.httpClient.client.LaserClient;
  12. import com.fdkankan.manage_jp.httpClient.param.LaserSceneParam;
  13. import com.fdkankan.manage_jp.httpClient.param.SSDownSceneParam;
  14. import com.fdkankan.manage_jp.httpClient.vo.FdkkResponse;
  15. import com.fdkankan.manage_jp.httpClient.vo.SSDownSceneVo;
  16. import com.fdkankan.manage_jp.service.ICameraDetailService;
  17. import com.fdkankan.manage_jp.service.ICameraService;
  18. import com.fdkankan.manage_jp.service.ICompanyService;
  19. import com.fdkankan.manage_jp.service.IUserService;
  20. import com.fdkankan.manage_jp.vo.request.SceneParam;
  21. import com.fdkankan.manage_jp.vo.response.SceneVo;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.apache.commons.collections4.CollectionUtils;
  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 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. ICompanyService companyService;
  47. public PageInfo pageList(SceneParam param) {
  48. LaserSceneParam laserSceneParam = getLaserSceneParam(param);
  49. if(laserSceneParam == null ){
  50. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  51. }
  52. FdkkResponse response = laserClient.sceneList(laserSceneParam);
  53. JSONObject jsonObject =response.getData();
  54. if(jsonObject == null){
  55. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  56. }
  57. JSONArray list = jsonObject.getJSONArray("list");
  58. long total =jsonObject.getLong("total");
  59. List<SceneVo> sceneVoList = new ArrayList<>();
  60. String newBasePath = basePath;
  61. newBasePath = newBasePath.contains("dev")? newBasePath + "/dev" : newBasePath;
  62. newBasePath = newBasePath.contains("uat")? newBasePath + "/uat" : newBasePath;
  63. newBasePath = newBasePath.replace("/backend","");
  64. for (Object o : list) {
  65. String res = JSONObject.toJSONString(o);
  66. SceneVo vo = JSONObject.parseObject(res,SceneVo.class);
  67. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  68. JSONObject obj = (JSONObject) o;
  69. vo.setStatusString(getLaserStatus(vo.getStatus()));
  70. vo.setStatus(toFdStatus(vo.getStatus()));
  71. if(vo.getStatus() == -3){
  72. vo.setPayStatus(-1);
  73. }else {
  74. vo.setPayStatus(1);
  75. }
  76. vo.setSceneName(obj.getString("title"));
  77. vo.setUserName(obj.getString("phone"));
  78. vo.setWebSite(newBasePath +"/index.html?m="+vo.getNum() );
  79. vo.setChildName(obj.getString("snCode"));
  80. vo.setPayStatus(1);
  81. sceneVoList.add(vo);
  82. }
  83. for (SceneVo sceneVo : sceneVoList) {
  84. Company company = companyService.getByChildName(sceneVo.getChildName());
  85. if(company != null){
  86. sceneVo.setCompanyName(company.getCompanyName());
  87. }
  88. }
  89. Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
  90. voPage.setRecords(sceneVoList);
  91. voPage.setTotal(total);
  92. return PageInfo.PageInfo(voPage);
  93. }
  94. private LaserSceneParam getLaserSceneParam(SceneParam param) {
  95. LaserSceneParam newParam = new LaserSceneParam();
  96. if(param.getCompanyId() != null){ //客户场景
  97. List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyId(param.getCompanyId());
  98. param.setSnCodes(this.setSnCodes(cameraDetails));
  99. if(param.getSnCodes() == null || param.getSnCodes().size() <=0){
  100. return null;
  101. }
  102. }
  103. if(param.getUserId() != null){ //客户场景
  104. User user = userService.getById(param.getUserId());
  105. newParam.setPhone("no-user");
  106. if(user != null){
  107. newParam.setPhone(user.getUserName());
  108. }
  109. }
  110. if(StringUtils.isNotBlank(param.getCompanyName())){ //客户场景
  111. List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyName(param.getCompanyName());
  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.getChildName())){
  118. List<Camera> cameraList = cameraService.getLikeChildName(param.getChildName());
  119. List<String> snCodes = cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  120. if(snCodes.size() >0){
  121. if(param.getSnCodes() != null && param.getSnCodes().size() >0){
  122. List<String> list3 = param.getSnCodes().stream().filter(snCodes::contains).collect(Collectors.toList());
  123. param.setSnCodes(list3);
  124. }else {
  125. param.setSnCodes(snCodes);
  126. }
  127. }
  128. }
  129. BeanUtils.copyProperties(param,newParam);
  130. newParam.setTitle(param.getSceneName());
  131. return newParam;
  132. }
  133. private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
  134. if(cameraDetails != null && cameraDetails.size() >0){
  135. Set<Long> cameraIds = cameraDetails.stream()
  136. .filter(entity -> entity.getGoodsId() == 10).map(CameraDetail::getCameraId).collect(Collectors.toSet());
  137. if(cameraIds.size() >0){
  138. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  139. return cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  140. }
  141. }
  142. return null;
  143. }
  144. private Integer toFdStatus(Integer status) {
  145. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  146. switch (status){
  147. case 0 :
  148. case 4 :
  149. return 0;
  150. case 2 : return -2;
  151. case 3 : return -3;
  152. default: return -1;
  153. }
  154. }
  155. public static String getLaserStatus(Integer status){
  156. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  157. switch (status){
  158. case -1 : return "场景已删除";
  159. case 0 : return "计算中";
  160. case 1 : return "计算失败";
  161. case 2 : return "计算成功";
  162. case 3 : return "封存";
  163. case 4 : return "生成OBJ中";
  164. default: return "";
  165. }
  166. }
  167. public SSDownSceneVo downOfflineSceneStatus(String num) {
  168. try {
  169. SSDownSceneVo vo ;
  170. SSDownSceneParam param = new SSDownSceneParam();
  171. param.setSceneCode(num);
  172. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  173. if( responseEntity.getCode() != HttpStatus.OK.value()){
  174. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  175. return null;
  176. }
  177. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  178. return vo;
  179. }catch (Exception e){
  180. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  181. }
  182. return null ;
  183. }
  184. public SSDownSceneVo downOfflineScene(String num) {
  185. try {
  186. SSDownSceneVo vo ;
  187. SSDownSceneParam param = new SSDownSceneParam();
  188. param.setSceneCode(num);
  189. Result responseEntity = laserClient.downOfflineScene(param);
  190. if( responseEntity.getCode() != HttpStatus.OK.value()){
  191. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  192. return null;
  193. }
  194. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  195. return vo ;
  196. }catch (Exception e){
  197. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  198. }
  199. return null ;
  200. }
  201. public void delete(String num) {
  202. try {
  203. Map<String,Object> params = new HashMap<>();
  204. params.put("sceneCode", num);
  205. params.put("status", -1);
  206. Result result = laserClient.saveOrEdit(num, params);
  207. if(result.getCode() != HttpStatus.OK.value()){
  208. log.error("激光场景状态同步失败!");
  209. }
  210. }catch (Exception e){
  211. log.error("激光场景状态同步失败!",e);
  212. }
  213. }
  214. }