duyongjia
2025-02-28 cb385f0b515c738b503c5c75c9d7efcec323716d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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);
        }
 
    }
}