|
|
@@ -20,12 +20,12 @@ import (
|
|
|
"github.com/gogf/gf/util/grand"
|
|
|
)
|
|
|
|
|
|
-type UserService struct {
|
|
|
+type userService struct {
|
|
|
Dao *dao.SysUserDao
|
|
|
}
|
|
|
|
|
|
-func NewUserService(ctx context.Context) (*UserService, error) {
|
|
|
- user := new(UserService)
|
|
|
+func NewUserService(ctx context.Context) (*userService, error) {
|
|
|
+ user := new(userService)
|
|
|
// 获取租户码
|
|
|
tenant, err := micro_srv.GetTenant(ctx)
|
|
|
if err != nil {
|
|
|
@@ -38,7 +38,7 @@ func NewUserService(ctx context.Context) (*UserService, error) {
|
|
|
}
|
|
|
|
|
|
// Login 用户登录,成功返回用户UUID,否则返回空字符串;
|
|
|
-func (s *UserService) Login(username, password string) (*request.UserInfo, error) {
|
|
|
+func (s *userService) Login(username, password string) (*request.UserInfo, error) {
|
|
|
record, err := s.Dao.Where("user_name", username).Where("status='10'").FindOne()
|
|
|
if err != nil {
|
|
|
return nil, errors.New("系统异常")
|
|
|
@@ -71,7 +71,7 @@ func (s *UserService) Login(username, password string) (*request.UserInfo, error
|
|
|
return userInfo, nil
|
|
|
}
|
|
|
|
|
|
-func (s *UserService) GetUserList(req *model.SysUserSearchReq) (total int, userList []*model.SysUser, err error) {
|
|
|
+func (s *userService) GetUserList(req *model.SysUserSearchReq) (total int, userList []*model.SysUser, err error) {
|
|
|
if req.PageSize == 0 {
|
|
|
req.PageSize = comModel.PageSize
|
|
|
}
|
|
|
@@ -110,7 +110,7 @@ func (s *UserService) GetUserList(req *model.SysUserSearchReq) (total int, userL
|
|
|
}
|
|
|
|
|
|
// GetAdminUserByUsernamePassword 后台登陆验证
|
|
|
-func (s *UserService) GetAdminUserByUsernamePassword(ctx context.Context, req *model.LoginParamsReq) (user *model.LoginUserRes, err error) {
|
|
|
+func (s *userService) GetAdminUserByUsernamePassword(ctx context.Context, req *model.LoginParamsReq) (user *model.LoginUserRes, err error) {
|
|
|
user, err = s.GetUserByUsernamePassword(ctx, req)
|
|
|
if err != nil {
|
|
|
return
|
|
|
@@ -123,7 +123,7 @@ func (s *UserService) GetAdminUserByUsernamePassword(ctx context.Context, req *m
|
|
|
}
|
|
|
|
|
|
// GetUserByUsernamePassword 登陆验证
|
|
|
-func (s *UserService) GetUserByUsernamePassword(ctx context.Context, req *model.LoginParamsReq) (user *model.LoginUserRes, err error) {
|
|
|
+func (s *userService) GetUserByUsernamePassword(ctx context.Context, req *model.LoginParamsReq) (user *model.LoginUserRes, err error) {
|
|
|
user, err = s.GetUserByUsername(ctx, req.Username)
|
|
|
if err != nil {
|
|
|
return
|
|
|
@@ -143,12 +143,12 @@ func (s *UserService) GetUserByUsernamePassword(ctx context.Context, req *model.
|
|
|
}
|
|
|
|
|
|
// GetUserByUsername 通过用户名获取用户信息
|
|
|
-func (s *UserService) GetUserByUsername(ctx context.Context, userName string) (user *model.LoginUserRes, err error) {
|
|
|
+func (s *userService) GetUserByUsername(ctx context.Context, userName string) (user *model.LoginUserRes, err error) {
|
|
|
return dao.SysUser.FindByUsername(ctx, userName)
|
|
|
}
|
|
|
|
|
|
// UpdateLoginInfo 更新用户登录信息 保存登录日志
|
|
|
-func (s *UserService) UpdateLoginInfo(id int, username, ip, userAgent, msg, module string) {
|
|
|
+func (s *userService) UpdateLoginInfo(id int, username, ip, userAgent, msg, module string) {
|
|
|
status := 0 //登录状态 0失败 1成功
|
|
|
if id != 0 {
|
|
|
//说明登录成功更新登录信息
|
|
|
@@ -167,7 +167,7 @@ func (s *UserService) UpdateLoginInfo(id int, username, ip, userAgent, msg, modu
|
|
|
}
|
|
|
|
|
|
// LoginLog 记录登录日志
|
|
|
-func (s *UserService) LoginLog(params *model.LoginLogParams) {
|
|
|
+func (s *userService) LoginLog(params *model.LoginLogParams) {
|
|
|
//ua := user_agent.New(params.UserAgent)
|
|
|
//browser, _ := ua.Browser()
|
|
|
//loginData := &model.SysLogin{
|
|
|
@@ -190,7 +190,7 @@ func (s *UserService) LoginLog(params *model.LoginLogParams) {
|
|
|
//}
|
|
|
|
|
|
// GetAdminRole 获取用户角色
|
|
|
-func (s *UserService) GetAdminRole(userId int, allRoleList []*model.SysRole) (roles []*model.SysRole, err error) {
|
|
|
+func (s *userService) GetAdminRole(userId int, allRoleList []*model.SysRole) (roles []*model.SysRole, err error) {
|
|
|
var roleIds []uint
|
|
|
roleIds, err = s.GetAdminRoleIds(userId)
|
|
|
if err != nil {
|
|
|
@@ -211,7 +211,7 @@ func (s *UserService) GetAdminRole(userId int, allRoleList []*model.SysRole) (ro
|
|
|
}
|
|
|
|
|
|
// GetAdminRoleIds 获取用户角色ids
|
|
|
-func (s *UserService) GetAdminRoleIds(userId int) (roleIds []uint, err error) {
|
|
|
+func (s *userService) GetAdminRoleIds(userId int) (roleIds []uint, err error) {
|
|
|
enforcer, e := service.Casbin.GetEnforcer()
|
|
|
if e != nil {
|
|
|
err = e
|
|
|
@@ -230,7 +230,7 @@ func (s *UserService) GetAdminRoleIds(userId int) (roleIds []uint, err error) {
|
|
|
}
|
|
|
|
|
|
// AddUserPost 添加用户岗位信息
|
|
|
-func (s *UserService) AddUserPost(postIds []int, userId int64, tx *gdb.TX) (err error) {
|
|
|
+func (s *userService) AddUserPost(postIds []int, userId int64, tx *gdb.TX) (err error) {
|
|
|
//删除旧岗位信息
|
|
|
_, err = dao.SysUserPost.TX(tx).Where(dao.SysUserPost.Columns.UserId, userId).Delete()
|
|
|
if err != nil {
|
|
|
@@ -257,7 +257,7 @@ func (s *UserService) AddUserPost(postIds []int, userId int64, tx *gdb.TX) (err
|
|
|
}
|
|
|
|
|
|
// GetUserInfoById 通过Id获取用户信息
|
|
|
-func (s *UserService) GetUserInfoById(id int, withPwd ...bool) (user *model.SysUser, err error) {
|
|
|
+func (s *userService) GetUserInfoById(id int, withPwd ...bool) (user *model.SysUser, err error) {
|
|
|
if len(withPwd) > 0 && withPwd[0] {
|
|
|
//用户用户信息
|
|
|
err = dao.SysUser.Where(dao.SysUser.Columns.Id, id).Scan(&user)
|
|
|
@@ -274,7 +274,7 @@ func (s *UserService) GetUserInfoById(id int, withPwd ...bool) (user *model.SysU
|
|
|
}
|
|
|
|
|
|
// GetEditUser 获取要修改的用户信息
|
|
|
-func (s *UserService) GetEditUser(id int) (g.Map, error) {
|
|
|
+func (s *userService) GetEditUser(id int) (g.Map, error) {
|
|
|
userData, err := s.GetUserInfoById(id)
|
|
|
//获取角色信息
|
|
|
//roleList, err := SysRole.GetRoleList()
|
|
|
@@ -317,7 +317,7 @@ func (s *UserService) GetEditUser(id int) (g.Map, error) {
|
|
|
}
|
|
|
|
|
|
// GetUsedPost 获取正常状态的岗位
|
|
|
-func (s *UserService) GetUsedPost() (list []*model.SysPost, err error) {
|
|
|
+func (s *userService) GetUsedPost() (list []*model.SysPost, err error) {
|
|
|
err = dao.SysPost.Where(dao.SysPost.Columns.Status, 1).
|
|
|
Order(dao.SysPost.Columns.Sort + " ASC, " + dao.SysPost.Columns.Id + " ASC ").Scan(&list)
|
|
|
if err != nil {
|
|
|
@@ -328,7 +328,7 @@ func (s *UserService) GetUsedPost() (list []*model.SysPost, err error) {
|
|
|
}
|
|
|
|
|
|
// GetUserPostIds 获取用户岗位
|
|
|
-func (s *UserService) GetUserPostIds(userId int) (postIds []int, err error) {
|
|
|
+func (s *userService) GetUserPostIds(userId int) (postIds []int, err error) {
|
|
|
var list []*model.SysUserPost
|
|
|
err = dao.SysUserPost.Where(dao.SysUserPost.Columns.UserId, userId).Scan(&list)
|
|
|
if err != nil {
|
|
|
@@ -343,7 +343,7 @@ func (s *UserService) GetUserPostIds(userId int) (postIds []int, err error) {
|
|
|
}
|
|
|
|
|
|
// GetPostsByUserId 根据用户id获取岗位信息详情
|
|
|
-func (s *UserService) GetPostsByUserId(userId int) ([]*model.SysPost, error) {
|
|
|
+func (s *userService) GetPostsByUserId(userId int) ([]*model.SysPost, error) {
|
|
|
postIds, err := s.GetUserPostIds(userId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
@@ -353,7 +353,7 @@ func (s *UserService) GetPostsByUserId(userId int) ([]*model.SysPost, error) {
|
|
|
return posts, err
|
|
|
}
|
|
|
|
|
|
-func (s *UserService) AddUser(req *model.AddUserReq) (err error) {
|
|
|
+func (s *userService) AddUser(req *model.AddUserReq) (err error) {
|
|
|
req.UserSalt = grand.S(10)
|
|
|
req.Password = utils.EncryptPassword(req.Password, req.UserSalt)
|
|
|
var tx *gdb.TX
|
|
|
@@ -416,7 +416,7 @@ func (s *UserService) AddUser(req *model.AddUserReq) (err error) {
|
|
|
}
|
|
|
|
|
|
// AddUserRole 添加用户角色信息
|
|
|
-func (s *UserService) AddUserRole(roleIds interface{}, userId int64) (err error) {
|
|
|
+func (s *userService) AddUserRole(roleIds interface{}, userId int64) (err error) {
|
|
|
enforcer, e := service.Casbin.GetEnforcer()
|
|
|
if e != nil {
|
|
|
err = e
|
|
|
@@ -433,7 +433,7 @@ func (s *UserService) AddUserRole(roleIds interface{}, userId int64) (err error)
|
|
|
}
|
|
|
|
|
|
// EditUser 修改用户
|
|
|
-func (s *UserService) EditUser(req *model.EditUserReq) (err error) {
|
|
|
+func (s *userService) EditUser(req *model.EditUserReq) (err error) {
|
|
|
if i, _ := dao.SysUser.Where("id!=? and phone=?", req.Id, req.Phone).Count(); i != 0 {
|
|
|
err = gerror.New("手机号已经存在")
|
|
|
return
|
|
|
@@ -490,7 +490,7 @@ func (s *UserService) EditUser(req *model.EditUserReq) (err error) {
|
|
|
}
|
|
|
|
|
|
// EditUserRole 修改用户角色信息
|
|
|
-func (s *UserService) EditUserRole(roleIds interface{}, userId int) (err error) {
|
|
|
+func (s *userService) EditUserRole(roleIds interface{}, userId int) (err error) {
|
|
|
enforcer, e := service.Casbin.GetEnforcer()
|
|
|
if e != nil {
|
|
|
err = e
|
|
|
@@ -509,7 +509,7 @@ func (s *UserService) EditUserRole(roleIds interface{}, userId int) (err error)
|
|
|
}
|
|
|
|
|
|
// ResetUserPwd 重置用户密码
|
|
|
-func (s *UserService) ResetUserPwd(req *model.SysUserResetPwdReq) error {
|
|
|
+func (s *userService) ResetUserPwd(req *model.SysUserResetPwdReq) error {
|
|
|
salt := grand.S(10)
|
|
|
password := utils.EncryptPassword(req.Password, salt)
|
|
|
_, err := dao.SysUser.WherePri(req.Id).Update(g.Map{
|
|
|
@@ -519,7 +519,7 @@ func (s *UserService) ResetUserPwd(req *model.SysUserResetPwdReq) error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
-func (s *UserService) ChangeUserStatus(req *model.SysUserStatusReq) error {
|
|
|
+func (s *userService) ChangeUserStatus(req *model.SysUserStatusReq) error {
|
|
|
_, err := dao.SysUser.WherePri(req.Id).Update(g.Map{
|
|
|
dao.SysUser.Columns.Status: req.UserStatus,
|
|
|
})
|
|
|
@@ -527,7 +527,7 @@ func (s *UserService) ChangeUserStatus(req *model.SysUserStatusReq) error {
|
|
|
}
|
|
|
|
|
|
// DeleteUserByIds 删除用户信息
|
|
|
-func (s *UserService) DeleteUserByIds(ctx context.Context, ids []int64) error {
|
|
|
+func (s *userService) DeleteUserByIds(ctx context.Context, ids []int64) error {
|
|
|
return g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
|
|
|
_, err := s.Dao.Ctx(ctx).TX(tx).Where(dao.SysUser.Columns.Id+" in(?)", ids).Delete()
|
|
|
//删除对应权限
|
|
|
@@ -544,7 +544,7 @@ func (s *UserService) DeleteUserByIds(ctx context.Context, ids []int64) error {
|
|
|
}
|
|
|
|
|
|
// SetAvatar 修改用户头像
|
|
|
-func (s *UserService) SetAvatar(userId int, avatarUrl string) error {
|
|
|
+func (s *userService) SetAvatar(userId int, avatarUrl string) error {
|
|
|
_, err := dao.SysUser.WherePri(userId).Unscoped().Update(g.Map{
|
|
|
dao.SysUser.Columns.Avatar: avatarUrl,
|
|
|
})
|
|
|
@@ -552,13 +552,13 @@ func (s *UserService) SetAvatar(userId int, avatarUrl string) error {
|
|
|
}
|
|
|
|
|
|
// ProfileEdit 修改个人资料
|
|
|
-func (s *UserService) ProfileEdit(req *model.ProfileUpReq) error {
|
|
|
+func (s *userService) ProfileEdit(req *model.ProfileUpReq) error {
|
|
|
_, err := dao.SysUser.WherePri(req.UserId).Unscoped().Update(req)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// ProfileUpdatePwd 修改个人密码
|
|
|
-func (s *UserService) ProfileUpdatePwd(req *model.ProfileUpdatePwdReq) error {
|
|
|
+func (s *userService) ProfileUpdatePwd(req *model.ProfileUpdatePwdReq) error {
|
|
|
userInfo, err := s.GetUserInfoById(req.UserId, true)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -645,7 +645,7 @@ func (s *UserService) ProfileUpdatePwd(req *model.ProfileUpdatePwdReq) error {
|
|
|
//}
|
|
|
|
|
|
// GetUsers 通过用户ids查询多个用户信息
|
|
|
-func (s *UserService) GetUsers(ids []int) (users []*model.SysUserRes, err error) {
|
|
|
+func (s *userService) GetUsers(ids []int) (users []*model.SysUserRes, err error) {
|
|
|
if len(ids) == 0 {
|
|
|
return
|
|
|
}
|