分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-06-07 fdf6494705b9bcddb2e16b933b231262497fc227
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WMS.Common
{
    public class GetStation
    {
        /// <summary>
        /// 当前库位同一行是否存在入库占用
        /// true:是 false:否
        /// </summary>
        /// <param name="StationCode"></param>
        /// <returns></returns>
        public static bool InBusyStation(string StationCode)
        {
            bool OK = false;
            try
            {
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                var station = stationinfoRepository.Find(x => x.stationCode == StationCode).FirstOrDefault();
                OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.location_state == LocationStateEnum.InBusy.ToString()).Any();
            }
            catch (Exception ex)
            {
 
            }
            return OK;
        }
        /// <summary>
        /// 当前库位同一行是否存在出库占用
        /// true:是 false:否
        /// </summary>
        /// <param name="StationCode"></param>
        /// <returns></returns>
        public static bool OutBusyStation(string StationCode)
        {
            bool OK = false;
            try
            {
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                var station = stationinfoRepository.Find(x => x.stationCode == StationCode).FirstOrDefault();
                OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.location_state == LocationStateEnum.OutBusy.ToString()).Any();
            }
            catch (Exception ex)
            {
 
            }
            return OK;
        }
        /// <summary>
        /// 当前库位外边的货位是否都为空
        /// true:否 false:是
        /// </summary>
        /// <param name="StationCode"></param>
        /// <returns></returns>
        public static bool QueueStation(string StationCode)
        {
            bool OK = false;
            try
            {
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                var station = stationinfoRepository.Find(x => x.stationCode == StationCode).FirstOrDefault();
                if (station.area == "10" || station.area == "11")
                {
                    OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.column < station.column && x.location_state != LocationStateEnum.Empty.ToString()).Any();
                }
                else
                {
                    OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.column > station.column && x.location_state != LocationStateEnum.Empty.ToString()).Any();
                }
            }
            catch (Exception ex)
            {
 
            }
            return OK;
        }
        /// <summary>
        /// 找可入库空托位
        /// </summary>
        public static void EmptyStation()
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
                var Stations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity == 5 && x.enable).ToList();
                foreach (var Station in Stations)
                {
                    var area = Station.tray_type == "SmallTray" ? "11" : "10";
                }
            }
            catch (Exception ex)
            {
 
            }
        }
        /// <summary>
        /// 查找当前行可入库空货位
        /// </summary>
        /// <param name="EmptyStation"></param>
        /// <param name="stationinfoRepository"></param>
        /// <returns></returns>
        public static dt_stationinfo Station(dt_stationinfo EmptyStation, Idt_stationinfoRepository stationinfoRepository)
        {
            dt_stationinfo stationinfo = null;
            try
            {
                if (stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state.Contains("Busy")).Any()) return stationinfo;
 
 
                stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.quantity > 0 && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
                if (stationinfo != null)
                    if (stationinfo.quantity < 5) return stationinfo;
 
                stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
 
            }
            catch (Exception ex)
            {
 
            }
            return stationinfo;
        }
 
        /// <summary>
        /// 空托可入库货位
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public static dt_stationinfo EmptyPalletStation1(string area)
        {
            dt_stationinfo stationinfo = null;
            try
            {
                VOLContext Context = new VOLContext();
                Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
 
                #region 查找AB库可入空托空货位
                if (area == "11" && stationinfoRepository.Find(x => x.stationCode == "A01001001" && x.quantity == 5 && x.location_state == LocationStateEnum.Stroge.ToString()).Any())
                {
                    #region MyRegion
                    var EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && (x.area == "2" || x.area == "3") && x.tray_status == TrayStateEnum.EmptyTray.ToString() && x.enable).OrderByDescending(x => x.area).ThenByDescending(x => x.line).ThenByDescending(x => x.column).FirstOrDefault();
                    #endregion
                    if (EmptyStation == null)
                        EmptyStation = stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Busy.ToString() && (x.area == "2" || x.area == "3") && x.tray_status == TrayStateEnum.EmptyTray.ToString() && x.enable).OrderByDescending(x => x.area).ThenByDescending(x => x.line).ThenByDescending(x => x.column).FirstOrDefault();
 
                    #region 查找库区2和库区3的空托货位
                    //var EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && (x.area == "2" || x.area == "3")
                    //   && x.tray_status == TrayStateEnum.EmptyTray.ToString() && x.enable).OrderByDescending(x => x.lastUpdateTime).FirstOrDefault();
 
                    if (EmptyStation != null)
                    {
                        stationinfo = Station(EmptyStation, stationinfoRepository);
                        if (stationinfo != null)
                            if (!QueueStation(stationinfo.stationCode)) return stationinfo;
 
                        EmptyStation = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
                        if (EmptyStation.quantity != 5) return null;
                    }
                    #endregion
 
                    #region 未找到空托货位或当前行已满,寻找新的一行
                    stationinfo = stationinfoRepository.Find(x => x.column == 2 && x.area == "3" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.line).FirstOrDefault();
                    if (stationinfo == null)
                        stationinfo = stationinfoRepository.Find(x => x.column == 1 && x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.line).FirstOrDefault();
                    #endregion
                }
                #endregion
 
                #region 查找空托库区
                else
                {
                    if (stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Busy.ToString()).Any()) return stationinfo;
                    stationinfo = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.enable).OrderBy(x => x.column).FirstOrDefault();
                    if (stationinfo != null)
                        if (!QueueStation(stationinfo.stationCode) && stationinfo.quantity < 5) return stationinfo;
                    stationinfo = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
 
                }
                #endregion
 
                #region 查看当前空货位后是否存在有料
                if (stationinfo != null)
                    if (GetStation.QueueStation(stationinfo.stationCode)) stationinfo = null;
                #endregion
 
                #region 判断当前货位是否存在任务
                if (stationinfo != null)
                    if (agvtaskService.Find(x => x.agv_toaddress == stationinfo.stationCode).Any()) stationinfo = null;
                #endregion
 
            }
            catch (Exception ex)
            {
                throw;
            }
            return stationinfo;
        }
        /// <summary>
        /// 空托可入库货位
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public static dt_stationinfo EmptyPalletStation(string area)
        {
            dt_stationinfo stationinfo = null;
            try
            {
                VOLContext Context = new VOLContext();
                Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
 
                #region 查找空托盘库区
                if (stationinfoRepository.Find(x => x.stationCode == "A01001001" && x.quantity == 5 && x.location_state == LocationStateEnum.Stroge.ToString()).Any())
                {
                    var EmptyStation = stationinfoRepository.Find(x => x.stationCode == "C01005002" && x.location_state == LocationStateEnum.Empty.ToString()).FirstOrDefault();
                    if (EmptyStation != null)
                    {
                        if (!stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state != LocationStateEnum.Empty.ToString()).Any())
                            return EmptyStation;
                    }
                    EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && x.stationCode == "C01005002" && x.location_state == "Stroge" && x.tray_status == "EmptyTray" && x.enable).FirstOrDefault();
 
 
                    if (EmptyStation != null) stationinfo = Station(EmptyStation, stationinfoRepository);
                    if (stationinfo != null) return stationinfo;
 
                    EmptyStation = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
 
                    if (EmptyStation.quantity == 5)
                    {
                        EmptyStation = stationinfoRepository.Find(x => x.stationCode == "C01004002" && x.location_state == LocationStateEnum.Empty.ToString()).FirstOrDefault();
                        if (EmptyStation != null)
                        {
                            if (!stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state != LocationStateEnum.Empty.ToString()).Any())
                                return EmptyStation;
                        }
 
                        EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && x.stationCode == "C01004002" && x.location_state == "Stroge" && x.tray_status == "EmptyTray" && x.enable).FirstOrDefault();
                        if (EmptyStation != null) stationinfo = Station(EmptyStation, stationinfoRepository);
                    }
 
                }
                else
                {
                    if (stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Busy.ToString()).Any()) return stationinfo;
                    stationinfo = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.enable).OrderBy(x => x.column).FirstOrDefault();
                    if (stationinfo != null)
                        if (stationinfo.quantity < 5) return stationinfo;
                    stationinfo = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
 
                }
                #endregion
 
                #region 判断当前货位是否存在任务
                if (stationinfo != null)
                    if (agvtaskService.Find(x => /*x.agv_fromaddress == stationinfo.stationCode ||*/ x.agv_toaddress == stationinfo.stationCode).Any()) stationinfo = null;
                #endregion
 
            }
            catch (Exception ex)
            {
                throw;
            }
            return stationinfo;
        }
    }
}