dengjunjie
2025-03-27 bb56b2b6f21acb7c69c02585e5bc534d2f67715f
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
using Magicodes.IE.Core;
using MailKit.Search;
using System;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.WCSInfo;
using WIDESEA_Model.Models;
using WIDESEAWCS_DTO.WCSInfo;
 
namespace WIDESEA_TaskInfoService
{
    public partial class TaskService
    {
 
        /// <summary>
        /// 产线申请
        /// </summary>
        /// <param name="productionlineDTO"></param>
        /// <returns></returns>
        public WebResponseContent ProductionlineRequest(ProductionlineDTO productionlineDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                #region MyRegion
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(productionlineDTO.Barcode);
                if (stockInfo != null) throw new Exception($"托盘【{productionlineDTO.Barcode}】已存在库存信息");
                stockInfo = new Dt_StockInfo();
                stockInfo.Details = new List<Dt_StockInfoDetail>();
                #region MyRegion
                Dt_InboundOrderDetail inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == productionlineDTO.batchNo);
                if (inboundOrderDetail == null)
                    throw new Exception($"未找到批号【{productionlineDTO.batchNo}】的入库详情");
                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1)
                    throw new Exception($"批号【{productionlineDTO.batchNo}】组盘数量超出");
                Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.Id == inboundOrderDetail.OrderId);
                if (inboundOrder == null) throw new Exception($"未找到批号【{productionlineDTO.batchNo}】的入库头表");
                inboundOrder.Details = new List<Dt_InboundOrderDetail>() { inboundOrderDetail };
                #endregion
                #region MyRegion
                //var OrderNo = productionlineDTO.batchNo.Split('T')[0];
                //Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(OrderNo);
                //if (inboundOrder == null) throw new Exception($"未找到入库单【{OrderNo}】");
                //Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == productionlineDTO.batchNo);
                //if (inboundOrderDetail == null) throw new Exception($"未找到批号【{productionlineDTO.batchNo}】的入库详情");
                //if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1) throw new Exception($"批号【{productionlineDTO.batchNo}】组盘数量超出"); 
                #endregion
 
                Dt_Task dt_Task = new Dt_Task()
                {
                    CurrentAddress = productionlineDTO.stationCode,
                    NextAddress = "SC01",
                    SourceAddress = productionlineDTO.stationCode,
                    TargetAddress = "SC01",
                    Creater = "System",
                    PalletCode = productionlineDTO.Barcode,
                    Roadway = "SC01",
                    OrderNo = inboundOrder.OrderNo,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    //TaskType = productionlineDTO.traytype == 2 ? TaskTypeEnum.PalletInbound.ObjToInt() : TaskTypeEnum.PalletReturnInbound.ObjToInt(),
                    CreateDate = DateTime.Now,
                    Dispatchertime = DateTime.Now,
                };
 
                content = _stockService.StockInfoService.AddStockInfo(ref stockInfo, ref inboundOrder, productionlineDTO);
                if (!content.Status) throw new Exception(content.Message);
                Db.Ado.BeginTran();
                _inboundService.InbounOrderService.UpdateDataWithDetail(inboundOrder);
                _stockService.StockInfoService.AddMaterielGroup(stockInfo);
                AddData(dt_Task);
                content.OK(data: dt_Task);
                Db.Ado.CommitTran();
                #endregion
                #region MyRegion
                //switch (productionlineDTO.traytype)
                //{
                //    case 1://放空托
                //    case 3://放空盒
                //           //case 5://放满盒
                //        {
                //            //查找物料所有库存
                //            var stockInfos = _stockService.StockInfoService.Repository.GetStockInfos(productionlineDTO.traytype.ToString());
                //            //查找先入物料货位最后入库物料
                //            var stockInfo = stockInfos.Where(x => x.LocationCode == stockInfos.OrderBy(x => x.InDate).FirstOrDefault()?.LocationCode).OrderByDescending(x => x.InDate).FirstOrDefault();
                //            if (stockInfo == null) throw new Exception($"无物料编号【{productionlineDTO.traytype}】的库存");
                //            var location = _basicService.LocationInfoService.GetLocation(stockInfo.LocationCode);
                //            #region 生成出库任务
                //            Dt_Task dt_Task = new Dt_Task()
                //            {
                //                CurrentAddress = stockInfo.LocationCode,
                //                NextAddress = "SC01",
                //                SourceAddress = stockInfo.LocationCode,
                //                TargetAddress = productionlineDTO.stationCode,
                //                Creater = "System",
                //                PalletCode = stockInfo.PalletCode,
                //                OrderNo = null,
                //                Roadway = "SC01",
                //                TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
                //                TaskState = OutTaskStatusEnum.OutNew.ObjToInt(),
                //                TaskType = productionlineDTO.traytype == 1 ? TaskTypeEnum.PalletOutbound.ObjToInt() : TaskTypeEnum.PalletFillOutbound.ObjToInt(),
                //                IsPickPlace = location.MaxQty - location.CurrentQty == 0,
                //                CreateDate = DateTime.Now,
                //                Dispatchertime = DateTime.Now,
                //            };
                //            #endregion
                //            location.CurrentQty--;
                //            location.LocationStatus = LocationStatusEnum.Outbounding.ObjToInt();
                //            stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                //            stockInfo.Details.FirstOrDefault().Status = StockStatusEmun.出库锁定.ObjToInt();
 
                //            Db.Ado.BeginTran();
                //            AddData(dt_Task);
                //            _basicService.LocationInfoService.UpdateData(location);
                //            _stockService.StockInfoService.Repository.UpdateDataWithDetail(stockInfo);
                //            content.OK(data: dt_Task);
                //            Db.Ado.CommitTran();
                //        }
                //        break;
                //    case 2://取空托
                //    case 4://取满盒
                //    case 6://取空盒
                //        {
                //            Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(productionlineDTO.Barcode);
                //            if (stockInfo != null) throw new Exception($"托盘【{productionlineDTO.Barcode}】已存在库存信息");
                //            productionlineDTO.QtySum = Array.ConvertAll(productionlineDTO.productQty.Split(","), s => decimal.Parse(s)).Sum();//入库总数
                //            stockInfo = new Dt_StockInfo();
                //            stockInfo.Details = new List<Dt_StockInfoDetail>();
                //            Dt_InboundOrder inboundOrder = null;
                //            #region 生成入库任务
                //            Dt_Task dt_Task = new Dt_Task()
                //            {
                //                CurrentAddress = productionlineDTO.stationCode,
                //                NextAddress = "SC01",
                //                SourceAddress = productionlineDTO.stationCode,
                //                TargetAddress = "SC01",
                //                Creater = "System",
                //                PalletCode = productionlineDTO.Barcode,
                //                Roadway = "SC01",
                //                TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
                //                TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                //                TaskType = productionlineDTO.traytype == 2 ? TaskTypeEnum.PalletInbound.ObjToInt() : TaskTypeEnum.PalletReturnInbound.ObjToInt(),
                //                CreateDate = DateTime.Now,
                //                Dispatchertime = DateTime.Now,
                //            };
                //            #endregion
                //            if (productionlineDTO.traytype == 4)
                //            {
                //                var OrderNo = productionlineDTO.batchNo.Split('T')[0];
                //                inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(OrderNo);
                //                if (inboundOrder == null) throw new Exception($"未找到入库单【{OrderNo}】");
                //                Dt_InboundOrderDetail inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == productionlineDTO.batchNo);
                //                if (inboundOrderDetail == null) throw new Exception($"未找到批号【{productionlineDTO.batchNo}】的入库详情");
                //                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1) throw new Exception($"批号【{productionlineDTO.batchNo}】组盘数量超出");
 
                //                dt_Task.OrderNo = OrderNo;
                //                dt_Task.TaskType = TaskTypeEnum.Inbound.ObjToInt();
                //            }
                //            content = _stockService.StockInfoService.AddStockInfo(ref stockInfo, ref inboundOrder, productionlineDTO);
                //            if (!content.Status) throw new Exception(content.Message);
                //            Db.Ado.BeginTran();
                //            if (inboundOrder != null) _inboundService.InbounOrderService.UpdateDataWithDetail(inboundOrder);
                //            _stockService.StockInfoService.AddMaterielGroup(stockInfo);
                //            AddData(dt_Task);
                //            content.OK(data: dt_Task);
                //            Db.Ado.CommitTran();
                //        }
                //        break;
                //    default:
                //        throw new Exception("未定义托盘类型");
                //} 
                #endregion
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// 产线申请
        /// </summary>
        /// <param name="lineDTO"></param>
        /// <returns></returns>
        public WebResponseContent ProductionlineRequest(ConveyorLineDTO lineDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode);
                if (task != null && task.TaskType == TaskTypeEnum.Inbound.ObjToInt())
                    return content.OK(data: task);
                if (task != null) throw new Exception($"托盘号[{lineDTO.Barcode}]已存在任务");
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode);
                (bool, string) result = CheckRequestInbound(lineDTO.stationCode, lineDTO.Barcode, true, stockInfo);
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                var StockInfoDetails = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).ToList();
                #region 生成入库任务
                Dt_Task dt_Task = new Dt_Task()
                {
                    CurrentAddress = lineDTO.stationCode,
                    NextAddress = "SC01",
                    SourceAddress = lineDTO.stationCode,
                    TargetAddress = "SC01",
                    CreateDate = DateTime.Now,
                    Creater = "System",
                    PalletCode = lineDTO.Barcode,
                    OrderNo = StockInfoDetails.Count() == 1 ? StockInfoDetails.First().OrderNo : null,
                    Roadway = "SC01",
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                };
                dt_Task.Dispatchertime = dt_Task.CreateDate;
                Db.Ado.BeginTran();
                BaseDal.AddData(dt_Task);
                task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode && x.TaskType == TaskTypeEnum.Inbound.ObjToInt());
                //content.Data = dt_Task;
                Db.Ado.CommitTran();
                if (task != null) return content.OK(data: task);
                #endregion
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
    }
}