| | |
| | | _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(); |
| | | //å¦æè®¢åç¸åãååä¸è´å¹¶ä¸åé
æ°éå°äºç åç»ææ°éååé
å°ä¸èµ· |
| | | _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); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(barCode, packaxisTask); |
| | | return content.Error($"æªæ¾å°æ¡ç {barCode}"); |
| | | } |
| | | catch (Exception ex) |
| | | 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(); |
| | | //å¦æè®¢åç¸åãååä¸è´å¹¶ä¸åé
æ°éå°äºç åç»ææ°éååé
å°ä¸èµ· |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (stationPackInfo != null) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | 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); |
| | | |
| | | } |
| | | return content; |
| | | 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); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(barCode, packaxisTask); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// ç åç»æå¹¶ä¸ä¼ ç åå·¥ä½ç åæç»æ°æ® |