test
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/admin"
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/internal/svc"
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type RoleNamesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewRoleNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleNamesLogic {
|
||||
return &RoleNamesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *RoleNamesLogic) RoleNames(in *admin.RoleNameRequest) (*admin.Response, error) {
|
||||
var services []dao.ServicesNames
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{"status": utils.StringStatusOk},
|
||||
}
|
||||
err := model.ServicesModel{}.Init().Items(w, &services)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
|
||||
var items []dao.RoleServiceNameItems
|
||||
var roles []dao.Role
|
||||
modelObj := model.RoleModel{}.Init()
|
||||
w = modelbase.Params{
|
||||
Eq: map[string]string{"status": utils.StringStatusOk},
|
||||
}
|
||||
w.Like = make(map[string]string)
|
||||
if len(in.Name) > utils.NumberZero {
|
||||
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
|
||||
}
|
||||
err = modelObj.Items(w, &roles)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
tmp := map[int64][]dao.RoleNameItems{}
|
||||
for _, item := range roles {
|
||||
tmp[item.ServiceId] = append(tmp[item.ServiceId], dao.RoleNameItems{
|
||||
Name: item.Name,
|
||||
Id: item.Id,
|
||||
})
|
||||
}
|
||||
for _, pro := range services {
|
||||
if _, ok := tmp[pro.Id]; ok {
|
||||
items = append(items, dao.RoleServiceNameItems{
|
||||
Id: pro.Id,
|
||||
Name: pro.Name,
|
||||
Items: tmp[pro.Id],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return l.ok(items), nil
|
||||
}
|
||||
Reference in New Issue
Block a user