From 33a0a3c4773cb01df81c4127e542f0d64c56e001 Mon Sep 17 00:00:00 2001 From: dev02 Date: Wed, 9 Nov 2022 18:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=96=E8=B3=87api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/GraphManageController.cs | 39 ++++++++++++------- FrontendWebApi/Models/GraphManage.cs | 3 ++ 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/FrontendWebApi/ApiControllers/GraphManageController.cs b/FrontendWebApi/ApiControllers/GraphManageController.cs index 7d66318..dd0e2e8 100644 --- a/FrontendWebApi/ApiControllers/GraphManageController.cs +++ b/FrontendWebApi/ApiControllers/GraphManageController.cs @@ -100,8 +100,8 @@ namespace FrontendWebApi.ApiControllers { var sqlString = @$"SELECT * 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 - JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 + 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"; @@ -115,8 +115,9 @@ namespace FrontendWebApi.ApiControllers 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(@$"SELECT * FROM graph_manage gm - JOIN variable v2 ON gm.sub_system_id = v2.id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 - WHERE v2.id in @sub_system_id AND gm.deleted = 0 + 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); } @@ -143,12 +144,12 @@ namespace FrontendWebApi.ApiControllers { var sqlString = @$"SELECT * 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 - JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 - WHERE v2.system_value = @sub_system_tag AND gm.deleted = 0 AND gm.code = @code + JOIN variable v1 ON v1.system_value = gm.main_system_tag and v1.system_type = @graph_manage_layer1 and v1.deleted = 0 + JOIN variable v2 ON v1.id = v2.system_parent_id AND v2.system_type = @graph_manage_layer2 AND v2.deleted = 0 and v2.system_value = gm.sub_system_tag + WHERE gm.id = @id 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, @code = gi.code }; + var param = new { @id = gi.id }; graManList = await backendRepository.GetOneAsync(sqlString, param); @@ -179,9 +180,9 @@ namespace FrontendWebApi.ApiControllers try { - var sqlString = @$"UPDATE graph_manage SET deleted = 1, updated_at = @time, updated_by = @user WHERE code = @code AND sub_system_tag = @sub_system_tag AND main_system_tag = @main_system_tag"; + var sqlString = @$"UPDATE graph_manage SET deleted = 1, updated_at = @time, updated_by = @user WHERE id = @id"; - var param = new { @code = gi.code, @sub_system_tag = gi.sub_system_tag, @main_system_tag = gi.main_system_tag, @time = DateTime.Now, @user = myUser.userinfo_guid }; + var param = new { @id = gi.id, @time = DateTime.Now, @user = myUser.userinfo_guid }; await backendRepository.ExecuteSql(sqlString, param); apiResult.Code = "0000"; @@ -204,8 +205,8 @@ namespace FrontendWebApi.ApiControllers try { - var sWhere = @$"deleted = 0 AND code = @code AND sub_system_tag = @sub_system_tag AND main_system_tag = @main_system_tag"; - var gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @code = gii.code, @sub_system_tag = gii.sub_system_tag, @main_system_tag = gii.main_system_tag}); + var sWhere = @$"deleted = 0 AND id = @id"; + var gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @id = gii.id }); if (gm == null) { @@ -214,6 +215,16 @@ namespace FrontendWebApi.ApiControllers return apiResult; } + sWhere = $@"deleted = 0 and id != @id and code = @code and sub_system_tag = @sub_system_tag and main_system_tag = @main_system_tag"; + gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @id = gii.id, @code = gii.code, @sub_system_tag = gii.sub_system_tag, @main_system_tag = gii.main_system_tag }); + + if (gm != null) + { + apiResult.Code = "0002"; + apiResult.Data = "無法找到圖資"; + return apiResult; + } + Dictionary graph_manage = new Dictionary(); //edit file @@ -264,7 +275,7 @@ namespace FrontendWebApi.ApiControllers graph_manage.Add("@oriSavName", fileName); } } - + graph_manage.Add("@code", gii.code); graph_manage.Add("@name", gii.name); graph_manage.Add("@main_system_tag", gii.main_system_tag); graph_manage.Add("@sub_system_tag", gii.sub_system_tag); @@ -272,7 +283,7 @@ namespace FrontendWebApi.ApiControllers graph_manage.Add("@updated_by", myUser.userinfo_guid); //graph_manage.Add("@priority", gii.priority); - await backendRepository.UpdateOneByCustomTable(graph_manage, "graph_manage", "code='" + gm.code + "'" + " and sub_system_tag ='" + gm.sub_system_tag + "' and main_system_tag = '" + gm.main_system_tag + "'"); + await backendRepository.UpdateOneByCustomTable(graph_manage, "graph_manage", "id = " + gii.id); apiResult.Code = "0000"; apiResult.Data = "修改成功"; } diff --git a/FrontendWebApi/Models/GraphManage.cs b/FrontendWebApi/Models/GraphManage.cs index 2a39fd5..ffeb4e6 100644 --- a/FrontendWebApi/Models/GraphManage.cs +++ b/FrontendWebApi/Models/GraphManage.cs @@ -8,6 +8,7 @@ namespace FrontendWebApi.Models { public class GraphList { + public int id { get; set; } public string code { get; set; } public string main_system_tag { get; set; } public int sub_system_tag { get; set; } @@ -20,6 +21,7 @@ namespace FrontendWebApi.Models public class GraphInsInfo { + public int id { get; set; } public string code { get; set; } public string main_system_tag { get; set; } public string sub_system_tag { get; set; } @@ -35,6 +37,7 @@ namespace FrontendWebApi.Models public class GraphInfo: Actor { + public int id { get; set; } public string code { get; set; } public string main_system_tag { get; set; } public List sub_system_tag { get; set; }