From 7a4c218909936721fe281737491d10efc7378e09 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 19 七月 2024 17:53:30 +0800
Subject: [PATCH] 优化工单信息页面

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/OutboundTask.cs |  290 +++++++++++++++++----------------------------------------
 1 files changed, 89 insertions(+), 201 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/OutboundTask.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/OutboundTask.cs"
index 0f45587..ca16830 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/OutboundTask.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/OutboundTask.cs"
@@ -30,39 +30,43 @@
             {
                 VOLContext context = new VOLContext();
                 Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
-                Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(context);
-                Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(context);
                 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_heads = mes_HeadRepository.Find(x => x.processCode == "28").OrderBy(x => x.expectedStartTime).ToList();
-                //var mes_heads = mes_HeadRepository.Find(x => x.processCode == "28").OrderByDescending(x => x.CreateTime).ToList();
-                foreach (var mes_head in mes_heads)
+                var Mes_Works = workinfoRepository.Find(x => x.processCode == "28").OrderByDescending(x => x.CreateTime).ToList();
+                foreach (var Mes_Work in Mes_Works)
                 {
-                    #region 鏍规嵁搴撳瓨鍏ュ簱鏃堕棿鏈�鏅氭煡璇�
-                    var inventory = inventoryRepository.Find(x => x.FigureNumber == mes_head.drawingNo).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
+                    var inventory = inventoryRepository.Find(x => x.SN == Mes_Work.SN).FirstOrDefault();
                     if (inventory != null)
                     {
-                        var Station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
+                        var Station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();//鏌ユ壘搴撳瓨璐т綅
                         if (Station != null)
                         {
-                            #region 瀛樺湪鍏ュ簱浠诲姟涓嶈兘鍑哄簱
-                            var InTask = stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.location_state == LocationStateEnum.InBusy.ToString()).Any();
-                            if (InTask) continue;
-                            #endregion
-                            var stationinfo = stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.enable && x.location_state == LocationStateEnum.Stroge.ToString()).OrderByDescending(x => x.column).FirstOrDefault();
+
+                            #region 
+
+                            dt_stationinfo stationinfo = null;
+                            //鏌ユ壘褰撳墠璐т綅鍚岃鏄惁瀛樺湪鍏ュ簱浠诲姟
+                            if (GetStation.InBusyStation(Station.stationCode)) 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 (agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).Any()) continue;
+
+                                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;
-                                    //throw new Exception(stationinfo.stationCode + "杞﹁疆SN鍙蜂俊鎭紓甯�!");
                                 }
-                                if (agvtaskRepository.Find(x => x.agv_fromaddress == stationinfo.stationCode).Any())
-                                    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)
@@ -70,196 +74,81 @@
                                     if (!string.IsNullOrEmpty(SN))
                                         lists.Add(SN);
                                 }
-                                foreach (var item in lists)
-                                {
-                                    //var a = mes_DetailRepository.Find(x => x.jobID == mes_head.jobID /*&& x.SN == item*/).ToList();
-                                    //var b = a.Where(x => x.SN == item).FirstOrDefault();
 
-                                    if (mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN == item).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");
-                                        return;
-                                    }
-                                }
-                            }
-                            var stationinfos = stationinfoRepository.Find(x => x.stationType == mes_head.drawingNo && x.line != Station.line && x.area == Station.area && x.location_state == "Stroge").OrderBy(x => x.line).ThenByDescending(x => x.column).ToList();
-                            foreach (var item in stationinfos)
-                            {
-                                if (item != null && stationinfo.enable)
+                                #region 璐т綅杞﹁疆鍏ㄩ儴鍖呭惈鍦ㄥ伐鍗曞唴鍒欎笅鍙戜换鍔�
+                                var count = 0;
+                                foreach (var SN in lists)
                                 {
-                                    if (item.bindSN == null)
-                                    {
-                                        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);
-                                    }
-                                    foreach (var list in lists)
-                                    {
-                                        if (mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN == list).Any())
-                                        {
-                                            dt_agvtask agvtask = new dt_agvtask()
-                                            {
-                                                agv_fromaddress = stationinfo.stationCode,
-                                                agv_id = Guid.NewGuid(),
-                                                agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                                                agv_grade = 1,
-                                                agv_createtime = DateTime.Now,
-                                                agv_taskstate = "Queue",
-                                                agv_materielid = stationinfo.stationType,
-                                                agv_qty = stationinfo.quantity,
-                                                jobID = mes_head.jobID,
-                                                agv_tasktype = "TaskType_Outbound",
-                                                agv_toaddress = "",
-                                                agv_userid = "绯荤粺",
-                                                bindSN = stationinfo.bindSN,
-                                                agv_worktype = Convert.ToInt32(mes_head.processCode),
-                                                agv_materbarcode = mes_head.materialCode,
-                                                agv_Traytype = stationinfo.tray_type,
-                                                agv_TrayStatus = stationinfo.tray_status
-                                            };
-                                            WriteDBLog.Success("鍒涘缓鍑哄簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
-                                            agvtaskRepository.Add(agvtask, true);
-                                            return;
-                                        }
-                                    }
-                                }
-                            }
+                                    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++;
 
-                            #region MyRegion
-                            //if (stationinfo != null && stationinfo.enable)
-                            //{
-                            //    if (stationinfo.bindSN == null)
-                            //        throw new Exception(stationinfo.stationCode + "杞﹁疆SN鍙蜂俊鎭紓甯�!");
-                            //    List<string> lists = new List<string>();
-                            //    var SNS = stationinfo.bindSN.Split(",");
-                            //    foreach (var SN in SNS)
-                            //    {
-                            //        if (!string.IsNullOrEmpty(SN))
-                            //            lists.Add(SN);
-                            //    }
-                            //    foreach (var item in lists)
-                            //    {
-                            //        if (freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mes_head.jobID && x.SN == item).Any())
-                            //        {
-                            //            dt_agvtask agvtask = new dt_agvtask()
-                            //            {
-                            //                agv_fromaddress = stationinfo.stationCode,
-                            //                agv_id = Guid.NewGuid(),
-                            //                agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                            //                agv_grade = 1,
-                            //                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,
-                            //                agv_worktype = Convert.ToInt32(mes_head.processCode),
-                            //                agv_materbarcode = mes_head.materialCode,
-                            //                agv_Traytype = stationinfo.tray_type,
-                            //                agv_TrayStatus = stationinfo.tray_status
-                            //            };
-                            //            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);
-                            //            return;
-                            //        }
-                            //    }
-                            //}
+                                }
+                                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
                         }
                     }
-                    #endregion
-
-                    #region MyRegion
-                    //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 SNS = station.bindSN.Split(",");
-                    //    foreach (var SN in SNS)
-                    //    {
-                    //        if (!string.IsNullOrEmpty(SN))
-                    //            list.Add(SN);
-                    //    }
-                    //}
-                    //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);
-                    //}
-                    #endregion
-
                 }
             }
             catch (Exception ex)
@@ -267,6 +156,5 @@
                 WriteDBLog.Error("鍒涘缓鍑哄簱浠诲姟", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
             }
         }
-
     }
 }

--
Gitblit v1.9.3