...
|
...
|
@@ -2,16 +2,18 @@ package domainService |
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"sort"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/collection"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/repository"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/starrocks"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/log"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
const DefaultExpandNum = 10000
|
|
|
const MaxExpandNum = 50000
|
|
|
const DefaultExpandNum = 1000
|
|
|
const MaxExpandNum = 5000
|
|
|
|
|
|
func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain.QuerySet, queryComponents []*domain.QueryComponent) (*domain.DataTable, error) {
|
|
|
var (
|
...
|
...
|
@@ -26,7 +28,13 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain |
|
|
// 加载Tables数据
|
|
|
q := queryComponents[0]
|
|
|
cells := q.Layout.LayoutCells()
|
|
|
dataTables = ptr.LoadDataTables(ctx, cells)
|
|
|
if len(cells) == 0 {
|
|
|
return res, nil
|
|
|
}
|
|
|
dataTables, err = ptr.LoadDataTables(ctx, cells)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 设置数据
|
|
|
dt := &DataLayoutDataTable{
|
|
|
DataTable: res,
|
...
|
...
|
@@ -38,10 +46,10 @@ func (ptr *QuerySetService) LoadCalculateSetData(ctx *domain.Context, qs *domain |
|
|
cells[i].Length = length
|
|
|
cells[i].BlockData = blockData
|
|
|
}
|
|
|
// 根据数据修改便宜
|
|
|
// 根据数据修改偏移
|
|
|
CellsLocationAdjust(cells)
|
|
|
// 数据布局
|
|
|
res, err = DataLayout(res, dataTables, cells)
|
|
|
res, err = DataLayout(res, cells)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -60,18 +68,6 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { |
|
|
yMin = cells[0].Y
|
|
|
yMax = cells[0].Y
|
|
|
}
|
|
|
min := func(a, b int) int {
|
|
|
if a > b {
|
|
|
return b
|
|
|
}
|
|
|
return a
|
|
|
}
|
|
|
max := func(a, b int) int {
|
|
|
if a < b {
|
|
|
return b
|
|
|
}
|
|
|
return a
|
|
|
}
|
|
|
for i := 1; i <= len(cells)-1; i++ {
|
|
|
cell := cells[i]
|
|
|
xMin = min(xMin, cell.X)
|
...
|
...
|
@@ -111,7 +107,7 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { |
|
|
}
|
|
|
//move = cell.Length
|
|
|
//c = cell
|
|
|
if max(move, cell.Length) != move {
|
|
|
if max(move, cell.Length) != move && c == nil {
|
|
|
c = cell
|
|
|
}
|
|
|
move = max(move, cell.Length)
|
...
|
...
|
@@ -121,6 +117,61 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
func CellsLocationAdjustV1(cells []*domain.LayoutCell) {
|
|
|
yList := cellsRange(cells, "y")
|
|
|
xList := cellsRange(cells, "x")
|
|
|
for i := 0; i < len(yList); i++ {
|
|
|
j := yList[i]
|
|
|
move := 0
|
|
|
var c *domain.LayoutCell
|
|
|
for _, cell := range cells {
|
|
|
if cell.Y != j {
|
|
|
continue
|
|
|
}
|
|
|
if cell.Direction != domain.DirectionRight {
|
|
|
continue
|
|
|
}
|
|
|
if max(move, cell.Length) != move {
|
|
|
c = cell
|
|
|
}
|
|
|
move = max(move, cell.Length)
|
|
|
}
|
|
|
ChangeLocation(cells, domain.DirectionRight, j, move, c)
|
|
|
}
|
|
|
for j := 0; j < len(xList); j++ {
|
|
|
i := xList[j]
|
|
|
move := 0
|
|
|
var c *domain.LayoutCell
|
|
|
for _, cell := range cells {
|
|
|
if cell.X != i {
|
|
|
continue
|
|
|
}
|
|
|
if cell.Direction != domain.DirectionDown {
|
|
|
continue
|
|
|
}
|
|
|
if max(move, cell.Length) != move && c == nil {
|
|
|
c = cell
|
|
|
}
|
|
|
move = max(move, cell.Length)
|
|
|
}
|
|
|
ChangeLocation(cells, domain.DirectionDown, i, move, c)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func cellsRange(cells []*domain.LayoutCell, direction string) []int {
|
|
|
list := collection.NewSet()
|
|
|
for i := range cells {
|
|
|
if strings.ToLower(direction) == "x" {
|
|
|
list.Add(cells[i].X)
|
|
|
} else {
|
|
|
list.Add(cells[i].Y)
|
|
|
}
|
|
|
}
|
|
|
sortList := list.KeysInt()
|
|
|
sort.Ints(sortList)
|
|
|
return sortList
|
|
|
}
|
|
|
|
|
|
func ChangeLocation(cells []*domain.LayoutCell, direction string, position, move int, c *domain.LayoutCell) {
|
|
|
// log.Logger.Info("修改定位点")
|
|
|
if move == 0 {
|
...
|
...
|
@@ -148,6 +199,8 @@ func FastTable(table *domain.Table) (*domain.DataTable, error) { |
|
|
TableName: table.SQLName,
|
|
|
Select: table.Fields(false),
|
|
|
}
|
|
|
options.SetDefaultOrder()
|
|
|
options.SetOffsetLimit(1, 10000)
|
|
|
var dataTable *domain.DataTable
|
|
|
dataTable, err = FastDataTable(options)
|
|
|
if err != nil {
|
...
|
...
|
@@ -164,7 +217,6 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) { |
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
dataTable.Total, err = starrocks.WrapQueryCountWithDB(options, starrocks.DB)()
|
|
|
if err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -172,7 +224,7 @@ func FastDataTable(options starrocks.QueryOptions) (*domain.DataTable, error) { |
|
|
return dataTable, nil
|
|
|
}
|
|
|
|
|
|
func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.LayoutCell) map[int]*domain.DataTable {
|
|
|
func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain.LayoutCell) (map[int]*domain.DataTable, error) {
|
|
|
var (
|
|
|
dataTables = make(map[int]*domain.DataTable)
|
|
|
tableRepository, _ = repository.NewTableRepository(ptr.transactionContext)
|
...
|
...
|
@@ -187,28 +239,27 @@ func (ptr *QuerySetService) LoadDataTables(ctx *domain.Context, cells []*domain. |
|
|
if len(tableIds.KeysInt()) > 0 {
|
|
|
_, tables, err := tableRepository.Find(map[string]interface{}{"context": ctx, "tableIds": tableIds.KeysInt()})
|
|
|
if err != nil {
|
|
|
return nil
|
|
|
return nil, err
|
|
|
}
|
|
|
for _, t := range tables {
|
|
|
if _, ok := dataTables[t.TableId]; ok {
|
|
|
continue
|
|
|
}
|
|
|
dataTable, e := FastTable(t)
|
|
|
if e != nil {
|
|
|
log.Logger.Error(e.Error())
|
|
|
continue
|
|
|
dataTable, err := FastTable(t)
|
|
|
if err != nil {
|
|
|
log.Logger.Error(err.Error())
|
|
|
return nil, fmt.Errorf("获取【%s】出现异常:%s", t.Name, err.Error())
|
|
|
}
|
|
|
dataTable.Fields = t.DataFields
|
|
|
dataTables[t.TableId] = dataTable
|
|
|
}
|
|
|
}
|
|
|
return dataTables
|
|
|
return dataTables, nil
|
|
|
}
|
|
|
|
|
|
func DataLayout(res *domain.DataTable, dataTables map[int]*domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) {
|
|
|
func DataLayout(res *domain.DataTable, cells []*domain.LayoutCell) (*domain.DataTable, error) {
|
|
|
dt := &DataLayoutDataTable{
|
|
|
DataTable: res,
|
|
|
//MapDataTables: dataTables,
|
|
|
unprocessed: cells,
|
|
|
}
|
|
|
dt.Init(DefaultExpandNum)
|
...
|
...
|
@@ -218,14 +269,6 @@ func DataLayout(res *domain.DataTable, dataTables map[int]*domain.DataTable, cel |
|
|
}
|
|
|
cell := dt.unprocessed[0]
|
|
|
dt.unprocessed = dt.unprocessed[1:]
|
|
|
//blockData, length := dt.BlockData(cell)
|
|
|
//if err := dt.Expand(cell, length); err != nil {
|
|
|
// return nil, err
|
|
|
//}
|
|
|
//dt.addByLocation(cell, blockData)
|
|
|
//blockData, length := dt.BlockData(cell)
|
|
|
// 当前单元格子 影响其他格子坐标
|
|
|
//dt.changeUnProcessedLocation(cell, cell.Length)
|
|
|
if err := dt.Expand(cell, cell.Length); err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -273,8 +316,13 @@ func (l *Location) UpdateY(y int) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
func (d *DataLayoutDataTable) StartCell() {
|
|
|
|
|
|
func (l *Location) Update(x int, y int, compare func(int, int) int) {
|
|
|
if x != 0 {
|
|
|
l.X = compare(l.X, x)
|
|
|
}
|
|
|
if y != 0 {
|
|
|
l.Y = compare(l.Y, y)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData []string) {
|
...
|
...
|
@@ -287,23 +335,19 @@ func (d *DataLayoutDataTable) addByLocation(cell *domain.LayoutCell, blockData [ |
|
|
for i := range blockData {
|
|
|
d.DataTable.Data[cell.X][cell.Y+i] = blockData[i]
|
|
|
}
|
|
|
d.PointEnd.UpdateX(cell.X)
|
|
|
d.PointEnd.UpdateY(cell.Y + len(blockData) - 1)
|
|
|
d.PointEnd.Update(cell.X, cell.Y+len(blockData)-1, max)
|
|
|
case domain.DirectionDown:
|
|
|
for i := range blockData {
|
|
|
d.DataTable.Data[cell.X+i][cell.Y] = blockData[i]
|
|
|
}
|
|
|
d.PointEnd.UpdateX(cell.X + len(blockData) - 1)
|
|
|
d.PointEnd.UpdateY(cell.Y)
|
|
|
d.PointEnd.Update(cell.X+len(blockData)-1, cell.Y, max)
|
|
|
case domain.DirectionNone:
|
|
|
d.DataTable.Data[cell.X][cell.Y] = blockData[0]
|
|
|
d.PointEnd.UpdateX(cell.X)
|
|
|
d.PointEnd.UpdateY(cell.Y)
|
|
|
d.PointEnd.Update(cell.X, cell.Y, max)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutCell, length int) {
|
|
|
// log.Logger.Info("修改定位点")
|
|
|
for _, cell := range d.unprocessed {
|
|
|
switch lastCell.Direction {
|
|
|
case domain.DirectionRight:
|
...
|
...
|
@@ -315,7 +359,6 @@ func (d *DataLayoutDataTable) changeUnProcessedLocation(lastCell *domain.LayoutC |
|
|
cell.X += length - 1
|
|
|
}
|
|
|
}
|
|
|
// log.Logger.Info(fmt.Sprintf("%s %s X:%d Y:%d", cell.Data.Field.SQLName, cell.Direction, cell.X, cell.Y))
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -329,7 +372,7 @@ func (d *DataLayoutDataTable) BlockData(cells *domain.LayoutCell) ([]string, int |
|
|
if !ok {
|
|
|
return block, 0
|
|
|
}
|
|
|
values := table.Values(&domain.Field{SQLName: cells.Data.TableField.FieldSqlName})
|
|
|
values := table.Values(&domain.Field{SQLName: cells.Data.TableField.FieldSqlName, SQLType: cells.Data.TableField.FieldSQLType})
|
|
|
if len(values) == 0 {
|
|
|
return block, 0
|
|
|
}
|
...
|
...
|
@@ -411,3 +454,16 @@ func (d *DataLayoutDataTable) CellOutRange(cell *domain.LayoutCell, length int) |
|
|
}
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
func min(a, b int) int {
|
|
|
if a > b {
|
|
|
return b
|
|
|
}
|
|
|
return a
|
|
|
}
|
|
|
func max(a, b int) int {
|
|
|
if a < b {
|
|
|
return b
|
|
|
}
|
|
|
return a
|
|
|
} |
...
|
...
|
|