table_preview_dto.go 1.3 KB
package dto

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

type TablePreviewDto struct {
	// 表Id
	TableId int `json:"objectId"`
	// 表Id
	ObjectType string `json:"objectType"`
	// 表类型 MainTable:主表 SideTable:副表 SubTable:分表  ExcelTable:Excel表
	TableType string `json:"tableType"`
	// 名称
	Name string `json:"name"`
	// 数据
	//*domain.DataTable
	Fields []*domain.Field `json:"fields"`
	Data   interface{}     `json:"grid"`
	//Total  int64               `json:"total"`
}

func (d *TablePreviewDto) Load(m *domain.Table, dataTable *domain.DataTable, objectType string) *TablePreviewDto {
	d.TableId = m.TableId
	d.TableType = m.TableType
	d.ObjectType = objectType
	d.Name = m.Name
	d.Fields = dataTable.MatchFields(m.Fields(true))
	d.Data = domain.GripData(domain.ToFieldData(m.Fields(true), dataTable.Data, false), dataTable.Total)
	//d.Total = dataTable.Total
	return d
}

func ToFieldDataByPK(m *domain.Table, dataTable *domain.DataTable) map[string]map[string]string {
	var dataListByPk = make(map[string]map[string]string)
	for _, item := range domain.ToFieldData(m.Fields(true), dataTable.Data, false) {
		if v, ok := item[domain.DefaultPkField]; ok {
			dataListByPk[v] = item
		}
	}
	return dataListByPk
}