数据集

This commit is contained in:
XM-GO
2023-05-09 17:42:31 +08:00
parent 5dfa857249
commit 93fbf456d8
4 changed files with 26 additions and 11 deletions

View File

@@ -49,6 +49,14 @@ func (p *VisualDataSetTableApi) GetVisualDataSetTableList(rc *restfulx.ReqCtx) {
}
}
// GetVisualDataSetTableListAll DataSetTable列表数据
func (p *VisualDataSetTableApi) GetVisualDataSetTableListAll(rc *restfulx.ReqCtx) {
data := entity.VisualDataSetTable{}
data.Name = restfulx.QueryParam(rc, "name")
data.TableType = restfulx.QueryParam(rc, "tableType")
rc.ResData = p.VisualDataSetTableApp.FindList(data)
}
// GetVisualDataSetTable 获取DataSetTable
func (p *VisualDataSetTableApi) GetVisualDataSetTable(rc *restfulx.ReqCtx) {
tableId := restfulx.PathParam(rc, "tableId")

View File

@@ -4,13 +4,14 @@ import "github.com/XM-GO/PandaKit/model"
type VisualDataSetTable struct {
model.BaseModelD
TableId string `gorm:"primary_key;tableId;comment:表id" json:"tableId"`
DataSourceId string `gorm:"dataSourceId;type:varchar(64);comment:数据源ID" json:"sourceId"`
Name string `gorm:"name;type:varchar(64);comment:名称" json:"name"`
TableType string `gorm:"tableType;type:varchar(64);comment:db,sql,excel,union" json:"tableType"`
Info string `gorm:"info;type:TEXT;comment:原始表信息" json:"info"` //
CreateBy int64 `gorm:"create_by" json:"createBy"` //创建人ID
DataSource VisualDataSource `gorm:"foreignKey:DataSourceId;references:SourceId" json:"dataSource"`
TableId string `gorm:"primary_key;tableId;comment:表id" json:"tableId"`
DataSourceId string `gorm:"dataSourceId;type:varchar(64);comment:数据源ID" json:"sourceId"`
Name string `gorm:"name;type:varchar(64);comment:名称" json:"name"`
TableType string `gorm:"tableType;type:varchar(64);comment:db,sql,excel,union" json:"tableType"`
Info string `gorm:"info;type:TEXT;comment:原始表信息" json:"info"` //
CreateBy int64 `gorm:"create_by" json:"createBy"` //创建人ID
DataSource VisualDataSource `gorm:"foreignKey:DataSourceId;references:SourceId" json:"dataSource"`
DataSetFields []VisualDataSetField `gorm:"foreignKey:TableId" json:"dataSetFields"` //
}
func (VisualDataSetTable) TableName() string {
@@ -33,7 +34,7 @@ func (VisualDataSetField) TableName() string {
}
type VisualDataSetRes struct {
Data []map[string]interface{} `json:"data"`
Data []map[string]interface{} `json:"series"`
Fields []string `json:"fields"`
}

View File

@@ -37,6 +37,12 @@ func InitVisualDataSetTableRouter(container *restful.Container) {
Writes(model.ResultPage{}).
Returns(200, "OK", model.ResultPage{}))
ws.Route(ws.GET("/list/all").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithNeedCasbin(false).WithLog("获取DataSetTable列表").Handle(s.GetVisualDataSetTableListAll)
}).
Doc("获取DataSetTable分页列表").
Metadata(restfulspec.KeyOpenAPITags, tags))
ws.Route(ws.GET("/{tableId}").To(func(request *restful.Request, response *restful.Response) {
restfulx.NewReqCtx(request, response).WithNeedCasbin(false).WithLog("获取DataSetTable信息").Handle(s.GetVisualDataSetTable)
}).

View File

@@ -42,7 +42,7 @@ func (m *datasettableModelImpl) Insert(data entity.VisualDataSetTable) *entity.V
func (m *datasettableModelImpl) FindOne(tableId string) *entity.VisualDataSetTable {
resData := new(entity.VisualDataSetTable)
db := global.Db.Table(m.table).Where("table_id = ?", tableId)
err := db.Preload("DataSource").First(resData).Error
err := db.Preload("DataSetFields").Preload("DataSource").First(resData).Error
biz.ErrIsNil(err, "查询数据集表失败")
return resData
}
@@ -60,7 +60,7 @@ func (m *datasettableModelImpl) FindListPage(page, pageSize int, data entity.Vis
db = db.Where("table_type = ?", data.TableType)
}
err := db.Count(&total).Error
err = db.Order("create_time").Limit(pageSize).Offset(offset).Preload("DataSource").Find(&list).Error
err = db.Order("create_time").Limit(pageSize).Offset(offset).Preload("DataSetFields").Preload("DataSource").Find(&list).Error
biz.ErrIsNil(err, "查询数据集表分页列表失败")
return &list, total
}
@@ -75,7 +75,7 @@ func (m *datasettableModelImpl) FindList(data entity.VisualDataSetTable) *[]enti
if data.TableType != "" {
db = db.Where("table_type = ?", data.TableType)
}
biz.ErrIsNil(db.Order("create_time").Preload("DataSource").Find(&list).Error, "查询数据集表列表失败")
biz.ErrIsNil(db.Order("create_time").Preload("DataSetFields").Preload("DataSource").Find(&list).Error, "查询数据集表列表失败")
return &list
}