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
{
///
/// 请求流向
///
///
///
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);
}
}
}
}