Browse Source

syste_user: 系统设置-用户管理

Yi 1 year ago
parent
commit
b0af64ab17

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240401040019-3fb9a6003d30
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240402084550-7d66da05ebce
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/getsentry/sentry-go v0.23.0

+ 8 - 0
go.sum

@@ -56,6 +56,14 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240329090614-8d1695394747 h1:nZe/zepM
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240329090614-8d1695394747/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240401040019-3fb9a6003d30 h1:R80acl0/nOILonC3X86X6H5QlqFN7cBX4wnTpKUcBvw=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240401040019-3fb9a6003d30/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402020613-ef0dd52fe945 h1:Zt7Jr66rrzpQgthmZhJNAG+VBJWNdIYBeUU/hsIg4AU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402020613-ef0dd52fe945/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402022220-80c8e03da1c5 h1:2xCXNhFV8gEKsCVqk8eIzwEN9l08PKhw2HRVsiU8QKM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402022220-80c8e03da1c5/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402030013-33c4fbabf0f5 h1:rJCO0qqvOhqan+uz3tOOO4jX5yEi2VLoXxiEX5o3iRY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402030013-33c4fbabf0f5/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402084550-7d66da05ebce h1:HxA+zjiJdYNCK4iu3y1s0sfzOQkdhZ0PPwGOiKowdV0=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240402084550-7d66da05ebce/go.mod h1:x47UOU+lOkZnrtAENAsOGd7mZ5I8D2JRkMKMqLLRlVw=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015 h1:dfb5dRd57L2HKjdwLT93UFmPYFPOmEl56gtZmqcNnaE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015/go.mod h1:Fk4GYI/v0IK3XFrm1Gn+VkgCz5Y7mfswD5hsTJYOG6A=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 25 - 60
http/handler/system/user.go

@@ -38,9 +38,9 @@ func Login(c *gin.Context) {
 	ginutil.JSONResp(c, res)
 }
 
-// AddSystemUser 创建系统用户
-func AddSystemUser(c *gin.Context) {
-	var req operationPb.AddSystemUser
+// UserCreateOrUpdate 创建系统用户
+func UserCreateOrUpdate(c *gin.Context) {
+	var req pasturePb.SearchUserRequest
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -48,17 +48,14 @@ func AddSystemUser(c *gin.Context) {
 
 	if err := valid.ValidateStruct(&req,
 		valid.Field(&req.Name, valid.Required),
-		valid.Field(&req.Phone, valid.Required),
-		valid.Field(&req.EmployeeName, valid.Required),
-		valid.Field(&req.Roles, valid.NotNil),
-		valid.Field(&req.IsShow, valid.Max(2), valid.Min(1)),
-		valid.Field(&req.CreateUser, valid.Required),
+		valid.Field(&req.DeptId, valid.Required),
+		valid.Field(&req.Mobile, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
-	if err := middleware.Dependency(c).StoreEventHub.OpsService.CreateSystemUser(c, &req); err != nil {
+	if err := middleware.Dependency(c).StoreEventHub.OpsService.SystemUserCreateOrUpdate(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}
@@ -106,7 +103,7 @@ func GetUserInfo(c *gin.Context) {
 
 // SearchSystemUserList 查询系统用户列表
 func SearchSystemUserList(c *gin.Context) {
-	var req operationPb.SearchUserRequest
+	var req pasturePb.SearchUserRequest
 	if err := ginutil.BindProto(c, &req); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -119,7 +116,7 @@ func SearchSystemUserList(c *gin.Context) {
 		return
 	}
 
-	req.Pagination = &operationPb.PaginationModel{
+	req.Pagination = &pasturePb.PaginationModel{
 		Page:       int32(c.GetInt(middleware.Page)),
 		PageSize:   int32(c.GetInt(middleware.PageSize)),
 		PageOffset: int32(c.GetInt(middleware.PageOffset)),
@@ -133,40 +130,9 @@ func SearchSystemUserList(c *gin.Context) {
 	ginutil.JSONResp(c, res)
 }
 
-// EditSystemUser 编辑系统用户
-func EditSystemUser(c *gin.Context) {
-	var req operationPb.AddSystemUser
-	if err := ginutil.BindProto(c, &req); err != nil {
-		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
-		return
-	}
-
-	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.Id, valid.Required, valid.Min(1)),
-		valid.Field(&req.Name, valid.Required),
-		valid.Field(&req.Phone, valid.Required),
-		valid.Field(&req.EmployeeName, valid.Required),
-		valid.Field(&req.Roles, valid.Required),
-		valid.Field(&req.CreateUser, valid.Required),
-	); err != nil {
-		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
-		return
-	}
-
-	if err := middleware.Dependency(c).StoreEventHub.OpsService.EditSystemUser(c, &req); err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-	ginutil.JSONResp(c, &operationPb.CommonOK{
-		Code: http.StatusOK,
-		Msg:  "ok",
-		Data: &operationPb.Success{Success: true},
-	})
-}
-
 // DeleteUser 删除系统用户
 func DeleteUser(c *gin.Context) {
-	userIdStr := c.Param("user_id")
+	userIdStr := c.Param("id")
 	userId, _ := strconv.Atoi(userIdStr)
 
 	if err := valid.Validate(userId, valid.Required, valid.Min(1)); err != nil {
@@ -188,21 +154,14 @@ func DeleteUser(c *gin.Context) {
 
 // IsShowSystemUser 系统用户启动开关
 func IsShowSystemUser(c *gin.Context) {
-	var req operationPb.IsShowSystemUserRequest
-	if err := ginutil.BindProto(c, &req); err != nil {
-		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
-		return
-	}
+	userIdStr := c.Param("id")
+	userId, _ := strconv.Atoi(userIdStr)
 
-	if err := valid.ValidateStruct(&req,
-		valid.Field(&req.UserId, valid.Required, valid.Min(1)),
-		valid.Field(&req.IsShow, valid.Required, valid.Min(1), valid.Max(2)),
-	); err != nil {
-		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+	if err := valid.Validate(userId, valid.Required, valid.Min(1)); err != nil {
+		apierr.ClassifiedAbort(c, err)
 		return
 	}
-
-	if err := middleware.Dependency(c).StoreEventHub.OpsService.IsShowSystemUser(c, &req); err != nil {
+	if err := middleware.Dependency(c).StoreEventHub.OpsService.IsShowSystemUser(c, int64(userId)); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}
@@ -231,15 +190,21 @@ func GetSystemUserPermissions(c *gin.Context) {
 
 // ResetPasswordSystemUser 用户密码重置
 func ResetPasswordSystemUser(c *gin.Context) {
-	userIdStr := c.Param("user_id")
-	userId, _ := strconv.Atoi(userIdStr)
+	var req pasturePb.ResetUserPasswordRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
+		return
+	}
 
-	if err := valid.Validate(userId, valid.Required, valid.Min(1)); err != nil {
-		apierr.ClassifiedAbort(c, err)
+	if err := valid.ValidateStruct(&req,
+		valid.Field(&req.Id, valid.Required),
+		valid.Field(&req.Password, valid.Required),
+	); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
-	if err := middleware.BackendOperation(c).OpsService.ResetPasswordSystemUser(c, int64(userId)); err != nil {
+	if err := middleware.BackendOperation(c).OpsService.ResetPasswordSystemUser(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
 	}

+ 10 - 1
http/middleware/log.go

@@ -51,8 +51,17 @@ func GinLogger() gin.HandlerFunc {
 			zap.String("user-agent", c.Request.UserAgent()),
 			zap.String("errors", c.Errors.ByType(gin.ErrorTypePrivate).String()),
 			zap.String("time", cost.String()),
-			zap.String("x-request-id", c.Request.Header.Get("X-Request-Id")),
 		}
+		headers := c.Request.Header
+		var headerList = make(map[string][]string)
+		for k, v := range headers {
+			if headerList[k] == nil {
+				headerList[k] = make([]string, 0)
+			}
+			headerList[k] = v
+		}
+		c.Request.Header = headers
+		logFields = append(logFields, zap.Any("headers", headerList))
 		logFields = append(logFields, zap.String("Request body", string(requestBody)))
 		logFields = append(logFields, zap.String("Response body", w.body.String()))
 		zaplog.Info("Http-Access-Log", logFields...)

+ 1 - 1
http/middleware/pagination.go

@@ -25,7 +25,7 @@ func Pagination() gin.HandlerFunc {
 
 func getSetItem(c *gin.Context, k string, d int) int {
 	var n int
-	if v := c.Query(k); v != "" {
+	if v := c.Request.Header.Get(k); v != "" {
 		if i, err := strconv.Atoi(v); err == nil {
 			if i > 0 {
 				n = i

+ 8 - 8
http/route/system_api.go

@@ -19,18 +19,18 @@ func SystemAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		s.GET("/check", handler.Health)
 		s.POST("/api/v1/login", system.Login)
 
-		// system API 组
-		// 系统用户
+		// system API 组  系统用户
 		systemRoute := authRouteGroup(s, "/api/v1/system/")
+		systemRoute.POST("/user/list", system.SearchSystemUserList)
+		systemRoute.PUT("/user/is_show/:id", system.IsShowSystemUser)
+		systemRoute.DELETE("/user/:id", system.DeleteUser)
+		systemRoute.POST("/user/createOrUpdate", system.UserCreateOrUpdate)
+		systemRoute.POST("/user/rest/password", system.ResetPasswordSystemUser)
+
 		systemRoute.POST("/user_info", system.GetUserInfo)
-		systemRoute.POST("/user/add", system.AddSystemUser)
 		systemRoute.GET("/user/details/:user_id", system.DetailsSystemUser)
-		systemRoute.POST("/user/list", system.SearchSystemUserList)
-		systemRoute.POST("/user/edit", system.EditSystemUser)
-		systemRoute.POST("/user/is_show", system.IsShowSystemUser)
-		systemRoute.DELETE("/user/:user_id", system.DeleteUser)
 		systemRoute.POST("/user/permissions", system.GetSystemUserPermissions)
-		systemRoute.POST("/user/rest_password/:user_id", system.ResetPasswordSystemUser)
+
 		systemRoute.POST("/user/logout", system.LogoutSystemUser)
 
 		// 系统角色

+ 31 - 6
model/system_user.go

@@ -8,7 +8,7 @@ import (
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 )
 
-const InitManagerPassword = "123456"
+const InitManagerPassword = "kpt123456"
 
 type SystemUser struct {
 	Id        int64                  `json:"id"`
@@ -53,15 +53,40 @@ func (s *SystemUser) SystemUserFormat(userRoles []*SystemRole, pastures []*opera
 
 type SystemUserSlice []*SystemUser
 
-func (s SystemUserSlice) ToPB(roleList []*SystemRole) []*operationPb.AddSystemUser {
-	res := make([]*operationPb.AddSystemUser, len(s))
+func (s SystemUserSlice) ToPB(deptList []*SystemDept, roleList []*SystemRole) []*pasturePb.SearchUserRequest {
+	res := make([]*pasturePb.SearchUserRequest, len(s))
 	for i, v := range s {
-		res[i] = &operationPb.AddSystemUser{
+		deptName := ""
+		for _, d := range deptList {
+			if v.DeptId == d.Id {
+				deptName = d.Name
+				break
+			}
+		}
+		roleName := ""
+		for _, r := range roleList {
+			if v.RoleId == r.Id {
+				roleName += r.Name
+				break
+			}
+		}
+
+		res[i] = &pasturePb.SearchUserRequest{
 			Id:              int32(v.Id),
 			Name:            v.Name,
-			CreatedAt:       int32(v.CreatedAt),
+			Mobile:          v.Mobile,
+			NickName:        v.NickName,
+			Avatar:          v.Avatar,
+			Gender:          v.Gender,
+			IsShow:          v.IsShow,
+			IsDelete:        v.IsDelete,
+			Remarks:         v.Remarks,
+			DeptId:          int32(v.DeptId),
+			DeptName:        deptName,
+			RoleId:          int32(v.RoleId),
+			RoleName:        roleName,
 			CreatedAtFormat: time.Unix(v.CreatedAt, 0).Format(LayoutTime),
-			RoleName:        "",
+			UpdatedAtFormat: time.Unix(v.UpdatedAt, 0).Format(LayoutTime),
 		}
 	}
 	return res

+ 6 - 6
module/backend/interface.go

@@ -49,15 +49,15 @@ type KptService interface {
 type SystemService interface {
 	// Login 系统用户相关
 	Login(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SystemUserResponse, error)
+	SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SearchUserResponse, error)
+	IsShowSystemUser(ctx context.Context, userId int64) error
+	DeleteSystemUser(ctx context.Context, userId int64) error
+	SystemUserCreateOrUpdate(ctx context.Context, req *pasturePb.SearchUserRequest) error
+	ResetPasswordSystemUser(ctx context.Context, req *pasturePb.ResetUserPasswordRequest) error
+
 	GetCurrentUserName(ctx context.Context) (string, error)
 	GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error)
-	CreateSystemUser(ctx context.Context, req *operationPb.AddSystemUser) error
-	SearchSystemUserList(ctx context.Context, req *operationPb.SearchUserRequest) (*operationPb.SearchUserResponse, error)
-	EditSystemUser(ctx context.Context, req *operationPb.AddSystemUser) error
-	DeleteSystemUser(ctx context.Context, userId int64) error
-	ResetPasswordSystemUser(ctx context.Context, userId int64) error
 	DetailsSystemUser(ctx context.Context, userId int64) (*operationPb.UserDetails, error)
-	IsShowSystemUser(ctx context.Context, req *operationPb.IsShowSystemUserRequest) error
 	GetSystemUserPermissions(ctx context.Context, token string) (*operationPb.SystemUserMenuPermissions, error)
 
 	// CreateSystemRole 系统角色相关

+ 108 - 102
module/backend/system_service.go

@@ -15,7 +15,6 @@ import (
 	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"
 	"go.uber.org/zap"
 
@@ -63,56 +62,8 @@ func (s *StoreEntry) Login(ctx context.Context, req *pasturePb.SearchUserRequest
 	}, nil
 }
 
-func (s *StoreEntry) GetCurrentUserName(ctx context.Context) (string, error) {
-	userNameInter := ctx.Value(CurrentUserName)
-	if userNameInter == nil {
-		return "", xerr.Customf("cannot userName")
-	}
-
-	if userName, ok := userNameInter.(string); ok {
-		return userName, nil
-	} else {
-		return "", xerr.Customf("waring userName")
-	}
-}
-
-// GetUserInfo 获取用户信息
-func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error) {
-	systemUser := &model.SystemUser{}
-	userName, err := s.GetCurrentUserName(ctx)
-	if err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	if err = s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
-		return nil, xerr.WithStack(err)
-	}
-
-	systemRole := make([]*model.SystemRole, 0)
-	return systemUser.SystemUserFormat(systemRole, nil), nil
-}
-
-// 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,
-		IsShow:       operationPb.IsShow_OK,
-		IsDelete:     operationPb.IsShow_OK,*/
-	}
-	/*systemUsers.SystemUserRoleFormat(req)*/
-
-	if err := s.DB.Create(systemUsers).Error; err != nil {
-		return xerr.WithStack(err)
-	}
-	return nil
-}
-
 // SearchSystemUserList 查询系统用户
-func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *operationPb.SearchUserRequest) (*operationPb.SearchUserResponse, error) {
+func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *pasturePb.SearchUserRequest) (*pasturePb.SearchUserResponse, error) {
 	systemUserList := make([]*model.SystemUser, 0)
 	var count int64 = 0
 
@@ -120,16 +71,17 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *operationPb.
 	if req.Name != "" {
 		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
 	}
-	if req.EmployeeName != "" {
-		pref.Where("employee_name like ?", fmt.Sprintf("%s%s%s", "%", req.EmployeeName, "%"))
+
+	if req.Mobile != "" {
+		pref.Where("mobile = ?", req.Mobile)
 	}
 
-	if req.IsShow > 0 {
-		pref.Where("is_show = ?", req.IsShow)
+	if req.DeptId > 0 {
+		pref.Where("dept_id = ?", req.DeptId)
 	}
 
-	if req.CreatedStartTime > 0 && req.CreatedEndTime > 0 && req.CreatedStartTime <= req.CreatedEndTime {
-		pref.Where("created_at  BETWEEN  ? AND ?", req.CreatedStartTime, req.CreatedEndTime)
+	if req.IsShow > 0 {
+		pref.Where("is_show = ?", req.IsShow)
 	}
 
 	if err := pref.Order("id desc").Count(&count).Limit(int(req.Pagination.PageSize)).Offset(int(req.Pagination.PageOffset)).
@@ -142,46 +94,43 @@ func (s *StoreEntry) SearchSystemUserList(ctx context.Context, req *operationPb.
 		return nil, xerr.WithStack(err)
 	}
 
-	return &operationPb.SearchUserResponse{
-		Code: http.StatusOK,
-		Msg:  "ok",
-		Data: &operationPb.SearchUserData{
-			Page:     req.Pagination.Page,
+	deptList, err := s.SearchSystemDeptListByIds(ctx, []int64{})
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	return &pasturePb.SearchUserResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchUserData{
+			List:     model.SystemUserSlice(systemUserList).ToPB(deptList, roleList),
 			Total:    int32(count),
 			PageSize: req.Pagination.PageSize,
-			List:     model.SystemUserSlice(systemUserList).ToPB(roleList),
+			Page:     req.Pagination.Page,
 		},
 	}, nil
 }
 
-// EditSystemUser 编辑用户
-func (s *StoreEntry) EditSystemUser(ctx context.Context, req *operationPb.AddSystemUser) error {
-	systemUser := &model.SystemUser{Id: int64(req.Id)}
+// DeleteSystemUser 删除系统用户
+func (s *StoreEntry) DeleteSystemUser(ctx context.Context, userId int64) error {
+	systemUser := &model.SystemUser{
+		Id: userId,
+	}
 	if err := s.DB.First(systemUser).Error; err != nil {
 		if errors.Is(err, gorm.ErrRecordNotFound) {
-			return xerr.Custom("该数据不存在!")
+			return xerr.Custom("该用户不存在")
 		}
 		return xerr.WithStack(err)
 	}
 
-	updateData := &model.SystemUser{
-		Name: req.Name,
-		/*EmployeeName: req.EmployeeName,
-		Phone:        req.Phone,*/
-	}
-	/*updateData.SystemUserRoleFormat(req)*/
-
-	if err := s.DB.Model(new(model.SystemUser)).Omit("is_show", "password", "is_delete", "create_user").
-		Where("id = ?", systemUser.Id).
-		Updates(updateData).Error; err != nil {
+	if err := s.DB.Model(systemUser).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
 		return xerr.WithStack(err)
 	}
-
 	return nil
 }
 
-// DeleteSystemUser 删除系统用户
-func (s *StoreEntry) DeleteSystemUser(ctx context.Context, userId int64) error {
+// IsShowSystemUser 用户是否启用
+func (s *StoreEntry) IsShowSystemUser(ctx context.Context, userId int64) error {
 	systemUser := &model.SystemUser{
 		Id: userId,
 	}
@@ -191,17 +140,79 @@ func (s *StoreEntry) DeleteSystemUser(ctx context.Context, userId int64) error {
 		}
 		return xerr.WithStack(err)
 	}
+	isShow := pasturePb.IsShow_No
+	if systemUser.IsShow == pasturePb.IsShow_No {
+		isShow = pasturePb.IsShow_Ok
+	}
 
-	if err := s.DB.Model(systemUser).Update("is_delete", operationPb.IsShow_NO).Error; err != nil {
+	if err := s.DB.Model(systemUser).Update("is_show", isShow).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+	return nil
+}
+
+// GetCurrentUserName 获取当前用户名
+func (s *StoreEntry) GetCurrentUserName(ctx context.Context) (string, error) {
+	userNameInter := ctx.Value(CurrentUserName)
+	if userNameInter == nil {
+		return "", xerr.Customf("cannot userName")
+	}
+
+	if userName, ok := userNameInter.(string); ok {
+		return userName, nil
+	} else {
+		return "", xerr.Customf("waring userName")
+	}
+}
+
+// GetUserInfo 获取用户信息
+func (s *StoreEntry) GetUserInfo(ctx context.Context, token string) (*operationPb.UserAuth, error) {
+	systemUser := &model.SystemUser{}
+	userName, err := s.GetCurrentUserName(ctx)
+	if err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	if err = s.DB.Where("name = ?", userName).First(systemUser).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	systemRole := make([]*model.SystemRole, 0)
+	return systemUser.SystemUserFormat(systemRole, nil), nil
+}
+
+// SystemUserCreateOrUpdate 创建或者更新系统用户
+func (s *StoreEntry) SystemUserCreateOrUpdate(ctx context.Context, req *pasturePb.SearchUserRequest) error {
+	if req.Id > 0 {
+		systemUser := &model.SystemUser{}
+		if err := s.DB.First(systemUser).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+		req.Password = systemUser.Password
+	}
+
+	if err := s.DB.Model(&model.SystemUser{}).Where(map[string]interface{}{
+		"id": req.Id,
+	}).Assign(map[string]interface{}{
+		"name":      req.Name,
+		"nick_name": req.NickName,
+		"mobile":    req.Mobile,
+		"gender":    req.Gender,
+		"password":  req.Password,
+		"dept_id":   req.DeptId,
+		"remarks":   req.Remarks,
+		"is_delete": operationPb.IsShow_OK,
+		"is_show":   req.IsShow,
+	}).FirstOrCreate(&model.SystemUser{}).Error; err != nil {
 		return xerr.WithStack(err)
 	}
 	return nil
 }
 
 // ResetPasswordSystemUser 重置系统用户密码
-func (s *StoreEntry) ResetPasswordSystemUser(ctx context.Context, userId int64) error {
+func (s *StoreEntry) ResetPasswordSystemUser(ctx context.Context, req *pasturePb.ResetUserPasswordRequest) error {
 	systemUser := &model.SystemUser{
-		Id: userId,
+		Id: int64(req.Id),
 	}
 	if err := s.DB.First(systemUser).Error; err != nil {
 		if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -210,7 +221,7 @@ func (s *StoreEntry) ResetPasswordSystemUser(ctx context.Context, userId int64)
 		return xerr.WithStack(err)
 	}
 
-	if err := s.DB.Model(systemUser).Update("password", tool.Md5String(model.InitManagerPassword)).Error; err != nil {
+	if err := s.DB.Model(systemUser).Update("password", req.Password).Error; err != nil {
 		return xerr.WithStack(err)
 	}
 	return nil
@@ -235,24 +246,6 @@ func (s *StoreEntry) DetailsSystemUser(ctx context.Context, userId int64) (*oper
 	}, nil
 }
 
-// IsShowSystemUser 用户是否启用
-func (s *StoreEntry) IsShowSystemUser(ctx context.Context, req *operationPb.IsShowSystemUserRequest) error {
-	systemUser := &model.SystemUser{
-		Id: int64(req.UserId),
-	}
-	if err := s.DB.First(systemUser).Error; err != nil {
-		if errors.Is(err, gorm.ErrRecordNotFound) {
-			return xerr.Custom("该用户不存在")
-		}
-		return xerr.WithStack(err)
-	}
-
-	if err := s.DB.Model(systemUser).Update("is_show", req.IsShow).Error; err != nil {
-		return xerr.WithStack(err)
-	}
-	return nil
-}
-
 // GetSystemUserPermissions 返回系统用户相关菜单权限
 func (s *StoreEntry) GetSystemUserPermissions(ctx context.Context, token string) (*operationPb.SystemUserMenuPermissions, error) {
 	// 解析token
@@ -508,7 +501,9 @@ func (s *StoreEntry) SearchSystemRoleList(ctx context.Context, req *operationPb.
 // SearchSystemRoleListByIds 根据id查询角色列表
 func (s *StoreEntry) SearchSystemRoleListByIds(ctx context.Context, ids []int64) ([]*model.SystemRole, error) {
 	systemRoleList := make([]*model.SystemRole, 0)
-	if err := s.DB.Model(new(model.SystemRole)).Where("is_show = ?", operationPb.IsShow_OK).Find(&systemRoleList, ids).Error; err != nil {
+	if err := s.DB.Model(new(model.SystemRole)).
+		Where("is_show = ?", operationPb.IsShow_OK).
+		Find(&systemRoleList, ids).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
@@ -724,3 +719,14 @@ func (s *StoreEntry) SystemDeptCreateOrUpdate(ctx context.Context, req *pastureP
 	}
 	return nil
 }
+
+// SearchSystemDeptListByIds 根据id查询部门列表
+func (s *StoreEntry) SearchSystemDeptListByIds(ctx context.Context, ids []int64) ([]*model.SystemDept, error) {
+	systemDeptList := make([]*model.SystemDept, 0)
+	if err := s.DB.Model(new(model.SystemDept)).
+		Where("is_show = ?", operationPb.IsShow_OK).
+		Find(&systemDeptList, ids).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	return systemDeptList, nil
+}