2026-03-07 09:11:08 +08:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"x-agents/server/internal/model"
|
|
|
|
|
"x-agents/server/internal/service"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Neo4jHandler struct {
|
|
|
|
|
service *service.Neo4jService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewNeo4jHandler(svc *service.Neo4jService) *Neo4jHandler {
|
|
|
|
|
return &Neo4jHandler{service: svc}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:26:04 +08:00
|
|
|
// @Summary 检查 Neo4j 连接
|
|
|
|
|
// @Description 测试 Neo4j 数据库连接是否正常
|
|
|
|
|
// @Tags Neo4j
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Param request body model.Neo4jCheckRequest true "Neo4j连接信息"
|
|
|
|
|
// @Success 200 {object} map[string]interface{}
|
|
|
|
|
// @Failure 400 {object} map[string]string
|
|
|
|
|
// @Failure 500 {object} map[string]string
|
|
|
|
|
// @Router /neo4j/check [post]
|
2026-03-07 09:11:08 +08:00
|
|
|
func (h *Neo4jHandler) Check(c *gin.Context) {
|
|
|
|
|
var req model.Neo4jCheckRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := h.service.Check(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:26:04 +08:00
|
|
|
// @Summary 获取图谱概览
|
|
|
|
|
// @Description 获取 Neo4j 中的图谱概览数据
|
|
|
|
|
// @Tags Neo4j
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Param request body model.Neo4jGraphRequest true "图谱查询请求"
|
|
|
|
|
// @Success 200 {object} map[string]interface{}
|
|
|
|
|
// @Failure 400 {object} map[string]string
|
|
|
|
|
// @Failure 500 {object} map[string]string
|
|
|
|
|
// @Router /neo4j/graphs [post]
|
2026-03-07 09:11:08 +08:00
|
|
|
func (h *Neo4jHandler) GetGraphs(c *gin.Context) {
|
|
|
|
|
var req model.Neo4jGraphRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := h.service.GetGraphs(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:26:04 +08:00
|
|
|
// @Summary 获取节点列表
|
|
|
|
|
// @Description 获取 Neo4j 中的节点详情
|
|
|
|
|
// @Tags Neo4j
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Param request body model.Neo4jNodeRequest true "节点查询请求"
|
|
|
|
|
// @Success 200 {object} map[string]interface{}
|
|
|
|
|
// @Failure 400 {object} map[string]string
|
|
|
|
|
// @Failure 500 {object} map[string]string
|
|
|
|
|
// @Router /neo4j/nodes [post]
|
2026-03-07 09:11:08 +08:00
|
|
|
func (h *Neo4jHandler) GetNodes(c *gin.Context) {
|
|
|
|
|
var req model.Neo4jNodeRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := h.service.GetNodes(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:26:04 +08:00
|
|
|
// @Summary 获取关系列表
|
|
|
|
|
// @Description 获取 Neo4j 中的关系详情
|
|
|
|
|
// @Tags Neo4j
|
|
|
|
|
// @Accept json
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Param request body model.Neo4jRelRequest true "关系查询请求"
|
|
|
|
|
// @Success 200 {object} map[string]interface{}
|
|
|
|
|
// @Failure 400 {object} map[string]string
|
|
|
|
|
// @Failure 500 {object} map[string]string
|
|
|
|
|
// @Router /neo4j/relationships [post]
|
2026-03-07 09:11:08 +08:00
|
|
|
func (h *Neo4jHandler) GetRelationships(c *gin.Context) {
|
|
|
|
|
var req model.Neo4jRelRequest
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := h.service.GetRelationships(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
|
|
|
}
|