refactor(工单导入): 重构工单序号生成逻辑
将工单序号生成逻辑拆分为10线和其他线分别处理 10线从101开始编号,其他线统一从1开始编号 移除不再需要的currentIndex变量
This commit is contained in:
@@ -464,8 +464,11 @@ namespace DOAN.Service.MES.product
|
||||
int currentSort = (maxSort / 10) * 10 + 10;
|
||||
|
||||
// 直接按照Excel导入顺序生成工单号
|
||||
// 用于跟踪RouteCode为10的工单序号
|
||||
// 用于跟踪10线的工单序号
|
||||
int? route10CurrentIndex = null;
|
||||
// 用于跟踪其他线的统一工单序号
|
||||
int? otherRouteCurrentIndex = null;
|
||||
|
||||
foreach (var workorder in workorderList)
|
||||
{
|
||||
string nickCode = mmMaterials
|
||||
@@ -473,14 +476,16 @@ namespace DOAN.Service.MES.product
|
||||
.Select(it => it.Type)
|
||||
.FirstOrDefault();
|
||||
|
||||
// 特殊处理:当RouteCode为10时,计数从101开始
|
||||
int indexToUse = currentIndex;
|
||||
if (workorder.RouteCode == "10")
|
||||
// 获取当前线别的序号
|
||||
int indexToUse;
|
||||
string routeCode = workorder.RouteCode;
|
||||
|
||||
if (routeCode == "10")
|
||||
{
|
||||
// 第一次处理RouteCode为10的工单时,查询数据库获取最大序号
|
||||
// 10线特殊处理,从101开始
|
||||
if (!route10CurrentIndex.HasValue)
|
||||
{
|
||||
// 检查是否已经有RouteCode为10的工单
|
||||
// 第一次处理10线工单时,查询数据库获取最大序号
|
||||
var route10Workorders = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.WorkorderDate == dateValue.Date)
|
||||
@@ -509,11 +514,43 @@ namespace DOAN.Service.MES.product
|
||||
}
|
||||
else
|
||||
{
|
||||
// 后续的RouteCode为10的工单,直接在内存中递增序号
|
||||
// 后续的10线工单,直接在内存中递增序号
|
||||
route10CurrentIndex++;
|
||||
}
|
||||
indexToUse = route10CurrentIndex.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 其他线统一编号,从1开始
|
||||
if (!otherRouteCurrentIndex.HasValue)
|
||||
{
|
||||
// 第一次处理其他线工单时,查询数据库获取最大序号
|
||||
var otherRouteWorkorders = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.WorkorderDate == dateValue.Date)
|
||||
.Where(it => it.RouteCode != "10")
|
||||
.Select(it => it.Workorder)
|
||||
.ToList()
|
||||
.Where(w => w.StartsWith(dateValue.ToString("yyyyMMdd")))
|
||||
.Select(w =>
|
||||
{
|
||||
var parts = w.Split('_');
|
||||
if (parts.Length >= 4 && int.TryParse(parts[3], out int index))
|
||||
return index;
|
||||
return 0;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
int otherRouteMaxIndex = otherRouteWorkorders.Count > 0 ? otherRouteWorkorders.Max() : 0;
|
||||
otherRouteCurrentIndex = otherRouteMaxIndex + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 后续的其他线工单,直接在内存中递增序号
|
||||
otherRouteCurrentIndex++;
|
||||
}
|
||||
indexToUse = otherRouteCurrentIndex.Value;
|
||||
}
|
||||
|
||||
// 生成唯一的工单编号
|
||||
var generateResult = GenerateUniqueWorkorderNo(workorder, dateValue, indexToUse, nickCode);
|
||||
@@ -522,7 +559,6 @@ namespace DOAN.Service.MES.product
|
||||
workorder.Sort = currentSort;
|
||||
|
||||
Logger.Info($"生成工单编号: {workorder.Workorder},产品: {workorder.productionName},sort: {currentSort}");
|
||||
currentIndex = generateResult.Item2 + 1;
|
||||
// 增加sort值,确保下一个工单的sort值为当前值+10
|
||||
currentSort += 10;
|
||||
}
|
||||
@@ -590,8 +626,11 @@ namespace DOAN.Service.MES.product
|
||||
int currentSort = (maxSort / 10) * 10 + 10;
|
||||
|
||||
// 直接按照Excel导入顺序生成工单号
|
||||
// 用于跟踪RouteCode为10的工单序号
|
||||
// 用于跟踪10线的工单序号
|
||||
int? route10CurrentIndex = null;
|
||||
// 用于跟踪其他线的统一工单序号
|
||||
int? otherRouteCurrentIndex = null;
|
||||
|
||||
foreach (var workorder in workorderList)
|
||||
{
|
||||
string nickCode = mmMaterials
|
||||
@@ -599,14 +638,16 @@ namespace DOAN.Service.MES.product
|
||||
.Select(it => it.Type)
|
||||
.FirstOrDefault();
|
||||
|
||||
// 特殊处理:当RouteCode为10时,计数从101开始
|
||||
int indexToUse = currentIndex;
|
||||
if (workorder.RouteCode == "10")
|
||||
// 获取当前线别的序号
|
||||
int indexToUse;
|
||||
string routeCode = workorder.RouteCode;
|
||||
|
||||
if (routeCode == "10")
|
||||
{
|
||||
// 第一次处理RouteCode为10的工单时,查询数据库获取最大序号
|
||||
// 10线特殊处理,从101开始
|
||||
if (!route10CurrentIndex.HasValue)
|
||||
{
|
||||
// 检查是否已经有RouteCode为10的工单
|
||||
// 第一次处理10线工单时,查询数据库获取最大序号
|
||||
var route10Workorders = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.WorkorderDate == dateValue.Date)
|
||||
@@ -635,11 +676,43 @@ namespace DOAN.Service.MES.product
|
||||
}
|
||||
else
|
||||
{
|
||||
// 后续的RouteCode为10的工单,直接在内存中递增序号
|
||||
// 后续的10线工单,直接在内存中递增序号
|
||||
route10CurrentIndex++;
|
||||
}
|
||||
indexToUse = route10CurrentIndex.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 其他线统一编号,从1开始
|
||||
if (!otherRouteCurrentIndex.HasValue)
|
||||
{
|
||||
// 第一次处理其他线工单时,查询数据库获取最大序号
|
||||
var otherRouteWorkorders = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => it.WorkorderDate == dateValue.Date)
|
||||
.Where(it => it.RouteCode != "10")
|
||||
.Select(it => it.Workorder)
|
||||
.ToList()
|
||||
.Where(w => w.StartsWith(dateValue.ToString("yyyyMMdd")))
|
||||
.Select(w =>
|
||||
{
|
||||
var parts = w.Split('_');
|
||||
if (parts.Length >= 4 && int.TryParse(parts[3], out int index))
|
||||
return index;
|
||||
return 0;
|
||||
})
|
||||
.ToList();
|
||||
|
||||
int otherRouteMaxIndex = otherRouteWorkorders.Count > 0 ? otherRouteWorkorders.Max() : 0;
|
||||
otherRouteCurrentIndex = otherRouteMaxIndex + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 后续的其他线工单,直接在内存中递增序号
|
||||
otherRouteCurrentIndex++;
|
||||
}
|
||||
indexToUse = otherRouteCurrentIndex.Value;
|
||||
}
|
||||
|
||||
// 生成唯一的工单编号
|
||||
var generateResult = GenerateUniqueWorkorderNo(workorder, dateValue, indexToUse, nickCode);
|
||||
@@ -648,7 +721,6 @@ namespace DOAN.Service.MES.product
|
||||
workorder.Sort = currentSort;
|
||||
|
||||
Logger.Info($"生成工单编号: {workorder.Workorder},产品: {workorder.productionName},sort: {currentSort}");
|
||||
currentIndex = generateResult.Item2 + 1;
|
||||
// 增加sort值,确保下一个工单的sort值为当前值+10
|
||||
currentSort += 10;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user