file_dto.go 2.2 KB
package dto

import (
	"github.com/linmadan/egglib-go/utils/xtime"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
)

type FileDto struct {
	// 文件ID
	FileId int `json:"fileId"`
	// 名称
	Name string `json:"name"`
	// 文件地址
	Url string `json:"url"`
	// 文件类型
	FileType string `json:"fileType"`
	// 后缀扩展
	Ext string `json:"ext"`
	// 创建时间
	Time string `json:"time"`
	// 行号
	HeaderRow int `json:"headerRow"`
	// 所属应用
	AppKey string `json:"appKey"`
	// 表ID
	TableId int `json:"tableId"`
	// 允许表生成标识 1:允许生成分表 0:不允许
	AllowTableGenerateFlag int `json:"-"`
	// 允许表处理标识 1:允许 0:不允许
	AllowTableProcessFlag int `json:"-"`
	// 允许表导出标识 1:允许 0:不允许
	AllowTableExportFlag int `json:"-"`
	// 标志位 1:可校验 2:可分表生成 4:导出
	Flag int `json:"-"`
	// 标志位 1:可校验 2:可分表生成 4:导出
	Flags []int `json:"flags"`
}

func (d *FileDto) Load(f *domain.File) *FileDto {
	if f == nil {
		return nil
	}
	d.FileId = f.FileId
	d.Name = f.FileInfo.Name
	d.Url = f.FileInfo.Url
	d.FileType = f.FileType
	d.Ext = f.FileInfo.Ext
	d.Time = xtime.New(f.UpdatedAt).Local().Format("2006-01-02 15:04:05")
	d.HeaderRow = domain.GetHeaderRow(f.FileInfo.HeaderRow)
	d.AppKey = f.AppKey
	//d.AllowTableProcessFlag = 1
	//d.AllowTableExportFlag = 1
	d.AddFlag(5) // 默认可以 校验、导出
	if len(f.AppKey) > 0 && f.FileInfo.TableId > 0 {
		d.TableId = f.FileInfo.TableId
		//d.AllowTableGenerateFlag = 1
		d.AddFlag(2)    // 可分表生成
		d.RemoveFlag(1) // 不可校验
		//d.RemoveFlag(4) // 不可校验
		//d.AllowTableProcessFlag = 0
		//d.AllowTableExportFlag = 0
	}
	for i := 1; i <= 4; i = i << 1 {
		if i&d.Flag == i {
			d.Flags = append(d.Flags, i)
		}
	}
	return d
}

func (d *FileDto) AddFlag(flag int) {
	if d.Flag&flag == flag {
		return
	}
	d.Flag |= flag
}

func (d *FileDto) RemoveFlag(flag int) {
	if d.Flag&flag != flag {
		return
	}
	d.Flag ^= flag
}

type AppDto struct {
	AppId   int64      `json:"appId"`
	AppKey  string     `json:"appKey"`
	AppName string     `json:"appName"`
	Files   []*FileDto `json:"files"`
}