diff --git a/FrontendWebApi/ApiControllers/HistoryController.cs b/FrontendWebApi/ApiControllers/HistoryController.cs index 884e997..33a89d7 100644 --- a/FrontendWebApi/ApiControllers/HistoryController.cs +++ b/FrontendWebApi/ApiControllers/HistoryController.cs @@ -1021,17 +1021,25 @@ namespace FrontendWebApi.ApiControllers var sqlMainSubSystem = $@"select v1.system_value as main_system_tag, v1.system_key as main_name, v2.system_value as sub_system_tag, v2.system_key as sub_name from variable v2 - inner join variable v1 on v2.system_parent_id = v1.id - where v2.deleted = 0 and + join variable v1 on v2.system_parent_id = v1.id + join (SELECT DISTINCT a.device_system_tag,a.device_name_tag + from device a + join device_item b on b.device_system_tag = a.device_system_tag + and b.device_building_tag COLLATE utf8mb4_unicode_ci = a.device_building_tag + and b.device_name_tag COLLATE utf8mb4_unicode_ci = a.device_name_tag + where a.deleted = 0 and b.deleted = 0 and a.is_link = 1 and b.is_link = 1 + and b.is_show_history = 1) d on d.device_system_tag = v1.system_value and d.device_name_tag = v2.system_value + where v2.deleted = 0 and v1.deleted = 0 and v2.id in ( select ap.ShowView from role_auth ra - inner join auth_page ap on ra.AuthCode = ap.AuthCode - inner join userinfo ui on ra.role_guid = ui.role_guid + join auth_page ap on ra.AuthCode = ap.AuthCode + join userinfo ui on ra.role_guid = ui.role_guid where ui.account = @Account ) order by v1.system_priority, v2.system_priority;"; + var mainSubSystemRawDatas = await frontendRepository.GetAllAsync(sqlMainSubSystem, post); var mainSubSystemRawDatas_GroupBy_main_system_guid = mainSubSystemRawDatas.GroupBy(x => x.main_system_tag).ToList(); diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index 79e31c1..1fc6fff 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -219,8 +219,8 @@ namespace FrontendWebApi.ApiControllers .ToList(); if (newValues.Any()) { - string insertSql = $@"INSERT INTO archive_electric_meter_tenant_bill (device_number, device_name_tag,full_name, created_at) - SELECT device_number, device_name_tag,full_name, NOW() + string insertSql = $@"INSERT INTO archive_electric_meter_tenant_bill (device_number, device_name_tag, created_at) + SELECT device_number, device_name_tag, NOW() FROM device WHERE device_number IN ('{string.Join("', '", newValues)}')"; await backendRepository.ExecuteSql(insertSql); @@ -242,15 +242,15 @@ namespace FrontendWebApi.ApiControllers if (building_tag == "D2") { sqlString = - $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name,tenant_guid " + + $"SELECT bill_id,a.device_number,b.full_name,start_timestamp,end_timestamp,result,bill,tenant_name,tenant_guid " + $"from {TenantBilltable} a join device b on a.device_number =b.device_number " + $"where device_building_tag = 'D1' and a.device_name_tag = '{ElecOrWater}' and a.deleted = 0 || device_building_tag = 'D2' and a.device_name_tag = '{ElecOrWater}' and a.deleted = 0"; } else { sqlString = - $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name,tenant_guid " + - $"from {TenantBilltable} a join device b on a.device_number =b.device_number " + + $"SELECT bill_id,a.device_number,b.full_name,start_timestamp,end_timestamp,result,bill,tenant_name,tenant_guid " + + $"from {TenantBilltable} a join device b on a.device_number = b.device_number " + $"where device_building_tag = '{building_tag}' and a.device_name_tag = '{ElecOrWater}' and a.deleted = 0"; } @@ -508,6 +508,7 @@ namespace FrontendWebApi.ApiControllers string sqlString = $@"SELECT tenant_name, + tenant_guid, start_timestamp, end_timestamp, bill_perKWH, @@ -520,6 +521,7 @@ namespace FrontendWebApi.ApiControllers FROM ( SELECT a.tenant_name, + a.tenant_guid, MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp, MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp, bill_perKWH, @@ -536,7 +538,10 @@ namespace FrontendWebApi.ApiControllers ) AS subquery_alias;"; outputBill = await backendRepository.GetAllAsync(sqlString); - string filePath = CreateOutputForm(outputBill); + string deviceSql = @$"select a.tenant_guid,d.full_name from archive_electric_meter_tenant_bill a join device d on a.device_number = d.device_number"; + var device = await backendRepository.GetAllAsync(deviceSql); + + string filePath = CreateOutputForm(outputBill, device); byte[] file = System.IO.File.ReadAllBytes(filePath); @@ -562,11 +567,11 @@ namespace FrontendWebApi.ApiControllers }; } - public string CreateOutputForm(List outputBill) + public string CreateOutputForm(List outputBill, List device) { try { - string htmlStr = this.getOutputFormHtmlStr(outputBill); + string htmlStr = this.getOutputFormHtmlStr(outputBill, device); string filepath = Configuration.GetValue("FilePath:OutputForm"); if (!Directory.Exists(filepath)) @@ -630,7 +635,7 @@ namespace FrontendWebApi.ApiControllers } } - private string getOutputFormHtmlStr(List outputBill) + private string getOutputFormHtmlStr(List outputBill, List device) { try @@ -651,42 +656,55 @@ namespace FrontendWebApi.ApiControllers string bill = ""; foreach (var item in outputBill) { - bill += $"
" + - $"
" + - $" \"Taipei " + - $"

水電費用明細

" + - $"
" + - $"
" + - $"

費用資訊

" + - $"

用戶: {item.tenant_name}

" + - $"

起訖時間: {item.start_timestamp} ~ {item.end_timestamp}

" + - $" " + - $" " + - $" " + - $" " + - $" " + - $" " + - $" " + - $" " + - $" " + - $" " + - $" " + - $"
用電量: {item.elec_result}度單價: {item.bill_perKWH}元/度電費總計: {item.elec_bill}元
用水量: {item.water_result}度單價: {item.bill_perRCV}元/度水費總計: {item.water_bill}元
" + - $"

總計(費用):各電/水量加總 * 單價(四捨五入)

" + - $"
" + - $"
" + - $"
" + - $"

總計金額

" + - $"
" + - $" {item.total_bill}元 " + - $"
" + - $"
" + - $"
" + - $"
"; + var devices = device.Where(x => x.tenant_guid == item.tenant_guid).Select(x => x.full_name).ToList(); + string deviceList = string.Join(" , ", devices); + + bill += @$"
+
+ Taipei Dome Logo +

水電費用明細

+
+
+

費用資訊

+

用戶: {item.tenant_name}

+

起訖時間: {item.start_timestamp} ~ {item.end_timestamp}

+ + + + + + + + + + + +
用電量: {item.elec_result}度單價: {item.bill_perKWH}元/度電費總計: {item.elec_bill.ToString("#,##0")}元
用水量: {item.water_result}度單價: {item.bill_perRCV}元/度水費總計: {item.water_bill.ToString("#,##0")}元
+

+ 總計(費用):各電/水量加總 * 單價(四捨五入) +

+
+
+
+

總計金額

+
+ {item.total_bill.ToString("#,##0")}元 +
+
+
+

設備列表

+
+ {deviceList} +
+
+
+
"; + + + } - htmlStr = htmlStr.Replace("{{bill}}", bill); diff --git a/FrontendWebApi/Models/Bill.cs b/FrontendWebApi/Models/Bill.cs index 2749a44..783b230 100644 --- a/FrontendWebApi/Models/Bill.cs +++ b/FrontendWebApi/Models/Bill.cs @@ -55,8 +55,7 @@ namespace FrontendWebApi.Models public decimal bill_perKWH { get; set; } public decimal bill_perRCV { get; set; } public int total_bill { get; set; } - - + public string tenant_guid { get; set; } } diff --git a/FrontendWebApi/wwwroot/upload/OutputFormTemplate/import.html b/FrontendWebApi/wwwroot/upload/OutputFormTemplate/import.html index a69998f..73d41ac 100644 --- a/FrontendWebApi/wwwroot/upload/OutputFormTemplate/import.html +++ b/FrontendWebApi/wwwroot/upload/OutputFormTemplate/import.html @@ -9,14 +9,16 @@ - {{bill}} + {{bill}} \ No newline at end of file