Преглед изворни кода

搜索控制器 -> 新增 团组各项费用录入 关键字输入提示(智能版) 接口

Lyyyi пре 2 дана
родитељ
комит
d02f7d868c

Разлика између датотеке није приказан због своје велике величине
+ 655 - 230
OASystem/OASystem.Api/Controllers/GroupsController.cs


+ 156 - 1
OASystem/OASystem.Api/Controllers/SearchController.cs

@@ -211,7 +211,6 @@ namespace OASystem.API.Controllers
 
         }
 
-
         /// <summary>
         /// 客户资料
         /// </summary>
@@ -466,5 +465,161 @@ namespace OASystem.API.Controllers
                 return Ok(JsonView(true, $"搜索服务暂时不可用!"));
             }
         }
+
+        /// <summary>
+        /// 团组各项费用录入 关键字输入提示(智能版)
+        /// 76	酒店预订
+        /// 79	车/导游地接
+        /// 80	签证
+        /// 81	邀请/公务活动
+        /// 82	团组客户保险
+        /// 85	机票预订
+        /// 98	其他款项
+        /// 285	收款退还
+        /// 1015 超支费用
+        /// 1081 文档下载
+        /// 1466 会务相关
+        /// </summary>
+        /// <param name="userId">用户Id</param>
+        /// <param name="feeType">费用类型</param>
+        /// <param name="keyword">关键字</param>
+        /// <returns></returns>
+        [HttpGet("GroupFeeKeywordSearch/{userId}/{feeType}/{keyword}")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GroupFeeKeywordSearch(int userId, int feeType, string keyword)
+        {
+            try
+            {
+                #region 参数验证
+
+                // 基本参数验证
+                if (userId <= 0)
+                    return Ok(JsonView(false, "用户ID必须大于0!"));
+
+                if (feeType <= 0)
+                    return Ok(JsonView(false, "费用类型必须大于0!"));
+
+                // 验证用户是否存在
+                var userExists = await _sqlSugar.Queryable<Sys_Users>()
+                    .Where(x => x.IsDel == 0 && x.Id == userId)
+                    .AnyAsync();
+
+                if (!userExists)
+                {
+                    return Ok(JsonView(false, "用户不存在或已被删除"));
+                }
+
+                // 验证费用类型是否有效
+                var feeTypeExists = await _sqlSugar.Queryable<Sys_SetData>()
+                    .Where(x => x.IsDel == 0 && x.STid == 16 && x.Id == feeType)
+                    .AnyAsync();
+
+                if (!feeTypeExists)
+                {
+                    return Ok(JsonView(false, "无效的费用类型"));
+                }
+
+                // 验证关键字
+                if (string.IsNullOrWhiteSpace(keyword))
+                {
+                    return Ok(JsonView(false, "请输入搜索关键字"));
+                }
+
+                #endregion
+
+                #region 获取用户有权限的团组ID
+
+                // 获取用户有权限访问的团组ID列表
+                var authorizedGroupIds = await _sqlSugar.Queryable<Grp_GroupsTaskAssignment>()
+                    .Where(x => x.IsDel == 0 && x.UId == userId && x.CTId == feeType)
+                    .Select(x => x.DIId)
+                    .Distinct()
+                    .ToListAsync();
+
+                if (!authorizedGroupIds.Any())
+                {
+                    return Ok(JsonView(true, "暂无数据", new List<object>(), 0));
+                }
+
+                #endregion
+
+                #region 构建搜索请求
+
+                var searchRequest = new DynamicSearchRequest
+                {
+                    Keyword = keyword.Trim(),
+                    RequireAllSingleChars = true,
+                    PageIndex = 1,
+                    PageSize = 20, // 限制返回数量,提高性能
+                    FieldWeights = new Dictionary<string, int>
+                    {
+                        { "TeamName", 10 }
+                    },
+                    Filters = new List<SearchFilter>
+                    {
+                        new SearchFilter { Field = "IsDel", Operator = "eq", Value = "0" },
+                        new SearchFilter { Field = "Id", Operator = "in", Values = authorizedGroupIds.ConvertAll<object>(x => x) }
+                    },
+                    OrderBy = "VisitDate", // 添加排序方向
+                    ReturnFields = new List<string> { "Id", "TeamName" } // 添加ID字段
+                };
+
+                #endregion
+
+                #region 字段配置验证
+
+                var validation = _groupSearchService.ValidateFieldConfig(
+                    searchRequest.FieldWeights,
+                    searchRequest.ReturnFields);
+
+                if (!validation.IsValid)
+                {
+                    return Ok(JsonView(false, $"字段配置错误: {validation.Message}"));
+                }
+
+                #endregion
+
+                #region 执行搜索
+
+                var result = await _groupSearchService.SearchAsync(searchRequest);
+
+                if (!result.Success)
+                {
+                    return Ok(JsonView(false, result.Message ?? "搜索失败"));
+                }
+
+                if (result.Items == null || !result.Items.Any())
+                {
+                    return Ok(JsonView(true, "未找到匹配的团组", new List<object>(), 0));
+                }
+
+                #endregion
+
+                #region 构建返回数据
+
+                var responseData = result.Items
+                    .Where(item => item.Data != null)
+                    .Select(item => new
+                    {
+                        Id = item.Data.Id,
+                        TeamName = item.Data.TeamName
+                    })
+                    .Where(x => !string.IsNullOrWhiteSpace(x.TeamName)) // 过滤空名称
+                    .Distinct() // 去重
+                    .ToList();
+
+                #endregion
+
+                return Ok(JsonView(true, "搜索成功", responseData, responseData.Count));
+            }
+            catch (Exception ex)
+            {
+                // 记录日志(实际项目中应该使用日志框架)
+                // _logger.LogError(ex, "团组费用关键字搜索失败,用户ID: {UserId}, 费用类型: {FeeType}", userId, feeType);
+
+                // 生产环境中不要返回详细的错误信息
+                return Ok(JsonView(false, "搜索服务暂时不可用,请稍后重试"));
+            }
+        }
     }
 }