feat:完善项目
This commit is contained in:
@ -12,3 +12,51 @@ func (*User) Info(c *gin.Context) {
|
||||
data := user.NewInstance()(getSession()(c).(*service.Session)).Info()
|
||||
APIResponse(nil, data)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (*User) Add(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)
|
||||
}
|
||||
|
||||
func (*User) Edit(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)
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package model
|
||||
|
||||
type SysDepartment struct {
|
||||
Model
|
||||
ModelTenant
|
||||
ParentID uint64 `gorm:"column:parent_id;type:int;default:0;comment:父级ID" json:"parent_id"`
|
||||
Title string `gorm:"column:title;type:varchar(20);default:null;comment:部门名称" json:"title"`
|
||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:联系人" json:"name"`
|
||||
Mobile string `gorm:"column:mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注信息" json:"remark"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *SysDepartment) TableName() string {
|
||||
return m.NewTableName("sys_department")
|
||||
}
|
||||
|
||||
func NewSysDepartment() *SysDepartment {
|
||||
return &SysDepartment{}
|
||||
}
|
@ -3,37 +3,17 @@ package model
|
||||
type SysRole struct {
|
||||
Model
|
||||
ModelTenant
|
||||
Name string `gorm:"column:name;type:varchar(30);default:null;comment:角色名" json:"name"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:角色备注" json:"remark"`
|
||||
Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:排序" json:"-"`
|
||||
Status SysRoleStatus `gorm:"column:status;type:tinyint(1);default:0;comment:状态" json:"-"`
|
||||
Name string `gorm:"column:name;type:varchar(30);default:null;comment:角色名" json:"name"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:角色备注" json:"remark"`
|
||||
Sort int `gorm:"column:sort;type:tinyint(3);default:0;comment:排序" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
// SysRoleStatus 角色状态
|
||||
type SysRoleStatus int
|
||||
|
||||
const (
|
||||
// SysRoleStatusForNormal 正常
|
||||
SysRoleStatusForNormal SysRoleStatus = iota + 1
|
||||
// SysRoleStatusForDisable 禁用
|
||||
SysRoleStatusForDisable
|
||||
)
|
||||
|
||||
func (m *SysRole) TableName() string {
|
||||
return m.NewTableName("sys_role")
|
||||
}
|
||||
|
||||
func (m *SysRole) StatusTitle() string {
|
||||
if m.Status == SysRoleStatusForNormal {
|
||||
return "正常"
|
||||
} else if m.Status == SysRoleStatusForDisable {
|
||||
return "禁用"
|
||||
}
|
||||
return "-"
|
||||
}
|
||||
|
||||
func NewSysRole() *SysRole {
|
||||
return &SysRole{}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ type SysUser struct {
|
||||
Salt string `gorm:"column:salt;type:varchar(10);default:null;comment:盐值" json:"-"`
|
||||
IsAdmin SysUserAdministrator `gorm:"column:is_admin;type:tinyint(1);default:0;comment:管理员(0:普通用户,1:管理员)" json:"-"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:null;comment:备注" json:"-"`
|
||||
Status SysUserStatus `gorm:"column:status;type:tinyint(1);default:1;comment:账号状态" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
@ -34,6 +35,15 @@ const (
|
||||
SysUserAdministratorForAdmin
|
||||
)
|
||||
|
||||
type SysUserStatus int
|
||||
|
||||
const (
|
||||
// SysUserStatusForNormal 正常
|
||||
SysUserStatusForNormal SysUserStatus = 1
|
||||
// SysUserStatusForDisable 禁止登陆
|
||||
SysUserStatusForDisable
|
||||
)
|
||||
|
||||
func (m *SysUser) TableName() string {
|
||||
return "sys_user"
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
package model
|
||||
|
||||
type SysUserTenant struct {
|
||||
Model
|
||||
ModelTenant
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Department string `gorm:"column:department;type:varchar(100);default:null;comment:部门信息" json:"department"`
|
||||
Role string `gorm:"column:role;type:varchar(100);default:null;comment:角色信息" json:"role"`
|
||||
Identity SysUserTenantIdentity `gorm:"column:identity;type:tinyint(1);default:0;comment:用户身份(1:管理员,2:用户)" json:"-"`
|
||||
Status SysUserTenantStatus `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:启用,2:禁用)" json:"-"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
type SysUserTenantIdentity int
|
||||
|
||||
const (
|
||||
// SysUserTenantIdentityForSystemAdmin 管理员
|
||||
SysUserTenantIdentityForSystemAdmin SysUserTenantIdentity = iota + 1
|
||||
// SysUserTenantIdentityForSystemUser 用户
|
||||
SysUserTenantIdentityForSystemUser
|
||||
)
|
||||
|
||||
// SysUserTenantStatus 状态
|
||||
type SysUserTenantStatus int
|
||||
|
||||
const (
|
||||
// SysUserTenantStatusForEnable 启用
|
||||
SysUserTenantStatusForEnable SysUserTenantStatus = iota + 1
|
||||
// SysUserTenantStatusForDisable 禁用
|
||||
SysUserTenantStatusForDisable
|
||||
)
|
||||
|
||||
func (m *SysUserTenant) TableName() string {
|
||||
return m.NewTableName("sys_user_tenant")
|
||||
}
|
||||
|
||||
func NewSysUserTenant() *SysUserTenant {
|
||||
return &SysUserTenant{}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
@ -29,8 +30,20 @@ func (c *Instance) Info() *InstanceBasic {
|
||||
}
|
||||
|
||||
// List 列表信息
|
||||
func (c *Instance) List(name string, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
func (c *Instance) List(name, mobile string, tenantID uint64, page, pageSize int) (*basic.PageDataResponse, error) {
|
||||
mSysUser := model.NewSysUser()
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("u.mobile", mobile))
|
||||
}
|
||||
if tenantID > 0 {
|
||||
where = append(where, model2.NewWhere("u.tenant_id", tenantID))
|
||||
}
|
||||
var count int64
|
||||
|
||||
out, err := mSysUser.Users(page, pageSize, &count)
|
||||
|
@ -1,11 +0,0 @@
|
||||
package model
|
||||
|
||||
import "ArmedPolice/app/common/model"
|
||||
|
||||
type SysDepartment struct {
|
||||
*model.SysDepartment
|
||||
}
|
||||
|
||||
func NewSysDepartment() *SysDepartment {
|
||||
return &SysDepartment{SysDepartment: model.NewSysDepartment()}
|
||||
}
|
@ -54,6 +54,7 @@ func (this *Router) registerAPI() {
|
||||
{
|
||||
_api := new(api.User)
|
||||
UserV1.GET("/info", _api.Info)
|
||||
UserV1.GET("/list", _api.List)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user