From 61d9b8f2c05f8fe62387782f5ca01aeb8d1ca991 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Tue, 23 Jan 2024 18:21:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B0=B4=E9=9B=BB=E5=A0=B1?= =?UTF-8?q?=E8=A1=A8Api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/TenantBillController.cs | 32 +++++++++---------- FrontendWebApi/Models/Bill.cs | 12 +++---- FrontendWebApi/Startup.cs | 7 ++++ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/FrontendWebApi/ApiControllers/TenantBillController.cs b/FrontendWebApi/ApiControllers/TenantBillController.cs index 6e17d1a..09da3a9 100644 --- a/FrontendWebApi/ApiControllers/TenantBillController.cs +++ b/FrontendWebApi/ApiControllers/TenantBillController.cs @@ -18,8 +18,8 @@ namespace FrontendWebApi.ApiControllers { //[Route("api/[controller]")] //[ApiController] - //public class TenantBillController - public class TenantBillController : MyBaseApiController + public class TenantBillController + //public class TenantBillController : MyBaseApiController { private readonly IBackendRepository backendRepository; @@ -41,7 +41,7 @@ namespace FrontendWebApi.ApiControllers List tenantList = new List(); try { - var sqlString = $"SELECT tenant_guid,tenant_id,tenant_name,bill_perKWH,bill_perRCV " + + var sqlString = $"SELECT tenant_guid,list_id,tenant_name,bill_perKWH,bill_perRCV " + $"from {TenantListtable} order by created_at"; tenantList = await backendRepository.GetAllAsync(sqlString); @@ -73,8 +73,8 @@ namespace FrontendWebApi.ApiControllers var bill_perRCV = tl.bill_perRCV; var created_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - var sqlString = $"INSERT INTO {TenantListtable} (tenant_guid,tenant_id,tenant_name, bill_perKWH, bill_perRCV, created_by,created_at) " + - $"VALUES ('{tenant_guid}',{tl.tenant_id},'{tenant_name}', {bill_perKWH}, {bill_perRCV},'{tl.created_by}', '{created_at}')"; + var sqlString = $"INSERT INTO {TenantListtable} (tenant_guid,list_id,tenant_name, bill_perKWH, bill_perRCV, created_by,created_at) " + + $"VALUES ('{tenant_guid}',{tl.list_id},'{tenant_name}', {bill_perKWH}, {bill_perRCV},'{tl.created_by}', '{created_at}')"; await backendRepository.ExecuteSql(sqlString); @@ -103,7 +103,7 @@ namespace FrontendWebApi.ApiControllers $"`tenant_name` = '{tl.tenant_name}', " + $"`bill_perKWH` = {tl.bill_perKWH}, " + $"`bill_perRCV` = {tl.bill_perRCV}, " + - $"`updated_by` = {tl.updated_by}, " + + $"`updated_by` = '{tl.updated_by}', " + $"`updated_at` = '{updated_at}' " + $"WHERE `tenant_guid` = '{tl.tenant_guid}'"; @@ -165,26 +165,26 @@ namespace FrontendWebApi.ApiControllers if (building_tag == "ALL") { sqlString = - $"SELECT tenant_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name " + + $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name " + $"from {TenantBilltable} a join device b on a.device_number =b.device_number" + $"where a.device_name_tag = '{ElecOrWater}' "; } else if (building_tag == "D2") { sqlString = - $"SELECT tenant_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name " + + $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name " + $"from {TenantBilltable} a join device b on a.device_number =b.device_number " + $"where device_building_tag = 'D1' and a.device_name_tag = '{ElecOrWater}' || device_building_tag = 'D2' and a.device_name_tag = '{ElecOrWater}'"; } else { sqlString = - $"SELECT tenant_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name " + + $"SELECT bill_id,a.device_number,a.full_name,start_timestamp,end_timestamp,result,bill,tenant_name " + $"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}' "; } - + tenantBill = await backendRepository.GetAllAsync(sqlString); @@ -210,17 +210,17 @@ namespace FrontendWebApi.ApiControllers { string bill_per = tb.tableType == "elec" ? "bill_perKWH" : "bill_perRCV"; var updated_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); - var start_timestamp = tb.start_timestamp.ToString("yyyy-MM-dd HH:mm:ss"); - var end_timestamp = tb.end_timestamp.ToString("yyyy-MM-dd HH:mm:ss"); + var start_timestamp = tb.start_timestamp; + var end_timestamp = tb.end_timestamp; string sqlString = null; - string startMonth = tb.start_timestamp.Year.ToString() + tb.start_timestamp.Month.ToString("D2"); - string endMonth = tb.end_timestamp.Year.ToString() + tb.end_timestamp.Month.ToString("D2"); + string startMonth = tb.start_timestamp.Split("-")[0] + tb.start_timestamp.Split("-")[1]; + string endMonth = tb.end_timestamp.Split("-")[0] + tb.end_timestamp.Split("-")[1]; if (startMonth == endMonth) { sqlString = $"UPDATE {TenantBilltable} " + - $"set tenant_id = {tb.tenant_id} ,tenant_name = '{tb.tenant_name}', start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + + $"set bill_id = {tb.bill_id} ,tenant_name = '{tb.tenant_name}', start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + $"result= " + $"(select sum(sub_result) " + $"from archive_electric_water_meter_day_{startMonth} " + @@ -237,7 +237,7 @@ namespace FrontendWebApi.ApiControllers { sqlString = $"UPDATE {TenantBilltable} " + - $"set tenant_id = {tb.tenant_id} ,tenant_name = '{tb.tenant_name}', start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + + $"set bill_id = {tb.bill_id} ,tenant_name = '{tb.tenant_name}', start_timestamp = '{start_timestamp}',end_timestamp = '{end_timestamp}' , " + $"result= " + $"(SELECT sum(sub_result) " + $"FROM ( " + diff --git a/FrontendWebApi/Models/Bill.cs b/FrontendWebApi/Models/Bill.cs index 2b58ded..d933d4d 100644 --- a/FrontendWebApi/Models/Bill.cs +++ b/FrontendWebApi/Models/Bill.cs @@ -7,7 +7,7 @@ namespace FrontendWebApi.Models public class TenantList { public string tenant_guid { get; set; } - public int tenant_id { get; set; } + public int list_id { get; set; } public string tenant_name { get; set; } public decimal bill_perKWH { get; set; } public decimal bill_perRCV { get; set; } @@ -20,12 +20,12 @@ namespace FrontendWebApi.Models public class TenantBill { - public int tenant_id { get; set; } + public int bill_id { get; set; } public string tenant_name { get; set; } public string device_number { get; set; } public string full_name { get; set; } - public DateTime start_timestamp { get; set; } - public DateTime end_timestamp { get; set; } + public string start_timestamp { get; set; } + public string end_timestamp { get; set; } public string device_name_tag { get; set; } public decimal result { get; set; } public int bill { get; set; } @@ -42,8 +42,8 @@ namespace FrontendWebApi.Models public class OutputBill { public string tenant_name { get; set; } - public DateTime start_timestamp { get; set; } - public DateTime end_timestamp { get; set; } + public string start_timestamp { get; set; } + public string end_timestamp { get; set; } public decimal kwh_total { get; set; } public decimal bill_perKWH { get; set; } public int electric_total { get; set; } diff --git a/FrontendWebApi/Startup.cs b/FrontendWebApi/Startup.cs index 7ae8075..f2c656e 100644 --- a/FrontendWebApi/Startup.cs +++ b/FrontendWebApi/Startup.cs @@ -24,6 +24,8 @@ using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Text; using System.Threading.Tasks; +using WkHtmlToPdfDotNet.Contracts; +using WkHtmlToPdfDotNet; using static FrontendWebApi.Jwt.JwtHelpers; namespace FrontendWebApi @@ -81,6 +83,11 @@ namespace FrontendWebApi .AddConsole(); }); + #region htmlÂàPDF ª`¤J + services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); + #endregion + + #region DBHelper ª`¤J services.Configure(Configuration.GetSection("DBConfig")); services.AddTransient();