换电大屏 电池移仓等接口

master
lxw 6 months ago
parent 43b90759f8
commit 08a9d4462e

@ -0,0 +1,16 @@
namespace Common.Util;
public class DateUtils
{
public static bool IsDateTimeToday(DateTime? dateTime)
{
if (dateTime == null)
{
return false;
}
DateTime startOfToday = DateTime.Today;
DateTime endOfToday = startOfToday.AddDays(1).AddTicks(-1);
return dateTime >= startOfToday && dateTime <= endOfToday;
}
}

@ -0,0 +1,173 @@
namespace Entity.Api.Resp;
public class BinInfoResp
{
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
public int Id { get; set; }
/// <summary>
/// Desc:仓位编号
/// Default:
/// Nullable:True
/// </summary>
public string No { get; set; }
/// <summary>
/// Desc:仓位编码
/// Default:
/// Nullable:True
/// </summary>
public string Code { get; set; }
/// <summary>
/// Desc:仓位名称
/// Default:
/// Nullable:True
/// </summary>
public string Name { get; set; }
/// <summary>
/// Desc:在位状态0-不在位1-在位2-无效
/// Default:
/// Nullable:True
/// </summary>
public int Exists { get; set; }
/// <summary>
/// Desc:电池编号
/// Default:
/// Nullable:True
/// </summary>
public string BatteryNo { get; set; }
/// <summary>
/// Desc:充电机编号
/// Default:
/// Nullable:True
/// </summary>
public string ChargerNo { get; set; }
/// <summary>
/// Desc:充电枪编号
/// Default:
/// Nullable:True
/// </summary>
public string ChargerGunNo { get; set; }
/// <summary>
/// Desc:水冷编号
/// Default:
/// Nullable:True
/// </summary>
public string WaterCoolNo { get; set; }
/// <summary>
/// Desc:是否有电插头;0-无电插头1-有电插头
/// Default:
/// Nullable:True
/// </summary>
public int? ElecPluginFlag { get; set; }
/// <summary>
/// Desc:电插头状态;0-未知1-已经连接2-未连接
/// Default:
/// Nullable:True
/// </summary>
public string ElecPluginStatus { get; set; }
/// <summary>
/// Desc:是否有水插头;0-无水插头1-有水插头
/// Default:
/// Nullable:False
/// </summary>
public string WaterPluginFlag { get; set; }
/// <summary>
/// Desc:预约锁定;0-未锁定1-锁定
/// Default:
/// Nullable:True
/// </summary>
public int AmtLock { get; set; }
/// <summary>
/// Desc:soc
/// Default:
/// Nullable:True
/// </summary>
public decimal? Soc { get; set; }
/// <summary>
/// Desc:soe
/// Default:
/// Nullable:True
/// </summary>
public decimal? Soe { get; set; }
/// <summary>
/// Desc:soh
/// Default:
/// Nullable:True
/// </summary>
public decimal? Soh { get; set; }
/// <summary>
/// Desc:电池入仓顺序
/// Default:
/// Nullable:True
/// </summary>
public int? BatteryEnterSeq { get; set; }
/// <summary>
/// Desc:充电状态;0-未知1-正在充电2-无电池3-禁用
/// Default:0
/// Nullable:True
/// </summary>
public int? ChargeStatus { get; set; }
/// <summary>
/// Desc:仓位状态;0-禁用1-启用
/// Default:1
/// Nullable:True
/// </summary>
public int? Status { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
public DateTime? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
public string UpdatedBy { get; set; }
/// <summary>
/// Desc:最后结束充电时间 结束充电后更新
/// Default:
/// Nullable:True
/// </summary>
public DateTime? LastChargeFinishTime { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
public DateTime? UpdatedTime { get; set; }
/// <summary>
/// 缓存仓标记 0:不是 1:是
/// </summary>
public int CacheBinFlag { get; set; }
}

@ -1,4 +1,4 @@
namespace Service.Station; namespace Entity.Constant;
public class StationParamConst public class StationParamConst
{ {

@ -203,5 +203,11 @@ namespace Entity.DbModel.Station
/// </summary> /// </summary>
[SugarColumn(ColumnName = "updated_time")] [SugarColumn(ColumnName = "updated_time")]
public DateTime? UpdatedTime { get; set; } public DateTime? UpdatedTime { get; set; }
/// <summary>
/// 缓存仓标记 0:不是 1:是
/// </summary>
[SugarColumn(ColumnName = "cache_bin_flag")]
public int CacheBinFlag { get; set; }
} }
} }

@ -58,6 +58,7 @@
{ {
return Message(false, msg, default); return Message(false, msg, default);
} }
/// <summary> /// <summary>

@ -1,9 +1,12 @@
using Autofac; using Autofac;
using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using log4net; using log4net;
using Repository.Station; using Repository.Station;
using Service.Execute;
using Service.Execute.Api; using Service.Execute.Api;
using Service.Execute.Model;
namespace Service.BusinessTask.MyTask; namespace Service.BusinessTask.MyTask;
@ -30,7 +33,7 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler
protected override void Handle() protected override void Handle()
{ {
List<SwapOrderReportCloud> list = _reportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0); /*List<SwapOrderReportCloud> list = _reportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0);
if (list.Count <= 0) if (list.Count <= 0)
{ {
@ -39,9 +42,23 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler
List<long?> swapOrderIds = list.Select(i => i.SwapOrderId).ToList(); List<long?> swapOrderIds = list.Select(i => i.SwapOrderId).ToList();
List<SwapOrder> swapOrders = _swapOrderRepository.QueryListByClause(i => swapOrderIds.Contains(i.Id)); List<SwapOrder> swapOrders = _swapOrderRepository.QueryListByClause(i => swapOrderIds.Contains(i.Id));*/
/*//TODO::给前端测试 实时步骤变更
Array enumValues = Enum.GetValues(typeof(InfoEnum.BusinessSwappingStep));
foreach (InfoEnum.BusinessSwappingStep info in enumValues)
{
StepModel resp = new()
{
StepName = BaseEnumExtensions.GetDescription(info),
StepNo = (int)info,
StartTime = DateTime.Now
};
StationSoftMgr.SwappingStateMachine.StepModel = new List<StepModel>();
StationSoftMgr.SwappingStateMachine.StepModel.Add(resp);
Thread.Sleep(60000);
}*/
} }

@ -94,9 +94,9 @@ public class PlcApi
/// 下发启动换电 /// 下发启动换电
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static bool StartSwapping() public static bool StartSwapping(string inBinNo, string outBinNo)
{ {
return PlcMgr.StartSwapping(); return PlcMgr.DistributeTask(ushort.Parse(inBinNo),ushort.Parse(outBinNo),1);
} }
/// <summary> /// <summary>

@ -0,0 +1,37 @@
using HybirdFrameworkCore.Autofac.Attribute;
using Mapster;
namespace Service.Execute.Model;
public class DistributeTask
{
/// <summary>
/// 任务类型
/// 0.无任务
/// 1.换电任务
/// 2.移舱任务
/// 3.移出任务
/// 4.移入任务
/// 5.消防任务
/// </summary>
[Property(0, 16)]
public ushort TaskNo { get; set; }
/// <summary>
/// 入仓位选择
/// </summary>
[Property(16, 16)]
public ushort InBinNo { get; set; }
/// <summary>
/// 出仓仓位选择
/// </summary>
[Property(32, 16)]
public ushort OutBinNo { get; set; }
/// <summary>
/// 电池包类型 0
/// </summary>
[Property(48, 16)]
public ushort BatteryPackType { get; set; }
}

@ -27,12 +27,13 @@ public class CarCtrlState : IState
} }
//下发选包 //下发选包
InvokeStatus distributeSelectPack = DistributeSelectPack(machine); /*InvokeStatus distributeSelectPack = DistributeSelectPack(machine);
if (distributeSelectPack != InvokeStatus.Done) if (distributeSelectPack != InvokeStatus.Done)
{ {
return SwappingStateMachine.ReturnWithInvokeErr(distributeSelectPack, ExceptionReason.None); return SwappingStateMachine.ReturnWithInvokeErr(distributeSelectPack, ExceptionReason.None);
} }
*/
return new StateResult() return new StateResult()
{ {

@ -105,7 +105,8 @@ public class DoSwappingState : IState
if (unLock) if (unLock)
{ {
//查询车辆锁止状态 //查询车辆锁止状态
var startSwapping = PlcApi.StartSwapping(); var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No,
machine.SwapOrderBatteryInfo.UpBinInfo.No);
if (startSwapping) if (startSwapping)
{ {
machine.SwapOrder.SwapBeginTime = DateTime.Now; machine.SwapOrder.SwapBeginTime = DateTime.Now;

@ -1,4 +1,5 @@
using Autofac; using Autofac;
using Entity.Constant;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using Service.Station; using Service.Station;
using Service.System; using Service.System;

@ -1,5 +1,8 @@
using Autofac; using Autofac;
using HslCommunication;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Utils;
using Service.Execute.Model;
using Service.Plc.Msg; using Service.Plc.Msg;
namespace Service.Plc.Client; namespace Service.Plc.Client;
@ -138,6 +141,25 @@ public class PlcMgr
return false; return false;
} }
/// <summary>
/// 下发任务 plc 需要一起下发
/// </summary>
/// <returns></returns>
public static bool DistributeTask(ushort inBinNo, ushort outBinNo, ushort taskNo)
{
DistributeTask distributeTask = new()
{
TaskNo = taskNo,
InBinNo = inBinNo,
OutBinNo = outBinNo,
BatteryPackType = 0,
};
//需要将数据转换成byte数组
OperateResult operateResult = PlcClient.Write("111", ModelConvert.Encode(distributeTask));
return operateResult.IsSuccess;
}
/// <summary> /// <summary>
/// 下发启动换电 /// 下发启动换电

@ -1,9 +1,11 @@
using AutoMapper; using AutoMapper;
using Common.Util;
using Entity.Api.Resp; using Entity.Api.Resp;
using Entity.Constant; using Entity.Constant;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Repository.Station; using Repository.Station;
using Service.Cloud.Client; using Service.Cloud.Client;
using Service.Execute; using Service.Execute;
@ -15,30 +17,19 @@ using Service.Plc.Client;
namespace Service.Station; namespace Service.Station;
[Scope("SingleInstance")] [Scope("SingleInstance")]
public class SwapMonitorService public class MonitorService
{ {
public BinInfoRepository BinInfoRepository { get; set; } public BinInfoRepository BinInfoRepository { get; set; }
public SwapOrderRepository SwapOrderRepository { get; set; }
public ChargeOrderRepository ChargeOrderRepository { get; set; }
public Result<SwapMonitorScreenResp> GetSwapMonitorData() public Result<SwapMonitorScreenResp> GetSwapMonitorData()
{ {
var configBinInfo = var configBinInfo =
new MapperConfiguration(cfg => cfg.CreateMap<StepModel, SwappingStateInfoResp>().ReverseMap()); new MapperConfiguration(cfg => cfg.CreateMap<StepModel, SwappingStateInfoResp>().ReverseMap());
IMapper mapperBinInfo = configBinInfo.CreateMapper(); IMapper mapperBinInfo = configBinInfo.CreateMapper();
/*List<SwappingStateInfoResp> stateInfoList = List<SwappingStateInfoResp> stateInfoList =
mapperBinInfo.Map<List<SwappingStateInfoResp>>(StationSoftMgr.SwappingStateMachine.StepModel);*/ 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(); Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo();
@ -122,6 +113,69 @@ public class SwapMonitorService
public Result<SwapAndChargingCountResp> SwapAndChargingCount() public Result<SwapAndChargingCountResp> SwapAndChargingCount()
{ {
return Result<SwapAndChargingCountResp>.Success(null);
SwapAndChargingCountResp chargingCountResp = new()
{
ChargeTodayCount = ChargeOrderRepository.GetCount(i => DateUtils.IsDateTimeToday(i.EndTime)),
ChargeTotalCount = ChargeOrderRepository.GetCount(i => i.EndTime != null),
SwapTodayCount =
SwapOrderRepository.GetCount(i => i.SwapResult != 0 && DateUtils.IsDateTimeToday(i.SwapEndTime)),
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.Exists == 1 && i.AmtLock == 0);
if (removeBin == null)
{
return Result<bool>.Fail("出仓位状态有误");
}
BinInfo? putBin = BinInfoRepository.QueryByClause(i =>
i.No.Equals(putBinNo) && i.ChargeStatus == 2 && i.Exists == 0 && i.AmtLock == 0 && i.Status == 1);
if (putBin == null)
{
return Result<bool>.Fail("入仓位状态有误");
}
var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2) ? Result<bool>.Success() : Result<bool>.Fail();
if (!result.IsSuccess)
{
return Result<bool>.Fail();
}
//如果是缓存仓 更新缓存仓的数据
if (putBinNo == 1)
{
putBin.Exists = 1;
putBin.Soc = removeBin.Soc;
putBin.Soe = removeBin.Soe;
putBin.Soh = removeBin.Soh;
BinInfoRepository.Update(putBin);
}
return Result<bool>.Success();
}
public Result<List<BinInfoResp>> GetChargeBinOption()
{
List<BinInfo> queryListByClause = BinInfoRepository.Query();
var configBinInfo =
new MapperConfiguration(cfg => cfg.CreateMap<BinInfo, BinInfo>().ReverseMap());
IMapper mapperBinInfo = configBinInfo.CreateMapper();
return Result<List<BinInfoResp>>.Success(mapperBinInfo.Map<List<BinInfoResp>>(queryListByClause));
} }
} }

@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
using Autofac; using Autofac;
using Common.Enum; using Common.Enum;
using Entity.Base; using Entity.Base;
using Entity.Constant;
using Entity.DbModel.System.SysBaseObject; using Entity.DbModel.System.SysBaseObject;
using Entity.Dto.Req; using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac; using HybirdFrameworkCore.Autofac;

@ -1,4 +1,5 @@
using Entity.Api.Req; using Entity.Api.Req;
using Entity.Api.Resp;
using Entity.Base; using Entity.Base;
using Entity.DbModel.Station; using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity; using HybirdFrameworkCore.Entity;
@ -20,17 +21,20 @@ namespace WebStarter.Controllers;
public class ChargeMonitorController public class ChargeMonitorController
{ {
private readonly BinInfoService _binInfoService; private readonly BinInfoService _binInfoService;
public ChargeMonitorController(BinInfoService binInfoService) private readonly MonitorService _monitorService;
public ChargeMonitorController(BinInfoService binInfoService, MonitorService monitorService)
{ {
_binInfoService = binInfoService; _binInfoService = binInfoService;
_monitorService = monitorService;
} }
/// <summary> /// <summary>
/// 充电仓查询:条件:仓位编号 仓位名称 /// 充电仓查询:条件:仓位编号 仓位名称
/// </summary> /// </summary>
[HttpPost("ChargePositionQuery")] [HttpPost("ChargePositionQuery")]
public async Task<SqlSugarPagedList<BinInfo>> ChargePositionQuery([FromBody] ChargePositionQueryReq chargePositionQueryReq) public async Task<SqlSugarPagedList<BinInfo>> ChargePositionQuery(
[FromBody] ChargePositionQueryReq chargePositionQueryReq)
{ {
return await _binInfoService.ChargePositionQuery(chargePositionQueryReq); return await _binInfoService.ChargePositionQuery(chargePositionQueryReq);
} }
@ -58,7 +62,6 @@ public class ChargeMonitorController
/// <summary> /// <summary>
/// TODO:: 电池移仓
/// 电池移仓 /// 电池移仓
/// </summary> /// </summary>
/// <param name="removeBinNo">取仓号</param> /// <param name="removeBinNo">取仓号</param>
@ -67,18 +70,15 @@ public class ChargeMonitorController
[HttpGet("BatteryRelocation")] [HttpGet("BatteryRelocation")]
public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo) public async Task<Result<bool>> BatteryRelocation(ushort removeBinNo, ushort putBinNo)
{ {
return _monitorService.BatteryRelocation(removeBinNo, putBinNo);
// PlcMgr.DistributeBinNo();
return Result<bool>.Success();
} }
/// <summary> /// <summary>
/// TODO::移仓时下拉项 仓位电池状态
/// 移仓时下拉项 仓位电池状态 /// 移仓时下拉项 仓位电池状态
/// </summary> /// </summary>
[HttpGet("GetChargeBinOption")] [HttpGet("GetChargeBinOption")]
public Result<int[]> GetChargeBinOption() public Result<List<BinInfoResp>> GetChargeBinOption()
{ {
return Result<int[]>.Success(); return _monitorService.GetChargeBinOption();
} }
} }

@ -17,9 +17,9 @@ namespace WebStarter.Controllers;
[Route("api/[controller]")] [Route("api/[controller]")]
public class SwapMonitorController : ControllerBase public class SwapMonitorController : ControllerBase
{ {
private readonly SwapMonitorService? _swapMonitorService; private readonly MonitorService? _swapMonitorService;
public SwapMonitorController(SwapMonitorService? swapMonitorService) public SwapMonitorController(MonitorService? swapMonitorService)
{ {
_swapMonitorService = swapMonitorService; _swapMonitorService = swapMonitorService;
} }
@ -63,7 +63,7 @@ public class SwapMonitorController : ControllerBase
[HttpPost("GetSwapAndChargingCount")] [HttpPost("GetSwapAndChargingCount")]
public async Task<Result<SwapAndChargingCountResp>> SwapAndChargingCount() public async Task<Result<SwapAndChargingCountResp>> SwapAndChargingCount()
{ {
return Result<SwapAndChargingCountResp>.Success(null); return _swapMonitorService.SwapAndChargingCount();
} }

@ -155,6 +155,6 @@ CloudClientMgr.Init();
PlcMgr.Init(); PlcMgr.Init();
//启动换电流程 //启动换电流程
StationSoftMgr.SwappingStateMachineStart(); //StationSoftMgr.SwappingStateMachineStart();
StationSoftMgr.StartTasks();
app.Run(); app.Run();
Loading…
Cancel
Save