yanjinhui
12 小时以前 39531cf0ea52494fe56b8734afa552db32b7a164
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Common.LocationEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Common;
using WIDESEAWCS_Core;
using WIDESEAWCS_DTO.WMS;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_Core.Helper;
using HslCommunication.Core.IMessage;
using WIDESEAWCS_DTO.RGV.FOURBOT;
using Newtonsoft.Json;
using System.Reflection.Metadata;
 
namespace WIDESEAWCS_TaskInfoService
{
    public partial class TaskService
    {
        #region RGV任务创建
        /// <summary>
        /// 创建四向车入库任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public WebResponseContent CreateRGVNewInTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                #region 点到点
                //if (!string.IsNullOrEmpty(taskDTO.toLocationCode))
                //{
                //    var LocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点货位【{taskDTO.toLocationCode}】");
                //    if (LocationInfo.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"终点货位【{taskDTO.toLocationCode}】货位状态不为空货位");
                //}
                #endregion
                var rGVLocationInfo = _rGVLocationInfoService.GetInFreeLocationInfo(taskDTO.toAreaCode.ObjToInt()) ?? throw new Exception($"未找到终点库区【{taskDTO.toAreaCode}】可用空货位!");
                Dt_StationManger stationManger = _stationMangerService.GetInStationInfo(taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点位置【{taskDTO.fromLocationCode}】站台信息!");
                Dt_Task dt_Task = new()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = taskDTO.toAreaCode,
                    TaskState = TaskStatusEnum.New.ObjToInt(),
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = stationManger.RGVStationCode,
                    TargetAddress = "",
                    Dispatchertime=DateTime.Now,
                    Creater = "WMS",
                };
                BaseDal.AddData(dt_Task);
                return content.OK(data: new
                {
                    taskCode = taskDTO.taskCode,
                    Message = "成功!"
                });
            }
            catch (Exception ex)
            {
                content.Data = new
                {
                    taskCode = taskDTO.taskCode,
                    Message = $"失败!{ex.Message}"
                };
                return content.Error(ex.Message);
            }
        }
        /// <summary>
        /// 创建四向车出库任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public WebResponseContent CreateRGVNewOutTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var stationManger = _stationMangerService.GetOutStationInfo(taskDTO.toLocationCode);
                if (stationManger == null)
                {
                    return content.Error($"{taskDTO.toLocationCode}不是出库站台");
                }
                Dt_RGVLocationInfo rGVLocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                if (rGVLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                if (rGVLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{rGVLocationInfo.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                Dt_Task dt_Task = new()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = rGVLocationInfo.RoadwayNo,
                    TaskState = TaskStatusEnum.New.ObjToInt(),
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Dispatchertime = DateTime.Now,
                    Creater = "WMS",
                };
                rGVLocationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt();
                try
                {
                    Db.Ado.BeginTran();
                    BaseDal.AddData(dt_Task);
                    _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo);
                    Db.Ado.CommitTran();
                }
                catch (Exception ex)
                {
                    Db.Ado.RollbackTran();
                    throw new Exception(ex.Message);
                }
                return content.OK(data: new
                {
                    taskCode = taskDTO.taskCode,
                    Message = "成功!"
                });
            }
            catch (Exception ex)
            {
                content.Data = new
                {
                    taskCode = taskDTO.taskCode,
                    Message = $"失败!{ex.Message}"
                };
                return content.Error(ex.Message);
            }
           
        }
        #endregion
        /// <summary>
        /// 移库任务
        /// </summary>
        /// <param name="taskDTO"></param>
        /// <param name="taskType"></param>
        /// <returns></returns>
        public WebResponseContent CreateRGVNewMoveTask(TaskDTO taskDTO, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new();
            try
            {
                if (string.IsNullOrEmpty(taskDTO.fromLocationCode)) throw new Exception($"起点库位不能为空!");
                if (string.IsNullOrEmpty(taskDTO.toLocationCode)) throw new Exception($"终点库位不能为空!");
                Dt_RGVLocationInfo rGVLocationInfo = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.fromLocationCode) ?? throw new Exception($"未找到起点库位【{taskDTO.fromLocationCode}】!");
                if (rGVLocationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt()) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】当前库位状态不可出库!");
                if (rGVLocationInfo.PalletCode != taskDTO.containerCode) throw new Exception($"起点库位【{taskDTO.fromLocationCode}】绑定料箱号【{rGVLocationInfo.PalletCode}】与任务料箱号【{taskDTO.containerCode}】不匹配!");
                Dt_RGVLocationInfo rGVLocationInfo1 = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == taskDTO.toLocationCode) ?? throw new Exception($"未找到终点库位【{taskDTO.toLocationCode}】!");
                if (rGVLocationInfo1.LocationStatus != LocationStatusEnum.Free.ObjToInt()) throw new Exception($"终点库位【{taskDTO.toLocationCode}】当前库位状态不为空闲!");
                Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("未找到四向车任务下发接口配置信息!请检查接口配置");
                Dt_Task dt_Task = new()
                {
                    TaskNum = GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    WMSTaskNum = taskDTO.taskCode,
                    Grade = taskDTO.taskPriority,
                    PalletCode = taskDTO.containerCode,
                    Roadway = rGVLocationInfo.RoadwayNo,
                    TaskState = TaskStatusEnum.New.ObjToInt(),
                    TaskType = taskType,
                    SourceAddress = taskDTO.fromLocationCode,
                    CurrentAddress = taskDTO.fromLocationCode,
                    NextAddress = taskDTO.toLocationCode,
                    TargetAddress = taskDTO.toLocationCode,
                    Creater = "WMS",
                };
                rGVLocationInfo.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt();
                rGVLocationInfo1.LocationStatus = LocationStatusEnum.MoveLock.ObjToInt();
                #region 下发四向车任务
                fOURBOTnewMovePodTask = new FOURBOTnewMovePodTask
                {
                    priority = dt_Task.Grade,
                    podID = dt_Task.PalletCode,
                    desStorageID = dt_Task.TargetAddress,
                    desExt = new { unload = 1 }, // 是否放下容器,0否1是
                    desType = 2
                };
                fOURBOTnewMovePodTask.taskExt = new
                {
                    autoToRest = 1
                };
                string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
                var fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
                content.OK(data: fOURBOTReturn);
                if (fOURBOTReturn.returnCode != 0) throw new Exception($"下发成品移库任务错误:{fOURBOTReturn.returnMsg}");
                var data = fOURBOTReturn.data.ToString();
                var fOURBO = data.DeserializeObject<FOURBOTnewMovePodTaskResponseData>();
                dt_Task.RGVTaskId = fOURBO.taskID;
                dt_Task.TaskState = TaskStatusEnum.RGV_MoveTaskSend.ObjToInt();
                #endregion
                try
                {
                    Db.Ado.BeginTran();
                    BaseDal.AddData(dt_Task);
                    _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo);
                    _rGVLocationInfoService.Repository.UpdateData(rGVLocationInfo1);
                    Db.Ado.CommitTran();
                }
                catch (Exception ex)
                {
                    Db.Ado.RollbackTran();
                    throw new Exception(ex.Message);
                }
                return content.OK(data: new
                {
                    taskCode = taskDTO.taskCode,
                    Message = "成功!"
                });
            }
            catch (Exception ex)
            {
                content.Data = new
                {
                    taskCode = taskDTO.taskCode,
                    Message = $"失败!{ex.Message}"
                };
                return content.Error(ex.Message);
            }
        }
    }
}