diff --git a/OpenAuth.App/ServiceApp/MiManager/MiViolationReportApp.cs b/OpenAuth.App/ServiceApp/MiManager/MiViolationReportApp.cs index e288aa3..d4ff954 100644 --- a/OpenAuth.App/ServiceApp/MiManager/MiViolationReportApp.cs +++ b/OpenAuth.App/ServiceApp/MiManager/MiViolationReportApp.cs @@ -903,7 +903,7 @@ namespace OpenAuth.App #endregion #region 报表导出 - public async Task> GetPunchStatistics() + public async Task> GetPunchStatistics(DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { @@ -931,7 +931,9 @@ namespace OpenAuth.App ps.UserName = item.Name; ps.UserId = item.Id; //巡查信息 - var punchdata = uow.MiPunchRecord.AsQueryable().Where(r => r.UserId == item.Id); + var punchdata = uow.MiPunchRecord.AsQueryable() + .Where(r => r.UserId == item.Id) + .WhereIF(begindate != null && enddate != null, r => r.PunchTime >= begindate && r.PunchTime <= enddate); if (punchdata.Any()) { // 假设 PunchTime 是 DateTime 类型 @@ -944,24 +946,29 @@ namespace OpenAuth.App ps.PunchScope = $"{mintime}-{maxtime}"; var punchcount = punchdata.Count(); ps.PunchCount = punchcount; + ps.ReportCount = punchdata.Where(r => r.PunchStatus == 1).Count(); } else { ps.PunchScope = ""; ps.PunchCount = 0; + ps.ReportCount = 0; } //违法信息 - var violatedata = uow.MiViolationReport.AsQueryable().Where(r => r.Reporter == item.Id.ToString()); + var violatedata = uow.MiViolationReport.AsQueryable(). + Where(r => r.Reporter == item.Id.ToString()) + .WhereIF(begindate != null && enddate != null, r => r.ReportTime >= begindate && r.ReportTime <= enddate); if (violatedata.Any()) { var violatecount = violatedata.Count(); - ps.ReportCount = violatecount; - var dealCount = violatedata.Where(r => r.Status == 3 || r.Status > 4).Count(); - ps.DealCount = dealCount; + ps.DealCount = violatecount; + //var dealCount = violatedata.Where(r => r.Status == 3 || r.Status > 4).Count(); + //ps.DealCount = dealCount; } else { - ps.ReportCount = 0; ps.DealCount = 0; + //ps.ReportCount = 0; + ps.DealCount = 0; } plist.Add(ps); } @@ -980,7 +987,7 @@ namespace OpenAuth.App /// /// /// - public async Task> GetPointPunchStatistics() + public async Task> GetPointPunchStatistics(DateTime? begindate,DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { @@ -1005,7 +1012,9 @@ namespace OpenAuth.App ps.CountyName = item.CountyName; ps.PointId = item.Id; //巡查信息 - var punchdata = uow.MiPunchRecord.AsQueryable().Where(r => r.MinePointId == item.Id); + var punchdata = uow.MiPunchRecord.AsQueryable() + .Where(r => r.MinePointId == item.Id) + .WhereIF(begindate != null && enddate != null, r => r.PunchTime >= begindate && r.PunchTime <= enddate); if (punchdata.Any()) { // 假设 PunchTime 是 DateTime 类型 @@ -1018,24 +1027,30 @@ namespace OpenAuth.App ps.PunchScope = $"{mintime}-{maxtime}"; var punchcount = punchdata.Count(); ps.PunchCount = punchcount; + ps.ReportCount = punchdata.Where(r=>r.PunchStatus==1).Count(); } else { ps.PunchScope = ""; ps.PunchCount = 0; + ps.ReportCount = 0; } //违法信息 - var violatedata = uow.MiViolationReport.AsQueryable().Where(r => r.MinePointId == item.Id); + var violatedata = uow.MiViolationReport.AsQueryable() + .Where(r => r.MinePointId == item.Id) + .WhereIF(begindate != null && enddate != null, r => r.ReportTime >= begindate && r.ReportTime <= enddate); + if (violatedata.Any()) { var violatecount = violatedata.Count(); - ps.ReportCount = violatecount; - var dealCount = violatedata.Where(r => r.Status == 3||r.Status>4).Count(); - ps.DealCount = dealCount; + ps.DealCount = violatecount; + //var dealCount = violatedata.Where(r => r.Status == 3||r.Status>4).Count(); + //ps.DealCount = dealCount; } else { - ps.ReportCount = 0; ps.DealCount = 0; + //ps.ReportCount = 0; + ps.DealCount = 0; } plist.Add(ps); } @@ -1144,12 +1159,13 @@ namespace OpenAuth.App /// /// /// - public async Task GetPunchDetailData(long userid) + public async Task GetPunchDetailData(long userid, DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { var result = await uow.MiPunchRecord.AsQueryable() .Where(p => p.UserId == userid) + .WhereIF(begindate != null && enddate != null, p => p.PunchTime >= begindate && p.PunchTime <= enddate) .OrderByDescending(p => p.PunchTime) .Select((p) => new { @@ -1164,13 +1180,14 @@ namespace OpenAuth.App /// /// /// - public async Task GetReportDetailData(long userid) + public async Task GetReportDetailData(long userid, DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { - var result = await uow.MiViolationReport.AsQueryable() - .Where(p => p.Reporter == userid.ToString()) - .OrderByDescending(p => p.ReportTime) + var result = await uow.MiPunchRecord.AsQueryable() + .Where(p => p.UserId == userid&&p.PunchStatus==1) + .WhereIF(begindate != null && enddate != null, p => p.PunchTime >= begindate && p.PunchTime <= enddate) + .OrderByDescending(p => p.PunchTime) .Select((p) => new { Id = p.Id.SelectAll() @@ -1184,12 +1201,13 @@ namespace OpenAuth.App /// /// /// - public async Task GetDealDetailData(long userid) + public async Task GetDealDetailData(long userid, DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { var result = await uow.MiViolationReport.AsQueryable() - .Where(p => p.Reporter == userid.ToString()&&(p.Status==3||p.Status>4)) + .Where(p => p.Reporter == userid.ToString()) + .WhereIF(begindate != null && enddate != null, p => p.ReportTime >= begindate && p.ReportTime <= enddate) .OrderByDescending(p => p.ReportTime) .Select((p) => new { @@ -1205,12 +1223,13 @@ namespace OpenAuth.App /// /// 点位id /// - public async Task GetPointPunchDetailData(string pointid) + public async Task GetPointPunchDetailData(string pointid, DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { var result = await uow.MiPunchRecord.AsQueryable() .Where(r=>r.MinePointId==pointid) + .WhereIF(begindate != null && enddate != null, r => r.PunchTime >= begindate && r.PunchTime <= enddate) .LeftJoin((r, u) => r.UserId == u.Id) .LeftJoin((r, u, p) => r.MinePointId == p.Id) .OrderByDescending((r, u, p) => r.PunchTime) @@ -1234,17 +1253,27 @@ namespace OpenAuth.App /// /// /// - public async Task GetPointReportDetailData(string pointid) + public async Task GetPointReportDetailData(string pointid, DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { - var result = await uow.MiViolationReport.AsQueryable() - .Where(p => p.MinePointId==pointid) - .OrderByDescending(p => p.ReportTime) - .Select((p) => new - { - Id = p.Id.SelectAll() - }).ToListAsync(); + var result = await uow.MiPunchRecord.AsQueryable() + .Where(r => r.MinePointId == pointid&&r.PunchStatus==1) + .WhereIF(begindate != null && enddate != null, r => r.PunchTime >= begindate && r.PunchTime <= enddate) + .LeftJoin((r, u) => r.UserId == u.Id) + .LeftJoin((r, u, p) => r.MinePointId == p.Id) + .OrderByDescending((r, u, p) => r.PunchTime) + .Select((r, u, p) => new + { + Id = r.Id.SelectAll(), + UserName = u.Name, + PointName = p.Name, + StreetName = p.StreetName, + p.CountyName, + p.CommunityName, + StatusName = SqlFunc.Subqueryable().Where(a => a.ItemCode == "JGMinePointStatus" && a.ItemValue == r.PunchStatus.ToString()).Select(a => a.ItemName) + }) + .ToListAsync(); return result; } } @@ -1254,12 +1283,13 @@ namespace OpenAuth.App /// /// /// - public async Task GetPointDealDetailData(string pointid) + public async Task GetPointDealDetailData(string pointid, DateTime? begindate, DateTime? enddate) { using (var uow = UnitWork.CreateContext()) { var result = await uow.MiViolationReport.AsQueryable() - .Where(p => p.MinePointId == pointid &&( p.Status == 3 || p.Status > 4)) + .Where(p => p.MinePointId == pointid) + .WhereIF(begindate != null && enddate != null, p => p.ReportTime >= begindate && p.ReportTime <= enddate) .OrderByDescending(p => p.ReportTime) .Select((p) => new { @@ -1272,7 +1302,7 @@ namespace OpenAuth.App #region //导出 巡查台账--人员 - public async Task> ExportPunchStatistics() + public async Task> ExportPunchStatistics(DateTime? begindate, DateTime? enddate) { Response response = new Response(); try @@ -1310,7 +1340,7 @@ namespace OpenAuth.App #endregion // 获取统计数据 - var list = await GetPunchStatistics(); + var list = await GetPunchStatistics(begindate,enddate); int totalCount = list.Count; int pageSize = 60000; // 每个Sheet最大行数 int sheetCount = (totalCount / pageSize) + (totalCount % pageSize > 0 ? 1 : 0); @@ -1389,7 +1419,7 @@ namespace OpenAuth.App } - public async Task> ExportPointPunchStatistics() + public async Task> ExportPointPunchStatistics(DateTime? begindate, DateTime? enddate) { Response response = new Response(); try @@ -1427,7 +1457,7 @@ namespace OpenAuth.App #endregion // 获取统计数据 - var list = await GetPointPunchStatistics(); + var list = await GetPointPunchStatistics(begindate,enddate); int totalCount = list.Count; int pageSize = 60000; // 每个Sheet最大行数 int sheetCount = (totalCount / pageSize) + (totalCount % pageSize > 0 ? 1 : 0); diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/MiViolationReportController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/MiViolationReportController.cs index b94fe0d..32db98a 100644 --- a/OpenAuth.WebApi/Controllers/ServiceControllers/MiViolationReportController.cs +++ b/OpenAuth.WebApi/Controllers/ServiceControllers/MiViolationReportController.cs @@ -1,4 +1,5 @@ using DocumentFormat.OpenXml.EMMA; +using DocumentFormat.OpenXml.Spreadsheet; using Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -238,12 +239,12 @@ namespace OpenAuth.WebApi.Controllers /// /// [HttpGet] - public async Task>> GetPunchStatistics() + public async Task>> GetPunchStatistics(DateTime? begindate, DateTime? enddate) { var result = new Response>(); try { - result.Result = await _app.GetPunchStatistics(); + result.Result = await _app.GetPunchStatistics(begindate, enddate); } catch (Exception ex) { @@ -259,12 +260,12 @@ namespace OpenAuth.WebApi.Controllers /// /// [HttpGet] - public async Task>> GetPointPunchStatistics() + public async Task>> GetPointPunchStatistics(DateTime? begindate, DateTime? enddate) { var result = new Response>(); try { - result.Result = await _app.GetPointPunchStatistics(); + result.Result = await _app.GetPointPunchStatistics(begindate, enddate); } catch (Exception ex) { @@ -322,12 +323,34 @@ namespace OpenAuth.WebApi.Controllers /// 人员id /// [HttpGet] - public async Task> GetPunchDetailData(long userid) + public async Task> GetPunchDetailData(long userid, DateTime? begindate, DateTime? enddate) { var result = new Response(); try { - result.Result = await _app.GetPunchDetailData(userid); + result.Result = await _app.GetPunchDetailData(userid, begindate, enddate); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + + return result; + } + + /// + /// 巡查台账-人员-巡查异常次数 + /// + /// 人员id + /// + [HttpGet] + public async Task> GetReportDetailData(long userid, DateTime? begindate, DateTime? enddate) + { + var result = new Response(); + try + { + result.Result = await _app.GetReportDetailData(userid, begindate, enddate); } catch (Exception ex) { @@ -344,34 +367,12 @@ namespace OpenAuth.WebApi.Controllers /// 人员id /// [HttpGet] - public async Task> GetReportDetailData(long userid) + public async Task> GetDealDetailData(long userid, DateTime? begindate, DateTime? enddate) { var result = new Response(); try { - result.Result = await _app.GetReportDetailData(userid); - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - - /// - /// 巡查台账-人员-违法处理次数 - /// - /// 人员id - /// - [HttpGet] - public async Task> GetDealDetailData(long userid) - { - var result = new Response(); - try - { - result.Result = await _app.GetDealDetailData(userid); + result.Result = await _app.GetDealDetailData(userid, begindate, enddate); } catch (Exception ex) { @@ -388,12 +389,34 @@ namespace OpenAuth.WebApi.Controllers /// 巡查点id /// [HttpGet] - public async Task> GetPointPunchDetailData(string pointid) + public async Task> GetPointPunchDetailData(string pointid, DateTime? begindate, DateTime? enddate) { var result = new Response(); try { - result.Result = await _app.GetPointPunchDetailData(pointid); + result.Result = await _app.GetPointPunchDetailData(pointid, begindate, enddate); + } + catch (Exception ex) + { + result.Code = 500; + result.Message = ex.InnerException?.Message ?? ex.Message; + } + + return result; + } + + /// + /// 巡查台账-点位-巡查异常次数 + /// + /// 巡查点id + /// + [HttpGet] + public async Task> GetPointReportDetailData(string pointid, DateTime? begindate, DateTime? enddate) + { + var result = new Response(); + try + { + result.Result = await _app.GetPointReportDetailData(pointid, begindate, enddate); } catch (Exception ex) { @@ -410,34 +433,12 @@ namespace OpenAuth.WebApi.Controllers /// 巡查点id /// [HttpGet] - public async Task> GetPointReportDetailData(string pointid) + public async Task> GetPointDealDetailData(string pointid, DateTime? begindate, DateTime? enddate) { var result = new Response(); try { - result.Result = await _app.GetPointReportDetailData(pointid); - } - catch (Exception ex) - { - result.Code = 500; - result.Message = ex.InnerException?.Message ?? ex.Message; - } - - return result; - } - - /// - /// 巡查台账-点位-违法处理次数 - /// - /// 巡查点id - /// - [HttpGet] - public async Task> GetPointDealDetailData(string pointid) - { - var result = new Response(); - try - { - result.Result = await _app.GetPointDealDetailData(pointid); + result.Result = await _app.GetPointDealDetailData(pointid, begindate, enddate); } catch (Exception ex) { @@ -454,10 +455,10 @@ namespace OpenAuth.WebApi.Controllers /// /// [HttpGet] - public async Task ExportPunchStatistics() + public async Task ExportPunchStatistics(DateTime? begindate, DateTime? enddate) { var res = new Response(); - var excelRes = await _app.ExportPunchStatistics(); + var excelRes = await _app.ExportPunchStatistics(begindate, enddate); if (excelRes.Code == 200) { return File(excelRes.Result.ToArray(), @@ -477,10 +478,10 @@ namespace OpenAuth.WebApi.Controllers /// /// [HttpGet] - public async Task ExportPointPunchStatistics() + public async Task ExportPointPunchStatistics(DateTime? begindate, DateTime? enddate) { var res = new Response(); - var excelRes = await _app.ExportPointPunchStatistics(); + var excelRes = await _app.ExportPointPunchStatistics(begindate, enddate); if (excelRes.Code == 200) { return File(excelRes.Result.ToArray(),