Browse Source

团成统计-op成本计算同比代码编写(年/月、费用类型(主费用、子费用)、城市)

LEIYI 7 months ago
parent
commit
9ed8edd7bd

+ 39 - 30
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -7,6 +7,7 @@ using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.Statistics;
 using OASystem.Domain.ViewModels.Statistics;
 using OASystem.Infrastructure.Repositories.Groups;
 using OASystem.Infrastructure.Repositories.Groups;
+using OfficeOpenXml.Drawing;
 using System.Data;
 using System.Data;
 using System.Linq;
 using System.Linq;
 using System.Security.Cryptography.Xml;
 using System.Security.Cryptography.Xml;
@@ -4250,36 +4251,44 @@ ORDER BY
             }
             }
             else if (_dto.Type == 2)
             else if (_dto.Type == 2)
             {
             {
-                var monthData = new List<dynamic>();
-
-                //var data1 = opInfos.GroupBy(x => x.Month)
-                //                   .Select(x => new
-                //                   {
-                //                       monthId = x.Key,
-                //                       month = Enum.IsDefined(typeof(MonthEnum), (int)x.Key) ? ((MonthEnum)(int)x.Key).GetEnumDescription() : "",
-                //                       monthData = x.GroupBy(x1 => x1.ParentFeeId)
-                //                                    .Select(x1 => new StatisticsOPYOY(
-                //                                            feeId: x1.Key,
-                //                                            feeName: x1.FirstOrDefault(x1 => x1.Year == thisYear)?.ParentFeeName ?? "",
-                //                                            currPeriodFee: x1.Where(x1 => x1.Year == thisYear).Sum(x1 => x1.Price),
-                //                                            samePeriodFee: x1.Where(x1 => x1.Year == lastYear).Sum(x1 => x1.Price),
-                //                                            currPeriodGroupTotal: x1.Where(x1 => x1.Year == thisYear).Select(x1 => x1.DiId).Distinct().Count(),
-                //                                            samePeriodGroupTotal: x1.Where(x1 => x1.Year == lastYear).Select(x1 => x1.DiId).Distinct().Count()
-                //                                            //cityData: x1.GroupBy(x2 => x2.City)
-                //                                            //            .Select(x2 => new StatisticsOPCityYOY(
-                //                                            //                    cityName: x2.Key,
-                //                                            //                    currPeriodGroupTotal: x2.Where(x2 => x2.Year == thisYear).Select(x2 => x2.DiId).Distinct().Count(),
-                //                                            //                    samePeriodGroupTotal: x2.Where(x2 => x2.Year == lastYear).Select(x2 => x2.DiId).Distinct().Count(),
-                //                                            //                    currPeriodFee: x2.Where(x2 => x2.Year == thisYear).Sum(x2 => x2.Price),
-                //                                            //                    samePeriodFee: x2.Where(x2 => x2.Year == lastYear).Sum(x2 => x2.Price)
-                //                                            //                    )
-                //                                            //            ).ToArray()
-                //                                            )
-                //                                    )
-                //                                    .OrderBy(x1 => x1.FeeId)
-                //                                    .ToList()
-                //                   }).ToList();
-                //return Ok(JsonView(true, "操作成功!", data1));
+                var monthData = opInfos.GroupBy(x => x.Month)
+                                       .Select(x => new StatisticsOPMonthYOY(
+                                               monthId: x.Key,
+                                               monthName: Enum.IsDefined(typeof(MonthEnum), (int)x.Key) ? ((MonthEnum)(int)x.Key).GetEnumDescription() : "",
+                                               feeDatas:x.GroupBy(x1 => x1.ParentFeeId)
+                                                         .Select(x1 => new StatisticsOPYOY(
+                                                                       feeId:x1.Key,
+                                                                       feeName: x1.FirstOrDefault()?.ParentFeeName ?? "",
+                                                                       currPeriodFee: x1.Where(x1 => x1.Year == thisYear).Sum(x1 => x1.Price),
+                                                                       samePeriodFee: x1.Where(x1 => x1.Year == lastYear).Sum(x1 => x1.Price),
+                                                                       currPeriodGroupTotal: x1.Where(x1 => x1.Year == thisYear).Select(x1 => x1.DiId).Distinct().Count(),
+                                                                       samePeriodGroupTotal: x1.Where(x1 => x1.Year == lastYear).Select(x1 => x1.DiId).Distinct().Count(),
+                                                                       subFeeData:x1.GroupBy(x2 => x2.FeeSubType)
+                                                                                    .Select(x2 => new StatisticsOPSubFeeYOY(
+                                                                                                  feeId: x2.Key,
+                                                                                                  feeName: x2.FirstOrDefault()?.FeeSubTypeName ?? "",
+                                                                                                  currPeriodFee: x2.Where(x2 => x2.Year == thisYear).Sum(x2 => x2.Price),
+                                                                                                  samePeriodFee: x2.Where(x2 => x2.Year == lastYear).Sum(x2 => x2.Price),
+                                                                                                  currPeriodGroupTotal: x2.Where(x2 => x2.Year == thisYear).Select(x2 => x2.DiId).Distinct().Count(),
+                                                                                                  samePeriodGroupTotal: x2.Where(x2 => x2.Year == lastYear).Select(x2 => x2.DiId).Distinct().Count(),
+                                                                                                  cityData: x2.GroupBy(x3 => x3.City)
+                                                                                                              .Select(x3 => new StatisticsOPCityYOY(
+                                                                                                                            cityName: x3.Key,
+                                                                                                                            currPeriodFee: x3.Where(x3 => x3.Year == thisYear).Sum(x3 => x3.Price),
+                                                                                                                            samePeriodFee: x3.Where(x3 => x3.Year == lastYear).Sum(x3 => x3.Price),
+                                                                                                                            currPeriodGroupTotal: x3.Where(x3 => x3.Year == thisYear).Select(x3 => x3.DiId).Distinct().Count(),
+                                                                                                                            samePeriodGroupTotal: x3.Where(x3 => x3.Year == lastYear).Select(x3 => x3.DiId).Distinct().Count()
+                                                                                                                  ))
+                                                                                                              .ToArray()
+                                                                                        ))
+                                                                                    .ToArray()
+
+                                                             ))
+                                                         .ToArray()
+                                               ))
+                                       .OrderBy(x => x.MonthId)
+                                       .ToList();
+                return Ok(JsonView(true, "操作成功!", monthData));
             }
             }
             return Ok(JsonView(false, "操作失败!"));
             return Ok(JsonView(false, "操作失败!"));
         }
         }

+ 22 - 1
OASystem/OASystem.Domain/ViewModels/Financial/Fin_DailyFeePaymentView.cs

@@ -1243,6 +1243,8 @@ namespace OASystem.Domain.ViewModels.Financial
     public class StatisticsOPSubFeeYOY : StatisticsOPYOY
     public class StatisticsOPSubFeeYOY : StatisticsOPYOY
     {
     {
         public StatisticsOPCityYOY[] CityData { get; set; }
         public StatisticsOPCityYOY[] CityData { get; set; }
+
+        public StatisticsOPSubFeeYOY() { }
         /// <summary>
         /// <summary>
         /// 构造函数
         /// 构造函数
         /// </summary>
         /// </summary>
@@ -1306,11 +1308,30 @@ namespace OASystem.Domain.ViewModels.Financial
                 _yoy = ((currPeriodFee - samePeriodFee) / samePeriodFee).ToString("0.##");
                 _yoy = ((currPeriodFee - samePeriodFee) / samePeriodFee).ToString("0.##");
             }
             }
 
 
-            this.Yoy = decimal.Parse(_yoy);
+            this.Yoy = decimal.TryParse(_yoy, out decimal yoy1) ? yoy1 : 0.00M;
         }
         }
 
 
     }
     }
 
 
+
+    public class StatisticsOPMonthYOY
+    {
+        public int MonthId { get; set; }
+
+        public string MonthName { get; set; }
+
+        public StatisticsOPYOY[] FeeDatas { get; set; }
+
+        public StatisticsOPMonthYOY() { }
+
+        public StatisticsOPMonthYOY(int monthId, string monthName, StatisticsOPYOY[] feeDatas)
+        {
+            MonthId = monthId;
+            MonthName = monthName;
+            FeeDatas = feeDatas;
+        }
+    }
+
     #endregion
     #endregion
     #endregion
     #endregion
 }
 }