From 6462231c8619f7b8e7befa4e9f82fbe79400f113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 22 Jan 2021 16:50:08 +0800 Subject: [PATCH] aa --- business/jxstore/cms/permission.go | 30 ++++++++++++++++++++++++++++-- business/model/dao/place.go | 14 ++++++++++++++ controllers/permission.go | 3 ++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/permission.go b/business/jxstore/cms/permission.go index 2ee6a3591..29f10e803 100644 --- a/business/jxstore/cms/permission.go +++ b/business/jxstore/cms/permission.go @@ -82,8 +82,34 @@ func UpdateMenu(ctx *jxcontext.Context, menuID int, payload map[string]interface return num, err } -func GetRole(ctx *jxcontext.Context) (roles []*model.Role, err error) { - return dao.GetRole(dao.GetDB(), "", "") +type GetRoleResult struct { + Role *model.Role + CityInfo []*model.Place `json:"cityInfo"` + Stores []*model.Store `json:"storeInfo"` +} + +func GetRole(ctx *jxcontext.Context, name string) (getRoleResults []*GetRoleResult, err error) { + var ( + db = dao.GetDB() + ) + roles, err := dao.GetRole(db, name, "") + for _, v := range roles { + getRoleResult := &GetRoleResult{ + Role: v, + } + if v.CityCodes != "" { + if cityInfos, err := dao.GetPlaces(db, jxutils.StrListToIntList(strings.Split(v.CityCodes, ","))); err == nil { + getRoleResult.CityInfo = cityInfos + } + } + if v.StoreIDs != "" { + if stores, err := dao.GetStoreList(db, jxutils.StrListToIntList(strings.Split(v.StoreIDs, ",")), nil, nil, nil, nil, ""); err == nil { + getRoleResult.Stores = stores + } + } + getRoleResults = append(getRoleResults, getRoleResult) + } + return getRoleResults, err } func AddRole(ctx *jxcontext.Context, name string) (err error) { diff --git a/business/model/dao/place.go b/business/model/dao/place.go index 45aef1449..0f0b468f6 100644 --- a/business/model/dao/place.go +++ b/business/model/dao/place.go @@ -85,3 +85,17 @@ func GetPlaceByJdsCode(db *DaoDB, jdsCode int) (place *model.Place, err error) { err = db.Db.Read(place, "JdsCode") return place, err } + +func GetPlaces(db *DaoDB, cityCodes []int) (places []*model.Place, err error) { + sql := ` + SELECT * + FROM place + WHERE 1 = 1 + ` + sqlParams := []interface{}{} + if len(cityCodes) > 0 { + sql += " AND city_code IN (" + GenQuestionMarks(len(cityCodes)) + ")" + sqlParams = append(sqlParams, cityCodes) + } + return places, err +} diff --git a/controllers/permission.go b/controllers/permission.go index ae749aa24..69534c6a4 100644 --- a/controllers/permission.go +++ b/controllers/permission.go @@ -79,12 +79,13 @@ func (c *PowerController) AddRole() { // @Title 查询角色 // @Description 查询角色 // @Param token header string true "认证token" +// @Param name query string false "角色名" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetRole [get] func (c *PowerController) GetRole() { c.callGetRole(func(params *tPowerGetRoleParams) (retVal interface{}, errCode string, err error) { - retVal, err = cms.GetRole(params.Ctx) + retVal, err = cms.GetRole(params.Ctx, params.Name) return retVal, "", err }) }