Procházet zdrojové kódy

团组数据统计:
1、团组数量
2、团组人数
代码编写及开发环境测试

LEIYI před 7 měsíci
rodič
revize
f2e7cd3340

+ 111 - 32
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -3934,13 +3934,13 @@ WHERE
 
         /// <summary>
         ///  团组数据统计
-        ///  团组数量、人数
+        ///  团组数量
         /// </summary>
         /// <param name="_dto"></param>
         /// <returns></returns>
-        [HttpPost("StatisticsGroupInfo")]
+        [HttpPost("StatisticsGroupNum")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> StatisticsGroupInfo(YOYDto _dto)
+        public async Task<IActionResult> StatisticsGroupNum(YOYDto _dto)
         {
             if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
 
@@ -3957,48 +3957,127 @@ WHERE
                                                 Id = x.Id,
                                                 VisitDate = x.VisitDate,
                                                 Month = x.VisitDate.Month,
+                                                //MonthName = x.VisitDate.ToString("MMM", CultureInfo.GetCultureInfo("zh-CN")),
                                                 VisitPNumber = x.VisitPNumber
                                             })
                                             .MergeTable()
                                             .OrderBy(x => new { x.Month })
                                             .ToListAsync();
 
+            string groupNumStr = $"年度出访量:{groupInfos.Count}\r\n";
 
-            var groupInfos1 = groupInfos.GroupBy(x => x.Id);
+            var groupNumYearData = new
+            {
+                year = _dto.Year,
+                yearName = _dto.Year + "年",
+                num = groupInfos.Count,
+                linkGroupIds = groupInfos.Select(x => x.Id).ToList()
+            };
+            var groupNumData = groupInfos.GroupBy(x => x.Quarter)
+                                         .Select(x => new {
+                                             Quarter = x.Key,
+                                             QuarterName = x.FirstOrDefault()?.QuarterName ?? "-",
+                                             Num = x.Count(),
+                                             LinkGroupIds = x.Select(x1 => x1.Id).ToList()
+                                         })
+                                         .OrderBy(x => x.Quarter)
+                                         .ToList();
+            groupNumData.ForEach(x =>
+            {
+                groupNumStr += $"{x.QuarterName}出访量:{x.Num};";
+            });
 
-            var view = groupInfos1.Select(x =>
-                                            new {
-                                                groupTypeName = x.Key,
-                                                groupNum = x.Count(),
-                                                linkGroupId = x.Select(x1 => x1.Id).ToList()
-                                            }
-                                         )
-                                  .OrderByDescending(x => x.groupNum)
-                                  .ToList();
-            return Ok(JsonView(true, "操作成功!", view));
+            var groupNumMonthData = groupInfos.GroupBy(x => x.Month)
+                                         .Select(x => new {
+                                             Month = x.Key,
+                                             MonthName = x.FirstOrDefault()?.MonthName ?? "-",
+                                             Num = x.Count(),
+                                             LinkGroupIds = x.Select(x1 => x1.Id).ToList()
+                                         })
+                                         .OrderBy(x => x.Month)
+                                         .ToList();
+
+            return Ok(JsonView(true, "操作成功!", new
+            {
+                yearData = groupNumYearData,
+                quarterData = groupNumData,
+                monthData = groupNumMonthData,
+                remark = groupNumStr
+            }));
         }
 
-        public class StatisticsGroupInfoEntity
+        /// <summary>
+        ///  团组数据统计
+        ///  团组人数
+        /// </summary>
+        /// <param name="_dto"></param>
+        /// <returns></returns>
+        [HttpPost("StatisticsGroupPeopleNum")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> StatisticsGroupPeopleNum(YOYDto _dto)
         {
-            public int Id { get; set; }
-            public DateTime VisitDate { get; set; }
-            public int Month { get; set; }
-            public int Quarter
+            if (_dto.Year < 1) return Ok(JsonView(false, "操作失败"));
+
+            string beginDt = $"{_dto.Year}-01-01 00:00:00",
+                   endDt = $"{_dto.Year}-12-31 23:59:59";
+            DateTime _beginDt = Convert.ToDateTime(beginDt),
+                     _endDt = Convert.ToDateTime(endDt);
+
+            var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>()
+                                            .Where(x => x.IsDel == 0)
+                                            .Where(x => x.VisitDate >= _beginDt && x.VisitDate <= _endDt)
+                                            .Select(x => new StatisticsGroupInfoEntity
+                                            {
+                                                Id = x.Id,
+                                                VisitDate = x.VisitDate,
+                                                Month = x.VisitDate.Month,
+                                                VisitPNumber = x.VisitPNumber
+                                            })
+                                            .MergeTable()
+                                            .OrderBy(x => new { x.Month })
+                                            .ToListAsync();
+
+            string groupPeopleNumStr = $"年度出访人数:{groupInfos.Sum(x => x.VisitPNumber)}\r\n";
+
+            var groupPeopleNumYearData = new
             {
-                get
-                {
-                    int quarter = 0;
-                    if (Month < 1 || Month > 12) return quarter;
-                    if (Month >= 1 && Month <= 3) quarter = 1;
-                    else if (Month >= 4 && Month <= 6) quarter = 2;
-                    else if (Month >= 7 && Month <= 9) quarter = 3;
-                    else if (Month >= 10 && Month <= 12) quarter = 4;
-                    return quarter;
-                }
-            }
-            public int VisitPNumber { get; set; }
-        }
+                year = _dto.Year,
+                yearName = _dto.Year + "年",
+                num = groupInfos.Sum(x => x.VisitPNumber),
+                linkGroupIds = groupInfos.Select(x => x.Id).ToList()
+            };
+            var groupPeopleNumData = groupInfos.GroupBy(x => x.Quarter)
+                                               .Select(x => new {
+                                                   Quarter = x.Key,
+                                                   QuarterName = x.FirstOrDefault()?.QuarterName ?? "-",
+                                                   Num = x.Sum(x1 => x1.VisitPNumber),
+                                                   LinkGroupIds = x.Select(x1 => x1.Id).ToList()
+                                               })
+                                               .OrderBy(x => x.Quarter)
+                                               .ToList();
+            groupPeopleNumData.ForEach(x =>
+            {
+                groupPeopleNumStr += $"{x.QuarterName}出访人数:{x.Num};";
+            });
 
+            var groupPeopleNumMonthData = groupInfos.GroupBy(x => x.Month)
+                                                    .Select(x => new {
+                                                        Month = x.Key,
+                                                        MonthName = x.FirstOrDefault()?.MonthName ?? "-",
+                                                        Num = x.Sum(x1 => x1.VisitPNumber),
+                                                        LinkGroupIds = x.Select(x1 => x1.Id).ToList()
+                                                    })
+                                                    .OrderBy(x => x.Month)
+                                                    .ToList();
+
+            return Ok(JsonView(true, "操作成功!", new
+            {
+                yearData = groupPeopleNumYearData,
+                quarterData = groupPeopleNumData,
+                monthData = groupPeopleNumMonthData,
+                remark = groupPeopleNumStr
+            }));
+        }
         #endregion
     }
 }

+ 43 - 0
OASystem/OASystem.Domain/ViewModels/Financial/Fin_DailyFeePaymentView.cs

@@ -4,6 +4,7 @@ using OASystem.Domain.Entities.Financial;
 using OASystem.Domain.ViewModels.System;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -928,5 +929,47 @@ namespace OASystem.Domain.ViewModels.Financial
         public string Country { get; set; }    }
     #endregion
 
+
+    #region 团组相关
+
+    public class StatisticsGroupInfoEntity
+    {
+        public int Id { get; set; }
+        public DateTime VisitDate { get; set; }
+        public int Month { get; set; }
+
+        public string MonthName { get { return VisitDate.ToString("MMM", CultureInfo.GetCultureInfo("zh-CN")); } }
+
+        public int Quarter
+        {
+            get
+            {
+                int quarter = 0;
+                if (Month < 1 || Month > 12) return quarter;
+                if (Month >= 1 && Month <= 3) quarter = 1;
+                else if (Month >= 4 && Month <= 6) quarter = 2;
+                else if (Month >= 7 && Month <= 9) quarter = 3;
+                else if (Month >= 10 && Month <= 12) quarter = 4;
+                return quarter;
+            }
+        }
+
+        public string QuarterName
+        {
+            get
+            {
+                string quarterName = "-";
+                if (Month < 1 || Month > 12) return quarterName;
+                if (Month >= 1 && Month <= 3) quarterName = "第一季度";
+                else if (Month >= 4 && Month <= 6) quarterName = "第二季度";
+                else if (Month >= 7 && Month <= 9) quarterName = "第三季度";
+                else if (Month >= 10 && Month <= 12) quarterName = "第四季度";
+                return quarterName;
+            }
+        }
+        public int VisitPNumber { get; set; }
+    }
+
+    #endregion
     #endregion
 }