package domain // ===================交易商業邏輯種類=================== type BusinessName string const ( // NoBusinessName 非商業邏輯 NoBusinessName BusinessName = "" // OrderBusinessTypeBusinessName order業務邏輯 OrderBusinessTypeBusinessName BusinessName = "order" // SystemTransferBusinessTypeBusinessName 系統劃轉 SystemTransferBusinessTypeBusinessName BusinessName = "system_transfer" ) const ( // NoBusinessType 非商業邏輯 NoBusinessType int8 = iota // OrderBusinessTypeBusinessType order 業務邏輯 OrderBusinessTypeBusinessType // SystemTransferBusinessTypeBusinessType 系統劃轉 SystemTransferBusinessTypeBusinessType ) // 定義兩個map用於名稱和類型的相互映射 var nameToBusinessType = map[BusinessName]int8{ OrderBusinessTypeBusinessName: OrderBusinessTypeBusinessType, SystemTransferBusinessTypeBusinessName: SystemTransferBusinessTypeBusinessType, } var businessTypeToName = map[int8]BusinessName{ OrderBusinessTypeBusinessType: OrderBusinessTypeBusinessName, SystemTransferBusinessTypeBusinessType: SystemTransferBusinessTypeBusinessName, } // ToINT8 converts BusinessName to its corresponding int8 type func (b BusinessName) ToINT8() int8 { if val, ok := nameToBusinessType[b]; ok { return val } return NoBusinessType } // BusinessTypeToString converts an int8 type to its corresponding BusinessName func BusinessTypeToString(b int8) BusinessName { if val, ok := businessTypeToName[b]; ok { return val } return NoBusinessName }