431 lines
24 KiB
C#
431 lines
24 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
|
||
namespace BLL
|
||
{
|
||
/// <summary>
|
||
/// 点口明细表
|
||
/// </summary>
|
||
public static class Batch_PointBatchItemService
|
||
{
|
||
/// <summary>
|
||
/// 根据主键获取相关明细信息
|
||
/// </summary>
|
||
/// <param name="pointBatchId"></param>
|
||
/// <returns></returns>
|
||
public static Model.Batch_PointBatchItem GetPointBatchItemByPointBatchItemId(string pointBatchItemId)
|
||
{
|
||
return Funs.DB.Batch_PointBatchItem.FirstOrDefault(x => x.PointBatchItemId == pointBatchItemId);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据主键获取相关明细信息
|
||
/// </summary>
|
||
/// <param name="pointBatchId"></param>
|
||
/// <returns></returns>
|
||
public static List<Model.Batch_PointBatchItem> GetPointBatchItemByPointBatchId(string pointBatchId)
|
||
{
|
||
return (from x in Funs.DB.Batch_PointBatchItem where x.PointBatchId == pointBatchId select x).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据主键获取相关明细视图信息
|
||
/// </summary>
|
||
/// <param name="pointBatchId"></param>
|
||
/// <returns></returns>
|
||
public static List<Model.View_Batch_PointBatchItem> GetViewPointBatchItemByPointBatchId(string pointBatchId)
|
||
{
|
||
return (from x in Funs.DB.View_Batch_PointBatchItem where x.PointBatchId == pointBatchId orderby x.PipelineCode, x.WeldJointCode select x).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 增加
|
||
/// </summary>
|
||
/// <param name="pointBatchItem"></param>
|
||
public static void AddPointBatchItem(Model.Batch_PointBatchItem pointBatchItem)
|
||
{
|
||
Model.HJGLDB db = Funs.DB;
|
||
Model.Batch_PointBatchItem newPointBatchItem = new Model.Batch_PointBatchItem
|
||
{
|
||
PointBatchItemId = pointBatchItem.PointBatchItemId,
|
||
PointBatchId = pointBatchItem.PointBatchId,
|
||
WeldJointId = pointBatchItem.WeldJointId,
|
||
WeldingDate = pointBatchItem.WeldingDate,
|
||
PointState = pointBatchItem.PointState,
|
||
PointDate = pointBatchItem.PointDate,
|
||
RepairDate = pointBatchItem.RepairDate,
|
||
CutDate = pointBatchItem.CutDate,
|
||
CreatDate = pointBatchItem.CreatDate,
|
||
Remark = pointBatchItem.Remark,
|
||
OldPointState = pointBatchItem.OldPointState,
|
||
OldPointDate = pointBatchItem.OldPointDate,
|
||
IsCheckRepair = pointBatchItem.IsCheckRepair,
|
||
IsBuildTrust = pointBatchItem.IsBuildTrust,
|
||
AcceptLevel = pointBatchItem.AcceptLevel
|
||
|
||
};
|
||
db.Batch_PointBatchItem.InsertOnSubmit(newPointBatchItem);
|
||
db.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据主键删除相关明细信息
|
||
/// </summary>
|
||
/// <param name="pointBatchId"></param>
|
||
public static void DeletePointBatchItemByPointBatchId(string pointBatchId)
|
||
{
|
||
var pointBatchItem = (from x in Funs.DB.Batch_PointBatchItem where x.PointBatchId == pointBatchId select x).ToList();
|
||
if (pointBatchItem!=null)
|
||
{
|
||
Funs.DB.Batch_PointBatchItem.DeleteAllOnSubmit(pointBatchItem);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据主键删除相关明细信息
|
||
/// </summary>
|
||
/// <param name="pointBatchItemId"></param>
|
||
public static void DeletePointBatchItemById(string pointBatchItemId)
|
||
{
|
||
Model.HJGLDB db = Funs.DB;
|
||
var pointBatchItem = db.Batch_PointBatchItem.FirstOrDefault(x=> x.PointBatchItemId == pointBatchItemId);
|
||
if (pointBatchItem != null)
|
||
{
|
||
db.Batch_PointBatchItem.DeleteOnSubmit(pointBatchItem);
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#region 更新批明细表信息-点口
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="pointBatchItemId"></param>
|
||
/// <param name="pointState"></param>
|
||
/// <param name="pointDate"></param>
|
||
/// <param name="cutDate"></param>
|
||
public static void UpdatePointBatchItem(string pointBatchItemId, string pointState, DateTime? pointDate, DateTime? cutDate)
|
||
{
|
||
Model.HJGLDB db = Funs.DB;
|
||
Model.Batch_PointBatchItem newPointBatchItem = db.Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == pointBatchItemId);
|
||
if (newPointBatchItem != null)
|
||
{
|
||
newPointBatchItem.PointState = pointState;
|
||
newPointBatchItem.PointDate = pointDate;
|
||
newPointBatchItem.CutDate = cutDate;
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 首件制
|
||
/// <summary>
|
||
/// 焊工首两件
|
||
/// </summary>
|
||
/// <param name="pointBatchItemId"></param>
|
||
/// <param name="welderFirst"></param>
|
||
public static void UpdateWelderFirst(string pointBatchItemId, bool? welderFirst)
|
||
{
|
||
Model.HJGLDB db = Funs.DB;
|
||
Model.Batch_PointBatchItem newPointBatchItem = db.Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == pointBatchItemId);
|
||
newPointBatchItem.IsWelderFirst = welderFirst;
|
||
|
||
db.SubmitChanges();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 管线首件
|
||
/// </summary>
|
||
/// <param name="pointBatchItemId"></param>
|
||
/// <param name="pipelineFirst"></param>
|
||
public static void UpdatePipelineFirst(string pointBatchItemId, bool? pipelineFirst)
|
||
{
|
||
Model.HJGLDB db = Funs.DB;
|
||
Model.Batch_PointBatchItem newPointBatchItem = db.Batch_PointBatchItem.FirstOrDefault(e => e.PointBatchItemId == pointBatchItemId);
|
||
newPointBatchItem.IsPipelineFirst = pipelineFirst;
|
||
|
||
db.SubmitChanges();
|
||
}
|
||
#endregion
|
||
|
||
#region 生成焊口批 方法
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="projectId"></param>
|
||
/// <param name="unitId"></param>
|
||
/// <param name="installationId"></param>
|
||
/// <param name="welderId"></param>
|
||
/// <param name="weldJointId"></param>
|
||
/// <param name="weldingDate"></param>
|
||
public static void InsertPointBatch(string projectId, string welderId, string weldJointId, DateTime? weldingDate)
|
||
{
|
||
var jot = Funs.DB.Pipeline_WeldJoint.FirstOrDefault(x => x.WeldJointId == weldJointId); //焊口表
|
||
// 判断此焊口是否已存在批中
|
||
var pointBatchItemIsExists = from x in Funs.DB.Batch_PointBatchItem
|
||
where x.WeldJointId == weldJointId
|
||
select x;
|
||
if (jot != null && !string.IsNullOrEmpty(welderId) && pointBatchItemIsExists.Count() == 0)
|
||
{
|
||
string materialId = jot.Material1Id; //材质
|
||
var isoInfo = Funs.DB.Pipeline_Pipeline.FirstOrDefault(x => x.PipelineId == jot.PipelineId); //管线表
|
||
if (isoInfo != null)
|
||
{
|
||
string mediumId = isoInfo.MediumId; //介质id
|
||
//string isc_ID = jot.ISC_ID; //焊口里管线等级
|
||
string weldTypeId = jot.WeldTypeId; //焊口里焊缝类型
|
||
|
||
var isoNdt = from x in Funs.DB.Pipeline_PipelineDetectionType
|
||
where x.PipelineId == isoInfo.PipelineId && x.WeldTypeId == jot.WeldTypeId
|
||
&& jot.Dia >= x.MinDia && jot.Dia < x.MaxDia
|
||
&& jot.Thickness >= x.MinThickness && jot.Thickness < x.MaxThickness
|
||
select x; //管线明细是否存在探伤方法 探伤比例
|
||
if (isoNdt.Count() > 0)
|
||
{
|
||
foreach (var isoItem in isoNdt)
|
||
{
|
||
var rate = Funs.DB.Base_DetectionRate.FirstOrDefault(x => x.DetectionRateId == isoItem.DetectionRateId);
|
||
if (rate.DetectionRateValue != 0)
|
||
{
|
||
var pointBatch = from x in Funs.DB.Batch_PointBatch
|
||
where x.ProjectId == projectId && x.UnitId == isoInfo.UnitId && x.InstallationId == isoInfo.InstallationId
|
||
&& x.WelderId == welderId && x.MediumId == mediumId && x.MaterialId == materialId
|
||
&& x.DetectionRateId == isoItem.DetectionRateId && x.DetectionTypeId == isoItem.DetectionTypeId
|
||
&& x.WeldTypeId == isoItem.WeldTypeId
|
||
&& (!x.ClearDate.HasValue)
|
||
select x;
|
||
|
||
string pointBatchId = string.Empty;
|
||
|
||
if (pointBatch.Count() == 0) //批次空时
|
||
{
|
||
Model.Batch_PointBatch newPointBatch = new Model.Batch_PointBatch();
|
||
pointBatchId = SQLHelper.GetNewID(typeof(Model.Batch_PointBatch));
|
||
string pointBatchCode = Batch_PointBatchService.GetNewPointBatchCode(projectId, welderId, weldJointId, isoItem.DetectionTypeId, isoItem.DetectionRateId);
|
||
|
||
newPointBatch.PointBatchId = pointBatchId;
|
||
newPointBatch.PointBatchCode = pointBatchCode;
|
||
newPointBatch.ProjectId = projectId;
|
||
newPointBatch.UnitId = isoInfo.UnitId;
|
||
newPointBatch.InstallationId = isoInfo.InstallationId;
|
||
newPointBatch.DetectionTypeId = isoItem.DetectionTypeId;
|
||
newPointBatch.DetectionRateId = isoItem.DetectionRateId;
|
||
newPointBatch.WelderId = welderId;
|
||
newPointBatch.MediumId = mediumId;
|
||
newPointBatch.MaterialId = materialId;
|
||
newPointBatch.WeldTypeId = weldTypeId;
|
||
newPointBatch.StartDate = System.DateTime.Now;
|
||
newPointBatch.IsTrust = false;
|
||
|
||
Batch_PointBatchService.AddPointBatch(newPointBatch); // 生成主表
|
||
}
|
||
else
|
||
{
|
||
pointBatchId = pointBatch.FirstOrDefault().PointBatchId;
|
||
}
|
||
|
||
var ndtType = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(isoItem.DetectionTypeId);
|
||
var ndtRate = BLL.Base_DetectionRateService.GetDetectionRateByDetectionRateId(isoItem.DetectionRateId);
|
||
Model.Batch_PointBatchItem newPointBatchItem = new Model.Batch_PointBatchItem();
|
||
string pointBatchItemId = SQLHelper.GetNewID(typeof(Model.Batch_PointBatchItem));
|
||
newPointBatchItem.PointBatchItemId = pointBatchItemId;
|
||
newPointBatchItem.PointBatchId = pointBatchId;
|
||
newPointBatchItem.WeldJointId = weldJointId;
|
||
newPointBatchItem.WeldingDate = weldingDate;
|
||
newPointBatchItem.IsCheckRepair = false;
|
||
newPointBatchItem.AcceptLevel = isoItem.QualificationLevel;
|
||
#region 合格等级默认的不用了
|
||
//var weldType = BLL.Base_WeldTypeService.GetWeldTypeByWeldTypeId(jot.WeldTypeId);
|
||
//if (ndtType.SysType == "射线检测")
|
||
//{
|
||
// if (weldType.WeldTypeGroup != "支管连接焊缝" && weldType.WeldTypeCode!="SW")
|
||
// {
|
||
// if (ndtRate.DetectionRateValue == 5 || (ndtRate.DetectionRateValue>100 && ndtRate.DetectionRateValue <110))
|
||
// {
|
||
// newPointBatchItem.AcceptLevel = "Ⅲ";
|
||
// }
|
||
// else
|
||
// {
|
||
// newPointBatchItem.AcceptLevel = "Ⅱ";
|
||
// }
|
||
// }
|
||
// // RT的支管连接焊缝没有合格等级
|
||
// else
|
||
// {
|
||
// newPointBatchItem.AcceptLevel = null;
|
||
// }
|
||
|
||
//}
|
||
//if (ndtType.SysType == "超声波检测" || ndtType.SysType == "磁粉检测" || ndtType.SysType == "渗透检测")
|
||
//{
|
||
// newPointBatchItem.AcceptLevel = "Ⅰ";
|
||
//}
|
||
//if (ndtType.SysType == "光谱检测")
|
||
//{
|
||
// newPointBatchItem.AcceptLevel = null;
|
||
//}
|
||
#endregion
|
||
BLL.Batch_PointBatchItemService.AddPointBatchItem(newPointBatchItem); // 插入明细表
|
||
|
||
var ndt = BLL.Base_DetectionTypeService.GetDetectionTypeByDetectionTypeId(isoItem.DetectionTypeId);
|
||
if (ndt.SysType == "射线检测")
|
||
{
|
||
// 焊工首2道口RT必点 :在系统中超过6个月未焊的焊工首两道口必点
|
||
var joints = from x in Funs.DB.Batch_PointBatchItem
|
||
join y in Funs.DB.Batch_PointBatch on x.PointBatchId equals y.PointBatchId
|
||
join z in Funs.DB.Base_DetectionType on y.DetectionTypeId equals z.DetectionTypeId
|
||
join j in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals j.WeldJointId
|
||
join d in Funs.DB.Pipeline_WeldingDaily on j.WeldingDailyId equals d.WeldingDailyId
|
||
where z.SysType == "射线检测" && j.CoverWelderId == welderId && d.WeldingDate != null
|
||
&& d.WeldingDate.Value.AddMonths(6) > DateTime.Now
|
||
select x;
|
||
if (joints.Count() <= 2)
|
||
{
|
||
UpdatePointBatchItem(pointBatchItemId, "1", System.DateTime.Now, null);
|
||
UpdateWelderFirst(pointBatchItemId, true);
|
||
// 批次关闭
|
||
Batch_PointBatchService.UpdatePointBatch(pointBatchId, System.DateTime.Now);
|
||
}
|
||
|
||
// 管线首道进批的口RT必点
|
||
var jotIso = from x in Funs.DB.Batch_PointBatchItem
|
||
join y in Funs.DB.Batch_PointBatch on x.PointBatchId equals y.PointBatchId
|
||
join z in Funs.DB.Base_DetectionType on y.DetectionTypeId equals z.DetectionTypeId
|
||
join j in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals j.WeldJointId
|
||
where z.SysType == "射线检测" && j.PipelineId == jot.PipelineId
|
||
select x;
|
||
if (jotIso.Count() <= 1)
|
||
{
|
||
UpdatePointBatchItem(pointBatchItemId, "1", System.DateTime.Now, null);
|
||
UpdatePipelineFirst(pointBatchItemId, true);
|
||
// 批次关闭
|
||
Batch_PointBatchService.UpdatePointBatch(pointBatchId, System.DateTime.Now);
|
||
}
|
||
}
|
||
|
||
// 管径大于500的焊口或者是焊缝类型包含“G”的焊口100%点口
|
||
var wtype = BLL.Base_WeldTypeService.GetWeldTypeByWeldTypeId(jot.WeldTypeId);
|
||
if ((jot.Dia > 500 || (wtype!=null && wtype.WeldTypeCode.Contains("G"))) && ndt.SysType != "光谱检测")
|
||
{
|
||
UpdatePointBatchItem(pointBatchItemId, "1", System.DateTime.Now, null);
|
||
// 批次关闭
|
||
Batch_PointBatchService.UpdatePointBatch(pointBatchId, System.DateTime.Now);
|
||
}
|
||
|
||
var pointBatchItem = (from x in Funs.DB.Batch_PointBatchItem
|
||
where x.PointBatchId == pointBatchId
|
||
orderby x.CreatDate
|
||
select x).ToList();
|
||
|
||
//if (pointBatchItem.Where(e => e.PointState == "1" ).Count() == 0) // 表示批里没有点口,排除管线,焊工首件
|
||
//{
|
||
// if (pointBatchItem.Count() > 0 && (100 / (rate.DetectionRateValue * 2)) < pointBatchItem.Count()) // 当到达批中间数据时点口关闭,但批还未结束
|
||
// {
|
||
// int a = pointBatchItem.Count() - 1;
|
||
// string value = (pointBatchItem).ToList()[a].PointBatchItemId;
|
||
// UpdatePointBatchItem(value, "1", System.DateTime.Now, null);
|
||
// Batch_PointBatchService.UpdatePointBatch(pointBatchId, System.DateTime.Now);
|
||
// }
|
||
//}
|
||
|
||
if (pointBatchItem.Count() > 0 && pointBatchItem.Count() >= (100 / rate.DetectionRateValue))
|
||
{
|
||
if (pointBatchItem.Where(e => e.PointState == "1").Count() == 0) // 表示批里没有点口,排除管线,焊工首件
|
||
{
|
||
string id = string.Empty;
|
||
var jointG = from x in pointBatchItem
|
||
join y in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals y.WeldJointId
|
||
where y.JointAttribute == "固定F"
|
||
select x;
|
||
|
||
if (jointG.Count() > 0)
|
||
{
|
||
int[] r = Funs.GetRandomNum(1, 1, jointG.Count());
|
||
int a = r[0] - 1;
|
||
id = jointG.ToList()[a].PointBatchItemId;
|
||
}
|
||
else
|
||
{
|
||
// 为满足固定口检测比例达到40%,系统点口时优先选择除1G和1FG之外的焊接位置的焊口
|
||
var jointP = from x in pointBatchItem
|
||
join y in Funs.DB.Pipeline_WeldJoint on x.WeldJointId equals y.WeldJointId
|
||
join z in Funs.DB.Base_WeldingLocation on y.WeldingLocationId equals z.WeldingLocationId
|
||
where z.WeldingLocationCode!= "1G" && z.WeldingLocationCode != "1FG"
|
||
select x;
|
||
if (jointP.Count() > 0)
|
||
{
|
||
int[] r = Funs.GetRandomNum(1, 1, jointP.Count());
|
||
int a = r[0] - 1;
|
||
id = jointP.ToList()[a].PointBatchItemId;
|
||
}
|
||
else
|
||
{
|
||
int[] r = Funs.GetRandomNum(1, 1, pointBatchItem.Count());
|
||
int a = r[0] - 1;
|
||
id = pointBatchItem.ToList()[a].PointBatchItemId;
|
||
}
|
||
}
|
||
|
||
UpdatePointBatchItem(id, "1", System.DateTime.Now, null);
|
||
}
|
||
//结束批前如点口未关闭,则先关闭点口
|
||
Batch_PointBatchService.UpdatePointBatch(pointBatchId, System.DateTime.Now);
|
||
Batch_PointBatchService.UpdatePointBatchClearDate(pointBatchId, System.DateTime.Now); //结束批
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 是否显示返修\切除页面通过批id
|
||
/// <summary>
|
||
/// 是否显示返修\切除页面
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static bool GetIsShowPointRepairByPointBatchId(string pointBatchId)
|
||
{
|
||
////判断该焊口是否点口\扩透 是显示链接
|
||
var pointBatchItem = Funs.DB.Batch_PointBatchItem.FirstOrDefault(x => x.PointBatchId == pointBatchId
|
||
&& !x.CutDate.HasValue && x.PointDate.HasValue && x.IsCheckRepair.HasValue && x.IsCheckRepair.Value);
|
||
if (pointBatchItem != null)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 更新委托次数
|
||
/// </summary>
|
||
/// <param name="trustBatchItemId">委托批明细ID</param>
|
||
/// <param name="num"></param>
|
||
public static void UpdateTrustNum(string trustBatchItemId, int num)
|
||
{
|
||
Model.HJGLDB db = Funs.DB;
|
||
var trustBatchItem = db.Batch_BatchTrustItem.FirstOrDefault(x => x.TrustBatchItemId == trustBatchItemId);
|
||
if (trustBatchItem != null)
|
||
{
|
||
trustBatchItem.TrustNum = trustBatchItem.TrustNum ?? 0 + num;
|
||
if (trustBatchItem.TrustNum < 0)
|
||
{
|
||
trustBatchItem.TrustNum = 0;
|
||
}
|
||
}
|
||
db.SubmitChanges();
|
||
}
|
||
}
|
||
}
|