xiazhengtongxue
2026-04-07 b0b5deb5825684bca5b3fa7c2ab59f60ce0e799f
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using MailKit.Search;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.Log;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Task;
using WIDESEA_Model.Models;
using static WIDESEA_ITaskInfoService.ITaskService;
 
namespace WIDESEA_TaskInfoService
{
    public partial class WMSCruJob
    {
        /// <summary>
        /// 判断巷道内移库
        /// </summary>
        /// <param name="TaskNum"></param>
        /// <param name="SourceAddress"></param>
        /// <returns></returns>
        public WebResponseContent JudgmentIsRelocations(Dt_Task dt_Task)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                string Locationcodeadd = dt_Task.TaskType == (int)TaskTypeEnum.Inbound ? dt_Task.NextAddress : dt_Task.CurrentAddress;
                Dt_LocationInfo dt_Location = _locationInfoService.FindStorageLocation(Locationcodeadd);
                if (dt_Location == null) { return content.Error("未能查找到库位"); }
                if (dt_Location.RoadwayNo == "5") return content.OK();    //浅货位直接返回,可下发出入口任务
                if(dt_Location.Depth == 1 && dt_Task.TaskType== (int)TaskTypeEnum.Outbound) return content.OK();
 
                int locrow = _locationInfoService.judgmentRow(dt_Location.RoadwayNo, dt_Location.Row);
                Dt_LocationInfo shallowLocation = _locationInfoService.ShallowGetLocation(dt_Location.RoadwayNo, dt_Location.LocationType, locrow, dt_Location.Layer, dt_Location.Column);
                if (dt_Location.Depth == 1 && dt_Task.TaskType == (int)TaskTypeEnum.Inbound)
                {
                    if (shallowLocation.LocationStatus == (int)LocationStatusEnum.InStock) return content.OK();
                    return content.Error($"入库至深库位,但是浅货位有货,任务号:{dt_Task.TaskId},托盘条码");
                }
                if (shallowLocation.LocationStatus == (int)LocationStatusEnum.Free) return content.OK();
 
 
                //判断当前浅货位是否有出库任务
                var OutTask = _taskService.GeOutCuTaskQueue(shallowLocation.LocationCode);
                if (OutTask != null)
                {
                    //进行下发给堆垛机任务
                    WCSginseng outresult = _taskService.SC_IssueTasks(OutTask.TaskId, int.Parse(OutTask.Roadway), OutTask.TaskNum, OutTask.PalletCode, int.Parse(OutTask.PalletType), OutTask.CurrentAddress, OutTask.NextAddress, OutTask.TargetAddress);
                    if (outresult.IsSuccess)
                    {
 
                        OutTask.TaskStatus = (int)OutTaskStatusEnum.SC_OutExecuting;
                        OutTask.Dispatchertime = DateTime.Now;
                        _taskService.UpdateData(OutTask);
                        return content.OK();
                    }
                    else
                    {
                        UpdateTaskStatus(dt_Task, outresult,0, 1);
 
                        return content.Error($"下发wcs失败,原因:{outresult.Message}");
                    }
                }
 
 
                //判断是否有移库任务
                var TransferTask = _taskService.GeRelocationTaskQueue(shallowLocation.LocationCode);
                if (TransferTask != null)
                {
                    //进行下发给堆垛机任务
                    WCSginseng result = _taskService.SC_IssueTasks(TransferTask.TaskId,int.Parse(TransferTask.Roadway),TransferTask.TaskNum,TransferTask.PalletCode,int.Parse(TransferTask.PalletType),TransferTask.CurrentAddress,TransferTask.NextAddress,dt_Task.TargetAddress);
                    if (result.IsSuccess)
                    {
                        TransferTask.TaskStatus = (int)RelocationTaskStatusEnum.RelocationExecuting;
                        TransferTask.Dispatchertime = DateTime.Now;
                        _taskService.UpdateData(TransferTask);
                        return content.OK();
                    }
                    else
                    {
                        UpdateTaskStatus(dt_Task, result,0,1);  //默认不需要更改状态传0
 
                        return content.Error($"下发wcs失败,原因:{result.Message}");
                    }
                }
 
                var CuttTransferTask = _taskService.RelocationTaskProgress(dt_Task.Roadway);
                //判断当前是否有移库任务
                if (CuttTransferTask) return content.Error("当前有移库任务,不可下发");
 
 
                if (shallowLocation.LocationStatus != (int)LocationStatusEnum.InStock) return content.Error($"库位状态异常,当前状态:{(LocationStatusEnum)shallowLocation.LocationStatus},应为:{LocationStatusEnum.InStock}");
 
                //生成移库任务
                return content = GenerateTransferTask(shallowLocation.LocationCode);
            }
            catch (Exception ex)
            {
                return content.Error($"判断巷道内移库,失败,方法内故障,原因:{ex.Message}");
 
            }
        }
 
 
        //生成移库任务
        public WebResponseContent GenerateTransferTask(string shallowLocation)
        {
            WebResponseContent webResponse = new WebResponseContent();
            try
            {
                Dt_LocationInfo OriginalLocation = _locationInfoService.Repository.QueryData(x => x.LocationCode == shallowLocation).FirstOrDefault();
                Dt_StockInfo dt_StockInfo = _stockInfoService.Repository.QueryData(x => x.LocationCode == shallowLocation).FirstOrDefault();
                Dt_LocationInfo newLocation = _locationInfoService.GetLocation(OriginalLocation.RoadwayNo, OriginalLocation.LocationType);
                List<Dt_LocationInfo> dt_Locations = new List<Dt_LocationInfo>();
                var TransferTask = _taskService.GeRelocationTaskQueue(shallowLocation);
                MES_parameter mES_Parame = _taskService.ApplicationChangeStorageLocation(dt_StockInfo.PalletCode, OriginalLocation.LocationCode, newLocation.LocationCode);
                if (mES_Parame != null)
                {
                    if (mES_Parame.Result == "Y")
                    {
                        //进行生成任务,下发任务至MES
                        Dt_Task task = new Dt_Task();
                        task.TaskNum = $"REL{DateTime.Now:yyyyMMddHHmmss}{new Random().Next(1000, 9999)}";
                        //task.TaskNum = "0";
                        task.PalletCode = dt_StockInfo.PalletCode;
                        task.PalletType = dt_StockInfo.PalletType;
                        task.Roadway = OriginalLocation.RoadwayNo;
                        task.TaskType = (int)TaskTypeEnum.Relocation;
                        task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationNew;
                        task.SourceAddress = OriginalLocation.LocationCode;
                        task.TargetAddress = newLocation.LocationCode;
                        task.CurrentAddress = OriginalLocation.LocationCode;
                        task.NextAddress = newLocation.LocationCode;
                        task.WarehouseId = OriginalLocation.WarehouseId;
                        task.OrderNo = "";
                        task.Grade = 1;
                        task.Creater = "MES";
                        task.CreateDate = DateTime.Now;
 
                        OriginalLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                        newLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                        dt_StockInfo.StockStatus = (int)StockStatusEmun.移库锁定;
 
                        dt_Locations.Add(OriginalLocation);
                        dt_Locations.Add(newLocation);
 
                        _unitOfWorkManage.BeginTran();
 
                        int TaskId = _taskService.Repository.AddData(task);
                        _locationInfoService.UpdateData(dt_Locations);
                        _stockInfoService.UpdateData(dt_StockInfo);
                        _unitOfWorkManage.CommitTran();
                        return webResponse.Error("已生成移库任务");
                    }
                    else
                    {
 
                        WriteLog.Write_Log("WMS_移库故障", $"EMS申请储位异动返回失败内容", "失败", $"MES不允许移动====>>>>返回内容:{mES_Parame.ToJson()}");
                        return webResponse.Error($"申请储位异动,MES不允许移动====>>>>返回内容:{mES_Parame.ToJson()}");
                    }
                }
                else
                {
                    WriteLog.Write_Log("WMS_移库故障", $"EMS申请储位异动返回失败内容", "失败", $"申请储位异动,MES返回为空");
                    return webResponse.Error("申请储位异动,MES返回为空");
                }
 
                //进行下发给堆垛机任务
                /*WCSginseng result = _taskService.SC_IssueTasks(
                    TaskId,
                    int.Parse(task.Roadway),
                    task.TaskNum,
                    task.PalletCode,
                    int.Parse(task.PalletType),
                    task.CurrentAddress,
                    task.NextAddress,
                    task.TargetAddress);
                if (result.IsSuccess)
                {
                    Dt_Task dt_Task=_taskService.Repository.QueryFirst(x=>x.TaskId== task.TaskId);
                    dt_Task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationExecuting;
                    _taskService.UpdateData(dt_Task);
                    return webResponse.OK();
                }
                else
                {
                    return webResponse.Error($"下发移库失败,原因:{result.Message}");
                }*/
 
                /* MES_parameter mES_Parame = _taskService.ApplicationChangeStorageLocation(dt_StockInfo.PalletCode, OriginalLocation.LocationCode, newLocation.LocationCode);
                if (mES_Parame != null)
                {
                    if (mES_Parame.Result == "Y")
                    {
                        //进行生成任务,下发任务至MES
                        Dt_Task task = new Dt_Task();
                        task.TaskNum = "0";
                        task.PalletCode = dt_StockInfo.PalletCode;
                        task.PalletType = dt_StockInfo.PalletType;
                        task.Roadway = OriginalLocation.RoadwayNo;
                        task.TaskType = (int)TaskTypeEnum.Relocation;
                        task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationNew;
                        task.SourceAddress = OriginalLocation.LocationCode;
                        task.TargetAddress = newLocation.LocationCode;
                        task.CurrentAddress = OriginalLocation.LocationCode;
                        task.NextAddress = newLocation.LocationCode;
                        task.WarehouseId = OriginalLocation.WarehouseId;
                        task.OrderNo = "";
                        task.Grade = 1;
                        task.Creater = "MES";
                        task.CreateDate = DateTime.Now;
 
                        OriginalLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                        newLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                        dt_StockInfo.StockStatus = (int)StockStatusEmun.移库锁定;
 
                        dt_Locations.Add(OriginalLocation);
                        dt_Locations.Add(newLocation);
 
                        _unitOfWorkManage.BeginTran();
 
                        int TaskId = _taskService.Repository.AddData(task);
                        _locationInfoService.UpdateData(dt_Locations);
                        _stockInfoService.UpdateData(dt_StockInfo);
                        _unitOfWorkManage.CommitTran();
 
 
                        //return webResponse.Error("已生成移库任务");
                        //进行下发给堆垛机任务
                        WCSginseng result = _taskService.SC_IssueTasks(
                            TaskId,
                            int.Parse(task.Roadway),
                            task.TaskNum,
                            task.PalletCode,
                            int.Parse(task.PalletType),
                            task.CurrentAddress,
                            task.NextAddress,
                            task.TargetAddress);
                        if (result.IsSuccess)
                        {
                            task.TaskStatus = (int)RelocationTaskStatusEnum.RelocationExecuting;
                            _taskService.UpdateData(task);
                            return webResponse.OK();
                        }
                        else
                        {
                            return webResponse.Error($"下发移库失败,原因:{result.Message}");
                        }
                    }
                    else
                    {
                        return webResponse.Error($"申请储位异动,MES不允许移动====>>>>返回内容:{mES_Parame.ToJson()}");
                    }
                }
                else
                {
                    return webResponse.Error("申请储位异动,MES返回为空");
                }*/
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return webResponse.Error($"移库任务生成方法,系统故障,原因:{ex.Message}");
            }
        }
 
    }
}