230 lines
6.3 KiB
Go
230 lines
6.3 KiB
Go
package plant
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
common "sundynix-go/model/commom/request"
|
|
"sundynix-go/model/commom/response"
|
|
plantReq "sundynix-go/model/plant/request"
|
|
"sundynix-go/utils/auth"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type WikiApi struct{}
|
|
|
|
// CreateWiki 发布百科
|
|
// @Tags 百科
|
|
// @Summary 添加百科
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body plantReq.CreateWiki true "添加百科"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
|
|
// @Router /wiki/add [post]
|
|
func (a *WikiApi) CreateWiki(c *gin.Context) {
|
|
var req plantReq.CreateWiki
|
|
err := c.ShouldBind(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
err = wikiService.CreateWiki(req)
|
|
if err != nil {
|
|
global.Logger.Error("添加百科失败", zap.Error(err))
|
|
response.FailWithMsg("添加百科失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("添加百科成功", c)
|
|
}
|
|
|
|
// UpdateWiki 发布百科
|
|
// @Tags 百科
|
|
// @Summary 修改百科
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body plantReq.UpdateWiki true "修改百科"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
|
|
// @Router /wiki/update [post]
|
|
func (a *WikiApi) UpdateWiki(c *gin.Context) {
|
|
var req plantReq.UpdateWiki
|
|
err := c.ShouldBind(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
err = wikiService.UpdateWiki(req)
|
|
if err != nil {
|
|
global.Logger.Error("修改百科失败", zap.Error(err))
|
|
response.FailWithMsg("修改百科失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("修改百科成功", c)
|
|
|
|
}
|
|
|
|
// WikiPage 百科分页
|
|
// @Tags 百科
|
|
// @Summary 分页
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body plantReq.WikiPage true "百科分页"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发布成功"}"
|
|
// @Router /wiki/page [post]
|
|
func (a *WikiApi) WikiPage(c *gin.Context) {
|
|
var req plantReq.WikiPage
|
|
err := c.ShouldBind(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
userId := auth.GetUserId(c)
|
|
list, total, err := wikiService.WikiPage(req, userId)
|
|
if err != nil {
|
|
global.Logger.Error("分页百科失败", zap.Error(err))
|
|
response.FailWithMsg("分页百科失败", c)
|
|
return
|
|
}
|
|
response.OkWithData(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: req.Current,
|
|
PageSize: req.PageSize,
|
|
}, c)
|
|
}
|
|
|
|
// WikiDetail 百科详情
|
|
// @Tags 百科
|
|
// @Summary 百科详情
|
|
// @Security BearerAuth
|
|
// @Produce application/json
|
|
// @Param id query string true "id"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|
// @Router /wiki/detail [get]
|
|
func (a *WikiApi) WikiDetail(c *gin.Context) {
|
|
id := c.Query("id")
|
|
userId := auth.GetUserId(c)
|
|
topic, err := wikiService.Detail(id, userId)
|
|
if err != nil {
|
|
response.FailWithMsg("获取失败", c)
|
|
return
|
|
}
|
|
response.OkWithData(topic, c)
|
|
}
|
|
|
|
// DeleteWiki 删除百科
|
|
// @Tags 百科
|
|
// @Summary 删除百科
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body common.IdsReq true "删除百科"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
|
// @Router /wiki/delete [post]
|
|
func (a *WikiApi) DeleteWiki(c *gin.Context) {
|
|
var req common.IdsReq
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
err = wikiService.DeleteWiki(req)
|
|
if err != nil {
|
|
global.Logger.Error("删除失败", zap.Error(err))
|
|
response.FailWithMsg("删除失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("删除成功", c)
|
|
}
|
|
|
|
// SyncWikiQdrant 单条百科同步到 Qdrant
|
|
// @Tags 百科
|
|
// @Summary 百科同步到Qdrant
|
|
// @Security BearerAuth
|
|
// @Produce application/json
|
|
// @Param data body common.GetById true "单条百科"
|
|
// @Router /wiki/sync-qdrant [post]
|
|
func (a *WikiApi) SyncWikiQdrant(c *gin.Context) {
|
|
var req common.GetById
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
if err := aiRagService.SyncSingleWiki(req.ID); err != nil {
|
|
global.Logger.Error("同步 Qdrant 失败", zap.Error(err))
|
|
response.FailWithMsg("同步失败: "+err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithMsg("同步成功", c)
|
|
}
|
|
|
|
// DeleteWikiQdrant 从 Qdrant 移除单条百科向量
|
|
// @Tags 百科
|
|
// @Summary 百科移除Qdrant
|
|
// @Security BearerAuth
|
|
// @Produce application/json
|
|
// @Param data body common.GetById true "单条百科"
|
|
// @Router /wiki/delete-qdrant [post]
|
|
func (a *WikiApi) DeleteWikiQdrant(c *gin.Context) {
|
|
var req common.GetById
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
if err := aiRagService.DeleteFromQdrant(req.ID); err != nil {
|
|
global.Logger.Error("从 Qdrant 删除向量失败", zap.Error(err))
|
|
response.FailWithMsg("移除失败: "+err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithMsg("移除成功", c)
|
|
}
|
|
|
|
// StarWiki 收藏百科
|
|
// @Tags 百科
|
|
// @Summary 收藏百科
|
|
// @Security BearerAuth
|
|
// @Produce application/json
|
|
// @Param id query string true "百科id"
|
|
// @Param type query string true "收藏类型 1 收藏 2 取消收藏"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"收藏成功"}"
|
|
// @Router /wiki/star [get]
|
|
func (a *WikiApi) StarWiki(c *gin.Context) {
|
|
postId := c.Query("id")
|
|
class := c.Query("type")
|
|
userId := auth.GetUserId(c)
|
|
err := wikiService.StarWiki(userId, postId, class)
|
|
if err != nil {
|
|
global.Logger.Error("操作失败", zap.Error(err))
|
|
response.FailWithMsg("操作失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("操作成功", c)
|
|
}
|
|
|
|
// UploadImg 上传图片
|
|
// @Tags 百科
|
|
// @Summary 上传图片
|
|
// @Security BearerAuth
|
|
// @accept application/json
|
|
// @Produce application/json
|
|
// @Param data body common.UploadOss true "上传图片"
|
|
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
|
|
// @Router /wiki/uploadImg [post]
|
|
func (a *WikiApi) UploadImg(c *gin.Context) {
|
|
var req common.UploadOss
|
|
err := c.ShouldBind(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("请求参数错误", c)
|
|
return
|
|
}
|
|
err = wikiService.UploadImg(req)
|
|
if err != nil {
|
|
global.Logger.Error("上传失败", zap.Error(err))
|
|
response.FailWithMsg("上传失败", c)
|
|
return
|
|
}
|
|
response.OkWithMsg("上传成功", c)
|
|
}
|