权限,列表,详情
This commit is contained in:
@@ -42,7 +42,7 @@ func (l *AdminInfoLogic) AdminInfo(in *admin.AdminInfoRequest) (*admin.Response,
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
|
||||
return l.fail(utils.ErrorNotFund), nil
|
||||
}
|
||||
if info.Id > utils.NumberZero {
|
||||
mobile, dErr := utils.DecryptPhone(info.Phone)
|
||||
|
||||
@@ -96,7 +96,7 @@ func (l *AdminLoginLogic) setLogin(token, refresh string, data dao.JwtInfo) {
|
||||
redis.Client.Set(ctx, redisKey, userStr, expire).Result()
|
||||
|
||||
//获取原来的token与refresh
|
||||
redisKeysKey := utils.GetLoginKeysKey(utils.LoginTypeAdmin, strconv.FormatInt(data.Id, 10))
|
||||
redisKeysKey := utils.GetLoginKeysKey(utils.LoginTypeAdmin, strconv.FormatInt(data.Id, utils.NumberTen))
|
||||
var LoginInfo utils.LoginRedis
|
||||
oldAuth, oldErr := redis.Client.Get(ctx, redisKeysKey).Result()
|
||||
//如果获取到了数据情况之前的
|
||||
@@ -117,6 +117,6 @@ func (l *AdminLoginLogic) setLogin(token, refresh string, data dao.JwtInfo) {
|
||||
redis.Client.Set(ctx, redisKeysKey, newStr, refreshExpire).Result()
|
||||
//登录刷新信息写入redis
|
||||
refreshKey := utils.GetLoginRefreshKey(utils.LoginTypeAdmin, refresh)
|
||||
redis.Client.Set(ctx, refreshKey, strconv.FormatInt(data.Id, 10), refreshExpire).Result()
|
||||
redis.Client.Set(ctx, refreshKey, strconv.FormatInt(data.Id, utils.NumberTen), refreshExpire).Result()
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/validator"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type AuthorityInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewAuthorityInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorityInfoLogic {
|
||||
return &AuthorityInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AuthorityInfoLogic) AuthorityInfo(in *admin.InfoRequest) (*admin.Response, error) {
|
||||
var v validator.AuthorityInfoValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
info := dao.AuthorityInfo{}
|
||||
modelObj := model.AuthorityModel{}.Init()
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}}
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.ErrorNotFund), nil
|
||||
}
|
||||
new := dao.AuthorityInfoNew{
|
||||
AuthorityInfo: info,
|
||||
}
|
||||
if info.Type == dao.TypeData {
|
||||
var items []dao.AuthorityGetJsonIds
|
||||
w = modelbase.Params{Other: map[string]string{"FIND_IN_SET(?, data_ids)": strconv.FormatInt(info.Id, utils.NumberTen)}}
|
||||
err = modelObj.Items(w, &items)
|
||||
|
||||
if len(items) == utils.NumberThree {
|
||||
w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(items[utils.NumberZero].Id, utils.NumberTen)}}
|
||||
err = modelObj.GetOne(w, &info)
|
||||
new = dao.AuthorityInfoNew{
|
||||
AuthorityInfo: info,
|
||||
}
|
||||
new.JsonDataAll = items[utils.NumberZero].JsonTreeData
|
||||
new.JsonDataDepartment = items[utils.NumberOne].JsonTreeData
|
||||
new.JsonDataOneself = items[utils.NumberTwo].JsonTreeData
|
||||
}
|
||||
}
|
||||
|
||||
return l.ok(new), nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/validator"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type AuthorityItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewAuthorityItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorityItemsLogic {
|
||||
return &AuthorityItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AuthorityItemsLogic) AuthorityItems(in *admin.AuthorityItemsRequest) (*admin.Response, error) {
|
||||
var v validator.AuthorityItemsValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
modelObj := model.AuthorityModel{}.Init()
|
||||
w := modelbase.Params{
|
||||
Order: "level ASC, parent_id ASC, sort ASC",
|
||||
Eq: map[string]string{"service_id": strconv.FormatInt(in.ServiceId, utils.NumberTen)},
|
||||
}
|
||||
|
||||
var data []dao.Authority
|
||||
err := modelObj.Items(w, &data)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
items := l.getList(data, utils.NumberZero)
|
||||
l.processTreeNodes(items, utils.NumberOne)
|
||||
|
||||
return l.ok(items), nil
|
||||
}
|
||||
|
||||
func (l *AuthorityItemsLogic) processTreeNodes(nodes []*dao.AuthorityItems, level int) {
|
||||
// processTreeNodes 递归处理节点,添加IsFirst、IsLast和Level标识
|
||||
if len(nodes) == utils.NumberZero {
|
||||
return
|
||||
}
|
||||
|
||||
// 遍历当前层级的所有节点
|
||||
for i, node := range nodes {
|
||||
// 设置是否为第一个和最后一个节点
|
||||
node.IsFirst = i == utils.NumberZero
|
||||
node.IsLast = i == len(nodes)-utils.NumberOne
|
||||
|
||||
// 递归处理子节点,层级+1
|
||||
if len(node.Children) > utils.NumberZero {
|
||||
l.processTreeNodes(node.Children, level+utils.NumberOne)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取层级的下接数据 列表使用
|
||||
func (l *AuthorityItemsLogic) getList(data []dao.Authority, pid int64) []*dao.AuthorityItems {
|
||||
var dataArr []*dao.AuthorityItems
|
||||
for _, v := range data {
|
||||
if v.ParentId == pid {
|
||||
// 这里可以理解为每次都从最原始的数据里面找出相对就的ID进行匹配,直到找不到就返回
|
||||
children := l.getList(data, v.Id)
|
||||
node := dao.AuthorityItems{
|
||||
Id: v.Id,
|
||||
Name: v.Name,
|
||||
Sort: v.Sort,
|
||||
ParentId: v.ParentId,
|
||||
ParentIds: v.ParentIds,
|
||||
Description: v.Description,
|
||||
Status: v.Status,
|
||||
Level: v.Level,
|
||||
Children: children,
|
||||
Api: v.Api,
|
||||
Path: v.Path,
|
||||
ViewPath: v.ViewPath,
|
||||
Identification: v.Identification,
|
||||
Type: v.Type,
|
||||
IsShow: v.IsShow,
|
||||
Icon: v.Icon,
|
||||
Reason: v.Reason,
|
||||
AdminName: v.AdminName,
|
||||
AdminId: v.AdminId,
|
||||
}
|
||||
dataArr = append(dataArr, &node)
|
||||
}
|
||||
}
|
||||
return dataArr
|
||||
}
|
||||
Reference in New Issue
Block a user