|
@@ -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();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|