From 93fbf456d85e58709570b67a17e436cb7a63c3a3 Mon Sep 17 00:00:00 2001 From: XM-GO <93296511+XM-GO@users.noreply.github.com> Date: Tue, 9 May 2023 17:42:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/visual/api/visual_data_set_table.go | 8 ++++++++ apps/visual/entity/data_set.go | 17 +++++++++-------- apps/visual/router/visual_data_set_table.go | 6 ++++++ apps/visual/services/visual_data_set_table.go | 6 +++--- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/apps/visual/api/visual_data_set_table.go b/apps/visual/api/visual_data_set_table.go index ae84ee0..4653617 100644 --- a/apps/visual/api/visual_data_set_table.go +++ b/apps/visual/api/visual_data_set_table.go @@ -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") diff --git a/apps/visual/entity/data_set.go b/apps/visual/entity/data_set.go index 8d674a3..0894ff1 100644 --- a/apps/visual/entity/data_set.go +++ b/apps/visual/entity/data_set.go @@ -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"` } diff --git a/apps/visual/router/visual_data_set_table.go b/apps/visual/router/visual_data_set_table.go index 66f67a2..5871f46 100644 --- a/apps/visual/router/visual_data_set_table.go +++ b/apps/visual/router/visual_data_set_table.go @@ -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) }). diff --git a/apps/visual/services/visual_data_set_table.go b/apps/visual/services/visual_data_set_table.go index 8e8861c..d171af7 100644 --- a/apps/visual/services/visual_data_set_table.go +++ b/apps/visual/services/visual_data_set_table.go @@ -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 }