578 lines
19 KiB
Go
578 lines
19 KiB
Go
|
|
package servers
|
|||
|
|
|
|||
|
|
import (
|
|||
|
|
"WiiCITMS/process/hr"
|
|||
|
|
"context"
|
|||
|
|
"encoding/json"
|
|||
|
|
"fmt"
|
|||
|
|
|
|||
|
|
"github.com/mark3labs/mcp-go/mcp"
|
|||
|
|
"github.com/mark3labs/mcp-go/server"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// HROrgPositionTools 组织与岗位相关工具
|
|||
|
|
var HROrgPositionTools = []server.ServerTool{
|
|||
|
|
// 查询组织列表(增强版)
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"queryOrganizations",
|
|||
|
|
mcp.WithDescription("查询组织列表,支持更多查询条件"),
|
|||
|
|
mcp.WithString("organizationName", mcp.Description("组织名称,模糊查询")),
|
|||
|
|
mcp.WithString("parentGuid", mcp.Description("父组织ID,可选")),
|
|||
|
|
mcp.WithBoolean("includeChildren", 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.QueryOrganizationsRequest{
|
|||
|
|
OrganizationName: request.GetString("organizationName", ""),
|
|||
|
|
ParentGuid: request.GetString("parentGuid", ""),
|
|||
|
|
IncludeChildren: request.GetBool("includeChildren", false),
|
|||
|
|
Limit: request.GetInt("limit", 20),
|
|||
|
|
Offset: request.GetInt("offset", 0),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.QueryOrganizations(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 获取组织树
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getOrganizationTree",
|
|||
|
|
mcp.WithDescription("获取组织树结构"),
|
|||
|
|
mcp.WithString("rootOrgGuid", mcp.Description("根组织ID,不指定则获取所有顶级组织的树")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
rootOrgGuid := request.GetString("rootOrgGuid", "")
|
|||
|
|
|
|||
|
|
rep, proc := hr.GetOrganizationTree(rootOrgGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 获取组织详情
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getOrganization",
|
|||
|
|
mcp.WithDescription("根据ID获取组织详情"),
|
|||
|
|
mcp.WithString("orgGuid", mcp.Required(), mcp.Description("组织ID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
orgGuid := request.GetString("orgGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.GetOrganizationByID(orgGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 创建组织(增强版)
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"createOrganizationExt",
|
|||
|
|
mcp.WithDescription("创建组织(增强版)"),
|
|||
|
|
mcp.WithString("organizationName", mcp.Required(), mcp.Description("组织名称")),
|
|||
|
|
mcp.WithString("parentGuid", mcp.Description("父组织ID,可选")),
|
|||
|
|
mcp.WithNumber("organizationType", mcp.Required(), mcp.Description("组织类型:1-公司,2-部门,3-团队")),
|
|||
|
|
mcp.WithString("description", mcp.Description("组织描述,可选")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
name := request.GetString("organizationName", "")
|
|||
|
|
if name == "" {
|
|||
|
|
return nil, fmt.Errorf("组织名称不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
orgType := request.GetInt("organizationType", 0)
|
|||
|
|
if orgType <= 0 {
|
|||
|
|
return nil, fmt.Errorf("无效的组织类型")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.CreateOrganizationRequest{
|
|||
|
|
OrganizationName: name,
|
|||
|
|
ParentGuid: request.GetString("parentGuid", ""),
|
|||
|
|
OrganizationType: orgType,
|
|||
|
|
Description: request.GetString("description", ""),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.CreateOrganization(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 更新组织
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"updateOrganization",
|
|||
|
|
mcp.WithDescription("更新组织信息"),
|
|||
|
|
mcp.WithString("orgGuid", mcp.Required(), mcp.Description("组织ID")),
|
|||
|
|
mcp.WithString("organizationName", mcp.Description("组织名称,可选")),
|
|||
|
|
mcp.WithString("parentGuid", mcp.Description("父组织ID,可选")),
|
|||
|
|
mcp.WithNumber("organizationType", mcp.Description("组织类型:1-公司,2-部门,3-团队,可选")),
|
|||
|
|
mcp.WithString("description", mcp.Description("组织描述,可选")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
orgGuid := request.GetString("orgGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.CreateOrganizationRequest{
|
|||
|
|
OrganizationName: request.GetString("organizationName", ""),
|
|||
|
|
ParentGuid: request.GetString("parentGuid", ""),
|
|||
|
|
OrganizationType: request.GetInt("organizationType", 0),
|
|||
|
|
Description: request.GetString("description", ""),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.UpdateOrganization(orgGuid, params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 删除组织
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"deleteOrganization",
|
|||
|
|
mcp.WithDescription("删除组织(逻辑删除)"),
|
|||
|
|
mcp.WithString("orgGuid", mcp.Required(), mcp.Description("组织ID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
orgGuid := request.GetString("orgGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
proc := hr.DeleteOrganization(orgGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return mcp.NewToolResultText("删除成功"), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 创建岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"createPosition",
|
|||
|
|
mcp.WithDescription("创建岗位"),
|
|||
|
|
mcp.WithString("positionName", mcp.Required(), mcp.Description("岗位名称")),
|
|||
|
|
mcp.WithString("positionCode", mcp.Required(), mcp.Description("岗位代码")),
|
|||
|
|
mcp.WithString("description", mcp.Description("岗位描述,可选")),
|
|||
|
|
mcp.WithNumber("level", mcp.Description("岗位级别,可选")),
|
|||
|
|
mcp.WithNumber("categoryId", mcp.Description("岗位类别ID,可选")),
|
|||
|
|
mcp.WithString("categoryName", mcp.Description("岗位类别名称,可选")),
|
|||
|
|
mcp.WithBoolean("isManagement", mcp.Description("是否管理岗位,默认false")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
name := request.GetString("positionName", "")
|
|||
|
|
if name == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位名称不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
code := request.GetString("positionCode", "")
|
|||
|
|
if code == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位代码不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.CreatePositionRequest{
|
|||
|
|
PositionName: name,
|
|||
|
|
PositionCode: code,
|
|||
|
|
Description: request.GetString("description", ""),
|
|||
|
|
Level: request.GetInt("level", 0),
|
|||
|
|
CategoryID: request.GetInt("categoryId", 0),
|
|||
|
|
CategoryName: request.GetString("categoryName", ""),
|
|||
|
|
IsManagement: request.GetBool("isManagement", false),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.CreatePosition(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 查询岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"queryPositions",
|
|||
|
|
mcp.WithDescription("查询岗位列表"),
|
|||
|
|
mcp.WithString("query", mcp.Description("搜索关键词,可选")),
|
|||
|
|
mcp.WithString("positionName", mcp.Description("岗位名称,模糊查询")),
|
|||
|
|
mcp.WithString("positionCode", mcp.Description("岗位代码,精确查询")),
|
|||
|
|
mcp.WithNumber("categoryId", mcp.Description("岗位类别ID,筛选")),
|
|||
|
|
mcp.WithNumber("level", mcp.Description("岗位级别,筛选")),
|
|||
|
|
mcp.WithBoolean("isManagement", mcp.Description("是否管理岗位,筛选")),
|
|||
|
|
// mcp.WithNumber("status", mcp.Description("状态:-1-所有,1-启用,0-禁用")),
|
|||
|
|
mcp.WithNumber("limit", mcp.Description("分页参数,每页数量")),
|
|||
|
|
mcp.WithNumber("offset", mcp.Description("分页参数,偏移量")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
// 确保至少有一个参数
|
|||
|
|
query := request.GetString("query", "")
|
|||
|
|
|
|||
|
|
params := hr.QueryPositionsRequest{
|
|||
|
|
PositionName: request.GetString("positionName", query), // 如果positionName不存在,使用query作为名称搜索
|
|||
|
|
PositionCode: request.GetString("positionCode", ""),
|
|||
|
|
CategoryID: request.GetInt("categoryId", 0),
|
|||
|
|
Level: request.GetInt("level", 0),
|
|||
|
|
IsManagement: request.GetBool("isManagement", false),
|
|||
|
|
// Status: request.GetInt("status", -1),
|
|||
|
|
Limit: request.GetInt("limit", 20),
|
|||
|
|
Offset: request.GetInt("offset", 0),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.QueryPositions(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 获取岗位详情
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getPosition",
|
|||
|
|
mcp.WithDescription("获取岗位详情"),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Required(), mcp.Description("岗位ID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
positionGuid := request.GetString("positionGuid", "")
|
|||
|
|
if positionGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.GetPositionByID(positionGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 更新岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"updatePosition",
|
|||
|
|
mcp.WithDescription("更新岗位信息"),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Required(), mcp.Description("岗位ID")),
|
|||
|
|
mcp.WithString("positionName", mcp.Description("岗位名称,可选")),
|
|||
|
|
mcp.WithString("positionCode", mcp.Description("岗位代码,可选")),
|
|||
|
|
mcp.WithString("description", mcp.Description("岗位描述,可选")),
|
|||
|
|
mcp.WithNumber("level", mcp.Description("岗位级别,可选")),
|
|||
|
|
mcp.WithNumber("categoryId", mcp.Description("岗位类别ID,可选")),
|
|||
|
|
mcp.WithString("categoryName", mcp.Description("岗位类别名称,可选")),
|
|||
|
|
mcp.WithBoolean("isManagement", mcp.Description("是否管理岗位,可选")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
positionGuid := request.GetString("positionGuid", "")
|
|||
|
|
if positionGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.CreatePositionRequest{
|
|||
|
|
PositionName: request.GetString("positionName", ""),
|
|||
|
|
PositionCode: request.GetString("positionCode", ""),
|
|||
|
|
Description: request.GetString("description", ""),
|
|||
|
|
Level: request.GetInt("level", 0),
|
|||
|
|
CategoryID: request.GetInt("categoryId", 0),
|
|||
|
|
CategoryName: request.GetString("categoryName", ""),
|
|||
|
|
IsManagement: request.GetBool("isManagement", false),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.UpdatePosition(positionGuid, params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 更改岗位状态
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"changePositionStatus",
|
|||
|
|
mcp.WithDescription("更改岗位状态(启用/禁用)"),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Required(), mcp.Description("岗位ID")),
|
|||
|
|
mcp.WithNumber("status", mcp.Required(), mcp.Description("状态:1-启用,0-禁用")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
positionGuid := request.GetString("positionGuid", "")
|
|||
|
|
if positionGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
status := request.GetInt("status", -1)
|
|||
|
|
if status != 0 && status != 1 {
|
|||
|
|
return nil, fmt.Errorf("无效的状态值,必须为0或1")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.ChangePositionStatus(positionGuid, status)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 删除岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"deletePosition",
|
|||
|
|
mcp.WithDescription("删除岗位(逻辑删除)"),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Required(), mcp.Description("岗位ID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
positionGuid := request.GetString("positionGuid", "")
|
|||
|
|
if positionGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
proc := hr.DeletePosition(positionGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return mcp.NewToolResultText("删除成功"), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 为组织分配岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"assignPositionToOrg",
|
|||
|
|
mcp.WithDescription("为组织分配岗位"),
|
|||
|
|
mcp.WithString("organizationGuid", mcp.Required(), mcp.Description("组织ID")),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Required(), mcp.Description("岗位ID")),
|
|||
|
|
mcp.WithNumber("headCount", mcp.Description("岗位编制人数,默认1")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
orgGuid := request.GetString("organizationGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
positionGuid := request.GetString("positionGuid", "")
|
|||
|
|
if positionGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.AssignPositionToOrgRequest{
|
|||
|
|
OrganizationGuid: orgGuid,
|
|||
|
|
PositionGuid: positionGuid,
|
|||
|
|
HeadCount: request.GetInt("headCount", 1),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.AssignPositionToOrg(params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 更新组织岗位编制人数
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"updateOrgPositionHeadCount",
|
|||
|
|
mcp.WithDescription("更新组织岗位编制人数"),
|
|||
|
|
mcp.WithString("relationGuid", mcp.Required(), mcp.Description("组织岗位关系ID")),
|
|||
|
|
mcp.WithNumber("headCount", mcp.Required(), mcp.Description("岗位编制人数")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
relationGuid := request.GetString("relationGuid", "")
|
|||
|
|
if relationGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织岗位关系ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
headCount := request.GetInt("headCount", 0)
|
|||
|
|
if headCount <= 0 {
|
|||
|
|
return nil, fmt.Errorf("编制人数必须大于0")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.UpdateOrgPositionHeadCount(relationGuid, headCount)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 移除组织岗位
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"removePositionFromOrg",
|
|||
|
|
mcp.WithDescription("从组织中移除岗位"),
|
|||
|
|
mcp.WithString("relationGuid", mcp.Required(), mcp.Description("组织岗位关系ID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
relationGuid := request.GetString("relationGuid", "")
|
|||
|
|
if relationGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织岗位关系ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
proc := hr.RemovePositionFromOrg(relationGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return mcp.NewToolResultText("移除成功"), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 查询组织的岗位列表
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"queryPositionsByOrg",
|
|||
|
|
mcp.WithDescription("查询组织的岗位列表"),
|
|||
|
|
mcp.WithString("organizationGuid", mcp.Required(), mcp.Description("组织ID")),
|
|||
|
|
mcp.WithNumber("limit", mcp.Description("分页参数,每页数量")),
|
|||
|
|
mcp.WithNumber("offset", mcp.Description("分页参数,偏移量")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
orgGuid := request.GetString("organizationGuid", "")
|
|||
|
|
if orgGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.QueryOrgPositionRequest{
|
|||
|
|
Limit: request.GetInt("limit", 20),
|
|||
|
|
Offset: request.GetInt("offset", 0),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.QueryPositionsByOrg(orgGuid, params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 查询拥有指定岗位的组织列表
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"queryOrgsByPosition",
|
|||
|
|
mcp.WithDescription("查询拥有指定岗位的组织列表"),
|
|||
|
|
mcp.WithString("positionGuid", mcp.Required(), mcp.Description("岗位ID")),
|
|||
|
|
mcp.WithNumber("limit", mcp.Description("分页参数,每页数量")),
|
|||
|
|
mcp.WithNumber("offset", mcp.Description("分页参数,偏移量")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
positionGuid := request.GetString("positionGuid", "")
|
|||
|
|
if positionGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("岗位ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
params := hr.QueryOrgPositionRequest{
|
|||
|
|
Limit: request.GetInt("limit", 20),
|
|||
|
|
Offset: request.GetInt("offset", 0),
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.QueryOrgsByPosition(positionGuid, params)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
// 获取组织岗位关系详情
|
|||
|
|
{
|
|||
|
|
Tool: mcp.NewTool(
|
|||
|
|
"getPositionOrgRelation",
|
|||
|
|
mcp.WithDescription("获取组织岗位关系详情"),
|
|||
|
|
mcp.WithString("relationGuid", mcp.Required(), mcp.Description("组织岗位关系ID")),
|
|||
|
|
),
|
|||
|
|
Handler: func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
|||
|
|
relationGuid := request.GetString("relationGuid", "")
|
|||
|
|
if relationGuid == "" {
|
|||
|
|
return nil, fmt.Errorf("组织岗位关系ID不能为空")
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
rep, proc := hr.GetPositionOrgRelation(relationGuid)
|
|||
|
|
if proc.IsError() {
|
|||
|
|
return mcp.NewToolResultText(""), proc.Error
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
repStr, err := json.Marshal(rep)
|
|||
|
|
if err != nil {
|
|||
|
|
return mcp.NewToolResultText(""), err
|
|||
|
|
}
|
|||
|
|
return mcp.NewToolResultText(string(repStr)), nil
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
}
|