| | |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO; |
| | | using WIDESEA_DTO.ERP; |
| | | using WIDESEA_DTO.MES; |
| | | using WIDESEA_ITaskInfoRepository; |
| | | using WIDESEA_ITaskInfoService; |
| | | using WIDESEA_Model.Models; |
| | |
| | | using WIDESEA_DTO.Stock; |
| | | using SqlSugar; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | using WIDESEA_DTO.MES; |
| | | using WIDESEA_External.Model; |
| | | using System.Text.Json; |
| | | using System.Text.RegularExpressions; |
| | | using WIDESEA_Common.MaterielEnum; |
| | | using MailKit.Search; |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | | public partial class TaskService |
| | | { |
| | | static object lock_out = new object(); |
| | | static object lock_autoIssue = new object(); |
| | | static object lock_manualIssue = new object(); |
| | | static object lock_returnIssue = new object(); |
| | | /// <summary> |
| | | /// MESèªå¨å«ææ¥å£ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ReceiveAutoIssue(MESAutoIssueDTO autoIssueDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | lock (lock_autoIssue) |
| | | { |
| | | if (autoIssueDTO == null) |
| | | { |
| | | return content.Error("ä¼ å
¥ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | //è·å对åºåæ® |
| | | Dt_OutMESOrder? outMESOrder = _outboundRepository.OutMESOrderRepository.QueryFirst(x => x.OutDetailId == autoIssueDTO.OutDetailId); |
| | | if (outMESOrder == null) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(MESAutoIssueDTO.OutDetailId)}{autoIssueDTO.OutDetailId}ä¸åå¨"); |
| | | } |
| | | if (outMESOrder.OutMESOrderStatus == OutOrderStatusEnum.åºåºå®æ.ObjToInt()) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(MESAutoIssueDTO.OutDetailId)}{outMESOrder.ProductOrderNo}å·¥åå·²åºåºå®æ"); |
| | | } |
| | | //è·åå¨è½¬ä½ç½®ç¼å· |
| | | Dt_AGVStationInfo? stationInfo = _basicRepository.AGVStationInfoRepository.QueryFirst(x => x.MESPointCode == autoIssueDTO.PointCode); |
| | | if (stationInfo == null) |
| | | { |
| | | return content.Error($"é¢æè®¡åå¨è½¬ä½{nameof(MESAutoIssueDTO.PointCode)}{autoIssueDTO.PointCode}ä¸åå¨"); |
| | | } |
| | | if (autoIssueDTO.IsEmptyPallet > 0) |
| | | { |
| | | return content.Error($"é¢æè®¡åå¨è½¬ä½{nameof(MESAutoIssueDTO.PointCode)}{autoIssueDTO.PointCode}åå¨ç©ºæ"); |
| | | } |
| | | Dt_Task? task = BaseDal.QueryData(x => x.OrderNo == outMESOrder.OutMESOrderNo && x.TaskStatus == TaskStatusEnum.CallPending.ObjToInt()).OrderByDescending(x => x.Grade).ThenBy(x => x.TaskNum).FirstOrDefault(); |
| | | //è·åä»»å¡ |
| | | if (task == null) |
| | | { |
| | | return content.Error($"æªæ¾å°é¢æè®¡åç¼å·{outMESOrder.ProductOrderNo}å¯é
éä»»å¡"); |
| | | } |
| | | //è·åä»»å¡åºåºè¯¦æ
|
| | | Dt_OutStockLockInfo outStockLockInfo = _outboundRepository.OutStockLockInfoRepository.QueryFirst(x => x.TaskNum == task.TaskNum); |
| | | //è°ç¨MESé
éåºåæä»¤ |
| | | PlanDistributionInfo planDistribution = new PlanDistributionInfo() |
| | | { |
| | | DispatchPlanMaterialId = autoIssueDTO.OutDetailId, |
| | | InvItemCode = task.MaterielCode, |
| | | Quantity = outStockLockInfo.AssignQuantity, |
| | | SendOutTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | ArrivalTime = DateTime.Now.AddMinutes(15).ToString("yyyy-MM-dd HH:mm:ss") |
| | | }; |
| | | MESDispatchModel dispatchModel = new MESDispatchModel() |
| | | { |
| | | PRO_DispachPlanDistributionInfos = new List<PlanDistributionInfo>() { planDistribution } |
| | | }; |
| | | _unitOfWorkManage.BeginTran(); |
| | | task.TaskStatus = TaskStatusEnum.New.ObjToInt(); |
| | | task.TargetAddress = autoIssueDTO.PointCode.StartsWith("YS") ? stationInfo.AGVStationCode : autoIssueDTO.PointCode; |
| | | BaseDal.UpdateData(task); |
| | | MESResponse mESResponse = _invokeMESService.MESDispatchUp(dispatchModel).DeserializeObject<MESResponse>() ?? throw new Exception("æªè·åå°è¿åä¿¡æ¯"); |
| | | if (!mESResponse.Result) |
| | | { |
| | | throw new Exception($"MESé
éåºåæ¥å£è°ç¨æ¥é,MESè¿åä¿¡æ¯{DecodeUnicode(mESResponse.Msg)}"); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | PushTasksToWCS(new List<Dt_Task> { task }); |
| | | return content.OK("嫿æå"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | //å°Unicodeè§£ææä¸æ |
| | | public static string DecodeUnicode(string input) |
| | | { |
| | | return Regex.Replace(input, @"\\u([0-9a-fA-F]{4})", match => { |
| | | return ((char)Convert.ToInt32(match.Groups[1].Value, 16)).ToString(); |
| | | }); |
| | | } |
| | | |
| | | public WebResponseContent ReceiveManualIssue(MESManualIssueDTO manualIssueDTO) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | lock (lock_manualIssue) |
| | | { |
| | | if (manualIssueDTO == null) |
| | | { |
| | | return content.Error("ä¼ å
¥ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | //è·å对åºåæ® |
| | | Dt_OutMESOrder? outMESOrder = _outboundRepository.OutMESOrderRepository.QueryFirst(x => x.OutDetailId == manualIssueDTO.OutDetailId); |
| | | if (outMESOrder == null) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(MESAutoIssueDTO.OutDetailId)}{manualIssueDTO.OutDetailId}ä¸åå¨"); |
| | | } |
| | | if (outMESOrder.OutMESOrderStatus == OutOrderStatusEnum.å
³é.ObjToInt()) |
| | | { |
| | | return content.Error($"é¢æè®¡å{nameof(MESAutoIssueDTO.OutDetailId)}{outMESOrder.ProductOrderNo}å·¥åå·²å
³é"); |
| | | } |
| | | //è·åå¨è½¬ä½ç½®ç¼å· |
| | | Dt_AGVStationInfo? stationInfo = _basicRepository.AGVStationInfoRepository.QueryFirst(x => x.MESPointCode == manualIssueDTO.PointCode); |
| | | if (stationInfo == null) |
| | | { |
| | | return content.Error($"é¢æè®¡åå¨è½¬ä½{nameof(MESAutoIssueDTO.PointCode)}{manualIssueDTO.PointCode}ä¸åå¨"); |
| | | } |
| | | Dt_Task? task = BaseDal.QueryData(x => x.OrderNo == outMESOrder.OutMESOrderNo && x.TaskStatus == TaskStatusEnum.CallPending.ObjToInt()).OrderByDescending(x => x.Grade).ThenBy(x => x.TaskNum).FirstOrDefault(); |
| | | //è·åä»»å¡ |
| | | if (task == null) |
| | | { |
| | | return content.Error($"æªæ¾å°é¢æè®¡åç¼å·{outMESOrder.ProductOrderNo}å¯é
éä»»å¡"); |
| | | } |
| | | //è·åä»»å¡åºåºè¯¦æ
|
| | | Dt_OutStockLockInfo outStockLockInfo = _outboundRepository.OutStockLockInfoRepository.QueryFirst(x => x.TaskNum == task.TaskNum); |
| | | //è°ç¨MESé
éåºåæä»¤ |
| | | PlanDistributionInfo planDistribution = new PlanDistributionInfo() |
| | | { |
| | | DispatchPlanMaterialId = manualIssueDTO.OutDetailId, |
| | | InvItemCode = task.MaterielCode, |
| | | Quantity = outStockLockInfo.AssignQuantity, |
| | | SendOutTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | ArrivalTime = DateTime.Now.AddMinutes(15).ToString("yyyy-MM-dd HH:mm:ss") |
| | | }; |
| | | MESDispatchModel dispatchModel = new MESDispatchModel() |
| | | { |
| | | PRO_DispachPlanDistributionInfos = new List<PlanDistributionInfo>() { planDistribution } |
| | | }; |
| | | _unitOfWorkManage.BeginTran(); |
| | | task.TaskStatus = TaskStatusEnum.New.ObjToInt(); |
| | | task.TargetAddress = manualIssueDTO.PointCode.StartsWith("YS") ? stationInfo.AGVStationCode : manualIssueDTO.PointCode; |
| | | BaseDal.UpdateData(task); |
| | | MESResponse mESResponse = _invokeMESService.MESDispatchUp(dispatchModel).DeserializeObject<MESResponse>() ?? throw new Exception("æªè·åå°è¿åä¿¡æ¯"); |
| | | if (!mESResponse.Result) |
| | | { |
| | | throw new Exception($"MESé
éåºåæ¥å£è°ç¨æ¥é,MESè¿åä¿¡æ¯{DecodeUnicode(mESResponse.Msg)}"); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | PushTasksToWCS(new List<Dt_Task> { task }); |
| | | return content.OK("嫿æå"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// MES空æ/使å¼å«æ¥å£ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ReceiveReturnIssue(List<MESReturnIssueDTO> returnIssueDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | lock (lock_returnIssue) |
| | | { |
| | | if (returnIssueDTOs == null || returnIssueDTOs.Count <= 0) |
| | | { |
| | | return content.Error("ä¼ å
¥ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | //è·åææAGVç¹ä½ |
| | | List<Dt_AGVStationInfo> aGVStationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => !string.IsNullOrEmpty(x.MESPointCode)); |
| | | MESReturnIssueDTO? returnIssueDTO = returnIssueDTOs.FirstOrDefault(x => !aGVStationInfos.Select(x => x.MESPointCode).Contains(x.PointCode)); |
| | | if (returnIssueDTO != null) |
| | | { |
| | | return content.Error($"å¨è½¬ä½{nameof(MESReturnIssueDTO.PointCode)}{returnIssueDTO.PointCode}ä¸åå¨"); |
| | | } |
| | | //è·åææåºå |
| | | List<Dt_StockInfo> stockInfosOld = _stockRepository.StockInfoRepository.QueryData(); |
| | | ////空æ |
| | | //foreach (var item in returnIssueDTOs.Where(x=>x.ReturnMaterial==null)) |
| | | //{ |
| | | |
| | | //} |
| | | //éæ |
| | | List<Dt_StockInfo> stockInfos=new List<Dt_StockInfo>(); |
| | | List<Dt_Task> tasksNew = new List<Dt_Task>(); |
| | | foreach (var item in returnIssueDTOs.Where(x => x.ReturnMaterial != null)) |
| | | { |
| | | MESReturnMaterial? returnMaterial = item.ReturnMaterial; |
| | | if (returnMaterial.BarCode.IsNullOrEmpty()) |
| | | { |
| | | return content.Error($"éæä¼ å
¥æ¡ç ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | Dt_AGVStationInfo aGVStationInfo = aGVStationInfos.FirstOrDefault(x => x.MESPointCode == item.PointCode); |
| | | Dt_MaterielInfo? materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterielCode == returnMaterial.MaterialCode); |
| | | if (materielInfo == null) |
| | | { |
| | | return content.Error($"æªæ¾å°æ¡ç {returnMaterial.BarCode}ç©æä¿¡æ¯"); |
| | | } |
| | | //夿 |
| | | if (returnMaterial.Thickness <= 0 && materielInfo.WarehouseId==WarehouseEnum.LLDYL.ObjToInt()) |
| | | { |
| | | return content.Error($"ç©æ{returnMaterial.MaterialCode}æ¡ç {returnMaterial.BarCode}ç´å¾ä¸è½å°äº0"); |
| | | } |
| | | if (returnMaterial.Wide <= 0 && materielInfo.WarehouseId == WarehouseEnum.LLDYL.ObjToInt()) |
| | | { |
| | | return content.Error($"ç©æ{returnMaterial.MaterialCode}æ¡ç {returnMaterial.BarCode}ç´å¾ä¸è½å°äº0"); |
| | | } |
| | | Dt_StockInfo? stockInfoOld = stockInfosOld.FirstOrDefault(x => x.PalletCode == returnMaterial.BarCode); |
| | | if (stockInfoOld != null) |
| | | { |
| | | return content.Error($"æ¡ç {returnMaterial.BarCode}ä¿¡æ¯å·²åå¨"); |
| | | } |
| | | //çæåºåç»çä¿¡æ¯ |
| | | Dt_StockInfo stockInfo = new Dt_StockInfo() |
| | | { |
| | | MaterielInvOrgId = materielInfo.MaterielInvOrgId, |
| | | PalletCode = returnMaterial.BarCode, |
| | | LocationCode = "", |
| | | PalletType = 1, |
| | | WarehouseId = materielInfo.WarehouseId, |
| | | StockAttribute = materielInfo.MaterielSourceType, |
| | | StockStatus = StockStatusEmun.MES使éåº.ObjToInt(), |
| | | MaterielSpec = materielInfo.MaterielSpec, |
| | | BatchNo = returnMaterial.MaterialLot, |
| | | Unit = materielInfo.MaterielUnit, |
| | | MaterielThickness = returnMaterial.Thickness, |
| | | MaterielWide = returnMaterial.Wide, |
| | | MaterielWeight = returnMaterial.Weight, |
| | | MaterielCode = materielInfo.MaterielCode, |
| | | StockLength = returnMaterial.ReturnQuantity, |
| | | OrderNo = returnMaterial.ReturnOrderNo, |
| | | MaterielName = materielInfo.MaterielName, |
| | | IsFull = WhetherEnum.True.ObjToInt(), |
| | | IsPick = returnMaterial.Whether == 0 ? WhetherEnum.True.ObjToInt() : WhetherEnum.False.ObjToInt(), |
| | | Remark = StockStatusEmun.MES使éåº.ToString() |
| | | }; |
| | | if (stockInfo.MaterielWide > 1200) |
| | | { |
| | | stockInfo.PalletType = 2; |
| | | } |
| | | stockInfos.Add(stockInfo); |
| | | //çæä½æéæä»»å¡ |
| | | Dt_Task newTask = new Dt_Task() |
| | | { |
| | | CurrentAddress = item.PointCode.StartsWith("YS") ? aGVStationInfo.AGVStationCode : item.PointCode, |
| | | Grade = 0, |
| | | NextAddress = "", |
| | | PalletCode = stockInfo.PalletCode, |
| | | Roadway = "", |
| | | SourceAddress = item.PointCode.StartsWith("YS") ? aGVStationInfo.AGVStationCode : item.PointCode, |
| | | TargetAddress = "", |
| | | TaskStatus = TaskStatusEnum.New.ObjToInt(), |
| | | WarehouseId = materielInfo.WarehouseId, |
| | | PalletType = stockInfo.PalletType, |
| | | MaterielCode=stockInfo.MaterielCode, |
| | | Quantity=stockInfo.StockLength, |
| | | OrderNo=stockInfo.OrderNo, |
| | | TaskLength = (int)stockInfo.MaterielWide, |
| | | GroupId= item.IssueId, |
| | | WorkCentreCode=item.MakeCode |
| | | }; |
| | | TaskTypeEnum taskTypeEnum = aGVStationInfo.StationArea switch |
| | | { |
| | | nameof(StationAreaEnum.䏿¥¼å°å·) => TaskTypeEnum.PrintYLBackInbound, |
| | | _ => throw new Exception("æªæ¾å°å¯¹åºä»»å¡") |
| | | }; |
| | | newTask.TaskType = taskTypeEnum.ObjToInt(); |
| | | tasksNew.Add(newTask); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.AddData(tasksNew); |
| | | _stockRepository.StockInfoRepository.AddData(stockInfos); |
| | | _unitOfWorkManage.CommitTran(); |
| | | //æ¨éä»»å¡ |
| | | PushTasksToWCS(tasksNew); |
| | | content.OK("å¼å«æå"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |