123
This commit is contained in:
parent
fc68f88ca0
commit
3e6c4411b2
@ -7,27 +7,55 @@ namespace ZR.Model.Dto
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class QcBackEndPrintMqttEventDto
|
public class QcBackEndPrintMqttEventDto
|
||||||
{
|
{
|
||||||
public string Path { get; set; }
|
// btw文件路径
|
||||||
|
public string Path { get; set; } = "";
|
||||||
|
|
||||||
public string SiteNo { get; set; }
|
// 站点号
|
||||||
|
public string SiteNo { get; set; } = "";
|
||||||
|
|
||||||
public string Name { get; set; }
|
// 识别内容名称(内部)
|
||||||
|
public string Name { get; set; } = "";
|
||||||
|
|
||||||
public string PartNumber { get; set; }
|
// 零件号
|
||||||
|
public string PartNumber { get; set; } = "";
|
||||||
|
|
||||||
public string WorkOrder { get; set; }
|
// 产品名称
|
||||||
|
public string Description { get; set; } = "";
|
||||||
|
|
||||||
|
// 颜色
|
||||||
|
public string Color { get; set; } = "";
|
||||||
|
|
||||||
|
// 规格
|
||||||
|
public string Specification { get; set; } = "";
|
||||||
|
|
||||||
|
// 工单号
|
||||||
|
public string WorkOrder { get; set; } = "";
|
||||||
|
|
||||||
|
// 箱号
|
||||||
|
public string PackageCode { get; set; } = "";
|
||||||
|
|
||||||
|
// 班组
|
||||||
public string Team { get; set; } = "A";
|
public string Team { get; set; } = "A";
|
||||||
|
|
||||||
|
// 流水号
|
||||||
public int Sort { get; set; } = 1;
|
public int Sort { get; set; } = 1;
|
||||||
|
|
||||||
public string BatchCode { get; set; }
|
// 生产时间
|
||||||
|
public string ProductionTime { get; set; } = "";
|
||||||
|
|
||||||
|
// 批次号
|
||||||
|
public string BatchCode { get; set; } = "";
|
||||||
|
|
||||||
|
// 满箱数
|
||||||
public int PackageNum { get; set; } = 24;
|
public int PackageNum { get; set; } = 24;
|
||||||
|
|
||||||
|
// 标签内容
|
||||||
|
public string LabelCode { get; set; } = "";
|
||||||
|
|
||||||
|
// 标签区别
|
||||||
public int LabelType { get; set; } = 1;
|
public int LabelType { get; set; } = 1;
|
||||||
|
|
||||||
|
// 发送时间
|
||||||
public string CreatedTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
public string CreatedTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@ -168,6 +169,35 @@ namespace ZR.Service.Business
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 标签的批次号解析
|
||||||
|
public string DoAnalyzeBatchCode(string label)
|
||||||
|
{
|
||||||
|
// 标签批次号正则抓取
|
||||||
|
var predicate = Expressionable
|
||||||
|
.Create<QcBackEndBaseLabelAnalysis>()
|
||||||
|
.And(it => it.Code == "BatchCode")
|
||||||
|
.And(it => it.Status == "1");
|
||||||
|
List<QcBackEndBaseLabelAnalysis> analysisList = Context
|
||||||
|
.Queryable<QcBackEndBaseLabelAnalysis>()
|
||||||
|
.Where(predicate.ToExpression())
|
||||||
|
.ToList();
|
||||||
|
foreach (QcBackEndBaseLabelAnalysis analysis in analysisList)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(analysis.Expression))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 零件号正则表达式
|
||||||
|
Regex pattern = new(@analysis.Expression);
|
||||||
|
Match match = pattern.Match(label);
|
||||||
|
if (match.Success && match.Groups.Count > 1)
|
||||||
|
{
|
||||||
|
return match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public List<QcBackEndAlterationDefectDto> GetDefectInitOptions()
|
public List<QcBackEndAlterationDefectDto> GetDefectInitOptions()
|
||||||
{
|
{
|
||||||
List<QcBackEndAlterationDefectDto> defectList = new();
|
List<QcBackEndAlterationDefectDto> defectList = new();
|
||||||
@ -277,6 +307,7 @@ namespace ZR.Service.Business
|
|||||||
.Queryable<QcBackEndServiceWorkorder>()
|
.Queryable<QcBackEndServiceWorkorder>()
|
||||||
.Where(it => it.Label == data.Label)
|
.Where(it => it.Label == data.Label)
|
||||||
.First();
|
.First();
|
||||||
|
// 有旧记录则返回旧记录
|
||||||
if (oldWorkOrder != null)
|
if (oldWorkOrder != null)
|
||||||
{
|
{
|
||||||
return oldWorkOrder;
|
return oldWorkOrder;
|
||||||
@ -706,7 +737,6 @@ namespace ZR.Service.Business
|
|||||||
Context.Ado.RollbackTran();
|
Context.Ado.RollbackTran();
|
||||||
return $"异常:{e.Message}";
|
return $"异常:{e.Message}";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -716,7 +746,7 @@ namespace ZR.Service.Business
|
|||||||
public void CheckAndPrintPackageLabel(QcBackEndRecordLabelScan newLabelScran)
|
public void CheckAndPrintPackageLabel(QcBackEndRecordLabelScan newLabelScran)
|
||||||
{
|
{
|
||||||
DateTime nowTime = DateTime.Now;
|
DateTime nowTime = DateTime.Now;
|
||||||
// 找到最大箱容量与模板
|
// 找到最大箱容量与打印模板
|
||||||
QcBackEndServiceWorkorder workorder = Context
|
QcBackEndServiceWorkorder workorder = Context
|
||||||
.Queryable<QcBackEndServiceWorkorder>()
|
.Queryable<QcBackEndServiceWorkorder>()
|
||||||
.Where(it => it.WorkOrder == newLabelScran.WorkOrder)
|
.Where(it => it.WorkOrder == newLabelScran.WorkOrder)
|
||||||
@ -727,18 +757,21 @@ namespace ZR.Service.Business
|
|||||||
.First();
|
.First();
|
||||||
if (workorder == null)
|
if (workorder == null)
|
||||||
{
|
{
|
||||||
throw new Exception("工单异常");
|
throw new Exception($"工单异常:内标签工单不存在{newLabelScran.WorkOrder}");
|
||||||
}
|
}
|
||||||
if (packageLabelConfig == null)
|
if (packageLabelConfig == null)
|
||||||
{
|
{
|
||||||
throw new Exception("该标签打印参数未配置");
|
throw new Exception($"该产品内标签对应打印参数未配置:{newLabelScran.PartNumber}");
|
||||||
}
|
}
|
||||||
|
// 判断是否需要自动出满箱标签
|
||||||
int checkSort = newLabelScran.LabelSort ?? 0;
|
int checkSort = newLabelScran.LabelSort ?? 0;
|
||||||
|
|
||||||
int maxPackage = packageLabelConfig.PackageNum ?? 0;
|
int maxPackage = packageLabelConfig.PackageNum ?? 0;
|
||||||
if (checkSort >= maxPackage && checkSort % maxPackage == 0)
|
if (checkSort >= maxPackage && checkSort % maxPackage == 0)
|
||||||
{
|
{
|
||||||
int packageSort = 0;
|
// 需要打外箱标签
|
||||||
|
SendPrintPackageLabelAsync(newLabelScran, packageLabelConfig.FileUrl, maxPackage)
|
||||||
|
.Wait();
|
||||||
|
/*int packageSort = 0;
|
||||||
QcBackEndRecordLabelScan packagelabelScan = Context
|
QcBackEndRecordLabelScan packagelabelScan = Context
|
||||||
.Queryable<QcBackEndRecordLabelScan>()
|
.Queryable<QcBackEndRecordLabelScan>()
|
||||||
.Where(it => it.WorkOrder == newLabelScran.WorkOrder)
|
.Where(it => it.WorkOrder == newLabelScran.WorkOrder)
|
||||||
@ -769,11 +802,7 @@ namespace ZR.Service.Business
|
|||||||
CreatedBy = newLabelScran.CreatedBy,
|
CreatedBy = newLabelScran.CreatedBy,
|
||||||
CreatedTime = newLabelScran.CreatedTime,
|
CreatedTime = newLabelScran.CreatedTime,
|
||||||
};
|
};
|
||||||
int res = Context.Insertable(newPackagePrintLabel).ExecuteCommand();
|
int res = Context.Insertable(newPackagePrintLabel).ExecuteCommand();*/
|
||||||
if (res > 0)
|
|
||||||
{
|
|
||||||
SendPrintPackageLabelAsync(newLabelScran, packageLabelConfig.FileUrl).Wait();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,35 +811,27 @@ namespace ZR.Service.Business
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task SendPrintPackageLabelAsync(
|
public async Task SendPrintPackageLabelAsync(
|
||||||
QcBackEndRecordLabelScan newLabelScran,
|
QcBackEndRecordLabelScan newLabelScran,
|
||||||
string path
|
string path,
|
||||||
|
int maxPackage
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 构造主题和消息内容
|
// 构造主题和消息内容 (发送给1站点打印 XXX 预留多站点打印的情况)
|
||||||
string topic = $"shgg_mes/backEnd/print/{newLabelScran.SiteNo}";
|
string topic = $"shgg_mes/backEnd/print/1站点";
|
||||||
|
|
||||||
QcBackEndPrintMqttEventDto mqttEventDto =
|
QcBackEndPrintMqttEventDto mqttEventDto = CreateNewQcBackEndPrintMqttEventDto(
|
||||||
new()
|
newLabelScran,
|
||||||
{
|
path,
|
||||||
Path = path,
|
maxPackage
|
||||||
SiteNo = newLabelScran.SiteNo,
|
);
|
||||||
Name = newLabelScran.PartNumber,
|
|
||||||
WorkOrder = newLabelScran.WorkOrder,
|
|
||||||
Team = newLabelScran.Team,
|
|
||||||
Sort = (newLabelScran.LabelSort + 1) ?? 1,
|
|
||||||
BatchCode = DateTime.Now.ToString("yyyyMMdd"),
|
|
||||||
PackageNum = 24,
|
|
||||||
LabelType = newLabelScran.LabelType ?? 1,
|
|
||||||
CreatedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
|
||||||
};
|
|
||||||
var payload = JsonSerializer.Serialize(mqttEventDto);
|
var payload = JsonSerializer.Serialize(mqttEventDto);
|
||||||
|
|
||||||
// 调用MqttService的发布方法(支持异步调用)
|
// 调用MqttService的发布方法(支持异步调用)
|
||||||
await _mqttService.PublishAsync(
|
await _mqttService.PublishAsync(
|
||||||
topic,
|
topic,
|
||||||
payload,
|
payload,
|
||||||
MqttQualityOfServiceLevel.ExactlyOnce,
|
MqttQualityOfServiceLevel.AtLeastOnce,
|
||||||
// 可选:设置消息保留
|
// 可选:设置消息保留
|
||||||
retain: false
|
retain: false
|
||||||
);
|
);
|
||||||
@ -824,6 +845,73 @@ namespace ZR.Service.Business
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生成打印后道外箱标签的mqtt信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="newLabelScran"></param>
|
||||||
|
/// <param name="path"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public QcBackEndPrintMqttEventDto CreateNewQcBackEndPrintMqttEventDto(
|
||||||
|
QcBackEndRecordLabelScan newLabelScran,
|
||||||
|
string path,
|
||||||
|
int maxPackage
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// 提取箱流水号
|
||||||
|
int packageSort = 0;
|
||||||
|
QcBackEndRecordLabelScan packagelabelScan = Context
|
||||||
|
.Queryable<QcBackEndRecordLabelScan>()
|
||||||
|
.Where(it => it.WorkOrder == newLabelScran.WorkOrder)
|
||||||
|
.Where(it => it.LabelType == 1)
|
||||||
|
.OrderByDescending(it => it.LabelSort)
|
||||||
|
.First();
|
||||||
|
if (packagelabelScan != null)
|
||||||
|
{
|
||||||
|
packageSort = packagelabelScan.LabelSort + 1 ?? 0;
|
||||||
|
}
|
||||||
|
// 提取产品描述
|
||||||
|
WmMaterial material = Context
|
||||||
|
.Queryable<WmMaterial>()
|
||||||
|
.Where(it => it.Partnumber == newLabelScran.PartNumber)
|
||||||
|
.Where(it => it.Type == 1)
|
||||||
|
.Where(it => it.Status == 1)
|
||||||
|
.First();
|
||||||
|
|
||||||
|
// 解析产品批次号,如果没有,则生成最新批次号
|
||||||
|
string batchCode = DoAnalyzeBatchCode(newLabelScran.Label);
|
||||||
|
if (string.IsNullOrEmpty(batchCode))
|
||||||
|
{
|
||||||
|
batchCode = DateTime.Now.ToString("yyMMdd") + "000";
|
||||||
|
}
|
||||||
|
// 生成工单号
|
||||||
|
string workOrder = $"{batchCode}_{packageSort}{newLabelScran.Team}1";
|
||||||
|
string newLabelCode =
|
||||||
|
$"Code=BNW{workOrder}^ItemNumber={newLabelScran.PartNumber}^Order=W{workOrder}^Qty={maxPackage}^LabelType=1^LabelBy=HD";
|
||||||
|
string newPackageCode = $"BOX:BNW{workOrder}";
|
||||||
|
QcBackEndPrintMqttEventDto mqttEventDto =
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Path = path,
|
||||||
|
SiteNo = "1站点",
|
||||||
|
Name = "后道外箱标签打印",
|
||||||
|
PartNumber = newLabelScran.PartNumber,
|
||||||
|
Description = material.Description ?? "",
|
||||||
|
Color = material.Color ?? "",
|
||||||
|
Specification = material.Specification ?? "",
|
||||||
|
WorkOrder = workOrder,
|
||||||
|
PackageCode = newPackageCode,
|
||||||
|
Team = newLabelScran.Team,
|
||||||
|
Sort = packageSort,
|
||||||
|
ProductionTime = batchCode.Substring(6),
|
||||||
|
BatchCode = batchCode,
|
||||||
|
PackageNum = maxPackage,
|
||||||
|
LabelCode = newLabelCode,
|
||||||
|
LabelType = 1,
|
||||||
|
CreatedTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||||||
|
};
|
||||||
|
return mqttEventDto;
|
||||||
|
}
|
||||||
|
|
||||||
public string EndBackEndWorkOrderAndCreateStatistics(string workorder)
|
public string EndBackEndWorkOrderAndCreateStatistics(string workorder)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user