From 050db7dda514757be84b78605067b437f96fb41b Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Tue, 12 Mar 2024 13:41:11 +0800 Subject: [PATCH] =?UTF-8?q?[WebApi]=E4=BF=AE=E6=94=B9=E6=B0=B4=E9=9B=BB?= =?UTF-8?q?=E5=A0=B1=E8=A1=A8=E5=B0=8FBug=20&=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=8C=AF=E5=87=BApdf=E7=B8=BD=E5=83=B9=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E4=B8=A6=E5=8A=A0=E4=B8=8A=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/TenantBillController.cs | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index f3954be..50dda76 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -401,7 +401,7 @@ namespace FrontendWebApi.ApiControllers List tenantBill = new List(); try { - string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and a.deleted = 0"; + string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and deleted = 0"; tenantBill = await backendRepository.GetAllAsync(sqlString); if (tenantBill.Count > 1) @@ -445,7 +445,7 @@ namespace FrontendWebApi.ApiControllers try { - string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and a.deleted = 0"; + string sqlString = $@"select * from {TenantBilltable} WHERE tenant_guid= '{tb.tenant_guid}' and deleted = 0"; tenantBill = await backendRepository.GetAllAsync(sqlString); foreach (TenantBill t in tenantBill) @@ -507,21 +507,31 @@ namespace FrontendWebApi.ApiControllers { string sqlString = $@"SELECT - a.tenant_name, - MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp, - MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp, - bill_perKWH, - bill_perRCV, - SUM(CASE WHEN a.device_name_tag = 'E4' THEN result ELSE 0 END) AS elec_result, - SUM(CASE WHEN a.device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result, - SUM(CASE WHEN a.device_name_tag = 'E4' THEN bill ELSE 0 END) AS elec_bill, - SUM(CASE WHEN a.device_name_tag = 'W1' THEN bill ELSE 0 END) AS water_bill, - SUM(bill) AS total_bill - FROM archive_electric_meter_tenant_bill a - JOIN archive_electric_meter_tenant_list b ON a.tenant_guid = b.tenant_guid - join device c on a.device_number = c.device_number - where {building_tag} - GROUP BY a.tenant_name;"; + tenant_name, + start_timestamp, + end_timestamp, + bill_perKWH, + bill_perRCV, + elec_result, + water_result, + bill_perKWH * elec_result AS elec_bill, + bill_perRCV * water_result AS water_bill, + ROUND(bill_perKWH * elec_result + bill_perRCV * water_result) AS total_bill + FROM ( + SELECT + a.tenant_name, + MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp, + MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp, + bill_perKWH, + bill_perRCV, + SUM(CASE WHEN a.device_name_tag = 'E4' THEN result ELSE 0 END) AS elec_result, + SUM(CASE WHEN a.device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result + FROM archive_electric_meter_tenant_bill a + JOIN archive_electric_meter_tenant_list b ON a.tenant_guid = b.tenant_guid + JOIN device c ON a.device_number = c.device_number + WHERE {building_tag} + GROUP BY a.tenant_name + ) subquery_alias"; outputBill = await backendRepository.GetAllAsync(sqlString); string filePath = CreateOutputForm(outputBill); @@ -660,6 +670,7 @@ namespace FrontendWebApi.ApiControllers $" 水費總計: {item.water_bill}元 " + $" " + $" " + + $"

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

" + $" " + $"
" + $"
" +