[WebAPI]新增水電報表沒有用戶選擇設備就不能匯出的限制

This commit is contained in:
張家睿 2024-02-21 09:10:02 +08:00
parent f166793f04
commit a6aa294e7f
3 changed files with 46 additions and 15 deletions

View File

@ -64,7 +64,8 @@ namespace FrontendWebApi.ApiControllers
JOIN building b ON bm.building_tag = b.building_tag and b.deleted = 0
join variable v2 on ap.ShowView = v2.id and v2.deleted = 0
join variable v1 on v2.system_parent_id = v1.id
GROUP BY b.building_tag, b.full_name, v1.system_value, v1.system_key";
GROUP BY b.building_tag, b.full_name, v1.system_value, v1.system_key
order by b.priority, v1.system_priority, bm.priority, v2.system_priority, v2.created_at DESC";
var alarmRecordPanelRawDatas = await frontendRepository.GetAllAsync<AlarmRecordPanelRawData>(sqlBuildingMain, new { Account = account });

View File

@ -436,11 +436,31 @@ namespace FrontendWebApi.ApiControllers
[HttpPost]
public async Task<IActionResult> OutputTenantBill()
public async Task<IActionResult> OutputTenantBill([FromBody] TenantBill tb)
{
List<OutputBill> outputBill = new List<OutputBill>();
try
{
List<string> buildings = tb.building_tag_list;
string building_tag = "";
foreach (var item in buildings)
{
if (item == buildings[0])
{
building_tag = item == "D2" ? $@"device_building_tag = 'D1' || device_building_tag = '{item}'" : $@"device_building_tag = '{item}'" ;
}
else
{
building_tag += item == "D2" ? $@"|| device_building_tag = 'D1' || device_building_tag = '{item}'" : $@"|| device_building_tag = '{item}'";
}
}
string checkDataSql = $@"select * from archive_electric_meter_tenant_bill a
join device c on a.device_number = c.device_number
WHERE tenant_name is not null and tenant_guid is not null and tenant_name != '' and tenant_guid !=''
AND ({building_tag})";
var existData = await backendRepository.GetAllAsync<string>(checkDataSql);
if (existData.Count != 0)
{
string sqlString =
$@"SELECT
@ -449,14 +469,15 @@ namespace FrontendWebApi.ApiControllers
MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp,
bill_perKWH,
bill_perRCV,
SUM(CASE WHEN device_name_tag = 'E4' THEN result ELSE 0 END) AS elec_result,
SUM(CASE WHEN device_name_tag = 'W1' THEN result ELSE 0 END) AS water_result,
SUM(CASE WHEN device_name_tag = 'E4' THEN bill ELSE 0 END) AS elec_bill,
SUM(CASE WHEN device_name_tag = 'W1' THEN bill ELSE 0 END) AS water_bill,
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
GROUP BY a.tenant_name;";
join device c on a.device_number = c.device_number
where {building_tag} ";
outputBill = await backendRepository.GetAllAsync<OutputBill>(sqlString);
string filePath = CreateOutputForm(outputBill);
@ -469,6 +490,12 @@ namespace FrontendWebApi.ApiControllers
FileDownloadName = "水電報表.pdf"
};
}
else
{
var data = new { Code = "0001",Msg = "還沒有選擇用戶,無法匯出檔案。"};
return StatusCode(400, data);
}
}
catch (Exception exception)
{
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace FrontendWebApi.Models
{
@ -36,6 +37,8 @@ namespace FrontendWebApi.Models
public string tenant_guid { get; set; }
public string tableType { get; set; }
public string building_tag { get; set; }
public List<string> building_tag_list { get; set; }
}