作者 yangfu

chart property

... ... @@ -2,6 +2,8 @@ package chart
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
... ... @@ -24,7 +26,21 @@ func NewGetChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChart
}
func (l *GetChartLogic) GetChart(req *types.ChartGetRequest) (resp *types.ChartGetResponse, err error) {
// todo: add your logic here and delete this line
var (
conn = l.svcCtx.DefaultDBConn()
chart *domain.Chart
chartSetting *domain.ChartSetting
)
chart, err = l.svcCtx.ChartRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("图表不存在", err)
}
chartSetting, err = l.svcCtx.ChartSettingRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("图表配置不存在", err)
}
resp = &types.ChartGetResponse{
Chart: types.NewChartItemWithSetting(chart, chartSetting),
}
return
}
... ...
... ... @@ -32,18 +32,21 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
var (
conn = l.svcCtx.DefaultDBConn()
parentChart *domain.Chart
chart *domain.Chart
chartSetting *domain.ChartSetting
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
if !domain.ChartTypeContain(req.Type) {
return nil, xerr.NewErrMsgErr("未知类型:"+req.Type, err)
}
chart := &domain.Chart{
chart = &domain.Chart{
Name: req.Name,
Type: req.Type,
Pid: req.Pid,
Sort: 1,
Group: tool.Krand(10, tool.KC_RAND_KIND_UPPER),
TenantId: tenantId,
ChartType: req.ChartType,
}
if chart.Name == "" {
chart.Name = chart.RandName()
... ... @@ -62,12 +65,27 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
if chart, err = l.svcCtx.ChartRepository.Insert(ctx, conn, chart); err != nil {
return err
}
chartProperty := types.NewProperty(req.ChartProperty)
chartSetting = &domain.ChartSetting{
ChartId: chart.Id,
DataSourceId: chartProperty.GetFirstDataSourceId(),
DataSourceIds: chartProperty.GetAllDataSourceId(),
ChartType: chart.ChartType,
Title: chartProperty.Title,
TableAbility: chartProperty.TableAbility,
Series: chartProperty.Series,
TenantId: chart.TenantId,
}
if chartSetting, err = l.svcCtx.ChartSettingRepository.Insert(l.ctx, conn, chartSetting); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建失败", err)
}
resp = &types.ChartSaveResponse{
Chart: types.NewChartItem(chart),
Chart: types.NewChartItemWithSetting(chart, chartSetting),
}
return
}
... ...
... ... @@ -26,7 +26,7 @@ func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) {
response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId})
response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId, Token: req.Token})
if err != nil {
logx.Error(err)
return resp, xerr.NewErr(err)
... ...
... ... @@ -30,6 +30,7 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
var batchError errorx.BatchError
fx.Parallel(func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable},
Module: bytelib.ModuleDigitalCenter,
})
... ... @@ -39,6 +40,7 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
result["导入模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.SchemaTable},
Module: bytelib.ModuleQuerySetCenter,
})
... ... @@ -48,6 +50,7 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
result["拆解模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet},
Module: bytelib.ModuleCalculateCenter,
})
... ...
... ... @@ -27,6 +27,7 @@ func NewSearchTableDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *S
func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest) (resp interface{}, err error) {
tableDataPreviewRequest := &bytelib.TableDataPreviewRequest{
Token: req.Token,
ObjectType: bytelib.ObjectMetaTable,
ObjectId: int64(req.ObjectId),
Where: newWhere(req.Condition).WithPageSize(req.PageNumber, req.PageSize),
... ...
... ... @@ -27,6 +27,7 @@ func NewSearchTableFieldOptionalValuesLogic(ctx context.Context, svcCtx *svc.Ser
func (l *SearchTableFieldOptionalValuesLogic) SearchTableFieldOptionalValues(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) {
fieldOptionalValuesRequest := &bytelib.TableFieldOptionalValuesRequest{
Token: req.Token,
ObjectType: bytelib.ObjectMetaTable,
ObjectId: req.ObjectId,
Field: bytelib.Field{
... ...
... ... @@ -20,6 +20,7 @@ type ServiceContext struct {
Redis *redis.Redis
RedisCache gzcache.GZCache
ChartRepository domain.ChartRepository
ChartSettingRepository domain.ChartSettingRepository
ByteMetadataService bytelib.ByteMetadataService
}
... ... @@ -36,6 +37,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
RedisCache: redisCache,
Redis: redis,
ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)),
ChartSettingRepository: repository.NewChartSettingRepository(cache.NewCachedRepository(mlCache)),
ByteMetadataService: bytelib.ByteMetadataService{
Service: gateway.NewService(c.ByteMetadata.Name, c.ByteMetadata.Host, c.ByteMetadata.Timeout),
... ...
... ... @@ -8,6 +8,36 @@ import (
func NewChartItem(chart *domain.Chart) ChartItem {
item := ChartItem{}
copier.Copy(&item, chart)
//item.Charts = make([]ChartItem, 0)
return item
}
func NewChartItemWithProperty(chart *domain.Chart, property *ChartProperty) ChartItem {
item := ChartItem{}
copier.Copy(&item, chart)
if property != nil {
item.ChartProperty = property
}
return item
}
func NewChartItemWithSetting(chart *domain.Chart, chartSetting *domain.ChartSetting) ChartItem {
item := ChartItem{}
copier.Copy(&item, chart)
if chartSetting != nil {
property := NewPropertyItem(chartSetting.ChartProperty(chart.Cover))
item.ChartProperty = &property
}
return item
}
func NewProperty(property ChartProperty) domain.ChartProperty {
chartProperty := domain.ChartProperty{}
copier.Copy(&chartProperty, property)
return chartProperty
}
func NewPropertyItem(property domain.ChartProperty) ChartProperty {
chartProperty := ChartProperty{}
copier.Copy(&chartProperty, property)
return chartProperty
}
... ...
... ... @@ -13,6 +13,8 @@ type ChartSaveRequest struct {
Pid int64 `json:"pid,optional"` // 父级ID
Type string `json:"type"` // 类型 report:报表 group:分组 chart:图表
Name string `json:"name,optional"` // 名称
ChartType string `json:"chartType"` // 图表类型
ChartProperty ChartProperty `json:"property"` // 图表属性
}
type ChartSaveResponse struct {
... ... @@ -28,6 +30,8 @@ type ChartDeleteResponse struct {
type ChartUpdateRequest struct {
Id int64 `path:"id"`
ChartType string `json:"chartType"` // 图表类型
ChartProperty ChartProperty `json:"property"` // 图表属性
}
type ChartUpdateResponse struct {
... ... @@ -66,11 +70,11 @@ type ChartItem struct {
Type string `json:"type,optional"` // 类型 report:报表 group:分组 chart:图表
Sort int64 `json:"sort,optional"` // 排序
Name string `json:"name,optional"` // 名称
Charts []ChartItem `json:"charts,optional"`
ChartProperty *ChartProperty `json:"property,optional,omitempty"` //属性
}
type ChartComponentSearchRequest struct {
Name string `json:"name"`
Name string `json:"name,optional"`
}
type ChartComponentSearchResponse struct {
... ... @@ -85,13 +89,57 @@ type ChartComponentItem struct {
Desc string `json:"desc,optional"` // 描述
}
type ChartProperty struct {
Title Title `json:"title,optional"` // 标题
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
Cover string `json:"cover,optional"` // 封面
}
type Title struct {
TitleSwitch bool `json:"titleSwitch,optional"` // 组件标题开关
IntroduceSwitch bool `json:"introduceSwitch,optional"` // 组件说明开关
TitleType string `json:"titleType"` // 标题类型
Heading string `json:"heading,optional"` // 主标题
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
}
type TableAbility struct {
FilterSwitch bool `json:"filterSwitch,optional"` // 表筛选功能开关
DimensionList []Dimension `json:"dimensionList,optional"` // 维度列表
}
type Series struct {
Name string `json:"name"` // 名称 (例如 指标1、指标2)
SourceFrom string `json:"from,options=[ByteBank,User]"` // 数据源类型 ByteBank:字库 User:用户自定义
DataSourceId int64 `json:"dataSourceId,optional,omitempty"` // 数据源ID(from值为ByteBank时有值)
CustomText string `json:"customText,optional,omitempty"` // 自定义数据文本(from值为User时有值)
MatchExpressions []Expression `json:"matchExpressions,omitempty"` // 条件匹配表达式(总体指标)
}
type Expression struct {
Operator string `json:"operator"` // 操作符号 <,>,==,<>,<=,>=
CompareValue string `json:"compareValue"` // 比较值
ToValue string `json:"toValue"` // 显示值(转为)
}
type Dimension struct {
Name string `json:"name"`
Value string `json:"value"`
}
type SearchTableByModuleRequest struct {
Token string `header:"x-mmm-accesstoken"`
}
type SearchTableByModuleResponse struct {
}
type SearchTableFieldOptionalValuesRequest struct {
Token string `header:"x-mmm-accesstoken"`
ObjectId int `json:"objectId"` // 对象ID
Field string `json:"field"` // 当前选择的字段
SqlName string `json:"sqlName"` // 字段SqlName
... ... @@ -112,6 +160,7 @@ type Condition struct {
}
type GetTableDetailRequest struct {
Token string `header:"x-mmm-accesstoken"`
TableId int `path:"tableId"` // 表ID
}
... ... @@ -119,6 +168,7 @@ type GetTableDetailResponse struct {
}
type SearchTableDataRequest struct {
Token string `header:"x-mmm-accesstoken"`
ObjectId int `json:"objectId"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
... ...
... ... @@ -6,5 +6,8 @@ import (
)
func Migrate(db *gorm.DB) {
db.AutoMigrate(&models.Chart{})
db.AutoMigrate(
&models.Chart{},
&models.ChartSetting{},
)
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type Chart struct {
... ... @@ -14,8 +15,8 @@ type Chart struct {
Sort int `gorm:"index:idx_chart_t_pid_sort"` // 排序
Name string // 名称
Group string `gorm:"index:idx_chart_group"` // 分组
TenantId int64 `gorm:"index:idx_chart_t_pid_sort"` // 租户ID
TenantId int64 `gorm:"index:idx_chart_t_pid_sort"` // 租户ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
... ... @@ -28,13 +29,13 @@ func (m *Chart) TableName() string {
}
func (m *Chart) BeforeCreate(tx *gorm.DB) (err error) {
// m.CreatedAt = time.Now().Unix()
// m.UpdatedAt = time.Now().Unix()
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *Chart) BeforeUpdate(tx *gorm.DB) (err error) {
// m.UpdatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
... ...
... ... @@ -4,19 +4,26 @@ import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
)
type ChartSetting struct {
Id int64 // ID
ChartId int64 // 图表ID
Property string // 属性
Style string // 样式
Series string // 系列值-数据绑定
ChartId int64 `gorm:"uniqueIndex:idx_chart_setting_chart_id"` // 图表ID
DataSourceId int64 // (冗余)数据源ID,多个数据源取第一个源
DataSourceIds []int64 `gorm:"serializer:json"`
ChartType string // (冗余)图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
Title domain.Title `gorm:"serializer:json"`
TableAbility domain.TableAbility `gorm:"serializer:json"` // 表格能力
Series []domain.Series `gorm:"serializer:json"` // 系列值-数据绑定
TenantId int64 `gorm:"index:idx_chart_setting_t_id"` // 租户ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}
func (m *ChartSetting) TableName() string {
... ... @@ -24,21 +31,21 @@ func (m *ChartSetting) TableName() string {
}
func (m *ChartSetting) BeforeCreate(tx *gorm.DB) (err error) {
// m.CreatedAt = time.Now().Unix()
// m.UpdatedAt = time.Now().Unix()
m.CreatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *ChartSetting) BeforeUpdate(tx *gorm.DB) (err error) {
// m.UpdatedAt = time.Now().Unix()
m.UpdatedAt = time.Now().Unix()
return
}
func (m *ChartSetting) CacheKeyFunc() string {
if m.Id == 0 {
if m.ChartId == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.ChartId)
}
func (m *ChartSetting) CacheKeyFuncByObject(obj interface{}) string {
... ...
... ... @@ -97,7 +97,7 @@ func (repository *ChartSettingRepository) FindOne(ctx context.Context, conn tran
m = new(models.ChartSetting)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
tx = tx.Model(m).Where("chart_id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
... ...
... ... @@ -17,6 +17,8 @@ type Chart struct {
Name string // 名称
Group string // 分组
TenantId int64 // 租户ID
Cover string // 封面
ChartType string // 图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
... ...
package domain
var (
RecordTable1 = "RecordTable1"
MetricsCard1 = "MetricsCard1"
ContainerCard1 = "ContainerCard1"
QuarterChart1 = "QuarterChart1"
RecordTable1 = "RecordTable"
MetricsCard1 = "MetricsCard"
ContainerCard1 = "ContainerCard"
QuarterChart1 = "QuarterChart"
)
type ChartProperty struct {
Title *Title `json:"title,optional"` // 标题
FilterRule *FilterRule `json:"filterRule,optional"` // 过滤规则
Series []*Series `json:"series,optional"` // 系列
Title Title `json:"title,optional"` // 标题
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
Cover string `json:"cover,optional"` // 封面
//XAxis interface{} `json:"xAxis"` // X轴
//YAxis interface{} `json:"yAxis"` // Y轴
}
type Series struct {
Type string `json:"type"` // 图表类型 (记录型表格:RecordTable1 总体指标:MetricsCard1 容器卡片:ContainerCard1 四分图:QuarterChart1)
Name string `json:"name"` // 名称
Data interface{} `json:"data"` // 保存配置的时候置空
Config *DataConfig `json:"config"` // 配置
}
type Title struct {
MainTitle *TitleInfo `json:"main,optional"` // 主标题
SubTitle *TitleInfo `json:"sub,optional"` // 副标题
TitleSwitch bool `json:"titleSwitch,optional"` // 组件标题开关
IntroduceSwitch bool `json:"introduceSwitch,optional"` // 组件说明开关
TitleType string `json:"titleType"` // 标题类型
Heading string `json:"heading,optional"` // 主标题
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
}
type TitleInfo struct {
Content string `json:"content,optional"` // 标题内容
Description *Description `json:"description,optional"` // 描述
type TableAbility struct {
FilterSwitch bool `json:"filterSwitch,optional"` // 表筛选功能开关
DimensionList []Dimension `json:"dimensionList,optional"` // 维度列表
}
type Description struct {
Type string `json:"type"` // text:文字 attachment:附件
Remark string `json:"remark,optional"` // 备注说明
Attachment *File `json:"attachment,optional"` // 附件
}
type File struct {
FileName string `json:"name"`
Url string `json:"url"`
}
type FilterRule struct {
FilterItems []*FilterItem `json:"items"`
type Series struct {
// Type string `json:"type"` // 图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
Name string `json:"name"` // 名称 (例如 指标1、指标2)
SourceFrom string `json:"from,options=[ByteBank,User]"` // 数据源类型 ByteBank:字库 User:用户自定义
DataSourceId int64 `json:"dataSourceId,optional,omitempty"` // 数据源ID(from值为ByteBank时有值)
CustomText string `json:"customText,optional,omitempty"` // 自定义数据文本(from值为User时有值)
MatchExpressions []Expression `json:"matchExpressions,omitempty"` // 条件匹配表达式(总体指标)
}
type FilterItem struct {
FieldItem
type Expression struct {
Operator string `json:"operator,options=[<,>,==,<>,<=,>=]"` // 操作符号 <,>,==,<>,<=,>=
CompareValue string `json:"compareValue"` // 比较值
ToValue string `json:"toValue"` // 显示值(转为)
}
// FieldItem 字段项
type FieldItem struct {
Source
Field string `json:"field"`
type Dimension struct {
Name string `json:"name"`
Value string `json:"value"`
}
type Source struct {
From string `json:"from"` // 数据源类型 ByteBank:字库 User:用户自定义
SourceId int64 `json:"id"` // 数据源ID(from值为ByteBank时有值)
CustomData interface{} `json:"customData"` // 自定义数据(from值为User时有值)
func (e ChartProperty) GetFirstDataSourceId() int64 {
for _, s := range e.Series {
if s.DataSourceId > 0 {
return s.DataSourceId
}
}
return 0
}
type DataConfig struct {
Source Source `json:"source"`
func (e ChartProperty) GetAllDataSourceId() []int64 {
var idList = make([]int64, 0)
for _, s := range e.Series {
if s.DataSourceId > 0 {
idList = append(idList, s.DataSourceId)
}
}
return idList
}
... ...
... ... @@ -8,10 +8,14 @@ import (
type ChartSetting struct {
Id int64 // ID
ChartId int64 // 图表ID
Property string // 属性
Style string // 样式
Series string // 系列值-数据绑定
DataSourceId int64 // (冗余)数据源ID,多个数据源取第一个源
DataSourceIds []int64
ChartType string // (冗余)图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
Title Title
TableAbility TableAbility // 表格能力
Series []Series // 系列值-数据绑定
TenantId int64 // 租户ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
... ... @@ -33,3 +37,12 @@ func (m *ChartSetting) Identify() interface{} {
}
return m.Id
}
func (m *ChartSetting) ChartProperty(cover string) ChartProperty {
return ChartProperty{
Title: m.Title,
TableAbility: m.TableAbility,
Series: m.Series,
Cover: cover,
}
}
... ...
... ... @@ -14,6 +14,7 @@ func (gateway *ByteMetadataService) TableDataPreview(ctx context.Context, reques
}
type TableDataPreviewRequest struct {
Token string `header:"x-mmm-accesstoken"`
ObjectId int64 `json:"objectId"` //表ID
ObjectType string `json:"objectType"` //表类型 File:文件 MetaTable:元表 DBTable:数据库表 ;当对象类型为DBTable时 objectId 1:表操作日志 2.拆解模块日志
Where *TableQueryWhere `json:"where"` //查询条件
... ...
... ... @@ -14,6 +14,7 @@ func (gateway *ByteMetadataService) TableFieldOptionalValues(ctx context.Context
}
type TableFieldOptionalValuesRequest struct {
Token string `header:"x-mmm-accesstoken"`
ObjectType string `json:"objectType" valid:"Required"` // 对象类型
ObjectId int `json:"objectId" valid:"Required"` // 对象Id标识
Field Field `json:"field" valid:"Required"` // 选择列
... ...
... ... @@ -14,6 +14,7 @@ func (gateway *ByteMetadataService) TableInfo(ctx context.Context, request *Tabl
}
type TableInfoRequest struct {
Token string `header:"x-mmm-accesstoken"`
TableId int `path:"tableId"`
}
type TableInfoResponse struct {
... ...
... ... @@ -14,6 +14,7 @@ func (gateway *ByteMetadataService) ObjectTableSearch(ctx context.Context, reque
}
type ObjectTableSearchRequest struct {
Token string `header:"x-mmm-accesstoken"`
// 表名称
Name string `cname:"表名称" json:"name,optional"`
//ViewType string `cname:"视图类型 full:完整 main:主表关系" json:"viewType"`
... ...
... ... @@ -488,6 +488,31 @@
},
"title": "ChartItem"
},
"ChartProperty": {
"type": "object",
"properties": {
"title": {
"$ref": "#/definitions/Title",
"description": " 标题"
},
"table": {
"$ref": "#/definitions/TableAbility",
"description": " 表筛选功能"
},
"series": {
"type": "array",
"items": {
"$ref": "#/definitions/Series"
},
"description": " 系列(数据源)"
},
"cover": {
"type": "string",
"description": " 封面"
}
},
"title": "ChartProperty"
},
"ChartRenameRequest": {
"type": "object",
"properties": {
... ... @@ -525,11 +550,21 @@
"name": {
"type": "string",
"description": " 名称"
},
"chartType": {
"type": "string",
"description": " 图表类型"
},
"property": {
"$ref": "#/definitions/ChartProperty",
"description": " 图表属性"
}
},
"title": "ChartSaveRequest",
"required": [
"type"
"type",
"chartType",
"property"
]
},
"ChartSaveResponse": {
... ... @@ -587,11 +622,21 @@
"id": {
"type": "integer",
"format": "int64"
},
"chartType": {
"type": "string",
"description": " 图表类型"
},
"property": {
"$ref": "#/definitions/ChartProperty",
"description": " 图表属性"
}
},
"title": "ChartUpdateRequest",
"required": [
"id"
"id",
"chartType",
"property"
]
},
"ChartUpdateResponse": {
... ... @@ -660,6 +705,29 @@
"order"
]
},
"Expression": {
"type": "object",
"properties": {
"Operator": {
"type": "string",
"description": " 操作符号 \u003c,\u003e,==,\u003c\u003e,\u003c=,\u003e="
},
"compareValue": {
"type": "string",
"description": " 比较值"
},
"toValue": {
"type": "string",
"description": " 显示值(转为)"
}
},
"title": "Expression",
"required": [
"Operator",
"compareValue",
"toValue"
]
},
"GetTableDetailRequest": {
"type": "object",
"properties": {
... ... @@ -694,12 +762,12 @@
"format": "int32",
"description": " 对象ID"
},
"pageNumber": {
"page": {
"type": "integer",
"format": "int32",
"description": " 分页数"
},
"pageSize": {
"size": {
"type": "integer",
"format": "int32",
"description": " 页码"
... ... @@ -771,6 +839,103 @@
"values",
"total"
]
},
"Series": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": " 名称 (例如 指标1、指标2)"
},
"from": {
"type": "string",
"description": " 数据源类型 ByteBank:字库 User:用户自定义"
},
"dataSourceId": {
"type": "integer",
"format": "int64",
"description": " 数据源ID(from值为ByteBank时有值)"
},
"customText": {
"type": "string",
"description": " 自定义数据文本(from值为User时有值)"
},
"matchExpressions": {
"type": "array",
"items": {
"$ref": "#/definitions/Expression"
},
"description": " 条件匹配表达式(总体指标)"
}
},
"title": "Series",
"required": [
"name",
"from",
"matchExpressions"
]
},
"TableAbility": {
"type": "object",
"properties": {
"filterSwitch": {
"type": "boolean",
"format": "boolean",
"description": " 表筛选功能开关"
},
"dimensionList": {
"type": "array",
"items": {
"type": "string"
},
"description": " 维度列表"
}
},
"title": "TableAbility"
},
"Title": {
"type": "object",
"properties": {
"titleSwitch": {
"type": "boolean",
"format": "boolean",
"description": " 组件标题开关"
},
"introduceSwitch": {
"type": "boolean",
"format": "boolean",
"description": " 组件说明开关"
},
"titleType": {
"type": "string",
"description": " 标题类型"
},
"heading": {
"type": "string",
"description": " 主标题"
},
"subTitle": {
"type": "string",
"description": " 副标题"
},
"explainType": {
"type": "string",
"description": " text file"
},
"explainTxt": {
"type": "string",
"description": " 文字说明"
},
"fileUrl": {
"type": "string",
"description": " 组件图片/视频"
}
},
"title": "Title",
"required": [
"titleType",
"explainType"
]
}
},
"securityDefinitions": {
... ...
... ... @@ -55,6 +55,8 @@ type (
Pid int64 `json:"pid,optional"`// 父级ID
Type string `json:"type"`// 类型 report:报表 group:分组 chart:图表
Name string `json:"name,optional"`// 名称
ChartType string `json:"chartType"` // 图表类型
ChartProperty ChartProperty `json:"property"` // 图表属性
}
ChartSaveResponse struct{
Chart ChartItem `json:"chart"`
... ... @@ -67,6 +69,8 @@ type (
ChartUpdateRequest struct{
Id int64 `path:"id"`
ChartType string `json:"chartType"` // 图表类型
ChartProperty ChartProperty `json:"property"` // 图表属性
}
ChartUpdateResponse struct{}
... ... @@ -95,13 +99,14 @@ type (
Type string `json:"type,optional"`// 类型 report:报表 group:分组 chart:图表
Sort int64 `json:"sort,optional"`// 排序
Name string `json:"name,optional"`// 名称
Charts []ChartItem `json:"charts,optional"`
//Charts []ChartItem `json:"charts,optional"`
ChartProperty *ChartProperty `json:"property,optional,omitempty"` //属性
}
)
type(
ChartComponentSearchRequest{
Name string `json:"name"`
Name string `json:"name,optional"`
}
ChartComponentSearchResponse{
List []ChartComponentItem `json:"list"`
... ... @@ -114,3 +119,42 @@ type(
Desc string `json:"desc,optional"`// 描述
}
)
type(
ChartProperty struct {
Title Title `json:"title,optional"` // 标题
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
Cover string `json:"cover,optional"` // 封面
}
Title struct {
TitleSwitch bool `json:"titleSwitch,optional"` // 组件标题开关
IntroduceSwitch bool `json:"introduceSwitch,optional"` // 组件说明开关
TitleType string `json:"titleType"` // 标题类型
Heading string `json:"heading,optional"` // 主标题
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
}
TableAbility struct {
FilterSwitch bool `json:"filterSwitch,optional"` // 表筛选功能开关
DimensionList []Dimension `json:"dimensionList,optional"` // 维度列表
}
Series struct {// 图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
Name string `json:"name"` // 名称 (例如 指标1、指标2)
SourceFrom string `json:"from,options=[ByteBank,User]"` // 数据源类型 ByteBank:字库 User:用户自定义
DataSourceId int64 `json:"dataSourceId,optional,omitempty"` // 数据源ID(from值为ByteBank时有值)
CustomText string `json:"customText,optional,omitempty"` // 自定义数据文本(from值为User时有值)
MatchExpressions []Expression `json:"matchExpressions,omitempty"` // 条件匹配表达式(总体指标)
}
Expression struct {
Operator string `json:"operator"` // 操作符号 <,>,==,<>,<=,>=
CompareValue string `json:"compareValue"` // 比较值
ToValue string `json:"toValue"` // 显示值(转为)
}
Dimension struct{
Name string `json:"name"`
Value string `json:"value"`
}
)
\ No newline at end of file
... ...
... ... @@ -34,13 +34,14 @@ service Core {
type (
SearchTableByModuleRequest struct{
Token string `header:"x-mmm-accesstoken"`
}
SearchTableByModuleResponse struct{
}
SearchTableFieldOptionalValuesRequest struct{
Token string `header:"x-mmm-accesstoken"`
ObjectId int `json:"objectId"` // 对象ID
Field string `json:"field"` // 当前选择的字段
SqlName string `json:"sqlName"` // 字段SqlName
... ... @@ -62,6 +63,7 @@ type (
}
GetTableDetailRequest struct {
Token string `header:"x-mmm-accesstoken"`
TableId int `path:"tableId"` // 表ID
}
GetTableDetailResponse struct{
... ... @@ -69,6 +71,7 @@ type (
}
SearchTableDataRequest struct{
Token string `header:"x-mmm-accesstoken"`
ObjectId int `json:"objectId"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
... ...
... ... @@ -5,5 +5,9 @@ import (
)
func GetTenantFromCtx(ctx context.Context) int64 {
return 1
userToken := GetUserTokenFromCtx(ctx)
if userToken.CompanyId == 0 {
return 0
}
return userToken.CompanyId
}
... ...
... ... @@ -10,10 +10,11 @@ import (
)
var (
CtxKeyJwtUserId = "UserId"
CtxKeyJwtUserId = "userId"
CtxKeyJwtCompanyId = "companyId"
)
func GetUserIdFromCtx(ctx context.Context, key string) int64 {
func GetInt64FromCtx(ctx context.Context, key string) int64 {
var uid int64
if jsonUid, ok := ctx.Value(key).(json.Number); ok {
if int64Uid, err := jsonUid.Int64(); err == nil {
... ... @@ -52,12 +53,14 @@ func getArrayInt64FromCtx(ctx context.Context, key string) []int64 {
func GetUserTokenFromCtx(ctx context.Context) UserToken {
return UserToken{
UserId: GetUserIdFromCtx(ctx, CtxKeyJwtUserId),
UserId: GetInt64FromCtx(ctx, CtxKeyJwtUserId),
CompanyId: GetInt64FromCtx(ctx, CtxKeyJwtCompanyId),
}
}
type UserToken struct {
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
}
func (tk UserToken) GenerateToken(jwtConfig config.JwtAuth) (string, error) {
... ...