Admin
2026-03-12 4452684129f1b7e74e1dae9af7ffa81d61ad181f
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 命名空间:WIDESEAWCS_TaskInfoService
 * 创建者:胡童庆
 * 创建时间:2024/8/2 16:13:36
 * 版本:V1.0.0
 * 描述:
 *
 * ----------------------------------------------------------------
 * 修改人:
 * 修改时间:
 * 版本:V1.0.1
 * 修改说明:
 * 
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
 
using AutoMapper;
using Castle.Components.DictionaryAdapter.Xml;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.OpenApi.Any;
using NetTaste;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using SqlSugar;
using StackExchange.Profiling.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Metadata;
using System.Security.Cryptography.Xml;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Comm.Http;
using WIDESEA_Common.Log;
using WIDESEA_Core.Enums;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Enums;
using WIDESEAWCS_Core.Utilities;
using WIDESEAWCS_DTO.Enum;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.DTO;
using WIDESEAWCS_QuartzJob.Models;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_TaskInfoRepository;
using static Microsoft.IO.RecyclableMemoryStreamManager;
 
namespace WIDESEAWCS_TaskInfoService
{
    public partial class TaskService
    {
 
        //============================================以下是后续新增内容查找任务=============================================================
        #region wms任务模块
        //任务下发
        public ApiResponse saveTask(TransferTask transfer)
        {
            WriteLog.Write_Log("WMS任务下发接口", "WMS任务下发接口信息", "调取参数", transfer);
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (transfer == null) return apiResponse.ErrorResponse("接收的WMS任务下发参数为空");
                // 进一步校验必要字段
                if (string.IsNullOrEmpty(transfer.taskType)) return apiResponse.ErrorResponse("任务类型不能为空");
                if (string.IsNullOrEmpty(transfer.barCode)) return apiResponse.ErrorResponse("条码不能为空");
                if (transfer.from == null || string.IsNullOrEmpty(transfer.from.code)) return apiResponse.ErrorResponse("起始位置不能为空");
                if (transfer.to == null || string.IsNullOrEmpty(transfer.to.code)) return apiResponse.ErrorResponse("目标位置不能为空");
                if (transfer.device == null || string.IsNullOrEmpty(transfer.device.uuid)) return apiResponse.ErrorResponse("设备标识不能为空");
 
                Dt_Task setask = BaseDal.QueryData(x => x.WMStaskid == transfer.barCode).FirstOrDefault();
                if (setask != null) return apiResponse.ErrorResponse($"WCS已有当前任务,不可重复下发,托盘编号:{transfer.barCode}");
 
 
 
                (int TaskType, int TaskState) = transfer.taskType switch
                {
                    "in" => ((int)TaskTypeEnum.Inbound, (int)TaskInStatusEnum.InNew),
                    "out" => ((int)TaskTypeEnum.Outbound, (int)TaskOutStatusEnum.OutNew),
                    "check" => ((int)TaskTypeEnum.Inventorybound, (int)TaskinventoryStatusEnum.inventoryNew),
                    _ => (0, 0) // 保持原有的默认值
                };
 
                Dt_Task task = new Dt_Task();
                task.TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)); //任务编号
                task.PalletCode = transfer.original_barCode;
                task.Roadway = transfer.from.code.Substring(0, 1);
                task.TaskType = TaskType;
                task.TaskState = TaskState;
                task.SourceAddress = transfer.from.code;
                task.TargetAddress = transfer.to.code;
                task.CurrentAddress = transfer.from.code;
                task.NextAddress = transfer.to.code;
                task.Grade = 1;
                task.Creater = "WMS";
                task.CreateDate = DateTime.Now;
                task.WMStaskid = transfer.barCode;
                task.deviceuuid = transfer.device.uuid;
 
                _unitOfWorkManage.BeginTran();
                BaseDal.AddData(task);
                _unitOfWorkManage.CommitTran();
                return apiResponse.SuccessResponse();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
            }
        }
 
 
 
        //通知库口上料完成
        public ApiResponse scanData(TaskReportingData taskReporting)
        {
            WriteLog.Write_Log("通知库口上料完成接口", "通知库口上料完成信息", "调取参数", taskReporting);
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                if (taskReporting == null) return apiResponse.ErrorResponse("接收的WMS任务下发参数为空");
                if (taskReporting.baseInfo == null) return apiResponse.ErrorResponse("库口基础数据baseInfo不能为空");
                if (string.IsNullOrWhiteSpace(taskReporting.baseInfo.code)) return apiResponse.ErrorResponse("任务类型不能为空");
                if (taskReporting.details == null || !taskReporting.details.Any()) return apiResponse.ErrorResponse("库口详情集合details不能为空/无数据");
 
 
 
                return apiResponse.SuccessResponse();
            }
            catch (Exception ex)
            {
                return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
            }
        }
 
        //获取库口状态
        public ApiResponse getPortStatus(string[] datas)
        {
            WriteLog.Write_Log("获取库口状态接口", "获取库口状态信息", "调取参数", datas);
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                //IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
                //if (device == null) return apiResponse.ErrorResponse("WCS未能获取到库口实例");
                //CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
 
                Dictionary<string, int> portStatusDict = new Dictionary<string, int>();
 
                foreach (string DeStateName in datas)
                {
                    //暂时数据
                    portStatusDict[DeStateName] = 1;
 
                    /*DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "StationFree");
                    if (deviceProDTO == null) return apiResponse.ErrorResponse($"WCS未找到库口:{DeStateName},对应的协议");
                    conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
                    bool portStatus = conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
                    int statusValue = portStatus ? 1 : 0;
                    portStatusDict[DeStateName] = statusValue;*/
                }
 
                return apiResponse.SuccessResponse(portStatusDict);
            }
            catch (Exception ex)
            {
                return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
            }
        }
 
 
        //获取光幕状态
        public ApiResponse getSafeStatus(string[] datas)
        {
            WriteLog.Write_Log("获取光幕状态接口", "获取光幕状态信息", "调取参数", setCurtain);
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                Dictionary<string, int> portStatusDict = new Dictionary<string, int>();
                foreach (string DeStateName in datas)
                {
                    portStatusDict[DeStateName] = 1;
                }
 
                return apiResponse.SuccessResponse(portStatusDict);
            }
            catch (Exception ex)
            {
                return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
            }
        }
 
 
        //设置光幕
        public ApiResponse setCurtain(SetCurtainRequest setCurtain)
        {
            //获取WMS调取的参数
            WriteLog.Write_Log("设置光幕接口", "设置光幕信息", "调取参数", setCurtain);
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
                return apiResponse.SuccessResponse();
            }
            catch (Exception ex)
            {
                return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
            }
        }
 
 
        //agv进出状态反馈
        public ApiResponse getAGVStatus(AgvUpdateRequest agvUpdateRequest)
        {
            //获取WMS调取的参数
            WriteLog.Write_Log("agv进出状态反馈接口", "agv进出状态信息", "调取参数", setCurtain);
 
            ApiResponse apiResponse = new ApiResponse();
            try
            {
 
 
                return apiResponse.SuccessResponse();
            }
            catch (Exception ex)
            {
                return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
            }
        }
        #endregion
 
 
 
        #region 调取上游接口
        public CommandResult taskreturn(int taskId, string taskType, string invType, string psd)
        {
            CommandResult commandResult = new CommandResult();
            try
            {
                TaskInfo taskInfo1 = new TaskInfo();
                taskInfo1.taskId = taskId;
                taskInfo1.taskType = taskType;
                taskInfo1.invType = invType;
                taskInfo1.psd = "akjfapjfpadaoif";
                commandResult = HttpHelper.Post<CommandResult>(urlWMStaskreturn, taskInfo1, "任务状态回调");
 
                WriteLog.Write_Log("同步给上游反馈任务完成", "任务信息", $"任务号:{taskId}", $"调取参数:{taskInfo1.ToJson()},返回参数:{commandResult.ToJson()}");
                return commandResult;
            }
            catch (Exception ex)
            {
                commandResult.status = "error";
                commandResult.result = $"WCS接口错误,原因:{ex.Message}";
 
                WriteLog.Write_Log("同步给上游反馈任务完成", "任务信息", $"任务号:{taskId}", $"WCS接口错误,原因:{ex.Message}");
                return commandResult;
            }
            
        }
 
        public CommandResult deverror(string devuuid, string id, string errorcode, string errorinfo, string erroraddress, string warehouse, string remark, string devname, string dealType, string psd)
        {
            CommandResult commandResult = new CommandResult();
            try
            {
                DeviceErrorRequest deviceErrorRequest = new DeviceErrorRequest
                {
                    devErrorJsons = new List<DeviceErrorInfo>
                    {
                        new DeviceErrorInfo
                        {
                            devuuid = devuuid,
                            id = id,
                            errorcode = errorcode,
                            errorinfo = errorinfo,
                            erroraddress = erroraddress,
                            warehouse = warehouse,
                            remark = remark,
                            devname = devname
                        }
                    },
                    dealType = dealType,
                    psd = "akjfapjfpadaoif",
                };
               
                commandResult = HttpHelper.Post<CommandResult>(urlWMSdeverror, deviceErrorRequest, "设备故障回调");
                WriteLog.Write_Log("同步给上游设备故障信息", "设备故障信息", $"设备id:{devuuid},成功", $"调取参数:{deviceErrorRequest.ToJson()},返回参数:{commandResult.ToJson()}");
                return commandResult;
            }
            catch (Exception ex)
            {
                commandResult.status = "error";
                commandResult.result = $"WCS接口错误,原因:{ex.Message}";
 
                WriteLog.Write_Log("同步给上游设备故障信息", "设备故障信息", $"设备id:{devuuid},失败", $"WCS接口错误,原因:{ex.Message}");
                return commandResult;
            }
 
        }
 
 
        public CommandResult liftinposition(string invtype, string invcode, string kloccode)
        {
            CommandResult commandResult = new CommandResult();
            try
            {
                ShelvesPosition deviceErrorRequest = new ShelvesPosition
                {
                    invtype= invtype,
                    invcode = invcode,
                    kloccode = kloccode
                };
                commandResult = HttpHelper.Post<CommandResult>(urlWMSliftinposition, deviceErrorRequest, "设备故障回调");
 
                WriteLog.Write_Log("同步给上游提升到位信息", "信息内容", $"库口编号:{kloccode},成功信息", $"调取参数:{deviceErrorRequest.ToJson()},返回参数:{commandResult.ToJson()}");
                return commandResult;
            }
            catch (Exception ex)
            {
                commandResult.status = "error";
                commandResult.result = $"WCS接口错误,原因:{ex.Message}";
                WriteLog.Write_Log("同步给上游提升到位信息", "信息内容", $"错误信息", $"WCS接口错误,原因:{ex.Message}");
                return commandResult;
            }
 
        }
        #endregion
    }
}