using AutoMapper;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Common.StockEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Enums;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_DTO.Stock;
|
using WIDESEAWCS_IBasicRepository;
|
using WIDESEAWCS_IRecordRepository;
|
using WIDESEAWCS_IRecordService;
|
using WIDESEAWCS_IStockRepository;
|
using WIDESEAWCS_IStockService;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_StockService
|
{
|
public partial class StockInfoService : ServiceBase<Dt_StockInfo, IStockInfoRepository>, IStockInfoService
|
{
|
/// <summary>
|
/// 根据托盘号查询库存
|
/// </summary>
|
/// <param name="palletCode"></param>
|
/// <returns></returns>
|
public Dt_StockInfo? GetStockByPalletCode(string palletCode)
|
{
|
Dt_StockInfo stockInfo = BaseDal.QueryFirst(x => x.PalletCode == palletCode);
|
if (stockInfo != null)
|
{
|
stockInfo.Details = _stockRepository.StockInfoDetailRepository.QueryData(x => x.StockId == stockInfo.Id);
|
}
|
return stockInfo;
|
}
|
|
public void AddMaterielGroup(Dt_StockInfo stockInfo)
|
{
|
decimal beforeQuantity = 0;
|
List<Dt_StockInfoDetail> details = new List<Dt_StockInfoDetail>();
|
if (stockInfo.Id == 0)
|
{
|
BaseDal.Db.InsertNav(stockInfo).Include(x => x.Details).ExecuteCommand();
|
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(_stockRepository.StockInfoDetailRepository.Db.Insertable(stockInfo.Details[i]).ExecuteReturnEntity());
|
}
|
|
}
|
}
|
stockInfo.Details = details;
|
_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, StockChangeType.MaterielGroup);
|
}
|
|
}
|
}
|