helongyang
昨天 dc06f58d8ed537555fd529551180f43a0586ec3f
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs
@@ -1,4 +1,6 @@
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -9,12 +11,15 @@
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.OtherEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.WareHouseEnum;
using WIDESEA_Core;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.MES;
using WIDESEA_DTO.Task;
using WIDESEA_Model.Models;
@@ -56,7 +61,7 @@
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt())
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.送检完成.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
@@ -72,6 +77,10 @@
                {
                    Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseId);
                    if (locationInfo == null) return WebResponseContent.Instance.Error($"未找到当前库区货位信息");
                    if (stationCode!= "8005")
                    {
                        return WebResponseContent.Instance.Error($"起点错误:{stationCode}");
                    }
                    return DeviceRequestInboundTask(stationCode, locationInfo.RoadwayNo, palletCode);
                }
                else
@@ -88,7 +97,9 @@
                        TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfo.WarehouseId,
                        PalletType = stockInfo.PalletType
                        PalletType = stockInfo.PalletType,
                        MaterielCode = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode,
                        Quantity = (float)stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity),
                    };
                    //获取是否存在入库单
                    Dt_InboundOrder? inboundOrder =  null;
@@ -124,6 +135,11 @@
                        stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                        newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                    }
                    else if (stockInfo.StockStatus == StockStatusEmun.送检完成.ObjToInt())
                    {
                        stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                        newTask.TaskType = TaskTypeEnum.InQuality.ObjToInt();
                    }
                    else
                    {
                        stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
@@ -152,7 +168,52 @@
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// æŸ¥è¯¢è´¨æ£€æ•°é‡
        /// </summary>
        /// <param name="palletCode">托盘号</param>
        /// <returns></returns>
        public WebResponseContent InQualityConfirm(string palletCode)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(palletCode);
                if (stockInfo == null)
                {
                    return content.Error($"未找到该托盘库存信息");
                }
                if (stockInfo.Details.Count<=0)
                {
                    return content.Error($"该托盘库存明细为空");
                }
                if (stockInfo.StockStatus != StockStatusEmun.送检完成.ObjToInt())
                {
                    return content.Error($"该托盘还未送检出库完成");
                }
                Dt_OutStockLockInfo? outStockLockInfo = _outboundRepository.OutboundStockLockInfoRepository.QueryData(x => x.PalletCode == palletCode && x.Status == OutLockStockStatusEnum.出库完成.ObjToInt() && x.OrderType== OutOrderTypeEnum.Quality.ObjToInt()).OrderByDescending(x=>x.Id).FirstOrDefault();
                if (outStockLockInfo != null)
                {
                    //获取对应检验单
                    Dt_CheckOrder checkOrder = _checkOrderRepository.QueryFirst(x=>x.ReceiveDetailRowNo== outStockLockInfo.Id && x.CheckOrderStatus==CheckOrderStatusEnum.Checked.ObjToInt());
                    if (checkOrder == null)
                    {
                        return content.Error($"该托盘送检信息未检");
                    }
                    content.OK("成功", data:new { stockInfo.Details.FirstOrDefault()?.MaterielCode,checkOrder.ReceivedQuantity,checkOrder.ScrappedQuantity,checkOrder.DefectedQuantity,checkOrder.QualifiedQuantity,stockQuantity= stockInfo.Details.Sum(x=>x.StockQuantity) }) ;
                }
                else
                {
                    content.Error("该托盘送检出库详情不存在");
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// å…¥ç©ºç®±
        /// </summary>
@@ -324,8 +385,16 @@
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfoPPorGM.WarehouseId,
                        PalletType = stockInfoPPorGM.PalletType,
                        TaskLength= stockInfoPPorGM.StockLength
                        TaskLength= stockInfoPPorGM.StockLength,
                    };
                    string MaterielCodeGMPP = stockInfoPPorGM.Details?.Where(x => x.StockId == stockInfoPPorGM.Id).FirstOrDefault()?.MaterielCode;
                    float QuantityGMPP = (float)stockInfoPPorGM.Details?.Where(x => x.StockId == stockInfoPPorGM.Id).Sum(x => x.StockQuantity);
                    if (MaterielCodeGMPP != null && QuantityGMPP != null)
                    {
                        newTaskPPorGM.MaterielCode = MaterielCodeGMPP;
                        newTaskPPorGM.Quantity = QuantityGMPP;
                    }
                    //获取是否存在入库单
                    Dt_InboundOrder? inboundOrderPPorGM = null;
@@ -364,7 +433,7 @@
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt())
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.送检完成.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
@@ -391,8 +460,15 @@
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
                    PalletType = stockInfo.PalletType,
                };
                string MaterielCode = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode;
                float Quantity = (float)stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity);
                if (MaterielCode != null && Quantity != null)
                {
                    newTask.MaterielCode = MaterielCode;
                    newTask.Quantity = Quantity;
                }
                //获取是否存在入库单
                Dt_InboundOrder? inboundOrder = null;
@@ -423,7 +499,13 @@
                }
                else if (stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                    newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.送检完成.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                    newTask.TaskType = TaskTypeEnum.InQuality.ObjToInt();
                }
                else
                {
@@ -472,8 +554,7 @@
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
@@ -499,9 +580,15 @@
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
                    PalletType = stockInfo.PalletType,
                };
                string MaterielCode = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode;
                float Quantity = (float)stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity);
                if (MaterielCode != null && Quantity != null)
                {
                    newTask.MaterielCode = MaterielCode;
                    newTask.Quantity = (float)Quantity;
                }
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
@@ -513,8 +600,9 @@
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES空托退库.ObjToInt())
                {
                    Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x=>x.WarehouseId==stockInfo.WarehouseId && x.PalletType==stockInfo.PalletType);
                    //todo å°æ‰˜ç›˜æš‚时未启用
                    if (stockInfo.PalletType == PalletTypeEnum.MediumPallet.ObjToInt())
                    if (palletTypeInfo.LocaitonCount==2)
                    {
                        newTask.TaskType = TaskTypeEnum.MesPalletLargeReturn.ObjToInt();
                    }
@@ -572,7 +660,7 @@
                string roadwayNo = AssignRoadwayNo(staions, palletCode, heightType);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
@@ -598,9 +686,15 @@
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
                    PalletType = stockInfo.PalletType,
                };
                string MaterielCode = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode;
                float Quantity = (float)stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity);
                if (MaterielCode != null && Quantity != null)
                {
                    newTask.MaterielCode = MaterielCode;
                    newTask.Quantity = Quantity;
                }
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
@@ -734,6 +828,107 @@
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public WebResponseContent RequestZHInboundTask(string agvTaskCode, string palletCode, string palletType, string materialLot)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                //获取测试架原库存信息
                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseCode == WarehouseEnum.HA154.ToString());
                //获取库存记录
                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x =>
                  x.WarehouseId == warehouse.WarehouseId && x.PalletCode== palletCode).Includes(x => x.Details).ToList();
                if (stockInfos.Count > 0)
                {
                    return content.Error($"载具托盘已存在");
                }
                Dt_StockInfo? stockInfoOld = stockInfos.FirstOrDefault(x => x.Details.Any(x => x.BatchNo == materialLot));
                if (stockInfoOld != null)
                {
                    return content.Error($"库存信息已存在");
                }
                Dt_PalletTypeInfo palletTypeInfo = _palletTypeInfoRepository.QueryFirst(x=>x.CodeStartStr== palletType);
                if (palletTypeInfo == null)
                {
                    return content.Error($"托盘类型信息不存在");
                }
                ////获取阻焊批次
                //WebResponseContent requestLotInfo = GetZHMesMaterialLot(materialLot);
                //if (!requestLotInfo.Status)
                //{
                //    return content.Error($"请求阻焊批次信息失败,{requestLotInfo.Message}");
                //}
                //MesLotInfoModel mesLotInfo = JsonConvert.DeserializeObject<MesLotInfoModel>(requestLotInfo.Data.ToString());
                MesLotInfoModel mesLotInfo = new MesLotInfoModel()
                {
                    Product="FH001",
                    ProductVersion="A1",
                    Qty=20,
                    LotNo= materialLot,
                    IsFullNumber=true
                };
                Dt_StockInfoDetail stockInfoDetail = new Dt_StockInfoDetail()
                {
                    MaterielSpec = mesLotInfo.ProductVersion,
                    BatchNo = materialLot,
                    EffectiveDate = mesLotInfo.DateCode ?? " ",
                    MaterielCode = mesLotInfo.Product,
                    InboundOrderRowNo =  0,
                    MaterielName = mesLotInfo.Product,
                    ProductionDate = mesLotInfo.DateCode ?? " ",
                    OrderNo = "",
                    OutboundQuantity = 0,
                    SerialNumber = materialLot,
                    StockQuantity = (float)mesLotInfo.Qty,
                    Status = StockStatusEmun.入库确认.ObjToInt(),
                    Unit = "Lot",
                    Remark= mesLotInfo.IsFullNumber?"满Lot":"不满Lot"
                };
                Dt_StockInfo stockInfo = new Dt_StockInfo()
                {
                    PalletCode = palletCode,
                    PalletType = palletTypeInfo.PalletType,
                    WarehouseId = warehouse.WarehouseId,
                    StockStatus = StockStatusEmun.入库确认.ObjToInt(),
                    Details = new List<Dt_StockInfoDetail> { stockInfoDetail }
                };
                //生成退库任务
                Dt_Task taskIn = new()
                {
                    CurrentAddress = "AGV_ZH",
                    Grade = 0,
                    PalletCode = palletCode,
                    NextAddress = "",
                    Roadway = "SC01_ZH",
                    SourceAddress = "AGV_ZH",
                    TargetAddress = "",
                    TaskStatus = (int)TaskStatusEnum.New,
                    TaskType = palletTypeInfo.LocaitonCount==2? (int)TaskTypeEnum.InZHProductLarge : (int)TaskTypeEnum.InZHProductSmall,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    PalletType = palletTypeInfo.PalletType,
                    WarehouseId = warehouse.WarehouseId,
                    MaterielCode = mesLotInfo.Product,
                    Quantity = (float)mesLotInfo.Qty,
                };
                _unitOfWorkManage.BeginTran();
                Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
                BaseDal.AddData(taskIn);
                //BaseDal.AddData(task);
                _unitOfWorkManage.CommitTran();
                //将任务推送到WCS
                PushTasksToWCS(new List<Dt_Task>() { taskIn }, "AGV_ZH", agvTaskCode);
                content.OK(data: taskIn);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        public readonly string[] OutStartPonits = { "5230", "5237", "5244" };
        /// <summary>
        /// æˆå“ä½™æ–™é€€åº“入仓
@@ -826,7 +1021,9 @@
                    TaskType = TaskTypeEnum.InProductBack.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = warePoint.WarehouseId,
                    PalletType = proStockInfo.PalletType
                    PalletType = proStockInfo.PalletType,
                    MaterielCode = proStockInfo.proStockInfoDetails?.Where(x => x.ProStockId == proStockInfo.Id).FirstOrDefault()?.ProductCode,
                    Quantity = (float)proStockInfo.proStockInfoDetails?.Where(x => x.ProStockId == proStockInfo.Id).Sum(x => x.StockPcsQty)
                };
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);