diff --git a/Common/Util/DateUtils.cs b/Common/Util/DateUtils.cs new file mode 100644 index 0000000..6646055 --- /dev/null +++ b/Common/Util/DateUtils.cs @@ -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; + } +} \ No newline at end of file diff --git a/Entity/Api/Resp/BinInfoResp.cs b/Entity/Api/Resp/BinInfoResp.cs new file mode 100644 index 0000000..ad93307 --- /dev/null +++ b/Entity/Api/Resp/BinInfoResp.cs @@ -0,0 +1,173 @@ +namespace Entity.Api.Resp; + +public class BinInfoResp +{ + /// + /// Desc:id + /// Default: + /// Nullable:False + /// + public int Id { get; set; } + + /// + /// Desc:仓位编号 + /// Default: + /// Nullable:True + /// + public string No { get; set; } + + /// + /// Desc:仓位编码 + /// Default: + /// Nullable:True + /// + public string Code { get; set; } + + /// + /// Desc:仓位名称 + /// Default: + /// Nullable:True + /// + public string Name { get; set; } + + /// + /// Desc:在位状态:0-不在位;1-在位;2-无效 + /// Default: + /// Nullable:True + /// + public int Exists { get; set; } + + /// + /// Desc:电池编号 + /// Default: + /// Nullable:True + /// + public string BatteryNo { get; set; } + + /// + /// Desc:充电机编号 + /// Default: + /// Nullable:True + /// + public string ChargerNo { get; set; } + + /// + /// Desc:充电枪编号 + /// Default: + /// Nullable:True + /// + public string ChargerGunNo { get; set; } + + /// + /// Desc:水冷编号 + /// Default: + /// Nullable:True + /// + public string WaterCoolNo { get; set; } + + /// + /// Desc:是否有电插头;0-无电插头;1-有电插头 + /// Default: + /// Nullable:True + /// + public int? ElecPluginFlag { get; set; } + + /// + /// Desc:电插头状态;0-未知;1-已经连接;2-未连接 + /// Default: + /// Nullable:True + /// + public string ElecPluginStatus { get; set; } + + /// + /// Desc:是否有水插头;0-无水插头;1-有水插头 + /// Default: + /// Nullable:False + /// + public string WaterPluginFlag { get; set; } + + /// + /// Desc:预约锁定;0-未锁定;1-锁定 + /// Default: + /// Nullable:True + /// + public int AmtLock { get; set; } + + /// + /// Desc:soc + /// Default: + /// Nullable:True + /// + public decimal? Soc { get; set; } + + /// + /// Desc:soe + /// Default: + /// Nullable:True + /// + public decimal? Soe { get; set; } + + /// + /// Desc:soh + /// Default: + /// Nullable:True + /// + public decimal? Soh { get; set; } + + /// + /// Desc:电池入仓顺序 + /// Default: + /// Nullable:True + /// + public int? BatteryEnterSeq { get; set; } + + /// + /// Desc:充电状态;0-未知;1-正在充电;2-无电池;3-禁用 + /// Default:0 + /// Nullable:True + /// + public int? ChargeStatus { get; set; } + + /// + /// Desc:仓位状态;0-禁用;1-启用 + /// Default:1 + /// Nullable:True + /// + public int? Status { get; set; } + + + + /// + /// Desc:创建时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + public DateTime? CreatedTime { get; set; } + + /// + /// Desc:更新人 + /// Default: + /// Nullable:True + /// + public string UpdatedBy { get; set; } + + /// + /// Desc:最后结束充电时间 结束充电后更新 + /// Default: + /// Nullable:True + /// + public DateTime? LastChargeFinishTime { get; set; } + + /// + /// Desc:更新时间 + /// Default:CURRENT_TIMESTAMP + /// Nullable:True + /// + public DateTime? UpdatedTime { get; set; } + + + /// + /// 缓存仓标记 0:不是 1:是 + /// + public int CacheBinFlag { get; set; } +} \ No newline at end of file diff --git a/Service/Station/StationParamConst.cs b/Entity/Constant/StationParamConst.cs similarity index 99% rename from Service/Station/StationParamConst.cs rename to Entity/Constant/StationParamConst.cs index c4434e6..da92052 100644 --- a/Service/Station/StationParamConst.cs +++ b/Entity/Constant/StationParamConst.cs @@ -1,4 +1,4 @@ -namespace Service.Station; +namespace Entity.Constant; public class StationParamConst { diff --git a/Entity/DbModel/Station/BinInfo.cs b/Entity/DbModel/Station/BinInfo.cs index 6aed776..f21a91a 100644 --- a/Entity/DbModel/Station/BinInfo.cs +++ b/Entity/DbModel/Station/BinInfo.cs @@ -203,5 +203,11 @@ namespace Entity.DbModel.Station /// [SugarColumn(ColumnName = "updated_time")] public DateTime? UpdatedTime { get; set; } + + /// + /// 缓存仓标记 0:不是 1:是 + /// + [SugarColumn(ColumnName = "cache_bin_flag")] + public int CacheBinFlag { get; set; } } } \ No newline at end of file diff --git a/HybirdFrameworkCore/Entity/Result.cs b/HybirdFrameworkCore/Entity/Result.cs index 3bc3134..a265b81 100644 --- a/HybirdFrameworkCore/Entity/Result.cs +++ b/HybirdFrameworkCore/Entity/Result.cs @@ -58,6 +58,7 @@ { return Message(false, msg, default); } + /// diff --git a/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs b/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs index b9d23a0..1c8427b 100644 --- a/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs +++ b/Service/BusinessTask/MyTask/SwapOrderReportCloudTask.cs @@ -1,9 +1,12 @@ using Autofac; +using Entity.Constant; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac; using log4net; using Repository.Station; +using Service.Execute; using Service.Execute.Api; +using Service.Execute.Model; namespace Service.BusinessTask.MyTask; @@ -30,7 +33,7 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler protected override void Handle() { - List list = _reportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0); + /*List list = _reportCloudRepository.QueryListByClause(i => i.CloudReportStatus == 0); if (list.Count <= 0) { @@ -39,9 +42,23 @@ public class SwapOrderReportCloudTask : AbstractTaskHandler List swapOrderIds = list.Select(i => i.SwapOrderId).ToList(); - List swapOrders = _swapOrderRepository.QueryListByClause(i => swapOrderIds.Contains(i.Id)); - + List 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(); + StationSoftMgr.SwappingStateMachine.StepModel.Add(resp); + Thread.Sleep(60000); + }*/ } diff --git a/Service/Execute/Api/PlcApi.cs b/Service/Execute/Api/PlcApi.cs index be9e4ae..69ea38d 100644 --- a/Service/Execute/Api/PlcApi.cs +++ b/Service/Execute/Api/PlcApi.cs @@ -94,9 +94,9 @@ public class PlcApi /// 下发启动换电 /// /// - 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); } /// diff --git a/Service/Execute/Model/DistributeTask.cs b/Service/Execute/Model/DistributeTask.cs new file mode 100644 index 0000000..b802988 --- /dev/null +++ b/Service/Execute/Model/DistributeTask.cs @@ -0,0 +1,37 @@ +using HybirdFrameworkCore.Autofac.Attribute; +using Mapster; + +namespace Service.Execute.Model; + +public class DistributeTask +{ + /// + /// 任务类型 + /// 0.无任务 + /// 1.换电任务 + /// 2.移舱任务 + /// 3.移出任务 + /// 4.移入任务 + /// 5.消防任务 + /// + [Property(0, 16)] + public ushort TaskNo { get; set; } + + /// + /// 入仓位选择 + /// + [Property(16, 16)] + public ushort InBinNo { get; set; } + + /// + /// 出仓仓位选择 + /// + [Property(32, 16)] + public ushort OutBinNo { get; set; } + + /// + /// 电池包类型 0 + /// + [Property(48, 16)] + public ushort BatteryPackType { get; set; } +} \ No newline at end of file diff --git a/Service/Execute/Step/CarCtrlState.cs b/Service/Execute/Step/CarCtrlState.cs index 3cb52af..503b217 100644 --- a/Service/Execute/Step/CarCtrlState.cs +++ b/Service/Execute/Step/CarCtrlState.cs @@ -27,12 +27,13 @@ public class CarCtrlState : IState } //下发选包 - InvokeStatus distributeSelectPack = DistributeSelectPack(machine); + /*InvokeStatus distributeSelectPack = DistributeSelectPack(machine); if (distributeSelectPack != InvokeStatus.Done) { return SwappingStateMachine.ReturnWithInvokeErr(distributeSelectPack, ExceptionReason.None); } + */ return new StateResult() { diff --git a/Service/Execute/Step/DoSwappingState.cs b/Service/Execute/Step/DoSwappingState.cs index d1a48c8..e474e31 100644 --- a/Service/Execute/Step/DoSwappingState.cs +++ b/Service/Execute/Step/DoSwappingState.cs @@ -105,7 +105,8 @@ public class DoSwappingState : IState if (unLock) { //查询车辆锁止状态 - var startSwapping = PlcApi.StartSwapping(); + var startSwapping = PlcApi.StartSwapping(machine.SwapOrderBatteryInfo.InBinInfo.No, + machine.SwapOrderBatteryInfo.UpBinInfo.No); if (startSwapping) { machine.SwapOrder.SwapBeginTime = DateTime.Now; diff --git a/Service/Init/StaticStationInfo.cs b/Service/Init/StaticStationInfo.cs index a70ea8f..7848311 100644 --- a/Service/Init/StaticStationInfo.cs +++ b/Service/Init/StaticStationInfo.cs @@ -1,4 +1,5 @@ using Autofac; +using Entity.Constant; using HybirdFrameworkCore.Autofac; using Service.Station; using Service.System; diff --git a/Service/Plc/Client/PlcMgr.cs b/Service/Plc/Client/PlcMgr.cs index c35375e..664f832 100644 --- a/Service/Plc/Client/PlcMgr.cs +++ b/Service/Plc/Client/PlcMgr.cs @@ -1,5 +1,8 @@ using Autofac; +using HslCommunication; using HybirdFrameworkCore.Autofac; +using HybirdFrameworkCore.Utils; +using Service.Execute.Model; using Service.Plc.Msg; namespace Service.Plc.Client; @@ -138,6 +141,25 @@ public class PlcMgr return false; } + /// + /// 下发任务 plc 需要一起下发 + /// + /// + 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; + } + /// /// 下发启动换电 diff --git a/Service/Station/SwapMonitorService.cs b/Service/Station/MonitorService.cs similarity index 61% rename from Service/Station/SwapMonitorService.cs rename to Service/Station/MonitorService.cs index 73554cc..cc58dd7 100644 --- a/Service/Station/SwapMonitorService.cs +++ b/Service/Station/MonitorService.cs @@ -1,9 +1,11 @@ using AutoMapper; +using Common.Util; using Entity.Api.Resp; using Entity.Constant; using Entity.DbModel.Station; using HybirdFrameworkCore.Autofac.Attribute; using HybirdFrameworkCore.Entity; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; using Repository.Station; using Service.Cloud.Client; using Service.Execute; @@ -15,30 +17,19 @@ using Service.Plc.Client; namespace Service.Station; [Scope("SingleInstance")] -public class SwapMonitorService +public class MonitorService { public BinInfoRepository BinInfoRepository { get; set; } + public SwapOrderRepository SwapOrderRepository { get; set; } + public ChargeOrderRepository ChargeOrderRepository { get; set; } public Result GetSwapMonitorData() { var configBinInfo = new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); IMapper mapperBinInfo = configBinInfo.CreateMapper(); - /*List stateInfoList = - mapperBinInfo.Map>(StationSoftMgr.SwappingStateMachine.StepModel);*/ - //TODO::假数据 - List stateInfoList = new List(); - 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); - } + List stateInfoList = + mapperBinInfo.Map>(StationSoftMgr.SwappingStateMachine.StepModel); Task carInfo = TBoxApi.GetCarInfo(); @@ -122,6 +113,69 @@ public class SwapMonitorService public Result SwapAndChargingCount() { - return Result.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.Success(chargingCountResp); + } + + /// + /// 电池移仓 + /// + /// + /// + /// + public Result 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.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.Fail("入仓位状态有误"); + } + + var result = PlcMgr.DistributeTask(putBinNo, removeBinNo, 2) ? Result.Success() : Result.Fail(); + if (!result.IsSuccess) + { + return Result.Fail(); + } + + //如果是缓存仓 更新缓存仓的数据 + if (putBinNo == 1) + { + putBin.Exists = 1; + putBin.Soc = removeBin.Soc; + putBin.Soe = removeBin.Soe; + putBin.Soh = removeBin.Soh; + BinInfoRepository.Update(putBin); + } + + return Result.Success(); + } + + public Result> GetChargeBinOption() + { + List queryListByClause = BinInfoRepository.Query(); + var configBinInfo = + new MapperConfiguration(cfg => cfg.CreateMap().ReverseMap()); + IMapper mapperBinInfo = configBinInfo.CreateMapper(); + + return Result>.Success(mapperBinInfo.Map>(queryListByClause)); } } \ No newline at end of file diff --git a/Service/System/SysConfigService.cs b/Service/System/SysConfigService.cs index 5664e14..75eca74 100644 --- a/Service/System/SysConfigService.cs +++ b/Service/System/SysConfigService.cs @@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations; using Autofac; using Common.Enum; using Entity.Base; +using Entity.Constant; using Entity.DbModel.System.SysBaseObject; using Entity.Dto.Req; using HybirdFrameworkCore.Autofac; diff --git a/WebStarter/Controllers/ChargeMonitorController.cs b/WebStarter/Controllers/ChargeMonitorController.cs index 2fe3fd2..58e1937 100644 --- a/WebStarter/Controllers/ChargeMonitorController.cs +++ b/WebStarter/Controllers/ChargeMonitorController.cs @@ -1,4 +1,5 @@ using Entity.Api.Req; +using Entity.Api.Resp; using Entity.Base; using Entity.DbModel.Station; using HybirdFrameworkCore.Entity; @@ -20,17 +21,20 @@ namespace WebStarter.Controllers; public class ChargeMonitorController { private readonly BinInfoService _binInfoService; - public ChargeMonitorController(BinInfoService binInfoService) + private readonly MonitorService _monitorService; + + public ChargeMonitorController(BinInfoService binInfoService, MonitorService monitorService) { _binInfoService = binInfoService; - + _monitorService = monitorService; } /// /// 充电仓查询:条件:仓位编号 仓位名称 /// [HttpPost("ChargePositionQuery")] - public async Task> ChargePositionQuery([FromBody] ChargePositionQueryReq chargePositionQueryReq) + public async Task> ChargePositionQuery( + [FromBody] ChargePositionQueryReq chargePositionQueryReq) { return await _binInfoService.ChargePositionQuery(chargePositionQueryReq); } @@ -58,7 +62,6 @@ public class ChargeMonitorController /// - /// TODO:: 电池移仓 /// 电池移仓 /// /// 取仓号 @@ -67,18 +70,15 @@ public class ChargeMonitorController [HttpGet("BatteryRelocation")] public async Task> BatteryRelocation(ushort removeBinNo, ushort putBinNo) { - - // PlcMgr.DistributeBinNo(); - return Result.Success(); + return _monitorService.BatteryRelocation(removeBinNo, putBinNo); } /// - /// TODO::移仓时下拉项 仓位电池状态 /// 移仓时下拉项 仓位电池状态 /// [HttpGet("GetChargeBinOption")] - public Result GetChargeBinOption() + public Result> GetChargeBinOption() { - return Result.Success(); + return _monitorService.GetChargeBinOption(); } } \ No newline at end of file diff --git a/WebStarter/Controllers/SwapMonitorController.cs b/WebStarter/Controllers/SwapMonitorController.cs index 4873bfc..2babc2d 100644 --- a/WebStarter/Controllers/SwapMonitorController.cs +++ b/WebStarter/Controllers/SwapMonitorController.cs @@ -17,9 +17,9 @@ namespace WebStarter.Controllers; [Route("api/[controller]")] public class SwapMonitorController : ControllerBase { - private readonly SwapMonitorService? _swapMonitorService; + private readonly MonitorService? _swapMonitorService; - public SwapMonitorController(SwapMonitorService? swapMonitorService) + public SwapMonitorController(MonitorService? swapMonitorService) { _swapMonitorService = swapMonitorService; } @@ -63,7 +63,7 @@ public class SwapMonitorController : ControllerBase [HttpPost("GetSwapAndChargingCount")] public async Task> SwapAndChargingCount() { - return Result.Success(null); + return _swapMonitorService.SwapAndChargingCount(); } diff --git a/WebStarter/Program.cs b/WebStarter/Program.cs index 49b742d..ef4fdba 100644 --- a/WebStarter/Program.cs +++ b/WebStarter/Program.cs @@ -155,6 +155,6 @@ CloudClientMgr.Init(); PlcMgr.Init(); //启动换电流程 -StationSoftMgr.SwappingStateMachineStart(); - +//StationSoftMgr.SwappingStateMachineStart(); +StationSoftMgr.StartTasks(); app.Run(); \ No newline at end of file