浏览代码

应收报表

新增应收报表查询 API 及相关数据模型支持

在 FinancialController.cs 中新增 GetSyntheticalReceivableFeeDetails 方法,用于查询单个团组的应收报表费用明细。方法包含参数验证、SQL 注入防护、分组统计及排序逻辑,并通过日志记录增强错误处理。

在 Fin_ForeignReceivablesView.cs 中新增 SyntheticalReceivableFeeDetailsView 数据模型,包含费用明细相关字段。

同时引入 Humanizer 和 NPOI 等命名空间以支持新功能。
Lyyyi 1 天之前
父节点
当前提交
02135fdbdd

+ 93 - 1
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -3,7 +3,6 @@ using Aspose.Words;
 using EyeSoft.Extensions;
 using EyeSoft.IO;
 using FluentValidation;
-using NPOI.SS.UserModel;
 using NPOI.XSSF.UserModel;
 using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.APNs;
@@ -1996,6 +1995,99 @@ namespace OASystem.API.Controllers
 
         #region 应收报表
 
+        /// <summary>
+        /// 查询单个团组的应收报表 费用明细
+        /// </summary>
+        /// <param name="groupId"></param>
+        /// <returns></returns>
+        [HttpGet]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GetSyntheticalReceivableFeeDetails(int groupId)
+        {
+            // 参数验证
+            if (groupId <= 0)
+            {
+                return Ok(JsonView(false, "团组ID无效。"));
+            }
+
+            // 验证团组是否存在
+            var groupValid = await _sqlSugar.Queryable<Grp_DelegationInfo>()
+                .Where(x => x.Id == groupId && x.IsDel == 0)
+                .AnyAsync();
+
+            if (!groupValid)
+            {
+                return Ok(JsonView(false, "团组ID无效或已被删除。"));
+            }
+
+            // 使用参数化查询避免SQL注入
+            string sql = @"
+        SELECT 
+            di.id,
+            di.TeamName,
+            sd.Name AS ModouleName,
+            ccp.CTable,
+            CASE 
+                WHEN ccp.CTable = 76 THEN (SELECT hotelname FROM Grp_HotelReservations hr WHERE hr.Id = ccp.CId)
+                WHEN ccp.CTable = 79 THEN (SELECT PriceName FROM Grp_CarTouristGuideGroundReservations ctgr WHERE ctgr.Id = ccp.CId)
+                WHEN ccp.CTable = 80 THEN (SELECT Area FROM Grp_VisaInfo vi WHERE vi.Id = ccp.CId)
+                WHEN ccp.CTable = 81 THEN (SELECT InviterArea FROM Grp_InvitationOfficialActivities ioa WHERE ioa.Id = ccp.CId)
+                WHEN ccp.CTable = 82 THEN (SELECT (SELECT GName FROM Grp_InsuranceCost ic WHERE ic.Id = c.Iid) FROM Grp_Customers c WHERE c.Id = ccp.CId)
+                WHEN ccp.CTable = 85 THEN (SELECT FlightsCode FROM Grp_AirTicketReservations atr WHERE atr.Id = ccp.CId)
+                WHEN ccp.CTable = 98 THEN (SELECT PriceName FROM Grp_DecreasePayments dp WHERE dp.Id = ccp.CId)
+                WHEN ccp.CTable = 1015 THEN (SELECT PriceName FROM Fin_GroupExtraCost gec WHERE gec.Id = ccp.CId)
+                ELSE '-'
+            END AS PriceName,
+            (ccp.PayMoney * ccp.DayRate) AS CNYMoeny
+        FROM Grp_CreditCardPayment ccp
+        INNER JOIN Grp_DelegationInfo di ON ccp.DIId = di.Id
+        LEFT JOIN sys_setdata sd ON ccp.CTable = sd.Id
+        WHERE ccp.IsDel = 0 
+          AND di.IsDel = 0 
+          AND di.id = @GroupId";
+
+            try
+            {
+                var datas = await _sqlSugar.SqlQueryable<SyntheticalReceivableFeeDetailsView>(sql)
+                    .AddParameters(new { GroupId = groupId })
+                    .ToListAsync();
+
+                // 分组统计并排序
+                var feeDatas = datas
+                    .GroupBy(g => new { g.CTable, g.ModouleName })
+                    .Select(s => new SyntheticalReceivableFeeDetailsView
+                    {
+                        ModouleName = s.Key.ModouleName ?? "未知模块",
+                        CTable = s.Key.CTable,
+                        CNYMoeny = s.Sum(ss => ss.CNYMoeny)
+                    })
+                    .OrderBy(x => x.CTable)
+                    .ToList();
+
+                // 构建结果字符串
+                var feeLabel = new StringBuilder();
+                foreach (var item in feeDatas)
+                {
+                    feeLabel.AppendLine($"{item.ModouleName} :{item.CNYMoeny:#,##0.00} CNY");
+                    feeLabel.AppendLine(); // 空行
+                }
+
+                // 如果没有数据,返回提示信息
+                if (feeDatas.Count == 0)
+                {
+                    return Ok(JsonView(true, "查询成功,但未找到相关费用明细。", "暂无费用明细"));
+                }
+
+                return Ok(JsonView(true, "操作成功", feeLabel.ToString()));
+            }
+            catch (Exception ex)
+            {
+                // 记录日志
+                _logger.LogError(ex, "查询团组费用明细时发生错误,团组ID:{GroupId}", groupId);
+                return Ok(JsonView(false, "查询过程中发生错误,请稍后重试。"));
+            }
+        }
+
         /// <summary>
         /// 应收报表
         /// 查询 根据日期范围

+ 16 - 0
OASystem/OASystem.Domain/ViewModels/Financial/Fin_ForeignReceivablesView.cs

@@ -407,6 +407,22 @@ namespace OASystem.Domain.ViewModels.Financial
         public List<ClientFeeInfoView>? feeItem { get; set; }
     }
 
+    public class SyntheticalReceivableFeeDetailsView {
+
+        public int Id { get; set; }
+
+        public string TeamName { get; set; }
+
+        public int CTable { get; set; }
+
+        public string ModouleName { get; set; }
+
+        public string PriceName { get; set; }
+
+        public decimal CNYMoeny { get; set; }
+    }
+
+
     /// <summary>
     /// 单位应收已收详情 Info View
     /// 新增