🎨 新增AI客服相关接口
This commit is contained in:
30
api/v1/app/ai_kefu.go
Normal file
30
api/v1/app/ai_kefu.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"miniapp/global"
|
||||
"miniapp/model/app/request"
|
||||
r "miniapp/model/common/response"
|
||||
)
|
||||
|
||||
type AiKefuApi struct{}
|
||||
|
||||
// SendMessage 发送消息
|
||||
func (a *AiKefuApi) SendMessage(ctx *gin.Context) {
|
||||
var p request.Msg
|
||||
if err := ctx.ShouldBind(&p); err != nil {
|
||||
global.GVA_LOG.Error("参数校验失败", zap.Error(err))
|
||||
r.FailWithMessage("参数校验失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
kf, err := aiKefuService.MatchKeywordReplyContent(p)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询失败", zap.Error(err))
|
||||
r.FailWithMessage("查询失败", ctx)
|
||||
return
|
||||
}
|
||||
|
||||
r.OkWithDetailed(kf, "查询成功", ctx)
|
||||
}
|
@@ -8,6 +8,7 @@ type ApiGroup struct {
|
||||
FavoriteApi
|
||||
VisionApi
|
||||
TodosApi
|
||||
AiKefuApi
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -15,4 +16,5 @@ var (
|
||||
favoriteService = service.ServiceGroupApp.AppServiceGroup.FavoriteService
|
||||
visionService = service.ServiceGroupApp.AppServiceGroup.VisionService
|
||||
todosService = service.ServiceGroupApp.AppServiceGroup.TodesService
|
||||
aiKefuService = service.ServiceGroupApp.AppServiceGroup.AiKefuService
|
||||
)
|
||||
|
@@ -21,6 +21,7 @@ type ApiGroup struct {
|
||||
BannerApi
|
||||
HospitalApi
|
||||
ArticleApi
|
||||
AiKefulApi
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -43,4 +44,5 @@ var (
|
||||
hospitalService = service.ServiceGroupApp.SystemServiceGroup.HospitalService
|
||||
bannerService = service.ServiceGroupApp.SystemServiceGroup.BannerService
|
||||
articleService = service.ServiceGroupApp.SystemServiceGroup.ArticleService
|
||||
aiKefuService = service.ServiceGroupApp.SystemServiceGroup.AiKefuService
|
||||
)
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
"miniapp/model/common"
|
||||
"miniapp/model/common/request"
|
||||
r "miniapp/model/common/response"
|
||||
systemService "miniapp/service/system"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -20,7 +19,7 @@ func (h HospitalApi) GetHospitalList(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
list, total, err := systemService.HospitalService{}.GetHospitalList(p)
|
||||
list, total, err := hospitalService.GetHospitalList(p)
|
||||
if err != nil {
|
||||
r.FailWithMessage("获取医院列表失败", ctx)
|
||||
return
|
||||
@@ -37,7 +36,7 @@ func (h HospitalApi) CreateHospital(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err := systemService.HospitalService{}.CreateHospital(&hospital)
|
||||
err := hospitalService.CreateHospital(&hospital)
|
||||
if err != nil {
|
||||
r.FailWithMessage("创建失败"+err.Error(), ctx)
|
||||
return
|
||||
@@ -54,7 +53,7 @@ func (h HospitalApi) UpdateHospital(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err := systemService.HospitalService{}.UpdateHospital(&hospital)
|
||||
err := hospitalService.UpdateHospital(&hospital)
|
||||
if err != nil {
|
||||
r.FailWithMessage("更新失败"+err.Error(), ctx)
|
||||
return
|
||||
@@ -90,7 +89,7 @@ func (h HospitalApi) GetHospitalById(ctx *gin.Context) {
|
||||
|
||||
// 参数转换 string -> int
|
||||
id, _ := strconv.Atoi(Id)
|
||||
hospitalResult, err := systemService.HospitalService{}.GetHospitalById(uint(id))
|
||||
hospitalResult, err := hospitalService.GetHospitalById(uint(id))
|
||||
if err != nil {
|
||||
r.FailWithMessage("获取失败"+err.Error(), ctx)
|
||||
return
|
||||
|
108
api/v1/system/sys_ai_kefu.go
Normal file
108
api/v1/system/sys_ai_kefu.go
Normal file
@@ -0,0 +1,108 @@
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user