作者 庄敏学

获取数据加入本地存储

package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/golang-jwt/jwt/v4/request"
"github.com/zeromicro/go-queue/kq"
"github.com/zeromicro/go-zero/core/logx"
... ... @@ -10,6 +12,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"net/http"
"strings"
"time"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler"
... ... @@ -67,26 +70,26 @@ func main() {
func startConsume(c config.Config) {
svcCtx := svc.NewServiceContext(c)
go func() {
//for {
// notice := &domain.ObjectNotice{
// CompanyId: 1594869884284571648,
// TableId: 1573,
// TableType: "主表",
// ObjectType: "导入模块",
// Event: "table.data.edit",
// TableAffectedList: []int{1573},
// DataChanged: true,
// StructChanged: true,
// MetaData: domain.ObjectNoticeMetaData{
// Module: 0,
// Status: 0,
// },
// }
// mBytes, _ := json.Marshal(notice)
// err := kq.NewPusher(c.KqConsumerConf.Brokers, c.KqConsumerConf.Topic).Push(string(mBytes))
// fmt.Println(err)
// time.Sleep(10 * 10 * time.Second)
//}
for {
notice := &domain.ObjectNotice{
CompanyId: 1594869884284571648,
TableId: 1573,
TableType: "主表",
ObjectType: "导入模块",
Event: "table.data.edit",
TableAffectedList: []int{1573},
DataChanged: true,
StructChanged: true,
MetaData: domain.ObjectNoticeMetaData{
Module: 0,
Status: 0,
},
}
mBytes, _ := json.Marshal(notice)
err := kq.NewPusher(c.KqConsumerConf.Brokers, c.KqConsumerConf.Topic).Push(string(mBytes))
fmt.Println(err)
time.Sleep(10 * 10 * time.Second)
}
}()
go func() {
... ...
... ... @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/stores/redis"
"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"
... ... @@ -39,7 +40,9 @@ func (logic *ByteNoticeLogic) Consume(key, value string) error {
return err
}
//处理消息
err = logic.handleNotice(notice)
err = transaction.UseTrans(logic.ctx, logic.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
return logic.handleNotice(conn, notice)
}, true)
//更新处理结果
if err != nil {
notice.Status = domain.ObjectNoticeStatusError
... ... @@ -53,10 +56,10 @@ func (logic *ByteNoticeLogic) Consume(key, value string) error {
}
// handleNotice 处理消息
func (logic *ByteNoticeLogic) handleNotice(notice *domain.ObjectNotice) error {
func (logic *ByteNoticeLogic) handleNotice(conn transaction.Conn, notice *domain.ObjectNotice) error {
//是否删除消息
if notice.IsDeletedEvent() {
return logic.handleDelete(notice)
return logic.handleDelete(conn, notice)
}
accessToken, _ := types.TableAccessToken{CompanyId: notice.CompanyId}.GenerateToken()
//结构变更
... ... @@ -100,17 +103,25 @@ func (logic *ByteNoticeLogic) handleNotice(notice *domain.ObjectNotice) error {
CompanyId: notice.CompanyId,
ParentId: item.ParentId,
Flag: item.Flag,
Fields: tableInfo.Fields,
})
//父级节点
objectTables = append(objectTables, logic.getParents(notice.CompanyId, item.ParentId, list.List)...)
}
}
err = logic.saveTables(objectTables)
err = logic.saveTables(conn, objectTables)
if err != nil {
return err
}
}
//保存字段
_, err = logic.saveFields(conn, &domain.ObjectField{
Id: int64(tableInfo.TableId),
Name: tableInfo.Name,
Fields: tableInfo.Fields,
})
if err != nil {
return err
}
}
//数据变更
if notice.DataChanged {
... ... @@ -136,10 +147,15 @@ func (logic *ByteNoticeLogic) handleNotice(notice *domain.ObjectNotice) error {
acquire, err := lock.Acquire()
fmt.Println(acquire, err)
defer lock.Release()
err = transaction.UseTrans(logic.ctx, logic.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
return logic.svcCtx.ObjectTableDataRepository.InsertWithTableData(logic.ctx, conn, bytelib.TableData(tableDataPreview))
}, true)
fmt.Println(err)
err = logic.svcCtx.ObjectTableDataRepository.InsertWithTableData(logic.ctx, conn, bytelib.TableData(tableDataPreview))
if err != nil {
return err
}
//更新标记本地存储
err = logic.updateTableWithLocal(conn, int(tableDataPreview.ObjectId))
if err != nil {
return err
}
}
return nil
}
... ... @@ -156,7 +172,6 @@ func (logic *ByteNoticeLogic) getParents(companyId int64, parentId int, list []*
CompanyId: companyId,
ParentId: item.ParentId,
Flag: item.Flag,
Fields: item.Fields,
})
if item.ParentId > 0 {
result = append(result, logic.getParents(companyId, item.ParentId, list)...)
... ... @@ -167,11 +182,11 @@ func (logic *ByteNoticeLogic) getParents(companyId int64, parentId int, list []*
}
// handleDelete 删除
func (logic *ByteNoticeLogic) handleDelete(notice *domain.ObjectNotice) error {
objectTable, err := logic.svcCtx.ObjectTableRepository.FindOneByTableId(logic.ctx, logic.conn, notice.TableId)
func (logic *ByteNoticeLogic) handleDelete(conn transaction.Conn, notice *domain.ObjectNotice) error {
objectTable, err := logic.svcCtx.ObjectTableRepository.FindOneByTableId(logic.ctx, conn, notice.TableId)
if err == nil && objectTable.Id > 0 {
objectTable.RemoteDeleted = 1
_, err := logic.svcCtx.ObjectTableRepository.Update(logic.ctx, logic.conn, objectTable)
_, err := logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, objectTable)
if err != nil {
return err
}
... ... @@ -180,26 +195,46 @@ func (logic *ByteNoticeLogic) handleDelete(notice *domain.ObjectNotice) error {
}
// saveTables 保存表结构
func (logic *ByteNoticeLogic) saveTables(tables []*domain.ObjectTable) error {
err := transaction.UseTrans(logic.ctx, logic.conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
if len(tables) > 0 {
for _, item := range tables {
objectTable, err := logic.svcCtx.ObjectTableRepository.FindOne(logic.ctx, conn, item.Id)
if err == nil && objectTable.Id > 0 {
item.Id = objectTable.Id
_, err := logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, item)
if err != nil {
return err
}
} else {
_, err := logic.svcCtx.ObjectTableRepository.Insert(logic.ctx, conn, item)
if err != nil {
return err
}
func (logic *ByteNoticeLogic) saveTables(conn transaction.Conn, tables []*domain.ObjectTable) error {
if len(tables) > 0 {
for _, item := range tables {
objectTable, err := logic.svcCtx.ObjectTableRepository.FindOne(logic.ctx, conn, item.Id)
if err == nil && objectTable.Id > 0 {
item.Id = objectTable.Id
item.Version = objectTable.Version + 1
_, err := logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, item)
if err != nil {
return err
}
} else {
_, err := logic.svcCtx.ObjectTableRepository.Insert(logic.ctx, conn, item)
if err != nil {
return err
}
}
}
return nil
}, true)
return err
}
return nil
}
// saveFields 保存表字段
func (logic *ByteNoticeLogic) saveFields(conn transaction.Conn, objectField *domain.ObjectField) (*domain.ObjectField, error) {
mField, err := logic.svcCtx.ObjectFieldRepository.FindOne(logic.ctx, conn, objectField.Id)
if err == nil && mField.Id > 0 { //已存在 - 更新
objectField.Version = mField.Version + 1
return logic.svcCtx.ObjectFieldRepository.Update(logic.ctx, conn, objectField)
} else {
return logic.svcCtx.ObjectFieldRepository.Insert(logic.ctx, conn, objectField)
}
}
// updateTableWithLocal 更新表标记本地存储
func (logic *ByteNoticeLogic) updateTableWithLocal(conn transaction.Conn, tableId int) error {
objectTable, err := logic.svcCtx.ObjectTableRepository.FindOneByTableId(logic.ctx, conn, tableId)
if err == nil && objectTable.Id > 0 {
objectTable.IsLocal = true
_, err = logic.svcCtx.ObjectTableRepository.Update(logic.ctx, conn, objectTable)
return err
}
return errors.New("表不存在")
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"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/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
)
... ... @@ -29,50 +30,70 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
var result = make(map[string]interface{})
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 | bytelib.ModuleChartTemplate, // TODO:字库更新完改为只查 bytelib.ModuleChartTemplate
})
if err != nil {
batchError.Add(err)
mResp, err := l.getTableByLocal([]string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable})
if err == nil {
result["导入模块"] = mResp
} else {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.MainTable, bytelib.SubTable, bytelib.SideTable},
Module: bytelib.ModuleDigitalCenter | bytelib.ModuleChartTemplate, // TODO:字库更新完改为只查 bytelib.ModuleChartTemplate
})
if err != nil {
batchError.Add(err)
}
result["导入模块"] = newList(list)
}
result["导入模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.SchemaTable},
Module: bytelib.ModuleQuerySetCenter,
ReturnGroupItem: true,
})
if err != nil {
batchError.Add(err)
mResp, err := l.getTableByLocal([]string{bytelib.SchemaTable})
if err == nil {
result["拆解模块"] = mResp
} else {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.SchemaTable},
Module: bytelib.ModuleQuerySetCenter,
ReturnGroupItem: true,
})
if err != nil {
batchError.Add(err)
}
result["拆解模块"] = newList(list)
}
result["拆解模块"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.CalculateItem},
Module: bytelib.ModuleCalculateCenter,
ReturnGroupItem: true,
ExcludeTables: []int{0},
})
if err != nil {
batchError.Add(err)
mResp, err := l.getTableByLocal([]string{bytelib.CalculateItem})
if err == nil {
result["计算项"] = mResp
} else {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.CalculateItem},
Module: bytelib.ModuleCalculateCenter,
ReturnGroupItem: true,
ExcludeTables: []int{0},
})
if err != nil {
batchError.Add(err)
}
result["计算项"] = newList(list)
}
result["计算项"] = newList(list)
}, func() {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.CalculateSet},
Module: bytelib.ModuleCalculateCenter,
ReturnGroupItem: true,
ExcludeTables: []int{0},
})
if err != nil {
batchError.Add(err)
mResp, err := l.getTableByLocal([]string{bytelib.CalculateSet})
if err == nil {
result["计算集"] = mResp
} else {
list, err := l.svcCtx.ByteMetadataService.ObjectTableSearch(l.ctx, bytelib.ObjectTableSearchRequest{
Token: req.Token,
TableTypes: []string{bytelib.CalculateSet},
Module: bytelib.ModuleCalculateCenter,
ReturnGroupItem: true,
ExcludeTables: []int{0},
})
if err != nil {
batchError.Add(err)
}
result["计算集"] = newList(list)
}
result["计算集"] = newList(list)
})
if err = batchError.Err(); err != nil {
logx.Error(err)
... ... @@ -88,3 +109,30 @@ func newList(r bytelib.ObjectTableSearchResponse) interface{} {
"list": r.List,
}
}
func (l *SearchTableByModuleLogic) getTableByLocal(modules []string) (types.SearchTableByModuleResponse, error) {
tenantId := contextdata.GetTenantFromCtx(l.ctx)
response := types.SearchTableByModuleResponse{
Count: 0,
List: make([]types.SearchTableByModuleItem, 0),
}
total, list, err := l.svcCtx.ObjectTableRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), map[string]interface{}{
"companyId": tenantId,
"tableType": modules,
})
if err != nil {
return response, err
}
response.Count = int(total)
for _, item := range list {
response.List = append(response.List, types.SearchTableByModuleItem{
Id: item.Id,
TableId: item.TableId,
TableType: item.TableType,
Name: item.Name,
ParentId: item.ParentId,
Flag: item.Flag,
})
}
return response, nil
}
... ...
... ... @@ -2,6 +2,8 @@ package table
import (
"context"
"github.com/jinzhu/copier"
"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"
... ... @@ -32,9 +34,55 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
"fields": nil,
"total": 0,
"data": make([]string, 0),
"local": false,
}
return
}
resp, err = l.getLocal(req)
if err == nil {
return resp, nil
}
return l.getRemote(req)
}
// getLocal 获取本地数据
func (l *SearchTableDataLogic) getLocal(req *types.SearchTableDataRequest) (interface{}, error) {
conn := l.svcCtx.DefaultDBConn()
conditions := make([]*domain.TableDataCondition, 0)
_ = copier.Copy(&conditions, req.Condition)
//查询表数据
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("表字段不存在")
}
//表数据
total, list, err := l.svcCtx.ObjectTableDataRepository.Find(l.ctx, conn, req.ObjectId, &domain.ObjectTableDataQuery{
Page: req.PageNumber,
Size: req.PageSize,
Conditions: conditions,
})
if err != nil {
return nil, xerr.NewErrMsg("查询表数据失败")
}
return map[string]interface{}{
"objectId": req.ObjectId,
"fields": removeIdField(objectField.Fields),
"total": total,
"data": list,
"local": true,
}, nil
}
// getRemote 获取远程字库数据
func (l *SearchTableDataLogic) getRemote(req *types.SearchTableDataRequest) (resp interface{}, err error) {
tableDataPreviewRequest := &bytelib.TableDataPreviewRequest{
Token: req.Token,
ObjectType: bytelib.ObjectMetaTable,
... ... @@ -53,6 +101,7 @@ func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest
"fields": removeIdField(response.Fields),
"total": response.Grid.Total,
"data": response.Grid.List,
"local": false,
}
return
}
... ...
... ... @@ -24,6 +24,7 @@ type ServiceContext struct {
AppPageRepository domain.AppPageRepository
ObjectNoticeRepository domain.ObjectNoticeRepository
ObjectTableRepository domain.ObjectTableRepository
ObjectFieldRepository domain.ObjectFieldRepository
ObjectTableDataRepository domain.ObjectTableDataRepository
ByteMetadataService bytelib.ByteMetadataService
... ... @@ -45,6 +46,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
AppPageRepository: repository.NewAppPageRepository(cache.NewCachedRepository(mlCache)),
ObjectNoticeRepository: repository.NewObjectNoticeRepository(cache.NewCachedRepository(mlCache)),
ObjectTableRepository: repository.NewObjectTableRepository(cache.NewCachedRepository(mlCache)),
ObjectFieldRepository: repository.NewObjectFieldRepository(cache.NewCachedRepository(mlCache)),
ObjectTableDataRepository: repository.NewObjectTableDataRepository(),
ByteMetadataService: bytelib.ByteMetadataService{
... ...
... ... @@ -189,6 +189,18 @@ type SearchTableByModuleRequest struct {
}
type SearchTableByModuleResponse struct {
Count int `json:"count"`
List []SearchTableByModuleItem `json:"list"`
}
type SearchTableByModuleItem struct {
Id int `json:"id"` //ID
TableId int `json:"tableId"` //表ID
Name string `json:"name"` //表名
TableType string `json:"tableType"` //表类型
ParentId int `json:"parentId"` //父级ID
Flag string `json:"flag"` //分组:Group 集合:Set
IsLocal bool `json:"isLocal"` //是否本地存储
}
type SearchTableFieldOptionalValuesRequest struct {
... ...
... ... @@ -12,5 +12,6 @@ func Migrate(db *gorm.DB) {
&models.AppPage{},
&models.ObjectNotice{},
&models.ObjectTable{},
&models.ObjectField{},
)
}
... ...
... ... @@ -12,7 +12,7 @@ import (
type ObjectField struct {
Id int64 `json:"id" gorm:"primaryKey"` // ID
Name string `json:"name"` //表名
Fields []*bytelib.Field `json:"fields"` //表字段
Fields []*bytelib.Field `json:"fields" gorm:"serializer:json"` //表字段
Version int `json:",omitempty"` //版本
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
CreatedAt int64 `json:",omitempty"` //创建时间
... ...
... ... @@ -3,7 +3,6 @@ package models
import (
"fmt"
"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"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
"time"
... ... @@ -18,7 +17,7 @@ type ObjectTable struct {
ParentId int `json:"parentId" gorm:"default:0"` //父id
Flag string `json:"flag"` //分组:Group 集合:Set
Version int `json:",omitempty"` //版本
Fields []*bytelib.Field `json:"fields" gorm:"serializer:json"` //表字段
IsLocal bool `json:"isLocal" gorm:"default:false"` //是否有本地存储
RemoteDeleted int `json:"remoteDeleted"` //远端删除
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` //删除标记
CreatedAt int64 `json:",omitempty"` //创建时间
... ...
... ... @@ -120,9 +120,28 @@ func (repository *ObjectTableDataRepository) InsertWithTableData(ctx context.Con
return nil
}
// FindAll 获取表内所有数据
func (repository *ObjectTableDataRepository) FindAll(ctx context.Context, conn transaction.Conn, tableId int) {
// Find 获取表内所有数据
func (repository *ObjectTableDataRepository) Find(ctx context.Context, conn transaction.Conn, tableId int, query *domain.ObjectTableDataQuery) (int64, []map[string]interface{}, error) {
tx := conn.DB().Table(fmt.Sprintf("data.%v", tableId))
if len(query.Conditions) > 0 {
for _, item := range query.Conditions {
if item.FieldName == "" {
continue
}
if item.Like != "" {
tx = tx.Where(item.FieldName+" like ?", item.Like)
}
if len(item.In) > 0 {
tx = tx.Where(item.FieldName+" in ?", item.In)
}
if item.Order != "" {
tx = tx.Order(item.FieldName + " " + item.Order)
}
}
}
list := make([]map[string]interface{}, 0)
total, tx := transaction.PaginationAndCount(ctx, tx, domain.NewQueryOptions().WithOffsetLimit(query.Page, query.Size), &list)
return total, list, tx.Error
}
func NewObjectTableDataRepository() domain.ObjectTableDataRepository {
... ...
... ... @@ -113,19 +113,12 @@ func (repository *ObjectTableRepository) FindOne(ctx context.Context, conn trans
func (repository *ObjectTableRepository) FindOneByTableId(ctx context.Context, conn transaction.Conn, tableId int) (*domain.ObjectTable, error) {
var (
err error
tx = conn.DB()
m = new(models.ObjectTable)
tx = conn.DB()
m = new(models.ObjectTable)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("table_id = ?", tableId).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
if _, err = repository.Query(queryFunc); err != nil {
return nil, err
tx = tx.Model(m).Where("table_id = ?", tableId).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return repository.ModelToDomainModel(m)
}
... ... @@ -139,6 +132,12 @@ func (repository *ObjectTableRepository) Find(ctx context.Context, conn transact
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["companyId"]; ok {
tx = tx.Where("company_id = ?", v)
}
if v, ok := queryOptions["tableTypeIn"]; ok {
tx = tx.Where("table_type in ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -8,20 +8,20 @@ import (
)
type ObjectTable struct {
Id int `json:"id"` // ID
TableId int `json:"tableId" ` //表ID
Name string `json:"name"` //表名
TableType string `json:"tableType" ` //模块
CompanyId int64 `json:"companyId"` //公司id
ParentId int `json:"parentId"` //父id
Flag string `json:"flag"` //分组:Group 集合:Set
Fields []*bytelib.Field `json:"fields" gorm:"serializer:json"` //表字段
Version int `json:"version,omitempty"` //版本
RemoteDeleted int `json:"remoteDeleted"` //远端删除
IsDel soft_delete.DeletedAt `json:"isDel,omitempty"` //删除标记
CreatedAt int64 `json:"createdAt,omitempty"` //创建时间
UpdatedAt int64 `json:"updatedAt,omitempty"` //更新时间
DeletedAt int64 `json:"deletedAt,omitempty"` //删除时间
Id int `json:"id"` // ID
TableId int `json:"tableId" ` //表ID
Name string `json:"name"` //表名
TableType string `json:"tableType" ` //模块
CompanyId int64 `json:"companyId"` //公司id
ParentId int `json:"parentId"` //父id
Flag string `json:"flag"` //分组:Group 集合:Set
Version int `json:"version,omitempty"` //版本
IsLocal bool `json:"isLocal"` //是否有本地存储
RemoteDeleted int `json:"remoteDeleted"` //远端删除
IsDel soft_delete.DeletedAt `json:"isDel,omitempty"` //删除标记
CreatedAt int64 `json:"createdAt,omitempty"` //创建时间
UpdatedAt int64 `json:"updatedAt,omitempty"` //更新时间
DeletedAt int64 `json:"deletedAt,omitempty"` //删除时间
}
type ObjectTableRepository interface {
... ... @@ -34,8 +34,22 @@ type ObjectTableRepository interface {
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ObjectTable, error)
}
type ObjectTableDataQuery struct {
Page int
Size int
Conditions []*TableDataCondition
}
type TableDataCondition struct {
FieldName string `json:"field"` // 条件字段
Like string `json:"like"` // 模糊匹配
In []string `json:"in"` // 匹配多个值
Order string `json:"order"` // 排序 ASC DESC 默认ASC
}
type ObjectTableDataRepository interface {
InsertWithTableData(ctx context.Context, conn transaction.Conn, tableDataPreview bytelib.TableData) error
Find(ctx context.Context, conn transaction.Conn, tableId int, query *ObjectTableDataQuery) (int64, []map[string]interface{}, error)
}
func (m *ObjectTable) Identify() interface{} {
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: table
//jwt: JwtAuth
//middleware: Authority
prefix: v1
group: table
//jwt: JwtAuth
//middleware: Authority
)
service Core {
@doc "源数据表-字段可选值"
@handler searchTableFieldOptionalValues
post /table/field-optional-values (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 getTableDetail
get /table/:tableId (GetTableDetailRequest) returns (GetTableDetailResponse)
@doc "源数据表-数据"
@handler searchTableData
post /table/data (SearchTableDataRequest) returns (SearchTableDataResponse)
@doc "源数据表-数据"
@handler searchTableData
post /table/data (SearchTableDataRequest) returns (SearchTableDataResponse)
}
@server(
prefix: v1
group: table
jwt: JwtAuth
//middleware: Authority
prefix: v1
group: table
jwt: JwtAuth
//middleware: Authority
)
service Core {
@doc "源数据表-按模块搜索"
@handler searchTableByModule
post /table/search-by-module (SearchTableByModuleRequest) returns (SearchTableByModuleResponse)
@doc "源数据表-按模块搜索"
@handler searchTableByModule
post /table/search-by-module (SearchTableByModuleRequest) returns (SearchTableByModuleResponse)
}
type (
SearchTableByModuleRequest struct{
Token string `header:"x-mmm-accesstoken,optional"`
}
SearchTableByModuleResponse struct{
SearchTableByModuleRequest {
Token string `header:"x-mmm-accesstoken,optional"`
}
SearchTableByModuleResponse {
Count int `json:"count"`
List []SearchTableByModuleItem `json:"list"`
}
SearchTableByModuleItem {
Id int `json:"id"` //ID
TableId int `json:"tableId"` //表ID
Name string `json:"name"` //表名
TableType string `json:"tableType"` //表类型
ParentId int `json:"parentId"` //父级ID
Flag string `json:"flag"` //分组:Group 集合:Set
IsLocal bool `json:"isLocal"` //是否本地存储
}
}
SearchTableFieldOptionalValuesRequest {
Token string `header:"x-mmm-accesstoken,optional"`
ObjectId int `json:"objectId"` // 对象ID
Field string `json:"field"` // 当前选择的字段
//SqlName string `json:"sqlName,optional"` // 字段SqlName
// Match string `json:"match"`
//PageNumber int `json:"pageNumber,optional"` // 分页数
//PageSize int `json:"pageSize,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
}
SearchTableFieldOptionalValuesResponse {
Values []string `json:"values"`
Total int64 `json:"total"`
}
Condition {
FieldName string `json:"field"` // 条件字段
//SqlName string `json:"sqlName,optional"` // 字段SqlName
Like string `json:"like,optional"` // 模糊匹配
In []string `json:"in,optional"` // 匹配多个值
Order string `json:"order,optional,options=ASC||DESC"` // 排序 ASC DESC 默认ASC
}
SearchTableFieldOptionalValuesRequest struct{
Token string `header:"x-mmm-accesstoken,optional"`
ObjectId int `json:"objectId"` // 对象ID
Field string `json:"field"` // 当前选择的字段
//SqlName string `json:"sqlName,optional"` // 字段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,optional"` // 字段SqlName
Like string `json:"like,optional"` // 模糊匹配
In []string `json:"in,optional"` // 匹配多个值
Order string `json:"order,optional,options=ASC||DESC"` // 排序 ASC DESC 默认ASC
}
GetTableDetailRequest {
Token string `header:"x-mmm-accesstoken,optional"`
TableId int `path:"tableId"` // 表ID
}
GetTableDetailResponse {
}
GetTableDetailRequest struct {
Token string `header:"x-mmm-accesstoken,optional"`
TableId int `path:"tableId"` // 表ID
}
GetTableDetailResponse struct{
}
SearchTableDataRequest struct{
Token string `header:"x-mmm-accesstoken,optional"`
ObjectId int `json:"objectId,optional"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
}
SearchTableDataResponse struct{
}
SearchTableDataRequest {
Token string `header:"x-mmm-accesstoken,optional"`
ObjectId int `json:"objectId,optional"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
}
SearchTableDataResponse {
}
)
\ No newline at end of file
... ...