|
@@ -649,199 +649,210 @@ namespace Ropin.Inspection.Api
|
|
|
{
|
|
|
List<RunSpotConfigName> tabs = new List<RunSpotConfigName>();
|
|
|
var confCode = searchModel.C_DevOpeAccountConfigCode;
|
|
|
- IRow head = sheet.CreateRow(1);
|
|
|
- IRow head2 = sheet.CreateRow(2);
|
|
|
- IRow head3 = sheet.CreateRow(3);
|
|
|
- head.Height = 30 * 20;
|
|
|
- head2.Height = 30 * 20;
|
|
|
- head3.Height = 30 * 20;
|
|
|
if (!string.IsNullOrEmpty(confCode))
|
|
|
{
|
|
|
- head.CreateCell(0).SetCellValue("日期");
|
|
|
- tabs.Add(new RunSpotConfigName { Label = "日期", Name = "Date", BReadDevSpot = false });
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(1, 3, 0, 0));
|
|
|
- int cel = 1;
|
|
|
- var content = await _devDevOpeAccountConfigService.GetEntityByID(confCode);
|
|
|
- if (content != null && !string.IsNullOrEmpty(content.C_Config))
|
|
|
+ IRow head = sheet.CreateRow(1);
|
|
|
+ IRow head2 = sheet.CreateRow(2);
|
|
|
+ IRow head3 = sheet.CreateRow(3);
|
|
|
+ head.Height = 30 * 20;
|
|
|
+ head2.Height = 30 * 20;
|
|
|
+ head3.Height = 30 * 20;
|
|
|
+ if (!string.IsNullOrEmpty(confCode))
|
|
|
{
|
|
|
- var RunSpotConfig = JsonConvert.DeserializeObject<TdevDevOpeAccountConfigNameViewModel>(content.C_Config);
|
|
|
- List<RunSpotConfigName> CtabColumns = new List<RunSpotConfigName>();
|
|
|
- int headerNum = 1;
|
|
|
- foreach (var item in RunSpotConfig?.RunSpotConfigList.ToList())
|
|
|
+ head.CreateCell(0).SetCellValue("日期");
|
|
|
+ tabs.Add(new RunSpotConfigName { Label = "日期", Name = "Date", BReadDevSpot = false });
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 3, 0, 0));
|
|
|
+ int cel = 1;
|
|
|
+ var content = await _devDevOpeAccountConfigService.GetEntityByID(confCode);
|
|
|
+ if (content != null && !string.IsNullOrEmpty(content.C_Config))
|
|
|
{
|
|
|
- if (item != null)
|
|
|
+ var RunSpotConfig = JsonConvert.DeserializeObject<TdevDevOpeAccountConfigNameViewModel>(content.C_Config);
|
|
|
+ List<RunSpotConfigName> CtabColumns = new List<RunSpotConfigName>();
|
|
|
+ int headerNum = 1;
|
|
|
+ foreach (var item in RunSpotConfig?.RunSpotConfigList.ToList())
|
|
|
{
|
|
|
- headerNum = item.Label.Split("@").Count();
|
|
|
- if (item.BReadDevSpot)
|
|
|
+ if (item != null)
|
|
|
{
|
|
|
- headerNum++;
|
|
|
- tabs.Add(new RunSpotConfigName { Label = item.Label + "@平均值", Name = item.Name, BReadDevSpot = item.BReadDevSpot });
|
|
|
- tabs.Add(new RunSpotConfigName { Label = item.Label + "@最大值", Name = item.Name + "_Max", BReadDevSpot = item.BReadDevSpot });
|
|
|
- tabs.Add(new RunSpotConfigName { Label = item.Label + "@最小值", Name = item.Name + "_Min", BReadDevSpot = item.BReadDevSpot });
|
|
|
+ headerNum = item.Label.Split("@").Count();
|
|
|
+ if (item.BReadDevSpot)
|
|
|
+ {
|
|
|
+ headerNum++;
|
|
|
+ tabs.Add(new RunSpotConfigName { Label = item.Label + "@平均值", Name = item.Name, BReadDevSpot = item.BReadDevSpot });
|
|
|
+ tabs.Add(new RunSpotConfigName { Label = item.Label + "@最大值", Name = item.Name + "_Max", BReadDevSpot = item.BReadDevSpot });
|
|
|
+ tabs.Add(new RunSpotConfigName { Label = item.Label + "@最小值", Name = item.Name + "_Min", BReadDevSpot = item.BReadDevSpot });
|
|
|
|
|
|
- CtabColumns.Add(new RunSpotConfigName { Label = item.Label + "@平均值", Name = item.Name, BReadDevSpot = item.BReadDevSpot });
|
|
|
- CtabColumns.Add(new RunSpotConfigName { Label = item.Label + "@最大值", Name = item.Name + "_Max", BReadDevSpot = item.BReadDevSpot });
|
|
|
- CtabColumns.Add(new RunSpotConfigName { Label = item.Label + "@最小值", Name = item.Name + "_Min", BReadDevSpot = item.BReadDevSpot });
|
|
|
+ CtabColumns.Add(new RunSpotConfigName { Label = item.Label + "@平均值", Name = item.Name, BReadDevSpot = item.BReadDevSpot });
|
|
|
+ CtabColumns.Add(new RunSpotConfigName { Label = item.Label + "@最大值", Name = item.Name + "_Max", BReadDevSpot = item.BReadDevSpot });
|
|
|
+ CtabColumns.Add(new RunSpotConfigName { Label = item.Label + "@最小值", Name = item.Name + "_Min", BReadDevSpot = item.BReadDevSpot });
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tabs.Add(item);
|
|
|
- CtabColumns.Add(item);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tabs.Add(item);
|
|
|
+ CtabColumns.Add(item);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- bool IsVal = false; int merge = 0;
|
|
|
- bool IsVal2 = false; int merge2 = 0;
|
|
|
- foreach (var tab in CtabColumns)
|
|
|
- {
|
|
|
- if (tab != null)
|
|
|
+ bool IsVal = false; int merge = 0;
|
|
|
+ bool IsVal2 = false; int merge2 = 0;
|
|
|
+ foreach (var tab in CtabColumns)
|
|
|
{
|
|
|
- var vals = tab.Label;
|
|
|
- if (vals.Contains("@"))
|
|
|
+ if (tab != null)
|
|
|
{
|
|
|
- string[] tmp = vals.Split('@');//按,分割字符串
|
|
|
- if (tmp.Count() == 3)
|
|
|
+ var vals = tab.Label;
|
|
|
+ if (vals.Contains("@"))
|
|
|
{
|
|
|
- var getCel = sheet.GetRow(1).GetCell(cel - 1 - merge).ToString();
|
|
|
- var getCel2 = sheet.GetRow(2).GetCell(cel - 1 - merge2).ToString();
|
|
|
- if (getCel == tmp[0].ToString())
|
|
|
+ string[] tmp = vals.Split('@');//按,分割字符串
|
|
|
+ if (tmp.Count() == 3)
|
|
|
{
|
|
|
- head.CreateCell(cel).SetCellValue("");
|
|
|
- merge++;
|
|
|
- IsVal = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- IsVal = false;
|
|
|
- head.CreateCell(cel).SetCellValue(tmp[0].ToString());
|
|
|
- }
|
|
|
- if (getCel2 == tmp[1].ToString())
|
|
|
- {
|
|
|
- head2.CreateCell(cel).SetCellValue("");
|
|
|
- merge2++;
|
|
|
- IsVal2 = true;
|
|
|
+ var getCel = sheet.GetRow(1).GetCell(cel - 1 - merge).ToString();
|
|
|
+ var getCel2 = sheet.GetRow(2).GetCell(cel - 1 - merge2).ToString();
|
|
|
+ if (getCel == tmp[0].ToString())
|
|
|
+ {
|
|
|
+ head.CreateCell(cel).SetCellValue("");
|
|
|
+ merge++;
|
|
|
+ IsVal = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IsVal = false;
|
|
|
+ head.CreateCell(cel).SetCellValue(tmp[0].ToString());
|
|
|
+ }
|
|
|
+ if (getCel2 == tmp[1].ToString())
|
|
|
+ {
|
|
|
+ head2.CreateCell(cel).SetCellValue("");
|
|
|
+ merge2++;
|
|
|
+ IsVal2 = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ head2.CreateCell(cel).SetCellValue(tmp[1].ToString());
|
|
|
+ IsVal2 = false;
|
|
|
+ }
|
|
|
+ head3.CreateCell(cel).SetCellValue(tmp[2].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- head2.CreateCell(cel).SetCellValue(tmp[1].ToString());
|
|
|
IsVal2 = false;
|
|
|
+ var getCel = sheet.GetRow(1).GetCell(cel - 1 - merge).ToString();
|
|
|
+ if (getCel == tmp[0].ToString())
|
|
|
+ {
|
|
|
+ head.CreateCell(cel).SetCellValue("");
|
|
|
+ merge++;
|
|
|
+ IsVal = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ IsVal = false;
|
|
|
+ head.CreateCell(cel).SetCellValue(tmp[0].ToString());
|
|
|
+ }
|
|
|
+ head2.CreateCell(cel).SetCellValue(tmp[1].ToString());
|
|
|
+ head3.CreateCell(cel).SetCellValue("");
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(2, 3, cel, cel));
|
|
|
}
|
|
|
- head3.CreateCell(cel).SetCellValue(tmp[2].ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ IsVal = false;
|
|
|
IsVal2 = false;
|
|
|
- var getCel = sheet.GetRow(1).GetCell(cel - 1 - merge).ToString();
|
|
|
- if (getCel == tmp[0].ToString())
|
|
|
- {
|
|
|
- head.CreateCell(cel).SetCellValue("");
|
|
|
- merge++;
|
|
|
- IsVal = true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- IsVal = false;
|
|
|
- head.CreateCell(cel).SetCellValue(tmp[0].ToString());
|
|
|
- }
|
|
|
- head2.CreateCell(cel).SetCellValue(tmp[1].ToString());
|
|
|
+ head.CreateCell(cel).SetCellValue(vals);
|
|
|
+ head2.CreateCell(cel).SetCellValue("");
|
|
|
head3.CreateCell(cel).SetCellValue("");
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(2, 3, cel, cel));
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 3, cel, cel));
|
|
|
+ }
|
|
|
+ if (!IsVal && merge > 0)
|
|
|
+ {
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, cel - merge - 1, cel - 1));
|
|
|
+ merge = 0;
|
|
|
}
|
|
|
+ if (!IsVal2 && merge2 > 0)
|
|
|
+ {
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(2, 2, cel - merge2 - 1, cel - 1));
|
|
|
+ merge2 = 0;
|
|
|
+ }
|
|
|
+ cel++;
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ if (cel == CtabColumns.Count + 1 && merge > 0 && IsVal)
|
|
|
+ {
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(1, 1, cel - merge - 1, cel - 1));
|
|
|
+ merge = 0; IsVal = false;
|
|
|
+ }
|
|
|
+ if (cel == CtabColumns.Count + 1 && merge2 > 0 && IsVal2)
|
|
|
+ {
|
|
|
+ sheet.AddMergedRegion(new CellRangeAddress(2, 2, cel - merge2 - 1, cel - 1));
|
|
|
+ merge2 = 0; IsVal2 = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach (var item in head.Cells)
|
|
|
+ {
|
|
|
+ item.CellStyle = headCellStyle;
|
|
|
+ }
|
|
|
+ foreach (var item in head2.Cells)
|
|
|
+ {
|
|
|
+ item.CellStyle = headCellStyle;
|
|
|
+ }
|
|
|
+ foreach (var item in head3.Cells)
|
|
|
+ {
|
|
|
+ item.CellStyle = headCellStyle;
|
|
|
+ }
|
|
|
+ int rowNumber = 4;
|
|
|
+ var confData = devOpeAccountList.Select(t => t.C_Content).ToList();
|
|
|
+ for (int i = 0; i < confData.Count; i++)
|
|
|
+ {
|
|
|
+ IRow content = sheet.CreateRow(rowNumber);
|
|
|
+ Dictionary<string, object> dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(confData[i]);
|
|
|
+ int forCount = dict.Count + 1;
|
|
|
+ if (tabs.Count() > dict.Count) { forCount = tabs.Count() + 1; }
|
|
|
+ for (int j = 0; j < forCount; j++)
|
|
|
+ {
|
|
|
+ if (j < tabs.Count)
|
|
|
+ {
|
|
|
+ string celVal = "";
|
|
|
+ if (dict.ContainsKey(tabs[j].Name))
|
|
|
{
|
|
|
- IsVal = false;
|
|
|
- IsVal2 = false;
|
|
|
- head.CreateCell(cel).SetCellValue(vals);
|
|
|
- head2.CreateCell(cel).SetCellValue("");
|
|
|
- head3.CreateCell(cel).SetCellValue("");
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(1, 3, cel, cel));
|
|
|
+ celVal = dict[tabs[j].Name]?.ToString();
|
|
|
}
|
|
|
- if (!IsVal && merge > 0)
|
|
|
+ if (tabs[j].Name == "RunWhetherNormal")
|
|
|
{
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(1, 1, cel - merge - 1, cel - 1));
|
|
|
- merge = 0;
|
|
|
+ celVal = celVal.ToLower() == "true" ? "异常" : "正常";
|
|
|
+ content.CreateCell(j).SetCellValue(celVal);
|
|
|
}
|
|
|
- if (!IsVal2 && merge2 > 0)
|
|
|
+ else if (tabs[j].Name == "Date")
|
|
|
{
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(2, 2, cel - merge2 - 1, cel - 1));
|
|
|
- merge2 = 0;
|
|
|
+ content.CreateCell(j).SetCellValue(Convert.ToDateTime(celVal).ToString("yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ else if (DateTime.TryParse(celVal, out DateTime dt) && celVal.Length >= 10)
|
|
|
+ {
|
|
|
+ content.CreateCell(j).SetCellValue(dt.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ content.CreateCell(j).SetCellValue(celVal);
|
|
|
}
|
|
|
- cel++;
|
|
|
}
|
|
|
}
|
|
|
- if (cel == CtabColumns.Count + 1 && merge > 0 && IsVal)
|
|
|
- {
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(1, 1, cel - merge - 1, cel - 1));
|
|
|
- merge = 0; IsVal = false;
|
|
|
- }
|
|
|
- if (cel == CtabColumns.Count + 1 && merge2 > 0 && IsVal2)
|
|
|
- {
|
|
|
- sheet.AddMergedRegion(new CellRangeAddress(2, 2, cel - merge2 - 1, cel - 1));
|
|
|
- merge2 = 0; IsVal2 = false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach (var item in head.Cells)
|
|
|
- {
|
|
|
- item.CellStyle = headCellStyle;
|
|
|
- }
|
|
|
- foreach (var item in head2.Cells)
|
|
|
- {
|
|
|
- item.CellStyle = headCellStyle;
|
|
|
- }
|
|
|
- foreach (var item in head3.Cells)
|
|
|
- {
|
|
|
- item.CellStyle = headCellStyle;
|
|
|
- }
|
|
|
- int rowNumber = 4;
|
|
|
- var confData = devOpeAccountList.Select(t => t.C_Content).ToList();
|
|
|
- for (int i = 0; i < confData.Count; i++)
|
|
|
- {
|
|
|
- IRow content = sheet.CreateRow(rowNumber);
|
|
|
- Dictionary<string, object> dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(confData[i]);
|
|
|
- int forCount = dict.Count + 1;
|
|
|
- if (tabs.Count() > dict.Count) { forCount = tabs.Count() + 1; }
|
|
|
- for (int j = 0; j < forCount; j++)
|
|
|
- {
|
|
|
- if (j < tabs.Count)
|
|
|
+ foreach (var item in content.Cells)
|
|
|
{
|
|
|
- string celVal = "";
|
|
|
- if (dict.ContainsKey(tabs[j].Name))
|
|
|
- {
|
|
|
- celVal = dict[tabs[j].Name]?.ToString();
|
|
|
- }
|
|
|
- if (tabs[j].Name == "RunWhetherNormal")
|
|
|
- {
|
|
|
- celVal = celVal.ToLower() == "true" ? "异常" : "正常";
|
|
|
- content.CreateCell(j).SetCellValue(celVal);
|
|
|
- }
|
|
|
- else if (tabs[j].Name == "Date")
|
|
|
- {
|
|
|
- content.CreateCell(j).SetCellValue(Convert.ToDateTime(celVal).ToString("yyyy-MM-dd"));
|
|
|
- }
|
|
|
- else if (DateTime.TryParse(celVal, out DateTime dt) && celVal.Length >= 10)
|
|
|
- {
|
|
|
- content.CreateCell(j).SetCellValue(dt.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- content.CreateCell(j).SetCellValue(celVal);
|
|
|
- }
|
|
|
+ item.CellStyle = rowCellStyle;
|
|
|
}
|
|
|
+ rowNumber++;
|
|
|
}
|
|
|
- foreach (var item in content.Cells)
|
|
|
+
|
|
|
+ sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, tabs.Count - 1));
|
|
|
+ for (int i = 0; i <= tabs.Count; i++)
|
|
|
{
|
|
|
- item.CellStyle = rowCellStyle;
|
|
|
+ sheet.SetColumnWidth(i, 5000);
|
|
|
}
|
|
|
- rowNumber++;
|
|
|
}
|
|
|
-
|
|
|
- sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, tabs.Count - 1));
|
|
|
- for (int i = 0; i <= tabs.Count; i++)
|
|
|
+ else
|
|
|
{
|
|
|
- sheet.SetColumnWidth(i, 5000);
|
|
|
+ IRow content1 = sheet.CreateRow(1);
|
|
|
+ content1.CreateCell(0).SetCellValue("获取数据失败,没有选择台账配置!");
|
|
|
+ content1.Cells[0].CellStyle = headCellStyle;
|
|
|
+ sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 1, 0, 15));
|
|
|
+ sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, 15));
|
|
|
}
|
|
|
}
|
|
|
using (var stream = new NpoiMemoryStream())
|