[後端] 水電表增加設備名稱

This commit is contained in:
dev02 2023-06-19 14:10:09 +08:00
parent 048bb80f9c
commit 59ccf99d1e
2 changed files with 14 additions and 3 deletions

View File

@ -142,6 +142,11 @@ namespace FrontendWebApi.ApiControllers
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql, var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat }); new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat });
foreach (var rd in rawData)
{
rd.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{rd.device_number}' and deleted = 0");
}
List<HydroMeterOutput> list = new List<HydroMeterOutput>(); List<HydroMeterOutput> list = new List<HydroMeterOutput>();
if (tag_quantity == "5") if (tag_quantity == "5")
{ {
@ -314,6 +319,11 @@ namespace FrontendWebApi.ApiControllers
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql, var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataOutput>(sql,
new { startTime = startTime, endTime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat }); new { startTime = startTime, endTime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat });
foreach (var rd in rawData)
{
rd.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{rd.device_number}' and deleted = 0");
}
List<HydroMeterOutput> list = new List<HydroMeterOutput>(); List<HydroMeterOutput> list = new List<HydroMeterOutput>();
if (tag_quantity == "5") if (tag_quantity == "5")
{ {
@ -325,8 +335,8 @@ namespace FrontendWebApi.ApiControllers
else else
{ {
list = rawData list = rawData
.GroupBy(x => new { building_tag = x.device_number.Split("_")[1], floor_tag = x.device_number.Split("_")[4], device_serial_tag = x.device_number.Split("_")[7] }) .GroupBy(x => new { building_tag = x.device_number.Split("_")[1], floor_tag = x.device_number.Split("_")[4], device_master = x.device_number.Split("_")[5], device_serial_tag = x.device_number.Split("_")[7] })
.Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag }) .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag, device_master = x.Key.device_master })
.ToList(); .ToList();
} }
@ -342,7 +352,7 @@ namespace FrontendWebApi.ApiControllers
else else
{ {
l.rawData.AddRange( l.rawData.AddRange(
rawData.Where(x => x.device_number.Split("_")[1] == l.building_tag && x.device_number.Split("_")[4] == l.floor_tag && x.device_number.Split("_")[7] == l.device_serial_tag) rawData.Where(x => x.device_number.Split("_")[1] == l.building_tag && x.device_number.Split("_")[4] == l.floor_tag && x.device_number.Split("_")[5] == l.device_master && x.device_number.Split("_")[7] == l.device_serial_tag)
); );
} }
l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0", l.building_name = await backendRepository.GetOneAsync<string>("select full_name from building where building_tag = @building_tag and deleted = 0",

View File

@ -36,6 +36,7 @@ namespace FrontendWebApi.Models
public string timeStamp { get; set; } public string timeStamp { get; set; }
public string device_number { get; set; } public string device_number { get; set; }
public decimal avg_rawdata { get; set; } public decimal avg_rawdata { get; set; }
public string device_full_name { get; set; }
} }
public class HydroMeterPriceInput public class HydroMeterPriceInput