杨前锦
2025-06-04 d44e3abf0d51cfea1ed7df510974d69458cf516d
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
using HH.WCS.Mobox3.YNJT_BZP.api;
using HH.WCS.Mobox3.YNJT_BZP.device;
using HH.WCS.Mobox3.YNJT_BZP.models;
using HH.WCS.Mobox3.YNJT_BZP.process;
using HH.WCS.Mobox3.YNJT_BZP.util;
using HH.WCS.Mobox3.YNJT_BZP.wms;
using MySqlX.XDevAPI.Common;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
 
namespace HH.WCS.Mobox3.YNJT_BZP.core
{
    /// <summary>
    /// 定时轮询任务
    /// </summary>
    internal class Monitor
    {
       
        /// <summary>
        /// 自动呼叫母托盘出库
        /// </summary>
        public static void AutoEmptyTrayOutStock() 
        {
            foreach (var item in Settings.baseTrayBufferLocList)
            {
                Location endLoc = LocationHelper.GetLoc(item.bufferOutLoc);  // 母拖出库接驳位
                if (endLoc != null && endLoc.N_CURRENT_NUM == 0 && endLoc.N_LOCK_STATE == 0)
                {
                    var cst = WCSHelper.GetTaskByStartAndEnd(endLoc.S_CODE);
                    if (cst == null)
                    {
                        ApiHelper.baseTrayOutStock(endLoc.S_CODE, null, 0);
                    }
                }
            }
        }
 
        /// <summary>
        /// 缓存空托自动出库
        /// </summary>
        public static void BufferEmptyTrayOutStock()
        {
            var emptyTrayBuffers = WMSHelper.getEmptyTrayBufferList();
            foreach (var buffer in emptyTrayBuffers)
            {
                if (buffer.T_CREATE.AddMinutes(1) > DateTime.Now) 
                {
                    Location startLoc = WMSHelper.GetEmptyTrayStartLoc(buffer.TRAY_TYPE);
                    Location middleLoc = null;
                    string cntrCode = "";
                    string descCntrCode = "";
                    if (startLoc != null)
                    {
                        // 查询货位容器编码 、目标容器编码
                        var locCntrRels = LocationHelper.GetLocCntrRel(startLoc.S_CODE);
                        if (locCntrRels.Count > 0)
                        {
                            foreach (var item in locCntrRels)
                            {
                                var container = ContainerHelper.GetCntr(item.S_CNTR_CODE);
                                if (buffer.TRAY_TYPE == container.N_TYPE)
                                {
                                    descCntrCode = item.S_CNTR_CODE;
                                }
                                cntrCode = cntrCode + "," + item.S_CNTR_CODE;
                            }
                            cntrCode = cntrCode.Substring(1, cntrCode.Length - 1);
                        }
 
                        var locCodes = Settings.getAgvJBLocList( startLoc.N_ROADWAY, 2);
                        if (locCodes.Count > 0)
                        {
                            middleLoc = LocationHelper.GetLoc(locCodes[0]);
                        }
                    }
 
                    Location endLoc = LocationHelper.GetLoc(buffer.END_LOC);
 
                    if (startLoc != null && endLoc != null)
                    {
                        var wmsTask = new WMSTask()
                        {
                            S_CNTR_CODE = descCntrCode,
                            S_CODE = WMSHelper.GenerateTaskNo(),
                            S_START_LOC = startLoc.S_CODE,
                            S_START_AREA = startLoc.S_AREA_CODE,
                            S_END_LOC = endLoc.S_CODE,
                            S_END_AREA = endLoc.S_AREA_CODE,
                            S_TYPE = "空托出库任务",
                            S_OP_DEF_CODE = buffer.TASK_NO,
                            S_OP_DEF_NAME = "空托出库任务",
                            N_PRIORITY = buffer.PRIORITY,
                            T_START_TIME = DateTime.Now,
                        };
 
                        if (WMSHelper.CreateWmsTask(wmsTask))
                        {
                            // 创建一段出库任务
                            WCSTask wcsTask = new WCSTask()
                            {
                                S_OP_NAME = wmsTask.S_OP_DEF_NAME,
                                S_OP_CODE = wmsTask.S_CODE,
                                S_CODE = WCSHelper.GenerateTaskNo(),
                                S_CNTR_CODE = cntrCode,
                                S_TYPE = wmsTask.S_TYPE + "-1",
                                S_START_LOC = startLoc.S_CODE,
                                S_START_AREA = startLoc.S_AREA_CODE,
                                S_END_LOC = middleLoc.S_CODE,
                                S_END_AREA = middleLoc.S_AREA_CODE,
                                S_SCHEDULE_TYPE = "WCS",
                                N_PRIORITY = 1,
                                T_START_TIME = DateTime.Now,
                            };
 
                            if (WCSHelper.CreateTask(wcsTask))
                            {
                                // 起点、接驳点、终点加锁
                                LocationHelper.LockLoc(wcsTask.S_START_LOC, 2);
                                LocationHelper.LockLoc(wcsTask.S_END_LOC, 1);
 
                                // 更新作业任务状态
                                wmsTask.N_B_STATE = 1;
                                WMSHelper.UpdateTaskState(wmsTask);
                            }
                        }
                    }
                }
            }
        }
    }
}