This commit is contained in:
parent
9e54ba5b6e
commit
e0e162cb40
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
using FastReport.Utils;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.POIFS.Crypt;
|
||||
using OpenAI;
|
||||
using OpenAI.Managers;
|
||||
using OpenAI.ObjectModels.RequestModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BLL.Common
|
||||
{
|
||||
public class OpenAIhelper
|
||||
{
|
||||
private const string ApiKey = "sk-ee51958b5a4f4136b01ad4d866e1ba94";
|
||||
private const string AIURL = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
|
||||
|
||||
public static string ChatCompletion(string content)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + ApiKey);
|
||||
|
||||
var requestData = new
|
||||
{
|
||||
model = "qwen3.6-plus",
|
||||
messages = new[] {
|
||||
new { role = "user", content = content }
|
||||
},
|
||||
temperature = 0.7
|
||||
};
|
||||
|
||||
string json = JsonConvert.SerializeObject(requestData);
|
||||
var chatContent = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
// 同步请求
|
||||
var response = client.PostAsync(AIURL, chatContent).Result;
|
||||
string resultJson = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
// 解析返回
|
||||
dynamic result = JsonConvert.DeserializeObject(resultJson);
|
||||
return result.choices[0].message.content.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,18 @@
|
|||
using Aspose.Words.Rendering;
|
||||
using BLL;
|
||||
using BLL.Common;
|
||||
using FineUIPro.Web.HJGL.Match;
|
||||
using Model;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UglyToad.PdfPig;
|
||||
using UglyToad.PdfPig.Content;
|
||||
using UglyToad.PdfPig.Writer;
|
||||
|
|
@ -48,7 +54,17 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
ViewState["DataTable"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DataTable dtOther
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DataTable)ViewState["dtOther"];
|
||||
}
|
||||
set
|
||||
{
|
||||
ViewState["dtOther"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
|
|
@ -98,7 +114,7 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
string isono = "";
|
||||
foreach (string key in dic.Keys)
|
||||
{
|
||||
if (dic[key].IndexOf(i+1) >= 0)
|
||||
if (dic[key].IndexOf(i + 1) >= 0)
|
||||
{
|
||||
isono = key;
|
||||
outputPath = $"{rootPath}/File/PDF/Pipe/" + key;
|
||||
|
|
@ -106,7 +122,17 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
{
|
||||
Directory.CreateDirectory(outputPath);
|
||||
}
|
||||
outputPath = $"{outputPath}/" + key + dic[key].IndexOf(i) + ".pdf";
|
||||
string fileName = key;
|
||||
|
||||
var row = dtOther.Select(" page='" + (i + 1) + "' and region_type='C' ").FirstOrDefault();
|
||||
if (row != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(row["text"].ToString()))
|
||||
{
|
||||
fileName = row["text"].ToString();
|
||||
}
|
||||
}
|
||||
outputPath = $"{outputPath}/" + fileName + dic[key].IndexOf(i) + ".pdf";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -132,6 +158,63 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
var isoInfo = Funs.DB.HJGL_PW_IsoInfo.FirstOrDefault(x => x.ISO_IsoNo == isono && x.ProjectId==CurrUser.LoginProjectId);
|
||||
if (isoInfo != null)
|
||||
{
|
||||
Regex NumberRegex = new Regex(@"\d+\.?\d*");
|
||||
DataRow[] rows = dt.Select(" pipe_no='" + isono + "' and category='PIPE'");
|
||||
if (rows != null && rows.Length > 0)
|
||||
{
|
||||
string description = rows[0]["description"].ToString();
|
||||
|
||||
if (!isoInfo.ISO_Dia.HasValue || !isoInfo.ISO_Sch.HasValue || string.IsNullOrEmpty(isoInfo.MaterialStandardId))
|
||||
{
|
||||
string res = OpenAIhelper.ChatCompletion("请根据 " + description + ",识别外径,壁厚,材质标准(请严格按照国家标准返回),结果仅以JSON格式返回,不要解释,不要多余文字,不要markdown,例如 {\r\n \"外径\": \"33.4 mm\",\r\n \"壁厚\": \"6.35 mm\",\r\n \"材质标准\": \"GB/T 9948\"\r\n}");
|
||||
|
||||
JObject jobject = JObject.Parse(res);
|
||||
string dia = jobject.Value<string>("外径");
|
||||
string sch = jobject.Value<string>("壁厚");
|
||||
string materialStandard = jobject.Value<string>("材质标准");
|
||||
MatchCollection matchCollection1 = NumberRegex.Matches(dia);
|
||||
foreach (var match in matchCollection1)
|
||||
{
|
||||
// 使用 TryParse 确保转换安全,避免异常
|
||||
if (decimal.TryParse(match.ToString(), out decimal number))
|
||||
{
|
||||
isoInfo.ISO_Dia = number;
|
||||
}
|
||||
}
|
||||
|
||||
MatchCollection matchCollection2 = NumberRegex.Matches(sch);
|
||||
foreach (var match in matchCollection2)
|
||||
{
|
||||
// 使用 TryParse 确保转换安全,避免异常
|
||||
if (decimal.TryParse(match.ToString(), out decimal number))
|
||||
{
|
||||
isoInfo.ISO_Sch = number;
|
||||
}
|
||||
}
|
||||
|
||||
isoInfo.MaterialStandardId = Funs.DB.HJGL_BS_MaterialStandard.Where(x => x.MaterialStandardCode == materialStandard).Select(x => x.MaterialStandardId).FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
decimal length = 0;
|
||||
foreach(DataRow row in rows)
|
||||
{
|
||||
|
||||
MatchCollection matches = NumberRegex.Matches(row["qty"].ToString());
|
||||
foreach (var match in matches)
|
||||
{
|
||||
// 使用 TryParse 确保转换安全,避免异常
|
||||
if (decimal.TryParse(match.ToString(), out decimal number))
|
||||
{
|
||||
length += number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isoInfo.PipeLineLength = length;
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
//保存文件到附件
|
||||
|
||||
UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(outputPath.Replace(rootPath, ""), 10, null), outputPath.Replace(rootPath, ""), Const.HJGL_PipelineManageMenuId, isoInfo.ISO_ID);
|
||||
|
|
@ -142,6 +225,64 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
|
||||
|
||||
}
|
||||
public static string HeaderCorrespondence(string uploadUrl, string data, string method, string contenttype)
|
||||
{
|
||||
// 5. 创建HTTP请求
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uploadUrl);
|
||||
request.Method = string.IsNullOrEmpty(method) ? "GET" : method;
|
||||
request.ContentType = string.IsNullOrEmpty(contenttype) ? "application/json;charset=utf-8" : contenttype;
|
||||
if (uploadUrl.IndexOf("https") >= 0)
|
||||
{
|
||||
request.ProtocolVersion = HttpVersion.Version10;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(data))
|
||||
{
|
||||
Stream RequestStream = request.GetRequestStream();
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(data);
|
||||
RequestStream.Write(bytes, 0, bytes.Length);
|
||||
RequestStream.Close();
|
||||
}
|
||||
|
||||
HttpWebResponse response = null;
|
||||
Stream ResponseStream = null;
|
||||
StreamReader StreamReader = null;
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
ResponseStream = response.GetResponseStream();
|
||||
StreamReader = new StreamReader(ResponseStream, Encoding.GetEncoding("utf-8"));
|
||||
|
||||
string re = StreamReader.ReadToEnd();
|
||||
StreamReader.Close();
|
||||
ResponseStream.Close();
|
||||
return re;
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
ResponseStream = response.GetResponseStream();
|
||||
StreamReader = new StreamReader(ResponseStream, Encoding.GetEncoding("utf-8"));
|
||||
|
||||
string re = StreamReader.ReadToEnd();
|
||||
return re;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (StreamReader != null)
|
||||
{
|
||||
StreamReader.Close();
|
||||
}
|
||||
if (ResponseStream != null)
|
||||
{
|
||||
ResponseStream.Close();
|
||||
}
|
||||
if (response != null)
|
||||
{
|
||||
response.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void btnAudit_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
|
@ -153,6 +294,7 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
{
|
||||
JObject jobject = JObject.Parse(resultdata.Value);
|
||||
JArray jArray = jobject.Value<JArray>("material_rows");
|
||||
JArray jArrayOther = jobject.Value<JArray>("other_regions");
|
||||
dt = new DataTable();
|
||||
dt.Columns.Add("id");
|
||||
dt.Columns.Add("pipe_no");
|
||||
|
|
@ -165,6 +307,13 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
dt.Columns.Add("page_no");
|
||||
dt.Columns.Add("remark");
|
||||
|
||||
dtOther = new DataTable();
|
||||
dtOther.Columns.Add("id");
|
||||
dtOther.Columns.Add("region_type");
|
||||
dtOther.Columns.Add("region_label");
|
||||
dtOther.Columns.Add("page");
|
||||
dtOther.Columns.Add("text");
|
||||
|
||||
// 遍历并提取数据
|
||||
foreach (JObject item in jArray)
|
||||
{
|
||||
|
|
@ -181,6 +330,17 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
row["remark"] = item.Value<string>("remark");
|
||||
dt.Rows.Add(row);
|
||||
}
|
||||
|
||||
foreach (JObject item in jArrayOther)
|
||||
{
|
||||
var row = dtOther.NewRow();
|
||||
row["id"] = item.Value<string>("id");
|
||||
row["region_type"] = item.Value<string>("region_type");
|
||||
row["region_label"] = item.Value<string>("region_label");
|
||||
row["page"] = item.Value<string>("page");
|
||||
row["text"] = item.Value<string>("text");
|
||||
dtOther.Rows.Add(row);
|
||||
}
|
||||
BindGrid();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,6 +353,7 @@ namespace FineUIPro.Web.HJGL.DataIn
|
|||
break;
|
||||
case "设计压力":
|
||||
isoInfo.ISO_DesignPress = Funs.GetNewDecimal(row[dataColumn.ColumnName].ToString());
|
||||
isoInfo.LeakageTest = row[dataColumn.ColumnName].ToString();
|
||||
break;
|
||||
case "设计温度":
|
||||
isoInfo.ISO_DesignTemperature = Funs.GetNewDecimal(row[dataColumn.ColumnName].ToString());
|
||||
|
|
|
|||
Loading…
Reference in New Issue