123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- package com.fdkankan.manage.httpClient.service;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.manage.common.CacheUtil;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.common.Result;
- import com.fdkankan.manage.entity.Camera;
- import com.fdkankan.manage.entity.CameraDetail;
- import com.fdkankan.manage.entity.User;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.httpClient.client.LaserClient;
- import com.fdkankan.manage.httpClient.param.LaserSceneMoveParam;
- import com.fdkankan.manage.httpClient.param.LaserSceneParam;
- import com.fdkankan.manage.httpClient.param.SSDownSceneParam;
- import com.fdkankan.manage.httpClient.vo.FdkkResponse;
- import com.fdkankan.manage.httpClient.vo.LaserUpdateUserVo;
- import com.fdkankan.manage.service.ICameraDetailService;
- import com.fdkankan.manage.service.ICameraService;
- import com.fdkankan.manage.service.IUserService;
- import com.fdkankan.manage.vo.request.SceneParam;
- import com.fdkankan.manage.vo.response.SSDownSceneVo;
- import com.fdkankan.manage.vo.response.SceneVo;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.http.HttpStatus;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.*;
- import java.util.stream.Collectors;
- @Service
- @Slf4j
- public class LaserService {
- @Autowired
- LaserClient laserClient;
- @Value("${4dkk.laserService.basePath}")
- private String basePath;
- @Autowired
- IUserService userService;
- @Autowired
- ICameraDetailService cameraDetailService;
- @Autowired
- ICameraService cameraService;
- public Page<SceneVo> pageList(SceneParam param) {
- LaserSceneParam laserSceneParam = new LaserSceneParam();
- laserSceneParam.setSceneCode(param.getNum());
- laserSceneParam.setTitle(param.getSceneName());
- laserSceneParam.setPageNum(param.getPageNum());
- laserSceneParam.setPageSize(param.getPageSize());
- laserSceneParam.setSnCode(param.getSnCode());
- if(param.getUserId() != null){
- laserSceneParam.setUserId(param.getUserId());
- }
- if(StringUtils.isNotBlank(param.getUserName())){
- List<User> likeUserName = userService.getLikeUserName(param.getUserName());
- List<Long> userIds = likeUserName.stream().map(User::getId).collect(Collectors.toList());
- laserSceneParam.setOtherUserIds(userIds);
- }
- if(param.getType() == 2){
- laserSceneParam.setSceneSource(4);
- List<String> collect = param.getAuthNumList().stream().filter(entity -> entity.contains("SS-") ).collect(Collectors.toList());
- laserSceneParam.setSceneCodes(collect);
- }
- if(param.getType() == 6){
- laserSceneParam.setSceneSource(5);
- List<String> collect = param.getAuthNumList().stream().filter(entity -> entity.contains("SG-") ).collect(Collectors.toList());
- laserSceneParam.setSceneCodes(collect);
- }
- FdkkResponse response = laserClient.sceneList(laserSceneParam);
- JSONObject jsonObject =response.getData();
- if(jsonObject == null){
- return null;
- }
- JSONArray list = jsonObject.getJSONArray("list");
- long total =jsonObject.getLong("total");
- List<SceneVo> sceneVoList = new ArrayList<>();
- for (Object o : list) {
- String res = JSONObject.toJSONString(o);
- SceneVo vo = JSONObject.parseObject(res,SceneVo.class);
- //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
- JSONObject obj = (JSONObject) o;
- vo.setStatusString(getLaserStatus(vo.getStatus()));
- vo.setStatus(toFdStatus(vo.getStatus()));
- if(vo.getStatus() == -3){
- vo.setPayStatus(-1);
- }else {
- vo.setPayStatus(1);
- }
- vo.setSceneName(obj.getString("title"));
- vo.setUserName(obj.getString("phone"));
- vo.setPayStatus(1);
- sceneVoList.add(vo);
- }
- Page<SceneVo> page = new Page<>();
- page.setTotal(total);
- page.setRecords(sceneVoList);
- return page;
- }
- private LaserSceneParam getLaserSceneParam(SceneParam param) {
- LaserSceneParam newParam = new LaserSceneParam();
- if(param.getCompanyId()!= null){ //客户场景
- List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyId(param.getCompanyId());
- param.setSnCodes(this.setSnCodes(cameraDetails));
- if(param.getSnCodes() == null || param.getSnCodes().size() <=0){
- return null;
- }
- }
- if(StringUtils.isNotBlank(param.getUserName())){
- List<CameraDetail> cameraDetails = cameraDetailService.getByUserName(param.getUserName());
- param.setSnCodes(this.setSnCodes(cameraDetails));
- }
- if(StringUtils.isNotBlank(param.getUserName()) && StringUtils.isBlank(param.getSnCode()) &&
- (param.getSnCodes() == null || param.getSnCodes().size() <=0)){
- param.setSnCode("phoneEmptySelect");
- }
- BeanUtils.copyProperties(param,newParam);
- newParam.setTitle(param.getSceneName());
- if(param.getType() == 6){
- newParam.setSceneSource(5);
- }
- return newParam;
- }
- private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
- if(cameraDetails != null && cameraDetails.size() >0){
- Set<Long> cameraIds = cameraDetails.stream()
- .filter(entity -> entity.getType() == 10 || entity.getType() == 11).map(CameraDetail::getCameraId).collect(Collectors.toSet());
- if(cameraIds.size() >0){
- List<Camera> cameraList = cameraService.listByIds(cameraIds);
- return cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
- }
- }
- return null;
- }
- private Integer toFdStatus(Integer status) {
- //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
- switch (status){
- case 0 :
- case 4 :
- return 0;
- case 2 : return -2;
- case 3 : return -3;
- default: return -1;
- }
- }
- public static String getLaserStatus(Integer status){
- //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
- switch (status){
- case -1 : return "场景已删除";
- case 0 : return "计算中";
- case 1 : return "计算失败";
- case 2 : return "计算成功";
- case 3 : return "封存";
- case 4 : return "生成OBJ中";
- default: return "";
- }
- }
- public void move(String num, String snCode, String toSnCode) {
- LaserSceneMoveParam param = new LaserSceneMoveParam();
- param.setSceneCode(num);
- param.setSnCode(snCode);
- param.setToSnCode(toSnCode);
- laserClient.migrate(param);
- }
- public void copy(String snCode, String createTime, String newNum, Integer status, String sceneKey, String sceneName, Long userId){
- String phone = null;
- if(userId != null){
- User user = userService.getById(userId);
- if(user != null){
- phone = user.getUserName();
- }
- }
- Map<String,Object> params = new HashMap<>();
- params.put("childName",snCode);
- params.put("createTime", createTime);
- params.put("phone", phone);
- params.put("sceneCode", newNum);
- params.put("snCode",snCode);
- params.put("status", status);
- params.put("password", sceneKey);
- params.put("title", sceneName);
- params.put("userId", userId);
- params.put("copy", true);
- Result result = laserClient.saveOrEdit(newNum, params);
- if( result.getCode() != HttpStatus.OK.value()){
- log.error("激光场景状态同步失败!");
- }
- }
- public void delete(String num) {
- try {
- Map<String,Object> params = new HashMap<>();
- params.put("sceneCode", num);
- params.put("status", -1);
- Result result = laserClient.saveOrEdit(num, params);
- if(result.getCode() != HttpStatus.OK.value()){
- log.error("激光场景状态同步失败!");
- }
- }catch (Exception e){
- log.error("激光场景状态同步失败!",e);
- }
- }
- public void disableCooperation(String snCode, String cooperationUserName){
- List<Map<String, String>> laserParams = new ArrayList<>();
- Map<String, String> param = new HashMap<>();
- param.put("snCode", snCode);
- param.put("cooperationUserName", cooperationUserName);
- laserParams.add(param);
- this.disableCooperation(laserParams);
- }
- public void disableCooperation(List<Map<String, String>> params) {
- if(params.size() <=0){
- return;
- }
- laserClient.cooperationDisable(params);
- }
- public void updateUser(LaserUpdateUserVo laserUpdateUserVo) {
- FdkkResponse fdkkResponse = laserClient.updateUser(laserUpdateUserVo);
- if(fdkkResponse.getCode() != 200){
- throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
- }
- }
- public SSDownSceneVo downOfflineSceneStatus(String num) {
- try {
- SSDownSceneVo vo ;
- SSDownSceneParam param = new SSDownSceneParam();
- param.setSceneCode(num);
- Result responseEntity = laserClient.downOfflineSceneStatus(param);
- if( responseEntity.getCode() != HttpStatus.OK.value()){
- log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败:{}",responseEntity);
- return null;
- }
- vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
- return vo;
- }catch (Exception e){
- log.error("downOfflineSceneStatus-根据场景码获取激光转台下载状态失败!",e);
- }
- return null ;
- }
- public SSDownSceneVo downOfflineScene(String num) {
- try {
- SSDownSceneVo vo ;
- SSDownSceneParam param = new SSDownSceneParam();
- param.setSceneCode(num);
- Result responseEntity = laserClient.downOfflineScene(param);
- if( responseEntity.getCode() != HttpStatus.OK.value()){
- log.error("downOfflineScene-根据场景码获取激光转台下载失败:{}",responseEntity);
- return null;
- }
- vo = JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), SSDownSceneVo.class);
- return vo ;
- }catch (Exception e){
- log.error("downOfflineScene-根据场景码获取激光转台下载状态失败!",e);
- }
- return null ;
- }
- }
|