GP12触摸屏代码重构

This commit is contained in:
2025-02-14 17:26:56 +08:00
parent 965f17eecd
commit 96e0986a0e
5 changed files with 175 additions and 3 deletions

View File

@@ -176,5 +176,28 @@ namespace ZR.Admin.WebApi.Controllers
return SUCCESS(response); return SUCCESS(response);
} }
/// <summary>
/// 自动生成标签记录
/// </summary>
/// <returns></returns>
[HttpPost("GenerateVirtualLabel")]
[AllowAnonymous]
public IActionResult GenerateVirtualLabel([FromBody] QcGp12WorkorderDetailDto parm)
{
try
{
var modal = parm.Adapt<QcGp12WorkorderDetailDto>().ToCreate(HttpContext);
var response = _QcGp12Service.GenerateVirtualLabel(modal);
return SUCCESS(response);
}
catch (Exception ex)
{
return ToResponse(ApiResult.Error(ex.Message));
}
}
} }
} }

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<key id="f640f114-5530-4155-93d1-18881f207ae2" version="1">
<creationDate>2025-02-10T03:30:32.3322015Z</creationDate>
<activationDate>2025-02-10T03:30:32.1838996Z</activationDate>
<expirationDate>2025-05-11T03:30:32.1838996Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<descriptor>
<encryption algorithm="AES_256_CBC" />
<validation algorithm="HMACSHA256" />
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
<!-- Warning: the key below is in an unencrypted form. -->
<value>REaFIE6cup/0qF8KszWBx7UGvUJ57UOYEZuPcYu50gGn3+pASnFwUdgwwDFLRKozGD0w9lLToqhYT4gEcPT4rA==</value>
</masterKey>
</descriptor>
</descriptor>
</key>

View File

@@ -289,6 +289,7 @@ namespace ZR.Model.MES.wms
/// 是否是返工件 /// 是否是返工件
/// </summary> /// </summary>
[SugarColumn(ColumnName = "is_return_workpiece")] [SugarColumn(ColumnName = "is_return_workpiece")]
//[SugarColumn(IsIgnore = true)]
public bool IsReturnWorkpiece { get; set; } = false; public bool IsReturnWorkpiece { get; set; } = false;
/// <summary> /// <summary>

View File

@@ -38,8 +38,8 @@ namespace ZR.Service.Business.IBusinessService
/// <summary> /// <summary>
/// 解析标签 /// 解析标签
/// </summary> /// </summary>
/// <param name="label">标签内容</param> /// <param name="label">标签内容 扫码内容</param>
/// <param name="type">解析方法</param> /// <param name="type">解析方法 1-全解析 2-只看零件号</param>
/// <returns></returns> /// <returns></returns>
QcGp12LabelAnalysisDto AnalyzeLabelToDto(string label,int type); QcGp12LabelAnalysisDto AnalyzeLabelToDto(string label,int type);
@@ -76,8 +76,15 @@ namespace ZR.Service.Business.IBusinessService
/// <summary> /// <summary>
/// 更新工单相关信息 /// 更新工单相关信息
/// </summary> /// </summary>
/// <param name="workorder"></param> /// <param name="workorder">工单号</param>
/// <returns></returns> /// <returns></returns>
public QcGp12ServiceWorkorder UpdateWorkOrderDetail(string workorder); public QcGp12ServiceWorkorder UpdateWorkOrderDetail(string workorder);
/// <summary>
/// 生成虚拟标签
/// </summary>
/// <param name="workorderDetail">工单信息</param>
/// <returns></returns>
public QcGp12ServiceWorkorder GenerateVirtualLabel(QcGp12WorkorderDetailDto workorderDetail);
} }
} }

View File

@@ -253,6 +253,16 @@ namespace ZR.Service.Business
// 没有旧记录则开启新的记录 // 没有旧记录则开启新的记录
try try
{ {
// 检查箱标签是否当内标签扫过
bool isInnerLabelScan = Context
.Queryable<QcGp12RecordLabelScan>()
.Where(it => it.Label == data.Label)
.Where(it => it.LabelType == 2)
.Any();
if (isInnerLabelScan)
{
throw new Exception("标签异常,该标签已经当内标签扫过!");
}
Context.Ado.BeginTran(); Context.Ado.BeginTran();
DateTime nowTime = DateTime.Now; DateTime nowTime = DateTime.Now;
// 创建新工单号 // 创建新工单号
@@ -768,5 +778,120 @@ namespace ZR.Service.Business
(double)data.QualifiedNumber.Value / data.RequireNumber.Value * 100; (double)data.QualifiedNumber.Value / data.RequireNumber.Value * 100;
return $"{qualifiedRate:F1}%"; return $"{qualifiedRate:F1}%";
} }
public QcGp12ServiceWorkorder GenerateVirtualLabel(QcGp12WorkorderDetailDto workorderDetail)
{
try
{
Context.Ado.BeginTran();
// 检查当前工单已扫码合格数
int qualifiedNumber = workorderDetail.QualifiedNumber ?? -1;
if (qualifiedNumber < 0)
{
throw new ArgumentException("传入合格数异常!", nameof(workorderDetail.QualifiedNumber));
}
int labelCount = GetLabelCountForWorkOrder(workorderDetail.WorkOrder);
if (labelCount < qualifiedNumber)
{
GenerateVirtualLabels(workorderDetail, qualifiedNumber - labelCount);
}
else if (labelCount > qualifiedNumber)
{
DeleteExcessLabels(workorderDetail.WorkOrder, labelCount - qualifiedNumber);
}
Context.Ado.CommitTran();
return UpdateWorkOrderDetail(workorderDetail.WorkOrder);
}
catch (Exception e)
{
Context.Ado.RollbackTran();
throw new Exception($"生成虚拟标签时出错: {e.Message}", e);
}
}
private int GetLabelCountForWorkOrder(string workOrder)
{
return Context.Queryable<QcGp12RecordLabelScan>()
.Where(it => it.WorkOrder == workOrder && it.LabelType == 2)
.Count();
}
private void GenerateVirtualLabels(QcGp12WorkorderDetailDto workOrderDetail, int countToGenerate)
{
List<QcGp12RecordLabelScan> virtualLabels = new List<QcGp12RecordLabelScan>();
int nextLabelNumber = GetNextLabelNumber(workOrderDetail.WorkOrder);
for (int i = 0; i < countToGenerate; i++)
{
string uniqueLabel = GenerateUniqueSequentialLabel(workOrderDetail.WorkOrder, nextLabelNumber++);
virtualLabels.Add(new QcGp12RecordLabelScan
{
Id = SnowFlakeSingle.Instance.NextId().ToString(),
WorkOrder = workOrderDetail.WorkOrder,
PartNumber = workOrderDetail.PartNumber,
Team = workOrderDetail.Team,
SiteNo = workOrderDetail.SiteNo,
ComNo = workOrderDetail.ComNo,
ScanTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
Type = "2",
Status = "1",
Remark = "虚拟标签",
CreatedTime = DateTime.UtcNow,
CreatedBy = "系统",
LabelType = 2,
LabelSort = nextLabelNumber,
Label = uniqueLabel
});
}
Context.Insertable(virtualLabels).ExecuteCommand();
}
private void DeleteExcessLabels(string workOrder, int countToDelete)
{
var labelsToDelete = Context.Queryable<QcGp12RecordLabelScan>()
.Where(it => it.WorkOrder == workOrder && it.LabelType == 2)
.OrderByDescending(it => it.LabelSort)
.Take(countToDelete)
.ToList();
Context.Deleteable(labelsToDelete).ExecuteCommand();
}
private int GetNextLabelNumber(string workOrder)
{
return Context.Queryable<QcGp12RecordLabelScan>()
.Where(it => it.WorkOrder == workOrder && it.LabelType == 2)
.Max(it => it.LabelSort ?? 0);
}
private string GenerateUniqueSequentialLabel(string workOrder, int number)
{
const string prefix = "VIRT";
string baseLabel = $"{prefix}-{GenerateUniqueId()}-{number:D5}";
string uniqueLabel = baseLabel;
while (IsLabelExists(workOrder, uniqueLabel))
{
uniqueLabel = $"{baseLabel}-{GenerateUniqueId()}";
}
return uniqueLabel;
}
private bool IsLabelExists(string workOrder, string label)
{
return Context.Queryable<QcGp12RecordLabelScan>()
.Any(it => it.WorkOrder == workOrder && it.LabelType == 2 && it.Label == label);
}
private string GenerateUniqueId()
{
return Guid.NewGuid().ToString("N").Substring(0, 10); // Generate a 10-character unique ID
}
} }
} }