convert.go 2.1 KB
package bytelib

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

func DomainFieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
	result := make([]domain.ColumnSchema, 0)
	for _, f := range fields {
		res := domain.ColumnSchema{
			ColumnName:            f.Name,
			ColumnType:            f.SQLType,
			ColumnSqlFriendlyName: f.SQLName,
		}
		if convertFiledSQLType(f.SQLType) {
			res.ColumnType = domain.DECIMAL279.ToString()
		}
		result = append(result, res)
	}
	return result
}

func ToFieldSchemas(fields []*domain.Field) []FieldSchema {
	result := make([]FieldSchema, 0)
	for _, f := range fields {
		res := FieldSchema{
			FieldZhName:      f.Name,
			FieldEnName:      f.SQLName,
			FieldType:        f.SQLType,
			FieldDescription: f.Description,
			IsAllowNull:      true,
		}
		if convertFiledSQLType(f.SQLType) {
			res.FieldType = domain.DECIMAL279.ToString()
		}
		result = append(result, res)
	}
	return result
}

func NewFieldSchema(f domain.TableField) FieldSchema {
	var res = FieldSchema{
		FieldZhName:      f.FieldName,
		FieldEnName:      f.FieldSqlName,
		FieldType:        f.FieldSQLType,
		FieldDescription: "",
		IsAllowNull:      true,
	}
	if convertFiledSQLType(f.FieldSQLType) {
		res.FieldType = domain.DECIMAL279.ToString()
	}
	return res
}

func NewFieldSchemaFromField(f *domain.Field) FieldSchema {
	var res = FieldSchema{
		FieldZhName:      f.Name,
		FieldEnName:      f.SQLName,
		FieldType:        f.SQLType,
		FieldDescription: "",
		IsAllowNull:      true,
	}
	if convertFiledSQLType(f.SQLType) {
		res.FieldType = domain.DECIMAL279.ToString()
	}
	return res
}

func convertFiledSQLType(sqlType string) bool {
	if sqlType == domain.Float.ToString() || sqlType == domain.DECIMAL279.ToString() {
		return true
	}
	return false
}

func FieldsToColumnSchemas(fields []*domain.Field) []domain.ColumnSchema {
	result := make([]domain.ColumnSchema, 0)

	for _, f := range fields {
		result = append(result, domain.ColumnSchema{
			ColumnName:            f.Name,
			ColumnType:            f.SQLType,
			ColumnSqlFriendlyName: f.SQLName,
		})
	}
	return result
}