using System; using System.Text.Json.Serialization; namespace Mirle.Component.API.WarehouseExecutionSystem.Models { /// /// 交易名稱列舉 /// [JsonConverter(typeof(JsonStringEnumConverter))] public enum TransactionName { /// /// 建立命令請求 /// FW_001_CreateCommandRequest, /// /// 建立命令回應 /// TW_002_CreateCommandResponse, /// /// 執行命令回報 /// TW_003_ExecuteCommandReport, /// /// 執行命令回應 /// FW_004_ExecuteCommandAck, /// /// 完成命令回報 /// TW_005_FinishCommandReport, /// /// 完成命令回應 /// FW_006_FinishCommandAck, /// /// 取消命令請求 /// FW_007_CancelCommandRequest, /// /// 取消命令回應 /// TW_008_CancelCommandResponse, /// /// 確認載具編號及物料編號請求 /// TW_009_CheckCarrierIDRequest, /// /// 確認載具編號及物料編號回應 /// FW_010_CheckCarrierIDResponse, /// /// 棧板供收狀態回報 /// TW_011_PalletSupplyStatusReport, /// /// 棧板供收狀態回應 /// FW_012_PalletSupplyStatusAck, /// /// 心跳包回報 /// TW_013_HeartbeatReport, /// /// 心跳包回應 /// FW_014_HeartbeatAck, /// /// 物料重量請求 /// FW_015_MaterialWeightRequest, /// /// 物料重量回應 /// TW_016_MaterialWeightResponse, /// /// 緊急應變請求 /// TW_017_EmergencyEventRequest, /// /// 緊急應變回應 /// FW_018_EmergencyEventResponse } /// /// 交易名稱擴充方法類別 /// public static class TransactionNameExtension { /// /// 轉換成交易識別碼 /// /// 交易名稱列舉項目 /// 交易識別碼 /// 未知交易名稱列舉項目 public static string ToTransactionName(this TransactionName transactionName) { return transactionName switch { TransactionName.FW_001_CreateCommandRequest => "FW001", TransactionName.TW_002_CreateCommandResponse => "TW002", TransactionName.TW_003_ExecuteCommandReport => "TW003", TransactionName.FW_004_ExecuteCommandAck => "FW004", TransactionName.TW_005_FinishCommandReport => "TW005", TransactionName.FW_006_FinishCommandAck => "FW006", TransactionName.FW_007_CancelCommandRequest => "FW007", TransactionName.TW_008_CancelCommandResponse => "TW008", TransactionName.TW_009_CheckCarrierIDRequest => "TW009", TransactionName.FW_010_CheckCarrierIDResponse => "FW010", TransactionName.TW_011_PalletSupplyStatusReport => "TW011", TransactionName.FW_012_PalletSupplyStatusAck => "FW012", TransactionName.TW_013_HeartbeatReport => "TW013", TransactionName.FW_014_HeartbeatAck => "FW014", TransactionName.FW_015_MaterialWeightRequest => "FW015", TransactionName.TW_016_MaterialWeightResponse => "TW016", TransactionName.TW_017_EmergencyEventRequest => "TW017", TransactionName.FW_018_EmergencyEventResponse => "FW018", _ => throw new ArgumentException($"Unknow transaction name: {transactionName}") }; } /// /// 轉換成 Web Application Url /// /// 交易名稱列舉項目 /// WEB API URL /// 未知交易名稱列舉項目 public static string ToUrl(this TransactionName transactionName) { return transactionName switch { TransactionName.FW_001_CreateCommandRequest => "WES/FromWES/CREATE_COMMAND", TransactionName.TW_002_CreateCommandResponse => "WES/ToWES/CREATE_COMMAND", TransactionName.TW_003_ExecuteCommandReport => "WES/ToWES/EXECUTE_COMMAND", TransactionName.FW_004_ExecuteCommandAck => "WES/FromWES/EXECUTE_COMMAND", TransactionName.TW_005_FinishCommandReport => "WES/ToWES/FINISH_COMMAND", TransactionName.FW_006_FinishCommandAck => "WES/FromWES/FINISH_COMMAND", TransactionName.FW_007_CancelCommandRequest => "WES/FromWES/CANCEL_COMMAND", TransactionName.TW_008_CancelCommandResponse => "WES/ToWES/CANCEL_COMMAND", TransactionName.TW_009_CheckCarrierIDRequest => "WES/ToWES/CHECK_CARRIER_ID", TransactionName.FW_010_CheckCarrierIDResponse => "WES/FromWES/CHECK_CARRIER_ID", TransactionName.TW_011_PalletSupplyStatusReport => "WES/ToWES/PALLET_SUPPLY_STATUS", TransactionName.FW_012_PalletSupplyStatusAck => "WES/FromWES/PALLET_SUPPLT_STATUS", TransactionName.TW_013_HeartbeatReport => "WES/ToWES/HEARTBEAT", TransactionName.FW_014_HeartbeatAck => "WES/ToWES/HEARTBEAT", TransactionName.FW_015_MaterialWeightRequest => "WES/FromWES/MATERIAL_WEIGHT", TransactionName.TW_016_MaterialWeightResponse => "WES/ToWES/MATERIAL_WEIGHT", TransactionName.TW_017_EmergencyEventRequest => "WES/ToWES/EMERGENCY_EVENT", TransactionName.FW_018_EmergencyEventResponse => "WES/FromWES/EMERGENCY_EVENT", _ => throw new ArgumentException($"Unknow transaction name: {transactionName}") }; } } }