using Model; using System; using System.Collections.Generic; using System.Linq; using System.Web.UI.WebControls; namespace BLL { public partial class TestPackageEditService { public enum State : int { 试压前条件未确认 = 0, 试压前条件已确认 = 1, 尾项检查待整改 = 2, 尾项检查已整改 = 3, 试压包已完成 = 4, } public static Dictionary StateMap = new Dictionary() { { 0, State.试压前条件未确认.ToString()}, { 1, State.试压前条件已确认.ToString()}, { 2, State.尾项检查待整改.ToString()}, { 3, State.尾项检查已整改.ToString()}, { 4, State.试压包已完成.ToString()}, }; /// /// 根据试压Id获取用于试压信息 /// /// /// public static Model.PTP_TestPackage GetTestPackageByID(string PTP_ID) { var view = Funs.DB.PTP_TestPackage.FirstOrDefault(e => e.PTP_ID == PTP_ID); return view; } /// /// 根据试压Id获取用于管线明细信息 /// /// /// public static List GetPipeLineListByPTP_ID(string PTP_ID) { Model.SGGLDB db = Funs.DB; var view = from x in db.HJGL_Pipeline join y in db.PTP_PipelineList on x.PipelineId equals y.PipelineId where y.PTP_ID == PTP_ID select x; return view.ToList(); } /// /// 增加试压信息 /// /// 试压实体 public static void AddTestPackage(Model.PTP_TestPackage testPackage) { Model.SGGLDB db = Funs.DB; Model.PTP_TestPackage newTestPackage = new Model.PTP_TestPackage(); newTestPackage.PTP_ID = testPackage.PTP_ID; newTestPackage.UnitWorkId = testPackage.UnitWorkId; newTestPackage.UnitId = testPackage.UnitId; newTestPackage.TestPackageNo = testPackage.TestPackageNo; newTestPackage.TestPackageName = testPackage.TestPackageName; newTestPackage.Finisher = testPackage.Finisher; newTestPackage.FinishDate = testPackage.FinishDate; newTestPackage.Tabler = testPackage.Tabler; newTestPackage.TableDate = testPackage.TableDate; newTestPackage.Auditer = testPackage.Auditer; newTestPackage.AduditDate = testPackage.AduditDate; newTestPackage.Remark = testPackage.Remark; newTestPackage.ProjectId = testPackage.ProjectId; newTestPackage.AdjustTestPressure = testPackage.AdjustTestPressure; newTestPackage.Check1 = testPackage.Check1; newTestPackage.Check2 = testPackage.Check2; newTestPackage.Check3 = testPackage.Check3; newTestPackage.Check4 = testPackage.Check4; newTestPackage.Check5 = testPackage.Check5; newTestPackage.Check6 = testPackage.Check6; newTestPackage.Check7 = testPackage.Check7; newTestPackage.Check8 = testPackage.Check8; newTestPackage.Check9 = testPackage.Check9; newTestPackage.Check10 = testPackage.Check10; newTestPackage.Check11 = testPackage.Check11; newTestPackage.Check12 = testPackage.Check12; db.PTP_TestPackage.InsertOnSubmit(newTestPackage); db.SubmitChanges(); } /// /// 修改试压信息 /// /// 试压实体 public static void UpdateTestPackage(Model.PTP_TestPackage testPackage) { Model.SGGLDB db = Funs.DB; Model.PTP_TestPackage newTestPackage = db.PTP_TestPackage.First(e => e.PTP_ID == testPackage.PTP_ID); newTestPackage.UnitId = testPackage.UnitId; newTestPackage.UnitWorkId = testPackage.UnitWorkId; newTestPackage.TestPackageNo = testPackage.TestPackageNo; newTestPackage.TestPackageName = testPackage.TestPackageName; newTestPackage.Finisher = testPackage.Finisher; newTestPackage.FinishDate = testPackage.FinishDate; newTestPackage.Tabler = testPackage.Tabler; newTestPackage.TableDate = testPackage.TableDate; newTestPackage.Auditer = testPackage.Auditer; newTestPackage.AduditDate = testPackage.AduditDate; newTestPackage.Remark = testPackage.Remark; newTestPackage.AdjustTestPressure = testPackage.AdjustTestPressure; newTestPackage.ProjectId = testPackage.ProjectId; newTestPackage.Check1 = testPackage.Check1; newTestPackage.Check2 = testPackage.Check2; newTestPackage.Check3 = testPackage.Check3; newTestPackage.Check4 = testPackage.Check4; newTestPackage.Check5 = testPackage.Check5; newTestPackage.Check6 = testPackage.Check6; newTestPackage.Check7 = testPackage.Check7; newTestPackage.Check8 = testPackage.Check8; newTestPackage.Check9 = testPackage.Check9; newTestPackage.Check10 = testPackage.Check10; newTestPackage.Check11 = testPackage.Check11; newTestPackage.Check12 = testPackage.Check12; newTestPackage.TestMediumTemperature = testPackage.TestMediumTemperature; newTestPackage.AmbientTemperature = testPackage.AmbientTemperature; newTestPackage.HoldingTime = testPackage.HoldingTime; newTestPackage.State = testPackage.State; newTestPackage.TestDate = testPackage.TestDate; db.SubmitChanges(); } /// /// 根据主键删除试压信息 /// /// 试压主键 public static void DeleteTestPackage(string testPackageID) { Model.SGGLDB db = Funs.DB; Model.PTP_TestPackage testPackage = db.PTP_TestPackage.First(e => e.PTP_ID == testPackageID); var itemEndCheckLists = from x in db.PTP_ItemEndCheckList where x.PTP_ID == testPackageID select x; foreach (var item in itemEndCheckLists) { var ItemCheck = from x in db.PTP_ItemEndCheck where x.ItemEndCheckListId == item.ItemEndCheckListId select x; if (ItemCheck != null) { db.PTP_ItemEndCheck.DeleteAllOnSubmit(ItemCheck); db.SubmitChanges(); } var Approve = from x in db.PTP_TestPackageApprove where x.ItemEndCheckListId == item.ItemEndCheckListId select x; if (Approve != null) { db.PTP_TestPackageApprove.DeleteAllOnSubmit(Approve); db.SubmitChanges(); } } db.PTP_TestPackage.DeleteOnSubmit(testPackage); db.SubmitChanges(); } /// /// 根据主键删除试压信息明细 /// /// 试压主键 public static void DeletePipelineListByPTP_ID(string testPackageID) { Model.SGGLDB db = Funs.DB; var testPackage = from x in db.PTP_PipelineList where x.PTP_ID == testPackageID select x; if (testPackage != null) { db.PTP_PipelineList.DeleteAllOnSubmit(testPackage); db.SubmitChanges(); } } /// /// 增加试压信息明细 /// /// 试压明细实体 public static void AddPipelineList(Model.PTP_PipelineList IsoList) { Model.SGGLDB db = Funs.DB; Model.PTP_PipelineList newPipelineList = new Model.PTP_PipelineList(); newPipelineList.PT_PipeId = SQLHelper.GetNewID(typeof(Model.PTP_PipelineList)); newPipelineList.PTP_ID = IsoList.PTP_ID; newPipelineList.PipelineId = IsoList.PipelineId; newPipelineList.PT_DataType = IsoList.PT_DataType; newPipelineList.DesignPress = IsoList.DesignPress; newPipelineList.DesignTemperature = IsoList.DesignTemperature; newPipelineList.AmbientTemperature = IsoList.AmbientTemperature; newPipelineList.TestMedium = IsoList.TestMedium; newPipelineList.TestMediumTemperature = IsoList.TestMediumTemperature; newPipelineList.TestPressure = IsoList.TestPressure; newPipelineList.HoldingTime = IsoList.HoldingTime; db.PTP_PipelineList.InsertOnSubmit(newPipelineList); db.SubmitChanges(); } /// /// 修改试压信息明细 /// /// 试压明细实体 public static void UpdatePipelineList(Model.PTP_PipelineList IsoList) { Model.SGGLDB db = Funs.DB; Model.PTP_PipelineList newPipelineList = db.PTP_PipelineList.FirstOrDefault(e => e.PT_PipeId == IsoList.PT_PipeId); newPipelineList.PTP_ID = IsoList.PTP_ID; newPipelineList.PipelineId = IsoList.PipelineId; newPipelineList.PT_DataType = IsoList.PT_DataType; newPipelineList.DesignPress = IsoList.DesignPress; newPipelineList.DesignTemperature = IsoList.DesignTemperature; newPipelineList.AmbientTemperature = IsoList.AmbientTemperature; newPipelineList.TestMedium = IsoList.TestMedium; newPipelineList.TestMediumTemperature = IsoList.TestMediumTemperature; newPipelineList.TestPressure = IsoList.TestPressure; newPipelineList.HoldingTime = IsoList.HoldingTime; db.SubmitChanges(); } /// /// 根据单位获取试压 /// /// /// public static int GetTestPackageByUnitId(string unitId) { var q = (from x in Funs.DB.PTP_TestPackage where x.UnitId == unitId select x).ToList(); return q.Count(); } /// /// 根据装置获取试压 /// /// /// //public static int GetTestPackageByInstallationId(string installationId) //{ // var q = (from x in Funs.DB.PTP_TestPackage where x.InstallationId == installationId select x).ToList(); // return q.Count(); //} /// /// 试压包编号是否存在 /// /// /// /// public static bool IsExistTestPackageCode(string TestPackageNo, string PTP_ID, string projectId) { if (!string.IsNullOrEmpty(PTP_ID)) { var q = Funs.DB.PTP_TestPackage.FirstOrDefault(x => x.TestPackageNo == TestPackageNo && x.ProjectId == projectId && x.PTP_ID != PTP_ID); if (q != null) { return true; } else { return false; } } else { var q = Funs.DB.PTP_TestPackage.FirstOrDefault(x => x.TestPackageNo == TestPackageNo && x.ProjectId == projectId); if (q != null) { return true; } else { return false; } } } /// /// 试压包是否全部(需要热处理或硬度处理的已经全部处理) /// /// /// public static string IsExistNoHotHardItem(string PTP_ID) { string isohot = string.Empty; var pipelineList = from x in Funs.DB.PTP_PipelineList where x.PTP_ID == PTP_ID select x; if (pipelineList.Count() > 0) { foreach (var pipe in pipelineList) { var jots = from x in Funs.DB.HJGL_WeldJoint where x.PipelineId == pipe.PipelineId && x.IsHotProess == true select x; if (jots.Count() > 0) { string jotMessage = string.Empty; foreach (var jotItem in jots) { var hotProssItem = Funs.DB.HJGL_HotProess_TrustItem.FirstOrDefault(x => x.WeldJointId == jotItem.WeldJointId); if (hotProssItem == null) { jotMessage += "焊口:" + jotItem.WeldJointCode + "未作热处理;"; } else { var hotHardItem = Funs.DB.HJGL_Hard_TrustItem.FirstOrDefault(x => x.WeldJointId == jotItem.WeldJointId); if (hotHardItem == null) { jotMessage += "焊口:" + jotItem.WeldJointCode + "未作硬度检测;"; } } } if (!string.IsNullOrEmpty(jotMessage)) { var isoinfo = BLL.PipelineService.GetPipelineByPipelineId(pipe.PipelineId); if (isoinfo != null) { isohot += "管线:" + isoinfo.PipelineCode + "中" + jotMessage; } } } } } return isohot; } /// /// 检验试压包检测率(管线中设置的每个检测方法的检测比例是否达标) /// /// /// public static string InspectionIsoRate(string PTP_ID) { Model.SGGLDB db = Funs.DB; string isoRate = string.Empty; var pipelineList = from x in db.PTP_PipelineList where x.PTP_ID == PTP_ID select x; if (pipelineList.Count() > 0) { foreach (var isoInfo in pipelineList) { var isoinfo = BLL.PipelineService.GetPipelineByPipelineId(isoInfo.PipelineId); if (isoinfo != null) { decimal jotCouts = (from x in db.HJGL_WeldJoint where x.PipelineId == isoinfo.PipelineId select x).Count(); //焊口总数 if (jotCouts > 0) { int? raleValue = null; var rates = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(isoinfo.DetectionRateId); //探伤比例 if (rates != null) { raleValue = rates.DetectionRateValue; } if (raleValue.HasValue) { var checkJotCout = (from x in db.HJGL_Batch_NDEItem join y in db.HJGL_Batch_BatchTrustItem on x.TrustBatchItemId equals y.TrustBatchItemId join z in db.HJGL_Batch_BatchTrust on y.TrustBatchId equals z.TrustBatchId join d in db.Base_DetectionType on z.DetectionTypeId equals d.DetectionTypeId join e in db.HJGL_WeldJoint on y.WeldJointId equals e.WeldJointId where e.PipelineId == isoInfo.PipelineId //&& d.SysType == "射线检测" select y.WeldJointId).Distinct().Count(); decimal? realRaleValue = Convert.ToDecimal(Convert.ToDecimal(checkJotCout) / jotCouts) * 100; if (realRaleValue < raleValue) { isoRate += "管线:" + isoinfo.PipelineCode + "的RT实际检测比例小于应检测比例值。"; } } } } } } return isoRate; } public static void Init(FineUIPro.DropDownList dropName, string state, bool isShowPlease) { dropName.DataValueField = "Value"; dropName.DataTextField = "Text"; dropName.DataSource = GetHandleTypeByState(state); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } /// /// 根据状态选择下一步办理类型 /// /// /// public static ListItem[] GetHandleTypeByState(string state) { if (state == BLL.Const.TestPackage_Compile) { ListItem[] lis = new ListItem[1]; lis[0] = new ListItem("施工分包商整改", Const.TestPackage_Audit1); return lis; } else if (state == Const.TestPackage_Audit1 || state == Const.TestPackage_ReAudit2) { ListItem[] lis = new ListItem[1]; lis[0] = new ListItem("总包确认", Const.TestPackage_Audit2); return lis; } else if (state == Const.TestPackage_Audit2)//有是否同意 { ListItem[] lis = new ListItem[2]; lis[0] = new ListItem("监理确认", Const.TestPackage_Audit3);//是 加载 lis[1] = new ListItem("审批完成", Const.TestPackage_Complete);//是加载 return lis; } else if (state == Const.TestPackage_Audit3) { ListItem[] lis = new ListItem[1]; lis[0] = new ListItem("审批完成", "5"); return lis; } else if (state == "F")//选否 { ListItem[] lis = new ListItem[1]; lis[0] = new ListItem("施工分包商重新整改", Const.TestPackage_ReAudit2);//否加载 return lis; } else return null; } /// /// 根据试压包号、单位工程获取试压包信息 /// /// /// /// public static PTP_TestPackage GetTestPackageByNo(string testPackageNo, string unitWorkId) { Model.SGGLDB db = Funs.DB; Model.PTP_TestPackage q = null; q = Funs.DB.PTP_TestPackage.FirstOrDefault(x => x.TestPackageNo == testPackageNo && x.UnitWorkId == unitWorkId); return q; } public static List GetTestPackageByUnitWordId(string unitworkId) { var q = Funs.DB.PTP_TestPackage.Where(e => e.UnitWorkId == unitworkId).ToList(); return q; } public static List GetTestPackageByProjectId(string projectid) { var q = Funs.DB.PTP_TestPackage.Where(e => e.ProjectId == projectid).ToList(); return q; } public static void DeletePipelineListByUnitWorkId(string unitworkId) { var oldPipeline = GetTestPackageByUnitWordId(unitworkId); if (oldPipeline != null) { foreach (var pipeline in oldPipeline) { DeletePipelineListByPTP_ID(pipeline.PTP_ID); } } } /// /// 根据单位工程删除相关试压包 /// /// public static void DeleteTestPackageByUnitworkId(string unitworkId) { Model.SGGLDB db = Funs.DB; var pipeline = db.PTP_TestPackage.Where(e => e.UnitWorkId == unitworkId); if (pipeline != null) { db.PTP_TestPackage.DeleteAllOnSubmit(pipeline); db.SubmitChanges(); } } public static void AddPipelineLists(List pipelineList) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { db.PTP_PipelineList.InsertAllOnSubmit(pipelineList); db.SubmitChanges(); } } /// /// 修改试压包打印状态 /// /// public static void UpdateTestPackagePrintState(Model.PTP_TestPackage testPackage) { Model.PTP_TestPackage newTestPackage = Funs.DB.PTP_TestPackage.FirstOrDefault(e => e.PTP_ID == testPackage.PTP_ID); if (newTestPackage != null) { newTestPackage.PrintState = testPackage.PrintState; Funs.DB.SubmitChanges(); } } /// /// 计算试压包页面 ShowGridItem 需要的统计信息。 /// - 根据项目系统设置(SetId = "5")判断是否按管线组批(包含 "6") /// - 若按管线组批:按 PTP_PipelineList 对应的每条管线计算统计(等价于页面分行判断),返回 Count1..Count4 /// - 若不按管线组批:按页面原逻辑汇总整包的统计并返回(含 lab12.Label) /// 注意:方法只返回统计结果与标志,具体 UI 行样式仍由页面根据数据及返回结果决定。 /// public static TestPackageAnalyzeOutput getTestPackageAnalyze(string PTP_ID, string projectId) { // 返回结果对象,包含统计信息 var result = new TestPackageAnalyzeOutput(); Model.SGGLDB db = Funs.DB; var testPackage = db.PTP_TestPackage.FirstOrDefault(p => p.PTP_ID == PTP_ID); if (testPackage == null) return null; // 无效试压包,直接返回空结果 result.PTP_ID = PTP_ID; result.TestPackageNo = testPackage.TestPackageNo; result.UnitWorkName = BLL.UnitWorkService.GetUnitWorkALLName(testPackage.UnitWorkId); //判断当前试压包的状态 result.StateStr = State.试压前条件未确认.ToString(); if (testPackage.AduditDate.HasValue) { result.StateStr = State.试压前条件已确认.ToString(); } var PtpItemEndCheckList = (from x in db.PTP_ItemEndCheckList where x.PTP_ID == PTP_ID select x).FirstOrDefault(); if (PtpItemEndCheckList != null) { if (PtpItemEndCheckList.State == Const.TestPackage_Complete) { result.StateStr = State.尾项检查已整改.ToString(); } else { result.StateStr = State.尾项检查待整改.ToString(); } } if (testPackage.FinishDate.HasValue) { result.StateStr = State.试压包已完成.ToString(); } // 当前试压包下所有管线ID集合 var pipelineIds = (from p in db.PTP_PipelineList where p.PTP_ID == PTP_ID select p.PipelineId).ToList(); result.TotalPipelines = pipelineIds.Count; if (result.TotalPipelines == 0) return result; // 当前试压包下的焊口总数 result.TotalWeldJoints = db.HJGL_WeldJoint.Count(w => pipelineIds.Contains(w.PipelineId)); // 当前试压包下已焊接的焊口数 result.CompletedWeldJoints = db.HJGL_WeldJoint.Count(w => pipelineIds.Contains(w.PipelineId) && w.WeldingDailyId != null); // 当前试压包下已检测的焊口数(去重) result.DetectedWeldJoints = (from x in db.HJGL_Batch_NDEItem join t in db.HJGL_Batch_BatchTrustItem on x.TrustBatchItemId equals t.TrustBatchItemId join j in db.HJGL_WeldJoint on t.WeldJointId equals j.WeldJointId where pipelineIds.Contains(j.PipelineId) select t.WeldJointId).Distinct().Count(); if (result.TotalWeldJoints > 0) { // 焊口完成百分比 result.WeldCompletionPercent = Math.Round((decimal)result.CompletedWeldJoints / result.TotalWeldJoints * 100, 2); // 检测完成百分比 result.DetectionCompletionPercent = Math.Round((decimal)result.DetectedWeldJoints / result.TotalWeldJoints * 100, 2); } // 全通过管线计数 int passCount = 0; // 系统设置,判断是否按管线组批 var batch = BLL.Project_SysSetService.GetSysSetBySetId("5", projectId); if (batch != null && batch.SetValue != null && batch.SetValue.Contains("6")) { // 按管线组批,逐管线判断是否全通过 var pipelineList = (from p in db.PTP_PipelineList join iso in db.HJGL_Pipeline on p.PipelineId equals iso.PipelineId where p.PTP_ID == PTP_ID select new { p.PipelineId, Iso = iso }).ToList(); foreach (var item in pipelineList) { // 当前管线总焊口数 int total = db.HJGL_WeldJoint.Count(w => w.PipelineId == item.PipelineId); // 当前管线已焊接焊口数 int finished = db.HJGL_WeldJoint.Count(w => w.PipelineId == item.PipelineId && w.WeldingDailyId != null); // 当前管线应检测比例 int? rateValue = null; if (!string.IsNullOrEmpty(item.Iso.DetectionRateId)) { var rate = db.Base_DetectionRate.FirstOrDefault(r => r.DetectionRateId == item.Iso.DetectionRateId); if (rate != null) rateValue = rate.DetectionRateValue; } // 当前管线已检测焊口数 int detected = (from x in db.HJGL_Batch_NDEItem join t in db.HJGL_Batch_BatchTrustItem on x.TrustBatchItemId equals t.TrustBatchItemId join j in db.HJGL_WeldJoint on t.WeldJointId equals j.WeldJointId where j.PipelineId == item.PipelineId select t.WeldJointId).Distinct().Count(); // 检测比例 decimal ratio = (total > 0) ? (decimal)detected / total * 100 : 0M; // 检查返修焊口的最新检测是否全部合格 bool allNDEItemOK = true; var lastRepair = (from x in db.HJGL_RepairRecord join y in db.HJGL_WeldJoint on x.WeldJointId equals y.WeldJointId where x.ProjectId == projectId && y.PipelineId == item.PipelineId orderby x.NoticeDate descending select x).FirstOrDefault(); if (lastRepair != null) { // 返修批次 var batchTrustItem = db.HJGL_Batch_BatchTrustItem.FirstOrDefault(b => b.RepairRecordId == lastRepair.RepairRecordId); if (batchTrustItem != null) { // 返修检测单 var lastNDE = db.HJGL_Batch_NDE.FirstOrDefault(n => n.TrustBatchId == batchTrustItem.TrustBatchId); if (lastNDE != null) { // 检测单下所有检测项 var lastNDEItems = db.HJGL_Batch_NDEItem.Where(ni => ni.NDEID == lastNDE.NDEID); if (lastNDEItems.Any()) { foreach (var ni in lastNDEItems) { // 检查是否有未全部合格的项 if (ni.TotalFilm != null && ni.PassFilm != null && ni.TotalFilm != ni.PassFilm) { allNDEItemOK = false; break; } } } else allNDEItemOK = false; } else allNDEItemOK = false; } else allNDEItemOK = false; } // 满足所有条件才算全通过 if (!(total > finished) && !(rateValue.HasValue && rateValue.Value > ratio) && allNDEItemOK) passCount++; } } else { // 整包判断 var pipelineItem = db.PTP_PipelineList.FirstOrDefault(x => x.PTP_ID == PTP_ID); if (pipelineItem == null) return result; var pipeline = db.HJGL_Pipeline.FirstOrDefault(x => x.PipelineId == pipelineItem.PipelineId); if (pipeline == null) return result; // 整包所有焊口 var totalJoint = from x in db.HJGL_WeldJoint join y in db.HJGL_Pipeline on x.PipelineId equals y.PipelineId join z in db.PTP_PipelineList on y.PipelineId equals z.PipelineId where z.PTP_ID == PTP_ID && y.DetectionRateId == pipeline.DetectionRateId && y.DetectionType.Contains(pipeline.DetectionType) select x; int totalJointNum = totalJoint.Count(); // 整包总焊口数 int totalWeldingJointNum = totalJoint.Count(x => x.WeldingDailyId != null); // 整包已焊口数 int notCloseBatch = (from x in db.HJGL_Batch_PointBatch join y in db.PTP_PipelineList on x.PipelineId equals y.PipelineId where y.PTP_ID == PTP_ID && x.DetectionRateId == pipeline.DetectionRateId && x.DetectionTypeId == pipeline.DetectionType && x.EndDate == null select x).Count(); // 未关闭批次数 int allPointJointNum = (from x in db.HJGL_Batch_PointBatchItem join y in db.HJGL_Batch_PointBatch on x.PointBatchId equals y.PointBatchId join j in db.HJGL_WeldJoint on x.WeldJointId equals j.WeldJointId join p in db.PTP_PipelineList on j.PipelineId equals p.PipelineId where p.PTP_ID == PTP_ID && y.DetectionRateId == pipeline.DetectionRateId && y.DetectionTypeId == pipeline.DetectionType && x.PointState != null select x).Count(); // 所有检测点数 int allOKCheckNum = (from x in db.HJGL_Batch_NDEItem join y in db.HJGL_Batch_NDE on x.NDEID equals y.NDEID join t in db.HJGL_Batch_BatchTrustItem on x.TrustBatchItemId equals t.TrustBatchItemId join z in db.HJGL_Batch_BatchTrust on t.TrustBatchId equals z.TrustBatchId join j in db.HJGL_WeldJoint on t.WeldJointId equals j.WeldJointId join p in db.PTP_PipelineList on j.PipelineId equals p.PipelineId where p.PTP_ID == PTP_ID && z.DetectionRateId == pipeline.DetectionRateId && x.DetectionTypeId == pipeline.DetectionType && x.CheckResult == "1" select x).Count(); // 所有合格检测点数 // 满足所有条件才算全通过 if (!(totalJointNum > totalWeldingJointNum) && !(notCloseBatch > 0) && !(allPointJointNum > allOKCheckNum)) passCount = result.TotalPipelines; } result.PassPipelines = passCount;// 全通过管线数 // 计算管线通过率 result.PipelinePassPercent = result.TotalPipelines > 0 ? Math.Round((decimal)passCount / result.TotalPipelines * 100, 2) : 0M; // 设置试压条件状态:>=100% -> 已具备;>=80% and <100% -> 易具备;<80% -> 未具备 if (result.PipelinePassPercent >= 100M) { result.CanPressureTest = "已具备"; } else if (result.PipelinePassPercent >= 80M) { result.CanPressureTest = "易具备"; } else { result.CanPressureTest = "未具备"; } return result; } /// /// 获取单位工程下已完成试压包的通过率(完成试压包的通过数/总数*100,保留两位小数) /// /// 项目ID /// 单位工程ID /// 完成率百分比 public static decimal GetTestPackagePassPercentByUnitWorkId(string projectId, string unitWorkId) { Model.SGGLDB db = Funs.DB; // 获取该单位工程下所有试压包 int totalPipelines = db.PTP_TestPackage.Count(x => x.ProjectId == projectId && x.UnitWorkId == unitWorkId); if (totalPipelines == 0) return 0M; int finishedPipelines = db.PTP_TestPackage.Count(x => x.ProjectId == projectId && x.UnitWorkId == unitWorkId && x.FinishDate.HasValue); if (totalPipelines == 0) return 0M; return Math.Round((decimal)finishedPipelines / totalPipelines * 100, 2); } public static Dictionary GetTestPackagePassPercentByProjectId(string projectId) { Model.SGGLDB db = Funs.DB; Dictionary dic = new Dictionary(); // 获取该项目下所有单位工程分组统计 var groupQuery = db.PTP_TestPackage .Where(x => x.ProjectId == projectId) .GroupBy(x => x.UnitWorkId) .Select(g => new { UnitWorkId = g.Key, Total = g.Count(), Finished = g.Count(t => t.FinishDate.HasValue) }).ToList(); foreach (var item in groupQuery) { decimal percent = item.Total > 0 ? Math.Round((decimal)item.Finished / item.Total * 100, 2) : 0M; dic[item.UnitWorkId] = percent; } return dic; } } }