package managesdk import ( "fmt" ) type ManageService struct { client *Client } func (s *ManageService) getServicePath() string { switch s.client.config.Type { case ServiceTypePerson: return "/person" case ServiceTypeResource: return "/resource" default: return "/person" } } func (s *ManageService) Save(params any) (string, error) { var resp IDResponse _, err := s.client.http.R(). SetBody(params). SetResult(&resp). Post(s.client.apiV1Path(s.getServicePath() + "/save")) if err != nil { return "", fmt.Errorf("保存失败: %w", err) } if !resp.Success { return "", fmt.Errorf("保存失败: %s", resp.Msg) } return resp.Data, nil } func (s *ManageService) Query(params any) (*InfosData[map[string]any], error) { var resp InfosResponse[map[string]any] _, err := s.client.http.R(). SetBody(params). SetResult(&resp). Post(s.client.apiV1Path(s.getServicePath() + "/query")) if err != nil { return nil, fmt.Errorf("查询列表失败: %w", err) } if !resp.Success { return nil, fmt.Errorf("查询列表失败: %s", resp.Msg) } return &resp.Data, nil } func (s *ManageService) Get(params GetPersonParams) (*map[string]any, error) { var resp InfoResponse[map[string]any] _, err := s.client.http.R(). SetQueryParam("id", params.ID). SetResult(&resp). Get(s.client.apiV1Path(s.getServicePath() + "/get")) if err != nil { return nil, fmt.Errorf("查询详情失败: %w", err) } if !resp.Success { return nil, fmt.Errorf("查询详情失败: %s", resp.Msg) } return &resp.Data, nil } func (s *ManageService) Delete(params any) error { var resp MsgResponse _, err := s.client.http.R(). SetBody(params). SetResult(&resp). Delete(s.client.apiV1Path(s.getServicePath() + "/delete")) if err != nil { return fmt.Errorf("删除失败: %w", err) } if !resp.Success { return fmt.Errorf("删除失败: %s", resp.Msg) } return nil } func (s *ManageService) Options() ([]map[string]any, error) { var resp InfosResponse[map[string]any] var path string switch s.client.config.Type { case ServiceTypePerson: path = "/person/genders" case ServiceTypeResource: path = "/resource/categories" } _, err := s.client.http.R(). SetResult(&resp). Get(s.client.apiV1Path(path)) if err != nil { return nil, fmt.Errorf("查询选项列表失败: %w", err) } if !resp.Success { return nil, fmt.Errorf("查询选项列表失败: %s", resp.Msg) } return resp.Data.Infos, nil } func (s *ManageService) States() ([]map[string]any, error) { var resp InfosResponse[map[string]any] _, err := s.client.http.R(). SetResult(&resp). Get(s.client.apiV1Path(s.getServicePath() + "/states")) if err != nil { return nil, fmt.Errorf("查询状态列表失败: %w", err) } if !resp.Success { return nil, fmt.Errorf("查询状态列表失败: %s", resp.Msg) } return resp.Data.Infos, nil } func (s *ManageService) PredefinedFields() ([]map[string]any, error) { var resp InfosResponse[map[string]any] _, err := s.client.http.R(). SetResult(&resp). Get(s.client.apiV1Path(s.getServicePath() + "/predefined-fields")) if err != nil { return nil, fmt.Errorf("查询预定义字段失败: %w", err) } if !resp.Success { return nil, fmt.Errorf("查询预定义字段失败: %s", resp.Msg) } return resp.Data.Infos, nil }