Procházet zdrojové kódy

修改:更新分组
新增重命名接口, 前端拍乱,另外增加

wuweihao před 4 roky
rodič
revize
52d7a92a23

+ 28 - 0
720yun_fd_manage/gis_domain/src/main/java/com/gis/domain/dto/BaseDto.java

@@ -0,0 +1,28 @@
+package com.gis.domain.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * Created by owen on 2021/2/22 0022 10:24
+ */
+@Data
+public class BaseDto {
+
+    @NotBlank
+    @ApiModelProperty(value = "id", required = true)
+    private Long id;
+
+    @NotBlank(message = "名称不能为空")
+    @ApiModelProperty(value = "名称", required = true)
+    private String name;
+
+
+
+
+
+
+}

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

@@ -2,12 +2,15 @@ package com.gis.service;
 
 
 import com.gis.common.util.Result;
+import com.gis.domain.dto.BaseDto;
 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;
 
+import java.util.List;
+
 
 /**
  * Created by owen on 2020/3/11 0011 16:14
@@ -28,4 +31,8 @@ public interface CatalogService extends IBaseService<CatalogEntity, Long> {
     Result getScene(Long catalogId);
 
     CatalogVo voFindById(Long catalogId);
+
+    List<CatalogEntity> findByParentId(Long parentId);
+
+    Result editEntity(BaseDto param);
 }

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

@@ -52,4 +52,6 @@ public interface SceneService extends IBaseService<SceneEntity, Long> {
     List<SceneEntity> findByWorkId(Long workId);
 
     Result getVoIndex(Long workId);
+
+    Result editEntity(BaseDto param);
 }

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

@@ -2,6 +2,7 @@ package com.gis.service.impl;
 
 import com.gis.common.constant.MsgCode;
 import com.gis.common.util.Result;
+import com.gis.domain.dto.BaseDto;
 import com.gis.domain.dto.CatalogDto;
 import com.gis.domain.entity.CatalogEntity;
 import com.gis.domain.entity.SceneEntity;
@@ -20,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.transaction.Transactional;
+import javax.validation.constraints.NotBlank;
 import java.util.Date;
 import java.util.List;
 
@@ -101,6 +103,26 @@ public class CatalogServiceImpl extends IBaseServiceImpl<CatalogEntity, Long> im
     }
 
     @Override
+    public List<CatalogEntity> findByParentId(Long parentId) {
+        return entityMapper.findByParentId(parentId);
+    }
+
+    @Override
+    public Result editEntity(BaseDto param) {
+         Long id = param.getId();
+        CatalogEntity entity = findById(id);
+        if (entity == null) {
+            log.error("对象不存在: " + id);
+            Result.failure("对象不存在");
+        }
+
+        BeanUtils.copyProperties(param, entity);
+        entity.setUpdateTime(new Date());
+        update(entity);
+        return Result.success();
+    }
+
+    @Override
     public Result listTree(Long workId) {
         List<CatalogEntity> list = entityMapper.findByWorkId(workId);
         CatalogTreeUtil treeUtil = new CatalogTreeUtil(list, sceneMapper);

+ 74 - 26
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/SceneServiceImpl.java

@@ -155,9 +155,12 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         SceneEntity entity = null;
         Long catalogId = params.getCatalogId();
         Long workId = params.getWorkId();
+//        Long parentId = params.getParentId();
         // 创建分组
+        CatalogEntity catalogEntity = null;
         if (catalogId == null) {
-            catalogId = createCatalog(params);
+            catalogEntity = createCatalog(params);
+            catalogId = catalogEntity.getId();
         }
 
         List<SceneDto> scenes = params.getScenes();
@@ -179,36 +182,36 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
 
             }
         }
+        List<CatalogTree> trees = getTreeByParentId(catalogEntity);
 
-        // 前端需要分组对象
-        CatalogVo catalogVo = catalogService.voFindById(catalogId);
-        CatalogTree catalogTree = new CatalogTree();
-        catalogTree.setId(catalogVo.getCatalogId());
-        catalogTree.setName(catalogVo.getCatalogName());
-        Long parentId = catalogVo.getParentId();
-        catalogTree.setParentId(parentId);
+        return Result.success(trees);
+    }
 
-        // 结果集
-        List<CatalogTree> resultTree = new ArrayList<>();
+    /***
+     * 根据父节点查询子节点
+     */
+    private List<CatalogTree> getTreeByParentId(CatalogEntity catalogEntity){
+        Long parentId = catalogEntity.getParentId();
 
-        // 二层分组 (父子结构)
+        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);
+            // 查找子节点
+            List<CatalogEntity> parents = catalogService.findByParentId(parentId);
+            // 查找父节点
+            CatalogEntity parentCatalog = catalogService.findById(parentId);
+
+            parents.add(parentCatalog);
+            CatalogTreeUtil tree = new CatalogTreeUtil(parents);
+            resultTree = tree.buildTree();
         } else {
-            // 一层分组
+            // 只有父节点
+            CatalogTree catalogTree = new CatalogTree();
+            catalogTree.setId(catalogEntity.getId());
+            catalogTree.setName(catalogEntity.getName());
             resultTree.add(catalogTree);
         }
-
-
-
-
-        return Result.success(resultTree);
+        return resultTree;
     }
 
 
@@ -219,7 +222,8 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
      *
      * @return
      */
-    private Long createCatalog(CatalogSceneDto params) {
+
+    private CatalogEntity createCatalog(CatalogSceneDto params) {
         Long parentId = params.getParentId();
         String parentName = params.getParentName();
         Long workId = params.getWorkId();
@@ -243,9 +247,36 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         }
         // 创建目录
         catalogService.save(entity);
-        return entity.getId();
+        return entity;
     }
 
+//    private Long createCatalog(CatalogSceneDto params) {
+//        Long parentId = params.getParentId();
+//        String parentName = params.getParentName();
+//        Long workId = params.getWorkId();
+//
+//        CatalogEntity entity = new CatalogEntity();
+//        entity.setName(params.getCatalogName());
+//        entity.setWorkId(workId);
+//        // 当父id不为空时
+//        if (parentId != null) {
+//            entity.setParentId(parentId);
+//        }
+//
+//        // 创建父目录
+//        if (parentId == null && parentName != null) {
+//            CatalogEntity parentEntity = new CatalogEntity();
+//            parentEntity.setWorkId(workId);
+//            parentEntity.setName(parentName);
+//            catalogService.save(parentEntity);
+//            entity.setParentId(parentEntity.getId());
+//
+//        }
+//        // 创建目录
+//        catalogService.save(entity);
+//        return entity.getId();
+//    }
+
 
 
     @Override
@@ -440,5 +471,22 @@ public class SceneServiceImpl extends IBaseServiceImpl<SceneEntity, Long> implem
         return Result.success(vo);
     }
 
+    @Override
+    public Result editEntity(BaseDto param) {
+        Long id = param.getId();
+        SceneEntity entity = findById(id);
+        if (entity == null) {
+            log.error("对象不存在: " + id);
+            Result.failure("对象不存在");
+        }
+
+        entity = findById(id);
+        BeanUtils.copyProperties(param, entity);
+        entity.setUpdateTime(new Date());
+        this.update(entity);
+
+        return Result.success();
+    }
+
 
 }

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

@@ -2,6 +2,7 @@ package com.gis.web.controller;
 
 
 import com.gis.common.util.Result;
+import com.gis.domain.dto.BaseDto;
 import com.gis.domain.dto.CatalogDto;
 import com.gis.domain.entity.CatalogEntity;
 import com.gis.domain.entity.WorkEntity;
@@ -54,6 +55,11 @@ public class CatalogController extends BaseController {
 
 
 
+    @ApiOperation(value = "重命名分组", position = 1)
+    @PostMapping("edit")
+    public Result edit(@Valid @RequestBody BaseDto param) {
+        return catalogService.editEntity(param);
+    }
 
     @ApiOperation(value = "新增/修改分组", position = 1)
     @PostMapping("save")

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

@@ -83,6 +83,13 @@ public class SceneController extends BaseController {
         return sceneService.saves(param);
     }
 
+
+    @ApiOperation(value = "重命名场景名称", position = 1)
+    @PostMapping("edit")
+    public Result edit(@Valid @RequestBody BaseDto param) {
+        return sceneService.editEntity(param);
+    }
+
     @ApiOperation(value = "查询该作品是否存在场景")
     @GetMapping("findByWork/{workId}")
     public Result findByWorkId(@PathVariable Long workId) {

+ 15 - 0
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/WebController.java

@@ -39,6 +39,21 @@ public class WebController extends BaseController {
     @Autowired
     SceneService sceneService;
 
+
+
+    @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)
     @GetMapping("listTree/{workId}")
     public Result listTree(@PathVariable Long workId) {