Files
SGGL_SHJ/SGGL/BLL/HJGL/WeldingManage/WeldingDailyService.cs
T
lpf 42787c1520 feat(hjgl): 完善焊接日报审核与页面展示
统一 PC 端与接口的待审核查询、状态筛选和分页逻辑,补充日报查询参数及焊接信息展示,并调整试压包和焊口列表页面。
2026-08-20 10:47:12 +08:00

1398 lines
70 KiB
C#

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; }
}
/// <summary>
///获取焊接日报信息
/// </summary>
/// <returns></returns>
public static Model.HJGL_WeldingDaily GetPipeline_WeldingDailyByWeldingDailyId(string WeldingDailyId)
{
return Funs.DB.HJGL_WeldingDaily.FirstOrDefault(e => e.WeldingDailyId == WeldingDailyId);
}
/// <summary>
/// 根据焊接日报主键获取焊接日报信息
/// </summary>
/// <param name="weldReportNo">焊接日报编号</param>
/// <returns>焊接日报信息</returns>
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;
}
}
/// <summary>
/// 根据焊接日报Id获取焊接日报明细信息
/// </summary>
/// <param name="ManagerTotalId"></param>
/// <returns></returns>
public static List<Model.SpWeldingDailyItem> GetWeldingDailyItem(string weldingDailyId)
{
List<Model.SpWeldingDailyItem> returnViewMatch = new List<Model.SpWeldingDailyItem>();
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;
}
/// <summary>
/// 查找后返回集合增加到列表集团中
/// </summary>
/// <param name="hdItemsString"></param>
/// <returns></returns>
public static List<Model.SpWeldingDailyItem> GetWeldReportAddItem(string hdString)
{
List<Model.SpWeldingDailyItem> returnViewMatch = new List<Model.SpWeldingDailyItem>(); //= getWeldReportItem;
if (!string.IsNullOrEmpty(hdString))
{
List<string> totallist = Funs.GetStrListByStr(hdString, '@');
foreach (var hdItemsString in totallist)
{
List<string> list = Funs.GetStrListByStr(hdItemsString, '#');
if (list.Count() == 4)
{
string CoverWelderCode = string.Empty; //盖面焊工号
string BackingWelderCode = string.Empty; //打底焊工号
string welderLists = list[0];
List<string> 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<string> 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;
}
/// <summary>
/// 获取未焊接焊口信息
/// </summary>
/// <param name="ManagerTotalId"></param>
/// <returns></returns>
public static List<Model.SpWeldingDailyItem> GetWeldReportItemFind(string weldingDailyId, string pipelineId)
{
List<Model.SpWeldingDailyItem> returnViewMatch = new List<Model.SpWeldingDailyItem>();
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;
}
/// <summary>
/// 增加焊接日报信息
/// </summary>
/// <param name="WeldingDaily"></param>
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();
}
/// <summary>
/// 修改焊接日报信息
/// </summary>
/// <param name="WeldingDaily"></param>
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();
}
}
/// <summary>
/// 根据焊接日报Id删除一个焊接日报信息
/// </summary>
/// <param name="WeldingDailyId"></param>
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
/// <summary>
/// 获取焊接日报待审核明细列表。
/// </summary>
/// <param name="projectId">项目ID</param>
/// <param name="unitWorkId">单位工程ID,为空时不按单位工程过滤</param>
/// <param name="weldingDate">焊接日期,为空时不按日期过滤</param>
/// <param name="pipelineCode">管线编号关键字</param>
/// <param name="welderCode">焊工编号关键字</param>
/// <returns>待审核明细列表</returns>
public static List<Model.WeldingDailyTempDetailItem> GetWeldingDailyTempDetailList(string projectId,
string unitWorkId, DateTime? weldingDate, string pipelineCode, string welderCode)
{
if (string.IsNullOrEmpty(projectId))
{
return new List<Model.WeldingDailyTempDetailItem>();
}
int totalCount;
return GetWeldingDailyTempDetailList(new Model.WeldingDailyTempDetailInput
{
ProjectId = projectId,
UnitWorkId = unitWorkId,
WeldingDate = weldingDate,
PipelineCode = pipelineCode,
WelderCode = welderCode
}, out totalCount);
}
/// <summary>
/// 按查询参数获取焊接日报待审核明细列表。
/// </summary>
/// <param name="input">查询及分页条件</param>
/// <param name="totalCount">分页前总记录数</param>
/// <returns>待审核明细列表</returns>
public static List<Model.WeldingDailyTempDetailItem> GetWeldingDailyTempDetailList(
Model.WeldingDailyTempDetailInput input, out int totalCount)
{
return QueryPendingWeldingDailyTempDetails(input, out totalCount);
}
/// <summary>
/// 获取单条焊接日报待审核明细。
/// </summary>
/// <param name="tempDetailId">待审核明细ID</param>
/// <returns>待审核明细,不存在时返回空</returns>
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();
}
/// <summary>
/// 构造待审核查询。PC端列表和接口列表、明细均从这里读取,确保字段映射和待审核状态一致。
/// </summary>
/// <param name="input">查询及分页条件</param>
/// <param name="totalCount">分页前总记录数</param>
private static List<Model.WeldingDailyTempDetailItem> 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<Model.WeldingDailyTempDetailItem>();
}
List<Model.WeldingDailyTempDetailItem> 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;
}
/// <summary>
/// 按待审核明细ID批量回写焊前、焊后附件地址。
/// </summary>
private static void SetWeldingDailyTempDetailAttachUrls(List<Model.WeldingDailyTempDetailItem> data)
{
if (data == null || data.Count == 0)
{
return;
}
var toKeyIds = data.SelectMany(x => new[]
{
x.TempDetailId + "#Before",
x.TempDetailId + "#After"
}).ToList();
Dictionary<string, string> 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('\\', '/');
}
/// <summary>
/// 移动端按焊口保存焊接日报待审核明细
/// </summary>
/// <param name="weldJointId">焊口ID</param>
/// <param name="personId">提交焊工ID</param>
/// <param name="time">焊接日期</param>
/// <param name="weldingLocationId">焊接位置ID</param>
/// <param name="welderType">焊工类型 0 全部 1 打底 2 盖面</param>
/// <returns>错误信息</returns>
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);
}
/// <summary>
/// 移动端按焊口保存焊接日报待审核明细及实际焊接工艺快照。
/// </summary>
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;
}
/// <summary>
/// Web端保存焊接日报待审核明细
/// </summary>
/// <param name="weldJointId">焊口ID</param>
/// <param name="submitPersonId">提交人ID</param>
/// <param name="weldingDate">焊接日期</param>
/// <param name="coverWelderId">盖面焊工ID</param>
/// <param name="backingWelderId">打底焊工ID</param>
/// <param name="jointAttribute">焊口属性</param>
/// <param name="weldingLocationId">焊接位置ID</param>
/// <param name="projectId">项目ID</param>
/// <param name="unitId">单位ID</param>
/// <param name="unitWorkId">单位工程ID</param>
/// <param name="weldingMode">焊接模式</param>
/// <returns>错误信息</returns>
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;
}
/// <summary>
/// 班组审核焊接日报待审核明细,只记录班组审核留痕,不生成正式日报。
/// </summary>
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;
}
/// <summary>
/// 专工审核通过焊接日报待审核明细,并生成正式日报及热处理委托。
/// </summary>
/// <param name="tempDetailIds">待审核明细ID集合</param>
/// <param name="auditMan">审核人</param>
/// <returns>错误信息</returns>
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;
}
/// <summary>
/// 删除未审核的焊接日报待审核明细
/// </summary>
/// <param name="tempDetailIds">待审核明细ID集合</param>
/// <returns>错误信息</returns>
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;
}
/// <summary>
/// 将需要热处理的焊口归入焊接完成日期当天的自动热处理委托。
/// </summary>
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<string>(
"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<int>(
"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 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;
}
/// <summary>
/// 日报明细插入(更新焊口信息),组批等
/// </summary>
/// <param name="weldJointId">焊口ID</param>
/// <param name="coverWelderId">盖面焊工ID</param>
/// <param name="backingWelderId">打底焊工ID</param>
/// <param name="jointAttribute">焊口属性</param>
/// <param name="weldingDate">焊接日期</param>
/// <param name="batchCondition">组批条件</param>
/// <param name="isSave">是否保存</param>
/// <param name="weldingDailyId">日报ID</param>
/// <param name="projectId">项目ID</param>
/// <param name="weldingLocationId">焊接位置ID</param>
/// <returns>错误信息</returns>
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
/// <summary>
/// 日报明细删除
/// </summary>
/// <param name="weldJointId"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 按类型获取焊接日报项
/// </summary>
/// <param name="WeldingDailyType"></param>
/// <returns></returns>
public static List<Model.HJGL_WeldingDaily> 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<Model.HJGL_WeldingDaily> GetPipelineDailyListByUnitWorkId(string UnitWorkId)
{
var list = (from x in Funs.DB.HJGL_WeldingDaily
where x.UnitWorkId == UnitWorkId
orderby x.WeldingDailyCode
select x).ToList();
return list;
}
public static Dictionary<string, object> GetFileOutValueById(string WeldingDailyId)
{
var value = new Dictionary<string, object>();
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<SqlParameter> listStr = new List<SqlParameter>();
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<string, object> GetFileOutValueByUnitWorkId(string UnitWorkId, string Month)
{
var value = new Dictionary<string, object>();
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
/// <summary>
/// 焊接日报下拉项
/// </summary>
/// <param name="dropName">下拉框名称</param>
/// <param name="isShowPlease">是否显示请选择</param>
/// <param name="WeldingDailyType">耗材类型</param>
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
}
}