This commit is contained in:
GiteaAdmin 2023-06-15 10:04:17 +08:00
commit f012de5bd6
8 changed files with 174 additions and 46 deletions

View File

@ -113,13 +113,13 @@ namespace Backend.Controllers
building = data.GroupBy(x => x.tag_name.Split("_")[1]).Select(x => x.Key).ToList();
}
//string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node
//await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building, tag_quantity); // 匯入 MySQL table: import_niagara_tag
//await niagaraDataSynchronizeRepository.DeviceComparison(LightSwitchLevel);
//await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover();
//await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
//await niagaraDataSynchronizeRepository.InsertBuildingMenu();
//await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
string LightSwitchLevel = await niagaraDataSynchronizeRepository.getLightSwitchLevel(); //獲取照明開關 是否在 device or device_node
await niagaraDataSynchronizeRepository.InsertNiagaraTagList(ds, building, tag_quantity); // 匯入 MySQL table: import_niagara_tag
await niagaraDataSynchronizeRepository.DeviceComparison(LightSwitchLevel);
await niagaraDataSynchronizeRepository.CheckDiffFullNameAndCover();
await niagaraDataSynchronizeRepository.CheckFullNameEmptyReplaceByDeviceName();
await niagaraDataSynchronizeRepository.InsertBuildingMenu();
await niagaraDataSynchronizeRepository.InsertSubSystemFloor();
await this.DeviceDisasterAsync();
result = true;

View File

@ -510,7 +510,7 @@ namespace Backend.Controllers
var buildingGuid = "";
if (post.SelectedBuild != "0")
{
buildingGuid = $" AND ap.building_guid = '{post.SelectedBuild}'";
buildingGuid = $" AND ap.building_tag = '{post.SelectedBuild}'";
}
var sqlString = @$" SELECT ap.AuthCode, ap.MainName, ap.SubName FROM auth_page ap
WHERE ap.AuthType='{post.SelectedAuthType}'

View File

@ -18,10 +18,11 @@
"Port": "js2LutKe+rdjzdxMPQUrvQ==",
//"Database": "VJB2XC+lAtzuHObDGMVOAA==", //30
//"Database": "IgYBsgG2VLKKxFb64j7LOA==", //wsp
"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
//"Database": "7gWfmZ28HGIJZbxEbK+0yg==", //tpe_dome_dome
//"Database": "siTUcDaC/g2yGTMFWD72Kg==", //tpe_dome_hotel
//"Database": "iuaY0h0+TWkir44/eZLDqw==", //tpe_dome_office
//"Database": "Rq7Gn4x6LwBvVtl7GY8LbA==", //mcut
"Database": "2U+9jYGy0dCbMzLaguBXow==", //tpe_dome_mall
"Root": "SzdxEgaJJ7tcTCrUl2zKsA==",
"Password": "FVAPxztxpY4gJJKQ/se4bQ=="
},

View File

@ -363,7 +363,7 @@
let start = new Date($('#his_startdate').val());
let end = new Date(new Date().setDate(new Date($('#his_enddate input').val()).getDate() + 1));
if (pageAct.dateType == "today")
if (pageAct.dateType == "today" || pageAct.dateType == "day" || pageAct.dateType == "ytd")
end = new Date(new Date().setDate(start.getDate() + 1));
else if (pageAct.dateType == "month") {
start = new Date($('#getmonth').val());

View File

@ -236,18 +236,43 @@ namespace FrontendWebApi.ApiControllers
Sub_system = new List<Sub_systemGuid>()
};
var subsystem = ma.GroupBy(a => a.sub_system_tag).ToList();
string mainSystemTag = ma.Select(m => m.main_system_tag).FirstOrDefault();
foreach (var sub in subsystem)
{
Sub_systemGuid sub_System = new Sub_systemGuid()
if (mainSystemTag != "S") //normal
{
sub_system_tag = sub.Select(a => a.sub_system_tag).FirstOrDefault(),
full_name = sub.Select(a => a.subfull_name).FirstOrDefault(),
priority = sub.Select(a => a.subpriority).FirstOrDefault(),
device_system_tag = sub.Select(a => a.device_system_tag).FirstOrDefault(),
OpenTab = sub.Select(a => a.OpenTab).FirstOrDefault(),
system_url = sub.Select(a => a.left_system_url).FirstOrDefault()
};
main_System.Sub_system.Add(sub_System);
Sub_systemGuid sub_System = new Sub_systemGuid()
{
sub_system_tag = sub.Select(a => a.sub_system_tag).FirstOrDefault(),
full_name = sub.Select(a => a.subfull_name).FirstOrDefault(),
priority = sub.Select(a => a.subpriority).FirstOrDefault(),
device_system_tag = sub.Select(a => a.device_system_tag).FirstOrDefault(),
OpenTab = sub.Select(a => a.OpenTab).FirstOrDefault(),
system_url = sub.Select(a => a.left_system_url).FirstOrDefault()
};
main_System.Sub_system.Add(sub_System);
}
else // 人流計數處理
{
string name = sub.Select(s => s.subfull_name).FirstOrDefault();
bool check = true;
if (name == "人流計數")
check = sub.Select(s => s.sub_system_tag).FirstOrDefault().StartsWith(menu.Select(m => m.device_building_tag).FirstOrDefault());
if (check)
{
Sub_systemGuid sub_System = new Sub_systemGuid()
{
sub_system_tag = sub.Select(a => a.sub_system_tag).FirstOrDefault(),
full_name = sub.Select(a => a.subfull_name).FirstOrDefault(),
priority = sub.Select(a => a.subpriority).FirstOrDefault(),
device_system_tag = sub.Select(a => a.device_system_tag).FirstOrDefault(),
OpenTab = sub.Select(a => a.OpenTab).FirstOrDefault(),
system_url = sub.Select(a => a.left_system_url).FirstOrDefault()
};
main_System.Sub_system.Add(sub_System);
}
}
}
building1.main_system.Add(main_System);
}

View File

@ -239,9 +239,26 @@ namespace FrontendWebApi.ApiControllers
foreach (var sub in subs)
{
History_Sub_system history_Sub_System = new History_Sub_system();
history_Sub_System.full_name = sub.Select(x => x.sub_name).FirstOrDefault();
history_Sub_System.sub_system_tag = sub.Select(x => x.sub_system_tag).FirstOrDefault();
history_Sub_System.is_show_history = sub.Select(x => x.device_item_is_show_hsitory).FirstOrDefault();
if (main.Select(x => x.main_system_tag).FirstOrDefault() != "S")
{
history_Sub_System.full_name = sub.Select(x => x.sub_name).FirstOrDefault();
history_Sub_System.sub_system_tag = sub.Select(x => x.sub_system_tag).FirstOrDefault();
history_Sub_System.is_show_history = sub.Select(x => x.device_item_is_show_hsitory).FirstOrDefault();
}
else
{
string name = sub.Select(x => x.sub_name).FirstOrDefault();
bool check = true;
if (name == "人流計數")
check = sub.Any(x => x.sub_system_tag.StartsWith(hf.building_tag));
if (check)
{
history_Sub_System.full_name = sub.Select(x => x.sub_name).FirstOrDefault();
history_Sub_System.sub_system_tag = sub.Select(x => x.sub_system_tag).FirstOrDefault();
history_Sub_System.is_show_history = sub.Select(x => x.device_item_is_show_hsitory).FirstOrDefault();
}
}
var devices = dbsub.Where(x => x.main_system_tag == main.Select(m => m.main_system_tag).FirstOrDefault() && x.sub_system_tag == sub.Select(x => x.sub_system_tag).FirstOrDefault() && x.device_number != null).OrderBy(x=>x.device_full_name.Length).ThenBy(x=>x.device_full_name).ToList();
history_Sub_System.device = devices.Count > 0 ? new List<Device>() : null;
@ -305,8 +322,9 @@ namespace FrontendWebApi.ApiControllers
List<DeviceItem> deviceItems = new List<DeviceItem>();
var main_system_value = hf.device_number.Split('_')[2];
var sub_system_value = hf.device_number.Split('_')[3];
var sqlString = $@"select * from device_item where deleted = 0 and device_system_tag = @main_system_value and device_name_tag = @sub_system_value and is_show_history = 1";
deviceItems = await frontendRepository.GetAllAsync<DeviceItem>(sqlString, new { @main_system_value = main_system_value, @sub_system_value = sub_system_value });
var building_tag = hf.device_number.Split('_')[1];
var sqlString = $@"select * from device_item where deleted = 0 and device_system_tag = @main_system_value and device_name_tag = @sub_system_value and is_show_history = 1 and device_building_tag = @building_tag";
deviceItems = await frontendRepository.GetAllAsync<DeviceItem>(sqlString, new { @main_system_value = main_system_value, @sub_system_value = sub_system_value, building_tag = building_tag });
apiResult.Data = deviceItems;
apiResult.Code = "0000";

View File

@ -461,7 +461,7 @@ namespace FrontendWebApi.ApiControllers
int i = 0;
ICell cell = row.CreateCell(i++);
cell.SetCellValue("別");
cell.SetCellValue("別");
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("樓層");
@ -550,12 +550,13 @@ namespace FrontendWebApi.ApiControllers
}
[HttpPost]
[Route("api/ExportWaterList")]
public FileResult OpeExportExcelWater([FromBody] HydroMeterInput input)
[Route("api/ExportElectricCompareList")]
public FileResult OpeExportCompareExcelElec([FromBody] List<HydroMeterInput> input)
{
var result = this.WaterList(input).Result.Value.Data.ToList();
var result = new List<HydroMeterOutput>();
var result1 = this.ElectricList(input[0]).Result.Value.Data.ToList();
var result2 = this.ElectricList(input[1]).Result.Value.Data.ToList();
Dictionary<string, List<string>> compareDict = new Dictionary<string, List<string>>();
var workbook = new XSSFWorkbook();
#region excel設定
IFont font12 = workbook.CreateFont();
@ -598,11 +599,46 @@ namespace FrontendWebApi.ApiControllers
stylein12.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
stylein12.WrapText = true;
#endregion
var rawDataTitle = new List<string>();
if (input[0].tableType == "month")
{
for (var i = 1; i <= 12; i++)
{
rawDataTitle.Add(input[0].startTime + "-" + i.ToString().PadLeft(2, '0'));
rawDataTitle.Add(input[1].startTime + "-" + i.ToString().PadLeft(2, '0'));
}
}
else if (input[0].tableType == "day")
{
var days = GetDayInMonth(input[0].startTime);
for (var i = 1 ;i <= days ; i++) {
rawDataTitle.Add(input[0].startTime + "-" + i.ToString().PadLeft(2, '0'));
rawDataTitle.Add(input[1].startTime + "-" + i.ToString().PadLeft(2, '0'));
}
}
var sheet = workbook.CreateSheet("電表報表");
int RowPosition = 0;
if (result.Count > 0)
if (result1.Count > 0 || result2.Count > 0)
{
result = result1;
foreach (var r2 in result2)
{
var target = result.Where(r => r.building_tag == r2.building_tag && r.device_serial_tag == r2.device_serial_tag && r.floor_tag == r2.floor_tag).FirstOrDefault();
compareDict[r2.building_tag + r2.floor_tag + r2.device_serial_tag] = new List<string>() { r2.total, r2.price, r2.total_price };
if (target != null)
{
target.rawData = target.rawData.Concat(r2.rawData).ToList();
}
else {
r2.total = null;
r2.price = null;
r2.total_price= null;
result.Add(r2);
}
}
#region set cell
IRow row = sheet.CreateRow(RowPosition);
sheet.SetColumnWidth(0, 4 * 160 * 12);
@ -611,7 +647,7 @@ namespace FrontendWebApi.ApiControllers
int i = 0;
ICell cell = row.CreateCell(i++);
cell.SetCellValue("別");
cell.SetCellValue("別");
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("樓層");
@ -620,26 +656,43 @@ namespace FrontendWebApi.ApiControllers
cell.SetCellValue("設備");
cell.CellStyle = styleLine12;
foreach (var rr in result.FirstOrDefault().rawData)
foreach (var rr in rawDataTitle)
{
sheet.SetColumnWidth(i, 2 * 160 * 12);
cell = row.CreateCell(i++);
cell.SetCellValue(rr.timeStamp);
cell.SetCellValue(rr);
cell.CellStyle = styleLine12;
}
cell = row.CreateCell(i++);
cell.SetCellValue("小計");
cell.SetCellValue(input[0].startTime + "小計");
sheet.SetColumnWidth(i-1, 2 * 160 * 12);
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("單價");
cell.SetCellValue(input[1].startTime + "小計");
sheet.SetColumnWidth(i - 1, 2 * 160 * 12);
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue("金額總計");
cell.SetCellValue(input[0].startTime + "單價");
sheet.SetColumnWidth(i - 1, 2 * 160 * 12);
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue(input[1].startTime + "單價");
sheet.SetColumnWidth(i - 1, 2 * 160 * 12);
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue(input[0].startTime + "金額總計");
sheet.SetColumnWidth(i - 1, 2 * 160 * 12);
cell.CellStyle = styleLine12;
cell = row.CreateCell(i++);
cell.SetCellValue(input[1].startTime + "金額總計");
sheet.SetColumnWidth(i - 1, 2 * 160 * 12);
cell.CellStyle = styleLine12;
#endregion
foreach (var r in result)
{
string compareDictKey = r.building_tag + r.floor_tag + r.device_serial_tag;
RowPosition += 1;
int k = 3;
row = sheet.CreateRow(RowPosition);
@ -661,9 +714,10 @@ namespace FrontendWebApi.ApiControllers
if (j == 3)
{
foreach (var rr in r.rawData)
foreach (var rr in rawDataTitle)
{
cell.SetCellValue(rr.avg_rawdata.ToString());
var targetRaw = r.rawData.Where(rd => rd.timeStamp == rr).FirstOrDefault();
cell.SetCellValue(targetRaw?.avg_rawdata.ToString() ?? "");
j++;
k++;
cell = row.CreateCell(j);
@ -676,12 +730,24 @@ namespace FrontendWebApi.ApiControllers
}
if (j == k + 1)
{
cell.SetCellValue(r.price);
cell.SetCellValue(compareDict.ContainsKey(compareDictKey) ? compareDict[compareDictKey][0] : "");
}
if (j == k + 2)
{
cell.SetCellValue(r.price);
}
if (j == k + 3)
{
cell.SetCellValue(compareDict.ContainsKey(compareDictKey) ? compareDict[compareDictKey][1] : "");
}
if (j == k + 4)
{
cell.SetCellValue(r.total_price);
}
if (j == k + 5)
{
cell.SetCellValue(compareDict.ContainsKey(compareDictKey) ? compareDict[compareDictKey][2] : "");
}
cell.CellStyle = style12;
}
@ -695,10 +761,18 @@ namespace FrontendWebApi.ApiControllers
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
Response.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
return File(ms, "application/vnd.ms-excel", "電表報表.xlsx");
}
return File(ms, "application/vnd.ms-excel", "水表報表.xlsx");
public static int GetDayInMonth(string yearMonth)
{
List<string> datesList = new List<string>();
DateTime startOfMonth = DateTime.Parse(yearMonth + "-01");
int daysInMonth = DateTime.DaysInMonth(startOfMonth.Year, startOfMonth.Month);
return daysInMonth;
}
}
}

View File

@ -41,4 +41,14 @@ namespace FrontendWebApi.Models
{
public string type { get; set; }
}
public class HydroMeterCompareOutput
{
}
public class HydroMeterCompareExportInput
{
public List<HydroMeterCompareOutput> exportList { get; set; }
}
}