using SqlSugar;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseRepository;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Enums;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_Core.HttpContextUser;
|
using WIDESEA_DTO.Stock;
|
using WIDESEA_IStockService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_StockService
|
{
|
public partial class StockInfoDetailService : ServiceBase<Dt_StockInfoDetail, IRepository<Dt_StockInfoDetail>>, IStockInfoDetailService
|
{
|
public StockInfoDetailService(IRepository<Dt_StockInfoDetail> BaseDal, IRepository<Dt_StockInfo> stockinfoRepository) : base(BaseDal)
|
{
|
_stockinfoRepository = stockinfoRepository;
|
}
|
|
public IRepository<Dt_StockInfo> _stockinfoRepository;
|
public IRepository<Dt_StockInfoDetail> Repository => BaseDal;
|
|
public bool ExistBarcodes(string barcode)
|
{
|
return BaseDal.QueryFirst(x => x.Barcode == barcode) != null;
|
}
|
|
public bool ExistBarcodes(List<string> barcodes)
|
{
|
return BaseDal.QueryFirst(x => !string.IsNullOrEmpty(x.Barcode) && barcodes.Contains(x.Barcode)) != null;
|
}
|
|
public PageGridData<StockInfoDetailWithPalletDto> GetPageData2(PageDataOptions options)
|
{
|
// 1. 获取基础分页数据
|
PageGridData<Dt_StockInfoDetail> pageData = base.GetPageData(options);
|
List<Dt_StockInfoDetail> filteredDetails = pageData.Rows.ToList(); // 先拷贝原始数据
|
|
if (!string.IsNullOrEmpty(options.Wheres))
|
{
|
try
|
{
|
List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
|
if (searchParametersList?.Any() == true)
|
{
|
foreach (var param in searchParametersList)
|
{
|
// 匹配托盘编号查询条件(小写字段名)
|
if (param.Name.Equals(nameof(Dt_StockInfo.PalletCode).FirstLetterToLower(), StringComparison.OrdinalIgnoreCase)
|
&& !string.IsNullOrEmpty(param.Value?.ToString()))
|
{
|
// 优化:批量查询(如果有多个托盘码,这里也可以扩展)
|
string palletCode = param.Value.ToString().Trim();
|
var targetStock = _stockinfoRepository.QueryFirst(x => x.PalletCode == palletCode);
|
|
// 空值校验:未找到对应托盘的库存,直接过滤为空
|
if (targetStock != null)
|
{
|
filteredDetails = filteredDetails.Where(x => x.StockId == targetStock.Id).ToList();
|
}
|
else
|
{
|
filteredDetails = new List<Dt_StockInfoDetail>();
|
}
|
break; // 单个托盘码查询,匹配后退出循环
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
}
|
}
|
|
List<int> stockIds = filteredDetails.Select(detail => detail.StockId).Distinct().ToList();
|
var stockDict = _stockinfoRepository.QueryData(x => stockIds.Contains(x.Id))
|
.ToDictionary(x => x.Id, x => x.PalletCode ?? "无托盘编号");
|
|
List<StockInfoDetailWithPalletDto> dtoList = filteredDetails
|
.Select(detail => new StockInfoDetailWithPalletDto
|
{
|
Id = detail.Id,
|
StockId = detail.StockId,
|
MaterielCode = detail.MaterielCode,
|
MaterielName = detail.MaterielName,
|
OrderNo = detail.OrderNo,
|
BatchNo = detail.BatchNo,
|
ProductionDate = detail.ProductionDate,
|
EffectiveDate = detail.EffectiveDate,
|
SerialNumber = detail.SerialNumber,
|
StockQuantity = detail.StockQuantity,
|
OutboundQuantity = detail.OutboundQuantity,
|
Status = detail.Status,
|
Unit = detail.Unit,
|
InboundOrderRowNo = detail.InboundOrderRowNo,
|
SupplyCode = detail.SupplyCode,
|
WarehouseCode = detail.WarehouseCode,
|
Barcode = detail.Barcode,
|
BusinessType = detail.BusinessType,
|
Remark = detail.Remark,
|
Creater = detail.Creater,
|
CreateDate = detail.CreateDate,
|
Modifier = detail.Modifier,
|
ModifyDate = detail.ModifyDate,
|
PalletCode = stockDict.TryGetValue(detail.StockId, out var palletCode) ? palletCode : "无托盘编号"
|
})
|
.ToList();
|
|
return new PageGridData<StockInfoDetailWithPalletDto>
|
{
|
Rows = dtoList,
|
Total = pageData.Total,
|
Summary = pageData.Summary
|
};
|
}
|
}
|
}
|