1
wankeda
2025-03-13 286ff26fa658dabe9e758d830d134172e8abd03f
WMS/WIDESEA_WMSServer/WIDESEA_RecordService/Service/StockQuantityChangeRecordService.cs
@@ -15,33 +15,43 @@
{
    public partial class StockQuantityChangeRecordService : ServiceBase<Dt_StockQuantityChangeRecord, IStockQuantityChangeRecordRepository>, IStockQuantityChangeRecordService
    {
        public void AddStockChangeRecord(Dt_StockInfo stockInfo, List<Dt_StockInfoDetail> stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType)
        public void AddStockChangeRecord(Dt_StockInfo stockInfo, List<Dt_StockInfoDetail> stockInfoDetails, decimal beforeQuantity, decimal totalQuantity, StockChangeType changeType, int? taskNum = null)
        {
            List<Dt_StockQuantityChangeRecord> stockQuantityChangeRecords = new List<Dt_StockQuantityChangeRecord>();
            stockQuantityChangeRecords = _mapper.Map<List<Dt_StockQuantityChangeRecord>>(stockInfoDetails);
            int index = 0;
            decimal currentQuantity = 0;
            stockQuantityChangeRecords.ForEach(x =>
            try
            {
                x.PalleCode = stockInfo.PalletCode;
                x.BeforeQuantity = beforeQuantity;
                if (totalQuantity > beforeQuantity)
                List<Dt_StockQuantityChangeRecord> stockQuantityChangeRecords = new List<Dt_StockQuantityChangeRecord>();
                stockQuantityChangeRecords = _mapper.Map<List<Dt_StockQuantityChangeRecord>>(stockInfoDetails);
                int index = 0;
                decimal currentQuantity = 0;
                stockQuantityChangeRecords.ForEach(x =>
                {
                    x.ChangeQuantity = stockInfoDetails[index].StockQuantity;
                    currentQuantity += stockInfoDetails[index].StockQuantity;
                    x.AfterQuantity = stockInfoDetails[index].StockQuantity + beforeQuantity;
                }
                else
                {
                    x.ChangeQuantity = -stockInfoDetails[index].StockQuantity;
                    currentQuantity -= stockInfoDetails[index].StockQuantity;
                    x.AfterQuantity = beforeQuantity - stockInfoDetails[index].StockQuantity;
                }
                    x.PalleCode = stockInfo.PalletCode;
                    x.BeforeQuantity = beforeQuantity;
                    if (totalQuantity >= beforeQuantity)
                    {
                        x.ChangeQuantity = stockInfoDetails[index].StockQuantity;
                        currentQuantity += stockInfoDetails[index].StockQuantity;
                        x.AfterQuantity = stockInfoDetails[index].StockQuantity + beforeQuantity;
                    }
                    else
                    {
                        x.ChangeQuantity = -stockInfoDetails[index].StockQuantity;
                        currentQuantity -= stockInfoDetails[index].StockQuantity;
                        x.AfterQuantity = beforeQuantity - stockInfoDetails[index].StockQuantity;
                    }
                x.ChangeType = changeType.ObjToInt();
                beforeQuantity += x.ChangeQuantity;
            });
            BaseDal.AddData(stockQuantityChangeRecords);
                    x.ChangeType = changeType.ObjToInt();
                    beforeQuantity += x.ChangeQuantity;
                    x.TaskNum = taskNum;
                    index++;
                });
                BaseDal.AddData(stockQuantityChangeRecords);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}