feat: 完善材料条码与焊接业务功能
This commit is contained in:
@@ -51,16 +51,54 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
rootNode2.Expanded = true;
|
||||
this.tvControlItem.Nodes.Add(rootNode2);
|
||||
|
||||
var pUnits = (from x in Funs.DB.Project_ProjectUnit where x.ProjectId == this.CurrUser.LoginProjectId select x).ToList();
|
||||
// 获取当前用户所在单位
|
||||
var currUnit = pUnits.FirstOrDefault(x => x.UnitId == this.CurrUser.UnitId);
|
||||
|
||||
var unitWorkList = (from x in Funs.DB.WBS_UnitWork
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& x.SuperUnitWork == null && x.UnitId != null && x.ProjectType != null
|
||||
orderby x.UnitWorkCode
|
||||
select x).ToList();
|
||||
|
||||
var unitWorkIds = unitWorkList.Select(x => x.UnitWorkId).ToList();
|
||||
var testPackages = (from x in Funs.DB.PTP_TestPackage
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& unitWorkIds.Contains(x.UnitWorkId)
|
||||
orderby x.TestPackageNo
|
||||
select x).ToList();
|
||||
var testPackageIds = testPackages.Select(x => x.PTP_ID).ToList();
|
||||
|
||||
// 试压包与管线、焊口存在跨表联动,必须批量统计,避免按单位工程和试压包逐条访问数据库。
|
||||
var pipelineCountByTestPackage = new Dictionary<string, int>();
|
||||
if (testPackageIds.Count > 0)
|
||||
{
|
||||
var pipelineQuery = from x in Funs.DB.HJGL_Pipeline
|
||||
join y in Funs.DB.PTP_PipelineList on x.PipelineId equals y.PipelineId
|
||||
where testPackageIds.Contains(y.PTP_ID)
|
||||
&& x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
|
||||
select new { y.PTP_ID, x.PipelineId };
|
||||
|
||||
if (!cbAllPipeline.Checked)
|
||||
{
|
||||
pipelineQuery = pipelineQuery.Where(x => Funs.DB.HJGL_WeldJoint.Any(y =>
|
||||
y.PipelineId == x.PipelineId && y.IsTwoJoint == true));
|
||||
}
|
||||
|
||||
pipelineCountByTestPackage = pipelineQuery.Distinct()
|
||||
.ToList()
|
||||
.GroupBy(x => x.PTP_ID)
|
||||
.ToDictionary(x => x.Key, x => x.Count());
|
||||
}
|
||||
|
||||
var unitIds = unitWorkList
|
||||
.Where(x => !string.IsNullOrEmpty(x.UnitId))
|
||||
.SelectMany(x => x.UnitId.Split(','))
|
||||
.Where(x => !string.IsNullOrEmpty(x))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var unitNameById = Funs.DB.Base_Unit
|
||||
.Where(x => unitIds.Contains(x.UnitId))
|
||||
.ToDictionary(x => x.UnitId, x => x.UnitName);
|
||||
var testPackagesByUnitWork = testPackages.ToLookup(x => x.UnitWorkId);
|
||||
|
||||
List<Model.WBS_UnitWork> unitWork1 = null;
|
||||
List<Model.WBS_UnitWork> unitWork2 = null;
|
||||
|
||||
@@ -84,16 +122,9 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
{
|
||||
foreach (var q in unitWork1)
|
||||
{
|
||||
int a = 0;
|
||||
if (cbAllPipeline.Checked)
|
||||
{
|
||||
a = GetUnitWorkTestPackagePipelineCount(q.UnitWorkId);
|
||||
}
|
||||
else
|
||||
{
|
||||
a = GetUnitWorkTestPackagePipelineCount(q.UnitWorkId);
|
||||
}
|
||||
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
|
||||
var unitTestPackages = testPackagesByUnitWork[q.UnitWorkId].ToList();
|
||||
int a = unitTestPackages.Sum(x => GetPipelineCount(pipelineCountByTestPackage, x.PTP_ID));
|
||||
var unitNamesUnitIds = GetUnitNames(q.UnitId, unitNameById);
|
||||
TreeNode tn1 = new TreeNode();
|
||||
tn1.NodeID = q.UnitWorkId;
|
||||
tn1.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
|
||||
@@ -104,7 +135,7 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
rootNode1.Nodes.Add(tn1);
|
||||
if (a > 0)
|
||||
{
|
||||
BindTestPackageNodes(tn1);
|
||||
BindTestPackageNodes(tn1, unitTestPackages, pipelineCountByTestPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,16 +143,9 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
{
|
||||
foreach (var q in unitWork2)
|
||||
{
|
||||
int a = 0;
|
||||
if (cbAllPipeline.Checked)
|
||||
{
|
||||
a = GetUnitWorkTestPackagePipelineCount(q.UnitWorkId);
|
||||
}
|
||||
else
|
||||
{
|
||||
a = GetUnitWorkTestPackagePipelineCount(q.UnitWorkId);
|
||||
}
|
||||
var unitNamesUnitIds = BLL.UnitService.getUnitNamesUnitIds(q.UnitId);
|
||||
var unitTestPackages = testPackagesByUnitWork[q.UnitWorkId].ToList();
|
||||
int a = unitTestPackages.Sum(x => GetPipelineCount(pipelineCountByTestPackage, x.PTP_ID));
|
||||
var unitNamesUnitIds = GetUnitNames(q.UnitId, unitNameById);
|
||||
TreeNode tn2 = new TreeNode();
|
||||
tn2.NodeID = q.UnitWorkId;
|
||||
tn2.Text = q.UnitWorkName + "【" + a.ToString() + "】" + "管线";
|
||||
@@ -136,11 +160,29 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
rootNode2.Nodes.Add(tn2);
|
||||
if (a > 0)
|
||||
{
|
||||
BindTestPackageNodes(tn2);
|
||||
BindTestPackageNodes(tn2, unitTestPackages, pipelineCountByTestPackage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetPipelineCount(IDictionary<string, int> pipelineCountByTestPackage, string testPackageId)
|
||||
{
|
||||
int count;
|
||||
return pipelineCountByTestPackage.TryGetValue(testPackageId, out count) ? count : 0;
|
||||
}
|
||||
|
||||
private static string GetUnitNames(string unitIds, IDictionary<string, string> unitNameById)
|
||||
{
|
||||
if (string.IsNullOrEmpty(unitIds))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return string.Join(",", unitIds.Split(',')
|
||||
.Where(x => unitNameById.ContainsKey(x))
|
||||
.Select(x => unitNameById[x]));
|
||||
}
|
||||
#endregion
|
||||
private void BindNodes(TreeNode node)
|
||||
{
|
||||
@@ -214,27 +256,14 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
}
|
||||
}
|
||||
|
||||
private int GetUnitWorkTestPackagePipelineCount(string unitWorkId)
|
||||
private void BindTestPackageNodes(
|
||||
TreeNode unitWorkNode,
|
||||
IEnumerable<Model.PTP_TestPackage> testPackages,
|
||||
IDictionary<string, int> pipelineCountByTestPackage)
|
||||
{
|
||||
var testPackages = (from x in Funs.DB.PTP_TestPackage
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& x.UnitWorkId == unitWorkId
|
||||
select x.PTP_ID).ToList();
|
||||
|
||||
return testPackages.Select(x => GetTestPackagePipelineList(x).Count()).Sum();
|
||||
}
|
||||
|
||||
private void BindTestPackageNodes(TreeNode unitWorkNode)
|
||||
{
|
||||
var testPackages = (from x in Funs.DB.PTP_TestPackage
|
||||
where x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& x.UnitWorkId == unitWorkNode.NodeID
|
||||
orderby x.TestPackageNo
|
||||
select x).ToList();
|
||||
|
||||
foreach (var item in testPackages)
|
||||
{
|
||||
int pipelineCount = GetTestPackagePipelineList(item.PTP_ID).Count();
|
||||
int pipelineCount = GetPipelineCount(pipelineCountByTestPackage, item.PTP_ID);
|
||||
if (pipelineCount == 0)
|
||||
{
|
||||
continue;
|
||||
@@ -257,20 +286,21 @@ namespace FineUIPro.Web.HJGL.WeldingManage
|
||||
|
||||
private List<Model.HJGL_Pipeline> GetTestPackagePipelineList(string ptpId)
|
||||
{
|
||||
var pipeline = (from x in Funs.DB.HJGL_Pipeline
|
||||
join y in Funs.DB.PTP_PipelineList on x.PipelineId equals y.PipelineId
|
||||
where y.PTP_ID == ptpId
|
||||
&& x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
|
||||
orderby x.PipelineCode
|
||||
select x).Distinct().ToList();
|
||||
var pipelineQuery = (from x in Funs.DB.HJGL_Pipeline
|
||||
join y in Funs.DB.PTP_PipelineList on x.PipelineId equals y.PipelineId
|
||||
where y.PTP_ID == ptpId
|
||||
&& x.ProjectId == this.CurrUser.LoginProjectId
|
||||
&& x.PipelineCode.Contains(this.txtPipelineCode.Text.Trim())
|
||||
orderby x.PipelineCode
|
||||
select x).Distinct();
|
||||
|
||||
if (!cbAllPipeline.Checked)
|
||||
{
|
||||
pipeline = pipeline.Where(x => (from y in Funs.DB.HJGL_WeldJoint where y.PipelineId == x.PipelineId && y.IsTwoJoint == true select y).Count() > 0).ToList();
|
||||
pipelineQuery = pipelineQuery.Where(x => Funs.DB.HJGL_WeldJoint.Any(y =>
|
||||
y.PipelineId == x.PipelineId && y.IsTwoJoint == true));
|
||||
}
|
||||
|
||||
return pipeline;
|
||||
return pipelineQuery.ToList();
|
||||
}
|
||||
|
||||
#region 点击TreeView
|
||||
|
||||
Reference in New Issue
Block a user