2023-11-07 10:29:13 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fusenapi/model/gmodel"
|
|
|
|
"strconv"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type UserWebhookMsg struct {
|
|
|
|
Schema string `json:"schema"`
|
|
|
|
Header struct {
|
|
|
|
EventId string `json:"event_id"`
|
|
|
|
EventType string `json:"event_type"`
|
|
|
|
CreateTime string `json:"create_time"`
|
|
|
|
Token string `json:"token"`
|
|
|
|
AppId string `json:"app_id"`
|
|
|
|
TenantKey string `json:"tenant_key"`
|
|
|
|
} `json:"header"`
|
|
|
|
Event struct {
|
|
|
|
Object struct {
|
|
|
|
OpenId string `json:"open_id"`
|
|
|
|
UnionId string `json:"union_id"`
|
|
|
|
UserId string `json:"user_id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
EnName string `json:"en_name"`
|
|
|
|
Nickname string `json:"nickname"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
EnterpriseEmail string `json:"enterprise_email"`
|
|
|
|
JobTitle string `json:"job_title"`
|
|
|
|
Mobile string `json:"mobile"`
|
|
|
|
Gender int64 `json:"gender"`
|
|
|
|
Avatar struct {
|
|
|
|
Avatar72 string `json:"avatar_72"`
|
|
|
|
Avatar240 string `json:"avatar_240"`
|
|
|
|
Avatar640 string `json:"avatar_640"`
|
|
|
|
AvatarOrigin string `json:"avatar_origin"`
|
|
|
|
} `json:"avatar"`
|
|
|
|
Status struct {
|
|
|
|
IsFrozen bool `json:"is_frozen"`
|
|
|
|
IsResigned bool `json:"is_resigned"`
|
|
|
|
IsActivated bool `json:"is_activated"`
|
|
|
|
IsExited bool `json:"is_exited"`
|
|
|
|
IsUnjoin bool `json:"is_unjoin"`
|
|
|
|
} `json:"status"`
|
|
|
|
DepartmentIds []string `json:"department_ids"`
|
|
|
|
LeaderUserId string `json:"leader_user_id"`
|
|
|
|
City string `json:"city"`
|
|
|
|
Country string `json:"country"`
|
|
|
|
WorkStation string `json:"work_station"`
|
|
|
|
Joint64ime int64 `json:"join_time"`
|
|
|
|
EmployeeNo string `json:"employee_no"`
|
|
|
|
EmployeeType int64 `json:"employee_type"`
|
|
|
|
Orders []struct {
|
|
|
|
DepartmentId string `json:"department_id"`
|
|
|
|
UserOrder int64 `json:"user_order"`
|
|
|
|
DepartmentOrder int64 `json:"department_order"`
|
|
|
|
IsPrimaryDept bool `json:"is_primary_dept"`
|
|
|
|
} `json:"orders"`
|
|
|
|
CustomAttrs []struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
Id string `json:"id"`
|
|
|
|
Value struct {
|
|
|
|
Text string `json:"text"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
PcUrl string `json:"pc_url"`
|
|
|
|
OptionId string `json:"option_id"`
|
|
|
|
OptionValue string `json:"option_value"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
PictureUrl string `json:"picture_url"`
|
|
|
|
GenericUser struct {
|
|
|
|
Id string `json:"id"`
|
|
|
|
Type int64 `json:"type"`
|
|
|
|
} `json:"generic_user"`
|
|
|
|
} `json:"value"`
|
|
|
|
} `json:"custom_attrs"`
|
|
|
|
JobLevelId string `json:"job_level_id"`
|
|
|
|
JobFamilyId string `json:"job_family_id"`
|
|
|
|
DottedLineLeaderUserIds []string `json:"dotted_line_leader_user_ids"`
|
|
|
|
} `json:"object"`
|
|
|
|
} `json:"event"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// 员工增删改信息
|
|
|
|
func (l *WebhookLogic) OnUserChange(data []byte) error {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
isResigned := int64(0)
|
|
|
|
if msg.Event.Object.Status.IsResigned {
|
|
|
|
isResigned = 1
|
|
|
|
}
|
|
|
|
isActivated := int64(0)
|
|
|
|
if msg.Event.Object.Status.IsActivated {
|
|
|
|
isActivated = 1
|
|
|
|
}
|
|
|
|
isExited := int64(0)
|
|
|
|
if msg.Event.Object.Status.IsExited {
|
|
|
|
isExited = 1
|
|
|
|
}
|
|
|
|
isUnjoin := int64(0)
|
|
|
|
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)
|
2023-11-07 10:40:24 +00:00
|
|
|
joinTime := time.Unix(msg.Event.Object.Joint64ime, 0)
|
2023-11-07 10:29:13 +00:00
|
|
|
return l.svcCtx.AllModels.FsFeishuUser.CreateOrUpdate(l.ctx, msg.Header.AppId, msg.Event.Object.OpenId, &gmodel.FsFeishuUser{
|
|
|
|
AppId: &msg.Header.AppId,
|
|
|
|
OpenId: &msg.Event.Object.OpenId,
|
|
|
|
UnionId: &msg.Event.Object.UnionId,
|
|
|
|
Name: &msg.Event.Object.Name,
|
|
|
|
EnName: &msg.Event.Object.EnName,
|
|
|
|
Nickname: &msg.Event.Object.Nickname,
|
|
|
|
Email: &msg.Event.Object.Email,
|
|
|
|
EnterpriseEmail: &msg.Event.Object.EnterpriseEmail,
|
|
|
|
JobTitle: &msg.Event.Object.JobTitle,
|
|
|
|
Mobile: &msg.Event.Object.Mobile,
|
|
|
|
Gender: &msg.Event.Object.Gender,
|
|
|
|
Avatar: &avatar,
|
|
|
|
IsFrozen: &isFrozen,
|
|
|
|
IsResigned: &isResigned,
|
|
|
|
IsActivated: &isActivated,
|
|
|
|
IsExited: &isExited,
|
|
|
|
IsUnjoin: &isUnjoin,
|
|
|
|
DepartmentIds: &departmentIds,
|
|
|
|
WorkStation: &msg.Event.Object.WorkStation,
|
|
|
|
EmployeeNo: &msg.Event.Object.EmployeeNo,
|
|
|
|
EmployeeType: &msg.Event.Object.EmployeeType,
|
|
|
|
Orders: &orders,
|
2023-11-07 10:40:24 +00:00
|
|
|
JoinTime: &joinTime,
|
2023-11-07 10:29:13 +00:00
|
|
|
Ctime: &feiShuMsgCreateTime,
|
|
|
|
Utime: &feiShuMsgCreateTime,
|
|
|
|
})
|
|
|
|
}
|