Browse Source

优化数据查询和模型结构

在 `StatisticsController.cs` 中,注释掉了原有的 `dailyItems` 查询代码,保留其结构以备后用,并修改了 `PriceInfos` 的获取方式。
在 `CorporateProfitViews.cs` 中,更新了 `DailyInfo` 类的 `PriceInfos` 属性类型,反映与 `DailyPriceInfo` 的一对多关系。
在 `EnterExitCostRepository.cs` 中,增强了对 `enterExitCost` 查询条件的准确性,确保只处理未删除的记录。
LEIYI 3 months ago
parent
commit
9d81ccc643

+ 35 - 18
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -7932,24 +7932,41 @@ GROUP BY
 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 = SqlFunc.Subqueryable<Fin_DailyFeePaymentContent>().Where(dfpc => dfp.IsDel == 0 && dfp.Id == dfpc.DFPId).ToList()
-                })
-                .ToListAsync();
+            //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
+
+
             view.GroupItems = groupItems;
             //view.DailyItems = dailyItems;
             return view;

+ 5 - 1
OASystem/OASystem.Domain/ViewModels/Statistics/CorporateProfitViews.cs

@@ -20,6 +20,7 @@ namespace OASystem.Domain.ViewModels.Statistics
 
     public class DailyInfo
     {
+        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
         public int Id { get; set; }
         public int PriceParentTypeId { get; set; }
         public string PriceParentTypeName { get; set; }
@@ -28,11 +29,14 @@ namespace OASystem.Domain.ViewModels.Statistics
         public string CompanyName { get; set; }
         public string Instructions { get; set; }
         public decimal CNYTotal { get; set; }
-        public List<Fin_DailyFeePaymentContent> PriceInfos { 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; }

+ 1 - 1
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostRepository.cs

@@ -333,7 +333,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     {
                         //操作权限验证 只有创建人可修改
                         var info = await _sqlSugar.Queryable<Grp_EnterExitCost,Sys_Users>((eec,u) => new JoinQueryInfos(JoinType.Left,eec.CreateUserId == u.Id))
-                            .Where(it => it.IsDel == 0 && it.Id == enterExitCost.Id)
+                            .Where((eec, u) => eec.IsDel == 0 && eec.Id == enterExitCost.Id)
                             .Select((eec, u) => new { eec.CreateUserId,u.CnName })
                             .FirstAsync();
                         if (info.CreateUserId != dto.UserId)