using AutoMapper; using WIDESEA_Common.StockEnum; using WIDESEA_Core.BaseRepository; using WIDESEA_Core.BaseServices; using WIDESEA_IRecordService; using WIDESEA_IStockService; using WIDESEA_Model.Models; namespace WIDESEA_StockService { public partial class StockInfoService : ServiceBase>, IStockInfoService { private readonly IMapper _mapper; private readonly IRecordService _recordService; public IRepository Repository => BaseDal; private readonly IRepository _stockInfoDetailRepository; public StockInfoService(IRepository BaseDal, IMapper mapper, IRepository stockInfoDetailRepository, IRecordService recordService) : base(BaseDal) { _mapper = mapper; _stockInfoDetailRepository = stockInfoDetailRepository; _recordService = recordService; } /// /// 根据托盘号查询库存 /// /// /// public Dt_StockInfo? GetStockByPalletCode(string palletCode) { Dt_StockInfo stockInfo = BaseDal.QueryFirst(x => x.PalletCode == palletCode); if (stockInfo != null) { stockInfo.Details = _stockInfoDetailRepository.QueryData(x => x.StockId == stockInfo.Id); } return stockInfo; } public void AddMaterielGroup(Dt_StockInfo stockInfo) { decimal beforeQuantity = 0; List details = new List(); if (stockInfo.Id == 0) { if (stockInfo.Details != null && stockInfo.Details.Any()) { BaseDal.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand(); } else { BaseDal.AddData(stockInfo); } details = stockInfo.Details; } else { beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity); for (int i = 0; i < stockInfo.Details.Count; i++) { if (stockInfo.Details[i].Id == 0) { details.Add(_stockInfoDetailRepository.Db.Insertable(stockInfo.Details[i]).ExecuteReturnEntity()); } } } stockInfo.Details = details; _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup); } } }