正在显示
4 个修改的文件
包含
99 行增加
和
1 行删除
@@ -26,6 +26,11 @@ func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge | @@ -26,6 +26,11 @@ func NewGetTableDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge | ||
26 | } | 26 | } |
27 | 27 | ||
28 | func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) { | 28 | func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) (resp interface{}, err error) { |
29 | + //获取本地数据 | ||
30 | + local, err := l.GetLocal(req.TableId) | ||
31 | + if err == nil { | ||
32 | + return local, nil | ||
33 | + } | ||
29 | response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId, Token: req.Token}) | 34 | response, err := l.svcCtx.ByteMetadataService.TableInfo(l.ctx, &bytelib.TableInfoRequest{TableId: req.TableId, Token: req.Token}) |
30 | if err != nil { | 35 | if err != nil { |
31 | logx.Error(err) | 36 | logx.Error(err) |
@@ -35,3 +40,25 @@ func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) ( | @@ -35,3 +40,25 @@ func (l *GetTableDetailLogic) GetTableDetail(req *types.GetTableDetailRequest) ( | ||
35 | resp = response | 40 | resp = response |
36 | return | 41 | return |
37 | } | 42 | } |
43 | + | ||
44 | +func (l *GetTableDetailLogic) GetLocal(tableId int) (interface{}, error) { | ||
45 | + conn := l.svcCtx.DefaultDBConn() | ||
46 | + //查询表数据 | ||
47 | + objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, tableId) | ||
48 | + if err != nil || objectTable.Id <= 0 { | ||
49 | + return nil, xerr.NewErrMsg("表不存在") | ||
50 | + } | ||
51 | + //查询表字段 | ||
52 | + objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(tableId)) | ||
53 | + if err != nil || objectField.Id <= 0 { | ||
54 | + return nil, xerr.NewErrMsg("表字段不存在") | ||
55 | + } | ||
56 | + resp := bytelib.TableInfoResponse{ | ||
57 | + TableId: objectTable.TableId, | ||
58 | + TableType: objectTable.TableType, | ||
59 | + Name: objectTable.Name, | ||
60 | + ParentId: objectTable.ParentId, | ||
61 | + Fields: removeIdField(objectField.Fields), | ||
62 | + } | ||
63 | + return resp, nil | ||
64 | +} |
@@ -63,6 +63,19 @@ func (l *SearchTableDataLogic) getLocal(req *types.SearchTableDataRequest) (inte | @@ -63,6 +63,19 @@ func (l *SearchTableDataLogic) getLocal(req *types.SearchTableDataRequest) (inte | ||
63 | if err != nil || objectField.Id <= 0 { | 63 | if err != nil || objectField.Id <= 0 { |
64 | return nil, xerr.NewErrMsg("表字段不存在") | 64 | return nil, xerr.NewErrMsg("表字段不存在") |
65 | } | 65 | } |
66 | + //替换中文字段 | ||
67 | + for _, item := range conditions { | ||
68 | + replace := false | ||
69 | + for _, field := range objectField.Fields { | ||
70 | + if field.Name == item.FieldName { | ||
71 | + item.FieldName = field.SQLName | ||
72 | + replace = true | ||
73 | + } | ||
74 | + } | ||
75 | + if !replace { | ||
76 | + return nil, xerr.NewErrMsg("字段" + item.FieldName + "不存在") | ||
77 | + } | ||
78 | + } | ||
66 | //表数据 | 79 | //表数据 |
67 | total, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{ | 80 | total, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{ |
68 | Page: req.PageNumber, | 81 | Page: req.PageNumber, |
@@ -2,6 +2,10 @@ package table | @@ -2,6 +2,10 @@ package table | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + "fmt" | ||
6 | + "github.com/jinzhu/copier" | ||
7 | + "github.com/samber/lo" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain" | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" |
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr" |
7 | 11 | ||
@@ -69,3 +73,53 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere { | @@ -69,3 +73,53 @@ func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere { | ||
69 | } | 73 | } |
70 | return where | 74 | return where |
71 | } | 75 | } |
76 | + | ||
77 | +func (l *SearchTableFieldOptionalValuesLogic) getLocal(req *types.SearchTableFieldOptionalValuesRequest) (resp *types.SearchTableFieldOptionalValuesResponse, err error) { | ||
78 | + conn := l.svcCtx.DefaultDBConn() | ||
79 | + //查询表数据 | ||
80 | + objectTable, err := l.svcCtx.ObjectTableRepository.FindOneByTableId(l.ctx, conn, req.ObjectId) | ||
81 | + if err != nil || objectTable.Id <= 0 { | ||
82 | + return nil, xerr.NewErrMsg("表不存在") | ||
83 | + } | ||
84 | + if !objectTable.IsLocal { | ||
85 | + return nil, xerr.NewErrMsg("未保存到本地存储") | ||
86 | + } | ||
87 | + //查询表字段 | ||
88 | + objectField, err := l.svcCtx.ObjectFieldRepository.FindOne(l.ctx, conn, int64(req.ObjectId)) | ||
89 | + if err != nil || objectField.Id <= 0 { | ||
90 | + return nil, xerr.NewErrMsg("表字段不存在") | ||
91 | + } | ||
92 | + conditions := make([]*domain.TableDataCondition, 0) | ||
93 | + _ = copier.Copy(&conditions, req.Condition) | ||
94 | + //替换中文字段 | ||
95 | + for _, item := range conditions { | ||
96 | + replace := false | ||
97 | + for _, field := range objectField.Fields { | ||
98 | + if field.Name == item.FieldName { | ||
99 | + item.FieldName = field.SQLName | ||
100 | + replace = true | ||
101 | + } | ||
102 | + } | ||
103 | + if !replace { | ||
104 | + return nil, xerr.NewErrMsg("字段" + item.FieldName + "不存在") | ||
105 | + } | ||
106 | + } | ||
107 | + //表数据 | ||
108 | + _, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{ | ||
109 | + Conditions: conditions, | ||
110 | + }) | ||
111 | + fmt.Println(list) | ||
112 | + if err != nil { | ||
113 | + return nil, xerr.NewErrMsg("查询表数据失败") | ||
114 | + } | ||
115 | + resp = &types.SearchTableFieldOptionalValuesResponse{ | ||
116 | + Values: make([]string, 0), | ||
117 | + Total: 0, | ||
118 | + } | ||
119 | + if len(list) > 0 { | ||
120 | + lo.ForEach(list, func(item map[string]interface{}, index int) { | ||
121 | + | ||
122 | + }) | ||
123 | + } | ||
124 | + return resp, nil | ||
125 | +} |
@@ -140,7 +140,11 @@ func (repository *ObjectTableDataRepository) Find(ctx context.Context, conn tran | @@ -140,7 +140,11 @@ func (repository *ObjectTableDataRepository) Find(ctx context.Context, conn tran | ||
140 | } | 140 | } |
141 | } | 141 | } |
142 | list := make([]map[string]interface{}, 0) | 142 | list := make([]map[string]interface{}, 0) |
143 | - total, tx := transaction.PaginationAndCount(ctx, tx, domain.NewQueryOptions().WithOffsetLimit(query.Page, query.Size), &list) | 143 | + options := domain.NewQueryOptions() |
144 | + if query.Size > 0 { | ||
145 | + options = options.WithOffsetLimit(query.Page, query.Size) | ||
146 | + } | ||
147 | + total, tx := transaction.PaginationAndCount(ctx, tx, options, &list) | ||
144 | return total, list, tx.Error | 148 | return total, list, tx.Error |
145 | } | 149 | } |
146 | 150 |
-
请 注册 或 登录 后发表评论