2022-10-14 16:08:54 +08:00
using Backend.Models ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Logging ;
using Repository.BackendRepository.Interface ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text.Json ;
using System.Threading.Tasks ;
namespace Backend.Controllers
{
public class BuildMenuController : MybaseController < BuildMenuController >
{
private readonly IBackendRepository backendRepository ;
public BuildMenuController ( IBackendRepository backendRepository )
{
this . backendRepository = backendRepository ;
}
public IActionResult Index ( )
{
return View ( ) ;
}
[HttpPost]
public async Task < ApiResult < List < KeyValue > > > BuildInfoList ( )
{
ApiResult < List < KeyValue > > apiResult = new ApiResult < List < KeyValue > > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var sqlString = @ $"select building_tag as Value, full_name as Name from building a where a.deleted = 0 and a.status = 0 ORDER BY a.priority ASC, a.created_at DESC" ;
2022-10-14 16:08:54 +08:00
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString ) ;
apiResult . Code = "0000" ;
apiResult . Data = KeyValue ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
2022-10-21 19:40:38 +08:00
public async Task < ApiResult < List < KeyValue > > > MainListBybuild ( string building_tag )
2022-10-14 16:08:54 +08:00
{
ApiResult < List < KeyValue > > apiResult = new ApiResult < List < KeyValue > > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var sqlString = @ $ "select v.system_value value, v.system_key name
from (
select main_system_tag from building_menu bm where bm . building_tag = @building_tag group by bm . main_system_tag
) bm
2023-09-13 16:33:26 +08:00
join variable v on v . system_value = bm . main_system_tag AND v . system_type = @main_system_type and v . deleted = 0
2022-10-21 19:40:38 +08:00
ORDER BY v . system_priority ASC ";
var param = new { building_tag = building_tag , main_system_type = main_system_type } ;
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString , param ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = KeyValue ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ApiResult < List < KeyValue > > > MainList ( )
{
ApiResult < List < KeyValue > > apiResult = new ApiResult < List < KeyValue > > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var sqlString = @ $ "select system_key Name, system_value Value
from variable
where deleted = 0 and system_type = @main_system_type
ORDER BY system_priority ASC ";
var param = new { main_system_type = main_system_type } ;
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString , param ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = KeyValue ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ApiResult < List < KeyValue > > > SubListNotAdd ( SubListIn post )
{
ApiResult < List < KeyValue > > apiResult = new ApiResult < List < KeyValue > > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var mainList = await backendRepository . GetAllAsync < int > ( "select id from variable where system_value = @main_system_tag and system_type = @main_system_type" , new { main_system_tag = post . main_system_tag , main_system_type = main_system_type } ) ;
2022-10-14 16:08:54 +08:00
var sqlString = @ $ "select
2022-10-21 19:40:38 +08:00
sv . system_value value , sv . system_key name
from variable sv
left join (
select * from building_menu bm where bm . building_tag = @building_tag
) bm
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 ";
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString , new { building_tag = post . building_tag , mainList = mainList } ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = KeyValue ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
string json = System . Text . Json . JsonSerializer . Serialize ( post ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + json ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ApiResult < string > > SavebuildMenuModal ( BuildMenu buildMenu )
{
ApiResult < string > apiResult = new ApiResult < string > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
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}'" ) ;
2022-10-14 16:08:54 +08:00
if ( get = = null )
{
2022-10-21 19:40:38 +08:00
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 } ) ;
2022-10-14 16:08:54 +08:00
var dictionary = new Dictionary < string , object > ( )
{
2022-10-21 19:40:38 +08:00
{ "@building_tag" , buildMenu . building_tag } ,
{ "@main_system_tag" , buildMenu . main_system_tag } ,
{ "@sub_system_tag" , buildMenu . sub_system_tag } ,
2022-10-22 13:24:29 +08:00
{ "@left_drawing" , buildMenu . left_drawing } ,
{ "@right_drawing" , buildMenu . right_drawing } ,
2022-10-14 16:08:54 +08:00
{ "@created_by" , myUserInfo . Userinfo_guid } ,
2022-10-22 13:24:29 +08:00
{ "@left_planimetric_click" , buildMenu . left_planimetric_click } ,
{ "@right_planimetric_click" , buildMenu . right_planimetric_click }
2022-10-14 16:08:54 +08:00
} ;
2022-10-22 13:24:29 +08:00
if ( buildMenu . left_drawing = = 2 )
2022-10-14 16:08:54 +08:00
{
2022-10-22 13:24:29 +08:00
if ( buildMenu . left_system_url ! = null & & buildMenu . left_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . left_system_url . CompareTo ( "https://" ) < 0 )
2022-10-14 16:08:54 +08:00
{
//未包含http || https 抓該棟ip + port
2022-10-21 19:40:38 +08:00
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
2022-10-14 16:08:54 +08:00
2022-10-22 13:24:29 +08:00
buildMenu . left_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . left_system_url ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
dictionary . Add ( "@left_system_url" , buildMenu . left_system_url ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
else if ( buildMenu . left_drawing = = 4 )
2022-10-14 16:08:54 +08:00
{
2022-10-22 13:24:29 +08:00
if ( buildMenu . left_system_url ! = null & & buildMenu . left_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . left_system_url . CompareTo ( "https://" ) < 0 )
2022-10-14 16:08:54 +08:00
{
//未包含http || https 抓該棟ip + port
2022-10-21 19:40:38 +08:00
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
2022-10-14 16:08:54 +08:00
2022-10-22 13:24:29 +08:00
buildMenu . left_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . left_system_url ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
dictionary . Add ( "@left_riser_diagram_url" , buildMenu . left_riser_diagram_url ) ;
dictionary . Add ( "@left_icon_click" , buildMenu . left_icon_click ) ;
dictionary . Add ( "@left_icon_click_url" , buildMenu . left_icon_click_url ) ;
dictionary . Add ( "@left_icon_click_url_width" , buildMenu . left_icon_click_url_width ) ;
dictionary . Add ( "@left_icon_click_url_height" , buildMenu . left_icon_click_url_height ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
else if ( buildMenu . left_drawing = = 1 )
2022-10-14 16:08:54 +08:00
{
2022-10-22 13:24:29 +08:00
dictionary . Add ( "@planimetric_floor_guid" , buildMenu . left_planimetric_floor_guid ) ;
}
if ( buildMenu . right_drawing = = 2 )
{
if ( buildMenu . right_system_url ! = null & & buildMenu . right_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . right_system_url . CompareTo ( "https://" ) < 0 )
{
//未包含http || https 抓該棟ip + port
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
buildMenu . right_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . right_system_url ) ;
}
dictionary . Add ( "@right_system_url" , buildMenu . right_system_url ) ;
}
else if ( buildMenu . right_drawing = = 4 )
{
if ( buildMenu . right_system_url ! = null & & buildMenu . right_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . right_system_url . CompareTo ( "https://" ) < 0 )
{
//未包含http || https 抓該棟ip + port
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
buildMenu . right_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . right_system_url ) ;
}
dictionary . Add ( "@right_riser_diagram_url" , buildMenu . right_riser_diagram_url ) ;
dictionary . Add ( "@right_icon_click" , buildMenu . right_icon_click ) ;
dictionary . Add ( "@right_icon_click_url" , buildMenu . right_icon_click_url ) ;
dictionary . Add ( "@right_icon_click_url_width" , buildMenu . right_icon_click_url_width ) ;
dictionary . Add ( "@right_icon_click_url_height" , buildMenu . right_icon_click_url_height ) ;
}
else if ( buildMenu . right_drawing = = 1 )
{
dictionary . Add ( "@right_planimetric_floor_guid" , buildMenu . right_planimetric_floor_guid ) ;
2022-10-14 16:08:54 +08:00
}
await backendRepository . AddOneByCustomTable ( dictionary , "building_menu" ) ;
2022-10-21 19:40:38 +08:00
var max = await backendRepository . GetOneAsync < int > ( "select Max(CONVERT(SUBSTRING(AuthCode,2,5), SIGNED)) AuthCode from auth_page ap where ap.AuthCode like 'F%'" ) ;
var pageSql = $ @ "select sv.system_key SubName, mv.system_key MainName
from variable sv
left join variable mv on sv . system_parent_id = mv . id
where ( sv . system_value = @sub_system_tag and sv . system_type = @sub_system_type ) and ( mv . system_value = @main_system_tag and mv . system_type = @main_system_type ) ";
var pageParam = new { sub_system_tag = buildMenu . sub_system_tag , main_system_tag = buildMenu . main_system_tag , sub_system_type = sub_system_type , main_system_type = main_system_type } ;
var page = await backendRepository . GetOneAsync < Auth_page > ( pageSql , pageParam ) ;
2022-10-14 16:08:54 +08:00
var pagedictionary = new Dictionary < string , object > ( )
{
{ "@AuthCode" , "F" + ( max + 1 ) . ToString ( ) } ,
{ "@AuthType" , 1 } ,
{ "@MainName" , page . MainName } ,
{ "@SubName" , page . SubName } ,
2022-10-21 19:40:38 +08:00
{ "@building_tag" , buildMenu . building_tag } ,
{ "@ShowView" , subV . id }
2022-10-14 16:08:54 +08:00
} ;
await backendRepository . AddOneByCustomTable ( pagedictionary , "auth_page" ) ;
2022-10-21 19:40:38 +08:00
var param = new { main_system_type = main_system_type , sub_system_type = sub_system_type } ;
2022-10-14 16:08:54 +08:00
await backendRepository . ExecuteSql ( @ "DELETE FROM auth_page
2022-10-21 19:40:38 +08:00
WHERE auth_page . AuthCode like ' F % ' ;
INSERT INTO auth_page ( AuthCode , AuthType , MainName , SubName , building_tag , ShowView )
SELECT concat ( 'F' , CONVERT ( ROW_NUMBER ( ) OVER ( ORDER BY bm . building_tag ASC ) , nchar ) ) AuthCode , '1' as AuthType ,
mv . system_key MainName , sv . system_key SubName , bm . building_tag , sv . id ShowView
FROM building_menu bm
LEFT JOIN variable mv ON bm . main_system_tag = mv . system_value AND mv . system_type = @main_system_type
LEFT JOIN variable sv ON bm . sub_system_tag = sv . system_value AND sv . system_type = @sub_system_type ", param);
2022-10-14 16:08:54 +08:00
await backendRepository . ExecuteSql ( @ "delete a from role_auth a join role b on a.role_guid = b.role_guid where b.layer = 0;
INSERT INTO role_auth ( role_guid , AuthCode , created_by )
SELECT r . role_guid , ap . AuthCode , '0' created_by FROM auth_page ap , role r
WHERE r . layer = 0 ; ");
apiResult . Code = "0000" ;
apiResult . Msg = "儲存成功" ;
}
else
{
var dictionary = new Dictionary < string , object > ( )
{
2022-10-22 13:24:29 +08:00
{ "@left_drawing" , buildMenu . left_drawing } ,
{ "@right_drawing" , buildMenu . right_drawing } ,
2022-10-14 16:08:54 +08:00
{ "@updated_by" , myUserInfo . Userinfo_guid } ,
{ "@updated_at" , DateTime . Now } ,
2022-10-22 13:24:29 +08:00
{ "@left_planimetric_click" , buildMenu . left_planimetric_click } ,
{ "@right_planimetric_click" , buildMenu . right_planimetric_click }
2022-10-14 16:08:54 +08:00
} ;
2022-10-22 13:24:29 +08:00
if ( buildMenu . left_drawing = = 2 )
{
if ( buildMenu . left_system_url ! = null & & buildMenu . left_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . left_system_url . CompareTo ( "https://" ) < 0 )
{
//未包含http || https 抓該棟ip + port
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
buildMenu . left_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . left_system_url ) ;
}
dictionary . Add ( "@left_system_url" , buildMenu . left_system_url ) ;
}
else if ( buildMenu . left_drawing = = 4 )
{
if ( buildMenu . left_system_url ! = null & & buildMenu . left_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . left_system_url . CompareTo ( "https://" ) < 0 )
{
//未包含http || https 抓該棟ip + port
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
buildMenu . left_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . left_system_url ) ;
}
dictionary . Add ( "@left_riser_diagram_url" , buildMenu . left_riser_diagram_url ) ;
dictionary . Add ( "@left_icon_click" , buildMenu . left_icon_click ) ;
dictionary . Add ( "@left_icon_click_url" , buildMenu . left_icon_click_url ) ;
dictionary . Add ( "@left_icon_click_url_width" , buildMenu . left_icon_click_url_width ) ;
dictionary . Add ( "@left_icon_click_url_height" , buildMenu . left_icon_click_url_height ) ;
}
else if ( buildMenu . left_drawing = = 1 )
{
dictionary . Add ( "@left_planimetric_floor_guid" , buildMenu . left_planimetric_floor_guid ) ;
}
if ( buildMenu . right_drawing = = 2 )
2022-10-14 16:08:54 +08:00
{
2022-10-22 13:24:29 +08:00
if ( buildMenu . right_system_url ! = null & & buildMenu . right_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . right_system_url . CompareTo ( "https://" ) < 0 )
2022-10-14 16:08:54 +08:00
{
//未包含http || https 抓該棟ip + port
2022-10-21 19:40:38 +08:00
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
2022-10-14 16:08:54 +08:00
2022-10-22 13:24:29 +08:00
buildMenu . right_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . right_system_url ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
dictionary . Add ( "@right_system_url" , buildMenu . right_system_url ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
else if ( buildMenu . right_drawing = = 4 )
2022-10-14 16:08:54 +08:00
{
2022-10-22 13:24:29 +08:00
if ( buildMenu . right_system_url ! = null & & buildMenu . right_system_url . CompareTo ( "http://" ) < 0 & & buildMenu . right_system_url . CompareTo ( "https://" ) < 0 )
2022-10-14 16:08:54 +08:00
{
//未包含http || https 抓該棟ip + port
2022-10-21 19:40:38 +08:00
var building_where = @"deleted = 0 AND building_tag = @Building_tag" ;
var building = await backendRepository . GetOneAsync < BuildInfo > ( "building" , building_where , new { Building_tag = buildMenu . building_tag } ) ;
2022-10-14 16:08:54 +08:00
2022-10-22 13:24:29 +08:00
buildMenu . right_system_url = string . Format ( "http://{0}:{1}{2}" , building . Ip_address , building . Ip_port , buildMenu . right_system_url ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
dictionary . Add ( "@right_riser_diagram_url" , buildMenu . right_riser_diagram_url ) ;
dictionary . Add ( "@right_icon_click" , buildMenu . right_icon_click ) ;
dictionary . Add ( "@right_icon_click_url" , buildMenu . right_icon_click_url ) ;
dictionary . Add ( "@right_icon_click_url_width" , buildMenu . right_icon_click_url_width ) ;
dictionary . Add ( "@right_icon_click_url_height" , buildMenu . right_icon_click_url_height ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-22 13:24:29 +08:00
else if ( buildMenu . right_drawing = = 1 )
2022-10-14 16:08:54 +08:00
{
2022-10-22 13:24:29 +08:00
dictionary . Add ( "@right_planimetric_floor_guid" , buildMenu . right_planimetric_floor_guid ) ;
2022-10-14 16:08:54 +08:00
}
2022-10-21 19:40:38 +08:00
await backendRepository . UpdateOneByCustomTable ( dictionary , "building_menu" , $"building_tag = '{buildMenu.building_tag}' and main_system_tag = '{buildMenu.main_system_tag}' and sub_system_tag = '{buildMenu.sub_system_tag}'" ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Msg = "儲存成功" ;
}
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
string json = System . Text . Json . JsonSerializer . Serialize ( buildMenu ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + json ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
2022-10-24 17:53:33 +08:00
2022-10-14 16:08:54 +08:00
[HttpPost]
public async Task < ActionResult > BuildMenuTable ( BuildMenuTablePost post )
{
List < BuildMenuTable > buildMenuTables = new List < BuildMenuTable > ( ) ;
ApiResult < List < BuildMenuTable > > apiResult = new ApiResult < List < BuildMenuTable > > ( ) ;
try
{
buildMenuTables = await backendRepository . GetAllAsync < BuildMenuTable > ( $ @ "select bm.*,
2022-10-22 13:24:29 +08:00
case left_drawing when 1 then ' 樓 層 平 面 圖 ' when 2 then ' 系 統 圖 ' when 4 then ' 昇 位 圖 ' end left_drawing_name ,
case left_icon_click when 1 then '開' when 0 then '關' end left_icon_click_name ,
case left_planimetric_click when 1 then '開' when 0 then '關' end left_planimetric_click_name ,
case right_drawing when 1 then ' 樓 層 平 面 圖 ' when 2 then ' 系 統 圖 ' when 4 then ' 昇 位 圖 ' end right_drawing_name ,
case right_icon_click when 1 then '開' when 0 then '關' end right_icon_click_name ,
case right_planimetric_click when 1 then '開' when 0 then '關' end right_planimetric_click_name ,
mv . system_key main_system_guid_name , sv . system_key sub_system_guid_name , lf . full_name left_floor_guid_name , rf . full_name right_floor_guid_name
from building_menu bm
left join variable mv on bm . main_system_tag = mv . system_value and mv . system_type = @main_system_type and mv . deleted = 0
left 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 rf on rf . floor_guid = bm . right_planimetric_floor_guid
2023-09-07 16:16:58 +08:00
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 ",
2022-10-21 19:40:38 +08:00
new { building_tag = post . building_tag , MainList = post . MainList , main_system_type = main_system_type , sub_system_type = sub_system_type } ) ;
2022-10-14 16:08:54 +08:00
2023-09-19 19:14:51 +08:00
if ( buildMenuTables . Any ( ) )
{
var data = buildMenuTables . Where ( x = > x . main_system_tag = = "S" & & x . sub_system_tag . Contains ( "CA" ) ) . ToList ( ) ;
foreach ( var d in data )
{
if ( d . sub_system_tag . Length = = 3 & & ! ( d . building_tag [ 0 ] = = d . sub_system_tag [ 0 ] ) )
{
buildMenuTables . Remove ( d ) ;
}
}
}
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = buildMenuTables ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
var result = Json ( new
{
data = apiResult
} ) ;
return result ;
}
[HttpPost]
public async Task < ApiResult < BuildMenuAddSub > > GetBuildMenu ( MenuIn post )
{
ApiResult < BuildMenuAddSub > apiResult = new ApiResult < BuildMenuAddSub > ( ) ;
try
{
var BuildMenu = await backendRepository . GetOneAsync < BuildMenuAddSub > (
2022-10-22 13:24:29 +08:00
$ @ "select bm.*, sv.system_key sub_system_guid_name
2022-10-21 19:40:38 +08:00
from building_menu bm
left join variable sv on bm . sub_system_tag = sv . system_value and sv . system_type = @sub_system_type
where bm . building_tag = @building_tag and bm . main_system_tag = @main_system_tag and bm . sub_system_tag = @sub_system_tag "
, new { building_tag = post . building_tag , main_system_tag = post . main_system_tag , sub_system_tag = post . sub_system_tag , sub_system_type = sub_system_type } ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = BuildMenu ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
string json = System . Text . Json . JsonSerializer . Serialize ( post ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + json ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ApiResult < string > > DeleteBuildMenu ( MenuIn post )
{
ApiResult < string > apiResult = new ApiResult < string > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
await backendRepository . PurgeOneByGuidWithCustomDBNameAndTable ( "building_menu" , $"building_tag = '{post.building_tag}' and main_system_tag = '{post.main_system_tag}' and sub_system_tag = '{post.sub_system_tag}'" ) ;
2022-10-22 13:24:29 +08:00
var subV = await backendRepository . GetOneAsync < VariableInfo > ( @ $"select * from variable where system_value = @sub_system_tag and system_type = @sub_system_type and deleted = 0" , new { sub_system_tag = post . sub_system_tag , sub_system_type = sub_system_type } ) ;
2022-10-21 19:40:38 +08:00
var authcode = await backendRepository . GetOneAsync < string > ( @ $"select AuthCode from auth_page where building_tag = @building_tag and ShowView = @sub_id" , new { post . building_tag , subV . id } ) ;
2022-10-14 16:08:54 +08:00
if ( authcode ! = null )
{
await backendRepository . PurgeOneByGuidWithCustomDBNameAndTable ( "role_auth" , $" AuthCode = '{authcode}'" ) ;
await backendRepository . PurgeOneByGuidWithCustomDBNameAndTable ( "auth_page" , $" AuthCode = '{authcode}'" ) ;
await backendRepository . ExecuteSql ( @ "delete a from role_auth a join role b on a.role_guid = b.role_guid where b.layer = 0;
INSERT INTO role_auth ( role_guid , AuthCode , created_by )
SELECT r . role_guid , ap . AuthCode , '0' created_by FROM auth_page ap , role r
WHERE r . layer = 0 ; ");
}
apiResult . Code = "0000" ;
apiResult . Msg = "刪除成功" ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
string json = System . Text . Json . JsonSerializer . Serialize ( post ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + json ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ActionResult > BuildMenuFloorTable ( MenuIn post )
{
List < BuildMenuFloorTable > buildMenuFloorTables = new List < BuildMenuFloorTable > ( ) ;
ApiResult < List < BuildMenuFloorTable > > apiResult = new ApiResult < List < BuildMenuFloorTable > > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var param = new { building_tag = post . building_tag , main_system_tag = post . main_system_tag , sub_system_tag = post . sub_system_tag , main_system_type = main_system_type , sub_system_type = sub_system_type } ;
2022-10-14 16:08:54 +08:00
buildMenuFloorTables = await backendRepository . GetAllAsync < BuildMenuFloorTable > ( $ @ "
2022-10-21 19:40:38 +08:00
select sf . id sub_system_floor_id , f . full_name floor_guid_name , sf . * , mv . system_key main_system_guid_name , sv . system_key sub_system_guid_name
from (
select *
from sub_system_floor ssf
where ssf . building_tag = @building_tag and ssf . main_system_tag = @main_system_tag and ssf . sub_system_tag = @sub_system_tag and deleted = 0 and status = 0
) sf
2023-08-30 16:12:26 +08:00
left join floor f on sf . floor_tag = f . full_name and sf . building_tag = f . building_tag and f . deleted = 0
2022-10-21 19:40:38 +08:00
left join variable mv on sf . main_system_tag = mv . system_value and mv . system_type = @main_system_type and mv . deleted = 0
left join variable sv on sf . sub_system_tag = sv . system_value and sv . system_type = @sub_system_type and sv . deleted = 0
ORDER BY mv . system_priority , sv . system_priority , f . priority ", param);
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = buildMenuFloorTables ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
var result = Json ( new
{
data = apiResult
} ) ;
return result ;
}
[HttpPost]
public async Task < ApiResult < List < KeyValue > > > GetNotUsefloor ( MenuIn post )
{
ApiResult < List < KeyValue > > apiResult = new ApiResult < List < KeyValue > > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var param = new { building_tag = post . building_tag , main_system_tag = post . main_system_tag , sub_system_tag = post . sub_system_tag } ;
var sqlString = @ $ "select f.floor_guid value, f.full_name name
from (
select * from floor f where f . building_tag = @building_tag and f . deleted = 0 and f . status = 0
) f
left join (
select * from sub_system_floor where building_tag = @building_tag and main_system_tag = @main_system_tag and sub_system_tag = @sub_system_tag and deleted = 0 and status = 0
) ssf
on ssf . floor_tag = f . full_name
where ssf . floor_tag is null ORDER BY f . priority ";
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString , param ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = KeyValue ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ApiResult < string > > SaveAddsubfloor ( MenuInfloor menuInfloor )
{
ApiResult < string > apiResult = new ApiResult < string > ( ) ;
try
{
var listdictionary = new List < Dictionary < string , object > > ( ) ;
foreach ( var a in menuInfloor . floorlist )
{
var dictionary = new Dictionary < string , object > ( )
{
2022-10-21 19:40:38 +08:00
{ "@building_tag" , menuInfloor . building_tag } ,
{ "@main_system_tag" , menuInfloor . main_system_tag } ,
{ "@sub_system_tag" , menuInfloor . sub_system_tag } ,
{ "@floor_tag" , a } ,
{ "@is_link" , 1 } ,
2022-10-14 16:08:54 +08:00
{ "@created_by" , myUserInfo . Userinfo_guid }
} ;
listdictionary . Add ( dictionary ) ;
}
await backendRepository . AddMutiByCustomTable ( listdictionary , "sub_system_floor" ) ;
apiResult . Code = "0000" ;
apiResult . Msg = "儲存成功" ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
string json = System . Text . Json . JsonSerializer . Serialize ( menuInfloor ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + json ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
2022-10-21 19:40:38 +08:00
public async Task < ApiResult < string > > DeleteBuildFloorMenu ( string sub_system_floor_id )
2022-10-14 16:08:54 +08:00
{
ApiResult < string > apiResult = new ApiResult < string > ( ) ;
try
{
//檢查該樓層底下是否有設備
2022-10-21 19:40:38 +08:00
var sql = $ @ "SELECT
CONCAT ( b . full_name , ' - ' , mv . system_key , ' - ' , sv . system_key , ' - ' , f . full_name )
FROM device d
LEFT JOIN (
SELECT *
FROM sub_system_floor ssf
WHERE ssf . deleted = 0 AND ssf . id = @sub_system_floor_id
) ssf
ON d . deleted = 0
AND d . device_building_tag = ssf . building_tag
AND d . device_system_tag = ssf . main_system_tag
AND d . device_name_tag = ssf . sub_system_tag
AND d . device_floor_tag = ssf . floor_tag
LEFT JOIN building b ON b . deleted = 0 AND d . device_building_tag = b . building_tag
LEFT JOIN variable mv on mv . deleted = 0 AND d . device_system_tag = mv . system_value AND mv . system_type = @main_system_type and mv . deleted = 0
LEFT JOIN variable sv on sv . deleted = 0 AND d . device_name_tag = sv . system_value AND sv . system_type = @sub_system_type and sv . deleted = 0
LEFT JOIN floor f ON f . deleted = 0 AND d . full_name = f . full_name
WHERE ssf . id = @sub_system_floor_id ";
var sub_system_floors = await backendRepository . GetAllAsync < string > ( sql , new { sub_system_floor_id = sub_system_floor_id , main_system_type = main_system_type , sub_system_type = sub_system_type } ) ;
2022-10-14 16:08:54 +08:00
if ( sub_system_floors . Count > 0 )
{
apiResult . Code = "9997" ;
apiResult . Msg = "設備管理中尚有設備正在使用該選單樓層,故無法刪除" ;
return apiResult ;
}
2022-10-21 19:40:38 +08:00
await backendRepository . DeleteOne ( sub_system_floor_id , "sub_system_floor" , "id" ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Msg = "刪除成功" ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
2022-10-21 19:40:38 +08:00
string json = System . Text . Json . JsonSerializer . Serialize ( sub_system_floor_id ) ;
2022-10-14 16:08:54 +08:00
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + json ) ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
[HttpPost]
public async Task < ApiResult < List < KeyValue > > > GetFloorInSubSystem ( MenuIn post )
{
ApiResult < List < KeyValue > > apiResult = new ApiResult < List < KeyValue > > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
2022-10-21 19:40:38 +08:00
var sqlString = @ $ "select f.floor_guid Value, f.full_name Name
from sub_system_floor sf
2022-10-24 17:53:33 +08:00
left join floor f on sf . floor_tag = f . full_name and sf . building_tag = f . building_tag
2022-10-21 19:40:38 +08:00
where sf . deleted = 0 and sf . status = 0 and sf . building_tag = @building_tag and sf . main_system_tag = @main_system_tag and sf . sub_system_tag = @sub_system_tag
2022-10-24 17:53:33 +08:00
and ( f . InitMapName + f . floor_map_name ) is not null
2022-10-21 19:40:38 +08:00
ORDER BY f . priority , f . created_at ";
2022-10-24 17:53:33 +08:00
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString , new { building_tag = post . building_tag , main_system_tag = post . main_system_tag , sub_system_tag = post . sub_system_tag } ) ;
2022-10-14 16:08:54 +08:00
apiResult . Code = "0000" ;
apiResult . Data = KeyValue ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
2022-10-24 17:53:33 +08:00
[HttpPost]
public async Task < ApiResult < int > > GetBuildingHas3D ( MenuIn post )
{
ApiResult < int > apiResult = new ApiResult < int > ( ) ;
List < KeyValue > KeyValue = new List < KeyValue > ( ) ;
try
{
var sqlString = @ $ "select v.id
from building b
2022-10-26 09:59:36 +08:00
join variable v on v . system_type = @system_type and system_key = N ' 是 否 有 3D ' and system_value = 'Y' and v . deleted = 0
2022-10-24 17:53:33 +08:00
where b . building_tag = @building_tag and ( b . orgName_3D + b . saveName_3D ) is not null ; ";
KeyValue = await backendRepository . GetAllAsync < KeyValue > ( sqlString , new { building_tag = post . building_tag , system_type = system_setting_type } ) ;
apiResult . Code = "0000" ;
apiResult . Data = KeyValue . Count ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
2023-09-07 16:16:58 +08:00
/// <summary>
/// 修改棟別區域排列順序
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task < ApiResult < List < string > > > ChangeBuildMenuPriority ( PostBuildMenuPriority post )
{
ApiResult < List < string > > apiResult = new ApiResult < List < string > > ( ) ;
try
{
List < Dictionary < string , object > > building_priorities = new List < Dictionary < string , object > > ( ) ;
if ( post . BuildMenuPriorities ! = null )
{
foreach ( var building_priority in post . BuildMenuPriorities )
{
Dictionary < string , object > building_priority_dic = new Dictionary < string , object > ( ) ;
building_priority_dic = new Dictionary < string , object > ( )
{
{ "building_tag" , building_priority . Building_tag } ,
{ "main_system_tag" , building_priority . Main_System_tag } ,
{ "sub_system_tag" , building_priority . Sub_System_tag } ,
{ "@priority" , building_priority . Priority } ,
{ "@updated_by" , myUserInfo . Userinfo_guid } ,
{ "@updated_at" , DateTime . Now . ToString ( "yyyy-MM-dd HH:mm:ss" ) }
} ;
building_priorities . Add ( building_priority_dic ) ;
}
var sql = $ @ "UPDATE building_menu SET priority = @priority, updated_by = @updated_by, updated_at=@updated_at
WHERE building_tag = @building_tag and main_system_tag = @main_system_tag and sub_system_tag = @sub_system_tag ";
await backendRepository . ExecuteSql ( sql , building_priorities ) ;
}
apiResult . Code = "0000" ;
apiResult . Msg = "修改成功" ;
}
catch ( Exception exception )
{
apiResult . Code = "9999" ;
apiResult . Msg = "系統內部錯誤,請聯絡管理者。" ;
Logger . LogError ( "【" + controllerName + "/" + actionName + "】" + exception . Message ) ;
}
return apiResult ;
}
2022-10-14 16:08:54 +08:00
}
}