分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-04-27 25724888bc329401891bf1600a8a83d8aae338b3
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Core.BaseProvider;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Entity.ToAGV;
using WIDESEA_WCS.IRepositories;
using WIDESEA_WCS.Repositories;
using WIDESEA_WCS.WCSClient;
using WIDESEA_WMS.IRepositories;
using WIDESEA_WMS.IServices;
using WIDESEA_WMS.Repositories;
using static FreeSql.Internal.GlobalFilter;
using static System.Collections.Specialized.BitVector32;
 
namespace WIDESEA_WCS.JobsPart.Common
{
    public class RestockHCJ
    {
        /// <summary>
        /// 更新队列任务
        /// </summary>
        public static void HCJGetBarcode()
        {
            try
            {
                VOLContext Context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(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)
                {
                    try
                    {
                        if (task.agv_tasktype == "TaskType_EmptyPallet")//空托任务
                        {
                            if (task.agv_fromaddress == "" && DateTime.Now - task.agv_createtime >= TimeSpan.FromMinutes(2))
                            {
                                if (task.agv_tasknum.Contains("_"))
                                {
                                    string mainTaskNum = task.agv_tasknum.Split('_')[0];
                                    if (agvtaskService.Find(x => x.agv_tasknum == mainTaskNum && task.agv_taskstate != "Executing" && task.agv_taskstate != "Create").Any() || !agvtaskService.Find(x => x.agv_tasknum == mainTaskNum).Any())
                                        GetStation.EmptyPalletStation(task);
                                }
                                else
                                    GetStation.EmptyPalletStation(task);
 
                                WriteDBLog.Success("更新空托队列任务", $"任务编号:{task.agv_tasknum}", "PCS");
                                continue;
                            }
                        }
                        else if (task.agv_tasktype == "TaskType_OutsourceInbound" || task.agv_tasktype == "TaskType_Inbound")//外协库入库/AB库入库
                        {
                            if (task.agv_toaddress == "")
                            {
                                var stationinfo = stationinfoRepository.Find(x => x.stationCode == task.agv_fromaddress).FirstOrDefault();
                                var work = workinfoRepository.Find(x => x.workOrder == stationinfo.Number && x.drawingNo == stationinfo.stationType && x.heatID == stationinfo.heatNumber && x.processCode == "17").FirstOrDefault();
                                var TargetLocation = task.agv_tasktype == "TaskType_Inbound" ? GetLocation.GetEmptyLocation(stationinfoRepository, work, task) : 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.InBusy.ToString();
                                    TargetLocation.billetID = stationinfo.billetID;
                                    TargetLocation.stationType = task.agv_materielid;
                                    TargetLocation.heatNumber = stationinfo.heatNumber;
                                    TargetLocation.Number = task.jobID;
                                    stationinfoRepository.Update(TargetLocation, true);
                                    agvtaskService.Update(task, true);
                                    WriteDBLog.Success("更新入库队列任务", $"任务编号:{task.agv_tasknum}", "PCS");
                                    continue;
                                }
                            }
                        }
                        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.tray_status == "EmptyTray" || 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");
                                    continue;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //WriteDBLog.Error("更新队列任务", $"错误信息:{ex.Message}", "PCS");
                        WriteLog.Write_Log("更新队列任务","更新失败", "", $"错误信息:{ex.Message}");
                    }
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("更新队列任务", $"错误信息:{ex.Message}", "PCS");
            }
        }
    }
}