[FE API] 修改 個盤總盤查詢匯出功能 以更新會出報表結果與範本一致
This commit is contained in:
parent
3a8d5fb81c
commit
b68c13c905
@ -833,23 +833,17 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
[Route("api/ExportElectricEachTotalCompareList")]
|
[Route("api/ExportElectricEachTotalCompareList")]
|
||||||
public FileResult OpeExportEachTotalCompareExcelElec([FromBody] HydroMeterInput input)
|
public FileResult OpeExportEachTotalCompareExcelElec([FromBody] HydroMeterInput input)
|
||||||
{
|
{
|
||||||
List<HydroMeterOutput> result = new List<HydroMeterOutput>();
|
|
||||||
List<HydroMeterOutput> result_for_sum = new List<HydroMeterOutput>();
|
|
||||||
result = ElectricListEachTotal(input).Result.Value.Data.ToList();
|
|
||||||
|
|
||||||
bool flag = true;
|
bool flag = true;
|
||||||
bool total_flag = false;
|
bool total_flag = false;
|
||||||
if (input.Mode == HydroMeterInputSearchMode.Custom)
|
if (input.Mode == HydroMeterInputSearchMode.Custom)
|
||||||
{
|
{
|
||||||
input.Mode = HydroMeterInputSearchMode.All;
|
//flag = false;
|
||||||
result_for_sum = ElectricListEachTotal(input).Result.Value.Data.ToList();
|
|
||||||
flag = false;
|
|
||||||
total_flag = true;
|
total_flag = true;
|
||||||
|
input.Mode = HydroMeterInputSearchMode.All;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
List<HydroMeterOutput> result = new List<HydroMeterOutput>();
|
||||||
result_for_sum = new List<HydroMeterOutput>(result);
|
result = ElectricListEachTotal(input).Result.Value.Data.ToList();
|
||||||
}
|
|
||||||
|
|
||||||
List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>();
|
List<Dictionary<string, byte[]>> docFile = new List<Dictionary<string, byte[]>>();
|
||||||
var workbook = new XSSFWorkbook();
|
var workbook = new XSSFWorkbook();
|
||||||
@ -976,11 +970,11 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
"第一校區總盤",
|
"第一校區總盤",
|
||||||
"圖資大樓總盤",
|
"圖資大樓總盤",
|
||||||
"教學大樓總盤",
|
"教學大樓總盤",
|
||||||
"教學大樓總盤",
|
|
||||||
"電子館分盤",
|
"電子館分盤",
|
||||||
"機械館分盤",
|
"機械館分盤",
|
||||||
"電機館分盤",
|
"電機館分盤",
|
||||||
"學5舍總盤",
|
"學1-4舍空調總盤",
|
||||||
|
"學五舍總盤",
|
||||||
"8眷舍分盤",
|
"8眷舍分盤",
|
||||||
"企教分盤",
|
"企教分盤",
|
||||||
"7眷舍分盤",
|
"7眷舍分盤",
|
||||||
@ -992,10 +986,9 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
string last_build = "";
|
string last_build = "";
|
||||||
string last_device = "";
|
string last_device = "";
|
||||||
|
|
||||||
// ------------------
|
|
||||||
Dictionary<string, Dictionary<string, double>> buildingSumData = new Dictionary<string, Dictionary<string, double>>();
|
Dictionary<string, Dictionary<string, double>> buildingSumData = new Dictionary<string, Dictionary<string, double>>();
|
||||||
#region 特定棟別總計處理
|
#region 特定棟別總計處理
|
||||||
foreach (var item in result_for_sum)
|
foreach (var item in result)
|
||||||
{
|
{
|
||||||
if (!need_cal_total.Contains(item.building_name))
|
if (!need_cal_total.Contains(item.building_name))
|
||||||
{
|
{
|
||||||
@ -1021,7 +1014,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
buildingSumData[item.building_name][dataItem.timeStamp] += Math.Round(double.Parse(dataItem.avg_rawdata));
|
buildingSumData[item.building_name][dataItem.timeStamp] += Math.Round(double.Parse(dataItem.avg_rawdata));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
// 測試
|
// 測試
|
||||||
//foreach (var building in buildingSumData)
|
//foreach (var building in buildingSumData)
|
||||||
//{
|
//{
|
||||||
@ -1031,18 +1024,15 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
// Console.WriteLine($" TimeStamp: {timeStampData.Key}, Total Avg RawData: {timeStampData.Value}");
|
// Console.WriteLine($" TimeStamp: {timeStampData.Key}, Total Avg RawData: {timeStampData.Value}");
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
// ------------------
|
#endregion
|
||||||
|
|
||||||
foreach (var r in result)
|
foreach (var r in result)
|
||||||
{
|
{
|
||||||
if (total_flag)
|
//if (total_flag)
|
||||||
{
|
//{
|
||||||
flag = false;
|
// flag = false;
|
||||||
}
|
//}
|
||||||
if (r.device_full_name == "綜合大樓總盤")
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
string buildingName = r.building_name;
|
string buildingName = r.building_name;
|
||||||
string floorTag = r.floor_tag;
|
string floorTag = r.floor_tag;
|
||||||
string deviceFullName = r.device_full_name;
|
string deviceFullName = r.device_full_name;
|
||||||
@ -1060,6 +1050,11 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
cell.SetCellValue(count_index.ToString());
|
cell.SetCellValue(count_index.ToString());
|
||||||
count_index++;
|
count_index++;
|
||||||
|
if (total_flag)
|
||||||
|
{
|
||||||
|
cell = row.GetCell(columnIndex) ?? row.CreateCell(columnIndex);
|
||||||
|
cell.SetCellValue(buildingName + floorTag);
|
||||||
|
}
|
||||||
columnIndex++;
|
columnIndex++;
|
||||||
|
|
||||||
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
@ -1078,7 +1073,7 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
columnIndex = 0;
|
columnIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((total_flag && need_cal_total.Contains(last_build)) || (flag && buildingName != last_build && need_cal_total.Contains(last_build)))
|
if (flag && buildingName != last_build && need_cal_total.Contains(last_build))
|
||||||
{
|
{
|
||||||
row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
|
row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
|
||||||
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
@ -1108,6 +1103,10 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
// continue;
|
// continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (total_flag)
|
||||||
|
{
|
||||||
|
if (need_green_device.Contains(deviceFullName))
|
||||||
|
{
|
||||||
columnIndex = 0;
|
columnIndex = 0;
|
||||||
row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
|
row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
|
||||||
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
@ -1119,7 +1118,35 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
|
|
||||||
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
cell.SetCellValue(deviceFullName);
|
cell.SetCellValue(deviceFullName);
|
||||||
if (total_flag || need_green_device.Contains(deviceFullName))
|
cell.CellStyle = greenCellStyle;
|
||||||
|
|
||||||
|
foreach (var rawD in r.rawData)
|
||||||
|
{
|
||||||
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
|
cell.SetCellValue(rawD.avg_rawdata);
|
||||||
|
}
|
||||||
|
rowIndex++;
|
||||||
|
last_build = buildingName;
|
||||||
|
last_device = deviceFullName;
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
last_build = buildingName;
|
||||||
|
last_device = deviceFullName;
|
||||||
|
flag = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
columnIndex = 0;
|
||||||
|
row = sheet.GetRow(rowIndex) ?? sheet.CreateRow(rowIndex);
|
||||||
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
|
cell.SetCellValue(count_index.ToString());
|
||||||
|
count_index++;
|
||||||
|
|
||||||
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
|
cell.SetCellValue(buildingName + floorTag);
|
||||||
|
|
||||||
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
|
cell.SetCellValue(deviceFullName);
|
||||||
|
if (need_green_device.Contains(deviceFullName))
|
||||||
{
|
{
|
||||||
cell.CellStyle = greenCellStyle;
|
cell.CellStyle = greenCellStyle;
|
||||||
}
|
}
|
||||||
@ -1129,7 +1156,6 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
cell = row.GetCell(columnIndex++) ?? row.CreateCell(columnIndex++);
|
||||||
cell.SetCellValue(rawD.avg_rawdata);
|
cell.SetCellValue(rawD.avg_rawdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
last_build = buildingName;
|
last_build = buildingName;
|
||||||
last_device = deviceFullName;
|
last_device = deviceFullName;
|
||||||
@ -1184,19 +1210,20 @@ namespace FrontendWebApi.ApiControllers
|
|||||||
string sqlWhere = "";
|
string sqlWhere = "";
|
||||||
string tag_quantity = await backendRepository.GetOneAsync<string>("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0");
|
string tag_quantity = await backendRepository.GetOneAsync<string>("select system_value from variable where system_type = 'obixConfig' and system_key = 'tag_quantity' and deleted = 0");
|
||||||
|
|
||||||
switch (input.Mode)
|
//switch (input.Mode)
|
||||||
{
|
//{
|
||||||
case HydroMeterInputSearchMode.All:
|
// case HydroMeterInputSearchMode.All:
|
||||||
|
// sqlWhere = @$" a.priority <> 0 ";
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// case HydroMeterInputSearchMode.Custom:
|
||||||
|
// sqlWhere = @$" a.device_number in (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(system_value, '/', -1), '_', 8) COLLATE utf8mb4_0900_ai_ci as val FROM variable where system_type = 'dashboard_total_elec')";
|
||||||
|
// break;
|
||||||
|
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
sqlWhere = @$" a.priority <> 0 ";
|
sqlWhere = @$" a.priority <> 0 ";
|
||||||
break;
|
|
||||||
|
|
||||||
case HydroMeterInputSearchMode.Custom:
|
|
||||||
sqlWhere = @$" a.device_number in (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(system_value, '/', -1), '_', 8) COLLATE utf8mb4_0900_ai_ci as val FROM variable where system_type = 'dashboard_total_elec')";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var table = "archive_electric_meter_month";
|
var table = "archive_electric_meter_month";
|
||||||
var schema = await backendRepository.GetOneAsync<string>($"select system_value from variable where system_type = 'project_name'");
|
var schema = await backendRepository.GetOneAsync<string>($"select system_value from variable where system_type = 'project_name'");
|
||||||
@ -1224,6 +1251,24 @@ order by e.report_priority, a.priority";
|
|||||||
Logger.LogInformation("SQL = " + sql + " building=" + input.building_tag + " floor_tag = " + input.floor_tag);
|
Logger.LogInformation("SQL = " + sql + " building=" + input.building_tag + " floor_tag = " + input.floor_tag);
|
||||||
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataEachTotalOutput>(sql);
|
var rawData = await backendRepository.GetAllAsync<HydroMeterRawDataEachTotalOutput>(sql);
|
||||||
|
|
||||||
|
List<string> need_green_device = new List<string>
|
||||||
|
{
|
||||||
|
"第一校區總盤",
|
||||||
|
"圖資大樓總盤",
|
||||||
|
"教學大樓總盤",
|
||||||
|
"電子館分盤",
|
||||||
|
"機械館分盤",
|
||||||
|
"電機館分盤",
|
||||||
|
"學1-4舍空調總盤",
|
||||||
|
"學五舍總盤",
|
||||||
|
"8眷舍分盤",
|
||||||
|
"企教分盤",
|
||||||
|
"7眷舍分盤",
|
||||||
|
"第二校區總盤",
|
||||||
|
"薄膜一館分盤",
|
||||||
|
"薄膜二館分盤"
|
||||||
|
};
|
||||||
|
|
||||||
List<HydroMeterOutput> ResultData = new List<HydroMeterOutput>();
|
List<HydroMeterOutput> ResultData = new List<HydroMeterOutput>();
|
||||||
|
|
||||||
ResultData = rawData
|
ResultData = rawData
|
||||||
@ -1233,6 +1278,11 @@ order by e.report_priority, a.priority";
|
|||||||
|
|
||||||
foreach (var l in ResultData)
|
foreach (var l in ResultData)
|
||||||
{
|
{
|
||||||
|
var full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{l.device_number}'");
|
||||||
|
if (input.Mode == HydroMeterInputSearchMode.Custom && !need_green_device.Contains(full_name))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
l.rawData = new List<HydroMeterRawDataOutput>();
|
l.rawData = new List<HydroMeterRawDataOutput>();
|
||||||
|
|
||||||
@ -1287,7 +1337,7 @@ order by e.report_priority, a.priority";
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
l.device_full_name = await backendRepository.GetOneAsync<string>($"select full_name from device where device_number = '{l.device_number}'");
|
l.device_full_name = full_name;
|
||||||
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",
|
||||||
new { building_tag = l.building_tag });
|
new { building_tag = l.building_tag });
|
||||||
l.total = l.rawData.Where(x => x.avg_rawdata != "NaN").Sum(x => decimal.Parse(x.avg_rawdata ?? "0", System.Globalization.NumberStyles.Float)).ToString();
|
l.total = l.rawData.Where(x => x.avg_rawdata != "NaN").Sum(x => decimal.Parse(x.avg_rawdata ?? "0", System.Globalization.NumberStyles.Float)).ToString();
|
||||||
@ -1296,10 +1346,25 @@ order by e.report_priority, a.priority";
|
|||||||
: Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'ElectricPrice' and deleted = 0")), 2).ToString();
|
: Math.Round((await backendRepository.GetOneAsync<decimal>("select system_value from variable where system_type = 'ElectricPrice' and deleted = 0")), 2).ToString();
|
||||||
l.total_price = Math.Round((Decimal.Parse(l.total) * Decimal.Parse(l.price))).ToString();
|
l.total_price = Math.Round((Decimal.Parse(l.total) * Decimal.Parse(l.price))).ToString();
|
||||||
}
|
}
|
||||||
|
List<HydroMeterOutput> ResultData_custom = new List<HydroMeterOutput>();
|
||||||
|
foreach (var l in ResultData)
|
||||||
|
{
|
||||||
|
if (l.device_full_name != null)
|
||||||
|
{
|
||||||
|
ResultData_custom.Add(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
|
if (input.Mode == HydroMeterInputSearchMode.All)
|
||||||
|
{
|
||||||
apiResult.Data = ResultData;
|
apiResult.Data = ResultData;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
apiResult.Data = ResultData_custom;
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
apiResult.Code = "9999";
|
apiResult.Code = "9999";
|
||||||
|
Loading…
Reference in New Issue
Block a user