From c967a5c8f093fbbcdeef547351b605d57e06d109 Mon Sep 17 00:00:00 2001 From: maxbad <26058031@qq.com> Date: Wed, 17 May 2023 22:43:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=80=E4=BA=9B=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E5=B0=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/internal/logic/admin/dept.go | 44 ++++++++++++++++++++++- server/internal/logic/sys/log.go | 2 +- web/src/components/Form/src/BasicForm.vue | 16 ++++----- web/src/views/org/dept/dept.vue | 4 +-- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/server/internal/logic/admin/dept.go b/server/internal/logic/admin/dept.go index 1fa89e7..c769c4d 100644 --- a/server/internal/logic/admin/dept.go +++ b/server/internal/logic/admin/dept.go @@ -7,6 +7,8 @@ package admin import ( "context" + "fmt" + "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/errors/gerror" "github.com/gogf/gf/v2/os/gtime" "hotgo/internal/consts" @@ -91,7 +93,26 @@ func (s *sAdminDept) Edit(ctx context.Context, in adminin.DeptEditInp) (err erro // 修改 if in.Id > 0 { - _, err = dao.AdminDept.Ctx(ctx).Where("id", in.Id).Data(in).Update() + + // 获取父级tree + var pTree gdb.Value + pTree, err = dao.AdminDept.Ctx(ctx).Where("id", in.Pid).Fields("tree").Value() + if err != nil { + return + } + in.Tree = fmt.Sprintf("%str_%v ", pTree.String(), in.Id) + + err = dao.AdminDept.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error { + // 更新数据 + _, err = dao.AdminDept.Ctx(ctx).Where("id", in.Id).Data(in).Update() + if err != nil { + return err + } + + // 如果当前部门有子级,更新子级tree关系树 + return updateChildrenTree(ctx, in.Id, in.Level, in.Tree) + }) + return } @@ -100,6 +121,27 @@ func (s *sAdminDept) Edit(ctx context.Context, in adminin.DeptEditInp) (err erro return } +func updateChildrenTree(ctx context.Context, _id int64, _level int, _tree string) (err error) { + var list []*entity.AdminDept + err = dao.AdminDept.Ctx(ctx).Where("pid", _id).Scan(&list) + if err != nil { + return + } + for _, child := range list { + child.Level = _level + 1 + child.Tree = fmt.Sprintf("%str_%v ", _tree, child.Id) + _, err = dao.AdminDept.Ctx(ctx).Where("id", child.Id).Data("level", child.Level, "tree", child.Tree).Update() + if err != nil { + return err + } + err = updateChildrenTree(ctx, child.Id, child.Level, child.Tree) + if err != nil { + return + } + } + return +} + // Status 更新部门状态 func (s *sAdminDept) Status(ctx context.Context, in adminin.DeptStatusInp) (err error) { if in.Id <= 0 { diff --git a/server/internal/logic/sys/log.go b/server/internal/logic/sys/log.go index 0dec417..2ee953b 100644 --- a/server/internal/logic/sys/log.go +++ b/server/internal/logic/sys/log.go @@ -197,7 +197,7 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog { ipData, err := location.GetLocation(ctx, clientIp) if err != nil { - g.Log().Debugf(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err) + g.Log().Stdout(false).Debugf(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err) } if ipData == nil { diff --git a/web/src/components/Form/src/BasicForm.vue b/web/src/components/Form/src/BasicForm.vue index 9c0b9c1..5533228 100644 --- a/web/src/components/Form/src/BasicForm.vue +++ b/web/src/components/Form/src/BasicForm.vue @@ -43,15 +43,13 @@ diff --git a/web/src/views/org/dept/dept.vue b/web/src/views/org/dept/dept.vue index ce39784..84324f4 100644 --- a/web/src/views/org/dept/dept.vue +++ b/web/src/views/org/dept/dept.vue @@ -196,7 +196,7 @@ createdAt: string; status: number; name: string; - index: string; + id: number; children?: RowData[]; }; const data = ref([]); @@ -318,7 +318,7 @@ }, ]; - const rowKey = (row: RowData) => row.index; + const rowKey = (row: RowData) => row.id; function addTable() { showModal.value = true;