feat(hjgl): 增强焊口匹配与任务单打印

焊口台账、材料匹配和任务单打印需要统一到焊口维度处理。
新增焊口查询、匹配保存和打印模板适配,便于按焊口追溯材料和任务。
This commit is contained in:
2026-06-26 00:40:55 +08:00
parent bd9b5a6f4d
commit 02b524b895
14 changed files with 836 additions and 121 deletions
@@ -378,14 +378,11 @@ namespace FineUIPro.Web.HJGL.InfoQuery
private void BindGrid()
{
Model.View_HJGL_WeldJoint model = new Model.View_HJGL_WeldJoint();
model.ProjectId = this.CurrUser.LoginProjectId;
model.WeldJointCode = this.txtWeldJointCode.Text;
Model.View_HJGL_WeldJoint model = GetCurrentWeldJointQueryModel();
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
model.WeldJointCode = this.txtWeldJointCode.Text;
var list = BLL.WeldJointService.GetDataBymodel(model, Grid1.PageIndex, Grid1.PageSize);
Grid1.RecordCount = list.Total;
Grid1.DataSource = list.Data;
@@ -403,6 +400,36 @@ namespace FineUIPro.Web.HJGL.InfoQuery
}
}
/// <summary>
/// 汇总当前焊口台账查询条件,保证列表、导出和打印使用同一套过滤规则。
/// </summary>
private Model.View_HJGL_WeldJoint GetCurrentWeldJointQueryModel()
{
return new Model.View_HJGL_WeldJoint
{
ProjectId = this.CurrUser.LoginProjectId,
WeldJointCode = this.txtWeldJointCode.Text.Trim(),
IsWeldOK = this.ddlWeldState.SelectedValue
};
}
/// <summary>
/// 按当前树节点和筛选条件获取焊口铭牌待打印焊口。
/// </summary>
private List<Model.View_HJGL_WeldJoint> GetCurrentWeldJointList()
{
Model.View_HJGL_WeldJoint model = GetCurrentWeldJointQueryModel();
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
model.PipelineId = this.tvControlItem.SelectedNodeID;
}
return BLL.WeldJointService.GetViewWeldJointsBymodel(model);
}
private void get3DParmeter_weldjoint(List<View_HJGL_WeldJoint> model)
{
if (model.Any())
@@ -577,7 +604,7 @@ namespace FineUIPro.Web.HJGL.InfoQuery
string fileName = "";
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2) //单位工程
{
Model.View_HJGL_WeldJoint model = new Model.View_HJGL_WeldJoint();
Model.View_HJGL_WeldJoint model = GetCurrentWeldJointQueryModel();
model.UnitWorkId = this.tvControlItem.SelectedNodeID;
var list = BLL.WeldJointService.GetViewWeldJointsBymodel(model);
View_HJGL_WeldJoint = list;
@@ -585,6 +612,8 @@ namespace FineUIPro.Web.HJGL.InfoQuery
}
else if (this.tvControlItem.SelectedNode.CommandName == "管线")
{
var list = GetCurrentWeldJointList();
View_HJGL_WeldJoint = list;
fileName = PipelineService.GetPipelineByPipelineId(this.tvControlItem.SelectedNodeID)?.PipelineCode;
}
@@ -737,8 +766,11 @@ namespace FineUIPro.Web.HJGL.InfoQuery
{
if (this.tvControlItem.SelectedNode.CommandName.Split('|').Count() == 2)
{
var currentQuery = GetCurrentWeldJointQueryModel();
var q = (from x in Funs.DB.View_HJGL_WeldJoint
where x.ProjectId == this.CurrUser.LoginProjectId && x.UnitWorkId == this.tvControlItem.SelectedNodeID
&& (string.IsNullOrEmpty(currentQuery.WeldJointCode) || x.WeldJointCode.Contains(currentQuery.WeldJointCode))
&& (string.IsNullOrEmpty(currentQuery.IsWeldOK) || x.IsWeldOK == currentQuery.IsWeldOK)
select new
{
PipelineId = x.PipelineId,
@@ -787,6 +819,206 @@ namespace FineUIPro.Web.HJGL.InfoQuery
}
}
/// <summary>
/// 打印当前筛选范围内的焊口铭牌。
/// </summary>
protected void btnPrintJointNameplate_Click(object sender, EventArgs e)
{
if (this.Grid1.SelectedRowIDArray == null || this.Grid1.SelectedRowIDArray.Length == 0)
{
Alert.Show("请选择要打印的焊口");
return;
}
var weldJointList = GetSelectedWeldJointList();
if (weldJointList == null || weldJointList.Count == 0)
{
Alert.Show("当前条件下没有可打印的焊口");
return;
}
var tb = BuildWeldJointNameplateTable(weldJointList);
if (tb == null || tb.Rows.Count == 0)
{
Alert.Show("当前条件下没有可打印的焊口");
return;
}
BLL.FastReportService.ResetData();
tb.TableName = "Table1";
BLL.FastReportService.AddFastreportTable(tb);
string rootPath = Server.MapPath("~/");
string initTemplatePath = "File\\Fastreport\\焊口铭牌.frx";
if (File.Exists(rootPath + initTemplatePath))
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("~/Controls/Fastreport.aspx?ReportPath={0}", rootPath + initTemplatePath)));
}
}
/// <summary>
/// 获取当前勾选的焊口。
/// </summary>
private List<Model.View_HJGL_WeldJoint> GetSelectedWeldJointList()
{
var ids = this.Grid1.SelectedRowIDArray;
if (ids == null || ids.Length == 0)
{
return new List<Model.View_HJGL_WeldJoint>();
}
List<Model.View_HJGL_WeldJoint> list = new List<Model.View_HJGL_WeldJoint>();
foreach (string id in ids)
{
var item = WeldJointService.GetViewWeldJointById(id);
if (item != null)
{
list.Add(item);
}
}
return list;
}
/// <summary>
/// 组装焊口铭牌打印数据,材料列优先使用已反写主编码对应的材料库信息。
/// </summary>
private DataTable BuildWeldJointNameplateTable(List<Model.View_HJGL_WeldJoint> weldJointList)
{
DataTable tb = new DataTable();
// FastReport 对中文字段名兼容性不稳定,这里统一改成 ASCII 列名,模板只负责显示中文表头。
tb.Columns.Add("PipelineCode", typeof(string));
tb.Columns.Add("SegmentCode", typeof(string));
tb.Columns.Add("WeldJointNo", typeof(string));
tb.Columns.Add("MaterialText", typeof(string));
tb.Columns.Add("Spec", typeof(string));
tb.Columns.Add("DesignTemperature", typeof(string));
tb.Columns.Add("MaterialCode1", typeof(string));
tb.Columns.Add("MaterialCode2", typeof(string));
tb.Columns.Add("HeatNo1", typeof(string));
tb.Columns.Add("BatchNo1", typeof(string));
tb.Columns.Add("Material1Code", typeof(string));
tb.Columns.Add("Material2Code", typeof(string));
tb.Columns.Add("HeatNo2", typeof(string));
tb.Columns.Add("BatchNo2", typeof(string));
tb.Columns.Add("WelderCode", typeof(string));
tb.Columns.Add("WeldingDate", typeof(string));
tb.Columns.Add("WeldCheck", typeof(string));
tb.Columns.Add("CheckDate", typeof(string));
tb.Columns.Add("CleanCheck", typeof(string));
tb.Columns.Add("CleanCheckDate", typeof(string));
tb.Columns.Add("WeldJointId", typeof(string));
var jointIds = weldJointList.Select(x => x.WeldJointId).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
var pipelineIds = weldJointList.Select(x => x.PipelineId).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
var materialRows = (from x in Funs.DB.HJGL_PipeLineMat
where jointIds.Contains(x.WeldJointId) && pipelineIds.Contains(x.PipelineId)
orderby x.WeldJointId, x.Number, x.PipeLineMatId
select x).ToList();
var materialCodes = materialRows.Where(x => !string.IsNullOrEmpty(x.MaterialCode)).Select(x => x.MaterialCode).Distinct().ToList();
var materialCode2s = materialRows.Where(x => !string.IsNullOrEmpty(x.MaterialCode2)).Select(x => x.MaterialCode2).Distinct().ToList();
var libsByMaterialCode = Funs.DB.HJGL_MaterialCodeLib.Where(x => materialCodes.Contains(x.MaterialCode)).ToList().GroupBy(x => x.MaterialCode).ToDictionary(x => x.Key, x => x.First());
var libsByCode = Funs.DB.HJGL_MaterialCodeLib.Where(x => materialCode2s.Contains(x.Code)).ToList().GroupBy(x => x.Code).ToDictionary(x => x.Key, x => x.First());
foreach (var joint in weldJointList)
{
var rows = materialRows.Where(x => x.WeldJointId == joint.WeldJointId).ToList();
var row1 = rows.FirstOrDefault();
var row2 = rows.Skip(1).FirstOrDefault();
// 预制组件号按现有业务即预制组件编码显示,避免和管线号混淆。
string preCode = row1 == null ? string.Empty : row1.PrefabricatedComponents;
if (string.IsNullOrEmpty(preCode))
{
preCode = joint.TaskCode;
}
// 焊口号只显示末级编号,和焊口贴纸二维码对应的展示一致,避免带管线前缀。
string weldJointNo = joint.WeldJointCode;
if (!string.IsNullOrEmpty(weldJointNo) && weldJointNo.Contains("/"))
{
weldJointNo = weldJointNo.Substring(weldJointNo.LastIndexOf("/") + 1);
}
// 优先用已反写主编码匹配材料库;没有主编码时,用导入材料编码 Code 兜底。
HJGL_MaterialCodeLib lib1 = GetMaterialLib(row1, libsByMaterialCode, libsByCode);
HJGL_MaterialCodeLib lib2 = GetMaterialLib(row2, libsByMaterialCode, libsByCode);
DataRow dr = tb.NewRow();
dr["PipelineCode"] = joint.PipelineCode;
dr["SegmentCode"] = preCode;
dr["WeldJointNo"] = weldJointNo;
dr["MaterialText"] = string.IsNullOrEmpty(joint.Material1Code) ? joint.Material2Code : joint.Material1Code;
dr["Spec"] = joint.Specification;
dr["DesignTemperature"] = joint.PreTemperature;
dr["MaterialCode1"] = GetMaterialDisplayCode(row1, lib1);
dr["HeatNo1"] = lib1 == null ? string.Empty : lib1.HeatNo;
dr["BatchNo1"] = lib1 == null ? string.Empty : lib1.BatchNo;
dr["MaterialCode2"] = GetMaterialDisplayCode(row2, lib2);
dr["HeatNo2"] = lib2 == null ? string.Empty : lib2.HeatNo;
dr["BatchNo2"] = lib2 == null ? string.Empty : lib2.BatchNo;
dr["WelderCode"] = string.IsNullOrEmpty(joint.WelderCode) ? (string.IsNullOrEmpty(joint.BackingWelderCode) ? joint.CoverWelderCode : joint.BackingWelderCode) : joint.WelderCode;
dr["WeldingDate"] = joint.WeldingDate;
dr["WeldCheck"] = joint.CheckResult;
dr["CheckDate"] = joint.AuditDate == null ? string.Empty : joint.AuditDate.Value.ToString("yyyy-MM-dd");
dr["CleanCheck"] = joint.IsHotProessStr;
dr["CleanCheckDate"] = joint.AuditDate2 == null ? string.Empty : joint.AuditDate2.Value.ToString("yyyy-MM-dd");
dr["WeldJointId"] = joint.WeldJointId;
dr["Material1Code"] = joint.Material1Code;
dr["Material2Code"] = joint.Material2Code;
tb.Rows.Add(dr);
}
return tb;
}
/// <summary>
/// 获取材料库记录,优先按主编码,其次按导入编码。
/// </summary>
private HJGL_MaterialCodeLib GetMaterialLib(HJGL_PipeLineMat row, Dictionary<string, HJGL_MaterialCodeLib> libsByMaterialCode, Dictionary<string, HJGL_MaterialCodeLib> libsByCode)
{
if (row == null)
{
return null;
}
if (!string.IsNullOrEmpty(row.MaterialCode) && libsByMaterialCode.ContainsKey(row.MaterialCode))
{
return libsByMaterialCode[row.MaterialCode];
}
if (!string.IsNullOrEmpty(row.MaterialCode2) && libsByCode.ContainsKey(row.MaterialCode2))
{
return libsByCode[row.MaterialCode2];
}
return null;
}
/// <summary>
/// 返回打印用物料编码,优先显示导入编码。
/// </summary>
private string GetMaterialDisplayCode(HJGL_PipeLineMat row, HJGL_MaterialCodeLib lib)
{
if (row == null)
{
return string.Empty;
}
if (!string.IsNullOrEmpty(row.MaterialCode2))
{
return row.MaterialCode2;
}
if (lib != null)
{
return lib.Code;
}
return row.MaterialCode;
}
/// <summary>
/// 导出方法
/// </summary>
@@ -873,4 +1105,4 @@ namespace FineUIPro.Web.HJGL.InfoQuery
}
}
}