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;
|
|
/// <summary>
|
/// M_RoomStatusを管理する
|
/// SignalRより更新通知を届く予定
|
/// Redis订阅
|
/// </summary>
|
public class RoomStatusSetting : IDisposable
|
{
|
private static object syncObj = new object();
|
private static RoomStatusSetting m_Instance;
|
public static async Task<RoomStatusSetting> 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()
|
{
|
}
|
|
/// <summary>
|
/// SignalRより更新通知を届く予定
|
/// SortID順
|
/// </summary>
|
public List<RoomStatus> BufferStorage { get; set; } = new List<RoomStatus>();
|
|
/// <summary>
|
/// ID⇒BufferStorage.Index
|
/// </summary>
|
private Dictionary<int, int> m_IDMap = new Dictionary<int, int>();
|
|
/// <summary>
|
/// 空室のID
|
/// </summary>
|
public int Vacancy { get; set; } = 0;
|
|
/// <summary>
|
/// 清掃指示のID
|
/// </summary>
|
public int InstructClean { get; set; } = 0;
|
|
/// <summary>
|
/// 点検中のID
|
/// </summary>
|
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());
|
}
|
}
|
|
/// <summary>
|
/// 現在のIDより次のIDを取得する
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
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;
|
}
|
}
|
|
/// <summary>
|
/// 現在IDより前のIDを取得する
|
/// </summary>
|
/// <param name=""></param>
|
/// <param name=""></param>
|
/// <returns></returns>
|
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;
|
}
|
}
|
}
|