109 lines
2.7 KiB
Go
109 lines
2.7 KiB
Go
|
package system
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"go.uber.org/zap"
|
||
|
"miniapp/global"
|
||
|
"miniapp/model/common/request"
|
||
|
r "miniapp/model/common/response"
|
||
|
"miniapp/model/system"
|
||
|
)
|
||
|
|
||
|
type AiKefulApi struct {
|
||
|
}
|
||
|
|
||
|
// GetAiKefuList 获取列表
|
||
|
func (a *AiKefulApi) GetAiKefuList(ctx *gin.Context) {
|
||
|
p := request.PageInfo{}
|
||
|
if err := ctx.ShouldBind(&p); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
list, total, err := aiKefuService.GetAiKefuList(p)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("获取列表失败", zap.Error(err))
|
||
|
r.FailWithMessage("获取列表失败", ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithDetailed(r.PageResult{List: list, Total: total, Page: p.Page, PageSize: p.PageSize}, "获取成功", ctx)
|
||
|
}
|
||
|
|
||
|
// CreateAiKefu 创建
|
||
|
func (a *AiKefulApi) CreateAiKefu(ctx *gin.Context) {
|
||
|
var aiKefu system.Aikefu
|
||
|
if err := ctx.ShouldBind(&aiKefu); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := aiKefuService.CreateAiKefu(&aiKefu)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("创建失败", zap.Error(err))
|
||
|
r.FailWithMessage("创建失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithMessage("创建成功", ctx)
|
||
|
}
|
||
|
|
||
|
// UpdateAiKefu 更新
|
||
|
func (a *AiKefulApi) UpdateAiKefu(ctx *gin.Context) {
|
||
|
var aiKefu system.Aikefu
|
||
|
if err := ctx.ShouldBind(&aiKefu); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := aiKefuService.UpdateAiKefu(&aiKefu)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("更新失败", zap.Error(err))
|
||
|
r.FailWithMessage("更新失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithMessage("更新成功", ctx)
|
||
|
}
|
||
|
|
||
|
// DeleteAiKefu 删除
|
||
|
func (a *AiKefulApi) DeleteAiKefu(ctx *gin.Context) {
|
||
|
var aiKefu system.Aikefu
|
||
|
if err := ctx.ShouldBind(&aiKefu); err != nil {
|
||
|
global.GVA_LOG.Error("参数错误", zap.Error(err))
|
||
|
r.FailWithMessage("参数错误"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
err := aiKefuService.DeleteAiKefu(&aiKefu)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("删除失败", zap.Error(err))
|
||
|
r.FailWithMessage("删除失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithMessage("删除成功", ctx)
|
||
|
}
|
||
|
|
||
|
// GetAiKefuById 根据id获取
|
||
|
func (a *AiKefulApi) GetAiKefuById(ctx *gin.Context) {
|
||
|
Id := ctx.Param("id")
|
||
|
if Id == "" {
|
||
|
global.GVA_LOG.Error("参数错误")
|
||
|
r.FailWithMessage("参数错误", ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
aiKefu, err := aiKefuService.GetAiKefuById(Id)
|
||
|
if err != nil {
|
||
|
global.GVA_LOG.Error("获取失败", zap.Error(err))
|
||
|
r.FailWithMessage("获取失败"+err.Error(), ctx)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
r.OkWithData(aiKefu, ctx)
|
||
|
}
|