using Model; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Transactions; namespace BLL { public partial class WeldingDailyService { private const string AutoHotProcessRemark = "焊接日报审核自动生成"; private const int AuditStatePendingTeam = 0; private const int AuditStatePendingProfessional = 1; private const int AuditStateApproved = 2; private sealed class WeldingDailyTempSaveContext { public Model.View_HJGL_WeldJoint Joint { get; set; } public Model.HJGL_WeldTask WeldTask { get; set; } public DateTime WeldingDate { get; set; } public string SubmitPersonId { get; set; } public string CoverWelderId { get; set; } public string BackingWelderId { get; set; } public string JointAttribute { get; set; } public string WeldingLocationId { get; set; } public string ProjectId { get; set; } public string UnitId { get; set; } public string UnitWorkId { get; set; } public string WeldingMode { get; set; } public string WeldingMethodId { get; set; } public string WeldTypeId { get; set; } public string WeldingWire { get; set; } public string WeldingRod { get; set; } public int? WelderType { get; set; } } /// ///获取焊接日报信息 /// /// public static Model.HJGL_WeldingDaily GetPipeline_WeldingDailyByWeldingDailyId(string WeldingDailyId) { return Funs.DB.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDailyId); } /// /// 根据焊接日报主键获取焊接日报信息 /// /// 焊接日报编号 /// 焊接日报信息 public static bool IsExistWeldingDailyCode(string weldingDailyCode, string weldingDailyId, string projectId) { var q = Funs.DB.HJGL_WeldingDaily.FirstOrDefault(x => x.WeldingDailyCode == weldingDailyCode && x.ProjectId == projectId && x.WeldingDailyId != weldingDailyId); if (q != null) { return true; } else { return false; } } /// /// 根据焊接日报Id获取焊接日报明细信息 /// /// /// public static List GetWeldingDailyItem(string weldingDailyId) { List returnViewMatch = new List(); var weldlineLists = (from x in Funs.DB.View_HJGL_WeldJoint where x.WeldingDailyId == weldingDailyId select new SpWeldingDailyItem { WeldJointId = x.WeldJointId, WeldJointCode = x.WeldJointCode, PipelineCode = x.PipelineCode, CoverWelderCode = x.CoverWelderCode, CoverWelderId = x.CoverWelderId, BackingWelderCode = x.BackingWelderCode, BackingWelderId = x.BackingWelderId, WeldTypeId = x.WeldTypeCode, JointArea = x.JointArea, WeldingLocationId = x.WeldingLocationId, WeldingLocationCode = x.WeldingLocationCode, JointAttribute = x.JointAttribute, Size = x.Size, Dia = x.Dia, Thickness = x.Thickness, WeldingMethodCode = x.WeldingMethodCode, WeldingWireCode = x.WeldingWireCode, WeldingRodCode = x.WeldingRodCode }).ToList(); returnViewMatch = weldlineLists; //if (weldlineLists.Count() > 0) //{ // foreach (var item in weldlineLists) // { // Model.SpWeldingDailyItem newWeldReportItem = new Model.SpWeldingDailyItem(); // newWeldReportItem.WeldJointId = item.WeldJointId; // newWeldReportItem.WeldJointCode = item.WeldJointCode; // newWeldReportItem.PipelineCode = item.PipelineCode; // newWeldReportItem.CoverWelderCode = item.CoverWelderCode; // newWeldReportItem.CoverWelderId = item.CoverWelderId; // newWeldReportItem.BackingWelderCode = item.BackingWelderCode; // newWeldReportItem.BackingWelderId = item.BackingWelderId; // //newWeldReportItem.WeldTypeId = item.WeldTypeCode; // newWeldReportItem.JointArea = item.JointArea; // newWeldReportItem.WeldingLocationId = item.WeldingLocationId; // newWeldReportItem.WeldingLocationCode = item.WeldingLocationCode; // newWeldReportItem.JointAttribute = item.JointAttribute; // newWeldReportItem.Size = item.Size; // newWeldReportItem.Dia = item.Dia; // newWeldReportItem.Thickness = item.Thickness; // newWeldReportItem.WeldingMethodCode = item.WeldingMethodCode; // newWeldReportItem.WeldingWireCode = item.WeldingWireCode; // newWeldReportItem.WeldingRodCode = item.WeldingRodCode; // returnViewMatch.Add(newWeldReportItem); // } //} return returnViewMatch; } /// /// 查找后返回集合增加到列表集团中 /// /// /// public static List GetWeldReportAddItem(string hdString) { List returnViewMatch = new List(); //= getWeldReportItem; if (!string.IsNullOrEmpty(hdString)) { List totallist = Funs.GetStrListByStr(hdString, '@'); foreach (var hdItemsString in totallist) { List list = Funs.GetStrListByStr(hdItemsString, '#'); if (list.Count() == 4) { string CoverWelderCode = string.Empty; //盖面焊工号 string BackingWelderCode = string.Empty; //打底焊工号 string welderLists = list[0]; List welderIds = Funs.GetStrListByStr(welderLists, '|'); if (welderIds.Count() == 2) { var welderCell = BLL.SitePerson_PersonService.GetSitePersonById(welderIds[0]); if (welderCell != null) { CoverWelderCode = welderCell.WelderCode; } var welderFloor = BLL.SitePerson_PersonService.GetSitePersonById(welderIds[1]); if (welderFloor != null) { BackingWelderCode = welderFloor.WelderCode; } } string weldingLocationCode = string.Empty; string weldingLocationId = list[1]; var loc = BLL.Base_WeldingLocationServie.GetWeldingLocationById(weldingLocationId); if (loc != null) { weldingLocationCode = loc.WeldingLocationCode; } string jointAttribute = list[2]; string weldlineIdLists = list[3]; List weldlineIds = Funs.GetStrListByStr(weldlineIdLists, '|'); foreach (var weldlineItem in weldlineIds) { //if (returnViewMatch.FirstOrDefault(x => x.JOT_ID == jotItem) == null) //{ var jot = Funs.DB.View_HJGL_WeldJoint.FirstOrDefault(e => e.WeldJointId == weldlineItem); //var weldline = BLL.Pipeline_WeldJointService.GetViewWeldJointById(weldlineItem); if (jot != null) { Model.SpWeldingDailyItem newWeldReportItem = new Model.SpWeldingDailyItem(); newWeldReportItem.WeldJointId = jot.WeldJointId; newWeldReportItem.WeldJointCode = jot.WeldJointCode; newWeldReportItem.PipelineCode = jot.PipelineCode; newWeldReportItem.CoverWelderCode = CoverWelderCode; newWeldReportItem.CoverWelderId = welderIds[0]; newWeldReportItem.BackingWelderCode = BackingWelderCode; newWeldReportItem.BackingWelderId = welderIds[1]; newWeldReportItem.WeldTypeCode = jot.WeldTypeCode; newWeldReportItem.JointArea = jot.JointArea; newWeldReportItem.WeldingLocationId = weldingLocationId; newWeldReportItem.WeldingLocationCode = weldingLocationCode; newWeldReportItem.JointAttribute = jointAttribute; newWeldReportItem.Size = jot.Size; newWeldReportItem.Dia = jot.Dia; newWeldReportItem.Thickness = jot.Thickness; newWeldReportItem.WeldingMethodCode = jot.WeldingMethodCode; // 如存在日报,默认还是原日报焊工 if (!string.IsNullOrEmpty(jot.WeldingDailyId)) { newWeldReportItem.CoverWelderId = jot.CoverWelderId; newWeldReportItem.BackingWelderId = jot.BackingWelderId; var welderCover = SitePerson_PersonService.GetSitePersonById(jot.CoverWelderId); if (welderCover != null) { newWeldReportItem.CoverWelderCode = welderCover.WelderCode; } var welderBacking = SitePerson_PersonService.GetSitePersonById(jot.BackingWelderId); if (welderBacking != null) { newWeldReportItem.BackingWelderCode = welderBacking.WelderCode; } newWeldReportItem.JointAttribute = jot.JointAttribute; newWeldReportItem.WeldingLocationId = jot.WeldingLocationId; var location = BLL.Base_WeldingLocationServie.GetWeldingLocationById(jot.WeldingLocationId); if (location != null) { newWeldReportItem.WeldingLocationCode = location.WeldingLocationCode; } } returnViewMatch.Add(newWeldReportItem); } } } } } return returnViewMatch; } /// /// 获取未焊接焊口信息 /// /// /// public static List GetWeldReportItemFind(string weldingDailyId, string pipelineId) { List returnViewMatch = new List(); var weldlineLists = from x in Funs.DB.View_HJGL_NoWeldJointFind where x.PipelineId == pipelineId && (x.WeldingDailyId == null || x.WeldingDailyId == weldingDailyId) select x; if (weldlineLists.Count() > 0) { foreach (var item in weldlineLists) { Model.SpWeldingDailyItem newWeldReportItem = new Model.SpWeldingDailyItem(); newWeldReportItem.WeldJointId = item.WeldJointId; newWeldReportItem.WeldJointCode = item.WeldJointCode; newWeldReportItem.Dia = item.Dia; newWeldReportItem.Thickness = item.Thickness; newWeldReportItem.WeldingMethodCode = item.WeldingMethodCode; newWeldReportItem.WeldTypeCode = item.WeldTypeCode; returnViewMatch.Add(newWeldReportItem); } } return returnViewMatch; } /// /// 增加焊接日报信息 /// /// public static void AddWeldingDaily(Model.HJGL_WeldingDaily WeldingDaily) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldingDaily newWeldingDaily = new HJGL_WeldingDaily { WeldingDailyId = WeldingDaily.WeldingDailyId, WeldingDailyCode = WeldingDaily.WeldingDailyCode, ProjectId = WeldingDaily.ProjectId, UnitId = WeldingDaily.UnitId, UnitWorkId = WeldingDaily.UnitWorkId, WeldingDate = WeldingDaily.WeldingDate, Tabler = WeldingDaily.Tabler, TableDate = WeldingDaily.TableDate, Remark = WeldingDaily.Remark, }; db.HJGL_WeldingDaily.InsertOnSubmit(newWeldingDaily); db.SubmitChanges(); } /// /// 修改焊接日报信息 /// /// public static void UpdateWeldingDaily(Model.HJGL_WeldingDaily WeldingDaily) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldingDaily newWeldingDaily = db.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDaily.WeldingDailyId); if (newWeldingDaily != null) { newWeldingDaily.WeldingDailyCode = WeldingDaily.WeldingDailyCode; newWeldingDaily.UnitId = WeldingDaily.UnitId; newWeldingDaily.UnitWorkId = WeldingDaily.UnitWorkId; newWeldingDaily.WeldingDate = WeldingDaily.WeldingDate; newWeldingDaily.Tabler = WeldingDaily.Tabler; newWeldingDaily.TableDate = WeldingDaily.TableDate; newWeldingDaily.Remark = WeldingDaily.Remark; db.SubmitChanges(); } } /// /// 根据焊接日报Id删除一个焊接日报信息 /// /// public static void DeleteWeldingDaily(string WeldingDailyId) { Model.SGGLDB db = Funs.DB; Model.HJGL_WeldingDaily delWeldingDaily = db.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDailyId); if (delWeldingDaily != null) { db.HJGL_WeldingDaily.DeleteOnSubmit(delWeldingDaily); db.SubmitChanges(); } } #region 焊接日报待审核 /// /// 获取焊接日报待审核明细列表。 /// /// 项目ID /// 单位工程ID,为空时不按单位工程过滤 /// 焊接日期,为空时不按日期过滤 /// 管线编号关键字 /// 焊工编号关键字 /// 待审核明细列表 public static List GetWeldingDailyTempDetailList(string projectId, string unitWorkId, DateTime? weldingDate, string pipelineCode, string welderCode) { if (string.IsNullOrEmpty(projectId)) { return new List(); } int totalCount; return GetWeldingDailyTempDetailList(new Model.WeldingDailyTempDetailInput { ProjectId = projectId, UnitWorkId = unitWorkId, WeldingDate = weldingDate, PipelineCode = pipelineCode, WelderCode = welderCode }, out totalCount); } /// /// 按查询参数获取焊接日报待审核明细列表。 /// /// 查询及分页条件 /// 分页前总记录数 /// 待审核明细列表 public static List GetWeldingDailyTempDetailList( Model.WeldingDailyTempDetailInput input, out int totalCount) { return QueryPendingWeldingDailyTempDetails(input, out totalCount); } /// /// 获取单条焊接日报待审核明细。 /// /// 待审核明细ID /// 待审核明细,不存在时返回空 public static Model.WeldingDailyTempDetailItem GetWeldingDailyTempDetailById(string tempDetailId) { if (string.IsNullOrEmpty(tempDetailId)) { return null; } int totalCount; return QueryPendingWeldingDailyTempDetails(new Model.WeldingDailyTempDetailInput { TempDetailId = tempDetailId, PageIndex = 0, PageSize = 1 }, out totalCount).FirstOrDefault(); } /// /// 更新待审核明细的实际施工工艺参数。 /// /// 待审核明细及四项工艺参数 /// 错误信息,空字符串表示成功 public static string UpdateWeldingDailyTempDetailParameters(Model.WeldingDailyTempDetailEditInput input) { if (input == null || string.IsNullOrWhiteSpace(input.TempDetailId) || string.IsNullOrWhiteSpace(input.ProjectId)) { return "待审核明细或项目不能为空"; } string weldingMethodId = NormalizeOptionalId(input.WeldingMethodId); string weldTypeId = NormalizeOptionalId(input.WeldTypeId); string weldingWire = NormalizeOptionalId(input.WeldingWire); string weldingRod = NormalizeOptionalId(input.WeldingRod); string parameterError = ValidatePendingWeldingParameters( weldingMethodId, weldTypeId, weldingWire, weldingRod); if (!string.IsNullOrEmpty(parameterError)) { return parameterError; } using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var detail = db.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.TempDetailId == input.TempDetailId && x.ProjectId == input.ProjectId); if (detail == null) { return "待审核明细不存在"; } if (detail.AuditState >= AuditStateApproved) { return "该明细已完成审核,不能修改"; } // 编辑页只维护临时工艺快照;正式焊口仍在专工审核通过时统一回写。 detail.WeldingMethodId = weldingMethodId; detail.WeldTypeId = weldTypeId; detail.WeldingWire = weldingWire; detail.WeldingRod = weldingRod; db.SubmitChanges(); } return string.Empty; } /// /// 构造待审核查询。PC端列表和接口列表、明细均从这里读取,确保字段映射和待审核状态一致。 /// /// 查询及分页条件 /// 分页前总记录数 private static List QueryPendingWeldingDailyTempDetails( Model.WeldingDailyTempDetailInput input, out int totalCount) { input = input ?? new Model.WeldingDailyTempDetailInput(); if (input.ProjectId != null && string.IsNullOrWhiteSpace(input.ProjectId)) { totalCount = 0; return new List(); } List data; using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { var tempQuery = db.HJGL_WeldingDailyTempDetail .Where(x => x.AuditState != AuditStateApproved); if (!string.IsNullOrEmpty(input.TempDetailId)) { tempQuery = tempQuery.Where(x => x.TempDetailId == input.TempDetailId); } if (!string.IsNullOrEmpty(input.ProjectId)) { tempQuery = tempQuery.Where(x => x.ProjectId == input.ProjectId); } if (!string.IsNullOrEmpty(input.UnitWorkId)) { tempQuery = tempQuery.Where(x => x.UnitWorkId == input.UnitWorkId); } if (input.WeldingDate.HasValue) { tempQuery = tempQuery.Where(x => x.WeldingDate == input.WeldingDate); } if (input.AuditState.HasValue) { tempQuery = tempQuery.Where(x => x.AuditState == input.AuditState.Value); } // 主表条件先过滤,再执行关联和文本条件,避免无关待审核记录参与联表。 var query = from temp in tempQuery join jotItem in db.HJGL_WeldJoint on temp.WeldJointId equals jotItem.WeldJointId into jotItems from jot in jotItems.DefaultIfEmpty() join coverItem in db.SitePerson_Person on temp.CoverWelderId equals coverItem.PersonId into coverItems from coverWelder in coverItems.DefaultIfEmpty() join backingItem in db.SitePerson_Person on temp.BackingWelderId equals backingItem.PersonId into backingItems from backingWelder in backingItems.DefaultIfEmpty() join locationItem in db.Base_WeldingLocation on temp.WeldingLocationId equals locationItem.WeldingLocationId into locationItems from location in locationItems.DefaultIfEmpty() join weldTypeItem in db.Base_WeldType on (temp.WeldTypeId ?? jot.WeldTypeId) equals weldTypeItem.WeldTypeId into weldTypeItems from weldType in weldTypeItems.DefaultIfEmpty() join weldingMethodItem in db.Base_WeldingMethod on (temp.WeldingMethodId ?? jot.WeldingMethodId) equals weldingMethodItem.WeldingMethodId into weldingMethodItems from weldingMethod in weldingMethodItems.DefaultIfEmpty() join weldingWireItem in db.Base_Consumables on (temp.WeldingWire ?? jot.WeldingWire) equals weldingWireItem.ConsumablesId into weldingWireItems from weldingWire in weldingWireItems.DefaultIfEmpty() join weldingRodItem in db.Base_Consumables on (temp.WeldingRod ?? jot.WeldingRod) equals weldingRodItem.ConsumablesId into weldingRodItems from weldingRod in weldingRodItems.DefaultIfEmpty() join submitItem in db.Person_Persons on temp.SubmitPersonId equals submitItem.PersonId into submitItems from submitPerson in submitItems.DefaultIfEmpty() join teamAuditItem in db.Person_Persons on temp.TeamAuditMan equals teamAuditItem.PersonId into teamAuditItems from teamAuditPerson in teamAuditItems.DefaultIfEmpty() join professionalAuditItem in db.Person_Persons on temp.ProfessionalAuditMan equals professionalAuditItem.PersonId into professionalAuditItems from professionalAuditPerson in professionalAuditItems.DefaultIfEmpty() select new Model.WeldingDailyTempDetailItem { TempDetailId = temp.TempDetailId, ProjectId = temp.ProjectId, UnitId = temp.UnitId, UnitWorkId = temp.UnitWorkId, WeldJointId = temp.WeldJointId, PipelineId = jot == null ? null : jot.PipelineId, PipelineCode = jot == null ? null : jot.PipelineCode, WeldJointCode = jot == null ? null : jot.WeldJointCode, WeldingDate = temp.WeldingDate, CoverWelderId = temp.CoverWelderId, CoverWelderCode = coverWelder == null ? null : coverWelder.WelderCode, BackingWelderId = temp.BackingWelderId, BackingWelderCode = backingWelder == null ? null : backingWelder.WelderCode, JointAttribute = temp.JointAttribute, WeldingLocationId = temp.WeldingLocationId, WeldingLocationCode = location == null ? null : location.WeldingLocationCode, WeldingMode = temp.WeldingMode, DNDia = jot == null ? null : jot.DNDia, Size = jot == null ? (decimal?)null : jot.Size, Dia = jot == null ? (decimal?)null : jot.Dia, Thickness = jot == null ? (decimal?)null : jot.Thickness, WeldTypeId = temp.WeldTypeId ?? (jot == null ? null : jot.WeldTypeId), WeldTypeCode = weldType == null ? null : weldType.WeldTypeCode, WeldingMethodId = temp.WeldingMethodId ?? (jot == null ? null : jot.WeldingMethodId), WeldingMethodCode = weldingMethod == null ? null : weldingMethod.WeldingMethodCode, WeldingWire = temp.WeldingWire ?? (jot == null ? null : jot.WeldingWire), WeldingWireCode = weldingWire == null ? null : weldingWire.ConsumablesCode, WeldingRod = temp.WeldingRod ?? (jot == null ? null : jot.WeldingRod), WeldingRodCode = weldingRod == null ? null : weldingRod.ConsumablesCode, SubmitPersonId = temp.SubmitPersonId, SubmitPersonName = submitPerson == null ? null : submitPerson.PersonName, SubmitDate = temp.SubmitDate, AttachUrl = temp.AttachUrl, AuditState = temp.AuditState, AuditMan = temp.AuditMan, AuditDate = temp.AuditDate, AuditRemark = temp.AuditRemark, TeamAuditMan = temp.TeamAuditMan, TeamAuditManName = teamAuditPerson == null ? null : teamAuditPerson.PersonName, TeamAuditDate = temp.TeamAuditDate, ProfessionalAuditMan = temp.ProfessionalAuditMan, ProfessionalAuditManName = professionalAuditPerson == null ? null : professionalAuditPerson.PersonName, ProfessionalAuditDate = temp.ProfessionalAuditDate, AuditStateText = temp.AuditState == AuditStatePendingTeam ? "待班组审核" : "待专工审核" }; if (!string.IsNullOrEmpty(input.PipelineCode)) { query = query.Where(x => x.PipelineCode != null && x.PipelineCode.Contains(input.PipelineCode)); } if (!string.IsNullOrEmpty(input.WelderCode)) { query = query.Where(x => (x.CoverWelderCode != null && x.CoverWelderCode.Contains(input.WelderCode)) || (x.BackingWelderCode != null && x.BackingWelderCode.Contains(input.WelderCode))); } totalCount = query.Count(); query = query.OrderBy(x => x.PipelineCode).ThenBy(x => x.WeldJointCode); if (input.PageIndex.HasValue && input.PageIndex.Value >= 0 && input.PageSize.HasValue && input.PageSize.Value > 0) { query = query.Skip(input.PageIndex.Value * input.PageSize.Value).Take(input.PageSize.Value); } // 查询必须在数据上下文释放前物化,避免返回失效的延迟查询。 data = query.ToList(); } SetWeldingDailyTempDetailAttachUrls(data); return data; } /// /// 按待审核明细ID批量回写焊前、焊后附件地址。 /// private static void SetWeldingDailyTempDetailAttachUrls(List data) { if (data == null || data.Count == 0) { return; } var toKeyIds = data.SelectMany(x => new[] { x.TempDetailId + "#Before", x.TempDetailId + "#After" }).ToList(); Dictionary attachUrlMap; using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { attachUrlMap = db.AttachFile .Where(x => x.MenuId == Const.HJGL_WeldReportMenuId && toKeyIds.Contains(x.ToKeyId)) .Select(x => new { x.ToKeyId, x.AttachUrl }) .ToList() .GroupBy(x => x.ToKeyId) .ToDictionary(x => x.Key, x => x.Select(y => y.AttachUrl).FirstOrDefault()); } foreach (var item in data) { string beforeUrl; if (attachUrlMap.TryGetValue(item.TempDetailId + "#Before", out beforeUrl)) { // API统一返回斜杠路径,PC端继续兼容原有反斜杠路径显示逻辑。 item.BeforePhotoUrl = NormalizeAttachUrl(beforeUrl); } string afterUrl; if (attachUrlMap.TryGetValue(item.TempDetailId + "#After", out afterUrl)) { item.AfterPhotoUrl = NormalizeAttachUrl(afterUrl); } } } private static string NormalizeAttachUrl(string attachUrl) { return string.IsNullOrEmpty(attachUrl) ? attachUrl : attachUrl.Replace('\\', '/'); } /// /// 移动端按焊口保存焊接日报待审核明细 /// /// 焊口ID /// 提交焊工ID /// 焊接日期 /// 焊接位置ID /// 焊工类型 0 全部 1 打底 2 盖面 /// 错误信息 public static string SaveWeldingDailyTempDetailByMobile(string weldJointId, string personId, string time, string weldingLocationId, int welderType) { return SaveWeldingDailyTempDetailByMobile(weldJointId, personId, time, weldingLocationId, welderType, null, null, null, null); } /// /// 移动端按焊口保存焊接日报待审核明细及实际焊接工艺快照。 /// public static string SaveWeldingDailyTempDetailByMobile(string weldJointId, string personId, string time, string weldingLocationId, int welderType, string weldingMethodId, string weldTypeId, string weldingWire, string weldingRod) { string res = string.Empty; using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { try { DateTime weldingDate; if (!DateTime.TryParse(time, out weldingDate)) { return "焊接日期不正确"; } weldingDate = weldingDate.Date; var person = db.Person_Persons.FirstOrDefault(x => x.PersonId == personId); if (person == null) { return "人员不存在"; } var joint = db.View_HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId); string err = CheckWeldingDailyTempJoint(joint, weldingLocationId); if (!string.IsNullOrEmpty(err)) { return err; } var weldTask = db.HJGL_WeldTask.FirstOrDefault(x => x.WeldJointId == joint.WeldJointId); var weldJoint = db.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == joint.WeldJointId); if (weldJoint == null) { return "焊口不存在"; } string parameterError = ValidatePendingWeldingParameters(weldingMethodId, weldTypeId, weldingWire, weldingRod); if (!string.IsNullOrEmpty(parameterError)) { return parameterError; } if (welderType < 0 || welderType > 2) { return "焊工类型不正确"; } SaveWeldingDailyTempDetail(new WeldingDailyTempSaveContext { Joint = joint, WeldTask = weldTask, WeldingDate = weldingDate, SubmitPersonId = personId, CoverWelderId = weldJoint.CoverWelderId, BackingWelderId = weldJoint.BackingWelderId, JointAttribute = joint.JointAttribute, WeldingLocationId = weldingLocationId, ProjectId = joint.ProjectId, WeldingMode = joint.WeldingMode, WeldingMethodId = weldingMethodId, WeldTypeId = weldTypeId, WeldingWire = weldingWire, WeldingRod = weldingRod, WelderType = welderType }); } catch (Exception ex) { APICommonService.SaveSysAPILog("erro", ex.ToString(), "-1"); res = ex.Message; } } return res; } /// /// Web端保存焊接日报待审核明细 /// /// 焊口ID /// 提交人ID /// 焊接日期 /// 盖面焊工ID /// 打底焊工ID /// 焊口属性 /// 焊接位置ID /// 项目ID /// 单位ID /// 单位工程ID /// 焊接模式 /// 错误信息 public static string SaveWeldingDailyTempDetailByWeb(string weldJointId, string submitPersonId, DateTime weldingDate, string coverWelderId, string backingWelderId, string jointAttribute, string weldingLocationId, string projectId, string unitId, string unitWorkId, string weldingMode) { string res = string.Empty; using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { try { weldingDate = weldingDate.Date; weldingLocationId = NormalizeNullValue(weldingLocationId); unitId = NormalizeNullValue(unitId); unitWorkId = NormalizeNullValue(unitWorkId); if (string.IsNullOrEmpty(weldJointId)) { return "焊口不能为空"; } if (string.IsNullOrEmpty(coverWelderId) || string.IsNullOrEmpty(backingWelderId)) { return "未选择完整焊工"; } var joint = db.View_HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId); string err = CheckWeldingDailyTempJoint(joint, weldingLocationId); if (!string.IsNullOrEmpty(err)) { return err; } var coverWelder = db.SitePerson_Person.FirstOrDefault(x => x.ProjectId == projectId && x.PersonId == coverWelderId); if (coverWelder == null) { return "盖面焊工不存在"; } var backingWelder = db.SitePerson_Person.FirstOrDefault(x => x.ProjectId == projectId && x.PersonId == backingWelderId); if (backingWelder == null) { return "打底焊工不存在"; } var weldTask = db.HJGL_WeldTask.FirstOrDefault(x => x.WeldJointId == weldJointId); SaveWeldingDailyTempDetail(new WeldingDailyTempSaveContext { Joint = joint, WeldTask = weldTask, WeldingDate = weldingDate, SubmitPersonId = submitPersonId, CoverWelderId = coverWelderId, BackingWelderId = backingWelderId, JointAttribute = jointAttribute, WeldingLocationId = weldingLocationId, ProjectId = projectId, UnitId = unitId, UnitWorkId = unitWorkId, WeldingMode = weldingMode }); } catch (Exception ex) { APICommonService.SaveSysAPILog("erro", ex.ToString(), "-1"); res = ex.Message; } } return res; } /// /// 班组审核焊接日报待审核明细,只记录班组审核留痕,不生成正式日报。 /// public static string TeamAuditWeldingDailyTempDetails(string[] tempDetailIds, string auditMan) { if (tempDetailIds == null || tempDetailIds.Length == 0) return "请选择要审核的记录"; if (string.IsNullOrWhiteSpace(auditMan)) return "班组审核人不能为空"; string errlog = string.Empty; using (var scope = new TransactionScope()) { foreach (string id in tempDetailIds.Where(x => !string.IsNullOrEmpty(x)).Distinct()) { var detail = GetLockedWeldingDailyTempDetail(id); if (detail == null) { errlog += "待审核记录不存在;"; continue; } if (detail.AuditState != AuditStatePendingTeam) { errlog += "记录不是待班组审核状态;"; continue; } if (!HasCompleteWelders(detail)) { // 班组审核后记录不再允许补录,必须在状态流转前保证两类焊工完整。 errlog += "焊口待审核记录未选择完整焊工;"; continue; } detail.TeamAuditMan = auditMan; detail.TeamAuditDate = DateTime.Now; detail.AuditState = AuditStatePendingProfessional; } Funs.DB.SubmitChanges(); scope.Complete(); } return errlog; } /// /// 专工审核通过焊接日报待审核明细,并生成正式日报及热处理委托。 /// /// 待审核明细ID集合 /// 审核人 /// 错误信息 public static string AuditWeldingDailyTempDetails(string[] tempDetailIds, string auditMan) { string errlog = string.Empty; if (tempDetailIds == null || tempDetailIds.Length == 0) { return "请选择要审核的记录"; } if (string.IsNullOrWhiteSpace(auditMan)) return "专工审核人不能为空"; var sharedConnection = (SqlConnection)Funs.DB.Connection; bool closeConnection = sharedConnection.State != ConnectionState.Open; try { using (var scope = new TransactionScope()) { // 整个专工审核事务保持单一连接 if (closeConnection) sharedConnection.Open(); foreach (string tempDetailId in tempDetailIds.Where(x => !string.IsNullOrEmpty(x)).Distinct()) { var tempDetail = GetLockedWeldingDailyTempDetail(tempDetailId); if (tempDetail == null) { errlog += "待审核记录不存在;"; continue; } if (tempDetail.AuditState != AuditStatePendingProfessional || !tempDetail.TeamAuditDate.HasValue) { errlog += "焊口待审核记录尚未完成班组审核;"; continue; } if (!HasCompleteWelders(tempDetail)) { errlog += "焊口待审核记录未选择完整焊工;"; continue; } var weldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(tempDetail.WeldJointId); if (weldJoint == null) { errlog += "焊口不存在;"; continue; } if (!string.IsNullOrEmpty(weldJoint.WeldingDailyId)) { errlog += "焊口【" + weldJoint.WeldJointCode + "】已生成焊接日报;"; continue; } var batchC = BLL.Project_SysSetService.GetSysSetBySetId("5", tempDetail.ProjectId); if (batchC == null) { errlog += "请设置项目的组批条件;"; continue; } var weldingDaily = GetOrCreateWeldingDailyByTempDetail(tempDetail); // 实际工艺参数在专工审核事务内才回写焊口,审核失败时与正式日报一起回滚。 weldJoint.WeldingMethodId = FirstNotEmpty(tempDetail.WeldingMethodId, weldJoint.WeldingMethodId); weldJoint.WeldTypeId = FirstNotEmpty(tempDetail.WeldTypeId, weldJoint.WeldTypeId); weldJoint.WeldingWire = FirstNotEmpty(tempDetail.WeldingWire, weldJoint.WeldingWire); weldJoint.WeldingRod = FirstNotEmpty(tempDetail.WeldingRod, weldJoint.WeldingRod); Funs.DB.SubmitChanges(); string itemErr = InsertWeldingDailyItem(tempDetail.WeldJointId, tempDetail.CoverWelderId, tempDetail.BackingWelderId, tempDetail.JointAttribute, weldingDaily.WeldingDate, batchC.SetValue, true, weldingDaily.WeldingDailyId, tempDetail.ProjectId, tempDetail.WeldingLocationId, sharedConnection); if (!string.IsNullOrEmpty(itemErr)) { // 正式日报、焊口状态、组批和自动热处理委托必须整体成功,任一步失败即回滚本次审核。 throw new InvalidOperationException(itemErr); } BLL.HJGL_PipelineComponentjointService.UpdateStateByWeldJointId(tempDetail.WeldJointId, (DateTime)weldingDaily.WeldingDate); PipelineService.UpdataDateByWeldJointId(tempDetail.WeldJointId); tempDetail.AuditState = AuditStateApproved; tempDetail.ProfessionalAuditMan = auditMan; tempDetail.ProfessionalAuditDate = DateTime.Now; // 旧字段继续镜像专工审核信息,兼容历史查询和报表。 tempDetail.AuditMan = auditMan; tempDetail.AuditDate = tempDetail.ProfessionalAuditDate; EnsureAutomaticHotProcessTrust(tempDetail, weldJoint, auditMan); Funs.DB.SubmitChanges(); } scope.Complete(); } } finally { // 在 TransactionScope 完成提交或回滚后再释放连接。 if (closeConnection && sharedConnection.State != ConnectionState.Closed) sharedConnection.Close(); } return errlog; } /// /// 删除未审核的焊接日报待审核明细 /// /// 待审核明细ID集合 /// 错误信息 public static string DeleteWeldingDailyTempDetails(string[] tempDetailIds) { if (tempDetailIds == null || tempDetailIds.Length == 0) { return "请选择要删除的记录"; } string errlog = string.Empty; foreach (string tempDetailId in tempDetailIds.Where(x => !string.IsNullOrEmpty(x)).Distinct()) { var tempDetail = Funs.DB.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.TempDetailId == tempDetailId); if (tempDetail == null) { continue; } if (tempDetail.AuditState != AuditStatePendingTeam) { errlog += "已审核记录不能删除;"; continue; } Funs.DB.HJGL_WeldingDailyTempDetail.DeleteOnSubmit(tempDetail); } Funs.DB.SubmitChanges(); return errlog; } /// /// 将需要热处理的焊口归入焊接完成日期当天的自动热处理委托。 /// private static void EnsureAutomaticHotProcessTrust(Model.HJGL_WeldingDailyTempDetail tempDetail, Model.HJGL_WeldJoint weldJoint, string auditMan) { if (weldJoint.IsHotProess != true) return; if (Funs.DB.HJGL_HotProess_TrustItem.Any(x => x.WeldJointId == weldJoint.WeldJointId)) return; DateTime processDate = tempDetail.WeldingDate.Date; var trust = Funs.DB.HJGL_HotProess_Trust.FirstOrDefault(x => x.ProjectId == tempDetail.ProjectId && x.UnitWorkId == tempDetail.UnitWorkId && x.ProessDate.HasValue && x.ProessDate.Value >= processDate && x.ProessDate.Value < processDate.AddDays(1) && x.Remark == AutoHotProcessRemark); if (trust == null) { // 在当前事务内锁定同项目、单位工程编号范围,防止并发审核产生重复流水号。 var lockedNumbers = Funs.DB.ExecuteQuery( "SELECT HotProessTrustNo FROM dbo.HJGL_HotProess_Trust WITH (UPDLOCK,HOLDLOCK) WHERE ProjectId={0} AND UnitWorkId={1}", tempDetail.ProjectId, tempDetail.UnitWorkId).ToList(); var unitWork = Funs.DB.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkId == tempDetail.UnitWorkId); string unitWorkName = unitWork == null ? string.Empty : unitWork.UnitWorkName; string prefix = "FCC-" + unitWorkName + "-RCL-SPCECC-"; int serial = lockedNumbers.Where(x => !string.IsNullOrEmpty(x) && x.StartsWith(prefix)) .Select(ParseTrailingSerial).DefaultIfEmpty(0).Max() + 1; if (serial > 999) throw new InvalidOperationException("热处理委托编号三位流水号已用完。"); trust = new Model.HJGL_HotProess_Trust { HotProessTrustId = SQLHelper.GetNewID(), HotProessTrustNo = prefix + serial.ToString("D3"), ProessDate = processDate, ProjectId = tempDetail.ProjectId, UnitWorkId = tempDetail.UnitWorkId, UnitId = tempDetail.UnitId, Tabler = auditMan, Remark = AutoHotProcessRemark }; Funs.DB.HJGL_HotProess_Trust.InsertOnSubmit(trust); } Funs.DB.HJGL_HotProess_TrustItem.InsertOnSubmit(new Model.HJGL_HotProess_TrustItem { HotProessTrustItemId = SQLHelper.GetNewID(), HotProessTrustId = trust.HotProessTrustId, WeldJointId = weldJoint.WeldJointId, IsCompleted = false }); } private static int ParseTrailingSerial(string code) { if (string.IsNullOrEmpty(code)) return 0; int separator = code.LastIndexOf('-'); int value; return separator >= 0 && int.TryParse(code.Substring(separator + 1), out value) ? value : 0; } private static string CheckWeldingDailyTempJoint(Model.View_HJGL_WeldJoint joint, string weldingLocationId) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { if (joint == null) { return "焊口不存在"; } if (!string.IsNullOrEmpty(joint.WeldingDailyId)) { return "焊口【" + joint.WeldJointCode + "】已生成焊接日报,不能提交待审核"; } if (!string.IsNullOrEmpty(weldingLocationId) && !db.Base_WeldingLocation.Any(x => x.WeldingLocationId == weldingLocationId)) { return "焊口位置不存在"; } return string.Empty; } } private static Model.HJGL_WeldingDailyTempDetail GetLockedWeldingDailyTempDetail(string tempDetailId) { // 审核事务内锁定状态行,避免并发审核覆盖审核人和状态。 Funs.DB.ExecuteQuery( "SELECT AuditState FROM dbo.HJGL_WeldingDailyTempDetail WITH (UPDLOCK,HOLDLOCK) WHERE TempDetailId={0}", tempDetailId) .FirstOrDefault(); var detail = Funs.DB.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.TempDetailId == tempDetailId); if (detail != null) { Funs.DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, detail); } return detail; } private static bool HasCompleteWelders(Model.HJGL_WeldingDailyTempDetail detail) { return detail != null && !string.IsNullOrEmpty(detail.CoverWelderId) && !string.IsNullOrEmpty(detail.BackingWelderId); } private static void SaveWeldingDailyTempDetail(WeldingDailyTempSaveContext context) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { DateTime startDate = context.WeldingDate.Date; DateTime endDate = startDate.AddDays(1); var existingDetails = db.HJGL_WeldingDailyTempDetail .Where(x => x.WeldJointId == context.Joint.WeldJointId && x.WeldingDate >= startDate && x.WeldingDate < endDate) .ToList(); if (existingDetails.Any(x => x.AuditState == AuditStatePendingProfessional)) { // 状态1已形成班组审核留痕,禁止再次提交生成另一条状态0记录。 throw new InvalidOperationException("焊口【" + context.Joint.WeldJointCode + "】当日记录已完成班组审核,不能重复提交"); } var pending = existingDetails.FirstOrDefault(x => x.AuditState == AuditStatePendingTeam); if (pending == null) { pending = new Model.HJGL_WeldingDailyTempDetail { TempDetailId = Guid.NewGuid().ToString(), WeldJointId = context.Joint.WeldJointId, WeldingDate = context.WeldingDate.Date, AuditState = AuditStatePendingTeam, SubmitDate = DateTime.Now }; db.HJGL_WeldingDailyTempDetail.InsertOnSubmit(pending); } string coverWelderId = context.CoverWelderId; string backingWelderId = context.BackingWelderId; if (context.WelderType.HasValue) { // 移动端支持打底、盖面分次提交,优先保留当前待审核记录已经提交的焊工。 coverWelderId = !string.IsNullOrEmpty(pending.CoverWelderId) ? pending.CoverWelderId : coverWelderId; backingWelderId = !string.IsNullOrEmpty(pending.BackingWelderId) ? pending.BackingWelderId : backingWelderId; if (context.WelderType.Value == 0 || context.WelderType.Value == 2) { coverWelderId = context.SubmitPersonId; } if (context.WelderType.Value == 0 || context.WelderType.Value == 1) { backingWelderId = context.SubmitPersonId; } } pending.ProjectId = !string.IsNullOrEmpty(context.ProjectId) ? context.ProjectId : context.Joint.ProjectId; pending.UnitId = !string.IsNullOrEmpty(context.UnitId) ? context.UnitId : (context.WeldTask != null && !string.IsNullOrEmpty(context.WeldTask.UnitId) ? context.WeldTask.UnitId : context.Joint.UnitId); pending.UnitWorkId = !string.IsNullOrEmpty(context.UnitWorkId) ? context.UnitWorkId : context.Joint.UnitWorkId; pending.CoverWelderId = coverWelderId; pending.BackingWelderId = backingWelderId; pending.JointAttribute = !string.IsNullOrEmpty(context.JointAttribute) ? context.JointAttribute : context.Joint.JointAttribute; pending.WeldingLocationId = !string.IsNullOrEmpty(context.WeldingLocationId) ? context.WeldingLocationId : context.Joint.WeldingLocationId; pending.WeldingMode = !string.IsNullOrEmpty(context.WeldingMode) ? context.WeldingMode : context.Joint.WeldingMode; // 同一焊口可能由打底、盖面分次提交;未传参数时保留已有快照,再回退到焊口当前值。 pending.WeldingMethodId = FirstNotEmpty(context.WeldingMethodId, pending.WeldingMethodId, context.Joint.WeldingMethodId); pending.WeldTypeId = FirstNotEmpty(context.WeldTypeId, pending.WeldTypeId, context.Joint.WeldTypeId); pending.WeldingWire = FirstNotEmpty(context.WeldingWire, pending.WeldingWire, context.Joint.WeldingWire); pending.WeldingRod = FirstNotEmpty(context.WeldingRod, pending.WeldingRod, context.Joint.WeldingRod); pending.SubmitPersonId = context.SubmitPersonId; pending.SubmitDate = DateTime.Now; db.SubmitChanges(); } } private static string ValidatePendingWeldingParameters(string weldingMethodId, string weldTypeId, string weldingWire, string weldingRod) { using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { if (!string.IsNullOrWhiteSpace(weldingMethodId) && !db.Base_WeldingMethod.Any(x => x.WeldingMethodId == weldingMethodId)) { return "焊接方法不存在"; } if (!string.IsNullOrWhiteSpace(weldTypeId) && !db.Base_WeldType.Any(x => x.WeldTypeId == weldTypeId)) { return "焊缝类型不存在"; } if (!string.IsNullOrWhiteSpace(weldingWire) && !db.Base_Consumables.Any(x => x.ConsumablesId == weldingWire && x.ConsumablesType == "1")) { return "焊丝不存在或焊材类型不正确"; } if (!string.IsNullOrWhiteSpace(weldingRod) && !db.Base_Consumables.Any(x => x.ConsumablesId == weldingRod && x.ConsumablesType == "2")) { return "焊条不存在或焊材类型不正确"; } return string.Empty; } } private static string NormalizeOptionalId(string value) { return string.IsNullOrWhiteSpace(value) ? null : value.Trim(); } private static string FirstNotEmpty(params string[] values) { return values == null ? null : values.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x)); } private static Model.HJGL_WeldingDaily GetOrCreateWeldingDailyByTempDetail( Model.HJGL_WeldingDailyTempDetail tempDetail) { var weldingDaily = Funs.DB.HJGL_WeldingDaily.FirstOrDefault(x => x.UnitWorkId == tempDetail.UnitWorkId && x.WeldingDate >= tempDetail.WeldingDate.Date && x.WeldingDate < tempDetail.WeldingDate.Date.AddDays(1)); if (weldingDaily != null) { return weldingDaily; } var submitUnitwork = Funs.DB.WBS_UnitWork.FirstOrDefault(x => x.UnitWorkId == tempDetail.UnitWorkId); string unitWorkName = submitUnitwork != null ? submitUnitwork.UnitWorkName : string.Empty; string perfix = string.Format("{0:yyyyMMdd}", tempDetail.WeldingDate) + "-" + unitWorkName + "-"; // 直接读取当前最大编号并在内存中生成三位流水号,不再调用 SpGetThreeNumber。 string maxNumber = Funs.DB.HJGL_WeldingDaily .Where(x => x.ProjectId == tempDetail.ProjectId && x.WeldingDailyCode != null && x.WeldingDailyCode.StartsWith(perfix)) .Select(x => x.WeldingDailyCode) .OrderByDescending(x => x) .FirstOrDefault(); weldingDaily = new Model.HJGL_WeldingDaily { WeldingDailyId = Guid.NewGuid().ToString(), WeldingDailyCode = Funs.GetThreeNumber(maxNumber, perfix), WeldingDate = tempDetail.WeldingDate.Date, ProjectId = tempDetail.ProjectId, UnitWorkId = tempDetail.UnitWorkId, UnitId = tempDetail.UnitId, Tabler = tempDetail.SubmitPersonId, TableDate = tempDetail.WeldingDate.Date, Remark = "焊接日报待审核通过" }; BLL.WeldingDailyService.AddWeldingDaily(weldingDaily); return weldingDaily; } private static string NormalizeNullValue(string value) { return value == Const._Null ? null : value; } /// /// 日报明细插入(更新焊口信息),组批等 /// /// 焊口ID /// 盖面焊工ID /// 打底焊工ID /// 焊口属性 /// 焊接日期 /// 组批条件 /// 是否保存 /// 日报ID /// 项目ID /// 焊接位置ID /// 错误信息 private static string InsertWeldingDailyItem(string weldJointId, string coverWelderId, string backingWelderId, string jointAttribute, DateTime? weldingDate, string batchCondition, bool isSave, string weldingDailyId, string projectId, string weldingLocationId, SqlConnection sharedConnection) { string errlog = string.Empty; var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId); if (newWeldJoint == null) { return "焊口不存在;"; } var pipeline = BLL.PipelineService.GetPipelineByPipelineId(newWeldJoint.PipelineId); var weldingDaily = BLL.WeldingDailyService.GetPipeline_WeldingDailyByWeldingDailyId(weldingDailyId); if (pipeline == null || weldingDaily == null) { return "焊口关联管线或日报不存在;"; } if (!string.IsNullOrEmpty(coverWelderId) && !string.IsNullOrEmpty(backingWelderId)) { if (isSave) { newWeldJoint.WeldingDailyId = weldingDailyId; newWeldJoint.WeldingDailyCode = weldingDaily.WeldingDailyCode; newWeldJoint.CoverWelderId = coverWelderId; newWeldJoint.BackingWelderId = backingWelderId; newWeldJoint.CoverWelderTeamGroupId = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(pipeline.ProjectId, coverWelderId)?.TeamGroupId; newWeldJoint.BackingWelderTeamGroupId = SitePerson_PersonService.GetSitePersonByProjectIdPersonId(pipeline.ProjectId, backingWelderId)?.TeamGroupId; if (!string.IsNullOrEmpty(weldingLocationId)) { newWeldJoint.WeldingLocationId = weldingLocationId; } newWeldJoint.JointAttribute = jointAttribute; BLL.WeldJointService.UpdateWeldJoint(newWeldJoint); // 更新焊口号 修改固定焊口号后 +G BLL.WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd); errlog = PointBatchService.AddBatchByWeldJointId( weldJointId, weldingDate, batchCondition, sharedConnection);//自动组批 } } else { errlog = "焊口" + "【" + newWeldJoint.WeldJointCode + "】" + "未选择焊工"; } return errlog; } #endregion /// /// 日报明细删除 /// /// /// public static string DeleteWeldingDailyItemByweldJointId(string weldJointId) { string errlog = string.Empty; var newWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId); var pipeline = BLL.PipelineService.GetPipelineByPipelineId(newWeldJoint.PipelineId); if (newWeldJoint != null && !string.IsNullOrEmpty(newWeldJoint.WeldingDailyId)) { var isTrust = from x in Funs.DB.HJGL_Batch_BatchTrustItem where x.WeldJointId == weldJointId select x; ; if (isTrust.Count() == 0) { var updateWeldJoint = BLL.WeldJointService.GetWeldJointByWeldJointId(weldJointId); if (updateWeldJoint != null) { updateWeldJoint.WeldingDailyId = null; updateWeldJoint.WeldingDailyCode = null; updateWeldJoint.CoverWelderId = null; updateWeldJoint.BackingWelderId = null; BLL.WeldJointService.UpdateWeldJoint(updateWeldJoint); var weldTask = BLL.WeldTaskService.GetWeldTaskByWeldJointId(weldJointId); if (weldTask != null) { weldTask.CoverWelderId = null; weldTask.BackingWelderId = null; BLL.WeldTaskService.UpdateWeldTask(weldTask); } var pointBatchItems = from x in Funs.DB.HJGL_Batch_PointBatchItem where x.WeldJointId == weldJointId select x; string pointBatchId = pointBatchItems.FirstOrDefault().PointBatchId; // 删除焊口所在批明细信息 BLL.PointBatchDetailService.DeleteBatchDetail(weldJointId); // 删除批信息 var batch = from x in Funs.DB.HJGL_Batch_PointBatchItem where x.PointBatchId == pointBatchId select x; if (pointBatchId != null && batch.Count() == 0) { BLL.PointBatchService.DeleteBatch(pointBatchId); } } } else { errlog += "焊口【" + newWeldJoint.WeldJointCode + "】已进委托单了,不能删除。"; } } return errlog; } /// /// 按类型获取焊接日报项 /// /// /// public static List GetPipeline_WeldingDailyList(string unitId) { var list = (from x in Funs.DB.HJGL_WeldingDaily where x.UnitId == unitId orderby x.WeldingDailyCode select x).ToList(); return list; } public static List GetPipelineDailyListByUnitWorkId(string UnitWorkId) { var list = (from x in Funs.DB.HJGL_WeldingDaily where x.UnitWorkId == UnitWorkId orderby x.WeldingDailyCode select x).ToList(); return list; } /// /// 获取焊接日志导出数据;传日报ID时导出单份日报,否则按单位工程和月份导出。 /// /// 项目ID /// 单位工程ID /// 焊接日报ID /// 月份,格式为yyyy-MM /// 仅包含俄文表头和业务数据的焊接日志 public static DataTable GetWeldingLogExportData(string projectId, string unitWorkId, string weldingDailyId, string month) { if (string.IsNullOrWhiteSpace(projectId) || (string.IsNullOrWhiteSpace(unitWorkId) && string.IsNullOrWhiteSpace(weldingDailyId))) { return new DataTable(); } DateTime monthStart = DateTime.MinValue; if (string.IsNullOrWhiteSpace(weldingDailyId) && !DateTime.TryParse(month + "-01", out monthStart)) { return new DataTable(); } string condition; var parameters = new List { new SqlParameter("@ProjectId", projectId) }; if (!string.IsNullOrWhiteSpace(weldingDailyId)) { condition = "jot.WeldingDailyId = @WeldingDailyId"; parameters.Add(new SqlParameter("@WeldingDailyId", weldingDailyId)); } else { condition = @"jot.UnitWorkId = @UnitWorkId AND jot.WeldingDateD >= @MonthStart AND jot.WeldingDateD < @NextMonth"; parameters.Add(new SqlParameter("@UnitWorkId", unitWorkId)); parameters.Add(new SqlParameter("@MonthStart", monthStart.Date)); parameters.Add(new SqlParameter("@NextMonth", monthStart.Date.AddMonths(1))); } // 俄文日志列横跨焊口、日报、外观、热处理、硬度和无损检测,统一在服务层完成映射,页面仅负责下载。 string sql = @" SELECT ROW_NUMBER() OVER (ORDER BY jot.WeldingDateD, jot.PipelineCode, jot.WeldJointCode) AS C01, CONCAT(jot.PipelineCode, '/', jot.WeldJointCode, CASE WHEN ISNULL(jot.WeldTypeCode, '') = '' THEN '' ELSE ', ' + jot.WeldTypeCode END) AS C02, CASE WHEN welder.BackingDisplay = welder.CoverDisplay THEN welder.BackingDisplay WHEN welder.BackingDisplay = '' THEN welder.CoverDisplay WHEN welder.CoverDisplay = '' THEN welder.BackingDisplay ELSE welder.BackingDisplay + CHAR(10) + welder.CoverDisplay END AS C03, REPLACE(ISNULL(jot.MaterialCode, ''), '/', ' / ') AS C04, REPLACE(REPLACE( COALESCE(NULLIF(jot.Specification, ''), CONCAT(CONVERT(varchar(30), jot.Dia), N'×', CONVERT(varchar(30), jot.Thickness))), N'Φ', ''), '*', N'×') AS C05, CONVERT(varchar(10), jot.WeldingDateD, 104) AS C06, ISNULL(jot.WeldingMethodCode, '') AS C07, CONCAT( CASE WHEN ISNULL(jot.WeldingWireCode, '') = '' THEN '' ELSE jot.WeldingWireCode + CASE WHEN ISNULL(wire.Standard, '') = '' THEN '' ELSE ' (' + wire.Standard + ')' END END, CASE WHEN ISNULL(jot.WeldingWireCode, '') = '' OR ISNULL(jot.WeldingRodCode, '') = '' THEN '' ELSE CHAR(10) END, CASE WHEN ISNULL(jot.WeldingRodCode, '') = '' THEN '' ELSE jot.WeldingRodCode + CASE WHEN ISNULL(rod.Standard, '') = '' THEN '' ELSE ' (' + rod.Standard + ')' END END) AS C08, CASE WHEN appearance.PreheatTemperature IS NULL AND appearance.InterpassTemperature IS NULL THEN CASE WHEN ISNULL(jot.PreTemperature, '') = '' THEN '' ELSE jot.PreTemperature + N' °C' END WHEN appearance.InterpassTemperature IS NULL THEN CONCAT(CONVERT(varchar(30), appearance.PreheatTemperature), N' °C') WHEN appearance.PreheatTemperature IS NULL THEN CONCAT(CONVERT(varchar(30), appearance.InterpassTemperature), N' °C') ELSE CONCAT(CONVERT(varchar(30), appearance.PreheatTemperature), ' / ', CONVERT(varchar(30), appearance.InterpassTemperature), N' °C') END AS C09, N'' AS C10, N'' AS C11, N'' AS C12, ISNULL(hotProcess.RecordChartNo, '') AS C13, CONCAT( CASE WHEN hardness.HardNessValue1 IS NULL THEN '' ELSE CONVERT(varchar(20), hardness.HardNessValue1) END, CASE WHEN hardness.HardNessValue2 IS NULL THEN '' ELSE '/' + CONVERT(varchar(20), hardness.HardNessValue2) END, CASE WHEN hardness.HardNessValue3 IS NULL THEN '' ELSE '/' + CONVERT(varchar(20), hardness.HardNessValue3) END, CASE WHEN ISNULL(hardness.HardReportNo, '') = '' THEN '' ELSE ', ' + RTRIM(hardness.HardReportNo) END, CASE WHEN hardness.ReportDate IS NULL THEN '' ELSE ', ' + CONVERT(varchar(10), hardness.ReportDate, 104) END) AS C14, CASE WHEN appearance.IsQualified = 1 THEN N'Годен' WHEN appearance.IsQualified = 0 THEN N'Не годен' ELSE N'' END AS C15, ISNULL(ndt.ResultText, '') AS C16, N'' AS C17 FROM dbo.View_HJGL_WeldJoint AS jot LEFT JOIN dbo.Base_Consumables AS wire ON wire.ConsumablesId = jot.WeldingWire LEFT JOIN dbo.Base_Consumables AS rod ON rod.ConsumablesId = jot.WeldingRod OUTER APPLY ( SELECT CONCAT(ISNULL(jot.BackingWelderName, ''), CASE WHEN ISNULL(jot.BackingWelderCode, '') = '' THEN '' ELSE ' (' + jot.BackingWelderCode + ')' END) AS BackingDisplay, CONCAT(ISNULL(jot.CoverWelderName, ''), CASE WHEN ISNULL(jot.CoverWelderCode, '') = '' THEN '' ELSE ' (' + jot.CoverWelderCode + ')' END) AS CoverDisplay ) AS welder OUTER APPLY ( SELECT TOP 1 checkItem.IsQualified, checkItem.PreheatTemperature, checkItem.InterpassTemperature FROM dbo.HJGL_WeldAppearanceCheck AS checkItem WHERE checkItem.WeldJointId = jot.WeldJointId ORDER BY checkItem.CheckTime DESC, checkItem.CreateTime DESC, checkItem.AppearanceCheckId DESC ) AS appearance OUTER APPLY ( SELECT TOP 1 report.RecordChartNo FROM dbo.HJGL_HotProess_TrustItem AS trustItem LEFT JOIN dbo.HJGL_HotProess_Report AS report ON report.HotProessTrustItemId = trustItem.HotProessTrustItemId WHERE trustItem.WeldJointId = jot.WeldJointId ORDER BY report.ProessDate DESC, report.HotProessReportId DESC ) AS hotProcess OUTER APPLY ( SELECT TOP 1 report.HardReportNo, report.HardNessValue1, report.HardNessValue2, report.HardNessValue3, hardTrust.ReportDate FROM dbo.HJGL_Hard_TrustItem AS hardItem LEFT JOIN dbo.HJGL_Hard_Report AS report ON report.HardTrustItemID = hardItem.HardTrustItemID LEFT JOIN dbo.HJGL_Hard_Trust AS hardTrust ON hardTrust.HardTrustID = hardItem.HardTrustID WHERE hardItem.WeldJointId = jot.WeldJointId ORDER BY hardTrust.ReportDate DESC, report.SortIndex, report.HardReportId DESC ) AS hardness OUTER APPLY ( SELECT STUFF(( SELECT CHAR(10) + CONCAT(ISNULL(detectionType.DetectionTypeCode, ''), CASE ndeItem.CheckResult WHEN '1' THEN N': Годен' WHEN '2' THEN N': Не годен' ELSE '' END, CASE WHEN ISNULL(ndeItem.NDEReportNo, nde.NDECode) IS NULL THEN '' ELSE ', ' + ISNULL(ndeItem.NDEReportNo, nde.NDECode) END, CASE WHEN ndeItem.ReportDate IS NULL THEN '' ELSE ', ' + CONVERT(varchar(10), ndeItem.ReportDate, 104) END) FROM dbo.HJGL_Batch_BatchTrustItem AS trustItem INNER JOIN dbo.HJGL_Batch_NDEItem AS ndeItem ON ndeItem.TrustBatchItemId = trustItem.TrustBatchItemId LEFT JOIN dbo.HJGL_Batch_NDE AS nde ON nde.NDEID = ndeItem.NDEID LEFT JOIN dbo.Base_DetectionType AS detectionType ON detectionType.DetectionTypeId = ndeItem.DetectionTypeId WHERE trustItem.WeldJointId = jot.WeldJointId ORDER BY ndeItem.ReportDate, ndeItem.NDEItemID FOR XML PATH(''), TYPE).value('.', 'nvarchar(max)'), 1, 1, '') AS ResultText ) AS ndt WHERE jot.ProjectId = @ProjectId AND " + condition; DataTable table = SQLHelper.GetDataTableRunText(sql, parameters.ToArray()); string[] headers = { "№\r\nп/п", "Обозначение сварного соединения по исполнительному чертежу, тип сварного соединения ГОСТ 16037", "Ф.И.О.\r\nсварщика,\r\nличное\r\nклеймо", "Марка стали (композиция марок\r\nсталей), НД, №№ сертификатов", "Наружный диаметр элемента трубопровода и толщина стенки Dн×S, мм", "Дата сварки, температурные условия в рабочей зоне,°С", "Способ\r\nсварки", "Сварочные материалы (марка электрода, сварочной проволоки, защитный газ, флюс), НД, №№ сертификатов", "Режим\r\nпредварительного и\r\nсопутствующего\r\nподогрева", "Отметка о контроле\r\nкорня\r\nшва", "Стилоскопирование металла шва,\r\n№ заключения, дата", "Ф.И.О. оператора- термиста, личное клеймо", "№ диаграммы по журналу термообработки сварных соединений", "Твердость металла шва, № заключения, дата", "Отметка о годности сварного соединения по внешнему осмотру и измерениям", "Способ и результаты неразрушающего контроля сварного соединения, № заключения, дата", "Результаты измерения ферритной фазы в металле шва, № заключения, дата" }; for (int i = 0; i < headers.Length; i++) { table.Columns[i].ColumnName = headers[i]; } return table; } public static Dictionary GetFileOutValueById(string WeldingDailyId) { var value = new Dictionary(); string strSql = @" SELECT PipelineCode as '管线号', (case when charindex('/',WeldJointCode)>0 then RIGHT(WeldJointCode,CHARINDEX('/',REVERSE(WeldJointCode))-1) else WeldJointCode end) as '焊口序号', WeldJointCode as '焊口号', BackingWelderCode as '打底焊工', BackingWelderTeamGroupName as '打底焊工班组', CoverWelderCode as '盖面焊工', CoverWelderTeamGroupName as '盖面焊工班组', Material1Code as '材质1' , Material2Code as '材质2' , Dia as '外径' , DNDia as 'DN公称直径', Thickness as '壁厚' , WeldTypeCode as '焊缝类型' , WeldingMethodCode as '焊接方法' , WeldingWireCode as '焊丝' , WeldingMode as '焊口机动化程度' , WeldingRodCode as '焊条' , Size as '达因' FROM dbo.View_HJGL_WeldJoint WHERE WeldingDailyId=@WeldingDailyId"; List listStr = new List(); listStr.Add(new SqlParameter("@WeldingDailyId", WeldingDailyId)); SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); var WeldingDailyCode = (from x in Funs.DB.HJGL_WeldingDaily where x.WeldingDailyId == WeldingDailyId select x.WeldingDailyCode).FirstOrDefault(); if (!string.IsNullOrEmpty(WeldingDailyCode)) { value.Add(WeldingDailyCode, tb); } return value; } public static Dictionary GetFileOutValueByUnitWorkId(string UnitWorkId, string Month) { var value = new Dictionary(); var p = from x in Funs.DB.HJGL_WeldingDaily where x.UnitWorkId == UnitWorkId && x.WeldingDate < Convert.ToDateTime(Month + "-01").AddMonths(1) && x.WeldingDate >= Convert.ToDateTime(Month + "-01") orderby x.WeldingDailyCode descending select x; if (p.Count() > 0) { foreach (var item in p) { var detail = GetFileOutValueById(item.WeldingDailyId); value.Add(detail.Keys.First(), detail.Values.First()); } } return value; } #region 焊接日报下拉项 /// /// 焊接日报下拉项 /// /// 下拉框名称 /// 是否显示请选择 /// 耗材类型 public static void InitDropDownListByUnitId(FineUIPro.DropDownList dropName, bool isShowPlease, string unitId) { dropName.DataValueField = "WeldingDailyId"; dropName.DataTextField = "WeldingDailyCode"; dropName.DataSource = GetPipeline_WeldingDailyList(unitId); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } public static void InitDownListByUnitWortId(FineUIPro.DropDownList dropName, bool isShowPlease, string UnitWortId) { dropName.DataValueField = "WeldingDailyId"; dropName.DataTextField = "WeldingDailyCode"; dropName.DataSource = GetPipelineDailyListByUnitWorkId(UnitWortId); dropName.DataBind(); if (isShowPlease) { Funs.FineUIPleaseSelect(dropName); } } #endregion } }