feat(工单): 实现工单标签打印功能并优化相关逻辑
- 添加Bartender打印工具类实现工单标签打印功能 - 修改PrintTicketsByTemplate方法返回类型为string并实现完整打印逻辑 - 优化工单领料逻辑,增加原材料工单信息获取 - 调整工单查询条件,移除PlanNum>0的限制 - 修复出库单操作符赋值错误 - 优化不良品处理流程,统一使用不良库代替报废库 - 完善领料报工逻辑,增加计划数校验和原材料工单处理
This commit is contained in:
@@ -3,6 +3,8 @@ using DOAN.Model.MES.product.Dto;
|
||||
using DOAN.Service.MES.product.IService;
|
||||
using Infrastructure;
|
||||
using Infrastructure.Attribute;
|
||||
using linesider_screen_tool;
|
||||
using Microsoft.AspNetCore.Routing.Template;
|
||||
|
||||
namespace DOAN.Service.MES.product
|
||||
{
|
||||
@@ -15,6 +17,7 @@ namespace DOAN.Service.MES.product
|
||||
)]
|
||||
public class ProWorkorderUtilityService : BaseService<ProWorkorder>, IProWorkorderUtilityService
|
||||
{
|
||||
private readonly BartenderPrintHelper _printHelper = new();
|
||||
/// <summary>
|
||||
/// 生成工单号
|
||||
/// </summary>
|
||||
@@ -183,11 +186,94 @@ namespace DOAN.Service.MES.product
|
||||
/// </summary>
|
||||
/// <param name="param"></param>
|
||||
/// <returns></returns>
|
||||
public Task<CustomException> PrintTicketsByTemplate(ProWorkorderExportDto param)
|
||||
public string PrintTicketsByTemplate(ProWorkorderExportDto param)
|
||||
{
|
||||
// 这里需要实现工单打印逻辑
|
||||
// 暂时返回成功
|
||||
return Task.FromResult((CustomException)null);
|
||||
try
|
||||
{
|
||||
string templatePath = param.Path;
|
||||
if (string.IsNullOrEmpty(templatePath))
|
||||
{
|
||||
return "标签地址传入为空!";
|
||||
}
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!File.Exists(templatePath))
|
||||
{
|
||||
return $"标签文件不存在: {templatePath}";
|
||||
}
|
||||
|
||||
// 获取标签中的变量名
|
||||
var subString = _printHelper.GetNamedSubStrings(templatePath: templatePath);
|
||||
|
||||
// 检查是否成功获取到标签变量
|
||||
if (subString == null || subString.Result == null || subString.Result.Count == 0)
|
||||
{
|
||||
return $"无法获取标签变量: {templatePath}";
|
||||
}
|
||||
|
||||
// 获取工单信息
|
||||
List<ProWorkorder> workorders = Context
|
||||
.Queryable<ProWorkorder>()
|
||||
.Where(it => param.WorkorderArray.Contains(it.Workorder))
|
||||
.ToList();
|
||||
|
||||
if (workorders.Count == 0)
|
||||
{
|
||||
return "未找到指定的工单信息!";
|
||||
}
|
||||
|
||||
// 对每个工单执行打印
|
||||
int successCount = 0;
|
||||
foreach (ProWorkorder workorder in workorders)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 为每个工单生成标签参数
|
||||
Dictionary<string, string> parameters = new Dictionary<string, string>
|
||||
{
|
||||
{ "workorder", workorder.Workorder },
|
||||
{ "stoveCode", workorder.StoveCode },
|
||||
{ "qty", workorder.PlanNum.ToString() },
|
||||
//{ "productionName", workorder.productionName },
|
||||
//{ "productionCode", workorder.productionCode },
|
||||
//{ "materialCode", workorder.MaterialCode },
|
||||
//{ "drawingCode", workorder.DrawingCode }
|
||||
};
|
||||
|
||||
// 过滤出标签中存在的参数
|
||||
var intersect = parameters.Where(x => subString.Result.Contains(x.Key)).ToDictionary(
|
||||
x => x.Key, x => x.Value);
|
||||
|
||||
// 执行打印
|
||||
bool printSuccess = _printHelper.PrintLabel(
|
||||
templatePath: templatePath,
|
||||
subStringValues: intersect);
|
||||
|
||||
if (printSuccess)
|
||||
{
|
||||
successCount++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录单个工单打印失败的异常,但继续打印其他工单
|
||||
Console.WriteLine($"打印工单 {workorder.Workorder} 失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
if (successCount > 0)
|
||||
{
|
||||
return $"ok";
|
||||
}
|
||||
else
|
||||
{
|
||||
return $"工单标签打印失败: {templatePath}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"打印失败: {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user