分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-01 19c66ba052a7fb26c4d27deaa75ae46479eee342
´úÂë¹ÜÀí/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayTask.cs
@@ -48,7 +48,7 @@
                            agv_fromaddress = "",
                            agv_id = Guid.NewGuid(),
                            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                            agv_grade = 2,
                            agv_grade = station.stationCode.Contains("W0100100") ? 3 : 2,
                            agv_createtime = DateTime.Now,
                            agv_taskstate = "Queue",
                            agv_qty = 1,
@@ -81,41 +81,69 @@
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
                var stations = stationinfoRepository.Find(x => x.area == "2" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
                if (stations.Count < 1)
                {
                    stations = stationinfoRepository.Find(x => x.area == "3" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
                }
                var stations = stationinfoRepository.Find(x => x.stationCode.Contains("C01004") && x.enable && x.location_state == LocationStateEnum.Stroge.ToString()).OrderByDescending(x => x.column).ToList();
                //if (stations.Count < 1)
                //{
                //    stations = stationinfoRepository.Find(x => x.area == "3" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
                //}
                foreach (var station in stations)
                {
                    if (agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).Any())
                    if (agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode).Any())
                        continue;
                    dt_agvtask taskPart = new dt_agvtask()
                    {
                        agv_fromaddress = "",
                        agv_fromaddress = station.stationCode,
                        agv_id = Guid.NewGuid(),
                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
                        agv_grade = 2,
                        agv_grade = 1,
                        agv_createtime = DateTime.Now,
                        agv_taskstate = "Queue",
                        //agv_materielid = station.stationType,
                        agv_qty = 1,
                        StarQuantity = 0,
                        EndQuantity = 0,// EmptyStation.quantity,
                        agv_tasktype = "TaskType_EmptyPallet",
                        agv_toaddress = station.stationCode,
                        agv_toaddress = "",// EmptyStation.stationCode,
                        agv_userid = "系统",
                        agv_TrayStatus = "EmptyTray",// station.tray_status, "SmallTray" : "LargeTray"
                        agv_Traytype = station.area == "4" ? "LargeTray" : "SmallTray",
                        agv_TrayStatus = "EmptyTray",//station.tray_status,
                        agv_Traytype = station.tray_type,
                    };
                    agvtaskRepository.Add(taskPart, true);
                    station.location_state = LocationStateEnum.InBusy.ToString();
                    station.location_state = LocationStateEnum.OutBusy.ToString();
                    stationinfoRepository.Update(station, true);
                    WriteDBLog.Success("创建补库内空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
                    //WriteDBLog.Success("创建空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("创建补库内空托任务", $"错误信息:{ex.Message}", "PCS");
                //WriteDBLog.Error("创建补库内空托任务", $"错误信息:{ex.Message}", "PCS");
                //throw;
            }
        }
        public static void task()
        {
            VOLContext context = new VOLContext();
            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
            Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
            var tasks = agvtaskRepository.Find(x => x.agv_taskstate == "Queue").OrderBy(x => x.agv_createtime).ToList();
            foreach (var task in tasks)
            {
                if (task.agv_tasktype == "TaskType_EmptyPallet")
                {
                    if (task.agv_toaddress == "")
                    {
                        var EmptyStation = stationinfoRepository.Find(x => x.area == "11" && x.stationCode.Contains("A") && x.quantity < 5 && x.enable).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault();
                        if (EmptyStation == null) return;
                        if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) return;
                        task.agv_toaddress = EmptyStation.stationCode;
                        task.EndQuantity = EmptyStation.quantity;
                        task.agv_taskstate = "Create";
                        EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                        stationinfoRepository.Update(EmptyStation, true);
                        agvtaskRepository.Update(task, true);
                    }
                }
            }
        }
    }
}