[後端] 修改需求: history 列表更改api參數, 修改系統監控列表, 增加variable 全域參數

This commit is contained in:
dev02 2023-06-26 15:41:38 +08:00
parent 441c430948
commit 4956dde967
6 changed files with 176 additions and 19 deletions

View File

@ -131,6 +131,113 @@ namespace FrontendWebApi.ApiControllers
return Ok(apiResult);
}
/// <summary>
/// 系統監控列表(改)
/// </summary>
/// <param name="account"></param>
/// <returns></returns>
[HttpPost]
[Route("api/Device/GetSysMonMainSub")]
public async Task<ActionResult<ApiResult<List<History_Building>>>> GetSysMonMainSub([FromBody] FindDevice fd)
{
ApiResult<List<History_Building>> apiResult = new ApiResult<List<History_Building>>(jwt_str);
if (!jwtlife)
{
apiResult.Code = "5000";
return BadRequest(apiResult);
}
//else if (string.IsNullOrEmpty(fd.building_tag))
//{
// apiResult.Code = "0002";
// apiResult.Msg = "必須選擇東別";
// return apiResult;
//}
try
{
var dbsub = await frontendRepository.GetAllAsync<HistoryDBMainSub>(
@$"select distinct build.full_name as building_name, d.device_building_tag, 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,
dk.device_normal_color, dk.device_close_color, dk.device_error_color,dk.device_normal_flashing, dk.device_close_flashing, dk.device_error_flashing,
dk.device_normal_text, dk.device_close_text, dk.device_error_text,dk.device_normal_point_name, dk.device_close_point_name, dk.device_error_point_name,
dk.device_normal_point_value, dk.device_close_point_value, dk.device_error_point_value
-- di.full_name as device_item_name, di.points as device_item_points, di.unit as device_item_unit, di.is_show_riserDiagram as device_item_is_show_riserDiagram,
-- di.is_controll as device_item_is_controll, di.is_bool as device_item_is_bool, di.is_link as device_item_is_link
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
join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0
left join device_kind dk on v1.system_value = dk.device_system_tag and v2.system_value = dk.device_name_tag and dk.device_building_tag = d.device_building_tag
left join building build on d.device_building_tag = build.building_tag and build.deleted = 0
-- left join device_item di on v2.system_value = di.device_name_tag and v1.system_value = di.device_system_tag and di.deleted = 0
join (
select distinct main_system_tag, sub_system_tag from building_menu where is_link = 1
) as bm on v2.system_value = bm.sub_system_tag and v1.system_value = bm.main_system_tag
where c.account = @account
order by v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type });
var building = dbsub.GroupBy(x => x.device_building_tag).ToList();
apiResult.Data = new List<History_Building>();
foreach (var b in building)
{
History_Building history_Building = new History_Building();
history_Building.building_tag = b.Select(x => x.device_building_tag).FirstOrDefault();
history_Building.building_name = b.Select(x => x.building_name).FirstOrDefault();
history_Building.history_Main_Systems = new List<History_Main_system>();
var mains = dbsub.Where(a => a.device_building_tag == history_Building.building_tag).ToList();
foreach (var main in mains)
{
History_Main_system history_Main_System = new History_Main_system();
history_Main_System.main_system_tag = main.main_system_tag;
history_Main_System.full_name = main.main_name;
history_Main_System.History_Sub_systems = new List<History_Sub_system>();
var subs = dbsub.Where(x => x.main_system_tag == main.main_system_tag).ToList();
foreach (var sub in subs)
{
History_Sub_system history_Sub_System = new History_Sub_system();
history_Sub_System.sub_system_tag = sub.sub_system_tag;
history_Sub_System.full_name = sub.sub_name;
history_Sub_System.device_normal_color = sub.device_normal_color;
history_Sub_System.device_close_color = sub.device_close_color;
history_Sub_System.device_error_color = sub.device_error_color;
history_Sub_System.device_normal_flashing = sub.device_normal_flashing;
history_Sub_System.device_close_flashing = sub.device_close_flashing;
history_Sub_System.device_error_flashing = sub.device_error_flashing;
history_Sub_System.device_normal_text = sub.device_normal_text;
history_Sub_System.device_close_text = sub.device_close_text;
history_Sub_System.device_error_text = sub.device_error_text;
history_Sub_System.device_normal_point_name = sub.device_normal_point_name;
history_Sub_System.device_close_point_name = sub.device_close_point_name;
history_Sub_System.device_error_point_name = sub.device_error_point_name;
history_Sub_System.device_normal_point_value = sub.device_normal_point_value;
history_Sub_System.device_close_point_value = sub.device_close_point_value;
history_Sub_System.device_error_point_value = sub.device_error_point_value;
history_Main_System.History_Sub_systems.Add(history_Sub_System);
}
history_Building.history_Main_Systems.Add(history_Main_System);
}
apiResult.Data.Add(history_Building);
}
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>

View File

@ -212,11 +212,11 @@ namespace FrontendWebApi.ApiControllers
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
join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0 and d.visible = 1 and d.is_link = 1
join device d on v1.system_value = d.device_system_tag and v2.system_value = d.device_name_tag and d.deleted = 0 and d.visible = 1 and d.is_link = 1 and d.device_building_tag = @building_tag
join device_item di on d.device_system_tag=di.device_system_tag and d.device_name_tag=di.device_name_tag
and di.is_link = 1 and di.is_show_history = 1
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 });
order by v1.system_priority, v2.system_priority", new { @account = myUser.account, @sub_system_type = sub_system_type, @main_system_type = main_system_type, building_tag = hf.building_tag });
var dbbuilding = await frontendRepository.GetAllAsync<History_Build>(
@$"select distinct d.building_tag,d.full_name,d.priority from role_auth a
join auth_page b on a.AuthCode = b.AuthCode

View File

@ -1,4 +1,5 @@
using FrontendWebApi.Models;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MySqlX.XDevAPI;
@ -11,6 +12,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Ionic.Zip;
namespace FrontendWebApi.ApiControllers
{
@ -54,12 +56,12 @@ namespace FrontendWebApi.ApiControllers
apiResult.Msg = "表單類別錯誤";
return BadRequest(apiResult);
}
else if (input.floor_tag.Count == 0)
{
apiResult.Code = "0000";
apiResult.Data = new List<HydroMeterOutput>() { };
return Ok(apiResult);
}
//else if (input.floor_tag.Count == 0)
//{
// apiResult.Code = "0000";
// apiResult.Data = new List<HydroMeterOutput>() { };
// return Ok(apiResult);
//}
try
{
@ -84,13 +86,13 @@ namespace FrontendWebApi.ApiControllers
else
buildingSql = " and SUBSTRING_INDEX(SUBSTRING_INDEX(device_number, '_', 2), '_', -1) = @building_tag ";
if (input.floor_tag.Count > 0)
{
if (tag_quantity == "5")
sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag ";
else
sqlWhere = $@" and substring_index(substring_index(device_number, '_', 5), '_', -1) in @floor_tag ";
}
//if (input.floor_tag.Count > 0)
//{
// if (tag_quantity == "5")
// sqlWhere = $@" and substring_index(substring_index(device_number, '_', 3), '_', -1) in @floor_tag ";
// else
// sqlWhere = $@" and substring_index(substring_index(device_number, '_', 5), '_', -1) in @floor_tag ";
//}
if (input.tableType == "year")
{
@ -140,7 +142,7 @@ namespace FrontendWebApi.ApiControllers
) aemm on aemm.start_timestamp >= {aemmStaDate} and aemm.end_timestamp < {aemmEndDate} and aemm.device_number = fd.device_number
order by fd.device_number, fd.date";
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat });
new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, dateFormat = dateFormat });
List<HydroMeterOutput> list = new List<HydroMeterOutput>();
if (tag_quantity == "5")
@ -406,7 +408,14 @@ namespace FrontendWebApi.ApiControllers
[Route("api/ExportElectricList")]
public FileResult OpeExportExcelElec([FromBody] HydroMeterInput input)
{
input = new HydroMeterInput();
input.building_tag = "G6";
input.floor_tag = new List<string>();
input.startTime = "2023-06";
input.tableType = "day";
var result = this.ElectricList(input).Result.Value.Data.ToList();
List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>();
var workbook = new XSSFWorkbook();
#region excel設定
@ -547,8 +556,23 @@ namespace FrontendWebApi.ApiControllers
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
docFile.Add(new Dictionary<string, byte[]>() { { "電表報表", ms.ToArray() } });
var memoryStream = new MemoryStream();
using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(System.Text.Encoding.UTF8))
{
foreach(var d in docFile)
{
foreach(var dic in d)
{
zip.AddEntry(dic.Key, dic.Value);
}
}
zip.Save(memoryStream);
}
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(ms, "application/vnd.ms-excel", "電表報表.xlsx");
return File(memoryStream, "application/octet-stream", "電表報表.zip");
}
[HttpPost]

View File

@ -156,6 +156,24 @@ namespace FrontendWebApi.ApiControllers
return apiResult;
}
public async Task<ActionResult<ApiResult<bool>>> isShowBuilding()
{
ApiResult<bool> apiResult = new ApiResult<bool>(jwt_str);
try
{
var isShow = await backendRepository.GetOneAsync<string>("select system_value from variable where system_type = 'show_building' and deleted = 0");
var isBool = bool.Parse(isShow);
apiResult.Data = isBool;
apiResult.Code = "0000";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = "系統內部錯誤,請聯絡管理者。";
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
return Ok(apiResult);
}
return Ok(apiResult);
}
}
}

View File

@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Autodesk.Forge" Version="1.9.7" />
<PackageReference Include="DotNetZip" Version="1.16.0" />
<PackageReference Include="iTextSharp" Version="5.5.13.2" />
<PackageReference Include="Microsoft.AspNet.WebApi.Cors" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.21" />

View File

@ -59,6 +59,8 @@ namespace FrontendWebApi.Models
public string main_name { get; set; }
public string sub_system_tag { get; set; }
public string sub_name { get; set; }
public string building_name { get; set; }
public string device_building_tag { get; set; }
public string device_number { get; set; }
public string device_full_name { get; set; }
public string device_serial_tag { get; set; }
@ -297,5 +299,10 @@ namespace FrontendWebApi.Models
public string type { get; set; }
}
public class History_Building
{
public string building_tag { get; set; }
public string building_name { get; set; }
public List<History_Main_system> history_Main_Systems { get; set; }
}
}