feat:完善项目

This commit is contained in:
henry
2021-11-02 17:28:19 +08:00
parent 0fa2630933
commit 09ef8a7885
8 changed files with 76 additions and 96 deletions

View File

@ -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)
}

View File

@ -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{}
}

View File

@ -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{}
}

View File

@ -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"
}

View File

@ -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{}
}

View File

@ -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)

View File

@ -1,11 +0,0 @@
package model
import "ArmedPolice/app/common/model"
type SysDepartment struct {
*model.SysDepartment
}
func NewSysDepartment() *SysDepartment {
return &SysDepartment{SysDepartment: model.NewSysDepartment()}
}

View File

@ -54,6 +54,7 @@ func (this *Router) registerAPI() {
{
_api := new(api.User)
UserV1.GET("/info", _api.Info)
UserV1.GET("/list", _api.List)
}
}