管线导入修改
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
|
||||
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
|
||||
<Use64BitIISExpress />
|
||||
<IISExpressSSLPort />
|
||||
<IISExpressAnonymousAuthentication />
|
||||
|
||||
@@ -116,76 +116,36 @@ namespace FineUIPro.Web.HJGL.DataIn
|
||||
/// <param name="e"></param>
|
||||
protected void InitGrid()
|
||||
{
|
||||
|
||||
// 加载PDF文档
|
||||
PdfDocument pdf = new PdfDocument();
|
||||
if (!File.Exists(fileUrl))
|
||||
{
|
||||
return;
|
||||
}
|
||||
pdf.LoadFromFile(fileUrl);
|
||||
PdfTableExtractor extractor = new PdfTableExtractor(pdf);
|
||||
// 遍历每一页
|
||||
int i = 0;
|
||||
if (ckbSkipFirst == "1")
|
||||
|
||||
int startPageIndex = ckbSkipFirst == "1" ? 1 : 0;
|
||||
DataTable dtTemp = ExtractAllPdfTables(fileUrl, startPageIndex);
|
||||
if (dtTemp.Rows.Count == 0 || dtTemp.Columns.Count <= 1)
|
||||
{
|
||||
i = 1;
|
||||
BindIsoGrid();
|
||||
return;
|
||||
}
|
||||
var units = from x in Funs.DB.Base_Unit
|
||||
join y in Funs.DB.Project_Unit on x.UnitId equals y.UnitId
|
||||
where y.ProjectId == CurrUser.LoginProjectId
|
||||
select x;
|
||||
var installs = from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId select x;
|
||||
|
||||
ProcessMergedTable(dtTemp);
|
||||
BindIsoGrid();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统一清洗、映射并转换全部PDF页面的数据。
|
||||
/// </summary>
|
||||
private void ProcessMergedTable(DataTable dtTemp)
|
||||
{
|
||||
var steels = from x in Funs.DB.HJGL_BS_Steel select x;
|
||||
var materialStandards = from x in Funs.DB.HJGL_BS_MaterialStandard select x;
|
||||
|
||||
var rates = from x in Funs.DB.HJGL_BS_NDTRate select x;
|
||||
var types = from x in Funs.DB.HJGL_BS_JointType select x;
|
||||
var methods = from x in Funs.DB.HJGL_BS_WeldMethod select x;
|
||||
var materials = from x in Funs.DB.HJGL_BS_WeldMaterial select x;
|
||||
var services = from x in Funs.DB.HJGL_BS_Service select x;
|
||||
var slopeTypes = from x in Funs.DB.HJGL_BS_SlopeType select x;
|
||||
var isoClasss = from x in Funs.DB.HJGL_BS_IsoClass select x;
|
||||
var components = from x in Funs.DB.HJGL_BS_Component select x;
|
||||
var dns = from x in Funs.DB.HJGL_BS_SchTab select x;
|
||||
var execStandards = from x in Funs.DB.HJGL_BS_ExecStandard select x;
|
||||
var dataInTemp = from x in Funs.DB.HJGL_Sys_DataInTemp
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId && x.UserId == this.CurrUser.UserId && x.Type == this.IsPDMS
|
||||
select x;
|
||||
var users = from x in Funs.DB.Sys_User select x;
|
||||
string serviceNames = string.Empty;
|
||||
for (; i < pdf.Pages.Count; i++)
|
||||
{
|
||||
PdfPageBase page = pdf.Pages[i];
|
||||
// 提取页面中的表格
|
||||
PdfTable[] tables = extractor.ExtractTable(i);
|
||||
// 输出找到的表格数量
|
||||
Console.WriteLine($"第 {i + 1} 页找到 {tables.Length} 个表格");
|
||||
// 遍历提取到的表格
|
||||
for (int j = 0; j < tables.Length; j++)
|
||||
{
|
||||
PdfTable table = tables[j];
|
||||
DataTable dtTemp = new DataTable();
|
||||
for (int col = 0; col < table.GetColumnCount(); col++)
|
||||
{
|
||||
dtTemp.Columns.Add("col" + col);
|
||||
}
|
||||
// 遍历表格的行列
|
||||
for (int row = 0; row < table.GetRowCount(); row++)
|
||||
{
|
||||
DataRow rowData = dtTemp.NewRow();
|
||||
dtTemp.Rows.Add(rowData);
|
||||
for (int col = 0; col < table.GetColumnCount(); col++)
|
||||
{
|
||||
string text = table.GetText(row, col);
|
||||
rowData[col] = table.GetText(row, col);
|
||||
Console.Write($"{text}\t");
|
||||
}
|
||||
Console.WriteLine(); // 换行
|
||||
}
|
||||
|
||||
if (dtTemp.Rows.Count > 0 && dtTemp.Columns.Count > 1)
|
||||
{// 2. 转换为CSV
|
||||
// 所有页面的表格已经合并,只调用一次大模型清洗和表头映射。
|
||||
string csvContent = ConvertDataTableToCsv(dtTemp);
|
||||
Console.WriteLine("生成的CSV内容:");
|
||||
Console.WriteLine(csvContent);
|
||||
@@ -194,36 +154,15 @@ namespace FineUIPro.Web.HJGL.DataIn
|
||||
string uploadUrl = "http://localhost:8000/api/table/clean"; // 替换为实际上传地址
|
||||
string fileName = $"data_{DateTime.Now:yyyyMMddHHmmss}.csv";
|
||||
//"管线号", "公称直径", "管道等级", "管道材料", "主要介质", "起止点", "操作参数温度", "操作参数压力", "设计参数温度", "设计参数压力", "隔热工程代号", "隔热材料", "厚度", "介质", "压力", "比例", "方法", "合格等级", "PID尾号", "压力管道类别", "应力分析题号", "备注"
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
Grid grid = new Grid();
|
||||
grid.ShowGridHeader = true;
|
||||
grid.Title = dtTemp.TableName;
|
||||
grid.AllowColumnLocking = true;
|
||||
grid.DataKeyNames = new string[] { "Id" };
|
||||
foreach (DataColumn dc in dtTemp.Columns)
|
||||
{
|
||||
grid.Columns.Add(new BoundField() { DataField = dc.ColumnName, HeaderText = dc.ColumnName });
|
||||
}
|
||||
grid.DataSource = dtTemp;
|
||||
grid.DataBind();
|
||||
Region2.Items.Add(grid);
|
||||
Region2.Items.Add(CreateTableGrid(dtTemp));
|
||||
set.Tables.Add(dtTemp);
|
||||
string response = UploadCsvFile(csvContent, uploadUrl, fileName);
|
||||
Grid grid1 = new Grid();
|
||||
grid1.ShowGridHeader = true;
|
||||
grid1.Title = dtTemp.TableName;
|
||||
grid1.AllowColumnLocking = true;
|
||||
grid1.DataKeyNames = new string[] { "Id" };
|
||||
JObject dynamicObj = JObject.Parse(response);
|
||||
|
||||
DataTable dtAfterProcess = new DataTable();
|
||||
foreach (JToken employeeToken in dynamicObj["headers"])
|
||||
{
|
||||
dtAfterProcess.Columns.Add(employeeToken.ToString());
|
||||
grid1.Columns.Add(new BoundField() { DataField = employeeToken.ToString(), HeaderText = employeeToken.ToString() });
|
||||
}
|
||||
dtAfterProcess.Columns.Add("Id");
|
||||
|
||||
@@ -250,9 +189,7 @@ namespace FineUIPro.Web.HJGL.DataIn
|
||||
//}
|
||||
dtAfterProcess.Rows.Add(row);
|
||||
}
|
||||
grid1.DataSource = dtAfterProcess;
|
||||
grid1.DataBind();
|
||||
Region1.Items.Add(grid1);
|
||||
Region1.Items.Add(CreateTableGrid(dtAfterProcess));
|
||||
setAfterProcess.Tables.Add(dtAfterProcess);
|
||||
|
||||
string urlHeaderCorrespondence = "http://localhost:8000/api/table/head";
|
||||
@@ -401,7 +338,7 @@ namespace FineUIPro.Web.HJGL.DataIn
|
||||
case "泄露性试验":
|
||||
if (isoInfo.ISO_DesignPress.HasValue)
|
||||
{
|
||||
isoInfo.LeakageTest = isoInfo.ISO_DesignPress.Value.ToString("##.##");// row[dataColumn.ColumnName].ToString();
|
||||
isoInfo.LeakageTest = isoInfo.ISO_DesignPress.Value.ToString("0.00") ?? "";// row[dataColumn.ColumnName].ToString();
|
||||
}
|
||||
break;
|
||||
case "设计压力":
|
||||
@@ -449,7 +386,14 @@ namespace FineUIPro.Web.HJGL.DataIn
|
||||
}
|
||||
if (row[dataColumn.ColumnName].ToString().Contains("SH"))
|
||||
{
|
||||
isoInfo.ISC_ID = isoClasss.Where(x => x.ISC_IsoName == row[dataColumn.ColumnName].ToString() || x.ISC_IsoCode == row[dataColumn.ColumnName].ToString()).Select(x => x.ISC_ID).FirstOrDefault();
|
||||
var parts = row[dataColumn.ColumnName].ToString().Split(new[] { "SH" }, StringSplitOptions.None);
|
||||
string PipeLineClass = parts[0]; // GC2
|
||||
string ISC_IsoName = "SH" + parts[1]; // SHB3
|
||||
isoInfo.ISC_ID = isoClasss.Where(x => x.ISC_IsoName == ISC_IsoName || x.ISC_IsoCode == ISC_IsoName).Select(x => x.ISC_ID).FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(PipeLineClass))
|
||||
{
|
||||
isoInfo.PipeLineClass = PipeLineClass;
|
||||
}
|
||||
}
|
||||
if (row[dataColumn.ColumnName].ToString().Contains("焊后热处理"))
|
||||
{
|
||||
@@ -460,22 +404,105 @@ namespace FineUIPro.Web.HJGL.DataIn
|
||||
isoList.Add(isoInfo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e11)
|
||||
|
||||
/// <summary>
|
||||
/// 一次性读取PDF指定页范围内的全部表格,并按列位置合并为一个数据表。
|
||||
/// </summary>
|
||||
private static DataTable ExtractAllPdfTables(string pdfFilePath, int startPageIndex)
|
||||
{
|
||||
DataTable result = new DataTable("PDF全部页");
|
||||
using (PdfDocument pdf = new PdfDocument())
|
||||
{
|
||||
pdf.LoadFromFile(pdfFilePath);
|
||||
PdfTableExtractor extractor = new PdfTableExtractor(pdf);
|
||||
|
||||
for (int pageIndex = startPageIndex; pageIndex < pdf.Pages.Count; pageIndex++)
|
||||
{
|
||||
PdfTable[] tables = extractor.ExtractTable(pageIndex);
|
||||
foreach (PdfTable table in tables)
|
||||
{
|
||||
AppendPdfTable(result, table);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将单个PDF表格追加到汇总表,页间列数不同时按最大列数补齐。
|
||||
/// </summary>
|
||||
private static void AppendPdfTable(DataTable target, PdfTable source)
|
||||
{
|
||||
int firstColumnIndex = 0;
|
||||
while (firstColumnIndex < source.GetColumnCount() && IsPdfColumnEmpty(source, firstColumnIndex))
|
||||
{
|
||||
firstColumnIndex++;
|
||||
}
|
||||
Console.WriteLine($"\n--- 表格 {j + 1} ---");
|
||||
|
||||
int lastColumnIndex = source.GetColumnCount() - 1;
|
||||
while (lastColumnIndex >= firstColumnIndex && IsPdfColumnEmpty(source, lastColumnIndex))
|
||||
{
|
||||
lastColumnIndex--;
|
||||
}
|
||||
|
||||
if (lastColumnIndex < firstColumnIndex)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Spire可能在不同页面的表格首尾生成全空占位列,追加前先去掉这些列,避免整页错位。
|
||||
int contentColumnCount = lastColumnIndex - firstColumnIndex + 1;
|
||||
while (target.Columns.Count < contentColumnCount)
|
||||
{
|
||||
target.Columns.Add("col" + target.Columns.Count);
|
||||
}
|
||||
|
||||
for (int rowIndex = 0; rowIndex < source.GetRowCount(); rowIndex++)
|
||||
{
|
||||
DataRow row = target.NewRow();
|
||||
for (int columnIndex = 0; columnIndex < contentColumnCount; columnIndex++)
|
||||
{
|
||||
row[columnIndex] = source.GetText(rowIndex, firstColumnIndex + columnIndex);
|
||||
}
|
||||
target.Rows.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsPdfColumnEmpty(PdfTable table, int columnIndex)
|
||||
{
|
||||
for (int rowIndex = 0; rowIndex < table.GetRowCount(); rowIndex++)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(table.GetText(rowIndex, columnIndex)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void BindIsoGrid()
|
||||
{
|
||||
IsoGrid.DataSource = isoList;
|
||||
IsoGrid.DataBind();
|
||||
}
|
||||
|
||||
this.IsoGrid.DataSource = this.isoList;
|
||||
this.IsoGrid.DataBind();
|
||||
private static Grid CreateTableGrid(DataTable table)
|
||||
{
|
||||
Grid grid = new Grid
|
||||
{
|
||||
ShowGridHeader = true,
|
||||
Title = table.TableName,
|
||||
AllowColumnLocking = true,
|
||||
DataKeyNames = new string[] { "Id" }
|
||||
};
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
grid.Columns.Add(new BoundField { DataField = column.ColumnName, HeaderText = column.ColumnName });
|
||||
}
|
||||
grid.DataSource = table;
|
||||
grid.DataBind();
|
||||
return grid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
|
||||
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
|
||||
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<Use64BitIISExpress />
|
||||
|
||||
Reference in New Issue
Block a user