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.*; import com.fdkankan.manage.entity.Camera; import com.fdkankan.manage.entity.CameraDetail; import com.fdkankan.manage.entity.SceneBuildProcessLog; 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.service.*; 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; @Autowired ISceneBuildProcessLogService sceneBuildProcessLogService; @Autowired IScenePlusService scenePlusService; public PageInfo pageList(SceneParam param) { try { if( !CacheUtil.uploadType.equals("oss")){ return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize()); } LaserSceneParam laserSceneParam = getLaserSceneParam(param); if(laserSceneParam == null ){ return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize()); } FdkkResponse response = laserClient.sceneList(laserSceneParam); JSONObject jsonObject =response.getData(); if(jsonObject == null){ return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize()); } JSONArray list = jsonObject.getJSONArray("list"); long total =jsonObject.getLong("total"); List sceneVoList = new ArrayList<>(); String newBasePath = basePath; newBasePath = newBasePath.contains("dev")? newBasePath + "/dev" : newBasePath; newBasePath = newBasePath.contains("uat")? newBasePath + "/uat" : newBasePath; newBasePath = newBasePath.replace("/backend",""); 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.setThumb(newBasePath +"/index.html?m="+vo.getNum() ); vo.setPayStatus(1); vo.setIsObj(obj.getInteger("buildObjStatus")); if(vo.getStatus() == -1){ //计算失败 SceneBuildProcessLog sceneBuildProcessLog = sceneBuildProcessLogService.getByNum(vo.getNum()); String process = null; if(sceneBuildProcessLog !=null){ process = sceneBuildProcessLog.getProcess(); } vo.setBuildErrorReason(SceneBuildProcessLogEnum.getReason(process)); vo.setDataSource(scenePlusService.getDataSourceByNum(vo.getNum())); } sceneVoList.add(vo); } Page voPage = new Page<>(param.getPageNum(),param.getPageSize()); voPage.setRecords(sceneVoList); voPage.setTotal(total); return PageInfo.PageInfo(voPage); }catch (Exception e){ log.error("访问深时失败:",e); //throw new BusinessException(ResultCode.SS_GET_ERROR); } Page voPage = new Page<>(param.getPageNum(),param.getPageSize()); return PageInfo.PageInfo(voPage); } 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()); List snCodes = this.setSnCodes(cameraDetails); if(param.getCompanyId() == null){ param.setSnCodes(snCodes); }else { if(snCodes == null || snCodes.size() <=0){ return null; } //取交集 List intersection = param.getSnCodes().stream().filter(snCodes::contains).collect(Collectors.toList()); param.setSnCodes(intersection); } } if(StringUtils.isNotBlank(param.getUserName()) && StringUtils.isBlank(param.getSnCode()) && (param.getSnCodes() == null || param.getSnCodes().size() <=0)){ param.setSnCode("phoneEmptySelect"); } if(StringUtils.isNotBlank(param.getNum())){ newParam.setSceneCode(param.getNum()); } BeanUtils.copyProperties(param,newParam); newParam.setTitle(param.getSceneName()); if(StringUtils.isNotBlank(param.getField()) && param.getField().equals("create_time")){ newParam.setOrderBy("shoot_time"); }else { newParam.setOrderBy(param.getField()); } newParam.setSortBy(param.getOrder()); return newParam; } private List setSnCodes(List cameraDetails) { if(cameraDetails != null && cameraDetails.size() >0){ Set cameraIds = cameraDetails.stream() .filter(entity -> entity.getGoodsId() == 10).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,Long userId) { LaserSceneMoveParam param = new LaserSceneMoveParam(); param.setSceneCode(num); param.setSnCode(snCode); param.setToSnCode(toSnCode); param.setUserId(userId); if(userId != null){ User user = userService.getById(userId); if(user != null){ param.setPhone(user.getUserName()); } } 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 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 ; } }