| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Comm; |
| | | using WIDESEA_Comm.LogInfo; |
| | | using WIDESEA_Comm.TaskNo; |
| | | using WIDESEA_Core.EFDbContext; |
| | | using WIDESEA_Core.FreeDB; |
| | | using WIDESEA_Core.Extensions; |
| | | using WIDESEA_Entity.DomainModels; |
| | | using WIDESEA_WCS.IRepositories; |
| | | using WIDESEA_WCS.Repositories; |
| | | using WIDESEA_WMS.IRepositories; |
| | | using WIDESEA_WMS.Repositories; |
| | | using static FreeSql.Internal.GlobalFilter; |
| | | using static System.Collections.Specialized.BitVector32; |
| | | |
| | |
| | | { |
| | | public class OutboundTask |
| | | { |
| | | static FreeDB freeDB = new FreeDB(); |
| | | /// <summary> |
| | | /// å建åºåºä»»å¡ |
| | | /// </summary> |
| | |
| | | { |
| | | VOLContext context = new VOLContext(); |
| | | Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); |
| | | var mes_heads = freeDB.Select<dt_mes_head>().Where(x => x.processCode == "28").OrderBy(x => x.expectedStartTime).ToList(); |
| | | foreach (var mes_head in mes_heads) |
| | | Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context); |
| | | Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context); |
| | | IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context); |
| | | |
| | | var Mes_Works = workinfoRepository.Find(x => x.processCode == "28").OrderBy(x => x.CreateTime).ToList(); |
| | | foreach (var Mes_Work in Mes_Works) |
| | | { |
| | | //var inventorys = freeDB.Select<dt_inventory>().Where(x => x.FigureNumber == mes_head.drawingNo).OrderBy.ToList(); |
| | | var station = stationinfoRepository.Find(x => x.stationType == mes_head.drawingNo && x.line != x.line).OrderBy(x => x.line).ThenByDescending(x => x.column).FirstOrDefault(); |
| | | bool ok = false; |
| | | List<string> list = new List<string>(); |
| | | if (station != null && station.location_state == LocationStateEnum.Stroge.ToString() && station.enable) |
| | | var inventory = inventoryRepository.Find(x => x.SN == Mes_Work.SN).FirstOrDefault(); |
| | | if (inventory != null) |
| | | { |
| | | var SNS = station.bindSN.Split(","); |
| | | foreach (var SN in SNS) |
| | | var Station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();//æ¥æ¾åºåè´§ä½ |
| | | if (Station != null) |
| | | { |
| | | if (!string.IsNullOrEmpty(SN)) |
| | | list.Add(SN); |
| | | |
| | | #region |
| | | |
| | | dt_stationinfo stationinfo = null; |
| | | if (Station.area == "1") |
| | | { |
| | | //æ¥æ¾å½åè´§ä½å忝å¦åå¨å
¥åºä»»å¡ |
| | | if (stationinfoRepository.Find(x => x.column == Station.column && x.area == "1" && x.location_state == LocationStateEnum.InBusy.ToString()).Any()) continue; |
| | | |
| | | stationinfo = stationinfoRepository.Find(x => x.column == Station.column && x.enable && x.area == "1" && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderBy(x => x.line).FirstOrDefault(); |
| | | } |
| | | else |
| | | { |
| | | //æ¥æ¾å½åè´§ä½å忝å¦åå¨å
¥åºä»»å¡ |
| | | if (stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.location_state == LocationStateEnum.InBusy.ToString()).Any()) continue; |
| | | |
| | | stationinfo = stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.enable && x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderByDescending(x => x.column).FirstOrDefault(); |
| | | } |
| | | if (stationinfo != null) |
| | | { |
| | | if (stationinfoRepository.Find(x => x.line == stationinfo.line && x.area == stationinfo.area && x.column > stationinfo.column && !x.enable).Any()) |
| | | continue; |
| | | if (string.IsNullOrEmpty(stationinfo.bindSN)) |
| | | { |
| | | stationinfo.remark = "车轮SNå·ä¿¡æ¯å¼å¸¸"; |
| | | stationinfo.location_state = "Abnormal"; |
| | | stationinfoRepository.Update(stationinfo, true); |
| | | continue; |
| | | } |
| | | |
| | | if (agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).Any()) continue; |
| | | |
| | | List<string> lists = new List<string>(); |
| | | var SNS = stationinfo.bindSN.Split(","); |
| | | foreach (var SN in SNS) |
| | | { |
| | | if (!string.IsNullOrEmpty(SN)) |
| | | lists.Add(SN); |
| | | } |
| | | |
| | | #region è´§ä½è½¦è½®å
¨é¨å
å«å¨å·¥åå
åä¸åä»»å¡ |
| | | var count = 0; |
| | | foreach (var SN in lists) |
| | | { |
| | | if (workinfoRepository.Find(x => x.processCode == "28" && x.SN == SN).Any()) count++; |
| | | //if (workinfoRepository.Find(x => x.processCode == "28" && x.SN.Contains(SN)).Any()) count++; |
| | | |
| | | } |
| | | if (count != lists.Count) continue; |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_fromaddress = stationinfo.stationCode, |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), |
| | | agv_grade = 2, |
| | | agv_createtime = DateTime.Now, |
| | | agv_taskstate = "Queue", |
| | | agv_materielid = stationinfo.stationType, |
| | | agv_qty = stationinfo.quantity, |
| | | agv_tasktype = "TaskType_Outbound", |
| | | agv_toaddress = "", |
| | | agv_userid = "ç³»ç»", |
| | | bindSN = stationinfo.bindSN, |
| | | jobID = Mes_Work.workOrder, |
| | | agv_worktype = Convert.ToInt32(Mes_Work.processCode), |
| | | agv_materbarcode = Mes_Work.materialCode, |
| | | agv_Traytype = stationinfo.tray_type, |
| | | agv_TrayStatus = stationinfo.tray_status |
| | | }; |
| | | stationinfo.location_state = LocationStateEnum.OutBusy.ToString(); |
| | | stationinfoRepository.Update(stationinfo, true); |
| | | agvtaskRepository.Add(agvtask, true); |
| | | WriteDBLog.Success("å建åºåºä»»å¡", $"ä»»å¡ç¼å·ï¼{agvtask.agv_tasknum}", "PCS"); |
| | | continue; |
| | | |
| | | #endregion |
| | | |
| | | #region è´§ä½è½¦è½®æä¸ä¸ªå
å«å¨å·¥åå
åä¸åä»»å¡ |
| | | //foreach (var SN in lists) |
| | | //{ |
| | | // if (mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN == SN).Any()) |
| | | // { |
| | | // dt_agvtask agvtask = new dt_agvtask() |
| | | // { |
| | | // agv_fromaddress = stationinfo.stationCode, |
| | | // agv_id = Guid.NewGuid(), |
| | | // agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), |
| | | // agv_grade = 2, |
| | | // agv_createtime = DateTime.Now, |
| | | // agv_taskstate = "Queue", |
| | | // agv_materielid = stationinfo.stationType, |
| | | // agv_qty = stationinfo.quantity, |
| | | // agv_tasktype = "TaskType_Outbound", |
| | | // agv_toaddress = "", |
| | | // agv_userid = "ç³»ç»", |
| | | // bindSN = stationinfo.bindSN, |
| | | // jobID = mes_head.jobID, |
| | | // agv_worktype = Convert.ToInt32(mes_head.processCode), |
| | | // agv_materbarcode = mes_head.materialCode, |
| | | // agv_Traytype = stationinfo.tray_type, |
| | | // agv_TrayStatus = stationinfo.tray_status |
| | | // }; |
| | | // stationinfo.location_state = LocationStateEnum.OutBusy.ToString(); |
| | | // stationinfoRepository.Update(stationinfo, true); |
| | | // agvtaskRepository.Add(agvtask, true); |
| | | // WriteDBLog.Success("å建åºåºä»»å¡", $"ä»»å¡ç¼å·ï¼{agvtask.agv_tasknum}", "PCS"); |
| | | // continue; |
| | | // } |
| | | //} |
| | | #endregion |
| | | } |
| | | #endregion |
| | | } |
| | | } |
| | | foreach (var SN in list) |
| | | { |
| | | if (ok = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mes_head.jobID && x.SN == SN).Any()) continue; |
| | | } |
| | | if (ok) |
| | | { |
| | | dt_agvtask agvtask = new dt_agvtask() |
| | | { |
| | | agv_fromaddress = station.stationCode, |
| | | agv_id = Guid.NewGuid(), |
| | | agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"), |
| | | agv_grade = 1, |
| | | agv_createtime = DateTime.Now, |
| | | agv_taskstate = "Queue", |
| | | agv_materielid = station.stationType, |
| | | agv_qty = station.quantity, |
| | | agv_tasktype = "TaskType_Outbound", |
| | | agv_toaddress = "", |
| | | agv_userid = "ç³»ç»", |
| | | bindSN = station.bindSN, |
| | | agv_worktype = Convert.ToInt32(mes_head.processCode), |
| | | agv_materbarcode = mes_head.materialCode, |
| | | agv_barcode = station.tray_type |
| | | }; |
| | | dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository); |
| | | if (TargetLocation != null) |
| | | { |
| | | agvtask.agv_taskstate = "Create"; |
| | | agvtask.agv_toaddress = TargetLocation.stationCode; |
| | | TargetLocation.location_state = LocationStateEnum.Busy.ToString(); |
| | | freeDB.Update(TargetLocation); |
| | | } |
| | | freeDB.Add(agvtask); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception) |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | throw; |
| | | WriteDBLog.Error("å建åºåºä»»å¡", $"é误信æ¯ï¼{ex.Message}", "PCS"); |
| | | } |
| | | } |
| | | private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository) |
| | | { |
| | | dt_stationinfo TargetLocation = null; |
| | | var stations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001")); |
| | | foreach (var station in stations) |
| | | { |
| | | TargetLocation = stationinfoRepository.FindFirst(x => x.stationCode == station.stationCode && x.location_state == LocationStateEnum.Empty.ToString() && x.enable); |
| | | if (TargetLocation != null) continue; |
| | | } |
| | | |
| | | if (TargetLocation == null) |
| | | { |
| | | throw new Exception("æ£æµçº¿ä¸æä½å·²æ»¡"); |
| | | } |
| | | return TargetLocation; |
| | | } |
| | | } |
| | | } |