236 lines
7.4 KiB
Go
236 lines
7.4 KiB
Go
|
|
package servers
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"WiiCITMS/process/hr"
|
|||
|
|
"context"
|
|||
|
|
"encoding/json"
|
|||
|
|
"fmt"
|
|||
|
|
|
|||
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|||
|
|
"github.com/mark3labs/mcp-go/server"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// HRStaffTools 员工管理工具
|
|||
|
|
var HRStaffTools = []server.ServerTool{
|
|||
|
|
// 创建员工并指定所属组织
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"createStaffWithOrganization",
|
|||
|
|
mcp.WithDescription("创建员工并指定所属组织"),
|
|||
|
|
mcp.WithString("staffName", mcp.Required(), mcp.Description("员工姓名")),
|
|||
|
|
mcp.WithString("affiliated", mcp.Required(), mcp.Description("所属组织GUID")),
|
|||
|
|
mcp.WithNumber("staffType", mcp.Description("员工类型,0-正式员工,1-实习员工,2-外包员工,默认0")),
|
|||
|
|
mcp.WithNumber("affiliatedType", mcp.Description("隶属关系类型,0-主部门,1-兼职部门,默认0")),
|
|||
|
|
mcp.WithString("account", mcp.Description("账号(可选)")),
|
|||
|
|
mcp.WithString("userGuid", mcp.Description("SSO平台用户GUID(可选)")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
staffName := request.GetString("staffName", "")
|
|||
|
|
if staffName == "" {
|
|||
|
|
return nil, fmt.Errorf("员工姓名不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
affiliated := request.GetString("affiliated", "")
|
|||
|
|
if affiliated == "" {
|
|||
|
|
return nil, fmt.Errorf("所属组织不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.CreateStaffWithOrganizationRequest{
|
|||
|
|
StaffName: staffName,
|
|||
|
|
Affiliated: affiliated,
|
|||
|
|
StaffType: request.GetInt("staffType", 0),
|
|||
|
|
AffiliatedType: request.GetInt("affiliatedType", 0),
|
|||
|
|
Account: request.GetString("account", ""),
|
|||
|
|
UserGuid: request.GetString("userGuid", ""),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staff, proc := hr.CreateStaffWithOrganization(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staff)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 绑定SSO用户到员工
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"bindStaff",
|
|||
|
|
mcp.WithDescription("绑定SSO用户到员工"),
|
|||
|
|
mcp.WithString("staffGuid", mcp.Required(), mcp.Description("员工GUID")),
|
|||
|
|
mcp.WithString("account", mcp.Description("账号")),
|
|||
|
|
mcp.WithString("userGuid", mcp.Description("SSO平台用户GUID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
staffGuid := request.GetString("staffGuid", "")
|
|||
|
|
if staffGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("员工GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
account := request.GetString("account", "")
|
|||
|
|
userGuid := request.GetString("userGuid", "")
|
|||
|
|
|
|||
|
|
if account == "" && userGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("账号和用户GUID至少提供一个")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.BindStaffRequest{
|
|||
|
|
StaffGuid: staffGuid,
|
|||
|
|
Account: account,
|
|||
|
|
UserGuid: userGuid,
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staff, proc := hr.BindStaff(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staff)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 解除员工与SSO用户的绑定
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"unbindStaff",
|
|||
|
|
mcp.WithDescription("解除员工与SSO用户的绑定"),
|
|||
|
|
mcp.WithString("staffGuid", mcp.Required(), mcp.Description("员工GUID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
staffGuid := request.GetString("staffGuid", "")
|
|||
|
|
if staffGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("员工GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staff, proc := hr.UnbindStaff(staffGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staff)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 获取员工详情
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getStaff",
|
|||
|
|
mcp.WithDescription("获取员工详情"),
|
|||
|
|
mcp.WithString("staffGuid", mcp.Required(), mcp.Description("员工GUID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
staffGuid := request.GetString("staffGuid", "")
|
|||
|
|
if staffGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("员工GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staffDetail, proc := hr.GetStaff(staffGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staffDetail)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 查询员工列表
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"queryStaffs",
|
|||
|
|
mcp.WithDescription("查询员工列表"),
|
|||
|
|
mcp.WithString("staffName", mcp.Description("员工姓名,模糊匹配")),
|
|||
|
|
mcp.WithString("account", mcp.Description("账号,精确匹配")),
|
|||
|
|
mcp.WithString("userGuid", mcp.Description("SSO平台用户GUID")),
|
|||
|
|
mcp.WithString("organizationGuid", mcp.Description("所属组织GUID")),
|
|||
|
|
mcp.WithNumber("staffType", mcp.Description("员工类型")),
|
|||
|
|
mcp.WithNumber("limit", mcp.Description("分页参数,每页数量")),
|
|||
|
|
mcp.WithNumber("offset", mcp.Description("分页参数,偏移量")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
params := hr.QueryStaffRequest{
|
|||
|
|
StaffName: request.GetString("staffName", ""),
|
|||
|
|
Account: request.GetString("account", ""),
|
|||
|
|
UserGuid: request.GetString("userGuid", ""),
|
|||
|
|
OrganizationGuid: request.GetString("organizationGuid", ""),
|
|||
|
|
StaffType: request.GetInt("staffType", 0),
|
|||
|
|
Limit: request.GetInt("limit", 20),
|
|||
|
|
Offset: request.GetInt("offset", 0),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staffs, proc := hr.QueryStaffs(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staffs)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 根据SSO用户GUID获取员工
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getStaffByUserGuid",
|
|||
|
|
mcp.WithDescription("根据SSO用户GUID获取员工"),
|
|||
|
|
mcp.WithString("userGuid", mcp.Required(), mcp.Description("SSO平台用户GUID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
userGuid := request.GetString("userGuid", "")
|
|||
|
|
if userGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("用户GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staffDetail, proc := hr.GetStaffByUserGuid(userGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staffDetail)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 根据账号获取员工
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getStaffByAccount",
|
|||
|
|
mcp.WithDescription("根据账号获取员工"),
|
|||
|
|
mcp.WithString("account", mcp.Required(), mcp.Description("账号")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
account := request.GetString("account", "")
|
|||
|
|
if account == "" {
|
|||
|
|
return nil, fmt.Errorf("账号不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
staffDetail, proc := hr.GetStaffByAccount(account)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(staffDetail)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
}
|