huanghongfeng
2025-03-06 1c213042c6608c7b5cfc3fd4a801f946dc2d8651
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core.Enums;
using WIDESEA_Core;
using WIDESEA_Model.Models;
using WIDESEA_Core.Helper;
using Microsoft.Extensions.Logging;
using MailKit.Search;
using System.Reflection.Metadata;
using static WIDESEA_ITaskInfoService.ITaskService;
using Org.BouncyCastle.Bcpg;
using WIDESEA_Model.Models.System;
using Newtonsoft.Json;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
        
    
        public WebResponseContent PalletQueryinventory()
        {
            WebResponseContent content = new WebResponseContent();
            List<Dt_LocationInfo> locationinfoData = _basicService.LocationInfoService.Repository.QueryData(x => x.RoadwayNo=="2" && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() 
            && x.LocationType == (int)LocationTypeEnum.EmptyCube && x.EnableStatus == (int)EnableStatusEnum.Normal);
            if (locationinfoData.Count < 20)
            {
                return content = WebResponseContent.Instance.OK(data: 1);
            }
            else
            {
                return content = WebResponseContent.Instance.OK(data: 3);
            }
        }
 
        public string ToWCSTask = WIDESEA_Core.Helper.AppSettings.Configuration["ToWCSTask"];
        public WebResponseContent RequestInboundPDA(SaveModel saveModel)
        {
 
            WebResponseContent content = new WebResponseContent();
 
            //查找货位信息,并修改
            try
            {
                 List<Dt_Task> taskdt = new List<Dt_Task>();
                string barcode = saveModel.MainData["barcode"].ToString();  //条码
                string stationName = saveModel.MainData["stationName"].ToString();  //车型
                string cartnme = saveModel.MainData["cartnme"].ToString();      //名称
                int cartcount = int.Parse(saveModel.MainData["cartcount"].ToString());   //数量
                string barcodemodel = saveModel.MainData["barcodemodel"].ToString();    //车号
                string cartnumber = saveModel.MainData["cartnumber"].ToString();    //车组号
 
                Dt_LocationInfo newLocation;
                newLocation = _basicService.LocationInfoService.GetLocation("", 1);
                if (newLocation != null)
                {
                    newLocation.LocationStatus = (int)LocationStatusEnum.Lock;
                    //添加组盘库存信息
                    Dt_StockInfo dt_Stock = new()
                    {
                        PalletCode = barcode,
                        IsFull = true,
                        LocationCode = newLocation.LocationCode,
                        StockStatus = (int)StockStatusEmun.组盘暂存,
                        Creater = "WMS",
                        CreateDate = DateTime.Now,
                        MaterialType = (int)InventoryMaterialType.满托,
                        Wlstatus = (int)InventoryMaterialStatus.待修,
                        Materialweight = cartcount,
                        WagonModel = barcodemodel,
                        WagonName = cartnme,
                        Wagonnumber = stationName,
                        Wagongroup= cartnumber
                    };
 
                    //生成入库任务
                    Dt_Task dt_Task = new()
                    {
                        PalletCode = barcode,
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Roadway = newLocation.RoadwayNo,
                        TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                        TaskStatus = InTaskStatusEnum.InNew.ObjToInt(),
                        SourceAddress = "1084",
                        TargetAddress = newLocation.LocationCode,
                        CurrentAddress = "1084",
                        NextAddress = newLocation.LocationCode,
                        Grade = 1,
                        Depth = newLocation.Depth,
                        MaterialType = (int)InventoryMaterialType.满托
                    };
                   
                    BaseDal.AddData(dt_Task);
                    _stockService.StockInfoService.Repository.AddData(dt_Stock);
                    _basicService.LocationInfoService.UpdateData(newLocation);
 
                    
                    taskdt.Add(dt_Task);
                    //调取wcs接口传递任务
                    WebResponseContent webResponseContent = HttpHelper.Post<WebResponseContent>(ToWCSTask, taskdt, "入库任务下发");
                    if (webResponseContent.Status)
                    {
                        return content.OK("已添加入库任务");
                    }
                    else
                    {
                        return content.Error("入库任务,下发WCS失败");
                    }
 
                }
                else
                {
                    return content.Error("已无可用的货架,无法入库");
                }
            }
            catch (Exception ex)
            {
                return content.Error($"入库添加失败,系统错误:{ex.Message}");
                throw;
            }
        }
 
        /// <summary>
        /// 空托入库
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent EmptyInbound(GenerateInv saveModel)
        {
 
            WebResponseContent content = new WebResponseContent();
 
            //查找货位信息,并修改
            try
            {
 
 
                if (saveModel.barcode != null && saveModel.barcode.ToString() != "")
                {
 
                    Dt_traycodeinfo _Traycodeinfo= _sys_Traycodeinfo.GetInCacheList(saveModel.barcode.ToString());
                    if(_Traycodeinfo!=null)
                    {
                        Dt_LocationInfo newLocation;
                        newLocation = _basicService.LocationInfoService.GetLocation("", 1);
                        if (newLocation != null)
                        {
                            newLocation.LocationStatus = (int)LocationStatusEnum.PalletLock;
                            //添加组盘库存信息
                            Dt_StockInfo dt_Stock = new()
                            {
                                PalletCode = saveModel.barcode.ToString(),
                                IsFull = false,
                                LocationCode = newLocation.LocationCode,
                                StockStatus = (int)StockStatusEmun.组盘暂存,
                                Creater = "WMS",
                                CreateDate = DateTime.Now,
                                MaterialType = (int)InventoryMaterialType.空托,
                                Wlstatus = (int)InventoryMaterialStatus.空托,
                                //Materialweight = int.Parse(_Traycodeinfo.traycode_type), 
                                Materialweight = 1,
                                WagonModel = _Traycodeinfo.traycode_materiel,
                                WagonName = _Traycodeinfo.traycode_name,
                            };
 
                            //生成入库任务
                            Dt_Task dt_Task = new()
                            {
                                PalletCode = saveModel.barcode.ToString(),
                                TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                                Roadway = newLocation.RoadwayNo,
                                TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                                TaskStatus = InTaskStatusEnum.InNew.ObjToInt(),
                                SourceAddress = saveModel.stationnum.ToString(),
                                TargetAddress = newLocation.LocationCode,
                                CurrentAddress = saveModel.stationnum.ToString(),
                                NextAddress = newLocation.LocationCode,
                                Grade = 1,
                                Depth = newLocation.Depth,
                                MaterialType = (int)InventoryMaterialType.空托,
                                Creater = "WMS",
                                CreateDate= DateTime.Now,
                            };
 
                            BaseDal.AddData(dt_Task);
                            _stockService.StockInfoService.Repository.AddData(dt_Stock);
                            _basicService.LocationInfoService.UpdateData(newLocation);
 
                            return content.OK(data: dt_Task);
 
                        }
                        else
                        {
                            return content.Error("已无可用的货架,无法入库");
                        }
 
                    }
                    else
                    {
                        return content.Error("未在托盘管理中找到该托盘");
                    }
 
                }
                else
                {
                    return content.Error("申请入库的条码为空,入库失败!");
                }
            }
            catch (Exception ex)
            {
                return content.Error($"入库添加失败,系统错误:{ex.Message}");
                throw;
            }
        }
 
 
        /// <summary>
        /// 检修回库方法
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent MaintenanceStorage(GenerateInv saveModel)
        {
            WebResponseContent content = new WebResponseContent();
 
            //查找货位信息,并修改
            try
            {
 
                Dt_StockInfo stocktData = _stockService.StockInfoService.Repository.QueryFirst(x => x.StockStatus == (int)StockStatusEmun.检修中 && x.MaterialType == (int)InventoryMaterialType.满托 && x.PalletCode== saveModel.barcode.ToString());
 
                if (stocktData != null)
                {
                    stocktData.StockStatus = (int)StockStatusEmun.检修入库锁定;
                    //生成入库任务
                    Dt_Task dt_Task = new()
                    {
                        PalletCode = saveModel.barcode.ToString(),
                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                        Roadway = "1",
                        TaskType = TaskTypeEnum.PalletMaintenancein.ObjToInt(),
                        TaskStatus = AGVTaskStatusEnum.AGVin_Executing.ObjToInt(),
                        SourceAddress = saveModel.stationnum.ToString(),
                        TargetAddress = stocktData.LocationCode,
                        CurrentAddress = saveModel.stationnum.ToString(),
                        NextAddress = stocktData.LocationCode,
                        Grade = 1,
                        Depth = 1,
                        MaterialType = (int)InventoryMaterialType.满托,
                        Creater="WMS",
                        CreateDate = DateTime.Now,
                    };
 
                    BaseDal.AddData(dt_Task);
                    _stockService.StockInfoService.Repository.UpdateData(stocktData);
                    //调取wcs接口传递任务
                    //WebResponseContent webResponseContent = HttpHelper.Post<WebResponseContent>(ReceiveWCSTask, dt_Task, "入库任务下发");
                    return content.OK(data: dt_Task);
                }
                else
                {
                    return content.Error($"未找到该托盘条码的库存,申请的托盘条码:{saveModel.barcode.ToString()},站台编号{saveModel.stationnum.ToString()}");
                }
            }
            catch (Exception ex)
            {
                return content.Error($"入库添加失败,系统错误:{ex.Message}");
                throw;
            }
        }
    }
}