using Entity.Constant; using Entity.DbModel.Station; using Entity.Dto; using HybirdFrameworkCore.Autofac.Attribute; using log4net; using Newtonsoft.Json; using SqlSugar; namespace Repository.Station; [Scope("SingleInstance")] public class BinInfoRepository : BaseRepository { private static readonly ILog _log = LogManager.GetLogger(typeof(BinInfoRepository)); public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar) { } /// /// 选包 /// /// StaticStationInfo.SwapSoc /// StaticStationInfo.SwapFinishChargeTime /// public SelectPackDto SelectPack(int swapSoc, int swapFinishChargeTime, string upMoveNo=default) { _log.Info($"BinInfoRepository SelectPack swapSoc={swapSoc}, swapFinishChargeTime={swapFinishChargeTime},upMoveNo={upMoveNo}"); SelectPackDto selectPackDto = new() { SuccessFlag = false, }; /* List 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)}"); // BinInfo? cacheBinBattery = ChooseCacheBinBattery(swapSoc); if (list.Count <= 0) { _log.Info($"list1 return"); selectPackDto.Info = InfoEnum.SelectBinStatusInfo.NoBattery; return selectPackDto; } list = list.OrderBy(i => i.CacheBinFlag).ToList(); _log.Info($"BinInfoRepository SelectPack list2={JsonConvert.SerializeObject(list)}"); if (!string.IsNullOrWhiteSpace(upMoveNo)) { 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.ChargeStatus == 2 || i.ChargeStatus == 4).ToList(); if (list.Count <= 0) { selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOfFinishCharging; return selectPackDto; } list = list.Where(i => i.Soc != null &&i.Soc >= swapSoc).ToList(); if (list.Count <= 0) { 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) { selectPackDto.Info = InfoEnum.SelectBinStatusInfo.LessOf3Minute; return selectPackDto; }#1# */ // selectPackDto.BinInfo = list[0]; selectPackDto.Info = InfoEnum.SelectBinStatusInfo.Success; selectPackDto.SuccessFlag = true; selectPackDto.BinInfo = new BinInfo() { Id = 2, No = "2", BatteryNo = "1111", Soc = 100, }; return selectPackDto; } /// /// 选择缓存仓的电池 /// /// public BinInfo? ChooseCacheBinBattery() { return QueryByClause(i => i.CacheBinFlag == 1 && i.CanSwapFlag==1 && i.Exists == 1 && i.Status == 1 && i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock); } }