分支自 SuZhouGuanHong/TaiYuanTaiZhong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Common;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_WCS.JobsPart.Common;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.Repositories;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WMS.Common
{
    public partial class AGVServer
    {
        /// <summary>
        /// 更新取空托队列任务
        /// </summary>
        public static void UpdateEmptyPalletTask()
        {
            string tasknum = "";
            try
            {
                VOLContext Context = new VOLContext();
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(Context);
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
 
                #region 叠盘区满5个入库
                var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.enable).ToList();
                var EmptyD = EmptyStations.Where(x => x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity == 5).FirstOrDefault();
                if (EmptyD != null) EmptyTray.CreateEmptyTrayIn(stationinfoRepository, EmptyD);
                #endregion
                var agv_task = agvtaskRepository.Find(x => x.agv_taskstate == AGVTaskStateEnum.Queue.ToString() && x.agv_tasktype == AGVTaskTypeEnum.TaskType_EmptyPallet.ToString() && string.IsNullOrEmpty(x.agv_toaddress)).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
                if (agv_task != null)
                {
                    tasknum = agv_task.agv_tasknum;
                    #region MyRegion
                    //var task = agvtaskRepository.Find(x => (x.agv_toaddress.Contains("W") || x.agv_toaddress.Contains("X")) && x.agv_taskstate == AGVTaskStateEnum.Queue.ToString() && x.agv_tasktype == AGVTaskTypeEnum.TaskType_EmptyPallet.ToString() && x.agv_Traytype == agv_task.agv_Traytype).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
                    //if (task != null)
                    //{
                    //    task.agv_fromaddress = station.stationCode;
                    //    task.StarQuantity = 0;
                    //    task.agv_taskstate = "Create";
                    //    if (station.stationCode.Contains("S0100100"))
                    //        task.agv_grade = 3;
                    //    agvtaskService.Update(task, true);
                    //    station.location_state = LocationStateEnum.Busy.ToString();
                    //    stationinfoRepository.Update(station, true);
                    //    WriteDBLog.Success("更新补空托队列任务", $"任务编号:{task.agv_tasknum},托盘信号:{PalletSignal},货物信号:{MaterialSignal}", "WMS");
                    //    return;
                    //}
                    #endregion
                    dt_stationinfo EmptyStation = null;
                    #region 检测上料的空托叠盘
                    if (agv_task.agv_fromaddress.Contains("S"))
                    {
                        //var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity < 5 && x.enable).ToList();
                        EmptyStation = EmptyStations.Where(x => x.tray_type == agv_task.agv_Traytype && x.quantity < 5 && x.location_state == LocationStateEnum.Stroge.ToString()).FirstOrDefault();
                        if (EmptyStation == null)
                            EmptyStation = EmptyStations.Where(x => x.location_state == LocationStateEnum.Empty.ToString() && x.quantity == 0).FirstOrDefault();
                        if (EmptyStation == null)
                        {
                            EmptyD = EmptyStations.Where(x => x.location_state == LocationStateEnum.Stroge.ToString() && x.quantity > 0).OrderByDescending(x => x.quantity).FirstOrDefault();
                            if (EmptyD != null) EmptyTray.CreateEmptyTrayIn(stationinfoRepository, EmptyD);
                        }
                    }
                    #endregion
                    else
                    {
                        EmptyStation = GetStation.EmptyPalletStation(agv_task.agv_Traytype == "SmallTray" ? "11" : "10");
                    }
 
                    if (EmptyStation != null)
                    {
                        agv_task.agv_taskstate = AGVTaskStateEnum.Create.ToString();
                        agv_task.EndQuantity = EmptyStation.quantity;
                        agv_task.agv_toaddress = EmptyStation.stationCode;
                        agvtaskRepository.Update(agv_task, true);
                        EmptyStation.location_state = LocationStateEnum.Busy.ToString();
                        stationinfoRepository.Update(EmptyStation, true);
                        WriteDBLog.Success("更新自动取空托队列任务", $"任务编号:{agv_task.agv_tasknum}", "WMS");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteLog.Write_Log("报错日志", "更新自动取空托队列任务", "错误信息!", $"{tasknum};错误信息:{ex.Message}");
            }
        }
    }
}