From b725eb500ec523df0f3136164514e9ea791aab1c Mon Sep 17 00:00:00 2001
From: zhangbin <460190368@qq.com>
Date: Mon, 18 Nov 2024 15:13:21 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E5=88=97?=
=?UTF-8?q?=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=80=BC=EF=BC=8C=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
OpenAuth.App/ServiceApp/AdminTaskManageApp.cs | 17 +-
OpenAuth.App/ServiceApp/DataAnalysisApp.cs | 290 +++++++++++++++++-
.../AiShpDataExpenseAccountingTableResp.cs | 16 +
.../Response/InsTaskForAdminResp.cs | 16 +
.../Response/UserOrGroupTaskResp.cs | 16 +
.../ServiceApp/Response/UserTaskResp.cs | 14 +
.../AdminTaskManageController.cs | 6 +-
.../DataAnalysisController.cs | 55 +++-
8 files changed, 417 insertions(+), 13 deletions(-)
create mode 100644 OpenAuth.App/ServiceApp/Response/AiShpDataExpenseAccountingTableResp.cs
create mode 100644 OpenAuth.App/ServiceApp/Response/InsTaskForAdminResp.cs
create mode 100644 OpenAuth.App/ServiceApp/Response/UserOrGroupTaskResp.cs
create mode 100644 OpenAuth.App/ServiceApp/Response/UserTaskResp.cs
diff --git a/OpenAuth.App/ServiceApp/AdminTaskManageApp.cs b/OpenAuth.App/ServiceApp/AdminTaskManageApp.cs
index ada9fd0..57adefc 100644
--- a/OpenAuth.App/ServiceApp/AdminTaskManageApp.cs
+++ b/OpenAuth.App/ServiceApp/AdminTaskManageApp.cs
@@ -129,7 +129,7 @@ namespace OpenAuth.App.ServiceApp
var content = new
{
queryid = insTaskInfo.Id,
- message="有新创建的任务"
+ message = "有新创建的任务"
};
var contents = Json.ToJson(content);
try
@@ -161,18 +161,25 @@ namespace OpenAuth.App.ServiceApp
/// 任务列表
///
///
- public async Task>>> GteTaskListForAdmin(string taskName, int page, int limit)
+ public async Task>>> GteTaskListForAdmin(string taskName, int page, int limit)
{
using (var db = base.UnitWork.CreateContext())
{
RefAsync totalCount = 0;
var tsakList = await db.InsTask.AsQueryable()
+ .LeftJoin((a, b) => a.ShpId == b.Id)
.WhereIF(!string.IsNullOrEmpty(taskName), r => r.TaskName.Contains(taskName))
- .ToPageListAsync(page, limit, totalCount);
+ .Select((a, b) => new InsTaskForAdminResp()
+ {
+ Id = a.Id.SelectAll(),
+ ShpCount = b.ShpCount,
+ ReceiveShpCount = SqlFunc.Subqueryable().Where(r => r.TaskId == a.Id && !string.IsNullOrEmpty(r.ReciveUserId)).Sum(r=>(r.EndNum-r.BeginNum)),
+ NoReceiveShpCount = SqlFunc.Subqueryable().Where(r => r.TaskId == a.Id && string.IsNullOrEmpty(r.ReciveUserId)).Sum(r => (r.EndNum - r.BeginNum)),
+ }).ToPageListAsync(page, limit, totalCount);
- return new Response>>
+ return new Response>>
{
- Result = new PageInfo>
+ Result = new PageInfo>
{
Items = tsakList,
Total = totalCount
diff --git a/OpenAuth.App/ServiceApp/DataAnalysisApp.cs b/OpenAuth.App/ServiceApp/DataAnalysisApp.cs
index ba8cc37..701414d 100644
--- a/OpenAuth.App/ServiceApp/DataAnalysisApp.cs
+++ b/OpenAuth.App/ServiceApp/DataAnalysisApp.cs
@@ -1,5 +1,10 @@
-using Microsoft.Extensions.Configuration;
+using Infrastructure;
+using Microsoft.Extensions.Configuration;
+using OpenAuth.App.BaseApp.Base;
using OpenAuth.App.Interface;
+using OpenAuth.App.ServiceApp.Response;
+using OpenAuth.Repository;
+using OpenAuth.Repository.Domain;
using SqlSugar;
using System;
using System.Collections.Generic;
@@ -12,16 +17,295 @@ namespace OpenAuth.App.ServiceApp
///
/// 统计分析
///
- public class DataAnalysisApp
+ public class DataAnalysisApp : SqlSugarBaseApp
{
private readonly IConfiguration _configuration;
private readonly ISqlSugarClient client;
- public DataAnalysisApp(IAuth auth, ISqlSugarClient sqlSugarClient, IConfiguration configuration)
+ private readonly IAuth _auth;
+ public DataAnalysisApp(ISugarUnitOfWork unitWork, ISimpleClient repository, IAuth auth, ISqlSugarClient sqlSugarClient, IConfiguration configuration) : base(unitWork, repository, auth)
{
_configuration = configuration;
this.client = sqlSugarClient;
+ _auth = auth;
+ }
+ ///
+ /// 时相统计
+ ///
+ ///
+ public async Task>>> GteTaskListForAdmin(int month, int week, DateTime beginTime, DateTime endTime, string taskName, int page, int limit)
+ {
+ using (var db = base.UnitWork.CreateContext())
+ {
+ RefAsync totalCount = 0;
+ var tsakList = await db.InsTask.AsQueryable()
+ .WhereIF(string.IsNullOrEmpty(taskName), r => r.TaskName.Contains(taskName))
+ .ToPageListAsync(page, limit, totalCount);
+
+ if (beginTime.Year == 0001)
+ {
+ beginTime = GetMonthStartAndEndDate(month).Start;
+ endTime = GetMonthStartAndEndDate(month).End;
+ }
+ var tifList = await db.InsTif.AsQueryable()
+ .WhereIF(beginTime.Year != 0001 || month != 0, r => r.CreateTime >= beginTime && r.CreateTime <= endTime)
+ .ToListAsync();
+ //总面积
+ var totalTifArea = tifList.Sum(r => r.AreaNum);
+ //个数
+ var totalTifCount = tifList.Count();
+ return new Response>>
+ {
+ Result = new PageInfo>
+ {
+ Items = tsakList,
+ Total = totalCount
+ }
+ };
+
+ }
+ }
+ ///
+ /// 每个县区的时相统计
+ ///
+ ///
+ public async Task>> GetShiXiangForArea(int month, int week, DateTime beginTime, DateTime endTime)
+ {
+ using (var db = base.UnitWork.CreateContext())
+ {
+ if (beginTime.Year == 0001)
+ {
+ beginTime = GetMonthStartAndEndDate(month).Start;
+ endTime = GetMonthStartAndEndDate(month).End;
+ }
+ var tifList = db.InsTif.AsQueryable()
+ .WhereIF(beginTime.Year != 0001 || month != 0, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
+ //总面积
+ var totalTifArea = tifList.Sum(r => r.AreaNum);
+ //个数
+ var totalTifCount = tifList.Count();
+
+ var endData = await tifList.GroupBy(r => r.AreaNum).Select(r => new
+ {
+ r.AreaName,
+ sumArea = SqlFunc.AggregateSum(r.AreaNum),
+ }).ToListAsync();
+ return new Response>
+ {
+ Result = endData,
+ };
+ }
+ }
+ ///
+ /// 每天时相统计
+ ///
+ ///
+ public async Task>> GetShiXiangForTime(int month, int week, DateTime beginTime, DateTime endTime)
+ {
+ using (var db = base.UnitWork.CreateContext())
+ {
+ if (beginTime.Year == 0001)
+ {
+ beginTime = GetMonthStartAndEndDate(month).Start;
+ endTime = GetMonthStartAndEndDate(month).End;
+ }
+ var tifList = db.InsTif.AsQueryable()
+ .WhereIF(beginTime.Year != 0001 || month != 0, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
+ //总面积
+ var totalTifArea = tifList.Sum(r => r.AreaNum);
+ //个数
+ var totalTifCount = tifList.Count();
+
+ var endData = await tifList.GroupBy(r => r.CreateTime).Select(r => new
+ {
+ r.CreateTime,
+ sumArea = SqlFunc.AggregateSum(r.AreaNum),
+ }).ToListAsync();
+ return new Response>
+ {
+ Result = endData,
+ };
+ }
+ }
+ static (DateTime Start, DateTime End) GetMonthStartAndEndDate(int month)
+ {
+ int year = DateTime.Now.Year; // 获取当前年份
+ DateTime startDate = new DateTime(year, month, 1, 0, 0, 0); // 当月起始日期
+ DateTime endDate = startDate.AddMonths(1).AddSeconds(-1); // 当月结束日期
+ return (startDate, endDate);
+ }
+ // 获取本月的起始时间和结束时间
+ public static (DateTime startOfMonth, DateTime endOfMonth) GetStartEndOfMonth()
+ {
+ DateTime now = DateTime.Now;
+ // 本月的第一天
+ DateTime startOfMonth = new DateTime(now.Year, now.Month, 1, 0, 0, 0);
+ // 本月的最后一天
+ DateTime endOfMonth = startOfMonth.AddMonths(1).AddSeconds(-1);
+
+ return (startOfMonth, endOfMonth);
+ }
+ public static (DateTime startOfWeek, DateTime endOfWeek) GetStartEndOfWeek()
+ {
+ DateTime now = DateTime.Now;
+ // 计算本周的第一天(假设一周从周一开始)
+ DateTime startOfWeek = now.AddDays(-((int)now.DayOfWeek - 1));
+ startOfWeek = startOfWeek.Date;
+ // 计算本周的最后一天(假设一周从周一开始,周日为最后一天)
+ DateTime endOfWeek = startOfWeek.AddDays(7).AddSeconds(-1);
+ return (startOfWeek, endOfWeek);
}
+ #region 统计数据
+ ///
+ /// 小组 人员 的任务数和图斑数
+ ///
+ ///
+ ///
+ ///
+ public async Task>> GetGroupOrUserTaskAndTuBan(int type, int dateType)
+ {
+ var user = _auth.GetCurrentUser().User;
+
+ DateTime beginTime, endTime;
+ if (dateType == 1)
+ {
+ beginTime = GetStartEndOfMonth().startOfMonth;
+ endTime = GetStartEndOfMonth().endOfMonth;
+ }
+ else if (dateType == 2)
+ {
+ beginTime = GetStartEndOfWeek().startOfWeek;
+ endTime = GetStartEndOfWeek().endOfWeek;
+ }
+ else
+ {
+ beginTime = DateTime.Today;
+ endTime = DateTime.Now;
+ }
+
+ using (var db = base.UnitWork.CreateContext())
+ {
+ // 获取当前用户相关的所有小组用户
+ var groupIds = await db.SysGroup.AsQueryable()
+ .Where(r => r.GroupLeaderId == user.Id.ToString())
+ .Select(r => r.Id)
+ .ToListAsync();
+
+ var groupUser = await db.SysGroupuser.AsQueryable()
+ .Where(r => groupIds.Contains(r.GroupId) || r.UserId == user.Id.ToString())
+ .Select(r => r.UserId)
+ .ToListAsync();
+
+ // 如果是小组统计
+ if (type == 1)
+ {
+ var result = await db.InsTaskgroup.AsQueryable()
+ .LeftJoin((a, b) => a.ReciveUserId == b.Id.ToString())
+ .WhereIF(beginTime.Year != 0001, a => a.CreateTime >= beginTime && a.CreateTime <= endTime)
+ .WhereIF(groupUser.Count > 0, a => groupUser.Contains(a.ReciveUserId))
+ .GroupBy((a, b) => b.Name)
+ .Select((a, b) => new UserOrGroupTaskResp
+ {
+ UserName = b.Name,
+ TaskCount = SqlFunc.AggregateCount(a.Id),
+ TuBanCount = SqlFunc.AggregateSum(a.EndNum - a.BeginNum),
+ }).ToListAsync();
+
+ return new Response>
+ {
+ Result = result,
+ };
+ }
+ // 如果是人员统计
+ else if (type == 2)
+ {
+ var result = await db.InsTaskgroup.AsQueryable()
+ .LeftJoin((a, b) => a.ReciveUserId == b.UserId)
+ .LeftJoin((a, b, c) => b.GroupId == c.Id)
+ .WhereIF(beginTime.Year != 0001, a => a.CreateTime >= beginTime && a.CreateTime <= endTime)
+ .WhereIF(groupUser.Count > 0, a => groupUser.Contains(a.ReciveUserId))
+ .GroupBy((a, b, c) => c.Name)
+ .Select((a, b, c) => new UserOrGroupTaskResp
+ {
+ UserName = c.Name,
+ TaskCount = SqlFunc.AggregateCount(a.Id),
+ TuBanCount = SqlFunc.AggregateSum(a.EndNum - a.BeginNum),
+ }).ToListAsync();
+
+ return new Response>
+ {
+ Result = result,
+ };
+ }
+ }
+
+ return new Response>(); // 默认返回空列表
+ }
+
+ public async Task>> GetAiShpDataExpenseAccountingTableOld(DateTime beginTime, DateTime endTime)
+ {
+ using (var db = base.UnitWork.CreateContext())
+ {
+ var aiShpList = db.InsAishp.AsQueryable()
+ .WhereIF(beginTime.Year != 0001, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
+ //总面积
+ var totalTifArea = aiShpList.Sum(r => r.AreaNum);
+ //个数
+ var totalTifCount = aiShpList.Count();
+
+ var endData = await aiShpList.GroupBy(r => r.ShpDate.Date).Select(r => new AiShpDataExpenseAccountingTableResp
+ {
+ ShapDate = r.ShpDate.Date.ToString("yyyyMMdd"),
+ AreaNum = SqlFunc.AggregateSum(r.AreaNum),
+ ShpCount = SqlFunc.AggregateSum(r.ShpCount),
+ }).ToListAsync();
+ return new Response>()
+ {
+ Result = endData
+ };
+ }
+ }
+ public async Task>> GetAiShpDataExpenseAccountingTable(DateTime beginTime, DateTime endTime)
+ {
+ using (var db = base.UnitWork.CreateContext())
+ {
+ List dateList = new List();
+ List dataList = new List();
+ if (beginTime > endTime)
+ {
+ throw new ArgumentException("开始时间需要小于结束时间");
+ }
+ // 从开始日期遍历到结束日期
+ for (DateTime date = beginTime.Date; date <= endTime.Date; date = date.AddDays(1))
+ {
+ dateList.Add(date);
+ }
+ var aiShpList = db.InsAishp.AsQueryable().WhereIF(beginTime.Year != 0001, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
+ var taskList = db.InsTask.AsQueryable().WhereIF(beginTime.Year != 0001, t => t.CreateTime >= beginTime && t.CreateTime <= endTime);
+ for (int i = 0; i < dateList.Count; i++)
+ {
+ AiShpDataExpenseAccountingTableResp aiShpDataExpenseAccountingTableResp = new AiShpDataExpenseAccountingTableResp();
+ var aiShpListDay = db.InsAishp.AsQueryable().Where(r => r.ShpDate >= dateList[i]);
+ aiShpDataExpenseAccountingTableResp.ShapDate = dateList[i].ToString("yyyyMMdd");
+ //提取个数
+ aiShpDataExpenseAccountingTableResp.AreaNum = await aiShpListDay.SumAsync(r => r.AreaNum);
+ aiShpDataExpenseAccountingTableResp.ShpCount = await aiShpListDay.SumAsync(r => r.ShpCount);
+ //下发数量
+ aiShpDataExpenseAccountingTableResp.issuedCount = await taskList.Where(t => aiShpListDay.Select(r => r.Id).ToList().Contains(t.ShpId)).CountAsync();
+
+ }
+
+ //总面积
+ var totalTifArea = aiShpList.Sum(r => r.AreaNum);
+ //个数
+ var totalTifCount = aiShpList.Count();
+ return new Response>()
+ {
+ Result = dataList
+ };
+ }
+ }
+ #endregion
}
}
diff --git a/OpenAuth.App/ServiceApp/Response/AiShpDataExpenseAccountingTableResp.cs b/OpenAuth.App/ServiceApp/Response/AiShpDataExpenseAccountingTableResp.cs
new file mode 100644
index 0000000..c3e260e
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/Response/AiShpDataExpenseAccountingTableResp.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.App.ServiceApp.Response
+{
+ public class AiShpDataExpenseAccountingTableResp
+ {
+ public string ShapDate { get; set; }
+ public decimal AreaNum { get; set; }
+ public int? ShpCount { get; set; }
+ public int issuedCount { get; set; }
+ }
+}
diff --git a/OpenAuth.App/ServiceApp/Response/InsTaskForAdminResp.cs b/OpenAuth.App/ServiceApp/Response/InsTaskForAdminResp.cs
new file mode 100644
index 0000000..fc5b814
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/Response/InsTaskForAdminResp.cs
@@ -0,0 +1,16 @@
+using OpenAuth.Repository.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.App.ServiceApp.Response
+{
+ public class InsTaskForAdminResp: InsTask
+ {
+ public int? ShpCount { get; set; }
+ public int ReceiveShpCount { get; set; }
+ public int NoReceiveShpCount { get; set; }
+ }
+}
diff --git a/OpenAuth.App/ServiceApp/Response/UserOrGroupTaskResp.cs b/OpenAuth.App/ServiceApp/Response/UserOrGroupTaskResp.cs
new file mode 100644
index 0000000..a4494c8
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/Response/UserOrGroupTaskResp.cs
@@ -0,0 +1,16 @@
+using OpenAuth.Repository.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.App.ServiceApp.Response
+{
+ public class UserOrGroupTaskResp
+ {
+ public string UserName { get; set; }
+ public int TaskCount { get; set; }
+ public int TuBanCount { get; set; }
+ }
+}
diff --git a/OpenAuth.App/ServiceApp/Response/UserTaskResp.cs b/OpenAuth.App/ServiceApp/Response/UserTaskResp.cs
new file mode 100644
index 0000000..b8ac53c
--- /dev/null
+++ b/OpenAuth.App/ServiceApp/Response/UserTaskResp.cs
@@ -0,0 +1,14 @@
+using OpenAuth.Repository.Domain;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenAuth.App.ServiceApp.Response
+{
+ public class UserTaskResp: InsTaskgroup
+ {
+ public string UserName { get; set; }
+ }
+}
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/AdminTaskManageController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/AdminTaskManageController.cs
index f56e244..c9e90e8 100644
--- a/OpenAuth.WebApi/Controllers/ServiceControllers/AdminTaskManageController.cs
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/AdminTaskManageController.cs
@@ -1,4 +1,5 @@
using Infrastructure;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using OpenAuth.App.ServiceApp;
using OpenAuth.App.ServiceApp.Request;
@@ -27,9 +28,10 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
///
///
[HttpGet]
- public async Task>>> GteTaskListForAdmin(string taskName, int page, int limit)
+ [AllowAnonymous]
+ public async Task>>> GteTaskListForAdmin(string taskName, int page, int limit)
{
- Response>> response = new Response>>();
+ Response>> response = new Response>>();
try
{
return await _app.GteTaskListForAdmin(taskName, page, limit);
diff --git a/OpenAuth.WebApi/Controllers/ServiceControllers/DataAnalysisController.cs b/OpenAuth.WebApi/Controllers/ServiceControllers/DataAnalysisController.cs
index 84fa4a3..b363202 100644
--- a/OpenAuth.WebApi/Controllers/ServiceControllers/DataAnalysisController.cs
+++ b/OpenAuth.WebApi/Controllers/ServiceControllers/DataAnalysisController.cs
@@ -1,4 +1,9 @@
-using Microsoft.AspNetCore.Mvc;
+using Infrastructure;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using OpenAuth.App.ServiceApp;
+using OpenAuth.App.ServiceApp.Response;
+using OpenAuth.WebApi.Model.CustomAttribute;
namespace OpenAuth.WebApi.Controllers.ServiceControllers
{
@@ -9,9 +14,53 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
[ApiController]
public class DataAnalysisController : ControllerBase
{
- public DataAnalysisController()
+ readonly DataAnalysisApp _app;
+ public DataAnalysisController(DataAnalysisApp app)
{
-
+ _app = app;
+ }
+ ///
+ /// 小组或人员统计
+ ///
+ /// 1-小组,2-人员
+ /// 1-本月,2-本周,3-本日
+ ///
+ [HttpGet]
+ public async Task>> GetGroupOrUserTaskAndTuBan(int type, int dateType)
+ {
+ Response> response = new Response>();
+ try
+ {
+ return await _app.GetGroupOrUserTaskAndTuBan(type, dateType);
+ }
+ catch (Exception ex)
+ {
+ response.Code = 500;
+ response.Message = ex.InnerException?.Message ?? ex.Message;
+ }
+ return response;
+ }
+ ///
+ /// 解译分析数据交付与费用记账表
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ [AllowAnonymous]
+ public async Task>> GetAiShpDataExpenseAccountingTable(DateTime beginTime, DateTime endTime)
+ {
+ Response> response = new Response>();
+ try
+ {
+ return await _app.GetAiShpDataExpenseAccountingTable(beginTime, endTime);
+ }
+ catch (Exception ex)
+ {
+ response.Code = 500;
+ response.Message = ex.InnerException?.Message ?? ex.Message;
+ }
+ return response;
}
}
}