| | |
| | | { |
| | | 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> |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (autoIssueDTO == null) |
| | | lock (lock_autoIssue) |
| | | { |
| | | return content.Error("ä¼ å
¥ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | 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 = stationInfo.AGVStationCode; |
| | | BaseDal.UpdateData(task); |
| | | MESResponse mESResponse = _invokeMESService.MESDispatchUp(dispatchModel).DeserializeObject<MESResponse>() ?? throw new Exception("æªè·åå°è¿åä¿¡æ¯"); |
| | | if (!mESResponse.Result) |
| | | { |
| | | throw new Exception($"MESé
éåºåæ¥å£è°ç¨æ¥é,MESè¿åä¿¡æ¯{DecodeUnicode(mESResponse.Msg)}"); |
| | | } |
| | | PushTasksToWCS(new List<Dt_Task> { task }); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK("嫿æå"); |
| | | } |
| | | //è·å对åºåæ® |
| | | 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(10).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 = stationInfo.AGVStationCode; |
| | | BaseDal.UpdateData(task); |
| | | MESResponse mESResponse = _invokeMESService.MESDispatchUp(dispatchModel).DeserializeObject<MESResponse>() ?? throw new Exception("æªè·åå°è¿åä¿¡æ¯"); |
| | | if (!mESResponse.Result) |
| | | { |
| | | throw new Exception($"MESé
éåºåæ¥å£è°ç¨æ¥é,MESè¿åä¿¡æ¯{DecodeUnicode(mESResponse.Msg)}"); |
| | | } |
| | | PushTasksToWCS(new List<Dt_Task> { task }); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK("嫿æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (manualIssueDTO == null) |
| | | lock (lock_manualIssue) |
| | | { |
| | | return content.Error("ä¼ å
¥ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | 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 = stationInfo.AGVStationCode; |
| | | BaseDal.UpdateData(task); |
| | | MESResponse mESResponse = _invokeMESService.MESDispatchUp(dispatchModel).DeserializeObject<MESResponse>() ?? throw new Exception("æªè·åå°è¿åä¿¡æ¯"); |
| | | if (!mESResponse.Result) |
| | | { |
| | | throw new Exception($"MESé
éåºåæ¥å£è°ç¨æ¥é,MESè¿åä¿¡æ¯{DecodeUnicode(mESResponse.Msg)}"); |
| | | } |
| | | PushTasksToWCS(new List<Dt_Task> { task }); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK("嫿æå"); |
| | | } |
| | | //è·å对åºåæ® |
| | | 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(10).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 = stationInfo.AGVStationCode; |
| | | BaseDal.UpdateData(task); |
| | | MESResponse mESResponse = _invokeMESService.MESDispatchUp(dispatchModel).DeserializeObject<MESResponse>() ?? throw new Exception("æªè·åå°è¿åä¿¡æ¯"); |
| | | if (!mESResponse.Result) |
| | | { |
| | | throw new Exception($"MESé
éåºåæ¥å£è°ç¨æ¥é,MESè¿åä¿¡æ¯{DecodeUnicode(mESResponse.Msg)}"); |
| | | } |
| | | PushTasksToWCS(new List<Dt_Task> { task }); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK("嫿æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// MES空æ/使å¼å«æ¥å£ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent ReceiveReturnIssue(List<MESReturnIssueDTO> returnIssueDTOs) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (returnIssueDTOs==null || returnIssueDTOs.Count<=0) |
| | | lock (lock_returnIssue) |
| | | { |
| | | return content.Error("ä¼ å
¥ä¿¡æ¯ä¸è½ä¸ºç©º"); |
| | | 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}ä¸åå¨"); |
| | | } |
| | | |
| | | content.OK("å¼å«æå"); |
| | | } |
| | | //è·åææ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}ä¸åå¨"); |
| | | } |
| | | content.OK("å¼å«æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |