Skip to content

Commit 5343539

Browse files
authored
fix: 用户更新时提交默认分组的问题 (#276)
1 parent 2032322 commit 5343539

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

logic/user_logic.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package logic
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/eryajf/go-ldap-admin/config"
78
"github.com/eryajf/go-ldap-admin/model"
@@ -216,6 +217,24 @@ func (l UserLogic) Update(c *gin.Context, req interface{}) (data interface{}, rs
216217
return nil, tools.NewMySqlError(err)
217218
}
218219

220+
var (
221+
depts string
222+
deptids []uint
223+
)
224+
if strings.Contains(r.Departments, "请选择部门信息") {
225+
for _, v := range strings.Split(r.Departments, ",") {
226+
if v != "请选择部门信息" {
227+
depts += v + ","
228+
}
229+
}
230+
for _, j := range r.DepartmentId {
231+
if j != 0 {
232+
deptids = append(deptids, j)
233+
}
234+
}
235+
}
236+
// fmt.Println(depts, deptids)
237+
219238
// 拼装新的用户信息
220239
user := model.User{
221240
Model: oldData.Model,
@@ -227,11 +246,11 @@ func (l UserLogic) Update(c *gin.Context, req interface{}) (data interface{}, rs
227246
Mobile: r.Mobile,
228247
Avatar: r.Avatar,
229248
PostalAddress: r.PostalAddress,
230-
Departments: r.Departments,
249+
Departments: depts,
231250
Position: r.Position,
232251
Introduction: r.Introduction,
233252
Creator: ctxUser.Username,
234-
DepartmentId: tools.SliceToString(r.DepartmentId, ","),
253+
DepartmentId: tools.SliceToString(deptids, ","),
235254
Source: oldData.Source,
236255
Roles: roles,
237256
UserDN: oldData.UserDN,

0 commit comments

Comments
 (0)