From 5343539efe381e1c45504343217669ebdbc9ccc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E4=B8=AB=E8=AE=B2=E6=A2=B5?= Date: Sun, 12 Nov 2023 13:59:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=97=B6=E6=8F=90=E4=BA=A4=E9=BB=98=E8=AE=A4=E5=88=86=E7=BB=84?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#276)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/user_logic.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/logic/user_logic.go b/logic/user_logic.go index 1fcdea5..1e3f55e 100644 --- a/logic/user_logic.go +++ b/logic/user_logic.go @@ -2,6 +2,7 @@ package logic import ( "fmt" + "strings" "github.com/eryajf/go-ldap-admin/config" "github.com/eryajf/go-ldap-admin/model" @@ -216,6 +217,24 @@ func (l UserLogic) Update(c *gin.Context, req interface{}) (data interface{}, rs return nil, tools.NewMySqlError(err) } + var ( + depts string + deptids []uint + ) + if strings.Contains(r.Departments, "请选择部门信息") { + for _, v := range strings.Split(r.Departments, ",") { + if v != "请选择部门信息" { + depts += v + "," + } + } + for _, j := range r.DepartmentId { + if j != 0 { + deptids = append(deptids, j) + } + } + } + // fmt.Println(depts, deptids) + // 拼装新的用户信息 user := model.User{ Model: oldData.Model, @@ -227,11 +246,11 @@ func (l UserLogic) Update(c *gin.Context, req interface{}) (data interface{}, rs Mobile: r.Mobile, Avatar: r.Avatar, PostalAddress: r.PostalAddress, - Departments: r.Departments, + Departments: depts, Position: r.Position, Introduction: r.Introduction, Creator: ctxUser.Username, - DepartmentId: tools.SliceToString(r.DepartmentId, ","), + DepartmentId: tools.SliceToString(deptids, ","), Source: oldData.Source, Roles: roles, UserDN: oldData.UserDN,