浏览代码

团组报表、费用未审核 团组查询优化

Lyyyi 1 周之前
父节点
当前提交
fd10bdb90e

+ 48 - 4
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -7175,14 +7175,58 @@ Group by PriceType ", dto.diId);
                 return Ok(jw);
             }
 
-            var _groupDatas = _sqlSugar.Queryable<Grp_DelegationInfo>()
+            // 构建搜索条件
+            var searchFields = new List<string>
+            {
+                "TeamName"
+            };
+
+            var searchConfig = new SearchConfig
+            {
+                EnableExactMatch = true,
+                EnablePrefixMatch = true,
+                EnableFuzzySearch = true,
+                EnableCharSearch = true,
+                RequireAllWords = true,
+                RequireAllChars = false,
+                EnableSmartSplitting = true,
+                MinSplitLength = 4,
+                RequireAllWordsForSplit = false
+            };
+
+            // 使用智能混合搜索模式
+            var (searchCondition, searchParameters) = AdvancedSearchHelper.BuildEnhancedSearchCondition(
+                searchTerm: teamName,
+                searchFields: searchFields,
+                prefix: "search_",
+                searchMode: SearchMode.AutoDetect,
+                combinationMode: CombinationMode.SmartMix,
+                config: searchConfig
+            );
+
+            // 主查询
+            var query = _sqlSugar.Queryable<Grp_DelegationInfo>()
                 .Where(x => x.IsDel == 0 &&
                         x.VisitDate >= _beginDt &&
-                        x.VisitDate <= _endDt
-                        )
-                .WhereIF(!string.IsNullOrEmpty(teamName), x => x.TeamName.Contains(teamName))
+                        x.VisitDate <= _endDt);
+
+            // 如果存在搜索条件,添加到查询中
+            if (!string.IsNullOrEmpty(searchCondition))
+            {
+                query = query.Where(searchCondition, searchParameters.ToArray());
+            }
+            else if (!string.IsNullOrEmpty(teamName))
+            {
+                // 如果搜索条件构建失败但有搜索词,使用简单包含匹配
+                query = query.Where(x => x.TeamName.Contains(teamName));
+            }
+
+            var _groupDatas = query
+                .OrderByDescending(x => x.CreateTime)
                 .ToList();
+
             var _groupIds = _groupDatas.Select(x => x.Id).ToList();
+
             if (_groupIds.Count < 1)
             {
                 jw.Msg = $"该时间段暂无出访的团组!";

+ 102 - 32
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -1,5 +1,6 @@
 using Aspose.Cells;
 using FluentValidation;
+using Humanizer;
 using OASystem.API.OAMethodLib;
 using OASystem.API.OAMethodLib.JuHeAPI;
 using OASystem.Domain.AesEncryption;
@@ -72,11 +73,11 @@ namespace OASystem.API.Controllers
         ///  团组报表
         ///  Items 
         /// </summary>
-        /// <param name="_dto">团组列表请求dto</param>
+        /// <param name="dto">团组列表请求dto</param>
         /// <returns></returns>
         [HttpPost("PostGroupStatementItems")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto _dto)
+        public async Task<IActionResult> PostGroupStatementItems(GroupStatementItemsDto dto)
         {
             #region  参数验证
             if (_dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
@@ -90,49 +91,118 @@ namespace OASystem.API.Controllers
             #endregion
 
             #endregion
-            if (_dto.PortType == 1 || _dto.PortType == 2 || _dto.PortType == 3) // web/Android/IOS
+            if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) // web/Android/IOS
             {
-                string sqlWhere = string.Empty;
-                if (_dto.IsSure == 0) //未完成
+                // 构建基础查询
+                var query = _sqlSugar.Queryable<Grp_DelegationInfo, Sys_SetData, Sys_SetData, Sys_Users, Fin_ProceedsReceived>(
+                        (gdi, ssd, ssd1, su, pr) => new JoinQueryInfos(
+                            JoinType.Left, gdi.TeamDid == ssd.Id,
+                            JoinType.Left, gdi.TeamLevSId == ssd1.Id,
+                            JoinType.Left, gdi.JietuanOperator == su.Id,
+                            JoinType.Left, gdi.Id == pr.Diid
+                        )
+                    )
+                    .Where((gdi, ssd, ssd1, su, pr) => gdi.IsDel == 0)
+                    .Select((gdi, ssd, ssd1, su, pr) => new GroupStatementItemView
+                    {
+                        Id = gdi.Id,
+                        TourCode = gdi.TourCode,
+                        TeamName = gdi.TeamName,
+                        ClientName = gdi.ClientName,
+                        ClientUnit = gdi.ClientUnit,
+                        VisitDate = gdi.VisitDate,
+                        VisitDays = gdi.VisitDays,
+                        VisitPNumber = gdi.VisitPNumber,
+                        IsSure = gdi.IsSure,
+                        TeamTypeId = ssd.Id,
+                        TeamType = ssd.Name,
+                        TeamLevId = ssd1.Id,
+                        TeamLev = ssd1.Name,
+                        JietuanOperator = su.CnName,
+                        LastCollectionTime = SqlFunc.AggregateMax(pr.CreateTime)
+                    });
+
+                // 完成状态筛选
+                if (dto.IsSure == 0) // 未完成
                 {
-                    sqlWhere += string.Format(@" And IsSure = 0");
+                    query = query.Where(gdi => gdi.IsSure == 0);
                 }
-                else if (_dto.IsSure == 1) //已完成
+                else if (dto.IsSure == 1) // 已完成
                 {
-                    sqlWhere += string.Format(@" And IsSure = 1");
+                    query = query.Where(gdi => gdi.IsSure == 1);
                 }
 
-                if (!string.IsNullOrEmpty(_dto.SearchCriteria))
+                // 高级搜索处理
+                if (!string.IsNullOrEmpty(dto.SearchCriteria))
                 {
-                    string tj = _dto.SearchCriteria;
-                    sqlWhere += string.Format(@"And (ssd.Name Like '%{0}%' Or TeamName Like '%{1}%' Or ClientName Like '%{2}%' Or  ClientName Like '%{3}%' Or su.CnName  Like '%{4}%')",
-                       tj, tj, tj, tj, tj);
+                    string searchTerm = dto.SearchCriteria;
+
+                    // 搜索字段列表(对应查询中的字段)
+                    var searchFields = new List<string>
+                    {
+                        "TeamName",         // 团队名称
+                        "ClientName",       // 客户名称
+                        "JietuanOperator",  // 接团操作员
+                        "TourCode",         // 团号
+                        "ClientUnit",       // 客户单位
+                        "TeamType",         // 团队类型
+                        "TeamLev"           // 团队级别
+                    };
+
+                    // 搜索配置
+                    var searchConfig = new SearchConfig
+                    {
+                        EnableExactMatch = true,
+                        EnablePrefixMatch = true,
+                        EnableFuzzySearch = true,
+                        EnableCharSearch = true,
+                        RequireAllWords = true,
+                        RequireAllChars = false,
+                        EnableSmartSplitting = true,
+                        MinSplitLength = 4
+                    };
+
+                    // 构建搜索条件
+                    var (searchCondition, searchParameters) = AdvancedSearchHelper.BuildEnhancedSearchCondition(
+                        searchTerm: searchTerm,
+                        searchFields: searchFields,
+                        prefix: "search_groupExcel_",
+                        searchMode: SearchMode.AutoDetect,
+                        combinationMode: CombinationMode.SmartMix,
+                        config: searchConfig
+                    );
+
+                    if (!string.IsNullOrEmpty(searchCondition))
+                    {
+                        // 添加搜索条件和参数
+                        query = query.Where(searchCondition, searchParameters.ToArray());
+                    }
+                    else
+                    {
+                        // 回退到简单搜索
+                        query = query.Where(gdi =>
+                            gdi.TeamName.Contains(searchTerm) ||
+                            gdi.ClientName.Contains(searchTerm) ||
+                            gdi.JietuanOperator.Contains(searchTerm) ||
+                            gdi.TourCode.Contains(searchTerm) ||
+                            gdi.ClientUnit.Contains(searchTerm) ||
+                            gdi.TeamType.Contains(searchTerm) ||
+                            gdi.TeamLev.Contains(searchTerm));
+                    }
                 }
 
-                string sql = string.Format(@"Select row_number() over(order by gdi.VisitStartDate Desc) as Row_Number, 
-											    gdi.Id,TourCode,ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,
-											    ClientName,ClientUnit,VisitDate,ssd.Id TeamTypeId, ssd.Name TeamType,
-											    VisitDays,VisitPNumber,su.CnName JietuanOperator,IsSure,gdi.CreateTime,
-											    pr.LastCollectionTime
-											    From  Grp_DelegationInfo gdi
-											    Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
-											    Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
-											    Left Join Sys_Users su On gdi.JietuanOperator = su.Id
-											    Left Join (
-												    SELECT Diid, MAX(CreateTime) LastCollectionTime
-												    FROM Fin_ProceedsReceived
-												    Where IsDel = 0
-												    GROUP BY Diid
-											    ) pr On gdi.Id = pr.Diid
-										    Where gdi.IsDel = 0 {0} ", sqlWhere);
-
-                RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
-                var _DelegationList = await _sqlSugar.SqlQueryable<GroupStatementItemView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);//ToPageAsync
+                // 获取总数
+                RefAsync<int> total = 0;
+
+                // 执行分页查询
+                var delegationList = await query
+                    .OrderByDescending(gdi => gdi.VisitDate)
+                    .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
 
                 var _view = new
                 {
                     PageFuncAuth = pageFunAuthView,
-                    Data = _DelegationList
+                    Data = delegationList
                 };
                 return Ok(JsonView(true, "查询成功!", _view, total));