1
huanghongfeng
2024-11-22 91adcbb1b813198d0a81ca03257bf94d43d4ef60
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs
@@ -17,6 +17,7 @@
using static WIDESEA_ITaskInfoService.ITaskService;
using MailKit.Search;
using WIDESEA_Common.Log;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
namespace WIDESEA_TaskInfoService
{
@@ -654,7 +655,6 @@
        public WebResponseContent ManualOutbound(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_StockInfo> dtstockt = new List<Dt_StockInfo>();
@@ -666,72 +666,81 @@
                    Dt_StockInfo stockt = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == saveModel.DelKeys[i].ToString());
                    if (stockt.StockStatus == (int)StockStatusEmun.已入库)
                    {
                        Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockt.Id);
                        stockt.StockStatus = (int)StockStatusEmun.出库锁定;
                        if (stockt.MaterialType != (int)InventoryMaterialType.空托)
                        if(stockt.MaterialType != (int)InventoryMaterialType.原材料)
                        {
                            stocktdetail.Status = (int)StockStatusEmun.出库锁定;
                        }
                        Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockt.LocationCode);
                        if (locationinfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
                        {
                            locationinfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                        }
                        else if (locationinfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt())
                        {
                            locationinfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt();
                        }
                        string LocationName = "R01-002-044-001-01";
                        if (stockt.MaterialType == (int)InventoryMaterialType.原材料)
                        {
                            Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockt.Id);
                            stockt.StockStatus = (int)StockStatusEmun.出库锁定;
                            if (stockt.MaterialType != (int)InventoryMaterialType.空托)
                            {
                                stocktdetail.Status = (int)StockStatusEmun.出库锁定;
                            }
                            Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockt.LocationCode);
                            if (locationinfo.RoadwayNo == "1")
                            {
                                LocationName = "R01-002-041-011-01";
                                if (locationinfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
                                {
                                    locationinfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                                }
                                else if (locationinfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt())
                                {
                                    locationinfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt();
                                }
                                string LocationName = "R01-002-044-001-01";
                                if (stockt.MaterialType == (int)InventoryMaterialType.空托)
                                {
                                    LocationName = "R01-002-043-001-01";
                                }
                                Dt_LocationInfo newTargetAddress;
                                newTargetAddress = _basicService.LocationInfoService.GetLocationplatform(LocationName);
                                Dt_Task dt_Task = new()
                                {
                                    PalletCode = stockt.PalletCode,
                                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                                    Roadway = newTargetAddress.RoadwayNo,
                                    TaskType = TaskTypeEnum.Outbound.ObjToInt(),
                                    TaskStatus = InTaskStatusEnum.InNew.ObjToInt(),
                                    SourceAddress = locationinfo.LocationCode,
                                    TargetAddress = newTargetAddress.LocationCode,
                                    CurrentAddress = locationinfo.LocationCode,
                                    NextAddress = newTargetAddress.LocationCode,
                                    Grade = 1,
                                    Creater = "WMS",
                                    Depth = locationinfo.Depth,
                                    CreateDate = DateTime.Now,
                                };
                                dtstockt.Add(stockt);
                                locations.Add(locationinfo);
                                taskdt.Add(dt_Task);
                                if (stockt.MaterialType != (int)InventoryMaterialType.空托)
                                {
                                    dtstocktdetail.Add(stocktdetail);
                                }
                            }
                            else
                            {
                                LocationName = "R02-002-027-011-01";
                                return content = WebResponseContent.Instance.Error($"出库失败,只可出库1巷道的托盘和成品");
                            }
                        }
                        Dt_LocationInfo newTargetAddress;
                        newTargetAddress = _basicService.LocationInfoService.GetLocationplatform(LocationName);
                        Dt_Task dt_Task = new()
                        else
                        {
                            PalletCode = stockt.PalletCode,
                            TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                            Roadway = newTargetAddress.RoadwayNo,
                            TaskType = TaskTypeEnum.Outbound.ObjToInt(),
                            TaskStatus = InTaskStatusEnum.InNew.ObjToInt(),
                            SourceAddress = locationinfo.LocationCode,
                            TargetAddress = newTargetAddress.LocationCode,
                            CurrentAddress = locationinfo.LocationCode,
                            NextAddress = newTargetAddress.LocationCode,
                            Grade = 1,
                            Creater = "WMS",
                            Depth = locationinfo.Depth,
                            CreateDate = DateTime.Now,
                        };
                        dtstockt.Add(stockt);
                        locations.Add(locationinfo);
                        taskdt.Add(dt_Task);
                        if (stockt.MaterialType != (int)InventoryMaterialType.空托)
                        {
                            dtstocktdetail.Add(stocktdetail);
                            return content = WebResponseContent.Instance.Error($"出库失败,请不要选择原材料出库");
                        }
                    }
                    else
                    {
                        return content = WebResponseContent.Instance.Error($"出库失败,该库存信息不可进行出库");
                        return content = WebResponseContent.Instance.Error($"出库失败,请选择已入库的库存信息进行出库");
                    }
                }
                var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTask, taskdt, "下发任务入库");
                _unitOfWorkManage.BeginTran();
                _stockService.StockInfoService.Repository.UpdateData(dtstockt);
                _stockService.StockInfoDetailService.Repository.UpdateData(dtstocktdetail);
                _basicService.LocationInfoService.Repository.UpdateData(locations);
                BaseDal.AddData(taskdt);
                if (dtstockt.Count > 0)
                {
                    _stockService.StockInfoService.Repository.UpdateData(dtstockt);
                    _stockService.StockInfoDetailService.Repository.UpdateData(dtstocktdetail);
                    _basicService.LocationInfoService.Repository.UpdateData(locations);
                    BaseDal.AddData(taskdt);
                }
                _unitOfWorkManage.CommitTran();
                content = WebResponseContent.Instance.OK();
                return content;
@@ -744,6 +753,98 @@
            }
        }
        public WebResponseContent ManualOutbound2(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_StockInfo> dtstockt = new List<Dt_StockInfo>();
                List<Dt_LocationInfo> locations = new List<Dt_LocationInfo>();
                List<Dt_Task> taskdt = new List<Dt_Task>();
                List<Dt_StockInfoDetail> dtstocktdetail = new List<Dt_StockInfoDetail>();
                List<Dt_StockInfo> stocktData= _stockService.StockInfoService.Repository.QueryData(x=>x.StockStatus== (int)StockStatusEmun.已入库 && x.MaterialType == (int)InventoryMaterialType.原材料);
                List<Dt_LocationInfo> locationinfoData = _basicService.LocationInfoService.Repository.QueryData(x =>x.LocationStatus == LocationStatusEnum.InStock.ObjToInt());
                List<Dt_StockInfoDetail> StockInfoDetailData = _stockService.StockInfoDetailService.Repository.QueryData(x => x.Status == (int)StockStatusEmun.已入库);
                string json = saveModel.DelKeys[0].ToString();
                List<string> palletCodes = JsonConvert.DeserializeObject<List<string>>(json);
                foreach (var palletCode in palletCodes)
                {
                    Dt_StockInfo stockt = stocktData.FirstOrDefault(x => x.PalletCode == palletCode);
                    if (stockt !=null)
                    {
                        if (stockt.StockStatus == (int)StockStatusEmun.已入库)
                        {
                            Dt_StockInfoDetail stocktdetail = StockInfoDetailData.FirstOrDefault(x => x.StockId == stockt.Id);
                            if(stocktdetail != null)
                            {
                                Dt_LocationInfo locationinfo = locationinfoData.FirstOrDefault(x => x.LocationCode == stockt.LocationCode);
                                if(locationinfo != null)
                                {
                                    stockt.StockStatus = (int)StockStatusEmun.出库锁定;
                                    if (locationinfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
                                    {
                                        locationinfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                                    }
                                    Dt_Task dt_Task = new()
                                    {
                                        PalletCode = stockt.PalletCode,
                                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                                        Roadway = locationinfo.RoadwayNo,
                                        TaskType = TaskTypeEnum.Outbound.ObjToInt(),
                                        TaskStatus = InTaskStatusEnum.InNew.ObjToInt(),
                                        SourceAddress = locationinfo.LocationCode,
                                        TargetAddress = locationinfo.RoadwayNo == "2" ? "R02-002-027-011-01" : "R01-002-041-011-01",
                                        CurrentAddress = locationinfo.LocationCode,
                                        NextAddress = locationinfo.RoadwayNo == "2" ? "R02-002-027-011-01" : "R01-002-041-011-01",
                                        Grade = 1,
                                        Creater = "WMS",
                                        Depth = locationinfo.Depth,
                                        CreateDate = DateTime.Now,
                                        PLCTo = int.Parse(saveModel.DelKeys[1].ToString()),
                                    };
                                    dtstockt.Add(stockt);
                                    locations.Add(locationinfo);
                                    taskdt.Add(dt_Task);
                                    dtstocktdetail.Add(stocktdetail);
                                }
                            }
                        }
                    }
                }
                var responses = HttpHelper.Post<WebResponseContent>(ReceiveWMSTask, taskdt, "下发任务入库");
                _unitOfWorkManage.BeginTran();
                if(dtstockt.Count > 0)
                {
                    _stockService.StockInfoService.Repository.UpdateData(dtstockt);
                    _stockService.StockInfoDetailService.Repository.UpdateData(dtstocktdetail);
                    _basicService.LocationInfoService.Repository.UpdateData(locations);
                    BaseDal.AddData(taskdt);
                }
                _unitOfWorkManage.CommitTran();
                content = WebResponseContent.Instance.OK($"出库成功,出库总数:{palletCodes.Count},成功数量:{dtstockt.Count}");
                return content;
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return content = WebResponseContent.Instance.Error($"出库失败,报错信息:{ex.Message}");
                throw;
            }
        }
        public class PalletCodeList
        {
            public string PalletCode { get; set; }
        }
        public (Dt_Task?, Dt_LocationInfo?) AddRelocationTask(Dt_LocationInfo location, Dt_StockInfo stockInfo, Dt_Task task)
        {
            Dt_LocationInfo? locationInfos = _basicService.LocationInfoService.AssignLocation(location.RoadwayNo);