| | |
| | | *----------------------------------------------------------------*/ |
| | | #endregion << ç æ¬ 注 é >> |
| | | using AutoMapper; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Newtonsoft.Json; |
| | | using NPOI.SS.Formula.Functions; |
| | | using SqlSugar; |
| | | using System.Diagnostics.CodeAnalysis; |
| | | using System.DirectoryServices.Protocols; |
| | | using System.Linq; |
| | | using System.Net.Http.Headers; |
| | | using System.Security.Policy; |
| | | using WIDESEA_DTO.Agv; |
| | | using WIDESEA_External.Model; |
| | | using WIDESEAWCS_Common; |
| | | using WIDESEAWCS_Common.APIEnum; |
| | | using WIDESEAWCS_Common.TaskEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_Core.Enums; |
| | | using WIDESEAWCS_Core.Helper; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | using WIDESEAWCS_DTO; |
| | | using WIDESEAWCS_DTO.Agv; |
| | | using WIDESEAWCS_DTO.TaskInfo; |
| | | using WIDESEAWCS_IBasicInfoRepository; |
| | | using WIDESEAWCS_IBasicInfoService; |
| | | using WIDESEAWCS_ITaskInfoRepository; |
| | | using WIDESEAWCS_ITaskInfoService; |
| | | using WIDESEAWCS_Model.Models; |
| | |
| | | public partial class TaskService : ServiceBase<Dt_Task, ITaskRepository>, ITaskService |
| | | { |
| | | private readonly IMapper _mapper; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | private readonly ICacheService _cacheService; |
| | | private readonly IRouterService _routerService; |
| | | private readonly ITaskExecuteDetailService _taskExecuteDetailService; |
| | |
| | | private readonly IStationMangerRepository _stationMangerRepository; |
| | | private readonly IRouterRepository _routerRepository; |
| | | private readonly IApiInfoRepository _apiInfoRepository; |
| | | private List<Dt_ApiInfo> apiInfos; |
| | | private readonly ILocationInfoRepository _locationInfoRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | |
| | | private Dictionary<string, OrderByType> _taskOrderBy = new() |
| | | { |
| | |
| | | {nameof(Dt_Task.CreateDate),OrderByType.Asc}, |
| | | }; |
| | | |
| | | private List<Dt_Warehouse>? Warehouses = new List<Dt_Warehouse>(); |
| | | |
| | | public Dictionary<string, OrderByType> TaskOrderBy { get { return _taskOrderBy; } set { _taskOrderBy = value; } } |
| | | |
| | |
| | | |
| | | public List<int> TaskRelocationTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 900 && x < 1000).ToList(); |
| | | |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository) : base(BaseDal) |
| | | public TaskService(ITaskRepository BaseDal, IMapper mapper, ICacheService cacheService, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, ITaskExecuteDetailRepository taskExecuteDetailRepository, IStationMangerRepository stationMangerRepository, IRouterRepository routerRepository, IApiInfoRepository apiInfoRepository,ILocationInfoRepository locationInfoRepository,IUnitOfWorkManage unitOfWorkManage, ILocationInfoService locationInfoService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _cacheService = cacheService; |
| | |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _routerRepository = routerRepository; |
| | | _apiInfoRepository = apiInfoRepository; |
| | | |
| | | string? cacheStr = _cacheService.Get(nameof(Dt_Warehouse)); |
| | | if (!string.IsNullOrEmpty(cacheStr)) |
| | | { |
| | | Warehouses = JsonConvert.DeserializeObject<List<Dt_Warehouse>>(cacheStr); |
| | | } |
| | | |
| | | |
| | | string? apiInfoStr = _cacheService.Get("apiInfos"); |
| | | if (!string.IsNullOrEmpty(apiInfoStr)) |
| | | { |
| | | List<Dt_ApiInfo>? infos = JsonConvert.DeserializeObject<List<Dt_ApiInfo>>(apiInfoStr); |
| | | if (infos == null || infos.Count == 0) |
| | | { |
| | | apiInfos = new List<Dt_ApiInfo>(); |
| | | } |
| | | else |
| | | { |
| | | apiInfos = infos; |
| | | } |
| | | } |
| | | _locationInfoRepository = locationInfoRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _locationInfoService = locationInfoService; |
| | | } |
| | | static object lock_taskReceive = new object(); |
| | | /// <summary> |
| | | /// æ¥æ¶WMSä»»å¡ä¿¡æ¯ |
| | | /// </summary> |
| | | /// <param name="taskDTOs">WMSä»»å¡å¯¹è±¡éå</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs) |
| | | public WebResponseContent ReceiveWMSTask([NotNull] WMSTaskDTO taskDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | string errorMsg = ""; |
| | | try |
| | | { |
| | | bool flag = false; |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | foreach (var item in taskDTOs) |
| | | lock (lock_taskReceive) |
| | | { |
| | | if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum) != null) |
| | | { |
| | | flag = true; |
| | | continue; |
| | | } |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | task.Creater = "WMS"; |
| | | task.TaskState = (int)TaskStatusEnum.New; |
| | | task.CurrentAddress = item.SourceAddress; |
| | | |
| | | Dt_Router? router; |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | Dt_Task taskOld = BaseDal.QueryFirst(x=> taskDTO.Tasks.Select(x => x.TaskDescribe.ContainerCode).Contains(x.PalletCode)); |
| | | if (taskOld != null) throw new Exception($"æç®±{taskOld.PalletCode}"+(taskOld.TaskType == TaskTypeEnum.Inbound.ObjToInt() ? "å
¥åºä»»å¡å·²åå¨" : "åºåºä»»å¡å·²åå¨")); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.GetCanOut(taskDTO.Tasks.Select(x=>x.TaskDescribe.ContainerCode).ToList()); |
| | | |
| | | Dt_LocationInfo? noOutLocation = locationInfos.FirstOrDefault(x=>x.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || x.EnableStatus != EnableStatusEnum.Normal.ObjToInt()); |
| | | |
| | | if (noOutLocation != null) throw new Exception($"æç®±{noOutLocation.PalletCode}è´§ä½{noOutLocation.LocationCode}ç¶æä¸å¯åºåº"); |
| | | List<Dt_StationManger> stationMangers = _stationMangerRepository.QueryData(); |
| | | //ä¸åä»»å¡ç» |
| | | string taskGroup= taskDTO.TaskGroupCode.IsNullOrEmpty() ? Guid.NewGuid().ToString().Replace("-","") : taskDTO.TaskGroupCode; |
| | | foreach (var item in taskDTO.Tasks.OrderBy(x=>x.TaskDescribe.ToStationCode)) |
| | | { |
| | | if (item.TaskDescribe.ToStationCode.IsNullOrEmpty()) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°ä¸è½ä¸ºç©º"); |
| | | //è·åæä½å° |
| | | Dt_StationManger? stationManger = stationMangers.FirstOrDefault(x => x.PickStationCode == item.TaskDescribe.ToStationCode); |
| | | if (stationManger == null) throw new Exception($"ä»»å¡{item.TaskCode}åºåºç®æ æä½å°{item.TaskDescribe.ToStationCode}ä¸åå¨"); |
| | | |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.PalletCode == item.TaskDescribe.ContainerCode); |
| | | if (locationInfo == null) |
| | | { |
| | | errorMsg += $"æç®±{item.TaskDescribe.ContainerCode}ä¸åå¨;"; |
| | | continue; |
| | | }; |
| | | |
| | | Dt_Task task = _mapper.Map<Dt_Task>(item); |
| | | |
| | | task.SourceAddress = locationInfo.LocationCode; |
| | | task.CurrentAddress = locationInfo.LocationCode; |
| | | task.NextAddress = stationManger.PickStationCode; |
| | | task.TargetAddress = stationManger.PickStationCode; |
| | | task.GroupId = taskGroup; |
| | | task.TaskType = TaskTypeEnum.Outbound.ObjToInt(); |
| | | task.Roadway = locationInfo.RoadwayNo; |
| | | task.DeviceCode = stationManger.CraneCode; |
| | | task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt(); |
| | | tasks.Add(task); |
| | | } |
| | | |
| | | locationInfos.ForEach(x => |
| | | { |
| | | x.LocationStatus=LocationStatusEnum.Lock.ObjToInt(); |
| | | }); |
| | | //æ·»å 任塿´æ°è´§ä½æ°æ® |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.AddData(tasks); |
| | | _locationInfoRepository.UpdateData(locationInfos); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "æ¥æ¶WMSä»»å¡"); |
| | | |
| | | content = tasks.Count > 0 ? content.OK("æå!"+(errorMsg.IsNullOrEmpty()? "": errorMsg)) : content.Error("失败"); |
| | | } |
| | | BaseDal.AddData(tasks); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "æ¥æ¶WMSä»»å¡"); |
| | | |
| | | content = (flag || tasks.Count > 0) ? WebResponseContent.Instance.OK("æå") : WebResponseContent.Instance.Error("失败"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"任塿¥æ¶é误,é误信æ¯:{ex.Message}"); |
| | | content.Error($"任塿¥æ¶é误,é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | static object lock_containerFlow = new object(); |
| | | /// <summary> |
| | | /// æ ¹æ®æçå·ãèµ·å§å°ååWMS请æ±ä»»å¡ |
| | | /// </summary> |
| | | /// <param name="palletCode">æçå·</param> |
| | | /// <param name="sourceAddress">èµ·å§å°å</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress, string materielBoxCode = "") |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == sourceAddress); |
| | | if (stationManger == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°ç«å°ä¿¡æ¯"); |
| | | } |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°WMSApiå°å"); |
| | | } |
| | | string responseStr = ""; |
| | | if (!string.IsNullOrEmpty(materielBoxCode)) |
| | | { |
| | | responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={stationManger.StackerCraneCode}&palletCode={palletCode}&materielBoxCode={materielBoxCode}"); |
| | | } |
| | | else |
| | | { |
| | | responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTask?stationCode={sourceAddress}&roadwayNo={stationManger.StackerCraneCode}&palletCode={palletCode}"); |
| | | } |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | // <summary> |
| | | /// 请æ±å
¥åºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="palletCode">æçå·</param> |
| | | /// <param name="sourceAddress">èµ·å§å°å</param> |
| | | /// /// <param name="roadWay">å··é</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestYLWMSTaskSimple(string palletCode, string sourceAddress,int taskNum=0) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°WMSApiå°å"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/RequestYLWMSTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}&taskNum{taskNum}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | if (taskDTO != null) |
| | | { |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | content = responseContent ?? content.Error("ç»æé误"); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | // <summary> |
| | | /// 请æ±å
¥åºå··é |
| | | /// 容å¨å
¥åºåå»ºä»»å¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent AssignCPRoadwayNo() |
| | | public WebResponseContent ContainerFlow(ContainerFlowDTO containerFlowDTO, string deviceCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | lock (lock_containerFlow) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°WMSApiå°å"); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoRepository.QueryData(); |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x=>x.PalletCode== containerFlowDTO.ContainerCode); |
| | | if (locationInfo != null) throw new Exception($"åºä½æç®±å·{containerFlowDTO.ContainerCode}å·²åå¨"); |
| | | if (BaseDal.QueryFirst(x=>x.PalletCode==containerFlowDTO.ContainerCode)!=null) throw new Exception($"æç®±å·{containerFlowDTO.ContainerCode}ä»»å¡å·²åå¨"); |
| | | Dt_LocationInfo? noInLocation = locationInfos.FirstOrDefault(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt()); |
| | | if (noInLocation == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | | Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.StationType == StationTypeEnum.StationType_OnlyInbound.ObjToInt() && x.StationDeviceCode == deviceCode); |
| | | //åå»ºä»»å¡ |
| | | Dt_Task task = new Dt_Task(); |
| | | task.PalletCode = containerFlowDTO.ContainerCode; |
| | | task.SourceAddress = containerFlowDTO.SlotCode; |
| | | task.CurrentAddress = containerFlowDTO.SlotCode; |
| | | task.NextAddress = stationManger.StationCode; |
| | | task.TargetAddress = ""; |
| | | task.WMSId = ""; |
| | | task.TaskType = TaskTypeEnum.Inbound.ObjToInt(); |
| | | task.Roadway = noInLocation.RoadwayNo; |
| | | task.DeviceCode = stationManger.StationDeviceCode; |
| | | task.TaskState = TaskStatusEnum.CL_Executing.ObjToInt(); |
| | | //æ·»å ä»»å¡ |
| | | BaseDal.AddData(task); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, "å建å
¥åºä»»å¡"); |
| | | content.OK("æå"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/AssignCPRoadwayNo"); |
| | | |
| | | if (!responseStr.IsNullOrEmpty()) |
| | | { |
| | | content.OK("æå", responseStr); |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | content.Error($"é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | // <summary> |
| | | /// 请æ±åæå
¥åºå··é |
| | | static object lock_requestInTask = new object(); |
| | | /// <summary> |
| | | /// ç³è¯·å
¥åº |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent AssignYLRoadwayNo(string palletCode) |
| | | public WebResponseContent RequestInTask(string stationCode,string barCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | lock (lock_requestInTask) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°WMSApiå°å"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/AssignYLRoadwayNo?palletCode={palletCode}"); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | content = responseContent; |
| | | } |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.PalletCode == barCode && x.TaskType==TaskTypeEnum.Inbound.ObjToInt() && x.NextAddress == stationCode && x.TaskState == TaskStatusEnum.CL_Executing.ObjToInt()); |
| | | if (task == null) throw new Exception($"{barCode}æç®±æªæ¾å°ä»»å¡!"); |
| | | Dt_LocationInfo? locationInfo = _locationInfoService.AssignLocation(); |
| | | if (locationInfo == null) throw new Exception($"å¯ç¨è´§ä½ä¸è¶³!"); |
| | | task.NextAddress = locationInfo.LocationCode; |
| | | task.TargetAddress = locationInfo.LocationCode; |
| | | task.CurrentAddress = stationCode; |
| | | task.DeviceCode = "AGV"; |
| | | task.TaskState = TaskStatusEnum.AGV_Execute.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | //æ´æ°ä»»å¡åè´§ä½æ°æ® |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.UpdateData(task); |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | _unitOfWorkManage.CommitTran(); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(new List<int>() { task.TaskNum }, $"åé
è´§ä½{locationInfo.LocationCode}"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | // <summary> |
| | | /// 请æ±å
¥åºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="palletCode">æçå·</param> |
| | | /// <param name="sourceAddress">èµ·å§å°å</param> |
| | | /// /// <param name="roadWay">å··é</param> |
| | | /// <returns></returns> |
| | | public WebResponseContent RequestWMSTaskSimple(string palletCode, string sourceAddress,string roadWay="", int taskType=630, int taskNum = 0, string targetAddress = "") |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | //string address = AppSettings.Get("WMSApiAddress"); |
| | | //if (string.IsNullOrEmpty(address)) |
| | | //{ |
| | | // return WebResponseContent.Instance.Error($"æªæ¾å°WMSApiå°å"); |
| | | //} |
| | | //string responseStr = HttpHelper.Get($"{address}/api/Task/DeviceRequestInboundTaskSimple?stationCode={sourceAddress}&palletCode={palletCode}"); |
| | | //WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | //if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | //{ |
| | | // WMSTaskDTO? taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(responseContent.Data.ToString()); |
| | | // if (taskDTO != null) |
| | | // { |
| | | WMSTaskDTO? taskDTO = new WMSTaskDTO() |
| | | { |
| | | TaskNum = taskNum ==0 ? DateTime.Now.ToString("mmss").ObjToInt(): taskNum, |
| | | PalletCode= palletCode, |
| | | RoadWay= roadWay, |
| | | TaskType= taskType, |
| | | PalletType=1, |
| | | TaskStatus= TaskStatusEnum.New.ObjToInt(), |
| | | SourceAddress= sourceAddress, |
| | | TargetAddress= targetAddress, |
| | | WarehouseId=2, |
| | | Grade=0, |
| | | }; |
| | | content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO }); |
| | | // } |
| | | //} |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | public WebResponseContent MESBoxCodeNotice(string boxCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°WMSApiå°å"); |
| | | content.OK("æå"); |
| | | } |
| | | string responseStr = HttpHelper.Get($"{address}/api/Mes/MESBoxCodeNotice?boxCode={boxCode}"); |
| | | return content.OK(responseStr); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error($"é误信æ¯:{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public static string Post(string serviceAddress, string requestJson = "", string contentType = "application/json", Dictionary<string, string>? headers = null) |
| | | { |
| | | string result = string.Empty; |
| | | DateTime beginDate = DateTime.Now; |
| | | try |
| | | { |
| | | using (HttpContent httpContent = new StringContent(requestJson)) |
| | | using (HttpContent httpContent = new StringContent(string.Empty)) |
| | | { |
| | | httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
| | | |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 30); |
| | | string LoginToken = AppSettings.Get("MESLoginToken"); |
| | | headers = new Dictionary<string, string> |
| | | { |
| | | //æ£å¼ |
| | | { "LoginToken", LoginToken } |
| | | }; |
| | | if (headers != null) |
| | | { |
| | | foreach (var header in headers) |
| | | httpClient.DefaultRequestHeaders.Add(header.Key, header.Value); |
| | | } |
| | | HttpResponseMessage responseMessage = httpClient.PostAsync(serviceAddress, httpContent).Result; |
| | | result = responseMessage.Content.ReadAsStringAsync().Result; |
| | | } |
| | |
| | | { |
| | | Logger.Add(serviceAddress, requestJson == null ? "" : requestJson, result, beginDate); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åWMSç³è¯·åé
è´§ä½ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <param name="roadwayNo">å··éå·</param> |
| | | /// <returns></returns> |
| | | public string? RequestAssignLocation(int taskNum, string roadwayNo) |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) throw new Exception("æªæ¾å°WMSApiå°å"); |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/AssignInboundTaskLocation?taskNum={taskNum}&roadwayNo={roadwayNo}"); |
| | | |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent.Data.ToString(); |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | /// <summary> |
| | | /// åWMSç³è¯·åºåºAGVç»ç¹ |
| | | /// </summary> |
| | | /// <param name="taskNum">ä»»å¡å·</param> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public string? RequestTargetAddress(int taskNum) |
| | | { |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | if (string.IsNullOrEmpty(address)) throw new Exception("æªæ¾å°WMSApiå°å"); |
| | | string responseStr = HttpHelper.Get($"{address}/api/Task/AssignOutTargetAddress?taskNum={taskNum}"); |
| | | |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(responseStr); |
| | | if (responseContent != null && responseContent.Status && responseContent.Data != null) |
| | | { |
| | | return responseContent.Data.ToString(); |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | task.ModifyDate = DateTime.Now; |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, task.ExceptionMessage); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, task.ExceptionMessage); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"人工æ¢å¤æèµ·ä»»å¡,æ¢å¤æèµ·æ¶ä»»å¡ç¶æã{task.TaskState}ã"); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"人工æ¢å¤æèµ·ä»»å¡,æ¢å¤æèµ·æ¶ä»»å¡ç¶æã{task.TaskState}ã"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | |
| | | BaseDal.UpdateData(task); |
| | | |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task.TaskNum, $"人工å°ä»»å¡ç¶æä»ã{oldState}ãåæ»å°ã{task.TaskState}ã"); |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"人工å°ä»»å¡ç¶æä»ã{oldState}ãåæ»å°ã{task.TaskState}ã"); |
| | | |
| | | content = WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public Dt_Task QueryBarCodeAGVFinishTask(int TaskNum, string currentAddress) |
| | | /// <summary> |
| | | /// AGV任塿¾è¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent AgvTaskFlow(string code) |
| | | { |
| | | return BaseDal.QueryFirst(x => TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskStatusEnum.AGV_Finish && x.CurrentAddress == currentAddress && x.TaskNum == TaskNum, TaskOrderBy); |
| | | WebResponseContent content=new WebResponseContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.AgvTaskFlow.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) throw new Exception($"{code},æªæ¾å°AGV任塿¾è¡æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | AgvTaskFlowDTO agvTaskFlowDTO = new AgvTaskFlowDTO() |
| | | { |
| | | RequestId = Guid.NewGuid().ToString().Replace("-", ""), |
| | | MissionCode = code |
| | | }; |
| | | string request = JsonConvert.SerializeObject(agvTaskFlowDTO, settings); |
| | | string response = HttpHelper.Post(url, request); |
| | | AgvResponseContent agvResponse = JsonConvert.DeserializeObject<AgvResponseContent>(response) ?? throw new Exception($"{code},æªæ¥æ¶å°AGV任塿¾è¡è¿åå¼"); |
| | | if (!agvResponse.Success) throw new Exception($"æç®±{code},AGV任塿¾è¡é误,ä¿¡æ¯:{agvResponse.Message}"); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// WMSæç®±å°è¾¾æ£éä½ä¸æ¥ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent WMSPickUp(string stationCode,string pickCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSPickArrivedUp.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) throw new Exception($"æªæ¾å°WMSæç®±å°è¾¾æ£éä½ä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | ContainerArriveDTO containerArriveDTO = new ContainerArriveDTO() |
| | | { |
| | | SlotCode = stationCode, |
| | | ContainerCode = pickCode |
| | | }; |
| | | string request = JsonConvert.SerializeObject(containerArriveDTO, settings); |
| | | string response = HttpHelper.Post(url, request); |
| | | WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{pickCode},æªæ¥æ¶å°WMSæç®±å°è¾¾æ£éä½ä¸æ¥è¿åå¼"); |
| | | if (wMSResponse.Code != "0") throw new Exception($"æç®±{pickCode}WMSæç®±å°è¾¾æ£éä½ä¸æ¥é误,ä¿¡æ¯:{wMSResponse.Msg}"); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// ä»»å¡å®æ |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent TaskCompleted(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)//åºåºä»»å¡å®æé»è¾ |
| | | { |
| | | Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x=>x.PalletCode==task.PalletCode); |
| | | if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt()) |
| | | { |
| | | return content.Error($"{locationInfo.LocationCode}è´§ä½ç¶æä¸æ£ç¡®"); |
| | | } |
| | | task.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | locationInfo.PalletCode = ""; |
| | | //æç®±åºåºå®æä¸æ¥ç»WMS |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"æªæ¾å°WMSåºåºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | UpdateTaskExceptionMessage(taskNum, $"æªæ¾å°WMSåºåºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | return content.Error($"{taskNum},æªæ¾å°WMSåºåºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO() |
| | | { |
| | | TaskCode = task.TaskNum.ToString(), |
| | | ContainerCode = task.PalletCode, |
| | | StationCode = task.TargetAddress, |
| | | LocationCode = task.SourceAddress, |
| | | CompleteType = 1 |
| | | }; |
| | | string request = JsonConvert.SerializeObject(containerInFinishDTO, settings); |
| | | //è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},æªæ¥æ¶å°WMSåºåºä¸æ¥è¿åå¼"); |
| | | if (wMSResponse.Code != "0") throw new Exception($"åºåºä»»å¡{task.TaskNum}WMSåºåºä¸æ¥é误,ä¿¡æ¯:{wMSResponse.Msg}"); |
| | | _unitOfWorkManage.BeginTran(); |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | else if(task != null && task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)//å
¥åºä»»å¡å®æé»è¾ |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.WMSInOutBoundBack.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | _taskExecuteDetailService.AddTaskExecuteDetail(task, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | UpdateTaskExceptionMessage(taskNum, $"æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | return content.Error($"{taskNum},æªæ¾å°WMSå
¥åºä¸æ¥æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | ContainerInFinishDTO containerInFinishDTO = new ContainerInFinishDTO() |
| | | { |
| | | TaskCode = task.TaskNum.ToString(), |
| | | ContainerCode = task.PalletCode, |
| | | StationCode = task.SourceAddress, |
| | | LocationCode = task.TargetAddress, |
| | | CompleteType = 2 |
| | | }; |
| | | string request = JsonConvert.SerializeObject(containerInFinishDTO, settings); |
| | | //è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | WMSResponseContent wMSResponse = JsonConvert.DeserializeObject<WMSResponseContent>(response) ?? throw new Exception($"{taskNum},æªæ¥æ¶å°WMSå
¥åºä¸æ¥è¿åå¼"); |
| | | if (wMSResponse.Code != "0") throw new Exception($"å
¥åºä»»å¡{task.TaskNum}WMSå
¥åºä¸æ¥é误,ä¿¡æ¯:{wMSResponse.Msg}"); |
| | | Dt_LocationInfo locationInfo = _locationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (locationInfo.LocationStatus != LocationStatusEnum.Lock.ObjToInt()) |
| | | { |
| | | return content.Error($"{locationInfo.LocationCode}è´§ä½ç¶æä¸æ£ç¡®"); |
| | | } |
| | | task.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | locationInfo.PalletCode = task.PalletCode; |
| | | _unitOfWorkManage.BeginTran(); |
| | | _locationInfoRepository.UpdateData(locationInfo); |
| | | BaseDal.DeleteAndMoveIntoHty(task, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | content.OK("ä»»å¡å®æ"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// äºææç§å¢ä¸å |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public EPLightContent PickOrderInfoRequest(List<EPLightSendDTO> lightSendDTOs) |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.PickOrderInfoRequest.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error($"æªæ¾å°æç§å¢ä¸åæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | string request = JsonConvert.SerializeObject(lightSendDTOs, settings); |
| | | //è°ç¨æ¥å£ |
| | | string response = HttpHelper.Post(url, request); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢ä¸å䏿¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢ä¸åé误,ä¿¡æ¯:{lightContent.Msg}"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// äºææç§å¢åå§å |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public EPLightContent INITIALIZATION() |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.INITIALIZATION.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error($"æªæ¾å°æç§å¢åå§åæ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | //è°ç¨æ¥å£ |
| | | string response = Post(url); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢åå§å䏿¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢åå§åé误,ä¿¡æ¯:{lightContent.Msg}"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// äºææç§å¢ç»æä½ä¸ |
| | | /// </summary> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | public EPLightContent ENDWORK() |
| | | { |
| | | EPLightContent content = new EPLightContent(); |
| | | try |
| | | { |
| | | string? url = _apiInfoRepository.QueryFirst(x => x.ApiCode == APIEnum.ENDWORK.ToString())?.ApiAddress; |
| | | if (string.IsNullOrEmpty(url)) |
| | | { |
| | | return content.Error($"æªæ¾å°æç§å¢ç»æä½ä¸æ¥å£,è¯·æ£æ¥æ¥å£é
ç½®"); |
| | | } |
| | | //è°ç¨æ¥å£ |
| | | string response = Post(url); |
| | | EPLightContent lightContent = JsonConvert.DeserializeObject<EPLightContent>(response) ?? throw new Exception($"æªæ¥æ¶å°æç§å¢ç»æä½ä¸ä¸æ¥è¿åå¼"); |
| | | if (lightContent.Result != "0") throw new Exception($"æç§å¢ç»æä½ä¸é误,ä¿¡æ¯:{lightContent.Msg}"); |
| | | content.OK("æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |