object_table.go 3.0 KB
package domain

import (
	"context"
	"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/gateway/bytelib"
	"gorm.io/plugin/soft_delete"
)

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
	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 {
	Insert(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
	Update(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
	UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
	Delete(ctx context.Context, conn transaction.Conn, dm *ObjectTable) (*ObjectTable, error)
	FindOne(ctx context.Context, conn transaction.Conn, id int, tableType string) (*ObjectTable, error)
	FindOneByTableId(ctx context.Context, conn transaction.Conn, tableId int) (*ObjectTable, error)
	Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ObjectTable, error)
	DeleteGroup(ctx context.Context, conn transaction.Conn, companyId int64, parentId int) error
}

type ObjectTableDataQuery struct {
	Page       int
	Size       int
	Conditions []*TableDataCondition
	Group      string
	Select     string
}

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)
	DropTable(ctx context.Context, conn transaction.Conn, tableId int) error
}

func (m *ObjectTable) Identify() interface{} {
	if m.Id == 0 {
		return nil
	}
	return m.Id
}