c6c1c00141
- Implement role management endpoints including listing, creating, updating, and deleting roles. - Add session management endpoints for viewing and revoking sessions. - Create skill definition management endpoints for CRUD operations and status updates. - Introduce tag management endpoints for handling tags with sorting and status updates. - Develop ticket management endpoints for viewing, creating, updating, and managing ticket progress. - Implement user management endpoints for CRUD operations, role assignments, and password resets. - Add WeChat callback handlers for verifying and processing messages.
151 lines
4.0 KiB
Go
151 lines
4.0 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"cs-agent/internal/builders"
|
|
"cs-agent/internal/pkg/constants"
|
|
"cs-agent/internal/pkg/dto"
|
|
"cs-agent/internal/pkg/dto/request"
|
|
"cs-agent/internal/pkg/enums"
|
|
"cs-agent/internal/pkg/httpx"
|
|
"cs-agent/internal/services"
|
|
|
|
"cs-agent/internal/pkg/httpx/params"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/mlogclub/simple/web"
|
|
)
|
|
|
|
func CustomerPostList(ctx *gin.Context) {
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerView); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
var req request.CustomerListRequest
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
list, paging := services.CustomerService.ListCustomers(req)
|
|
httpx.WriteJSON(ctx, &web.PageResult{Results: builders.BuildCustomerList(list), Page: paging})
|
|
}
|
|
|
|
func CustomerGetBy(ctx *gin.Context) {
|
|
id, ok := httpx.GetPathInt64(ctx, "id")
|
|
if !ok {
|
|
return
|
|
}
|
|
if _, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerView); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
item := services.CustomerService.Get(id)
|
|
if item == nil || item.Status == enums.StatusDeleted {
|
|
httpx.WriteJSON(ctx, nil)
|
|
return
|
|
}
|
|
ret := builders.BuildCustomer(item)
|
|
httpx.WriteJSON(ctx, &ret)
|
|
}
|
|
|
|
// PostSave_profile POST /save_profile — 客户主信息与联系方式在同一事务中保存。
|
|
func CustomerPostSave_profile(ctx *gin.Context) {
|
|
req := request.SaveCustomerProfileRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
createMode := req.ID == nil || *req.ID <= 0
|
|
var user *dto.AuthPrincipal
|
|
var err error
|
|
if createMode {
|
|
user, err = services.AuthService.RequirePermission(ctx, constants.PermissionCustomerCreate)
|
|
} else {
|
|
user, err = services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
|
|
}
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
item, err := services.CustomerService.SaveCustomerProfile(req, user)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
ret := builders.BuildCustomer(item)
|
|
httpx.WriteJSON(ctx, &ret)
|
|
}
|
|
|
|
func CustomerPostCreate(ctx *gin.Context) {
|
|
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerCreate)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
req := request.CreateCustomerRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
item, err := services.CustomerService.CreateCustomer(req, user)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
ret := builders.BuildCustomer(item)
|
|
httpx.WriteJSON(ctx, &ret)
|
|
}
|
|
|
|
func CustomerPostUpdate(ctx *gin.Context) {
|
|
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
req := request.UpdateCustomerRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
if err := services.CustomerService.UpdateCustomer(req, user); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, nil)
|
|
}
|
|
|
|
func CustomerPostDelete(ctx *gin.Context) {
|
|
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerDelete)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
req := request.DeleteCustomerRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
if err := services.CustomerService.DeleteCustomer(req.ID, *user); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, nil)
|
|
}
|
|
|
|
func CustomerPostUpdate_status(ctx *gin.Context) {
|
|
user, err := services.AuthService.RequirePermission(ctx, constants.PermissionCustomerUpdate)
|
|
if err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
req := request.UpdateCustomerStatusRequest{}
|
|
if err := params.ReadJSON(ctx, &req); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
if err := services.CustomerService.UpdateStatus(req.ID, req.Status, user); err != nil {
|
|
httpx.WriteJSON(ctx, err)
|
|
return
|
|
}
|
|
httpx.WriteJSON(ctx, nil)
|
|
}
|