From 2aa083e0945576b857bb3c590f1babcc11c1f09d Mon Sep 17 00:00:00 2001 From: Matrix-X Date: Thu, 16 May 2024 15:07:40 +0800 Subject: [PATCH 1/2] feat(work): oa add approvial --- src/work/application.go | 8 +++- src/work/oa/approval/client.go | 33 +++++++++++++++ .../reponse/responseUpdateTemplate.go | 1 + .../approval/request/requestUpdateTemplate.go | 41 +++++++++++++++++++ src/work/oa/provider.go | 28 ++++++++----- 5 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 src/work/oa/approval/client.go create mode 100644 src/work/oa/approval/reponse/responseUpdateTemplate.go create mode 100644 src/work/oa/approval/request/requestUpdateTemplate.go diff --git a/src/work/application.go b/src/work/application.go index d71aa3b9..a5569906 100644 --- a/src/work/application.go +++ b/src/work/application.go @@ -45,6 +45,7 @@ import ( miniProgram "github.com/ArtisanCloud/PowerWeChat/v3/src/work/miniProgram" msgaudit "github.com/ArtisanCloud/PowerWeChat/v3/src/work/msgAudit" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa" + "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/approval" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/calendar" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/dial" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/journal" @@ -127,6 +128,7 @@ type Work struct { OAPSTNCC *pstncc.Client OASchedule *schedule.Client OAWebDrive *webdrive.Client + OAApproval *approval.Client MsgAudit *msgaudit.Client @@ -334,7 +336,9 @@ func NewWork(config *UserConfig) (*Work, error) { app.OAMeetingRoom, app.OAPSTNCC, app.OASchedule, - app.OAWebDrive, err = oa.RegisterProvider(app) + app.OAWebDrive, + app.OAApproval, + err = oa.RegisterProvider(app) if err != nil { return nil, err } @@ -478,6 +482,8 @@ func (app *Work) GetComponent(name string) interface{} { return app.OASchedule case "OAWebDrive": return app.OAWebDrive + case "OAApproval": + return app.OAApproval case "MsgAudit": return app.MsgAudit diff --git a/src/work/oa/approval/client.go b/src/work/oa/approval/client.go new file mode 100644 index 00000000..220c10bb --- /dev/null +++ b/src/work/oa/approval/client.go @@ -0,0 +1,33 @@ +package approval + +import ( + "context" + "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel" + "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response" + "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/approval/request" +) + +type Client struct { + BaseClient *kernel.BaseClient +} + +func NewClient(app kernel.ApplicationInterface) (*Client, error) { + baseClient, err := kernel.NewBaseClient(&app, nil) + if err != nil { + return nil, err + } + return &Client{ + baseClient, + }, nil +} + +// 更新审批模板 +// https://developer.work.weixin.qq.com/document/path/97438 +func (comp *Client) UpdateTemplate(ctx context.Context, options *request.RequestUpdateTemplate) (*response.ResponseWork, error) { + + result := &response.ResponseWork{} + + _, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/approval/update_template", options, nil, nil, result) + + return result, err +} diff --git a/src/work/oa/approval/reponse/responseUpdateTemplate.go b/src/work/oa/approval/reponse/responseUpdateTemplate.go new file mode 100644 index 00000000..205d4d0c --- /dev/null +++ b/src/work/oa/approval/reponse/responseUpdateTemplate.go @@ -0,0 +1 @@ +package reponse diff --git a/src/work/oa/approval/request/requestUpdateTemplate.go b/src/work/oa/approval/request/requestUpdateTemplate.go new file mode 100644 index 00000000..a0d43c3d --- /dev/null +++ b/src/work/oa/approval/request/requestUpdateTemplate.go @@ -0,0 +1,41 @@ +package request + +type TemplateName struct { + Text string `json:"text"` + Lang string `json:"lang"` +} + +type Title struct { + Text string `json:"text"` + Lang string `json:"lang"` +} + +type Placeholder struct { + Text string `json:"text"` + Lang string `json:"lang"` +} + +type Property struct { + Control string `json:"control"` + Id string `json:"id"` + Title []Title `json:"title"` + Placeholder []Placeholder `json:"placeholder"` + Require int `json:"require"` + UnPrint int `json:"un_print"` +} + +type Control struct { + Property Property `json:"property"` + Config struct { + } `json:"config"` +} + +type TemplateContent struct { + Controls []Control `json:"controls"` +} + +type RequestUpdateTemplate struct { + TemplateId string `json:"template_id"` + TemplateName []TemplateName `json:"template_name"` + TemplateContent TemplateContent `json:"template_content"` +} diff --git a/src/work/oa/provider.go b/src/work/oa/provider.go index 31e0b1cf..71102f02 100644 --- a/src/work/oa/provider.go +++ b/src/work/oa/provider.go @@ -2,6 +2,7 @@ package oa import ( "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel" + "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/approval" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/calendar" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/dial" "github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/journal" @@ -23,6 +24,7 @@ func RegisterProvider(app kernel.ApplicationInterface) (*Client, *pstncc.Client, *schedule.Client, *webdrive.Client, + *approval.Client, error, ) { @@ -30,45 +32,48 @@ func RegisterProvider(app kernel.ApplicationInterface) (*Client, Client, err := NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } Calendar, err := calendar.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } Dial, err := dial.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } Journal, err := journal.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } Living, err := living.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } Meeting, err := meeting.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } MeetingRoom, err := meetingroom.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } PSTNCC, err := pstncc.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } Schedule, err := schedule.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } WebDrive, err := webdrive.NewClient(app) if err != nil { - return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err + } + Approval, err := approval.NewClient(app) + if err != nil { + return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } - return Client, Calendar, Dial, @@ -79,6 +84,7 @@ func RegisterProvider(app kernel.ApplicationInterface) (*Client, PSTNCC, Schedule, WebDrive, + Approval, nil } From 6fa73cac97e2798e8c674580cf34eb74bc22e4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=9B=E6=99=A8=E9=98=B3?= <625226669@qq.com> Date: Sun, 19 May 2024 13:24:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9GetApprovalInfo=EF=BC=88?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E8=8E=B7=E5=8F=96=E5=AE=A1=E6=89=B9=E5=8D=95?= =?UTF-8?q?=E5=8F=B7=EF=BC=89=E5=87=BD=E6=95=B0=E7=9A=84=E4=BC=A0=E5=8F=82?= =?UTF-8?q?filters=E4=B8=BA=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/work/oa/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/work/oa/client.go b/src/work/oa/client.go index 3f995b2d..8caeb330 100644 --- a/src/work/oa/client.go +++ b/src/work/oa/client.go @@ -195,7 +195,7 @@ func (comp *Client) CreateApproval(ctx context.Context, data *power.HashMap) (*r // 批量获取审批单号 // https://developer.work.weixin.qq.com/document/path/91816 -func (comp *Client) GetApprovalInfo(ctx context.Context, startTime int, endTime int, nextCursor int, size int, filters *object.HashMap) (*response.ResponseApprovalNoList, error) { +func (comp *Client) GetApprovalInfo(ctx context.Context, startTime int, endTime int, nextCursor int, size int, filters []*object.HashMap) (*response.ResponseApprovalNoList, error) { result := &response.ResponseApprovalNoList{}