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 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 likeUserName = userService.getLikeUserName(param.getUserName()); List userIds = likeUserName.stream().map(User::getId).collect(Collectors.toList()); laserSceneParam.setOtherUserIds(userIds); } if(param.getType() == 2){ laserSceneParam.setSceneSource(4); List collect = param.getAuthNumList().stream().filter(entity -> entity.contains("SS-") ).collect(Collectors.toList()); laserSceneParam.setSceneCodes(collect); } if(param.getType() == 6){ laserSceneParam.setSceneSource(5); List 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 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 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 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 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 setSnCodes(List cameraDetails) { if(cameraDetails != null && cameraDetails.size() >0){ Set cameraIds = cameraDetails.stream() .filter(entity -> entity.getType() == 10 || entity.getType() == 11).map(CameraDetail::getCameraId).collect(Collectors.toSet()); if(cameraIds.size() >0){ List 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 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 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> laserParams = new ArrayList<>(); Map param = new HashMap<>(); param.put("snCode", snCode); param.put("cooperationUserName", cooperationUserName); laserParams.add(param); this.disableCooperation(laserParams); } public void disableCooperation(List> 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 ; } }