陈勇
2026-03-17 40ef2cb3dd897dfc74d9576d0973517b24cc9367
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using WIDESEA_Common;
using WIDESEA_IServices;
using WIDESEAWCS_BasicInfoRepository;
using WIDESEAWCS_Model.Models;
 
namespace WIDESEAWCS_BasicInfoService
{
    public partial class Dt_BDCConfigurationService : ServiceBase<Dt_BDCConfiguration, IDt_BDCConfigurationRepository>, IDt_BDCConfigurationService
    {
        private readonly ISys_ConfigService _sys_ConfigService;
        private readonly IDt_PalletStockInfoRepository _palletStockInfoRepository;
 
        public Dt_BDCConfigurationService(IDt_BDCConfigurationRepository BaseDal, ISys_ConfigService sys_ConfigService, IDt_PalletStockInfoRepository palletStockInfoRepository) : base(BaseDal)
        {
            _sys_ConfigService = sys_ConfigService;
            _palletStockInfoRepository = palletStockInfoRepository;
        }
 
        public async Task<Dt_BDCConfiguration> GetCurrentConfiguration()
        {
            // 获取当前生效的配置
            var currentConfig = await BaseDal.QueryFirstAsync(c => c.IsActive == 1);
 
            // 如果没有配置,创建默认配置
            if (currentConfig == null)
            {
                currentConfig = new Dt_BDCConfiguration();
                BaseDal.AddData(currentConfig);
            }
            return currentConfig;
        }
 
        public override WebResponseContent UpdateData(SaveModel saveModel)
        {
 
            return base.UpdateData(saveModel);
        }
 
        public async Task<Dt_BDCConfiguration> UpdateConfiguration(int maxWhiteBody, int maxPaintedBody,
       int maxBatteryCase, int maxEmptySled)
        {
            // 禁用当前配置
            var currentConfigs = await BaseDal.QueryDataAsync(c => c.IsActive == 1);
            currentConfigs.ForEach(c => c.IsActive = 2);
 
            // 创建新配置
            var newConfig = new Dt_BDCConfiguration
            {
                MaxWhiteBodyCache = maxWhiteBody,
                MaxPaintedBodyCache = maxPaintedBody,
                MaxBatteryCaseCache = maxBatteryCase,
                MaxEmptySledCache = maxEmptySled,
                CreateDate = DateTime.Now,
                Creater = App.User.UserName,
                IsActive = 1
            };
 
            BaseDal.UpdateData(currentConfigs);
            BaseDal.AddData(newConfig);
            return newConfig;
        }
 
        /// <summary>
        /// 白车身是否可入库
        /// </summary>
        /// <returns></returns>
        public async Task<bool> CanAddWhiteBody()
        {
            var config = await GetCurrentConfiguration();
            var currentCount = GetWhiteBodyCount();
 
            // 预留5%的缓冲空间
            var threshold = (int)(config.MaxWhiteBodyCache * 0.95);
            return currentCount < threshold;
        }
 
        public async Task<bool> CanAddPaintedBody()
        {
            var config = await GetCurrentConfiguration();
            var currentCount = GetPaintedBodyCount();
 
            // 预留5%的缓冲空间
            var threshold = (int)(config.MaxPaintedBodyCache * 0.95);
            return currentCount < threshold;
        }
 
        public async Task<bool> CanAddEmptySled()
        {
            var config = await GetCurrentConfiguration();
            var currentCount = GetEmptySledCount();
 
            // 预留5%的缓冲空间
            var threshold = (int)(config.MaxEmptySledCache * 0.95);
            return currentCount < threshold;
        }
 
        /// <summary>
        /// 白车身库存数量
        /// </summary>
        /// <returns></returns>
        public int GetWhiteBodyCount()
        {
            return _palletStockInfoRepository.QueryData(b => b.CarBodyInfo.CarType == (int)BodyType.WhiteBody && b.StockStatus == (int)BodyStatus.InBDC).Count;
        }
 
        /// <summary>
        /// 彩车身库存数量
        /// </summary>
        /// <returns></returns>
        public int GetPaintedBodyCount()
        {
            return _palletStockInfoRepository.QueryData(b => b.CarBodyInfo.CarType == (int)BodyType.PaintedBody && b.StockStatus == (int)BodyStatus.InBDC).Count;
        }
 
        /// <summary>
        /// 电池壳库存数量
        /// </summary>
        /// <returns></returns>
        public int GetBatteryCaseCount()
        {
            return _palletStockInfoRepository.QueryData(b => b.StockStatus == (int)BodyStatus.InBDC).Count;
        }
 
        /// <summary>
        /// 空滑橇库存数量
        /// </summary>
        /// <returns></returns>
        public int GetEmptySledCount()
        {
            return _palletStockInfoRepository.QueryData(s => s.StockStatus == (int)BodyStatus.InBDC).Count;
        }
    }
}