Skip to content

Commit

Permalink
daily commit
Browse files Browse the repository at this point in the history
  • Loading branch information
northseadl committed Nov 5, 2023
1 parent 4b94a78 commit 59adc14
Show file tree
Hide file tree
Showing 17 changed files with 448 additions and 11 deletions.
4 changes: 4 additions & 0 deletions api/admin.scrm.api
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ import "admin/scrm/resource/weworkresource.api"
import "admin/scrm/qrcode/weworkcustomergroupqrcode.api"
// tag
import "admin/scrm/tag/weworktag.api"
// common
import "admin/scrm/common.api"
// groupsend
import "admin/scrm/operation/groupsend.api"
23 changes: 23 additions & 0 deletions api/admin/scrm/common.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "v1"

info(
title: "SCRM基础接口"
desc: "公共管理"
author: "YourName"
email: "[email protected]"
)

@server(
group: admin/scrm/common
prefix: /api/v1/admin/scrm/common
)

service PowerX {
@doc "[Public] SCRM是否可用"
@handler AvailabilityCheck
post /availability-check

@doc "[Public] 获取SCRM通用选项"
@handler GetOptions
get /options (GetOptionsRequest) returns (GetOptionsReply)
}
58 changes: 58 additions & 0 deletions api/admin/scrm/operation/groupsend.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
syntax = "v1"

info(
title: "企业微信客户群发"
desc: "企业微信客户群发"
author: "Northseadl"
email: "[email protected]"
version: "v1"
)

@server(
group: admin/scrm/operation
prefix: /api/v1/admin/scrm/operation/group-send
middleware: EmployeeJWTAuth
)

service PowerX {
@doc "企业微信客户群发"
@handler GroupSend
post /group-send (GroupSendRequest)

@doc "获取企业群发记录"
@handler ListGroupSendLog
get /group-send-log (ListGroupSendLogRequest) returns(ListGroupSendLogReply)
}

type (
GroupSendText {
Content string `json:"content"`
}

GroupSendRequest {
ChatType string `json:"chatType"`
ExternalUserIds []string `json:"userIds"`
Text GroupSendText `json:"text"`
}

ListGroupSendLogRequest {
Limit int `json:"limit"`
Cursor string `json:"cursor"`
ChatType string `json:"chatType"`
StartTime string `json:"startTime"`
EndTime string `json:"EndTime"`
Creator string `json:"creator"`
}

WeWorkSendList {
ExternalUserID string `json:"externalUserid"`
ChatID string `json:"chat_id"`
UserID string `json:"userid"`
Status int `json:"status"`
}

ListGroupSendLogReply {
NextCursor string `json:"nextCursor"`
SendList []WeWorkSendList `json:"sendList"`
}
)
21 changes: 21 additions & 0 deletions internal/handler/admin/scrm/common/availabilitycheckhandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package common

import (
"net/http"

"PowerX/internal/logic/admin/scrm/common"
"PowerX/internal/svc"
"github.com/zeromicro/go-zero/rest/httpx"
)

func AvailabilityCheckHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := common.NewAvailabilityCheckLogic(r.Context(), svcCtx)
err := l.AvailabilityCheck()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
}
}
28 changes: 28 additions & 0 deletions internal/handler/admin/scrm/common/getoptionshandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package common

import (
"net/http"

"PowerX/internal/logic/admin/scrm/common"
"PowerX/internal/svc"
"PowerX/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

func GetOptionsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetOptionsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := common.NewGetOptionsLogic(r.Context(), svcCtx)
resp, err := l.GetOptions(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
28 changes: 28 additions & 0 deletions internal/handler/admin/scrm/operation/groupsendhandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package operation

import (
"net/http"

"PowerX/internal/logic/admin/scrm/operation"
"PowerX/internal/svc"
"PowerX/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

func GroupSendHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GroupSendRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := operation.NewGroupSendLogic(r.Context(), svcCtx)
err := l.GroupSend(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
}
}
28 changes: 28 additions & 0 deletions internal/handler/admin/scrm/operation/listgroupsendloghandler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package operation

import (
"net/http"

"PowerX/internal/logic/admin/scrm/operation"
"PowerX/internal/svc"
"PowerX/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)

func ListGroupSendLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListGroupSendLogRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}

l := operation.NewListGroupSendLogLogic(r.Context(), svcCtx)
resp, err := l.ListGroupSendLog(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
37 changes: 37 additions & 0 deletions internal/handler/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions internal/logic/admin/scrm/common/availabilitychecklogic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package common

import (
"context"

"PowerX/internal/svc"

"github.com/zeromicro/go-zero/core/logx"
)

type AvailabilityCheckLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewAvailabilityCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AvailabilityCheckLogic {
return &AvailabilityCheckLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *AvailabilityCheckLogic) AvailabilityCheck() (err error) {
if err = l.svcCtx.PowerX.SCRM.AvailabilityCheck(); err != nil {
return err
}
return nil
}
53 changes: 53 additions & 0 deletions internal/logic/admin/scrm/common/getoptionslogic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package common

import (
"context"
"fmt"

"PowerX/internal/svc"
"PowerX/internal/types"
"PowerX/internal/uc/powerx/scrm/wechat"

"github.com/zeromicro/go-zero/core/logx"
)

type GetOptionsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewGetOptionsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOptionsLogic {
return &GetOptionsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *GetOptionsLogic) GetOptions(req *types.GetOptionsRequest) (resp *types.GetOptionsReply, err error) {
switch req.Type {
case "customer-external":
result, err := l.svcCtx.PowerX.SCRM.Wechat.FindManyWeWorkCustomerPage(l.ctx, &types.PageOption[wechat.FindManyWechatCustomerOption]{
PageIndex: 1,
PageSize: 10,
Option: wechat.FindManyWechatCustomerOption{
Name: req.Search,
},
}, 0)
if err != nil {
return nil, err
}
options := make([]map[string]any, len(result.List))
for i, v := range result.List {
options[i] = map[string]any{
"label": v.Name,
"value": v.ExternalUserId,
}
}
resp.Options = options
default:
err = fmt.Errorf("invalid type: %s", req.Type)
}
return resp, err
}
44 changes: 44 additions & 0 deletions internal/logic/admin/scrm/operation/groupsendlogic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package operation

import (
"context"
"fmt"

"github.com/ArtisanCloud/PowerWeChat/v3/src/work/externalContact/messageTemplate/request"

"PowerX/internal/svc"
"PowerX/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type GroupSendLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewGroupSendLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GroupSendLogic {
return &GroupSendLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *GroupSendLogic) GroupSend(req *types.GroupSendRequest) error {
result, err := l.svcCtx.PowerX.SCRM.Wework.ExternalContactMessageTemplate.AddMsgTemplate(l.ctx, &request.RequestAddMsgTemplate{
ChatType: "single",
ExternalUserID: req.ExternalUserIds,
Text: &request.TextOfMessage{
Content: req.Text.Content,
},
})
if err != nil {
return err
}
if result.ErrCode != 0 {
return fmt.Errorf("errcode: %d, errmsg: %s", result.ErrCode, result.ErrMsg)
}
return nil
}
Loading

0 comments on commit 59adc14

Please sign in to comment.