Quellcode durchsuchen

增强 CorporateProfitItem 方法并更新 DTO 类

在 `StatisticsController.cs` 文件中:
- 将 `Array.ConvertAll` 和 `Array.Empty` 替换为 `System.Array.ConvertAll` 和 `System.Array.Empty`。
- 增加了新的私有方法 `CorporateProfitItems`,用于生成和下载 Excel 文件。
- 在 `CorporateProfitItem` 方法中调用了新的 `CorporateProfitItems` 方法。
- 在 `CorporateProfitItems` 方法中使用 `WorkbookDesigner` 类生成 Excel 文件。
- 在 `CorporateProfitItem` 方法中添加了对参数的验证逻辑。

在 `CorporateProfitDtos.cs` 文件中:
- `CorporateProfitItemDto` 类的基类从 `CorporateProfitExcelDownloadDto` 改为 `CorporateProfitDtos`,并新增了 `BeginDt` 和 `EndDt` 属性。
- `CorporateProfitItemDtoFoalidator` 类中包含的验证器从 `CorporateProfitExcelDownloadDtoFoalidator` 改为 `CorporateProfitDtosDtoBaseFoalidator`,并新增了对 `BeginDt` 和 `EndDt` 属性的日期格式验证规则。
- `CorporateProfitExcelDownloadDto` 类的基类从 `CorporateProfitDtos` 改为 `CorporateProfitItemDto`。
- `CorporateProfitExcelDownloadDtoFoalidator` 类中包含的验证器从 `CorporateProfitDtosDtoBaseFoalidator` 改为 `CorporateProfitItemDtoFoalidator`,并移除了对 `BeginDt` 和 `EndDt` 属性的日期格式验证规则。

在 `CorporateProfitViews.cs` 文件中:
- 新增了 `CorporateProfitDailyView` 类和 `CorporateProfitDailyCommentView` 类,分别包含了一些新的属性。
LEIYI vor 1 Jahr
Ursprung
Commit
5174f52e08

+ 508 - 385
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -1,5 +1,6 @@
 using Aspose.Cells;
 using Aspose.Words.Tables;
+using crypto;
 using EyeSoft.Collections.Generic;
 using FluentValidation;
 using Google.Protobuf.WellKnownTypes;
@@ -9,6 +10,7 @@ using Microsoft.Extensions.Hosting;
 using MySqlX.XDevAPI.Relational;
 using NetUV.Core.Handles;
 using NodaTime;
+using NPOI.HPSF;
 using NPOI.POIFS.Properties;
 using NPOI.SS.Formula.Functions;
 using NPOI.SS.Formula.PTG;
@@ -817,7 +819,7 @@ ORDER BY
                             }
                             if (clientIds.Length > 0)
                             {
-                                int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
+                                int[] output = System.Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
 
                                 if (output.Contains(-1))
                                 {
@@ -2948,7 +2950,7 @@ ORDER BY
                             }
                             if (clientIds.Length > 0)
                             {
-                                int[] output = Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
+                                int[] output = System.Array.ConvertAll<string, int>(clientIds, delegate (string s) { return int.Parse(s); });
 
                                 if (output.Contains(-1))
                                 {
@@ -7050,7 +7052,7 @@ ORDER BY
                         monthData.Add(new StatisticsOPMonthYOY(
                                           monthId: item,
                                           monthName: System.Enum.IsDefined(typeof(MonthEnum), (int)item) ? ((MonthEnum)(int)item).GetEnumDescription() : "",
-                                          feeDatas: Array.Empty<StatisticsOPYOY>()
+                                          feeDatas: System.Array.Empty<StatisticsOPYOY>()
                                           ));
                     }
                     monthData = monthData.OrderBy(x => x.MonthId).ToList();
@@ -7073,7 +7075,7 @@ ORDER BY
                                              samePeriodFee: 0.00M,
                                              currPeriodGroupTotal: 0,
                                              samePeriodGroupTotal: 0,
-                                             subFeeData: Array.Empty<StatisticsOPSubFeeYOY>()
+                                             subFeeData: System.Array.Empty<StatisticsOPSubFeeYOY>()
                                 ));
                         }
                         feeDatas = feeDatas.OrderBy(x => x.FeeId).ToList();
@@ -7962,43 +7964,20 @@ ORDER BY
             return view;
         }
 
+
         /// <summary>
-        /// 企业利润 
-        /// Item
+        /// 团组利润item详情
         /// </summary>
-        /// <param name="dto"></param>
+        /// <param name="type">
+        /// 1:详情
+        /// 2:excel 生成
+        /// </param>
+        /// <param name="begin"></param>
+        /// <param name="end"></param>
         /// <returns></returns>
-        [HttpPost("CorporateProfitItem")]
-        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> CorporateProfitItem(CorporateProfitItemDto dto)
+        private async Task<CorporateProfitItemView> CorporateProfitItems(int type, string begin, string end)
         {
-
-            int portType = dto.PortType,
-                userId = dto.UserId,
-                pageId = dto.PageId;
-            #region  参数验证
-
-            //var validationRules = new CorporateProfitItemDtoFoalidator();
-            //var validResult = await validationRules.ValidateAsync(dto);
-            //if (!validResult.IsValid)
-            //{
-            //    var errors = new StringBuilder();
-            //    foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
-            //    return Ok(JsonView(false, errors.ToString()));
-            //}
-
-            //#region 页面操作权限验证
-            //var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(userId, pageId);
-
-            //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
-            //#endregion
-
-            #endregion
-
-            string beginDt = $"{dto.BeginDt} 00:00:00",
-                   endDt = $"{dto.EndDt} 23:59:59";
-            
-            var data = await CorporateProfitInfos(beginDt, endDt);
+            var data = await CorporateProfitInfos(begin, end);
             var groupItems = data.GroupItems;
             var dailyItems = data.DailyItems;
 
@@ -8057,12 +8036,77 @@ ORDER BY
 
             string label = string.Format(@$"团组收款合计:{groupCollectionTotal.ToString("#0.00")} CNY\t团组产生费用合计:{groupCostTotal.ToString("#0.00")} CNY\t团组利润合计:{groupProfitTotal.ToString("#0.00")} CNY\r\n非团组收款合计:{notGroupCollectionTotal.ToString("#0.00")} CNY\t非团组产生费用合计:{notGroupCostTotal.ToString("#0.00")} CNY\t非团组利润合计:{notGroupProfitTotal.ToString("#0.00")} CNY\r\n{dailyLabel}其中会务:{inforCount}个\r\n服务人数:{serviceCount}人\r\n总利润:{totalProfit.ToString("#0.00")} CNY\r\n");
 
-            var view = new CorporateProfitItemView() { 
-                Items = _mapper.Map<CorporateProfitItem[]>(groupItems),
+            var datas = _mapper.Map<CorporateProfitItem[]>(groupItems);
+            if (type == 2) //excel 下载
+            {
+                var designer = new WorkbookDesigner();
+                var tempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/团组利润模板.xls";
+                designer.Workbook = new Workbook(tempPath);
+                designer.SetDataSource("ReceivablesTemp", datas);
+
+                designer.SetDataSource("SumAccounts", groupCollectionTotal.ToString("#0.00"));
+                designer.SetDataSource("SumReceived", groupCostTotal.ToString("#0.00"));
+                designer.SetDataSource("SumBalance", groupProfitTotal.ToString("#0.00"));
+                designer.SetDataSource("notSumAccounts", notGroupCollectionTotal.ToString("#0.00"));
+                designer.SetDataSource("notSumReceived", notGroupCostTotal.ToString("#0.00"));
+                designer.SetDataSource("SumOfNotTeamBalance", notGroupProfitTotal.ToString("#0.00"));
+                designer.SetDataSource("DailyLabel", dailyLabel);
+                designer.SetDataSource("MeetingNumber", inforCount + "个");
+                designer.SetDataSource("ServiceNumber", serviceCount + "人");
+                designer.SetDataSource("SumAllBalance", totalProfit.ToString("#0.00"));
+
+                //根据数据源处理生成报表内容
+                designer.Process();
+                string fileName = $"团组利润({Convert.ToDateTime(begin).ToString("yyyy年MM月dd日")}~{Convert.ToDateTime(end).ToString("yyyy年MM月dd日")}){Guid.NewGuid().ToString()}.xls";
+                designer.Workbook.Save($"{AppSettingsHelper.Get("ExcelBasePath")}CorporateProfit/{fileName}");
+                string url = $"{AppSettingsHelper.Get("ExcelBaseUrl")}Office/Excel/CorporateProfit/{fileName}";
+                label = url;
+            }
+
+            return new CorporateProfitItemView()
+            {
+                Items = datas,
                 Label = label
             };
+        }
+
+        /// <summary>
+        /// 企业利润 
+        /// Item
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost("CorporateProfitItem")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> CorporateProfitItem(CorporateProfitItemDto dto)
+        {
+
+            int portType = dto.PortType,
+                userId = dto.UserId,
+                pageId = dto.PageId;
+            #region  参数验证
 
-            return Ok(JsonView(true,"操作成功!", view));
+            //var validationRules = new CorporateProfitItemDtoFoalidator();
+            //var validResult = await validationRules.ValidateAsync(dto);
+            //if (!validResult.IsValid)
+            //{
+            //    var errors = new StringBuilder();
+            //    foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
+            //    return Ok(JsonView(false, errors.ToString()));
+            //}
+
+            //#region 页面操作权限验证
+            //var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(userId, pageId);
+
+            //if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
+            //#endregion
+
+            #endregion
+
+            string beginDt = $"{dto.BeginDt} 00:00:00",
+                   endDt = $"{dto.EndDt} 23:59:59";
+
+            return Ok(JsonView(true,"操作成功!", await CorporateProfitItems(1, beginDt, endDt)));
         }
 
         /// <summary>
@@ -8105,429 +8149,508 @@ ORDER BY
             string yearBeginDt = $"{beginDate.Year}-01-01 00:00:00",
                    yearEndDt = $"{beginDate.Year}-12-31 23:59:59";
 
+            //业务类型
+            var priceTypeIds = new List<int>() {
+                686, //686 信用卡还款
+                687, //687 张总私人费用
+                688, //688 代报销社保生育补贴
+                688, //688 代报销社保生育补贴
+                306, //306 人事行政费用-张总家用类
+                325, //325 会展部备用金
+                689, //689 团组签证保险
+            };
+
             var data = await CorporateProfitInfos(beginDt, endDt);
             var groupItems = data.GroupItems;
             var dailyItems = data.DailyItems;
+            //筛选不统计的费用类型
+            //if (dailyItems.Any()) dailyItems = dailyItems.Where(x => !priceTypeIds.Contains(x.PriceTypeId)).ToArray();
 
             var yearData = await CorporateProfitInfos(yearBeginDt, yearEndDt);
-            var yearGroupItems = data.GroupItems;
-            var yearDailyItems = data.DailyItems;
-
-            //48    人员费用
-            //49    办公费用
-            //90    各部门基础固定费用明细
-            //50    销售费用
-            //51    其他费用
-            var feeTypeDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && new int[] { 48, 49, 90, 50, 51 }.Contains(x.Id)).ToListAsync();
+            var yearGroupItems = yearData.GroupItems;
+            var yearDailyItems = yearData.DailyItems;
+            //筛选不统计的费用类型
+            //if (yearDailyItems.Any()) yearDailyItems = yearDailyItems.Where(x => !priceTypeIds.Contains(x.PriceTypeId)).ToArray();
+
+            #region 公共参数
+            //团组收款、成本、利润 合计
+            decimal monthGroupCollectionTotal = groupItems.Sum(x => x.CollectionTotal),
+                    monthGroupCostTotal = groupItems.Sum(x => x.CostTotal),
+                    yearGroupCollectionTotal = yearGroupItems.Sum(x => x.CollectionTotal),
+                    yearGroupCostTotal = yearGroupItems.Sum(x => x.CostTotal);
+            //日付申请 48 人员费用、 49 办公费用、50 销售费用、51 其他费用、55	大运会、90	各部门基础固定费用明细
+            decimal monthStaffCosts = dailyItems.Where(x => x.PriceParentTypeId == 48).Sum(x => x.CNYTotal),
+                    monthOfficeExpenses = dailyItems.Where(x => x.PriceParentTypeId == 49).Sum(x => x.CNYTotal),
+                    monthCostSales = dailyItems.Where(x => x.PriceParentTypeId == 50).Sum(x => x.CNYTotal),
+                    monthOtherFees = dailyItems.Where(x => x.PriceParentTypeId == 51).Sum(x => x.CNYTotal),
+                    monthDyhFees = dailyItems.Where(x => x.PriceParentTypeId == 55).Sum(x => x.CNYTotal),
+                    monthDepartFixedExpenses = dailyItems.Where(x => x.PriceParentTypeId == 90).Sum(x => x.CNYTotal),
+                    yearStaffCosts = yearDailyItems.Where(x => x.PriceParentTypeId == 48).Sum(x => x.CNYTotal),
+                    yearOfficeExpenses = yearDailyItems.Where(x => x.PriceParentTypeId == 49).Sum(x => x.CNYTotal),
+                    yearCostSales = yearDailyItems.Where(x => x.PriceParentTypeId == 50).Sum(x => x.CNYTotal),
+                    yearOtherFees = yearDailyItems.Where(x => x.PriceParentTypeId == 51).Sum(x => x.CNYTotal),
+                    yearDyhFees = yearDailyItems.Where(x => x.PriceParentTypeId == 55).Sum(x => x.CNYTotal),
+                    yearDepartFixedExpenses = yearDailyItems.Where(x => x.PriceParentTypeId == 90).Sum(x => x.CNYTotal);
+            #endregion
 
-            if (excelType == 1)
+            //月度报表、季度报表、年度报表
+            if (excelType == 1 || excelType == 2 || excelType == 3)
             {
-                //团组收款、成本、利润 合计
-                decimal monthCollectionTotal = groupItems.Sum(x => x.CollectionTotal),
-                        monthCostTotal = groupItems.Sum(x => x.CostTotal),
-                        yearCollectionTotal = yearGroupItems.Sum(x => x.CollectionTotal),
-                        yearCostTotal = yearGroupItems.Sum(x => x.CostTotal);
+                var designer = new WorkbookDesigner();
+                string fileName = $"({beginDate.ToString("yyyy年MM月dd日")}~{endDate.ToString("yyyy年MM月dd日")}){Guid.NewGuid().ToString()}.xls",
+                       fileNamePrefix = string.Empty,
+                       tempPath = string.Empty,
+                       workSheetName = string.Empty;
+                if (excelType == 1)
+                {
+                    tempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/月度报表模板.xls";
+                    workSheetName = "月度报表";
+                    fileNamePrefix = "月度报表";
+                }
+                else if (excelType == 2)
+                {
+                    tempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/季度报表模板.xls";
+                    workSheetName = "季度报表";
+                    fileNamePrefix = "季度报表";
+                }
+                else if (excelType == 3)
+                {
+                    tempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/年度报表模板.xls";
+                    workSheetName = "年度报表";
+                    fileNamePrefix = "年度报表";
+                }
+                else return Ok(JsonView(false));
 
+                designer.Workbook = new Workbook(tempPath);
+                designer.Workbook.Worksheets[0].Name = workSheetName;
 
-            }
-            else if (excelType == 2)
-            {
-            }
-            else if (excelType == 3)
-            {
-            }
-            else if (excelType == 4)
-            {
-            }
-            else if (excelType == 5)
-            {
-            }
+                #region 填充值
+                string time = $"所属期间: {beginDate.ToString("yyyy 年 MM 月 dd 日")} 至 {endDate.ToString("yyyy 年 MM 月 dd 日")}";
+                designer.SetDataSource("Time", time);
 
+                designer.SetDataSource("MonthReceivedPrice", monthGroupCollectionTotal.ToString("#0.00"));//本月已收
+                designer.SetDataSource("YearReceivedPrice", yearGroupCollectionTotal.ToString("#0.00"));  //本年已收
 
+                designer.SetDataSource("MonthSumReceives", monthGroupCollectionTotal.ToString("#0.00"));//本月团组收款
+                designer.SetDataSource("MonthTeamCost", monthGroupCostTotal.ToString("#0.00"));         //本月团组成本
 
-            return Ok(JsonView(false));
-        }
+                designer.SetDataSource("YearSumReceives", yearGroupCollectionTotal.ToString("#0.00"));//本年团组收款
+                designer.SetDataSource("YearTeamCost", yearGroupCostTotal.ToString("#0.00"));         //本年团组成本
 
-        /// <summary>
-        /// 企业利润 Excel导出
-        /// </summary>
-        /// <param name="dto"></param>
-        /// <returns></returns>
-        [HttpPost("CorporateProfitExcelDownload1")]
-        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> CorporateProfitExcelDownload1(CorporateProfitExcelDownloadDto dto)
-        {
+                designer.SetDataSource("MonthStaffCosts", monthStaffCosts.ToString("#0.00"));//本月人员费用
+                designer.SetDataSource("YearStaffCosts", yearStaffCosts.ToString("#0.00"));  //本年人员费用
 
-            int portType = dto.PortType,
-                userId = dto.UserId,
-                pageId = dto.PageId;
-            #region  参数验证
+                designer.SetDataSource("MonthOfficeExpenses", monthOfficeExpenses.ToString("#0.00"));//本月办公费用
+                designer.SetDataSource("YearOfficeExpenses", yearOfficeExpenses.ToString("#0.00"));  //本年办公费用
 
-            var validationRules = new CorporateProfitExcelDownloadDtoFoalidator();
-            var validResult = await validationRules.ValidateAsync(dto);
-            if (!validResult.IsValid)
-            {
-                var errors = new StringBuilder();
-                foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
-                return Ok(JsonView(false, errors.ToString()));
-            }
+                designer.SetDataSource("MonthCostSales", monthCostSales.ToString("#0.00"));//本月销售费用
+                designer.SetDataSource("YearCostSales", yearCostSales.ToString("#0.00"));  //本年销售费用
 
-            #region 页面操作权限验证
-            //var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(userId,pageId);
+                designer.SetDataSource("MonthOtherFees", monthOtherFees.ToString("#0.00"));//本月其他费用
+                designer.SetDataSource("YearOtherFees", yearOtherFees.ToString("#0.00"));  //本年其他费用
 
-            //if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权限!"));
-            #endregion
+                designer.SetDataSource("MonthDYHFees", monthDyhFees.ToString("#0.00"));//本月大运会费用
+                designer.SetDataSource("YearDYHFees", yearDyhFees.ToString("#0.00"));  //本年大运会费用
 
-            #endregion
+                designer.SetDataSource("MonthDepartFixedFees", monthDepartFixedExpenses.ToString("#0.00"));//本月各部门基础固定费用明细费用
+                designer.SetDataSource("YearDepartFixedFees", yearDepartFixedExpenses.ToString("#0.00"));  //本年各部门基础固定费用明细费用
 
-            DateTime beginDt = DateTime.Parse($"{dto.BeginDt} 00:00:00"),
-                endDt = DateTime.Parse($"{dto.EndDt} 23:59:59");
+                // 填表时间
+                string fillingTime = $"填报时间:{DateTime.Now.ToString("yyyy.MM.dd")}";
+                designer.SetDataSource("FillingTime", fillingTime);
+                #endregion
 
-            if (portType == 1 || portType == 2 ||portType == 3) // web/Android/IOS
+                //根据数据源处理生成报表内容
+                designer.Process();
+                fileName = fileNamePrefix + fileName;
+                designer.Workbook.Save($"{AppSettingsHelper.Get("ExcelBasePath")}CorporateProfit/{fileName}");
+                string url = $"{AppSettingsHelper.Get("ExcelBaseUrl")}Office/Excel/CorporateProfit/{fileName}";
+                return Ok(JsonView(true, "操作成功!", url));
+            }
+            //利润报表
+            else if (excelType == 4)
             {
-                //获取模板
-                string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/利润报表.xlsx");
                 var designer = new WorkbookDesigner();
+                var tempPath = $"{AppSettingsHelper.Get("ExcelBasePath")}Template/利润报表New.xlsx";
                 designer.Workbook = new Workbook(tempPath);
+                #region 填充值
+                string time = $"所属期间: {beginDate.ToString("yyyy 年 MM 月 dd 日")} 至 {endDate.ToString("yyyy 年 MM 月 dd 日")}";
+                designer.SetDataSource("Time", time);
 
-                var currDt = DateTime.Now;
-                DateTime startTimeMonth = new DateTime(currDt.Year, currDt.Month, 1);  //月初
-                DateTime endTimeMonth = startTimeMonth.AddMonths(1).AddDays(-1);  //月末
+                //办公费用
+                decimal officePirce = yearStaffCosts + yearOfficeExpenses;
+                designer.SetDataSource("officePirce", officePirce.ToString("#0.00"));
 
-                var yearDic = CalculatePrice(beginDt,endDt);
-                var monthDic = CalculatePrice(startTimeMonth, endTimeMonth);
+                //业务类型
+                var groupTypeIds = new List<int>() {
+                    38,   //  政府团
+                    39,   //  企业团
+                    40,   //  散客团
+                    1048  // 高校团
+                };
+                var inforTypeIds = new List<int>() {
+                   302,   // 成都-会务活动
+                   691,   // 四川-会务活动
+                };
+                var competitionTypeIds = new List<int>() {
+                   762,   //四川-赛事项目收入
+                   1047,  // 成都-赛事项目收入
+                };
+
+                var otherTypeIds = new List<int>();
+                otherTypeIds.AddRange(groupTypeIds);
+                otherTypeIds.AddRange(inforTypeIds);
+                otherTypeIds.AddRange(competitionTypeIds);
+
+                decimal monthAllIncomes = groupItems.Sum(x => x.ReceivedAmount), //月-收入
+                        monthTzIncomes = groupItems.Where(x => groupTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        monthHwIncomes = groupItems.Where(x => inforTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        monthSsIncomes = groupItems.Where(x => competitionTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        monthQtIncomes = groupItems.Where(x => !otherTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        monthAllCost = groupItems.Sum(x => x.CostTotal), //月-成本
+                        monthTzCost = groupItems.Where(x => groupTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        monthHwCost = groupItems.Where(x => inforTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        monthSsCost = groupItems.Where(x => competitionTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        monthQtCost = groupItems.Where(x => !otherTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        monthAllGross = monthAllIncomes - monthAllCost, //月-毛利金额
+                        monthTzGross = monthTzIncomes - monthTzCost,
+                        monthHwGross = monthHwIncomes - monthHwCost,
+                        monthSsGross = monthSsIncomes - monthSsCost,
+                        monthQtGross = monthQtIncomes - monthQtCost,
+                        yearAllIncomes = yearGroupItems.Sum(x => x.ReceivedAmount), //年-收入
+                        yearTzIncomes = yearGroupItems.Where(x => groupTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        yearHwIncomes = yearGroupItems.Where(x => inforTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        yearSsIncomes = yearGroupItems.Where(x => competitionTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        yearQtIncomes = yearGroupItems.Where(x => !otherTypeIds.Contains(x.TeamDid)).Sum(x => x.ReceivedAmount),
+                        yearAllCost = yearGroupItems.Sum(x => x.CostTotal), //年-成本
+                        yearTzCost = yearGroupItems.Where(x => groupTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        yearHwCost = yearGroupItems.Where(x => inforTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        yearSsCost = yearGroupItems.Where(x => competitionTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        yearQtCost = yearGroupItems.Where(x => !otherTypeIds.Contains(x.TeamDid)).Sum(x => x.CostTotal),
+                        yearAllGross = yearAllIncomes - yearAllCost, //年-毛利金额
+                        yearTzGross = yearTzIncomes - yearTzCost,
+                        yearHwGross = yearHwIncomes - yearHwCost,
+                        yearSsGross = yearSsIncomes - yearSsCost,
+                        yearQtGross = yearQtIncomes - yearQtCost;
+                //年-团数量
+                int yearAllCount = yearGroupItems.Count(), 
+                    yearTzCount = yearGroupItems.Where(x => groupTypeIds.Contains(x.TeamDid)).Count(),
+                    yearHwCount = yearGroupItems.Where(x => inforTypeIds.Contains(x.TeamDid)).Count(),
+                    yearSsCount = yearGroupItems.Where(x => competitionTypeIds.Contains(x.TeamDid)).Count(),
+                    yearQtCount = yearGroupItems.Where(x => !otherTypeIds.Contains(x.TeamDid)).Count();
+
+                //年-利率
+                string yearAllRate = "0.00 %",
+                       yearTzRate = "0.00 %",
+                       yearHwRate = "0.00 %",
+                       yearSsRate = "0.00 %",
+                       yearQtRate = "0.00 %";
+                if (yearAllIncomes != 0) yearAllRate = (yearAllGross / yearAllIncomes * 100).ToString("#0.00") + "%";
+                if (yearTzIncomes != 0) yearTzRate = (yearTzGross / yearTzIncomes * 100).ToString("#0.00") + "%";
+                if (yearHwIncomes != 0) yearHwRate = (yearHwGross / yearHwIncomes * 100).ToString("#0.00") + "%";
+                if (yearSsIncomes != 0) yearSsRate = (yearSsGross / yearSsIncomes * 100).ToString("#0.00") + "%";
+                if (yearQtIncomes != 0) yearQtRate = (yearQtGross / yearQtIncomes * 100).ToString("#0.00") + "%";
+
+                #region 月
+                //收入
+                designer.SetDataSource("MonthAllIncomes", monthAllIncomes.ToString("#0.00"));
+                designer.SetDataSource("MonthtzIncomes", monthTzIncomes.ToString("#0.00"));
+                designer.SetDataSource("MonthhwIncomes", monthHwIncomes.ToString("#0.00"));
+                designer.SetDataSource("MonthssIncomes", monthSsIncomes.ToString("#0.00"));
+                designer.SetDataSource("MonthqtIncomes", monthQtIncomes.ToString("#0.00"));
+
+                //成本
+                designer.SetDataSource("MonthAllCost", monthAllCost.ToString("#0.00"));
+                designer.SetDataSource("MonthtzCost", monthTzCost.ToString("#0.00"));
+                designer.SetDataSource("MonthhwCost", monthHwCost.ToString("#0.00"));
+                designer.SetDataSource("MonthssCost", monthSsCost.ToString("#0.00"));
+                designer.SetDataSource("MonthqtCost", monthQtCost.ToString("#0.00"));
+
+                //毛利金额
+                designer.SetDataSource("MonthAllGross", monthAllGross.ToString("#0.00"));
+                designer.SetDataSource("MonthtzGross", monthTzGross.ToString("#0.00"));
+                designer.SetDataSource("MonthhwGross", monthHwGross.ToString("#0.00"));
+                designer.SetDataSource("MonthssGross", monthSsGross.ToString("#0.00"));
+                designer.SetDataSource("MonthqtGross", monthQtGross.ToString("#0.00"));
+                #endregion
 
                 #region 年
                 //收入
-                designer.SetDataSource("TotalMoney", yearDic["TotalMoney"].ToString("#0.00"));
-                designer.SetDataSource("GroupIncome", yearDic["GroupIncome"].ToString("#0.00"));
-                designer.SetDataSource("ActivityIncome", yearDic["ActivityIncome"].ToString("#0.00"));
-                designer.SetDataSource("CompetitionIncome", yearDic["CompetitionIncome"].ToString("#0.00"));
-                designer.SetDataSource("OtherIncome", yearDic["OtherIncome"].ToString("#0.00"));
+                designer.SetDataSource("YearAllIncomes", yearAllIncomes.ToString("#0.00"));
+                designer.SetDataSource("YeartzIncomes", yearTzIncomes.ToString("#0.00"));
+                designer.SetDataSource("YearhwIncomes", yearHwIncomes.ToString("#0.00"));
+                designer.SetDataSource("YearssIncomes", yearSsIncomes.ToString("#0.00"));
+                designer.SetDataSource("YearqtIncomes", yearQtIncomes.ToString("#0.00"));
 
                 //成本
-                designer.SetDataSource("TotalCost", yearDic["TotalCost"].ToString("#0.00"));
-                designer.SetDataSource("GroupCost", yearDic["GroupCost"].ToString("#0.00"));
-                designer.SetDataSource("ActivityCost", yearDic["ActivityCost"].ToString("#0.00"));
-                designer.SetDataSource("CompetitionCost", yearDic["CompetitionCost"].ToString("#0.00"));
-                designer.SetDataSource("OtherCost", yearDic["OtherCost"].ToString("#0.00"));
+                designer.SetDataSource("YearAllCost", yearAllCost.ToString("#0.00"));
+                designer.SetDataSource("YeartzCost", yearTzCost.ToString("#0.00"));
+                designer.SetDataSource("YearhwCost", yearHwCost.ToString("#0.00"));
+                designer.SetDataSource("YearssCost", yearSsCost.ToString("#0.00"));
+                designer.SetDataSource("YearqtCost", yearQtCost.ToString("#0.00"));
 
                 //毛利金额
-                designer.SetDataSource("TotalGrossProfit", yearDic["TotalGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("GroupGrossProfit", yearDic["GroupGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("ActivityGrossProfit", yearDic["ActivityGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("CompetitionGrossProfit", yearDic["CompetitionGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("OtherGrossProfit", yearDic["OtherGrossProfit"].ToString("#0.00"));
+                designer.SetDataSource("YearAllGross", yearAllGross.ToString("#0.00"));
+                designer.SetDataSource("YeartzGross", yearTzGross.ToString("#0.00"));
+                designer.SetDataSource("YearhwGross", yearHwGross.ToString("#0.00"));
+                designer.SetDataSource("YearssGross", yearSsGross.ToString("#0.00"));
+                designer.SetDataSource("YearqtGross", yearQtGross.ToString("#0.00"));
 
                 //毛利率
-                designer.SetDataSource("TotalInterestRate", yearDic["TotalInterestRate"].ToString("#0.00") + "%");
-                designer.SetDataSource("GroupInterestRate", yearDic["GroupInterestRate"].ToString("#0.00") + "%");
-                designer.SetDataSource("ActivityInterestRate", yearDic["ActivityInterestRate"].ToString("#0.00") + "%");
-                designer.SetDataSource("CompetitionInterestRate", yearDic["CompetitionInterestRate"].ToString("#0.00") + "%");
-                designer.SetDataSource("OtherInterestRate", yearDic["OtherInterestRate"].ToString("#0.00") + "%");
+                designer.SetDataSource("YearAllRate", yearAllRate);
+                designer.SetDataSource("YeartzRate", yearTzRate);
+                designer.SetDataSource("YearhwRate", yearHwRate);
+                designer.SetDataSource("YearssRate", yearSsRate);
+                designer.SetDataSource("YearqtRate", yearQtRate);
 
                 //数量
-                designer.SetDataSource("TotalQuantity", yearDic["TotalQuantity"].ToString());
-                designer.SetDataSource("GroupQuantity", yearDic["GroupQuantity"].ToString());
-                designer.SetDataSource("ActivityQuantity", yearDic["ActivityQuantity"].ToString());
-                designer.SetDataSource("CompetitionQuantity", yearDic["CompetitionQuantity"].ToString());
-                designer.SetDataSource("OtherQuantity", yearDic["OtherQuantity"].ToString());
-
-                //办公费用
-                designer.SetDataSource("OfficeTotalCost", yearDic["OfficeTotalCost"].ToString());
+                designer.SetDataSource("AllCount", yearAllCount.ToString());
+                designer.SetDataSource("tzCount", yearTzCount.ToString());
+                designer.SetDataSource("hwCount", yearHwCount.ToString());
+                designer.SetDataSource("ssCount", yearSsCount.ToString());
+                designer.SetDataSource("qtCount", yearQtCount.ToString());
                 #endregion
 
-                #region 月
-                //收入
-                designer.SetDataSource("MonthAllIncomes", monthDic["TotalMoney"].ToString("#0.00"));
-                designer.SetDataSource("MonthtzIncomes", monthDic["GroupIncome"].ToString("#0.00"));
-                designer.SetDataSource("MonthhwIncomes", monthDic["ActivityIncome"].ToString("#0.00"));
-                designer.SetDataSource("MonthssIncomes", monthDic["CompetitionIncome"].ToString("#0.00"));
-                designer.SetDataSource("MonthqtIncomes", monthDic["OtherIncome"].ToString("#0.00"));
+                #region 日付相关
 
-                //成本
-                designer.SetDataSource("MonthAllCost", monthDic["TotalCost"].ToString("#0.00"));
-                designer.SetDataSource("MonthtzCost", monthDic["GroupCost"].ToString("#0.00"));
-                designer.SetDataSource("MonthhwCost", monthDic["ActivityCost"].ToString("#0.00"));
-                designer.SetDataSource("MonthssCost", monthDic["CompetitionCost"].ToString("#0.00"));
-                designer.SetDataSource("MonthqtCost", monthDic["OtherCost"].ToString("#0.00"));
+                var dailyViewItems = new List<CorporateProfitDailyView>();
 
-                //毛利金额
-                designer.SetDataSource("MonthAllGross", monthDic["TotalGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("MonthtzGross", monthDic["GroupGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("MonthhwGross", monthDic["ActivityGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("MonthssGross", monthDic["CompetitionGrossProfit"].ToString("#0.00"));
-                designer.SetDataSource("MonthqtGross", monthDic["OtherGrossProfit"].ToString("#0.00"));
-                #endregion
+                var dailyTypes = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToListAsync();
+                var conmmentTexts = new List<CorporateProfitDailyCommentView>();
 
-                designer.Process();
-                //文件名
-                string fileName = $"利润报表({dto.BeginDt}至{dto.EndDt}){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
-                designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "CorporateProfit/" + fileName);
-                string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/CorporateProfit/" + fileName;
-                return Ok(JsonView(true, "成功", url));
-            }
+                #region 员工费用 48
+                decimal monthStaffCostTotal = dailyItems.Where(x => x.PriceParentTypeId == 48).Sum(x => x.ItemTotal),
+                        yearStaffCostTotal = yearDailyItems.Where(x => x.PriceParentTypeId == 48).Sum(x => x.ItemTotal);
 
-            return Ok(JsonView(false));
-        }
+                dailyViewItems.Add(new CorporateProfitDailyView() { No = "一", PriceName = "人员费用", ThisMonthAmount = monthStaffCostTotal, ThisYearAmount = yearStaffCostTotal});
+                conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                {
+                    MonthComment = DailyListToString(dailyItems.Where(x => x.PriceParentTypeId == 48).ToArray()),
+                    YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceParentTypeId == 48).ToArray())
+                });
 
+                var dailyStaffTypes = dailyTypes.Where(x => x.STid == 48).OrderBy(x => x.Id).ToList();
+                foreach (var item in dailyStaffTypes)
+                {
+                    string priceName = !string.IsNullOrEmpty(item.Remark) ? item.Remark : item.Name;
+                    decimal monthAmount = dailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal),
+                            yearAmount = yearDailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal);
+                    dailyViewItems.Add(new CorporateProfitDailyView() { PriceName = priceName, ThisMonthAmount = monthAmount, ThisYearAmount = yearAmount });
+                    conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                    {
+                        MonthComment = DailyListToString(dailyItems.Where(x => x.PriceTypeId == item.Id).ToArray()),
+                        YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceTypeId == item.Id).ToArray())
+                    });
+                }
 
-        /// <summary>
-        /// 计算团组全部费用
-        /// </summary>
-        /// <param name="startTime"></param>
-        /// <param name="endTime"></param>
-        /// <returns></returns>
-        private Dictionary<string, decimal> CalculatePrice(DateTime startTime, DateTime endTime)
-        {
-            DateTime beginDt = startTime,
-                     endDt = endTime;
-            var dic = new Dictionary<string, decimal>();
-            
-            decimal totalIncomes = 0.00M; //总收入
-            decimal totalCost = 0.00M;    //总成本
-
-            #region 团组
-            //团组收入,会务收入,赛事项目收入,其他非团组收入
-            decimal groupIncome = 0.00M;    //团组收入            
-            decimal activityIncome = 0.00M;    //会务收入
-            decimal competitionIncome = 0.00M;    //赛事项目收入
-            decimal otherIncome = 0.00M;    //其他非团组收入
-            decimal groupCost = 0.00M;       //团组成本
-            decimal activityCost = 0.00M;       //会务成本
-            decimal competitionCost = 0.00M;       //赛事项目成本
-            decimal otherCost = 0.00M;       //其他非团组成本
-
-            var groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>()
-                .Where(x => x.IsDel == 0 && x.VisitDate >= beginDt && x.VisitDate <= endDt)
-                .Select(x => new { x.Id, x.TeamName,x.TeamDid,  x.VisitDate })
-                .ToList();
+                #endregion
 
-            var groupIds = groupDatas.Select(x => x.Id).ToList();
-            //应收
-            var receivableDatas = _sqlSugar.Queryable<Fin_ForeignReceivables>().Where(x => x.IsDel == 0 && groupIds.Contains(x.Diid)).ToList();
-            //已收
-            var receivedDatas = _sqlSugar.Queryable<Fin_ProceedsReceived>().Where(x => x.IsDel == 0 && groupIds.Contains(x.Diid)).ToList();
-            //成本
-            var costDatas = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.IsDel == 0 && groupIds.Contains(x.DIId) && x.IsPay == 1).ToList();
-            //提成
-            var groupRoyaltyDatas = _sqlSugar.Queryable<Fin_RoyaltyConfirm>().Where(x => x.IsDel == 0 && groupIds.Contains(x.TeamId) && x.IsConfirm == 1).ToList();
-
-            #region 团组
-            var groupTyepIds = new List<int> { 38, 39, 40, 1048 };
-            var groupIncomIds = groupDatas.Where(x => groupTyepIds.Contains(x.TeamDid)).Select(x => x.Id).ToList();
-            //收入
-            groupIncome = receivedDatas.Where(x => groupIncomIds.Contains(x.Diid)).Sum(x => x.Price);
-            //成本
-            groupCost = costDatas.Where(x => groupIncomIds.Contains(x.DIId)).Sum(x => x.PayMoney * x.DayRate);
-            //提成
-            groupCost += groupRoyaltyDatas.Where(x => groupIncomIds.Contains(x.TeamId)).Sum(x => x.Price);
-            #endregion
+                #region 办公费用
 
-            #region 会务
-            var activityTyepIds = new List<int> { 302, 691 };
-            var activityIncomIds = groupDatas.Where(x => activityTyepIds.Contains(x.TeamDid)).Select(x => x.Id).ToList();
-            //收入
-            activityIncome = receivedDatas.Where(x => activityIncomIds.Contains(x.Diid)).Sum(x => x.Price);
-            //成本
-            activityCost = costDatas.Where(x => activityIncomIds.Contains(x.DIId)).Sum(x => x.PayMoney * x.DayRate);
-            //提成
-            activityCost += groupRoyaltyDatas.Where(x => activityIncomIds.Contains(x.TeamId)).Sum(x => x.Price);
-            #endregion
+                decimal monthWorkCostTotal = dailyItems.Where(x => x.PriceParentTypeId == 49).Sum(x => x.ItemTotal), //总费用
+                        yearWorkCostTotal = yearDailyItems.Where(x => x.PriceParentTypeId == 49).Sum(x => x.ItemTotal);
 
-            #region 赛事
-            var competitionTyepIds = new List<int> { 762, 1047 };
-            var competitionIncomIds = groupDatas.Where(x => competitionTyepIds.Contains(x.TeamDid)).Select(x => x.Id).ToList();
-            //收入
-            competitionIncome = receivedDatas.Where(x => competitionIncomIds.Contains(x.Diid)).Sum(x => x.Price);
-            //成本
-            competitionCost = costDatas.Where(x => competitionIncomIds.Contains(x.DIId)).Sum(x => x.PayMoney * x.DayRate);
-            //提成
-            competitionCost += groupRoyaltyDatas.Where(x => competitionIncomIds.Contains(x.TeamId)).Sum(x => x.Price);
-            #endregion
+                dailyViewItems.Add(new CorporateProfitDailyView() { No = "二", PriceName = "办公费用", ThisMonthAmount = monthWorkCostTotal, ThisYearAmount = yearWorkCostTotal });
+                conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                {
+                    MonthComment = DailyListToString(dailyItems.Where(x => x.PriceParentTypeId == 49).ToArray()),
+                    YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceParentTypeId == 49).ToArray())
+                });
 
-            #region 其他非团组
-            //收入
-            var otherTyepIds = new List<int> { 102, 248 };
-            var otherIncomIds = groupDatas.Where(x => otherTyepIds.Contains(x.TeamDid)).Select(x => x.Id).ToList();
-            otherIncome = receivedDatas.Where(x => otherIncomIds.Contains(x.Diid)).Sum(x => x.Price);
-            //成本
-            otherCost = costDatas.Where(x => otherIncomIds.Contains(x.DIId)).Sum(x => x.PayMoney * x.DayRate);
-            //提成
-            competitionCost += groupRoyaltyDatas.Where(x => otherIncomIds.Contains(x.TeamId)).Sum(x => x.Price);
+                var dailyWorkTypes = dailyTypes.Where(x => x.STid == 49).OrderBy(x => x.Id).ToList();
+                foreach (var item in dailyWorkTypes)
+                {
+                    string priceName = !string.IsNullOrEmpty(item.Remark) ? item.Remark : item.Name;
+                    decimal monthAmount = dailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal),
+                            yearAmount = yearDailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal);
+                    dailyViewItems.Add(new CorporateProfitDailyView() { PriceName = priceName, ThisMonthAmount = monthAmount, ThisYearAmount = yearAmount });
+                    conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                    {
+                        MonthComment = DailyListToString(dailyItems.Where(x => x.PriceTypeId == item.Id).ToArray()),
+                        YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceTypeId == item.Id).ToArray())
+                    });
+                }
 
-            #endregion
-            #endregion
+                #endregion
 
-            #region 办公费用
-            //48人员费用  49办公费用 50 销售费用 51 其他费用 55 大运会
-            var typeIds = new List<int>() {
-                48, //人员费用
-                49, //办公费用
-                50, //销售费用
-                51, //其他费用
-                55, //大运会
-                90, //各部门基础固定费用明细
-            };
-            //var priceTypeData = _sqlSugar.Queryable<Sys_SetData>().Where(s => typeIds.Contains(s.Id)).ToList();
-            var priceSubTypeDatas = _sqlSugar.Queryable<Sys_SetData>().Where(s => s.IsDel == 0 && typeIds.Contains(s.STid)).ToList();
-            var priceSubTypeIds = priceSubTypeDatas.Select(x => x.Id).ToList();
-            var dailyFeeDatass = _sqlSugar
-                .Queryable<Fin_DailyFeePayment>()
-                .Where(x => x.IsDel == 0 && x.CreateTime >= beginDt && x.CreateTime <= endDt && priceSubTypeIds.Contains(x.PriceTypeId) && x.IsPay == 1)
-                .ToList();
+                #region 销售费用
+                decimal monthSalesCostTotal = dailyItems.Where(x => x.PriceParentTypeId == 50).Sum(x => x.ItemTotal), //总费用
+                        yearSalesCostTotal = yearDailyItems.Where(x => x.PriceParentTypeId == 50).Sum(x => x.ItemTotal);
 
-            //人员费用
-            var staffCostTypeIds = priceSubTypeDatas.Where(x => x.STid == 48).Select(x => x.Id).ToList();
-            decimal staffCost = dailyFeeDatass.Where(x => staffCostTypeIds.Contains(x.PriceTypeId)).Sum(x => x.SumPrice);
+                dailyViewItems.Add(new CorporateProfitDailyView() { No = "三", PriceName = "销售费用", ThisMonthAmount = monthSalesCostTotal, ThisYearAmount = yearSalesCostTotal });
+                conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                {
+                    MonthComment = DailyListToString(dailyItems.Where(x => x.PriceParentTypeId == 50).ToArray()),
+                    YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceParentTypeId == 50).ToArray())
+                });
 
-            //办公费用
-            var officeCostTypeIds = priceSubTypeDatas.Where(x => x.STid == 49).Select(x => x.Id).ToList();
-            decimal officeCost = dailyFeeDatass.Where(x => officeCostTypeIds.Contains(x.PriceTypeId)).Sum(x => x.SumPrice);
+                var dailySalesTypes = dailyTypes.Where(x => x.STid == 50).OrderBy(x => x.Id).ToList();
+                foreach (var item in dailySalesTypes)
+                {
+                    string priceName = !string.IsNullOrEmpty(item.Remark) ? item.Remark : item.Name;
+                    decimal monthAmount = dailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal),
+                            yearAmount = yearDailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal);
+                    dailyViewItems.Add(new CorporateProfitDailyView() { PriceName = priceName, ThisMonthAmount = monthAmount, ThisYearAmount = yearAmount });
+                    conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                    {
+                        MonthComment = DailyListToString(dailyItems.Where(x => x.PriceTypeId == item.Id).ToArray()),
+                        YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceTypeId == item.Id).ToArray())
+                    });
+                }
 
-            //销售费用
-            var marketingCostTypeIds = priceSubTypeDatas.Where(x => x.STid == 50).Select(x => x.Id).ToList();
-            decimal marketingCost = dailyFeeDatass.Where(x => marketingCostTypeIds.Contains(x.PriceTypeId)).Sum(x => x.SumPrice);
+                #endregion
 
-            //其他费用
-            var bg_otherCostTypeIds = priceSubTypeDatas.Where(x => x.STid == 51).Select(x => x.Id).ToList();
-            decimal bg_otherCost = dailyFeeDatass.Where(x => bg_otherCostTypeIds.Contains(x.PriceTypeId)).Sum(x => x.SumPrice);
+                #region 51 其他费用
 
-            //大运会
-            var universityGamesCostTypeIds = priceSubTypeDatas.Where(x => x.STid == 55).Select(x => x.Id).ToList();
-            decimal universityGamesCost = dailyFeeDatass.Where(x => universityGamesCostTypeIds.Contains(x.PriceTypeId)).Sum(x => x.SumPrice);
+                decimal monthOtherCostTotal = dailyItems.Where(x => x.PriceParentTypeId == 51).Sum(x => x.ItemTotal), //总费用
+                        yearOtherCostTotal = yearDailyItems.Where(x => x.PriceParentTypeId == 51).Sum(x => x.ItemTotal);
 
-            //各部门基础固定费用明细
-            var basicCostTypeIds = priceSubTypeDatas.Where(x => x.STid == 90).Select(x => x.Id).ToList();
-            decimal basicGamesCost = dailyFeeDatass.Where(x => basicCostTypeIds.Contains(x.PriceTypeId)).Sum(x => x.SumPrice);
-            #endregion
+                dailyViewItems.Add(new CorporateProfitDailyView() { No = "四", PriceName = "其他费用", ThisMonthAmount = monthOtherCostTotal, ThisYearAmount = yearOtherCostTotal });
+                conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                {
+                    MonthComment = DailyListToString(dailyItems.Where(x => x.PriceParentTypeId == 51).ToArray()),
+                    YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceParentTypeId == 51).ToArray())
+                });
 
-            totalCost = costDatas.Sum(x => x.PayMoney * x.DayRate) + groupRoyaltyDatas.Sum(x => x.Price);
-            totalIncomes = receivedDatas.Sum(x => x.Price);
+                var dailyOtherTypes = dailyTypes.Where(x => x.STid == 51).OrderBy(x => x.Id).ToList();
+                foreach (var item in dailyOtherTypes)
+                {
+                    string priceName = !string.IsNullOrEmpty(item.Remark) ? item.Remark : item.Name;
+                    decimal monthAmount = dailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal),
+                            yearAmount = yearDailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal);
+                    dailyViewItems.Add(new CorporateProfitDailyView() { PriceName = priceName, ThisMonthAmount = monthAmount, ThisYearAmount = yearAmount });
+                    conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                    {
+                        MonthComment = DailyListToString(dailyItems.Where(x => x.PriceTypeId == item.Id).ToArray()),
+                        YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceTypeId == item.Id).ToArray())
+                    });
+                }
 
-            #region 填充值
+                #endregion
 
-            #region 本年累计
+                #region 55 大运会
 
-            decimal totalInterestRate = 0.00M,
-                totalGrossProfit = 0.00M;
-            if (totalIncomes > 0)
-            {
-                totalGrossProfit = totalIncomes - totalCost;
-                totalInterestRate = totalGrossProfit / totalIncomes * 100;
-            }
+                decimal monthDyhCostTotal = dailyItems.Where(x => x.PriceParentTypeId == 55).Sum(x => x.ItemTotal), //总费用
+                        yearDyhCostTotal = yearDailyItems.Where(x => x.PriceParentTypeId == 55).Sum(x => x.ItemTotal);
 
-            //业务数量
-            dic.Add("TotalQuantity", groupDatas.Count);
-            //应收金额
-            dic.Add("TotalMoney", totalIncomes);
-            //成本
-            dic.Add("TotalCost", totalCost);
-            //毛利润
-            dic.Add("TotalGrossProfit", totalGrossProfit);
-            //利率 
-            dic.Add("TotalInterestRate", totalInterestRate);
+                dailyViewItems.Add(new CorporateProfitDailyView() { No = "五", PriceName = "大运会", ThisMonthAmount = monthDyhCostTotal, ThisYearAmount = yearDyhCostTotal });
+                conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                {
+                    MonthComment = DailyListToString(dailyItems.Where(x => x.PriceParentTypeId == 55).ToArray()),
+                    YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceParentTypeId == 55).ToArray())
+                });
 
-            #endregion
+                var dailyDyhTypes = dailyTypes.Where(x => x.STid == 55).OrderBy(x => x.Id).ToList();
+                foreach (var item in dailyDyhTypes)
+                {
+                    string priceName = !string.IsNullOrEmpty(item.Remark) ? item.Remark : item.Name;
+                    decimal monthAmount = dailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal),
+                            yearAmount = yearDailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal);
+                    dailyViewItems.Add(new CorporateProfitDailyView() { PriceName = priceName, ThisMonthAmount = monthAmount, ThisYearAmount = yearAmount }); 
+                    conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                    {
+                        MonthComment = DailyListToString(dailyItems.Where(x => x.PriceTypeId == item.Id).ToArray()),
+                        YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceTypeId == item.Id).ToArray())
+                    });
+                }
 
-            #region 团组
-            decimal groupInterestRate = 0.00M,
-                groupGrossProfit = 0.00M;
-            if (groupIncome > 0)
-            {
-                groupGrossProfit = groupIncome - groupCost;
-                groupInterestRate = groupGrossProfit / groupIncome * 100;
-            }
+                #endregion
 
-            //数量
-            dic.Add("GroupQuantity", groupIncomIds.Count);
-            //收入
-            dic.Add("GroupIncome", groupIncome);
-            //成本
-            dic.Add("GroupCost", groupCost);
-            //毛利润
-            dic.Add("GroupGrossProfit", groupGrossProfit);
-            //利率 
-            dic.Add("GroupInterestRate", groupInterestRate);
-            #endregion
+                #region 90 各部门基础固定费用明细
 
-            #region 会务
+                decimal monthBasicCostTotal = dailyItems.Where(x => x.PriceParentTypeId == 90).Sum(x => x.ItemTotal), //总费用
+                        yearBasicCostTotal = yearDailyItems.Where(x => x.PriceParentTypeId == 90).Sum(x => x.ItemTotal);
 
-            decimal activityInterestRate = 0.00M,
-                activityGrossProfit = 0.00M;
-            if (activityIncome > 0)
-            {
-                activityGrossProfit = activityIncome - activityCost;
-                activityInterestRate = activityGrossProfit / activityIncome * 100;
-            }
+                dailyViewItems.Add(new CorporateProfitDailyView() { No = "六", PriceName = "各部门基础固定费用明细", ThisMonthAmount = monthBasicCostTotal, ThisYearAmount = yearBasicCostTotal });
+                conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                {
+                    MonthComment = DailyListToString(dailyItems.Where(x => x.PriceParentTypeId == 90).ToArray()),
+                    YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceParentTypeId == 90).ToArray())
+                });
 
-            //数量
-            dic.Add("ActivityQuantity", activityIncomIds.Count);
-            //收入
-            dic.Add("ActivityIncome", activityIncome);
-            //成本
-            dic.Add("ActivityCost", activityCost);
-            //毛利润
-            dic.Add("ActivityGrossProfit", activityGrossProfit);
-            //利率 
-            dic.Add("ActivityInterestRate", activityInterestRate);
-            #endregion
+                var dailyBasicTypes = dailyTypes.Where(x => x.STid == 90).OrderBy(x => x.Id).ToList();
+                foreach (var item in dailyBasicTypes)
+                {
+                    string priceName = item.Name;
+                    decimal monthAmount = dailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal),
+                            yearAmount = yearDailyItems.Where(x => x.PriceTypeId == item.Id).Sum(x => x.ItemTotal);
+                    dailyViewItems.Add(new CorporateProfitDailyView() { PriceName = priceName, ThisMonthAmount = monthAmount, ThisYearAmount = yearAmount });
+                    conmmentTexts.Add(new CorporateProfitDailyCommentView()
+                    {
+                        MonthComment = DailyListToString(dailyItems.Where(x => x.PriceTypeId == item.Id).ToArray()),
+                        YearComment = DailyListToString(yearDailyItems.Where(x => x.PriceTypeId == item.Id).ToArray())
+                    });
+                }
 
-            #region 赛事项目
-            decimal competitionInterestRate = 0.00M,
-                    competitionGrossProfit = 0.00M;
-            if (competitionIncome > 0)
-            {
-                competitionGrossProfit = competitionIncome - competitionCost;
-                activityInterestRate = competitionGrossProfit / competitionIncome * 100;
-            }
+                #endregion
 
-            //数量
-            dic.Add("CompetitionQuantity", competitionIncomIds.Count);
-            //收入
-            dic.Add("CompetitionIncome", competitionIncome);         
-            //成本
-            dic.Add("CompetitionCost", competitionCost);              
-            //毛利润
-            dic.Add("CompetitionGrossProfit", competitionGrossProfit);
-            //毛利率
-            dic.Add("CompetitionInterestRate", competitionInterestRate);
+                //designer.SetDataSource("DailyView", dailyViewItems);
+                var dt = CommonFun.ToDataTableArray(dailyViewItems);
+                dt.TableName = "DailyView";
+                designer.SetDataSource(dt);
+               
+                #endregion
 
-            #endregion
+                #endregion
 
-            #region 其他非团组
-            decimal otherInterestRate = 0.00M,
-                    otherGrossProfit = 0.00M;
-            if (otherIncome > 0)
-            {
-                otherGrossProfit = otherIncome - otherCost;
-                otherInterestRate = otherGrossProfit / otherIncome * 100;
-            }
+                //根据数据源处理生成报表内容
+                designer.Process();
 
-            //数量
-            dic.Add("OtherQuantity", otherIncomIds.Count);   
-            //收入
-            dic.Add("OtherIncome", otherIncome);             
-            //成本
-            dic.Add("OtherCost", otherCost);                 
-            //毛利润
-            dic.Add("OtherGrossProfit", otherGrossProfit); 
-            //毛利率
-            dic.Add("OtherInterestRate", otherInterestRate);
-            #endregion
+                var dailySheet = designer.Workbook.Worksheets[1];
+                //渲染批注
+                for (int i = 0; i < dailyViewItems.Count; i++)
+                {
+                    string monthComment = $"C{i + 3}",
+                           yearComment = $"D{i + 3}";
+                    int monthCommentIndex = dailySheet.Comments.Add(monthComment),
+                        yearCommentIndex = dailySheet.Comments.Add(yearComment);
+                    
+
+                    string commentText1 = conmmentTexts[i].MonthComment,
+                           commentText2 = conmmentTexts[i].YearComment;
+
+                    Aspose.Cells.Comment comment1 = dailySheet.Comments[monthCommentIndex];
+                    comment1.Note = commentText1;
+                    comment1.Width = 400;
+                    comment1.Height = 400;
+                    comment1.Font.Color = Color.Red;
+
+                    Aspose.Cells.Comment comment2 = dailySheet.Comments[yearCommentIndex];
+                    comment2.Note = commentText2;
+                    comment2.Width = 400;
+                    comment2.Height = 400;
+                    comment2.Font.Color = Color.Red;
+                }
 
-            #region 办公费用
+                string fileName = $"利润报表({beginDate.ToString("yyyy年MM月dd日")}~{endDate.ToString("yyyy年MM月dd日")}){Guid.NewGuid().ToString()}.xls";
+                designer.Workbook.Save($"{AppSettingsHelper.Get("ExcelBasePath")}CorporateProfit/{fileName}");
+                string url = $"{AppSettingsHelper.Get("ExcelBaseUrl")}Office/Excel/CorporateProfit/{fileName}";
+                return Ok(JsonView(true, "操作成功!", url));
+            }
+            else if (excelType == 5)
+            {
+                var view = await CorporateProfitItems(2, beginDt, endDt);
+                return Ok(JsonView(true, "操作成功!", view.Label));
 
-            decimal officeTotalCost = dailyFeeDatass.Sum(x => x.SumPrice);
-            dic.Add("OfficeTotalCost", officeTotalCost);
-            #endregion
 
-            #endregion
+            }
+            return Ok(JsonView(false));
+        }
 
-            return dic;
+        private static string DailyListToString(DailyInfo[] infos)
+        {
+            StringBuilder sb = new StringBuilder();
+            int index = 1;
+            foreach (var info in infos)
+            {
+                sb.Append(index + "、");
+                sb.Append($"[{info.ItemTotal.ToString("#0.00")}]:{info.PriceName};");
+                sb.Append(Environment.NewLine);
+                index++;
+            }
+            return sb.ToString();
         }
 
         #endregion
-
     }
 }

+ 12 - 10
OASystem/OASystem.Domain/Dtos/Statistics/CorporateProfitDtos.cs

@@ -27,8 +27,10 @@ namespace OASystem.Domain.Dtos.Statistics
     /// <summary>
     /// item Dto
     /// </summary>
-    public class CorporateProfitItemDto : CorporateProfitExcelDownloadDto
+    public class CorporateProfitItemDto : CorporateProfitDtos
     {
+        public string BeginDt { get; set; }
+        public string EndDt { get; set; }
     }
 
     /// <summary>
@@ -39,12 +41,18 @@ namespace OASystem.Domain.Dtos.Statistics
     {
         public CorporateProfitItemDtoFoalidator()
         {
-            Include(new CorporateProfitExcelDownloadDtoFoalidator());
+            Include(new CorporateProfitDtosDtoBaseFoalidator());
+            RuleFor(it => it.BeginDt)
+                .Must(dateString => DateTime.TryParse(dateString, out _))
+                .WithMessage("请输入有效开始的日期");
+            RuleFor(it => it.EndDt)
+                .Must(dateString => DateTime.TryParse(dateString, out _))
+                .WithMessage("请输入有效结束的日期");
         }
     }
 
 
-    public class CorporateProfitExcelDownloadDto : CorporateProfitDtos
+    public class CorporateProfitExcelDownloadDto : CorporateProfitItemDto
     {
         /// <summary>
         /// excel类型
@@ -59,14 +67,8 @@ namespace OASystem.Domain.Dtos.Statistics
     {
         public CorporateProfitExcelDownloadDtoFoalidator()
         {
-            Include(new CorporateProfitDtosDtoBaseFoalidator());
+            Include(new CorporateProfitItemDtoFoalidator());
             RuleFor(it => it.ExcelType).InclusiveBetween(1, 5).WithMessage("请输入有效的Excel类型");
-            RuleFor(it => it.BeginDt)
-                .Must(dateString => DateTime.TryParse(dateString, out _))
-                .WithMessage("请输入有效开始的日期");
-            RuleFor(it => it.EndDt)
-                .Must(dateString => DateTime.TryParse(dateString, out _))
-                .WithMessage("请输入有效结束的日期");
 
         }
     }

+ 17 - 0
OASystem/OASystem.Domain/ViewModels/Statistics/CorporateProfitViews.cs

@@ -138,4 +138,21 @@ namespace OASystem.Domain.ViewModels.Statistics
         public string Label { get; set; }
 
     }
+
+
+    public class CorporateProfitDailyView
+    {
+        public string No { get; set; }
+        public string PriceName { get; set; }
+
+        public decimal ThisMonthAmount { get; set; }
+        public decimal ThisYearAmount { get; set; }
+        public string Remark { get; set; }
+    }
+
+    public class CorporateProfitDailyCommentView
+    {
+        public string MonthComment { get; set; }
+        public string YearComment { get; set; }
+    }
 }