feat(hjgl): 完善管线预制与焊接业务
同步管线组件、材料和焊口关联数据,优化预制组件打印及焊接相关查询,减少业务台账与实际关联信息不一致。
This commit is contained in:
@@ -194,9 +194,6 @@ namespace BLL
|
||||
from aunit in aunitJoin.DefaultIfEmpty()
|
||||
join unitwork in db.WBS_UnitWork on pipe.UnitWorkId equals unitwork.UnitWorkId into unitworkJoin
|
||||
from unitwork in unitworkJoin.DefaultIfEmpty()
|
||||
join mater in db.Base_Material on pipe.MaterialId equals mater.MaterialId into materJoin
|
||||
from mater in materJoin.DefaultIfEmpty()
|
||||
where com.QRCode != ""
|
||||
orderby com.PipelineComponentCode, com.PipelineId
|
||||
select new PipelineComponentPrintDto
|
||||
{
|
||||
@@ -208,13 +205,10 @@ namespace BLL
|
||||
PreUnit = punit.UnitName,
|
||||
AssembleUnit = aunit.UnitName,
|
||||
PrefabricatedComponents = mat.PrefabricatedComponents,
|
||||
QRCode = com.QRCode,
|
||||
State = com.State,
|
||||
PlanStartDate = string.Format("yyyy-MM-dd", pipe.PlanStartDate),
|
||||
PipelineCode = pipe.PipelineCode,
|
||||
FlowingSection = pipe.FlowingSection,
|
||||
QRCode2 = "PrePipeline$" + com.PipelineComponentId,
|
||||
MaterialCode = mater.MaterialCode,
|
||||
IsPrint = com.IsPrint
|
||||
};
|
||||
|
||||
@@ -278,14 +272,15 @@ namespace BLL
|
||||
return;
|
||||
}
|
||||
|
||||
var model_mat = BLL.PipelineMatService.GetPipeLineMat(pipeLineMatId);
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
var model_mat = db.HJGL_PipeLineMat.FirstOrDefault(x => x.PipeLineMatId == pipeLineMatId);
|
||||
if (model_mat == null || string.IsNullOrEmpty(model_mat.PipelineId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var PipelineId = model_mat.PipelineId;
|
||||
var pipelineModel = BLL.PipelineService.GetPipelineByPipelineId(PipelineId);
|
||||
var pipelineModel = db.HJGL_Pipeline.FirstOrDefault(x => x.PipelineId == PipelineId);
|
||||
if (pipelineModel == null)
|
||||
{
|
||||
return;
|
||||
@@ -294,37 +289,64 @@ namespace BLL
|
||||
var PipeArea = pipelineModel.PipeArea;
|
||||
if (PipeArea == PipelineService.PipeArea_SHOP && !string.IsNullOrEmpty(model_mat.PrefabricatedComponents))
|
||||
{
|
||||
// var model = GetPipelineComponentByMatId(pipeLineMatId);
|
||||
var model = GetPipelineComponentByCodeandpipelineId(model_mat.PrefabricatedComponents, PipelineId);
|
||||
var model = db.HJGL_Pipeline_Component.FirstOrDefault(x => x.PipelineComponentCode == model_mat.PrefabricatedComponents
|
||||
&& x.PipelineId == PipelineId);
|
||||
// 组件号可能来自导入数据,未包含分隔符时直接使用原值,避免截取时报错。
|
||||
var drawingName = GetDrawingNameByComponentCode(model_mat.PrefabricatedComponents);
|
||||
if (model != null)
|
||||
if (model == null)
|
||||
{
|
||||
model.PipelineId = PipelineId;
|
||||
model.PipelineComponentCode = model_mat.PrefabricatedComponents;
|
||||
model.DrawingName = drawingName;
|
||||
model.State = State0;
|
||||
model.ProductionState = 0;
|
||||
UpdatePipelineComponent(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new Model.HJGL_Pipeline_Component();
|
||||
model.PipelineComponentId = SQLHelper.GetNewID();
|
||||
model.PipelineId = PipelineId;
|
||||
model.PipelineComponentCode = model_mat.PrefabricatedComponents;
|
||||
model.DrawingName = drawingName;
|
||||
model.State = State0;
|
||||
model.ProductionState = 0;
|
||||
model.IsPrint = false;
|
||||
AddPipelineComponent(model);
|
||||
model = new Model.HJGL_Pipeline_Component
|
||||
{
|
||||
PipelineComponentId = SQLHelper.GetNewID(),
|
||||
IsPrint = false
|
||||
};
|
||||
db.HJGL_Pipeline_Component.InsertOnSubmit(model);
|
||||
}
|
||||
|
||||
model.PipelineId = PipelineId;
|
||||
model.PipelineComponentCode = model_mat.PrefabricatedComponents;
|
||||
model.DrawingName = drawingName;
|
||||
model.State = State0;
|
||||
model.ProductionState = 0;
|
||||
|
||||
// 材料导入同步组件时,同时按焊口幂等维护组件关联,避免只生成组件主数据。
|
||||
SyncPipelineComponentJoint(db, model, model_mat.WeldJointId);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 按焊口同步预制组件关联。
|
||||
/// </summary>
|
||||
private static void SyncPipelineComponentJoint(Model.SGGLDB db, Model.HJGL_Pipeline_Component pipelineComponent, string weldJointId)
|
||||
{
|
||||
if (pipelineComponent == null || string.IsNullOrEmpty(weldJointId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var weldJoint = db.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId);
|
||||
if (weldJoint == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var componentJoint = db.HJGL_Pipeline_ComponentJoint.FirstOrDefault(x => x.WeldJointId == weldJointId);
|
||||
if (componentJoint == null)
|
||||
{
|
||||
componentJoint = new Model.HJGL_Pipeline_ComponentJoint
|
||||
{
|
||||
Id = SQLHelper.GetNewID(),
|
||||
WeldJointId = weldJoint.WeldJointId,
|
||||
State = State0
|
||||
};
|
||||
db.HJGL_Pipeline_ComponentJoint.InsertOnSubmit(componentJoint);
|
||||
}
|
||||
|
||||
|
||||
// 已存在的关联保留生产状态,只刷新组件及焊口标识。
|
||||
componentJoint.PipelineComponentId = pipelineComponent.PipelineComponentId;
|
||||
componentJoint.PipelineComponentCode = pipelineComponent.PipelineComponentCode;
|
||||
componentJoint.WeldJointCode = weldJoint.WeldJointCode;
|
||||
}
|
||||
|
||||
private static string GetDrawingNameByComponentCode(string pipelineComponentCode)
|
||||
@@ -371,6 +393,53 @@ namespace BLL
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改管线预制组件基础信息,并同步材料及焊口关联中的组件编号。
|
||||
/// </summary>
|
||||
public static void UpdatePipelineComponentBasicInfo(Model.HJGL_Pipeline_Component pipeline)
|
||||
{
|
||||
if (pipeline == null || string.IsNullOrEmpty(pipeline.PipelineComponentId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
var current = db.HJGL_Pipeline_Component.FirstOrDefault(e => e.PipelineComponentId == pipeline.PipelineComponentId);
|
||||
if (current == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string oldPipelineComponentCode = current.PipelineComponentCode;
|
||||
current.PipelineId = pipeline.PipelineId;
|
||||
current.PreUnit = pipeline.PreUnit;
|
||||
current.AssembleUnit = pipeline.AssembleUnit;
|
||||
current.PipelineComponentCode = pipeline.PipelineComponentCode;
|
||||
current.BoxNumber = pipeline.BoxNumber;
|
||||
|
||||
if (!string.Equals(oldPipelineComponentCode, pipeline.PipelineComponentCode, StringComparison.Ordinal))
|
||||
{
|
||||
// 组件编号是材料和组件焊口关联的逻辑键,编辑时必须同步更新。
|
||||
if (!string.IsNullOrEmpty(oldPipelineComponentCode))
|
||||
{
|
||||
var pipelineMaterials = db.HJGL_PipeLineMat.Where(x => x.PipelineId == current.PipelineId
|
||||
&& x.PrefabricatedComponents == oldPipelineComponentCode);
|
||||
foreach (var pipelineMaterial in pipelineMaterials)
|
||||
{
|
||||
pipelineMaterial.PrefabricatedComponents = pipeline.PipelineComponentCode;
|
||||
}
|
||||
}
|
||||
|
||||
var componentJoints = db.HJGL_Pipeline_ComponentJoint.Where(x => x.PipelineComponentId == current.PipelineComponentId);
|
||||
foreach (var componentJoint in componentJoints)
|
||||
{
|
||||
componentJoint.PipelineComponentCode = pipeline.PipelineComponentCode;
|
||||
}
|
||||
}
|
||||
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改管线预制组件
|
||||
/// </summary>
|
||||
@@ -507,10 +576,14 @@ namespace BLL
|
||||
public static void DeletePipelineComponentBypipelineId(string pipelineId)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
var mdoel = db.HJGL_Pipeline_Component.Where(e => e.PipelineId == pipelineId);
|
||||
if (mdoel != null)
|
||||
var components = db.HJGL_Pipeline_Component.Where(e => e.PipelineId == pipelineId).ToList();
|
||||
if (components.Count > 0)
|
||||
{
|
||||
db.HJGL_Pipeline_Component.DeleteAllOnSubmit(mdoel);
|
||||
// 更新导入会重建管线组件,先清理旧组件焊口关联,避免遗留孤儿数据。
|
||||
var componentIds = components.Select(x => x.PipelineComponentId).ToArray();
|
||||
var componentJoints = db.HJGL_Pipeline_ComponentJoint.Where(x => componentIds.Contains(x.PipelineComponentId));
|
||||
db.HJGL_Pipeline_ComponentJoint.DeleteAllOnSubmit(componentJoints);
|
||||
db.HJGL_Pipeline_Component.DeleteAllOnSubmit(components);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,42 @@ namespace BLL
|
||||
|
||||
public static class PipelineMatService
|
||||
{
|
||||
/// <summary>
|
||||
/// 按焊口编号顺序,先左后右校准零数量材料的主编码。
|
||||
/// </summary>
|
||||
public static int CalibrateSharedMaterialCodes(string pipelineId)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
var materials = db.HJGL_PipeLineMat.Where(x => x.PipelineId == pipelineId).ToList();
|
||||
var joints = db.HJGL_WeldJoint.Where(x => x.PipelineId == pipelineId)
|
||||
.OrderBy(x => x.WeldJointCode).ToList();
|
||||
int count = 0;
|
||||
|
||||
foreach (var material in materials.Where(x => x.Number == 0m))
|
||||
{
|
||||
int jointIndex = joints.FindIndex(x => x.WeldJointId == material.WeldJointId);
|
||||
HJGL_PipeLineMat source = null;
|
||||
if (jointIndex > 0)
|
||||
{
|
||||
source = materials.FirstOrDefault(x => x.WeldJointId == joints[jointIndex - 1].WeldJointId
|
||||
&& x.MaterialCode2 == material.MaterialCode2 && x.MaterialCode != null);
|
||||
}
|
||||
if (source == null && jointIndex < joints.Count - 1)
|
||||
{
|
||||
source = materials.FirstOrDefault(x => x.WeldJointId == joints[jointIndex + 1].WeldJointId
|
||||
&& x.MaterialCode2 == material.MaterialCode2 && x.MaterialCode != null);
|
||||
}
|
||||
if (source != null)
|
||||
{
|
||||
material.MaterialCode = source.MaterialCode;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
db.SubmitChanges();
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///获取管线材料信息
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user