huanghongfeng
4 天以前 1d8897348d578648421b024d0dc5ff3d626e05f9
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs
@@ -16,6 +16,8 @@
using System.Security.Policy;
using static WIDESEA_ITaskInfoService.ITaskService;
using MailKit.Search;
using WIDESEA_Common.Log;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
namespace WIDESEA_TaskInfoService
{
@@ -402,7 +404,7 @@
                    }
                    targetCodes[4] = "01";
                    string LocationCode = string.Join("-", targetCodes); //组装浅库位地址
                    Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
                    Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode && (x.LocationStatus == (int)LocationStatusEnum.Free || x.LocationStatus == (int)LocationStatusEnum.InStock));
                    if (locationInfos == null)
                    {
                        return content = WebResponseContent.Instance.Error($"未找到该货位信息,货位编号:{locationInfos}");
@@ -415,7 +417,7 @@
                        }
                        else
                        {
                            Dt_StockInfo dt_StockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
                            Dt_StockInfo dt_StockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode && x.StockStatus== (int)StockStatusEmun.已入库);
                            if (dt_StockInfo == null)
                            {
                                return content = WebResponseContent.Instance.Error($"未找到该货位的库存信息,货位编号:{LocationCode}");
@@ -424,7 +426,47 @@
                            {
                                Dt_LocationInfo newLocation;
                                //查走货位,进行生成移库任务 
                                newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo); //拿到了移库后的货位
                                int Locationtype = 9;   //默认为9
                                if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.成品)
                                {
                                    Locationtype = 11;
                                }
                                else if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.原材料)
                                {
                                    Locationtype = 10;
                                }
                                //newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo,Locationtype); //拿到了移库后的货位
                                if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.成品)
                                {
                                    string[] targetCodesst = dt_StockInfo.PalletCode.Split("*");
                                    Dt_InboundOrder dt_Inbound = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.OrderName == targetCodesst[0]);
                                    if (dt_Inbound.Startingcolumn != 0 || dt_Inbound.Terminationcolumn != 0)
                                    {
                                        newLocation = _basicService.LocationInfoService.GetLocation2(locationInfos.RoadwayNo, Locationtype, dt_Inbound.Startingcolumn, dt_Inbound.Terminationcolumn);
                                    }
                                    else
                                    {
                                        newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype);
                                    }
                                }
                                else
                                {
                                    newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype);
                                }
                                //目标货位查找库位是否有货
                                Dt_StockInfo dt_StockCurren = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == newLocation.LocationCode);
                                if (dt_StockCurren != null) return content = WebResponseContent.Instance.Error($"入库失败,托盘条码:{dt_StockInfo.PalletCode},查找出的货位信息对应已有库存");
                                Dt_Task taskcurren = BaseDal.QueryFirst(x => x.TargetAddress == newLocation.LocationCode);
                                if (taskcurren != null) return content = WebResponseContent.Instance.Error($"入库失败,托盘条码:{dt_StockInfo.PalletCode},查找出的货位信息已有入库任务");
                                bool crutaskthy = _taskHtyService.CrueeTaskHty(newLocation.LocationCode);
                                if (crutaskthy) return content = WebResponseContent.Instance.Error($"入库失败,托盘条码:{dt_StockInfo.PalletCode},查找出的货位在任务历史信息中,有入库或移库信息");
                                if (newLocation != null)
                                {
                                    Dt_Task dt_Task = new()
@@ -441,6 +483,7 @@
                                        Creater = "WMS",
                                        CreateDate = DateTime.Now,
                                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                                        MaterialType = dt_StockInfo.MaterialType
                                    };
                                    _unitOfWorkManage.BeginTran();
                                    if (locationInfos.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
@@ -457,6 +500,7 @@
                                    loca.Add(newLocation);
                                    loca.Add(locationInfos);
                                    _basicService.LocationInfoService.UpdateData(loca);
                                    BaseDal.AddData(dt_Task);
                                    _unitOfWorkManage.CommitTran();
                                    return content = WebResponseContent.Instance.OK(data: dt_Task);
                                }
@@ -499,7 +543,12 @@
                    {
                        RoadwayNo = "2";
                    }
                    Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.RoadwayNo == RoadwayNo && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt());
                    Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.RoadwayNo == RoadwayNo && x.EnableStatus != (int)EnableStatusEnum.Disable && x.Depth==1 && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt());
                    if(locationInfos == null)
                    {
                        locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.RoadwayNo == RoadwayNo && x.Depth == 2 && x.EnableStatus != (int)EnableStatusEnum.Disable && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt());
                    }
                    if (locationInfos != null)
                    {
                        Dt_StockInfo dt_StockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == locationInfos.LocationCode);
@@ -527,6 +576,7 @@
                                    Depth = locationInfos.Depth,
                                    CreateDate = DateTime.Now,
                                    PalletCodequantity = (int)dt_StockInfo.Materialweight,
                                    MaterialType = dt_StockInfo.MaterialType
                                };
                                _unitOfWorkManage.BeginTran();
@@ -607,6 +657,7 @@
                            CreateDate = DateTime.Now,
                            PalletCodequantity = (int)dt_StockInfo[i].Materialweight,
                            PLCTo = generate.TargetAddress == "R01-002-041-011-01" ? 1 : 2,
                            MaterialType = dt_StockInfo[i].MaterialType
                        };
                        _unitOfWorkManage.BeginTran();
@@ -635,6 +686,7 @@
                return content = WebResponseContent.Instance.Error($"未找到出库的库存信息");
            }
        }
        /// <summary>
        /// æ‰‹åŠ¨ç”Ÿæˆå‡ºåº“ä»»åŠ¡
        /// </summary>
@@ -643,7 +695,6 @@
        public WebResponseContent ManualOutbound(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_StockInfo> dtstockt = new List<Dt_StockInfo>();
@@ -653,74 +704,84 @@
                for (int i = 0; i < saveModel.DelKeys.Count; i++)
                {
                    Dt_StockInfo stockt = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == saveModel.DelKeys[i].ToString());
                    if (stockt.StockStatus != (int)StockStatusEmun.已入库)
                    if (stockt.StockStatus == (int)StockStatusEmun.已入库 && (stockt.Wlstatus == (int)InventoryMaterialStatus.合格 || stockt.Wlstatus == (int)InventoryMaterialStatus.返工 || stockt.Wlstatus == (int)InventoryMaterialStatus.特采) )
                    {
                        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-003-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,
                                    MaterialType= stockt.MaterialType
                                };
                                dtstockt.Add(stockt);
                                locations.Add(locationinfo);
                                taskdt.Add(dt_Task);
                                if (stockt.MaterialType != (int)InventoryMaterialType.空托)
                                {
                                    dtstocktdetail.Add(stocktdetail);
                                }
                            }
                            else
                            {
                                LocationName = "R02-003-027-011-01";
                                return content = WebResponseContent.Instance.Error($"出库失败,只可出库1巷道的托盘和成品,出库条码:{saveModel.DelKeys[i].ToString()}");
                            }
                        }
                        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($"出库失败,请不要选择原材料出库,出库条码:{saveModel.DelKeys[i].ToString()}");
                        }
                    }
                    else
                    {
                        return content = WebResponseContent.Instance.Error($"出库失败,该库存信息不可进行出库");
                        return content = WebResponseContent.Instance.Error($"出库失败,请选择已入库且(合格,返工,特采)的物料出库!!!,出库条码:{saveModel.DelKeys[i].ToString()}");
                    }
                }
                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;
@@ -732,6 +793,222 @@
                throw;
            }
        }
        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.已入库 && (stockt.Wlstatus == (int)InventoryMaterialStatus.合格 || stockt.Wlstatus == (int)InventoryMaterialStatus.退货 || stockt.Wlstatus == (int)InventoryMaterialStatus.特采))
                        {
                            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();
                                    }
                                    string TargetAdd = "";
                                    if (saveModel.DelKeys[1].ToString()=="20")
                                    {
                                        TargetAdd = "R02-001-021-001-02";
                                    }else if(saveModel.DelKeys[1].ToString() == "30")
                                    {
                                        TargetAdd = "R02-001-022-001-02";
                                    }
                                    else if (saveModel.DelKeys[1].ToString() == "40")
                                    {
                                        TargetAdd = "R01-002-044-001-01";
                                    }
                                    else
                                    {
                                        TargetAdd = locationinfo.RoadwayNo == "2" ? "R02-002-027-011-01" : "R01-002-041-011-01";
                                    }
                                    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 = TargetAdd,
                                        CurrentAddress = locationinfo.LocationCode,
                                        NextAddress = TargetAdd,
                                        Grade = 1,
                                        Creater = "WMS",
                                        Depth = locationinfo.Depth,
                                        CreateDate = DateTime.Now,
                                        PLCTo = int.Parse(saveModel.DelKeys[1].ToString()),
                                        MaterialType=stockt.MaterialType
                                    };
                                    dtstockt.Add(stockt);
                                    locations.Add(locationinfo);
                                    taskdt.Add(dt_Task);
                                    dtstocktdetail.Add(stocktdetail);
                                }
                                else
                                {
                                    return content = WebResponseContent.Instance.Error($"出库失败,未找到对应的库位信息,请核对!!!,出库条码:{palletCode}");
                                }
                            }
                            else
                            {
                                return content = WebResponseContent.Instance.Error($"出库失败,未找到对应的库存详情信息,请核对!!!,出库条码:{palletCode}");
                            }
                        }
                        else
                        {
                            return content = WebResponseContent.Instance.Error($"出库失败,请选择已入库且(合格,特采,退货)的物料出库!!!,出库条码:{palletCode}");
                        }
                    }
                    else
                    {
                        return content = WebResponseContent.Instance.Error($"出库失败,未找到对应条码的库存信息,出库条码:{palletCode}");
                    }
                }
                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 WebResponseContent ManualOutbound3(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_StockInfo> dtstockt = new List<Dt_StockInfo>();
                List<Dt_StockInfo> stocktData = _stockService.StockInfoService.Repository.QueryData(x => x.StockStatus == (int)StockStatusEmun.已入库);
                string json = saveModel.DelKeys[0].ToString();
                List<int> palletCodes = JsonConvert.DeserializeObject<List<int>>(json);
                foreach (int pallid in palletCodes)
                {
                    Dt_StockInfo stockt = stocktData.FirstOrDefault(x => x.Id == pallid);
                    if (stockt != null)
                    {
                        stockt.Wlstatus = int.Parse(saveModel.DelKeys[1].ToString());
                        dtstockt.Add(stockt);
                    }
                    else
                    {
                        return content = WebResponseContent.Instance.Error($"修改失败,未找到对应的库存信息,库存编号:{pallid}");
                    }
                }
                _unitOfWorkManage.BeginTran();
                if (dtstockt.Count > 0)
                {
                    _stockService.StockInfoService.Repository.UpdateData(dtstockt);
                }
                _unitOfWorkManage.CommitTran();
                content = WebResponseContent.Instance.OK($"修改成功");
                return content;
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return content = WebResponseContent.Instance.Error($"修改失败,报错信息:{ex.Message}");
                throw;
            }
        }
        public WebResponseContent ManualOutbound4(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                List<Dt_StockInfo> dtstockt = new List<Dt_StockInfo>();
                List<Dt_StockInfo> stocktData = _stockService.StockInfoService.Repository.QueryData(x => x.StockStatus == (int)StockStatusEmun.已入库);
                string json = saveModel.DelKeys[0].ToString();
                List<int> palletCodes = JsonConvert.DeserializeObject<List<int>>(json);
                foreach (int pallid in palletCodes)
                {
                    Dt_StockInfo stockt = stocktData.FirstOrDefault(x => x.Id == pallid);
                    if (stockt != null)
                    {
                        stockt.Mgeneratetime = DateTime.Parse(saveModel.DelKeys[1].ToString());
                        dtstockt.Add(stockt);
                    }
                    else
                    {
                        return content = WebResponseContent.Instance.Error($"修改失败,未找到对应的库存信息,库存编号:{pallid}");
                    }
                }
                _unitOfWorkManage.BeginTran();
                if (dtstockt.Count > 0)
                {
                    _stockService.StockInfoService.Repository.UpdateData(dtstockt);
                }
                _unitOfWorkManage.CommitTran();
                content = WebResponseContent.Instance.OK($"修改成功");
                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)
        {
@@ -928,5 +1205,188 @@
            }
            return (null, LocationStatusEnum.Free.ObjToInt());
        }
        /// <summary>
        /// äººå·¥æ‰‹åŠ¨å‡ºåº“ï¼ˆåˆ é™¤åº“å­˜ï¼‰
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent ManualOutboundDeleteinventory(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_StockInfoDetail> dtstocktdetail = new List<Dt_StockInfoDetail>();
                for (int i = 0; i < saveModel.DelKeys.Count; i++)
                {
                    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);
                        Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockt.LocationCode);
                        Dt_Task_Hty task_Hty = new Dt_Task_Hty()
                        {
                            TaskNum = 001,
                            PalletCode = stockt.PalletCode,
                            Roadway = locationinfo.RoadwayNo,
                            TaskType = (int)TaskTypeEnum.Outbound,
                            TaskStatus = (int)OutTaskStatusEnum.OutFinish,
                            SourceAddress = locationinfo.LocationCode,
                            TargetAddress = locationinfo.LocationCode,
                            CurrentAddress = locationinfo.LocationCode,
                            NextAddress = locationinfo.LocationCode,
                            Grade = 1,
                            Dispatchertime = DateTime.Now,
                            Creater = App.User.UserName,
                        CreateDate = DateTime.Now,
                            ModifyDate = DateTime.Now,
                            Modifier = App.User.UserName,
                            Remark = "人工出库",
                            PLCTo = 1,
                            PalletCodequantity = 1,
                            MaterialType = 1
                        };
                        _taskHtyService.AddData(task_Hty);
                        locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                        dtstockt.Add(stockt);
                        locations.Add(locationinfo);
                        if (stockt.MaterialType != (int)InventoryMaterialType.空托)
                        {
                            dtstocktdetail.Add(stocktdetail);
                        }
                        WriteLog.GetLog("人工手动删除库存信息").Write($"托盘条码:{stockt.PalletCode},库位编号:{stockt.LocationCode}", $"人工出库库存");
                    }
                    else
                    {
                        return content = WebResponseContent.Instance.Error($"出库失败,该库存信息不可进行出库");
                    }
                }
                _unitOfWorkManage.BeginTran();
                _stockService.StockInfoService.Repository.DeleteData(dtstockt);
                _stockService.StockInfoDetailService.Repository.DeleteData(dtstocktdetail);
                _basicService.LocationInfoService.Repository.UpdateData(locations);
                _unitOfWorkManage.CommitTran();
                content = WebResponseContent.Instance.OK();
                return content;
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return content = WebResponseContent.Instance.Error($"手动出库信息失败,报错信息:{ex.Message}");
                throw;
            }
        }
        /// <summary>
        /// ä»»åŠ¡å–æ¶ˆ
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent Cancelinventory(int taskNum)
        {
            WebResponseContent content = new WebResponseContent();
            Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
            if(task != null)
            {
                if(task.TaskType== (int)TaskTypeEnum.Outbound || task.TaskType == (int)TaskTypeEnum.PalletOutbound)
                {
                    //处理出库的逻辑
                    Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
                    if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt())
                    {
                        locationinfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    }
                    if (locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt())
                    {
                        locationinfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
                    }
                    _basicService.LocationInfoService.Repository.UpdateData(locationinfo);
                    Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode);
                    stockInfo.StockStatus = (int)StockStatusEmun.已入库;
                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                    Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id);
                    if(stocktdetail != null)
                    {
                        stocktdetail.Status = (int)StockStatusEmun.已入库;
                        _stockService.StockInfoDetailService.Repository.UpdateData(stocktdetail);
                    }
                    BaseDal.DeleteData(task);
                    BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工删除);
                    WriteLog.GetLog("任务日志").Write($"出库任务取消成功,托盘条码:{task.PalletCode}", $"任务取消");
                    WebResponseContent webResponseContent = HttpHelper.Post<WebResponseContent>(ReceiveWCSTask, task.TaskNum, "任务删除");
                    return content = WebResponseContent.Instance.Error($"出库任务取消成功");
                }
                else if(task.TaskType == (int)TaskTypeEnum.Inbound || task.TaskType == (int)TaskTypeEnum.PalletInbound)
                {
                    //处理出库的逻辑
                    Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                    if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt() || locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt())
                    {
                        locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                    }
                    _basicService.LocationInfoService.Repository.UpdateData(locationinfo);
                    Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode);
                    _stockService.StockInfoService.Repository.DeleteData(stockInfo);
                    Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id);
                    if (stocktdetail != null)
                    {
                        _stockService.StockInfoDetailService.Repository.DeleteData(stocktdetail);
                    }
                    BaseDal.DeleteData(task);
                    BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工删除);
                    WriteLog.GetLog("任务日志").Write($"入库任务取消成功,托盘条码:{task.PalletCode}", $"任务取消");
                    WebResponseContent webResponseContent = HttpHelper.Post<WebResponseContent>(ReceiveWCSTask, task.TaskNum, "任务删除");
                    return content = WebResponseContent.Instance.Error($"入库任务取消成功");
                }
                else if (task.TaskType == (int)TaskTypeEnum.RelocationIn)    //库内移库
                {
                    //处理出库的逻辑
                    Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                    if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt() || locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt())
                    {
                        locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt();
                    }
                    _basicService.LocationInfoService.Repository.UpdateData(locationinfo);
                    Dt_LocationInfo locationinfo2 = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
                    if (locationinfo2.LocationStatus == LocationStatusEnum.Lock.ObjToInt())
                    {
                        locationinfo2.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                    }
                    if (locationinfo2.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt())
                    {
                        locationinfo2.LocationStatus = LocationStatusEnum.Pallet.ObjToInt();
                    }
                    _basicService.LocationInfoService.Repository.UpdateData(locationinfo2);
                    Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode);
                    stockInfo.StockStatus = (int)StockStatusEmun.已入库;
                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                    Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id);
                    if (stocktdetail != null)
                    {
                        stocktdetail.Status = (int)StockStatusEmun.已入库;
                        _stockService.StockInfoDetailService.Repository.UpdateData(stocktdetail);
                    }
                    BaseDal.DeleteData(task);
                    BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工删除);
                    WriteLog.GetLog("任务日志").Write($"入库任务取消成功,托盘条码:{task.PalletCode}", $"任务取消");
                    WebResponseContent webResponseContent = HttpHelper.Post<WebResponseContent>(ReceiveWCSTask, task.TaskNum, "任务删除");
                    return content = WebResponseContent.Instance.Error($"入库任务取消成功");
                }
                else
                {
                    return content = WebResponseContent.Instance.Error($"该任务的任务类型异常,取消失败");
                }
            }
            else
            {
                return content = WebResponseContent.Instance.Error($"未找到任务号");
            }
        }
    }
}