[Webapi]歷史資料過濾條件修正,水電報表匯出加上千分位&列出所有設備
This commit is contained in:
parent
c1e92638f9
commit
29ee81b469
@ -1021,17 +1021,25 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
var sqlMainSubSystem = $@"select
|
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
|
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
|
from variable v2
|
||||||
inner join variable v1 on v2.system_parent_id = v1.id
|
join variable v1 on v2.system_parent_id = v1.id
|
||||||
where v2.deleted = 0 and
|
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 (
|
v2.id in (
|
||||||
select ap.ShowView
|
select ap.ShowView
|
||||||
from role_auth ra
|
from role_auth ra
|
||||||
inner join auth_page ap on ra.AuthCode = ap.AuthCode
|
join auth_page ap on ra.AuthCode = ap.AuthCode
|
||||||
inner join userinfo ui on ra.role_guid = ui.role_guid
|
join userinfo ui on ra.role_guid = ui.role_guid
|
||||||
where ui.account = @Account
|
where ui.account = @Account
|
||||||
)
|
)
|
||||||
order by v1.system_priority, v2.system_priority;";
|
order by v1.system_priority, v2.system_priority;";
|
||||||
|
|
||||||
|
|
||||||
var mainSubSystemRawDatas = await frontendRepository.GetAllAsync<HistoryDBMainSub>(sqlMainSubSystem, post);
|
var mainSubSystemRawDatas = await frontendRepository.GetAllAsync<HistoryDBMainSub>(sqlMainSubSystem, post);
|
||||||
|
|
||||||
var mainSubSystemRawDatas_GroupBy_main_system_guid = mainSubSystemRawDatas.GroupBy(x => x.main_system_tag).ToList();
|
var mainSubSystemRawDatas_GroupBy_main_system_guid = mainSubSystemRawDatas.GroupBy(x => x.main_system_tag).ToList();
|
||||||
|
@ -219,8 +219,8 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
.ToList();
|
.ToList();
|
||||||
if (newValues.Any())
|
if (newValues.Any())
|
||||||
{
|
{
|
||||||
string insertSql = $@"INSERT INTO archive_electric_meter_tenant_bill (device_number, device_name_tag,full_name, created_at)
|
string insertSql = $@"INSERT INTO archive_electric_meter_tenant_bill (device_number, device_name_tag, created_at)
|
||||||
SELECT device_number, device_name_tag,full_name, NOW()
|
SELECT device_number, device_name_tag, NOW()
|
||||||
FROM device
|
FROM device
|
||||||
WHERE device_number IN ('{string.Join("', '", newValues)}')";
|
WHERE device_number IN ('{string.Join("', '", newValues)}')";
|
||||||
await backendRepository.ExecuteSql(insertSql);
|
await backendRepository.ExecuteSql(insertSql);
|
||||||
@ -242,15 +242,15 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
if (building_tag == "D2")
|
if (building_tag == "D2")
|
||||||
{
|
{
|
||||||
sqlString =
|
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 " +
|
$"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";
|
$"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
|
else
|
||||||
{
|
{
|
||||||
sqlString =
|
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 " +
|
$"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";
|
$"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 =
|
string sqlString =
|
||||||
$@"SELECT
|
$@"SELECT
|
||||||
tenant_name,
|
tenant_name,
|
||||||
|
tenant_guid,
|
||||||
start_timestamp,
|
start_timestamp,
|
||||||
end_timestamp,
|
end_timestamp,
|
||||||
bill_perKWH,
|
bill_perKWH,
|
||||||
@ -520,6 +521,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
a.tenant_name,
|
a.tenant_name,
|
||||||
|
a.tenant_guid,
|
||||||
MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp,
|
MIN(NULLIF(a.start_timestamp, '')) AS start_timestamp,
|
||||||
MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp,
|
MAX(NULLIF(a.end_timestamp, '')) AS end_timestamp,
|
||||||
bill_perKWH,
|
bill_perKWH,
|
||||||
@ -536,7 +538,10 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
) AS subquery_alias;";
|
) AS subquery_alias;";
|
||||||
|
|
||||||
outputBill = await backendRepository.GetAllAsync<OutputBill>(sqlString);
|
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);
|
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
|
try
|
||||||
{
|
{
|
||||||
string htmlStr = this.getOutputFormHtmlStr(outputBill);
|
string htmlStr = this.getOutputFormHtmlStr(outputBill, device);
|
||||||
|
|
||||||
string filepath = Configuration.GetValue<string>("FilePath:OutputForm");
|
string filepath = Configuration.GetValue<string>("FilePath:OutputForm");
|
||||||
if (!Directory.Exists(filepath))
|
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
|
try
|
||||||
@ -651,42 +656,55 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
string bill = "";
|
string bill = "";
|
||||||
foreach (var item in outputBill)
|
foreach (var item in outputBill)
|
||||||
{
|
{
|
||||||
bill += $" <div class=\"container a4-page\"> " +
|
var devices = device.Where(x => x.tenant_guid == item.tenant_guid).Select(x => x.full_name).ToList();
|
||||||
$" <div class=\"header\"> " +
|
string deviceList = string.Join(" , ", devices);
|
||||||
$" <img src=\"{image}\" alt=\"Taipei Dome Logo\" width=\"150\"> " +
|
|
||||||
$" <h2>水電費用明細</h2> " +
|
bill += @$" <div class='container a4-page'>
|
||||||
$" </div> " +
|
<div class='header'>
|
||||||
$" <div class=\"statistics\"> " +
|
<img src='{image}' alt='Taipei Dome Logo' width='150'>
|
||||||
$" <h3>費用資訊</h3> " +
|
<h2>水電費用明細</h2>
|
||||||
$" <p><strong>用戶: </strong>{item.tenant_name}</p> " +
|
</div>
|
||||||
$" <p><strong>起訖時間: </strong>{item.start_timestamp} ~ {item.end_timestamp}</p> " +
|
<div class='statistics'>
|
||||||
$" <table class=\"br\"> " +
|
<h3>費用資訊</h3>
|
||||||
$" <tr> " +
|
<p><strong>用戶: </strong>{item.tenant_name}</p>
|
||||||
$" <td><strong>用電量: </strong>{item.elec_result}度</td> " +
|
<p><strong>起訖時間: </strong>{item.start_timestamp} ~ {item.end_timestamp}</p>
|
||||||
$" <td><strong>單價: </strong>{item.bill_perKWH}元/度</td> " +
|
<table class='br'>
|
||||||
$" <td><strong>電費總計: </strong>{item.elec_bill}元</td> " +
|
<tr>
|
||||||
$" </tr> " +
|
<td><strong>用電量: </strong>{item.elec_result}度</td>
|
||||||
$" <tr> " +
|
<td><strong>單價: </strong>{item.bill_perKWH}元/度</td>
|
||||||
$" <td><strong>用水量: </strong>{item.water_result}度</td> " +
|
<td><strong>電費總計: </strong>{item.elec_bill.ToString("#,##0")}元</td>
|
||||||
$" <td><strong>單價: </strong>{item.bill_perRCV}元/度</td> " +
|
</tr>
|
||||||
$" <td><strong>水費總計: </strong>{item.water_bill}元</td> " +
|
<tr>
|
||||||
$" </tr> " +
|
<td><strong>用水量: </strong>{item.water_result}度</td>
|
||||||
$" </table> " +
|
<td><strong>單價: </strong>{item.bill_perRCV}元/度</td>
|
||||||
$" <p style=\"font-size: larger; color: red; text-align: right; margin: 0; padding: 0;\"><strong>總計(費用):各電/水量加總 * 單價(四捨五入)</p> " +
|
<td><strong>水費總計: </strong>{item.water_bill.ToString("#,##0")}元</td>
|
||||||
$" </div> " +
|
</tr>
|
||||||
$" <div class=\"total\"> " +
|
</table>
|
||||||
$" <div class=\"total-area\"> " +
|
<p class='warnTxt'>
|
||||||
$" <p>總計金額</p> " +
|
<strong>總計(費用):各電/水量加總 * 單價(四捨五入)</strong>
|
||||||
$" <div class=\"total-box\"> " +
|
</p>
|
||||||
$" <span class=\"total-money\">{item.total_bill}</span>元 " +
|
</div>
|
||||||
$" </div> " +
|
<div class='total'>
|
||||||
$" </div> " +
|
<div class='total-area'>
|
||||||
$" </div> " +
|
<h3>總計金額</h3>
|
||||||
$" </div>";
|
<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);
|
htmlStr = htmlStr.Replace("{{bill}}", bill);
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,8 +55,7 @@ namespace FrontendWebApi.Models
|
|||||||
public decimal bill_perKWH { get; set; }
|
public decimal bill_perKWH { get; set; }
|
||||||
public decimal bill_perRCV { get; set; }
|
public decimal bill_perRCV { get; set; }
|
||||||
public int total_bill { get; set; }
|
public int total_bill { get; set; }
|
||||||
|
public string tenant_guid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
font-family: Arial, sans-serif;
|
font-family: Arial, sans-serif;
|
||||||
zoom:1.5;
|
margin: 1cm;
|
||||||
|
zoom: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
.container {
|
||||||
@ -17,6 +18,7 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
max-width: 21cm;
|
max-width: 21cm;
|
||||||
max-height: 29.7cm;
|
max-height: 29.7cm;
|
||||||
|
word-wrap: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
@ -26,15 +28,16 @@
|
|||||||
|
|
||||||
.header img {
|
.header img {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left:10px;
|
||||||
top: 50%;
|
top: 20%;
|
||||||
transform: translateY(-50%);
|
transform: translateY(-50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.header h2 {
|
.header h2 {
|
||||||
text-align: center;
|
|
||||||
font-size: 35px;
|
font-size: 35px;
|
||||||
|
text-align: center;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
|
margin: 0 auto 10px auto
|
||||||
}
|
}
|
||||||
|
|
||||||
.statistics {
|
.statistics {
|
||||||
@ -49,26 +52,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.statistics table {
|
.statistics table {
|
||||||
width:700px;
|
width: 700px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.statistics p {
|
.statistics p {
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.total {
|
.total {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: end;
|
}
|
||||||
justify-content: flex-start;
|
|
||||||
padding: 20px 10px;
|
.total-area {
|
||||||
|
flex: 1;
|
||||||
|
padding: 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.total .total-area p {
|
.total .total-area p {
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
margin: 20px 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.total-box {
|
.total-box {
|
||||||
width: 400px;
|
width: 95%;
|
||||||
height: 180px;
|
height: 100px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
@ -80,25 +87,31 @@
|
|||||||
font-size: 40px;
|
font-size: 40px;
|
||||||
padding-right: 8px;
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.warnTxt {
|
||||||
|
font-size: larger;
|
||||||
|
color: red;
|
||||||
|
text-align: right;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
@page {
|
@page {
|
||||||
size: A4;
|
size: A4;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
|
||||||
margin: 1cm;
|
|
||||||
}
|
|
||||||
|
|
||||||
.a4-page {
|
.a4-page {
|
||||||
page-break-before: always;
|
page-break-before: always;
|
||||||
}
|
}
|
||||||
|
|
||||||
.br {
|
.br {
|
||||||
border-spacing: 0px 20px;
|
border-spacing: 0px 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
{{bill}}
|
{{bill}}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user