bytelib.go 2.8 KB
package bytecore

import "gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"

type ByteLibService interface {
	LoadDataTable(param ReqLoadDataTable) (*DataLoadDataTable, error)
	EditTable(param ReqEditDataTable) (*DataEditDataTable, error)
	SaveTable(param ReqSaveTable) (*DataSaveTable, error)
	GenerateTable(param ReqGenerateTable) (*DataGenerateTable, error)
	CopyTable(param ReqCopyTable) (*DataCopyTable, error)
	AppendData(param ReqAppendData) (*DataAppendData, error)
	DeleteTable(param ReqDeleteTable) (*DataDeleteTable, error)
	CancelFile(param ReqCancelFile) (*DataCancelFile, error)
	EditTableData(param ReqEditTableData) (*DataEditTableData, error)
}

type (
	ReqLoadDataTable struct {
		FileId   int
		FileName string
		Url      string
		Ext      string
		domain.Where
	}

	DataLoadDataTable struct {
		FileId       int           `json:"objectId"`
		ObjectType   string        `json:"objectType"`
		TableType    string        `json:"tableType"`
		Fields       []*Field      `json:"fields"`
		Data         [][]string    `json:"data"`
		Total        int           `json:"total"`
		PageNumber   int           `json:"pageNumber"`
		InValidCells []InValidCell `json:"inValidCells"`
	}

	Field struct {
		// 索引序号
		Index int `json:"index"`
		// 名称
		Name string `json:"name"`
		// 对应数据库类型
		Type string `json:"sqlType"`
	}

	InValidCell struct {
		X     int    `json:"x"`
		Y     int    `json:"y"`
		Error string `json:"error"`
	}
)

// https://github.com/go-gota/gota 类似pandas的数据处理包
// https://github.com/gonum/gonum

func (table DataLoadDataTable) Filter(where domain.Where) *DataLoadDataTable {
	begin := (where.PageNumber - 1) * where.PageSize
	if begin < 0 {
		begin = 0
	}
	end := begin + where.PageSize
	data := make([][]string, 0)
	if begin < table.Total {
		if end < table.Total {
			data = table.Data[begin:end]
		} else {
			data = table.Data[begin:]
		}
	}
	return &DataLoadDataTable{
		FileId:       table.FileId,
		Fields:       table.Fields,
		Data:         data,
		Total:        table.Total,
		PageNumber:   where.PageNumber,
		InValidCells: make([]InValidCell, 0),
	}
}

type (
	ReqEditDataTable struct {
		FileId   int
		FileName string
		Url      string
		Ext      string
		Fields   []*Field
		Action   string
		Params   []interface{}
	}

	DataEditDataTable struct {
		DataLoadDataTable
	}
)

type (
	ReqSaveTable struct {
	}

	DataSaveTable struct {
		Url string `json:"url"`
	}
)

type (
	ReqGenerateTable struct {
	}

	DataGenerateTable struct {
	}
)

type (
	ReqCopyTable struct {
	}

	DataCopyTable struct {
	}
)

type (
	ReqAppendData struct {
	}

	DataAppendData struct {
	}
)

type (
	ReqDeleteTable struct {
	}

	DataDeleteTable struct {
	}
)

type (
	ReqCancelFile struct {
	}

	DataCancelFile struct {
	}
)

type (
	ReqEditTableData struct {
	}

	DataEditTableData struct {
	}
)