作者 yangfu

table data

正在显示 29 个修改的文件 包含 1140 行增加95 行删除
Name: Core
Name: chart
Host: 0.0.0.0
Port: 8080
Port: 8081
Verbose: false
JwtAuth:
... ... @@ -14,3 +13,9 @@ Redis:
Pass:
DB:
DataSource: host=106.52.103.187 user=postgres password=UYXN134KUm8TeE7 dbname=skateboard-test port=25431 sslmode=disable TimeZone=Asia/Shanghai
ByteMetadata:
Name: ApiByteMetadata
Host1: http://127.0.0.1:8080
Host: http://character-library-metadata-bastion-test.fjmaimaimai.com
Timeout: 0s
\ No newline at end of file
... ...
... ... @@ -4,10 +4,18 @@ import (
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/rest"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/config"
"time"
)
type Config struct {
rest.RestConf
config.Config
Redis redis.RedisConf `json:",optional"`
Redis redis.RedisConf `json:",optional"`
ByteMetadata ApiService
}
type ApiService struct {
Name string
Host string
Timeout time.Duration
}
... ...
package chart
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/chart"
"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"
)
func SearchChartComponentsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ChartComponentSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := chart.NewSearchChartComponentsLogic(r.Context(), svcCtx)
resp, err := l.SearchChartComponents(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"net/http"
chart "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/chart"
table "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/table"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"github.com/zeromicro/go-zero/rest"
... ... @@ -48,6 +49,38 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/chart/rename",
Handler: chart.RenameChartSortHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chart/components/search",
Handler: chart.SearchChartComponentsHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
Path: "/table/search-by-module",
Handler: table.SearchTableByModuleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/table/field-optional-values",
Handler: table.SearchTableFieldOptionalValuesHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/table/:tableId",
Handler: table.GetTableDetailHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/table/data",
Handler: table.SearchTableDataHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/v1"),
... ...
package table
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/table"
"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"
)
func GetTableDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetTableDetailRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := table.NewGetTableDetailLogic(r.Context(), svcCtx)
resp, err := l.GetTableDetail(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package table
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/table"
"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"
)
func SearchTableByModuleHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SearchTableByModuleRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := table.NewSearchTableByModuleLogic(r.Context(), svcCtx)
resp, err := l.SearchTableByModule(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package table
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/table"
"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"
)
func SearchTableDataHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SearchTableDataRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := table.NewSearchTableDataLogic(r.Context(), svcCtx)
resp, err := l.SearchTableData(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package table
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/table"
"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"
)
func SearchTableFieldOptionalValuesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SearchTableFieldOptionalValuesRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := table.NewSearchTableFieldOptionalValuesLogic(r.Context(), svcCtx)
resp, err := l.SearchTableFieldOptionalValues(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package chart
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"strings"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchChartComponentsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchChartComponentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchChartComponentsLogic {
return &SearchChartComponentsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchChartComponentsLogic) SearchChartComponents(req *types.ChartComponentSearchRequest) (resp *types.ChartComponentSearchResponse, err error) {
var list = []types.ChartComponentItem{
{
Name: "记录型表格",
Code: domain.RecordTable1,
Cover: "",
},
{
Name: "总体指标",
Code: domain.MetricsCard1,
Cover: "",
},
{
Name: "容器卡片",
Code: domain.ContainerCard1,
Cover: "",
},
{
Name: "四分图",
Code: domain.QuarterChart1,
Cover: "",
},
}
var result = make([]types.ChartComponentItem, 0)
for _, com := range list {
if req.Name != "" {
if !strings.Contains(com.Name, req.Name) {
continue
}
}
result = append(result, com)
}
resp = &types.ChartComponentSearchResponse{
List: result,
Total: int64(len(result)),
}
return
}
... ...
package table
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type GetTableDetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTableDetailLogic {
return &GetTableDetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) {
response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId})
if err != nil {
logx.Error(err)
return resp, xerr.NewErr(err)
}
resp = response
return
}
... ...
package table
import (
"context"
"github.com/zeromicro/go-zero/core/errorx"
"github.com/zeromicro/go-zero/core/fx"
"github.com/zeromicro/go-zero/core/logx"
"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"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
)
type SearchTableByModuleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchTableByModuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchTableByModuleLogic {
return &SearchTableByModuleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByModuleRequest) (resp interface{}, err error) {
var result = make(map[string]interface{})
var batchError errorx.BatchError
fx.Parallel(func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
TableTypes: []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable},
Module: bytelib.ModuleDigitalCenter,
})
if err != nil {
batchError.Add(err)
}
result["导入模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
TableTypes: []string{bytelib.SchemaTable},
Module: bytelib.ModuleQuerySetCenter,
})
if err != nil {
batchError.Add(err)
}
result["拆解模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet},
Module: bytelib.ModuleCalculateCenter,
})
if err != nil {
batchError.Add(err)
}
result["计算模块"] = newList(list)
})
if err = batchError.Err(); err != nil {
logx.Error(err)
return resp, xerr.NewErr(err)
}
resp = result
return
}
func newList(r bytelib.ObjectTableSearchResponse) interface{} {
return map[string]interface{}{
"count": r.Count,
"list": r.List,
}
}
... ...
package table
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchTableDataLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchTableDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchTableDataLogic {
return &SearchTableDataLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest) (resp interface{}, err error) {
tableDataPreviewRequest := &bytelib.TableDataPreviewRequest{
ObjectType: bytelib.ObjectMetaTable,
ObjectId: int64(req.ObjectId),
Where: newWhere(req.Condition).WithPageSize(req.PageNumber, req.PageSize),
}
var (
response bytelib.TablePreviewResponse
)
response, err = l.svcCtx.ByteMetadataService.TableDataPreview(l.ctx, tableDataPreviewRequest)
if err != nil {
return resp, xerr.NewErr(err)
}
resp = map[string]interface{}{
"objectId": response.ObjectId,
"fields": response.Fields,
"total": response.Grid.Total,
"data": response.Grid.List,
}
return
}
... ...
package table
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"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"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchTableFieldOptionalValuesLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchTableFieldOptionalValuesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchTableFieldOptionalValuesLogic {
return &SearchTableFieldOptionalValuesLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchTableFieldOptionalValuesLogic) SearchTableFieldOptionalValues(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) {
fieldOptionalValuesRequest := &bytelib.TableFieldOptionalValuesRequest{
ObjectType: bytelib.ObjectMetaTable,
ObjectId: req.ObjectId,
Field: bytelib.Field{
Name: req.Field,
SQLName: req.SqlName,
},
//PageSize: req.PageSize,
//PageNumber: req.PageNumber,
Where: newWhere(req.Condition),
}
var (
response bytelib.TableFieldOptionalValuesResponse
)
response, err = l.svcCtx.ByteMetadataService.TableFieldOptionalValues(l.ctx, fieldOptionalValuesRequest)
if err != nil {
return resp, xerr.NewErr(err)
}
resp = &types.SearchTableFieldOptionalValuesResponse{
Values: response.Values,
Total: response.Total,
}
return
}
func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere {
where := &bytelib.TableQueryWhere{}
for _, c := range conditions {
order := c.Order
if order == "" {
order = "ASC"
}
where.Conditions = append(where.Conditions, &bytelib.TableQueryCondition{
Field: &bytelib.Field{
Name: c.FieldName,
SQLName: c.SqlName,
},
Like: c.Like,
In: c.In,
Order: order,
})
}
return where
}
... ...
... ... @@ -7,6 +7,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/repository"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/database"
"gorm.io/gorm"
... ... @@ -18,6 +20,8 @@ type ServiceContext struct {
Redis *redis.Redis
RedisCache gzcache.GZCache
ChartRepository domain.ChartRepository
ByteMetadataService bytelib.ByteMetadataService
}
func NewServiceContext(c config.Config) *ServiceContext {
... ... @@ -32,6 +36,10 @@ func NewServiceContext(c config.Config) *ServiceContext {
RedisCache: redisCache,
Redis: redis,
ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)),
ByteMetadataService: bytelib.ByteMetadataService{
Service: gateway.NewService(c.ByteMetadata.Name, c.ByteMetadata.Host, c.ByteMetadata.Timeout),
},
}
}
... ...
... ... @@ -46,7 +46,7 @@ type ChartSearchResponse struct {
type ChartUpdateSortRequest struct {
Id int64 `json:"id"`
Pid int64 `json:"pid"`
Index int `json:"index"` // 元素下标,从0开始
Index int `json:"index"` // 元素下标
}
type ChartUpdateSortResponse struct {
... ... @@ -61,10 +61,69 @@ type ChartRenameResponse struct {
}
type ChartItem struct {
Id int64 `json:"id,optional"` // ID
Pid int64 `json:"pid,optional"` // 父级ID
Type string `json:"type,optional"` // 类型 report:报表 group:分组 chart:图表
Sort int64 `json:"sort,optional"` // 排序
Name string `json:"name,optional"` // 名称
//Charts []ChartItem `json:"charts,optional"`
Id int64 `json:"id,optional"` // ID
Pid int64 `json:"pid,optional"` // 父级ID
Type string `json:"type,optional"` // 类型 report:报表 group:分组 chart:图表
Sort int64 `json:"sort,optional"` // 排序
Name string `json:"name,optional"` // 名称
Charts []ChartItem `json:"charts,optional"`
}
type ChartComponentSearchRequest struct {
Name string `json:"name"`
}
type ChartComponentSearchResponse struct {
List []ChartComponentItem `json:"list"`
Total int64 `json:"total"`
}
type ChartComponentItem struct {
Name string `json:"name,optional"` // 名称
Code string `json:"code,optional"` // 编码
Cover string `json:"cover,optional"` // 封面
Desc string `json:"desc,optional"` // 描述
}
type SearchTableByModuleRequest struct {
}
type SearchTableByModuleResponse struct {
}
type SearchTableFieldOptionalValuesRequest struct {
ObjectId int `json:"objectId"` // 对象ID
Field string `json:"field"` // 当前选择的字段
SqlName string `json:"sqlName"` // 字段SqlName
Condition []*Condition `json:"conditions,optional"` // 条件
}
type SearchTableFieldOptionalValuesResponse struct {
Values []string `json:"values"`
Total int64 `json:"total"`
}
type Condition struct {
FieldName string `json:"field"` // 条件字段
SqlName string `json:"sqlName"` // 字段SqlName
Like string `json:"like,optional"` // 模糊匹配
In []string `json:"in,optional"` // 匹配多个值
Order string `json:"order,optional,options=[ASC,DESC]"` // 排序 ASC DESC 默认ASC
}
type GetTableDetailRequest struct {
TableId int `path:"tableId"` // 表ID
}
type GetTableDetailResponse struct {
}
type SearchTableDataRequest struct {
ObjectId int `json:"objectId"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
}
type SearchTableDataResponse struct {
}
... ...
package domain
var (
RecordTable1 = "RecordTable1"
MetricsCard1 = "MetricsCard1"
ContainerCard1 = "ContainerCard1"
QuarterChart1 = "QuarterChart1"
)
type ChartProperty struct {
Title *Title `json:"title,optional"` // 标题
FilterRule *FilterRule `json:"filterRule,optional"` // 过滤规则
... ... @@ -11,7 +18,7 @@ type ChartProperty struct {
}
type Series struct {
Type string `json:"type"` // 图表类型 (记录型表格:RecordTable-1 总体指标:MetricsCard-1 容器卡片:ContainerCard-1 四分图:QuarterChart-1)
Type string `json:"type"` // 图表类型 (记录型表格:RecordTable1 总体指标:MetricsCard1 容器卡片:ContainerCard1 四分图:QuarterChart1)
Name string `json:"name"` // 名称
Data interface{} `json:"data"` // 保存配置的时候置空
Config *DataConfig `json:"config"` // 配置
... ...
... ... @@ -5,15 +5,11 @@ import (
"fmt"
)
type MessageCode struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
// Response 统一消息返回格式
type Response struct {
MessageCode
Data json.RawMessage `json:"data"`
Code int `json:"code,optional"`
Msg string `json:"msg,optional"`
Data json.RawMessage `json:"data,optional"`
}
//
... ...
... ... @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/zeromicro/go-zero/core/mapping"
"github.com/zeromicro/go-zero/rest/httpc"
"io/ioutil"
"net/http"
"strings"
"time"
... ... @@ -21,9 +22,10 @@ type Service struct {
func NewService(name string, host string, timeout time.Duration, opts ...httpc.Option) Service {
client := &http.Client{}
client.Timeout = timeout
//client.Timeout = timeout
service := Service{
host: host,
service: httpc.NewServiceWithClient(name, client, opts...),
}
return service
... ... @@ -31,10 +33,11 @@ func NewService(name string, host string, timeout time.Duration, opts ...httpc.O
func (gateway Service) Do(ctx context.Context, url string, method string, val interface{}, result interface{}) error {
var (
baseResponse = &Response{}
baseResponse = Response{}
begin = time.Now()
body []byte
)
response, err := gateway.service.Do(ctx, gateway.host+url, method, val)
response, err := gateway.service.Do(ctx, method, gateway.host+url, val)
defer func() {
jsonParam, _ := json.Marshal(val)
jsonData, _ := json.Marshal(result)
... ... @@ -55,19 +58,31 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in
if response.StatusCode != http.StatusOK {
return HttpError{
Base: Response{
MessageCode: MessageCode{
Code: response.StatusCode,
Msg: response.Status,
},
Code: response.StatusCode,
Msg: response.Status,
},
}
}
if err = httpc.ParseJsonBody(response, baseResponse); err != nil {
body, err = Bytes(response)
if err != nil {
return err
}
if err = json.Unmarshal(body, &baseResponse); err != nil {
return err
}
if err = mapping.UnmarshalJsonBytes(baseResponse.Data, result); err != nil {
return err
}
return nil
}
func Bytes(resp *http.Response) ([]byte, error) {
var body []byte
if resp.Body == nil {
return nil, nil
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
return body, err
}
... ...
... ... @@ -22,11 +22,23 @@ type TableDataPreviewRequest struct {
}
type TableQueryWhere struct {
PageNumber int64 `json:"pageNumber"`
PageSize int64 `json:"pageSize"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
Conditions []*TableQueryCondition `json:"conditions"`
}
func (w *TableQueryWhere) WithPageSize(page, size int) *TableQueryWhere {
w.PageNumber = page - 1
w.PageSize = size
if page == 0 {
w.PageNumber = 0
}
if w.PageSize == 0 {
w.PageSize = 20
}
return w
}
type TableQueryCondition struct {
Field *Field `json:"field"` //字段
Like string `json:"like"` //模糊匹配
... ... @@ -56,7 +68,7 @@ type TableData struct {
type TableDataGrid struct {
//数据列表
List []interface{} `json:"list"`
List []map[string]string `json:"list"`
//总记录数
Total int64 `json:"total"`
}
... ...
package bytelib
import (
"context"
"net/http"
)
func (gateway *ByteMetadataService) TableFieldOptionalValues(ctx context.Context, request *TableFieldOptionalValuesRequest) (TableFieldOptionalValuesResponse, error) {
var result TableFieldOptionalValuesResponse
if err := gateway.Do(ctx, "/data/field-optional-values", http.MethodPost, request, &result); err != nil {
return result, err
}
return result, nil
}
type TableFieldOptionalValuesRequest struct {
ObjectType string `json:"objectType" valid:"Required"` // 对象类型
ObjectId int `json:"objectId" valid:"Required"` // 对象Id标识
Field Field `json:"field" valid:"Required"` // 选择列
Match string `json:"match"` // 模糊匹配
PageNumber int `json:"pageNumber"` // 页吗
PageSize int `json:"pageSize"` // 页
Where *TableQueryWhere `json:"where"`
}
type TableFieldOptionalValuesResponse struct {
Values []string `json:"values"`
Total int64 `json:"total"`
}
//type Where struct {
// Conditions []TableQueryCondition `json:"conditions"`
//}
... ...
... ... @@ -7,7 +7,7 @@ import (
func (gateway *ByteMetadataService) TableInfo(ctx context.Context, request *TableInfoRequest) (TableInfoResponse, error) {
var result TableInfoResponse
if err := gateway.Do(ctx, "/tables/:tableId", http.MethodGet, request, &result); err != nil {
if err := gateway.Do(ctx, "/data/tables/:tableId", http.MethodGet, request, &result); err != nil {
return result, err
}
return result, nil
... ...
... ... @@ -15,29 +15,30 @@ func (gateway *ByteMetadataService) ObjectTableSearch(ctx context.Context, reque
type ObjectTableSearchRequest struct {
// 表名称
Name string `cname:"表名称" json:"name"`
Name string `cname:"表名称" json:"name,optional"`
//ViewType string `cname:"视图类型 full:完整 main:主表关系" json:"viewType"`
// 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表 SubProcess:子过程 Schema:方案
TableTypes []string `cname:"表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表" json:"tableTypes" valid:"Required"`
TableTypes []string `json:"tableTypes"`
// 父级ID
ParentId int `cname:"父级ID" json:"parentId"`
ParentId int `json:"parentId,optional"`
// 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块
Module int `json:"module"`
// 父级ID
ParentTableId int `cname:"父级ID" json:"parentTableId"`
// 返回结构信息
ReturnDetailStructInfo bool `cname:"返回具体的结构信息 默认不返回" json:"returnDetailStructInfo"`
ParentTableId int `json:"parentTableId,optional"`
// 返回具体的结构信息 默认不返回
ReturnDetailStructInfo bool `json:"returnDetailStructInfo,optional"`
// 排除分组项,只返回一级列表;默认 false 不排除,连分组也返回
ReturnGroupItem bool `cname:"排除分组" json:"returnGroupItem"`
ReturnGroupItem bool `json:"returnGroupItem,optional"`
// 排除指定表
ExcludeTables []int `cname:"排除指定表" json:"excludeTables"`
FilterRules []*FilterRule `json:"filterRules"`
TableId int `cname:"ID" json:"tableId"`
ExcludeTables []int `json:"excludeTables,optional"`
FilterRules []*FilterRule `json:"filterRules,optional"`
TableId int `json:"tableId,optional"`
QuerySetId int64 `json:"QuerySetId,optional"`
}
type ObjectTableSearchResponse struct {
Count int `json:"count"`
List []*Table `json:"list"`
List []*Table `json:"tableObjects"`
}
type FilterRule struct {
... ... @@ -48,7 +49,7 @@ type FilterRule struct {
type Table struct {
// 序号
Id int `json:"id"`
// Id int `json:"id"`
// 表Id
TableId int `json:"tableId"`
// 表类型 MainTable:主表 SideTable:副表 SubTable:分表 ExcelTable:Excel表
... ... @@ -56,17 +57,17 @@ type Table struct {
// 名称
Name string `json:"name"`
// 对应数据库名称
SQLName string `json:"sqlName,omitempty"`
// SQLName string `json:"sqlName,omitempty"`
// 父级ID
ParentId int `json:"parentId"`
// 模块 应用于模块 1:数控中心 2:拆解模块 4:计算模块
Module int `json:"module"`
// Module int `json:"module"`
// 标识
Flag string `json:"flag,omitempty"`
// Flag string `json:"flag,omitempty"`
// 启用状态
Status int `json:"status"`
// Status int `json:"status"`
// 冲突状态
InConflict bool `json:"inConflict"`
// InConflict bool `json:"inConflict"`
// 表字段
Fields []*Field `json:"fields"`
}
... ... @@ -80,5 +81,5 @@ type Field struct {
// 对应数据库类型
SQLType string `json:"sqlType"`
// 标识 1.主键 2:主表字段 3:手动添加
Flag int `json:"flag"`
//Flag int `json:"flag"`
}
... ...
package bytelib
var (
MainTable TableType = "MainTable" // 主表
SideTable TableType = "SideTable" // 副表
SubTable TableType = "SubTable" // 分表
SchemaTable TableType = "Schema" // 方案
SubProcessTable TableType = "SubProcess" // 子过程
CalculateItem TableType = "CalculateItem" // 计算项
CalculateTable TableType = "CalculateTable" // 计算表
CalculateSet TableType = "CalculateSet" // 计算集
MainTable string = "MainTable" // 主表
SideTable string = "SideTable" // 副表
SubTable string = "SubTable" // 分表
SchemaTable string = "Schema" // 方案
SubProcessTable string = "SubProcess" // 子过程
CalculateItem string = "CalculateItem" // 计算项
CalculateTable string = "CalculateTable" // 计算表
CalculateSet string = "CalculateSet" // 计算集
)
type TableType string
const (
ModuleAll = ModuleDigitalCenter | ModuleQuerySetCenter | ModuleCalculateCenter
ModuleDigitalCenter = 1
ModuleQuerySetCenter = 2
ModuleCalculateCenter = 4
)
func (t TableType) ToString() string {
return string(t)
}
const (
ObjectFile = "File"
ObjectMetaTable = "MetaTable"
ObjectDBTable = "DBTable"
)
... ...
import "core/chart.api"
import "core/table.api"
// import "./core/chart_stting.api"
\ No newline at end of file
... ...
... ... @@ -43,10 +43,38 @@
]
}
},
"v1/chart/rename": {
"v1/chart/components/search": {
"post": {
"summary": "更新图表排序",
"operationId": "renameChartSort",
"summary": "搜索图表组件",
"operationId": "searchChartComponents",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChartComponentSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChartComponentSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"chart"
]
}
},
"v1/chart/move": {
"post": {
"summary": "移动图表",
"operationId": "updateChartSort",
"responses": {
"200": {
"description": "A successful response.",
... ... @@ -71,15 +99,15 @@
]
}
},
"v1/chart/search": {
"v1/chart/rename": {
"post": {
"summary": "搜索图表",
"operationId": "searchChart",
"summary": "重命名图表",
"operationId": "renameChartSort",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChartSearchResponse"
"$ref": "#/definitions/ChartRenameResponse"
}
}
},
... ... @@ -89,7 +117,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChartSearchRequest"
"$ref": "#/definitions/ChartRenameRequest"
}
}
],
... ... @@ -99,15 +127,15 @@
]
}
},
"v1/chart/sort": {
"v1/chart/search": {
"post": {
"summary": "更新图表排序",
"operationId": "updateChartSort",
"summary": "搜索图表",
"operationId": "searchChart",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChartUpdateSortResponse"
"$ref": "#/definitions/ChartSearchResponse"
}
}
},
... ... @@ -117,7 +145,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChartUpdateSortRequest"
"$ref": "#/definitions/ChartSearchRequest"
}
}
],
... ... @@ -216,9 +244,173 @@
"chart"
]
}
},
"v1/table/data": {
"post": {
"summary": "源数据表-数据",
"operationId": "searchTableData",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SearchTableDataResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SearchTableDataRequest"
}
}
],
"requestBody": {},
"tags": [
"table"
]
}
},
"v1/table/field-optional-values": {
"post": {
"summary": "源数据表-字段可选值",
"operationId": "searchTableFieldOptionalValues",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SearchTableByModuleResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SearchTableByModuleRequest"
}
}
],
"requestBody": {},
"tags": [
"table"
]
}
},
"v1/table/search-by-module": {
"post": {
"summary": "源数据表-按模块搜索",
"operationId": "searchTableByModule",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/SearchTableByModuleResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/SearchTableByModuleRequest"
}
}
],
"requestBody": {},
"tags": [
"table"
]
}
},
"v1/table/{tableId}": {
"get": {
"summary": "源数据表-详情",
"operationId": "getTableDetail",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/GetTableDetailResponse"
}
}
},
"parameters": [
{
"name": "tableId",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"table"
]
}
}
},
"definitions": {
"ChartComponentItem": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": " 名称"
},
"code": {
"type": "string",
"description": " 编码"
},
"cover": {
"type": "string",
"description": " 封面"
},
"desc": {
"type": "string",
"description": " 描述"
}
},
"title": "ChartComponentItem"
},
"ChartComponentSearchRequest": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"title": "ChartComponentSearchRequest",
"required": [
"name"
]
},
"ChartComponentSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/ChartComponentItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "ChartComponentSearchResponse",
"required": [
"list",
"total"
]
},
"ChartDeleteRequest": {
"type": "object",
"properties": {
... ... @@ -355,20 +547,19 @@
"ChartSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
"includeTypes": {
"type": "array",
"items": {
"type": "string"
},
"description": "包含的类型: 类型 report:报表 group:分组 chart:图表(未指定返回所有)"
},
"size": {
"type": "integer",
"format": "int32"
"dataStyle": {
"type": "string",
"description": " 数据样式 tree:树形 flat:平铺"
}
},
"title": "ChartSearchRequest",
"required": [
"page",
"size"
]
"title": "ChartSearchRequest"
},
"ChartSearchResponse": {
"type": "object",
... ... @@ -414,25 +605,172 @@
"type": "integer",
"format": "int64"
},
"sort": {
"pid": {
"type": "integer",
"format": "int32"
"format": "int64"
},
"pid": {
"index": {
"type": "integer",
"format": "int32"
"format": "int32",
"description": " 元素下标"
}
},
"title": "ChartUpdateSortRequest",
"required": [
"id",
"sort",
"pid"
"pid",
"index"
]
},
"ChartUpdateSortResponse": {
"type": "object",
"title": "ChartUpdateSortResponse"
},
"Condition": {
"type": "object",
"properties": {
"field": {
"type": "string",
"description": " 条件字段"
},
"sqlName": {
"type": "string",
"description": " 字段SqlName"
},
"like": {
"type": "string",
"description": " 模糊匹配"
},
"in": {
"type": "array",
"items": {
"type": "string"
},
"description": " 匹配多个值"
},
"order": {
"type": "string",
"description": " 排序 ASC DESC 默认ASC"
}
},
"title": "Condition",
"required": [
"field",
"sqlName",
"order"
]
},
"GetTableDetailRequest": {
"type": "object",
"properties": {
"tableId": {
"type": "integer",
"format": "int32",
"description": " 表ID"
}
},
"title": "GetTableDetailRequest",
"required": [
"tableId"
]
},
"GetTableDetailResponse": {
"type": "object",
"title": "GetTableDetailResponse"
},
"SearchTableByModuleRequest": {
"type": "object",
"title": "SearchTableByModuleRequest"
},
"SearchTableByModuleResponse": {
"type": "object",
"title": "SearchTableByModuleResponse"
},
"SearchTableDataRequest": {
"type": "object",
"properties": {
"objectId": {
"type": "integer",
"format": "int32",
"description": " 对象ID"
},
"pageNumber": {
"type": "integer",
"format": "int32",
"description": " 分页数"
},
"pageSize": {
"type": "integer",
"format": "int32",
"description": " 页码"
},
"conditions": {
"type": "array",
"items": {
"$ref": "#/definitions/Condition"
},
"description": " 条件"
}
},
"title": "SearchTableDataRequest",
"required": [
"objectId"
]
},
"SearchTableDataResponse": {
"type": "object",
"title": "SearchTableDataResponse"
},
"SearchTableFieldOptionalValuesRequest": {
"type": "object",
"properties": {
"objectId": {
"type": "integer",
"format": "int32",
"description": " 对象ID"
},
"field": {
"type": "string",
"description": " 当前选择的字段"
},
"sqlName": {
"type": "string",
"description": " 字段SqlName"
},
"conditions": {
"type": "array",
"items": {
"$ref": "#/definitions/Condition"
},
"description": " 条件"
}
},
"title": "SearchTableFieldOptionalValuesRequest",
"required": [
"objectId",
"field",
"sqlName"
]
},
"SearchTableFieldOptionalValuesResponse": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "string"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "SearchTableFieldOptionalValuesResponse",
"required": [
"values",
"total"
]
}
},
"securityDefinitions": {
... ...
... ... @@ -2,9 +2,9 @@
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
... ... @@ -37,6 +37,10 @@ service Core {
@doc "重命名图表"
@handler renameChartSort
post /chart/rename (ChartRenameRequest) returns (ChartRenameResponse)
@doc "搜索图表组件"
@handler searchChartComponents
post /chart/components/search(ChartComponentSearchRequest)returns(ChartComponentSearchResponse)
}
type (
... ... @@ -94,3 +98,19 @@ type (
Charts []ChartItem `json:"charts,optional"`
}
)
type(
ChartComponentSearchRequest{
Name string `json:"name"`
}
ChartComponentSearchResponse{
List []ChartComponentItem `json:"list"`
Total int64 `json:"total"`
}
ChartComponentItem struct{
Name string `json:"name,optional"`// 名称
Code string `json:"code,optional"`// 编码
Cover string `json:"cover,optional"` // 封面
Desc string `json:"desc,optional"`// 描述
}
)
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: table
jwt: JwtAuth
//middleware: Authority
)
service Core {
@doc "源数据表-按模块搜索"
@handler searchTableByModule
post /table/search-by-module (SearchTableByModuleRequest) returns (SearchTableByModuleResponse)
@doc "源数据表-字段可选值"
@handler searchTableFieldOptionalValues
post /table/field-optional-values (SearchTableByModuleRequest) returns (SearchTableByModuleResponse)
@doc "源数据表-详情"
@handler getTableDetail
get /table/:tableId (GetTableDetailRequest) returns (GetTableDetailResponse)
@doc "源数据表-数据"
@handler searchTableData
post /table/data (SearchTableDataRequest) returns (SearchTableDataResponse)
}
type (
SearchTableByModuleRequest struct{
}
SearchTableByModuleResponse struct{
}
SearchTableFieldOptionalValuesRequest struct{
ObjectId int `json:"objectId"` // 对象ID
Field string `json:"field"` // 当前选择的字段
SqlName string `json:"sqlName"` // 字段SqlName
// Match string `json:"match"`
//PageNumber int `json:"pageNumber,optional"` // 分页数
//PageSize int `json:"pageSize,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
}
SearchTableFieldOptionalValuesResponse struct{
Values []string `json:"values"`
Total int64 `json:"total"`
}
Condition struct {
FieldName string `json:"field"` // 条件字段
SqlName string `json:"sqlName"` // 字段SqlName
Like string `json:"like,optional"` // 模糊匹配
In []string `json:"in,optional"` // 匹配多个值
Order string `json:"order,optional,options=[ASC,DESC]"` // 排序 ASC DESC 默认ASC
}
GetTableDetailRequest struct {
TableId int `path:"tableId"` // 表ID
}
GetTableDetailResponse struct{
}
SearchTableDataRequest struct{
ObjectId int `json:"objectId"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
}
SearchTableDataResponse struct{
}
)
\ No newline at end of file
... ...
... ... @@ -21,6 +21,9 @@ func (e *CodeError) GetErrCode() uint32 {
// GetErrMsg 返回给前端显示端错误信息
func (e *CodeError) GetErrMsg() string {
if e.errMsg == "" {
return MapErrMsg(e.errCode)
}
return e.errMsg
}
... ...