[Webapi]歷史資料過濾條件修正,水電報表匯出加上千分位&列出所有設備
This commit is contained in:
parent
c1e92638f9
commit
29ee81b469
@ -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<HistoryDBMainSub>(sqlMainSubSystem, post);
|
||||
|
||||
var mainSubSystemRawDatas_GroupBy_main_system_guid = mainSubSystemRawDatas.GroupBy(x => x.main_system_tag).ToList();
|
||||
|
@ -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<OutputBill>(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<TenantBill>(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> outputBill)
|
||||
public string CreateOutputForm(List<OutputBill> outputBill, List<TenantBill> device)
|
||||
{
|
||||
try
|
||||
{
|
||||
string htmlStr = this.getOutputFormHtmlStr(outputBill);
|
||||
string htmlStr = this.getOutputFormHtmlStr(outputBill, device);
|
||||
|
||||
string filepath = Configuration.GetValue<string>("FilePath:OutputForm");
|
||||
if (!Directory.Exists(filepath))
|
||||
@ -630,7 +635,7 @@ namespace FrontendWebApi.ApiControllers
|
||||
}
|
||||
}
|
||||
|
||||
private string getOutputFormHtmlStr(List<OutputBill> outputBill)
|
||||
private string getOutputFormHtmlStr(List<OutputBill> outputBill, List<TenantBill> device)
|
||||
{
|
||||
|
||||
try
|
||||
@ -651,42 +656,55 @@ namespace FrontendWebApi.ApiControllers
|
||||
string bill = "";
|
||||
foreach (var item in outputBill)
|
||||
{
|
||||
bill += $" <div class=\"container a4-page\"> " +
|
||||
$" <div class=\"header\"> " +
|
||||
$" <img src=\"{image}\" alt=\"Taipei Dome Logo\" width=\"150\"> " +
|
||||
$" <h2>水電費用明細</h2> " +
|
||||
$" </div> " +
|
||||
$" <div class=\"statistics\"> " +
|
||||
$" <h3>費用資訊</h3> " +
|
||||
$" <p><strong>用戶: </strong>{item.tenant_name}</p> " +
|
||||
$" <p><strong>起訖時間: </strong>{item.start_timestamp} ~ {item.end_timestamp}</p> " +
|
||||
$" <table class=\"br\"> " +
|
||||
$" <tr> " +
|
||||
$" <td><strong>用電量: </strong>{item.elec_result}度</td> " +
|
||||
$" <td><strong>單價: </strong>{item.bill_perKWH}元/度</td> " +
|
||||
$" <td><strong>電費總計: </strong>{item.elec_bill}元</td> " +
|
||||
$" </tr> " +
|
||||
$" <tr> " +
|
||||
$" <td><strong>用水量: </strong>{item.water_result}度</td> " +
|
||||
$" <td><strong>單價: </strong>{item.bill_perRCV}元/度</td> " +
|
||||
$" <td><strong>水費總計: </strong>{item.water_bill}元</td> " +
|
||||
$" </tr> " +
|
||||
$" </table> " +
|
||||
$" <p style=\"font-size: larger; color: red; text-align: right; margin: 0; padding: 0;\"><strong>總計(費用):各電/水量加總 * 單價(四捨五入)</p> " +
|
||||
$" </div> " +
|
||||
$" <div class=\"total\"> " +
|
||||
$" <div class=\"total-area\"> " +
|
||||
$" <p>總計金額</p> " +
|
||||
$" <div class=\"total-box\"> " +
|
||||
$" <span class=\"total-money\">{item.total_bill}</span>元 " +
|
||||
$" </div> " +
|
||||
$" </div> " +
|
||||
$" </div> " +
|
||||
$" </div>";
|
||||
var devices = device.Where(x => x.tenant_guid == item.tenant_guid).Select(x => x.full_name).ToList();
|
||||
string deviceList = string.Join(" , ", devices);
|
||||
|
||||
bill += @$" <div class='container a4-page'>
|
||||
<div class='header'>
|
||||
<img src='{image}' alt='Taipei Dome Logo' width='150'>
|
||||
<h2>水電費用明細</h2>
|
||||
</div>
|
||||
<div class='statistics'>
|
||||
<h3>費用資訊</h3>
|
||||
<p><strong>用戶: </strong>{item.tenant_name}</p>
|
||||
<p><strong>起訖時間: </strong>{item.start_timestamp} ~ {item.end_timestamp}</p>
|
||||
<table class='br'>
|
||||
<tr>
|
||||
<td><strong>用電量: </strong>{item.elec_result}度</td>
|
||||
<td><strong>單價: </strong>{item.bill_perKWH}元/度</td>
|
||||
<td><strong>電費總計: </strong>{item.elec_bill.ToString("#,##0")}元</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>用水量: </strong>{item.water_result}度</td>
|
||||
<td><strong>單價: </strong>{item.bill_perRCV}元/度</td>
|
||||
<td><strong>水費總計: </strong>{item.water_bill.ToString("#,##0")}元</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class='warnTxt'>
|
||||
<strong>總計(費用):各電/水量加總 * 單價(四捨五入)</strong>
|
||||
</p>
|
||||
</div>
|
||||
<div class='total'>
|
||||
<div class='total-area'>
|
||||
<h3>總計金額</h3>
|
||||
<div class='total-box'>
|
||||
<span class='total-money'>{item.total_bill.ToString("#,##0")}</span>元
|
||||
</div>
|
||||
</div>
|
||||
<div class='total-area'>
|
||||
<h3>設備列表</h3>
|
||||
<div>
|
||||
{deviceList}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>";
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
htmlStr = htmlStr.Replace("{{bill}}", bill);
|
||||
|
||||
|
||||
|
@ -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; }
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,8 @@
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
zoom:1.5;
|
||||
margin: 1cm;
|
||||
zoom: 1.5;
|
||||
}
|
||||
|
||||
.container {
|
||||
@ -17,6 +18,7 @@
|
||||
height: 100%;
|
||||
max-width: 21cm;
|
||||
max-height: 29.7cm;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.header {
|
||||
@ -26,15 +28,16 @@
|
||||
|
||||
.header img {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 50%;
|
||||
left:10px;
|
||||
top: 20%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.header h2 {
|
||||
text-align: center;
|
||||
font-size: 35px;
|
||||
text-align: center;
|
||||
font-weight: normal;
|
||||
margin: 0 auto 10px auto
|
||||
}
|
||||
|
||||
.statistics {
|
||||
@ -49,26 +52,30 @@
|
||||
}
|
||||
|
||||
.statistics table {
|
||||
width:700px;
|
||||
width: 700px;
|
||||
}
|
||||
|
||||
.statistics p {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.total {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
justify-content: flex-start;
|
||||
padding: 20px 10px;
|
||||
}
|
||||
|
||||
.total-area {
|
||||
flex: 1;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.total .total-area p {
|
||||
font-size: 1.2rem;
|
||||
margin: 20px 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.total-box {
|
||||
width: 400px;
|
||||
height: 180px;
|
||||
width: 95%;
|
||||
height: 100px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: flex-start;
|
||||
@ -80,25 +87,31 @@
|
||||
font-size: 40px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
.warnTxt {
|
||||
font-size: larger;
|
||||
color: red;
|
||||
text-align: right;
|
||||
margin: 0 !important;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 1cm;
|
||||
}
|
||||
|
||||
.a4-page {
|
||||
page-break-before: always;
|
||||
}
|
||||
|
||||
.br {
|
||||
border-spacing: 0px 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
{{bill}}
|
||||
{{bill}}
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user