You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.9 KiB
90 lines
2.9 KiB
using Entity.Constant;
|
|
using Entity.DbModel.Station;
|
|
using Entity.Dto;
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using SqlSugar;
|
|
|
|
namespace Repository.Station;
|
|
|
|
[Scope("SingleInstance")]
|
|
public class BinInfoRepository : BaseRepository<BinInfo>
|
|
{
|
|
public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 选包
|
|
/// </summary>
|
|
/// <param name="swapSoc"> StaticStationInfo.SwapSoc </param>
|
|
/// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
|
|
/// <returns></returns>
|
|
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime)
|
|
{
|
|
SelectPackDto selectPackDto = new()
|
|
{
|
|
SuccessFlag = false,
|
|
};
|
|
List<BinInfo> list =
|
|
QueryListByClause(i => i.CacheBinFlag == 0 && i.CanSwapFlag==1 &&
|
|
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock,
|
|
"in_time asc");
|
|
BinInfo? cacheBinBattery = ChooseCacheBinBattery();
|
|
if (list.Count <= 0 && cacheBinBattery == null)
|
|
{
|
|
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery;
|
|
return selectPackDto;
|
|
}
|
|
|
|
list = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus==4).ToList();
|
|
if (list.Count <= 0 && cacheBinBattery == null)
|
|
{
|
|
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
|
|
return selectPackDto;
|
|
}
|
|
|
|
|
|
list = list.Where(i => i.Soc != null && i.Soc >= swapSoc).ToList();
|
|
if (list.Count <= 0 && cacheBinBattery == null)
|
|
{
|
|
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
|
|
return selectPackDto;
|
|
}
|
|
|
|
list = list.Where(i => i.LastChargeFinishTime != null && new TimeSpan(DateTime.Now.Ticks -
|
|
i.LastChargeFinishTime.ToDateTime().Ticks)
|
|
.TotalMinutes > swapFinishChargeTime).ToList();
|
|
if (list.Count <= 0 && cacheBinBattery == null)
|
|
{
|
|
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute;
|
|
return selectPackDto;
|
|
}
|
|
|
|
if (list.Count > 0)
|
|
{
|
|
selectPackDto.BinInfo = list[0];
|
|
}
|
|
else
|
|
{
|
|
selectPackDto.BinInfo = cacheBinBattery;
|
|
}
|
|
|
|
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
|
|
selectPackDto.SuccessFlag = true;
|
|
|
|
|
|
return selectPackDto;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 选择缓存仓的电池
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public BinInfo? ChooseCacheBinBattery()
|
|
{
|
|
return
|
|
QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag==1 &&
|
|
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock);
|
|
}
|
|
} |