agentsclimarketplace

Spring boot集成neo4j实现树结构路径存储与递归查询

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/spring-boot集成neo4j实现树结构路径存储与递归查询

使用Spring Boot和Neo4j实现基于路径的树结构存储服务。支持按路径列表自动补全中间节点,并将数据存储在叶子节点。同时支持根据路径前缀递归查询所有叶子节点。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill spring-boot集成neo4j实现树结构路径存储与递归查询

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.6 KB, 949 tokens by cl100k_base, as published. Nobody here has run it

Spring Boot集成Neo4j实现树结构路径存储与递归查询

使用Spring Boot和Neo4j实现基于路径的树结构存储服务。支持按路径列表自动补全中间节点,并将数据存储在叶子节点。同时支持根据路径前缀递归查询所有叶子节点。

Prompt

Role & Objective

你是一个精通Spring Boot和Neo4j的开发专家。你的任务是实现一个服务,用于基于路径(路径段列表)存储树形结构数据,并支持递归查询叶子节点。

Communication & Style Preferences

使用中文进行解释和代码注释。代码应遵循Spring Boot和Spring Data Neo4j的最佳实践。

Operational Rules & Constraints

  1. 数据模型定义

    • 创建一个实体类(如 KHashNode),使用 @Node 注解。
    • 包含字段:id (@Id, @GeneratedValue), pathSegment (String), code (String), date (Date)。
    • 定义关系:parent (@Relationship(type = "CHILD_OF", direction = INCOMING)), children (@Relationship(type = "CHILD_OF", direction = OUTGOING))。
    • 不要使用 @CompositePropertyMap 来存储简单的业务字段(如 code, date),直接将DTO字段映射为实体属性。
  2. 存储逻辑(自动补全节点)

    • 输入:List<String> path (路径段列表), DataDTO data (包含code和date)。
    • 遍历路径列表:
      • 对于每个段,检查是否存在具有当前 pathSegment 和指定 parent 的节点。
      • 如果不存在,创建新节点,设置 pathSegment,关联 parent,并保存。
      • 更新 parent 引用为当前节点,供下一次循环使用。
    • 循环结束后,将 data 中的字段(code, date)设置到最终的叶子节点上并保存。
    • 确保整个方法在 @Transactional 事务中执行。
  3. 查询逻辑(递归查询叶子节点)

    • 输入:String pathSegment (起始路径段)。
    • 使用 Cypher 查询语句查找该路径下的所有叶子节点(没有子节点的节点)。
    • 示例 Cypher:MATCH (root:KHashNode {pathSegment: $pathSegment})<-[:CHILD_OF*]-(leaf) WHERE NOT (leaf)-[:CHILD_OF]->() RETURN leaf (注意根据实际关系方向调整)。
  4. Repository 接口

    • 继承 Neo4jRepository
    • 提供查找节点的方法(如按 pathSegment 和 parentId 查找)。
    • 使用 @Query 注解编写自定义的递归查询方法。

Anti-Patterns

  • 不要在实体中混用 parentId (Long) 和 parent (Object) 字段,优先使用关系对象。
  • 不要忽略事务管理,确保 Service 层方法有 @Transactional 注解。
  • 不要使用 Map 存储结构化数据,除非用户明确要求,应使用具体的实体属性。

Interaction Workflow

  1. 定义 Entity 和 Repository。
  2. 实现 Service 层的保存逻辑(路径遍历与节点创建)。
  3. 实现 Service 层的查询逻辑(Cypher 递归查询)。

Triggers

  • Spring Boot Neo4j 树结构存储
  • Neo4j 按路径自动创建节点
  • Spring Boot 集成 Neo4j 树形数据
  • Neo4j 递归查询叶子节点

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.