diff --git a/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackEndController.cs b/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackEndController.cs
index b05bae9a..3bbe9932 100644
--- a/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackEndController.cs
+++ b/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackEndController.cs
@@ -159,6 +159,49 @@ namespace ZR.Admin.WebApi.Controllers
}
+ ///
+ /// 扫描外箱标签,添加想标签记录
+ ///
+ ///
+ [HttpPost("ScanPackageLabel")]
+ [AllowAnonymous]
+ public IActionResult ScanPackageLabel([FromBody] QcBackEndLabelScanDto parm)
+ {
+ try
+ {
+ var modal = parm.Adapt().ToCreate(HttpContext);
+
+ var response = _QcBackEndService.ScanPackageLabel(modal);
+
+ return SUCCESS(response);
+ }
+ catch (Exception ex)
+ {
+ return SUCCESS("请刷新页面,错误代码:" + ex.Message);
+ }
+
+ }
+
+ ///
+ /// 判断是否要扫描箱标签
+ ///
+ ///
+ [HttpGet("CheckPackageIsFullAndNeedScanPackageLabel")]
+ [AllowAnonymous]
+ public IActionResult CheckPackageIsFullAndNeedScanPackageLabel(string workorder)
+ {
+ try
+ {
+ var response = _QcBackEndService.CheckPackageIsFullAndNeedScanPackageLabel(workorder);
+ return SUCCESS(response);
+ }
+ catch (Exception ex)
+ {
+ return SUCCESS("检查是否要扫描箱标签功能异常:" + ex.Message);
+ }
+
+ }
+
///
/// 结束工单,并生成质量报表
///
diff --git a/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackendRecordLabelPrintController.cs b/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackendRecordLabelPrintController.cs
new file mode 100644
index 00000000..9323157b
--- /dev/null
+++ b/ZR.Admin.WebApi/Controllers/mes/qc/backend/QcBackendRecordLabelPrintController.cs
@@ -0,0 +1,109 @@
+using Microsoft.AspNetCore.Mvc;
+using ZR.Model.Dto;
+using ZR.Model.Business;
+using ZR.Service.Business.IBusinessService;
+using ZR.Admin.WebApi.Extensions;
+using ZR.Admin.WebApi.Filters;
+
+//创建时间:2025-05-22
+namespace ZR.Admin.WebApi.Controllers
+{
+ ///
+ /// 后道标签打印记录
+ ///
+ [Verify]
+ [Route("/mes/qc/BackEnd/QcBackendRecordLabelPrint")]
+ public class QcBackendRecordLabelPrintController : BaseController
+ {
+ ///
+ /// 后道标签打印记录接口
+ ///
+ private readonly IQcBackendRecordLabelPrintService _QcBackendRecordLabelPrintService;
+
+ public QcBackendRecordLabelPrintController(IQcBackendRecordLabelPrintService QcBackendRecordLabelPrintService)
+ {
+ _QcBackendRecordLabelPrintService = QcBackendRecordLabelPrintService;
+ }
+
+ ///
+ /// 查询后道标签打印记录列表
+ ///
+ ///
+ ///
+ [HttpGet("list")]
+ [ActionPermissionFilter(Permission = "business:qcbackendrecordlabelprint:list")]
+ public IActionResult QueryQcBackendRecordLabelPrint([FromQuery] QcBackendRecordLabelPrintQueryDto parm)
+ {
+ var response = _QcBackendRecordLabelPrintService.GetList(parm);
+ return SUCCESS(response);
+ }
+
+
+ ///
+ /// 查询后道标签打印记录详情
+ ///
+ ///
+ ///
+ [HttpGet("{Id}")]
+ [ActionPermissionFilter(Permission = "business:qcbackendrecordlabelprint:query")]
+ public IActionResult GetQcBackendRecordLabelPrint(string Id)
+ {
+ var response = _QcBackendRecordLabelPrintService.GetInfo(Id);
+
+ var info = response.Adapt();
+ return SUCCESS(info);
+ }
+
+ ///
+ /// 添加后道标签打印记录
+ ///
+ ///
+ [HttpPost]
+ [ActionPermissionFilter(Permission = "business:qcbackendrecordlabelprint:add")]
+ [Log(Title = "后道标签打印记录", BusinessType = BusinessType.INSERT)]
+ public IActionResult AddQcBackendRecordLabelPrint([FromBody] QcBackendRecordLabelPrintDto parm)
+ {
+ var modal = parm.Adapt().ToCreate(HttpContext);
+
+ var response = _QcBackendRecordLabelPrintService.AddQcBackendRecordLabelPrint(modal);
+
+ return SUCCESS(response);
+ }
+
+ ///
+ /// 更新后道标签打印记录
+ ///
+ ///
+ [HttpPut]
+ [ActionPermissionFilter(Permission = "business:qcbackendrecordlabelprint:edit")]
+ [Log(Title = "后道标签打印记录", BusinessType = BusinessType.UPDATE)]
+ public IActionResult UpdateQcBackendRecordLabelPrint([FromBody] QcBackendRecordLabelPrintDto parm)
+ {
+ var modal = parm.Adapt().ToUpdate(HttpContext);
+ var response = _QcBackendRecordLabelPrintService.UpdateQcBackendRecordLabelPrint(modal);
+
+ return ToResponse(response);
+ }
+
+ ///
+ /// 删除后道标签打印记录
+ ///
+ ///
+ [HttpDelete("{ids}")]
+ [ActionPermissionFilter(Permission = "business:qcbackendrecordlabelprint:delete")]
+ [Log(Title = "后道标签打印记录", BusinessType = BusinessType.DELETE)]
+ public IActionResult DeleteQcBackendRecordLabelPrint(string ids)
+ {
+ int[] idsArr = Tools.SpitIntArrary(ids);
+ if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
+
+ var response = _QcBackendRecordLabelPrintService.Delete(idsArr);
+
+ return ToResponse(response);
+ }
+
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/ZR.Admin.WebApi/wwwroot/Generatecode/ZrAdmin.NET-后道标签打印记录-0522151305.zip b/ZR.Admin.WebApi/wwwroot/Generatecode/ZrAdmin.NET-后道标签打印记录-0522151305.zip
new file mode 100644
index 00000000..0900d63b
Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/Generatecode/ZrAdmin.NET-后道标签打印记录-0522151305.zip differ
diff --git a/ZR.Model/MES/qc/DTO/backend/QcBackendRecordLabelPrintDto.cs b/ZR.Model/MES/qc/DTO/backend/QcBackendRecordLabelPrintDto.cs
new file mode 100644
index 00000000..ca742805
--- /dev/null
+++ b/ZR.Model/MES/qc/DTO/backend/QcBackendRecordLabelPrintDto.cs
@@ -0,0 +1,54 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace ZR.Model.Dto
+{
+ ///
+ /// 后道标签打印记录查询对象
+ ///
+ public class QcBackendRecordLabelPrintQueryDto : PagerInfo
+ {
+ }
+
+ ///
+ /// 后道标签打印记录输入输出对象
+ ///
+ public class QcBackendRecordLabelPrintDto
+ {
+ [Required(ErrorMessage = "主键不能为空")]
+ public string Id { get; set; }
+
+ public string MachineCode { get; set; }
+
+ [Required(ErrorMessage = "标签编码不能为空")]
+ public string LabelCode { get; set; }
+
+ public string WorkOrder { get; set; }
+
+ public string PartNumber { get; set; }
+
+ public string Description { get; set; }
+
+ public string Team { get; set; }
+
+ public string BatchCode { get; set; }
+
+ public int? SerialNumber { get; set; }
+
+ public int? PartNum { get; set; }
+
+ public int? LabelType { get; set; }
+
+ public int? BoxMaxNum { get; set; }
+
+ public int? IsFull { get; set; }
+
+ public int? IsLcl { get; set; }
+
+ public string CreateBy { get; set; }
+
+ public DateTime? CreateTime { get; set; }
+
+
+
+ }
+}
\ No newline at end of file
diff --git a/ZR.Model/MES/qc/backend/QcBackendRecordLabelPrint.cs b/ZR.Model/MES/qc/backend/QcBackendRecordLabelPrint.cs
new file mode 100644
index 00000000..c2007f25
--- /dev/null
+++ b/ZR.Model/MES/qc/backend/QcBackendRecordLabelPrint.cs
@@ -0,0 +1,105 @@
+
+namespace ZR.Model.Business
+{
+ ///
+ /// 后道标签打印记录
+ ///
+ [SugarTable("qc_backend_record_label_print")]
+ public class QcBackendRecordLabelPrint
+ {
+ ///
+ /// 主键
+ ///
+ [SugarColumn(IsPrimaryKey = true, IsIdentity = false)]
+ public string Id { get; set; }
+
+ ///
+ /// 设备编码
+ ///
+ [SugarColumn(ColumnName = "machine_code")]
+ public string MachineCode { get; set; }
+
+ ///
+ /// 标签编码
+ ///
+ [SugarColumn(ColumnName = "label_code")]
+ public string LabelCode { get; set; }
+
+ ///
+ /// 后道工单号
+ ///
+ [SugarColumn(ColumnName = "work_order")]
+ public string WorkOrder { get; set; }
+
+ ///
+ /// 零件号
+ ///
+ [SugarColumn(ColumnName = "part_number")]
+ public string PartNumber { get; set; }
+
+ ///
+ /// 描述
+ ///
+ public string Description { get; set; }
+
+ ///
+ /// 班组
+ ///
+ public string Team { get; set; }
+
+ ///
+ /// 批次号
+ ///
+ [SugarColumn(ColumnName = "batch_code")]
+ public string BatchCode { get; set; }
+
+ ///
+ /// 流水号
+ ///
+ [SugarColumn(ColumnName = "serial_number")]
+ public int? SerialNumber { get; set; }
+
+ ///
+ /// 零件数
+ ///
+ [SugarColumn(ColumnName = "part_num")]
+ public int? PartNum { get; set; }
+
+ ///
+ /// 标签类别 1-箱标签 2-产品标签 3-其他
+ ///
+ [SugarColumn(ColumnName = "label_type")]
+ public int? LabelType { get; set; }
+
+ ///
+ /// 箱最大容量
+ ///
+ [SugarColumn(ColumnName = "box_max_num")]
+ public int? BoxMaxNum { get; set; }
+
+ ///
+ /// 是否满箱 1-是 0-否
+ ///
+ [SugarColumn(ColumnName = "is_full")]
+ public int? IsFull { get; set; }
+
+ ///
+ /// 是否拼箱 1-是 0-否
+ ///
+ [SugarColumn(ColumnName = "is_lcl")]
+ public int? IsLcl { get; set; }
+
+ ///
+ /// 创建人
+ ///
+ [SugarColumn(ColumnName = "create_by")]
+ public string CreateBy { get; set; }
+
+ ///
+ /// 创建时间
+ ///
+ [SugarColumn(ColumnName = "create_time")]
+ public DateTime? CreateTime { get; set; }
+
+ }
+}
\ No newline at end of file
diff --git a/ZR.Service/mes/qc/IService/backend/IQcBackEndService.cs b/ZR.Service/mes/qc/IService/backend/IQcBackEndService.cs
index fa255fcd..d4018380 100644
--- a/ZR.Service/mes/qc/IService/backend/IQcBackEndService.cs
+++ b/ZR.Service/mes/qc/IService/backend/IQcBackEndService.cs
@@ -67,6 +67,18 @@ namespace ZR.Service.Business.IBusinessService
///
string ScanInnerLabel(QcBackEndLabelScanDto data);
+ ///
+ /// 扫内标签后检查是否满箱并需要扫箱标签
+ ///
+ ///
+ bool CheckPackageIsFullAndNeedScanPackageLabel(string workorder);
+
+ ///
+ /// 触摸屏扫箱标签检验
+ ///
+ ///
+ string ScanPackageLabel(QcBackEndLabelScanDto data);
+
///
/// 结束工单并生成质量报表
///
diff --git a/ZR.Service/mes/qc/IService/backend/IQcBackendRecordLabelPrintService.cs b/ZR.Service/mes/qc/IService/backend/IQcBackendRecordLabelPrintService.cs
new file mode 100644
index 00000000..8be2d09d
--- /dev/null
+++ b/ZR.Service/mes/qc/IService/backend/IQcBackendRecordLabelPrintService.cs
@@ -0,0 +1,23 @@
+using System;
+using ZR.Model;
+using ZR.Model.Dto;
+using ZR.Model.Business;
+using System.Collections.Generic;
+
+namespace ZR.Service.Business.IBusinessService
+{
+ ///
+ /// 后道标签打印记录service接口
+ ///
+ public interface IQcBackendRecordLabelPrintService : IBaseService
+ {
+ PagedInfo GetList(QcBackendRecordLabelPrintQueryDto parm);
+
+ QcBackendRecordLabelPrint GetInfo(string Id);
+
+ QcBackendRecordLabelPrint AddQcBackendRecordLabelPrint(QcBackendRecordLabelPrint parm);
+
+ int UpdateQcBackendRecordLabelPrint(QcBackendRecordLabelPrint parm);
+
+ }
+}
diff --git a/ZR.Service/mes/qc/backend/QcBackEndService.cs b/ZR.Service/mes/qc/backend/QcBackEndService.cs
index 3c92068e..75768f9d 100644
--- a/ZR.Service/mes/qc/backend/QcBackEndService.cs
+++ b/ZR.Service/mes/qc/backend/QcBackEndService.cs
@@ -74,7 +74,6 @@ namespace ZR.Service.Business
RegexOptions.IgnoreCase
);
-
WmMaterial material = Context
.Queryable()
.Where(it => it.Partnumber == processedPartnumber)
@@ -675,7 +674,75 @@ namespace ZR.Service.Business
.ExecuteCommand();
return qcBackEndWorkorder;
}
- // 后道扫内标签与外标签
+
+ // 后道扫描箱标签
+ public string ScanPackageLabel(QcBackEndLabelScanDto data)
+ {
+ try
+ {
+ Context.Ado.BeginTran();
+ DateTime nowTime = DateTime.Now;
+ // 标签防错 (零件号)
+ string partNumber = DoAnalyzePartnumber(data.Label);
+ // 内外标签零件号不一致
+ if (!partNumber.Contains(data.PartNumber))
+ {
+ Context.Ado.RollbackTran();
+ return "箱标签零件号与工单零件号不一致!";
+ }
+ // 上一个内标签流水号检查
+ int oldPackageLabelSort = 1;
+ QcBackEndRecordLabelScan lastPackagelabelInfo = Context
+ .Queryable()
+ .Where(it => it.WorkOrder == data.WorkOrder)
+ .Where(it => it.LabelType == 1)
+ .OrderByDescending(it => it.LabelSort)
+ .First();
+ if(lastPackagelabelInfo == null)
+ {
+ oldPackageLabelSort = 0;
+ }
+ else
+ {
+ oldPackageLabelSort = lastPackagelabelInfo.LabelSort.Value;
+ }
+ // 新箱标签录入
+ QcBackEndRecordLabelScan newLabelScran =
+ new()
+ {
+ Id = SnowFlakeSingle.Instance.NextId().ToString(),
+ WorkOrder = data.WorkOrder,
+ PartNumber = data.PartNumber,
+ Team = data.Team,
+ SiteNo = data.SiteNo,
+ ComNo = data.ComNo,
+ Label = data.Label,
+ LabelType = 1,
+ LabelSort = oldPackageLabelSort + 1,
+ ScanTime = $"{nowTime:yyyy-MM-dd HH:mm:ss}",
+ Type = "1",
+ Status = "1",
+ Remark = "外箱标签",
+ CreatedBy = data.CreatedBy,
+ CreatedTime = data.CreatedTime,
+ };
+ int res = Context.Insertable(newLabelScran).ExecuteCommand();
+ if (res == 0)
+ {
+ Context.Ado.RollbackTran();
+ return "箱标签录入系统失败!";
+ }
+ Context.Ado.CommitTran();
+ return "ok";
+ }
+ catch (Exception)
+ {
+ Context.Ado.RollbackTran();
+ return "箱标签录入系统失败!";
+ }
+ }
+
+ // 后道扫内标签
public string ScanInnerLabel(QcBackEndLabelScanDto data)
{
try
@@ -684,7 +751,7 @@ namespace ZR.Service.Business
DateTime nowTime = DateTime.Now;
// 标签防错 (内标签零件号)
string partNumber = DoAnalyzePartnumber(data.Label);
- // 内标签包含外标签
+ // 内外标签零件号不一致
if (!partNumber.Contains(data.PartNumber))
{
Context.Ado.RollbackTran();
@@ -732,41 +799,8 @@ namespace ZR.Service.Business
{
oldInnerLabelSort = labelScan.LabelSort ?? 0;
}
-
- // 上一个箱标签流水号
- int oldPackageLabelSort = 0;
- QcBackEndRecordLabelScan packageLabelScan = Context
- .Queryable()
- .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()
- .Where(it => it.WorkOrder == data.WorkOrder)
- .Where(it => it.LabelType == 2)
- .Count();
- // 箱标签总数
- int packageLabelCount = Context.Queryable()
- .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()
@@ -787,75 +821,13 @@ namespace ZR.Service.Business
CreatedBy = data.CreatedBy,
CreatedTime = data.CreatedTime,
};
-
- //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()
- .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 $"已满箱,请扫描箱标签!当前满箱判断数:{maxPackage}";
- }
- // 已扫过则继续扫内箱标签
- //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();
@@ -868,11 +840,64 @@ namespace ZR.Service.Business
}
}
+ // 判断是否满箱并且要出箱标签
+ public bool CheckPackageIsFullAndNeedScanPackageLabel(string workorder)
+ {
+ // 判断是否需要扫箱标签
+ bool neeedScan = false;
+ // 工单判断
+ QcBackEndServiceWorkorder workorderInfo = Context
+ .Queryable()
+ .Where(it => it.WorkOrder == workorder)
+ .First();
+ if (workorder == null)
+ {
+ throw new Exception($"异常:工单不存在{workorder}");
+ }
+ // 打印配置确认
+ QcBackendBaseOutpackage packageLabelConfig = Context
+ .Queryable()
+ .Where(it => workorderInfo.Description.Contains(it.CheckStr))
+ .First();
+ if (packageLabelConfig == null)
+ {
+ throw new Exception($"异常:零件满箱配置不存在{workorder}");
+ }
+ int maxPackageNum = packageLabelConfig.PackageNum ?? 0;
+ // 内标签总数
+ int innerLabelCount = Context
+ .Queryable()
+ .Where(it => it.WorkOrder == workorder)
+ .Where(it => it.LabelType == 2)
+ .Count();
+ // 箱标签总数
+ int packageLabelCount = Context
+ .Queryable()
+ .Where(it => it.WorkOrder == workorder)
+ .Where(it => it.LabelType == 1)
+ .Count();
+
+ packageLabelCount -= 1;
+ if (packageLabelCount < 0)
+ {
+ packageLabelCount = 0;
+ }
+ // 是否满箱
+ bool isFull = (innerLabelCount > 0) && (innerLabelCount % maxPackageNum == 0);
+ // 是否需要扫箱标签
+ bool needScanPackageLabel = packageLabelCount * maxPackageNum < innerLabelCount;
+ neeedScan = isFull && needScanPackageLabel;
+ return neeedScan;
+ }
+
///
/// 判断是否需要自动出满箱标签
///
///
- public void CheckAndPrintPackageLabel(QcBackEndRecordLabelScan newLabelScran,QcBackendBaseOutpackage packageLabelConfig)
+ public void CheckAndPrintPackageLabel(
+ QcBackEndRecordLabelScan newLabelScran,
+ QcBackendBaseOutpackage packageLabelConfig
+ )
{
DateTime nowTime = DateTime.Now;
// 判断是否需要自动出满箱标签
@@ -883,53 +908,32 @@ namespace ZR.Service.Business
// 需要打外箱标签
SendPrintPackageLabelAsync(newLabelScran, packageLabelConfig.FileUrl, maxPackage)
.Wait();
- /*int packageSort = 0;
- QcBackEndRecordLabelScan packagelabelScan = Context
- .Queryable()
- .Where(it => it.WorkOrder == newLabelScran.WorkOrder)
- .Where(it => it.LabelType == 1)
- .OrderByDescending(it => it.LabelSort)
- .First();
- if (packagelabelScan != null)
- {
- packageSort = packagelabelScan.LabelSort ?? 0;
- }
- QcBackEndRecordLabelScan newPackagePrintLabel =
- new()
- {
- Id = SnowFlakeSingle.Instance.NextId().ToString(),
- WorkOrder = newLabelScran.WorkOrder,
- PartNumber = newLabelScran.PartNumber,
- Team = newLabelScran.Team,
- SiteNo = newLabelScran.SiteNo,
- ComNo = newLabelScran.ComNo,
- Label =
- $"Code=BN{newLabelScran.WorkOrder}_{newLabelScran.Team}{packageSort + 1}^ItemNumber={newLabelScran.PartNumber}^Order={newLabelScran.WorkOrder}^Qty={maxPackage}^Type=packageLabel",
- LabelType = 1,
- LabelSort = packageSort + 1,
- ScanTime = $"{nowTime:yyyy-MM-dd HH:mm:ss}",
- Type = "1",
- Status = "1",
- Remark = "自动出满箱标签",
- CreatedBy = newLabelScran.CreatedBy,
- CreatedTime = newLabelScran.CreatedTime,
- };
- int res = Context.Insertable(newPackagePrintLabel).ExecuteCommand();*/
}
}
///
- /// 发送打印后道外箱标签的mqtt信息
+ /// 发送打印后道外箱标签的MQTT信息
///
+ /// 当输入参数为null时抛出
+ /// 当标签内容无效时抛出
public async Task SendPrintPackageLabelAsync(
QcBackEndRecordLabelScan newLabelScran,
string path,
int maxPackage
)
{
+ // 参数验证
+ if (newLabelScran == null)
+ throw new ArgumentNullException(nameof(newLabelScran), "标签扫描信息不能为空");
+
+ if (string.IsNullOrWhiteSpace(newLabelScran.Label))
+ throw new ArgumentException("标签内容不能为空", nameof(newLabelScran.Label));
+
+ if (maxPackage <= 0)
+ throw new ArgumentException("包装数量必须大于0", nameof(maxPackage));
+
try
{
- // 构造主题和消息内容 (发送给1站点打印 XXX 预留多站点打印的情况)
string topic = $"shgg_mes/backEnd/print/1站点";
QcBackEndPrintMqttEventDto mqttEventDto = CreateNewQcBackEndPrintMqttEventDto(
@@ -937,23 +941,100 @@ namespace ZR.Service.Business
path,
maxPackage
);
+
var payload = JsonSerializer.Serialize(mqttEventDto);
- // 调用MqttService的发布方法(支持异步调用)
+ // 保持原有PublishAsync调用方式
await _mqttService.PublishAsync(
topic,
payload,
MqttQualityOfServiceLevel.AtLeastOnce,
- // 可选:设置消息保留
retain: false
);
_logger.LogInformation($"发送后道外箱标签打印成功:{topic}");
+
+ // 添加打印记录
+ await AddBackendLabelPrintRecordAsync(newLabelScran,mqttEventDto, maxPackage);
+ }
+ catch (JsonException ex)
+ {
+ _logger.LogError(ex, "序列化MQTT消息失败");
+ throw new InvalidOperationException("MQTT消息格式错误", ex);
}
catch (Exception ex)
{
_logger.LogError(ex, $"发送后道外箱标签打印失败:{ex.Message}");
- throw; // 或根据业务需求处理异常
+ throw;
+ }
+ }
+
+ ///
+ /// 异步添加后道箱标签打印记录
+ ///
+ private async Task AddBackendLabelPrintRecordAsync(
+ QcBackEndRecordLabelScan newLabelScran,
+ QcBackEndPrintMqttEventDto labelScan,
+ int maxPackage
+ )
+ {
+ try
+ {
+ string labelCode = labelScan.LabelCode ?? "";
+ string description = "";
+ string batchCode = "";
+ try
+ {
+ batchCode = DoAnalyzeBatchCode(labelCode);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogWarning(ex, "解析批次号失败");
+ }
+ // 上一个内标签流水号检查
+ int oldPackageLabelSort = 1;
+ QcBackendRecordLabelPrint lastPackagelabelInfo = Context
+ .Queryable()
+ .Where(it => it.WorkOrder == newLabelScran.WorkOrder)
+ .Where(it => it.LabelType == 1)
+ .OrderByDescending(it => it.SerialNumber)
+ .First();
+ if (lastPackagelabelInfo == null)
+ {
+ oldPackageLabelSort = 1;
+ }
+ else
+ {
+ oldPackageLabelSort = lastPackagelabelInfo.SerialNumber.Value;
+ }
+ QcBackendRecordLabelPrint printRecord =
+ new()
+ {
+ Id = SnowFlakeSingle.instance.NextId().ToString(),
+ MachineCode = labelScan.SiteNo ?? "未知站点",
+ LabelCode = labelCode,
+ WorkOrder = newLabelScran.WorkOrder ?? "未知工单",
+ PartNumber = labelScan.PartNumber ?? "未知零件号",
+ Description = description,
+ Team = labelScan.Team ?? "未知班组",
+ BatchCode = batchCode,
+ SerialNumber = oldPackageLabelSort + 1,
+ PartNum = maxPackage,
+ LabelType = 1,
+ BoxMaxNum = maxPackage,
+ IsFull = 1,
+ IsLcl = 0,
+ CreateBy = "后道标签打印系统",
+ CreateTime = DateTime.Now
+ };
+
+ // 使用异步数据库操作
+ await Context.Insertable(printRecord).ExecuteCommandAsync();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "添加打印记录失败");
+ throw new Exception("保存打印记录失败", ex);
}
}
@@ -977,16 +1058,16 @@ namespace ZR.Service.Business
}
// 提取箱流水号
int packageSort = 0;
- QcBackEndRecordLabelScan packagelabelScan = Context
- .Queryable()
+ QcBackendRecordLabelPrint labelPrintRecord = Context
+ .Queryable()
.Where(it => it.PartNumber == newLabelScran.PartNumber)
- .Where(it => it.Label.Contains(batchCode))
+ .Where(it => it.BatchCode.Contains(batchCode))
.Where(it => it.LabelType == 1)
- .OrderByDescending(it => it.LabelSort)
+ .OrderByDescending(it => it.SerialNumber)
.First();
- if (packagelabelScan != null)
+ if (labelPrintRecord != null)
{
- packageSort = packagelabelScan.LabelSort + 1 ?? 0;
+ packageSort = labelPrintRecord.SerialNumber + 1 ?? 0;
}
// 提取产品描述
string checkPartnumber = newLabelScran.PartNumber;
@@ -1003,7 +1084,7 @@ namespace ZR.Service.Business
.Where(it => it.Type == 1)
.Where(it => it.Status == 1)
.First();
- if(material == null)
+ if (material == null)
{
throw new Exception("生成打印后道外箱标签的信息:此零件号不在物料清单内!" + processedPartnumber);
}
@@ -1026,7 +1107,7 @@ namespace ZR.Service.Business
PackageCode = newPackageCode,
Team = newLabelScran.Team,
Sort = packageSort,
- ProductionTime = "20" + batchCode.Substring(0,6),
+ ProductionTime = "20" + batchCode.Substring(0, 6),
BatchCode = batchCode,
PackageNum = maxPackage,
LabelCode = newLabelCode,
@@ -1291,5 +1372,6 @@ namespace ZR.Service.Business
{
return Guid.NewGuid().ToString("N").Substring(0, 10); // Generate a 10-character unique ID
}
+
}
}
diff --git a/ZR.Service/mes/qc/backend/QcBackendRecordLabelPrintService.cs b/ZR.Service/mes/qc/backend/QcBackendRecordLabelPrintService.cs
new file mode 100644
index 00000000..483ddbb0
--- /dev/null
+++ b/ZR.Service/mes/qc/backend/QcBackendRecordLabelPrintService.cs
@@ -0,0 +1,89 @@
+using System;
+using SqlSugar;
+using Infrastructure.Attribute;
+using Infrastructure.Extensions;
+using ZR.Model;
+using ZR.Model.Dto;
+using ZR.Model.Business;
+using ZR.Repository;
+using ZR.Service.Business.IBusinessService;
+using System.Linq;
+
+namespace ZR.Service.Business
+{
+ ///
+ /// 后道标签打印记录Service业务层处理
+ ///
+ [AppService(ServiceType = typeof(IQcBackendRecordLabelPrintService), ServiceLifetime = LifeTime.Transient)]
+ public class QcBackendRecordLabelPrintService : BaseService, IQcBackendRecordLabelPrintService
+ {
+ ///
+ /// 查询后道标签打印记录列表
+ ///
+ ///
+ ///
+ public PagedInfo GetList(QcBackendRecordLabelPrintQueryDto parm)
+ {
+ var predicate = Expressionable.Create();
+
+ var response = Queryable()
+ .Where(predicate.ToExpression())
+ .ToPage(parm);
+
+ return response;
+ }
+
+
+ ///
+ /// 获取详情
+ ///
+ ///
+ ///
+ public QcBackendRecordLabelPrint GetInfo(string Id)
+ {
+ var response = Queryable()
+ .Where(x => x.Id == Id)
+ .First();
+
+ return response;
+ }
+
+ ///
+ /// 添加后道标签打印记录
+ ///
+ ///
+ ///
+ public QcBackendRecordLabelPrint AddQcBackendRecordLabelPrint(QcBackendRecordLabelPrint model)
+ {
+ return Context.Insertable(model).ExecuteReturnEntity();
+ }
+
+ ///
+ /// 修改后道标签打印记录
+ ///
+ ///
+ ///
+ public int UpdateQcBackendRecordLabelPrint(QcBackendRecordLabelPrint model)
+ {
+ //var response = Update(w => w.Id == model.Id, it => new QcBackendRecordLabelPrint()
+ //{
+ // MachineCode = model.MachineCode,
+ // LabelCode = model.LabelCode,
+ // WorkOrder = model.WorkOrder,
+ // PartNumber = model.PartNumber,
+ // Description = model.Description,
+ // Team = model.Team,
+ // BatchCode = model.BatchCode,
+ // SerialNumber = model.SerialNumber,
+ // PartNum = model.PartNum,
+ // LabelType = model.LabelType,
+ // BoxMaxNum = model.BoxMaxNum,
+ // IsFull = model.IsFull,
+ // IsLcl = model.IsLcl,
+ //});
+ //return response;
+ return Update(model, true);
+ }
+
+ }
+}
\ No newline at end of file