From fb98eea517acdef61d9d9c1a1f537a728282fac9 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期五, 22 八月 2025 10:01:54 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.CommonServer.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs | 103 ++++++++++++++++++++++++++++----------------------- 1 files changed, 57 insertions(+), 46 deletions(-) diff --git a/FlexJobApi.CommonServer.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs b/FlexJobApi.CommonServer.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs index 5443518..002d01e 100644 --- a/FlexJobApi.CommonServer.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs +++ b/FlexJobApi.CommonServer.Application/Dictionaries/Queries/DictionaryDatasQueryHandler.cs @@ -4,11 +4,13 @@ using Mapster; using MediatR; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace FlexJobApi.CommonServer.Application { @@ -74,55 +76,64 @@ /// <returns></returns> public async Task<List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>>> Handle(GetDictionaryDataSelectQuery request, CancellationToken cancellationToken) { - var models = await request.GetSelect<DictionaryData, string, GetDictionaryDataSelectQueryResultOption>( - it => it.Code, - it => it.Content, - q => - { - q = q - .OrderBy(it => it.Sort) - .Where(it => !it.IsDisabled); - if (request.All != true) - { - q = q.Where(it => it.ParentId == request.ParentId); - } - if (request.MaxDeep.HasValue) - { - q = q.Where(it => it.Deep <= request.MaxDeep); - } - if (request.Keywords.IsNotNull()) - { - q = q.Where(it => - it.Code.Contains(request.Keywords) - || it.Content.Contains(request.Keywords) - || it.Field1.Contains(request.Keywords) - || it.Field2.Contains(request.Keywords) - || it.Field3.Contains(request.Keywords) - || it.Field4.Contains(request.Keywords) - || it.Field5.Contains(request.Keywords)); - } - if (request.CategoryId.HasValue) - { - q = q.Where(it => it.CategoryId == request.CategoryId); - } - else if (request.CategoryCode.IsNotNull()) - { - q = q.Where(it => it.Category.Code == request.CategoryCode); - } - else - { - throw Oops.Oh(EnumErrorCodeType.s400, "璇峰~鍐欑被鍒獻d鎴栫紪鍙�"); - } - return q; - }, - cancellationToken); - if (request.WithChildren) + var sql = @"SELECT d.* FROM DictionaryData d +INNER JOIN DictionaryCategory c ON d.CategoryId = c.Id +WHERE d.IsDisabled = 0"; + if (request.All != true) { - var parents = models.Where(it => it.Data.ParentId == null).ToList(); - LoopChildrens(parents, models); + if (request.ParentId == null) + { + sql += " AND d.ParentId IS NULL"; + } + else + { + sql += " AND d.ParentId = @ParentId"; + } + } + if (request.MaxDeep.HasValue) + { + sql += " AND d.Deep <= @MaxDeep"; + } + if (request.Keywords.IsNotNull()) + { + sql += @" AND (d.Code LIKE @Keywords +OR d.Content LIKE @Keywords +OR d.Field1 LIKE @Keywords +OR d.Field2 LIKE @Keywords +OR d.Field3 LIKE @Keywords +OR d.Field4 LIKE @Keywords +OR d.Field5 LIKE @Keywords)"; + } + if (request.CategoryId.HasValue) + { + sql += " AND d.CategoryId = @CategoryId"; + } + else if (request.CategoryCode.IsNotNull()) + { + sql += " AND c.Code = @CategoryCode"; + } + else + { + throw Oops.Oh(EnumErrorCodeType.s400, "璇峰~鍐欑被鍒獻d鎴栫紪鍙�"); + } + sql += " ORDER BY d.Sort"; + var models = await rep.SqlQueriesAsync<GetDictionaryDataSelectQueryResultOption>(sql, request, cancellationToken); + var options = new List<SelectOption<string, GetDictionaryDataSelectQueryResultOption>>(); + foreach (var model in models) + { + var option = new SelectOption<string, GetDictionaryDataSelectQueryResultOption>(); + option.Data = model; + option.Value = model.Code; + option.Label = model.Content; + options.Add(option); + } + if (request.WithChildren == true) + { + var parents = options.Where(it => it.Data.ParentId == null).ToList(); + LoopChildrens(parents, options); return parents; } - return models; + return options; } /// <summary> -- Gitblit v1.9.1