544 lines
14 KiB
Go
544 lines
14 KiB
Go
package api
|
||
|
||
import (
|
||
model2 "ArmedPolice/app/common/model"
|
||
"ArmedPolice/app/controller/user"
|
||
"ArmedPolice/app/service"
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
/**
|
||
* @apiDefine User 用户管理
|
||
*/
|
||
|
||
type User struct{}
|
||
|
||
type userForm struct {
|
||
TenantID string `json:"tenant_id" form:"tenant_id"`
|
||
Account string `json:"account" form:"account" binding:"required"`
|
||
Name string `json:"name" form:"name" binding:"required"`
|
||
Avatar string `json:"avatar" form:"avatar"`
|
||
Mobile string `json:"mobile" form:"mobile" binding:"required"`
|
||
Password string `json:"password" form:"password"`
|
||
Gender int `json:"gender" form:"gender" binding:"required"`
|
||
Status int `json:"status" form:"status" binding:"required"`
|
||
Remark string `json:"remark" form:"remark"`
|
||
RoleIDs []string `json:"role_ids" form:"role_ids"`
|
||
}
|
||
|
||
func (this *userForm) avatarInfo() string {
|
||
obj := &ImageForm{Image: this.Avatar}
|
||
return obj.FilterImageURL()
|
||
}
|
||
|
||
func (this *userForm) tenantInfo() uint64 {
|
||
obj := &IDStringForm{ID: this.TenantID}
|
||
return obj.Convert()
|
||
}
|
||
|
||
// roleInfo 角色信息
|
||
func (this *userForm) roleInfo() []uint64 {
|
||
obj := new(IDStringForm)
|
||
roleIDs := make([]uint64, 0)
|
||
|
||
for _, v := range this.RoleIDs {
|
||
obj.ID = v
|
||
roleIDs = append(roleIDs, obj.Convert())
|
||
}
|
||
return roleIDs
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/user/info 用户信息
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserInfo
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
* @apiSuccess (200) {String} data.name 用户名
|
||
* @apiSuccess (200) {String} data.avatar 用户头像
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": {
|
||
* "name": "商挈智能",
|
||
* "avatar": "",
|
||
* }
|
||
* }
|
||
*/
|
||
func (*User) Info(c *gin.Context) {
|
||
data := user.NewInstance()(getSession()(c).(*service.Session)).Info()
|
||
APIResponse(nil, data)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/user/select 用户Select信息
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserSelect
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
* @apiSuccess (200) {String} data.id ID-即uuid
|
||
* @apiSuccess (200) {String} data.name 用户名
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "id": "2098151543063711744",
|
||
* "name": "超级管理员",
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
func (*User) Select(c *gin.Context) {
|
||
data, err := user.NewInstance()(getSession()(c).(*service.Session)).Select()
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/user/menu 用户菜单信息
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserMenu
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息-参考菜单信息
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "id": "7X2JlBVknr",
|
||
* "name": "装备维修",
|
||
* "kind": 1,
|
||
* "link": "",
|
||
* "component": "",
|
||
* "icon": "",
|
||
* "parent_id": "",
|
||
* "checked": true,
|
||
* "checked": [],
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
func (*User) Menu(c *gin.Context) {
|
||
data, err := user.NewMenu()(getSession()(c).(*service.Session)).Menu()
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
func (*User) List(c *gin.Context) {
|
||
form := &struct {
|
||
Name string `json:"name" form:"name"`
|
||
Mobile string `json:"mobile" form:"mobile"`
|
||
TenantID uint64 `json:"tenant_id" form:"tenant_id"`
|
||
PageForm
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
data, err := user.NewInstance()(getSession()(c).(*service.Session)).List(form.Name, form.Mobile, form.TenantID,
|
||
form.Page, form.PageSize)
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
func (*User) Detail(c *gin.Context) {
|
||
form := new(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
data, err := user.NewInstance()(getSession()(c).(*service.Session)).Detail(form.Convert())
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/add 用户信息添加
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserAdd
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} tenant_id 租户单位信息
|
||
* @apiParam {String} account 登陆账号
|
||
* @apiParam {String} name 姓名
|
||
* @apiParam {String} [avatar="''"] 头像
|
||
* @apiParam {String} mobile 手机号
|
||
* @apiParam {String} password 密码
|
||
* @apiParam {Number} gender 性别,1:男,2:女
|
||
* @apiParam {Number} status 状态,1:启用,2:禁用
|
||
* @apiParam {String} [remark="''"] 备注信息
|
||
* @apiParam {String[]} [role_ids="[]"] 角色信息
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
* @apiSuccess (200) {String} data.name 用户名
|
||
* @apiSuccess (200) {String} data.avatar 用户头像
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (*User) Add(c *gin.Context) {
|
||
form := new(userForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).Form(&user.InstanceParams{
|
||
TenantID: form.tenantInfo(), Account: form.Account, Name: form.Name, Avatar: form.avatarInfo(),
|
||
Mobile: form.Mobile, Password: form.Password, Remark: form.Remark, Gender: form.Gender, Status: form.Status,
|
||
RoleIDs: form.roleInfo(),
|
||
})
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/edit 用户信息修改
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserEdit
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
* @apiParam {String} tenant_id 租户单位信息
|
||
* @apiParam {String} account 登陆账号
|
||
* @apiParam {String} name 姓名
|
||
* @apiParam {String} [avatar="''"] 头像
|
||
* @apiParam {String} mobile 手机号
|
||
* @apiParam {Number} gender 性别,1:男,2:女
|
||
* @apiParam {Number} status 状态,1:启用,2:禁用
|
||
* @apiParam {String} [remark="''"] 备注信息
|
||
* @apiParam {String[]} [role_ids="[]"] 角色信息
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
* @apiSuccess (200) {String} data.name 用户名
|
||
* @apiSuccess (200) {String} data.avatar 用户头像
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
|
||
func (*User) Edit(c *gin.Context) {
|
||
form := &struct {
|
||
IDStringForm
|
||
userForm
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).Form(&user.InstanceParams{
|
||
ID: form.Convert(), TenantID: form.tenantInfo(), Account: form.Account, Name: form.Name, Avatar: form.avatarInfo(),
|
||
Mobile: form.Mobile, Password: form.Password, Remark: form.Remark, Gender: form.Gender, Status: form.Status,
|
||
RoleIDs: form.roleInfo(),
|
||
})
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/delete 用户信息删除
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserDelete
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
*
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (*User) Delete(c *gin.Context) {
|
||
form := new(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/password/quick 用户密码快速设置
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserPasswordQuick
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
* @apiParam {String} passowrd 密码
|
||
*
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (*User) PasswordQuick(c *gin.Context) {
|
||
form := &struct {
|
||
IDStringForm
|
||
Password string `json:"password" form:"password" binding:"required"`
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).PasswordQuick(form.Convert(), form.Password)
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/password/tradition 用户密码传统设置
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserPasswordTradition
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
* @apiParam {String} original_pwd 旧密码
|
||
* @apiParam {String} passowrd 新密码
|
||
* @apiParam {String} repeat_pwd 重复密码
|
||
*
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (*User) PasswordTradition(c *gin.Context) {
|
||
form := &struct {
|
||
IDStringForm
|
||
OriginalPwd string `json:"original_pwd" form:"original_pwd" binding:"required"`
|
||
Password string `json:"password" form:"password" binding:"required"`
|
||
RepeatPwd string `json:"repeat_pwd" form:"repeat_pwd" binding:"required"`
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).PasswordTradition(form.Convert(),
|
||
form.OriginalPwd, form.Password, form.RepeatPwd)
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/activate 用户账号激活
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserPasswordActivate
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
*
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (*User) Activate(c *gin.Context) {
|
||
form := new(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).Status(form.Convert(), model2.SysUserStatusForNormal)
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/frozen 用户账号冻结
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserPasswordFrozen
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
*
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (*User) Frozen(c *gin.Context) {
|
||
form := new(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := user.NewInstance()(getSession()(c).(*service.Session)).Status(form.Convert(), model2.SysUserStatusForDisable)
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {get} /api/v1/user/role 用户角色信息
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserRole
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
*
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
* @apiSuccess (200) {String} data.id 角色ID
|
||
* @apiSuccess (200) {String} data.name 角色名称
|
||
* @apiSuccess (200) {String} data.parent_id 角色父集ID
|
||
* @apiSuccess (200) {Object} data.children 子集
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": [
|
||
* {
|
||
* "id": "EgmJ4Ga7LQ",
|
||
* "name": "分管领导",
|
||
* "parent_id": "",
|
||
* "checked": true,
|
||
* "children": [
|
||
* {
|
||
* "id": "7K1Jx6VYod",
|
||
* "name": "区域支队",
|
||
* }
|
||
* ]
|
||
* }
|
||
* ]
|
||
* }
|
||
*/
|
||
func (a *User) Role(c *gin.Context) {
|
||
form := new(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
data, err := user.NewRole()(getSession()(c).(*service.Session)).List(form.Convert())
|
||
APIResponse(err, data)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/user/role/bind 用户角色绑定
|
||
* @apiVersion 1.0.0
|
||
* @apiName UserRoleBind
|
||
* @apiGroup User
|
||
*
|
||
* @apiHeader {string} x-token token
|
||
*
|
||
* @apiParam {String} id ID
|
||
* @apiParam {Array.string} role_ids 角色IDs
|
||
*
|
||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||
* @apiSuccess (200) {String} msg 成功提示
|
||
* @apiSuccess (200) {Object} data 数据信息
|
||
*
|
||
* @apiSuccessExample {json} Success response:
|
||
* HTTPS 200 OK
|
||
* {
|
||
* "code": 200
|
||
* "msg": "ok"
|
||
* "data": null
|
||
* }
|
||
*/
|
||
func (a *User) RoleBind(c *gin.Context) {
|
||
form := &struct {
|
||
IDStringForm
|
||
RoleIDs []string `json:"role_ids" form:"role_ids" binding:"required"`
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
obj := new(IDStringForm)
|
||
roleIDs := make([]uint64, 0)
|
||
|
||
for _, v := range form.RoleIDs {
|
||
obj.ID = v
|
||
roleIDs = append(roleIDs, obj.Convert())
|
||
}
|
||
err := user.NewRole()(getSession()(c).(*service.Session)).Bind(form.Convert(), roleIDs)
|
||
APIResponse(err)(c)
|
||
}
|