|
@@ -4,15 +4,16 @@ import (
|
|
|
"context"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
+ "kpt-tmr-group/model"
|
|
|
+ "net/http"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+
|
|
|
operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
|
|
|
"gitee.com/xuyiping_admin/pkg/jwt"
|
|
|
"gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
"gitee.com/xuyiping_admin/pkg/tool"
|
|
|
"gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
- "kpt-tmr-group/model"
|
|
|
- "net/http"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
@@ -51,28 +52,27 @@ func (s *StoreEntry) Auth(ctx context.Context, auth *operationPb.UserAuthData) (
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) GetCurrentUserName(ctx context.Context) (string, error) {
|
|
|
+func (s *StoreEntry) GetCurrentUserName(ctx context.Context) string {
|
|
|
userNameInter := ctx.Value(CurrentUserName)
|
|
|
if userNameInter == nil {
|
|
|
- return "", xerr.Customf("cannot userName")
|
|
|
+ zaplog.Error("GetCurrentUserName", zap.String("userNameInter", "cannot userName"))
|
|
|
+ return ""
|
|
|
}
|
|
|
|
|
|
if userName, ok := userNameInter.(string); ok {
|
|
|
- return userName, nil
|
|
|
+ return userName
|
|
|
} else {
|
|
|
- return "", xerr.Customf("waring userName")
|
|
|
+ zaplog.Error("GetCurrentUserName", zap.String("userNameInter", "waring userName"))
|
|
|
+ return ""
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// GetUserInfo 获取用户信息
|
|
|
-func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error) {
|
|
|
+func (s *StoreEntry) GetUserInfo(ctx context.Context) (*operationPb.UserAuth, error) {
|
|
|
systemUser := &model.SystemUser{}
|
|
|
- userName, err := s.GetCurrentUserName(ctx)
|
|
|
- if err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
+ userName := s.GetCurrentUserName(ctx)
|
|
|
|
|
|
- if err = s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
|
|
|
+ if err := s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
@@ -86,12 +86,12 @@ func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationP
|
|
|
roleIds = append(roleIds, roleId)
|
|
|
}
|
|
|
|
|
|
- if err = s.DB.Model(new(model.SystemGroupPasturePermissions)).Select("DISTINCT(group_pasture.id) AS did, group_pasture.id as id,group_pasture.name as name").
|
|
|
+ if err := s.DB.Model(new(model.SystemGroupPasturePermissions)).Select("DISTINCT(group_pasture.id) AS did, group_pasture.id as id,group_pasture.name as name").
|
|
|
Where("system_group_pasture_permissions.role_id IN ?", roleIds).Where("system_group_pasture_permissions.is_show = ?", operationPb.IsShow_OK).
|
|
|
Joins("right join group_pasture on system_group_pasture_permissions.pasture_id = group_pasture.id").Find(&pastureList).Debug().Error; err != nil {
|
|
|
}
|
|
|
|
|
|
- if err = s.DB.Find(&systemRole, roleIds).Error; err != nil {
|
|
|
+ if err := s.DB.Find(&systemRole, roleIds).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
}
|
|
@@ -101,13 +101,12 @@ func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationP
|
|
|
|
|
|
// CreateSystemUser 创建系统用户
|
|
|
func (s *StoreEntry) CreateSystemUser(ctx context.Context, req *operationPb.AddSystemUser) error {
|
|
|
-
|
|
|
systemUsers := &model.SystemUser{
|
|
|
Name: req.Name,
|
|
|
EmployeeName: req.EmployeeName,
|
|
|
Phone: req.Phone,
|
|
|
Password: tool.Md5String(model.InitManagerPassword),
|
|
|
- CreateUser: req.CreateUser,
|
|
|
+ CreateUser: s.GetCurrentUserName(ctx),
|
|
|
IsShow: operationPb.IsShow_OK,
|
|
|
IsDelete: operationPb.IsShow_OK,
|
|
|
}
|
|
@@ -262,15 +261,12 @@ func (s *StoreEntry) IsShowSystemUser(ctx context.Context, req *operationPb.IsSh
|
|
|
}
|
|
|
|
|
|
// GetSystemUserPermissions 返回系统用户相关菜单权限
|
|
|
-func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string) (*operationPb.SystemUserMenuPermissions, error) {
|
|
|
+func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context) (*operationPb.SystemUserMenuPermissions, error) {
|
|
|
// 解析token
|
|
|
- userName, err := s.GetCurrentUserName(ctx)
|
|
|
- if err != nil {
|
|
|
- return nil, xerr.WithStack(err)
|
|
|
- }
|
|
|
+ userName := s.GetCurrentUserName(ctx)
|
|
|
// 根据用户token获取用户数据
|
|
|
systemUser := &model.SystemUser{Name: userName}
|
|
|
- if err = s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
|
|
|
+ if err := s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
return nil, xerr.Custom("该用户数据不存在")
|
|
|
}
|
|
@@ -280,7 +276,7 @@ func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string)
|
|
|
|
|
|
// 获取用户角色数据
|
|
|
systemRoles := make([]*model.SystemRole, 0)
|
|
|
- if err = s.DB.Where("is_show = ?", operationPb.IsShow_OK).Find(&systemRoles, roleIds).Error; err != nil {
|
|
|
+ if err := s.DB.Where("is_show = ?", operationPb.IsShow_OK).Find(&systemRoles, roleIds).Error; err != nil {
|
|
|
return nil, xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
@@ -321,6 +317,7 @@ func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string)
|
|
|
func (s *StoreEntry) CreateSystemRole(ctx context.Context, req *operationPb.AddRoleRequest) error {
|
|
|
if err := s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
// 创建角色数据
|
|
|
+ req.CreateUser = s.GetCurrentUserName(ctx)
|
|
|
role := model.NewSystemRole(req)
|
|
|
if err := tx.Create(role).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|