MCPcopy Create free account
hub / github.com/53AI/53AIHub / BatchAddInternalUsers

Method BatchAddInternalUsers

api/service/user_service.go:81–229  ·  view source on GitHub ↗

BatchAddInternalUsers batch add internal users

(eid int64, users []InternalUserInfo)

Source from the content-addressed store, hash-verified

79
80// BatchAddInternalUsers batch add internal users
81func (s *UserService) BatchAddInternalUsers(eid int64, users []InternalUserInfo) (*BatchAddInternalUserResult, error) {
82 // Begin transaction
83 // 去重收集需要在提交后关联的平台账号(仅手机号)
84 accountsToLink := make(map[string]struct{})
85
86 tx := model.DB.Begin()
87 if tx.Error != nil {
88 return nil, tx.Error
89 }
90
91 result := &BatchAddInternalUserResult{
92 Success: []BatchAddUserResult{},
93 Failed: []BatchAddUserResult{},
94 }
95
96 // Process each user
97 for _, userInfo := range users {
98 username := userInfo.Username
99
100 // Validate username format
101 isEmail := helper.IsValidEmail(username)
102 isMobile := helper.IsValidPhone(username)
103
104 if !isEmail && !isMobile {
105 result.Failed = append(result.Failed, BatchAddUserResult{
106 Username: username,
107 Message: "invalid username",
108 })
109 continue
110 }
111
112 // Create user object
113 user := model.User{
114 Username: username,
115 Nickname: userInfo.Nickname,
116 Password: userInfo.Password,
117 Eid: eid,
118 GroupId: 0,
119 Type: model.UserTypeInternal,
120 Role: model.RoleCommonUser,
121 }
122
123 // Set email or mobile
124 if isMobile {
125 user.Mobile = username
126 }
127 if isEmail {
128 user.Email = username
129 }
130
131 // Validate user struct
132 if err := common.Validate.Struct(&user); err != nil {
133 result.Failed = append(result.Failed, BatchAddUserResult{
134 Username: username,
135 Message: err.Error(),
136 })
137 continue
138 }

Callers 1

BatchAddInternalUsersFunction · 0.95

Calls 8

checkExistingUserMethod · 0.95
createMemberBindingMethod · 0.95
postLinkPlatformAccountsFunction · 0.70
UpdateMethod · 0.65
ErrorMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected