app-cloudep-trade-service/internal/domain/wallet/wallet_business_name.go

53 lines
1.3 KiB
Go
Raw Normal View History

2024-10-31 04:05:22 +00:00
package wallet
// ===================商業邏輯類型===================
type BusinessLogic string
// 定義商業邏輯名稱
const (
// NoLogic 無商業邏輯
NoLogic BusinessLogic = ""
// OrderLogic 訂單相關業務邏輯
OrderLogic BusinessLogic = "order"
// SystemTransferLogic 系統劃轉邏輯
SystemTransferLogic BusinessLogic = "system_transfer"
)
// 定義商業邏輯類型
const (
// NoLogicType 無商業邏輯類型
NoLogicType int8 = iota
// OrderLogicType 訂單業務邏輯類型
OrderLogicType
// SystemTransferLogicType 系統劃轉業務邏輯類型
SystemTransferLogicType
)
// 定義名稱和類型之間的映射
var logicNameToType = map[BusinessLogic]int8{
OrderLogic: OrderLogicType,
SystemTransferLogic: SystemTransferLogicType,
}
var logicTypeToName = map[int8]BusinessLogic{
OrderLogicType: OrderLogic,
SystemTransferLogicType: SystemTransferLogic,
}
// ToInt8 將 BusinessLogic 轉換為對應的 int8 類型
func (b BusinessLogic) ToInt8() int8 {
if val, ok := logicNameToType[b]; ok {
return val
}
return NoLogicType
}
// LogicTypeToName 將 int8 類型轉換為對應的 BusinessLogic 名稱
func LogicTypeToName(b int8) BusinessLogic {
if val, ok := logicTypeToName[b]; ok {
return val
}
return NoLogic
}