修改搜尋問題

This commit is contained in:
dev02 2022-11-11 10:12:27 +08:00
parent b3acc32126
commit 89c2b0da8f

View File

@ -10,6 +10,7 @@ using System.Linq;
using Repository.BackendRepository.Interface;
using Repository.FrontendRepository.Interface;
using System.IO;
using static Microsoft.Extensions.Logging.EventSource.LoggingEventSource;
namespace FrontendWebApi.ApiControllers
{
@ -98,28 +99,27 @@ namespace FrontendWebApi.ApiControllers
List<GraphList> graManList = new List<GraphList>();
try
{
var sqlString = @$"SELECT gm.*
var param = new { @graph_manage_layer1 = graph_manage_layer1, @graph_manage_layer2 = graph_manage_layer2, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag };
if (gi.keyWord != null && !string.IsNullOrEmpty(gi.keyWord))
{
graManList = await backendRepository.GetAllAsync<GraphList>(@$"SELECT gm.*
FROM graph_manage gm
JOIN variable v1 ON v1.system_value = @main_system_tag and v1.system_type = @graph_manage_layer1 and v1.deleted = 0 AND convert(v1.system_value, nchar) = gm.main_system_tag
JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 and convert(v2.system_value, nchar) = gm.sub_system_tag
WHERE v2.system_value in @sub_system_tag AND gm.deleted = 0
AND (gm.code like '%{gi.keyWord}%' OR gm.name like '%{gi.keyWord}%' OR gm.oriOrgName like '%{gi.keyWord}%' OR gm.donOrgName like '%{gi.keyWord}%')
ORDER BY gm.priority, gm.created_at desc", param);
}
else
{
var sqlString = @$"SELECT gm.*
FROM graph_manage gm
JOIN variable v1 ON v1.system_value = @main_system_tag and v1.system_type = @graph_manage_layer1 and v1.deleted = 0 AND convert(v1.system_value, nchar) = gm.main_system_tag
JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 AND convert(v2.system_value, nchar) = gm.sub_system_tag
WHERE v2.system_value in @sub_system_tag AND gm.deleted = 0
ORDER BY gm.priority, gm.created_at desc";
var param = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag };
graManList = await backendRepository.GetAllAsync<GraphList>(sqlString, param);
if (gi.keyWord != null)
{
var wParam = new { @graph_manage_layer1 = graph_manage_layer1, graph_manage_layer2 = graph_manage_layer2, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag, @keyWord = gi.keyWord };
graManList = await backendRepository.GetAllAsync<GraphList>(@$"SELECT gm.*
FROM graph_manage gm
JOIN variable v1 ON v1.system_value = @main_system_tag and v1.system_type = @graph_manage_layer1 and v1.deleted = 0 AND convert(v1.system_value, nchar) = gm.main_system_tag
JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 and convert(v2.system_value, nchar) = gm.sub_system_tag
WHERE v2.system_value in @sub_system_tag AND gm.deleted = 0
AND (code like '%@keyWord%' OR name like '%@keyWord%' OR oriOrgName like '%@keyWord%' OR donOrgName like '%@keyWord%')
ORDER BY gm.priority, gm.created_at desc", wParam);
graManList = await backendRepository.GetAllAsync<GraphList>(sqlString, param);
}
apiResult.Code = "0000";