using WIDESEA_Common; using WIDESEA_IServices; using WIDESEAWCS_BasicInfoRepository; using WIDESEAWCS_Model.Models; namespace WIDESEAWCS_BasicInfoService { public partial class Dt_BDCConfigurationService : ServiceBase, 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 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 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; } /// /// 白车身是否可入库 /// /// public async Task CanAddWhiteBody() { var config = await GetCurrentConfiguration(); var currentCount = GetWhiteBodyCount(); // 预留5%的缓冲空间 var threshold = (int)(config.MaxWhiteBodyCache * 0.95); return currentCount < threshold; } public async Task CanAddPaintedBody() { var config = await GetCurrentConfiguration(); var currentCount = GetPaintedBodyCount(); // 预留5%的缓冲空间 var threshold = (int)(config.MaxPaintedBodyCache * 0.95); return currentCount < threshold; } public async Task CanAddEmptySled() { var config = await GetCurrentConfiguration(); var currentCount = GetEmptySledCount(); // 预留5%的缓冲空间 var threshold = (int)(config.MaxEmptySledCache * 0.95); return currentCount < threshold; } /// /// 白车身库存数量 /// /// public int GetWhiteBodyCount() { return _palletStockInfoRepository.QueryData(b => b.CarBodyInfo.CarType == (int)BodyType.WhiteBody && b.StockStatus == (int)BodyStatus.InBDC).Count; } /// /// 彩车身库存数量 /// /// public int GetPaintedBodyCount() { return _palletStockInfoRepository.QueryData(b => b.CarBodyInfo.CarType == (int)BodyType.PaintedBody && b.StockStatus == (int)BodyStatus.InBDC).Count; } /// /// 电池壳库存数量 /// /// public int GetBatteryCaseCount() { return _palletStockInfoRepository.QueryData(b => b.StockStatus == (int)BodyStatus.InBDC).Count; } /// /// 空滑橇库存数量 /// /// public int GetEmptySledCount() { return _palletStockInfoRepository.QueryData(s => s.StockStatus == (int)BodyStatus.InBDC).Count; } } }