LaserService.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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.CacheUtil;
  6. import com.fdkankan.manage.common.PageInfo;
  7. import com.fdkankan.manage.common.Result;
  8. import com.fdkankan.manage.entity.Camera;
  9. import com.fdkankan.manage.entity.CameraDetail;
  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.vo.FdkkResponse;
  17. import com.fdkankan.manage.httpClient.vo.LaserUpdateUserVo;
  18. import com.fdkankan.manage.service.ICameraDetailService;
  19. import com.fdkankan.manage.service.ICameraService;
  20. import com.fdkankan.manage.service.IUserService;
  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. public Page<SceneVo> pageList(SceneParam param) {
  48. LaserSceneParam laserSceneParam = new LaserSceneParam();
  49. laserSceneParam.setSceneCode(param.getNum());
  50. laserSceneParam.setTitle(param.getSceneName());
  51. laserSceneParam.setPageNum(param.getPageNum());
  52. laserSceneParam.setPageSize(param.getPageSize());
  53. laserSceneParam.setSnCode(param.getSnCode());
  54. if(param.getUserId() != null){
  55. laserSceneParam.setUserId(param.getUserId());
  56. }
  57. if(StringUtils.isNotBlank(param.getUserName())){
  58. List<User> likeUserName = userService.getLikeUserName(param.getUserName());
  59. List<Long> userIds = likeUserName.stream().map(User::getId).collect(Collectors.toList());
  60. laserSceneParam.setOtherUserIds(userIds);
  61. }
  62. if(param.getType() == 2){
  63. laserSceneParam.setSceneSource(4);
  64. List<String> collect = param.getAuthNumList().stream().filter(entity -> entity.contains("SS-") ).collect(Collectors.toList());
  65. laserSceneParam.setSceneCodes(collect);
  66. }
  67. if(param.getType() == 6){
  68. laserSceneParam.setSceneSource(5);
  69. List<String> collect = param.getAuthNumList().stream().filter(entity -> entity.contains("SG-") ).collect(Collectors.toList());
  70. laserSceneParam.setSceneCodes(collect);
  71. }
  72. FdkkResponse response = laserClient.sceneList(laserSceneParam);
  73. JSONObject jsonObject =response.getData();
  74. if(jsonObject == null){
  75. return null;
  76. }
  77. JSONArray list = jsonObject.getJSONArray("list");
  78. long total =jsonObject.getLong("total");
  79. List<SceneVo> sceneVoList = new ArrayList<>();
  80. for (Object o : list) {
  81. String res = JSONObject.toJSONString(o);
  82. SceneVo vo = JSONObject.parseObject(res,SceneVo.class);
  83. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  84. JSONObject obj = (JSONObject) o;
  85. vo.setStatusString(getLaserStatus(vo.getStatus()));
  86. vo.setStatus(toFdStatus(vo.getStatus()));
  87. if(vo.getStatus() == -3){
  88. vo.setPayStatus(-1);
  89. }else {
  90. vo.setPayStatus(1);
  91. }
  92. vo.setSceneName(obj.getString("title"));
  93. vo.setUserName(obj.getString("phone"));
  94. vo.setPayStatus(1);
  95. sceneVoList.add(vo);
  96. }
  97. Page<SceneVo> page = new Page<>();
  98. page.setTotal(total);
  99. page.setRecords(sceneVoList);
  100. return page;
  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. param.setSnCodes(this.setSnCodes(cameraDetails));
  114. }
  115. if(StringUtils.isNotBlank(param.getUserName()) && StringUtils.isBlank(param.getSnCode()) &&
  116. (param.getSnCodes() == null || param.getSnCodes().size() <=0)){
  117. param.setSnCode("phoneEmptySelect");
  118. }
  119. BeanUtils.copyProperties(param,newParam);
  120. newParam.setTitle(param.getSceneName());
  121. if(param.getType() == 6){
  122. newParam.setSceneSource(5);
  123. }
  124. return newParam;
  125. }
  126. private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
  127. if(cameraDetails != null && cameraDetails.size() >0){
  128. Set<Long> cameraIds = cameraDetails.stream()
  129. .filter(entity -> entity.getType() == 10 || entity.getType() == 11).map(CameraDetail::getCameraId).collect(Collectors.toSet());
  130. if(cameraIds.size() >0){
  131. List<Camera> cameraList = cameraService.listByIds(cameraIds);
  132. return cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
  133. }
  134. }
  135. return null;
  136. }
  137. private Integer toFdStatus(Integer status) {
  138. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  139. switch (status){
  140. case 0 :
  141. case 4 :
  142. return 0;
  143. case 2 : return -2;
  144. case 3 : return -3;
  145. default: return -1;
  146. }
  147. }
  148. public static String getLaserStatus(Integer status){
  149. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  150. switch (status){
  151. case -1 : return "场景已删除";
  152. case 0 : return "计算中";
  153. case 1 : return "计算失败";
  154. case 2 : return "计算成功";
  155. case 3 : return "封存";
  156. case 4 : return "生成OBJ中";
  157. default: return "";
  158. }
  159. }
  160. public void move(String num, String snCode, String toSnCode) {
  161. LaserSceneMoveParam param = new LaserSceneMoveParam();
  162. param.setSceneCode(num);
  163. param.setSnCode(snCode);
  164. param.setToSnCode(toSnCode);
  165. laserClient.migrate(param);
  166. }
  167. public void copy(String snCode, String createTime, String newNum, Integer status, String sceneKey, String sceneName, Long userId){
  168. String phone = null;
  169. if(userId != null){
  170. User user = userService.getById(userId);
  171. if(user != null){
  172. phone = user.getUserName();
  173. }
  174. }
  175. Map<String,Object> params = new HashMap<>();
  176. params.put("childName",snCode);
  177. params.put("createTime", createTime);
  178. params.put("phone", phone);
  179. params.put("sceneCode", newNum);
  180. params.put("snCode",snCode);
  181. params.put("status", status);
  182. params.put("password", sceneKey);
  183. params.put("title", sceneName);
  184. params.put("userId", userId);
  185. params.put("copy", true);
  186. Result result = laserClient.saveOrEdit(newNum, params);
  187. if( result.getCode() != HttpStatus.OK.value()){
  188. log.error("激光场景状态同步失败!");
  189. }
  190. }
  191. public void delete(String num) {
  192. try {
  193. Map<String,Object> params = new HashMap<>();
  194. params.put("sceneCode", num);
  195. params.put("status", -1);
  196. Result result = laserClient.saveOrEdit(num, params);
  197. if(result.getCode() != HttpStatus.OK.value()){
  198. log.error("激光场景状态同步失败!");
  199. }
  200. }catch (Exception e){
  201. log.error("激光场景状态同步失败!",e);
  202. }
  203. }
  204. public void disableCooperation(String snCode, String cooperationUserName){
  205. List<Map<String, String>> laserParams = new ArrayList<>();
  206. Map<String, String> param = new HashMap<>();
  207. param.put("snCode", snCode);
  208. param.put("cooperationUserName", cooperationUserName);
  209. laserParams.add(param);
  210. this.disableCooperation(laserParams);
  211. }
  212. public void disableCooperation(List<Map<String, String>> params) {
  213. if(params.size() <=0){
  214. return;
  215. }
  216. laserClient.cooperationDisable(params);
  217. }
  218. public void updateUser(LaserUpdateUserVo laserUpdateUserVo) {
  219. FdkkResponse fdkkResponse = laserClient.updateUser(laserUpdateUserVo);
  220. if(fdkkResponse.getCode() != 200){
  221. throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
  222. }
  223. }
  224. public SSDownSceneVo downOfflineSceneStatus(String num) {
  225. try {
  226. SSDownSceneVo vo ;
  227. SSDownSceneParam param = new SSDownSceneParam();
  228. param.setSceneCode(num);
  229. Result responseEntity = laserClient.downOfflineSceneStatus(param);
  230. if( responseEntity.getCode() != HttpStatus.OK.value()){
  231. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
  232. return null;
  233. }
  234. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  235. return vo;
  236. }catch (Exception e){
  237. log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
  238. }
  239. return null ;
  240. }
  241. public SSDownSceneVo downOfflineScene(String num) {
  242. try {
  243. SSDownSceneVo vo ;
  244. SSDownSceneParam param = new SSDownSceneParam();
  245. param.setSceneCode(num);
  246. Result responseEntity = laserClient.downOfflineScene(param);
  247. if( responseEntity.getCode() != HttpStatus.OK.value()){
  248. log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
  249. return null;
  250. }
  251. vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
  252. return vo ;
  253. }catch (Exception e){
  254. log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
  255. }
  256. return null ;
  257. }
  258. }