作者 庄敏学

数据存储

... ... @@ -26,6 +26,11 @@ func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
}
func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) {
//获取本地数据
local, err := l.GetLocal(req.TableId)
if err == nil {
return local, nil
}
response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId, Token: req.Token})
if err != nil {
logx.Error(err)
... ... @@ -35,3 +40,25 @@ func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (
resp = response
return
}
func (l *GetTableDetailLogic) GetLocal(tableId int) (interface{}, error) {
conn := l.svcCtx.DefaultDBConn()
//查询表数据
objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, tableId)
if err != nil || objectTable.Id <= 0 {
return nil, xerr.NewErrMsg("表不存在")
}
//查询表字段
objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(tableId))
if err != nil || objectField.Id <= 0 {
return nil, xerr.NewErrMsg("表字段不存在")
}
resp := bytelib.TableInfoResponse{
TableId: objectTable.TableId,
TableType: objectTable.TableType,
Name: objectTable.Name,
ParentId: objectTable.ParentId,
Fields: removeIdField(objectField.Fields),
}
return resp, nil
}
... ...
... ... @@ -63,6 +63,19 @@ func (l *SearchTableDataLogic) getLocal(req *types.SearchTableDataRequest) (inte
if err != nil || objectField.Id <= 0 {
return nil, xerr.NewErrMsg("表字段不存在")
}
//替换中文字段
for _, item := range conditions {
replace := false
for _, field := range objectField.Fields {
if field.Name == item.FieldName {
item.FieldName = field.SQLName
replace = true
}
}
if !replace {
return nil, xerr.NewErrMsg("字段" + item.FieldName + "不存在")
}
}
//表数据
total, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{
Page: req.PageNumber,
... ...
... ... @@ -2,6 +2,10 @@ package table
import (
"context"
"fmt"
"github.com/jinzhu/copier"
"github.com/samber/lo"
"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/bytelib"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
... ... @@ -69,3 +73,53 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere {
}
return where
}
func (l *SearchTableFieldOptionalValuesLogic) getLocal(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) {
conn := l.svcCtx.DefaultDBConn()
//查询表数据
objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, req.ObjectId)
if err != nil || objectTable.Id <= 0 {
return nil, xerr.NewErrMsg("表不存在")
}
if !objectTable.IsLocal {
return nil, xerr.NewErrMsg("未保存到本地存储")
}
//查询表字段
objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(req.ObjectId))
if err != nil || objectField.Id <= 0 {
return nil, xerr.NewErrMsg("表字段不存在")
}
conditions := make([]*domain.TableDataCondition, 0)
_ = copier.Copy(&conditions, req.Condition)
//替换中文字段
for _, item := range conditions {
replace := false
for _, field := range objectField.Fields {
if field.Name == item.FieldName {
item.FieldName = field.SQLName
replace = true
}
}
if !replace {
return nil, xerr.NewErrMsg("字段" + item.FieldName + "不存在")
}
}
//表数据
_, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{
Conditions: conditions,
})
fmt.Println(list)
if err != nil {
return nil, xerr.NewErrMsg("查询表数据失败")
}
resp = &types.SearchTableFieldOptionalValuesResponse{
Values: make([]string, 0),
Total: 0,
}
if len(list) > 0 {
lo.ForEach(list, func(item map[string]interface{}, index int) {
})
}
return resp, nil
}
... ...
... ... @@ -140,7 +140,11 @@ func (repository *ObjectTableDataRepository) Find(ctx context.Context, conn tran
}
}
list := make([]map[string]interface{}, 0)
total, tx := transaction.PaginationAndCount(ctx, tx, domain.NewQueryOptions().WithOffsetLimit(query.Page, query.Size), &list)
options := domain.NewQueryOptions()
if query.Size > 0 {
options = options.WithOffsetLimit(query.Page, query.Size)
}
total, tx := transaction.PaginationAndCount(ctx, tx, options, &list)
return total, list, tx.Error
}
... ...