From 07d77f10705b2b37445b0034d9d8aa915b1b7764 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Fri, 8 Mar 2024 19:03:57 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E9=97=A8=E7=A6=81=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SummariesController.cs | 12 ++++- .../Summary/Response/DoorDataResponse.cs | 35 ++++++++++++++ .../Summary/Services/ISummaryService.cs | 2 + .../Services/Implements/SummaryService.cs | 46 +++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 Src/Dlhis.Basic/Summary/Response/DoorDataResponse.cs diff --git a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs index 2acddc4e..cf79395e 100644 --- a/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs +++ b/Src/Dlhis.Basic/Summary/Controllers/SummariesController.cs @@ -29,7 +29,7 @@ public class SummariesController : ControllerBase } /// - /// 门禁首页数据 + /// 门禁首页设备数据 /// /// [HttpGet("door-summary")] @@ -37,4 +37,14 @@ public class SummariesController : ControllerBase { return await _summaryService.GetDoorHomeDataAsync(); } + + /// + /// 门禁首页数据 + /// + /// + [HttpGet("door-data")] + public async Task GetDoorDataAsync() + { + return await _summaryService.GetDoorDataAsync(); + } } diff --git a/Src/Dlhis.Basic/Summary/Response/DoorDataResponse.cs b/Src/Dlhis.Basic/Summary/Response/DoorDataResponse.cs new file mode 100644 index 00000000..c7d7a178 --- /dev/null +++ b/Src/Dlhis.Basic/Summary/Response/DoorDataResponse.cs @@ -0,0 +1,35 @@ +namespace Dlhis.Basic.Summary.Response +{ + public class DoorDataResponse + { + /// + /// 门禁总人数 + /// + public int Total => Employed + Unemployed; + + /// + /// 在职人数 + /// + public int Employed { get; set; } + + /// + /// 周在职人数 + /// + public int WeekEmployed { get; set; } + + /// + /// 非在职人数 + /// + public int Unemployed { get; set; } + + /// + /// 周非在职人数 + /// + public int WeekUnemployed { get; set; } + + /// + /// 人员趋势 7天 + /// + public GainfoTrendResponse GainfoTrend { get; set; } + } +} diff --git a/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs b/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs index 9c92e218..0b4046cf 100644 --- a/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/ISummaryService.cs @@ -8,4 +8,6 @@ public interface ISummaryService : IScopeDependency Task GetAttendanceSummaryAsync(); Task GetDoorHomeDataAsync(); + + Task GetDoorDataAsync(); } diff --git a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs index 4feeb179..cdd29667 100644 --- a/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs +++ b/Src/Dlhis.Basic/Summary/Services/Implements/SummaryService.cs @@ -118,6 +118,52 @@ public class SummaryService : ISummaryService return res; } + public async Task GetDoorDataAsync() + { + var res = new DoorDataResponse(); + List workingGainfos = await _gainfoStore.Queryable(GainfoStatusEnumType.Working).ToListAsync(); + var leaveGainfos = await _gainfoStore.Queryable(GainfoStatusEnumType.Leave).ToListAsync(); + res.Employed = workingGainfos.Count; + res.Unemployed = leaveGainfos.Count; + + var employedTrend = new List(); + var unemployedTrend = new List(); + + //获取近7天并转化为"yyyy-MM-dd"集合 + DateTime currentDate = DateTime.Now; + List times = new List(); + for (int i = 0; i < 7; i++) + { + DateTime date = currentDate.AddDays(-i); + string dateString = date.ToString("yyyy-MM-dd"); + times.Add(dateString); + } + + + foreach (var time in times) + { + var emDto = new TrendDto + { + Date = DateTime.ParseExact(time, "yyyy-MM-dd", null), + Count = workingGainfos.Where(x => x.CreateTime.ToString("yyy-MM-dd") == time).ToList().Count, + }; + employedTrend.Add(emDto); + var unDto = new TrendDto + { + Date = DateTime.ParseExact(time, "yyyy-MM-dd", null), + Count = leaveGainfos.Where(x => x.CreateTime.ToString("yyy-MM-dd") == time).ToList().Count, + }; + unemployedTrend.Add(unDto); + } + var ginfoTrendResponse = new GainfoTrendResponse(); + ginfoTrendResponse.EmployedTrend = employedTrend; + ginfoTrendResponse.UnemployedTrend = unemployedTrend; + res.GainfoTrend = ginfoTrendResponse; + employedTrend.ForEach(x => res.WeekEmployed += x.Count); + unemployedTrend.ForEach(x => res.WeekUnemployed+=x.Count); + return res; + } + private static List FixTrend(IEnumerable dtos, DateTime start, DateTime end) { var result = dtos.ToList();