| | |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | _stationMangerRepository = stationMangerRepository; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | private static object lock_reqPackTask = new object(); |
| | | /// <summary> |
| | | /// åé
ç åä»»å¡ |
| | | /// </summary> |
| | |
| | | /// <returns></returns> |
| | | public WebResponseContent ReqPackTask(string barCode,string deviceCode) |
| | | { |
| | | WebResponseContent content= new WebResponseContent(); |
| | | try |
| | | lock (lock_reqPackTask) |
| | | { |
| | | Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x=>x.BarCode==barCode && x.PackStatus==StationOccupiedEnum.None.ObjToInt()); |
| | | if (packinfo==null) |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | return content.Error($"æªæ¾å°æ¡ç {barCode}"); |
| | | } |
| | | List<Dt_StationPackInfo> stationPackInfos = _stationPackInfoRepository.QueryData(); |
| | | Dt_StationPackInfo? stationPackInfo=stationPackInfos.FirstOrDefault(x=>x.PackType==packinfo.PackType && x.OrderNo==packinfo.OrderNo && x.AssignNum<x.PackNum); |
| | | //å¦æè®¢åç¸åãååä¸è´å¹¶ä¸åé
æ°éå°äºç åç»ææ°éååé
å°ä¸èµ· |
| | | if (stationPackInfo!=null) |
| | | { |
| | | Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask() |
| | | Dt_Packinfo packinfo = _packinfoRepository.QueryFirst(x => x.BarCode == barCode && x.PackStatus == StationOccupiedEnum.None.ObjToInt()); |
| | | if (packinfo == null) |
| | | { |
| | | 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(); |
| | | //æ´æ°ç åæ§è¡å·¥ä½ |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | //æ´æ°å¾
ç åä¿¡æ¯è¡¨ |
| | | _packinfoRepository.UpdateData(packinfo); |
| | | //æ·»å ç åä»»å¡ |
| | | BaseDal.AddData(packaxisTask); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(barCode, 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.QueryData(x => x.PackType == packinfo.PackType); |
| | | if (packaxes.Count==0) |
| | | { |
| | | return content.Error("æªæ¾å°ç ååæ é
ç½®"); |
| | | return content.Error($"æªæ¾å°æ¡ç {barCode}"); |
| | | } |
| | | List<string> packStations = packaxes.Select(x => x.StationCode).ToList(); |
| | | Dt_StationPackInfo? packInfoAssign = stationPackInfos.Where(x => x.PackType == 0 && x.AssignNum == 0 && stations.Contains(x.StationCode) && packStations.Contains(x.StationCode)).OrderByDescending(x => x.StationCode).FirstOrDefault(); |
| | | if (packInfoAssign == null) |
| | | List<Dt_StationPackInfo> stationPackInfos = _stationPackInfoRepository.QueryData(); |
| | | Dt_StationPackInfo? stationPackInfo = stationPackInfos.FirstOrDefault(x => x.PackType == packinfo.PackType && x.OrderNo == packinfo.OrderNo && x.AssignNum < x.PackNum); |
| | | //å¦æè®¢åç¸åãååä¸è´å¹¶ä¸åé
æ°éå°äºç åç»ææ°éååé
å°ä¸èµ· |
| | | if (stationPackInfo != null) |
| | | { |
| | | return content.Error("æªæ¾å°å¯åé
åä½"); |
| | | 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(); |
| | | //æ´æ°ç åæ§è¡å·¥ä½ |
| | | _stationPackInfoRepository.UpdateData(stationPackInfo); |
| | | //æ´æ°å¾
ç åä¿¡æ¯è¡¨ |
| | | _packinfoRepository.UpdateData(packinfo); |
| | | //æ·»å ç åä»»å¡ |
| | | BaseDal.AddData(packaxisTask); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content.OK(barCode, packaxisTask); |
| | | } |
| | | 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; |
| | | Dt_PackaxisTask packaxisTask = new Dt_PackaxisTask() |
| | | else//åé
æ°å·¥ä½ |
| | | { |
| | | 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.OK(barCode, packaxisTask); |
| | | //è·åå½å空çåå¤çç åå·¥ä½ |
| | | 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.QueryData(x => x.PackType == packinfo.PackType && stations.Contains(x.StationCode)); |
| | | 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; |
| | | Dt_PackaxisTask 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.OK(barCode, packaxisTask); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | /// <summary> |
| | | /// ç åç»æå¹¶ä¸ä¼ ç åå·¥ä½ç åæç»æ°æ® |
| | |
| | | |
| | | >>>>>>> main |
| | | } |
| | | public class MDCount |
| | | { |
| | | public string MDNo { get; set; } |
| | | |
| | | public int Count { get; set; } |
| | | } |
| | | } |