v2
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
@@ -27,36 +26,25 @@ func GetSysRole(ctx context.Context, id int32) (*db.SysRole, error) {
|
||||
|
||||
func ListSysRoleCondition(ctx context.Context, q dto.SearchDto) ([]*db.SysRole, int64, error) {
|
||||
countArg := &db.CountSysRoleConditionParams{
|
||||
IsStatus: q.SearchStatus != 9999,
|
||||
Status: int32(q.SearchStatus),
|
||||
IsParentID: q.SearchParentID != 0,
|
||||
ParentID: int32(q.SearchParentID),
|
||||
IsStatus: q.SearchStatus != 9999,
|
||||
Status: int32(q.SearchStatus),
|
||||
IsID: q.SearchID != 0,
|
||||
ID: int32(q.SearchID),
|
||||
IsParentID: q.SearchParentID != 0,
|
||||
ParentID: int32(q.SearchParentID),
|
||||
DisplayName: q.SearchName,
|
||||
}
|
||||
|
||||
dataArg := &db.ListSysRoleConditionParams{
|
||||
IsStatus: q.SearchStatus != 9999,
|
||||
Status: int32(q.SearchStatus),
|
||||
IsParentID: q.SearchParentID != 0,
|
||||
ParentID: int32(q.SearchParentID),
|
||||
Skip: (int32(q.Page) - 1) * int32(q.Rows),
|
||||
Size: int32(q.Rows),
|
||||
}
|
||||
|
||||
if len(q.SearchKey) > 0 {
|
||||
switch strings.ToLower(q.SearchName) {
|
||||
case "id":
|
||||
id, err := strconv.Atoi(q.SearchKey)
|
||||
if err == nil {
|
||||
countArg.IsID = true
|
||||
countArg.ID = int32(id)
|
||||
|
||||
dataArg.IsID = true
|
||||
dataArg.ID = int32(id)
|
||||
}
|
||||
case "name":
|
||||
countArg.DisplayName = q.SearchKey
|
||||
dataArg.DisplayName = q.SearchKey
|
||||
}
|
||||
IsStatus: q.SearchStatus != 9999,
|
||||
Status: int32(q.SearchStatus),
|
||||
IsID: q.SearchID != 0,
|
||||
ID: int32(q.SearchID),
|
||||
IsParentID: q.SearchParentID != 0,
|
||||
ParentID: int32(q.SearchParentID),
|
||||
DisplayName: q.SearchName,
|
||||
Skip: (int32(q.Page) - 1) * int32(q.Rows),
|
||||
Size: int32(q.Rows),
|
||||
}
|
||||
count, err := db.Engine.CountSysRoleCondition(ctx, countArg)
|
||||
if err != nil {
|
||||
@@ -71,18 +59,29 @@ func ListSysRoleCondition(ctx context.Context, q dto.SearchDto) ([]*db.SysRole,
|
||||
return roles, count, nil
|
||||
}
|
||||
|
||||
func XmSelectSysRole(ctx context.Context) ([]*dto.XmSelectDto, error) {
|
||||
func XmSelectSysRole(ctx context.Context, id int32) ([]*dto.XmSelectTreeDto, error) {
|
||||
all, err := db.Engine.AllSysRole(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res []*dto.XmSelectDto
|
||||
for _, item := range all {
|
||||
res = append(res, &dto.XmSelectDto{Name: item.DisplayName, Value: int(item.ID)})
|
||||
return toXmSelectTree(id, all), nil
|
||||
}
|
||||
|
||||
func toXmSelectTree(parentId int32, data []*db.SysRole) []*dto.XmSelectTreeDto {
|
||||
var res []*dto.XmSelectTreeDto
|
||||
for _, v := range data {
|
||||
if v.ParentID == parentId {
|
||||
item := dto.XmSelectTreeDto{
|
||||
Name: v.Name,
|
||||
Value: strconv.FormatInt(int64(v.ID), 10),
|
||||
Children: toXmSelectTree(v.ID, data),
|
||||
}
|
||||
res = append(res, &item)
|
||||
}
|
||||
}
|
||||
|
||||
return res, nil
|
||||
return res
|
||||
}
|
||||
|
||||
func SetMenu(ctx context.Context, roleID int32, menus []*db.SysMenu) error {
|
||||
|
||||
Reference in New Issue
Block a user