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.
127 lines
5.0 KiB
127 lines
5.0 KiB
6 months ago
|
using AutoMapper;
|
||
|
using Entity.Api.Resp;
|
||
|
using Entity.Constant;
|
||
|
using Entity.DbModel.Station;
|
||
|
using HybirdFrameworkCore.Autofac.Attribute;
|
||
|
using HybirdFrameworkCore.Entity;
|
||
|
using Repository.Station;
|
||
|
using Service.Cloud.Client;
|
||
|
using Service.Execute;
|
||
|
using Service.Execute.Api;
|
||
|
using Service.Execute.Model;
|
||
|
using Service.Init;
|
||
|
using Service.Plc.Client;
|
||
|
|
||
|
namespace Service.Station;
|
||
|
|
||
|
[Scope("SingleInstance")]
|
||
|
public class SwapMonitorService
|
||
|
{
|
||
|
public BinInfoRepository BinInfoRepository { get; set; }
|
||
|
|
||
|
public Result<SwapMonitorScreenResp> GetSwapMonitorData()
|
||
|
{
|
||
|
var configBinInfo =
|
||
|
new MapperConfiguration(cfg => cfg.CreateMap<StepModel, SwappingStateInfoResp>().ReverseMap());
|
||
|
IMapper mapperBinInfo = configBinInfo.CreateMapper();
|
||
|
/*List<SwappingStateInfoResp> stateInfoList =
|
||
|
mapperBinInfo.Map<List<SwappingStateInfoResp>>(StationSoftMgr.SwappingStateMachine.StepModel);*/
|
||
|
//TODO::假数据
|
||
|
List<SwappingStateInfoResp> stateInfoList = new List<SwappingStateInfoResp>();
|
||
|
Array enumValues = Enum.GetValues(typeof(InfoEnum.BusinessSwappingStep));
|
||
|
foreach (InfoEnum.BusinessSwappingStep info in enumValues)
|
||
|
{
|
||
|
SwappingStateInfoResp resp = new()
|
||
|
{
|
||
|
StepName = BaseEnumExtensions.GetDescription(info),
|
||
|
StepNo = (int)info,
|
||
|
StartTime = DateTime.Now
|
||
|
};
|
||
|
stateInfoList.Add(resp);
|
||
|
}
|
||
|
|
||
|
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo();
|
||
|
|
||
|
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 = carInfo.Result != null ? carInfo.Result.HeartBeatMsg.LockStatus : null,
|
||
|
KeyStatus = carInfo.Result != null ? carInfo.Result.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 > int.Parse(StaticStationInfo.SwapSoc) &&
|
||
|
new TimeSpan(DateTime.Now.Ticks -
|
||
|
i.LastChargeFinishTime.ToDateTime().Ticks)
|
||
|
.TotalMinutes >
|
||
|
int.Parse(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()
|
||
|
{
|
||
|
var isConnected = TBoxApi.IsConnected();
|
||
|
DeviceStateResp resp = new()
|
||
|
{
|
||
|
BoxConnectFlag = isConnected.Result != null ? isConnected.Result : false,
|
||
|
CloudConnectFlag = CloudClientMgr.CloudClient.Connected,
|
||
|
PlcConnectFlag = PlcMgr.PlcClient.Connected
|
||
|
};
|
||
|
|
||
|
return Result<DeviceStateResp>.Success(resp);
|
||
|
}
|
||
|
|
||
|
public Result<SwapAndChargingCountResp> SwapAndChargingCount()
|
||
|
{
|
||
|
return Result<SwapAndChargingCountResp>.Success(null);
|
||
|
}
|
||
|
}
|