feat(hjgl): 支持按焊口匹配和回写管线材料

管线材料导入需要关联到具体焊口,并允许按材料编码匹配库存后回写
材料主编码。新增 HJGL_PipeLineMat 的焊口和材料编码字段,材料匹配、
任务生成和出库关系同步按焊口维度处理,避免仅按组件匹配导致材料
范围不准确。
This commit is contained in:
2026-06-11 10:39:58 +08:00
parent c48972cc60
commit 201443e437
15 changed files with 488 additions and 206 deletions
+88 -33
View File
@@ -94,14 +94,14 @@ namespace BLL
/// <param name="warehouseCode"></param>
/// <param name="projectId"></param>
/// <returns></returns>
public static List<Tw_PipeMatMatchOutput> GetMatMatchOutput(List<Tw_PipeMatMatchOutput> requiredMaterials, string warehouseCode, string projectId)
public static List<Tw_PipeMatMatchOutput> GetMatMatchOutput(List<Tw_PipeMatMatchOutput> requiredMaterials, string warehouseCode, string projectId, bool matchByMaterialCodeLibCode = false)
{
Tw_MaterialStockOutput twMaterialStockOutput = new Tw_MaterialStockOutput
{
WarehouseCode = warehouseCode,
ProjectId = projectId
};
var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(twMaterialStockOutput).ToList();//获取库存列表
var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(twMaterialStockOutput).ToList();//获取库存列表
// 预扣除出库申请单中状态为待审核/已审核的材料数量
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
@@ -133,7 +133,14 @@ var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(twMaterialStoc
foreach (var material in requiredMaterials)
{
material.Id = Guid.NewGuid().ToString();
var thisMaterialStockNum = stockList.FirstOrDefault(x => x.PipeLineMatCode == material.MaterialCode)?.StockNum ?? 0;
var stock = matchByMaterialCodeLibCode
? stockList
.Where(x => x.Code == material.MaterialCode && (x.StockNum ?? 0) > 0)
.OrderByDescending(x => (x.StockNum ?? 0) >= (material.NeedNum ?? 0))
.ThenBy(x => x.PipeLineMatCode)
.FirstOrDefault()
: stockList.FirstOrDefault(x => x.PipeLineMatCode == material.MaterialCode);
var thisMaterialStockNum = stock?.StockNum ?? 0;
if (thisMaterialStockNum >= material.NeedNum)
{
material.MatchNum = material.NeedNum;
@@ -147,8 +154,8 @@ var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(twMaterialStoc
material.MatchRateString = Math.Round((decimal)(material.MatchRate ?? 0) * 100, 2).ToString() + "%";
}
material.MatchMaterialCode = stock?.PipeLineMatCode;
//修改stockList对应的库存数量
var stock = stockList.FirstOrDefault(x => x.PipeLineMatCode == material.MaterialCode);
if (stock != null)
{
stock.StockNum -= material.MatchNum;
@@ -246,56 +253,104 @@ var stockList = TwMaterialstockService.GetTw_MaterialStockByModle(twMaterialStoc
/// <param name="pipelineIds"></param>
/// <param name="warehouseCode"></param>
/// <returns></returns>
public static List<Tw_PipeMatMatchOutput> GetPipeMatMatch(string projectId, List<string> pipelineIds, string warehouseCode, Dictionary<string, List<string>> priorityComponents = null)
public static List<Tw_PipeMatMatchOutput> GetPipeMatMatch(string projectId, List<string> pipelineIds, string warehouseCode, Dictionary<string, List<string>> priorityWeldJoints = null)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var results = new List<Tw_PipeMatMatchOutput>();
// 获取所需材料列表
var requiredMaterials = (from x in db.HJGL_PipeLineMat
join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
var pipeLineMats = (from x in db.HJGL_PipeLineMat
join z in db.HJGL_Pipeline on x.PipelineId equals z.PipelineId
join m in db.WBS_UnitWork on z.UnitWorkId equals m.UnitWorkId
where z.ProjectId == projectId && pipelineIds.Contains(z.PipelineId) && x.PrefabricatedComponents != "" //x.PrefabricatedComponents!="" 用于筛选非散件材料
select new Tw_PipeMatMatchOutput
{
Id = Guid.NewGuid().ToString(),
PipelineId = x.PipelineId,
PipelineCode = z.PipelineCode,
UnitWorkId = z.UnitWorkId,
UnitWorkName = m.UnitWorkName,
PrefabricatedComponents = x.PrefabricatedComponents,
MaterialCode = x.MaterialCode,
Code = y.Code,
HeatNo = y.HeatNo,
BatchNo = y.BatchNo,
MaterialName = y.MaterialName,
MaterialSpec = y.MaterialSpec,
MaterialUnit = y.MaterialUnit,
MaterialDef = y.MaterialDef,
NeedNum = x.Number,
}
).ToList();
join w in db.HJGL_WeldJoint on x.WeldJointId equals w.WeldJointId into weldJoin
from w in weldJoin.DefaultIfEmpty()
where z.ProjectId == projectId && pipelineIds.Contains(z.PipelineId) && x.PrefabricatedComponents != "" //x.PrefabricatedComponents!="" 用于筛选非散件材料
select new
{
PipeLineMat = x,
PipelineCode = z.PipelineCode,
UnitWorkId = z.UnitWorkId,
UnitWorkName = m.UnitWorkName,
WeldJointCode = w == null ? null : w.WeldJointCode
}).ToList();
var materialCodes = pipeLineMats
.Where(x => !string.IsNullOrEmpty(x.PipeLineMat.MaterialCode))
.Select(x => x.PipeLineMat.MaterialCode)
.Distinct()
.ToList();
var materialCode2s = pipeLineMats
.Where(x => !string.IsNullOrEmpty(x.PipeLineMat.MaterialCode2))
.Select(x => x.PipeLineMat.MaterialCode2)
.Distinct()
.ToList();
var libByMaterialCode = db.HJGL_MaterialCodeLib
.Where(x => materialCodes.Contains(x.MaterialCode))
.ToList()
.GroupBy(x => x.MaterialCode)
.ToDictionary(x => x.Key, x => x.First());
var libByCode = db.HJGL_MaterialCodeLib
.Where(x => materialCode2s.Contains(x.Code))
.ToList()
.GroupBy(x => x.Code)
.ToDictionary(x => x.Key, x => x.First());
var requiredMaterials = pipeLineMats.Select(x =>
{
HJGL_MaterialCodeLib lib = null;
if (!string.IsNullOrEmpty(x.PipeLineMat.MaterialCode) && libByMaterialCode.ContainsKey(x.PipeLineMat.MaterialCode))
{
lib = libByMaterialCode[x.PipeLineMat.MaterialCode];
}
else if (!string.IsNullOrEmpty(x.PipeLineMat.MaterialCode2) && libByCode.ContainsKey(x.PipeLineMat.MaterialCode2))
{
lib = libByCode[x.PipeLineMat.MaterialCode2];
}
string code = !string.IsNullOrEmpty(x.PipeLineMat.MaterialCode2) ? x.PipeLineMat.MaterialCode2 : lib?.Code;
return new Tw_PipeMatMatchOutput
{
Id = Guid.NewGuid().ToString(),
PipeLineMatId = x.PipeLineMat.PipeLineMatId,
PipelineId = x.PipeLineMat.PipelineId,
PipelineCode = x.PipelineCode,
UnitWorkId = x.UnitWorkId,
UnitWorkName = x.UnitWorkName,
PrefabricatedComponents = x.PipeLineMat.PrefabricatedComponents,
WeldJointId = x.PipeLineMat.WeldJointId,
WeldJointCode = x.WeldJointCode,
MaterialCode = code,
MatchMaterialCode = x.PipeLineMat.MaterialCode,
Code = code,
HeatNo = lib?.HeatNo,
BatchNo = lib?.BatchNo,
MaterialName = lib?.MaterialName,
MaterialSpec = lib?.MaterialSpec,
MaterialUnit = lib?.MaterialUnit,
MaterialDef = lib?.MaterialDef,
NeedNum = x.PipeLineMat.Number,
};
}).ToList();
var newRequiredMaterials = new List<Tw_PipeMatMatchOutput>();
foreach (string id in pipelineIds)
{
var pipelineMaterials = requiredMaterials.Where(x => x.PipelineId == id).ToList();
if (priorityComponents != null && priorityComponents.ContainsKey(id) && priorityComponents[id] != null && priorityComponents[id].Any())
if (priorityWeldJoints != null && priorityWeldJoints.ContainsKey(id) && priorityWeldJoints[id] != null && priorityWeldJoints[id].Any())
{
var components = priorityComponents[id];
var weldJointIds = priorityWeldJoints[id];
newRequiredMaterials.AddRange(pipelineMaterials
.Where(x => components.Contains(x.PrefabricatedComponents))
.OrderBy(x => components.IndexOf(x.PrefabricatedComponents)));
.Where(x => weldJointIds.Contains(x.WeldJointId))
.OrderBy(x => weldJointIds.IndexOf(x.WeldJointId)));
newRequiredMaterials.AddRange(pipelineMaterials
.Where(x => !components.Contains(x.PrefabricatedComponents)));
.Where(x => !weldJointIds.Contains(x.WeldJointId)));
}
else
{
newRequiredMaterials.AddRange(pipelineMaterials);
}
}
results = GetMatMatchOutput(newRequiredMaterials, warehouseCode, projectId);
results = GetMatMatchOutput(newRequiredMaterials, warehouseCode, projectId, true);
return results;
}
}
@@ -102,6 +102,7 @@ namespace BLL
MaterialCode = newtable.MaterialCode,
PrefabricatedComponents = newtable.PrefabricatedComponents,
Number = newtable.Number,
WeldJointId = newtable.WeldJointId,
};
Funs.DB.Tw_InOutPlanDetail_Relation.InsertOnSubmit(table);
Funs.DB.SubmitChanges();
@@ -133,6 +134,7 @@ namespace BLL
table.MaterialCode = newtable.MaterialCode;
table.PrefabricatedComponents = newtable.PrefabricatedComponents;
table.Number = newtable.Number;
table.WeldJointId = newtable.WeldJointId;
Funs.DB.SubmitChanges();
}
@@ -158,56 +160,6 @@ namespace BLL
}
}
public static void InsertByPipeLineMat(string inOutPlanMasterId, List<Model.Tw_PipeLineMat> tw_PipeLineMats)
{
var master = TwInOutplanmasterService.GetById(inOutPlanMasterId);
if (master == null)
{
return;
}
var outMateriaList = from x in tw_PipeLineMats
group x by new { x.MaterialCode, x.MaterialUnit }
into g
select new
{
g.Key.MaterialCode,
planNum = g.Sum(x => x.Number) ?? 0,
MaterialName = g.Key.MaterialUnit,
};
switch (master.Category)
{
case (int)TwConst.Category.:
outMateriaList.Where(x => x.MaterialName.Contains("米"));//管段
break;
case (int)TwConst.Category.:
outMateriaList.Where(x => x.MaterialName.Contains("个"));//管件
break;
}
foreach (var item in outMateriaList)
{
Model.Tw_InOutPlanDetail detail = new Model.Tw_InOutPlanDetail
{
Id = Guid.NewGuid().ToString(),
InOutPlanMasterId = inOutPlanMasterId,
MaterialCode = item.MaterialCode,
PlanNum = item.planNum,
};
TwInOutplandetailService.Add(detail);
}
var twinoutplandetailRelationList = tw_PipeLineMats.Select(x => new Tw_InOutPlanDetail_Relation
{
PipelineId = x.PipelineId,
MaterialCode = x.MaterialCode,
Number = x.Number,
PrefabricatedComponents = x.PrefabricatedComponents,
}).ToList();
TwInoutplandetailRelationService.AddList(twinoutplandetailRelationList, inOutPlanMasterId);
}
public static IEnumerable GetPrintListByOutputMasterIds(List<string> outputMasterIds)
{
var q = from x in Funs.DB.Tw_InOutPlanDetail_Relation
+9 -21
View File
@@ -992,36 +992,22 @@ namespace BLL
.Select(e => e.WeldJointId)
.Distinct()
.ToList();
var taskComponents = (from relation in db.HJGL_Pipeline_ComponentJoint
join component in db.HJGL_Pipeline_Component on relation.PipelineComponentId equals component.PipelineComponentId into componentJoin
from componentItem in componentJoin.DefaultIfEmpty()
join weldJointItem in db.HJGL_WeldJoint on relation.WeldJointId equals weldJointItem.WeldJointId
where taskWeldJointIds.Contains(relation.WeldJointId)
&& weldJointItem.PipelineId != null
&& (relation.PipelineComponentCode != null || (componentItem != null && componentItem.PipelineComponentCode != null))
select new
{
PipelineId = weldJointItem.PipelineId,
PipelineComponentCode = componentItem != null && componentItem.PipelineComponentCode != null ? componentItem.PipelineComponentCode : relation.PipelineComponentCode
}).Distinct().ToList();
//领料出库需要排除散件材料
var allMaterDatial = (from x in db.HJGL_PipeLineMat
join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
where pipelineList.Contains(x.PipelineId) && x.PrefabricatedComponents != null
where pipelineList.Contains(x.PipelineId)
&& taskWeldJointIds.Contains(x.WeldJointId)
&& x.PrefabricatedComponents != null
select new
{
x.PipelineId,
x.PrefabricatedComponents,
x.WeldJointId,
x.MaterialCode,
x.Number,
y.MaterialUnit,
}).ToList();
var componentPipelineIds = taskComponents.Select(x => x.PipelineId).Distinct().ToList();
var MaterDatial = taskComponents.Any()
? allMaterDatial.Where(mat => !componentPipelineIds.Contains(mat.PipelineId)
|| taskComponents.Any(component => component.PipelineId == mat.PipelineId
&& component.PipelineComponentCode == mat.PrefabricatedComponents)).ToList()
: allMaterDatial;
var MaterDatial = allMaterDatial;
//var outMateriaList = from x in db.HJGL_PipeLineMat
// join y in db.HJGL_MaterialCodeLib on x.MaterialCode equals y.MaterialCode
// where pipelineList.Contains(x.PipelineId)
@@ -1077,12 +1063,13 @@ namespace BLL
};
TwInOutplandetailService.Add(detail);
}
var twinoutplandetailRelationList = MaterDatial.Select(x => new Tw_InOutPlanDetail_Relation
var twinoutplandetailRelationList = MaterDatial.Where(x => x.MaterialUnit.Contains("个")).Select(x => new Tw_InOutPlanDetail_Relation
{
PipelineId = x.PipelineId,
MaterialCode = x.MaterialCode,
Number = x.Number,
PrefabricatedComponents = x.PrefabricatedComponents,
WeldJointId = x.WeldJointId,
}).ToList();
TwInoutplandetailRelationService.AddList(twinoutplandetailRelationList, table.Id);
}
@@ -1116,12 +1103,13 @@ namespace BLL
};
TwInOutplandetailService.Add(detail);
}
var twinoutplandetailRelationList = MaterDatial.Select(x => new Tw_InOutPlanDetail_Relation
var twinoutplandetailRelationList = MaterDatial.Where(x => x.MaterialUnit.Contains("米")).Select(x => new Tw_InOutPlanDetail_Relation
{
PipelineId = x.PipelineId,
MaterialCode = x.MaterialCode,
Number = x.Number,
PrefabricatedComponents = x.PrefabricatedComponents,
WeldJointId = x.WeldJointId,
}).ToList();
TwInoutplandetailRelationService.AddList(twinoutplandetailRelationList, table.Id);
}