fix: 设备组详情补充 auth_type/device_type 字段,统一用户名显示
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 8m15s
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 8m15s
- FamilyMemberItem 新增 auth_type、device_type 字段 - FamilySummary 新增 owner_auth_type 字段 - findUserIdentifiers 返回 identifierInfo(含 auth_type) - 新增 parseDeviceType() 从 UserAgent 解析设备类型 Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
parent
4a2501a3d1
commit
e5c8e965af
@ -567,6 +567,7 @@ type (
|
|||||||
FamilyId int64 `json:"family_id"`
|
FamilyId int64 `json:"family_id"`
|
||||||
OwnerUserId int64 `json:"owner_user_id"`
|
OwnerUserId int64 `json:"owner_user_id"`
|
||||||
OwnerIdentifier string `json:"owner_identifier"`
|
OwnerIdentifier string `json:"owner_identifier"`
|
||||||
|
OwnerAuthType string `json:"owner_auth_type"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
ActiveMemberCount int64 `json:"active_member_count"`
|
ActiveMemberCount int64 `json:"active_member_count"`
|
||||||
MaxMembers int64 `json:"max_members"`
|
MaxMembers int64 `json:"max_members"`
|
||||||
@ -576,7 +577,9 @@ type (
|
|||||||
FamilyMemberItem {
|
FamilyMemberItem {
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
Identifier string `json:"identifier"`
|
Identifier string `json:"identifier"`
|
||||||
|
AuthType string `json:"auth_type"`
|
||||||
DeviceNo string `json:"device_no"`
|
DeviceNo string `json:"device_no"`
|
||||||
|
DeviceType string `json:"device_type"`
|
||||||
Role uint8 `json:"role"`
|
Role uint8 `json:"role"`
|
||||||
RoleName string `json:"role_name"`
|
RoleName string `json:"role_name"`
|
||||||
Status uint8 `json:"status"`
|
Status uint8 `json:"status"`
|
||||||
|
|||||||
@ -53,8 +53,13 @@ func normalizeFamilyStatusInput(status string) (uint8, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func findUserIdentifiers(ctx context.Context, db *gorm.DB, userIDs []int64) (map[int64]string, error) {
|
type identifierInfo struct {
|
||||||
identifierMap := make(map[int64]string)
|
Identifier string
|
||||||
|
AuthType string
|
||||||
|
}
|
||||||
|
|
||||||
|
func findUserIdentifiers(ctx context.Context, db *gorm.DB, userIDs []int64) (map[int64]identifierInfo, error) {
|
||||||
|
identifierMap := make(map[int64]identifierInfo)
|
||||||
if len(userIDs) == 0 {
|
if len(userIDs) == 0 {
|
||||||
return identifierMap, nil
|
return identifierMap, nil
|
||||||
}
|
}
|
||||||
@ -92,8 +97,31 @@ func findUserIdentifiers(ctx context.Context, db *gorm.DB, userIDs []int64) (map
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
selectedPriority[row.UserId] = currentPriority
|
selectedPriority[row.UserId] = currentPriority
|
||||||
identifierMap[row.UserId] = row.AuthIdentifier
|
identifierMap[row.UserId] = identifierInfo{
|
||||||
|
Identifier: row.AuthIdentifier,
|
||||||
|
AuthType: row.AuthType,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return identifierMap, nil
|
return identifierMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseDeviceType(userAgent string) string {
|
||||||
|
ua := strings.ToLower(userAgent)
|
||||||
|
switch {
|
||||||
|
case strings.Contains(ua, "iphone"):
|
||||||
|
return "iPhone"
|
||||||
|
case strings.Contains(ua, "ipad"):
|
||||||
|
return "iPad"
|
||||||
|
case strings.Contains(ua, "android"):
|
||||||
|
return "Android"
|
||||||
|
case strings.Contains(ua, "windows"):
|
||||||
|
return "Windows"
|
||||||
|
case strings.Contains(ua, "macintosh"), strings.Contains(ua, "mac os"):
|
||||||
|
return "Mac"
|
||||||
|
case strings.Contains(ua, "linux"):
|
||||||
|
return "Linux"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -63,18 +63,22 @@ func (l *GetFamilyDetailLogic) GetFamilyDetail(req *types.GetFamilyDetailRequest
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query family member identifiers failed")
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query family member identifiers failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查出所有成员的设备,构建 userId → deviceNo 映射
|
// 查出所有成员的设备,构建 userId → deviceNo 映射 + deviceType 映射
|
||||||
deviceNoMap := make(map[int64]string)
|
deviceNoMap := make(map[int64]string)
|
||||||
|
deviceTypeMap := make(map[int64]string)
|
||||||
devices, _, _ := l.svcCtx.UserModel.QueryDeviceListByUserIds(l.ctx, userIDs)
|
devices, _, _ := l.svcCtx.UserModel.QueryDeviceListByUserIds(l.ctx, userIDs)
|
||||||
for _, d := range devices {
|
for _, d := range devices {
|
||||||
if _, exists := deviceNoMap[d.UserId]; !exists {
|
if _, exists := deviceNoMap[d.UserId]; !exists {
|
||||||
deviceNoMap[d.UserId] = tool.DeviceIdToHash(d.Id)
|
deviceNoMap[d.UserId] = tool.DeviceIdToHash(d.Id)
|
||||||
|
deviceTypeMap[d.UserId] = parseDeviceType(d.UserAgent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memberItems := make([]types.FamilyMemberItem, 0, len(members))
|
memberItems := make([]types.FamilyMemberItem, 0, len(members))
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
identifier := identifierMap[member.UserId]
|
info := identifierMap[member.UserId]
|
||||||
|
identifier := info.Identifier
|
||||||
|
authType := info.AuthType
|
||||||
if identifier == "" {
|
if identifier == "" {
|
||||||
identifier = strconv.FormatInt(member.UserId, 10)
|
identifier = strconv.FormatInt(member.UserId, 10)
|
||||||
}
|
}
|
||||||
@ -82,7 +86,9 @@ func (l *GetFamilyDetailLogic) GetFamilyDetail(req *types.GetFamilyDetailRequest
|
|||||||
memberItem := types.FamilyMemberItem{
|
memberItem := types.FamilyMemberItem{
|
||||||
UserId: member.UserId,
|
UserId: member.UserId,
|
||||||
Identifier: identifier,
|
Identifier: identifier,
|
||||||
DeviceNo : deviceNoMap[member.UserId],
|
AuthType: authType,
|
||||||
|
DeviceNo: deviceNoMap[member.UserId],
|
||||||
|
DeviceType: deviceTypeMap[member.UserId],
|
||||||
Role: member.Role,
|
Role: member.Role,
|
||||||
RoleName: mapFamilyRoleName(member.Role),
|
RoleName: mapFamilyRoleName(member.Role),
|
||||||
Status: member.Status,
|
Status: member.Status,
|
||||||
@ -96,7 +102,9 @@ func (l *GetFamilyDetailLogic) GetFamilyDetail(req *types.GetFamilyDetailRequest
|
|||||||
memberItems = append(memberItems, memberItem)
|
memberItems = append(memberItems, memberItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
ownerIdentifier := identifierMap[family.OwnerUserId]
|
ownerInfo := identifierMap[family.OwnerUserId]
|
||||||
|
ownerIdentifier := ownerInfo.Identifier
|
||||||
|
ownerAuthType := ownerInfo.AuthType
|
||||||
if ownerIdentifier == "" {
|
if ownerIdentifier == "" {
|
||||||
ownerIdentifier = strconv.FormatInt(family.OwnerUserId, 10)
|
ownerIdentifier = strconv.FormatInt(family.OwnerUserId, 10)
|
||||||
}
|
}
|
||||||
@ -106,6 +114,7 @@ func (l *GetFamilyDetailLogic) GetFamilyDetail(req *types.GetFamilyDetailRequest
|
|||||||
FamilyId: family.Id,
|
FamilyId: family.Id,
|
||||||
OwnerUserId: family.OwnerUserId,
|
OwnerUserId: family.OwnerUserId,
|
||||||
OwnerIdentifier: ownerIdentifier,
|
OwnerIdentifier: ownerIdentifier,
|
||||||
|
OwnerAuthType: ownerAuthType,
|
||||||
Status: mapFamilyStatus(family.Status),
|
Status: mapFamilyStatus(family.Status),
|
||||||
ActiveMemberCount: activeMemberCount,
|
ActiveMemberCount: activeMemberCount,
|
||||||
MaxMembers: family.MaxMembers,
|
MaxMembers: family.MaxMembers,
|
||||||
|
|||||||
@ -123,7 +123,9 @@ func (l *GetFamilyListLogic) GetFamilyList(req *types.GetFamilyListRequest) (*ty
|
|||||||
|
|
||||||
list := make([]types.FamilySummary, 0, len(families))
|
list := make([]types.FamilySummary, 0, len(families))
|
||||||
for _, family := range families {
|
for _, family := range families {
|
||||||
ownerIdentifier := identifierMap[family.OwnerUserId]
|
ownerInfo := identifierMap[family.OwnerUserId]
|
||||||
|
ownerIdentifier := ownerInfo.Identifier
|
||||||
|
ownerAuthType := ownerInfo.AuthType
|
||||||
if ownerIdentifier == "" {
|
if ownerIdentifier == "" {
|
||||||
ownerIdentifier = strconv.FormatInt(family.OwnerUserId, 10)
|
ownerIdentifier = strconv.FormatInt(family.OwnerUserId, 10)
|
||||||
}
|
}
|
||||||
@ -132,6 +134,7 @@ func (l *GetFamilyListLogic) GetFamilyList(req *types.GetFamilyListRequest) (*ty
|
|||||||
FamilyId: family.Id,
|
FamilyId: family.Id,
|
||||||
OwnerUserId: family.OwnerUserId,
|
OwnerUserId: family.OwnerUserId,
|
||||||
OwnerIdentifier: ownerIdentifier,
|
OwnerIdentifier: ownerIdentifier,
|
||||||
|
OwnerAuthType: ownerAuthType,
|
||||||
Status: mapFamilyStatus(family.Status),
|
Status: mapFamilyStatus(family.Status),
|
||||||
ActiveMemberCount: countMap[family.Id],
|
ActiveMemberCount: countMap[family.Id],
|
||||||
MaxMembers: family.MaxMembers,
|
MaxMembers: family.MaxMembers,
|
||||||
|
|||||||
@ -715,7 +715,9 @@ type FamilyDetail struct {
|
|||||||
type FamilyMemberItem struct {
|
type FamilyMemberItem struct {
|
||||||
UserId int64 `json:"user_id"`
|
UserId int64 `json:"user_id"`
|
||||||
Identifier string `json:"identifier"`
|
Identifier string `json:"identifier"`
|
||||||
|
AuthType string `json:"auth_type"`
|
||||||
DeviceNo string `json:"device_no"`
|
DeviceNo string `json:"device_no"`
|
||||||
|
DeviceType string `json:"device_type"`
|
||||||
Role uint8 `json:"role"`
|
Role uint8 `json:"role"`
|
||||||
RoleName string `json:"role_name"`
|
RoleName string `json:"role_name"`
|
||||||
Status uint8 `json:"status"`
|
Status uint8 `json:"status"`
|
||||||
@ -729,6 +731,7 @@ type FamilySummary struct {
|
|||||||
FamilyId int64 `json:"family_id"`
|
FamilyId int64 `json:"family_id"`
|
||||||
OwnerUserId int64 `json:"owner_user_id"`
|
OwnerUserId int64 `json:"owner_user_id"`
|
||||||
OwnerIdentifier string `json:"owner_identifier"`
|
OwnerIdentifier string `json:"owner_identifier"`
|
||||||
|
OwnerAuthType string `json:"owner_auth_type"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
ActiveMemberCount int64 `json:"active_member_count"`
|
ActiveMemberCount int64 `json:"active_member_count"`
|
||||||
MaxMembers int64 `json:"max_members"`
|
MaxMembers int64 `json:"max_members"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user