fix:焊口号发生更改时,将此焊口对应管线图纸信息HJGL_DrawingInfo中DrawingJson同步修改

This commit is contained in:
2026-09-01 17:05:32 +08:00
parent 3943b6a042
commit 4091b11fde
8 changed files with 160 additions and 7 deletions
@@ -1,5 +1,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BLL
{
@@ -8,6 +13,10 @@ namespace BLL
/// </summary>
public static class DrawingInfoService
{
private static readonly Regex JointNoRegex = new Regex(
@"^(?<prefix>[^0-9]*)(?<number>[0-9]+(?:\.[0-9]+)?)(?<suffix>.*)$",
RegexOptions.Compiled);
/// <summary>
/// 根据附件文件标识获取图纸 JSON。
/// </summary>
@@ -24,6 +33,136 @@ namespace BLL
.FirstOrDefault();
}
/// <summary>
/// 同步管线图纸中的焊口标注,数据由调用方统一提交。
/// </summary>
public static void UpdateJointAnnotation(Model.SGGLDB db, string isoId, string oldJointNo, string newJointNo)
{
if (db == null || string.IsNullOrWhiteSpace(isoId)
|| string.IsNullOrWhiteSpace(oldJointNo) || string.IsNullOrWhiteSpace(newJointNo)
|| string.Equals(oldJointNo, newJointNo, StringComparison.Ordinal))
{
return;
}
Model.AttachFile attachFile = db.AttachFile.FirstOrDefault(x =>
x.ToKeyId == isoId && x.MenuId == Const.HJGL_PipelineManageMenuId);
if (attachFile == null || string.IsNullOrWhiteSpace(attachFile.AttachSource))
{
return;
}
List<string> attachFileIds;
try
{
attachFileIds = JArray.Parse(attachFile.AttachSource)
.OfType<JObject>()
.Select(x => x.Value<string>("id"))
.Where(x => !string.IsNullOrWhiteSpace(x))
.Distinct()
.ToList();
}
catch (JsonException)
{
return;
}
var drawingInfos = db.HJGL_DrawingInfo
.Where(x => attachFileIds.Contains(x.AttachFileId))
.ToList();
foreach (Model.HJGL_DrawingInfo drawingInfo in drawingInfos)
{
if (string.IsNullOrWhiteSpace(drawingInfo.DrawingJson))
{
continue;
}
try
{
string drawingJson = UpdateDrawingJson(drawingInfo.DrawingJson, oldJointNo, newJointNo);
if (drawingJson != null)
{
drawingInfo.DrawingJson = drawingJson;
}
}
catch (JsonException)
{
// 单张图纸 JSON 异常时跳过,不影响焊口信息更新。
}
}
}
private static string UpdateDrawingJson(string drawingJson, string oldJointNo, string newJointNo)
{
JObject drawing = JsonConvert.DeserializeObject<JObject>(drawingJson);
JObject annotations = drawing == null ? null : drawing["annotations"] as JObject;
if (annotations == null)
{
return null;
}
JointNoParts jointNoParts = JointNoParts.Parse(newJointNo);
List<JObject> matchedAnnotations = annotations.Properties()
.SelectMany(x => x.Value.OfType<JObject>())
.Where(x => string.Equals(x.Value<string>("label"), oldJointNo, StringComparison.Ordinal))
.ToList();
foreach (JObject annotation in matchedAnnotations)
{
annotation["label"] = newJointNo;
annotation["displayValue"] = JToken.FromObject(jointNoParts.DisplayValue);
JObject settings = annotation["settings"] as JObject ?? new JObject();
settings["prefix"] = jointNoParts.Prefix;
settings["suffix"] = jointNoParts.Suffix;
annotation["settings"] = settings;
}
return matchedAnnotations.Count > 0 ? JsonConvert.SerializeObject(drawing) : null;
}
private sealed class JointNoParts
{
public string Prefix { get; private set; }
public object DisplayValue { get; private set; }
public string Suffix { get; private set; }
public static JointNoParts Parse(string jointNo)
{
Match match = JointNoRegex.Match(jointNo);
if (!match.Success)
{
return new JointNoParts { Prefix = string.Empty, DisplayValue = jointNo, Suffix = string.Empty };
}
string number = match.Groups["number"].Value;
string integerPart = number.Split('.')[0];
long numberValue;
decimal decimalValue;
bool hasLeadingZero = integerPart.Length > 1 && integerPart.StartsWith("0");
object displayValue = number;
if (!hasLeadingZero && long.TryParse(number, out numberValue))
{
displayValue = numberValue;
}
else if (!hasLeadingZero && decimal.TryParse(number, NumberStyles.AllowDecimalPoint,
CultureInfo.InvariantCulture, out decimalValue))
{
displayValue = decimalValue;
}
return new JointNoParts
{
Prefix = match.Groups["prefix"].Value,
DisplayValue = displayValue,
Suffix = match.Groups["suffix"].Value
};
}
}
/// <summary>
/// 新增或更新图纸标注信息,同一 AttachFileId 只保留一条记录。
/// </summary>
@@ -96,6 +96,9 @@ namespace BLL
Model.HJGL_PW_JointInfo newJointInfo = db.HJGL_PW_JointInfo.FirstOrDefault(e => e.JOT_ID == jointInfo.JOT_ID);
if (newJointInfo != null)
{
Model.HJGL_PW_JointInfo originalJointInfo = db.HJGL_PW_JointInfo.GetOriginalEntityState(newJointInfo);
string oldJointNo = originalJointInfo == null ? newJointInfo.JOT_JointNo : originalJointInfo.JOT_JointNo;
string drawingIsoId = originalJointInfo == null ? newJointInfo.ISO_ID : originalJointInfo.ISO_ID;
newJointInfo.JOT_JointNo = jointInfo.JOT_JointNo;
newJointInfo.DReportID = jointInfo.DReportID;
newJointInfo.ISO_ID = jointInfo.ISO_ID;
@@ -138,6 +141,7 @@ namespace BLL
newJointInfo.PressureTestPackageNo = jointInfo.PressureTestPackageNo;
newJointInfo.IsGold = jointInfo.IsGold;
DrawingInfoService.UpdateJointAnnotation(db, drawingIsoId, oldJointNo, newJointInfo.JOT_JointNo);
db.SubmitChanges();
}
}
@@ -501,15 +505,24 @@ namespace BLL
if (operateState == Const.Delete || jointAttribute != "固定")
{
Model.HJGL_PW_JointInfo deleteJointInfo = db.HJGL_PW_JointInfo.FirstOrDefault(e => e.JOT_ID == jotId);
if (deleteJointInfo.JOT_JointNo.Last() == 'G')
if (deleteJointInfo != null && !string.IsNullOrEmpty(deleteJointInfo.JOT_JointNo)
&& deleteJointInfo.JOT_JointNo.Last() == 'G')
{
string oldJointNo = deleteJointInfo.JOT_JointNo;
deleteJointInfo.JOT_JointNo = deleteJointInfo.JOT_JointNo.Substring(0, deleteJointInfo.JOT_JointNo.Length - 1);
DrawingInfoService.UpdateJointAnnotation(db, deleteJointInfo.ISO_ID, oldJointNo, deleteJointInfo.JOT_JointNo);
db.SubmitChanges();
}
}
else
{
Model.HJGL_PW_JointInfo addJointInfo = db.HJGL_PW_JointInfo.FirstOrDefault(e => e.JOT_ID == jotId);
if (addJointInfo == null || string.IsNullOrEmpty(addJointInfo.JOT_JointNo))
{
return;
}
string oldJointNo = addJointInfo.JOT_JointNo;
if (addJointInfo.JOT_JointNo.Last() != 'G')
{
addJointInfo.JOT_JointNo += "G";
@@ -518,6 +531,7 @@ namespace BLL
{
addJointInfo.JOT_JointNo += "H";
}
DrawingInfoService.UpdateJointAnnotation(db, addJointInfo.ISO_ID, oldJointNo, addJointInfo.JOT_JointNo);
db.SubmitChanges();
}
}
@@ -6,12 +6,12 @@
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="module" crossorigin src="./assets/viewer-C4q9fMuF.js"></script>
<script type="module" crossorigin src="./assets/viewer-D3iNrO9k.js"></script>
<link rel="modulepreload" crossorigin href="./assets/pdf-lib-AfLQbX6n.js">
<link rel="modulepreload" crossorigin href="./assets/pdfjs-DXqArq6h.js">
<link rel="modulepreload" crossorigin href="./assets/styles-G88NglGL.js">
<link rel="stylesheet" crossorigin href="./assets/styles-CXI0s-Oz.css">
<link rel="stylesheet" crossorigin href="./assets/viewer-ieFmb7PT.css">
<link rel="stylesheet" crossorigin href="./assets/viewer-u37LBwT8.css">
</head>
<body>
<form id="form1" runat="server">
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
.viewer-container[data-v-7710504d]{display:flex;height:100vh;padding:12px;box-sizing:border-box}.viewer-main[data-v-7710504d]{flex:1;min-width:0;display:flex;flex-direction:column;border:1px solid var(--border);border-radius:10px;background:var(--panel);box-shadow:0 10px 30px -18px #00000059;padding:8px;box-sizing:border-box}.controls[data-v-7710504d]{flex-wrap:wrap;overflow:visible}.controls[data-v-7710504d]>*{flex-shrink:0}
@@ -0,0 +1 @@
.viewer-container[data-v-b1adea8b]{display:flex;height:100vh;padding:12px;box-sizing:border-box}.viewer-main[data-v-b1adea8b]{flex:1;min-width:0;display:flex;flex-direction:column;border:1px solid var(--border);border-radius:10px;background:var(--panel);box-shadow:0 10px 30px -18px #00000059;padding:8px;box-sizing:border-box}.controls[data-v-b1adea8b]{flex-wrap:wrap;overflow:visible}.controls[data-v-b1adea8b]>*{flex-shrink:0}
@@ -4,12 +4,12 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PDF 预览</title>
<script type="module" crossorigin src="./assets/viewer-C4q9fMuF.js"></script>
<script type="module" crossorigin src="./assets/viewer-D3iNrO9k.js"></script>
<link rel="modulepreload" crossorigin href="./assets/pdf-lib-AfLQbX6n.js">
<link rel="modulepreload" crossorigin href="./assets/pdfjs-DXqArq6h.js">
<link rel="modulepreload" crossorigin href="./assets/styles-G88NglGL.js">
<link rel="stylesheet" crossorigin href="./assets/styles-CXI0s-Oz.css">
<link rel="stylesheet" crossorigin href="./assets/viewer-ieFmb7PT.css">
<link rel="stylesheet" crossorigin href="./assets/viewer-u37LBwT8.css">
</head>
<body>
<div id="app"></div>