feat(hjgl): 完善焊接任务与质量管理流程
This commit is contained in:
@@ -4,6 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Transactions;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
@@ -16,38 +17,58 @@ namespace BLL
|
||||
|
||||
public static List<AntiCorrosionTrustOutput> GetListData(AntiCorrosionTrustOutput filter)
|
||||
{
|
||||
var query = from t in Funs.DB.Tw_AntiCorrosionTrust
|
||||
join uw in Funs.DB.WBS_UnitWork on t.UnitWorkId equals uw.UnitWorkId into uwJoin
|
||||
from uw in uwJoin.DefaultIfEmpty()
|
||||
join om in Funs.DB.Tw_OutputMaster on t.OutputMasterId equals om.Id into omJoin
|
||||
from om in omJoin.DefaultIfEmpty()
|
||||
join p in Funs.DB.Person_Persons on t.CreateMan equals p.PersonId into pJoin
|
||||
from p in pJoin.DefaultIfEmpty()
|
||||
filter = filter ?? new AntiCorrosionTrustOutput();
|
||||
var data = (from t in Funs.DB.Tw_AntiCorrosionTrust
|
||||
join uw in Funs.DB.WBS_UnitWork on t.UnitWorkId equals uw.UnitWorkId into unitWorks
|
||||
from uw in unitWorks.DefaultIfEmpty()
|
||||
join p in Funs.DB.Person_Persons on t.CreateMan equals p.PersonId into persons
|
||||
from p in persons.DefaultIfEmpty()
|
||||
where (string.IsNullOrEmpty(filter.Id) || t.Id == filter.Id)
|
||||
&& (string.IsNullOrEmpty(filter.ProjectId) || t.ProjectId == filter.ProjectId)
|
||||
&& (string.IsNullOrEmpty(filter.UnitWorkId) || t.UnitWorkId == filter.UnitWorkId)
|
||||
&& (string.IsNullOrEmpty(filter.TrustCode) || t.TrustCode.Contains(filter.TrustCode))
|
||||
&& (string.IsNullOrEmpty(filter.OutputMasterCode) || om.CusBillCode.Contains(filter.OutputMasterCode))
|
||||
&& (string.IsNullOrEmpty(filter.WeldTaskCode) || t.WeldTaskCode.Contains(filter.WeldTaskCode))
|
||||
orderby t.CreateDate descending, t.TrustCode descending
|
||||
select new AntiCorrosionTrustOutput
|
||||
{
|
||||
Id = t.Id,
|
||||
ProjectId = t.ProjectId,
|
||||
UnitWorkId = t.UnitWorkId,
|
||||
UnitWorkName = uw.UnitWorkName,
|
||||
UnitWorkName = uw == null ? string.Empty : uw.UnitWorkName,
|
||||
ConstructionPart = t.ConstructionPart,
|
||||
ConstructionProfessional = t.ConstructionProfessional,
|
||||
TrustCode = t.TrustCode,
|
||||
OutputMasterId = t.OutputMasterId,
|
||||
OutputMasterCode = om.CusBillCode,
|
||||
WeldTaskCode = t.WeldTaskCode,
|
||||
HotProessTrustId = t.HotProessTrustId,
|
||||
OutputMasterCode = string.Empty,
|
||||
DemandDate = t.DemandDate,
|
||||
CompleteDate = t.CompleteDate,
|
||||
CreateMan = t.CreateMan,
|
||||
CreateManName = p.PersonName,
|
||||
CreateManName = p == null ? string.Empty : p.PersonName,
|
||||
CreateDate = t.CreateDate,
|
||||
Remark = t.Remark
|
||||
};
|
||||
return query.ToList();
|
||||
}).ToList();
|
||||
|
||||
var taskCodes = data.Select(x => x.WeldTaskCode).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
|
||||
var taskTeams = Funs.DB.HJGL_WeldTask
|
||||
.Where(x => taskCodes.Contains(x.TaskCode))
|
||||
.Select(x => new { x.ProjectId, x.TaskCode, x.TeamGroupId })
|
||||
.ToList()
|
||||
.GroupBy(x => x.ProjectId + "|" + x.TaskCode)
|
||||
.ToDictionary(x => x.Key, x => x.Select(y => y.TeamGroupId).FirstOrDefault(y => !string.IsNullOrEmpty(y)));
|
||||
var teamIds = taskTeams.Values.Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
|
||||
var teamNames = Funs.DB.ProjectData_TeamGroup.Where(x => teamIds.Contains(x.TeamGroupId))
|
||||
.ToDictionary(x => x.TeamGroupId, x => x.TeamGroupName);
|
||||
foreach (var item in data.Where(x => !string.IsNullOrEmpty(x.WeldTaskCode)))
|
||||
{
|
||||
string teamId;
|
||||
if (taskTeams.TryGetValue(item.ProjectId + "|" + item.WeldTaskCode, out teamId))
|
||||
{
|
||||
item.TeamGroupId = teamId;
|
||||
item.TeamGroupName = !string.IsNullOrEmpty(teamId) && teamNames.ContainsKey(teamId) ? teamNames[teamId] : string.Empty;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static IEnumerable<AntiCorrosionTrustOutput> GetListData(AntiCorrosionTrustOutput filter, Grid grid)
|
||||
@@ -59,206 +80,153 @@ namespace BLL
|
||||
|
||||
public static AntiCorrosionTrustOutput GetById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return GetListData(new AntiCorrosionTrustOutput { Id = id })
|
||||
.FirstOrDefault(x => x.Id == id);
|
||||
return string.IsNullOrEmpty(id) ? null : GetListData(new AntiCorrosionTrustOutput { Id = id }).FirstOrDefault();
|
||||
}
|
||||
|
||||
public static bool IsExistTrustCode(string trustCode, string id, string projectId)
|
||||
{
|
||||
return Funs.DB.Tw_AntiCorrosionTrust.Any(x => x.TrustCode == trustCode
|
||||
&& x.ProjectId == projectId
|
||||
return Funs.DB.Tw_AntiCorrosionTrust.Any(x => x.TrustCode == trustCode && x.ProjectId == projectId
|
||||
&& (string.IsNullOrEmpty(id) || x.Id != id));
|
||||
}
|
||||
|
||||
public static string GenerateTrustCode(string unitWorkId)
|
||||
{
|
||||
var unitWork = UnitWorkService.GetUnitWorkByUnitWorkId(unitWorkId);
|
||||
if (unitWork == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var prefix = "SXHJ-ECFF-" + unitWork.UnitWorkName + "-";
|
||||
var maxSerial = Funs.DB.Tw_AntiCorrosionTrust
|
||||
.Where(x => x.UnitWorkId == unitWorkId && x.TrustCode.StartsWith(prefix))
|
||||
.Select(x => x.TrustCode)
|
||||
.ToList()
|
||||
.Select(x => GetTrustCodeSerial(x))
|
||||
.DefaultIfEmpty(0)
|
||||
.Max();
|
||||
|
||||
if (unitWork == null) return string.Empty;
|
||||
string prefix = "SXHJ-ECFF-" + unitWork.UnitWorkName + "-";
|
||||
// 生成按钮和拆单均在事务中调用;锁定同一单位工程编号范围,避免并发取到相同流水号。
|
||||
var trustCodes = Funs.DB.ExecuteQuery<string>(
|
||||
"SELECT TrustCode FROM dbo.Tw_AntiCorrosionTrust WITH (UPDLOCK,HOLDLOCK) WHERE UnitWorkId={0}",
|
||||
unitWorkId).ToList();
|
||||
int maxSerial = trustCodes.Where(x => x != null && x.StartsWith(prefix))
|
||||
.Select(GetTrustCodeSerial).DefaultIfEmpty(0).Max();
|
||||
return prefix + (maxSerial + 1).ToString("000");
|
||||
}
|
||||
|
||||
public static List<Tw_InOutMasterOutput> GetAvailableOutputMasters(string projectId, string unitWorkId, string currentTrustId)
|
||||
public static List<WeldTaskListItem> GetAvailableWeldTasks(string projectId, string unitWorkId, string currentTrustId)
|
||||
{
|
||||
var usedOutputIds = Funs.DB.Tw_AntiCorrosionTrust
|
||||
.Where(x => x.ProjectId == projectId && (string.IsNullOrEmpty(currentTrustId) || x.Id != currentTrustId))
|
||||
.Select(x => x.OutputMasterId)
|
||||
.ToList();
|
||||
|
||||
var query = from om in Funs.DB.Tw_OutputMaster
|
||||
join plan in Funs.DB.Tw_InOutPlanMaster on om.InOutPlanMasterId equals plan.Id into planJoin
|
||||
from plan in planJoin.DefaultIfEmpty()
|
||||
join createPerson in Funs.DB.Person_Persons on om.CreateMan equals createPerson.PersonId into createJoin
|
||||
from createPerson in createJoin.DefaultIfEmpty()
|
||||
join reqUnit in Funs.DB.Base_Unit on om.ReqUnitId equals reqUnit.UnitId into unitJoin
|
||||
from reqUnit in unitJoin.DefaultIfEmpty()
|
||||
where om.ProjectId == projectId
|
||||
&& !usedOutputIds.Contains(om.Id)
|
||||
&& (string.IsNullOrEmpty(unitWorkId) || (plan.WeldTaskId != null && plan.WeldTaskId.Contains(unitWorkId)))
|
||||
orderby om.CreateDate descending, om.CusBillCode descending
|
||||
select new Tw_InOutMasterOutput
|
||||
{
|
||||
Id = om.Id,
|
||||
ProjectId = om.ProjectId,
|
||||
CusBillCode = om.CusBillCode,
|
||||
InOutPlanMasterId = om.InOutPlanMasterId,
|
||||
WarehouseId = om.WarehouseId,
|
||||
WarehouseCode = om.WarehouseCode,
|
||||
WarehouseName = om.WarehouseCode,
|
||||
Source = om.Source,
|
||||
TypeInt = om.TypeInt,
|
||||
State = om.State,
|
||||
CreateMan = om.CreateMan,
|
||||
CreateManName = createPerson.PersonName,
|
||||
CreateDate = om.CreateDate,
|
||||
ReqUnitId = om.ReqUnitId,
|
||||
ReqUnitName = reqUnit.UnitName,
|
||||
Category = om.Category,
|
||||
AuditMan = om.AuditMan,
|
||||
AuditDate = om.AuditDate,
|
||||
AuditMan2 = om.AuditMan2,
|
||||
AuditDate2 = om.AuditDate2,
|
||||
WarehouseMan = om.WarehouseMan,
|
||||
WarehouseDate = om.WarehouseDate,
|
||||
WeldTaskId = plan.WeldTaskId,
|
||||
Remark = plan.Remark
|
||||
};
|
||||
return query.ToList();
|
||||
}
|
||||
|
||||
public static Tw_InOutMasterOutput GetOutputMasterById(string id)
|
||||
{
|
||||
if (string.IsNullOrEmpty(id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var query = from om in Funs.DB.Tw_OutputMaster
|
||||
join plan in Funs.DB.Tw_InOutPlanMaster on om.InOutPlanMasterId equals plan.Id into planJoin
|
||||
from plan in planJoin.DefaultIfEmpty()
|
||||
join reqUnit in Funs.DB.Base_Unit on om.ReqUnitId equals reqUnit.UnitId into unitJoin
|
||||
from reqUnit in unitJoin.DefaultIfEmpty()
|
||||
where om.Id == id
|
||||
select new Tw_InOutMasterOutput
|
||||
{
|
||||
Id = om.Id,
|
||||
ProjectId = om.ProjectId,
|
||||
CusBillCode = om.CusBillCode,
|
||||
InOutPlanMasterId = om.InOutPlanMasterId,
|
||||
WarehouseId = om.WarehouseId,
|
||||
WarehouseCode = om.WarehouseCode,
|
||||
WarehouseName = om.WarehouseCode,
|
||||
Source = om.Source,
|
||||
TypeInt = om.TypeInt,
|
||||
State = om.State,
|
||||
CreateMan = om.CreateMan,
|
||||
CreateDate = om.CreateDate,
|
||||
ReqUnitId = om.ReqUnitId,
|
||||
ReqUnitName = reqUnit.UnitName,
|
||||
Category = om.Category,
|
||||
AuditMan = om.AuditMan,
|
||||
AuditDate = om.AuditDate,
|
||||
AuditMan2 = om.AuditMan2,
|
||||
AuditDate2 = om.AuditDate2,
|
||||
WarehouseMan = om.WarehouseMan,
|
||||
WarehouseDate = om.WarehouseDate,
|
||||
WeldTaskId = plan.WeldTaskId,
|
||||
Remark = plan.Remark
|
||||
};
|
||||
return query.FirstOrDefault();
|
||||
var used = Funs.DB.Tw_AntiCorrosionTrust
|
||||
.Where(x => x.ProjectId == projectId && x.WeldTaskCode != null
|
||||
&& (string.IsNullOrEmpty(currentTrustId) || x.Id != currentTrustId))
|
||||
.Select(x => x.WeldTaskCode).ToList();
|
||||
return WeldTaskService.GetTaskListByTeamGroup(projectId, null, unitWorkId)
|
||||
.Where(x => !used.Contains(x.TaskCode)).ToList();
|
||||
}
|
||||
|
||||
public static List<AntiCorrosionTrustDetailOutput> GetDetailList(string trustId)
|
||||
{
|
||||
var query = from d in Funs.DB.Tw_AntiCorrosionTrustDetail
|
||||
join m in Funs.DB.HJGL_MaterialCodeLib on d.MaterialCode equals m.MaterialCode into materialJoin
|
||||
from m in materialJoin.DefaultIfEmpty()
|
||||
where d.TrustId == trustId
|
||||
orderby d.SortIndex
|
||||
select new AntiCorrosionTrustDetailOutput
|
||||
{
|
||||
Id = d.Id,
|
||||
TrustId = d.TrustId,
|
||||
SortIndex = d.SortIndex,
|
||||
MaterialCode = d.MaterialCode,
|
||||
Code = m.Code,
|
||||
MaterialName = m.MaterialName,
|
||||
MaterialSpec = m.MaterialSpec,
|
||||
MaterialDef = m.MaterialDef,
|
||||
MaterialUnit = m.MaterialUnit,
|
||||
Quantity = d.Quantity,
|
||||
PaintCode = d.PaintCode,
|
||||
Primer = d.Primer,
|
||||
IntermediatePaint = d.IntermediatePaint,
|
||||
Topcoat = d.Topcoat,
|
||||
ColorCode = d.ColorCode,
|
||||
Remark = d.Remark
|
||||
};
|
||||
return query.ToList();
|
||||
return (from d in Funs.DB.Tw_AntiCorrosionTrustDetail
|
||||
join m in Funs.DB.HJGL_MaterialCodeLib on d.MaterialCode equals m.MaterialCode into materials
|
||||
from m in materials.DefaultIfEmpty()
|
||||
where d.TrustId == trustId
|
||||
orderby d.SortIndex
|
||||
select new AntiCorrosionTrustDetailOutput
|
||||
{
|
||||
Id = d.Id,
|
||||
TrustId = d.TrustId,
|
||||
SortIndex = d.SortIndex,
|
||||
MaterialCode = d.MaterialCode,
|
||||
Code = m == null ? string.Empty : m.Code,
|
||||
MaterialName = m == null ? string.Empty : m.MaterialName,
|
||||
MaterialSpec = m == null ? string.Empty : m.MaterialSpec,
|
||||
MaterialDef = m == null ? string.Empty : m.MaterialDef,
|
||||
MaterialUnit = m == null ? string.Empty : m.MaterialUnit,
|
||||
Quantity = d.Quantity,
|
||||
PaintCode = d.PaintCode,
|
||||
Primer = d.Primer,
|
||||
IntermediatePaint = d.IntermediatePaint,
|
||||
Topcoat = d.Topcoat,
|
||||
ColorCode = d.ColorCode,
|
||||
IsPostWeld = d.IsPostWeld,
|
||||
Remark = d.Remark
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public static List<AntiCorrosionTrustDetailOutput> GetDetailsByOutputMasterId(string outputMasterId)
|
||||
public static List<AntiCorrosionTrustDetailOutput> GetDetailsByTaskCode(string projectId, string taskCode)
|
||||
{
|
||||
var outputDetails = Funs.DB.Tw_OutputDetail
|
||||
.Where(x => x.OutputMasterId == outputMasterId)
|
||||
.OrderBy(x => x.Id)
|
||||
.ToList();
|
||||
var materialCodes = outputDetails.Select(x => x.MaterialCode).Where(x => !string.IsNullOrEmpty(x)).Distinct().ToList();
|
||||
var materials = Funs.DB.HJGL_MaterialCodeLib
|
||||
.Where(x => materialCodes.Contains(x.MaterialCode))
|
||||
.ToDictionary(x => x.MaterialCode, x => x);
|
||||
var weldJointIds = Funs.DB.HJGL_WeldTask
|
||||
.Where(x => x.ProjectId == projectId && x.TaskCode == taskCode && x.WeldJointId != null)
|
||||
.Select(x => x.WeldJointId).Distinct().ToList();
|
||||
return BuildDetailsByWeldJointIds(weldJointIds, false, false);
|
||||
}
|
||||
|
||||
var index = 0;
|
||||
var result = new List<AntiCorrosionTrustDetailOutput>();
|
||||
foreach (var detail in outputDetails)
|
||||
{
|
||||
index++;
|
||||
HJGL_MaterialCodeLib material = null;
|
||||
if (!string.IsNullOrEmpty(detail.MaterialCode) && materials.ContainsKey(detail.MaterialCode))
|
||||
{
|
||||
material = materials[detail.MaterialCode];
|
||||
}
|
||||
public static List<AntiCorrosionTrustDetailOutput> GetDetailsByHotProessTrustId(string hotProessTrustId)
|
||||
{
|
||||
var weldJointIds = Funs.DB.HJGL_HotProess_TrustItem
|
||||
.Where(x => x.HotProessTrustId == hotProessTrustId && x.IsCompleted == true
|
||||
&& Funs.DB.HJGL_HotProess_Report.Any(r => r.HotProessTrustItemId == x.HotProessTrustItemId))
|
||||
.Select(x => x.WeldJointId).Where(x => x != null).Distinct().ToList();
|
||||
return BuildDetailsByWeldJointIds(weldJointIds, true, true);
|
||||
}
|
||||
|
||||
// 防腐明细只保存材料主编码和数量,展示字段统一由材料编码库补齐。
|
||||
result.Add(new AntiCorrosionTrustDetailOutput
|
||||
private static List<AntiCorrosionTrustDetailOutput> BuildDetailsByWeldJointIds(
|
||||
List<string> weldJointIds, bool isPostWeld, bool fillComponentRemark)
|
||||
{
|
||||
if (weldJointIds == null || weldJointIds.Count == 0) return new List<AntiCorrosionTrustDetailOutput>();
|
||||
var materials = (from pm in Funs.DB.HJGL_PipeLineMat
|
||||
join material in Funs.DB.HJGL_MaterialCodeLib on pm.MaterialCode equals material.MaterialCode
|
||||
join joint in Funs.DB.HJGL_WeldJoint on pm.WeldJointId equals joint.WeldJointId
|
||||
join pipeline in Funs.DB.HJGL_Pipeline on joint.PipelineId equals pipeline.PipelineId into pipelines
|
||||
from pipeline in pipelines.DefaultIfEmpty()
|
||||
join paint in Funs.DB.Tw_PaintCodeDict on pipeline.PaintId equals paint.Id into paints
|
||||
from paint in paints.DefaultIfEmpty()
|
||||
where weldJointIds.Contains(pm.WeldJointId) && pm.MaterialCode != null
|
||||
select new
|
||||
{
|
||||
pm.MaterialCode,
|
||||
pm.Number,
|
||||
pm.PrefabricatedComponents,
|
||||
PaintId = pipeline == null ? null : pipeline.PaintId,
|
||||
PaintCode = paint == null ? null : paint.PaintCode,
|
||||
Primer = paint == null ? null : paint.Primer,
|
||||
IntermediatePaint = paint == null ? null : paint.IntermediatePaint,
|
||||
Topcoat = paint == null ? null : paint.Topcoat,
|
||||
ColorCode = paint == null ? null : paint.ColorCode,
|
||||
material.Code,
|
||||
material.MaterialName,
|
||||
material.MaterialSpec,
|
||||
material.MaterialDef,
|
||||
material.MaterialUnit
|
||||
}).ToList();
|
||||
|
||||
int index = 0;
|
||||
return materials.GroupBy(x => new { x.MaterialCode, x.PaintId })
|
||||
.OrderBy(x => x.Key.MaterialCode).ThenBy(x => x.Key.PaintId)
|
||||
.Select(group =>
|
||||
{
|
||||
Id = SQLHelper.GetNewID(),
|
||||
SortIndex = index,
|
||||
MaterialCode = detail.MaterialCode,
|
||||
Code = material == null ? string.Empty : material.Code,
|
||||
MaterialName = material == null ? string.Empty : material.MaterialName,
|
||||
MaterialSpec = material == null ? string.Empty : material.MaterialSpec,
|
||||
MaterialDef = material == null ? string.Empty : material.MaterialDef,
|
||||
MaterialUnit = material == null ? string.Empty : material.MaterialUnit,
|
||||
Quantity = detail.ActNum ?? detail.PlanNum
|
||||
});
|
||||
}
|
||||
return result;
|
||||
index++;
|
||||
var first = group.First();
|
||||
string remark = string.Empty;
|
||||
if (fillComponentRemark)
|
||||
{
|
||||
remark = string.Join("、", group.Select(x => x.PrefabricatedComponents)
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().OrderBy(x => x));
|
||||
}
|
||||
return new AntiCorrosionTrustDetailOutput
|
||||
{
|
||||
Id = SQLHelper.GetNewID(),
|
||||
SortIndex = index,
|
||||
MaterialCode = first.MaterialCode,
|
||||
Code = first.Code,
|
||||
MaterialName = first.MaterialName,
|
||||
MaterialSpec = first.MaterialSpec,
|
||||
MaterialDef = first.MaterialDef,
|
||||
MaterialUnit = first.MaterialUnit,
|
||||
Quantity = group.Sum(x => x.Number ?? 0),
|
||||
PaintCode = first.PaintCode,
|
||||
Primer = first.Primer,
|
||||
IntermediatePaint = first.IntermediatePaint,
|
||||
Topcoat = first.Topcoat,
|
||||
ColorCode = first.ColorCode,
|
||||
IsPostWeld = isPostWeld,
|
||||
Remark = remark
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public static List<PaintCodeDictOutput> GetPaintCodeList()
|
||||
{
|
||||
return Funs.DB.Tw_PaintCodeDict
|
||||
.Where(x => x.IsUsed)
|
||||
.OrderBy(x => x.SortIndex)
|
||||
.ThenBy(x => x.PaintCode)
|
||||
return Funs.DB.Tw_PaintCodeDict.Where(x => x.IsUsed).OrderBy(x => x.SortIndex).ThenBy(x => x.PaintCode)
|
||||
.Select(x => new PaintCodeDictOutput
|
||||
{
|
||||
Id = x.Id,
|
||||
@@ -268,15 +236,129 @@ namespace BLL
|
||||
Topcoat = x.Topcoat,
|
||||
ColorCode = x.ColorCode,
|
||||
SortIndex = x.SortIndex
|
||||
})
|
||||
.ToList();
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
public static void Save(AntiCorrosionTrustOutput trust, List<AntiCorrosionTrustDetailOutput> details)
|
||||
public static void Save(AntiCorrosionTrustOutput trust, List<AntiCorrosionTrustDetailOutput> details, bool splitOnSubmit)
|
||||
{
|
||||
var isNew = string.IsNullOrEmpty(trust.Id);
|
||||
Tw_AntiCorrosionTrust entity;
|
||||
if (isNew)
|
||||
if (trust == null) throw new ArgumentNullException("trust");
|
||||
var validDetails = (details ?? new List<AntiCorrosionTrustDetailOutput>())
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.MaterialCode)).OrderBy(x => x.SortIndex ?? int.MaxValue).ToList();
|
||||
if (validDetails.Count == 0) throw new ArgumentException("防腐委托单明细不能为空。");
|
||||
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
if (string.IsNullOrEmpty(trust.Id))
|
||||
{
|
||||
// 新单在保存事务内重新取号,页面预览编号不作为最终并发依据。
|
||||
trust.TrustCode = GenerateTrustCode(trust.UnitWorkId);
|
||||
}
|
||||
if (!splitOnSubmit || validDetails.Select(x => x.IsPostWeld).Distinct().Count() == 1)
|
||||
{
|
||||
var entity = SaveCategory(trust, validDetails, true, splitOnSubmit);
|
||||
trust.Id = entity.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool originalCategory = validDetails.First().IsPostWeld;
|
||||
var originalDetails = validDetails.Where(x => x.IsPostWeld == originalCategory).ToList();
|
||||
var splitDetails = validDetails.Where(x => x.IsPostWeld != originalCategory).ToList();
|
||||
var original = SaveCategory(trust, originalDetails, true, true);
|
||||
Funs.DB.SubmitChanges();
|
||||
|
||||
var splitTrust = new AntiCorrosionTrustOutput
|
||||
{
|
||||
ProjectId = trust.ProjectId,
|
||||
UnitWorkId = trust.UnitWorkId,
|
||||
ConstructionPart = trust.ConstructionPart,
|
||||
ConstructionProfessional = trust.ConstructionProfessional,
|
||||
TrustCode = GenerateTrustCode(trust.UnitWorkId),
|
||||
DemandDate = trust.DemandDate,
|
||||
CompleteDate = trust.CompleteDate,
|
||||
CreateMan = trust.CreateMan,
|
||||
// 来源ID只保留在原单,保证同一来源可可靠防重。
|
||||
WeldTaskCode = null,
|
||||
HotProessTrustId = null
|
||||
};
|
||||
SaveCategory(splitTrust, splitDetails, false, true);
|
||||
trust.Id = original.Id;
|
||||
}
|
||||
Funs.DB.SubmitChanges();
|
||||
scope.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateByTaskCode(string projectId, string taskCode, string createMan)
|
||||
{
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
var existingId = Funs.DB.ExecuteQuery<string>(
|
||||
"SELECT Id FROM dbo.Tw_AntiCorrosionTrust WITH (UPDLOCK,HOLDLOCK) WHERE ProjectId={0} AND WeldTaskCode={1}",
|
||||
projectId, taskCode).FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(existingId))
|
||||
{
|
||||
scope.Complete();
|
||||
return existingId;
|
||||
}
|
||||
var task = WeldTaskService.GetTaskDetail(projectId, taskCode);
|
||||
if (task == null) throw new ArgumentException("焊接任务单不存在。");
|
||||
var details = GetDetailsByTaskCode(projectId, taskCode);
|
||||
if (details.Count == 0) throw new ArgumentException("任务单没有可生成防腐委托的焊口材料。");
|
||||
var trust = new AntiCorrosionTrustOutput
|
||||
{
|
||||
ProjectId = projectId,
|
||||
UnitWorkId = task.UnitWorkId,
|
||||
TrustCode = GenerateTrustCode(task.UnitWorkId),
|
||||
WeldTaskCode = taskCode,
|
||||
DemandDate = task.TaskDate,
|
||||
CreateMan = createMan,
|
||||
Remark = "原材料防腐"
|
||||
};
|
||||
Save(trust, details, true);
|
||||
scope.Complete();
|
||||
return trust.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateByHotProessTrustId(string hotProessTrustId, string createMan)
|
||||
{
|
||||
using (var scope = new TransactionScope())
|
||||
{
|
||||
var existingId = Funs.DB.ExecuteQuery<string>(
|
||||
"SELECT Id FROM dbo.Tw_AntiCorrosionTrust WITH (UPDLOCK,HOLDLOCK) WHERE HotProessTrustId={0}",
|
||||
hotProessTrustId).FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(existingId))
|
||||
{
|
||||
scope.Complete();
|
||||
return existingId;
|
||||
}
|
||||
var hotTrust = Funs.DB.HJGL_HotProess_Trust.FirstOrDefault(x => x.HotProessTrustId == hotProessTrustId);
|
||||
if (hotTrust == null) throw new ArgumentException("热处理委托不存在。");
|
||||
var details = GetDetailsByHotProessTrustId(hotProessTrustId);
|
||||
if (details.Count == 0) throw new ArgumentException("当前热处理报告没有可生成防腐委托的已完成焊口材料。");
|
||||
var trust = new AntiCorrosionTrustOutput
|
||||
{
|
||||
ProjectId = hotTrust.ProjectId,
|
||||
UnitWorkId = hotTrust.UnitWorkId,
|
||||
TrustCode = GenerateTrustCode(hotTrust.UnitWorkId),
|
||||
HotProessTrustId = hotProessTrustId,
|
||||
CreateMan = createMan,
|
||||
Remark = "管段防腐"
|
||||
};
|
||||
Save(trust, details, true);
|
||||
scope.Complete();
|
||||
return trust.Id;
|
||||
}
|
||||
}
|
||||
|
||||
private static Tw_AntiCorrosionTrust SaveCategory(
|
||||
AntiCorrosionTrustOutput trust, List<AntiCorrosionTrustDetailOutput> details,
|
||||
bool keepSource, bool applyCategoryRemark)
|
||||
{
|
||||
var entity = string.IsNullOrEmpty(trust.Id)
|
||||
? null
|
||||
: Funs.DB.Tw_AntiCorrosionTrust.FirstOrDefault(x => x.Id == trust.Id);
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new Tw_AntiCorrosionTrust
|
||||
{
|
||||
@@ -287,42 +369,35 @@ namespace BLL
|
||||
};
|
||||
Funs.DB.Tw_AntiCorrosionTrust.InsertOnSubmit(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity = Funs.DB.Tw_AntiCorrosionTrust.FirstOrDefault(x => x.Id == trust.Id);
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception("防腐委托单不存在或已删除!");
|
||||
}
|
||||
}
|
||||
|
||||
bool isPostWeld = details.First().IsPostWeld;
|
||||
entity.UnitWorkId = trust.UnitWorkId;
|
||||
entity.ConstructionPart = trust.ConstructionPart;
|
||||
entity.ConstructionProfessional = trust.ConstructionProfessional;
|
||||
entity.TrustCode = trust.TrustCode;
|
||||
entity.OutputMasterId = trust.OutputMasterId;
|
||||
entity.WeldTaskCode = keepSource ? trust.WeldTaskCode : null;
|
||||
entity.HotProessTrustId = keepSource ? trust.HotProessTrustId : null;
|
||||
entity.DemandDate = trust.DemandDate;
|
||||
entity.CompleteDate = trust.CompleteDate;
|
||||
entity.Remark = trust.Remark;
|
||||
entity.Remark = applyCategoryRemark
|
||||
? (isPostWeld ? "管段防腐" : "原材料防腐")
|
||||
: trust.Remark;
|
||||
|
||||
var oldDetails = Funs.DB.Tw_AntiCorrosionTrustDetail.Where(x => x.TrustId == entity.Id).ToList();
|
||||
Funs.DB.Tw_AntiCorrosionTrustDetail.DeleteAllOnSubmit(oldDetails);
|
||||
|
||||
var paintMap = GetPaintCodeList().ToDictionary(x => x.PaintCode ?? string.Empty, x => x);
|
||||
var index = 0;
|
||||
foreach (var detail in details.Where(x => !string.IsNullOrEmpty(x.MaterialCode)))
|
||||
int index = 0;
|
||||
foreach (var detail in details)
|
||||
{
|
||||
index++;
|
||||
if (!string.IsNullOrEmpty(detail.PaintCode) && paintMap.ContainsKey(detail.PaintCode))
|
||||
PaintCodeDictOutput paint;
|
||||
if (!string.IsNullOrEmpty(detail.PaintCode) && paintMap.TryGetValue(detail.PaintCode, out paint))
|
||||
{
|
||||
var paint = paintMap[detail.PaintCode];
|
||||
detail.Primer = paint.Primer;
|
||||
detail.IntermediatePaint = paint.IntermediatePaint;
|
||||
detail.Topcoat = paint.Topcoat;
|
||||
detail.ColorCode = paint.ColorCode;
|
||||
}
|
||||
|
||||
// 涂漆代码保存时按字典补齐,避免前端联动遗漏造成打印字段为空。
|
||||
Funs.DB.Tw_AntiCorrosionTrustDetail.InsertOnSubmit(new Tw_AntiCorrosionTrustDetail
|
||||
{
|
||||
Id = SQLHelper.GetNewID(),
|
||||
@@ -335,12 +410,11 @@ namespace BLL
|
||||
IntermediatePaint = detail.IntermediatePaint,
|
||||
Topcoat = detail.Topcoat,
|
||||
ColorCode = detail.ColorCode,
|
||||
IsPostWeld = detail.IsPostWeld,
|
||||
Remark = detail.Remark
|
||||
});
|
||||
}
|
||||
|
||||
Funs.DB.SubmitChanges();
|
||||
trust.Id = entity.Id;
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static void DeleteById(string id)
|
||||
@@ -348,40 +422,33 @@ namespace BLL
|
||||
var details = Funs.DB.Tw_AntiCorrosionTrustDetail.Where(x => x.TrustId == id).ToList();
|
||||
Funs.DB.Tw_AntiCorrosionTrustDetail.DeleteAllOnSubmit(details);
|
||||
var trust = Funs.DB.Tw_AntiCorrosionTrust.FirstOrDefault(x => x.Id == id);
|
||||
if (trust != null)
|
||||
{
|
||||
Funs.DB.Tw_AntiCorrosionTrust.DeleteOnSubmit(trust);
|
||||
}
|
||||
if (trust != null) Funs.DB.Tw_AntiCorrosionTrust.DeleteOnSubmit(trust);
|
||||
Funs.DB.SubmitChanges();
|
||||
}
|
||||
|
||||
public static DataTable GetPrintMasterTable(string id)
|
||||
{
|
||||
var query = (from t in Funs.DB.Tw_AntiCorrosionTrust
|
||||
join p in Funs.DB.Base_Project on t.ProjectId equals p.ProjectId into projectJoin
|
||||
from p in projectJoin.DefaultIfEmpty()
|
||||
join uw in Funs.DB.WBS_UnitWork on t.UnitWorkId equals uw.UnitWorkId into uwJoin
|
||||
from uw in uwJoin.DefaultIfEmpty()
|
||||
join om in Funs.DB.Tw_OutputMaster on t.OutputMasterId equals om.Id into omJoin
|
||||
from om in omJoin.DefaultIfEmpty()
|
||||
join createPerson in Funs.DB.Person_Persons on t.CreateMan equals createPerson.PersonId into personJoin
|
||||
from createPerson in personJoin.DefaultIfEmpty()
|
||||
join p in Funs.DB.Base_Project on t.ProjectId equals p.ProjectId into projects
|
||||
from p in projects.DefaultIfEmpty()
|
||||
join uw in Funs.DB.WBS_UnitWork on t.UnitWorkId equals uw.UnitWorkId into unitWorks
|
||||
from uw in unitWorks.DefaultIfEmpty()
|
||||
join person in Funs.DB.Person_Persons on t.CreateMan equals person.PersonId into persons
|
||||
from person in persons.DefaultIfEmpty()
|
||||
where t.Id == id
|
||||
select new
|
||||
{
|
||||
p.ProjectName,
|
||||
uw.UnitWorkName,
|
||||
uw.UnitWorkCode,
|
||||
ProjectName = p == null ? string.Empty : p.ProjectName,
|
||||
UnitWorkName = uw == null ? string.Empty : uw.UnitWorkName,
|
||||
UnitWorkCode = uw == null ? string.Empty : uw.UnitWorkCode,
|
||||
t.ConstructionPart,
|
||||
t.ConstructionProfessional,
|
||||
t.TrustCode,
|
||||
OutputMasterCode = om.CusBillCode,
|
||||
OutputMasterCode = string.Empty,
|
||||
t.DemandDate,
|
||||
t.CompleteDate,
|
||||
CreateManName = createPerson.PersonName
|
||||
})
|
||||
.ToList()
|
||||
.Select(x => new
|
||||
CreateManName = person == null ? string.Empty : person.PersonName
|
||||
}).ToList().Select(x => new
|
||||
{
|
||||
x.ProjectName,
|
||||
x.UnitWorkName,
|
||||
@@ -399,39 +466,33 @@ namespace BLL
|
||||
|
||||
public static DataTable GetPrintDetailTable(string id)
|
||||
{
|
||||
var query = from d in Funs.DB.Tw_AntiCorrosionTrustDetail
|
||||
join m in Funs.DB.HJGL_MaterialCodeLib on d.MaterialCode equals m.MaterialCode into materialJoin
|
||||
from m in materialJoin.DefaultIfEmpty()
|
||||
where d.TrustId == id
|
||||
orderby d.SortIndex
|
||||
select new
|
||||
{
|
||||
d.SortIndex,
|
||||
m.MaterialName,
|
||||
m.Code,
|
||||
m.MaterialSpec,
|
||||
m.MaterialDef,
|
||||
m.MaterialUnit,
|
||||
d.Quantity,
|
||||
d.PaintCode,
|
||||
d.Primer,
|
||||
d.IntermediatePaint,
|
||||
d.Topcoat,
|
||||
d.ColorCode,
|
||||
d.Remark
|
||||
};
|
||||
return ToDataTable(query.ToList(), "Data");
|
||||
var query = GetDetailList(id).Select(x => new
|
||||
{
|
||||
x.SortIndex,
|
||||
x.Code,
|
||||
x.MaterialName,
|
||||
x.MaterialSpec,
|
||||
x.MaterialDef,
|
||||
x.MaterialUnit,
|
||||
x.Quantity,
|
||||
x.PaintCode,
|
||||
x.Primer,
|
||||
x.IntermediatePaint,
|
||||
x.Topcoat,
|
||||
x.ColorCode,
|
||||
IsPostWeld = x.IsPostWeld ? "是" : "否",
|
||||
x.Remark
|
||||
});
|
||||
// FastReport 防腐委托模板的数据带固定绑定 Data,表名必须与模板保持一致。
|
||||
return ToDataTable(query, "Data");
|
||||
}
|
||||
|
||||
private static int GetTrustCodeSerial(string trustCode)
|
||||
{
|
||||
if (string.IsNullOrEmpty(trustCode) || trustCode.Length < 3)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(trustCode)) return 0;
|
||||
int index = trustCode.LastIndexOf('-');
|
||||
int serial;
|
||||
return int.TryParse(trustCode.Substring(trustCode.Length - 3), out serial) ? serial : 0;
|
||||
return index >= 0 && int.TryParse(trustCode.Substring(index + 1), out serial) ? serial : 0;
|
||||
}
|
||||
|
||||
private static DataTable ToDataTable<T>(IEnumerable<T> data, string tableName)
|
||||
@@ -440,10 +501,8 @@ namespace BLL
|
||||
var properties = typeof(T).GetProperties();
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var propertyType = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType;
|
||||
table.Columns.Add(property.Name, propertyType);
|
||||
table.Columns.Add(property.Name, Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType);
|
||||
}
|
||||
|
||||
foreach (var item in data)
|
||||
{
|
||||
var row = table.NewRow();
|
||||
|
||||
@@ -1310,7 +1310,7 @@ namespace BLL
|
||||
MaterialName = g.Key.MaterialUnit,
|
||||
};
|
||||
|
||||
var outPlanDetailListPiece = outMateriaList.Where(x => x.MaterialName.Contains("个"));//管件
|
||||
var outPlanDetailListPiece = outMateriaList.Where(x => x.MaterialName.Contains("个")|| x.MaterialName.Contains("片"));//管件
|
||||
var outPlanDetailListOthere = outMateriaList.Where(x => x.MaterialName.Contains("米"));//管段
|
||||
var weldTaskCode = WeldTaskService.GetWeldTaskById(weldTask.WeldTaskId)?.TaskCode;
|
||||
var taskPipeline = PipelineService.GetPipelineByPipelineId(weldTask.PipelineId);
|
||||
@@ -1347,8 +1347,8 @@ namespace BLL
|
||||
};
|
||||
TwInOutplandetailService.Add(detail);
|
||||
}
|
||||
// 管件申请单只保存单位为“个”的材料关联,并同步记录焊口ID,便于追溯出库材料归属。
|
||||
var twinoutplandetailRelationList = MaterDatial.Where(x => x.MaterialUnit.Contains("个")).Select(x => new Tw_InOutPlanDetail_Relation
|
||||
// 管件申请单只保存单位为“个”和“片”的材料关联,并同步记录焊口ID,便于追溯出库材料归属。
|
||||
var twinoutplandetailRelationList = MaterDatial.Where(x => x.MaterialUnit.Contains("个") || x.MaterialUnit.Contains("片")).Select(x => new Tw_InOutPlanDetail_Relation
|
||||
{
|
||||
PipelineId = x.PipelineId,
|
||||
MaterialCode = x.MaterialCode,
|
||||
|
||||
Reference in New Issue
Block a user