mirror of
https://gitee.com/XM-GO/PandaX.git
synced 2026-04-23 10:58:35 +08:00
【feature】添加组织数据读取权限
This commit is contained in:
@@ -18,39 +18,44 @@ type GenTableApi struct {
|
||||
|
||||
// GetDBTableList 分页列表数据 / page list data
|
||||
func (g *GenTableApi) GetDBTableList(rc *restfulx.ReqCtx) {
|
||||
dbt := entity.DBTables{}
|
||||
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
|
||||
tableName := restfulx.QueryParam(rc, "tableName")
|
||||
dbt.TableName = restfulx.QueryParam(rc, "tableName")
|
||||
|
||||
list, total := g.GenTableApp.FindDbTablesListPage(pageNum, pageSize, entity.DBTables{TableName: tableName})
|
||||
list, total := g.GenTableApp.FindDbTablesListPage(pageNum, pageSize, dbt)
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
PageSize: int64(pageNum),
|
||||
PageSize: int64(pageSize),
|
||||
Data: list,
|
||||
}
|
||||
}
|
||||
|
||||
// GetTablePage 分页列表数据
|
||||
func (g *GenTableApi) GetTablePage(rc *restfulx.ReqCtx) {
|
||||
dgt := entity.DevGenTable{}
|
||||
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
|
||||
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
|
||||
tableName := restfulx.QueryParam(rc, "tableName")
|
||||
tableComment := restfulx.QueryParam(rc, "tableComment")
|
||||
dgt.TableName = restfulx.QueryParam(rc, "tableName")
|
||||
dgt.TableComment = restfulx.QueryParam(rc, "tableComment")
|
||||
dgt.RoleId = rc.LoginAccount.RoleId
|
||||
|
||||
list, total := g.GenTableApp.FindListPage(pageNum, pageSize, entity.DevGenTable{TableName: tableName, TableComment: tableComment})
|
||||
list, total := g.GenTableApp.FindListPage(pageNum, pageSize, dgt)
|
||||
rc.ResData = model.ResultPage{
|
||||
Total: total,
|
||||
PageNum: int64(pageNum),
|
||||
PageSize: int64(pageNum),
|
||||
PageSize: int64(pageSize),
|
||||
Data: list,
|
||||
}
|
||||
}
|
||||
|
||||
// GetTableInfo 获取表信息
|
||||
func (g *GenTableApi) GetTableInfo(rc *restfulx.ReqCtx) {
|
||||
tableId := restfulx.PathParamInt(rc, "tableId")
|
||||
result := g.GenTableApp.FindOne(entity.DevGenTable{TableId: int64(tableId)}, true)
|
||||
dgt := entity.DevGenTable{}
|
||||
dgt.TableId = int64(restfulx.PathParamInt(rc, "tableId"))
|
||||
dgt.RoleId = rc.LoginAccount.RoleId
|
||||
result := g.GenTableApp.FindOne(dgt, true)
|
||||
rc.ResData = vo.TableInfoVo{
|
||||
List: result.Columns,
|
||||
Info: *result,
|
||||
@@ -59,8 +64,10 @@ func (g *GenTableApi) GetTableInfo(rc *restfulx.ReqCtx) {
|
||||
|
||||
// GetTableInfoByName 获取表信息
|
||||
func (g *GenTableApi) GetTableInfoByName(rc *restfulx.ReqCtx) {
|
||||
tableName := restfulx.QueryParam(rc, "tableName")
|
||||
result := g.GenTableApp.FindOne(entity.DevGenTable{TableName: tableName}, true)
|
||||
dgt := entity.DevGenTable{}
|
||||
dgt.TableName = restfulx.QueryParam(rc, "tableName")
|
||||
dgt.RoleId = rc.LoginAccount.RoleId
|
||||
result := g.GenTableApp.FindOne(dgt, true)
|
||||
rc.ResData = vo.TableInfoVo{
|
||||
List: result.Columns,
|
||||
Info: *result,
|
||||
@@ -69,7 +76,9 @@ func (g *GenTableApi) GetTableInfoByName(rc *restfulx.ReqCtx) {
|
||||
|
||||
// GetTableTree 获取树表信息
|
||||
func (g *GenTableApi) GetTableTree(rc *restfulx.ReqCtx) {
|
||||
rc.ResData = g.GenTableApp.FindTree(entity.DevGenTable{})
|
||||
dgt := entity.DevGenTable{}
|
||||
dgt.RoleId = rc.LoginAccount.RoleId
|
||||
rc.ResData = g.GenTableApp.FindTree(dgt)
|
||||
}
|
||||
|
||||
// Insert 添加表结构
|
||||
@@ -82,6 +91,7 @@ func (g *GenTableApi) Insert(rc *restfulx.ReqCtx) {
|
||||
wg.Add(1)
|
||||
go func(wg *sync.WaitGroup, index int) {
|
||||
genTable := gen.ToolsGenTableColumn.GenTableInit(tablesList[index])
|
||||
genTable.OrgId = rc.LoginAccount.OrganizationId
|
||||
g.GenTableApp.Insert(genTable)
|
||||
wg.Done()
|
||||
}(&wg, index)
|
||||
|
||||
@@ -4,22 +4,25 @@ import "github.com/PandaXGO/PandaKit/model"
|
||||
|
||||
type DevGenTable struct {
|
||||
TableId int64 `gorm:"primaryKey;autoIncrement" json:"tableId"` // 编号
|
||||
TableName string `gorm:"table_name" json:"tableName"` // 表名称
|
||||
TableComment string `gorm:"table_comment" json:"tableComment"` // 表描述
|
||||
ClassName string `gorm:"class_name" json:"className"` // 实体类名称
|
||||
TplCategory string `gorm:"tpl_category" json:"tplCategory"` // 使用的模板(crud单表操作 tree树表操作)
|
||||
PackageName string `gorm:"package_name" json:"packageName"` // 生成包路径
|
||||
ModuleName string `gorm:"module_name" json:"moduleName"` // 生成模块名
|
||||
BusinessName string `gorm:"business_name" json:"businessName"` // 生成业务名
|
||||
FunctionName string `gorm:"function_name" json:"functionName"` // 生成功能名
|
||||
FunctionAuthor string `gorm:"function_author" json:"functionAuthor"` // 生成功能作者
|
||||
Options string `gorm:"options" json:"options"` // 其它生成选项
|
||||
Remark string `gorm:"remark" json:"remark"` // 备注
|
||||
OrgId int64 `json:"orgId" gorm:"type:int;comment:机构ID"`
|
||||
TableName string `gorm:"table_name" json:"tableName"` // 表名称
|
||||
TableComment string `gorm:"table_comment" json:"tableComment"` // 表描述
|
||||
ClassName string `gorm:"class_name" json:"className"` // 实体类名称
|
||||
TplCategory string `gorm:"tpl_category" json:"tplCategory"` // 使用的模板(crud单表操作 tree树表操作)
|
||||
PackageName string `gorm:"package_name" json:"packageName"` // 生成包路径
|
||||
ModuleName string `gorm:"module_name" json:"moduleName"` // 生成模块名
|
||||
BusinessName string `gorm:"business_name" json:"businessName"` // 生成业务名
|
||||
FunctionName string `gorm:"function_name" json:"functionName"` // 生成功能名
|
||||
FunctionAuthor string `gorm:"function_author" json:"functionAuthor"` // 生成功能作者
|
||||
Options string `gorm:"options" json:"options"` // 其它生成选项
|
||||
Remark string `gorm:"remark" json:"remark"` // 备注
|
||||
PkColumn string `gorm:"pk_column;" json:"pkColumn"`
|
||||
PkGoField string `gorm:"pk_go_field" json:"pkGoField"`
|
||||
PkJsonField string `gorm:"pk_json_field" json:"pkJsonField"`
|
||||
Columns []DevGenTableColumn `gorm:"-" json:"columns"` // 字段信息
|
||||
model.BaseModel
|
||||
|
||||
RoleId int64 `gorm:"-"` // 角色数据权限
|
||||
}
|
||||
|
||||
type DBTables struct {
|
||||
|
||||
@@ -2,7 +2,8 @@ package entity
|
||||
|
||||
type DevGenTableColumn struct {
|
||||
ColumnId int64 `gorm:"primaryKey;autoIncrement" json:"columnId"` // 编号
|
||||
TableId int64 `gorm:"table_id" json:"tableId"` // 归属表编号
|
||||
OrgId int64 `json:"orgId" gorm:"type:int;comment:机构ID"`
|
||||
TableId int64 `gorm:"table_id" json:"tableId"` // 归属表编号
|
||||
TableName string `gorm:"table_name" json:"tableName"`
|
||||
ColumnName string `gorm:"column_name" json:"columnName"` // 列名称
|
||||
ColumnComment string `gorm:"column_comment" json:"columnComment"` // 列描述
|
||||
@@ -28,6 +29,8 @@ type DevGenTableColumn struct {
|
||||
LinkTablePackage string `gorm:"link_table_package" json:"linkTablePackage"` // 关联表包名
|
||||
LinkLabelId string `gorm:"link_label_id" json:"linkLabelId"` // 关联表键名
|
||||
LinkLabelName string `gorm:"link_label_name" json:"linkLabelName"` // 关联表字段值
|
||||
|
||||
RoleId int64 `gorm:"-"` // 角色数据权限
|
||||
}
|
||||
|
||||
type DBColumns struct {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/PandaXGO/PandaKit/utils"
|
||||
"pandax/apps/develop/entity"
|
||||
"pandax/pkg/global"
|
||||
"pandax/pkg/tool"
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -94,7 +95,9 @@ func (m *devGenTableModelImpl) Insert(dgt entity.DevGenTable) {
|
||||
biz.ErrIsNil(err, "新增生成代码表失败")
|
||||
for i := 0; i < len(dgt.Columns); i++ {
|
||||
dgt.Columns[i].TableId = dgt.TableId
|
||||
DevTableColumnModelDao.Insert(dgt.Columns[i])
|
||||
columns := dgt.Columns[i]
|
||||
columns.OrgId = dgt.OrgId
|
||||
DevTableColumnModelDao.Insert(columns)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,11 +133,14 @@ func (m *devGenTableModelImpl) FindTree(data entity.DevGenTable) *[]entity.DevGe
|
||||
if data.TableComment != "" {
|
||||
db = db.Where("table_comment = ?", data.TableComment)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
tool.OrgAuthSet(db, data.RoleId)
|
||||
err := db.Find(&resData).Error
|
||||
biz.ErrIsNil(err, "获取TableTree失败")
|
||||
for i := 0; i < len(resData); i++ {
|
||||
var col entity.DevGenTableColumn
|
||||
col.TableId = resData[i].TableId
|
||||
col.RoleId = data.RoleId
|
||||
columns := DevTableColumnModelDao.FindList(col, false)
|
||||
resData[i].Columns = *columns
|
||||
}
|
||||
@@ -154,6 +160,8 @@ func (m *devGenTableModelImpl) FindListPage(page, pageSize int, data entity.DevG
|
||||
if data.TableComment != "" {
|
||||
db = db.Where("table_comment = ?", data.TableComment)
|
||||
}
|
||||
// 组织数据访问权限
|
||||
tool.OrgAuthSet(db, data.RoleId)
|
||||
db.Where("delete_time IS NULL")
|
||||
err := db.Count(&total).Error
|
||||
err = db.Limit(pageSize).Offset(offset).Find(&list).Error
|
||||
|
||||
Reference in New Issue
Block a user