| | |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_Comm; |
| | | using WIDESEA_Core.FreeDB; |
| | | using WIDESEA_Comm.LogInfo; |
| | | using WIDESEA_Core.BaseProvider; |
| | | using WIDESEA_Core.EFDbContext; |
| | | using WIDESEA_Entity.DomainModels; |
| | | using WIDESEA_WCS.IRepositories; |
| | | using WIDESEA_WCS.Repositories; |
| | | using WIDESEA_WCS.WCSClient; |
| | | using WIDESEA_WMS.IRepositories; |
| | | using WIDESEA_WMS.IServices; |
| | | using WIDESEA_WMS.Repositories; |
| | | |
| | | namespace WIDESEA_WCS.JobsPart.Common |
| | | { |
| | | public class RestockHCJ |
| | | { |
| | | static FreeDB freeDB = new FreeDB(); |
| | | public static Dictionary<string, List<string>> areaForList; |
| | | public RestockHCJ() |
| | | { |
| | | if (areaForList == null || areaForList.Count == 0) |
| | | { |
| | | areaForList = new Dictionary<string, List<string>>(); |
| | | var stationList = freeDB.Select<dt_stationinfo>().Where(x => true).ToList(); |
| | | areaForList.Add("䏿åº", stationList.Where(x => x.stationCode.Contains("X")).Select(x => x.stationCode).ToList()); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ´æ°è¡¥ç©ºæä»»å¡ |
| | | /// æ´æ°éåä»»å¡ |
| | | /// </summary> |
| | | public static void HCJGetBarcode() |
| | | { |
| | | var tasks = freeDB.Select<dt_agvtask>().Where(x => x.agv_taskstate == "Queue").ToList(); |
| | | foreach (var task in tasks) |
| | | try |
| | | { |
| | | if (task.agv_tasktype == "TaskType_EmptyPallet")//空æä»»å¡ |
| | | VOLContext Context = new VOLContext(); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(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_fromaddress == "") |
| | | if (task.agv_tasktype == "TaskType_EmptyPallet")//空æä»»å¡ |
| | | { |
| | | var area = task.agv_Traytype == "SmallTray" ? "11" : "10"; |
| | | //æ¾1åºåºç空æä½ |
| | | var EmptyStation = freeDB.Select<dt_stationinfo>().Where(x => x.area == area && x.stationCode.Contains("A") && x.location_state == LocationStateEnum.Stroge.ToString() && x.enable) |
| | | .OrderByDescending(x => x.column).OrderBy(x => x.line).First(); |
| | | if (EmptyStation == null) |
| | | EmptyStation = freeDB.Select<dt_stationinfo>().Where(x => x.area == area && x.stationCode.Contains("C") && x.location_state == LocationStateEnum.Stroge.ToString() && x.enable) |
| | | .OrderBy(x => x.line).OrderByDescending(x => x.column).First(); |
| | | if (EmptyStation != null) |
| | | if (task.agv_fromaddress == "") |
| | | { |
| | | task.agv_fromaddress = EmptyStation.stationCode; |
| | | task.agv_taskstate = "Create"; |
| | | freeDB.Update(task); |
| | | 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) |
| | | { |
| | | #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 |
| | | } |
| | | } |
| | | } |
| | | else if (task.agv_tasktype == "TaskType_OutsourceOutbound" || task.agv_tasktype == "TaskType_Outbound")//å¤ååºåºåº/ABåºåºåº |
| | | { |
| | | if (task.agv_toaddress == "") |
| | | { |
| | | var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && x.location_state == "Empty" && x.enable).ToList(); |
| | | foreach (var EmptyStation in EmptyStations) |
| | | { |
| | | if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue; |
| | | task.agv_taskstate = "Create"; |
| | | task.agv_toaddress = EmptyStation.stationCode; |
| | | EmptyStation.location_state = LocationStateEnum.Busy.ToString(); |
| | | stationinfoRepository.Update(EmptyStation, true); |
| | | agvtaskService.Update(task, true); |
| | | WriteDBLog.Success("æ´æ°åºåºéåä»»å¡", $"ä»»å¡ç¼å·ï¼{task.agv_tasknum}", "PCS"); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | else if (task.agv_tasktype == "TaskType_OutsourceCarry")//å¤åç§»åº |
| | | { |
| | | if (task.agv_toaddress == "") |
| | | { |
| | | var TargetLocation = 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.OutBusy.ToString(); |
| | | TargetLocation.stationType = task.agv_materielid; |
| | | stationinfoRepository.Update(TargetLocation, true); |
| | | agvtaskService.Update(task, true); |
| | | WriteDBLog.Success("æ´æ°åºåºéåä»»å¡", $"ä»»å¡ç¼å·ï¼{task.agv_tasknum}", "PCS"); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WriteDBLog.Error("æ´æ°éåä»»å¡", $"é误信æ¯ï¼{ex.Message}", "PCS"); |
| | | } |
| | | } |
| | | } |
| | | } |