Commit 51eebe6a authored by 黄智's avatar 黄智

新增用户模块

parent fca661f8
package entity
import (
"time"
)
// SystemRole 系统角色
type SystemRole struct {
Id int64 `json:"id" xorm:"pk autoincr"` // id
RoleName string `json:"role_name"` // 角色名称
RoleDesc string `json:"role_desc"` // 角色描述
State int `json:"state"` // 状态0禁用1启用
CreatedBy int `json:"created_by"` // 角色创建人
CreatedTime time.Time `json:"created_time"` // 角色创建时间
UpdatedTime time.Time `json:"updated_time"` // 角色更新时间
UpdatedBy string `json:"updated_by"` // 角色更新人
RoleType int `json:"role_type"` // 角色类型(0 普通角色 1 内置角色类型 不能删除和编辑 )
RoleId string `json:"role_id"` // 角色id(uuid)
IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除
}
...@@ -17,6 +17,7 @@ type SystemUser struct { ...@@ -17,6 +17,7 @@ type SystemUser struct {
UpdatedBy int `json:"updated_by" ` // 更新者 UpdatedBy int `json:"updated_by" ` // 更新者
UpdatedTime time.Time `json:"updated_time" xorm:"updated" ` // 更新时间 UpdatedTime time.Time `json:"updated_time" xorm:"updated" ` // 更新时间
IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除 IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除
Phone string `json:"phone" xorm:"phone"` // 手机号
} }
type SystemUserInfo struct { type SystemUserInfo struct {
...@@ -28,4 +29,5 @@ type SystemUserInfo struct { ...@@ -28,4 +29,5 @@ type SystemUserInfo struct {
State int `json:"state" xorm:"state"` // 状态0禁用1启用 State int `json:"state" xorm:"state"` // 状态0禁用1启用
Logo string `json:"logo" xorm:"logo"` // 头像logo Logo string `json:"logo" xorm:"logo"` // 头像logo
IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除 IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除
Phone string `json:"phone" xorm:"phone"` // 手机号
} }
...@@ -34,33 +34,26 @@ type GetBusinessMsgInput struct { ...@@ -34,33 +34,26 @@ type GetBusinessMsgInput struct {
// 新增用户 // 新增用户
type OrgUserInput struct { type OrgUserInput struct {
Name string `json:"name"` // 姓名
Logo string `json:"logo"` // 头像logo Logo string `json:"logo"` // 头像logo
SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号 SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号
ContactPhone string `json:"contact_phone" vd:"phone($)"` // 联系人电话 Phone string `json:"phone" vd:"phone($)"` // 联系人电话
Password string `json:"password" vd:"len($)>1;msg:'请输入密码'"` // 密码 Password string `json:"password" vd:"len($)>1;msg:'请输入密码'"` // 密码
SelectRole []string `json:"select_role"` // 选择角色 SelectRole []string `json:"select_role"` // 选择角色
State int `json:"state"` // 状态0禁用1启用 State int `json:"state"` // 状态0禁用1启用
ContactName string `json:"contact_name"` // 联系人姓名
ContactEmail string `json:"contact_email"` // 联系人邮箱
Remark string `json:"remark"` // 备注
OrganizationId string `json:"organization_id" vd:"len($)>1;msg:'请选择所属组织'"` // 所属组织 OrganizationId string `json:"organization_id" vd:"len($)>1;msg:'请选择所属组织'"` // 所属组织
DocumentType int64 `json:"document_type"` //证件类型 1 身份证 //IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
DocumentNumber string `json:"document_number"` //证件号
IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
} }
// 编辑用户 // 编辑用户
type UpdateOrgUserInput struct { type UpdateOrgUserInput struct {
Name string `json:"name"` // 联系人姓名
Logo string `json:"logo"` // 头像logo Logo string `json:"logo"` // 头像logo
SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号 SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号
ContactPhone string `json:"contact_phone" vd:"phone($)"` // 联系人电话 Phone string `json:"phone" vd:"phone($)"` // 联系人电话
// SelectRole []string `json:"select_role"` // 选择角色 SelectRole []string `json:"select_role"` // 选择角色
State int `json:"state"` // 状态0禁用1启用 State int `json:"state"` // 状态0禁用1启用
ContactName string `json:"contact_name"` // 联系人姓名
ContactEmail string `json:"contact_email" vd:"email($)"` // 联系人邮箱
Remark string `json:"remark"` // 备注
DocumentType int64 `json:"document_type"` //证件类型 1 身份证
DocumentNumber string `json:"document_number"` //证件号
} }
// 删除用户 // 删除用户
...@@ -71,5 +64,5 @@ type DelOrgUser struct { ...@@ -71,5 +64,5 @@ type DelOrgUser struct {
// 去重校验 // 去重校验
type CheckRepetition struct { type CheckRepetition struct {
Id int `form:"id" json:"id"` Id int `form:"id" json:"id"`
ContactPhone string `form:"contact_phone" json:"contact_phone"` Phone string `form:"phone" json:"phone"`
} }
package request
type CreateSystemRoleReq struct {
RoleName string `json:"role_name" vd:"len($)>0;msg:'请输入角色名称'"` // 角色名称
RoleDesc string `json:"role_desc"` // 角色描述
State int `json:"state"` // 状态0禁用1启用
RoleId string `json:"role_id"` // 角色id(uuid)
DataPurview int `json:"data_purview" vd:"$>0;msg:'请输入数据权限'"` // 数据权限:1-仅自己,2-本组织所有,3-全平台所有
MenuIds []int `json:"menu_ids" ` // 菜单ids
CreatedBy string `json:"created_by"` // 用户创建人
}
type UpdateSystemRoleReq struct {
Id int `json:"id"` // id
RoleName string `json:"role_name" vd:"len($)>0;msg:'请输入角色名称'"` // 角色名称
RoleDesc string `json:"role_desc"` // 角色描述
State int `json:"state"` // 状态0禁用1启用
DataPurview int `json:"data_purview" vd:"$>0;msg:'请输入数据权限'"` // 数据权限:1-仅自己,2-本组织所有,3-全平台所有
MenuIds []int `json:"menu_ids" ` // 菜单ids
UpdatedBy string `json:"updated_by"` // 角色更新人
}
type SystemRoleListReq struct {
IsAdmin int `json:"is_admin"`
Pagination
}
type SystemAllotUserListReq struct {
Pagination
RoleId int `json:"role_id" form:"role_id" vd:"$>0;msg:'请输入role_id'"` // 角色id
IsAdmin int `json:"is_admin" form:"is_admin"` // 账户类型
OrganizationId int64 `json:"organization_id" form:"organization_id"` // 所属组织
}
type SystemRoleDetailReq struct {
Id string `json:"id" form:"id" vd:"len($)>0;msg:'请输入id'"` // id
}
type SystemRoleStateReq struct {
Id string `json:"id" form:"id" vd:"len($)>0;msg:'请输入id'"` // id
State string `json:"state" vd:"len($)>0;msg:'请填写状态'"` // Id
}
type DeleteSystemRoleReq struct {
Ids []int `json:"ids"` // ids
}
type SystemRoleAllotmentUserReq struct {
UserIds []int `json:"user_ids"` // 用户ids
Id int `json:"id"` // id
}
...@@ -35,24 +35,18 @@ type OrgAdminUser struct { ...@@ -35,24 +35,18 @@ type OrgAdminUser struct {
// 账号详情 // 账号详情
type OrgUserDetail struct { type OrgUserDetail struct {
Id int32 `json:"id" xorm:"pk autoincr" ` // id Id int32 `json:"id" xorm:"pk autoincr" ` // id
ContactPhone string `json:"contact_phone" xorm:"contact_phone"` // 联系人电话 Name string `json:"name" xorm:"name"` // 联系人姓名
Phone string `json:"phone" xorm:"phone"` // 联系人电话
SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号 SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号
SystemRole []string `json:"system_role" xorm:"-"` // 系统角色id SystemRole []string `json:"system_role" xorm:"-"` // 系统角色id
Organization string `json:"organization" xorm:"organization"` // 所属组织 Organization string `json:"organization" xorm:"organization"` // 所属组织
OrganizationId string `json:"organization_id"` // 所属组织 OrganizationId string `json:"organization_id"` // 所属组织
CreatedBy string `json:"created_by"` // 创建者 CreatedBy int `json:"created_by"` // 创建者
CreatedByAccount string `json:"created_by_account"` // 创建账号 CreatedName string `json:"created_name"` // 创建账号
UpdatedTime jsontime.Time `json:"updated_time" xorm:"updated" ` // 更新时间 UpdatedTime jsontime.Time `json:"updated_time" xorm:"updated" ` // 更新时间
CreatedTime jsontime.Time `json:"created_time" xorm:"created" ` // 创建时间 CreatedTime jsontime.Time `json:"created_time" xorm:"created" ` // 创建时间
ContactName string `json:"contact_name" xorm:"contact_name"` // 联系人姓名
ContactEmail string `json:"contact_email" xorm:"contact_email"` // 联系人邮箱
DocumentType int64 `json:"document_type"` // 证件类型
DocumentNumber string `json:"document_number"` // 证件号
Remark string `json:"remark" xorm:"remark"` // 备注
Logo string `json:"logo"` // 头像logo Logo string `json:"logo"` // 头像logo
State int `json:"state"` // 状态0禁用1启用 State int `json:"state"` // 状态0禁用1启用
SystemId string `json:"-" xorm:"system_id"` // 系统账号id
IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
} }
// 编辑组织账号 // 编辑组织账号
...@@ -80,9 +74,3 @@ type OrgDetail struct { ...@@ -80,9 +74,3 @@ type OrgDetail struct {
Description string `json:"description"` //组织介绍 Description string `json:"description"` //组织介绍
PlatformUsersNumber int64 `json:"platform_users_number"` //平台用户数 PlatformUsersNumber int64 `json:"platform_users_number"` //平台用户数
} }
type BusinessSystem struct {
BusinessName string `json:"business_name" xorm:"business_name"` // 业务系统名称
SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号
State int `json:"state"` // 状态0禁用1启用
}
...@@ -7,9 +7,11 @@ import ( ...@@ -7,9 +7,11 @@ import (
// 系统用户角色关联查询 // 系统用户角色关联查询
type SystemUserRole struct { type SystemUserRole struct {
SystemId string `json:"system_id" xorm:"system_id"` // 系统账号id UserId int `json:"user_id" xorm:"user_id"` // 用户id
RoleId string `json:"role_id" xorm:"role_id"` // 角色id
RoleName string `json:"role_name"` // 角色名称 RoleName string `json:"role_name"` // 角色名称
} }
type SystemRoleList struct { type SystemRoleList struct {
Id int64 `json:"id"` // id Id int64 `json:"id"` // id
RoleName string `json:"role_name"` // 角色名称 RoleName string `json:"role_name"` // 角色名称
......
...@@ -134,141 +134,3 @@ func OrgDetail(c *gin.Context) { ...@@ -134,141 +134,3 @@ func OrgDetail(c *gin.Context) {
} }
SendJsonResponse(c, resp.OK, result) SendJsonResponse(c, resp.OK, result)
} }
//
//// 查询业务系统信息
//func GetBusinessMsg(c *gin.Context) {
// var input request.GetBusinessMsgInput
// if err := c.ShouldBind(&input); err != nil {
// SendJsonResponse(c, resp.InvalidParam.ErrorDetail(err), nil)
// return
// }
// if input.OrganizationId == "" {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("组织id必填")), nil)
// return
// }
// if input.Limit == 0 {
// input.Limit = 10
// }
// orgService := service.Organization{}
// respult, count, err := orgService.GetBusinessMsg(input)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonPageResponse(c, resp.GET_OK, respult, count)
//}
//
//// 查询组织用户详情
//func OrgUserDetail(c *gin.Context) {
// id := cast.ToInt(c.Param("id"))
// if id <= 0 {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil)
// return
// }
// orgService := service.Organization{}
// respult, err := orgService.OrgUserDetail(id)
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.GET_OK, respult)
//}
//
//// 组织添加用户时查询的角色列表
//func OrgUserRoles(c *gin.Context) {
// isadmin := c.Query("is_admin")
// if isadmin == "" {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("用户类型必填")), nil)
// return
// }
// orgService := service.Organization{}
// respult, err := orgService.OrgUserRoles(cast.ToInt(isadmin))
// if err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.GET_OK, respult)
//}
//
//// 添加组织用户
//func OrgAddUser(c *gin.Context) {
// var input request.OrgUserInput
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// if err := vd.Validate(input); err != nil {
// SendJsonResponse(c, err, "")
// return
// }
// if input.IsAdmin != 2 && input.IsAdmin != 3 {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(errors.New("超出类型可选范围")), nil)
// return
// }
//
// orgService := service.Organization{User: util.GetContextUser(c)}
// if err := orgService.OrgAddUser(input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.ADD_OK, nil)
//}
//
//// 编辑用户
//func OrgUpdateUser(c *gin.Context) {
// id := cast.ToInt(c.Param("id"))
// if id <= 0 {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil)
// return
// }
// var input request.UpdateOrgUserInput
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// if err := vd.Validate(input); err != nil {
// SendJsonResponse(c, err, "")
// return
// }
// orgService := service.Organization{User: util.GetContextUser(c)}
// if err := orgService.OrgUpdateUser(id, input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.UPDATE_OK, nil)
//}
//
//// 删除组织用户
//func DelOrgUser(c *gin.Context) {
// var input request.DelOrgUser
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// if len(input.Ids) <= 0 {
// SendJsonResponse(c, resp.ParamsMissError.ErrorDetail(errors.New("请输入用户id")), nil)
// return
// }
// orgService := service.Organization{User: util.GetContextUser(c)}
// if err := orgService.DelOrgUser(input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.DELETE_OK, nil)
//}
//
//// 去重校验
//func CheckRepetition(c *gin.Context) {
// var input request.CheckRepetition
// if err := c.ShouldBindJSON(&input); err != nil {
// SendJsonResponse(c, resp.ParamsParserError.ErrorDetail(err), nil)
// return
// }
// orgService := service.Organization{}
// if err := orgService.CheckRepetition(input); err != nil {
// SendJsonResponse(c, err, nil)
// return
// }
// SendJsonResponse(c, resp.GET_OK, nil)
//}
package controller
import (
"errors"
vd "github.com/bytedance/go-tagexpr/validator"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/service"
)
// 查询组织用户详情
func OrgUserDetail(c *gin.Context) {
id := cast.ToInt(c.Param("id"))
if id <= 0 {
SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入用户id"), nil)
return
}
svc := service.User{}
result, err := svc.OrgUserDetail(id)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
// 组织添加用户时查询的角色列表
func OrgUserRoles(c *gin.Context) {
isAdmin := c.Query("is_admin")
if isAdmin == "" {
SendJsonResponse(c, resp.InvalidParam.WithMsg("用户类型必填"), nil)
return
}
svc := service.User{}
result, err := svc.OrgUserRoles(cast.ToInt(isAdmin))
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, result)
}
// 添加组织用户
func OrgAddUser(c *gin.Context) {
var input request.OrgUserInput
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
if err := vd.Validate(input); err != nil {
SendJsonResponse(c, err, "")
return
}
svc := service.User{User: header.GetUser(c)}
if err := svc.OrgAddUser(input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 编辑用户
func OrgUpdateUser(c *gin.Context) {
id := cast.ToInt(c.Param("id"))
if id <= 0 {
SendJsonResponse(c, resp.InvalidParam.WithMsg("请输入用户id"), nil)
return
}
var input request.UpdateOrgUserInput
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.FAIL.WithError(err), nil)
return
}
if err := vd.Validate(input); err != nil {
SendJsonResponse(c, err, "")
return
}
svc := service.User{User: header.GetUser(c)}
if err := svc.OrgUpdateUser(id, input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 删除组织用户
func DelOrgUser(c *gin.Context) {
var input request.DelOrgUser
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
if len(input.Ids) <= 0 {
SendJsonResponse(c, resp.FAIL.WithMsg("请输入用户id"), nil)
return
}
svc := service.User{User: header.GetUser(c)}
if err := svc.DelOrgUser(input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// 去重校验
func CheckRepetition(c *gin.Context) {
var input request.CheckRepetition
if err := c.ShouldBindJSON(&input); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
svc := service.User{}
if err := svc.CheckRepetition(input); err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// SystemUserEditPassword 修改密码
func SystemUserEditPassword(c *gin.Context) {
params := request.SystemUserEditPasswordReq{}
if err := c.ShouldBindJSON(&params); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
pwdLen := len([]rune(params.Password))
if pwdLen <= 0 {
SendJsonResponse(c, resp.InvalidParam.WithError(errors.New("请输入密码")), "")
}
if err := vd.Validate(params); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), "")
return
}
err := service.SystemUserEditPassword(params)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
// ResetSystemUserPassword 重置系统账户密码
func ResetSystemUserPassword(c *gin.Context) {
params := request.ResetSystemUserPasswordReq{}
if err := c.ShouldBindJSON(&params); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), nil)
return
}
if err := vd.Validate(params); err != nil {
SendJsonResponse(c, resp.InvalidParam.WithError(err), "")
return
}
err := service.ResetSystemUserPassword(params)
if err != nil {
SendJsonResponse(c, err, nil)
return
}
SendJsonResponse(c, resp.OK, nil)
}
...@@ -38,6 +38,13 @@ func (r Resp) WithError(err error) Resp { ...@@ -38,6 +38,13 @@ func (r Resp) WithError(err error) Resp {
return r return r
} }
func (r Resp) ErrorDetail(err error) Resp {
if err != nil {
r.Data = err.Error()
}
return r
}
// TranslateError 翻译validate验证错误 // TranslateError 翻译validate验证错误
func (r Resp) TranslateError(err error) Resp { func (r Resp) TranslateError(err error) Resp {
translatedErrors := make([]string, 0) translatedErrors := make([]string, 0)
......
...@@ -19,12 +19,5 @@ func InitOrganizationRouter(e *gin.Engine) { ...@@ -19,12 +19,5 @@ func InitOrganizationRouter(e *gin.Engine) {
base.PUT("/sort", controller.SortOrg) //组织排序 base.PUT("/sort", controller.SortOrg) //组织排序
base.GET("/tree", controller.GetOrgTree) //查询组织树 base.GET("/tree", controller.GetOrgTree) //查询组织树
base.GET("/detail", controller.OrgDetail) //查询组织详情 base.GET("/detail", controller.OrgDetail) //查询组织详情
//base.GET("/business/msg", controller.GetBusinessMsg) //查询业务系统信息
//base.GET("/user/:id", controller.OrgUserDetail) //查询组织用户详情
//base.GET("/select/role", controller.OrgUserRoles) //注册平台用户使用的查询角色列表
//base.POST("/add/user", controller.OrgAddUser) //添加组织用户
//base.PUT("/update/user/:id", controller.OrgUpdateUser) //组织编辑用户
//base.DELETE("/del/user", controller.DelOrgUser) //删除组织用户
//base.POST("/check", controller.CheckRepetition) //去重校验
} }
} }
...@@ -36,6 +36,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) { ...@@ -36,6 +36,8 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
InitSystemLoginRouter(r) InitSystemLoginRouter(r)
// 初始化组织相关路由 // 初始化组织相关路由
InitOrganizationRouter(r) InitOrganizationRouter(r)
// 初始化用户相关路由
InitSystemUserRouter(r)
// 初始化指标配置路由 // 初始化指标配置路由
InitMetricConfigRouter(r) InitMetricConfigRouter(r)
// 初始化prometheus路由 // 初始化prometheus路由
......
package router
import (
"fmt"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/controller"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/router/middleware/header"
"github.com/gin-gonic/gin"
)
// 初始化登录相关路由
func InitSystemUserRouter(e *gin.Engine) {
base := e.Group(fmt.Sprintf("%s/user", conf.Options.Prefix), header.SetContext)
{
base.GET("/:id", controller.OrgUserDetail) //查询组织用户详情
base.GET("/select/role", controller.OrgUserRoles) //注册平台用户使用的查询角色列表
base.POST("/add", controller.OrgAddUser) //添加组织用户
base.PUT("/:id", controller.OrgUpdateUser) //组织编辑用户
base.DELETE("/del", controller.DelOrgUser) //删除组织用户
base.POST("/check", controller.CheckRepetition) //去重校验
base.POST("/updatePwd", controller.SystemUserEditPassword) // 修改账户密码
base.POST("/resetPwd", controller.ResetSystemUserPassword) // 重置账户密码
}
}
...@@ -313,291 +313,3 @@ func (o *Organization) OrgDetail(input request.QueryOrgDetailInput) (interface{} ...@@ -313,291 +313,3 @@ func (o *Organization) OrgDetail(input request.QueryOrgDetailInput) (interface{}
} }
return result, nil return result, nil
} }
//// 查询组织业务系统信息
//func (o *Organization) GetBusinessMsg(input request.GetBusinessMsgInput) (interface{}, int64, error) {
// db, err := client.GetDbClient()
// if err != nil {
// return nil, 0, res.DbConnectError.ErrorDetail(err)
// }
//
// //查询业务系统信息
// var result []response.BusinessSystem
// count, err := db.Table("system_user").Select("business_name, system_account, state").
// Where("organization_id = ? and is_admin = 1 and is_deleted = 0", input.OrganizationId).Limit(input.Limit, (input.Page-1)*input.Limit).Asc("system_user.created_time").FindAndCount(&result)
// if err != nil {
// conf.Logger.Error("查询业务系统信息失败", zap.Error(err))
// return nil, 0, res.DbSelectError.ErrorDetail(err)
// }
// return result, count, nil
//}
//
//// 查询组织用户详情
//func (o *Organization) OrgUserDetail(id int) (interface{}, error) {
// db, err := client.GetDbClient()
// if err != nil {
// return nil, res.DbConnectError.ErrorDetail(err)
// }
// selectSql := "su.id, su.organization_id, su.contact_phone, su.system_account, so.name as organization, createduser.contact_name as created_by, createduser.system_account as created_by_account, " +
// "su.updated_time, su.created_time, su.contact_name, su.contact_email, su.document_type, su.document_number, su.remark, su.logo, su.state, su.system_id, su.is_admin"
// var result response.OrgUserDetail
// has, err := db.Table("system_user").Alias("su").
// Select(selectSql).
// Join("left", "system_organization so", "so.organization_id = su.organization_id").
// Join("left", "system_user createduser", "createduser.system_id::varchar = su.created_by").
// Where("su.id = ? and su.is_deleted = 0", id).Get(&result)
// if err != nil {
// conf.Logger.Error("查询组织用户详情失败", zap.Error(err))
// return nil, res.DbSelectError.ErrorDetail(err)
// }
// if !has {
// return nil, res.DbSelectError.ErrorDetail(errors.New("用户不存在"))
// }
//
// //查询用户角色
// var systemUserRoles []response.SystemUserRole
// if err := db.Table("system_user_role").Alias("sur").Select("sur.system_id::varchar, sr.role_name").
// Join("left", "system_role sr", "sr.role_id = sur.role_id").Where("sur.system_id::varchar = ?", result.SystemId).Find(&systemUserRoles); err != nil {
// conf.Logger.Error("查询用户角色信息失败", zap.Error(err))
// return nil, res.DbSelectError.ErrorDetail(err)
// }
// for _, v := range systemUserRoles {
// result.SystemRole = append(result.SystemRole, v.RoleName)
// }
// return result, nil
//}
//
//// 组织添加用户时查询角色列表 查询非内置角色 + 平台运营者
//func (o *Organization) OrgUserRoles(is_admin int) (interface{}, error) {
// db, err := client.GetDbClient()
// if err != nil {
// return nil, res.DbConnectError.ErrorDetail(err)
// }
// var rols []entity.SystemRole
// if is_admin == 3 {
// if err := db.Table("system_role").Where("(role_type = 0 and is_deleted = 0 and state = 1) or role_id = ?", util.PINGTAIYUNYINGZHE).Find(&rols); err != nil {
// conf.Logger.Error("查询用户角色信息失败", zap.Error(err))
// return nil, res.DbSelectError.ErrorDetail(err)
// }
// } else if is_admin == 2 {
// if err := db.Table("system_role").Where("role_id = ?", util.ZUZHIGUANLIYUAN).Find(&rols); err != nil {
// conf.Logger.Error("查询用户角色信息失败", zap.Error(err))
// return nil, res.DbSelectError.ErrorDetail(err)
// }
// } else if is_admin == 1 {
// if err := db.Table("system_role").Where("role_id = ?", util.YEWUXITONGJUESE).Find(&rols); err != nil {
// conf.Logger.Error("查询用户角色信息失败", zap.Error(err))
// return nil, res.DbSelectError.ErrorDetail(err)
// }
// }
// return rols, nil
//}
//
//// 添加组织用户
//func (o *Organization) OrgAddUser(input request.OrgUserInput) error {
// db, err := client.GetDbClient()
// if err != nil {
// return res.DbConnectError.ErrorDetail(err)
// }
//
// //验证账号是否存在
// has, err := db.Table("system_user").Select("id").Where("system_account = ? and is_deleted = 0", input.SystemAccount).Exist(&entity.SystemUser{})
// if err != nil {
// conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
// return res.DbInsertError.ErrorDetail(err)
// }
// if has {
// return res.DbInsertError.ErrorDetail(errors.New("账号已存在"))
// }
//
// //验证手机号是否存在
// has, err = db.Table("system_user").Select("id").Where("contact_phone = ? and is_deleted = 0", input.ContactPhone).Exist(&entity.SystemUser{})
// if err != nil {
// conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
// return res.DbInsertError.ErrorDetail(err)
// }
// if has {
// return res.DbInsertError.ErrorDetail(errors.New("手机号已存在"))
// }
//
// systemId := util.GetUUID()
// upperMd5Pass, err := SolvePassword(systemId, input.Password)
// if err != nil {
// conf.Logger.Error("密码处理出错", zap.Error(err))
// return res.DbInsertError.ErrorDetail(err)
// }
// userModel := entity.SystemUser{
// SystemId: systemId,
// Logo: input.Logo,
// SystemAccount: input.SystemAccount,
// ContactPhone: input.ContactPhone,
// Password: upperMd5Pass,
// State: input.State,
// ContactName: input.ContactName,
// ContactEmail: input.ContactEmail,
// Remark: input.Remark,
// OrganizationId: input.OrganizationId,
// DocumentType: input.DocumentType,
// DocumentNumber: input.DocumentNumber,
// CreatedBy: o.User.SystemId,
// IsAdmin: cast.ToInt(input.IsAdmin),
// }
//
// _, err = db.Transaction(func(s *xorm.Session) (interface{}, error) {
// if _, err := s.Table("system_user").Insert(&userModel); err != nil {
// conf.Logger.Error("创建系统账户失败", zap.Error(err))
// return nil, res.DbInsertError.ErrorDetail(err)
// }
//
// var systemUserRoles []entity.SystemUserRole
// for _, v := range input.SelectRole {
// systemUserRoles = append(systemUserRoles, entity.SystemUserRole{SystemId: systemId, RoleId: v})
// }
// if _, err := s.Table("system_user_role").Insert(&systemUserRoles); err != nil {
// conf.Logger.Error("创建用户角色失败", zap.Error(err))
// return nil, res.DbInsertError.ErrorDetail(err)
// }
// return nil, nil
// })
// return err
//}
//
//// 更新组织用户
//func (o *Organization) OrgUpdateUser(id int, input request.UpdateOrgUserInput) error {
// db, err := client.GetDbClient()
// if err != nil {
// return res.DbConnectError.ErrorDetail(err)
// }
// var baseUser entity.SystemUser
// has, err := db.Table("system_user").ID(id).Where("is_deleted = 0").Get(&baseUser)
// if err != nil {
// conf.Logger.Error("查询账号信息失败", zap.Error(err))
// return res.DbUpdateError.ErrorDetail(err)
// }
// if !has {
// return res.DbUpdateError.ErrorDetail(errors.New("该用户不存在"))
// }
//
// if baseUser.SystemAccount != input.SystemAccount {
// //验证账号是否存在
// has, err = db.Table("system_user").Select("id").Where("system_account = ? and is_deleted = 0", input.SystemAccount).Exist(&entity.SystemUser{})
// if err != nil {
// conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
// return res.DbUpdateError.ErrorDetail(err)
// }
// if has {
// return res.DbUpdateError.ErrorDetail(errors.New("账号已存在"))
// }
// }
//
// if baseUser.ContactPhone != input.ContactPhone {
// //验证手机号是否存在
// has, err = db.Table("system_user").Select("id").Where("contact_phone = ? and is_deleted = 0", input.ContactPhone).Exist(&entity.SystemUser{})
// if err != nil {
// conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
// return res.DbUpdateError.ErrorDetail(err)
// }
// if has {
// return res.DbUpdateError.ErrorDetail(errors.New("手机号已存在"))
// }
// }
//
// userModel := entity.SystemUser{
// Logo: input.Logo,
// SystemAccount: input.SystemAccount,
// ContactPhone: input.ContactPhone,
// State: input.State,
// ContactName: input.ContactName,
// ContactEmail: input.ContactEmail,
// Remark: input.Remark,
// DocumentType: input.DocumentType,
// DocumentNumber: input.DocumentNumber,
// UpdatedBy: o.User.SystemId,
// }
//
// if _, err := db.Table("system_user").ID(id).Update(&userModel); err != nil {
// conf.Logger.Error("账号信息更新失败", zap.Error(err))
// return res.DbUpdateError.ErrorDetail(err)
// }
// return nil
//}
//
//// 删除组织用户
//func (o *Organization) DelOrgUser(input request.DelOrgUser) error {
// db, err := client.GetDbClient()
// if err != nil {
// return res.DbConnectError.ErrorDetail(err)
// }
//
// _, err = db.Transaction(func(s *xorm.Session) (interface{}, error) {
// var baseUsers []entity.SystemUser
// if err := s.Table("system_user").In("id", input.Ids).Where("is_deleted = 0").Find(&baseUsers); err != nil {
// conf.Logger.Error("查询账号信息失败", zap.Error(err))
// return nil, res.DbDeleteError.ErrorDetail(err)
// }
// if len(baseUsers) == 0 {
// return nil, res.DbDeleteError.ErrorDetail(errors.New("用户数据不存在,删除失败"))
// }
// for _, v := range baseUsers {
// if v.State == 1 {
// return nil, res.DbDeleteError.ErrorDetail(errors.New("删除内容中有启用状态的数据,不可删除!"))
// }
// }
//
// //是组织管理员 验证是否为最后一个组织管理员账号 组织管理员人数不能为0,不可删除!
// if len(baseUsers) > 0 && baseUsers[0].IsAdmin == 2 {
// count, err := s.Table("system_user").Where("organization_id = ? and is_deleted = 0 and is_admin = 2", baseUsers[0].OrganizationId).Count(&entity.SystemUser{})
// if err != nil {
// conf.Logger.Error("查询账号验证统计失败", zap.Error(err))
// return nil, res.DbDeleteError.ErrorDetail(err)
// }
// if int(count)-len(baseUsers) <= 0 {
// return nil, res.DbDeleteError.ErrorDetail(errors.New("组织管理员人数不能为0,不可删除!"))
// }
// }
//
// if _, err := db.Table("system_user").In("id", input.Ids).Update(&entity.SystemUser{IsDeleted: 1, UpdatedBy: o.User.SystemId}); err != nil {
// conf.Logger.Error("用户删除失败", zap.Error(err))
// return nil, res.DbDeleteError.ErrorDetail(err)
// }
//
// //删除用户关联角色
// var system_ids []string
// for _, v := range baseUsers {
// system_ids = append(system_ids, v.SystemId)
// }
// if _, err := db.Table("system_user_role").In("system_id", system_ids).Delete(&entity.SystemUserRole{}); err != nil {
// conf.Logger.Error("删除用户关联角色失败", zap.Error(err))
// return nil, res.DbDeleteError.ErrorDetail(err)
// }
// return nil, nil
// })
// return err
//}
//
//// 去重校验
//func (o *Organization) CheckRepetition(input request.CheckRepetition) error {
// db, err := client.GetDbClient()
// if err != nil {
// return res.DbConnectError.ErrorDetail(err)
// }
//
// var system_user entity.SystemUser
// if input.Id != 0 {
// if _, err := db.Table("system_user").Select("id, contact_phone").ID(input.Id).Where("is_deleted = 0").Get(&system_user); err != nil {
// conf.Logger.Error("查询用户失败", zap.Error(err))
// return res.DbDataCheckError.ErrorDetail(err)
// }
// }
// if input.ContactPhone != system_user.ContactPhone {
// has, err := db.Table("system_user").Select("id").Where("contact_phone = ? and is_deleted = 0", input.ContactPhone).Exist(&entity.SystemUser{})
// if err != nil {
// conf.Logger.Error("手机号去重查询失败", zap.Error(err))
// return res.DbDataCheckError.ErrorDetail(err)
// }
// if has {
// return res.DbDataCheckError.ErrorDetail(errors.New("该手机号已注册"))
// }
// }
// return nil
//}
package service
import (
"crypto/md5"
"encoding/hex"
"errors"
"fmt"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/request"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/vo/response"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/util"
"xorm.io/xorm"
"go.uber.org/zap"
"strings"
)
const (
defaultPassword = "123456" // 重置默认密码
)
type User struct {
User entity.SystemUserInfo
}
// 查询组织用户详情
func (o *User) OrgUserDetail(id int) (interface{}, error) {
db, err := client.GetDbClient()
if err != nil {
return nil, resp.DbConnectError.WithError(err)
}
selectSql := "su.id, su.organization_id, su.phone, su.system_account, so.name as organization, su.created_by,u.name as created_name, " +
"su.updated_time, su.created_time, su.name, su.logo, su.state"
var result response.OrgUserDetail
has, err := db.Table("system_user").Alias("su").
Select(selectSql).
Join("left", "system_organization so", "so.organization_id = su.organization_id").
Join("left", "system_user u", "u.id = su.created_by").
Where("su.id = ? and su.is_deleted = 0", id).Get(&result)
if err != nil {
conf.Logger.Error("查询组织用户详情失败", zap.Error(err))
return nil, resp.DbSelectError.WithError(err)
}
if !has {
return nil, resp.DbSelectError.ErrorDetail(errors.New("用户不存在"))
}
//查询用户角色
//var systemUserRoles []response.SystemUserRole
//if err := db.Table("system_user_role").Alias("sur").Select(" sr.role_name").
// Join("left", "system_role sr", "sr.role_id = sur.role_id").Where("sur.user_id = ?", result.Id).Find(&systemUserRoles); err != nil {
// conf.Logger.Error("查询用户角色信息失败", zap.Error(err))
// return nil, resp.DbSelectError.ErrorDetail(err)
//}
//for _, v := range systemUserRoles {
// result.SystemRole = append(result.SystemRole, v.RoleName)
//}
return result, nil
}
// 组织添加用户时查询角色列表 查询非内置角色 + 平台运营者
func (o *User) OrgUserRoles(hasAdmin int) (interface{}, error) {
db, err := client.GetDbClient()
if err != nil {
return nil, resp.DbConnectError.ErrorDetail(err)
}
session := db.Table("system_role").Where("role_type = 0 and is_deleted = 0 and state = 1 ")
if hasAdmin == 1 {
session.Or("role_type = 1 and is_deleted = 0 and state = 1")
}
var roles []entity.SystemRole
if err := session.Find(&roles); err != nil {
conf.Logger.Error("查询用户角色信息失败", zap.Error(err))
return nil, resp.DbSelectError.ErrorDetail(err)
}
return roles, nil
}
// 添加组织用户
func (o *User) OrgAddUser(input request.OrgUserInput) error {
db, err := client.GetDbClient()
if err != nil {
return resp.DbConnectError.WithError(err)
}
//验证账号是否存在
has, err := db.Table("system_user").Select("id").Where("system_account = ? and is_deleted = 0", input.SystemAccount).Exist(&entity.SystemUser{})
if err != nil {
conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
return resp.DbInsertError.WithError(err)
}
if has {
return resp.DbInsertError.WithMsg("账号已存在")
}
//验证手机号是否存在
has, err = db.Table("system_user").Select("id").Where("phone = ? and is_deleted = 0", input.Phone).Exist(&entity.SystemUser{})
if err != nil {
conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
return resp.DbInsertError.ErrorDetail(err)
}
if has {
return resp.DbInsertError.WithMsg("手机号已存在")
}
userModel := entity.SystemUser{
OrganizationId: input.OrganizationId,
Name: input.Name,
Logo: input.Logo,
SystemAccount: input.SystemAccount,
Phone: input.Phone,
State: input.State,
CreatedBy: o.User.Id,
}
_, err = db.Transaction(func(s *xorm.Session) (interface{}, error) {
if _, err := s.Table("system_user").Insert(&userModel); err != nil {
conf.Logger.Error("创建系统账户失败", zap.Error(err))
return nil, resp.DbInsertError.ErrorDetail(err)
}
upperMd5Pass, err := SolvePassword(userModel.Id, input.Password)
if err != nil {
conf.Logger.Error("密码处理出错", zap.Error(err))
return nil, resp.DbInsertError.ErrorDetail(err)
}
_, err = s.Table("system_user").Where("id = ?", userModel.Id).Update(map[string]string{
"password": upperMd5Pass,
})
if err != nil {
conf.Logger.Error("密码处理出错", zap.Error(err))
return nil, resp.DbInsertError.ErrorDetail(err)
}
//var systemUserRoles []entity.SystemUserRole
//for _, v := range input.SelectRole {
// systemUserRoles = append(systemUserRoles, entity.SystemUserRole{SystemId: systemId, RoleId: v})
//}
//if _, err := s.Table("system_user_role").Insert(&systemUserRoles); err != nil {
// conf.Logger.Error("创建用户角色失败", zap.Error(err))
// return nil, res.DbInsertError.ErrorDetail(err)
//}
return nil, nil
})
return err
}
// 更新组织用户
func (o *User) OrgUpdateUser(id int, input request.UpdateOrgUserInput) error {
db, err := client.GetDbClient()
if err != nil {
return resp.DbConnectError.ErrorDetail(err)
}
var baseUser entity.SystemUser
has, err := db.Table("system_user").ID(id).Where("is_deleted = 0").Get(&baseUser)
if err != nil {
conf.Logger.Error("查询账号信息失败", zap.Error(err))
return resp.DbUpdateError.ErrorDetail(err)
}
if !has {
return resp.DbUpdateError.ErrorDetail(errors.New("该用户不存在"))
}
if baseUser.SystemAccount != input.SystemAccount {
//验证账号是否存在
has, err = db.Table("system_user").Select("id").Where("system_account = ? and is_deleted = 0", input.SystemAccount).Exist(&entity.SystemUser{})
if err != nil {
conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
return resp.DbUpdateError.ErrorDetail(err)
}
if has {
return resp.DbUpdateError.ErrorDetail(errors.New("账号已存在"))
}
}
if baseUser.Phone != input.Phone {
//验证手机号是否存在
has, err = db.Table("system_user").Select("id").Where("phone = ? and is_deleted = 0", input.Phone).Exist(&entity.SystemUser{})
if err != nil {
conf.Logger.Error("查询账号信息验证失败", zap.Error(err))
return resp.DbUpdateError.ErrorDetail(err)
}
if has {
return resp.DbUpdateError.ErrorDetail(errors.New("手机号已存在"))
}
}
userModel := entity.SystemUser{
Logo: input.Logo,
SystemAccount: input.SystemAccount,
Phone: input.Phone,
State: input.State,
Name: input.Name,
UpdatedBy: o.User.Id,
}
if _, err := db.Table("system_user").ID(id).Cols("logo,system_account,phone,state,name,update_by").Update(&userModel); err != nil {
conf.Logger.Error("账号信息更新失败", zap.Error(err))
return resp.DbUpdateError.ErrorDetail(err)
}
return nil
}
// 删除组织用户
func (o *User) DelOrgUser(input request.DelOrgUser) error {
db, err := client.GetDbClient()
if err != nil {
return resp.DbConnectError.ErrorDetail(err)
}
_, err = db.Transaction(func(s *xorm.Session) (interface{}, error) {
var baseUsers []entity.SystemUser
if err := s.Table("system_user").In("id", input.Ids).Where("is_deleted = 0").Find(&baseUsers); err != nil {
conf.Logger.Error("查询账号信息失败", zap.Error(err))
return nil, resp.DbDeleteError.ErrorDetail(err)
}
if len(baseUsers) == 0 {
return nil, resp.DbDeleteError.ErrorDetail(errors.New("用户数据不存在,删除失败"))
}
for _, v := range baseUsers {
if v.State == 1 {
return nil, resp.DbDeleteError.ErrorDetail(errors.New("删除内容中有启用状态的数据,不可删除!"))
}
}
if _, err := db.Table("system_user").In("id", input.Ids).Update(&entity.SystemUser{IsDeleted: 1, UpdatedBy: o.User.Id}); err != nil {
conf.Logger.Error("用户删除失败", zap.Error(err))
return nil, resp.DbDeleteError.ErrorDetail(err)
}
//删除用户关联角色
//var user_ids []int
//for _, v := range baseUsers {
// user_ids = append(user_ids, v.Id)
//}
//if _, err := db.Table("system_user_role").In("user_id", user_ids).Delete(&entity.SystemUserRole{}); err != nil {
// conf.Logger.Error("删除用户关联角色失败", zap.Error(err))
// return nil, res.DbDeleteError.ErrorDetail(err)
//}
return nil, nil
})
return err
}
// 去重校验
func (o *User) CheckRepetition(input request.CheckRepetition) error {
db, err := client.GetDbClient()
if err != nil {
return resp.DbConnectError.ErrorDetail(err)
}
var system_user entity.SystemUser
if input.Id != 0 {
if _, err := db.Table("system_user").Select("id, phone").ID(input.Id).Where("is_deleted = 0").Get(&system_user); err != nil {
conf.Logger.Error("查询用户失败", zap.Error(err))
return resp.DbDataCheckError.ErrorDetail(err)
}
}
if input.Phone != system_user.Phone {
has, err := db.Table("system_user").Select("id").Where("phone = ? and is_deleted = 0", &input).Exist(&entity.SystemUser{})
if err != nil {
conf.Logger.Error("手机号去重查询失败", zap.Error(err))
return resp.DbDataCheckError.ErrorDetail(err)
}
if has {
return resp.DbDataCheckError.ErrorDetail(errors.New("该手机号已注册"))
}
}
return nil
}
// SystemUserEditPassword 修改密码
func SystemUserEditPassword(params request.SystemUserEditPasswordReq) (err error) {
db, err := client.GetDbClient()
if err != nil {
err = resp.DbConnectError.ErrorDetail(err)
return
}
oldSystemUser := entity.SystemUser{}
has, err := db.Cols("password", "id").ID(params.Id).Get(&oldSystemUser)
if err != nil || !has {
conf.Logger.Error("查询系统账户详情失败", zap.Error(err))
err = resp.DbSelectError.ErrorDetail(errors.New("查询系统账户详情失败"))
return
}
password, err := SolvePassword(oldSystemUser.Id, params.Password)
if err != nil {
return
}
SystemUser := entity.SystemUser{}
SystemUser.Password = password
_, err = db.Where("id=?", oldSystemUser.Id).Where("is_deleted = 0").Update(&SystemUser)
if err != nil {
conf.Logger.Error("修改系统账户失败", zap.Error(err))
err = resp.DbUpdateError.ErrorDetail(errors.New("修改系统账户失败"))
return
}
return
}
// ResetSystemUserPassword 批量重置密码
func ResetSystemUserPassword(params request.ResetSystemUserPasswordReq) (err error) {
db, err := client.GetDbClient()
if err != nil {
err = resp.DbConnectError.ErrorDetail(err)
return
}
str, EncryptErr := util.EncryptPwd(defaultPassword)
if EncryptErr != nil {
err = resp.DbUpdateError.ErrorDetail(err)
}
for _, v := range params.Ids {
password, SolvePwdErr := SolvePassword(v, str)
if SolvePwdErr != nil {
return SolvePwdErr
}
updateData := entity.SystemUser{}
updateData.Password = password
_, err = db.Where("id=?", v).Update(&updateData)
if err != nil {
conf.Logger.Error("重置账户密码失败", zap.Error(err))
err = resp.DbUpdateError.ErrorDetail(errors.New("重置账户密码失败"))
return
}
}
return
}
// SolvePassword 密码处理
func SolvePassword(userId int, password string) (string, error) {
passwordKey, err := util.DecryptPwd(password)
if passwordKey == "" {
return "", resp.InvalidParam.WithError(err)
}
h := md5.New()
_, err = h.Write([]byte(strings.ToUpper(fmt.Sprintf("%v-%v", userId, passwordKey))))
if err != nil {
return "", resp.InvalidParam.WithError(err)
}
md5Pwd := strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
return md5Pwd, nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment