diff --git a/FrontendWebApi/ApiControllers/GraphManageController.cs b/FrontendWebApi/ApiControllers/GraphManageController.cs index dd0e2e8..4616afd 100644 --- a/FrontendWebApi/ApiControllers/GraphManageController.cs +++ b/FrontendWebApi/ApiControllers/GraphManageController.cs @@ -98,7 +98,7 @@ namespace FrontendWebApi.ApiControllers List graManList = new List(); try { - var sqlString = @$"SELECT * + 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 @@ -113,7 +113,7 @@ namespace FrontendWebApi.ApiControllers 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(@$"SELECT * + graManList = await backendRepository.GetAllAsync(@$"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 @@ -144,12 +144,12 @@ namespace FrontendWebApi.ApiControllers { var sqlString = @$"SELECT * FROM graph_manage gm - 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 + JOIN variable v1 ON convert(v1.system_value, nchar) = 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 convert(v2.system_value, nchar) = gm.sub_system_tag WHERE gm.id = @id ORDER BY gm.priority, gm.created_at desc"; - var param = new { @id = gi.id }; + var param = new { @id = gi.id , @graph_manage_layer1 = graph_manage_layer1, @graph_manage_layer2 = graph_manage_layer2 }; graManList = await backendRepository.GetOneAsync(sqlString, param); @@ -205,18 +205,9 @@ namespace FrontendWebApi.ApiControllers try { - var sWhere = @$"deleted = 0 AND id = @id"; - var gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @id = gii.id }); - - if (gm == null) - { - apiResult.Code = "0001"; - apiResult.Data = "無法找到圖資"; - 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 }); + var sWhere = $@"deleted = 0 and id != @id 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 { @id = gii.id, @code = gii.code, @sub_system_tag = gii.sub_system_tag, @main_system_tag = gii.main_system_tag }); if (gm != null) { @@ -225,56 +216,103 @@ namespace FrontendWebApi.ApiControllers return apiResult; } + sWhere = @$"deleted = 0 AND id = @id"; + gm = await backendRepository.GetOneAsync("graph_manage", sWhere, new { @id = gii.id }); + + if (gm == null) + { + apiResult.Code = "0001"; + apiResult.Data = "無法找到圖資"; + return apiResult; + } + + Dictionary graph_manage = new Dictionary(); - //edit file - if (gii.oriOrgName != null || gii.donOrgName != null) + var new_guid = Guid.NewGuid(); + + //刪除原本檔案 + FolderFunction folderFunction = new FolderFunction(); + folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.oriSavName)); + + var fileName = new_guid + "." + gii.oriOrgName.Split('.')[1]; + + var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) { - if (!System.IO.Directory.Exists(graphManageFileSaveAsPath)) - System.IO.Directory.CreateDirectory(graphManageFileSaveAsPath); - - if (gm.oriSavName != null && gii.oriOrgName != null) - { - var new_guid = Guid.NewGuid(); - - //刪除原本檔案 - FolderFunction folderFunction = new FolderFunction(); - folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.oriSavName)); - - var fileName = new_guid + "." + gii.oriOrgName.Split('.')[1]; - - var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); - - using (var stream = new FileStream(fullPath, FileMode.Create)) - { - gii.oriFile.CopyTo(stream); - } - - graph_manage.Add("@oriOrgName", gii.oriOrgName); - graph_manage.Add("@oriSavName", fileName); - } - - if (gm.donSavName != null && gii.donOrgName != null) - { - var new_guid = Guid.NewGuid(); - - //刪除原本檔案 - FolderFunction folderFunction = new FolderFunction(); - folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.donSavName)); - - var fileName = new_guid + "." + gii.donOrgName.Split('.')[1]; - - var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); - - using (var stream = new FileStream(fullPath, FileMode.Create)) - { - gii.donFile.CopyTo(stream); - } - - graph_manage.Add("@oriOrgName", gii.donOrgName); - graph_manage.Add("@oriSavName", fileName); - } + gii.oriFile.CopyTo(stream); } + + graph_manage.Add("@oriOrgName", gii.oriOrgName); + graph_manage.Add("@oriSavName", fileName); + + new_guid = Guid.NewGuid(); + + //刪除原本檔案 + folderFunction = new FolderFunction(); + folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.donSavName)); + + fileName = new_guid + "." + gii.donOrgName.Split('.')[1]; + + fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + using (var stream = new FileStream(fullPath, FileMode.Create)) + { + gii.donFile.CopyTo(stream); + } + + graph_manage.Add("@oriOrgName", gii.donOrgName); + graph_manage.Add("@oriSavName", fileName); + + //edit file + //if (gii.oriOrgName != null || gii.donOrgName != null) + //{ + // if (!System.IO.Directory.Exists(graphManageFileSaveAsPath)) + // System.IO.Directory.CreateDirectory(graphManageFileSaveAsPath); + + // if (gm.oriSavName != null && gii.oriOrgName != null) + // { + // var new_guid = Guid.NewGuid(); + + // //刪除原本檔案 + // FolderFunction folderFunction = new FolderFunction(); + // folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.oriSavName)); + + // var fileName = new_guid + "." + gii.oriOrgName.Split('.')[1]; + + // var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + // using (var stream = new FileStream(fullPath, FileMode.Create)) + // { + // gii.oriFile.CopyTo(stream); + // } + + // graph_manage.Add("@oriOrgName", gii.oriOrgName); + // graph_manage.Add("@oriSavName", fileName); + // } + + // if (gm.donSavName != null && gii.donOrgName != null) + // { + // var new_guid = Guid.NewGuid(); + + // //刪除原本檔案 + // FolderFunction folderFunction = new FolderFunction(); + // folderFunction.DeleteFile(Path.Combine(graphManageFileSaveAsPath, gm.donSavName)); + + // var fileName = new_guid + "." + gii.donOrgName.Split('.')[1]; + + // var fullPath = Path.Combine(graphManageFileSaveAsPath, fileName); + + // using (var stream = new FileStream(fullPath, FileMode.Create)) + // { + // gii.donFile.CopyTo(stream); + // } + + // graph_manage.Add("@oriOrgName", gii.donOrgName); + // 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); diff --git a/FrontendWebApi/wwwroot/upload/graph_manage/9709a746-063c-4fe1-8827-9cce23bdeb5d.png b/FrontendWebApi/wwwroot/upload/graph_manage/9709a746-063c-4fe1-8827-9cce23bdeb5d.png new file mode 100644 index 0000000..1616986 Binary files /dev/null and b/FrontendWebApi/wwwroot/upload/graph_manage/9709a746-063c-4fe1-8827-9cce23bdeb5d.png differ diff --git a/FrontendWebApi/wwwroot/upload/graph_manage/f34134c8-0211-4fa3-b40c-f08b7628bb13.png b/FrontendWebApi/wwwroot/upload/graph_manage/f34134c8-0211-4fa3-b40c-f08b7628bb13.png new file mode 100644 index 0000000..79096e5 Binary files /dev/null and b/FrontendWebApi/wwwroot/upload/graph_manage/f34134c8-0211-4fa3-b40c-f08b7628bb13.png differ