feat(hjgl): 完善焊接任务与质量管理流程

This commit is contained in:
2026-08-19 17:13:33 +08:00
parent 08792e0dc8
commit 679e9f6cec
68 changed files with 2481 additions and 1170 deletions
@@ -53,6 +53,7 @@ namespace BLL
WeldJointCode = x.w.WeldJointCode,
CuttingLength = x.c.CuttingLength,
GrooveForm = x.c.GrooveForm,
GrooveProcessType = x.c.GrooveProcessType,
GrooveAngle = x.c.GrooveAngle,
IsMaterialCodeBatchNoAccurate = x.c.IsMaterialCodeBatchNoAccurate,
IsMaterialQuantityAccurate = x.c.IsMaterialQuantityAccurate,
@@ -87,8 +88,6 @@ namespace BLL
{
var query = from f in db.HJGL_PreWeldFitupCheck
join w in db.HJGL_WeldJoint on f.WeldJointId equals w.WeldJointId
join g in db.Base_GrooveType on f.GrooveTypeId equals g.GrooveTypeId into grooveTypes
from g in grooveTypes.DefaultIfEmpty()
join p in db.Person_Persons on f.CheckPerson equals p.PersonId into persons
from p in persons.DefaultIfEmpty()
where string.IsNullOrEmpty(projectId) || f.ProjectId == projectId || w.ProjectId == projectId
@@ -96,7 +95,6 @@ namespace BLL
{
f,
w,
g,
CheckPersonName = p == null ? string.Empty : p.PersonName
};
@@ -120,17 +118,8 @@ namespace BLL
WeldJointId = x.f.WeldJointId,
PipelineCode = x.w.PipelineCode,
WeldJointCode = x.w.WeldJointCode,
GrooveTypeId = x.f.GrooveTypeId,
GrooveTypeCode = x.g == null ? string.Empty : x.g.GrooveTypeCode,
GrooveTypeName = x.g == null ? string.Empty : x.g.GrooveTypeName,
GrooveProcessType = x.f.GrooveProcessType,
GrooveAngle = x.f.GrooveAngle,
FitupGap = x.f.FitupGap,
Misalignment = x.f.Misalignment,
WeldReinforcement = x.f.WeldReinforcement,
WeldHeight = x.f.WeldHeight,
WeldWidth = x.f.WeldWidth,
SurfaceDefect = x.f.SurfaceDefect,
CheckPerson = x.f.CheckPerson,
CheckPersonName = x.CheckPersonName,
CheckTime = x.f.CheckTime,
@@ -218,6 +207,7 @@ namespace BLL
WeldJointCode = w.WeldJointCode,
CuttingLength = c.CuttingLength,
GrooveForm = c.GrooveForm,
GrooveProcessType = c.GrooveProcessType,
GrooveAngle = c.GrooveAngle,
IsMaterialCodeBatchNoAccurate = c.IsMaterialCodeBatchNoAccurate,
IsMaterialQuantityAccurate = c.IsMaterialQuantityAccurate,
@@ -293,6 +283,7 @@ namespace BLL
check.ProjectId = string.IsNullOrEmpty(item.ProjectId) ? weldJoint.ProjectId : item.ProjectId;
check.CuttingLength = item.CuttingLength;
check.GrooveForm = item.GrooveForm;
check.GrooveProcessType = item.GrooveProcessType;
check.GrooveAngle = item.GrooveAngle;
check.IsMaterialCodeBatchNoAccurate = item.IsMaterialCodeBatchNoAccurate;
check.IsMaterialQuantityAccurate = item.IsMaterialQuantityAccurate;
@@ -381,11 +372,6 @@ namespace BLL
{
throw new ArgumentException("焊口ID不能为空。");
}
/* if (string.IsNullOrEmpty(item.GrooveTypeId))
{
throw new ArgumentException("坡口类型不能为空。");
}*/
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var weldJoint = db.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == item.WeldJointId);
@@ -393,11 +379,6 @@ namespace BLL
{
throw new ArgumentException("未找到对应焊口。");
}
/* if (!db.Base_GrooveType.Any(x => x.GrooveTypeId == item.GrooveTypeId))
{
throw new ArgumentException("坡口类型不存在。");
}*/
var check = string.IsNullOrEmpty(item.FitupCheckId)
? null
: db.HJGL_PreWeldFitupCheck.FirstOrDefault(x => x.FitupCheckId == item.FitupCheckId);
@@ -413,15 +394,8 @@ namespace BLL
check.ProjectId = string.IsNullOrEmpty(item.ProjectId) ? weldJoint.ProjectId : item.ProjectId;
check.WeldJointId = item.WeldJointId;
//check.GrooveTypeId = item.GrooveTypeId;
check.GrooveProcessType = item.GrooveProcessType;
check.GrooveAngle = item.GrooveAngle;
check.FitupGap = item.FitupGap;
check.Misalignment = item.Misalignment;
check.WeldReinforcement = item.WeldReinforcement;
check.WeldHeight = item.WeldHeight;
check.WeldWidth = item.WeldWidth;
check.SurfaceDefect = item.SurfaceDefect;
check.CheckPerson = item.CheckPerson;
check.CheckTime = item.CheckTime ?? DateTime.Now;
check.CreateUser = item.CreateUser ?? item.CheckPerson;
@@ -430,10 +404,7 @@ namespace BLL
check.RectifyRequirement = item.RectifyRequirement;
check.Remark = item.Remark;
// 组对检查需要同步回写焊口主表,保证焊口基础信息保持最新
// weldJoint.GrooveTypeId = item.GrooveTypeId;
weldJoint.GrooveProcessType = item.GrooveProcessType;
weldJoint.GrooveAngle = item.GrooveAngle;
// 组对检查只同步组对间隙和错边量。
weldJoint.FitupGap = item.FitupGap;
weldJoint.Misalignment = item.Misalignment;
@@ -602,22 +573,37 @@ namespace BLL
}
/// <summary>
/// 按材料编码获取防腐记录列表
/// 按入库条码获取材料信息及防腐记录列表
/// </summary>
public static List<Model.AntiCorrosionCheckRecordItem> GetAntiCorrosionChecksByMaterialCode(string barCode, string projectId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var normalizedBarCode = string.IsNullOrWhiteSpace(barCode) ? string.Empty : barCode.Trim();
var barCodeMaterial = (from code in db.Tw_InputDetailBarCode
join m in db.HJGL_MaterialCodeLib on code.MaterialCode equals m.MaterialCode into materialJoin
from m in materialJoin.DefaultIfEmpty()
where code.BarCode == normalizedBarCode
select new
{
code.MaterialCode,
Material = m
}).FirstOrDefault();
if (barCodeMaterial == null)
{
return new List<Model.AntiCorrosionCheckRecordItem>();
}
// 先按条码解析材料,再查询检查记录;无检查记录时仍需返回一条材料基础信息供扫码录入使用。
var query = from r in db.HJGL_AntiCorrosionCheckRecord
join m in db.HJGL_MaterialCodeLib on r.MaterialCode equals m.MaterialCode into materialJoin
from m in materialJoin.DefaultIfEmpty()
join code in db.Tw_InputDetailBarCode on m.MaterialCode equals code.MaterialCode into barCodeJoin
from code in barCodeJoin.DefaultIfEmpty()
join paint in db.Tw_PaintCodeDict on r.PaintId equals paint.Id into paintJoin
from paint in paintJoin.DefaultIfEmpty()
join person in db.Person_Persons on r.CheckPerson equals person.PersonId into personJoin
from person in personJoin.DefaultIfEmpty()
where code.BarCode == barCode && (string.IsNullOrEmpty(projectId) || r.ProjectId == projectId)
where r.MaterialCode == barCodeMaterial.MaterialCode &&
(string.IsNullOrEmpty(projectId) || r.ProjectId == projectId)
orderby r.CheckTime descending
select new Model.AntiCorrosionCheckRecordItem
{
@@ -655,9 +641,29 @@ namespace BLL
CreateTime = r.CreateTime
};
var data = query.ToList();
if (data.Count == 0)
{
var material = barCodeMaterial.Material;
data.Add(new Model.AntiCorrosionCheckRecordItem
{
ProjectId = projectId,
MaterialCode = barCodeMaterial.MaterialCode,
MaterialName = material == null ? string.Empty : material.MaterialName,
MaterialSpec = material == null ? string.Empty : material.MaterialSpec,
MaterialMade = material == null ? string.Empty : material.MaterialMade,
MaterialDef = material == null ? string.Empty : material.MaterialDef,
MaterialUnit = material == null ? string.Empty : material.MaterialUnit,
HeatNo = material == null ? string.Empty : material.HeatNo,
BatchNo = material == null ? string.Empty : material.BatchNo,
Code = material == null ? string.Empty : material.Code
});
}
foreach (var item in data)
{
item.AttachUrl1 = GetInspectionAttachUrl(db, Const.Tw_AntiCorrosionCheckRecordMenuId, item.AntiCorrosionCheckId);
if (!string.IsNullOrEmpty(item.AntiCorrosionCheckId))
{
item.AttachUrl1 = GetInspectionAttachUrl(db, Const.Tw_AntiCorrosionCheckRecordMenuId, item.AntiCorrosionCheckId);
}
}
return data;
}
@@ -52,6 +52,7 @@ namespace BLL
.Select(x => new Model.WeldAppearanceCheckItem
{
AppearanceCheckId = x.c.AppearanceCheckId,
CheckCode = x.c.CheckCode,
ProjectId = x.c.ProjectId,
WeldJointId = x.c.WeldJointId,
PipelineCode = x.w.PipelineCode,
@@ -62,6 +63,12 @@ namespace BLL
CheckPersonName = x.CheckPersonName,
CheckTime = x.c.CheckTime,
Remark = x.c.Remark,
WeldReinforcement = x.c.WeldReinforcement,
WeldHeight = x.c.WeldHeight,
WeldWidth = x.c.WeldWidth,
SurfaceDefect = x.c.SurfaceDefect,
PreheatTemperature = x.c.PreheatTemperature,
InterpassTemperature = x.c.InterpassTemperature,
CreateTime = x.c.CreateTime
}).ToList();
PopulateAttachUrls(data);
@@ -164,6 +171,16 @@ namespace BLL
throw new ArgumentException("只能对已焊接焊口进行外观检测。");
}
string unitWorkName = (from pipeline in db.HJGL_Pipeline
join unitWork in db.WBS_UnitWork on pipeline.UnitWorkId equals unitWork.UnitWorkId
where pipeline.PipelineId == joint.PipelineId
select unitWork.UnitWorkName).FirstOrDefault();
if (string.IsNullOrWhiteSpace(unitWorkName))
{
throw new ArgumentException("焊口所属单位工程不存在,无法生成检测编号。");
}
DateTime checkTime = item.CheckTime ?? DateTime.Now;
string id = string.IsNullOrWhiteSpace(item.AppearanceCheckId)
? Guid.NewGuid().ToString()
: item.AppearanceCheckId;
@@ -192,10 +209,18 @@ namespace BLL
check.ProjectId = string.IsNullOrEmpty(item.ProjectId) ? joint.ProjectId : item.ProjectId;
check.WeldJointId = item.WeldJointId;
// 检测编号由单位工程和检测日期统一生成,PC页面与WebAPI保存共用此规则。
check.CheckCode = "FCC-" + unitWorkName.Trim() + "-" + checkTime.ToString("yyyyMMdd");
check.IsQualified = item.IsQualified;
check.CheckPerson = item.CheckPerson;
check.CheckTime = item.CheckTime ?? DateTime.Now;
check.CheckTime = checkTime;
check.Remark = item.Remark;
check.WeldReinforcement = item.WeldReinforcement;
check.WeldHeight = item.WeldHeight;
check.WeldWidth = item.WeldWidth;
check.SurfaceDefect = item.SurfaceDefect;
check.PreheatTemperature = item.PreheatTemperature;
check.InterpassTemperature = item.InterpassTemperature;
db.SubmitChanges();
if (!string.IsNullOrWhiteSpace(item.AttachUrl))
@@ -250,6 +275,7 @@ namespace BLL
select new Model.WeldAppearanceCheckItem
{
AppearanceCheckId = c.AppearanceCheckId,
CheckCode = c.CheckCode,
ProjectId = c.ProjectId,
WeldJointId = c.WeldJointId,
PipelineCode = w.PipelineCode,
@@ -260,6 +286,12 @@ namespace BLL
CheckPersonName = p == null ? string.Empty : p.PersonName,
CheckTime = c.CheckTime,
Remark = c.Remark,
WeldReinforcement = c.WeldReinforcement,
WeldHeight = c.WeldHeight,
WeldWidth = c.WeldWidth,
SurfaceDefect = c.SurfaceDefect,
PreheatTemperature = c.PreheatTemperature,
InterpassTemperature = c.InterpassTemperature,
CreateTime = c.CreateTime
};
}
+132 -1
View File
@@ -112,6 +112,135 @@ namespace BLL
return q.ToList();
}
/// <summary>
/// 按项目、班组查询逻辑任务单;同一TaskCode下的多条焊口记录合并为一张任务单。
/// </summary>
public static List<Model.WeldTaskListItem> GetTaskListByTeamGroup(string projectId, string teamGroupId, string unitWorkId)
{
if (string.IsNullOrWhiteSpace(projectId))
{
return new List<Model.WeldTaskListItem>();
}
var query = Funs.DB.HJGL_WeldTask.Where(x => x.ProjectId == projectId && x.TaskCode != null);
if (!string.IsNullOrWhiteSpace(teamGroupId))
{
query = query.Where(x => x.TeamGroupId == teamGroupId);
}
if (!string.IsNullOrWhiteSpace(unitWorkId))
{
query = query.Where(x => x.UnitWorkId == unitWorkId);
}
var tasks = query.ToList()
.GroupBy(x => new { x.ProjectId, x.TaskCode })
.Select(g =>
{
var first = g.OrderBy(x => x.WeldTaskId).First();
return new Model.WeldTaskListItem
{
ProjectId = g.Key.ProjectId,
TaskCode = g.Key.TaskCode,
UnitWorkId = first.UnitWorkId,
UnitId = first.UnitId,
TaskDate = first.TaskDate,
SerialNumber = first.SerialNumber,
TeamGroupId = g.Select(x => x.TeamGroupId).FirstOrDefault(x => !string.IsNullOrEmpty(x)),
WeldJointCount = g.Select(x => x.WeldJointId).Where(x => x != null).Distinct().Count()
};
})
.OrderByDescending(x => x.TaskDate)
.ThenByDescending(x => x.TaskCode)
.ToList();
var unitWorkIds = tasks.Select(x => x.UnitWorkId).Where(x => x != null).Distinct().ToList();
var unitIds = tasks.Select(x => x.UnitId).Where(x => x != null).Distinct().ToList();
var teamIds = tasks.Select(x => x.TeamGroupId).Where(x => x != null).Distinct().ToList();
var unitWorkMap = Funs.DB.WBS_UnitWork.Where(x => unitWorkIds.Contains(x.UnitWorkId)).ToDictionary(x => x.UnitWorkId, x => x.UnitWorkName);
var unitMap = Funs.DB.Base_Unit.Where(x => unitIds.Contains(x.UnitId)).ToDictionary(x => x.UnitId, x => x.UnitName);
var teamMap = Funs.DB.ProjectData_TeamGroup.Where(x => teamIds.Contains(x.TeamGroupId)).ToDictionary(x => x.TeamGroupId, x => x.TeamGroupName);
foreach (var task in tasks)
{
task.UnitWorkName = task.UnitWorkId != null && unitWorkMap.ContainsKey(task.UnitWorkId) ? unitWorkMap[task.UnitWorkId] : string.Empty;
task.UnitName = task.UnitId != null && unitMap.ContainsKey(task.UnitId) ? unitMap[task.UnitId] : string.Empty;
task.TeamGroupName = task.TeamGroupId != null && teamMap.ContainsKey(task.TeamGroupId) ? teamMap[task.TeamGroupId] : string.Empty;
}
return tasks;
}
public static Model.WeldTaskDetailItem GetTaskDetail(string projectId, string taskCode)
{
var tasks = Funs.DB.HJGL_WeldTask
.Where(x => x.ProjectId == projectId && x.TaskCode == taskCode)
.OrderBy(x => x.PipeLineSortIndex)
.ThenBy(x => x.WeldTaskId)
.ToList();
var first = tasks.FirstOrDefault();
if (first == null) return null;
var summary = GetTaskListByTeamGroup(projectId, null, first.UnitWorkId)
.FirstOrDefault(x => x.TaskCode == taskCode);
if (summary == null) return null;
var jointIds = tasks.Select(x => x.WeldJointId).Where(x => x != null).Distinct().ToList();
var jointMap = Funs.DB.View_HJGL_WeldJoint.Where(x => jointIds.Contains(x.WeldJointId)).ToDictionary(x => x.WeldJointId, x => x);
return new Model.WeldTaskDetailItem
{
ProjectId = first.ProjectId,
TaskCode = summary.TaskCode,
UnitWorkId = summary.UnitWorkId,
UnitWorkName = summary.UnitWorkName,
UnitId = summary.UnitId,
UnitName = summary.UnitName,
TaskDate = summary.TaskDate,
SerialNumber = summary.SerialNumber,
TeamGroupId = summary.TeamGroupId,
TeamGroupName = summary.TeamGroupName,
WeldJointCount = summary.WeldJointCount,
Joints = tasks.Select(x =>
{
Model.View_HJGL_WeldJoint joint = null;
if (!string.IsNullOrEmpty(x.WeldJointId) && jointMap.ContainsKey(x.WeldJointId)) joint = jointMap[x.WeldJointId];
return new Model.WeldTaskJointItem
{
WeldTaskId = x.WeldTaskId,
WeldJointId = x.WeldJointId,
PipelineId = joint == null ? null : joint.PipelineId,
PipelineCode = joint == null ? null : joint.PipelineCode,
WeldJointCode = joint == null ? null : joint.WeldJointCode,
JointAttribute = x.JointAttribute,
WeldingMode = x.WeldingMode,
WeldTypeCode = joint == null ? null : joint.WeldTypeCode,
Size = joint == null ? null : joint.Size,
CoverWelderId = x.CoverWelderId,
BackingWelderId = x.BackingWelderId
};
}).ToList()
};
}
public static void UpdateTaskTeamGroup(string projectId, string taskCode, string teamGroupId)
{
var tasks = Funs.DB.HJGL_WeldTask.Where(x => x.ProjectId == projectId && x.TaskCode == taskCode).ToList();
foreach (var task in tasks)
{
task.TeamGroupId = string.IsNullOrWhiteSpace(teamGroupId) || teamGroupId == Const._Null ? null : teamGroupId;
}
Funs.DB.SubmitChanges();
}
public static void GenerateOutPlanByTaskCode(string projectId, string taskCode, string personId)
{
var task = Funs.DB.HJGL_WeldTask.FirstOrDefault(x => x.ProjectId == projectId && x.TaskCode == taskCode);
if (task == null || !task.TaskDate.HasValue)
{
throw new ArgumentException("焊接任务单不存在或任务日期为空。");
}
// 沿用原方法,TaskCode只负责定位其所需的组合任务参数。
TwInOutplanmasterService.GenOutPlanmasterByWeldTaskId(
task.UnitWorkId, task.UnitId, task.TaskDate.Value, task.SerialNumber, personId);
}
/// <summary>
/// 增加焊接任务单信息
/// </summary>
@@ -139,7 +268,8 @@ namespace BLL
CanWeldingRodName = WeldTask.CanWeldingRodName,
CanWeldingWireName = WeldTask.CanWeldingWireName,
PipeLineSortIndex = WeldTask.PipeLineSortIndex,
SerialNumber = WeldTask.SerialNumber
SerialNumber = WeldTask.SerialNumber,
TeamGroupId = WeldTask.TeamGroupId
};
@@ -172,6 +302,7 @@ namespace BLL
newWeldTask.IsSaved = WeldTask.IsSaved;
newWeldTask.SerialNumber = WeldTask.SerialNumber;
newWeldTask.PipeLineSortIndex = WeldTask.PipeLineSortIndex;
newWeldTask.TeamGroupId = WeldTask.TeamGroupId;
db.SubmitChanges();
}
}
+465 -183
View File
@@ -4,11 +4,37 @@ 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>
@@ -312,34 +338,29 @@ namespace BLL
return new List<Model.WeldingDailyTempDetailItem>();
}
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
var query = QueryPendingWeldingDailyTempDetails().AsQueryable();
query = query.Where(x => x.ProjectId == projectId);
if (!string.IsNullOrEmpty(unitWorkId))
{
var query = QueryPendingWeldingDailyTempDetails(db);
query = query.Where(x => x.ProjectId == projectId);
if (!string.IsNullOrEmpty(unitWorkId))
{
query = query.Where(x => x.UnitWorkId == unitWorkId);
}
if (weldingDate.HasValue)
{
DateTime startDate = weldingDate.Value.Date;
DateTime endDate = startDate.AddDays(1);
query = query.Where(x => x.WeldingDate >= startDate && x.WeldingDate < endDate);
}
if (!string.IsNullOrEmpty(pipelineCode))
{
query = query.Where(x => x.PipelineCode != null && x.PipelineCode.Contains(pipelineCode));
}
if (!string.IsNullOrEmpty(welderCode))
{
query = query.Where(x => (x.CoverWelderCode != null && x.CoverWelderCode.Contains(welderCode))
|| (x.BackingWelderCode != null && x.BackingWelderCode.Contains(welderCode)));
}
var data = query.OrderBy(x => x.PipelineCode).ThenBy(x => x.WeldJointCode).ToList();
SetWeldingDailyTempDetailAttachUrls(db, data);
return data;
query = query.Where(x => x.UnitWorkId == unitWorkId);
}
if (weldingDate.HasValue)
{
DateTime startDate = weldingDate.Value.Date;
DateTime endDate = startDate.AddDays(1);
query = query.Where(x => x.WeldingDate >= startDate && x.WeldingDate < endDate);
}
if (!string.IsNullOrEmpty(pipelineCode))
{
query = query.Where(x => x.PipelineCode != null && x.PipelineCode.Contains(pipelineCode));
}
if (!string.IsNullOrEmpty(welderCode))
{
query = query.Where(x => (x.CoverWelderCode != null && x.CoverWelderCode.Contains(welderCode))
|| (x.BackingWelderCode != null && x.BackingWelderCode.Contains(welderCode)));
}
return query.OrderBy(x => x.PipelineCode).ThenBy(x => x.WeldJointCode).ToList();
}
/// <summary>
@@ -354,24 +375,19 @@ namespace BLL
return null;
}
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var data = QueryPendingWeldingDailyTempDetails(db)
.Where(x => x.TempDetailId == tempDetailId)
.Take(1)
.ToList();
SetWeldingDailyTempDetailAttachUrls(db, data);
return data.FirstOrDefault();
}
return QueryPendingWeldingDailyTempDetails().FirstOrDefault(x => x.TempDetailId == tempDetailId);
}
/// <summary>
/// 构造待审核查询。PC端列表和接口列表、明细均从这里读取,确保字段映射和待审核状态一致。
/// </summary>
private static System.Linq.IQueryable<Model.WeldingDailyTempDetailItem> QueryPendingWeldingDailyTempDetails(Model.SGGLDB db)
private static List<Model.WeldingDailyTempDetailItem> QueryPendingWeldingDailyTempDetails()
{
// 待审核模块只展示 AuditState=0;审核、删除仍复用本类下方已有批量业务方法。
return from temp in db.HJGL_WeldingDailyTempDetail
List<Model.WeldingDailyTempDetailItem> data;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
// 查询必须在数据上下文释放前物化,避免返回失效的延迟查询。
data = (from temp in db.HJGL_WeldingDailyTempDetail
join jotItem in db.View_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
@@ -380,9 +396,21 @@ namespace BLL
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 equals weldTypeItem.WeldTypeId into weldTypeItems
from weldType in weldTypeItems.DefaultIfEmpty()
join weldingMethodItem in db.Base_WeldingMethod on temp.WeldingMethodId equals weldingMethodItem.WeldingMethodId into weldingMethodItems
from weldingMethod in weldingMethodItems.DefaultIfEmpty()
join weldingWireItem in db.Base_Consumables on temp.WeldingWire equals weldingWireItem.ConsumablesId into weldingWireItems
from weldingWire in weldingWireItems.DefaultIfEmpty()
join weldingRodItem in db.Base_Consumables on temp.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()
where temp.AuditState == 0
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()
where temp.AuditState < AuditStateApproved
select new Model.WeldingDailyTempDetailItem
{
TempDetailId = temp.TempDetailId,
@@ -408,10 +436,14 @@ namespace BLL
Size = jot == null ? (decimal?)null : jot.Size,
Dia = jot == null ? (decimal?)null : jot.Dia,
Thickness = jot == null ? (decimal?)null : jot.Thickness,
WeldTypeCode = jot == null ? null : jot.WeldTypeCode,
WeldingMethodCode = jot == null ? null : jot.WeldingMethodCode,
WeldingWireCode = jot == null ? null : jot.WeldingWireCode,
WeldingRodCode = jot == null ? null : jot.WeldingRodCode,
WeldTypeId = temp.WeldTypeId ?? (jot == null ? null : jot.WeldTypeId),
WeldTypeCode = weldType == null ? (jot == null ? null : jot.WeldTypeCode) : weldType.WeldTypeCode,
WeldingMethodId = temp.WeldingMethodId ?? (jot == null ? null : jot.WeldingMethodId),
WeldingMethodCode = weldingMethod == null ? (jot == null ? null : jot.WeldingMethodCode) : weldingMethod.WeldingMethodCode,
WeldingWire = temp.WeldingWire ?? (jot == null ? null : jot.WeldingWire),
WeldingWireCode = weldingWire == null ? (jot == null ? null : jot.WeldingWireCode) : weldingWire.ConsumablesCode,
WeldingRod = temp.WeldingRod ?? (jot == null ? null : jot.WeldingRod),
WeldingRodCode = weldingRod == null ? (jot == null ? null : jot.WeldingRodCode) : weldingRod.ConsumablesCode,
SubmitPersonId = temp.SubmitPersonId,
SubmitPersonName = submitPerson == null ? null : submitPerson.PersonName,
SubmitDate = temp.SubmitDate,
@@ -419,15 +451,24 @@ namespace BLL
AuditState = temp.AuditState,
AuditMan = temp.AuditMan,
AuditDate = temp.AuditDate,
AuditRemark = temp.AuditRemark
};
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 ? "待班组审核" : "待专工审核"
}).ToList();
}
SetWeldingDailyTempDetailAttachUrls(data);
return data;
}
/// <summary>
/// 按待审核明细ID批量回写焊前、焊后附件地址。
/// </summary>
private static void SetWeldingDailyTempDetailAttachUrls(Model.SGGLDB db,
List<Model.WeldingDailyTempDetailItem> data)
private static void SetWeldingDailyTempDetailAttachUrls(List<Model.WeldingDailyTempDetailItem> data)
{
if (data == null || data.Count == 0)
{
@@ -439,12 +480,16 @@ namespace BLL
x.TempDetailId + "#Before",
x.TempDetailId + "#After"
}).ToList();
var 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());
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)
{
@@ -479,14 +524,15 @@ namespace BLL
/// <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);
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 weldingLocationId, int welderType, string weldingMethodId, string weldTypeId,
string weldingWire, string weldingRod)
{
string res = string.Empty;
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
@@ -507,7 +553,7 @@ namespace BLL
}
var joint = db.View_HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId);
string err = CheckWeldingDailyTempJoint(db, joint, weldingLocationId);
string err = CheckWeldingDailyTempJoint(joint, weldingLocationId);
if (!string.IsNullOrEmpty(err))
{
return err;
@@ -515,38 +561,39 @@ namespace BLL
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 "焊口不存在";
}
// 兼容旧版小程序:只有两个参数同时存在时才成对更新,避免焊口工艺信息出现半更新。
if (!string.IsNullOrWhiteSpace(weldingMethodId) && !string.IsNullOrWhiteSpace(weldTypeId))
string parameterError = ValidatePendingWeldingParameters(weldingMethodId, weldTypeId, weldingWire, weldingRod);
if (!string.IsNullOrEmpty(parameterError))
{
weldJoint.WeldingMethodId = weldingMethodId;
weldJoint.WeldTypeId = weldTypeId;
return parameterError;
}
var pending = GetPendingTempDetail(db, weldJointId, weldingDate);
string coverWelderId = pending != null ? pending.CoverWelderId : weldJoint.CoverWelderId;
string backingWelderId = pending != null ? pending.BackingWelderId : weldJoint.BackingWelderId;
if (welderType == 0)
{
coverWelderId = personId;
backingWelderId = personId;
}
else if (welderType == 1)
{
backingWelderId = personId;
}
else if (welderType == 2)
{
coverWelderId = personId;
}
else
if (welderType < 0 || welderType > 2)
{
return "焊工类型不正确";
}
SaveWeldingDailyTempDetail(db, joint, weldTask, weldingDate, personId, coverWelderId, backingWelderId,
joint.JointAttribute, weldingLocationId, joint.ProjectId, null, null, joint.WeldingMode);
db.SubmitChanges();
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)
{
@@ -595,7 +642,7 @@ namespace BLL
}
var joint = db.View_HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId);
string err = CheckWeldingDailyTempJoint(db, joint, weldingLocationId);
string err = CheckWeldingDailyTempJoint(joint, weldingLocationId);
if (!string.IsNullOrEmpty(err))
{
return err;
@@ -613,9 +660,21 @@ namespace BLL
}
var weldTask = db.HJGL_WeldTask.FirstOrDefault(x => x.WeldJointId == weldJointId);
SaveWeldingDailyTempDetail(db, joint, weldTask, weldingDate, submitPersonId, coverWelderId, backingWelderId,
jointAttribute, weldingLocationId, projectId, unitId, unitWorkId, weldingMode);
db.SubmitChanges();
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)
{
@@ -627,7 +686,46 @@ namespace BLL
}
/// <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>
@@ -639,61 +737,90 @@ namespace BLL
{
return "请选择要审核的记录";
}
if (string.IsNullOrWhiteSpace(auditMan)) return "专工审核人不能为空";
foreach (string tempDetailId in tempDetailIds.Where(x => !string.IsNullOrEmpty(x)).Distinct())
var sharedConnection = (SqlConnection)Funs.DB.Connection;
bool closeConnection = sharedConnection.State != ConnectionState.Open;
try
{
var tempDetail = Funs.DB.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.TempDetailId == tempDetailId);
if (tempDetail == null)
using (var scope = new TransactionScope())
{
errlog += "待审核记录不存在;";
continue;
}
if (tempDetail.AuditState != 0)
{
errlog += "焊口待审核记录已审核;";
continue;
}
if (string.IsNullOrEmpty(tempDetail.CoverWelderId) || string.IsNullOrEmpty(tempDetail.BackingWelderId))
{
errlog += "焊口待审核记录未选择完整焊工;";
continue;
}
// 整个专工审核事务保持单一连接
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 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 batchC = BLL.Project_SysSetService.GetSysSetBySetId("5", tempDetail.ProjectId);
if (batchC == null)
{
errlog += "请设置项目的组批条件;";
continue;
}
var weldingDaily = GetOrCreateWeldingDailyByTempDetail(tempDetail);
string itemErr = InsertWeldingDailyItem(tempDetail.WeldJointId, tempDetail.CoverWelderId, tempDetail.BackingWelderId,
tempDetail.JointAttribute, weldingDaily.WeldingDate, batchC.SetValue, true, weldingDaily.WeldingDailyId,
tempDetail.ProjectId, tempDetail.WeldingLocationId);
if (!string.IsNullOrEmpty(itemErr))
{
errlog += itemErr;
continue;
}
var weldingDaily = GetOrCreateWeldingDailyByTempDetail(tempDetail);
BLL.HJGL_PipelineComponentjointService.UpdateStateByWeldJointId(tempDetail.WeldJointId, (DateTime)weldingDaily.WeldingDate);//更改预制口实际时间和状态
PipelineService.UpdataDateByWeldJointId(tempDetail.WeldJointId);//更改安装口时间和状态
tempDetail.AuditState = 1;
tempDetail.AuditMan = auditMan;
tempDetail.AuditDate = DateTime.Now;
Funs.DB.SubmitChanges();
// 实际工艺参数在专工审核事务内才回写焊口,审核失败时与正式日报一起回滚。
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;
@@ -719,7 +846,7 @@ namespace BLL
{
continue;
}
if (tempDetail.AuditState != 0)
if (tempDetail.AuditState != AuditStatePendingTeam)
{
errlog += "已审核记录不能删除;";
continue;
@@ -730,66 +857,210 @@ namespace BLL
return errlog;
}
private static string CheckWeldingDailyTempJoint(Model.SGGLDB db, Model.View_HJGL_WeldJoint joint, string weldingLocationId)
/// <summary>
/// 将需要热处理的焊口归入焊接完成日期当天的自动热处理委托。
/// </summary>
private static void EnsureAutomaticHotProcessTrust(Model.HJGL_WeldingDailyTempDetail tempDetail,
Model.HJGL_WeldJoint weldJoint, string auditMan)
{
if (joint == null)
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)
{
return "焊口不存在";
// 在当前事务内锁定同项目、单位工程编号范围,防止并发审核产生重复流水号。
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);
}
if (!string.IsNullOrEmpty(joint.WeldingDailyId))
Funs.DB.HJGL_HotProess_TrustItem.InsertOnSubmit(new Model.HJGL_HotProess_TrustItem
{
return "焊口【" + joint.WeldJointCode + "】已生成焊接日报,不能提交待审核";
}
if (!string.IsNullOrEmpty(weldingLocationId))
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))
{
var weldingLocationModel = db.Base_WeldingLocation.FirstOrDefault(x => x.WeldingLocationId == weldingLocationId);
if (weldingLocationModel == null)
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;
}
return string.Empty;
}
private static Model.HJGL_WeldingDailyTempDetail GetPendingTempDetail(Model.SGGLDB db, string weldJointId, DateTime weldingDate)
private static Model.HJGL_WeldingDailyTempDetail GetLockedWeldingDailyTempDetail(string tempDetailId)
{
return db.HJGL_WeldingDailyTempDetail.FirstOrDefault(x => x.WeldJointId == weldJointId
&& x.WeldingDate >= weldingDate.Date
&& x.WeldingDate < weldingDate.Date.AddDays(1)
&& x.AuditState == 0);
}
private static void SaveWeldingDailyTempDetail(Model.SGGLDB db, Model.View_HJGL_WeldJoint joint, Model.HJGL_WeldTask weldTask,
DateTime weldingDate, string submitPersonId, string coverWelderId, string backingWelderId, string jointAttribute,
string weldingLocationId, string projectId, string unitId, string unitWorkId, string weldingMode)
{
var pending = GetPendingTempDetail(db, joint.WeldJointId, weldingDate);
if (pending == null)
// 审核事务内锁定状态行,避免并发审核覆盖审核人和状态。
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)
{
pending = new Model.HJGL_WeldingDailyTempDetail
{
TempDetailId = Guid.NewGuid().ToString(),
WeldJointId = joint.WeldJointId,
WeldingDate = weldingDate.Date,
AuditState = 0,
SubmitDate = DateTime.Now
};
db.HJGL_WeldingDailyTempDetail.InsertOnSubmit(pending);
Funs.DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, detail);
}
pending.ProjectId = !string.IsNullOrEmpty(projectId) ? projectId : joint.ProjectId;
pending.UnitId = !string.IsNullOrEmpty(unitId) ? unitId : (weldTask != null && !string.IsNullOrEmpty(weldTask.UnitId) ? weldTask.UnitId : joint.UnitId);
pending.UnitWorkId = !string.IsNullOrEmpty(unitWorkId) ? unitWorkId : joint.UnitWorkId;
pending.CoverWelderId = coverWelderId;
pending.BackingWelderId = backingWelderId;
pending.JointAttribute = !string.IsNullOrEmpty(jointAttribute) ? jointAttribute : joint.JointAttribute;
pending.WeldingLocationId = !string.IsNullOrEmpty(weldingLocationId) ? weldingLocationId : joint.WeldingLocationId;
pending.WeldingMode = !string.IsNullOrEmpty(weldingMode) ? weldingMode : joint.WeldingMode;
pending.SubmitPersonId = submitPersonId;
pending.SubmitDate = DateTime.Now;
return detail;
}
private static Model.HJGL_WeldingDaily GetOrCreateWeldingDailyByTempDetail(Model.HJGL_WeldingDailyTempDetail tempDetail)
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
@@ -802,10 +1073,18 @@ namespace BLL
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 = BLL.SQLHelper.RunProcNewId("SpGetThreeNumber", "dbo.HJGL_WeldingDaily", "WeldingDailyCode", tempDetail.ProjectId, perfix),
WeldingDailyCode = Funs.GetThreeNumber(maxNumber, perfix),
WeldingDate = tempDetail.WeldingDate.Date,
ProjectId = tempDetail.ProjectId,
UnitWorkId = tempDetail.UnitWorkId,
@@ -837,7 +1116,9 @@ namespace BLL
/// <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)
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);
@@ -872,7 +1153,8 @@ namespace BLL
// 更新焊口号 修改固定焊口号后 +G
BLL.WeldJointService.UpdateWeldJointAddG(newWeldJoint.WeldJointId, newWeldJoint.JointAttribute, Const.BtnAdd);
errlog = PointBatchService.AddBatchByWeldJointId(weldJointId, weldingDate, batchCondition);//自动组批
errlog = PointBatchService.AddBatchByWeldJointId(
weldJointId, weldingDate, batchCondition, sharedConnection);//自动组批
}
}
else