¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Core.Helper; |
| | | using Microsoft.Extensions.Logging; |
| | | using System.Net.Http.Headers; |
| | | using System.Security.Policy; |
| | | using Newtonsoft.Json; |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | | public partial class TaskService |
| | | { |
| | | public string url = AppSettings.Configuration["WCS"]; |
| | | /// <summary> |
| | | /// PDAç³è¯·å
¥åº--å åæºç«åºå
¥åº |
| | | /// </summary> |
| | | /// <param name="stationCode">èµ·å§å°å</param> |
| | | /// <param name="taskType">ä»»å¡ç±»å--å
¥ç©ºï¼å
¥æ</param> |
| | | /// <param name="palletCode">æçç¼å·</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent GenerateInboundTask(string stationCode, int taskType, string palletCode) |
| | | { |
| | | string? name = Enum.GetName(typeof(TaskTypeEnum), taskType); |
| | | MethodInfo? methodInfo = GetType().GetMethod(name + "Request"); |
| | | if (methodInfo != null) |
| | | { |
| | | WebResponseContent? responseContent = (WebResponseContent?)methodInfo.Invoke(this, new object[] { stationCode, palletCode }); |
| | | if (responseContent != null) |
| | | { |
| | | return responseContent; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°è¯¥ä»»å¡ç±»åä¸å¡"); |
| | | } |
| | | return WebResponseContent.Instance.Error($"é误"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 空æçå
¥åº |
| | | /// </summary> |
| | | /// <param name="stationCode">èµ·å§å°å</param> |
| | | /// <param name="palletCode">æçç¼å·</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent PalletInboundRequest(string stationCode, string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | (bool, string) result = CheckRequestInbound(stationCode, palletCode, false); |
| | | if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | content = AssignLocUpdateData(stationCode, TaskTypeEnum.PalletInbound.ObjToInt(), palletCode, false); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç©æå
¥åº |
| | | /// </summary> |
| | | /// <param name="stationCode">èµ·å§å°å</param> |
| | | /// <param name="palletCode">æçç¼å·</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | public WebResponseContent InboundRequest(string stationCode, string palletCode) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(palletCode); |
| | | (bool, string) result = CheckRequestInbound(stationCode, palletCode, true, stockInfo); |
| | | if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); |
| | | content = AssignLocUpdateData(stationCode, TaskTypeEnum.Inbound.ObjToInt(), palletCode, true, stockInfo); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content = WebResponseContent.Instance.Error($"{ex.Message}"); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
¥åºåé
è´§ä½åå¤çæ°æ® |
| | | /// </summary> |
| | | /// <param name="stationCode">èµ·å§å°å</param> |
| | | /// <param name="taskType">ä»»å¡ç±»å</param> |
| | | /// <param name="palletCode">æçç¼å·</param> |
| | | /// <param name="isUpdateStock">æ¯å¦æ´æ°ç»çä¿¡æ¯--åºåç©æå
¥åºå空æå
¥åº</param> |
| | | /// <param name="stockInfo">ç»çä¿¡æ¯--å¯ç©º</param> |
| | | /// <param name="orderNo">订åå·--å¯ç©º</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | private WebResponseContent AssignLocUpdateData(string stationCode, int taskType, string palletCode, bool isUpdateStock = true, Dt_StockInfo? stockInfo = null, string orderNo = "") |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | _unitOfWorkManage.BeginTran(); |
| | | Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(stationCode, taskType); |
| | | if (locationInfo != null) |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | Dt_Task task = new() |
| | | { |
| | | CurrentAddress = stationCode, |
| | | Grade = 2, |
| | | PalletCode = palletCode, |
| | | NextAddress = locationInfo.LocationCode, |
| | | Roadway = locationInfo.RoadwayNo, |
| | | SourceAddress = stationCode, |
| | | TargetAddress = locationInfo.LocationCode, |
| | | TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), |
| | | TaskType = taskType, |
| | | Depth= locationInfo.Depth, |
| | | }; |
| | | BaseDal.AddData(task); |
| | | int beforeStatus = locationInfo.LocationStatus; |
| | | |
| | | if (isUpdateStock) |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | if (locationInfo.Depth == 2) |
| | | { |
| | | _basicService.LocationInfoService.UpdateLocationLock(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false); |
| | | } |
| | | |
| | | if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Count > 0) |
| | | { |
| | | orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? ""; |
| | | |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error("æªæ¾å°åºåä¿¡æ¯"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); |
| | | if (locationInfo.Depth == 2) |
| | | { |
| | | _basicService.LocationInfoService.UpdateLocationLock(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false); |
| | | } |
| | | task.Grade = 1; |
| | | } |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationInfo); |
| | | |
| | | tasks.Add(task); |
| | | _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), orderNo, task.TaskNum); |
| | | |
| | | var response = HttpHelper.Post<WebResponseContent>(url + "ReceiveTask/", tasks, "å
¥åºä»»å¡ä¸å"); |
| | | if (!response.Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content = WebResponseContent.Instance.Error($"{response.Message}"); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content = WebResponseContent.Instance.OK(); |
| | | } |
| | | return content = WebResponseContent.Instance.Error("æªæ¾å°å¯åé
è´§ä½"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content = WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éªè¯æ°æ® |
| | | /// </summary> |
| | | /// <param name="stationCode">èµ·å§å°å</param> |
| | | /// <param name="palletCode">æçç¼å·</param> |
| | | /// <param name="isCheckStock">æ¯å¦æ£æ¥ç»çä¿¡æ¯--åºåç©æå
¥åºå空æå
¥åº</param> |
| | | /// <param name="stockInfo">ç»çä¿¡æ¯--å¯ç©º</param> |
| | | /// <returns>è¿åå¤çç»æ</returns> |
| | | private (bool, string) CheckRequestInbound(string stationCode, string palletCode, bool isCheckStock = true, Dt_StockInfo? stockInfo = null) |
| | | { |
| | | if (BaseDal.QueryFirst(x => x.PalletCode == palletCode) != null) |
| | | { |
| | | return (false, "该æçå·å·²æä»»å¡!"); |
| | | } |
| | | if (BaseDal.QueryFirst(x => (x.SourceAddress == stationCode || x.CurrentAddress == stationCode) && x.TaskStatus == InTaskStatusEnum.InNew.ObjToInt()) != null) |
| | | { |
| | | return (false, "å½åå
¥åºç«å°å·²æä¸æ¡æ°å»ºä»»å¡!"); |
| | | } |
| | | if (isCheckStock) |
| | | { |
| | | if (stockInfo == null) |
| | | { |
| | | return (false, "æªæ¾å°ç»çä¿¡æ¯!"); |
| | | } |
| | | if (stockInfo.StockStatus != StockStatusEmun.ç»çæå.ObjToInt()) |
| | | { |
| | | return (false, "该ç»çç¶æä¸å¯å
¥åº!"); |
| | | } |
| | | if (!string.IsNullOrEmpty(stockInfo.LocationCode)) |
| | | { |
| | | return (false, "该æçå·²ç»å®è´§ä½!"); |
| | | } |
| | | if (stockInfo.Details == null || stockInfo.Details.Count == 0) |
| | | { |
| | | return (false, "没æåºåæç»ä¿¡æ¯!"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (_stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == palletCode) != null) |
| | | { |
| | | return (false, "该æçå·²åå¨åºå
!"); |
| | | } |
| | | } |
| | | |
| | | return (true, "æå!"); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |