using Grpc.Net.Client; using HotelPms.Client.Blazor.Util; using HotelPms.Data.Common; using HotelPms.Data.Master; using HotelPms.DataAccessGrpc.Client; using HotelPms.Share.Data; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using System.Data; namespace HotelPms.Client.Blazor.Models; /// /// M_RoomStatusを管理する /// SignalRより更新通知を届く予定 /// Redis订阅 /// public class RoomStatusSetting : IDisposable { private static object syncObj = new object(); private static RoomStatusSetting m_Instance; public static async Task Instance() { bool isNew = false; lock (syncObj) { if (m_Instance == null) { m_Instance = new RoomStatusSetting(); isNew = true; } } if(isNew) { await m_Instance.GetData(); } return m_Instance; } public void Dispose() { } public RoomStatusSetting() { } /// /// SignalRより更新通知を届く予定 /// SortID順 /// public List BufferStorage { get; set; } = new List(); /// /// ID⇒BufferStorage.Index /// private Dictionary m_IDMap = new Dictionary(); /// /// 空室のID /// public int Vacancy { get; set; } = 0; /// /// 清掃指示のID /// public int InstructClean { get; set; } = 0; /// /// 点検中のID /// public int MaidCheck { get; set; } = 0; public void ClearBuffer() { BufferStorage.Clear(); m_IDMap.Clear(); } public async Task GetData() { ClearBuffer(); using RoomStatusAccess access = new RoomStatusAccess(EnvironmentSetting.GrpcChannel); var data = await access.GetDataAsync(string.Empty); int i = 0; foreach(RoomStatus item in data.Rows) { m_IDMap.Add(item.ID, i++); BufferStorage.Add(item); if (item.MaidType == (int)EMaidType.Vacancy) { Vacancy = item.ID; } else if (item.MaidType == (int)EMaidType.Instruct) { InstructClean = item.ID; } else if (item.MaidType == (int)EMaidType.Check) { MaidCheck = item.ID; } EnvironmentSetting.Debug(item.ToText()); } } /// /// 現在のIDより次のIDを取得する /// /// /// public RoomStatus Next(int id) { try { if (BufferStorage.Count == 0) { return null; } int idx = m_IDMap[id]; if (idx == (BufferStorage.Count - 1)) { return BufferStorage[0]; } else { return BufferStorage[idx + 1]; } } catch { return null; } } /// /// 現在IDより前のIDを取得する /// /// /// /// public RoomStatus Prev(int id) { try { if (BufferStorage.Count == 0) { return null; } int idx = m_IDMap[id]; if (idx == 0) { return BufferStorage[BufferStorage.Count - 1]; } else { return BufferStorage[idx - 1]; } } catch { return null; } } }