feat: 初次启动
This commit is contained in:
@@ -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