ChengDa_English/SGGL/BLL/API/HJGL/APIPipeJointService.cs

596 lines
27 KiB
C#

using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public static class APIPipeJointService
{
#region 线
/// <summary>
/// 根据单位工程ID获取管线列表
/// </summary>
/// <param name="unitWrokId"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> getPipelineList(string projectId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getDataLists = (from x in db.PW_IsoInfo
where x.ProjectId == projectId
orderby x.ISO_IsoNo
select new Model.BaseInfoItem
{
BaseInfoId = x.ISO_ID,
BaseInfoCode = x.ISO_IsoNo
}
).ToList();
return getDataLists;
}
}
#endregion
#region
/// <summary>
/// 根据管线ID获取未焊接的焊口信息
/// </summary>
/// <param name="pipeLineId"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> GetUnweldedWeldJointList(string pipeLineId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getData = (from x in db.PW_JointInfo
where x.ISO_ID == pipeLineId
&& x.DReportID == null
orderby x.JOT_JointNo
select new Model.BaseInfoItem
{
BaseInfoId = x.JOT_ID,
BaseInfoCode = x.JOT_JointNo,
BaseInfoName = x.JOT_Size.ToString(),
}
).ToList();
return getData;
}
}
#endregion
#region
/// <summary>
/// 获取焊口属性下拉框信息
/// </summary>
/// <param name="pipeLineId"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> GetJointAttributeList()
{
List<Model.BaseInfoItem> list = new List<Model.BaseInfoItem>();
Model.BaseInfoItem item1 = new Model.BaseInfoItem();
item1.BaseInfoId = "活动";
item1.BaseInfoCode = "活动";
list.Add(item1);
Model.BaseInfoItem item2 = new Model.BaseInfoItem();
item2.BaseInfoId = "固定";
item2.BaseInfoCode = "固定";
list.Add(item2);
return list;
}
#endregion
#region
/// <summary>
/// 获取焊接位置下拉框信息
/// </summary>
/// <param name="pipeLineId"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> GetJOTLocationList()
{
List<Model.BaseInfoItem> list = new List<Model.BaseInfoItem>();
Model.BaseInfoItem item1 = new Model.BaseInfoItem();
item1.BaseInfoId = "1G";
item1.BaseInfoCode = "1G";
list.Add(item1);
Model.BaseInfoItem item2 = new Model.BaseInfoItem();
item2.BaseInfoId = "2G";
item2.BaseInfoCode = "2G";
list.Add(item2);
Model.BaseInfoItem item3 = new Model.BaseInfoItem();
item3.BaseInfoId = "3G";
item3.BaseInfoCode = "3G";
list.Add(item3);
Model.BaseInfoItem item4 = new Model.BaseInfoItem();
item4.BaseInfoId = "4G";
item4.BaseInfoCode = "4G";
list.Add(item4);
Model.BaseInfoItem item5 = new Model.BaseInfoItem();
item5.BaseInfoId = "5G";
item5.BaseInfoCode = "5G";
list.Add(item5);
Model.BaseInfoItem item6 = new Model.BaseInfoItem();
item6.BaseInfoId = "6G";
item6.BaseInfoCode = "6G";
list.Add(item6);
Model.BaseInfoItem item7 = new Model.BaseInfoItem();
item7.BaseInfoId = "1F";
item7.BaseInfoCode = "1F";
list.Add(item7);
Model.BaseInfoItem item8 = new Model.BaseInfoItem();
item8.BaseInfoId = "2F";
item8.BaseInfoCode = "2F";
list.Add(item8);
Model.BaseInfoItem item9 = new Model.BaseInfoItem();
item9.BaseInfoId = "2FR";
item9.BaseInfoCode = "2FR";
list.Add(item9);
Model.BaseInfoItem item10 = new Model.BaseInfoItem();
item10.BaseInfoId = "4F";
item10.BaseInfoCode = "4F";
list.Add(item10);
Model.BaseInfoItem item11 = new Model.BaseInfoItem();
item11.BaseInfoId = "5F";
item11.BaseInfoCode = "5F";
list.Add(item11);
Model.BaseInfoItem item12 = new Model.BaseInfoItem();
item12.BaseInfoId = "5FG";
item12.BaseInfoCode = "5FG";
list.Add(item12);
Model.BaseInfoItem item13 = new Model.BaseInfoItem();
item13.BaseInfoId = "6FG";
item13.BaseInfoCode = "6FG";
list.Add(item13);
Model.BaseInfoItem item14 = new Model.BaseInfoItem();
item14.BaseInfoId = "2FG";
item14.BaseInfoCode = "2FG";
list.Add(item14);
Model.BaseInfoItem item15 = new Model.BaseInfoItem();
item15.BaseInfoId = "4FG";
item15.BaseInfoCode = "4FG";
list.Add(item15);
return list;
}
#endregion
#region 线ID获取所有焊口信息
/// <summary>
/// 根据管线ID获取所有焊口信息
/// </summary>
/// <param name="pipeLineId"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> GetAllWeldJointList(string pipeLineId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getDataLists = (from x in db.PW_JointInfo
where x.ISO_ID == pipeLineId
orderby x.JOT_JointNo
select new Model.BaseInfoItem
{
BaseInfoId = x.JOT_ID,
BaseInfoCode = x.JOT_JointNo
}
).ToList();
return getDataLists;
}
}
#endregion
#region
/// <summary>
/// 根据管线ID获取焊口列表
/// </summary>
/// <param name="unitWorkId"></param>
/// <returns></returns>
public static List<Model.BaseInfoItem> getWelderList(string unitWorkId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var p = db.WBS_UnitWork.Where(x => x.UnitWorkId == unitWorkId).FirstOrDefault();
var getDataLists = (from x in db.SitePerson_Person
where x.UnitId == p.UnitId && x.WorkPostId == Const.WorkPost_Welder
&& x.WelderCode != null
orderby x.WelderCode
select new Model.BaseInfoItem
{
BaseInfoId = x.PersonId,
BaseInfoCode = x.WelderCode
}
).ToList();
return getDataLists;
}
}
#endregion
#region ID获取焊口信息
/// <summary>
/// 根据焊口ID获取焊口信息
/// </summary>
/// <param name="weldJointId"></param>
/// <returns></returns>
public static Model.WeldJointItem getWeldJointInfo(string weldJointId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getDateInfo = from x in db.PW_JointInfo
join iso in db.PW_IsoInfo on x.ISO_ID equals iso.ISO_ID
join y in db.BO_WeldReportMain on x.DReportID equals y.DReportID into jonMain
from y in jonMain.DefaultIfEmpty()
where x.JOT_ID == weldJointId
select new Model.WeldJointItem
{
WeldJointId = x.JOT_ID,
ProjectId=x.ProjectId,
WeldJointCode = x.JOT_JointNo,
PipelineId = x.ISO_ID,
WorkAreaCode = db.ProjectData_WorkArea.First(w=>w.WorkAreaId ==iso.WorkAreaId).WorkAreaCode,
PipelineCode = iso.ISO_IsoNo,
Size = x.JOT_Size,
JointAttribute = x.JOT_JointAttribute,
WeldingMode = db.Base_WeldingMethod.First(w=> w.WeldingMethodId == x.WME_ID).WeldingMethodCode,
Dia = x.JOT_Dia,
Thickness = x.JOT_Sch,
DetectionRate = db.Base_DetectionRate.First(w=> w.DetectionRateId == x.DetectionRateId).DetectionRateValue + "%",
IsHotProess = x.IS_Proess == "1" ? "是" : "否",
WeldingLocation=x.JOT_Location,
BackingWelderId = x.JOT_FloorWelder,
BackingWelderCode = db.BS_Welder.First(w => w.WED_ID == x.JOT_FloorWelder).WED_Code,
BackingWelderName= db.BS_Welder.First(w => w.WED_ID == x.JOT_FloorWelder).WED_Name,
CoverWelderId = x.JOT_CellWelder,
CoverWelderCode = db.BS_Welder.First(w => w.WED_ID == x.JOT_CellWelder).WED_Code,
CoverWelderName= db.BS_Welder.First(w => w.WED_ID == x.JOT_CellWelder).WED_Name,
WeldingDate = y.JOT_WeldDate,
JOT_DailyReportNo = y.JOT_DailyReportNo,
DReportID = x.DReportID,
QRCodeAttachUrl=x.QRCodeAttachUrl.Replace('\\', '/'),
AttachUrl= APIUpLoadFileService.getFileUrl(x.JOT_ID, null),
};
return getDateInfo.FirstOrDefault();
}
}
#endregion
/// <summary>
/// 根据管线ID获取探伤比例
/// </summary>
/// <param name="pipeLineId"></param>
/// <returns></returns>
private static string GetDetectionRate(string pipeLineId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
string detectionRate = string.Empty;
var pipe = db.HJGL_Pipeline.FirstOrDefault(e => e.PipelineId == pipeLineId);
if (pipe != null && !string.IsNullOrEmpty(pipe.DetectionRateId))
{
var r = db.Base_DetectionRate.FirstOrDefault(e => e.DetectionRateId == pipe.DetectionRateId);
detectionRate = r.DetectionRateValue + "%";
}
return detectionRate;
}
}
#region
/// <summary>
/// 根据焊口标识获取焊口详细信息
/// </summary>
/// <param name="weldJointIdentify">焊口标识</param>
/// <returns></returns>
public static Model.WeldJointItem getWeldJointByIdentify(string weldJointIdentify)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var getDateInfo = from x in db.HJGL_WeldJoint
join y in db.HJGL_WeldingDaily on x.WeldingDailyId equals y.WeldingDailyId
where x.WeldJointIdentify == weldJointIdentify
select new Model.WeldJointItem
{
WeldJointId = x.WeldJointId,
WeldJointCode = x.WeldJointCode,
WeldJointIdentify = x.WeldJointIdentify,
Position = x.Position,
PipelineId = x.PipelineId,
PipelineCode = x.PipelineCode,
JointArea = x.JointArea,
JointAttribute = x.JointAttribute,
WeldingMode = x.WeldingMode,
Size = x.Size,
Dia = x.Dia,
Thickness = (x.Thickness ?? 0).ToString(),
WeldingMethodCode = db.Base_WeldingMethod.First(z => z.WeldingMethodId == x.WeldingMethodId).WeldingMethodCode,
WeldingDate = y.WeldingDate,
BackingWelderCode = db.SitePerson_Person.First(z => z.PersonId == x.BackingWelderId).WelderCode,
CoverWelderCode = db.SitePerson_Person.First(z => z.PersonId == x.CoverWelderId).WelderCode,
IsHotProess = x.IsHotProess == true ? "是" : "否",
AttachUrl = x.AttachUrl
};
return getDateInfo.FirstOrDefault();
}
}
#endregion
#region 线
/// <summary>
/// 保存管线焊口信息
/// </summary>
/// <param name="addItem"></param>
public static void SavePipeWeldJoint(Model.WeldJointItem addItem)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
string projectId = string.Empty;
string unitId = string.Empty;
string pipelineId = string.Empty;
var p = db.HJGL_Pipeline.Where(x => x.ProjectId == addItem.ProjectId && x.UnitWorkId == addItem.UnitWorkId && x.PipelineCode == addItem.PipelineCode).FirstOrDefault();
var w = db.WBS_UnitWork.Where(x => x.UnitWorkId == addItem.UnitWorkId).FirstOrDefault();
if (w != null)
{
projectId = w.ProjectId;
unitId = w.UnitId;
}
if (p != null)
{
pipelineId = p.PipelineId;
}
else
{
// 保存管线信息
pipelineId = SQLHelper.GetNewID();
var pipeClass = db.Base_PipingClass.FirstOrDefault(z => z.PipingClassCode == addItem.PipingClass);
var medium = db.Base_Medium.FirstOrDefault(z => z.MediumCode == addItem.Medium);
var detectionRate = db.Base_DetectionRate.FirstOrDefault(z => z.DetectionRateCode == addItem.DetectionRate);
var detectionType = db.Base_DetectionType.FirstOrDefault(z => z.DetectionTypeCode == addItem.DetectionType);
var testMedium = db.Base_Medium.FirstOrDefault(z => z.MediumCode == addItem.TestMedium);
Model.HJGL_Pipeline newPipe = new Model.HJGL_Pipeline();
newPipe.PipelineId = pipelineId;
newPipe.ProjectId = projectId;
newPipe.UnitWorkId = addItem.UnitWorkId;
newPipe.UnitId = unitId;
newPipe.PipelineCode = addItem.PipelineCode;
newPipe.SingleNumber = addItem.SingleNumber;
if (pipeClass != null)
{
newPipe.PipingClassId = pipeClass.PipingClassId;
}
if (medium != null)
{
newPipe.MediumId = medium.MediumId;
}
if (detectionRate != null)
{
newPipe.DetectionRateId = detectionRate.DetectionRateId;
}
if (detectionType != null)
{
newPipe.DetectionType = detectionType.DetectionTypeId;
}
newPipe.TestPressure = addItem.TestPressure;
if (testMedium != null)
{
newPipe.TestMedium = testMedium.MediumId;
}
db.HJGL_Pipeline.InsertOnSubmit(newPipe);
db.SubmitChanges();
}
var jot = db.HJGL_WeldJoint.Where(x => x.PipelineId == pipelineId && (x.WeldJointCode == addItem.WeldJointCode || x.WeldJointIdentify == addItem.WeldJointIdentify)).FirstOrDefault();
if (jot == null)
{
var weldType = db.Base_WeldType.FirstOrDefault(z => z.WeldTypeCode == addItem.WeldType);
var material1 = db.Base_Material.FirstOrDefault(z => z.MaterialCode == addItem.Material1);
var material2 = db.Base_Material.FirstOrDefault(z => z.MaterialCode == addItem.Material2);
var weldingMethod = db.Base_WeldingMethod.FirstOrDefault(z => z.WeldingMethodCode == addItem.WeldingMethodCode);
var grooveType = db.Base_GrooveType.FirstOrDefault(z => z.GrooveTypeCode == addItem.GrooveType);
var weldingLocation = db.Base_WeldingLocation.FirstOrDefault(z => z.WeldingLocationCode == addItem.WeldingLocation);
var weldingWire = db.Base_Consumables.FirstOrDefault(z => z.ConsumablesName == addItem.WeldingWire);
var weldingRod = db.Base_Consumables.FirstOrDefault(z => z.ConsumablesName == addItem.WeldingRod);
Model.HJGL_WeldJoint newJot = new Model.HJGL_WeldJoint();
newJot.WeldJointId = SQLHelper.GetNewID();
newJot.WeldJointCode = addItem.WeldJointCode;
newJot.WeldJointIdentify = addItem.WeldJointIdentify;
newJot.Position = addItem.Position;
newJot.ProjectId = projectId;
newJot.PipelineId = pipelineId;
newJot.PipelineCode = addItem.PipelineCode;
if (weldType != null)
{
newJot.WeldTypeId = weldType.WeldTypeId;
}
if (material1 != null)
{
newJot.Material1Id = material1.MaterialId;
}
if (material2 != null)
{
newJot.Material2Id = material2.MaterialId;
}
if (weldingMethod != null)
{
newJot.WeldingMethodId = weldingMethod.WeldingMethodId;
}
newJot.JointArea = addItem.JointArea;
newJot.Dia = addItem.Dia;
newJot.Thickness = Funs.GetNewDecimalOrZero(addItem.Thickness);
newJot.Specification = addItem.Specification;
newJot.JointAttribute = addItem.JointAttribute;
if (grooveType != null)
{
newJot.GrooveTypeId = grooveType.GrooveTypeId;
}
if (weldingLocation != null)
{
newJot.WeldingLocationId = weldingLocation.WeldingLocationId;
}
if (weldingWire != null)
{
newJot.WeldingWire = weldingWire.ConsumablesId;
}
if (weldingRod != null)
{
newJot.WeldingRod = weldingRod.ConsumablesId;
}
db.HJGL_WeldJoint.InsertOnSubmit(newJot);
db.SubmitChanges();
}
}
}
#endregion
#region 线
/// <summary>
/// 批量保存管线焊口信息
/// </summary>
/// <param name="addItems"></param>
public static void SavePipeWeldJointList(List<Model.WeldJointItem> addItems)
{
if (addItems.Count() > 0)
{
foreach (Model.WeldJointItem addItem in addItems)
{
SavePipeWeldJoint(addItem);
}
}
}
#endregion
/// <summary>
/// 保存预提交日报
/// </summary>
/// <param name="addItem"></param>
public static void SaveWeldingDaily(Model.WeldJointItem addItem)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
Model.BO_WeldReportMain newWeldReportMain = new Model.BO_WeldReportMain();
newWeldReportMain.ProjectId = addItem.ProjectId;
var unit = (from x in db.Base_Unit
join y in db.PW_IsoInfo on x.UnitId equals y.UnitId
join z in db.PW_JointInfo on y.ISO_ID equals z.ISO_ID
where z.JOT_ID == addItem.WeldJointId
select x).FirstOrDefault();
if (unit != null)
{
newWeldReportMain.UnitId = unit.UnitId;
}
var installation = (from x in db.Project_Installation
join y in db.ProjectData_WorkArea on x.InstallationId equals y.InstallationId
join z in db.PW_IsoInfo on y.WorkAreaId equals z.WorkAreaId
join a in db.PW_JointInfo on z.ISO_ID equals a.ISO_ID
where a.JOT_ID == addItem.WeldJointId
select x).FirstOrDefault();
if (installation != null)
{
newWeldReportMain.InstallationId = installation.InstallationId;
}
DateTime? weldDate = Funs.GetNewDateTime(addItem.WeldingDate.ToString());
if (weldDate.HasValue)
{
newWeldReportMain.JOT_WeldDate = weldDate.Value;
}
else
{
newWeldReportMain.JOT_WeldDate = System.DateTime.Now;
}
if (!string.IsNullOrEmpty(addItem.UserId))
{
newWeldReportMain.CHT_Tabler = addItem.UserId;
}
newWeldReportMain.CHT_TableDate = Funs.GetNewDateTime(addItem.WeldingDate.ToString());
#region
var workAreaCode = string.Empty;
var welderCode = string.Empty;
string jotId = addItem.WeldJointId;
if (!string.IsNullOrEmpty(jotId))
{
var jotInfo = db.PW_JointInfo.FirstOrDefault(e => e.JOT_ID == jotId);
if (jotInfo != null)
{
if (!string.IsNullOrEmpty(jotInfo.ISO_ID))
{
var isoInfo =db.PW_IsoInfo.FirstOrDefault(e => e.ISO_ID == jotInfo.ISO_ID);
if (isoInfo != null)
{
workAreaCode = BLL.WorkAreaService.GetWorkAreaCodeByWorkAreaIdForApi(isoInfo.WorkAreaId);
}
}
}
}
string welderId = addItem.CoverWelderId;
if (!string.IsNullOrEmpty(welderId))
{
welderCode = BLL.WelderService.GetWelderById(welderId).WED_Code;
}
string perfix = workAreaCode + "-" + welderCode + "-";
newWeldReportMain.JOT_DailyReportNo = BLL.SQLHelper.RunProcNewId("SpGetNewCode5ByProjectId", "dbo.BO_WeldReportMain", "JOT_DailyReportNo", addItem.ProjectId, perfix);
#endregion
string DReportID = SQLHelper.GetNewID(typeof(Model.BO_WeldReportMain));
newWeldReportMain.DReportID = DReportID;
BLL.WeldReportService.AddWeldReport(newWeldReportMain);
BLL.LogService.AddSys_Log(db.Sys_User.FirstOrDefault(e => e.UserId == addItem.UserId), newWeldReportMain.JOT_DailyReportNo, DReportID, BLL.Const.HJGL_WeldReportMenuId, "添加焊接日报信息");
Model.PW_JointInfo jot = db.PW_JointInfo.FirstOrDefault(e => e.JOT_ID == addItem.WeldJointId);
jot.DReportID = newWeldReportMain.DReportID;
jot.JOT_CellWelder = addItem.CoverWelderId;
jot.JOT_FloorWelder = addItem.BackingWelderId;
jot.WLO_Code = addItem.JointAttribute == "活动" ? "F" : "S";
jot.JOT_JointAttribute = addItem.JointAttribute;
jot.JOT_Location = addItem.WeldingLocation;
jot.JOT_DoneDin = jot.JOT_Size;
//jot.JOT_Electricity = item.JOT_Electricity;
//jot.JOT_Voltage = item.JOT_Voltage;
jot.JOT_JointStatus = "100";
//jot.WeldingSpeed = item.WeldingSpeed;
//jot.JOT_PrepareTemp = item.JOT_PrepareTemp;
//jot.ActualPrepareTemp = item.ActualPrepareTemp;
//jot.JOT_CellTemp = item.JOT_CellTemp;
//jot.JOT_LastTemp = item.JOT_LastTemp;
db.SubmitChanges();
//更新焊口号 修改固定焊口号后 +G
BLL.PW_JointInfoService.UpdateJointNoAddGForApi(jot.JOT_ID, addItem.JointAttribute, "Add");
SaveAttachFile(addItem.WeldJointId, BLL.Const.HJGL_WeldReportMenuId, addItem.AttachUrl);
}
}
/// <summary>
///
/// </summary>
public static void SaveAttachFile(string dataId, string menuId, string url)
{
Model.ToDoItem toDoItem = new Model.ToDoItem
{
MenuId = menuId,
DataId = dataId,
UrlStr = url,
};
APIUpLoadFileService.SaveAttachUrl(toDoItem);
}
}
}