diff --git a/app/api/user.go b/app/api/user.go index 2549d34..3ac58f2 100644 --- a/app/api/user.go +++ b/app/api/user.go @@ -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) +} diff --git a/app/common/model/sys_department.go b/app/common/model/sys_department.go deleted file mode 100644 index 8128537..0000000 --- a/app/common/model/sys_department.go +++ /dev/null @@ -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{} -} diff --git a/app/common/model/sys_role.go b/app/common/model/sys_role.go index 0cb3a7e..6fdc1ec 100644 --- a/app/common/model/sys_role.go +++ b/app/common/model/sys_role.go @@ -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{} } diff --git a/app/common/model/sys_user.go b/app/common/model/sys_user.go index c371b8b..5cb4896 100644 --- a/app/common/model/sys_user.go +++ b/app/common/model/sys_user.go @@ -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" } diff --git a/app/common/model/sys_user_tenant.go b/app/common/model/sys_user_tenant.go deleted file mode 100644 index c7732da..0000000 --- a/app/common/model/sys_user_tenant.go +++ /dev/null @@ -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{} -} diff --git a/app/controller/user/instance.go b/app/controller/user/instance.go index 8337b20..78007df 100644 --- a/app/controller/user/instance.go +++ b/app/controller/user/instance.go @@ -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) diff --git a/app/model/sys_deparement.go b/app/model/sys_deparement.go deleted file mode 100644 index 76a2cd5..0000000 --- a/app/model/sys_deparement.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -import "ArmedPolice/app/common/model" - -type SysDepartment struct { - *model.SysDepartment -} - -func NewSysDepartment() *SysDepartment { - return &SysDepartment{SysDepartment: model.NewSysDepartment()} -} diff --git a/router/router.go b/router/router.go index 12e76bc..e4befe8 100644 --- a/router/router.go +++ b/router/router.go @@ -54,6 +54,7 @@ func (this *Router) registerAPI() { { _api := new(api.User) UserV1.GET("/info", _api.Info) + UserV1.GET("/list", _api.List) } }