[圖資管理] 資料結構調整 | API 調整 | [歷史資料] API GetDevice 調整

This commit is contained in:
dev01 2023-05-16 12:15:38 +08:00
parent 8c0738addf
commit 68ef0a1685
3 changed files with 58 additions and 41 deletions

View File

@ -40,21 +40,21 @@ namespace FrontendWebApi.ApiControllers
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<List<Variable>>> VarList() public async Task<ApiResult<List<GraphManageTree>>> GraphManageTreeList()
{ {
ApiResult<List<Variable>> apiResult = new ApiResult<List<Variable>>(); ApiResult<List<GraphManageTree>> apiResult = new ApiResult<List<GraphManageTree>>();
List<Variable> variables = new List<Variable>(); List<GraphManageTree> gmTree = new List<GraphManageTree>();
try try
{ {
var sqlString = @$"select * from variable var sqlString = @$"select * from graph_manage_tree
where system_type = 'graph_manage_layer' and deleted = 0 where deleted = 0
order by id asc"; order by id asc";
variables = await backendRepository.GetAllAsync<Variable>(sqlString); gmTree = await backendRepository.GetAllAsync<GraphManageTree>(sqlString);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = variables; apiResult.Data = gmTree;
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -72,25 +72,24 @@ namespace FrontendWebApi.ApiControllers
/// <param name="gv"></param> /// <param name="gv"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> SaveVar([FromBody] GraphVar gv) public async Task<ApiResult<string>> SaveGraphManageTree([FromBody] GraphManageTree gmTree)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
Dictionary<string, object> variable = new Dictionary<string, object>(); Dictionary<string, object> newGmTree = new Dictionary<string, object>();
var system_priority = backendRepository.GetOneAsync<string>("select system_priority from variable where system_type = @graph_manage_layer and deleted = 0 order by system_priority desc limit 1", new { graph_manage_layer = graph_manage_layer }).Result; var system_priority = backendRepository.GetOneAsync<string>("select priority from graph_manage_tree where deleted = 0 order by priority desc limit 1").Result;
variable.Add("@deleted", 0); newGmTree.Add("@deleted", 0);
variable.Add("@system_type", graph_manage_layer); newGmTree.Add("@name", gmTree.name);
variable.Add("@system_key", gv.system_key); newGmTree.Add("@parent_id", gmTree.parent_id);
variable.Add("@system_parent_id", gv.system_parent_id); newGmTree.Add("@remark", "圖資管理-" + gmTree.name);
variable.Add("@system_remark", "圖資管理-" + gv.system_key); newGmTree.Add("@priority", Int32.Parse(system_priority) + 1);
variable.Add("@system_priority", Int32.Parse(system_priority) + 1);
variable.Add("@created_by", myUser.userinfo_guid); newGmTree.Add("@created_by", myUser.userinfo_guid);
variable.Add("@created_at", DateTime.Now); newGmTree.Add("@created_at", DateTime.Now);
var id = await backendRepository.AddOneByCustomTableReturnId(variable, "variable"); var id = await backendRepository.AddOneByCustomTableReturnId(newGmTree, "graph_manage_tree");
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = id.ToString(); apiResult.Data = id.ToString();
} }
@ -98,7 +97,7 @@ namespace FrontendWebApi.ApiControllers
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
string json = System.Text.Json.JsonSerializer.Serialize(gv); string json = System.Text.Json.JsonSerializer.Serialize(gmTree);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
} }
@ -112,10 +111,10 @@ namespace FrontendWebApi.ApiControllers
/// <param name="gv"></param> /// <param name="gv"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> EditVar([FromBody] GraphVar gv) public async Task<ApiResult<string>> EditGraphManageTree([FromBody] GraphManageTree gmTree)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
var gm = await backendRepository.GetOneAsync<GraphInsInfo>("select * from variable where id = @id and deleted = 0", new { @id = gv.id }); var gm = await backendRepository.GetOneAsync<GraphInsInfo>("select * from graph_manage_tree where id = @id and deleted = 0", new { @id = gmTree.id });
if (gm == null) if (gm == null)
{ {
@ -126,13 +125,14 @@ namespace FrontendWebApi.ApiControllers
try try
{ {
Dictionary<string, object> variable = new Dictionary<string, object>(); Dictionary<string, object> newGmTree = new Dictionary<string, object>();
variable.Add("@system_key", gv.system_key); newGmTree.Add("@name", gmTree.name);
variable.Add("@updated_by", myUser.userinfo_guid); newGmTree.Add("@remark", "圖資管理-" + gmTree.name);
variable.Add("@updated_at", DateTime.Now); newGmTree.Add("@updated_by", myUser.userinfo_guid);
newGmTree.Add("@updated_at", DateTime.Now);
await backendRepository.UpdateOneByCustomTable(variable, "variable", "id = " + gv.id); await backendRepository.UpdateOneByCustomTable(newGmTree, "graph_manage_tree", "id = " + gmTree.id);
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = "編輯成功"; apiResult.Data = "編輯成功";
} }
@ -140,7 +140,7 @@ namespace FrontendWebApi.ApiControllers
{ {
apiResult.Code = "9999"; apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
string json = System.Text.Json.JsonSerializer.Serialize(gv); string json = System.Text.Json.JsonSerializer.Serialize(gmTree);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); Logger.LogError("【" + controllerName + "/" + actionName + "】" + json);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
} }
@ -154,15 +154,15 @@ namespace FrontendWebApi.ApiControllers
/// <param name="gv"></param> /// <param name="gv"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<string>> DelVar([FromBody] GraphVar gv) public async Task<ApiResult<string>> DelGraphManageTree([FromBody] GraphManageTree gmTree)
{ {
ApiResult<string> apiResult = new ApiResult<string>(); ApiResult<string> apiResult = new ApiResult<string>();
try try
{ {
var sqlString = @$"UPDATE variable SET deleted = 1, updated_at = @time, updated_by = @user WHERE id = @id"; var sqlString = @$"UPDATE graph_manage_tree SET deleted = 1, updated_at = @time, updated_by = @user WHERE id = @id";
var param = new { @id = gv.id, @time = DateTime.Now, @user = myUser.userinfo_guid }; var param = new { @id = gmTree.id, @time = DateTime.Now, @user = myUser.userinfo_guid };
await backendRepository.ExecuteSql(sqlString, param); await backendRepository.ExecuteSql(sqlString, param);
apiResult.Code = "0000"; apiResult.Code = "0000";
@ -185,21 +185,21 @@ namespace FrontendWebApi.ApiControllers
List<GraphList> graManList = new List<GraphList>(); List<GraphList> graManList = new List<GraphList>();
try try
{ {
var param = new { layer_id = gi.layer_id , graph_manage_layer = graph_manage_layer }; var param = new { layer_id = gi.layer_id , graph_manage_layer = graph_manage_layer, keyWord = gi.keyWord };
if (gi.keyWord != null && !string.IsNullOrEmpty(gi.keyWord)) if (gi.keyWord != null && !string.IsNullOrEmpty(gi.keyWord))
{ {
graManList = await backendRepository.GetAllAsync<GraphList>(@$"SELECT gm.* graManList = await backendRepository.GetAllAsync<GraphList>(@$"SELECT gm.*
FROM graph_manage gm FROM graph_manage gm
JOIN variable v1 ON v1.id = @layer_id and v1.system_type = @graph_manage_layer and v1.deleted = 0 JOIN graph_manage_tree gmtree ON gmtree.id = @layer_id and gmtree.deleted = 0
WHERE gm.deleted = 0 WHERE 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}%') AND (gm.code like '%{gi.keyWord}%' OR gm.name like '%@keyWord%' OR gm.oriOrgName like '%@keyWord%' OR gm.donOrgName like '%@keyWord%')
ORDER BY gm.priority, gm.created_at desc", param); ORDER BY gm.priority, gm.created_at desc", param);
} }
else else
{ {
var sqlString = @$"SELECT gm.* var sqlString = @$"SELECT gm.*
FROM graph_manage gm FROM graph_manage gm
JOIN variable v1 ON v1.id = @layer_id and v1.system_type = @graph_manage_layer and v1.deleted = 0 JOIN graph_manage_tree gmtree ON gmtree.id = @layer_id and gmtree.deleted = 0
WHERE gm.deleted = 0 and gm.layer_id = @layer_id WHERE gm.deleted = 0 and gm.layer_id = @layer_id
ORDER BY gm.priority, gm.created_at desc"; ORDER BY gm.priority, gm.created_at desc";
@ -228,7 +228,7 @@ namespace FrontendWebApi.ApiControllers
{ {
var sqlString = @$"SELECT * var sqlString = @$"SELECT *
FROM graph_manage gm FROM graph_manage gm
JOIN variable v1 ON convert(v1.id, nchar) = gm.layer_id and v1.system_type = @graph_manage_layer and v1.deleted = 0 JOIN graph_manage_tree gmtree ON convert(gmtree.id, nchar) = gm.layer_id and gmtree.deleted = 0
WHERE gm.id = @id AND gm.deleted = 0 WHERE gm.id = @id AND gm.deleted = 0
ORDER BY gm.priority, gm.created_at desc"; ORDER BY gm.priority, gm.created_at desc";

View File

@ -343,7 +343,7 @@ namespace FrontendWebApi.ApiControllers
if (postDevice.SelectFloors != null && postDevice.SelectFloors.Count() > 0) if (postDevice.SelectFloors != null && postDevice.SelectFloors.Count() > 0)
{ {
wheres.Add("d.floor_guid in @floor_guid"); wheres.Add("d.device_floor_tag in @floor_tag");
} }
if (postDevice.SelectSub != null && postDevice.SelectSub.Count() > 0) if (postDevice.SelectSub != null && postDevice.SelectSub.Count() > 0)
@ -373,7 +373,7 @@ namespace FrontendWebApi.ApiControllers
join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3' join variable v2 on v2.system_value = a.device_name_tag and v2.deleted = 0 and v2.system_type = 'device_system_category_layer3'
order by b.priority,v1.system_priority,v2.system_priority,a.priority"; order by b.priority,v1.system_priority,v2.system_priority,a.priority";
var dbDevice = await backendRepository.GetAllAsync<History_GetDevice>(sql, new { builds = postDevice.SelectBuildings, floor_guid = postDevice.SelectFloors, syss = postDevice.SelectSub, device_name = postDevice.Device_name }); var dbDevice = await backendRepository.GetAllAsync<History_GetDevice>(sql, new { builds = postDevice.SelectBuildings, floor_tag = postDevice.SelectFloors, syss = postDevice.SelectSub, device_name = postDevice.Device_name });
apiResult.Data = dbDevice; apiResult.Data = dbDevice;
apiResult.Code = "0000"; apiResult.Code = "0000";
} }
@ -863,7 +863,7 @@ namespace FrontendWebApi.ApiControllers
from variable v2 from variable v2
inner join variable v1 on v2.system_parent_id = v1.id inner join variable v1 on v2.system_parent_id = v1.id
where v2.deleted = 0 and where v2.deleted = 0 and
v2.system_value in ( v2.id in (
select ap.ShowView select ap.ShowView
from role_auth ra from role_auth ra
inner join auth_page ap on ra.AuthCode = ap.AuthCode inner join auth_page ap on ra.AuthCode = ap.AuthCode

View File

@ -58,4 +58,21 @@ namespace FrontendWebApi.Models
public string system_type { get; set; } public string system_type { get; set; }
public int system_parent_id { get; set; } public int system_parent_id { get; set; }
} }
public class GraphManageTree
{
public int id { get; set; }
public short deleted { get; set; }
public string name{ get; set; }
public string remark{ get; set; }
public int priority{ get; set; }
public int parent_id { get; set; }
public string created_by { get; set; }
public DateTime created_at { get; set; }
public string updated_by { get; set; }
public DateTime? updated_at { get; set; }
}
} }