fix 营业点类型枚举和考勤summary
This commit is contained in:
@@ -28,4 +28,8 @@
|
||||
<ProjectReference Include="..\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Summary\Request\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
29
Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs
Normal file
29
Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Dlhis.Basic.Summary.Response;
|
||||
using Dlhis.Basic.Summary.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Summary.Controllers;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class SummariesController : ControllerBase
|
||||
{
|
||||
private readonly ISummaryService _summaryService;
|
||||
|
||||
public SummariesController(ISummaryService summaryService)
|
||||
{
|
||||
_summaryService = summaryService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 考勤首页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("attendance-summary")]
|
||||
public async Task<AttendanceSummaryResponse> GetKaoQingSummary()
|
||||
{
|
||||
return await _summaryService.GetAttendanceSummaryAsync();
|
||||
}
|
||||
}
|
||||
8
Src/Dlhis.Basic/Summary/Dto/TrendDto.cs
Normal file
8
Src/Dlhis.Basic/Summary/Dto/TrendDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Dlhis.Basic.Summary.Dto;
|
||||
|
||||
public class TrendDto
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
}
|
||||
21
Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs
Normal file
21
Src/Dlhis.Basic/Summary/Response/AttendanceDetailSummary.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Dlhis.Basic.Summary.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Summary.Response;
|
||||
|
||||
public class AttendanceDetailSummary
|
||||
{
|
||||
/// <summary>
|
||||
/// 在职人数
|
||||
/// </summary>
|
||||
public int Employed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 非在职人数
|
||||
/// </summary>
|
||||
public int Unemployed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人员趋势 7天
|
||||
/// </summary>
|
||||
public GainfoTrendResponse GainfoTrend { get; set; }
|
||||
}
|
||||
26
Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs
Normal file
26
Src/Dlhis.Basic/Summary/Response/AttendanceDeviceSummary.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Dlhis.Basic.Summary.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Summary.Response;
|
||||
|
||||
public class AttendanceDeviceSummary
|
||||
{
|
||||
/// <summary>
|
||||
/// 总数
|
||||
/// </summary>
|
||||
public int Total { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 在线数
|
||||
/// </summary>
|
||||
public int OnlineCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 启用数
|
||||
/// </summary>
|
||||
public int EnableCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 新增设备趋势 30天内
|
||||
/// </summary>
|
||||
public List<TrendDto> Trend { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Dlhis.Basic.Summary.Response
|
||||
{
|
||||
public class AttendanceSummaryResponse
|
||||
{
|
||||
public AttendanceDeviceSummary DeviceSummary { get; set; }
|
||||
|
||||
public AttendanceDetailSummary AttendanceDetailSummary { get; set; }
|
||||
}
|
||||
}
|
||||
10
Src/Dlhis.Basic/Summary/Response/GainfoTrendResponse.cs
Normal file
10
Src/Dlhis.Basic/Summary/Response/GainfoTrendResponse.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Dlhis.Basic.Summary.Dto;
|
||||
|
||||
namespace Dlhis.Basic.Summary.Response
|
||||
{
|
||||
public class GainfoTrendResponse
|
||||
{
|
||||
public List<TrendDto> EmployedTrend { get; set; }
|
||||
public List<TrendDto> UnemployedTrend { get; set; }
|
||||
}
|
||||
}
|
||||
8
Src/Dlhis.Basic/Summary/Services/ISummaryService.cs
Normal file
8
Src/Dlhis.Basic/Summary/Services/ISummaryService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Dlhis.Basic.Summary.Response;
|
||||
|
||||
namespace Dlhis.Basic.Summary.Services;
|
||||
|
||||
public interface ISummaryService : IScopeDependency
|
||||
{
|
||||
Task<AttendanceSummaryResponse> GetAttendanceSummaryAsync();
|
||||
}
|
||||
106
Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs
Normal file
106
Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Dlhis.Basic.Organization.Services;
|
||||
using Dlhis.Basic.Summary.Dto;
|
||||
using Dlhis.Basic.Summary.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.Basic.Summary.Services.Implements;
|
||||
|
||||
public class SummaryService : ISummaryService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IGainfoStore _gainfoStore;
|
||||
|
||||
public SummaryService(IDbContext dbContext, IGainfoStore gainfoStore)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_gainfoStore = gainfoStore;
|
||||
}
|
||||
|
||||
public async Task<AttendanceSummaryResponse> GetAttendanceSummaryAsync()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
|
||||
var currentDay = DateTime.Today.AddDays(1).AddSeconds(-1);
|
||||
var before30Day = DateTime.Today.AddDays(-29);
|
||||
var before7Day = DateTime.Today.AddDays(-6);
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
var deviceUniqueNos = devices.Select(x => x.UniqueNo).ToList();
|
||||
|
||||
var deviceRegistries = await _dbContext.Queryable<DeviceRegistryEntity>()
|
||||
.LeftJoin<DeviceEntity>((x, d) => x.DeviceUniqueNo == d.UniqueNo)
|
||||
.Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo))
|
||||
.Select((x, d) => new
|
||||
{
|
||||
d.HeartbeatInterval,
|
||||
x.LastHeartbeatTime
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var workingGainfos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).ToListAsync();
|
||||
var leaveGainfos = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave).ToListAsync();
|
||||
|
||||
return new AttendanceSummaryResponse
|
||||
{
|
||||
DeviceSummary = new AttendanceDeviceSummary
|
||||
{
|
||||
Total = devices.Count,
|
||||
EnableCount = devices.Where(x => x.Enable).Count(),
|
||||
OnlineCount = deviceRegistries.Where(x =>
|
||||
{
|
||||
if (x.HeartbeatInterval <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return x.LastHeartbeatTime.AddSeconds(x.HeartbeatInterval * 3) >= now;
|
||||
|
||||
}).Count(),
|
||||
Trend = FixTrend(devices.Where(x => x.CreateTime >= before30Day && x.CreateTime <= currentDay)
|
||||
.GroupBy(x => x.CreateTime.Date)
|
||||
.Select(x => new TrendDto { Date = x.Key, Count = x.Count() }), before30Day, currentDay)
|
||||
},
|
||||
AttendanceDetailSummary = new AttendanceDetailSummary
|
||||
{
|
||||
Employed = workingGainfos.Count,
|
||||
Unemployed = leaveGainfos.Count,
|
||||
GainfoTrend = new GainfoTrendResponse
|
||||
{
|
||||
EmployedTrend = FixTrend(workingGainfos.Where(x => x.CreateTime >= before7Day && x.CreateTime <= currentDay)
|
||||
.GroupBy(x => x.CreateTime.Date)
|
||||
.Select(x => new TrendDto { Date = x.Key, Count = x.Count() }), before7Day, currentDay),
|
||||
UnemployedTrend = FixTrend(leaveGainfos.Where(x => x.CreateTime >= before7Day && x.CreateTime <= currentDay)
|
||||
.GroupBy(x => x.CreateTime.Date)
|
||||
.Select(x => new TrendDto { Date = x.Key, Count = x.Count() }), before7Day, currentDay),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static List<TrendDto> FixTrend(IEnumerable<TrendDto> dtos, DateTime start, DateTime end)
|
||||
{
|
||||
var result = dtos.ToList();
|
||||
|
||||
start = start.Date;
|
||||
end = end.Date;
|
||||
|
||||
var currentDate = start;
|
||||
while (currentDate <= end)
|
||||
{
|
||||
if (result.Any(x => x.Date == currentDate))
|
||||
{
|
||||
currentDate = currentDate.AddDays(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
result.Add(new TrendDto { Date = currentDate, Count = 0 });
|
||||
|
||||
currentDate = currentDate.AddDays(1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,15 @@ public enum CanteenBusinessPlaceCatalogEnumType
|
||||
[Description("食堂")]
|
||||
Cafeteria = 2,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 超市
|
||||
/// </summary>
|
||||
[Description("超市")]
|
||||
Supermarket = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 水吧
|
||||
/// </summary>
|
||||
[Description("水吧")]
|
||||
Bar = 4,
|
||||
}
|
||||
Reference in New Issue
Block a user