diff --git a/FrontendWebApi/ApiControllers/HydroMeterController.cs b/FrontendWebApi/ApiControllers/HydroMeterController.cs index cbf58c0..11b8d9e 100644 --- a/FrontendWebApi/ApiControllers/HydroMeterController.cs +++ b/FrontendWebApi/ApiControllers/HydroMeterController.cs @@ -131,17 +131,38 @@ namespace FrontendWebApi.ApiControllers order by fd.device_number, fd.date"; var rawData = await backendRepository.GetAllAsync(sql, new { startTime = startTime, endtime = endTime, building_tag = input.building_tag, floor_tag = input.floor_tag, dateFormat = dateFormat }); - var list = rawData + + 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 }) .ToList(); + } + else + { + 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("_")[3] }) + .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag }) + .ToList(); + } foreach (var l in list) { l.rawData = new List(); - l.rawData.AddRange( - rawData.Where(x => x.device_number.Split("_")[0] == l.building_tag && x.device_number.Split("_")[2] == l.floor_tag && x.device_number.Split("_")[4] == l.device_serial_tag) - ); + if (tag_quantity == "5") + { + l.rawData.AddRange( + rawData.Where(x => x.device_number.Split("_")[0] == l.building_tag && x.device_number.Split("_")[2] == l.floor_tag && x.device_number.Split("_")[4] == l.device_serial_tag) + ); + } + else + { + 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("_")[3] == l.device_serial_tag) + ); + } l.building_name = await backendRepository.GetOneAsync("select full_name from building where building_tag = @building_tag and deleted = 0", new { building_tag = l.building_tag }); l.total = l.rawData.Sum(x => x.avg_rawdata).ToString(); @@ -271,17 +292,38 @@ 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 }); - var list = rawData + + 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 }) .ToList(); + } + else + { + 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("_")[3] }) + .Select(x => new HydroMeterOutput { building_tag = x.Key.building_tag, floor_tag = x.Key.floor_tag, device_serial_tag = x.Key.device_serial_tag }) + .ToList(); + } foreach (var l in list) { l.rawData = new List(); - l.rawData.AddRange( - rawData.Where(x => x.device_number.Split("_")[0] == l.building_tag && x.device_number.Split("_")[2] == l.floor_tag && x.device_number.Split("_")[4] == l.device_serial_tag) - ); + if (tag_quantity == "5") + { + l.rawData.AddRange( + rawData.Where(x => x.device_number.Split("_")[0] == l.building_tag && x.device_number.Split("_")[2] == l.floor_tag && x.device_number.Split("_")[4] == l.device_serial_tag) + ); + } + else + { + 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("_")[3] == l.device_serial_tag) + ); + } l.building_name = await backendRepository.GetOneAsync("select full_name from building where building_tag = @building_tag and deleted = 0", new { building_tag = l.building_tag }); l.total = l.rawData.Sum(x => x.avg_rawdata).ToString();