feat: rbac迁移完成,并已部署至dev服务器

This commit is contained in:
Blizzard
2026-05-01 01:19:50 +08:00
parent f80a3dc064
commit 8b11068fef
250 changed files with 6314 additions and 13072 deletions
@@ -0,0 +1,45 @@
package logic
import (
"context"
"time"
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 CreateOperationRecordLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateOperationRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOperationRecordLogic {
return &CreateOperationRecordLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *CreateOperationRecordLogic) CreateOperationRecord(in *system.CreateOperationRecordReq) (*system.CommonResp, error) {
record := sysModel.SundynixOperationRecord{
ClientID: in.ClientId,
IP: in.Ip,
Method: in.Method,
Path: in.Path,
Status: int(in.Status),
Latency: time.Duration(in.Latency),
Agent: in.Agent,
ErrorMessage: in.ErrorMessage,
Body: in.Body,
Resp: in.Resp,
UserID: in.UserId,
}
if err := l.svcCtx.DB.Create(&record).Error; err != nil {
l.Errorf("写入操作日志失败: %v", err)
// 日志写入失败不影响业务,不返回error
}
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -3,10 +3,13 @@ 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"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type CreateRoleLogic struct {
@@ -20,15 +23,21 @@ func NewCreateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
}
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})
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
role := sysModel.SundynixRole{Name: in.Name, Code: in.Code, Sort: int(in.Sort)}
if err := tx.Create(&role).Error; err != nil {
return fmt.Errorf("创建角色失败: %w", err)
}
// 关联菜单
for _, mid := range in.MenuIds {
if err := tx.Create(&sysModel.SundynixRoleMenu{RoleID: role.ID, MenuID: mid}).Error; err != nil {
return fmt.Errorf("关联菜单失败: %w", err)
}
}
return nil
})
if err != nil {
return nil, err
}
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -0,0 +1,62 @@
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"
"sundynix-micro-go/common/utils/hash"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateUserLogic {
return &CreateUserLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *CreateUserLogic) CreateUser(in *system.CreateUserReq) (*system.CreateUserResp, error) {
// 如果有 OpenId,先查是否已存在(社交登录场景:已有用户直接返回)
if in.OpenId != "" {
var existing sysModel.SundynixUser
if err := l.svcCtx.DB.Where("open_id = ?", in.OpenId).First(&existing).Error; err == nil {
// 用户已存在,更新 session_key 后直接返回
if in.SessionKey != "" {
l.svcCtx.DB.Model(&existing).Update("session_key", in.SessionKey)
}
return &system.CreateUserResp{User: convertUserToProto(&existing)}, nil
}
}
// 如果有 Account,检查是否重复(后台创建用户场景:禁止重复)
if in.Account != "" {
var count int64
l.svcCtx.DB.Model(&sysModel.SundynixUser{}).Where("account = ?", in.Account).Count(&count)
if count > 0 {
return nil, fmt.Errorf("账号 %s 已存在", in.Account)
}
}
u := sysModel.SundynixUser{
Name: in.Name,
Account: in.Account,
Phone: in.Phone,
OpenID: in.OpenId,
SessionKey: in.SessionKey,
ClientID: in.ClientId,
}
if in.Password != "" {
u.Password = hash.BcryptHash(in.Password)
}
if err := l.svcCtx.DB.Create(&u).Error; err != nil {
return nil, fmt.Errorf("创建用户失败: %w", err)
}
return &system.CreateUserResp{User: convertUserToProto(&u)}, nil
}
@@ -3,10 +3,13 @@ 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"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type DeleteMenuLogic struct {
@@ -20,9 +23,17 @@ func NewDeleteMenuLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
}
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("删除菜单失败")
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixMenu{}).Error; err != nil {
return fmt.Errorf("删除菜单失败: %w", err)
}
if err := tx.Where("menu_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{}).Error; err != nil {
return fmt.Errorf("清除角色关联失败: %w", err)
}
return nil
})
if err != nil {
return nil, err
}
l.svcCtx.DB.Where("menu_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{})
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -3,10 +3,13 @@ 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"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type DeleteRoleLogic struct {
@@ -20,9 +23,17 @@ func NewDeleteRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
}
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("删除角色失败")
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixRole{}).Error; err != nil {
return fmt.Errorf("删除角色失败: %w", err)
}
if err := tx.Where("role_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{}).Error; err != nil {
return fmt.Errorf("清除菜单关联失败: %w", err)
}
return nil
})
if err != nil {
return nil, err
}
l.svcCtx.DB.Where("role_id IN ?", in.Ids).Delete(&sysModel.SundynixRoleMenu{})
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -0,0 +1,39 @@
package logic
import (
"context"
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"
"gorm.io/gorm"
)
type DeleteUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteUserLogic {
return &DeleteUserLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *DeleteUserLogic) DeleteUser(in *system.DeleteUserReq) (*system.CommonResp, error) {
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("id IN ?", in.Ids).Delete(&sysModel.SundynixUser{}).Error; err != nil {
return err
}
// 同时删除用户角色关联
if err := tx.Where("user_id IN ?", in.Ids).Delete(&sysModel.SundynixUserRole{}).Error; err != nil {
return err
}
return nil
})
if err != nil {
return nil, err
}
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -2,6 +2,7 @@ package logic
import (
"context"
"errors"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/internal/svc"
@@ -32,10 +33,11 @@ func (l *GetClientByIdLogic) GetClientById(in *system.GetClientByIdReq) (*system
var client sysModel.SundynixClient
err := l.svcCtx.DB.Where("client_id = ?", in.ClientId).First(&client).Error
if err != nil {
if err == gorm.ErrRecordNotFound {
if errors.Is(err, gorm.ErrRecordNotFound) {
l.Infof("[GetClientById] 客户端不存在 | clientId=%s", in.ClientId)
return nil, status.Error(codes.NotFound, "客户端不存在")
}
l.Errorf("查询客户端失败: %v", err)
l.Errorf("[GetClientById] ❌ 查询客户端失败 | clientId=%s | err=%v", in.ClientId, err)
return nil, status.Error(codes.Internal, "查询客户端失败")
}
@@ -3,10 +3,11 @@ 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"
"github.com/zeromicro/go-zero/core/logx"
)
type GetMenuListLogic struct {
@@ -22,9 +23,11 @@ func NewGetMenuListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMe
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 {
l.Errorf("[GetMenuList] ❌ 查询菜单失败: %v", err)
return nil, fmt.Errorf("查询菜单列表失败")
}
tree := buildMenuTree(menus, "")
l.Infof("[GetMenuList] 查询到菜单数量: %d", len(menus))
tree := buildMenuTree(menus, "0")
return &system.MenuListResp{Menus: tree}, nil
}
@@ -73,7 +73,8 @@ func (l *GetMenusByRoleIdLogic) GetMenusByRoleId(in *system.GetMenusByRoleIdReq)
menuMap[m.ID] = menuInfo
}
for _, menuInfo := range menuMap {
for _, m := range menus {
menuInfo := menuMap[m.ID]
if menuInfo.ParentId == "0" || menuInfo.ParentId == "" {
rootMenus = append(rootMenus, menuInfo)
} else {
@@ -46,11 +46,21 @@ func (l *GetOperationRecordListLogic) GetOperationRecordList(in *system.Operatio
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(),
Id: r.ID,
ClientId: r.ClientID,
Ip: r.IP,
Method: r.Method,
Path: r.Path,
Status: int32(r.Status),
Latency: int64(r.Latency),
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,36 @@
package logic
import (
"context"
"errors"
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"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)
type GetUserByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserByIdLogic {
return &GetUserByIdLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *GetUserByIdLogic) GetUserById(in *system.GetUserByIdReq) (*system.GetUserByIdResp, error) {
var u sysModel.SundynixUser
if err := l.svcCtx.DB.Where("id = ?", in.Id).First(&u).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "用户不存在")
}
return nil, status.Error(codes.Internal, "查询用户失败")
}
return &system.GetUserByIdResp{User: convertUserToProto(&u)}, nil
}
@@ -0,0 +1,36 @@
package logic
import (
"context"
"errors"
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"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)
type GetUserByOpenIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserByOpenIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserByOpenIdLogic {
return &GetUserByOpenIdLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *GetUserByOpenIdLogic) GetUserByOpenId(in *system.GetUserByOpenIdReq) (*system.GetUserByOpenIdResp, error) {
var u sysModel.SundynixUser
if err := l.svcCtx.DB.Where("open_id = ?", in.OpenId).First(&u).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "用户不存在")
}
return nil, status.Error(codes.Internal, "查询失败")
}
return &system.GetUserByOpenIdResp{User: convertUserToProto(&u)}, nil
}
@@ -0,0 +1,51 @@
package logic
import (
"context"
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 GetUserListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
return &GetUserListLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *GetUserListLogic) GetUserList(in *system.GetUserListReq) (*system.GetUserListResp, error) {
db := l.svcCtx.DB.Model(&sysModel.SundynixUser{})
if in.Name != "" {
db = db.Where("name LIKE ?", "%"+in.Name+"%")
}
if in.Account != "" {
db = db.Where("account LIKE ?", "%"+in.Account+"%")
}
var total int64
db.Count(&total)
var list []sysModel.SundynixUser
pageSize := int(in.PageSize)
if pageSize <= 0 {
pageSize = 10
}
current := int(in.Current)
if current <= 0 {
current = 1
}
db.Offset((current - 1) * pageSize).Limit(pageSize).Order("created_at DESC").Find(&list)
var protoList []*system.UserInfo
for _, u := range list {
protoList = append(protoList, convertUserToProto(&u))
}
return &system.GetUserListResp{List: protoList, Total: total}, nil
}
@@ -0,0 +1,48 @@
package logic
import (
"context"
"errors"
"time"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/internal/svc"
"sundynix-micro-go/app/system/rpc/system"
"sundynix-micro-go/common/utils/hash"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)
type LoginByAccountLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewLoginByAccountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginByAccountLogic {
return &LoginByAccountLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *LoginByAccountLogic) LoginByAccount(in *system.LoginByAccountReq) (*system.LoginByAccountResp, error) {
var u sysModel.SundynixUser
err := l.svcCtx.DB.Where("account = ?", in.Account).First(&u).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "账号不存在")
}
return nil, status.Error(codes.Internal, "查询用户失败")
}
if !hash.BcryptCheck(in.Password, u.Password) {
return nil, status.Error(codes.Unauthenticated, "密码错误")
}
// 更新最后登录时间
now := time.Now()
l.svcCtx.DB.Model(&u).Update("last_login_at", now)
u.LastLoginAt = &now
return &system.LoginByAccountResp{User: convertUserToProto(&u)}, nil
}
@@ -0,0 +1,30 @@
package logic
import (
"context"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/internal/svc"
"sundynix-micro-go/app/system/rpc/system"
"sundynix-micro-go/common/utils/hash"
"github.com/zeromicro/go-zero/core/logx"
)
type ResetPasswordLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
return &ResetPasswordLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *ResetPasswordLogic) ResetPassword(in *system.ResetPasswordReq) (*system.CommonResp, error) {
if err := l.svcCtx.DB.Model(&sysModel.SundynixUser{}).Where("id = ?", in.Id).
Update("password", hash.BcryptHash(in.Password)).Error; err != nil {
return nil, err
}
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -3,10 +3,13 @@ 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"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/gorm"
)
type UpdateRoleLogic struct {
@@ -20,15 +23,26 @@ func NewUpdateRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
}
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})
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
if err := tx.Model(&sysModel.SundynixRole{}).Where("id = ?", in.Id).Updates(map[string]interface{}{
"name": in.Name, "code": in.Code, "sort": in.Sort,
}).Error; err != nil {
return fmt.Errorf("更新角色失败: %w", err)
}
// 先删除旧的菜单关联
if err := tx.Where("role_id = ?", in.Id).Delete(&sysModel.SundynixRoleMenu{}).Error; err != nil {
return fmt.Errorf("清除菜单关联失败: %w", err)
}
// 重新关联菜单
for _, mid := range in.MenuIds {
if err := tx.Create(&sysModel.SundynixRoleMenu{RoleID: in.Id, MenuID: mid}).Error; err != nil {
return fmt.Errorf("关联菜单失败: %w", err)
}
}
return nil
})
if err != nil {
return nil, err
}
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -0,0 +1,44 @@
package logic
import (
"context"
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 UpdateUserLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
return &UpdateUserLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *UpdateUserLogic) UpdateUser(in *system.UpdateUserReq) (*system.CommonResp, error) {
updates := map[string]interface{}{}
if in.Name != "" {
updates["name"] = in.Name
}
if in.Account != "" {
updates["account"] = in.Account
}
if in.Phone != "" {
updates["phone"] = in.Phone
}
if in.AvatarId != "" {
updates["avatar_id"] = in.AvatarId
}
if in.NickName != "" {
updates["nick_name"] = in.NickName
}
if err := l.svcCtx.DB.Model(&sysModel.SundynixUser{}).Where("id = ?", in.Id).Updates(updates).Error; err != nil {
return nil, err
}
return &system.CommonResp{Code: 200, Msg: "success"}, nil
}
@@ -0,0 +1,31 @@
package logic
import (
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/system"
)
// convertUserToProto 将 model 转为 proto UserInfo
func convertUserToProto(u *sysModel.SundynixUser) *system.UserInfo {
info := &system.UserInfo{
Id: u.ID,
TenantId: u.TenantID,
ClientId: u.ClientID,
Name: u.Name,
Account: u.Account,
NickName: u.NickName,
Phone: u.Phone,
SessionKey: u.SessionKey,
UnionId: u.UnionID,
OpenId: u.OpenID,
SaOpenId: u.SaOpenID,
AvatarId: u.AvatarID,
Gender: int32(u.Gender),
CreatedAt: u.CreatedAt.Unix(),
UpdatedAt: u.UpdatedAt.Unix(),
}
if u.LastLoginAt != nil {
info.LastLoginAt = u.LastLoginAt.Unix()
}
return info
}
@@ -23,6 +23,47 @@ func NewSystemServiceServer(svcCtx *svc.ServiceContext) *SystemServiceServer {
}
}
// --- 用户 ---
func (s *SystemServiceServer) GetUserById(ctx context.Context, in *system.GetUserByIdReq) (*system.GetUserByIdResp, error) {
l := logic.NewGetUserByIdLogic(ctx, s.svcCtx)
return l.GetUserById(in)
}
func (s *SystemServiceServer) GetUserByOpenId(ctx context.Context, in *system.GetUserByOpenIdReq) (*system.GetUserByOpenIdResp, error) {
l := logic.NewGetUserByOpenIdLogic(ctx, s.svcCtx)
return l.GetUserByOpenId(in)
}
func (s *SystemServiceServer) LoginByAccount(ctx context.Context, in *system.LoginByAccountReq) (*system.LoginByAccountResp, error) {
l := logic.NewLoginByAccountLogic(ctx, s.svcCtx)
return l.LoginByAccount(in)
}
func (s *SystemServiceServer) CreateUser(ctx context.Context, in *system.CreateUserReq) (*system.CreateUserResp, error) {
l := logic.NewCreateUserLogic(ctx, s.svcCtx)
return l.CreateUser(in)
}
func (s *SystemServiceServer) UpdateUser(ctx context.Context, in *system.UpdateUserReq) (*system.CommonResp, error) {
l := logic.NewUpdateUserLogic(ctx, s.svcCtx)
return l.UpdateUser(in)
}
func (s *SystemServiceServer) GetUserList(ctx context.Context, in *system.GetUserListReq) (*system.GetUserListResp, error) {
l := logic.NewGetUserListLogic(ctx, s.svcCtx)
return l.GetUserList(in)
}
func (s *SystemServiceServer) DeleteUser(ctx context.Context, in *system.DeleteUserReq) (*system.CommonResp, error) {
l := logic.NewDeleteUserLogic(ctx, s.svcCtx)
return l.DeleteUser(in)
}
func (s *SystemServiceServer) ResetPassword(ctx context.Context, in *system.ResetPasswordReq) (*system.CommonResp, error) {
l := logic.NewResetPasswordLogic(ctx, s.svcCtx)
return l.ResetPassword(in)
}
// --- 角色 ---
func (s *SystemServiceServer) GetRolesByUserId(ctx context.Context, in *system.GetRolesByUserIdReq) (*system.GetRolesByUserIdResp, error) {
l := logic.NewGetRolesByUserIdLogic(ctx, s.svcCtx)
@@ -123,6 +164,11 @@ func (s *SystemServiceServer) GetDictList(ctx context.Context, in *system.DictLi
}
// --- 操作日志 ---
func (s *SystemServiceServer) CreateOperationRecord(ctx context.Context, in *system.CreateOperationRecordReq) (*system.CommonResp, error) {
l := logic.NewCreateOperationRecordLogic(ctx, s.svcCtx)
return l.CreateOperationRecord(in)
}
func (s *SystemServiceServer) DeleteOperationRecord(ctx context.Context, in *system.IdsReq) (*system.CommonResp, error) {
l := logic.NewDeleteOperationRecordLogic(ctx, s.svcCtx)
return l.DeleteOperationRecord(in)
+22 -4
View File
@@ -1,6 +1,8 @@
package svc
import (
"time"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/internal/config"
@@ -17,20 +19,36 @@ type ServiceContext struct {
func NewServiceContext(c config.Config) *ServiceContext {
db, err := gorm.Open(mysql.Open(c.DB.DataSource), &gorm.Config{})
if err != nil {
logx.Errorf("连接数据库失败: %v", err)
logx.Errorf("[system-rpc] ❌ 连接数据库失败: %v", err)
panic(err)
}
// 配置连接池,防止高并发耗尽连接
sqlDB, err := db.DB()
if err != nil {
logx.Errorf("[system-rpc] ❌ 获取底层 DB 失败: %v", err)
panic(err)
}
sqlDB.SetMaxOpenConns(100)
sqlDB.SetMaxIdleConns(20)
sqlDB.SetConnMaxLifetime(time.Hour)
logx.Infof("[system-rpc] ✅ 数据库连接成功 | MaxOpen=100 MaxIdle=20")
// 自动迁移
if err := db.AutoMigrate(
tables := []interface{}{
&sysModel.SundynixClient{},
&sysModel.SundynixRole{},
&sysModel.SundynixMenu{},
&sysModel.SundynixRoleMenu{},
&sysModel.SundynixOperationRecord{},
&sysModel.SundynixDict{},
); err != nil {
logx.Errorf("数据库迁移失败: %v", err)
&sysModel.SundynixUser{},
&sysModel.SundynixUserRole{},
}
if err := db.AutoMigrate(tables...); err != nil {
logx.Errorf("[system-rpc] ⚠️ 数据库迁移失败: %v", err)
} else {
logx.Infof("[system-rpc] ✅ 数据库迁移完成 | 表数量: %d", len(tables))
}
return &ServiceContext{
+133 -8
View File
@@ -185,16 +185,32 @@ message DictListResp {
message OperationRecordInfo {
string id = 1;
string clientId = 2;
string ip = 3;
string method = 4;
string path = 5;
int32 status = 6;
int64 latency = 7;
string agent = 8;
string errorMessage = 9;
string body = 10;
string resp = 11;
string userId = 12;
int64 createdAt = 13;
}
message CreateOperationRecordReq {
string clientId = 1;
string ip = 2;
string method = 3;
string path = 4;
int32 status = 5;
string agent = 6;
string errorMessage = 7;
string body = 8;
string resp = 9;
string userId = 10;
int64 createdAt = 11;
int64 latency = 6;
string agent = 7;
string errorMessage = 8;
string body = 9;
string resp = 10;
string userId = 11;
}
message OperationRecordListReq {
@@ -210,7 +226,105 @@ message OperationRecordListResp {
int64 total = 2;
}
// ========== 请求/响应(原有) ==========
// ========== 用户 ==========
message UserInfo {
string id = 1;
string tenantId = 2;
string clientId = 3;
string name = 4;
string account = 5;
string nickName = 6;
string phone = 7;
string sessionKey = 8;
string unionId = 9;
string openId = 10;
string saOpenId = 11;
string avatarId = 12;
int32 gender = 13;
string country = 14;
string province = 15;
string city = 16;
string language = 17;
int32 isVip = 18;
int64 vipExpireAt = 19;
string lastLoginIp = 20;
int64 lastLoginAt = 21;
int64 createdAt = 22;
int64 updatedAt = 23;
string avatarUrl = 24;
}
message GetUserByIdReq {
string id = 1;
}
message GetUserByIdResp {
UserInfo user = 1;
}
message GetUserByOpenIdReq {
string openId = 1;
}
message GetUserByOpenIdResp {
UserInfo user = 1;
}
message CreateUserReq {
string name = 1;
string account = 2;
string password = 3;
string openId = 4;
string sessionKey = 5;
string clientId = 6;
string phone = 7;
}
message CreateUserResp {
UserInfo user = 1;
}
message UpdateUserReq {
string id = 1;
string name = 2;
string account = 3;
string phone = 4;
string avatarId = 5;
string nickName = 6;
}
message LoginByAccountReq {
string account = 1;
string password = 2;
}
message LoginByAccountResp {
UserInfo user = 1;
}
message GetUserListReq {
int32 current = 1;
int32 pageSize = 2;
string name = 3;
string account = 4;
}
message GetUserListResp {
repeated UserInfo list = 1;
int64 total = 2;
}
message DeleteUserReq {
repeated string ids = 1;
}
message ResetPasswordReq {
string id = 1;
string password = 2;
}
// ========== 请求/响应(跨模块) ==========
message GetRolesByUserIdReq {
string userId = 1;
@@ -239,6 +353,16 @@ message GetClientByIdResp {
// ========== 服务定义 ==========
service SystemService {
// --- 用户 ---
rpc GetUserById(GetUserByIdReq) returns (GetUserByIdResp);
rpc GetUserByOpenId(GetUserByOpenIdReq) returns (GetUserByOpenIdResp);
rpc LoginByAccount(LoginByAccountReq) returns (LoginByAccountResp);
rpc CreateUser(CreateUserReq) returns (CreateUserResp);
rpc UpdateUser(UpdateUserReq) returns (CommonResp);
rpc GetUserList(GetUserListReq) returns (GetUserListResp);
rpc DeleteUser(DeleteUserReq) returns (CommonResp);
rpc ResetPassword(ResetPasswordReq) returns (CommonResp);
// --- 角色 ---
rpc GetRolesByUserId(GetRolesByUserIdReq) returns (GetRolesByUserIdResp);
rpc CreateRole(RoleReq) returns (CommonResp);
@@ -251,7 +375,7 @@ service SystemService {
rpc CreateMenu(MenuReq) returns (CommonResp);
rpc UpdateMenu(MenuUpdateReq) returns (CommonResp);
rpc DeleteMenu(IdsReq) returns (CommonResp);
rpc GetMenuList(IdReq) returns (MenuListResp); // 传空id返回全部树
rpc GetMenuList(IdReq) returns (MenuListResp);
// --- 客户端 ---
rpc GetClientById(GetClientByIdReq) returns (GetClientByIdResp);
@@ -267,6 +391,7 @@ service SystemService {
rpc GetDictList(DictListReq) returns (DictListResp);
// --- 操作日志 ---
rpc CreateOperationRecord(CreateOperationRecordReq) returns (CommonResp);
rpc DeleteOperationRecord(IdsReq) returns (CommonResp);
rpc GetOperationRecordList(OperationRecordListReq) returns (OperationRecordListResp);
}
+2
View File
@@ -11,6 +11,7 @@ import (
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/core/service"
"github.com/zeromicro/go-zero/core/stat"
"github.com/zeromicro/go-zero/zrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
@@ -20,6 +21,7 @@ var configFile = flag.String("f", "etc/system.yaml", "the config file")
func main() {
flag.Parse()
stat.DisableLog()
var c config.Config
conf.MustLoad(*configFile, &c)
File diff suppressed because it is too large Load Diff
+344
View File
@@ -19,6 +19,14 @@ import (
const _ = grpc.SupportPackageIsVersion9
const (
SystemService_GetUserById_FullMethodName = "/system.SystemService/GetUserById"
SystemService_GetUserByOpenId_FullMethodName = "/system.SystemService/GetUserByOpenId"
SystemService_LoginByAccount_FullMethodName = "/system.SystemService/LoginByAccount"
SystemService_CreateUser_FullMethodName = "/system.SystemService/CreateUser"
SystemService_UpdateUser_FullMethodName = "/system.SystemService/UpdateUser"
SystemService_GetUserList_FullMethodName = "/system.SystemService/GetUserList"
SystemService_DeleteUser_FullMethodName = "/system.SystemService/DeleteUser"
SystemService_ResetPassword_FullMethodName = "/system.SystemService/ResetPassword"
SystemService_GetRolesByUserId_FullMethodName = "/system.SystemService/GetRolesByUserId"
SystemService_CreateRole_FullMethodName = "/system.SystemService/CreateRole"
SystemService_UpdateRole_FullMethodName = "/system.SystemService/UpdateRole"
@@ -38,6 +46,7 @@ const (
SystemService_UpdateDict_FullMethodName = "/system.SystemService/UpdateDict"
SystemService_DeleteDict_FullMethodName = "/system.SystemService/DeleteDict"
SystemService_GetDictList_FullMethodName = "/system.SystemService/GetDictList"
SystemService_CreateOperationRecord_FullMethodName = "/system.SystemService/CreateOperationRecord"
SystemService_DeleteOperationRecord_FullMethodName = "/system.SystemService/DeleteOperationRecord"
SystemService_GetOperationRecordList_FullMethodName = "/system.SystemService/GetOperationRecordList"
)
@@ -46,6 +55,15 @@ const (
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SystemServiceClient interface {
// --- 用户 ---
GetUserById(ctx context.Context, in *GetUserByIdReq, opts ...grpc.CallOption) (*GetUserByIdResp, error)
GetUserByOpenId(ctx context.Context, in *GetUserByOpenIdReq, opts ...grpc.CallOption) (*GetUserByOpenIdResp, error)
LoginByAccount(ctx context.Context, in *LoginByAccountReq, opts ...grpc.CallOption) (*LoginByAccountResp, error)
CreateUser(ctx context.Context, in *CreateUserReq, opts ...grpc.CallOption) (*CreateUserResp, error)
UpdateUser(ctx context.Context, in *UpdateUserReq, opts ...grpc.CallOption) (*CommonResp, error)
GetUserList(ctx context.Context, in *GetUserListReq, opts ...grpc.CallOption) (*GetUserListResp, error)
DeleteUser(ctx context.Context, in *DeleteUserReq, opts ...grpc.CallOption) (*CommonResp, error)
ResetPassword(ctx context.Context, in *ResetPasswordReq, opts ...grpc.CallOption) (*CommonResp, error)
// --- 角色 ---
GetRolesByUserId(ctx context.Context, in *GetRolesByUserIdReq, opts ...grpc.CallOption) (*GetRolesByUserIdResp, error)
CreateRole(ctx context.Context, in *RoleReq, opts ...grpc.CallOption) (*CommonResp, error)
@@ -70,6 +88,7 @@ type SystemServiceClient interface {
DeleteDict(ctx context.Context, in *IdsReq, opts ...grpc.CallOption) (*CommonResp, error)
GetDictList(ctx context.Context, in *DictListReq, opts ...grpc.CallOption) (*DictListResp, error)
// --- 操作日志 ---
CreateOperationRecord(ctx context.Context, in *CreateOperationRecordReq, opts ...grpc.CallOption) (*CommonResp, error)
DeleteOperationRecord(ctx context.Context, in *IdsReq, opts ...grpc.CallOption) (*CommonResp, error)
GetOperationRecordList(ctx context.Context, in *OperationRecordListReq, opts ...grpc.CallOption) (*OperationRecordListResp, error)
}
@@ -82,6 +101,86 @@ func NewSystemServiceClient(cc grpc.ClientConnInterface) SystemServiceClient {
return &systemServiceClient{cc}
}
func (c *systemServiceClient) GetUserById(ctx context.Context, in *GetUserByIdReq, opts ...grpc.CallOption) (*GetUserByIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetUserByIdResp)
err := c.cc.Invoke(ctx, SystemService_GetUserById_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) GetUserByOpenId(ctx context.Context, in *GetUserByOpenIdReq, opts ...grpc.CallOption) (*GetUserByOpenIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetUserByOpenIdResp)
err := c.cc.Invoke(ctx, SystemService_GetUserByOpenId_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) LoginByAccount(ctx context.Context, in *LoginByAccountReq, opts ...grpc.CallOption) (*LoginByAccountResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(LoginByAccountResp)
err := c.cc.Invoke(ctx, SystemService_LoginByAccount_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) CreateUser(ctx context.Context, in *CreateUserReq, opts ...grpc.CallOption) (*CreateUserResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CreateUserResp)
err := c.cc.Invoke(ctx, SystemService_CreateUser_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) UpdateUser(ctx context.Context, in *UpdateUserReq, opts ...grpc.CallOption) (*CommonResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CommonResp)
err := c.cc.Invoke(ctx, SystemService_UpdateUser_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) GetUserList(ctx context.Context, in *GetUserListReq, opts ...grpc.CallOption) (*GetUserListResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetUserListResp)
err := c.cc.Invoke(ctx, SystemService_GetUserList_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) DeleteUser(ctx context.Context, in *DeleteUserReq, opts ...grpc.CallOption) (*CommonResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CommonResp)
err := c.cc.Invoke(ctx, SystemService_DeleteUser_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) ResetPassword(ctx context.Context, in *ResetPasswordReq, opts ...grpc.CallOption) (*CommonResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CommonResp)
err := c.cc.Invoke(ctx, SystemService_ResetPassword_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) GetRolesByUserId(ctx context.Context, in *GetRolesByUserIdReq, opts ...grpc.CallOption) (*GetRolesByUserIdResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetRolesByUserIdResp)
@@ -272,6 +371,16 @@ func (c *systemServiceClient) GetDictList(ctx context.Context, in *DictListReq,
return out, nil
}
func (c *systemServiceClient) CreateOperationRecord(ctx context.Context, in *CreateOperationRecordReq, opts ...grpc.CallOption) (*CommonResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CommonResp)
err := c.cc.Invoke(ctx, SystemService_CreateOperationRecord_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *systemServiceClient) DeleteOperationRecord(ctx context.Context, in *IdsReq, opts ...grpc.CallOption) (*CommonResp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CommonResp)
@@ -296,6 +405,15 @@ func (c *systemServiceClient) GetOperationRecordList(ctx context.Context, in *Op
// All implementations must embed UnimplementedSystemServiceServer
// for forward compatibility.
type SystemServiceServer interface {
// --- 用户 ---
GetUserById(context.Context, *GetUserByIdReq) (*GetUserByIdResp, error)
GetUserByOpenId(context.Context, *GetUserByOpenIdReq) (*GetUserByOpenIdResp, error)
LoginByAccount(context.Context, *LoginByAccountReq) (*LoginByAccountResp, error)
CreateUser(context.Context, *CreateUserReq) (*CreateUserResp, error)
UpdateUser(context.Context, *UpdateUserReq) (*CommonResp, error)
GetUserList(context.Context, *GetUserListReq) (*GetUserListResp, error)
DeleteUser(context.Context, *DeleteUserReq) (*CommonResp, error)
ResetPassword(context.Context, *ResetPasswordReq) (*CommonResp, error)
// --- 角色 ---
GetRolesByUserId(context.Context, *GetRolesByUserIdReq) (*GetRolesByUserIdResp, error)
CreateRole(context.Context, *RoleReq) (*CommonResp, error)
@@ -320,6 +438,7 @@ type SystemServiceServer interface {
DeleteDict(context.Context, *IdsReq) (*CommonResp, error)
GetDictList(context.Context, *DictListReq) (*DictListResp, error)
// --- 操作日志 ---
CreateOperationRecord(context.Context, *CreateOperationRecordReq) (*CommonResp, error)
DeleteOperationRecord(context.Context, *IdsReq) (*CommonResp, error)
GetOperationRecordList(context.Context, *OperationRecordListReq) (*OperationRecordListResp, error)
mustEmbedUnimplementedSystemServiceServer()
@@ -332,6 +451,30 @@ type SystemServiceServer interface {
// pointer dereference when methods are called.
type UnimplementedSystemServiceServer struct{}
func (UnimplementedSystemServiceServer) GetUserById(context.Context, *GetUserByIdReq) (*GetUserByIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetUserById not implemented")
}
func (UnimplementedSystemServiceServer) GetUserByOpenId(context.Context, *GetUserByOpenIdReq) (*GetUserByOpenIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetUserByOpenId not implemented")
}
func (UnimplementedSystemServiceServer) LoginByAccount(context.Context, *LoginByAccountReq) (*LoginByAccountResp, error) {
return nil, status.Error(codes.Unimplemented, "method LoginByAccount not implemented")
}
func (UnimplementedSystemServiceServer) CreateUser(context.Context, *CreateUserReq) (*CreateUserResp, error) {
return nil, status.Error(codes.Unimplemented, "method CreateUser not implemented")
}
func (UnimplementedSystemServiceServer) UpdateUser(context.Context, *UpdateUserReq) (*CommonResp, error) {
return nil, status.Error(codes.Unimplemented, "method UpdateUser not implemented")
}
func (UnimplementedSystemServiceServer) GetUserList(context.Context, *GetUserListReq) (*GetUserListResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetUserList not implemented")
}
func (UnimplementedSystemServiceServer) DeleteUser(context.Context, *DeleteUserReq) (*CommonResp, error) {
return nil, status.Error(codes.Unimplemented, "method DeleteUser not implemented")
}
func (UnimplementedSystemServiceServer) ResetPassword(context.Context, *ResetPasswordReq) (*CommonResp, error) {
return nil, status.Error(codes.Unimplemented, "method ResetPassword not implemented")
}
func (UnimplementedSystemServiceServer) GetRolesByUserId(context.Context, *GetRolesByUserIdReq) (*GetRolesByUserIdResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetRolesByUserId not implemented")
}
@@ -389,6 +532,9 @@ func (UnimplementedSystemServiceServer) DeleteDict(context.Context, *IdsReq) (*C
func (UnimplementedSystemServiceServer) GetDictList(context.Context, *DictListReq) (*DictListResp, error) {
return nil, status.Error(codes.Unimplemented, "method GetDictList not implemented")
}
func (UnimplementedSystemServiceServer) CreateOperationRecord(context.Context, *CreateOperationRecordReq) (*CommonResp, error) {
return nil, status.Error(codes.Unimplemented, "method CreateOperationRecord not implemented")
}
func (UnimplementedSystemServiceServer) DeleteOperationRecord(context.Context, *IdsReq) (*CommonResp, error) {
return nil, status.Error(codes.Unimplemented, "method DeleteOperationRecord not implemented")
}
@@ -416,6 +562,150 @@ func RegisterSystemServiceServer(s grpc.ServiceRegistrar, srv SystemServiceServe
s.RegisterService(&SystemService_ServiceDesc, srv)
}
func _SystemService_GetUserById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetUserByIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).GetUserById(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_GetUserById_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).GetUserById(ctx, req.(*GetUserByIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_GetUserByOpenId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetUserByOpenIdReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).GetUserByOpenId(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_GetUserByOpenId_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).GetUserByOpenId(ctx, req.(*GetUserByOpenIdReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_LoginByAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(LoginByAccountReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).LoginByAccount(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_LoginByAccount_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).LoginByAccount(ctx, req.(*LoginByAccountReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_CreateUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateUserReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).CreateUser(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_CreateUser_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).CreateUser(ctx, req.(*CreateUserReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_UpdateUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateUserReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).UpdateUser(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_UpdateUser_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).UpdateUser(ctx, req.(*UpdateUserReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_GetUserList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetUserListReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).GetUserList(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_GetUserList_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).GetUserList(ctx, req.(*GetUserListReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_DeleteUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeleteUserReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).DeleteUser(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_DeleteUser_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).DeleteUser(ctx, req.(*DeleteUserReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_ResetPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ResetPasswordReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).ResetPassword(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_ResetPassword_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).ResetPassword(ctx, req.(*ResetPasswordReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_GetRolesByUserId_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetRolesByUserIdReq)
if err := dec(in); err != nil {
@@ -758,6 +1048,24 @@ func _SystemService_GetDictList_Handler(srv interface{}, ctx context.Context, de
return interceptor(ctx, in, info, handler)
}
func _SystemService_CreateOperationRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreateOperationRecordReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SystemServiceServer).CreateOperationRecord(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: SystemService_CreateOperationRecord_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SystemServiceServer).CreateOperationRecord(ctx, req.(*CreateOperationRecordReq))
}
return interceptor(ctx, in, info, handler)
}
func _SystemService_DeleteOperationRecord_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(IdsReq)
if err := dec(in); err != nil {
@@ -801,6 +1109,38 @@ var SystemService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "system.SystemService",
HandlerType: (*SystemServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetUserById",
Handler: _SystemService_GetUserById_Handler,
},
{
MethodName: "GetUserByOpenId",
Handler: _SystemService_GetUserByOpenId_Handler,
},
{
MethodName: "LoginByAccount",
Handler: _SystemService_LoginByAccount_Handler,
},
{
MethodName: "CreateUser",
Handler: _SystemService_CreateUser_Handler,
},
{
MethodName: "UpdateUser",
Handler: _SystemService_UpdateUser_Handler,
},
{
MethodName: "GetUserList",
Handler: _SystemService_GetUserList_Handler,
},
{
MethodName: "DeleteUser",
Handler: _SystemService_DeleteUser_Handler,
},
{
MethodName: "ResetPassword",
Handler: _SystemService_ResetPassword_Handler,
},
{
MethodName: "GetRolesByUserId",
Handler: _SystemService_GetRolesByUserId_Handler,
@@ -877,6 +1217,10 @@ var SystemService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetDictList",
Handler: _SystemService_GetDictList_Handler,
},
{
MethodName: "CreateOperationRecord",
Handler: _SystemService_CreateOperationRecord_Handler,
},
{
MethodName: "DeleteOperationRecord",
Handler: _SystemService_DeleteOperationRecord_Handler,
+102 -31
View File
@@ -14,39 +14,63 @@ import (
)
type (
ClientInfo = system.ClientInfo
ClientListReq = system.ClientListReq
ClientListResp = system.ClientListResp
ClientReq = system.ClientReq
ClientUpdateReq = system.ClientUpdateReq
CommonResp = system.CommonResp
DictInfo = system.DictInfo
DictListReq = system.DictListReq
DictListResp = system.DictListResp
DictReq = system.DictReq
DictUpdateReq = system.DictUpdateReq
GetClientByIdReq = system.GetClientByIdReq
GetClientByIdResp = system.GetClientByIdResp
GetMenusByRoleIdReq = system.GetMenusByRoleIdReq
GetMenusByRoleIdResp = system.GetMenusByRoleIdResp
GetRolesByUserIdReq = system.GetRolesByUserIdReq
GetRolesByUserIdResp = system.GetRolesByUserIdResp
IdReq = system.IdReq
IdsReq = system.IdsReq
MenuInfo = system.MenuInfo
MenuListResp = system.MenuListResp
MenuReq = system.MenuReq
MenuUpdateReq = system.MenuUpdateReq
OperationRecordInfo = system.OperationRecordInfo
OperationRecordListReq = system.OperationRecordListReq
OperationRecordListResp = system.OperationRecordListResp
RoleInfo = system.RoleInfo
RoleListReq = system.RoleListReq
RoleListResp = system.RoleListResp
RoleReq = system.RoleReq
RoleUpdateReq = system.RoleUpdateReq
ClientInfo = system.ClientInfo
ClientListReq = system.ClientListReq
ClientListResp = system.ClientListResp
ClientReq = system.ClientReq
ClientUpdateReq = system.ClientUpdateReq
CommonResp = system.CommonResp
CreateOperationRecordReq = system.CreateOperationRecordReq
CreateUserReq = system.CreateUserReq
CreateUserResp = system.CreateUserResp
DeleteUserReq = system.DeleteUserReq
DictInfo = system.DictInfo
DictListReq = system.DictListReq
DictListResp = system.DictListResp
DictReq = system.DictReq
DictUpdateReq = system.DictUpdateReq
GetClientByIdReq = system.GetClientByIdReq
GetClientByIdResp = system.GetClientByIdResp
GetMenusByRoleIdReq = system.GetMenusByRoleIdReq
GetMenusByRoleIdResp = system.GetMenusByRoleIdResp
GetRolesByUserIdReq = system.GetRolesByUserIdReq
GetRolesByUserIdResp = system.GetRolesByUserIdResp
GetUserByIdReq = system.GetUserByIdReq
GetUserByIdResp = system.GetUserByIdResp
GetUserByOpenIdReq = system.GetUserByOpenIdReq
GetUserByOpenIdResp = system.GetUserByOpenIdResp
GetUserListReq = system.GetUserListReq
GetUserListResp = system.GetUserListResp
IdReq = system.IdReq
IdsReq = system.IdsReq
LoginByAccountReq = system.LoginByAccountReq
LoginByAccountResp = system.LoginByAccountResp
MenuInfo = system.MenuInfo
MenuListResp = system.MenuListResp
MenuReq = system.MenuReq
MenuUpdateReq = system.MenuUpdateReq
OperationRecordInfo = system.OperationRecordInfo
OperationRecordListReq = system.OperationRecordListReq
OperationRecordListResp = system.OperationRecordListResp
ResetPasswordReq = system.ResetPasswordReq
RoleInfo = system.RoleInfo
RoleListReq = system.RoleListReq
RoleListResp = system.RoleListResp
RoleReq = system.RoleReq
RoleUpdateReq = system.RoleUpdateReq
UpdateUserReq = system.UpdateUserReq
UserInfo = system.UserInfo
SystemService interface {
// --- 用户 ---
GetUserById(ctx context.Context, in *GetUserByIdReq, opts ...grpc.CallOption) (*GetUserByIdResp, error)
GetUserByOpenId(ctx context.Context, in *GetUserByOpenIdReq, opts ...grpc.CallOption) (*GetUserByOpenIdResp, error)
LoginByAccount(ctx context.Context, in *LoginByAccountReq, opts ...grpc.CallOption) (*LoginByAccountResp, error)
CreateUser(ctx context.Context, in *CreateUserReq, opts ...grpc.CallOption) (*CreateUserResp, error)
UpdateUser(ctx context.Context, in *UpdateUserReq, opts ...grpc.CallOption) (*CommonResp, error)
GetUserList(ctx context.Context, in *GetUserListReq, opts ...grpc.CallOption) (*GetUserListResp, error)
DeleteUser(ctx context.Context, in *DeleteUserReq, opts ...grpc.CallOption) (*CommonResp, error)
ResetPassword(ctx context.Context, in *ResetPasswordReq, opts ...grpc.CallOption) (*CommonResp, error)
// --- 角色 ---
GetRolesByUserId(ctx context.Context, in *GetRolesByUserIdReq, opts ...grpc.CallOption) (*GetRolesByUserIdResp, error)
CreateRole(ctx context.Context, in *RoleReq, opts ...grpc.CallOption) (*CommonResp, error)
@@ -71,6 +95,7 @@ type (
DeleteDict(ctx context.Context, in *IdsReq, opts ...grpc.CallOption) (*CommonResp, error)
GetDictList(ctx context.Context, in *DictListReq, opts ...grpc.CallOption) (*DictListResp, error)
// --- 操作日志 ---
CreateOperationRecord(ctx context.Context, in *CreateOperationRecordReq, opts ...grpc.CallOption) (*CommonResp, error)
DeleteOperationRecord(ctx context.Context, in *IdsReq, opts ...grpc.CallOption) (*CommonResp, error)
GetOperationRecordList(ctx context.Context, in *OperationRecordListReq, opts ...grpc.CallOption) (*OperationRecordListResp, error)
}
@@ -86,6 +111,47 @@ func NewSystemService(cli zrpc.Client) SystemService {
}
}
// --- 用户 ---
func (m *defaultSystemService) GetUserById(ctx context.Context, in *GetUserByIdReq, opts ...grpc.CallOption) (*GetUserByIdResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.GetUserById(ctx, in, opts...)
}
func (m *defaultSystemService) GetUserByOpenId(ctx context.Context, in *GetUserByOpenIdReq, opts ...grpc.CallOption) (*GetUserByOpenIdResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.GetUserByOpenId(ctx, in, opts...)
}
func (m *defaultSystemService) LoginByAccount(ctx context.Context, in *LoginByAccountReq, opts ...grpc.CallOption) (*LoginByAccountResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.LoginByAccount(ctx, in, opts...)
}
func (m *defaultSystemService) CreateUser(ctx context.Context, in *CreateUserReq, opts ...grpc.CallOption) (*CreateUserResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.CreateUser(ctx, in, opts...)
}
func (m *defaultSystemService) UpdateUser(ctx context.Context, in *UpdateUserReq, opts ...grpc.CallOption) (*CommonResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.UpdateUser(ctx, in, opts...)
}
func (m *defaultSystemService) GetUserList(ctx context.Context, in *GetUserListReq, opts ...grpc.CallOption) (*GetUserListResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.GetUserList(ctx, in, opts...)
}
func (m *defaultSystemService) DeleteUser(ctx context.Context, in *DeleteUserReq, opts ...grpc.CallOption) (*CommonResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.DeleteUser(ctx, in, opts...)
}
func (m *defaultSystemService) ResetPassword(ctx context.Context, in *ResetPasswordReq, opts ...grpc.CallOption) (*CommonResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.ResetPassword(ctx, in, opts...)
}
// --- 角色 ---
func (m *defaultSystemService) GetRolesByUserId(ctx context.Context, in *GetRolesByUserIdReq, opts ...grpc.CallOption) (*GetRolesByUserIdResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
@@ -186,6 +252,11 @@ func (m *defaultSystemService) GetDictList(ctx context.Context, in *DictListReq,
}
// --- 操作日志 ---
func (m *defaultSystemService) CreateOperationRecord(ctx context.Context, in *CreateOperationRecordReq, opts ...grpc.CallOption) (*CommonResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.CreateOperationRecord(ctx, in, opts...)
}
func (m *defaultSystemService) DeleteOperationRecord(ctx context.Context, in *IdsReq, opts ...grpc.CallOption) (*CommonResp, error) {
client := system.NewSystemServiceClient(m.cli.Conn())
return client.DeleteOperationRecord(ctx, in, opts...)