feat: 初次启动
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateClientLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateClientLogic {
|
||||
return &CreateClientLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *CreateClientLogic) CreateClient(in *system.ClientReq) (*system.CommonResp, error) {
|
||||
client := sysModel.SundynixClient{
|
||||
ClientID: in.ClientId, Name: in.Name, GrantType: in.GrantType,
|
||||
AdditionalInfo: in.AdditionalInfo, ActiveTimeout: in.ActiveTimeout,
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&client).Error; err != nil {
|
||||
return nil, fmt.Errorf("创建客户端失败: %v", err)
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateDictLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateDictLogic {
|
||||
return &CreateDictLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *CreateDictLogic) CreateDict(in *system.DictReq) (*system.CommonResp, error) {
|
||||
dict := sysModel.SundynixDict{Type: in.Type, Label: in.Label, Value: in.Value, Sort: int(in.Sort), Desc: in.Desc}
|
||||
if err := l.svcCtx.DB.Create(&dict).Error; err != nil {
|
||||
return nil, fmt.Errorf("创建字典失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateMenuLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateMenuLogic {
|
||||
return &CreateMenuLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *CreateMenuLogic) CreateMenu(in *system.MenuReq) (*system.CommonResp, error) {
|
||||
menu := sysModel.SundynixMenu{
|
||||
ParentID: in.ParentId, Category: int(in.Category), Name: in.Name, Title: in.Title,
|
||||
Code: in.Code, Path: in.Path, Permission: in.Permission, Locale: in.Locale,
|
||||
Icon: in.Icon, Sort: int(in.Sort),
|
||||
}
|
||||
if err := l.svcCtx.DB.Create(&menu).Error; err != nil {
|
||||
return nil, fmt.Errorf("创建菜单失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type CreateRoleLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateRoleLogic {
|
||||
return &CreateRoleLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *CreateRoleLogic) CreateRole(in *system.RoleReq) (*system.CommonResp, error) {
|
||||
role := sysModel.SundynixRole{Name: in.Name, Code: in.Code, Sort: int(in.Sort)}
|
||||
if err := l.svcCtx.DB.Create(&role).Error; err != nil {
|
||||
return nil, fmt.Errorf("创建角色失败")
|
||||
}
|
||||
// 关联菜单
|
||||
if len(in.MenuIds) > 0 {
|
||||
for _, mid := range in.MenuIds {
|
||||
l.svcCtx.DB.Create(&sysModel.SundynixRoleMenu{RoleID: role.ID, MenuID: mid})
|
||||
}
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteClientLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteClientLogic {
|
||||
return &DeleteClientLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *DeleteClientLogic) DeleteClient(in *system.IdsReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixClient{}).Error; err != nil {
|
||||
return nil, fmt.Errorf("删除客户端失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteDictLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictLogic {
|
||||
return &DeleteDictLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *DeleteDictLogic) DeleteDict(in *system.IdsReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixDict{}).Error; err != nil {
|
||||
return nil, fmt.Errorf("删除字典失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteMenuLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteMenuLogic {
|
||||
return &DeleteMenuLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *DeleteMenuLogic) DeleteMenu(in *system.IdsReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixMenu{}).Error; err != nil {
|
||||
return nil, fmt.Errorf("删除菜单失败")
|
||||
}
|
||||
l.svcCtx.DB.Where("menu_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{})
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteOperationRecordLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteOperationRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOperationRecordLogic {
|
||||
return &DeleteOperationRecordLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *DeleteOperationRecordLogic) DeleteOperationRecord(in *system.IdsReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixOperationRecord{}).Error; err != nil {
|
||||
return nil, fmt.Errorf("删除操作日志失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type DeleteRoleLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteRoleLogic {
|
||||
return &DeleteRoleLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *DeleteRoleLogic) DeleteRole(in *system.IdsReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixRole{}).Error; err != nil {
|
||||
return nil, fmt.Errorf("删除角色失败")
|
||||
}
|
||||
l.svcCtx.DB.Where("role_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{})
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetClientListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetClientListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClientListLogic {
|
||||
return &GetClientListLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *GetClientListLogic) GetClientList(in *system.ClientListReq) (*system.ClientListResp, error) {
|
||||
var list []sysModel.SundynixClient
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixClient{})
|
||||
if in.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+in.Name+"%")
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := int(in.Current), int(in.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(&list).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询客户端列表失败")
|
||||
}
|
||||
var items []*system.ClientInfo
|
||||
for _, c := range list {
|
||||
items = append(items, &system.ClientInfo{
|
||||
Id: c.ID, ClientId: c.ClientID, Name: c.Name, GrantType: c.GrantType,
|
||||
AdditionalInfo: c.AdditionalInfo, ActiveTimeout: int64(c.ActiveTimeout),
|
||||
})
|
||||
}
|
||||
return &system.ClientListResp{List: items, Total: total}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetDictListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetDictListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictListLogic {
|
||||
return &GetDictListLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *GetDictListLogic) GetDictList(in *system.DictListReq) (*system.DictListResp, error) {
|
||||
var list []sysModel.SundynixDict
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixDict{})
|
||||
if in.Type != "" {
|
||||
db = db.Where("type = ?", in.Type)
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := int(in.Current), int(in.PageSize)
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("sort ASC").Find(&list).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询字典列表失败")
|
||||
}
|
||||
var items []*system.DictInfo
|
||||
for _, d := range list {
|
||||
items = append(items, &system.DictInfo{Id: d.ID, Type: d.Type, Label: d.Label, Value: d.Value, Sort: int32(d.Sort), Desc: d.Desc})
|
||||
}
|
||||
return &system.DictListResp{List: items, Total: total}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetMenuListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuListLogic {
|
||||
return &GetMenuListLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *GetMenuListLogic) GetMenuList(in *system.IdReq) (*system.MenuListResp, error) {
|
||||
var menus []sysModel.SundynixMenu
|
||||
if err := l.svcCtx.DB.Order("sort ASC").Find(&menus).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询菜单列表失败")
|
||||
}
|
||||
tree := buildMenuTree(menus, "")
|
||||
return &system.MenuListResp{Menus: tree}, nil
|
||||
}
|
||||
|
||||
func buildMenuTree(menus []sysModel.SundynixMenu, parentID string) []*system.MenuInfo {
|
||||
var result []*system.MenuInfo
|
||||
for _, m := range menus {
|
||||
if m.ParentID == parentID {
|
||||
info := &system.MenuInfo{
|
||||
Id: m.ID, ParentId: m.ParentID, Category: int32(m.Category), Name: m.Name,
|
||||
Title: m.Title, Code: m.Code, Path: m.Path, Permission: m.Permission,
|
||||
Locale: m.Locale, Icon: m.Icon, Sort: int32(m.Sort),
|
||||
Children: buildMenuTree(menus, m.ID),
|
||||
}
|
||||
result = append(result, info)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetOperationRecordListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetOperationRecordListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOperationRecordListLogic {
|
||||
return &GetOperationRecordListLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *GetOperationRecordListLogic) GetOperationRecordList(in *system.OperationRecordListReq) (*system.OperationRecordListResp, error) {
|
||||
var list []sysModel.SundynixOperationRecord
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixOperationRecord{})
|
||||
if in.Method != "" {
|
||||
db = db.Where("method = ?", in.Method)
|
||||
}
|
||||
if in.Path != "" {
|
||||
db = db.Where("path LIKE ?", "%"+in.Path+"%")
|
||||
}
|
||||
if in.Status > 0 {
|
||||
db = db.Where("status = ?", in.Status)
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := int(in.Current), int(in.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(&list).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询操作日志失败")
|
||||
}
|
||||
var items []*system.OperationRecordInfo
|
||||
for _, r := range list {
|
||||
items = append(items, &system.OperationRecordInfo{
|
||||
Id: r.ID, Ip: r.IP, Method: r.Method, Path: r.Path,
|
||||
Status: int32(r.Status), Agent: r.Agent, ErrorMessage: r.ErrorMessage,
|
||||
Body: r.Body, Resp: r.Resp, UserId: r.UserID,
|
||||
CreatedAt: r.CreatedAt.Unix(),
|
||||
})
|
||||
}
|
||||
return &system.OperationRecordListResp{List: items, Total: total}, nil
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type GetRoleListLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetRoleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRoleListLogic {
|
||||
return &GetRoleListLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *GetRoleListLogic) GetRoleList(in *system.RoleListReq) (*system.RoleListResp, error) {
|
||||
var list []sysModel.SundynixRole
|
||||
var total int64
|
||||
db := l.svcCtx.DB.Model(&sysModel.SundynixRole{})
|
||||
if in.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+in.Name+"%")
|
||||
}
|
||||
db.Count(&total)
|
||||
current, pageSize := int(in.Current), int(in.PageSize)
|
||||
if current <= 0 {
|
||||
current = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
if err := db.Offset((current - 1) * pageSize).Limit(pageSize).Order("sort ASC").Find(&list).Error; err != nil {
|
||||
return nil, fmt.Errorf("查询角色列表失败")
|
||||
}
|
||||
var items []*system.RoleInfo
|
||||
for _, r := range list {
|
||||
items = append(items, &system.RoleInfo{Id: r.ID, Name: r.Name, Code: r.Code, Sort: int32(r.Sort)})
|
||||
}
|
||||
return &system.RoleListResp{List: items, Total: total}, nil
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateClientLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClientLogic {
|
||||
return &UpdateClientLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *UpdateClientLogic) UpdateClient(in *system.ClientUpdateReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixClient{}).Where("id = ?", in.Id).Updates(map[string]interface{}{
|
||||
"client_id": in.ClientId, "name": in.Name, "grant_type": in.GrantType,
|
||||
"additional_info": in.AdditionalInfo, "active_timeout": in.ActiveTimeout,
|
||||
}).Error; err != nil {
|
||||
return nil, fmt.Errorf("更新客户端失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateDictLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateDictLogic {
|
||||
return &UpdateDictLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *UpdateDictLogic) UpdateDict(in *system.DictUpdateReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixDict{}).Where("id = ?", in.Id).Updates(map[string]interface{}{
|
||||
"type": in.Type, "label": in.Label, "value": in.Value, "sort": in.Sort, "desc": in.Desc,
|
||||
}).Error; err != nil {
|
||||
return nil, fmt.Errorf("更新字典失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateMenuLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateMenuLogic {
|
||||
return &UpdateMenuLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *UpdateMenuLogic) UpdateMenu(in *system.MenuUpdateReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixMenu{}).Where("id = ?", in.Id).Updates(map[string]interface{}{
|
||||
"parent_id": in.ParentId, "category": in.Category, "name": in.Name, "title": in.Title,
|
||||
"code": in.Code, "path": in.Path, "permission": in.Permission, "locale": in.Locale,
|
||||
"icon": in.Icon, "sort": in.Sort,
|
||||
}).Error; err != nil {
|
||||
return nil, fmt.Errorf("更新菜单失败")
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
sysModel "sundynix-micro-go/app/system/model"
|
||||
"sundynix-micro-go/app/system/rpc/internal/svc"
|
||||
"sundynix-micro-go/app/system/rpc/system"
|
||||
)
|
||||
|
||||
type UpdateRoleLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateRoleLogic {
|
||||
return &UpdateRoleLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
|
||||
}
|
||||
|
||||
func (l *UpdateRoleLogic) UpdateRole(in *system.RoleUpdateReq) (*system.CommonResp, error) {
|
||||
if err := l.svcCtx.DB.Model(&sysModel.SundynixRole{}).Where("id = ?", in.Id).Updates(map[string]interface{}{
|
||||
"name": in.Name, "code": in.Code, "sort": in.Sort,
|
||||
}).Error; err != nil {
|
||||
return nil, fmt.Errorf("更新角色失败")
|
||||
}
|
||||
// 更新菜单关联
|
||||
l.svcCtx.DB.Where("role_id = ?", in.Id).Delete(&sysModel.SundynixRoleMenu{})
|
||||
for _, mid := range in.MenuIds {
|
||||
l.svcCtx.DB.Create(&sysModel.SundynixRoleMenu{RoleID: in.Id, MenuID: mid})
|
||||
}
|
||||
return &system.CommonResp{Code: 200, Msg: "success"}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user