This commit is contained in:
laodaming
2023-11-10 15:24:25 +08:00
parent 360c19a8f5
commit d6a25673bc
33 changed files with 394 additions and 106 deletions

View File

@@ -17,11 +17,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/feishu/webhook",
Handler: WebhookHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/feishu/sync_feishu_departments",
Handler: SyncFeiShuGroupsHandler(serverCtx),
},
},
)
}

View File

@@ -1,35 +0,0 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/feishu-sync/internal/logic"
"fusenapi/server/feishu-sync/internal/svc"
"fusenapi/server/feishu-sync/internal/types"
)
func SyncFeiShuGroupsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.Request
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewSyncFeiShuGroupsLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.SyncFeiShuGroups(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -1,39 +0,0 @@
package logic
import (
"context"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/server/feishu-sync/internal/svc"
"fusenapi/server/feishu-sync/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SyncFeiShuGroupsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSyncFeiShuGroupsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SyncFeiShuGroupsLogic {
return &SyncFeiShuGroupsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *SyncFeiShuGroupsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *SyncFeiShuGroupsLogic) SyncFeiShuGroups(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
return resp.SetStatus(basic.CodeOK)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *SyncFeiShuGroupsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -1,5 +1,13 @@
package logic
import (
"encoding/json"
"fusenapi/model/gmodel"
"strconv"
"strings"
"time"
)
type UserWebhookMsg struct {
Schema string `json:"schema"`
Header struct {
@@ -76,12 +84,10 @@ type UserWebhookMsg struct {
// 员工增删改信息
func (l *WebhookLogic) OnUserChange(data []byte) error {
return nil
/*var msg UserWebhookMsg
var msg UserWebhookMsg
if err := json.Unmarshal(data, &msg); err != nil {
return err
}
avatar, _ := json.Marshal(msg.Event.Object.Avatar)
isFrozen := int64(0)
if msg.Event.Object.Status.IsFrozen {
isFrozen = 1
@@ -102,14 +108,16 @@ func (l *WebhookLogic) OnUserChange(data []byte) error {
if msg.Event.Object.Status.IsUnjoin {
isUnjoin = 1
}
departmentIds, _ := json.Marshal(msg.Event.Object.DepartmentIds)
orders, _ := json.Marshal(msg.Event.Object.Orders)
feiShuMsgCreateTimeInt64, err := strconv.ParseInt(msg.Header.CreateTime, 10, 64)
if err != nil {
return err
}
feiShuMsgCreateTime := time.UnixMilli(feiShuMsgCreateTimeInt64)
return l.svcCtx.AllModels.FsFeishuUser.CreateOrUpdate(l.ctx, msg.Header.AppId, msg.Event.Object.OpenId, &gmodel.FsFeishuUser{
departmentIds := strings.Join(msg.Event.Object.DepartmentIds, ",")
joinTime := time.Unix(msg.Event.Object.Joint64ime, 0)
source := int64(1)
return l.svcCtx.AllModels.LdapUsers.CreateOrUpdate(l.ctx, msg.Header.AppId, msg.Event.Object.OpenId, &gmodel.LdapUsers{
Source: &source,
AppId: &msg.Header.AppId,
OpenId: &msg.Event.Object.OpenId,
UnionId: &msg.Event.Object.UnionId,
@@ -121,18 +129,18 @@ func (l *WebhookLogic) OnUserChange(data []byte) error {
JobTitle: &msg.Event.Object.JobTitle,
Mobile: &msg.Event.Object.Mobile,
Gender: &msg.Event.Object.Gender,
Avatar: &avatar,
Avatar: &msg.Event.Object.Avatar.AvatarOrigin,
IsFrozen: &isFrozen,
IsResigned: &isResigned,
IsActivated: &isActivated,
IsExited: &isExited,
IsUnjoin: &isUnjoin,
DepartmentIds: &departmentIds,
Departmentids: &departmentIds,
WorkStation: &msg.Event.Object.WorkStation,
EmployeeNo: &msg.Event.Object.EmployeeNo,
EmployeeType: &msg.Event.Object.EmployeeType,
Orders: &orders,
JoinTime: &joinTime,
Ctime: &feiShuMsgCreateTime,
Utime: &feiShuMsgCreateTime,
})*/
})
}

View File

@@ -35,7 +35,7 @@ func (l *DeleteCartLogic) DeleteCart(req *types.DeleteCartReq, userinfo *auth.Us
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please sign in")
}
//删除购物车
if err := l.svcCtx.AllModels.FsShoppingCart.Delete(l.ctx, userinfo.UserId, req.Id); err != nil {
if err := l.svcCtx.AllModels.FsShoppingCart.Delete(l.ctx, userinfo.UserId, req.IdList); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to delete shopping cart")
}

View File

@@ -35,7 +35,7 @@ type DiyInfo struct {
}
type DeleteCartReq struct {
Id int64 `json:"id"` //购物车id
IdList []int64 `json:"id"` //购物车id
}
type GetCartsReq struct {