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/pkg/httpx"
|
2026-04-09 10:01:23 +08:00
|
|
|
"context"
|
2026-04-17 15:54:09 +08:00
|
|
|
"strings"
|
2026-04-09 10:01:23 +08:00
|
|
|
"time"
|
|
|
|
|
|
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/dto/response"
|
|
|
|
|
"agent-desk/internal/pkg/enums"
|
|
|
|
|
"agent-desk/internal/services"
|
2026-04-09 10:01:23 +08:00
|
|
|
|
2026-05-31 18:43:48 +08:00
|
|
|
"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/web"
|
|
|
|
|
)
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func SkillDefinitionAnyList(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionView); 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: "name", Op: params.Like},
|
2026-04-14 17:44:06 +08:00
|
|
|
).Desc("id")
|
2026-05-23 22:22:18 +08:00
|
|
|
if _, ok := params.Get(ctx, "status"); !ok {
|
2026-04-17 15:54:09 +08:00
|
|
|
cnd.Where("status <> ?", enums.StatusDeleted)
|
|
|
|
|
}
|
2026-04-09 10:01:23 +08:00
|
|
|
list, paging := services.SkillDefinitionService.FindPageByCnd(cnd)
|
|
|
|
|
results := make([]response.SkillDefinitionResponse, 0, len(list))
|
|
|
|
|
for _, item := range list {
|
|
|
|
|
results = append(results, builders.BuildSkillDefinitionResponse(&item))
|
|
|
|
|
}
|
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-23 22:22:18 +08:00
|
|
|
func SkillDefinitionGetList_all(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionView); 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.NewSqlCnd(ctx,
|
2026-04-09 10:01:23 +08:00
|
|
|
params.QueryFilter{ParamName: "status"},
|
2026-04-17 15:54:09 +08:00
|
|
|
).Desc("id")
|
2026-05-23 22:22:18 +08:00
|
|
|
if status, ok := params.Get(ctx, "status"); !ok || strings.TrimSpace(status) == "" {
|
2026-04-17 15:54:09 +08:00
|
|
|
cnd.Where("status <> ?", enums.StatusDeleted)
|
|
|
|
|
}
|
|
|
|
|
list := services.SkillDefinitionService.Find(cnd)
|
2026-04-09 10:01:23 +08:00
|
|
|
results := make([]response.SkillDefinitionResponse, 0, len(list))
|
|
|
|
|
for _, item := range list {
|
|
|
|
|
results = append(results, builders.BuildSkillDefinitionResponse(&item))
|
|
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, results)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:28:21 +08:00
|
|
|
func SkillDefinitionGetBy(ctx *gin.Context) {
|
|
|
|
|
id, ok := httpx.GetPathInt64(ctx, "id")
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionView); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item := services.SkillDefinitionService.Get(id)
|
|
|
|
|
if item == nil {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, builders.BuildSkillDefinitionResponse(item))
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func SkillDefinitionPostCreate(ctx *gin.Context) {
|
|
|
|
|
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionCreate)
|
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.CreateSkillDefinitionRequest{}
|
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
|
|
|
}
|
2026-04-10 14:43:57 +08:00
|
|
|
item, err := services.SkillDefinitionService.CreateSkillDefinition(req, operator)
|
|
|
|
|
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-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, builders.BuildSkillDefinitionResponse(item))
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func SkillDefinitionPostUpdate(ctx *gin.Context) {
|
|
|
|
|
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionUpdate)
|
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.UpdateSkillDefinitionRequest{}
|
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
|
|
|
}
|
2026-04-10 14:43:57 +08:00
|
|
|
if err := services.SkillDefinitionService.UpdateSkillDefinition(req, operator); 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 SkillDefinitionPostUpdate_status(ctx *gin.Context) {
|
|
|
|
|
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionUpdate)
|
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.UpdateSkillDefinitionStatusRequest{}
|
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 req.ID <= 0 {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0052"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
if !enums.IsValidStatus(req.Status) {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0254"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-04-17 15:54:09 +08:00
|
|
|
item := services.SkillDefinitionService.Get(req.ID)
|
|
|
|
|
if item == nil {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-04-17 15:54:09 +08:00
|
|
|
if item.Status == enums.StatusDeleted {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0184"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
if req.Status == int(enums.StatusDeleted) {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0319"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
2026-04-09 10:01:23 +08:00
|
|
|
|
|
|
|
|
if err := services.SkillDefinitionService.Updates(req.ID, map[string]any{
|
|
|
|
|
"status": req.Status,
|
|
|
|
|
"update_user_id": operator.UserID,
|
|
|
|
|
"update_user_name": operator.Username,
|
|
|
|
|
"updated_at": time.Now(),
|
|
|
|
|
}); 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 SkillDefinitionPostDelete(ctx *gin.Context) {
|
|
|
|
|
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionDelete)
|
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.DeleteSkillDefinitionRequest{}
|
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 req.ID <= 0 {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0052"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
if services.SkillDefinitionService.Get(req.ID) == nil {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
if err := services.SkillDefinitionService.Updates(req.ID, map[string]any{
|
|
|
|
|
"status": enums.StatusDeleted,
|
|
|
|
|
"update_user_id": operator.UserID,
|
|
|
|
|
"update_user_name": operator.Username,
|
|
|
|
|
"updated_at": time.Now(),
|
|
|
|
|
}); 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-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func SkillDefinitionPostRestore(ctx *gin.Context) {
|
|
|
|
|
operator, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionDelete)
|
2026-04-17 15:54:09 +08:00
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req := request.RestoreSkillDefinitionRequest{}
|
2026-05-23 22:22:18 +08:00
|
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
if req.ID <= 0 {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0052"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item := services.SkillDefinitionService.Get(req.ID)
|
|
|
|
|
if item == nil {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0053"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
if item.Status != enums.StatusDeleted {
|
2026-06-02 20:51:13 +08:00
|
|
|
httpx.WriteJSON(ctx, httpx.JsonErrorMsg(ctx, "error.e0088"))
|
2026-05-23 22:22:18 +08:00
|
|
|
return
|
2026-04-17 15:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := services.SkillDefinitionService.Updates(req.ID, map[string]any{
|
|
|
|
|
"status": enums.StatusDisabled,
|
|
|
|
|
"update_user_id": operator.UserID,
|
|
|
|
|
"update_user_name": operator.Username,
|
|
|
|
|
"updated_at": time.Now(),
|
|
|
|
|
}); err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-17 15:54:09 +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 SkillDefinitionPostDebug_run(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionView); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req := request.SkillDebugRunRequest{}
|
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
|
|
|
}
|
|
|
|
|
resp, err := services.SkillRuntimeService.DebugRun(context.Background(), req)
|
|
|
|
|
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-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, resp)
|
2026-04-09 10:01:23 +08:00
|
|
|
}
|
2026-04-10 17:27:44 +08:00
|
|
|
|
2026-05-23 22:22:18 +08:00
|
|
|
func SkillDefinitionPostDebug_resume(ctx *gin.Context) {
|
|
|
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionSkillDefinitionView); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-10 17:27:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req := request.SkillDebugResumeRequest{}
|
2026-05-23 22:22:18 +08:00
|
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-10 17:27:44 +08:00
|
|
|
}
|
|
|
|
|
resp, err := services.SkillRuntimeService.DebugResume(context.Background(), req)
|
|
|
|
|
if err != nil {
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, err)
|
|
|
|
|
return
|
2026-04-10 17:27:44 +08:00
|
|
|
}
|
2026-05-23 22:22:18 +08:00
|
|
|
httpx.WriteJSON(ctx, resp)
|
2026-04-10 17:27:44 +08:00
|
|
|
}
|