feat:完善项目
This commit is contained in:
105
app/api/user.go
105
app/api/user.go
@ -215,7 +215,7 @@ func (*User) Delete(c *gin.Context) {
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
@ -253,7 +253,7 @@ func (*User) PasswordQuick(c *gin.Context) {
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
@ -291,7 +291,7 @@ func (*User) PasswordTradition(c *gin.Context) {
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
@ -313,9 +313,9 @@ func (*User) Activate(c *gin.Context) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/v1/user/password/frozen( 用户账号冻结
|
||||
* @api {get} /api/v1/user/password/frozen 用户账号冻结
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName UserPasswordFrozen(
|
||||
* @apiName UserPasswordFrozen
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
@ -324,7 +324,7 @@ func (*User) Activate(c *gin.Context) {
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Json} data 数据信息
|
||||
* @apiSuccess (200) {Object} data 数据信息
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
@ -344,3 +344,96 @@ func (*User) Frozen(c *gin.Context) {
|
||||
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) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @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 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* {
|
||||
* "id": "EgmJ4Ga7LQ",
|
||||
* "name": "分管领导",
|
||||
* "parent_id": "0",
|
||||
* "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 {get} /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)
|
||||
}
|
||||
|
@ -1,24 +1,115 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/basic"
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/serve/orm"
|
||||
"ArmedPolice/utils"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Role struct{ *service.Session }
|
||||
|
||||
type RoleHandle func(session *service.Session) *Role
|
||||
|
||||
func (c *Role) List() (*basic.PageDataResponse, error) {
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
// RoleInfo 基本信息
|
||||
type RoleInfo struct {
|
||||
ID string `json:"id"`
|
||||
ParentID string `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
Checked bool `json:"checked"`
|
||||
Children []*RoleInfo `json:"children"`
|
||||
}
|
||||
|
||||
func (c *Role) Form() error {
|
||||
return nil
|
||||
func (c *Role) tree(iModel model2.IModel, src []*model.SysRoleUserInfo, parentID uint64) []*RoleInfo {
|
||||
out := make([]*RoleInfo, 0)
|
||||
|
||||
for _, v := range src {
|
||||
if v.ParentID == parentID {
|
||||
iModel.SetID(v.ID)
|
||||
id := iModel.GetEncodeID()
|
||||
|
||||
_parentID := "0"
|
||||
|
||||
if v.ParentID > 0 {
|
||||
iModel.SetID(v.ID)
|
||||
_parentID = iModel.GetEncodeID()
|
||||
}
|
||||
out = append(out, &RoleInfo{
|
||||
ID: id,
|
||||
ParentID: _parentID,
|
||||
Name: v.Name,
|
||||
Checked: v.UserRoleID > 0,
|
||||
Children: c.tree(iModel, src, v.ID),
|
||||
})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *Role) Delete() error {
|
||||
return nil
|
||||
// List 列表信息
|
||||
func (c *Role) List(id uint64) ([]*RoleInfo, error) {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid"})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, errors.New("操作错误,用户信息不存在或已被删除")
|
||||
}
|
||||
mSysRole := model.NewSysRole()
|
||||
|
||||
out := make([]*model.SysRoleUserInfo, 0)
|
||||
|
||||
if out, err = mSysRole.UserRole(mSysUser.UUID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.tree(mSysRole.SysRole, out, 0), nil
|
||||
}
|
||||
|
||||
func (c *Role) Bind(id uint64, roleIDs []uint64) error {
|
||||
mSysUser := model.NewSysUser()
|
||||
mSysUser.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mSysUser.SysUser, []string{"id", "uuid"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,用户信息不存在或已被删除")
|
||||
}
|
||||
mSysUserRole := model.NewSysUserRole()
|
||||
|
||||
return orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
if err = model2.DeleteWhere(mSysUserRole.SysUserRole, []*model2.ModelWhere{model2.NewWhere("uid", mSysUser.UUID)}, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
roles := make([]*model2.SysUserRole, 0)
|
||||
obj := make([]string, 0)
|
||||
|
||||
mark := make(map[uint64]uint64, 0)
|
||||
|
||||
for _, v := range roleIDs {
|
||||
if _, has := mark[v]; has {
|
||||
continue
|
||||
}
|
||||
obj = append(obj, utils.UintToString(v))
|
||||
|
||||
roles = append(roles, &model2.SysUserRole{
|
||||
UID: mSysUser.UUID, RoleID: v,
|
||||
})
|
||||
mark[v] = v
|
||||
}
|
||||
if err = model2.Creates(mSysUserRole.SysUserRole, roles, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func NewRole() RoleHandle {
|
||||
|
@ -2,12 +2,45 @@ package model
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/common/model"
|
||||
"ArmedPolice/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SysRole struct {
|
||||
*model.SysRole
|
||||
}
|
||||
|
||||
// SysRoleBasic 基本信息
|
||||
type SysRoleBasic struct {
|
||||
ID uint64 `json:"id"`
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// SysRoleUserInfo 用户角色信息
|
||||
type SysRoleUserInfo struct {
|
||||
*SysRoleBasic
|
||||
UserRoleID uint64 `json:"user_role_id"`
|
||||
}
|
||||
|
||||
// UserRole 用户角色信息
|
||||
func (m *SysRole) UserRole(uid uint64) ([]*SysRoleUserInfo, error) {
|
||||
mSysUserRole := NewSysUserRole()
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS r").
|
||||
Select("r.is", "r.parent_id", "r.name", "u_r.id AS user_role_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS u_r ON r.id = u_r.role_id AND u_r.uid = %d AND u_r.is_deleted = %d",
|
||||
mSysUserRole.TableName(), uid, model.DeleteStatusForNot)).
|
||||
Where("r.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
out := make([]*SysRoleUserInfo, 0)
|
||||
|
||||
if err := db.Order("r.sort " + model.OrderModeToDesc).Order("r.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewSysRole() *SysRole {
|
||||
return &SysRole{SysRole: model.NewSysRole()}
|
||||
}
|
||||
|
@ -130,9 +130,9 @@ func (this *Router) registerAPI() {
|
||||
supplierV1.POST("/repair/edit", _api.RepairEdit)
|
||||
supplierV1.POST("/repair/delete", _api.RepairDelete)
|
||||
supplierV1.POST("/manufacturer", _api.Manufacturer)
|
||||
supplierV1.POST("/manufacturer/add", _api.MaterialAdd)
|
||||
supplierV1.POST("/manufacturer/edit", _api.MaterialEdit)
|
||||
supplierV1.POST("/manufacturer/delete", _api.MaterialDelete)
|
||||
supplierV1.POST("/manufacturer/add", _api.ManufacturerAdd)
|
||||
supplierV1.POST("/manufacturer/edit", _api.ManufacturerEdit)
|
||||
supplierV1.POST("/manufacturer/delete", _api.ManufacturerDelete)
|
||||
}
|
||||
// Manage 数据管理
|
||||
manageV1 := v1.Group("/manage")
|
||||
|
Reference in New Issue
Block a user