155 lines
4.9 KiB
Go
155 lines
4.9 KiB
Go
|
|
package servers
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"WiiCITMS/process/hr"
|
|||
|
|
"context"
|
|||
|
|
"encoding/json"
|
|||
|
|
"fmt"
|
|||
|
|
|
|||
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|||
|
|
"github.com/mark3labs/mcp-go/server"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// HRStaffPositionTools 员工岗位管理工具
|
|||
|
|
var HRStaffPositionTools = []server.ServerTool{
|
|||
|
|
// 为员工分配岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"assignPosition",
|
|||
|
|
mcp.WithDescription("为员工分配组织和岗位"),
|
|||
|
|
mcp.WithString("staffGuid", mcp.Required(), mcp.Description("员工GUID")),
|
|||
|
|
mcp.WithString("organizationGuid", mcp.Required(), mcp.Description("组织GUID")),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Description("岗位GUID,可选,不提供则只绑定组织")),
|
|||
|
|
mcp.WithBoolean("isLeader", mcp.Description("是否是组织负责人,默认false")),
|
|||
|
|
mcp.WithNumber("recordType", mcp.Description("关系类型,0-主部门/岗位,1-兼职部门/岗位,默认1")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
staffGuid := request.GetString("staffGuid", "")
|
|||
|
|
if staffGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("员工GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
orgGuid := request.GetString("organizationGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.AssignPositionRequest{
|
|||
|
|
StaffGuid: staffGuid,
|
|||
|
|
OrganizationGuid: orgGuid,
|
|||
|
|
PositionGuid: request.GetString("positionGuid", ""),
|
|||
|
|
IsLeader: request.GetBool("isLeader", false),
|
|||
|
|
RecordType: request.GetInt("recordType", 1), // 默认为兼职部门/岗位
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
result, proc := hr.AssignPosition(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(result)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 更新员工岗位关系
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"updateStaffPosition",
|
|||
|
|
mcp.WithDescription("更新员工岗位关系"),
|
|||
|
|
mcp.WithString("recordGuid", mcp.Required(), mcp.Description("关系记录GUID")),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Description("岗位GUID")),
|
|||
|
|
mcp.WithBoolean("isLeader", mcp.Description("是否是组织负责人")),
|
|||
|
|
mcp.WithNumber("recordType", mcp.Description("关系类型,0-主部门/岗位,1-兼职部门/岗位")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
recordGuid := request.GetString("recordGuid", "")
|
|||
|
|
if recordGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("关系记录GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.UpdateStaffPositionRequest{
|
|||
|
|
RecordGuid: recordGuid,
|
|||
|
|
PositionGuid: request.GetString("positionGuid", ""),
|
|||
|
|
IsLeader: request.GetBool("isLeader", false),
|
|||
|
|
RecordType: request.GetInt("recordType", 1),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
result, proc := hr.UpdateStaffPosition(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(result)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 移除员工岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"removeStaffPosition",
|
|||
|
|
mcp.WithDescription("移除员工的组织和岗位关联"),
|
|||
|
|
mcp.WithString("staffGuid", mcp.Required(), mcp.Description("员工GUID")),
|
|||
|
|
mcp.WithString("organizationGuid", 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不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
orgGuid := request.GetString("organizationGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织GUID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.RemoveStaffPositionRequest{
|
|||
|
|
StaffGuid: staffGuid,
|
|||
|
|
OrganizationGuid: orgGuid,
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
proc := hr.RemoveStaffPosition(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
result := map[string]bool{"success": true}
|
|||
|
|
repStr, err := json.Marshal(result)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 获取员工的所有组织和岗位关联
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getStaffPositions",
|
|||
|
|
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不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
result, proc := hr.GetStaffPositions(staffGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(result)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
}
|