[Backend]後臺權限規則修整
This commit is contained in:
parent
5b43c7ab63
commit
e9189fe047
@ -54,7 +54,7 @@ namespace Backend.Controllers
|
|||||||
{
|
{
|
||||||
var sqlString = @$"select v.system_value value, v.system_key name
|
var sqlString = @$"select v.system_value value, v.system_key name
|
||||||
from (
|
from (
|
||||||
select main_system_tag from building_menu bm where bm.building_tag = @building_tag and is_link = 1 group by bm.building_tag,bm.main_system_tag
|
select main_system_tag from building_menu bm where bm.building_tag = @building_tag group by bm.building_tag,bm.main_system_tag
|
||||||
) bm
|
) bm
|
||||||
join variable v on v.system_value = bm.main_system_tag AND v.system_type = @main_system_type and v.deleted = 0
|
join variable v on v.system_value = bm.main_system_tag AND v.system_type = @main_system_type and v.deleted = 0
|
||||||
ORDER BY v.system_priority ASC";
|
ORDER BY v.system_priority ASC";
|
||||||
@ -113,7 +113,7 @@ namespace Backend.Controllers
|
|||||||
sv.system_value value, sv.system_key name
|
sv.system_value value, sv.system_key name
|
||||||
from variable sv
|
from variable sv
|
||||||
left join (
|
left join (
|
||||||
select * from building_menu bm where bm.building_tag = @building_tag and is_link = 1
|
select * from building_menu bm where bm.building_tag = @building_tag
|
||||||
) bm
|
) bm
|
||||||
on sv.system_value = bm.sub_system_tag
|
on sv.system_value = bm.sub_system_tag
|
||||||
where bm.sub_system_tag is null and sv.deleted = 0 and sv.system_parent_id in @mainList ORDER BY sv.system_priority ASC, sv.created_at DESC";
|
where bm.sub_system_tag is null and sv.deleted = 0 and sv.system_parent_id in @mainList ORDER BY sv.system_priority ASC, sv.created_at DESC";
|
||||||
@ -139,7 +139,7 @@ namespace Backend.Controllers
|
|||||||
ApiResult<string> apiResult = new ApiResult<string>();
|
ApiResult<string> apiResult = new ApiResult<string>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var get = await backendRepository.GetOneAsync<BuildMenu>("building_menu", $"building_tag = '{buildMenu.building_tag}' and main_system_tag = '{buildMenu.main_system_tag}' and sub_system_tag = '{buildMenu.sub_system_tag}' and is_link = 1");
|
var get = await backendRepository.GetOneAsync<BuildMenu>("building_menu", $"building_tag = '{buildMenu.building_tag}' and main_system_tag = '{buildMenu.main_system_tag}' and sub_system_tag = '{buildMenu.sub_system_tag}'");
|
||||||
if (get == null)
|
if (get == null)
|
||||||
{
|
{
|
||||||
var subV = await backendRepository.GetOneAsync<VariableInfo>("variable", "system_value = @sub_tag and system_type = @sub_system_type", new { sub_tag = buildMenu.sub_system_tag, sub_system_type = sub_system_type });
|
var subV = await backendRepository.GetOneAsync<VariableInfo>("variable", "system_value = @sub_tag and system_type = @sub_system_type", new { sub_tag = buildMenu.sub_system_tag, sub_system_type = sub_system_type });
|
||||||
@ -394,7 +394,7 @@ namespace Backend.Controllers
|
|||||||
join variable sv on bm.sub_system_tag = sv.system_value and sv.system_type = @sub_system_type and sv.deleted = 0
|
join variable sv on bm.sub_system_tag = sv.system_value and sv.system_type = @sub_system_type and sv.deleted = 0
|
||||||
left join floor lf on lf.floor_guid = bm.left_planimetric_floor_guid
|
left join floor lf on lf.floor_guid = bm.left_planimetric_floor_guid
|
||||||
left join floor rf on rf.floor_guid = bm.right_planimetric_floor_guid
|
left join floor rf on rf.floor_guid = bm.right_planimetric_floor_guid
|
||||||
where bm.building_tag = @building_tag and bm.main_system_tag in @MainList and bm.is_link > 0
|
where bm.building_tag = @building_tag and bm.main_system_tag in @MainList
|
||||||
ORDER BY bm.priority, mv.system_priority ASC, sv.system_priority ASC, sv.created_at DESC ",
|
ORDER BY bm.priority, mv.system_priority ASC, sv.system_priority ASC, sv.created_at DESC ",
|
||||||
new { building_tag = post.building_tag, MainList = post.MainList, main_system_type = main_system_type, sub_system_type = sub_system_type });
|
new { building_tag = post.building_tag, MainList = post.MainList, main_system_type = main_system_type, sub_system_type = sub_system_type });
|
||||||
|
|
||||||
|
@ -172,6 +172,12 @@ namespace Backend.Controllers
|
|||||||
stopwatchSection.Stop();
|
stopwatchSection.Stop();
|
||||||
await niagaraDataSynchronizeRepository.KeepTimeLog("InsertBuildingMenu", stopwatchSection.ElapsedMilliseconds);
|
await niagaraDataSynchronizeRepository.KeepTimeLog("InsertBuildingMenu", stopwatchSection.ElapsedMilliseconds);
|
||||||
|
|
||||||
|
stopwatchSection = new Stopwatch();
|
||||||
|
stopwatchSection.Start();
|
||||||
|
await niagaraDataSynchronizeRepository.UpdateAuthPageByBuildingMenu();
|
||||||
|
stopwatchSection.Stop();
|
||||||
|
await niagaraDataSynchronizeRepository.KeepTimeLog("UpdateAuthPageByBuildingMenu", stopwatchSection.ElapsedMilliseconds);
|
||||||
|
|
||||||
stopwatchSection = new Stopwatch();
|
stopwatchSection = new Stopwatch();
|
||||||
stopwatchSection.Start();
|
stopwatchSection.Start();
|
||||||
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
|
||||||
|
@ -355,18 +355,19 @@ namespace Backend.Controllers
|
|||||||
};
|
};
|
||||||
await backendRepository.AddOneByCustomTable(systemSubDic, "variable");
|
await backendRepository.AddOneByCustomTable(systemSubDic, "variable");
|
||||||
|
|
||||||
var systemId = await backendRepository.GetOneAsync<int>($@"select id from variable where system_value = '{post.system_value}' and deleted = 0 and system_parent_id = '{post.system_parent_id}' and system_type = '{sub_system_type}'");
|
// 加入權限的功能統一由區域選單管理新增,故先註解
|
||||||
var buildings = await backendRepository.GetAllAsync<string>($@"select building_tag from building where deleted = 0");
|
//var systemId = await backendRepository.GetOneAsync<int>($@"select id from variable where system_value = '{post.system_value}' and deleted = 0 and system_parent_id = '{post.system_parent_id}' and system_type = '{sub_system_type}'");
|
||||||
var authCode = await backendRepository.GetOneAsync<int>($@"select max(cast(SUBSTRING(authcode, 2) AS UNSIGNED)) from auth_page where authcode like 'F%'");
|
//var buildings = await backendRepository.GetAllAsync<string>($@"select building_tag from building where deleted = 0");
|
||||||
var parentSystemName = await backendRepository.GetOneAsync<string>($@"select system_key from variable where id = {post.system_parent_id}");
|
//var authCode = await backendRepository.GetOneAsync<int>($@"select max(cast(SUBSTRING(authcode, 2) AS UNSIGNED)) from auth_page where authcode like 'F%'");
|
||||||
StringBuilder sb = new StringBuilder();
|
//var parentSystemName = await backendRepository.GetOneAsync<string>($@"select system_key from variable where id = {post.system_parent_id}");
|
||||||
foreach (var b in buildings)
|
//StringBuilder sb = new StringBuilder();
|
||||||
{
|
//foreach (var b in buildings)
|
||||||
sb.Append($@" insert into auth_page(AuthCode, AuthType, MainName, SubName, building_tag, ShowView, created_at)
|
//{
|
||||||
values ('F{++authCode}', '1', '{parentSystemName}', '{post.System_key}', '{b}', '{systemId}', Now());");
|
// sb.Append($@" insert into auth_page(AuthCode, AuthType, MainName, SubName, building_tag, ShowView, created_at)
|
||||||
}
|
// values ('F{++authCode}', '1', '{parentSystemName}', '{post.System_key}', '{b}', '{systemId}', Now());");
|
||||||
|
//}
|
||||||
|
|
||||||
await backendRepository.ExecuteSql(sb.ToString());
|
//await backendRepository.ExecuteSql(sb.ToString());
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Msg = "新增成功";
|
apiResult.Msg = "新增成功";
|
||||||
|
@ -361,7 +361,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
strResponse = sr.ReadToEnd();
|
strResponse = sr.ReadToEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
apiResult.Msg = "執行成功";
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -19,6 +19,7 @@ using Org.BouncyCastle.Asn1.Mozilla;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Repository.BackendRepository.Implement
|
namespace Repository.BackendRepository.Implement
|
||||||
{
|
{
|
||||||
@ -1095,6 +1096,130 @@ namespace Repository.BackendRepository.Implement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根據Building_menu 更新 AuthPage
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task UpdateAuthPageByBuildingMenu()
|
||||||
|
{
|
||||||
|
stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
|
using (IDbConnection conn = GetDbConnection())
|
||||||
|
{
|
||||||
|
conn.Open();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<AuthPage> result;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
//building_menu有,auth_page沒有,且variable有對應的大小類,新增這些權限
|
||||||
|
stopwatchSection = new Stopwatch();
|
||||||
|
stopwatchSection.Start();
|
||||||
|
sb.Append($@"SELECT vm.system_key MainName,vs.system_key SubName,bm.building_tag,vs.id ShowView from building_menu bm
|
||||||
|
left join(SELECT vm.system_value main_system_tag,vs.system_value sub_system_tag,a.building_tag FROM `auth_page` a
|
||||||
|
join variable vs on a.ShowView = vs.id and vs.deleted = 0
|
||||||
|
join variable vm on vs.system_parent_id = vm.id and vm.deleted = 0
|
||||||
|
GROUP BY main_system_tag, sub_system_tag, building_tag) a on a.main_system_tag = bm.main_system_tag
|
||||||
|
and a.sub_system_tag = bm.sub_system_tag and a.building_tag = bm.building_tag
|
||||||
|
join variable vs on bm.sub_system_tag = vs.system_value and vs.system_type = 'device_system_category_layer3' and vs.deleted = 0
|
||||||
|
join variable vm on bm.main_system_tag = vm.system_value and vm.system_type = 'device_system_category_layer2'and vm.deleted = 0
|
||||||
|
WHERE bm.is_link = 1 and a.building_tag is null
|
||||||
|
ORDER BY vs.id");
|
||||||
|
result = (await conn.QueryAsync<AuthPage>(sb.ToString())).ToList<AuthPage>();
|
||||||
|
|
||||||
|
sb.Clear();
|
||||||
|
stopwatchSection.Stop();
|
||||||
|
await KeepTimeLog("filter auth_page from building_menu", stopwatchSection.ElapsedMilliseconds);
|
||||||
|
var max = (await conn.QueryAsync<int>("select ifnull((select Max(CONVERT(SUBSTRING(AuthCode,2,5), SIGNED)) AuthCode from auth_page ap where ap.AuthCode like 'F%'),'0') AuthCode")).First();
|
||||||
|
|
||||||
|
stopwatchSection = new Stopwatch();
|
||||||
|
stopwatchSection.Start();
|
||||||
|
if (result.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var data in result)
|
||||||
|
{
|
||||||
|
StringBuilder sqlString = new StringBuilder();
|
||||||
|
|
||||||
|
sb.Append(@$"insert into auth_page(AuthCode, AuthType, MainName, SubName, building_tag, ShowView, created_at)
|
||||||
|
values ('F{++max}', '1', '{data.MainName}', '{data.SubName}', '{data.building_tag}', '{data.ShowView}', Now());");
|
||||||
|
}
|
||||||
|
if (sb.Length > 0)
|
||||||
|
{
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
sb.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stopwatchSection.Stop();
|
||||||
|
await KeepTimeLog("insert into auth_page", stopwatchSection.ElapsedMilliseconds);
|
||||||
|
|
||||||
|
//auth_page有,building_menu沒有,把auth_code對應的role_auth也一併刪除
|
||||||
|
stopwatchSection = new Stopwatch();
|
||||||
|
stopwatchSection.Start();
|
||||||
|
sb.Append($@"DELETE FROM role_auth WHERE AuthCode in
|
||||||
|
(SELECT ap.AuthCode
|
||||||
|
FROM (SELECT vm.system_value main_system_tag,vs.system_value sub_system_tag,a.* FROM `auth_page` a
|
||||||
|
join variable vs on a.ShowView = vs.id and vs.deleted = 0
|
||||||
|
join variable vm on vs.system_parent_id = vm.id and vm.deleted = 0
|
||||||
|
GROUP BY main_system_tag, sub_system_tag, building_tag) ap
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT bm.main_system_tag, bm.sub_system_tag, bm.building_tag
|
||||||
|
FROM building_menu bm
|
||||||
|
WHERE bm.is_link = 1
|
||||||
|
) bm ON ap.building_tag = bm.building_tag
|
||||||
|
AND bm.main_system_tag = ap.main_system_tag
|
||||||
|
AND bm.sub_system_tag = ap.sub_system_tag
|
||||||
|
WHERE bm.building_tag IS NULL);");
|
||||||
|
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
stopwatchSection.Stop();
|
||||||
|
await KeepTimeLog("auth_page有,building_menu沒有,把auth_code對應的role_auth也一併刪除", stopwatchSection.ElapsedMilliseconds);
|
||||||
|
|
||||||
|
//auth_page有,building_menu沒有,刪除這些權限
|
||||||
|
stopwatchSection = new Stopwatch();
|
||||||
|
stopwatchSection.Start();
|
||||||
|
|
||||||
|
sb.Append($@"DELETE FROM auth_page WHERE AuthCode in
|
||||||
|
(SELECT ap.AuthCode
|
||||||
|
FROM (SELECT vm.system_value main_system_tag,vs.system_value sub_system_tag,a.* FROM `auth_page` a
|
||||||
|
join variable vs on a.ShowView = vs.id and vs.deleted = 0
|
||||||
|
join variable vm on vs.system_parent_id = vm.id and vm.deleted = 0
|
||||||
|
GROUP BY main_system_tag, sub_system_tag, building_tag) ap
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT bm.main_system_tag, bm.sub_system_tag, bm.building_tag
|
||||||
|
FROM building_menu bm
|
||||||
|
WHERE bm.is_link = 1
|
||||||
|
) bm ON ap.building_tag = bm.building_tag
|
||||||
|
AND bm.main_system_tag = ap.main_system_tag
|
||||||
|
AND bm.sub_system_tag = ap.sub_system_tag
|
||||||
|
WHERE bm.building_tag IS NULL);");
|
||||||
|
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
{
|
||||||
|
await conn.ExecuteAsync(sb.ToString());
|
||||||
|
}
|
||||||
|
sb.Clear();
|
||||||
|
stopwatchSection.Stop();
|
||||||
|
await KeepTimeLog("auth_page有,building_menu沒有,刪除這些權限", stopwatchSection.ElapsedMilliseconds);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
stopwatch.Stop();
|
||||||
|
await KeepTimeLog("UpdateAuthPageByBuildingMenu", stopwatch.ElapsedMilliseconds);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
conn.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 新增資料至 subSystemFloor
|
/// 新增資料至 subSystemFloor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -42,6 +42,11 @@ namespace Repository.BackendRepository.Interface
|
|||||||
Task CheckDiffFullNameAndCover();
|
Task CheckDiffFullNameAndCover();
|
||||||
|
|
||||||
Task CheckItemIsShowHistory();
|
Task CheckItemIsShowHistory();
|
||||||
|
/// <summary>
|
||||||
|
///根據Building_menu 更新 AuthPage
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpdateAuthPageByBuildingMenu();
|
||||||
|
|
||||||
Task InsertItemFromNiagara_History(List<ImpNiaItem> ds, List<string> building);
|
Task InsertItemFromNiagara_History(List<ImpNiaItem> ds, List<string> building);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -105,7 +105,17 @@ namespace Repository.Models
|
|||||||
public string device_system_tag { get; set; }
|
public string device_system_tag { get; set; }
|
||||||
public string device_name_tag { get; set; }
|
public string device_name_tag { get; set; }
|
||||||
}
|
}
|
||||||
|
public class AuthPage
|
||||||
|
{
|
||||||
|
public string AuthCode { get; set; }
|
||||||
|
public byte AuthType { get; set; }
|
||||||
|
public string MainName { get; set; }
|
||||||
|
public string SubName { get; set; }
|
||||||
|
public string building_guid { get; set; }
|
||||||
|
public string building_tag { get; set; }
|
||||||
|
public string ShowView { get; set; }
|
||||||
|
public string created_at { get; set; }
|
||||||
|
}
|
||||||
public class device_kind
|
public class device_kind
|
||||||
{
|
{
|
||||||
public string device_kind_guid { get; set; }
|
public string device_kind_guid { get; set; }
|
||||||
|
Loading…
Reference in New Issue
Block a user