diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index 0b9d40d..2ff72b7 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -142,30 +142,26 @@ namespace FrontendWebApi.ApiControllers var rawData = await backendRepository.GetAllAsync(sql, 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($"select full_name from device where device_number = '{rd.device_number}' and deleted = 0"); - } - List list = new List(); if (tag_quantity == "5") { list = rawData - .GroupBy(x => new { building_tag = x.device_number.Split("_")[0], floor_tag = x.device_number.Split("_")[2], device_serial_tag = x.device_number.Split("_")[4] }) - .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag }) + .GroupBy(x => new { building_tag = x.device_number.Split("_")[0], floor_tag = x.device_number.Split("_")[2], device_serial_tag = x.device_number.Split("_")[4], device_number = x.device_number }) + .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_number = x.Key.device_number }) .ToList(); } else { list = rawData - .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, device_master = x.Key.device_master }) + .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], device_number = x.device_number }) + .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, device_number = x.Key.device_number }) .ToList(); } foreach (var l in list) { l.rawData = new List(); + l.device_full_name = await backendRepository.GetOneAsync($"select full_name from device where device_number = '{l.device_number}' and deleted = 0"); if (tag_quantity == "5") { l.rawData.AddRange( @@ -319,30 +315,26 @@ namespace FrontendWebApi.ApiControllers var rawData = await backendRepository.GetAllAsync(sql, 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($"select full_name from device where device_number = '{rd.device_number}' and deleted = 0"); - } - List list = new List(); if (tag_quantity == "5") { list = rawData - .GroupBy(x => new { building_tag = x.device_number.Split("_")[0], floor_tag = x.device_number.Split("_")[2], device_serial_tag = x.device_number.Split("_")[4] }) - .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag }) + .GroupBy(x => new { building_tag = x.device_number.Split("_")[0], floor_tag = x.device_number.Split("_")[2], device_serial_tag = x.device_number.Split("_")[4], device_number = x.device_number }) + .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_number = x.Key.device_number }) .ToList(); } else { list = rawData - .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, device_master = x.Key.device_master }) + .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], device_number = x.device_number }) + .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, device_number = x.Key.device_number }) .ToList(); } foreach (var l in list) { l.rawData = new List(); + l.device_full_name = await backendRepository.GetOneAsync($"select full_name from device where device_number = '{l.device_number}' and deleted = 0"); if (tag_quantity == "5") { l.rawData.AddRange( @@ -516,7 +508,7 @@ namespace FrontendWebApi.ApiControllers } if (j == 2) { - cell.SetCellValue(r.device_serial_tag); + cell.SetCellValue(r.device_full_name); } if (j == 3) diff --git a/FrontendWebApi/Models/HydroMeter.cs b/FrontendWebApi/Models/HydroMeter.cs index 3afd783..c8c3f92 100644 --- a/FrontendWebApi/Models/HydroMeter.cs +++ b/FrontendWebApi/Models/HydroMeter.cs @@ -25,6 +25,8 @@ namespace FrontendWebApi.Models public string floor_tag { get; set; } public string device_serial_tag { get; set; } public string device_master { get; set; } + public string device_number { get; set; } + public string device_full_name { get; set; } public string total { get; set; } public string price { get; set; } public string total_price { get; set; } @@ -36,7 +38,6 @@ namespace FrontendWebApi.Models public string timeStamp { get; set; } public string device_number { get; set; } public decimal avg_rawdata { get; set; } - public string device_full_name { get; set; } } public class HydroMeterPriceInput