You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

154 lines
6.4 KiB

using System;
using System.Text.Json.Serialization;
namespace Mirle.Component.API.WarehouseExecutionSystem.Models
{
/// <summary>
/// 交易名稱列舉
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TransactionName
{
/// <summary>
/// 建立命令請求
/// </summary>
FW_001_CreateCommandRequest,
/// <summary>
/// 建立命令回應
/// </summary>
TW_002_CreateCommandResponse,
/// <summary>
/// 執行命令回報
/// </summary>
TW_003_ExecuteCommandReport,
/// <summary>
/// 執行命令回應
/// </summary>
FW_004_ExecuteCommandAck,
/// <summary>
/// 完成命令回報
/// </summary>
TW_005_FinishCommandReport,
/// <summary>
/// 完成命令回應
/// </summary>
FW_006_FinishCommandAck,
/// <summary>
/// 取消命令請求
/// </summary>
FW_007_CancelCommandRequest,
/// <summary>
/// 取消命令回應
/// </summary>
TW_008_CancelCommandResponse,
/// <summary>
/// 確認載具編號及物料編號請求
/// </summary>
TW_009_CheckCarrierIDRequest,
/// <summary>
/// 確認載具編號及物料編號回應
/// </summary>
FW_010_CheckCarrierIDResponse,
/// <summary>
/// 棧板供收狀態回報
/// </summary>
TW_011_PalletSupplyStatusReport,
/// <summary>
/// 棧板供收狀態回應
/// </summary>
FW_012_PalletSupplyStatusAck,
/// <summary>
/// 心跳包回報
/// </summary>
TW_013_HeartbeatReport,
/// <summary>
/// 心跳包回應
/// </summary>
FW_014_HeartbeatAck,
/// <summary>
/// 物料重量請求
/// </summary>
FW_015_MaterialWeightRequest,
/// <summary>
/// 物料重量回應
/// </summary>
TW_016_MaterialWeightResponse,
/// <summary>
/// 緊急應變請求
/// </summary>
TW_017_EmergencyEventRequest,
/// <summary>
/// 緊急應變回應
/// </summary>
FW_018_EmergencyEventResponse
}
/// <summary>
/// 交易名稱擴充方法類別
/// </summary>
public static class TransactionNameExtension
{
/// <summary>
/// 轉換成交易識別碼
/// </summary>
/// <param name="transactionName">交易名稱列舉項目</param>
/// <returns>交易識別碼</returns>
/// <exception cref="ArgumentException">未知交易名稱列舉項目</exception>
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}")
};
}
/// <summary>
/// 轉換成 Web Application Url
/// </summary>
/// <param name="transactionName">交易名稱列舉項目</param>
/// <returns>WEB API URL</returns>
/// <exception cref="ArgumentException">未知交易名稱列舉項目</exception>
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}")
};
}
}
}