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.
256 lines
9.1 KiB
256 lines
9.1 KiB
using AutoMapper;
|
|
using Common.Util;
|
|
using Entity.Api.Resp;
|
|
using Entity.Constant;
|
|
using Entity.DbModel.Station;
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
using HybirdFrameworkCore.Entity;
|
|
using log4net;
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
|
using Repository.Station;
|
|
using Service.Cloud.Client;
|
|
using Service.Execute;
|
|
using Service.Execute.Api;
|
|
using Service.Execute.Model;
|
|
using Service.Init;
|
|
using Service.Mgr;
|
|
using Service.Plc.Client;
|
|
|
|
namespace Service.Station;
|
|
|
|
[Scope("SingleInstance")]
|
|
public class MonitorService
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(MonitorService));
|
|
public BinInfoRepository BinInfoRepository { get; set; }
|
|
public SwapOrderRepository SwapOrderRepository { get; set; }
|
|
public ChargeOrderRepository ChargeOrderRepository { get; set; }
|
|
public PlcTaskMgr PlcTaskMgr { get; set; }
|
|
|
|
public Result<SwapMonitorScreenResp> GetSwapMonitorData()
|
|
{
|
|
var configBinInfo =
|
|
new MapperConfiguration(cfg => cfg.CreateMap<StepModel, SwappingStateInfoResp>().ReverseMap());
|
|
IMapper mapperBinInfo = configBinInfo.CreateMapper();
|
|
List<SwappingStateInfoResp> stateInfoList = new List<SwappingStateInfoResp>()
|
|
{
|
|
new SwappingStateInfoResp()
|
|
{
|
|
StepName = "空闲1",
|
|
StepNo = 1,
|
|
StartTime = DateTime.Now
|
|
},
|
|
new SwappingStateInfoResp()
|
|
{
|
|
StepName = "空闲2",
|
|
StepNo = 2,
|
|
StartTime = DateTime.Now
|
|
},
|
|
new SwappingStateInfoResp()
|
|
{
|
|
StepName = "空闲3",
|
|
StepNo = 3,
|
|
StartTime = DateTime.Now
|
|
},
|
|
new SwappingStateInfoResp()
|
|
{
|
|
StepName = "空闲4",
|
|
StepNo = 4,
|
|
StartTime = DateTime.Now
|
|
},
|
|
};
|
|
/*List<SwappingStateInfoResp> stateInfoList =
|
|
mapperBinInfo.Map<List<SwappingStateInfoResp>>(StationSoftMgr.SwappingStateMachine.StepModel);*/
|
|
|
|
var tboxCarInfoModel = StationSoftMgr.SwappingStateMachine.BoxCarInfoModel;
|
|
|
|
List<BinInfo> binInfos = BinInfoRepository.QueryListByClause(i => i.Exists == 1 && i.Status == 1);
|
|
SwapMonitorScreenResp monitorScreenResp = new()
|
|
{
|
|
PlcSwapModel = new PlcSwapModelResp()
|
|
{
|
|
ModelState = PlcMgr.PlcToHostData.ModeControl.Value,
|
|
StationInLampSts = PlcMgr.PlcToHostData.LightIn.Value,
|
|
ControlModel = PlcMgr.PlcToHostData.RemoteLocalControlState.Value,
|
|
},
|
|
StateInfo = stateInfoList,
|
|
VehicleInfo = new SwapVehicleResp()
|
|
{
|
|
OrderNo = StationSoftMgr.SwappingStateMachine.SwapOrder != null
|
|
? StationSoftMgr.SwappingStateMachine.SwapOrder.Sn
|
|
: null,
|
|
VelMac = StationSoftMgr.SwappingStateMachine.RfidReadModel != null
|
|
? StationSoftMgr.SwappingStateMachine.RfidReadModel.VelMac
|
|
: null,
|
|
LockStatus = tboxCarInfoModel != null ? tboxCarInfoModel.HeartBeatMsg.LockStatus : null,
|
|
KeyStatus = tboxCarInfoModel != null ? tboxCarInfoModel.HeartBeatMsg.KeyStatus : null,
|
|
VelNo = StationSoftMgr.SwappingStateMachine.RfidReadModel != null
|
|
? StationSoftMgr.SwappingStateMachine.RfidReadModel.VelNo
|
|
: null,
|
|
VelVin = StationSoftMgr.SwappingStateMachine.RfidReadModel != null
|
|
? StationSoftMgr.SwappingStateMachine.RfidReadModel.VelVin
|
|
: null,
|
|
},
|
|
BatteryInfo = new()
|
|
{
|
|
BatteryTotalCount = binInfos.Count,
|
|
UsingSwapBatteryCount = binInfos.Select(i => i.ChargeStatus == 2 &&
|
|
i.AmtLock == (int)InfoEnum.AmtBatLockStatus.UnLock &&
|
|
i.Soc > StaticStationInfo.SwapSoc &&
|
|
new TimeSpan(DateTime.Now.Ticks -
|
|
i.LastChargeFinishTime.ToDateTime().Ticks)
|
|
.TotalMinutes >
|
|
StaticStationInfo.SwapFinishChargeTime).Count()
|
|
}
|
|
};
|
|
|
|
|
|
return Result<SwapMonitorScreenResp>.Success(monitorScreenResp);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 模式類
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Result<SwapModelResp> GetModel()
|
|
{
|
|
SwapModelResp resp = new()
|
|
{
|
|
StationStatus = StaticStationInfo.StationStatus,
|
|
StationWay = StaticStationInfo.StationWay,
|
|
StationModel = StaticStationInfo.StationModel
|
|
};
|
|
|
|
return Result<SwapModelResp>.Success(resp);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 连接状态类
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Result<DeviceStateResp> GetDeviceState()
|
|
{
|
|
bool isConnected = StationSoftMgr.SwappingStateMachine.BoxCarInfoModel == null
|
|
? false
|
|
: StationSoftMgr.SwappingStateMachine.BoxCarInfoModel.Connected;
|
|
|
|
DeviceStateResp resp = new()
|
|
{
|
|
BoxConnectFlag = isConnected != null ? isConnected : false,
|
|
CloudConnectFlag = CloudClientMgr.CloudClient == null ? false : CloudClientMgr.CloudClient.Connected,
|
|
PlcConnectFlag = PlcMgr.PlcClient == null ? false : PlcMgr.PlcClient.Connected
|
|
};
|
|
|
|
return Result<DeviceStateResp>.Success(resp);
|
|
}
|
|
|
|
//TODO:: 首页--当月,当日换电量
|
|
public Result<SwapAndChargingCountResp> SwapAndChargingCount()
|
|
{
|
|
SwapAndChargingCountResp chargingCountResp = new()
|
|
{
|
|
ChargeTodayCount = ChargeOrderRepository.GetCount(i =>
|
|
DateTime.Today <= i.EndTime && i.EndTime <= DateUtils.GetTomorrowFirst()),
|
|
ChargeTotalCount = ChargeOrderRepository.GetCount(i => i.EndTime != null),
|
|
SwapTodayCount =
|
|
SwapOrderRepository.GetCount(i =>
|
|
i.SwapResult != 0 && DateTime.Today <= i.SwapEndTime &&
|
|
i.SwapEndTime <= DateUtils.GetTomorrowFirst()),
|
|
SwapTotalCount = SwapOrderRepository.GetCount(i => i.SwapResult != 0),
|
|
};
|
|
|
|
return Result<SwapAndChargingCountResp>.Success(chargingCountResp);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 电池移仓
|
|
/// </summary>
|
|
/// <param name="removeBinNo"></param>
|
|
/// <param name="putBinNo"></param>
|
|
/// <returns></returns>
|
|
public Result<bool> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
|
|
{
|
|
//校验:出仓位
|
|
BinInfo? removeBin = BinInfoRepository.QueryByClause(i =>
|
|
i.No.Equals(removeBinNo) && (i.ChargeStatus == 2 || i.ChargeStatus == 4) && i.Exists == 1 &&
|
|
i.AmtLock == 0);
|
|
|
|
if (removeBin == null)
|
|
{
|
|
return Result<bool>.Fail("出仓位状态有误");
|
|
}
|
|
|
|
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
|
|
i.No.Equals(putBinNo) && i.Exists == 0 && i.AmtLock == 0 &&
|
|
i.Status == 1);
|
|
if (putBin == null)
|
|
{
|
|
return Result<bool>.Fail("入仓位状态有误");
|
|
}
|
|
|
|
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2);
|
|
|
|
if (!result)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
result = PlcMgr.ReadTaskStatus(2);
|
|
if (!result)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
result = PlcMgr.HoldOn();
|
|
if (!result)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
Log.Info($"battery move task Manual removeBinNo={removeBinNo}, putBinNo={putBinNo} ");
|
|
|
|
var queryPlcTask = PlcTaskMgr.QueryPlcTask(2, 1200, 1201);
|
|
if (!queryPlcTask)
|
|
{
|
|
return Result<bool>.Fail();
|
|
}
|
|
|
|
//如果是缓存仓 更新缓存仓的数据
|
|
if (putBin.CacheBinFlag == 1)
|
|
{
|
|
putBin.Exists = 1;
|
|
putBin.BatteryNo = removeBin.BatteryNo;
|
|
putBin.Soc = removeBin.Soc;
|
|
putBin.Soe = removeBin.Soe;
|
|
putBin.Soh = removeBin.Soh;
|
|
BinInfoRepository.Update(putBin);
|
|
}
|
|
|
|
if (removeBin.CacheBinFlag == 1)
|
|
{
|
|
removeBin.Exists = 0;
|
|
removeBin.BatteryNo = "-1";
|
|
removeBin.Soc = -1;
|
|
removeBin.Soe = -1;
|
|
removeBin.Soh = -1;
|
|
BinInfoRepository.Update(removeBin);
|
|
}
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
|
return Result<bool>.Success();
|
|
}
|
|
|
|
|
|
public Result<List<BinInfoResp>> GetChargeBinOption()
|
|
{
|
|
List<BinInfo> queryListByClause = BinInfoRepository.Query();
|
|
var configBinInfo =
|
|
new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfoResp>().ReverseMap());
|
|
IMapper mapperBinInfo = configBinInfo.CreateMapper();
|
|
|
|
return Result<List<BinInfoResp>>.Success(mapperBinInfo.Map<List<BinInfoResp>>(queryListByClause));
|
|
}
|
|
} |