换电次数统计

master
xjl 4 months ago
parent 9442e5ec5f
commit 914ec35564

@ -0,0 +1,101 @@
using SqlSugar;
namespace Entity.Dto.Resp
{
public class ExchangeStationDayRunResultResp
{
/// <summary>
/// 主键ID
/// </summary>
public int Id { get; set; }
/// <summary>
/// 平均充电时长
/// </summary>
public string AvgChgTime { get; set; }
/// <summary>
/// 平均换电时长
/// </summary>
public string AvgRepTime { get; set; }
/// <summary>
/// 换电日期
/// </summary>
public string SwapDate { get; set; }
/// <summary>
/// 首次换电时间
/// </summary>
public string FristSwapTime { get; set; }
/// <summary>
/// 结束换电时间
/// </summary>
public string StopTime { get; set; }
/// <summary>
/// 运行开始时间
/// </summary>
public string RunStartTime { get; set; }
/// <summary>
/// 运行结束时间
/// </summary>
public string RunEndTime { get; set; }
/// <summary>
/// 充电总次数
/// </summary>
public int ChgCount { get; set; }
/// <summary>
/// 运营状态
/// </summary>
public int State { get; set; }
/// <summary>
/// 换电总次数
/// </summary>
public int ToltalSwapCount { get; set; }
/// <summary>
/// 换电总时长
/// </summary>
public double ToltalSwapAllTime { get; set; }
/// <summary>
/// 站运行总时长
/// </summary>
public double ToltalTimeCount { get; set; }
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
public string? CreatedBy { get; set; }
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
public string? CreatedTime { get; set; }
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
public string? UpdatedBy { get; set; }
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary
public string? UpdatedTime { get; set; }
}
}

@ -17,6 +17,7 @@ using Entity.Dto;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Entity.Dto.Resp;
namespace Service.Station
{
@ -94,8 +95,10 @@ namespace Service.Station
/// <returns></returns>
public async Task<List<ExchangeStationDayRunResult>> GetMonthRunResult()
{
var monthTime1 = DateTimeOffset.UtcNow.AddMonths(-1).ToString("yyyy/MM/01 00:00:00");//上月1号
var monthTime2 = DateTimeOffset.UtcNow.AddMonths(0).ToString("yyyy/MM/01 00:00:00");//本月1号
var runresult = await _exStationDayRunResultRepository.QueryListByClauseAsync(u => u.CreatedTime >= DateTimeOffset.UtcNow.AddDays(-30));
var runresult = await _exStationDayRunResultRepository.QueryListByClauseAsync(u => u.CreatedTime >= Convert.ToDateTime(monthTime1) && u.CreatedTime < Convert.ToDateTime(monthTime2));
return runresult;
}
@ -105,19 +108,27 @@ namespace Service.Station
/// 获取一年内每月的数据和
/// </summary>
/// <returns></returns>
public async Task<List<ExchangeStationDayRunResult>> GetYearRunResult()
public async Task<List<ExchangeStationDayRunResultResp>> GetYearRunResult()
{
var runresult = _exStationDayRunResultRepository.QueryListByClause(u => u.CreatedTime >= DateTimeOffset.UtcNow.AddMonths(-12))
var monthTime1 = DateTimeOffset.UtcNow.AddYears(0).ToString("yyyy/01/01 00:00:00");//今年1月1号
var monthTime2 = DateTimeOffset.UtcNow.AddMonths(0).ToString("yyyy/MM/01 00:00:00");//本月1号
var runresult = _exStationDayRunResultRepository.QueryListByClause(u => u.CreatedTime >= Convert.ToDateTime(monthTime1) && u.CreatedTime < Convert.ToDateTime(monthTime2))
.GroupBy(d => d.CreatedTime.Value.Month);
// 对每个月的数据求和
Dictionary<int, ExchangeStationDayRunResult> monthlyTotals = new Dictionary<int, ExchangeStationDayRunResult>();
Dictionary<int, ExchangeStationDayRunResultResp> monthlyTotals = new Dictionary<int, ExchangeStationDayRunResultResp>();
foreach (var group in runresult)
{
var month = group.Key;
ExchangeStationDayRunResult runResult = new ExchangeStationDayRunResult
DateTime CreatedTime = (DateTime)group.First().CreatedTime;
//CreatedTime=Convert.ToDateTime(CreatedTime.ToString("yyyy/MM"));
DateTime UpdatedTime = (DateTime)group.First().UpdatedTime;
//UpdatedTime = Convert.ToDateTime(CreatedTime.ToString("yyyy/MM"));
ExchangeStationDayRunResultResp runResult = new ExchangeStationDayRunResultResp
{
AvgChgTime = group.Sum(d => Convert.ToDouble(d.AvgChgTime)).ToString("F2"),
@ -126,15 +137,16 @@ namespace Service.Station
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,
CreatedTime= CreatedTime.ToString("yyyy/MM"),
UpdatedTime = UpdatedTime.ToString("yyyy/MM"),
};
monthlyTotals[month] = runResult;
}
List<ExchangeStationDayRunResult> resultList = monthlyTotals
List<ExchangeStationDayRunResultResp> resultList = monthlyTotals
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
.Select(pair => pair.Value)
.ToList();

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using Entity.DbModel.Station;
using Entity.Dto.Req;
using Entity.Dto.Resp;
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Init;
@ -23,7 +24,7 @@ public class StatisticsController
/// <summary>
/// 获取一个月的每日数据(30天)
/// 获取上个月的每日数据
/// </summary>
/// <returns></returns>
[HttpPost("GetMonthResult")]
@ -36,13 +37,13 @@ public class StatisticsController
/// <summary>
/// 获取一年内每月的数据和12月
/// 获取今年到上月的每月的数据和
/// </summary>
/// <returns></returns>
[HttpPost("GetYearResult")]
public async Task<Result<List<ExchangeStationDayRunResult>>> GetYearResult()
public async Task<Result<List<ExchangeStationDayRunResultResp>>> GetYearResult()
{
return Result<List<ExchangeStationDayRunResult>>.Success(await _exStationDayRunResultService.GetYearRunResult());
return Result<List<ExchangeStationDayRunResultResp>>.Success(await _exStationDayRunResultService.GetYearRunResult());
}
}

@ -2,7 +2,7 @@
"ConnectionStrings": {
"ConfigId": "master",
"DbType": "MySql",
"SqlConnection": "server=192.168.2.2;Port=3306;Database=nhet_dev;Uid=root;Pwd=Rszn123;Charset=utf8;"
"SqlConnection": "server=180.76.133.253;Port=16306;Database=nhet_dev;Uid=root;Pwd=Rszn123;Charset=utf8;"
},
"Update": {
"AutoUpdate": "false",
@ -10,7 +10,7 @@
"Url": "http://121.4.95.243:8090/Updates/AutoUpdaterStarter.xml"
},
"Redis": {
"Connection": "192.168.2.2:6379,password=123456",
"Connection": "127.0.0.1:6379,password=123456",
"InstanceName": "local",
"DefaultDB": "8"
},

Loading…
Cancel
Save