241 lines
10 KiB
C#
241 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BLL
|
|
{
|
|
/// <summary>
|
|
/// 小程序焊前抽检接口服务
|
|
/// </summary>
|
|
public static class APIPreWeldInspectionService
|
|
{
|
|
/// <summary>
|
|
/// 根据焊口ID获取焊前抽检基础信息
|
|
/// </summary>
|
|
/// <param name="weldJointId">焊口ID</param>
|
|
/// <returns>焊口基础信息</returns>
|
|
public static Model.PreWeldJointItem GetPreWeldJointByWeldJointId(string weldJointId)
|
|
{
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var query = from x in db.HJGL_WeldJoint
|
|
join p in db.Base_Project on x.ProjectId equals p.ProjectId into projects
|
|
from p in projects.DefaultIfEmpty()
|
|
join g in db.Base_GrooveType on x.GrooveTypeId equals g.GrooveTypeId into grooveTypes
|
|
from g in grooveTypes.DefaultIfEmpty()
|
|
where x.WeldJointId == weldJointId
|
|
select new Model.PreWeldJointItem
|
|
{
|
|
WeldJointId = x.WeldJointId,
|
|
WeldJointCode = x.WeldJointCode,
|
|
PipelineId = x.PipelineId,
|
|
PipelineCode = x.PipelineCode,
|
|
ProjectId = x.ProjectId,
|
|
ProjectName = p == null ? string.Empty : p.ProjectName,
|
|
GrooveTypeId = x.GrooveTypeId,
|
|
GrooveTypeCode = g == null ? string.Empty : g.GrooveTypeCode,
|
|
GrooveTypeName = g == null ? string.Empty : g.GrooveTypeName,
|
|
GrooveProcessType = x.GrooveProcessType,
|
|
GrooveAngle = x.GrooveAngle,
|
|
FitupGap = x.FitupGap,
|
|
Misalignment = x.Misalignment
|
|
};
|
|
|
|
var item = query.FirstOrDefault();
|
|
if (item != null)
|
|
{
|
|
SetInspectionAttachUrl(db, item);
|
|
}
|
|
|
|
return item;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回填下料、组对抽检附件路径
|
|
/// </summary>
|
|
/// <param name="db">数据库上下文</param>
|
|
/// <param name="item">焊前抽检基础信息</param>
|
|
private static void SetInspectionAttachUrl(Model.SGGLDB db, Model.PreWeldJointItem item)
|
|
{
|
|
var cuttingCheckId = db.HJGL_PreWeldCuttingCheck
|
|
.Where(x => x.WeldJointId == item.WeldJointId)
|
|
.Select(x => x.CuttingCheckId)
|
|
.FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(cuttingCheckId))
|
|
{
|
|
item.CuttingAttachUrl1 = GetAttachUrl(db, Const.HJGL_PreWeldCuttingCheckMenuId, cuttingCheckId);
|
|
}
|
|
|
|
var fitupCheckId = db.HJGL_PreWeldFitupCheck
|
|
.Where(x => x.WeldJointId == item.WeldJointId)
|
|
.Select(x => x.FitupCheckId)
|
|
.FirstOrDefault();
|
|
if (!string.IsNullOrEmpty(fitupCheckId))
|
|
{
|
|
item.FitupAttachUrl1 = GetAttachUrl(db, Const.HJGL_PreWeldFitupCheckMenuId, fitupCheckId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按菜单和业务ID获取附件路径
|
|
/// </summary>
|
|
/// <param name="db">数据库上下文</param>
|
|
/// <param name="menuId">菜单ID</param>
|
|
/// <param name="toKeyId">业务ID</param>
|
|
/// <returns>附件路径</returns>
|
|
private static string GetAttachUrl(Model.SGGLDB db, string menuId, string toKeyId)
|
|
{
|
|
var attachUrl = db.AttachFile
|
|
.Where(x => x.MenuId == menuId && x.ToKeyId == toKeyId)
|
|
.Select(x => x.AttachUrl)
|
|
.FirstOrDefault();
|
|
return string.IsNullOrEmpty(attachUrl) ? attachUrl : attachUrl.Replace('\\', '/');
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存下料抽检,已存在同一焊口记录时更新原记录
|
|
/// </summary>
|
|
/// <param name="item">下料抽检参数</param>
|
|
public static void SaveCuttingCheck(Model.PreWeldCuttingCheckItem item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
throw new ArgumentNullException("item");
|
|
}
|
|
if (string.IsNullOrEmpty(item.WeldJointId))
|
|
{
|
|
throw new ArgumentException("焊口ID不能为空。");
|
|
}
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
{
|
|
var weldJoint = db.HJGL_WeldJoint.FirstOrDefault(x => x.WeldJointId == item.WeldJointId);
|
|
if (weldJoint == null)
|
|
{
|
|
throw new ArgumentException("未找到对应焊口。");
|
|
}
|
|
|
|
var check = db.HJGL_PreWeldCuttingCheck.FirstOrDefault(x => x.WeldJointId == item.WeldJointId);
|
|
if (check == null)
|
|
{
|
|
check = new Model.HJGL_PreWeldCuttingCheck
|
|
{
|
|
CuttingCheckId = Guid.NewGuid().ToString(),
|
|
WeldJointId = item.WeldJointId,
|
|
ProjectId = string.IsNullOrEmpty(item.ProjectId) ? weldJoint.ProjectId : item.ProjectId,
|
|
CreateUser = item.CreateUser ?? item.CheckPerson,
|
|
CreateTime = DateTime.Now
|
|
};
|
|
db.HJGL_PreWeldCuttingCheck.InsertOnSubmit(check);
|
|
}
|
|
|
|
check.ProjectId = string.IsNullOrEmpty(item.ProjectId) ? weldJoint.ProjectId : item.ProjectId;
|
|
check.IsMaterialCodeBatchNoAccurate = item.IsMaterialCodeBatchNoAccurate;
|
|
check.IsMaterialQuantityAccurate = item.IsMaterialQuantityAccurate;
|
|
// 下料抽检合格规则:材料编码及炉批号、材料数量两个检查项均准确才合格。
|
|
check.IsQualified = item.IsMaterialCodeBatchNoAccurate && item.IsMaterialQuantityAccurate;
|
|
check.CheckPerson = item.CheckPerson;
|
|
check.CheckTime = item.CheckTime ?? DateTime.Now;
|
|
check.Remark = item.Remark;
|
|
|
|
db.SubmitChanges();
|
|
|
|
SaveInspectionAttachUrl(item.AttachUrl1, Const.HJGL_PreWeldCuttingCheckMenuId, check.CuttingCheckId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存组对抽检,已存在同一焊口记录时更新原记录并回写焊口主表
|
|
/// </summary>
|
|
/// <param name="item">组对抽检参数</param>
|
|
public static void SaveFitupCheck(Model.PreWeldFitupCheckItem item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
throw new ArgumentNullException("item");
|
|
}
|
|
if (string.IsNullOrEmpty(item.WeldJointId))
|
|
{
|
|
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);
|
|
if (weldJoint == null)
|
|
{
|
|
throw new ArgumentException("未找到对应焊口。");
|
|
}
|
|
if (!db.Base_GrooveType.Any(x => x.GrooveTypeId == item.GrooveTypeId))
|
|
{
|
|
throw new ArgumentException("坡口类型不存在。");
|
|
}
|
|
|
|
var check = db.HJGL_PreWeldFitupCheck.FirstOrDefault(x => x.WeldJointId == item.WeldJointId);
|
|
if (check == null)
|
|
{
|
|
check = new Model.HJGL_PreWeldFitupCheck
|
|
{
|
|
FitupCheckId = Guid.NewGuid().ToString(),
|
|
WeldJointId = item.WeldJointId,
|
|
ProjectId = string.IsNullOrEmpty(item.ProjectId) ? weldJoint.ProjectId : item.ProjectId,
|
|
CreateUser = item.CreateUser ?? item.CheckPerson,
|
|
CreateTime = DateTime.Now
|
|
};
|
|
db.HJGL_PreWeldFitupCheck.InsertOnSubmit(check);
|
|
}
|
|
|
|
check.ProjectId = string.IsNullOrEmpty(item.ProjectId) ? weldJoint.ProjectId : item.ProjectId;
|
|
check.GrooveTypeId = item.GrooveTypeId;
|
|
check.GrooveProcessType = item.GrooveProcessType;
|
|
check.GrooveAngle = item.GrooveAngle;
|
|
check.FitupGap = item.FitupGap;
|
|
check.Misalignment = item.Misalignment;
|
|
check.CheckPerson = item.CheckPerson;
|
|
check.CheckTime = item.CheckTime ?? DateTime.Now;
|
|
check.Remark = item.Remark;
|
|
|
|
// 组对抽检字段需同步回写焊口主表,供焊口台账和后续业务复用。
|
|
weldJoint.GrooveTypeId = item.GrooveTypeId;
|
|
weldJoint.GrooveProcessType = item.GrooveProcessType;
|
|
weldJoint.GrooveAngle = item.GrooveAngle;
|
|
weldJoint.FitupGap = item.FitupGap;
|
|
weldJoint.Misalignment = item.Misalignment;
|
|
|
|
db.SubmitChanges();
|
|
|
|
SaveInspectionAttachUrl(item.AttachUrl1, Const.HJGL_PreWeldFitupCheckMenuId, check.FitupCheckId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存焊前抽检附件,空附件时清理原附件。
|
|
/// </summary>
|
|
/// <param name="attachUrl">附件路径</param>
|
|
/// <param name="menuId">菜单ID</param>
|
|
/// <param name="dataId">业务数据ID</param>
|
|
private static void SaveInspectionAttachUrl(string attachUrl, string menuId, string dataId)
|
|
{
|
|
// AttachUrl1 为 null 表示旧调用方未传附件参数,避免误删已有附件;空字符串表示明确清空附件。
|
|
if (attachUrl == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(attachUrl))
|
|
{
|
|
UploadFileService.SaveAttachUrl(UploadFileService.GetSourceByAttachUrl(attachUrl, 10, null), attachUrl, menuId, dataId);
|
|
}
|
|
else
|
|
{
|
|
CommonService.DeleteAttachFileById(menuId, dataId);
|
|
}
|
|
}
|
|
}
|
|
}
|