刘磊
2024-11-23 4c511d29869878c7a7ea015cbac4367faeb0e27b
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
using MailKit;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_DTO;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEA_StoragIntegrationServices
{
    public partial class WCSService
    {
        /// <summary>
        /// 请求流向
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public WebResponseContent RequestFlow(RequestTaskDto json)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var minGroup = _locationRepository.QueryData(x => x.LocationStatus == (int)LocationEnum.Free && x.AreaId == json.area)
                             .GroupBy(x => x.RoadwayNo)  //根据堆垛机巷道分组
                             .OrderByDescending(g => g.Count()) // 根据每个组的元素数量排序
                             .First(); // 取出数量最多的巷道
 
                var stationinfo = _stationManagerRepository.QueryData(x => x.stationArea == json.area.ToString() && x.Roadway == minGroup.Key);
                Dt_StationManager stationManager = new Dt_StationManager();
                var task = _taskRepository.QueryFirst(x => x.Roadway == minGroup.Key);
                if (task != null)
                {
                    stationManager = stationinfo.FirstOrDefault(x => x.Roadway != task.Roadway);
                }
                else
                {
                    stationManager = stationinfo.FirstOrDefault();
                }
                if (stationManager == null)
                {
                    throw new Exception($"异常:无法分配巷道");
                }
                return content.OK(data: stationManager);
            }
            catch (Exception ex)
            {
                return content.Error(ex.Message);
            }
        }
    }
}