123
This commit is contained in:
@@ -354,7 +354,7 @@ namespace ZR.Service.Business
|
||||
ComNo = result.ComNo,
|
||||
Label = result.Label,
|
||||
LabelType = 1,
|
||||
LabelSort = 1,
|
||||
LabelSort = 0,
|
||||
ScanTime = $"{nowTime:yyyy-MM-dd HH:mm:ss}",
|
||||
Type = "1",
|
||||
Status = "1",
|
||||
@@ -688,10 +688,30 @@ namespace ZR.Service.Business
|
||||
if (hasAny)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "内标签重复扫码!";
|
||||
return "此内标签已扫过,禁止重复扫码!";
|
||||
}
|
||||
// 标签录入
|
||||
int sort = 0;
|
||||
// 内标签工单确认
|
||||
QcBackEndServiceWorkorder workorder = Context
|
||||
.Queryable<QcBackEndServiceWorkorder>()
|
||||
.Where(it => it.WorkOrder == data.WorkOrder)
|
||||
.First();
|
||||
if (workorder == null)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return $"工单异常:工单不存在{data.WorkOrder}";
|
||||
}
|
||||
// 打印配置确认
|
||||
QcBackendBaseOutpackage packageLabelConfig = Context
|
||||
.Queryable<QcBackendBaseOutpackage>()
|
||||
.Where(it => workorder.Description.Contains(it.CheckStr))
|
||||
.First();
|
||||
if (packageLabelConfig == null)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return $"该产品内标签,未检测到对应打印参数:{data.PartNumber}";
|
||||
}
|
||||
// 上一个内标签流水号检查
|
||||
int oldInnerLabelSort = 0;
|
||||
QcBackEndRecordLabelScan labelScan = Context
|
||||
.Queryable<QcBackEndRecordLabelScan>()
|
||||
.Where(it => it.WorkOrder == data.WorkOrder)
|
||||
@@ -700,8 +720,44 @@ namespace ZR.Service.Business
|
||||
.First();
|
||||
if (labelScan != null)
|
||||
{
|
||||
sort = labelScan.LabelSort ?? 0;
|
||||
oldInnerLabelSort = labelScan.LabelSort ?? 0;
|
||||
}
|
||||
|
||||
// 上一个箱标签流水号
|
||||
int oldPackageLabelSort = 0;
|
||||
QcBackEndRecordLabelScan packageLabelScan = Context
|
||||
.Queryable<QcBackEndRecordLabelScan>()
|
||||
.Where(it => it.WorkOrder == data.WorkOrder)
|
||||
.Where(it => it.LabelType == 1)
|
||||
.OrderByDescending(it => it.LabelSort)
|
||||
.First();
|
||||
if(packageLabelScan != null)
|
||||
{
|
||||
oldPackageLabelSort = packageLabelScan.LabelSort ?? 0;
|
||||
}
|
||||
// 内标签总数
|
||||
int innerLabelCount = Context.Queryable<QcBackEndRecordLabelScan>()
|
||||
.Where(it => it.WorkOrder == data.WorkOrder)
|
||||
.Where(it => it.LabelType == 2)
|
||||
.Count();
|
||||
// 箱标签总数
|
||||
int packageLabelCount = Context.Queryable<QcBackEndRecordLabelScan>()
|
||||
.Where(it => it.WorkOrder == data.WorkOrder)
|
||||
.Where(it => it.LabelType == 1)
|
||||
.Count();
|
||||
packageLabelCount -= 1;
|
||||
if(packageLabelCount < 0)
|
||||
{
|
||||
packageLabelCount = 0;
|
||||
}
|
||||
|
||||
// 新内标签流水号
|
||||
int newInnerLabelSort = oldInnerLabelSort + 1;
|
||||
// 新外标签流水号
|
||||
int newPackageLabelSort = oldPackageLabelSort + 1;
|
||||
// 满箱数
|
||||
int maxPackage = packageLabelConfig.PackageNum ?? 0;
|
||||
// 新标签录入
|
||||
QcBackEndRecordLabelScan newLabelScran =
|
||||
new()
|
||||
{
|
||||
@@ -713,22 +769,85 @@ namespace ZR.Service.Business
|
||||
ComNo = data.ComNo,
|
||||
Label = data.Label,
|
||||
LabelType = 2,
|
||||
LabelSort = sort + 1,
|
||||
LabelSort = newInnerLabelSort,
|
||||
ScanTime = $"{nowTime:yyyy-MM-dd HH:mm:ss}",
|
||||
Type = "1",
|
||||
Status = "1",
|
||||
Remark = "扫描标签",
|
||||
Remark = "",
|
||||
CreatedBy = data.CreatedBy,
|
||||
CreatedTime = data.CreatedTime,
|
||||
};
|
||||
int res = Context.Insertable(newLabelScran).ExecuteCommand();
|
||||
if (res == 0)
|
||||
|
||||
//20250516 TODO 判断下一次是否要扫满箱标签
|
||||
// XXX 满箱判断锁,预留
|
||||
bool IsCheckFullPackage = true;
|
||||
|
||||
// 判断是否是扫的后道箱标签
|
||||
bool isPackageLabel = false;
|
||||
string checkPackageLabelStr = "LabelType=1";
|
||||
if (data.Label.Contains(checkPackageLabelStr))
|
||||
{
|
||||
isPackageLabel = true;
|
||||
}
|
||||
if (isPackageLabel)
|
||||
{
|
||||
bool hasAnyPackageLabel = Context
|
||||
.Queryable<QcBackEndRecordLabelScan>()
|
||||
.Where(it => it.Label == data.Label)
|
||||
.Where(it => it.LabelType == 1)
|
||||
.Any();
|
||||
if (hasAnyPackageLabel)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "此箱标签已扫过,禁止重复扫码!";
|
||||
}
|
||||
}
|
||||
// 是否需要扫后道箱标签
|
||||
bool needScanPackageLabel = packageLabelCount * maxPackage < innerLabelCount;
|
||||
// 扫描的是箱标签时 判断是否需要扫箱标签(是箱标签,需要扫,上一组内标签满了)
|
||||
if (isPackageLabel && IsCheckFullPackage )
|
||||
{
|
||||
// 需要扫并且内标签也满了,扫完录入
|
||||
if (oldInnerLabelSort >= maxPackage && oldInnerLabelSort % maxPackage == 0 && needScanPackageLabel)
|
||||
{
|
||||
newLabelScran.LabelType = 1;
|
||||
newLabelScran.LabelSort = newPackageLabelSort;
|
||||
newLabelScran.Remark = "扫描箱标签";
|
||||
|
||||
int res1 = Context.Insertable(newLabelScran).ExecuteCommand();
|
||||
if (res1 == 0)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "箱标签录入系统失败!";
|
||||
}
|
||||
Context.Ado.CommitTran();
|
||||
return "箱标签扫入成功!";
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "未满箱,或已扫过箱标签,不需要再次扫箱标签!";
|
||||
}
|
||||
}
|
||||
// 扫描非箱标签,判断此时是否要扫外箱标签
|
||||
if (IsCheckFullPackage && newInnerLabelSort >= maxPackage && newInnerLabelSort % maxPackage == 1 && needScanPackageLabel)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "标签录入系统失败!";
|
||||
return $"已满箱,请扫描箱标签!当前满箱判断数:{maxPackage}";
|
||||
}
|
||||
//TODO 触发箱标签判定
|
||||
CheckAndPrintPackageLabel(newLabelScran);
|
||||
// 已扫过则继续扫内箱标签
|
||||
//TODO 其他情况触发箱标签打印判定
|
||||
newLabelScran.LabelType = 2;
|
||||
newLabelScran.LabelSort = newInnerLabelSort;
|
||||
newLabelScran.Remark = "";
|
||||
int res2 = Context.Insertable(newLabelScran).ExecuteCommand();
|
||||
if (res2 == 0)
|
||||
{
|
||||
Context.Ado.RollbackTran();
|
||||
return "产标签录入系统失败!";
|
||||
}
|
||||
CheckAndPrintPackageLabel(newLabelScran, packageLabelConfig);
|
||||
|
||||
Context.Ado.CommitTran();
|
||||
return "ok";
|
||||
}
|
||||
@@ -743,26 +862,9 @@ namespace ZR.Service.Business
|
||||
/// 判断是否需要自动出满箱标签
|
||||
/// </summary>
|
||||
/// <param name="workorder"></param>
|
||||
public void CheckAndPrintPackageLabel(QcBackEndRecordLabelScan newLabelScran)
|
||||
public void CheckAndPrintPackageLabel(QcBackEndRecordLabelScan newLabelScran,QcBackendBaseOutpackage packageLabelConfig)
|
||||
{
|
||||
DateTime nowTime = DateTime.Now;
|
||||
// 找到最大箱容量与打印模板
|
||||
QcBackEndServiceWorkorder workorder = Context
|
||||
.Queryable<QcBackEndServiceWorkorder>()
|
||||
.Where(it => it.WorkOrder == newLabelScran.WorkOrder)
|
||||
.First();
|
||||
QcBackendBaseOutpackage packageLabelConfig = Context
|
||||
.Queryable<QcBackendBaseOutpackage>()
|
||||
.Where(it => workorder.Description.Contains(it.CheckStr))
|
||||
.First();
|
||||
if (workorder == null)
|
||||
{
|
||||
throw new Exception($"工单异常:内标签工单不存在{newLabelScran.WorkOrder}");
|
||||
}
|
||||
if (packageLabelConfig == null)
|
||||
{
|
||||
throw new Exception($"该产品内标签对应打印参数未配置:{newLabelScran.PartNumber}");
|
||||
}
|
||||
// 判断是否需要自动出满箱标签
|
||||
int checkSort = newLabelScran.LabelSort ?? 0;
|
||||
int maxPackage = packageLabelConfig.PackageNum ?? 0;
|
||||
@@ -871,11 +973,11 @@ namespace ZR.Service.Business
|
||||
}
|
||||
// 提取产品描述
|
||||
WmMaterial material = Context
|
||||
.Queryable<WmMaterial>()
|
||||
.Where(it => it.Partnumber == newLabelScran.PartNumber)
|
||||
.Where(it => it.Type == 1)
|
||||
.Where(it => it.Status == 1)
|
||||
.First();
|
||||
.Queryable<WmMaterial>()
|
||||
.Where(it => it.Partnumber == newLabelScran.PartNumber)
|
||||
.Where(it => it.Type == 1)
|
||||
.Where(it => it.Status == 1)
|
||||
.First();
|
||||
|
||||
// 解析产品批次号,如果没有,则生成最新批次号
|
||||
string batchCode = DoAnalyzeBatchCode(newLabelScran.Label);
|
||||
@@ -884,10 +986,10 @@ namespace ZR.Service.Business
|
||||
batchCode = DateTime.Now.ToString("yyMMdd") + "000";
|
||||
}
|
||||
// 生成工单号
|
||||
string workOrder = $"{batchCode}_{packageSort}{newLabelScran.Team}1";
|
||||
string workOrder = $"{batchCode}_{packageSort}";
|
||||
string newLabelCode =
|
||||
$"Code=BNW{workOrder}^ItemNumber={newLabelScran.PartNumber}^Order=W{workOrder}^Qty={maxPackage}^LabelType=1^LabelBy=HD";
|
||||
string newPackageCode = $"BOX:BNW{workOrder}";
|
||||
$"Code=BNW{workOrder}^ItemNumber={newLabelScran.PartNumber}^Order=W{workOrder}^Qty={maxPackage}^LabelType=1^LabelBy=HD^Team={newLabelScran.Team}";
|
||||
string newPackageCode = $"BOX:BNW{workOrder}{newLabelScran.Team}1";
|
||||
QcBackEndPrintMqttEventDto mqttEventDto =
|
||||
new()
|
||||
{
|
||||
@@ -902,7 +1004,7 @@ namespace ZR.Service.Business
|
||||
PackageCode = newPackageCode,
|
||||
Team = newLabelScran.Team,
|
||||
Sort = packageSort,
|
||||
ProductionTime = batchCode.Substring(6),
|
||||
ProductionTime = "20" + batchCode.Substring(0,6),
|
||||
BatchCode = batchCode,
|
||||
PackageNum = maxPackage,
|
||||
LabelCode = newLabelCode,
|
||||
|
||||
Reference in New Issue
Block a user