异常人工操作记录,年月换电次数统计

master
xjl 3 months ago
parent 0731f7cf6c
commit 9442e5ec5f

@ -29,7 +29,7 @@ public class ManualOperationRecord : BaseModel
public string? Reason { get; set; }
/// <summary>
/// 操作类型 1人工确认成功;2人工确认失败
/// 操作类型 1人工确认成功;2人工确认失败;3人工确认上锁成功;4人工确认解锁成功
/// </summary>
[SugarColumn( ColumnName = "type")]

@ -0,0 +1,37 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Entity;
using SqlSugar;
namespace Entity.Dto.Req;
///<summary>
///人工操作表
///</summary>
public class ManualOperationRecordReq
{
}
public class PageManualOperationRecordReq : QueryPageModel
{
/// <summary>
/// 换电订单
/// </summary>
public string? SwapOrderSn { get; set; }
/// <summary>
/// 操作类型 1人工确认成功;2人工确认失败;3人工确认上锁成功;4人工确认解锁成功
/// </summary>
public int? Type { get; set; }
}
public class AddManualOperationRecordReq : ManualOperationRecord
{
}
public class UpdateManualOperationRecordReq : AddManualOperationRecordReq
{
}
public class DeleteManualOperationRecordReq : BaseIdReq
{
}

@ -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" };
}
/// <summary>
/// 获取一个月的每日数据
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public async Task<List<ExchangeStationDayRunResult>> GetMonthRunResult()
{
var runresult = await _exStationDayRunResultRepository.QueryListByClauseAsync(u => u.CreatedTime >= DateTimeOffset.UtcNow.AddDays(-30));
return runresult;
}
/// <summary>
/// 获取一年内每月的数据和
/// </summary>
/// <returns></returns>
public async Task<List<ExchangeStationDayRunResult>> GetYearRunResult()
{
var runresult = _exStationDayRunResultRepository.QueryListByClause(u => u.CreatedTime >= DateTimeOffset.UtcNow.AddMonths(-12))
.GroupBy(d => d.CreatedTime.Value.Month);
// 对每个月的数据求和
Dictionary<int, ExchangeStationDayRunResult> monthlyTotals = new Dictionary<int, ExchangeStationDayRunResult>();
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<ExchangeStationDayRunResult> resultList = monthlyTotals
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
.Select(pair => pair.Value)
.ToList();
return resultList;
}
}
}

@ -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<ManualOperationRecord>
{
private ManualOperationRecordRepository _manualOperationRecordRepository;
public ManualOperationRecordService(ManualOperationRecordRepository dal)
{
_manualOperationRecordRepository = dal;
BaseDal = dal;
}
/// <summary>
/// 异常人工操作分页列表 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[DisplayName("异常人工操作分页列表")]
public async Task<PageResult<ManualOperationRecord>> Page(PageManualOperationRecordReq input)
{
RefAsync<int> 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<ManualOperationRecord>()
{
PageNum = input.PageNum,
PageSize = input.PageSize,
ToTal = total,
Rows = items,
};
}
/// <summary>
/// 增加
/// </summary>
/// <param name="sn"></param>
/// <param name="type"></param>
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);
}
}
}

@ -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;
/// <summary>
/// 异常人工操作记录
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class ManualOperationRecordController
{
private readonly ManualOperationRecordService _manualOperationRecordService;
public ManualOperationRecordController(ManualOperationRecordService manualOperationRecordService)
{
_manualOperationRecordService = manualOperationRecordService;
}
/// <summary>
/// 查询
/// </summary>
/// <returns></returns>
[HttpPost("GetPageManualOperationRecord")]
public async Task<Result<PageResult<ManualOperationRecord>>> GetPageManualOperationRecord([FromBody] PageManualOperationRecordReq queryPageModel)
{
return Result<PageResult<ManualOperationRecord>>.Success(await _manualOperationRecordService.Page(queryPageModel));
}
}

@ -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;
/// <summary>
/// 统计
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class StatisticsController
{
private readonly ExStationDayRunResultService _exStationDayRunResultService;
public StatisticsController(ExStationDayRunResultService exStationDayRunResultService)
{
_exStationDayRunResultService = exStationDayRunResultService;
}
/// <summary>
/// 获取一个月的每日数据(30天)
/// </summary>
/// <returns></returns>
[HttpPost("GetMonthResult")]
public async Task<Result<List<ExchangeStationDayRunResult>>> GetMonthResult()
{
return Result<List<ExchangeStationDayRunResult>>.Success(await _exStationDayRunResultService.GetMonthRunResult());
}
/// <summary>
/// 获取一年内每月的数据和12月
/// </summary>
/// <returns></returns>
[HttpPost("GetYearResult")]
public async Task<Result<List<ExchangeStationDayRunResult>>> GetYearResult()
{
return Result<List<ExchangeStationDayRunResult>>.Success(await _exStationDayRunResultService.GetYearRunResult());
}
}

@ -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<Result<bool>> ConfirmLockSucc()
{
StationSoftMgr.SwappingStateMachine.ManualConfirmLockCar();
_manualOperationRecordService.AddManualOperationRecord(StationSoftMgr.SwappingStateMachine.SwapOrder.Sn, 3);
return Result<bool>.Success();
}
@ -311,6 +315,9 @@ public class SwapMonitorController : ControllerBase
public async Task<Result<bool>> ConfirmUnLockSucc()
{
StationSoftMgr.SwappingStateMachine.ManualConfirmUnLockCar();
_manualOperationRecordService.AddManualOperationRecord(StationSoftMgr.SwappingStateMachine.SwapOrder.Sn, 4);
return Result<bool>.Success();
}
}
Loading…
Cancel
Save