ai_scheduler/internal/pkg/dingtalk_notable/client.go

71 lines
1.7 KiB
Go

package dingtalk_notable
import (
"ai_scheduler/internal/config"
errorcode "ai_scheduler/internal/data/error"
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
notable "github.com/alibabacloud-go/dingtalk/notable_1_0"
util "github.com/alibabacloud-go/tea-utils/v2/service"
"github.com/alibabacloud-go/tea/tea"
)
type Client struct {
config *config.Config
cli *notable.Client
}
func NewnotableClient(config *config.Config) (*Client, error) {
cfg := &openapi.Config{
AccessKeyId: tea.String(config.Tools.DingTalkBot.APIKey),
AccessKeySecret: tea.String(config.Tools.DingTalkBot.APISecret),
Protocol: tea.String("https"),
RegionId: tea.String("central"),
}
c, err := notable.NewClient(cfg)
if err != nil {
return nil, err
}
return &Client{config: config, cli: c}, nil
}
type UpdateRecordReq struct {
BaseId string
SheetId string
RecordId string
UserId string
UnionId string
}
type UpdateRecordsserResp struct {
Body interface{}
}
func (c *Client) UpdateRecord(accessToken string, req *UpdateRecordReq) (bool, error) {
headers := &notable.UpdateRecordsHeaders{}
headers.XAcsDingtalkAccessToken = tea.String(accessToken)
resp, err := c.cli.UpdateRecordsWithOptions(
tea.String(req.BaseId),
tea.String(req.SheetId),
&notable.UpdateRecordsRequest{
OperatorId: tea.String(req.UnionId),
Records: []*notable.UpdateRecordsRequestRecords{
{
Fields: map[string]interface{}{
"提交人": req.UserId,
},
Id: tea.String(req.RecordId),
},
},
}, headers, &util.RuntimeOptions{})
if err != nil {
return false, err
}
if resp.Body == nil {
return false, errorcode.ParamErr("empty response body")
}
return true, nil
}