From 9442e5ec5f2e9316bf75ef01c2b823852faab17b Mon Sep 17 00:00:00 2001
From: xjl <2595686544@qq.com>
Date: Tue, 16 Jul 2024 15:03:51 +0800
Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E4=BA=BA=E5=B7=A5=E6=93=8D?=
=?UTF-8?q?=E4=BD=9C=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=B9=B4=E6=9C=88=E6=8D=A2?=
=?UTF-8?q?=E7=94=B5=E6=AC=A1=E6=95=B0=E7=BB=9F=E8=AE=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../DbModel/Station/ManualOperationRecord.cs | 2 +-
Entity/Dto/Req/ManualOperationRecordReq.cs | 37 +++++++++
.../Station/ExStationDayRunResultService.cs | 59 +++++++++++++++
.../Station/ManualOperationRecordService.cs | 75 +++++++++++++++++++
.../ManualOperationRecordController.cs | 35 +++++++++
.../Controllers/StatisticsController.cs | 48 ++++++++++++
.../Controllers/SwapMonitorController.cs | 11 ++-
7 files changed, 264 insertions(+), 3 deletions(-)
create mode 100644 Entity/Dto/Req/ManualOperationRecordReq.cs
create mode 100644 Service/Station/ManualOperationRecordService.cs
create mode 100644 WebStarter/Controllers/ManualOperationRecordController.cs
create mode 100644 WebStarter/Controllers/StatisticsController.cs
diff --git a/Entity/DbModel/Station/ManualOperationRecord.cs b/Entity/DbModel/Station/ManualOperationRecord.cs
index c9b6127..e17eb6d 100644
--- a/Entity/DbModel/Station/ManualOperationRecord.cs
+++ b/Entity/DbModel/Station/ManualOperationRecord.cs
@@ -29,7 +29,7 @@ public class ManualOperationRecord : BaseModel
public string? Reason { get; set; }
///
- /// 操作类型 : 1人工确认成功;2人工确认失败
+ /// 操作类型 : 1人工确认成功;2人工确认失败;3人工确认上锁成功;4人工确认解锁成功
///
[SugarColumn( ColumnName = "type")]
diff --git a/Entity/Dto/Req/ManualOperationRecordReq.cs b/Entity/Dto/Req/ManualOperationRecordReq.cs
new file mode 100644
index 0000000..5b27470
--- /dev/null
+++ b/Entity/Dto/Req/ManualOperationRecordReq.cs
@@ -0,0 +1,37 @@
+using Entity.DbModel.Station;
+using HybirdFrameworkCore.Entity;
+using SqlSugar;
+
+namespace Entity.Dto.Req;
+
+///
+///人工操作表
+///
+public class ManualOperationRecordReq
+{
+}
+
+public class PageManualOperationRecordReq : QueryPageModel
+{
+ ///
+ /// 换电订单
+ ///
+ public string? SwapOrderSn { get; set; }
+
+ ///
+ /// 操作类型 : 1人工确认成功;2人工确认失败;3人工确认上锁成功;4人工确认解锁成功
+ ///
+ public int? Type { get; set; }
+}
+
+public class AddManualOperationRecordReq : ManualOperationRecord
+{
+}
+
+public class UpdateManualOperationRecordReq : AddManualOperationRecordReq
+{
+}
+
+public class DeleteManualOperationRecordReq : BaseIdReq
+{
+}
\ No newline at end of file
diff --git a/Service/Station/ExStationDayRunResultService.cs b/Service/Station/ExStationDayRunResultService.cs
index 17e4764..c5c2322 100644
--- a/Service/Station/ExStationDayRunResultService.cs
+++ b/Service/Station/ExStationDayRunResultService.cs
@@ -16,6 +16,7 @@ using AutoMapper;
using Entity.Dto;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
+using SqlSugar;
namespace Service.Station
{
@@ -84,5 +85,63 @@ namespace Service.Station
{ FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "换电站日运行统计.xlsx" };
}
+
+
+ ///
+ /// 获取一个月的每日数据
+ ///
+ ///
+ ///
+ public async Task> GetMonthRunResult()
+ {
+
+ var runresult = await _exStationDayRunResultRepository.QueryListByClauseAsync(u => u.CreatedTime >= DateTimeOffset.UtcNow.AddDays(-30));
+
+ return runresult;
+ }
+
+
+ ///
+ /// 获取一年内每月的数据和
+ ///
+ ///
+ public async Task> GetYearRunResult()
+ {
+ var runresult = _exStationDayRunResultRepository.QueryListByClause(u => u.CreatedTime >= DateTimeOffset.UtcNow.AddMonths(-12))
+ .GroupBy(d => d.CreatedTime.Value.Month);
+
+
+
+ // 对每个月的数据求和
+ Dictionary monthlyTotals = new Dictionary();
+ foreach (var group in runresult)
+ {
+ var month = group.Key;
+ ExchangeStationDayRunResult runResult = new ExchangeStationDayRunResult
+ {
+
+ AvgChgTime = group.Sum(d => Convert.ToDouble(d.AvgChgTime)).ToString("F2"),
+ AvgRepTime = group.Sum(d => Convert.ToDouble(d.AvgRepTime)).ToString("F2"),
+ ChgCount = group.Sum(d => d.ChgCount),
+ ToltalSwapCount = group.Sum(d => d.ToltalSwapCount),
+ ToltalSwapAllTime = group.Sum(d => d.ToltalSwapAllTime),
+ ToltalTimeCount = group.Sum(d => d.ToltalTimeCount),
+ CreatedTime= group.First().CreatedTime,
+ UpdatedTime = group.First().UpdatedTime,
+ };
+
+
+ monthlyTotals[month] = runResult;
+ }
+
+ List resultList = monthlyTotals
+ .ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
+ .Select(pair => pair.Value)
+ .ToList();
+
+
+ return resultList;
+
+ }
}
}
diff --git a/Service/Station/ManualOperationRecordService.cs b/Service/Station/ManualOperationRecordService.cs
new file mode 100644
index 0000000..c190449
--- /dev/null
+++ b/Service/Station/ManualOperationRecordService.cs
@@ -0,0 +1,75 @@
+using System.ComponentModel;
+using System.Reflection.PortableExecutable;
+using Entity.Base;
+using Entity.DbModel.Station;
+using Entity.DbModel.System;
+using Entity.Dto.Req;
+using HybirdFrameworkCore.Autofac.Attribute;
+using HybirdFrameworkCore.Entity;
+using Mapster;
+using Repository.Station;
+using Service.Mgr;
+using SqlSugar;
+
+namespace Service.Station;
+
+[Scope("SingleInstance")]
+public class ManualOperationRecordService : BaseServices
+{
+ private ManualOperationRecordRepository _manualOperationRecordRepository;
+
+ public ManualOperationRecordService(ManualOperationRecordRepository dal)
+ {
+ _manualOperationRecordRepository = dal;
+ BaseDal = dal;
+ }
+
+ ///
+ /// 异常人工操作分页列表 🔖
+ ///
+ ///
+ ///
+ [DisplayName("异常人工操作分页列表")]
+ public async Task> Page(PageManualOperationRecordReq input)
+ {
+ RefAsync total = 0;
+ var items = await _manualOperationRecordRepository.QueryPageAsync(
+ entity => true,
+ false, entity => true,
+ !string.IsNullOrEmpty(input.SwapOrderSn), u => u.SwapOrderSn == input.SwapOrderSn,
+ input.Type != null, (u => input.Type != null && u.Type.Equals(input.Type.Value)),
+ u => u.CreatedTime, input.PageNum, input.PageSize, total
+ );
+ return new PageResult()
+ {
+ PageNum = input.PageNum,
+ PageSize = input.PageSize,
+ ToTal = total,
+ Rows = items,
+ };
+ }
+
+ ///
+ /// 增加
+ ///
+ ///
+ ///
+ public void AddManualOperationRecord(string sn,int type)
+ {
+ if (sn!=null)
+ {
+ var manualOperationRecord = new ManualOperationRecord()
+ {
+ SwapOrderSn = sn,
+ Type = type,
+ CreatedBy = UserManager.Account,
+ UpdatedBy = UserManager.Account,
+ Operator = UserManager.Account
+ };
+ _manualOperationRecordRepository.Insert(manualOperationRecord);
+
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/ManualOperationRecordController.cs b/WebStarter/Controllers/ManualOperationRecordController.cs
new file mode 100644
index 0000000..386d25e
--- /dev/null
+++ b/WebStarter/Controllers/ManualOperationRecordController.cs
@@ -0,0 +1,35 @@
+using System.ComponentModel.DataAnnotations;
+using Entity.DbModel.Station;
+using Entity.Dto.Req;
+using HybirdFrameworkCore.Entity;
+using Microsoft.AspNetCore.Mvc;
+using Service.Init;
+using Service.Station;
+
+namespace WebStarter.Controllers;
+
+///
+/// 异常人工操作记录
+///
+[ApiController]
+[Route("api/[controller]")]
+public class ManualOperationRecordController
+{
+ private readonly ManualOperationRecordService _manualOperationRecordService;
+
+ public ManualOperationRecordController(ManualOperationRecordService manualOperationRecordService)
+ {
+ _manualOperationRecordService = manualOperationRecordService;
+ }
+
+ ///
+ /// 查询
+ ///
+ ///
+ [HttpPost("GetPageManualOperationRecord")]
+ public async Task>> GetPageManualOperationRecord([FromBody] PageManualOperationRecordReq queryPageModel)
+ {
+ return Result>.Success(await _manualOperationRecordService.Page(queryPageModel));
+ }
+
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/StatisticsController.cs b/WebStarter/Controllers/StatisticsController.cs
new file mode 100644
index 0000000..f810a3c
--- /dev/null
+++ b/WebStarter/Controllers/StatisticsController.cs
@@ -0,0 +1,48 @@
+using System.ComponentModel.DataAnnotations;
+using Entity.DbModel.Station;
+using Entity.Dto.Req;
+using HybirdFrameworkCore.Entity;
+using Microsoft.AspNetCore.Mvc;
+using Service.Init;
+using Service.Station;
+
+namespace WebStarter.Controllers;
+
+///
+/// 统计
+///
+[ApiController]
+[Route("api/[controller]")]
+public class StatisticsController
+{
+ private readonly ExStationDayRunResultService _exStationDayRunResultService;
+ public StatisticsController(ExStationDayRunResultService exStationDayRunResultService)
+ {
+ _exStationDayRunResultService = exStationDayRunResultService;
+ }
+
+
+ ///
+ /// 获取一个月的每日数据(30天)
+ ///
+ ///
+ [HttpPost("GetMonthResult")]
+ public async Task>> GetMonthResult()
+ {
+
+ return Result>.Success(await _exStationDayRunResultService.GetMonthRunResult());
+ }
+
+
+
+ ///
+ /// 获取一年内每月的数据和(12月)
+ ///
+ ///
+ [HttpPost("GetYearResult")]
+ public async Task>> GetYearResult()
+ {
+
+ return Result>.Success(await _exStationDayRunResultService.GetYearRunResult());
+ }
+}
\ No newline at end of file
diff --git a/WebStarter/Controllers/SwapMonitorController.cs b/WebStarter/Controllers/SwapMonitorController.cs
index 1aebf33..a7d5c95 100644
--- a/WebStarter/Controllers/SwapMonitorController.cs
+++ b/WebStarter/Controllers/SwapMonitorController.cs
@@ -23,11 +23,12 @@ public class SwapMonitorController : ControllerBase
{
private readonly MonitorService _swapMonitorService;
private readonly BinInfoService _binInfoService;
-
- public SwapMonitorController(MonitorService swapMonitorService, BinInfoService binInfoService)
+ private readonly ManualOperationRecordService _manualOperationRecordService;
+ public SwapMonitorController(MonitorService swapMonitorService, BinInfoService binInfoService, ManualOperationRecordService manualOperationRecordService)
{
_swapMonitorService = swapMonitorService;
_binInfoService = binInfoService;
+ _manualOperationRecordService = manualOperationRecordService;
}
@@ -301,6 +302,9 @@ public class SwapMonitorController : ControllerBase
public async Task> ConfirmLockSucc()
{
StationSoftMgr.SwappingStateMachine.ManualConfirmLockCar();
+
+ _manualOperationRecordService.AddManualOperationRecord(StationSoftMgr.SwappingStateMachine.SwapOrder.Sn, 3);
+
return Result.Success();
}
@@ -311,6 +315,9 @@ public class SwapMonitorController : ControllerBase
public async Task> ConfirmUnLockSucc()
{
StationSoftMgr.SwappingStateMachine.ManualConfirmUnLockCar();
+
+ _manualOperationRecordService.AddManualOperationRecord(StationSoftMgr.SwappingStateMachine.SwapOrder.Sn, 4);
+
return Result.Success();
}
}
\ No newline at end of file