feat: 初次启动
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateClientLogic struct {
|
||||
@@ -21,24 +15,13 @@ type CreateClientLogic struct {
|
||||
}
|
||||
|
||||
func NewCreateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateClientLogic {
|
||||
return &CreateClientLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
return &CreateClientLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *CreateClientLogic) CreateClient(req *types.ClientReq) error {
|
||||
client := sysModel.SundynixClient{
|
||||
ClientID: req.ClientId,
|
||||
Name: req.Name,
|
||||
GrantType: req.GrantType,
|
||||
AdditionalInfo: req.AdditionalInfo,
|
||||
ActiveTimeout: req.ActiveTimeout,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&client).Error; err != nil {
|
||||
l.Errorf("创建客户端失败: %v", err)
|
||||
return fmt.Errorf("创建客户端失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.CreateClient(l.ctx, &system.ClientReq{
|
||||
ClientId: req.ClientId, Name: req.Name, GrantType: req.GrantType,
|
||||
AdditionalInfo: req.AdditionalInfo, ActiveTimeout: req.ActiveTimeout,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteClientLogic struct {
|
||||
@@ -21,17 +15,10 @@ type DeleteClientLogic struct {
|
||||
}
|
||||
|
||||
func NewDeleteClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteClientLogic {
|
||||
return &DeleteClientLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
return &DeleteClientLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *DeleteClientLogic) DeleteClient(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixClient{}).Error; err != nil {
|
||||
l.Errorf("删除客户端失败: %v", err)
|
||||
return fmt.Errorf("删除客户端失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.DeleteClient(l.ctx, &system.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetClientListLogic struct {
|
||||
@@ -21,46 +15,15 @@ type GetClientListLogic struct {
|
||||
}
|
||||
|
||||
func NewGetClientListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClientListLogic {
|
||||
return &GetClientListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
return &GetClientListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetClientListLogic) GetClientList(req *types.ClientListReq) (resp interface{}, err error) {
|
||||
var clients []sysModel.SundynixClient
|
||||
var total int64
|
||||
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixClient{})
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
func (l *GetClientListLogic) GetClientList(req *types.ClientListReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetClientList(l.ctx, &system.ClientListReq{
|
||||
Current: int32(req.Current), PageSize: int32(req.PageSize), Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
l.Errorf("查询客户端总数失败: %v", err)
|
||||
return nil, fmt.Errorf("查询失败")
|
||||
}
|
||||
|
||||
current := req.Current
|
||||
pageSize := req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
offset := (current - 1) * pageSize
|
||||
if err := db.Offset(offset).Limit(pageSize).Find(&clients).Error; err != nil {
|
||||
l.Errorf("查询客户端列表失败: %v", err)
|
||||
return nil, fmt.Errorf("查询失败")
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
"list": clients,
|
||||
"total": total,
|
||||
"current": current,
|
||||
"size": pageSize,
|
||||
}, nil
|
||||
return map[string]interface{}{"list": resp.List, "total": resp.Total, "current": req.Current, "size": req.PageSize}, nil
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateClientLogic struct {
|
||||
@@ -21,34 +15,13 @@ type UpdateClientLogic struct {
|
||||
}
|
||||
|
||||
func NewUpdateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClientLogic {
|
||||
return &UpdateClientLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
return &UpdateClientLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *UpdateClientLogic) UpdateClient(req *types.ClientUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.ClientId != "" {
|
||||
updates["client_id"] = req.ClientId
|
||||
}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.GrantType != "" {
|
||||
updates["grant_type"] = req.GrantType
|
||||
}
|
||||
if req.AdditionalInfo != "" {
|
||||
updates["additional_info"] = req.AdditionalInfo
|
||||
}
|
||||
if req.ActiveTimeout > 0 {
|
||||
updates["active_timeout"] = req.ActiveTimeout
|
||||
}
|
||||
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixClient{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
l.Errorf("更新客户端失败: %v", err)
|
||||
return fmt.Errorf("更新客户端失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.UpdateClient(l.ctx, &system.ClientUpdateReq{
|
||||
Id: req.Id, ClientId: req.ClientId, Name: req.Name, GrantType: req.GrantType,
|
||||
AdditionalInfo: req.AdditionalInfo, ActiveTimeout: req.ActiveTimeout,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateDictLogic struct {
|
||||
@@ -21,9 +19,8 @@ func NewCreateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
|
||||
func (l *CreateDictLogic) CreateDict(req *types.DictReq) error {
|
||||
dict := sysModel.SundynixDict{Type: req.Type, Label: req.Label, Value: req.Value, Sort: req.Sort, Desc: req.Desc}
|
||||
if err := l.svcCtx.DB.Create(&dict).Error; err != nil {
|
||||
return fmt.Errorf("创建字典失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.CreateDict(l.ctx, &system.DictReq{
|
||||
Type: req.Type, Label: req.Label, Value: req.Value, Sort: int32(req.Sort), Desc: req.Desc,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteDictLogic struct {
|
||||
@@ -21,8 +19,6 @@ func NewDeleteDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
||||
}
|
||||
|
||||
func (l *DeleteDictLogic) DeleteDict(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixDict{}).Error; err != nil {
|
||||
return fmt.Errorf("删除字典失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.DeleteDict(l.ctx, &system.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetDictListLogic struct {
|
||||
@@ -20,23 +18,12 @@ func NewGetDictListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDi
|
||||
return &GetDictListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetDictListLogic) GetDictList(req *types.DictListReq) (resp interface{}, err error) {
|
||||
var dicts []sysModel.SundynixDict
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixDict{})
|
||||
if req.Type != "" {
|
||||
db = db.Where("type = ?", req.Type)
|
||||
func (l *GetDictListLogic) GetDictList(req *types.DictListReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetDictList(l.ctx, &system.DictListReq{
|
||||
Current: int32(req.Current), PageSize: int32(req.PageSize), Type: req.Type,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("sort").Find(&dicts).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询字典列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": dicts, "total": total, "current": current, "size": pageSize}, nil
|
||||
return map[string]interface{}{"list": resp.List, "total": resp.Total}, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package dict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateDictLogic struct {
|
||||
@@ -21,26 +19,8 @@ func NewUpdateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
||||
}
|
||||
|
||||
func (l *UpdateDictLogic) UpdateDict(req *types.DictUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.Type != "" {
|
||||
updates["type"] = req.Type
|
||||
}
|
||||
if req.Label != "" {
|
||||
updates["label"] = req.Label
|
||||
}
|
||||
if req.Value != "" {
|
||||
updates["value"] = req.Value
|
||||
}
|
||||
if req.Sort > 0 {
|
||||
updates["sort"] = req.Sort
|
||||
}
|
||||
if req.Desc != "" {
|
||||
updates["desc"] = req.Desc
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixDict{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新字典失败")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.UpdateDict(l.ctx, &system.DictUpdateReq{
|
||||
Id: req.Id, Type: req.Type, Label: req.Label, Value: req.Value, Sort: int32(req.Sort), Desc: req.Desc,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateMenuLogic struct {
|
||||
@@ -21,16 +19,10 @@ func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
|
||||
func (l *CreateMenuLogic) CreateMenu(req *types.MenuReq) error {
|
||||
menu := sysModel.SundynixMenu{
|
||||
ParentID: req.ParentId, Category: req.Category, Name: req.Name, Title: req.Title,
|
||||
_, err := l.svcCtx.SystemRpc.CreateMenu(l.ctx, &system.MenuReq{
|
||||
ParentId: req.ParentId, Category: int32(req.Category), Name: req.Name, Title: req.Title,
|
||||
Code: req.Code, Path: req.Path, Permission: req.Permission, Locale: req.Locale,
|
||||
Icon: req.Icon, Sort: req.Sort,
|
||||
}
|
||||
if menu.ParentID == "" {
|
||||
menu.ParentID = "0"
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&menu).Error; err != nil {
|
||||
return fmt.Errorf("创建菜单失败")
|
||||
}
|
||||
return nil
|
||||
Icon: req.Icon, Sort: int32(req.Sort),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteMenuLogic struct {
|
||||
@@ -21,8 +19,6 @@ func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
||||
}
|
||||
|
||||
func (l *DeleteMenuLogic) DeleteMenu(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixMenu{}).Error; err != nil {
|
||||
return fmt.Errorf("删除菜单失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.DeleteMenu(l.ctx, &system.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetMenuByRoleLogic struct {
|
||||
@@ -20,10 +18,10 @@ func NewGetMenuByRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
|
||||
return &GetMenuByRoleLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMenuByRoleLogic) GetMenuByRole(req *types.IdReq) (resp interface{}, err error) {
|
||||
var role sysModel.SundynixRole
|
||||
if err := l.svcCtx.DB.Preload("Menus").Where("id = ?", req.Id).First(&role).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询角色菜单失败")
|
||||
func (l *GetMenuByRoleLogic) GetMenuByRole(req *types.IdReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetMenusByRoleId(l.ctx, &system.GetMenusByRoleIdReq{RoleId: req.Id})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return role.Menus, nil
|
||||
return resp.Menus, nil
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetMenuListLogic struct {
|
||||
@@ -19,26 +17,10 @@ func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMe
|
||||
return &GetMenuListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetMenuListLogic) GetMenuList() (resp interface{}, err error) {
|
||||
var menus []sysModel.SundynixMenu
|
||||
if err := l.svcCtx.DB.Order("sort").Find(&menus).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询菜单列表失败")
|
||||
func (l *GetMenuListLogic) GetMenuList() (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetMenuList(l.ctx, &system.IdReq{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 构建树形结构
|
||||
menuMap := make(map[string]*sysModel.SundynixMenu)
|
||||
for i := range menus {
|
||||
menus[i].Children = []*sysModel.SundynixMenu{}
|
||||
menuMap[menus[i].ID] = &menus[i]
|
||||
}
|
||||
var tree []*sysModel.SundynixMenu
|
||||
for _, m := range menuMap {
|
||||
if m.ParentID == "0" || m.ParentID == "" {
|
||||
tree = append(tree, m)
|
||||
} else if parent, ok := menuMap[m.ParentID]; ok {
|
||||
parent.Children = append(parent.Children, m)
|
||||
} else {
|
||||
tree = append(tree, m)
|
||||
}
|
||||
}
|
||||
return tree, nil
|
||||
return resp.Menus, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package menu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateMenuLogic struct {
|
||||
@@ -21,41 +19,10 @@ func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
||||
}
|
||||
|
||||
func (l *UpdateMenuLogic) UpdateMenu(req *types.MenuUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.ParentId != "" {
|
||||
updates["parent_id"] = req.ParentId
|
||||
}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.Title != "" {
|
||||
updates["title"] = req.Title
|
||||
}
|
||||
if req.Code != "" {
|
||||
updates["code"] = req.Code
|
||||
}
|
||||
if req.Path != "" {
|
||||
updates["path"] = req.Path
|
||||
}
|
||||
if req.Permission != "" {
|
||||
updates["permission"] = req.Permission
|
||||
}
|
||||
if req.Locale != "" {
|
||||
updates["locale"] = req.Locale
|
||||
}
|
||||
if req.Icon != "" {
|
||||
updates["icon"] = req.Icon
|
||||
}
|
||||
if req.Sort > 0 {
|
||||
updates["sort"] = req.Sort
|
||||
}
|
||||
if req.Category > 0 {
|
||||
updates["category"] = req.Category
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixMenu{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新菜单失败")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.UpdateMenu(l.ctx, &system.MenuUpdateReq{
|
||||
Id: req.Id, ParentId: req.ParentId, Category: int32(req.Category), Name: req.Name, Title: req.Title,
|
||||
Code: req.Code, Path: req.Path, Permission: req.Permission, Locale: req.Locale,
|
||||
Icon: req.Icon, Sort: int32(req.Sort),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package operationRecord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteOperationRecordLogic struct {
|
||||
@@ -21,8 +19,6 @@ func NewDeleteOperationRecordLogic(ctx context.Context, svcCtx *svc.ServiceConte
|
||||
}
|
||||
|
||||
func (l *DeleteOperationRecordLogic) DeleteOperationRecord(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixOperationRecord{}).Error; err != nil {
|
||||
return fmt.Errorf("删除操作日志失败")
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.DeleteOperationRecord(l.ctx, &system.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package operationRecord
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetOperationRecordListLogic struct {
|
||||
@@ -20,29 +18,13 @@ func NewGetOperationRecordListLogic(ctx context.Context, svcCtx *svc.ServiceCont
|
||||
return &GetOperationRecordListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetOperationRecordListLogic) GetOperationRecordList(req *types.OperationRecordListReq) (resp interface{}, err error) {
|
||||
var records []sysModel.SundynixOperationRecord
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixOperationRecord{})
|
||||
if req.Method != "" {
|
||||
db = db.Where("method = ?", req.Method)
|
||||
func (l *GetOperationRecordListLogic) GetOperationRecordList(req *types.OperationRecordListReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetOperationRecordList(l.ctx, &system.OperationRecordListReq{
|
||||
Current: int32(req.Current), PageSize: int32(req.PageSize),
|
||||
Method: req.Method, Path: req.Path, Status: int32(req.Status),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.Path != "" {
|
||||
db = db.Where("path LIKE ?", "%"+req.Path+"%")
|
||||
}
|
||||
if req.Status > 0 {
|
||||
db = db.Where("status = ?", req.Status)
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("created_at DESC").Find(&records).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询操作日志失败")
|
||||
}
|
||||
return map[string]interface{}{"list": records, "total": total, "current": current, "size": pageSize}, nil
|
||||
return map[string]interface{}{"list": resp.List, "total": resp.Total}, nil
|
||||
}
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.10.1
|
||||
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateRoleLogic struct {
|
||||
@@ -25,15 +19,8 @@ func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
||||
}
|
||||
|
||||
func (l *CreateRoleLogic) CreateRole(req *types.RoleReq) error {
|
||||
role := sysModel.SundynixRole{Name: req.Name, Code: req.Code, Sort: req.Sort}
|
||||
if err := l.svcCtx.DB.Create(&role).Error; err != nil {
|
||||
return fmt.Errorf("创建角色失败")
|
||||
}
|
||||
// 关联菜单
|
||||
if len(req.MenuIds) > 0 {
|
||||
for _, menuID := range req.MenuIds {
|
||||
l.svcCtx.DB.Create(&sysModel.SundynixRoleMenu{RoleID: role.ID, MenuID: menuID})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.CreateRole(l.ctx, &system.RoleReq{
|
||||
Name: req.Name, Code: req.Code, Sort: int32(req.Sort), MenuIds: req.MenuIds,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteRoleLogic struct {
|
||||
@@ -21,10 +19,6 @@ func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
||||
}
|
||||
|
||||
func (l *DeleteRoleLogic) DeleteRole(req *types.IdsReq) error {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", req.Ids).Delete(&sysModel.SundynixRole{}).Error; err != nil {
|
||||
return fmt.Errorf("删除角色失败")
|
||||
}
|
||||
// 清理角色菜单关联
|
||||
l.svcCtx.DB.Where("role_id IN ?", req.Ids).Delete(&sysModel.SundynixRoleMenu{})
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.DeleteRole(l.ctx, &system.IdsReq{Ids: req.Ids})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetRoleListLogic struct {
|
||||
@@ -20,23 +18,12 @@ func NewGetRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRo
|
||||
return &GetRoleListLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
|
||||
}
|
||||
|
||||
func (l *GetRoleListLogic) GetRoleList(req *types.RoleListReq) (resp interface{}, err error) {
|
||||
var roles []sysModel.SundynixRole
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixRole{})
|
||||
if req.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+req.Name+"%")
|
||||
func (l *GetRoleListLogic) GetRoleList(req *types.RoleListReq) (interface{}, error) {
|
||||
resp, err := l.svcCtx.SystemRpc.GetRoleList(l.ctx, &system.RoleListReq{
|
||||
Current: int32(req.Current), PageSize: int32(req.PageSize), Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := req.Current, req.PageSize
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Preload("Menus").Offset((current - 1) * pageSize).Limit(pageSize).Order("sort").Find(&roles).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询角色列表失败")
|
||||
}
|
||||
return map[string]interface{}{"list": roles, "total": total, "current": current, "size": pageSize}, nil
|
||||
return map[string]interface{}{"list": resp.List, "total": resp.Total}, nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
package role
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"sundynix-micro-go/app/system/api/internal/svc"
|
||||
"sundynix-micro-go/app/system/api/internal/types"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateRoleLogic struct {
|
||||
@@ -21,27 +19,8 @@ func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
||||
}
|
||||
|
||||
func (l *UpdateRoleLogic) UpdateRole(req *types.RoleUpdateReq) error {
|
||||
updates := map[string]interface{}{}
|
||||
if req.Name != "" {
|
||||
updates["name"] = req.Name
|
||||
}
|
||||
if req.Code != "" {
|
||||
updates["code"] = req.Code
|
||||
}
|
||||
if req.Sort > 0 {
|
||||
updates["sort"] = req.Sort
|
||||
}
|
||||
if len(updates) > 0 {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixRole{}).Where("id = ?", req.Id).Updates(updates).Error; err != nil {
|
||||
return fmt.Errorf("更新角色失败")
|
||||
}
|
||||
}
|
||||
// 更新菜单关联
|
||||
if len(req.MenuIds) > 0 {
|
||||
l.svcCtx.DB.Where("role_id = ?", req.Id).Delete(&sysModel.SundynixRoleMenu{})
|
||||
for _, menuID := range req.MenuIds {
|
||||
l.svcCtx.DB.Create(&sysModel.SundynixRoleMenu{RoleID: req.Id, MenuID: menuID})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
_, err := l.svcCtx.SystemRpc.UpdateRole(l.ctx, &system.RoleUpdateReq{
|
||||
Id: req.Id, Name: req.Name, Code: req.Code, Sort: int32(req.Sort), MenuIds: req.MenuIds,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user