| | |
| | | using WIDESEA_Core.BaseProvider; |
| | | using WIDESEA_Core.EFDbContext; |
| | | using WIDESEA_Entity.DomainModels; |
| | | using WIDESEA_Entity.ToAGV; |
| | | using WIDESEA_WCS.IRepositories; |
| | | using WIDESEA_WCS.Repositories; |
| | | using WIDESEA_WCS.WCSClient; |
| | | using WIDESEA_WMS.IRepositories; |
| | | using WIDESEA_WMS.IServices; |
| | | using WIDESEA_WMS.Repositories; |
| | | using static FreeSql.Internal.GlobalFilter; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | |
| | | namespace WIDESEA_WCS.JobsPart.Common |
| | | { |
| | |
| | | { |
| | | VOLContext Context = new VOLContext(); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context); |
| | | |
| | | IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context); |
| | | Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context); |
| | | var tasks = agvtaskService.Find(x => x.agv_taskstate == "Queue").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).ToList(); |
| | | foreach (var task in tasks) |
| | | { |
| | | if (task.agv_tasktype == "TaskType_EmptyPallet")//空æä»»å¡ |
| | | { |
| | | if (task.agv_fromaddress == "") |
| | | if (task.agv_fromaddress == "" && DateTime.Now - task.agv_createtime >= TimeSpan.FromMinutes(2)) |
| | | { |
| | | var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "龿¡æº"); |
| | | if (Pipeline_client == null) throw new Exception("龿¡æºè°åº¦æå¡æªå¼å¯ï¼"); |
| | | if (!Pipeline_client.IsConnected) throw new Exception("ä¸é¾æ¡æºè¿æ¥è¶
æ¶ï¼"); |
| | | var area = task.agv_Traytype == "SmallTray" ? "11" : "10"; |
| | | //æ¾1åºåºç空æä½ |
| | | var EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains("A") /*&& x.location_state == "Stroge"*//*LocationStateEnum.Stroge.ToString()*/ && x.enable).OrderBy(x => x.column).ThenBy(x => x.line).FirstOrDefault(); |
| | | if (EmptyStation != null) |
| | | if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) EmptyStation = null; |
| | | #region ä¸ä¸ªåºååªè½æä¸ä¸ªç©ºæä»»å¡ |
| | | //bool ok = false; |
| | | //if (EmptyStation != null) |
| | | // ok = agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any(); |
| | | //if (EmptyStation == null || ok) |
| | | // EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" /*LocationStateEnum.Stroge.ToString()*/ && x.enable) |
| | | // .OrderBy(x => x.line).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | #endregion |
| | | if (EmptyStation == null) |
| | | EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.enable).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | if (EmptyStation == null) continue; |
| | | #region åºå
åå¨ä»»å¡å ç¨ |
| | | if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) |
| | | continue; |
| | | #endregion |
| | | |
| | | if (EmptyStation == null) |
| | | EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" && x.enable).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | if (EmptyStation != null) |
| | | if (task.agv_tasknum.Contains("_")) |
| | | { |
| | | #region åºå
åå¨ä»»å¡å ç¨ |
| | | //if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) |
| | | // continue; |
| | | #endregion |
| | | string mainTaskNum = task.agv_tasknum.Split('_')[0]; |
| | | if (agvtaskService.Find(x => x.agv_tasknum == mainTaskNum && task.agv_taskstate != "Executing" && task.agv_taskstate != "Create").Any() || !agvtaskService.Find(x => x.agv_tasknum == mainTaskNum).Any()) |
| | | GetStation.EmptyPalletStation(task); |
| | | } |
| | | else |
| | | GetStation.EmptyPalletStation(task); |
| | | #region |
| | | //var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "龿¡æº"); |
| | | //if (Pipeline_client == null) throw new Exception("龿¡æºè°åº¦æå¡æªå¼å¯ï¼"); |
| | | //if (!Pipeline_client.IsConnected) throw new Exception("ä¸é¾æ¡æºè¿æ¥è¶
æ¶ï¼"); |
| | | //var area = task.agv_Traytype == "SmallTray" ? "11" : "10"; |
| | | ////æ¾1åºåºç空æä½ |
| | | //var EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains("A") /*&& x.location_state == "Stroge"*//*LocationStateEnum.Stroge.ToString()*/ && x.enable).OrderBy(x => x.column).ThenBy(x => x.line).FirstOrDefault(); |
| | | //if (EmptyStation != null) |
| | | // if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) EmptyStation = null; |
| | | //#region ä¸ä¸ªåºååªè½æä¸ä¸ªç©ºæä»»å¡ |
| | | ////bool ok = false; |
| | | ////if (EmptyStation != null) |
| | | //// ok = agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any(); |
| | | ////if (EmptyStation == null || ok) |
| | | //// EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" /*LocationStateEnum.Stroge.ToString()*/ && x.enable) |
| | | //// .OrderBy(x => x.line).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | //#endregion |
| | | //if (EmptyStation == null) |
| | | // EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.enable).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | //if (EmptyStation == null) continue; |
| | | //#region åºå
åå¨ä»»å¡å ç¨ |
| | | //if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) |
| | | // continue; |
| | | //#endregion |
| | | |
| | | //if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any()) |
| | | // return; |
| | | #region è¡¥åºå
空æçï¼ä¸éè¦å
çµå¤æ |
| | | var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", task.agv_toaddress);//读åæçä¿¡å·:1:æ,2æ |
| | | var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", task.agv_toaddress);//读åè´§ç©ä¿¡å·:1:æ,2æ |
| | | if (PalletSignal == 2 && MaterialSignal == 2) |
| | | { |
| | | task.agv_fromaddress = EmptyStation.stationCode; |
| | | task.StarQuantity = EmptyStation.quantity - 1; |
| | | task.agv_taskstate = "Create"; |
| | | agvtaskService.Update(task, true); |
| | | EmptyStation.location_state = LocationStateEnum.Busy.ToString(); |
| | | stationinfoRepository.Update(EmptyStation, true); |
| | | WriteDBLog.Success("æ´æ°ç©ºçéåä»»å¡", $"ä»»å¡ç¼å·ï¼{task.agv_tasknum}", "PCS"); |
| | | } |
| | | #endregion |
| | | //if (EmptyStation == null) |
| | | // EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" && x.enable).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | //if (EmptyStation != null) |
| | | //{ |
| | | // #region åºå
åå¨ä»»å¡å ç¨ |
| | | // //if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) |
| | | // // continue; |
| | | // #endregion |
| | | |
| | | // //if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any()) |
| | | // // return; |
| | | // #region è¡¥åºå
空æçï¼ä¸éè¦å
çµå¤æ |
| | | // var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", task.agv_toaddress);//读åæçä¿¡å·:1:æ,2æ |
| | | // var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", task.agv_toaddress);//读åè´§ç©ä¿¡å·:1:æ,2æ |
| | | // if (PalletSignal == 2 && MaterialSignal == 2) |
| | | // { |
| | | // task.agv_fromaddress = EmptyStation.stationCode; |
| | | // task.StarQuantity = EmptyStation.quantity - 1; |
| | | // task.agv_taskstate = "Create"; |
| | | // agvtaskService.Update(task, true); |
| | | // EmptyStation.location_state = LocationStateEnum.Busy.ToString(); |
| | | // stationinfoRepository.Update(EmptyStation, true); |
| | | // WriteDBLog.Success("æ´æ°ç©ºçéåä»»å¡", $"ä»»å¡ç¼å·ï¼{task.agv_tasknum}", "PCS"); |
| | | // } |
| | | // #endregion |
| | | //} |
| | | #endregion |
| | | } |
| | | } |
| | | else if (task.agv_tasktype == "TaskType_OutsourceInbound" || task.agv_tasktype == "TaskType_Inbound")//å¤ååºå
¥åº/ABåºå
¥åº |
| | | { |
| | | if (task.agv_toaddress == "") |
| | | { |
| | | var stationinfo = stationinfoRepository.Find(x => x.stationCode == task.agv_fromaddress).FirstOrDefault(); |
| | | var work = workinfoRepository.Find(x => x.workOrder == stationinfo.Number && x.drawingNo == stationinfo.stationType && x.heatID == stationinfo.heatNumber && x.processCode == "17").FirstOrDefault(); |
| | | var TargetLocation = task.agv_tasktype == "TaskType_Inbound" ? GetLocation.GetEmptyLocation(stationinfoRepository, work, stationinfo) : StationTask.GetEmptyLocation(stationinfoRepository); |
| | | if (TargetLocation != null) |
| | | { |
| | | if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue; |
| | | task.agv_taskstate = "Create"; |
| | | task.agv_toaddress = TargetLocation.stationCode; |
| | | TargetLocation.location_state = LocationStateEnum.InBusy.ToString(); |
| | | TargetLocation.billetID = stationinfo.billetID; |
| | | TargetLocation.stationType = task.agv_materielid; |
| | | TargetLocation.heatNumber = stationinfo.heatNumber; |
| | | TargetLocation.Number = task.jobID; |
| | | stationinfoRepository.Update(TargetLocation, true); |
| | | agvtaskService.Update(task, true); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | if (task.agv_toaddress == "") |
| | | { |
| | | var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && x.location_state == "Empty" && x.enable).ToList(); |
| | | var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && x.tray_status == "EmptyTray" /*x.location_state == "Empty"*/ && x.enable).ToList(); |
| | | foreach (var EmptyStation in EmptyStations) |
| | | { |
| | | if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue; |
| | |
| | | } |
| | | } |
| | | } |
| | | else if (task.agv_tasktype == "TaskType_OutsourceCarry")//å¤åç§»åº |
| | | else if (task.agv_tasktype == "TaskType_OutsourceCarry")//ç§»åºå¤å |
| | | { |
| | | if (task.agv_toaddress == "") |
| | | { |