修改水電報表Api

This commit is contained in:
張家睿 2024-01-23 18:21:53 +08:00
parent 5c8abc1f19
commit 61d9b8f2c0
3 changed files with 29 additions and 22 deletions

View File

@ -18,8 +18,8 @@ namespace FrontendWebApi.ApiControllers
{ {
//[Route("api/[controller]")] //[Route("api/[controller]")]
//[ApiController] //[ApiController]
//public class TenantBillController public class TenantBillController
public class TenantBillController : MyBaseApiController<TenantBillController> //public class TenantBillController : MyBaseApiController<TenantBillController>
{ {
private readonly IBackendRepository backendRepository; private readonly IBackendRepository backendRepository;
@ -41,7 +41,7 @@ namespace FrontendWebApi.ApiControllers
List<TenantList> tenantList = new List<TenantList>(); List<TenantList> tenantList = new List<TenantList>();
try 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"; $"from {TenantListtable} order by created_at";
tenantList = await backendRepository.GetAllAsync<TenantList>(sqlString); tenantList = await backendRepository.GetAllAsync<TenantList>(sqlString);
@ -73,8 +73,8 @@ namespace FrontendWebApi.ApiControllers
var bill_perRCV = tl.bill_perRCV; var bill_perRCV = tl.bill_perRCV;
var created_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); 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) " + var sqlString = $"INSERT INTO {TenantListtable} (tenant_guid,list_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}')"; $"VALUES ('{tenant_guid}',{tl.list_id},'{tenant_name}', {bill_perKWH}, {bill_perRCV},'{tl.created_by}', '{created_at}')";
await backendRepository.ExecuteSql(sqlString); await backendRepository.ExecuteSql(sqlString);
@ -103,7 +103,7 @@ namespace FrontendWebApi.ApiControllers
$"`tenant_name` = '{tl.tenant_name}', " + $"`tenant_name` = '{tl.tenant_name}', " +
$"`bill_perKWH` = {tl.bill_perKWH}, " + $"`bill_perKWH` = {tl.bill_perKWH}, " +
$"`bill_perRCV` = {tl.bill_perRCV}, " + $"`bill_perRCV` = {tl.bill_perRCV}, " +
$"`updated_by` = {tl.updated_by}, " + $"`updated_by` = '{tl.updated_by}', " +
$"`updated_at` = '{updated_at}' " + $"`updated_at` = '{updated_at}' " +
$"WHERE `tenant_guid` = '{tl.tenant_guid}'"; $"WHERE `tenant_guid` = '{tl.tenant_guid}'";
@ -165,26 +165,26 @@ namespace FrontendWebApi.ApiControllers
if (building_tag == "ALL") if (building_tag == "ALL")
{ {
sqlString = 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" + $"from {TenantBilltable} a join device b on a.device_number =b.device_number" +
$"where a.device_name_tag = '{ElecOrWater}' "; $"where a.device_name_tag = '{ElecOrWater}' ";
} }
else if (building_tag == "D2") else if (building_tag == "D2")
{ {
sqlString = 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 " + $"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}'"; $"where device_building_tag = 'D1' and a.device_name_tag = '{ElecOrWater}' || device_building_tag = 'D2' and a.device_name_tag = '{ElecOrWater}'";
} }
else else
{ {
sqlString = 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 " + $"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}' "; $"where device_building_tag = '{building_tag}' and a.device_name_tag = '{ElecOrWater}' ";
} }
tenantBill = await backendRepository.GetAllAsync<TenantBill>(sqlString); tenantBill = await backendRepository.GetAllAsync<TenantBill>(sqlString);
@ -210,17 +210,17 @@ namespace FrontendWebApi.ApiControllers
{ {
string bill_per = tb.tableType == "elec" ? "bill_perKWH" : "bill_perRCV"; string bill_per = tb.tableType == "elec" ? "bill_perKWH" : "bill_perRCV";
var updated_at = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); 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 start_timestamp = tb.start_timestamp;
var end_timestamp = tb.end_timestamp.ToString("yyyy-MM-dd HH:mm:ss"); var end_timestamp = tb.end_timestamp;
string sqlString = null; string sqlString = null;
string startMonth = tb.start_timestamp.Year.ToString() + tb.start_timestamp.Month.ToString("D2"); string startMonth = tb.start_timestamp.Split("-")[0] + tb.start_timestamp.Split("-")[1];
string endMonth = tb.end_timestamp.Year.ToString() + tb.end_timestamp.Month.ToString("D2"); string endMonth = tb.end_timestamp.Split("-")[0] + tb.end_timestamp.Split("-")[1];
if (startMonth == endMonth) if (startMonth == endMonth)
{ {
sqlString = sqlString =
$"UPDATE {TenantBilltable} " + $"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= " + $"result= " +
$"(select sum(sub_result) " + $"(select sum(sub_result) " +
$"from archive_electric_water_meter_day_{startMonth} " + $"from archive_electric_water_meter_day_{startMonth} " +
@ -237,7 +237,7 @@ namespace FrontendWebApi.ApiControllers
{ {
sqlString = sqlString =
$"UPDATE {TenantBilltable} " + $"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= " + $"result= " +
$"(SELECT sum(sub_result) " + $"(SELECT sum(sub_result) " +
$"FROM ( " + $"FROM ( " +

View File

@ -7,7 +7,7 @@ namespace FrontendWebApi.Models
public class TenantList public class TenantList
{ {
public string tenant_guid { get; set; } 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 string tenant_name { get; set; }
public decimal bill_perKWH { get; set; } public decimal bill_perKWH { get; set; }
public decimal bill_perRCV { get; set; } public decimal bill_perRCV { get; set; }
@ -20,12 +20,12 @@ namespace FrontendWebApi.Models
public class TenantBill public class TenantBill
{ {
public int tenant_id { get; set; } public int bill_id { get; set; }
public string tenant_name { get; set; } public string tenant_name { get; set; }
public string device_number { get; set; } public string device_number { get; set; }
public string full_name { get; set; } public string full_name { get; set; }
public DateTime start_timestamp { get; set; } public string start_timestamp { get; set; }
public DateTime end_timestamp { get; set; } public string end_timestamp { get; set; }
public string device_name_tag { get; set; } public string device_name_tag { get; set; }
public decimal result { get; set; } public decimal result { get; set; }
public int bill { get; set; } public int bill { get; set; }
@ -42,8 +42,8 @@ namespace FrontendWebApi.Models
public class OutputBill public class OutputBill
{ {
public string tenant_name { get; set; } public string tenant_name { get; set; }
public DateTime start_timestamp { get; set; } public string start_timestamp { get; set; }
public DateTime end_timestamp { get; set; } public string end_timestamp { get; set; }
public decimal kwh_total { get; set; } public decimal kwh_total { get; set; }
public decimal bill_perKWH { get; set; } public decimal bill_perKWH { get; set; }
public int electric_total { get; set; } public int electric_total { get; set; }

View File

@ -24,6 +24,8 @@ using System.IdentityModel.Tokens.Jwt;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using WkHtmlToPdfDotNet.Contracts;
using WkHtmlToPdfDotNet;
using static FrontendWebApi.Jwt.JwtHelpers; using static FrontendWebApi.Jwt.JwtHelpers;
namespace FrontendWebApi namespace FrontendWebApi
@ -81,6 +83,11 @@ namespace FrontendWebApi
.AddConsole(); .AddConsole();
}); });
#region htmlÂàPDF ª`¤J
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
#endregion
#region DBHelper ª`¤J #region DBHelper ª`¤J
services.Configure<DBConfig>(Configuration.GetSection("DBConfig")); services.Configure<DBConfig>(Configuration.GetSection("DBConfig"));
services.AddTransient<Repository.Helper.IDatabaseHelper, Repository.Helper.DatabaseHelper>(); services.AddTransient<Repository.Helper.IDatabaseHelper, Repository.Helper.DatabaseHelper>();