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 {
UpdatedBy int `json:"updated_by" ` // 更新者
UpdatedTime time.Time `json:"updated_time" xorm:"updated" ` // 更新时间
IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除
Phone string `json:"phone" xorm:"phone"` // 手机号
}
type SystemUserInfo struct {
......@@ -28,4 +29,5 @@ type SystemUserInfo struct {
State int `json:"state" xorm:"state"` // 状态0禁用1启用
Logo string `json:"logo" xorm:"logo"` // 头像logo
IsDeleted int `json:"is_deleted" xorm:"is_deleted"` // 是否删除
Phone string `json:"phone" xorm:"phone"` // 手机号
}
......@@ -34,33 +34,26 @@ type GetBusinessMsgInput struct {
// 新增用户
type OrgUserInput struct {
Name string `json:"name"` // 姓名
Logo string `json:"logo"` // 头像logo
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:'请输入密码'"` // 密码
SelectRole []string `json:"select_role"` // 选择角色
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:'请选择所属组织'"` // 所属组织
DocumentType int64 `json:"document_type"` //证件类型 1 身份证
DocumentNumber string `json:"document_number"` //证件号
IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
//IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
}
// 编辑用户
type UpdateOrgUserInput struct {
Logo string `json:"logo"` // 头像logo
SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号
ContactPhone string `json:"contact_phone" vd:"phone($)"` // 联系人电话
// SelectRole []string `json:"select_role"` // 选择角色
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"` //证件号
Name string `json:"name"` // 联系人姓名
Logo string `json:"logo"` // 头像logo
SystemAccount string `json:"system_account" vd:"len($)>1;msg:'请输入账号'"` // 系统账号
Phone string `json:"phone" vd:"phone($)"` // 联系人电话
SelectRole []string `json:"select_role"` // 选择角色
State int `json:"state"` // 状态0禁用1启用
}
// 删除用户
......@@ -70,6 +63,6 @@ type DelOrgUser struct {
// 去重校验
type CheckRepetition struct {
Id int `form:"id" json:"id"`
ContactPhone string `form:"contact_phone" json:"contact_phone"`
Id int `form:"id" json:"id"`
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
}
......@@ -34,25 +34,19 @@ type OrgAdminUser struct {
// 账号详情
type OrgUserDetail struct {
Id int32 `json:"id" xorm:"pk autoincr" ` // id
ContactPhone string `json:"contact_phone" xorm:"contact_phone"` // 联系人电话
SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号
SystemRole []string `json:"system_role" xorm:"-"` // 系统角色id
Organization string `json:"organization" xorm:"organization"` // 所属组织
OrganizationId string `json:"organization_id"` // 所属组织
CreatedBy string `json:"created_by"` // 创建者
CreatedByAccount string `json:"created_by_account"` // 创建账号
UpdatedTime jsontime.Time `json:"updated_time" xorm:"updated" ` // 更新时间
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
State int `json:"state"` // 状态0禁用1启用
SystemId string `json:"-" xorm:"system_id"` // 系统账号id
IsAdmin int `json:"is_admin"` // 用户类型(1.业务系统账号 2.组织管理员账号 3.平台用户账号)
Id int32 `json:"id" xorm:"pk autoincr" ` // id
Name string `json:"name" xorm:"name"` // 联系人姓名
Phone string `json:"phone" xorm:"phone"` // 联系人电话
SystemAccount string `json:"system_account" xorm:"system_account"` // 系统账号
SystemRole []string `json:"system_role" xorm:"-"` // 系统角色id
Organization string `json:"organization" xorm:"organization"` // 所属组织
OrganizationId string `json:"organization_id"` // 所属组织
CreatedBy int `json:"created_by"` // 创建者
CreatedName string `json:"created_name"` // 创建账号
UpdatedTime jsontime.Time `json:"updated_time" xorm:"updated" ` // 更新时间
CreatedTime jsontime.Time `json:"created_time" xorm:"created" ` // 创建时间
Logo string `json:"logo"` // 头像logo
State int `json:"state"` // 状态0禁用1启用
}
// 编辑组织账号
......@@ -80,9 +74,3 @@ type OrgDetail struct {
Description string `json:"description"` //组织介绍
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 (
// 系统用户角色关联查询
type SystemUserRole struct {
SystemId string `json:"system_id" xorm:"system_id"` // 系统账号id
RoleName string `json:"role_name"` // 角色名称
UserId int `json:"user_id" xorm:"user_id"` // 用户id
RoleId string `json:"role_id" xorm:"role_id"` // 角色id
RoleName string `json:"role_name"` // 角色名称
}
type SystemRoleList struct {
Id int64 `json:"id"` // id
RoleName string `json:"role_name"` // 角色名称
......
......@@ -134,141 +134,3 @@ func OrgDetail(c *gin.Context) {
}
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 {
return r
}
func (r Resp) ErrorDetail(err error) Resp {
if err != nil {
r.Data = err.Error()
}
return r
}
// TranslateError 翻译validate验证错误
func (r Resp) TranslateError(err error) Resp {
translatedErrors := make([]string, 0)
......
......@@ -19,12 +19,5 @@ func InitOrganizationRouter(e *gin.Engine) {
base.PUT("/sort", controller.SortOrg) //组织排序
base.GET("/tree", controller.GetOrgTree) //查询组织树
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) {
InitSystemLoginRouter(r)
// 初始化组织相关路由
InitOrganizationRouter(r)
// 初始化用户相关路由
InitSystemUserRouter(r)
// 初始化指标配置路由
InitMetricConfigRouter(r)
// 初始化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) // 重置账户密码
}
}
This diff is collapsed.
This diff is collapsed.
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