Merge branch 'master' of https://gitea.mjm-staging.developers-homelab.net/BIMS/BIMS
This commit is contained in:
commit
159942d96b
@ -33,12 +33,16 @@ namespace FrontendWebApi.ApiControllers
|
||||
this.frontendRepository = frontendRepository;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 系統監控列表
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/Device/GetDeviceList")]
|
||||
public async Task<ActionResult<ApiResult<List<Device>>>> GetDeviceList()
|
||||
[Route("api/Device/GetMainSub")]
|
||||
public async Task<ActionResult<ApiResult<History_MainSubBuildFloor>>> GetMainSub()
|
||||
{
|
||||
ApiResult<List<Building>> apiResult = new ApiResult<List<Building>>(jwt_str);
|
||||
ApiResult<History_MainSubBuildFloor> apiResult = new ApiResult<History_MainSubBuildFloor>(jwt_str);
|
||||
if (!jwtlife)
|
||||
{
|
||||
apiResult.Code = "5000";
|
||||
@ -46,58 +50,145 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
try
|
||||
{
|
||||
List<Building> buildingMenus = new List<Building>();
|
||||
var buildmenusql = await backendRepository.GetAllAsync<BuildMenuSql>(@$"select
|
||||
me.* , b.full_name bfull_name,b.ip_address,b.priority bpriority,
|
||||
ma.full_name mafull_name,ma.priority mapriority,ma.code,
|
||||
sub.full_name subfull_name,sub.priority subpriority
|
||||
from building_menu me
|
||||
left join building b on b.building_guid = me.building_guid
|
||||
left join main_system ma on ma.main_system_guid = me.main_system_guid
|
||||
left join sub_system sub on sub.sub_system_guid = me.sub_system_guid");
|
||||
|
||||
var floorsql = await backendRepository.GetAllAsync<Floorsql>(@"
|
||||
select * from (select * from sub_system_floor ssf where ssf.deleted = 0 and ssf.status = 0) a
|
||||
left join floor on floor.floor_guid = a.floor_guid");
|
||||
|
||||
var building = buildmenusql.GroupBy(a => a.building_guid).ToList();
|
||||
foreach (var menu in building)
|
||||
var dbsub = await frontendRepository.GetAllAsync<HistoryDBMainSub>(
|
||||
@$"select distinct v1.system_key main_name, v1.system_value main_system_tag, v2.system_key sub_name, v2.system_value sub_system_tag, v1.system_priority, v2.system_priority
|
||||
from role_auth a
|
||||
join auth_page b on a.AuthCode = b.AuthCode
|
||||
join userinfo c on c.role_guid = a.role_guid
|
||||
join variable v2 on b.ShowView = v2.id and v2.system_type = @sub_system_type
|
||||
join variable v1 on v1.id = v2.system_parent_id and v1.system_type = @main_system_type
|
||||
where c.account = @account
|
||||
order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type });
|
||||
var mains = dbsub.GroupBy(a => a.main_system_tag).ToList();
|
||||
apiResult.Data = new History_MainSubBuildFloor();
|
||||
apiResult.Data.history_Main_Systems = new List<History_Main_system>();
|
||||
foreach (var main in mains)
|
||||
{
|
||||
Building building1 = new Building()
|
||||
{
|
||||
building_guid = menu.Select(a => a.building_guid).FirstOrDefault(),
|
||||
full_name = menu.Select(a => a.bfull_name).FirstOrDefault(),
|
||||
ip_address = menu.Select(a => a.ip_address).FirstOrDefault(),
|
||||
priority = menu.Select(a => a.bpriority).FirstOrDefault(),
|
||||
main_system = new List<Main_system>()
|
||||
};
|
||||
var mainsystem = menu.GroupBy(a => a.main_system_guid).ToList();
|
||||
foreach (var ma in mainsystem)
|
||||
{
|
||||
Main_system main_System = new Main_system()
|
||||
{
|
||||
code = ma.Select(a => a.code).FirstOrDefault(),
|
||||
main_system_guid = ma.Select(a => a.main_system_guid).FirstOrDefault(),
|
||||
full_name = ma.Select(a => a.mafull_name).FirstOrDefault(),
|
||||
priority = ma.Select(a => a.mapriority).FirstOrDefault(),
|
||||
Sub_system = new List<Sub_systemGuid>()
|
||||
};
|
||||
var subsystem = ma.GroupBy(a => a.sub_system_guid).ToList();
|
||||
foreach (var sub in subsystem)
|
||||
{
|
||||
Sub_systemGuid sub_System = new Sub_systemGuid()
|
||||
{
|
||||
sub_system_guid = sub.Select(a => a.sub_system_guid).FirstOrDefault(),
|
||||
full_name = sub.Select(a => a.subfull_name).FirstOrDefault(),
|
||||
priority = sub.Select(a => a.subpriority).FirstOrDefault()
|
||||
};
|
||||
main_System.Sub_system.Add(sub_System);
|
||||
}
|
||||
building1.main_system.Add(main_System);
|
||||
}
|
||||
buildingMenus.Add(building1);
|
||||
History_Main_system history_Main_System = new History_Main_system();
|
||||
history_Main_System.main_system_tag = main.Select(a => a.main_system_tag).FirstOrDefault();
|
||||
history_Main_System.full_name = main.Select(a => a.main_name).FirstOrDefault();
|
||||
|
||||
apiResult.Data.history_Main_Systems.Add(history_Main_System);
|
||||
}
|
||||
apiResult.Data = buildingMenus;
|
||||
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
return Ok(apiResult);
|
||||
}
|
||||
return Ok(apiResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 東別列表
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/Device/GetBuild")]
|
||||
public async Task<ActionResult<ApiResult<List<BuildList>>>> GetBuild()
|
||||
{
|
||||
ApiResult<List<BuildList>> apiResult = new ApiResult<List<BuildList>>();
|
||||
|
||||
try
|
||||
{
|
||||
var sqlString = $@"select building_tag, full_name from building where deleted = 0";
|
||||
var bl = await backendRepository.GetAllAsync<BuildList>(sqlString);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = bl;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
return Ok(apiResult);
|
||||
}
|
||||
return Ok(apiResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 樓層列表
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/Device/GetFloor")]
|
||||
public async Task<ActionResult<ApiResult<List<FloorList>>>> GetFloor([FromBody] FindDevice fd)
|
||||
{
|
||||
ApiResult<List<FloorList>> apiResult = new ApiResult<List<FloorList>>();
|
||||
|
||||
if (string.IsNullOrEmpty(fd.building_tag))
|
||||
{
|
||||
apiResult.Code = "0002";
|
||||
apiResult.Msg = "必須選擇東別";
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var sqlString = $@"select floor_tag, full_name from floor where deleted = 0 and building_tag = @building_tag";
|
||||
var param = new { @building_tag = fd.building_tag };
|
||||
var fl = await backendRepository.GetAllAsync<FloorList>(sqlString, param);
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Data = fl;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
return Ok(apiResult);
|
||||
}
|
||||
return Ok(apiResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 設備列表
|
||||
/// </summary>
|
||||
/// <param name="fd">floor_tag: null->總覽</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/Device/GetDeviceList")]
|
||||
public async Task<ActionResult<ApiResult<List<FloorList>>>> GetDeviceList([FromBody] FindDevice fd)
|
||||
{
|
||||
ApiResult<List<FloorList>> apiResult = new ApiResult<List<FloorList>>();
|
||||
|
||||
if (string.IsNullOrEmpty(fd.main_system_tag))
|
||||
{
|
||||
apiResult.Code = "0001";
|
||||
apiResult.Msg = "必須系統類別";
|
||||
return BadRequest(apiResult);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(fd.building_tag))
|
||||
{
|
||||
apiResult.Code = "0002";
|
||||
apiResult.Msg = "必須選擇東別";
|
||||
return BadRequest(apiResult);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var sqlString = $@"select floor_tag, full_name from floor where deleted = 0 and building_tag = @building_tag and full_name = ifnull(@floor_tag, full_name)";
|
||||
var param = new { @building_tag = fd.building_tag, @floor_tag = fd.floor_tag };
|
||||
var fl = await backendRepository.GetAllAsync<FloorList>(sqlString, param);
|
||||
|
||||
foreach (var f in fl)
|
||||
{
|
||||
List<DeviceLists> dl = new List<DeviceLists>();
|
||||
sqlString = $@"select device_guid, device_last_name, status, device_coordinate where deleted = 0 and device_system_tag = @main_system_tag and device_building_tag = @building_tag and device_floor_tag = ifnull(@floor_tag, device_floor_tag)";
|
||||
var dlParam = new { @main_system_tag = fd.main_system_tag, @building_tag = fd.building_tag, @floor_tag = fd.floor_tag };
|
||||
dl = await backendRepository.GetAllAsync<DeviceLists>(sqlString, dlParam);
|
||||
f.device_list = dl;
|
||||
}
|
||||
|
||||
apiResult.Data = fl;
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception exception)
|
||||
@ -433,56 +524,5 @@ namespace FrontendWebApi.ApiControllers
|
||||
return Ok(apiResult);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 即時趨勢條件過濾條件面板
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("api/Device/GetMainSub")]
|
||||
public async Task<ActionResult<ApiResult<History_MainSubBuildFloor>>> GetMainSub()
|
||||
{
|
||||
ApiResult<History_MainSubBuildFloor> apiResult = new ApiResult<History_MainSubBuildFloor>(jwt_str);
|
||||
if (!jwtlife)
|
||||
{
|
||||
apiResult.Code = "5000";
|
||||
return BadRequest(apiResult);
|
||||
}
|
||||
try
|
||||
{
|
||||
var dbsub = await frontendRepository.GetAllAsync<HistoryDBMainSub>(
|
||||
@$"select distinct v1.system_key main_name, v1.system_value main_system_tag, v2.system_key sub_name, v2.system_value sub_system_tag, v1.system_priority, v2.system_priority
|
||||
from role_auth a
|
||||
join auth_page b on a.AuthCode = b.AuthCode
|
||||
join userinfo c on c.role_guid = a.role_guid
|
||||
join variable v2 on b.ShowView = v2.id and v2.system_type = @sub_system_type
|
||||
join variable v1 on v1.id = v2.system_parent_id and v1.system_type = @main_system_type
|
||||
where c.account = @account
|
||||
order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type });
|
||||
var mains = dbsub.GroupBy(a => a.main_system_tag).ToList();
|
||||
apiResult.Data = new History_MainSubBuildFloor();
|
||||
apiResult.Data.history_Main_Systems = new List<History_Main_system>();
|
||||
foreach (var main in mains)
|
||||
{
|
||||
History_Main_system history_Main_System = new History_Main_system();
|
||||
history_Main_System.main_system_tag = main.Select(a => a.main_system_tag).FirstOrDefault();
|
||||
history_Main_System.full_name = main.Select(a => a.main_name).FirstOrDefault();
|
||||
|
||||
apiResult.Data.history_Main_Systems.Add(history_Main_System);
|
||||
}
|
||||
|
||||
apiResult.Code = "0000";
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
apiResult.Code = "9999";
|
||||
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
|
||||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||||
return Ok(apiResult);
|
||||
}
|
||||
return Ok(apiResult);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
45
FrontendWebApi/Models/Device.cs
Normal file
45
FrontendWebApi/Models/Device.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FrontendWebApi.Models
|
||||
{
|
||||
public class FindDevice
|
||||
{
|
||||
public string main_system_tag { get; set; }
|
||||
public string building_tag { get; set; }
|
||||
public string floor_tag { get; set; }
|
||||
}
|
||||
|
||||
public class BuildList
|
||||
{
|
||||
public string full_name { get; set; }
|
||||
public string building_tag { get; set; }
|
||||
}
|
||||
|
||||
public class FloorList
|
||||
{
|
||||
public string full_name { get; set; }
|
||||
public string floor_tag { get; set; }
|
||||
public List<DeviceLists> device_list {get; set;}
|
||||
}
|
||||
|
||||
public class DeviceLists
|
||||
{
|
||||
public string device_guid { get; set; }
|
||||
public string full_name { get; set; }
|
||||
public string device_coordinate { get; set; }
|
||||
public string status { get; set; }
|
||||
public string device_status
|
||||
{
|
||||
get
|
||||
{
|
||||
Dictionary<string, string> name = new Dictionary<string, string>()
|
||||
{
|
||||
{ "0", "關閉"},
|
||||
{ "1", "正常"},
|
||||
{ "2", "異常"}
|
||||
};
|
||||
return name[status];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user