2026-04-15 17:12:30 +08:00
|
|
|
package dashboard
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
import (
|
2026-05-31 18:43:48 +08:00
|
|
|
"agent-desk/internal/builders"
|
|
|
|
|
"agent-desk/internal/pkg/constants"
|
|
|
|
|
"agent-desk/internal/pkg/dto/request"
|
|
|
|
|
"agent-desk/internal/pkg/enums"
|
|
|
|
|
"agent-desk/internal/pkg/httpx"
|
|
|
|
|
"agent-desk/internal/services"
|
|
|
|
|
|
|
|
|
|
"agent-desk/internal/pkg/httpx/params"
|
2026-05-23 22:22:18 +08:00
|
|
|
|
2026-05-23 22:10:20 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
2026-04-09 10:01:23 +08:00
|
|
|
"github.com/mlogclub/simple/sqls"
|
|
|
|
|
"github.com/mlogclub/simple/web"
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func QuickReplyAnyList(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionQuickReplyView); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
cnd := params.NewPagedSqlCnd(ctx,
|
2026-04-09 10:01:23 +08:00
|
|
|
params.QueryFilter{ParamName: "status"},
|
|
|
|
|
params.QueryFilter{ParamName: "groupName"},
|
|
|
|
|
params.QueryFilter{ParamName: "title", Op: params.Like},
|
|
|
|
|
).Asc("sort_no").Desc("id")
|
|
|
|
|
|
|
|
|
|
list, paging := services.QuickReplyService.FindPageByCnd(cnd)
|
2026-05-28 09:11:48 +08:00
|
|
|
results := builders.BuildQuickReplyResponses(list)
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, &web.PageResult{Results: results, Page: paging})
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-28 09:11:48 +08:00
|
|
|
func QuickReplyGetBy(ctx *gin.Context) {
|
|
|
|
|
id, ok := httpx.GetPathInt64(ctx, "id")
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionQuickReplyView); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item := services.QuickReplyService.Get(id)
|
|
|
|
|
if item == nil {
|
|
|
|
|
httpx.WriteJSON(ctx, web.JsonErrorMsg("快捷回复不存在"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
httpx.WriteJSON(ctx, builders.BuildQuickReplyResponse(item))
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func QuickReplyGetList_all(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionQuickReplyView); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
list := services.QuickReplyService.Find(sqls.NewCnd().Eq("status", enums.StatusOk).Asc("sort_no").Desc("id"))
|
2026-05-28 09:11:48 +08:00
|
|
|
results := builders.BuildQuickReplyResponses(list)
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, results)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func QuickReplyPostCreate(ctx *gin.Context) {
|
|
|
|
|
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionQuickReplyCreate)
|
2026-04-09 10:01:23 +08:00
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req := request.CreateQuickReplyRequest{}
|
2026-05-23 22:22:18 +08:00
|
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
item, err := services.QuickReplyService.CreateQuickReply(req, user)
|
|
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-05-28 09:11:48 +08:00
|
|
|
httpx.WriteJSON(ctx, builders.BuildQuickReplyResponse(item))
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func QuickReplyPostUpdate(ctx *gin.Context) {
|
|
|
|
|
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionQuickReplyUpdate)
|
2026-04-09 10:01:23 +08:00
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req := request.UpdateQuickReplyRequest{}
|
2026-05-23 22:22:18 +08:00
|
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
if err := services.QuickReplyService.UpdateQuickReply(req, user); err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, nil)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func QuickReplyPostDelete(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionQuickReplyDelete); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req := request.DeleteQuickReplyRequest{}
|
2026-05-23 22:22:18 +08:00
|
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
if err := services.QuickReplyService.DeleteQuickReply(req.ID); err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, nil)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|