fdaf615194
通过批量导入、标准化打印和材料导出,减少检测结果及材料信息的人工整理,确保检测单、委托状态和焊口质量资料保持一致。
171 lines
6.9 KiB
C#
171 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace BLL
|
|
{
|
|
/// <summary>
|
|
/// 单位工程级检测结果导入行
|
|
/// </summary>
|
|
public class UnitWorkNDEImportItem
|
|
{
|
|
public int RowNumber { get; set; }
|
|
|
|
public string TrustBatchId { get; set; }
|
|
|
|
public string TrustBatchCode { get; set; }
|
|
|
|
public string TrustBatchItemId { get; set; }
|
|
|
|
public string PipelineCode { get; set; }
|
|
|
|
public string WeldJointCode { get; set; }
|
|
|
|
public string WelderCode { get; set; }
|
|
|
|
public int TotalFilm { get; set; }
|
|
|
|
public int PassFilm { get; set; }
|
|
|
|
public string CheckResult { get; set; }
|
|
|
|
public string CheckResultText { get; set; }
|
|
|
|
public string JudgeGrade { get; set; }
|
|
|
|
public string CheckDefects { get; set; }
|
|
|
|
public string CheckDefectsText { get; set; }
|
|
|
|
public string RepairLocation { get; set; }
|
|
|
|
public string Remark { get; set; }
|
|
|
|
public DateTime? FilmDate { get; set; }
|
|
|
|
public DateTime? ReportDate { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 单位工程级检测结果批量导入
|
|
/// </summary>
|
|
public static class Batch_NDEImportService
|
|
{
|
|
/// <summary>
|
|
/// 一次性保存检测单主表、明细和委托检测状态
|
|
/// </summary>
|
|
public static void Import(string projectId, string unitWorkId, string personId, IList<UnitWorkNDEImportItem> importItems)
|
|
{
|
|
if (importItems == null || importItems.Count == 0)
|
|
{
|
|
throw new InvalidOperationException("没有可导入的数据!");
|
|
}
|
|
|
|
Model.SGGLDB db = Funs.DB;
|
|
bool isValidUnitWork = db.WBS_UnitWork.Any(x => x.UnitWorkId == unitWorkId
|
|
&& x.ProjectId == projectId
|
|
&& x.SuperUnitWork == null);
|
|
if (!isValidUnitWork)
|
|
{
|
|
throw new InvalidOperationException("单位工程不存在或不属于当前项目!");
|
|
}
|
|
|
|
List<string> trustBatchIds = importItems.Select(x => x.TrustBatchId).Distinct().ToList();
|
|
List<string> trustBatchItemIds = importItems.Select(x => x.TrustBatchItemId).Distinct().ToList();
|
|
|
|
List<Model.HJGL_Batch_BatchTrust> trusts = db.HJGL_Batch_BatchTrust
|
|
.Where(x => trustBatchIds.Contains(x.TrustBatchId)
|
|
&& x.ProjectId == projectId
|
|
&& x.UnitWorkId == unitWorkId)
|
|
.ToList();
|
|
if (trusts.Count != trustBatchIds.Count)
|
|
{
|
|
throw new InvalidOperationException("导入数据包含不属于当前单位工程的委托单,请重新审核文件!");
|
|
}
|
|
|
|
if (trustBatchItemIds.Count != importItems.Count)
|
|
{
|
|
throw new InvalidOperationException("导入数据包含重复的委托明细,请重新审核文件!");
|
|
}
|
|
|
|
List<Model.HJGL_Batch_BatchTrustItem> trustItems = db.HJGL_Batch_BatchTrustItem
|
|
.Where(x => trustBatchItemIds.Contains(x.TrustBatchItemId)
|
|
&& trustBatchIds.Contains(x.TrustBatchId))
|
|
.ToList();
|
|
if (trustItems.Count != trustBatchItemIds.Count
|
|
|| importItems.Any(x => !trustItems.Any(y => y.TrustBatchItemId == x.TrustBatchItemId
|
|
&& y.TrustBatchId == x.TrustBatchId)))
|
|
{
|
|
throw new InvalidOperationException("导入数据包含无效的委托明细,请重新审核文件!");
|
|
}
|
|
|
|
List<string> importedTrustBatchIds = db.HJGL_Batch_NDE
|
|
.Where(x => trustBatchIds.Contains(x.TrustBatchId))
|
|
.Select(x => x.TrustBatchId)
|
|
.ToList();
|
|
if (importedTrustBatchIds.Count > 0)
|
|
{
|
|
string codes = string.Join("、", importItems
|
|
.Where(x => importedTrustBatchIds.Contains(x.TrustBatchId))
|
|
.Select(x => x.TrustBatchCode)
|
|
.Distinct());
|
|
throw new InvalidOperationException("委托单[" + codes + "]已存在检测结果,不能重复导入!");
|
|
}
|
|
|
|
List<Model.HJGL_Batch_NDE> ndeList = new List<Model.HJGL_Batch_NDE>();
|
|
List<Model.HJGL_Batch_NDEItem> ndeItemList = new List<Model.HJGL_Batch_NDEItem>();
|
|
DateTime submitDate = DateTime.Now;
|
|
|
|
foreach (IGrouping<string, UnitWorkNDEImportItem> group in importItems.GroupBy(x => x.TrustBatchId))
|
|
{
|
|
Model.HJGL_Batch_BatchTrust trust = trusts.First(x => x.TrustBatchId == group.Key);
|
|
string ndeId = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDE));
|
|
|
|
// 检测流水号沿用检测单编辑页的委托编号转换规则。
|
|
string ndeCode = trust.TrustType == "R"
|
|
? trust.TrustBatchCode.Replace("-FXWT-", "-FXJC-")
|
|
: trust.TrustBatchCode.Replace("-WT-", "-JC-");
|
|
ndeList.Add(new Model.HJGL_Batch_NDE
|
|
{
|
|
NDEID = ndeId,
|
|
TrustBatchId = trust.TrustBatchId,
|
|
ProjectId = projectId,
|
|
UnitId = trust.UnitId,
|
|
UnitWorkId = unitWorkId,
|
|
NDEUnit = trust.NDEUnit,
|
|
NDECode = ndeCode,
|
|
NDEMan = personId
|
|
});
|
|
|
|
foreach (UnitWorkNDEImportItem importItem in group)
|
|
{
|
|
ndeItemList.Add(new Model.HJGL_Batch_NDEItem
|
|
{
|
|
NDEItemID = SQLHelper.GetNewID(typeof(Model.HJGL_Batch_NDEItem)),
|
|
NDEID = ndeId,
|
|
TrustBatchItemId = importItem.TrustBatchItemId,
|
|
DetectionTypeId = trust.DetectionTypeId,
|
|
TotalFilm = importItem.TotalFilm,
|
|
PassFilm = importItem.PassFilm,
|
|
CheckResult = importItem.CheckResult,
|
|
JudgeGrade = importItem.JudgeGrade,
|
|
CheckDefects = importItem.CheckDefects,
|
|
RepairLocation = importItem.RepairLocation,
|
|
Remark = importItem.Remark,
|
|
FilmDate = importItem.FilmDate,
|
|
ReportDate = importItem.ReportDate,
|
|
SubmitDate = submitDate
|
|
});
|
|
}
|
|
|
|
trust.IsCheck = true;
|
|
}
|
|
|
|
// 同一 DataContext 只提交一次,保证主表、明细和委托状态要么全部成功,要么全部失败。
|
|
db.HJGL_Batch_NDE.InsertAllOnSubmit(ndeList);
|
|
db.HJGL_Batch_NDEItem.InsertAllOnSubmit(ndeItemList);
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
}
|