分支自 SuZhouGuanHong/TaiYuanTaiZhong

dengjunjie
2024-05-25 8554717a7abbe2889ae1d835857661dc8b91aa68
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
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm;
using WIDESEA_Comm.LogInfo;
using WIDESEA_Comm.TaskNo;
using WIDESEA_Common;
using WIDESEA_Core.BaseProvider;
using WIDESEA_Core.EFDbContext;
using WIDESEA_Core.ManageUser;
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;
 
namespace WIDESEA_WMS.Common
{
    public class QueueTask
    {
        /// <summary>
        /// 创建更换托盘任务,需修改
        /// </summary>
        public static void ReplaceTrayTask()
        {
            try
            {
                VOLContext context = new VOLContext();
                Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
                var stations = stationinfoRepository.Find(x => (x.stationCode.Contains("X") || x.stationCode.Contains("W01001004") || x.stationCode.Contains("W01001005")) && x.location_state == LocationStateEnum.Trayswitching.ToString() && x.enable).ToList();
                foreach (var station in stations)
                {
                    var task = agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).FirstOrDefault();
                    if (task != null)
                    {
                        if (task.agv_taskstate != AGVTaskStateEnum.Queue.ToString()) continue;
                        task.agv_Traytype = station.tray_type == TrayTypeEnum.SmallTray.ToString() ? TrayTypeEnum.LargeTray.ToString() : TrayTypeEnum.SmallTray.ToString();
                        agvtaskRepository.Update(task, x => new { x.agv_Traytype }, true);
                    }
                    else if (!agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode).Any())
                    {
                        #region 为空托并且数量为0,创建取空托任务
                        if (station.tray_status == TrayStateEnum.EmptyTray.ToString() && station.quantity == 0)
                        {
                            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 = AGVTaskStateEnum.Queue.ToString(),
                                agv_qty = 1,
                                StarQuantity = 0,
                                EndQuantity = 0,
                                agv_tasktype = AGVTaskTypeEnum.TaskType_EmptyPallet.ToString(),
                                agv_toaddress = "",
                                agv_userid = "WMS",
                                agv_TrayStatus = station.tray_status,
                                agv_Traytype = station.tray_type
                            };
                            agvtaskRepository.Add(agvtask, true);
 
                            station.location_state = LocationStateEnum.Busy.ToString();
                        }
                        #endregion
 
                        #region 创建入库任务
                        else if (station.location_state == LocationStateEnum.Stroge.ToString() && station.quantity > 0)
                        {
                            var Work = workinfoRepository.Find(x => x.workOrder == station.Number && x.processCode == "17").FirstOrDefault();
                            if (Work == null) throw new Exception($"未找到货位{station.stationCode}的机加工工单信息!");
                            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 = AGVTaskStateEnum.Queue.ToString(),
                                agv_materielid = station.stationType,
                                agv_qty = station.quantity,
                                agv_tasktype = station.stationCode.Contains("3") ? AGVTaskTypeEnum.TaskType_OutsourceInbound.ToString() : AGVTaskTypeEnum.TaskType_Inbound.ToString(),
                                agv_toaddress = "",
                                agv_userid = "WMS",
                                bindSN = station.bindSN,
                                agv_worktype = Convert.ToInt32(Work.processCode),
                                agv_materbarcode = Work.materialCode,
                                agv_Traytype = station.tray_type,
                                jobID = station.Number,
                                agv_TrayStatus = station.tray_status
                            };
                            agvtaskRepository.Add(agvtask, true);
 
                            station.location_state = LocationStateEnum.InBusy.ToString();
                        }
                        #endregion
                    }
                    station.tray_type = station.tray_type == TrayTypeEnum.SmallTray.ToString() ? TrayTypeEnum.LargeTray.ToString() : TrayTypeEnum.SmallTray.ToString();
                    stationinfoRepository.Update(station, x => new { x.location_state, x.tray_type }, true);
                }
            }
            catch (Exception ex)
            {
                WriteDBLog.Error("创建更换空盘任务", $"错误信息:{ex.Message}", "PCS");
            }
        }
        /// <summary>
        /// 创建完整的补空托任务
        /// </summary>
        /// <param name="agvtask"></param>
        public static void CreatePartQueue(Idt_agvtaskRepository agvtaskRepository, dt_agvtask agvtask, string type = "")
        {
            //if (agvtask.agv_fromaddress.Contains("X") || agvtask.agv_fromaddress.Contains("W01001004") || agvtask.agv_fromaddress.Contains("W01001005"))
            //{
            dt_agvtask taskPart = new dt_agvtask()
            {
                agv_fromaddress = "",
                agv_id = Guid.NewGuid(),
                agv_tasknum = agvtask.agv_tasknum + "_1",
                agv_grade = 1,
                agv_createtime = DateTime.Now,
                agv_taskstate = "Queue",
                agv_qty = 1,
                agv_tasktype = "TaskType_EmptyPallet",
                agv_toaddress = agvtask.agv_fromaddress,
                agv_userid = "系统",
                agv_TrayStatus = agvtask.agv_TrayStatus,
                agv_Traytype = type,
            };
            agvtaskRepository.Add(taskPart, true);
            WriteDBLog.Success("创建更换空盘任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
            //}
        }
    }
}