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.

149 lines
4.6 KiB

using Entity.Constant;
using Entity.DbModel.Station;
using Entity.Dto;
using HybirdFrameworkCore.Autofac.Attribute;
5 months ago
using log4net;
using Newtonsoft.Json;
using SqlSugar;
namespace Repository.Station;
[Scope("SingleInstance")]
public class BinInfoRepository : BaseRepository<BinInfo>
{
5 months ago
private static readonly ILog _log = LogManager.GetLogger(typeof(BinInfoRepository));
public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
/// <summary>
///
/// </summary>
/// <param name="binNo"></param>
/// <returns></returns>
public BinInfo? SelectByBinNo(string? binNo)
{
if (string.IsNullOrWhiteSpace(binNo))
{
return null;
}
return this.QueryByClause(info => info.No == binNo);
}
/// <summary>
/// 选包
/// </summary>
/// <param name="swapSoc"> StaticStationInfo.SwapSoc </param>
/// <param name="swapFinishChargeTime">StaticStationInfo.SwapFinishChargeTime</param>
/// <returns></returns>
public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo)
{
_log.Info($"BinInfoRepository SelectPack swapSoc={swapSoc}, swapFinishChargeTime={swapFinishChargeTime},upMoveNo={upMoveNo}");
SelectPackDto selectPackDto = new()
{
SuccessFlag = false,
};
List<BinInfo> list =
QueryListByClause(i => i.CanSwapFlag == 1 &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock,
"in_time asc");
_log.Info($"BinInfoRepository SelectPack list1={JsonConvert.SerializeObject(list)}");
5 months ago
if (list.Count <= 0)
{
_log.Info($"list1 return");
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery;
return selectPackDto;
}
list = list.OrderBy(i => i.CacheBinFlag).ToList();
5 months ago
_log.Info($"BinInfoRepository SelectPack list2={JsonConvert.SerializeObject(list)}");
if (!string.IsNullOrWhiteSpace(upMoveNo))
{
5 months ago
list = list.Where(i => !upMoveNo.Equals(i.No) && i.No != "" && i.No != "-1").ToList();
_log.Info($"BinInfoRepository SelectPack list3={JsonConvert.SerializeObject(list)},upMoveNo={upMoveNo}");
}
list = list.Where(i => i.Soc != null &&i.Soc >= swapSoc).OrderByDescending(i => i.Soc).ToList();
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfSoc;
return selectPackDto;
}
// 符合soc不在充电
var socList = list.Where(i => i.ChargeStatus == 2 || i.ChargeStatus == 4).ToList();
if (socList.Count <= 0)
{
// 符合soc在充电
socList= list.Where(i => i.ChargeStatus == 1).ToList();
if (socList.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging;
return selectPackDto;
}
}
list = socList;
5 months ago
selectPackDto.BinInfo = list[0];
selectPackDto.CanSwapBinInfo = list;
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
selectPackDto.SuccessFlag = true;
return selectPackDto;
}
public SelectPackDto SelectPackInBin()
{
_log.Info($"BinInfoRepository SelctPackInBin ");
SelectPackDto selectPackDto = new()
{
SuccessFlag = false,
};
List<BinInfo> list =
QueryListByClause(i =>
i.CacheBinFlag == 0 &&
i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock
&& i.Exists == 0);
if (list.Count <= 0)
{
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfEmptyBin;
return selectPackDto;
}
/*var value = QueryMoveBinNo()[1];
if (!string.IsNullOrWhiteSpace(value))
{
list = list.Where(i => i.No != value).ToList();
}*/
selectPackDto.CanSwapBinInfo = list;
selectPackDto.BinInfo = list[0];
selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success;
selectPackDto.SuccessFlag = true;
return selectPackDto;
}
/// <summary>
/// 选择缓存仓的电池
/// </summary>
/// <returns></returns>
public BinInfo? ChooseCacheBinBattery(int swapSoc)
{
return
QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag == 1 && i.Soc >= swapSoc &&
i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock);
}
5 months ago
}