123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- package com.fdkankan.manage_jp.httpClient.service;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.manage_jp.common.PageInfo;
- import com.fdkankan.manage_jp.common.Result;
- import com.fdkankan.manage_jp.entity.Camera;
- import com.fdkankan.manage_jp.entity.CameraDetail;
- import com.fdkankan.manage_jp.entity.Company;
- import com.fdkankan.manage_jp.entity.User;
- import com.fdkankan.manage_jp.httpClient.client.LaserClient;
- import com.fdkankan.manage_jp.httpClient.param.LaserSceneParam;
- import com.fdkankan.manage_jp.httpClient.param.SSDownSceneParam;
- import com.fdkankan.manage_jp.httpClient.vo.FdkkResponse;
- import com.fdkankan.manage_jp.httpClient.vo.SSDownSceneVo;
- import com.fdkankan.manage_jp.service.ICameraDetailService;
- import com.fdkankan.manage_jp.service.ICameraService;
- import com.fdkankan.manage_jp.service.ICompanyService;
- import com.fdkankan.manage_jp.service.IUserService;
- import com.fdkankan.manage_jp.vo.request.SceneParam;
- import com.fdkankan.manage_jp.vo.response.SceneVo;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.collections4.CollectionUtils;
- 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 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
- ICompanyService companyService;
- public PageInfo pageList(SceneParam param) {
- 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<SceneVo> 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.setWebSite(newBasePath +"/index.html?m="+vo.getNum() );
- vo.setChildName(obj.getString("snCode"));
- vo.setPayStatus(1);
- sceneVoList.add(vo);
- }
- for (SceneVo sceneVo : sceneVoList) {
- Company company = companyService.getByChildName(sceneVo.getChildName());
- if(company != null){
- sceneVo.setCompanyName(company.getCompanyName());
- }
- }
- Page<SceneVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
- voPage.setRecords(sceneVoList);
- voPage.setTotal(total);
- return PageInfo.PageInfo(voPage);
- }
- 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(param.getUserId() != null){ //客户场景
- User user = userService.getById(param.getUserId());
- newParam.setPhone("no-user");
- if(user != null){
- newParam.setPhone(user.getUserName());
- }
- }
- if(StringUtils.isNotBlank(param.getCompanyName())){ //客户场景
- List<CameraDetail> cameraDetails = cameraDetailService.getListByCompanyName(param.getCompanyName());
- param.setSnCodes(this.setSnCodes(cameraDetails));
- if(param.getSnCodes() == null || param.getSnCodes().size() <=0){
- return null;
- }
- }
- if(StringUtils.isNotBlank(param.getChildName())){
- List<Camera> cameraList = cameraService.getLikeChildName(param.getChildName());
- List<String> snCodes = cameraList.stream().map(Camera::getSnCode).collect(Collectors.toList());
- if(snCodes.size() >0){
- if(param.getSnCodes() != null && param.getSnCodes().size() >0){
- List<String> list3 = param.getSnCodes().stream().filter(snCodes::contains).collect(Collectors.toList());
- param.setSnCodes(list3);
- }else {
- param.setSnCodes(snCodes);
- }
- }
- }
- BeanUtils.copyProperties(param,newParam);
- newParam.setTitle(param.getSceneName());
- return newParam;
- }
- private List<String> setSnCodes(List<CameraDetail> cameraDetails) {
- if(cameraDetails != null && cameraDetails.size() >0){
- Set<Long> cameraIds = cameraDetails.stream()
- .filter(entity -> entity.getGoodsId() == 10).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 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 ;
- }
- 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);
- }
- }
- }
|