소스 검색

修改:保存场景后返回树分组

wuweihao 4 년 전
부모
커밋
49628fd695

+ 35 - 0
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/dto/CatalogSceneDto.java

@@ -0,0 +1,35 @@
+package com.gis.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * Created by owen on 2021/2/22 0022 10:24
+ */
+@Data
+public class CatalogSceneDto {
+
+    @ApiModelProperty(value = "目录名称")
+    private String CatalogName;
+
+    @ApiModelProperty(value = "目录Id")
+    private Long CatalogId;
+
+    @ApiModelProperty(value = "父目录Id")
+    private Long parentId;
+
+    @ApiModelProperty(value = "父目录名称")
+    private String parentName;
+
+    @NotNull(message = "作品id不能为空")
+    @ApiModelProperty(value = "作品id")
+    private Long workId;
+
+    @ApiModelProperty(value = "场景")
+    private List<SceneDto> scenes;
+
+}

+ 2 - 17
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/dto/SceneDto.java

@@ -14,36 +14,21 @@ public class SceneDto {
     @ApiModelProperty(value = "id, 修改时必须传,新增忽略", name = "id")
     private Long id;
 
-//    @NotBlank(message = "标题不能为空")
     @ApiModelProperty(value = "场景名称")
     private String sceneTitle;
 
     @ApiModelProperty(value = "场景码")
     private String sceneCode;
 
-//    @NotBlank(message = "封面图不能为空")
     @ApiModelProperty(value = "封面图")
     private String icon;
 
-//    @ApiModelProperty(value = "分组Id")
-//    private Long catalogId;
-
-    @ApiModelProperty(value = "作品Id")
-    private Long workId;
+//    @ApiModelProperty(value = "作品Id")
+//    private Long workId;
 
     @ApiModelProperty(value = "类型:pano/4dkk")
     private String type;
 
-    @ApiModelProperty(value = "目录名称")
-    private String CatalogName;
-
-    @ApiModelProperty(value = "目录Id")
-    private Long CatalogId;
-
-    @ApiModelProperty(value = "父目录Id")
-    private Long parentId;
 
-    @ApiModelProperty(value = "父目录名称")
-    private String parentName;
 
 }

+ 0 - 60
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/dto/VrModelDto.java

@@ -1,60 +0,0 @@
-package com.gis.domain.dto;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-import javax.validation.constraints.NotBlank;
-
-/**
- * Created by owen on 2020/5/28 0028 16:36
- * 保存VR模型实体
- */
-@Data
-public class VrModelDto {
-
-    @ApiModelProperty(value = "id, 修改时必须传,新增忽略", name = "id")
-    private String id;
-
-    @NotBlank(message = "楼盘id不能为空")
-    @ApiModelProperty(value = "楼盘id", required = true)
-    private String houseId;
-
-    @NotBlank(message = "恒大样本间id不能为空")
-    @ApiModelProperty(value = "恒大样本间id", required = true)
-    private String roomId;
-
-    @NotBlank(message = "样版间名称不能为空")
-    @ApiModelProperty(value = "样版间名称", required = true)
-    private String roomName;
-
-    @NotBlank(message = "vrModelId不能为空")
-    @ApiModelProperty(value = "vrModelId(四维看看场景id)" ,required = true)
-    private String vrModelId;
-
-    @ApiModelProperty(value = "封面图")
-    private String icon;
-
-    @ApiModelProperty(value = "文件名")
-    private String fileName;
-
-    @ApiModelProperty(value = "场景名称")
-    private String sceneTitle;
-
-//    @NotBlank(message = "场景链接不能为空")
-//    @ApiModelProperty(value = "场景链接", required = true)
-//    private String webSite;
-
-    @NotBlank(message = "场景码不能为空")
-    @ApiModelProperty(value = "场景码(四维看看)", required = true)
-    private String sceneCode;
-
-    @NotBlank(message = "恒大id不能为空")
-    @ApiModelProperty(value = "恒大id", required = true)
-    private String hengdaId;
-
-
-
-
-
-
-}

+ 26 - 0
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/vo/CatalogVo.java

@@ -0,0 +1,26 @@
+package com.gis.domain.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * Created by owen on 2021/3/29 0029 14:58
+ *
+ * 展示页,需要目录
+ */
+@Data
+public class CatalogVo  {
+
+
+    @ApiModelProperty(value = "目录名称")
+    private String CatalogName;
+
+    @ApiModelProperty(value = "目录Id")
+    private Long CatalogId;
+
+    @ApiModelProperty(value = "父目录Id")
+    private Long parentId;
+
+    @ApiModelProperty(value = "父目录名称")
+    private String parentName;
+}

+ 4 - 0
720yun_fd_manage/gis_mapper/src/main/java/com/gis/mapper/CatalogMapper.java

@@ -3,6 +3,7 @@ package com.gis.mapper;
 
 import com.gis.domain.entity.CatalogEntity;
 import com.gis.domain.vo.CatalogSceneTree;
+import com.gis.domain.vo.CatalogVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
@@ -29,4 +30,7 @@ public interface CatalogMapper extends IBaseMapper<CatalogEntity, Long> {
 
     @Update("UPDATE tb_catalog SET is_delete = 1 where is_delete = 0 and work_id = #{workId}")
     void setDeleteByWorkId(Long workId);
+
+    @Select("select a.id as catalogId, a.name as catalogName, b.id as parentId, b.name as parentName from tb_catalog a left join  tb_catalog b on a.parent_id = b.id where a.is_delete = 0 and a.id = #{catalogId}")
+    CatalogVo voFindById(Long catalogId);
 }

+ 7 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/CatalogService.java

@@ -5,6 +5,7 @@ import com.gis.common.util.Result;
 import com.gis.domain.dto.CatalogDto;
 import com.gis.domain.entity.CatalogEntity;
 import com.gis.domain.entity.FodderEntity;
+import com.gis.domain.vo.CatalogVo;
 import org.springframework.web.multipart.MultipartFile;
 
 
@@ -21,4 +22,10 @@ public interface CatalogService extends IBaseService<CatalogEntity, Long> {
     Result webListTree(Long workId);
 
     Result remove(Long id);
+
+    Result getCatalog(Long workId);
+
+    Result getScene(Long catalogId);
+
+    CatalogVo voFindById(Long catalogId);
 }

+ 1 - 1
720yun_fd_manage/gis_service/src/main/java/com/gis/service/SceneService.java

@@ -42,7 +42,7 @@ public interface SceneService extends IBaseService<SceneEntity, Long> {
 
     SceneEntity findByIdForUpdate(Long id);
 
-    Result saves(List<SceneDto> param);
+    Result saves(CatalogSceneDto param);
 
 
     List<String> strFindByWorkId(Long workId, String type);

+ 21 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/CatalogServiceImpl.java

@@ -6,6 +6,7 @@ import com.gis.domain.dto.CatalogDto;
 import com.gis.domain.entity.CatalogEntity;
 import com.gis.domain.entity.SceneEntity;
 import com.gis.domain.vo.CatalogSceneTree;
+import com.gis.domain.vo.CatalogVo;
 import com.gis.mapper.CatalogMapper;
 import com.gis.mapper.IBaseMapper;
 import com.gis.mapper.SceneMapper;
@@ -81,6 +82,24 @@ public class CatalogServiceImpl extends IBaseServiceImpl<CatalogEntity, Long> im
         return Result.success();
     }
 
+
+    @Override
+    public Result getCatalog(Long workId) {
+        List<CatalogEntity> list = entityMapper.findByWorkId(workId);
+        CatalogTreeUtil treeUtil = new CatalogTreeUtil(list);
+        return Result.success(treeUtil.buildTree());
+    }
+
+    @Override
+    public Result getScene(Long catalogId) {
+        return Result.success(sceneService.findByCatalogId(catalogId));
+    }
+
+    @Override
+    public CatalogVo voFindById(Long catalogId) {
+        return entityMapper.voFindById(catalogId);
+    }
+
     @Override
     public Result listTree(Long workId) {
         List<CatalogEntity> list = entityMapper.findByWorkId(workId);
@@ -116,6 +135,8 @@ public class CatalogServiceImpl extends IBaseServiceImpl<CatalogEntity, Long> im
         return Result.success();
     }
 
+
+
     private void delete(Long id){
         CatalogEntity entity = this.findById(id);
         if (entity == null) {

+ 58 - 131
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/SceneServiceImpl.java

@@ -11,6 +11,7 @@ import com.gis.domain.entity.FodderEntity;
 import com.gis.domain.entity.SceneEntity;
 import com.gis.domain.entity.WorkEntity;
 import com.gis.domain.vo.CatalogSceneVo;
+import com.gis.domain.vo.CatalogVo;
 import com.gis.domain.vo.ProSceneVo;
 import com.gis.mapper.CatalogMapper;
 import com.gis.mapper.IBaseMapper;
@@ -18,6 +19,8 @@ import com.gis.mapper.SceneMapper;
 import com.gis.service.CatalogService;
 import com.gis.service.SceneService;
 import com.gis.service.WorkService;
+import com.gis.tree.CatalogTree;
+import com.gis.tree.CatalogTreeUtil;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -30,6 +33,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.transaction.Transactional;
+import javax.validation.constraints.NotNull;
 import java.io.*;
 import java.util.*;
 
@@ -57,10 +61,6 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
     @Autowired
     FileUtils fileUtils;
 
-//    @Autowired
-//    AliyunOssUtil aliyunOssUtil;
-
-
     @Override
     public IBaseMapper<SceneEntity, Long> getBaseMapper() {
         return this.entityMapper;
@@ -149,42 +149,26 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
 
     }
 
-//    @Override
-//    public Result saves(List<SceneDto> params) {
-//        SceneEntity entity = null;
-//        for (SceneDto sceneDto : params) {
-//            Long id = sceneDto.getId();
-//            if (id == null) {
-//                entity = new SceneEntity();
-//                BeanUtils.copyProperties(sceneDto, entity);
-//                this.save(entity);
-//            } else {
-//                entity = findById(id);
-//                BeanUtils.copyProperties(sceneDto, entity);
-//                entity.setUpdateTime(new Date());
-//                this.update(entity);
-//
-//            }
-//        }
-//
-//        return Result.success();
-//    }
-
 
     @Override
-    public Result saves(List<SceneDto> params) {
+    public Result saves(CatalogSceneDto params) {
         SceneEntity entity = null;
-        for (SceneDto sceneDto : params) {
+        Long catalogId = params.getCatalogId();
+        Long workId = params.getWorkId();
+        // 创建分组
+        if (catalogId == null) {
+            catalogId = createCatalog(params);
+        }
+
+        List<SceneDto> scenes = params.getScenes();
+
+        for (SceneDto sceneDto : scenes) {
             Long id = sceneDto.getId();
             if (id == null) {
                 entity = new SceneEntity();
                 BeanUtils.copyProperties(sceneDto, entity);
-
-                // 创建分组
-                Long catalogId = sceneDto.getCatalogId();
-                if (catalogId == null) {
-                    entity.setCatalogId(createCatalog(sceneDto));
-                }
+                entity.setCatalogId(catalogId);
+                entity.setWorkId(workId);
 
                 this.save(entity);
             } else {
@@ -196,21 +180,52 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
             }
         }
 
-        return Result.success();
+        // 前端需要分组对象
+        CatalogVo catalogVo = catalogService.voFindById(catalogId);
+        CatalogTree catalogTree = new CatalogTree();
+        catalogTree.setId(catalogVo.getCatalogId());
+        catalogTree.setName(catalogVo.getCatalogName());
+        Long parentId = catalogVo.getParentId();
+        catalogTree.setParentId(parentId);
+
+        // 结果集
+        List<CatalogTree> resultTree = new ArrayList<>();
+
+        // 二层分组 (父子结构)
+        if (parentId != null) {
+            CatalogTree parentCatalog = new CatalogTree();
+            parentCatalog.setId(parentId);
+            parentCatalog.setName(catalogVo.getParentName());
+            List<CatalogTree> children = new ArrayList<>();
+            children.add(catalogTree);
+            parentCatalog.setChildren(children);
+            resultTree.add(parentCatalog);
+        } else {
+            // 一层分组
+            resultTree.add(catalogTree);
+        }
+
+
+
+
+        return Result.success(resultTree);
     }
 
+
+
+
     /**
      * 创建分组
-     * @param sceneDto
+     *
      * @return
      */
-    private Long createCatalog(SceneDto sceneDto) {
-        Long parentId = sceneDto.getParentId();
-        String parentName = sceneDto.getParentName();
-        Long workId = sceneDto.getWorkId();
+    private Long createCatalog(CatalogSceneDto params) {
+        Long parentId = params.getParentId();
+        String parentName = params.getParentName();
+        Long workId = params.getWorkId();
 
         CatalogEntity entity = new CatalogEntity();
-        entity.setName(sceneDto.getCatalogName());
+        entity.setName(params.getCatalogName());
         entity.setWorkId(workId);
         // 当父id不为空时
         if (parentId != null) {
@@ -223,8 +238,7 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
             parentEntity.setWorkId(workId);
             parentEntity.setName(parentName);
             catalogService.save(parentEntity);
-
-            entity.setParentId(parentEntity.getParentId());
+            entity.setParentId(parentEntity.getId());
 
         }
         // 创建目录
@@ -232,6 +246,8 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         return entity.getId();
     }
 
+
+
     @Override
     public List<String> strFindByWorkId(Long workId, String type) {
         return entityMapper.strFindByWorkId(workId, type);
@@ -325,7 +341,6 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
 
     @Override
     public Result editXml(XmlDataDto param) {
-//        long start = System.currentTimeMillis();
         Long id = param.getId();
         SceneEntity entity = entityMapper.findByIdForUpdate(id);
         if (entity == null) {
@@ -333,36 +348,6 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
             return Result.failure("场景码不存在");
         }
 
-//        String sceneCode = entity.getSceneCode();
-//        FodderEntity fodderEntity = fodderService.findBySceneCode(sceneCode);
-//
-//
-//        // 注意网络下载会有缓存,必须加时间戳
-//        // http://ossxiaoan.4dage.com/cms_pano_fcb/p19/fcb_px2rJW96F/vtour/tour.xml
-//        String tourOssUrl = fodderEntity.getOssPath() + "/vtour/tour.xml?m=" + System.currentTimeMillis();
-//        log.info("网络下载文件地址: {}", tourOssUrl);
-//        String fileName = "tour2.xml";
-//        String filePath = fodderEntity.getFilePath();
-//        String localBasePath = StringUtils.substringBeforeLast(filePath, "/");
-//        FileUtils.downLoadFromUrl(tourOssUrl, fileName, localBasePath);
-//        log.info("网络下载成功: {}", localBasePath+ "/tour2.xml");
-//
-//        // 编辑xml, 修改初始角度
-//        String inPath = localBasePath + "/tour2.xml";
-//        String outPath = localBasePath + "/tour.xml";
-//        String hlookat = param.getHlookat();
-//        String vlookat = param.getVlookat();
-//        streamEditFile(inPath, outPath, hlookat, vlookat);
-//        log.info("编辑xml, 修改初始角度完毕");
-//
-////        String tourOssSavePath = configConstant.ossBasePath + entity.getHouseId() + "/" + entity.getSceneCode() + "/vtour/tour.xml";
-//        String tourOssSavePath = configConstant.ossBasePath + entity.getSceneCode() + "/vtour/tour.xml";
-//        log.info("osspath: " + tourOssSavePath);
-//        aliyunOssUtil.upload(outPath, tourOssSavePath);
-////        asyncTask.uploadOss(outPath, tourOssSavePath);
-//        long end = System.currentTimeMillis();
-//        log.info("tour.xml 上传oss完成, 共耗时: " + (end-start)/1000 + " s");
-
         // 保存初始视觉
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("hlookat", param.getHlookat());
@@ -375,64 +360,6 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         return Result.success();
     }
 
-    @Test
-    public void tes1() {
-        String inPath = "C:\\Users\\Administrator\\Desktop\\33\\tour2.xml";
-        String outPath = "C:\\Users\\Administrator\\Desktop\\33\\tour.xml";
-        streamEditFile(inPath, outPath, "0.1", "0.2");
-    }
-
-
-    public static void streamEditFile(String inPath, String outPath, String hlookat, String vlookat) {
-        // 4*4矩阵
-
-        BufferedReader reader = null;
-        try {
-            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(inPath), "UTF-8");
-            reader = new BufferedReader(inputStreamReader);
-
-
-            // 输出缓冲流
-
-            String tempString = null;
-            StringBuffer buffer = new StringBuffer();
-
-            // 转数组
-            while ((tempString = reader.readLine()) != null) {
-
-                if (tempString.contains("<view hlookat=")) {
-                    tempString = tempString.replace("\t", "");
-
-                    String start = StringUtils.substring(tempString, 0, 5);
-                    String end = StringUtils.substringAfter(tempString, "fovtype");
-
-                    StringBuffer aa = new StringBuffer();
-                    aa.append(start);
-                    aa.append(" hlookat=").append("\"").append(hlookat).append("\"");
-                    aa.append(" vlookat=").append("\"").append(vlookat).append("\"");
-                    aa.append(" fovtype");
-                    aa.append(end);
-                    // 写文件
-                    tempString = aa.toString();
-                    log.info("temp: " + tempString);
-                }
-                // 换行写入
-                buffer.append(tempString).append("\r\n");
-            }
-            reader.close();
-            FileUtil.writeUtf8String(buffer.toString(), outPath);
-        } catch (IOException ex) {
-            ex.printStackTrace();
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException ex) {
-                    ex.printStackTrace();
-                }
-            }
-        }
-    }
 
 
     @Test

+ 2 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/tree/CatalogTree.java

@@ -36,10 +36,12 @@ public class CatalogTree implements Serializable {
 
 
     /** 默认给空数组*/
+
     private List<CatalogTree> children = new ArrayList<>();
 
     /** 场景实体*/
 //    private List<SceneEntity> scenes;
+    @JSONField(serialize = false)
     private List<CatalogSceneVo> scenes;
 
 

+ 19 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/tree/CatalogTreeUtil.java

@@ -22,6 +22,25 @@ public class CatalogTreeUtil {
     public CatalogTreeUtil() {
     }
 
+
+    public CatalogTreeUtil(List<CatalogEntity> nodesList) {//通过构造函数初始化
+        for (CatalogEntity n : nodesList) {
+            CatalogTree tree = new CatalogTree();
+            Long id = n.getId();
+            tree.setId(id);
+            tree.setName(n.getName());
+//            List<SceneEntity> sceneList = sceneMapper.findByCatalogId(id);
+//            List<CatalogSceneVo> sceneList = sceneMapper.findVoByCatalogId(id);
+
+//            tree.setScenes(sceneList);
+
+            if (n.getParentId() != null) {
+                tree.setParentId(n.getParentId());
+            }
+            nodes.add(tree);
+        }
+    }
+
     //传入list参数
     public CatalogTreeUtil(List<CatalogEntity> nodesList, SceneMapper sceneMapper) {//通过构造函数初始化
         for (CatalogEntity n : nodesList) {

+ 16 - 0
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/CatalogController.java

@@ -32,6 +32,19 @@ public class CatalogController extends BaseController {
     @Autowired
     private CatalogService catalogService;
 
+
+    @ApiOperation(value = "获取场景", position = 1)
+    @GetMapping("getScene/{catalogId}")
+    public Result getScene(@PathVariable Long catalogId) {
+        return catalogService.getScene(catalogId);
+    }
+
+    @ApiOperation(value = "获取分组")
+    @GetMapping("getCatalog/{workId}")
+    public Result getCatalog(@PathVariable Long workId) {
+        return catalogService.getCatalog(workId);
+    }
+
     @ApiOperation(value = "场景列表", position = 1)
     @PostMapping("listTree/{workId}")
     public Result listTree(@PathVariable Long workId) {
@@ -39,6 +52,9 @@ public class CatalogController extends BaseController {
     }
 
 
+
+
+
     @ApiOperation(value = "新增/修改分组", position = 1)
     @PostMapping("save")
     public Result save(@Valid @RequestBody CatalogDto param) {

+ 1 - 1
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/SceneController.java

@@ -79,7 +79,7 @@ public class SceneController extends BaseController {
 
     @ApiOperation(value = "批量场景新增/修改", position = 1, notes = "注意创建目录层次问题, 有parentId表示有父级,有catalogId则更新,否则新建分组 ")
     @PostMapping("saves")
-    public Result saves(@RequestBody List<SceneDto> param) {
+    public Result saves(@RequestBody CatalogSceneDto param) {
         return sceneService.saves(param);
     }