| | |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | private static object lock_reqPackTask = new object(); |
| | | /// <summary> |
| | | /// åé
ç åä»»å¡ |
| | | /// </summary> |
| | |
| | | /// <returns></returns> |
| | | public WebResponseContent ReqPackTask(string barCode,string deviceCode) |
| | | { |
| | | lock (lock_reqPackTask) |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x => x.BarCode == barCode && x.PackStatus == StationOccupiedEnum.None.ObjToInt()); |
| | | if (packinfo == null) |
| | | { |
| | | Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x => x.BarCode == barCode && x.PackStatus == StationOccupiedEnum.None.ObjToInt()); |
| | | if (packinfo == null) |
| | | return content.Error($"æªæ¾å°æ¡ç {barCode}"); |
| | | } |
| | | List<Dt_StationPackInfo> stationPackInfos = _stationPackInfoRepository.Db.Queryable<Dt_StationPackInfo>().ToList(); |
| | | Dt_StationPackInfo? stationPackInfo = stationPackInfos.FirstOrDefault(x => x.PackType == packinfo.PackType && x.OrderNo == packinfo.OrderNo && x.AssignNum < x.PackNum); |
| | | Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask(); |
| | | //å¦æè®¢åç¸åãååä¸è´å¹¶ä¸åé
æ°éå°äºç åç»ææ°éååé
å°ä¸èµ· |
| | | if (stationPackInfo != null) |
| | | { |
| | | packaxisTask = new Dt_PackaxisTask() |
| | | { |
| | | return content.Error($"æªæ¾å°æ¡ç {barCode}"); |
| | | } |
| | | List<Dt_StationPackInfo> stationPackInfos = _stationPackInfoRepository.Db.Queryable<Dt_StationPackInfo>().ToList(); |
| | | Dt_StationPackInfo? stationPackInfo = stationPackInfos.FirstOrDefault(x => x.PackType == packinfo.PackType && x.OrderNo == packinfo.OrderNo && x.AssignNum < x.PackNum); |
| | | Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask(); |
| | | //å¦æè®¢åç¸åãååä¸è´å¹¶ä¸åé
æ°éå°äºç åç»ææ°éååé
å°ä¸èµ· |
| | | DeviceCode = deviceCode, |
| | | SourceAddress = "2421", |
| | | BarCode = barCode, |
| | | CurrentAddress = "2421", |
| | | TargetAddress = stationPackInfo.StationCode, |
| | | NextAddress = stationPackInfo.LineCode, |
| | | TaskState = TaskStatusEnum.Line_Executing.ObjToInt(), |
| | | PackLength = packinfo.Length, |
| | | PackWidth = packinfo.Width, |
| | | PackHeight = packinfo.Height, |
| | | PackType = packinfo.PackType, |
| | | Dispatchertime = DateTime.Now, |
| | | }; |
| | | stationPackInfo.AssignNum += 1; |
| | | stationPackInfo.ExecutingNum += 1; |
| | | packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stationPackInfo != null) |
| | | { |
| | | packaxisTask = new Dt_PackaxisTask() |
| | | { |
| | | DeviceCode = deviceCode, |
| | | SourceAddress = "2421", |
| | | BarCode = barCode, |
| | | CurrentAddress = "2421", |
| | | TargetAddress = stationPackInfo.StationCode, |
| | | NextAddress = stationPackInfo.LineCode, |
| | | TaskState = TaskStatusEnum.Line_Executing.ObjToInt(), |
| | | PackLength = packinfo.Length, |
| | | PackWidth = packinfo.Width, |
| | | PackHeight = packinfo.Height, |
| | | PackType = packinfo.PackType, |
| | | Dispatchertime = DateTime.Now, |
| | | }; |
| | | stationPackInfo.AssignNum += 1; |
| | | stationPackInfo.ExecutingNum += 1; |
| | | packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt(); |
| | | |
| | | //æ´æ°ç åæ§è¡å·¥ä½ |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | //æ´æ°å¾
ç åä¿¡æ¯è¡¨ |
| | | _packinfoRepository.UpdateData(packinfo); |
| | | //æ·»å ç åä»»å¡ |
| | | BaseDal.AddData(packaxisTask); |
| | | |
| | | } |
| | | else//åé
æ°å·¥ä½ |
| | | { |
| | | //è·åå½å空çåå¤çç åå·¥ä½ |
| | | List<string> stations = _stationMangerRepository.QueryData(x => x.StationDeviceCode == "CLC_CP" && x.IsOccupied == StationOccupiedEnum.None.ObjToInt()).Select(x => x.StationCode).ToList(); |
| | | //è·åç åé
置表æ¥è¯¢å¯åé
å¹¶å·²é
ç½®çç åå·¥ä½ |
| | | List<Dt_Packaxis> packaxes = _packaxisRepository.Db.Queryable<Dt_Packaxis>().Where(x => x.PackType == packinfo.PackType && stations.Contains(x.StationCode)).ToList(); |
| | | if (packaxes.Count == 0) |
| | | { |
| | | return content.Error("æªæ¾å°å¯åé
ç åé
ç½®"); |
| | | } |
| | | List<string> packStations = packaxes.Select(x => x.StationCode).ToList(); |
| | | Dt_StationPackInfo? packInfoAssign = stationPackInfos.Where(x => x.PackType == 0 && x.AssignNum == 0 && packStations.Contains(x.StationCode)).OrderBy(x => x.OrderIndex).FirstOrDefault(); |
| | | if (packInfoAssign == null) |
| | | { |
| | | return content.Error("æªæ¾å°å¯åé
åä½"); |
| | | } |
| | | packInfoAssign.PackType = packinfo.PackType; |
| | | packInfoAssign.OrderNo = packinfo.OrderNo; |
| | | packInfoAssign.MakeCode = packinfo.MakeCode; |
| | | packInfoAssign.MaterielCode = packInfoAssign.MaterielCode; |
| | | packInfoAssign.PackNum = packaxes.FirstOrDefault(x => x.StationCode == packInfoAssign.StationCode).PackNum; |
| | | packaxisTask = new Dt_PackaxisTask() |
| | | { |
| | | DeviceCode = deviceCode, |
| | | SourceAddress = "2421", |
| | | BarCode = barCode, |
| | | CurrentAddress = "2421", |
| | | TargetAddress = packInfoAssign.StationCode, |
| | | NextAddress = packInfoAssign.LineCode, |
| | | TaskState = TaskStatusEnum.Line_Executing.ObjToInt(), |
| | | PackLength = packinfo.Length, |
| | | PackWidth = packinfo.Width, |
| | | PackHeight = packinfo.Height, |
| | | PackType = packinfo.PackType, |
| | | Dispatchertime = DateTime.Now, |
| | | }; |
| | | packInfoAssign.AssignNum += 1; |
| | | packInfoAssign.ExecutingNum += 1; |
| | | packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt(); |
| | | //æ´æ°ç åæ§è¡å·¥ä½ |
| | | _stationPackInfoRepository.UpdateData(packInfoAssign); |
| | | //æ´æ°å¾
ç åä¿¡æ¯è¡¨ |
| | | _packinfoRepository.UpdateData(packinfo); |
| | | //æ·»å ç åä»»å¡ |
| | | BaseDal.AddData(packaxisTask); |
| | | } |
| | | //æ´æ°ç åæ§è¡å·¥ä½ |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | //æ´æ°å¾
ç åä¿¡æ¯è¡¨ |
| | | _packinfoRepository.UpdateData(packinfo); |
| | | //æ·»å ç åä»»å¡ |
| | | BaseDal.AddData(packaxisTask); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(barCode, packaxisTask); |
| | | } |
| | | catch (Exception ex) |
| | | else//åé
æ°å·¥ä½ |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | //è·åå½å空çåå¤çç åå·¥ä½ |
| | | List<string> stations = _stationMangerRepository.QueryData(x => x.StationDeviceCode == "CLC_CP" && x.IsOccupied == StationOccupiedEnum.None.ObjToInt()).Select(x => x.StationCode).ToList(); |
| | | //è·åç åé
置表æ¥è¯¢å¯åé
å¹¶å·²é
ç½®çç åå·¥ä½ |
| | | List<Dt_Packaxis> packaxes = _packaxisRepository.Db.Queryable<Dt_Packaxis>().Where(x => x.PackType == packinfo.PackType && stations.Contains(x.StationCode)).ToList(); |
| | | if (packaxes.Count == 0) |
| | | { |
| | | return content.Error("æªæ¾å°å¯åé
ç åé
ç½®"); |
| | | } |
| | | List<string> packStations = packaxes.Select(x => x.StationCode).ToList(); |
| | | Dt_StationPackInfo? packInfoAssign = stationPackInfos.Where(x => x.PackType == 0 && x.AssignNum == 0 && packStations.Contains(x.StationCode)).OrderBy(x => x.OrderIndex).FirstOrDefault(); |
| | | if (packInfoAssign == null) |
| | | { |
| | | return content.Error("æªæ¾å°å¯åé
åä½"); |
| | | } |
| | | Dt_Packaxis packaxis = packaxes.FirstOrDefault(x => x.StationCode == packInfoAssign.StationCode); |
| | | packInfoAssign.PackType = packinfo.PackType; |
| | | packInfoAssign.OrderNo = packinfo.OrderNo; |
| | | packInfoAssign.MakeCode = packinfo.MakeCode; |
| | | packInfoAssign.MaterielCode = packInfoAssign.MaterielCode; |
| | | packInfoAssign.PackNum = packaxis.PackNum; |
| | | //计ç®ç åå®çé«åº¦ |
| | | packInfoAssign.HeightNum = packaxis.AxisZCount * packaxis.AxisZSpacing + 200; |
| | | packaxisTask = new Dt_PackaxisTask() |
| | | { |
| | | DeviceCode = deviceCode, |
| | | SourceAddress = "2421", |
| | | BarCode = barCode, |
| | | CurrentAddress = "2421", |
| | | TargetAddress = packInfoAssign.StationCode, |
| | | NextAddress = packInfoAssign.LineCode, |
| | | TaskState = TaskStatusEnum.Line_Executing.ObjToInt(), |
| | | PackLength = packinfo.Length, |
| | | PackWidth = packinfo.Width, |
| | | PackHeight = packinfo.Height, |
| | | PackType = packinfo.PackType, |
| | | Dispatchertime = DateTime.Now, |
| | | }; |
| | | packInfoAssign.AssignNum += 1; |
| | | packInfoAssign.ExecutingNum += 1; |
| | | packinfo.PackStatus = StationOccupiedEnum.Sure.ObjToInt(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | //æ´æ°ç åæ§è¡å·¥ä½ |
| | | _stationPackInfoRepository.UpdateData(packInfoAssign); |
| | | //æ´æ°å¾
ç åä¿¡æ¯è¡¨ |
| | | _packinfoRepository.UpdateData(packinfo); |
| | | //æ·»å ç åä»»å¡ |
| | | BaseDal.AddData(packaxisTask); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | return content; |
| | | |
| | | return content.OK(barCode, packaxisTask); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// ç åç»æå¹¶ä¸ä¼ ç åå·¥ä½ç åæç»æ°æ® |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_StationPackInfo stationPackInfo = _stationPackInfoRepository.QueryFirst(x => x.StationCode == stationCode); |
| | | Dt_StationPackInfo stationPackInfo = _stationPackInfoRepository.Db.Queryable<Dt_StationPackInfo>().Where(x => x.StationCode == stationCode).Includes(x=>x.stationPackDetails).First(); |
| | | if (stationPackInfo.OverNum != stationPackInfo.AssignNum) |
| | | { |
| | | throw new Exception($"åé
æ°é{stationPackInfo.AssignNum}ï¼å®ææ°é{stationPackInfo.OverNum}æ°éä¸ç¬¦"); |
| | | } |
| | | List<Dt_StationPackDetail> stationPackDetails = _stationPackDetailRepository.QueryData(x => x.StationPackId == stationPackInfo.id); |
| | | List<Dt_StationPackDetail> stationPackDetails = stationPackInfo.stationPackDetails; |
| | | if (stationPackDetails.Count <= 0) |
| | | { |
| | | throw new Exception($"{stationCode}æªæ¾å°ç åæç»"); |
| | | } |
| | | List<string> barCodes = stationPackDetails.Select(x => x.BoxCode).ToList(); |
| | | List<Dt_Packinfo> packinfos = _packinfoRepository.QueryData(x => barCodes.Contains(x.BarCode)).ToList(); |
| | | List<Dt_Packinfo> packinfos = _packinfoRepository.QueryData(x => barCodes.Contains(x.BarCode) && x.PackStatus== StationOccupiedEnum.Sure.ObjToInt()).ToList(); |
| | | if (packinfos.Count != barCodes.Count) |
| | | { |
| | | throw new Exception($"ç åä¿¡æ¯ä¸å®é
ä¸ç¬¦ï¼ç åä¿¡æ¯æ°é{packinfos.Count},å®é
æ°é{barCodes.Count}"); |
| | | } |
| | | int heightNum = stationPackInfo.HeightNum; |
| | | stationPackInfo.PackType = 0; |
| | | stationPackInfo.OrderNo = ""; |
| | | stationPackInfo.MakeCode = ""; |
| | |
| | | stationPackInfo.OverNum = 0; |
| | | stationPackInfo.AssignNum = 0; |
| | | stationPackInfo.ExecutingNum = 0; |
| | | stationPackInfo.HeightNum = 0; |
| | | _unitOfWorkManage.BeginTran(); |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | _stationPackDetailRepository.DeleteData(stationPackDetails); |
| | | _packinfoRepository.DeleteAndMoveIntoHty(packinfos, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | //忥å°WMS |
| | | string address = AppSettings.Get("WMSApiAddress"); |
| | | string response = HttpHelper.Post($"{address}/api/Task/BoxingInBound?stationCode=" + stationCode, barCodes.Serialize()); |
| | | WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(response) ?? throw new Exception($"æªæ¶å°è¿åç»æ"); |
| | | if (!responseContent.Status) |
| | | { |
| | | throw new Exception(responseContent.Message); |
| | | } |
| | | //string address = AppSettings.Get("WMSApiAddress"); |
| | | //string response = HttpHelper.Post($"{address}/api/Task/BoxingInBound?stationCode={stationCode}&heightNum={heightNum}", barCodes.Serialize()); |
| | | //WebResponseContent? responseContent = JsonConvert.DeserializeObject<WebResponseContent>(response) ?? throw new Exception($"æªæ¶å°è¿åç»æ"); |
| | | //if (!responseContent.Status) |
| | | //{ |
| | | // throw new Exception(responseContent.Message); |
| | | //} |
| | | _unitOfWorkManage.CommitTran(); |
| | | content.OK(); |
| | | } |
| | |
| | | } |
| | | return content; |
| | | } |
| | | private readonly static object lockerCompleted = new object(); |
| | | /// <summary> |
| | | /// ç åä»»å¡å®æ |
| | | /// </summary> |
| | |
| | | /// <returns></returns> |
| | | public WebResponseContent TaskCompleted(int taskNum=0,Dt_PackaxisTask? packaxisTask=null) |
| | | { |
| | | try |
| | | lock (lockerCompleted) |
| | | { |
| | | |
| | | Dt_PackaxisTask? packaxisTaskFinish = null; |
| | | if (packaxisTask!=null) |
| | | try |
| | | { |
| | | packaxisTaskFinish= packaxisTask; |
| | | } |
| | | else |
| | | { |
| | | packaxisTaskFinish = BaseDal.QueryFirst(x => x.PackTaskNum == taskNum); |
| | | packaxisTaskFinish.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | } |
| | | if (packaxisTaskFinish != null) |
| | | { |
| | | Dt_StationPackInfo stationPackInfo = _stationPackInfoRepository.QueryFirst(x => x.StationCode == packaxisTaskFinish.TargetAddress); |
| | | stationPackInfo.ExecutingNum -= 1; |
| | | stationPackInfo.OverNum += 1; |
| | | Dt_StationPackDetail stationPackDetail = new Dt_StationPackDetail() |
| | | Dt_PackaxisTask? packaxisTaskFinish = null; |
| | | if (packaxisTask != null) |
| | | { |
| | | StationPackId = stationPackInfo.id, |
| | | BoxCode = packaxisTaskFinish.BarCode |
| | | }; |
| | | _unitOfWorkManage.BeginTran(); |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | _stationPackDetailRepository.AddData(stationPackDetail); |
| | | BaseDal.DeleteAndMoveIntoHty(packaxisTaskFinish, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | packaxisTaskFinish = packaxisTask; |
| | | } |
| | | else |
| | | { |
| | | packaxisTaskFinish = BaseDal.QueryFirst(x => x.PackTaskNum == taskNum); |
| | | } |
| | | if (packaxisTaskFinish != null) |
| | | { |
| | | Dt_StationPackInfo stationPackInfo = _stationPackInfoRepository.QueryFirst(x => x.StationCode == packaxisTaskFinish.TargetAddress); |
| | | stationPackInfo.ExecutingNum -= 1; |
| | | stationPackInfo.OverNum += 1; |
| | | Dt_StationPackDetail stationPackDetail = new Dt_StationPackDetail() |
| | | { |
| | | StationPackId = stationPackInfo.Id, |
| | | BoxCode = packaxisTaskFinish.BarCode |
| | | }; |
| | | packaxisTaskFinish.TaskState = TaskStatusEnum.Finish.ObjToInt(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | _stationPackDetailRepository.AddData(stationPackDetail); |
| | | BaseDal.DeleteAndMoveIntoHty(packaxisTaskFinish, App.User?.UserId == 0 ? OperateTypeEnum.èªå¨å®æ : OperateTypeEnum.äººå·¥å®æ); |
| | | _unitOfWorkManage.CommitTran(); |
| | | } |
| | | else |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡"); |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | else |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°ä»»å¡"); |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |