1
dengjunjie
2025-05-08 092971a8ba7848f024427694c642959d0fbc8599
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_ProductionLine.cs
@@ -1,4 +1,5 @@
using Magicodes.IE.Core;
using MailKit.Search;
using System;
using System.Threading.Tasks;
using WIDESEA_Core;
@@ -24,102 +25,47 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                switch (productionlineDTO.traytype)
                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
                string OrderNo = productionlineDTO.batchNo.Substring(0, 8);// DateTime.Now.ToString("yyMMdd");
                Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(OrderNo);
                if (inboundOrder == null) throw new Exception($"未找到批号为【{OrderNo}】的入库单");
                //var BatchNo = string.Join("", productionlineDTO.batchNo.Except(OrderNo));
                var BatchNo = productionlineDTO.batchNo.Substring(8);
                Dt_InboundOrderDetail? inboundOrderDetail = inboundOrder.Details.Where(x => x.BatchNo == BatchNo).FirstOrDefault();
                if (inboundOrderDetail == null) throw new Exception($"批号【{OrderNo}】的入库单未找到柜号【{BatchNo}】");
                if (inboundOrderDetail.OrderQuantity - inboundOrderDetail.ReceiptQuantity < 1) throw new Exception($"批号【{OrderNo}】的柜号【{BatchNo}】可组盘数量不足");
                Dt_Task dt_Task = new Dt_Task()
                {
                    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();
                    CurrentAddress = productionlineDTO.stationCode,
                    NextAddress = "SC01",
                    SourceAddress = productionlineDTO.stationCode,
                    TargetAddress = "SC01",
                    Creater = "System",
                    PalletCode = productionlineDTO.Barcode,
                    Roadway = "SC01",
                    OrderNo = productionlineDTO.batchNo,// inboundOrder.OrderNo,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    CreateDate = DateTime.Now,
                    Dispatchertime = DateTime.Now,
                };
                            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("未定义托盘类型");
                }
                productionlineDTO.batchNo = BatchNo;
                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
            }
            catch (Exception ex)
            {
@@ -158,7 +104,7 @@
                    PalletCode = lineDTO.Barcode,
                    OrderNo = StockInfoDetails.Count() == 1 ? StockInfoDetails.First().OrderNo : null,
                    Roadway = "SC01",
                    TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    TaskState = InTaskStatusEnum.InNew.ObjToInt(),
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                };