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 async Task<Dt_BDCConfiguration> UpdateConfiguration(int maxWhiteBody, int maxPaintedBody,
|
int maxBatteryCase, int maxEmptySled, string updatedBy)
|
{
|
// 禁用当前配置
|
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,
|
LastUpdatedTime = DateTime.Now,
|
UpdatedBy = updatedBy,
|
IsActive = 1
|
};
|
|
BaseDal.UpdateData(currentConfigs);
|
BaseDal.AddData(newConfig);
|
return newConfig;
|
}
|
|
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;
|
}
|
|
public int GetWhiteBodyCount()
|
{
|
return _palletStockInfoRepository.QueryData(b => b.CarType == (int)BodyType.WhiteBody && b.StockStatus == (int)BodyStatus.InBDC).Count;
|
}
|
|
public int GetPaintedBodyCount()
|
{
|
return _palletStockInfoRepository.QueryData(b => b.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;
|
}
|
}
|
}
|