From 8c895f3114557ae50a0473cbe2f1f5ff0f284268 Mon Sep 17 00:00:00 2001 From: dchaofei Date: Thu, 17 Jan 2019 10:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A7=92=E8=89=B2=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=90=8D=E7=A7=B0=E4=B8=8D=E8=83=BD=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/user_group/user_group.go | 6 ++++++ module/user/group.go | 7 +++++++ service/user/group.go | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/model/user_group/user_group.go b/model/user_group/user_group.go index 48da243..abbde98 100644 --- a/model/user_group/user_group.go +++ b/model/user_group/user_group.go @@ -60,3 +60,9 @@ func Delete(id int) bool { ok := model.DeleteByPk(TableName, UserGroup{ID: id}) return ok } + +func GetOne(query model.QueryParam) (UserGroup, bool) { + var data UserGroup + ok := model.GetOne(TableName, &data, query) + return data, ok +} \ No newline at end of file diff --git a/module/user/group.go b/module/user/group.go index 53a0e13..31d25ba 100644 --- a/module/user/group.go +++ b/module/user/group.go @@ -33,6 +33,13 @@ func groupUpdate(c *goweb.Context, id int) error { Name: name, Priv: gostring.StrSlice2IntSlice(gostring.StrFilterSliceEmpty(priv)), } + exists, err := userGroup.CheckGroupExists() + if err != nil { + return syncd.RenderAppError(err.Error()) + } + if exists { + return syncd.RenderCustomerError(syncd.CODE_ERR_DATA_REPEAT, "group exists") + } if err := userGroup.CreateOrUpdate(); err != nil { return syncd.RenderAppError(err.Error()) } diff --git a/service/user/group.go b/service/user/group.go index d4bfb5f..f709f20 100644 --- a/service/user/group.go +++ b/service/user/group.go @@ -173,3 +173,27 @@ func (g *Group) GetNameByIds(ids []int) (map[int]string, error){ } return groupNameList, nil } + +func (g *Group) CheckGroupExists() (bool, error){ + var where []baseModel.WhereParam + if g.Name != "" { + where = append(where, baseModel.WhereParam{ + Field: "name", + Prepare: g.Name, + }) + } + if g.ID > 0 { + where = append(where, baseModel.WhereParam{ + Field: "id", + Tag: "!=", + Prepare: g.ID, + }) + } + detail, ok := userGroupModel.GetOne(baseModel.QueryParam{ + Where: where, + }) + if !ok { + return false, errors.New("get group one data failed") + } + return detail.ID > 0, nil +} \ No newline at end of file