ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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;
        }
    }
}