56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
|
package permissionservicelogic
|
||
|
|
||
|
import (
|
||
|
"ark-permission/internal/domain"
|
||
|
ers "code.30cm.net/wanderland/library-go/errors"
|
||
|
"context"
|
||
|
|
||
|
"ark-permission/gen_result/pb/permission"
|
||
|
"ark-permission/internal/svc"
|
||
|
|
||
|
"github.com/zeromicro/go-zero/core/logx"
|
||
|
)
|
||
|
|
||
|
type ListPermissionStatusLogic struct {
|
||
|
ctx context.Context
|
||
|
svcCtx *svc.ServiceContext
|
||
|
logx.Logger
|
||
|
}
|
||
|
|
||
|
func NewListPermissionStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListPermissionStatusLogic {
|
||
|
return &ListPermissionStatusLogic{
|
||
|
ctx: ctx,
|
||
|
svcCtx: svcCtx,
|
||
|
Logger: logx.WithContext(ctx),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ListPermissionStatus 取得
|
||
|
func (l *ListPermissionStatusLogic) ListPermissionStatus(in *permission.NoneReq) (*permission.ListPermissionStatusResp, error) {
|
||
|
// 搜尋所有權限
|
||
|
permissions, err := l.svcCtx.Permission.FindAllOpenPermission(l.ctx)
|
||
|
if err != nil {
|
||
|
return nil, ers.DBError(err.Error())
|
||
|
}
|
||
|
|
||
|
exist := make(map[string]struct{})
|
||
|
status := make([]*permission.PermissionStatusItem, 0, len(permissions))
|
||
|
for _, v := range permissions {
|
||
|
if _, ok := exist[v.Name]; !ok {
|
||
|
t, _ := domain.ToPermissionTypeCode(v.Type)
|
||
|
status = append(status, &permission.PermissionStatusItem{
|
||
|
Id: v.Id, // 權限 ID
|
||
|
ParentId: v.Parent.Int64, // 上級權限的ID
|
||
|
Name: v.Name, // 權限名稱
|
||
|
Status: permission.PermissionStatus(v.Status), // 權限開啟或關閉,判斷時上級權限如果關閉,下級也應該關閉對此人關閉 // TODO 還沒做到,目前忠實呈現
|
||
|
Type: t.ToString(), // 前台權限,還是後台權限,還是其他中台之類的
|
||
|
})
|
||
|
exist[v.Name] = struct{}{}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return &permission.ListPermissionStatusResp{
|
||
|
Data: status,
|
||
|
}, nil
|
||
|
}
|