Browse Source

优化查询性能并更新视图模型

更新 SQL 查询语句,移除旧表连接,新增字段和调整条件。修改数据过滤和分组逻辑,新增 priceTypeIds 列表并按公司分组汇总。更新 CorporateProfitViews.cs 中的 DailyInfo 类,移除 DailyPriceInfo 类。绑定 dailyItems 到视图模型,更新 dailyLabel 生成逻辑。清理旧注释和不再使用的代码段。
LEIYI 4 days ago
parent
commit
bc6c9ac551

+ 55 - 48
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -7917,58 +7917,48 @@ WHERE
             var groupItems = await _sqlSugar.SqlQueryable<CorporateProfitInfo>(sql).ToArrayAsync();
 
             var dailySql = string.Format(@"SELECT
+  dfp.Id,
+  dfp.CompanyId,
   sc.CompanyName,
-  SUM(fdfp.SumPrice) 'CNYTotal'
-FROM
-  OA2023DB.dbo.Fin_DailyFeePayment fdfp
-  LEFT JOIN Sys_Company sc on fdfp.CompanyId = sc.Id
+  sd.DepName AS 'Branch',
+  su.CnName AS 'Applicant',
+  dfp.PriceTypeId,
+  sst.Id AS 'PriceParentTypeId',
+  sst.Name AS 'PriceParentTypeName',
+  ss.Id AS 'PriceTypeId',
+  ss.Name AS 'PriceypeName',
+  dfp.Instructions,
+  dfp.SumPrice AS 'CNYTotal',
+  dfpc.PriceName,
+  dfpc.Quantity,
+  dfpc.Price,
+  dfpc.ItemTotal,
+  dfpc.Remark,
+  dfp.CreateTime
+From
+  Fin_DailyFeePayment dfp
+  INNER JOIN Fin_DailyFeePaymentContent dfpc on dfp.Id = dfpc.DFPId
+  LEFT JOIN Sys_Company sc on dfp.CompanyId = sc.Id
+  LEFT JOIN Sys_Users su on dfp.CreateUserId = su.Id
+  LEFT JOIN Sys_Department sd on su.DepId = sd.Id
+  LEFT JOIN Sys_SetData ss on dfp.PriceTypeId = ss.Id
+  LEFT JOIN Sys_SetDataType sst on ss.STid = sst.Id
 WHERE
-  fdfp.IsDel = 0
-  AND fdfp.IsPay = 1
-  AND fdfp.PriceTypeId Not IN (325, 306, 686, 687, 688, 689)
-  AND fdfp.CreateTime BETWEEN '{0}' AND '{1}'
-GROUP BY
-  sc.CompanyName
+  dfp.IsDel = 0
+  AND dfpc.IsDel = 0
+  AND dfp.CreateTime BETWEEN '{0}' AND '{1}'
+  AND dfp.IsPay = 1
 ORDER BY
-  CNYTotal ASC", beginDt, endDt);
-
-            //var dailyItems = await _sqlSugar.Queryable<Fin_DailyFeePayment, Sys_SetData, Sys_SetDataType, Sys_Company>((dfp, sd, sdt, c) =>
-            //    new JoinQueryInfos(
-            //        JoinType.Left, dfp.PriceTypeId == sd.Id,
-            //        JoinType.Left, sd.STid == sdt.Id,
-            //        JoinType.Left, dfp.CompanyId == c.Id
-            //     ))
-                
-            //    .Select((dfp, sd, sdt, c) => new DailyInfo()
-            //     {
-            //         Id = dfp.Id,
-            //         PriceParentTypeId = sdt.Id,
-            //         PriceParentTypeName = sdt.Name,
-            //         PriceTypeId = sd.Id,
-            //         PriceTypeName = sd.Name,
-            //         CompanyName = c.CompanyName,
-            //         Instructions = dfp.Instructions,
-            //         CNYTotal = dfp.SumPrice,
-            //         PriceInfos = SqlSugar.SqlFunc.Subqueryable<Fin_DailyFeePaymentContent>()
-            //                 .Where(x => x.IsDel == 0 && dfp.Id == x.DFPId)
-            //                 .Select(x => new DailyPriceInfo()
-            //                 {
-            //                     Id = x.Id,
-            //                     DFPId = x.DFPId,
-            //                     PriceName = x.PriceName,
-            //                     Price = x.Price,
-            //                     Quantity = x.Quantity,
-            //                     ItemTotal = x.ItemTotal,
-            //                     Remark = x.Remark
-            //                 }).ToList()
-            //     })
-            //    .ToListAsync();
-
-           // var
+  dfp.CompanyId,
+  su.DepId,
+  dfp.CreateUserId,
+  dfp.PriceTypeId,
+  dfp.CreateTime ASC", beginDt, endDt);
 
+            var dailyItems = await _sqlSugar.SqlQueryable<DailyInfo>(dailySql).ToArrayAsync();
 
             view.GroupItems = groupItems;
-            //view.DailyItems = dailyItems;
+            view.DailyItems = dailyItems;
             return view;
         }
 
@@ -8012,6 +8002,23 @@ ORDER BY
             var groupItems = data.GroupItems;
             var dailyItems = data.DailyItems;
 
+            var priceTypeIds = new List<int>() {
+                686, //686 信用卡还款
+                687, //687 张总私人费用
+                688, //688 代报销社保生育补贴
+                688, //688 代报销社保生育补贴
+                306, //306 人事行政费用-张总家用类
+                325, //325 会展部备用金
+                689, //689 团组签证保险
+            };
+
+            var companyDailyItems = dailyItems
+                .Where(x => !priceTypeIds.Contains(x.PriceTypeId))
+                .GroupBy(x => x.CompanyName)
+                .Select(g => new { CompanyName = g.Key, CNYTotal = g.Sum(x => x.CNYTotal) })
+                .OrderBy(x => x.CNYTotal)
+                .ToArray();
+
             //业务类型
             var groupTypeIds = new List<int>() {
                     38,   //  政府团
@@ -8040,9 +8047,9 @@ ORDER BY
             decimal totalProfit = groupProfitTotal + notGroupProfitTotal;
 
             var dailyLabel = $"*不含日付费用类型(信用卡还款、张总私人费用、代报销社保生育补贴、人事行政费用 - 张总家用类、会展部备用金、团组签证保险)\r\n";
-            if (dailyItems.Any())
+            if (companyDailyItems.Any())
             {
-                foreach (var dailyFee in dailyItems)
+                foreach (var dailyFee in companyDailyItems)
                 {
                     dailyLabel += $"[{dailyFee.CompanyName}]日常产生费用:{dailyFee.CNYTotal.ToString("#0.00")} CNY \r\n";
                 }

+ 11 - 12
OASystem/OASystem.Domain/ViewModels/Statistics/CorporateProfitViews.cs

@@ -20,30 +20,29 @@ namespace OASystem.Domain.ViewModels.Statistics
 
     public class DailyInfo
     {
-        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
         public int Id { get; set; }
+        public int CompanyId { get; set; }
+        public string CompanyName { get; set; }
+        /// <summary>
+        /// 部门
+        /// </summary>
+        public string Branch { get; set; }
+        /// <summary>
+        /// 申请人
+        /// </summary>
+        public string Applicant { get; set; }
         public int PriceParentTypeId { get; set; }
         public string PriceParentTypeName { get; set; }
         public int PriceTypeId { get; set; }
         public string PriceTypeName { get; set; }
-        public string CompanyName { get; set; }
         public string Instructions { get; set; }
         public decimal CNYTotal { get; set; }
-        [Navigate(NavigateType.OneToMany, nameof(DailyPriceInfo.DFPId))]
-        public List<DailyPriceInfo> PriceInfos { get; set; }
-    }
-
-    public class DailyPriceInfo
-    {
-
-        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
-        public int Id { get; set; }
-        public int DFPId { get; set; }
         public string PriceName { get; set; }
         public decimal Quantity { get; set; }
         public decimal Price { get; set; }
         public decimal ItemTotal { get; set; }
         public string Remark { get; set; }
+        public DateTime CreateTime { get; set; }
     }
 
     public class CorporateProfitInfo