111
tjx
2025-12-03 b2be08ed3f369fc7ada79209d4bb2f8a98c03a61
111
已修改3个文件
136 ■■■■ 文件已修改
StandardPda/MES.Service/Dto/webApi/ReturnableStockDto.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardPda/MES.Service/Dto/webApi/ReturnableStockSearchDto.cs 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs 126 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
StandardPda/MES.Service/Dto/webApi/ReturnableStockDto.cs
@@ -84,4 +84,9 @@
    ///     物料条码
    /// </summary>
    public string? ItemBarcode { get; set; }
    /// <summary>
    ///     库存状态 (立库入库中=0, 已在立库内=1)
    /// </summary>
    public string? StockStatus { get; set; }
}
StandardPda/MES.Service/Dto/webApi/ReturnableStockSearchDto.cs
@@ -100,4 +100,9 @@
    ///     物料条码
    /// </summary>
    public string? ItemBarcode { get; set; }
    /// <summary>
    ///     库存状态 (立库入库中=0, 已在立库内=1, 进入立库的路上=2)
    /// </summary>
    public string? StockStatus { get; set; }
}
StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
@@ -33,10 +33,14 @@
            .Select(x => new { x.ItemBarcode, x.PalletCode, x.Code, x.Id })
            .ToList();
        // ReturnableStockDto增加一个库存状态的字段
        // 当allRackingTaskData中的Code为null时,库存状态为立库入库中
        // 当allRackingTaskData中的Code为200时,库存状态为已经在立库内
        // 对每个条码,取最新ID的记录,并过滤掉Code为500(表示失败)的记录
        var rackingTaskData = allRackingTaskData
            .GroupBy(x => x.ItemBarcode)
            .Select(g => g.OrderByDescending(x => x.Id).First())
            .Where(x => x.Code != "500")
            .GroupBy(x => x.ItemBarcode) // 按条码分组
            .Select(g => g.OrderByDescending(x => x.Id).First()) // 取每个条码最新的一条记录
            .Where(x => x.Code != "500") // 过滤掉Code为500的失败记录
            .ToList();
        if (rackingTaskData == null || !rackingTaskData.Any())
@@ -71,10 +75,23 @@
        var conditions = searchDto.Conditions;
        if (conditions != null)
        {
            //当conditions.IqcStatus为1时查询的值就要是特采直接使用,已检,免检,1的值
            // 精确匹配条件
            if (!string.IsNullOrEmpty(conditions.IqcStatus))
            {
                query = query.Where((stock, item, depot, org, unit) => stock.IqcStatus == conditions.IqcStatus);
                if (conditions.IqcStatus == "1")
                {
                    // 当IqcStatus为"1"时,查询特采直接使用、已检、免检状态
                    query = query.Where((stock, item, depot, org, unit) =>
                        stock.IqcStatus == "特采直接使用" ||
                        stock.IqcStatus == "已检" ||
                        stock.IqcStatus == "免检");
                }
                else
                {
                    // 其他情况按原值匹配
                    query = query.Where((stock, item, depot, org, unit) => stock.IqcStatus == conditions.IqcStatus);
                }
            }
            if (conditions.Quantity.HasValue)
@@ -184,16 +201,22 @@
        {
            // 优先使用StockStackCode,否则使用ItemBarcode去查找PalletCode
            var barcodeToMatch = !string.IsNullOrEmpty(x.StockStackCode) ? x.StockStackCode : x.ItemBarcode;
            var palletCode = rackingTaskData
            var rackingTask = rackingTaskData
                .Where(r => r.ItemBarcode == barcodeToMatch)
                .Select(r => r.PalletCode)
                .FirstOrDefault();
            
            // 根据Code值确定库存状态: null为立库入库中(0), 200为已在立库内(1)
            string stockStatus = "进入立库的路上"; // 默认为立库入库中
            if (rackingTask?.Code != null)
            {
                stockStatus = rackingTask.Code == "200" ? "已在立库中" : "进入立库的路上";
            }
            return new
            {
                IqcStatus = x.IqcStatus == "已检" ? "1" : "0",
                ItemType = x.DepotName == "原材料仓" ? "0" : "1",
                StackCode = palletCode, // 使用PalletCode作为母托盘编号
                StackCode = rackingTask?.PalletCode, // 使用PalletCode作为母托盘编号
                x.DepotCode,
                x.DepotName,
                x.DepotSectionsCode,
@@ -206,23 +229,24 @@
                x.IndepDate,
                x.OrgCode,
                x.OrgName,
                ItemBarcode = barcodeToMatch
                ItemBarcode = barcodeToMatch,
                StockStatus = stockStatus // 添加库存状态
            };
        }).ToList();
        // 5.1 应用IqcStatus搜索条件(在内存中过滤)
        if (conditions != null && !string.IsNullOrEmpty(conditions.IqcStatus))
        {
            tempDataList = tempDataList
                .Where(x => x.IqcStatus == conditions.IqcStatus)
                .ToList();
        }
        // 5.2 应用StackCode搜索条件(在内存中过滤PalletCode)
        // 5.1 应用StackCode搜索条件(在内存中过滤PalletCode)
        if (conditions != null && !string.IsNullOrEmpty(conditions.StackCode))
        {
            tempDataList = tempDataList
                .Where(x => x.StackCode != null && x.StackCode.Contains(conditions.StackCode))
                .ToList();
        }
        // 5.2 应用StockStatus搜索条件(在内存中过滤)
        if (conditions != null && !string.IsNullOrEmpty(conditions.StockStatus))
        {
            tempDataList = tempDataList
                .Where(x => x.StockStatus == conditions.StockStatus)
                .ToList();
        }
@@ -243,7 +267,8 @@
                x.ItemUnitName,
                x.OrgCode,
                x.OrgName,
                x.ItemBarcode
                x.ItemBarcode,
                x.StockStatus // 添加库存状态到分组键中
            })
            .Select(g => new ReturnableStockDto
            {
@@ -262,7 +287,8 @@
                IndepDate = g.Max(x => x.IndepDate),
                OrgCode = g.Key.OrgCode,
                OrgName = g.Key.OrgName,
                ItemBarcode = g.Key.ItemBarcode
                ItemBarcode = g.Key.ItemBarcode,
                StockStatus = g.Key.StockStatus // 添加库存状态到DTO中
            }).ToList();
        // 6. 应用ItemType筛选(在内存中过滤)
@@ -311,6 +337,17 @@
            return new List<ReturnableStockDto>();
        }
        // 1.1 查询XB_RACKING_TASK_SYXT_LOG中ItemBarcode和PalletCode、Code的映射关系
        var allRackingTaskData = Db.Queryable<XbRackingTaskSyxtLog>()
            .Where(x => !string.IsNullOrEmpty(x.ItemBarcode))
            .Select(x => new { x.ItemBarcode, x.PalletCode, x.Code, x.Id })
            .ToList();
        var rackingTaskData = allRackingTaskData
            .GroupBy(x => x.ItemBarcode)
            .Select(g => g.OrderByDescending(x => x.Id).First())
            .ToList();
        // 2. 使用条码查询MES_INV_ITEM_STOCKS中的数据,关联MES_ITEMS、MES_DEPOTS、ORGANIZE、MES_UNIT表
        var queryResult = Db.Queryable<MesInvItemStocks>()
            .LeftJoin<MesItems>((stock, item) => stock.ItemId == item.Id)
@@ -344,24 +381,39 @@
            .ToList();
        // 3. 在内存中进行数据转换
        var result = queryResult.Select(x => new ReturnableStockDto
        {
            IqcStatus = x.IqcStatus == "已检" ? "1" : "0",
            ItemType = x.DepotName == "原材料仓" ? "0" : "1",
            StackCode = x.StackCode,
            DepotCode = x.DepotCode,
            DepotName = x.DepotName,
            DepotSectionsCode = x.DepotSectionsCode,
            ItemNo = x.ItemNo,
            ItemName = x.ItemName,
            ItemModel = x.ItemModel,
            Quantity = x.Quantity,
            ItemUnit = x.ItemUnit,
            ItemUnitName = x.ItemUnitName,
            IndepDate = x.IndepDate,
            OrgCode = x.OrgCode,
            OrgName = x.OrgName,
            ItemBarcode = x.ItemBarcode
        var result = queryResult.Select(x => {
            // 根据条码查找对应的立库任务信息
            var rackingTask = rackingTaskData
                .Where(r => r.ItemBarcode == x.ItemBarcode)
                .FirstOrDefault();
                        // 根据Code值确定库存状态: null为立库入库中(0), 200为已在立库内(1)
            string stockStatus = "0"; // 默认为立库入库中
            if (rackingTask?.Code != null)
            {
                stockStatus = rackingTask.Code == "200" ? "1" : "2"; // 200对应已在立库中(1),其他非500值为进入立库的路上(2)
            }
            return new ReturnableStockDto
            {
                IqcStatus = x.IqcStatus == "已检" ? "1" : "0",
                ItemType = x.DepotName == "原材料仓" ? "0" : "1",
                StackCode = x.StackCode,
                DepotCode = x.DepotCode,
                DepotName = x.DepotName,
                DepotSectionsCode = x.DepotSectionsCode,
                ItemNo = x.ItemNo,
                ItemName = x.ItemName,
                ItemModel = x.ItemModel,
                Quantity = x.Quantity,
                ItemUnit = x.ItemUnit,
                ItemUnitName = x.ItemUnitName,
                IndepDate = x.IndepDate,
                OrgCode = x.OrgCode,
                OrgName = x.OrgName,
                ItemBarcode = x.ItemBarcode,
                StockStatus = stockStatus // 添加库存状态
            };
        }).ToList();
        return result;