mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 02:48:34 +08:00
【新增】部门岗位租户功能
This commit is contained in:
@@ -28,8 +28,12 @@ type DeptApi struct {
|
||||
// @Security X-TOKEN
|
||||
func (m *DeptApi) GetDeptTreeRoleSelect(rc *ctx.ReqCtx) {
|
||||
roleId := ginx.PathParamInt(rc.GinCtx, "roleId")
|
||||
var dept entity.SysDept
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
dept.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
|
||||
result := m.DeptApp.SelectDeptLable(entity.SysDept{})
|
||||
result := m.DeptApp.SelectDeptLable(dept)
|
||||
|
||||
deptIds := make([]int64, 0)
|
||||
if roleId != 0 {
|
||||
@@ -57,7 +61,9 @@ func (a *DeptApi) GetDeptList(rc *ctx.ReqCtx) {
|
||||
status := rc.GinCtx.Query("status")
|
||||
deptId := ginx.QueryInt(rc.GinCtx, "deptId", 0)
|
||||
dept := entity.SysDept{DeptName: deptName, Status: status, DeptId: int64(deptId)}
|
||||
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
dept.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
if dept.DeptName == "" {
|
||||
rc.ResData = a.DeptApp.SelectDept(dept)
|
||||
} else {
|
||||
@@ -72,7 +78,12 @@ func (a *DeptApi) GetDeptList(rc *ctx.ReqCtx) {
|
||||
// @Router /system/dept/ordinaryDeptLis [get]
|
||||
// @Security
|
||||
func (a *DeptApi) GetOrdinaryDeptList(rc *ctx.ReqCtx) {
|
||||
rc.ResData = a.DeptApp.FindList(entity.SysDept{})
|
||||
var dept entity.SysDept
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
dept.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
|
||||
rc.ResData = a.DeptApp.FindList(dept)
|
||||
}
|
||||
|
||||
// @Summary 所有部门树数据
|
||||
@@ -89,7 +100,9 @@ func (a *DeptApi) GetDeptTree(rc *ctx.ReqCtx) {
|
||||
status := rc.GinCtx.Query("status")
|
||||
deptId := ginx.QueryInt(rc.GinCtx, "deptId", 0)
|
||||
dept := entity.SysDept{DeptName: deptName, Status: status, DeptId: int64(deptId)}
|
||||
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
dept.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
rc.ResData = a.DeptApp.SelectDept(dept)
|
||||
}
|
||||
|
||||
@@ -119,7 +132,7 @@ func (a *DeptApi) InsertDept(rc *ctx.ReqCtx) {
|
||||
var dept entity.SysDept
|
||||
g := rc.GinCtx
|
||||
ginx.BindJsonAndValid(g, &dept)
|
||||
|
||||
dept.TenantId = rc.LoginAccount.TenantId
|
||||
dept.CreateBy = rc.LoginAccount.UserName
|
||||
a.DeptApp.Insert(dept)
|
||||
}
|
||||
|
||||
@@ -37,6 +37,11 @@ func (p *PostApi) GetPostList(rc *ctx.ReqCtx) {
|
||||
postName := rc.GinCtx.Query("postName")
|
||||
postCode := rc.GinCtx.Query("postCode")
|
||||
post := entity.SysPost{Status: status, PostName: postName, PostCode: postCode}
|
||||
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
post.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
|
||||
list, total := p.PostApp.FindListPage(pageNum, pageSize, post)
|
||||
|
||||
rc.ResData = map[string]any{
|
||||
@@ -72,7 +77,7 @@ func (p *PostApi) GetPost(rc *ctx.ReqCtx) {
|
||||
func (p *PostApi) InsertPost(rc *ctx.ReqCtx) {
|
||||
var post entity.SysPost
|
||||
ginx.BindJsonAndValid(rc.GinCtx, &post)
|
||||
|
||||
post.TenantId = rc.LoginAccount.TenantId
|
||||
post.CreateBy = rc.LoginAccount.UserName
|
||||
p.PostApp.Insert(post)
|
||||
}
|
||||
|
||||
@@ -38,8 +38,12 @@ func (r *RoleApi) GetRoleList(rc *ctx.ReqCtx) {
|
||||
status := rc.GinCtx.Query("status")
|
||||
roleName := rc.GinCtx.Query("roleName")
|
||||
roleKey := rc.GinCtx.Query("roleKey")
|
||||
|
||||
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
|
||||
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
role.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
|
||||
list, total := r.RoleApp.FindListPage(pageNum, pageSize, role)
|
||||
|
||||
rc.ResData = map[string]any{
|
||||
@@ -199,8 +203,12 @@ func (p *RoleApi) ExportRole(rc *ctx.ReqCtx) {
|
||||
status := rc.GinCtx.Query("status")
|
||||
roleName := rc.GinCtx.Query("roleName")
|
||||
roleKey := rc.GinCtx.Query("roleKey")
|
||||
role := entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
role.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
list := p.RoleApp.FindList(role)
|
||||
|
||||
list := p.RoleApp.FindList(entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey})
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
|
||||
@@ -113,3 +113,11 @@ func (p *SysTenantsApi) DeleteSysTenants(rc *ctx.ReqCtx) {
|
||||
tenantIds := utils.IdsStrToIdsIntGroup(tenantId)
|
||||
p.SysTenantsApp.Delete(tenantIds)
|
||||
}
|
||||
|
||||
// IsTenantAdmin 是否为主租户
|
||||
func IsTenantAdmin(tenantId int64) bool {
|
||||
if tenantId == 1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -179,6 +179,10 @@ func (u *UserApi) GetSysUserList(rc *ctx.ReqCtx) {
|
||||
user.Username = userName
|
||||
user.Phone = phone
|
||||
user.DeptId = int64(deptId)
|
||||
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
user.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
list, total := u.UserApp.FindListPage(pageNum, pageSize, user)
|
||||
|
||||
rc.ResData = map[string]any{
|
||||
@@ -281,9 +285,17 @@ func (u *UserApi) GetSysUser(rc *ctx.ReqCtx) {
|
||||
user.UserId = int64(userId)
|
||||
result := u.UserApp.FindOne(user)
|
||||
|
||||
roles := u.RoleApp.FindList(entity.SysRole{})
|
||||
var role entity.SysRole
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
role.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
roles := u.RoleApp.FindList(role)
|
||||
|
||||
posts := u.PostApp.FindList(entity.SysPost{})
|
||||
var post entity.SysPost
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
post.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
posts := u.PostApp.FindList(post)
|
||||
|
||||
rc.ResData = map[string]any{
|
||||
"data": result,
|
||||
@@ -301,9 +313,17 @@ func (u *UserApi) GetSysUser(rc *ctx.ReqCtx) {
|
||||
// @Router /system/user/getInit [get]
|
||||
// @Security
|
||||
func (u *UserApi) GetSysUserInit(rc *ctx.ReqCtx) {
|
||||
roles := u.RoleApp.FindList(entity.SysRole{})
|
||||
|
||||
posts := u.PostApp.FindList(entity.SysPost{})
|
||||
var role entity.SysRole
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
role.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
roles := u.RoleApp.FindList(role)
|
||||
var post entity.SysPost
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
post.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
posts := u.PostApp.FindList(post)
|
||||
mp := make(map[string]any, 2)
|
||||
mp["roles"] = roles
|
||||
mp["posts"] = posts
|
||||
@@ -418,22 +438,24 @@ func (u *UserApi) ExportUser(rc *ctx.ReqCtx) {
|
||||
user.Status = status
|
||||
user.Username = userName
|
||||
user.Phone = phone
|
||||
|
||||
if !IsTenantAdmin(rc.LoginAccount.TenantId) {
|
||||
user.TenantId = rc.LoginAccount.TenantId
|
||||
}
|
||||
|
||||
list := u.UserApp.FindList(user)
|
||||
fileName := utils.GetFileName(global.Conf.Server.ExcelDir, filename)
|
||||
utils.InterfaceToExcel(*list, fileName)
|
||||
rc.Download(fileName)
|
||||
}
|
||||
|
||||
// 构建前端路由
|
||||
// Build 构建前端路由
|
||||
func Build(menus []entity.SysMenu) []vo.RouterVo {
|
||||
equals := func(a string, b string) bool {
|
||||
if a == b {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if len(menus) == 0 {
|
||||
|
||||
}
|
||||
rvs := make([]vo.RouterVo, 0)
|
||||
for _, ms := range menus {
|
||||
|
||||
@@ -4,6 +4,7 @@ import "pandax/base/model"
|
||||
|
||||
type SysDept struct {
|
||||
DeptId int64 `json:"deptId" gorm:"primary_key;AUTO_INCREMENT"` //部门编码
|
||||
TenantId int64 `json:"tenantId" gorm:"type:int;comment:租户Id"`
|
||||
ParentId int64 `json:"parentId" gorm:"type:int;comment:上级部门"`
|
||||
DeptPath string `json:"deptPath" gorm:"type:varchar(255);comment:部门路径"`
|
||||
DeptName string `json:"deptName" gorm:"type:varchar(128);comment:部门名称"`
|
||||
|
||||
@@ -4,6 +4,7 @@ import "pandax/base/model"
|
||||
|
||||
type SysPost struct {
|
||||
PostId int64 `gorm:"primary_key;AUTO_INCREMENT" json:"postId"`
|
||||
TenantId int64 `json:"tenantId" gorm:"type:int;comment:租户Id"`
|
||||
PostName string `gorm:"type:varchar(128);comment:岗位名称" json:"postName"`
|
||||
PostCode string `gorm:"type:varchar(128);comment:岗位代码" json:"postCode"`
|
||||
Sort int64 `gorm:"type:int;comment:岗位排序" json:"sort"`
|
||||
|
||||
@@ -63,6 +63,9 @@ func (m *sysDeptModelImpl) FindListPage(page, pageSize int, data entity.SysDept)
|
||||
if data.DeptName != "" {
|
||||
db = db.Where("dept_name like ?", "%"+data.DeptName+"%")
|
||||
}
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.Status != "" {
|
||||
db = db.Where("status = ?", data.Status)
|
||||
}
|
||||
@@ -84,6 +87,9 @@ func (m *sysDeptModelImpl) FindList(data entity.SysDept) *[]entity.SysDept {
|
||||
if data.DeptId != 0 {
|
||||
db = db.Where("dept_id = ?", data.DeptId)
|
||||
}
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.DeptName != "" {
|
||||
db = db.Where("dept_name like ?", "%"+data.DeptName+"%")
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@ func (m *sysPostModelImpl) FindListPage(page, pageSize int, data entity.SysPost)
|
||||
if data.PostName != "" {
|
||||
db = db.Where("post_name like ?", "%"+data.PostName+"%")
|
||||
}
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.PostCode != "" {
|
||||
db = db.Where("post_code like ?", "%"+data.PostCode+"%")
|
||||
}
|
||||
@@ -73,6 +76,9 @@ func (m *sysPostModelImpl) FindList(data entity.SysPost) *[]entity.SysPost {
|
||||
if data.PostName != "" {
|
||||
db = db.Where("post_name = ?", data.PostName)
|
||||
}
|
||||
if data.TenantId != 0 {
|
||||
db = db.Where("tenant_id = ?", data.TenantId)
|
||||
}
|
||||
if data.PostCode != "" {
|
||||
db = db.Where("post_code = ?", data.PostCode)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ app:
|
||||
server:
|
||||
# debug release test
|
||||
model: release
|
||||
port: 7788
|
||||
port: 8080
|
||||
cors: true
|
||||
# 接口限流
|
||||
rate:
|
||||
@@ -40,9 +40,9 @@ redis:
|
||||
port: 6379
|
||||
|
||||
mysql:
|
||||
host: 47.104.252.2
|
||||
username: pandax
|
||||
password: pandax
|
||||
host: 127.0.0.1
|
||||
username: root
|
||||
password: 123456
|
||||
db-name: pandax
|
||||
config: charset=utf8&loc=Local&parseTime=true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user