feat: 大包/主单面单打印与标签类型 shipBag、shipMaster
All checks were successful
Build and Deploy / deploy (push) Successful in 1m16s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m16s
支持按模板批量出签,并补齐件重尺等字段与设计器预览字段。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8f43684217
commit
2984b9c885
@ -9,6 +9,10 @@
|
||||
-- UpdateUserId INT NULL
|
||||
-- UpdateTime DATETIME NULL
|
||||
-- 禁止 UNIQUE KEY;小包可不入袋、不上主单。可重复执行。
|
||||
-- 大包/主单件重尺与口岸:
|
||||
-- Length/Width/Height DECIMAL(10,2) NULL -- cm
|
||||
-- Weight DECIMAL(10,2) NULL -- kg
|
||||
-- DestinationPort VARCHAR(64) NULL -- 目的口岸
|
||||
-- =============================================================================
|
||||
SET @db := DATABASE();
|
||||
|
||||
@ -26,7 +30,12 @@ SET @sql := IF(
|
||||
`Status` VARCHAR(16) NOT NULL DEFAULT ''open'' COMMENT ''open/sealed/shipped/voided'',
|
||||
`WarehouseId` INT NULL COMMENT ''仓库ID'',
|
||||
`DestinationCountry` VARCHAR(8) NULL COMMENT ''目的国'',
|
||||
`DestinationPort` VARCHAR(64) NULL COMMENT ''目的口岸'',
|
||||
`ChannelCode` VARCHAR(64) NULL COMMENT ''渠道编码'',
|
||||
`Length` DECIMAL(10,2) NULL COMMENT ''长(cm)'',
|
||||
`Width` DECIMAL(10,2) NULL COMMENT ''宽(cm)'',
|
||||
`Height` DECIMAL(10,2) NULL COMMENT ''高(cm)'',
|
||||
`Weight` DECIMAL(10,2) NULL COMMENT ''重量(kg)'',
|
||||
`ParcelCount` INT NOT NULL DEFAULT 0 COMMENT ''袋内小包数'',
|
||||
`SealTime` DATETIME NULL COMMENT ''封袋时间'',
|
||||
`ShipTime` DATETIME NULL COMMENT ''出库时间'',
|
||||
@ -89,7 +98,12 @@ SET @sql := IF(
|
||||
`Status` VARCHAR(16) NOT NULL DEFAULT ''open'' COMMENT ''open/sealed/handed/voided'',
|
||||
`WarehouseId` INT NULL COMMENT ''仓库ID'',
|
||||
`DestinationCountry` VARCHAR(8) NULL COMMENT ''目的国'',
|
||||
`DestinationPort` VARCHAR(64) NULL COMMENT ''目的口岸'',
|
||||
`FlightOrVoyage` VARCHAR(64) NULL COMMENT ''航班/船名航次'',
|
||||
`Length` DECIMAL(10,2) NULL COMMENT ''长(cm)'',
|
||||
`Width` DECIMAL(10,2) NULL COMMENT ''宽(cm)'',
|
||||
`Height` DECIMAL(10,2) NULL COMMENT ''高(cm)'',
|
||||
`Weight` DECIMAL(10,2) NULL COMMENT ''重量(kg)'',
|
||||
`BagCount` INT NOT NULL DEFAULT 0 COMMENT ''大包数'',
|
||||
`ParcelCount` INT NOT NULL DEFAULT 0 COMMENT ''小包合计(含袋内)'',
|
||||
`SealTime` DATETIME NULL COMMENT ''封板时间'',
|
||||
@ -198,6 +212,41 @@ SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHE
|
||||
SET @sql := IF(@exists>0, 'ALTER TABLE `t_ship_master_item` MODIFY COLUMN `ConcurrencyStamp` CHAR(36) NOT NULL DEFAULT (UUID()) COMMENT ''并发戳''', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------- 存量补列:件重尺 + 目的口岸(可重复) ----------
|
||||
-- t_ship_bag
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_bag' AND COLUMN_NAME='DestinationPort');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_bag` ADD COLUMN `DestinationPort` VARCHAR(64) NULL COMMENT ''目的口岸'' AFTER `DestinationCountry`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_bag' AND COLUMN_NAME='Length');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_bag` ADD COLUMN `Length` DECIMAL(10,2) NULL COMMENT ''长(cm)'' AFTER `ChannelCode`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_bag' AND COLUMN_NAME='Width');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_bag` ADD COLUMN `Width` DECIMAL(10,2) NULL COMMENT ''宽(cm)'' AFTER `Length`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_bag' AND COLUMN_NAME='Height');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_bag` ADD COLUMN `Height` DECIMAL(10,2) NULL COMMENT ''高(cm)'' AFTER `Width`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_bag' AND COLUMN_NAME='Weight');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_bag` ADD COLUMN `Weight` DECIMAL(10,2) NULL COMMENT ''重量(kg)'' AFTER `Height`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- t_ship_master
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_master' AND COLUMN_NAME='DestinationPort');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_master` ADD COLUMN `DestinationPort` VARCHAR(64) NULL COMMENT ''目的口岸'' AFTER `DestinationCountry`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_master' AND COLUMN_NAME='Length');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_master` ADD COLUMN `Length` DECIMAL(10,2) NULL COMMENT ''长(cm)'' AFTER `FlightOrVoyage`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_master' AND COLUMN_NAME='Width');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_master` ADD COLUMN `Width` DECIMAL(10,2) NULL COMMENT ''宽(cm)'' AFTER `Length`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_master' AND COLUMN_NAME='Height');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_master` ADD COLUMN `Height` DECIMAL(10,2) NULL COMMENT ''高(cm)'' AFTER `Width`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
SET @exists := (SELECT COUNT(1) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=@db AND TABLE_NAME='t_ship_master' AND COLUMN_NAME='Weight');
|
||||
SET @sql := IF(@exists=0, 'ALTER TABLE `t_ship_master` ADD COLUMN `Weight` DECIMAL(10,2) NULL COMMENT ''重量(kg)'' AFTER `Height`', 'SELECT 1');
|
||||
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------- t_order 归属冗余(可空,不强制) ----------
|
||||
SET @exists := (
|
||||
SELECT COUNT(1) FROM information_schema.COLUMNS
|
||||
|
||||
@ -10,8 +10,46 @@ public class CreateShipBagInput
|
||||
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
public string? ChannelCode { get; set; }
|
||||
|
||||
/// <summary>长(cm)。</summary>
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
/// <summary>宽(cm)。</summary>
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
/// <summary>高(cm)。</summary>
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
/// <summary>重量(kg)。</summary>
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>更新大包件重尺 / 目的口岸等属性(交运前)。</summary>
|
||||
public class UpdateShipBagMetaInput
|
||||
{
|
||||
public string BagNo { get; set; } = string.Empty;
|
||||
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
public string? ChannelCode { get; set; }
|
||||
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
@ -60,8 +98,23 @@ public class ShipBagOutput
|
||||
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
public string? ChannelCode { get; set; }
|
||||
|
||||
/// <summary>长(cm)。</summary>
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
/// <summary>宽(cm)。</summary>
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
/// <summary>高(cm)。</summary>
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
/// <summary>重量(kg)。</summary>
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public int ParcelCount { get; set; }
|
||||
|
||||
public DateTime? SealTime { get; set; }
|
||||
@ -118,10 +171,44 @@ public class CreateShipMasterInput
|
||||
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
public string? FlightOrVoyage { get; set; }
|
||||
|
||||
public string? ExternalMawb { get; set; }
|
||||
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>更新主单件重尺 / 目的口岸等属性(交运前)。</summary>
|
||||
public class UpdateShipMasterMetaInput
|
||||
{
|
||||
public string MasterNo { get; set; } = string.Empty;
|
||||
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
public string? FlightOrVoyage { get; set; }
|
||||
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public string? Remark { get; set; }
|
||||
}
|
||||
|
||||
@ -196,8 +283,23 @@ public class ShipMasterOutput
|
||||
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
public string? FlightOrVoyage { get; set; }
|
||||
|
||||
/// <summary>长(cm)。</summary>
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
/// <summary>宽(cm)。</summary>
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
/// <summary>高(cm)。</summary>
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
/// <summary>重量(kg)。</summary>
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public int BagCount { get; set; }
|
||||
|
||||
public int ParcelCount { get; set; }
|
||||
@ -228,3 +330,59 @@ public class ShipMasterItemOutput
|
||||
|
||||
public string? WaybillNo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>批量打印大包标签入参。</summary>
|
||||
public class ShipBagPrintLabelsInput
|
||||
{
|
||||
/// <summary>大包号列表。</summary>
|
||||
public List<string> BagNos { get; set; } = [];
|
||||
|
||||
/// <summary>标签模板 ID;不传则取类型 shipBag 最新模板。</summary>
|
||||
public int? LabelTemplateId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>批量打印大包标签出参。</summary>
|
||||
public class ShipBagPrintLabelsOutput
|
||||
{
|
||||
/// <summary>使用的模板名称。</summary>
|
||||
public string? TemplateName { get; set; }
|
||||
|
||||
/// <summary>各包打印结果。</summary>
|
||||
public List<ShipBagPrintLabelItemOutput> Items { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>单个大包打印结果。</summary>
|
||||
public class ShipBagPrintLabelItemOutput
|
||||
{
|
||||
public string BagNo { get; set; } = string.Empty;
|
||||
|
||||
public string PrintUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>批量打印主单标签入参。</summary>
|
||||
public class ShipMasterPrintLabelsInput
|
||||
{
|
||||
/// <summary>内部主单号列表。</summary>
|
||||
public List<string> MasterNos { get; set; } = [];
|
||||
|
||||
/// <summary>标签模板 ID;不传则取类型 shipMaster 最新模板。</summary>
|
||||
public int? LabelTemplateId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>批量打印主单标签出参。</summary>
|
||||
public class ShipMasterPrintLabelsOutput
|
||||
{
|
||||
/// <summary>使用的模板名称。</summary>
|
||||
public string? TemplateName { get; set; }
|
||||
|
||||
/// <summary>各主单打印结果。</summary>
|
||||
public List<ShipMasterPrintLabelItemOutput> Items { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>单个主单打印结果。</summary>
|
||||
public class ShipMasterPrintLabelItemOutput
|
||||
{
|
||||
public string MasterNo { get; set; } = string.Empty;
|
||||
|
||||
public string PrintUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@ -121,6 +121,61 @@ public static class LabelFieldDictionary
|
||||
]
|
||||
},
|
||||
new LabelFieldGroup
|
||||
{
|
||||
Code = "shipBag",
|
||||
Title = "出库大包",
|
||||
Fields =
|
||||
[
|
||||
Field("bagNo", "大包号"),
|
||||
Field("bagType", "袋型编码"),
|
||||
Field("bagTypeName", "袋型名称"),
|
||||
Field("status", "状态"),
|
||||
Field("barcode", "条码内容"),
|
||||
Field("destinationCountry", "目的国"),
|
||||
Field("destinationPort", "目的口岸"),
|
||||
Field("channelCode", "渠道编码"),
|
||||
Field("parcelCount", "件数"),
|
||||
Field("weight", "重量(kg)"),
|
||||
Field("length", "长(cm)"),
|
||||
Field("width", "宽(cm)"),
|
||||
Field("height", "高(cm)"),
|
||||
Field("weightUnit", "重量单位"),
|
||||
Field("dimUnit", "尺寸单位"),
|
||||
Field("dimensions", "尺寸摘要"),
|
||||
Field("warehouseName", "仓库"),
|
||||
Field("sealTime", "封袋时间"),
|
||||
Field("remark", "备注")
|
||||
]
|
||||
},
|
||||
new LabelFieldGroup
|
||||
{
|
||||
Code = "shipMaster",
|
||||
Title = "内部主单",
|
||||
Fields =
|
||||
[
|
||||
Field("masterNo", "内部主单号"),
|
||||
Field("externalMawb", "外部MAWB"),
|
||||
Field("barcode", "条码内容"),
|
||||
Field("status", "状态"),
|
||||
Field("destinationCountry", "目的国"),
|
||||
Field("destinationPort", "目的口岸"),
|
||||
Field("flightOrVoyage", "航班/航次"),
|
||||
Field("bagCount", "大包数"),
|
||||
Field("parcelCount", "小包数"),
|
||||
Field("weight", "重量(kg)"),
|
||||
Field("length", "长(cm)"),
|
||||
Field("width", "宽(cm)"),
|
||||
Field("height", "高(cm)"),
|
||||
Field("weightUnit", "重量单位"),
|
||||
Field("dimUnit", "尺寸单位"),
|
||||
Field("dimensions", "尺寸摘要"),
|
||||
Field("warehouseName", "仓库"),
|
||||
Field("sealTime", "封板时间"),
|
||||
Field("handTime", "交运时间"),
|
||||
Field("remark", "备注")
|
||||
]
|
||||
},
|
||||
new LabelFieldGroup
|
||||
{
|
||||
Code = "system",
|
||||
Title = "系统",
|
||||
|
||||
80
src/Oms.Application/Labeling/ShipBagLabelPrintDataBuilder.cs
Normal file
80
src/Oms.Application/Labeling/ShipBagLabelPrintDataBuilder.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System.Globalization;
|
||||
using Oms.Domain.OperationsAggregate.Entities;
|
||||
|
||||
namespace Oms.Application.Labeling;
|
||||
|
||||
/// <summary>
|
||||
/// 出库大包标签 PrintData(camelCase,与 hiprint 字段对齐)。
|
||||
/// </summary>
|
||||
public static class ShipBagLabelPrintDataBuilder
|
||||
{
|
||||
public static IReadOnlyDictionary<string, object?> Build(
|
||||
ShipBag bag,
|
||||
string? warehouseName = null,
|
||||
string? operatorName = null,
|
||||
DateTime? printTime = null,
|
||||
int pageIndex = 1,
|
||||
int pageCount = 1)
|
||||
{
|
||||
return new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["bagNo"] = bag.BagNo,
|
||||
["bagType"] = bag.BagType,
|
||||
["bagTypeName"] = string.Equals(bag.BagType, "box", StringComparison.OrdinalIgnoreCase) ? "箱子" : "麻袋",
|
||||
["status"] = bag.Status,
|
||||
["barcode"] = bag.BagNo,
|
||||
["destinationCountry"] = bag.DestinationCountry,
|
||||
["destinationPort"] = bag.DestinationPort,
|
||||
["channelCode"] = bag.ChannelCode,
|
||||
["parcelCount"] = bag.ParcelCount,
|
||||
["weight"] = bag.Weight,
|
||||
["length"] = bag.Length,
|
||||
["width"] = bag.Width,
|
||||
["height"] = bag.Height,
|
||||
["weightUnit"] = "KG",
|
||||
["dimUnit"] = "CM",
|
||||
["dimensions"] = FormatDims(bag.Length, bag.Width, bag.Height),
|
||||
["remark"] = bag.Remark,
|
||||
["warehouseName"] = warehouseName,
|
||||
["sealTime"] = bag.SealTime?.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["pageIndex"] = pageIndex,
|
||||
["pageCount"] = pageCount,
|
||||
["printTime"] = (printTime ?? DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["operatorName"] = operatorName
|
||||
};
|
||||
}
|
||||
|
||||
public static IReadOnlyDictionary<string, object?> BuildMock() =>
|
||||
new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["bagNo"] = "BAG2511071200001234",
|
||||
["bagType"] = "sack",
|
||||
["bagTypeName"] = "麻袋",
|
||||
["status"] = "sealed",
|
||||
["barcode"] = "BAG2511071200001234",
|
||||
["destinationCountry"] = "US",
|
||||
["destinationPort"] = "LAX",
|
||||
["channelCode"] = "DEMO",
|
||||
["parcelCount"] = 12,
|
||||
["weight"] = 18.5m,
|
||||
["length"] = 60m,
|
||||
["width"] = 40m,
|
||||
["height"] = 40m,
|
||||
["weightUnit"] = "KG",
|
||||
["dimUnit"] = "CM",
|
||||
["dimensions"] = "60×40×40",
|
||||
["remark"] = null,
|
||||
["warehouseName"] = "深圳仓库",
|
||||
["sealTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["pageIndex"] = 1,
|
||||
["pageCount"] = 1,
|
||||
["printTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["operatorName"] = "demo"
|
||||
};
|
||||
|
||||
private static string? FormatDims(decimal? length, decimal? width, decimal? height)
|
||||
{
|
||||
if (length is null && width is null && height is null) return null;
|
||||
return $"{length ?? 0}×{width ?? 0}×{height ?? 0}";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
using System.Globalization;
|
||||
using Oms.Domain.OperationsAggregate.Entities;
|
||||
|
||||
namespace Oms.Application.Labeling;
|
||||
|
||||
/// <summary>
|
||||
/// 内部主单标签 PrintData(camelCase,与 hiprint 字段对齐)。
|
||||
/// </summary>
|
||||
public static class ShipMasterLabelPrintDataBuilder
|
||||
{
|
||||
public static IReadOnlyDictionary<string, object?> Build(
|
||||
ShipMaster master,
|
||||
string? warehouseName = null,
|
||||
string? operatorName = null,
|
||||
DateTime? printTime = null,
|
||||
int pageIndex = 1,
|
||||
int pageCount = 1)
|
||||
{
|
||||
return new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["masterNo"] = master.MasterNo,
|
||||
["externalMawb"] = master.ExternalMawb,
|
||||
["barcode"] = FirstNonEmpty(master.ExternalMawb, master.MasterNo),
|
||||
["status"] = master.Status,
|
||||
["destinationCountry"] = master.DestinationCountry,
|
||||
["destinationPort"] = master.DestinationPort,
|
||||
["flightOrVoyage"] = master.FlightOrVoyage,
|
||||
["bagCount"] = master.BagCount,
|
||||
["parcelCount"] = master.ParcelCount,
|
||||
["weight"] = master.Weight,
|
||||
["length"] = master.Length,
|
||||
["width"] = master.Width,
|
||||
["height"] = master.Height,
|
||||
["weightUnit"] = "KG",
|
||||
["dimUnit"] = "CM",
|
||||
["dimensions"] = FormatDims(master.Length, master.Width, master.Height),
|
||||
["remark"] = master.Remark,
|
||||
["warehouseName"] = warehouseName,
|
||||
["sealTime"] = master.SealTime?.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["handTime"] = master.HandTime?.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["pageIndex"] = pageIndex,
|
||||
["pageCount"] = pageCount,
|
||||
["printTime"] = (printTime ?? DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["operatorName"] = operatorName
|
||||
};
|
||||
}
|
||||
|
||||
public static IReadOnlyDictionary<string, object?> BuildMock() =>
|
||||
new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["masterNo"] = "MBL2511071200005678",
|
||||
["externalMawb"] = "176-12345678",
|
||||
["barcode"] = "176-12345678",
|
||||
["status"] = "sealed",
|
||||
["destinationCountry"] = "US",
|
||||
["destinationPort"] = "JFK",
|
||||
["flightOrVoyage"] = "CA981",
|
||||
["bagCount"] = 8,
|
||||
["parcelCount"] = 96,
|
||||
["weight"] = 320.5m,
|
||||
["length"] = 120m,
|
||||
["width"] = 100m,
|
||||
["height"] = 160m,
|
||||
["weightUnit"] = "KG",
|
||||
["dimUnit"] = "CM",
|
||||
["dimensions"] = "120×100×160",
|
||||
["remark"] = null,
|
||||
["warehouseName"] = "深圳仓库",
|
||||
["sealTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["handTime"] = null,
|
||||
["pageIndex"] = 1,
|
||||
["pageCount"] = 1,
|
||||
["printTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
|
||||
["operatorName"] = "demo"
|
||||
};
|
||||
|
||||
private static string? FormatDims(decimal? length, decimal? width, decimal? height)
|
||||
{
|
||||
if (length is null && width is null && height is null) return null;
|
||||
return $"{length ?? 0}×{width ?? 0}×{height ?? 0}";
|
||||
}
|
||||
|
||||
private static string? FirstNonEmpty(params string?[] values) =>
|
||||
values.FirstOrDefault(x => !string.IsNullOrWhiteSpace(x));
|
||||
}
|
||||
@ -115,6 +115,14 @@ public class LabelTemplateService : ApplicationService
|
||||
{
|
||||
printData = SkuLabelPrintDataBuilder.BuildMock();
|
||||
}
|
||||
else if (string.Equals(templateType, LabelTemplateTypeCodes.ShipBag, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
printData = ShipBagLabelPrintDataBuilder.BuildMock();
|
||||
}
|
||||
else if (string.Equals(templateType, LabelTemplateTypeCodes.ShipMaster, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
printData = ShipMasterLabelPrintDataBuilder.BuildMock();
|
||||
}
|
||||
|
||||
var bytes = await LabelPdfGenerationService.PreviewAsync(templateJson, printData);
|
||||
return new FileContentResult(bytes, "application/pdf")
|
||||
|
||||
@ -1,18 +1,25 @@
|
||||
using System.Data;
|
||||
using Fake.Application;
|
||||
using Fake.ObjectStorage;
|
||||
using Fake.UnitOfWork;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Operations;
|
||||
using Oms.Application.Dtos.Shared;
|
||||
using Oms.Application.Labeling;
|
||||
using Oms.Application.Services.Orders;
|
||||
using Oms.Application.Services.Orders.Issues;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Application.Storage;
|
||||
using Oms.Domain.ChannelsAggregate.Consts;
|
||||
using Oms.Domain.ChannelsAggregate.Entities;
|
||||
using Oms.Domain.ChannelsAggregate.Repositories;
|
||||
using Oms.Domain.OperationsAggregate.Consts;
|
||||
using Oms.Domain.OperationsAggregate.Entities;
|
||||
using Oms.Domain.OperationsAggregate.Repositories;
|
||||
using Oms.Domain.OrdersAggregate.Consts;
|
||||
using Oms.Domain.OrdersAggregate.Entities;
|
||||
using Oms.Domain.OrdersAggregate.Repositories;
|
||||
using Oms.Domain.SystemAggregate.Repositories;
|
||||
using OutboundRecord = Oms.Domain.OperationsAggregate.Entities.OutboundRecord;
|
||||
|
||||
namespace Oms.Application.Services.Operations;
|
||||
@ -31,6 +38,12 @@ public class ShipBagService : ApplicationService
|
||||
LazyServiceProvider.GetRequiredService<AutoTriggerRuntimeService>();
|
||||
private IOutboundRecordRepository OutboundRecordRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IOutboundRecordRepository>();
|
||||
private ILabelTemplateRepository LabelTemplateRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ILabelTemplateRepository>();
|
||||
private ILabelPdfRenderer LabelPdfRenderer => LazyServiceProvider.GetRequiredService<ILabelPdfRenderer>();
|
||||
private IObjectStorage FileStorage => LazyServiceProvider.GetRequiredService<IObjectStorage>();
|
||||
private IWarehouseAddressRepository WarehouseAddressRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IWarehouseAddressRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// 创建空大包(装袋中)。
|
||||
@ -56,7 +69,14 @@ public class ShipBagService : ApplicationService
|
||||
DestinationCountry = string.IsNullOrWhiteSpace(input.DestinationCountry)
|
||||
? null
|
||||
: input.DestinationCountry.Trim().ToUpperInvariant(),
|
||||
DestinationPort = string.IsNullOrWhiteSpace(input.DestinationPort)
|
||||
? null
|
||||
: input.DestinationPort.Trim(),
|
||||
ChannelCode = string.IsNullOrWhiteSpace(input.ChannelCode) ? null : input.ChannelCode.Trim(),
|
||||
Length = input.Length,
|
||||
Width = input.Width,
|
||||
Height = input.Height,
|
||||
Weight = input.Weight,
|
||||
Remark = input.Remark?.Trim(),
|
||||
ParcelCount = 0,
|
||||
};
|
||||
@ -65,6 +85,35 @@ public class ShipBagService : ApplicationService
|
||||
return MapBag(saved);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新大包件重尺、目的口岸等属性(已出库/作废不可改)。
|
||||
/// </summary>
|
||||
[HttpPost("/operation/bag/update-meta")]
|
||||
[UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
|
||||
public async Task<ShipBagOutput> UpdateMetaAsync(UpdateShipBagMetaInput input)
|
||||
{
|
||||
var bag = await RequireBagAsync(input.BagNo);
|
||||
if (bag.Status is ShipBagStatusCodes.Shipped or ShipBagStatusCodes.Voided)
|
||||
{
|
||||
throw new BusinessException("已出库或已作废的大包不可改属性");
|
||||
}
|
||||
|
||||
bag.DestinationCountry = string.IsNullOrWhiteSpace(input.DestinationCountry)
|
||||
? null
|
||||
: input.DestinationCountry.Trim().ToUpperInvariant();
|
||||
bag.DestinationPort = string.IsNullOrWhiteSpace(input.DestinationPort)
|
||||
? null
|
||||
: input.DestinationPort.Trim();
|
||||
bag.ChannelCode = string.IsNullOrWhiteSpace(input.ChannelCode) ? null : input.ChannelCode.Trim();
|
||||
bag.Length = input.Length;
|
||||
bag.Width = input.Width;
|
||||
bag.Height = input.Height;
|
||||
bag.Weight = input.Weight;
|
||||
bag.Remark = input.Remark?.Trim();
|
||||
await BagRepository.UpdateAsync(bag);
|
||||
return await GetDetailAsync(bag.BagNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫小包入袋(仅待发货;可不使用大包出库路径)。
|
||||
/// </summary>
|
||||
@ -374,6 +423,137 @@ public class ShipBagService : ApplicationService
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量打印大包标签:按所选模板(类型 shipBag)渲染 PDF,返回各包可打印 URL。
|
||||
/// </summary>
|
||||
/// <param name="input">大包号列表与可选模板 ID。</param>
|
||||
/// <returns>模板名 + 各包 printUrl。</returns>
|
||||
[HttpPost("/operation/bag/print-labels")]
|
||||
public async Task<ShipBagPrintLabelsOutput> PrintLabelsAsync(ShipBagPrintLabelsInput input)
|
||||
{
|
||||
var bagNos = (input.BagNos ?? [])
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Select(x => x.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
if (bagNos.Count == 0)
|
||||
{
|
||||
throw new BusinessException("请选择要打印的大包");
|
||||
}
|
||||
|
||||
var template = await ResolveLabelTemplateAsync(LabelTemplateTypeCodes.ShipBag, input.LabelTemplateId);
|
||||
var bags = await BagRepository.GetListAsync(x => bagNos.Contains(x.BagNo));
|
||||
if (bags.Count == 0)
|
||||
{
|
||||
throw new BusinessException("未找到可打印的大包");
|
||||
}
|
||||
|
||||
var bagMap = bags.ToDictionary(x => x.BagNo, StringComparer.OrdinalIgnoreCase);
|
||||
var warehouseIds = bags.Where(x => x.WarehouseId is > 0).Select(x => x.WarehouseId!.Value).Distinct().ToArray();
|
||||
var warehouses = warehouseIds.Length == 0
|
||||
? []
|
||||
: await WarehouseAddressRepository.GetListAsync(x => warehouseIds.Contains(x.Id));
|
||||
var warehouseMap = warehouses.ToDictionary(x => x.Id);
|
||||
var operatorName = CurrentUser?.UserName;
|
||||
var printTime = DateTime.Now;
|
||||
var pageCount = bagNos.Count(x => bagMap.ContainsKey(x));
|
||||
var pageIndex = 0;
|
||||
var items = new List<ShipBagPrintLabelItemOutput>();
|
||||
|
||||
foreach (var bagNo in bagNos)
|
||||
{
|
||||
if (!bagMap.TryGetValue(bagNo, out var bag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pageIndex++;
|
||||
string? warehouseName = null;
|
||||
if (bag.WarehouseId is > 0 && warehouseMap.TryGetValue(bag.WarehouseId.Value, out var wh))
|
||||
{
|
||||
warehouseName = wh.WarehouseName;
|
||||
}
|
||||
|
||||
var printData = ShipBagLabelPrintDataBuilder.Build(
|
||||
bag,
|
||||
warehouseName: warehouseName,
|
||||
operatorName: operatorName,
|
||||
printTime: printTime,
|
||||
pageIndex: pageIndex,
|
||||
pageCount: pageCount);
|
||||
var pdfBytes = await LabelPdfRenderer.RenderAsync(template.TemplateJson!, printData);
|
||||
var printUrl = await SaveBagLabelPdfAsync(bag.BagNo, pdfBytes);
|
||||
items.Add(new ShipBagPrintLabelItemOutput
|
||||
{
|
||||
BagNo = bag.BagNo,
|
||||
PrintUrl = printUrl
|
||||
});
|
||||
}
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
throw new BusinessException("未找到可打印的大包");
|
||||
}
|
||||
|
||||
return new ShipBagPrintLabelsOutput
|
||||
{
|
||||
TemplateName = template.Name,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<LabelTemplate> ResolveLabelTemplateAsync(string templateType, int? labelTemplateId)
|
||||
{
|
||||
if (labelTemplateId is > 0)
|
||||
{
|
||||
var specified = await LabelTemplateRepository.FirstOrDefaultAsync(x => x.Id == labelTemplateId.Value);
|
||||
if (specified == null)
|
||||
{
|
||||
throw new BusinessException("标签模板不存在");
|
||||
}
|
||||
|
||||
if (!string.Equals(specified.TemplateType, templateType, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new BusinessException($"请选择类型为 {templateType} 的标签模板");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(specified.TemplateJson))
|
||||
{
|
||||
throw new BusinessException("所选标签模板内容为空,请先在标签设计中保存");
|
||||
}
|
||||
|
||||
return specified;
|
||||
}
|
||||
|
||||
var templates = await LabelTemplateRepository.GetListAsync(x => x.TemplateType == templateType);
|
||||
var latest = templates
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.TemplateJson))
|
||||
.OrderByDescending(x => x.UpdateTime)
|
||||
.ThenByDescending(x => x.Id)
|
||||
.FirstOrDefault();
|
||||
if (latest == null)
|
||||
{
|
||||
throw new BusinessException($"未配置大包标签模板(类型 {templateType}),请先在标签设计中创建");
|
||||
}
|
||||
|
||||
return latest;
|
||||
}
|
||||
|
||||
private async Task<string> SaveBagLabelPdfAsync(string bagNo, byte[] pdfBytes)
|
||||
{
|
||||
var safeNo = string.IsNullOrWhiteSpace(bagNo) ? "bag" : bagNo.Trim();
|
||||
foreach (var c in Path.GetInvalidFileNameChars())
|
||||
{
|
||||
safeNo = safeNo.Replace(c, '_');
|
||||
}
|
||||
|
||||
var fileName = $"{safeNo}-{DateTime.Now:yyyyMMddHHmmssfff}.pdf";
|
||||
var relativeKey = $"uploads/prints/ship-bag-labels/{fileName}";
|
||||
await using var stream = new MemoryStream(pdfBytes);
|
||||
var key = await FileStorage.SaveObjectAsync(stream, relativeKey, "application/pdf");
|
||||
return FileStorage.GetPublicUrl(key);
|
||||
}
|
||||
|
||||
private async Task<ShipBag> RequireBagAsync(string bagNo)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(bagNo))
|
||||
@ -448,7 +628,12 @@ public class ShipBagService : ApplicationService
|
||||
},
|
||||
WarehouseId = bag.WarehouseId,
|
||||
DestinationCountry = bag.DestinationCountry,
|
||||
DestinationPort = bag.DestinationPort,
|
||||
ChannelCode = bag.ChannelCode,
|
||||
Length = bag.Length,
|
||||
Width = bag.Width,
|
||||
Height = bag.Height,
|
||||
Weight = bag.Weight,
|
||||
ParcelCount = bag.ParcelCount,
|
||||
SealTime = bag.SealTime,
|
||||
ShipTime = bag.ShipTime,
|
||||
|
||||
@ -1,15 +1,22 @@
|
||||
using System.Data;
|
||||
using Fake.Application;
|
||||
using Fake.ObjectStorage;
|
||||
using Fake.UnitOfWork;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Oms.Application.Dtos.Operations;
|
||||
using Oms.Application.Dtos.Shared;
|
||||
using Oms.Application.Labeling;
|
||||
using Oms.Application.Shared;
|
||||
using Oms.Application.Storage;
|
||||
using Oms.Domain.ChannelsAggregate.Consts;
|
||||
using Oms.Domain.ChannelsAggregate.Entities;
|
||||
using Oms.Domain.ChannelsAggregate.Repositories;
|
||||
using Oms.Domain.OperationsAggregate.Consts;
|
||||
using Oms.Domain.OperationsAggregate.Entities;
|
||||
using Oms.Domain.OperationsAggregate.Repositories;
|
||||
using Oms.Domain.OrdersAggregate.Consts;
|
||||
using Oms.Domain.OrdersAggregate.Repositories;
|
||||
using Oms.Domain.SystemAggregate.Repositories;
|
||||
|
||||
namespace Oms.Application.Services.Operations;
|
||||
|
||||
@ -27,6 +34,12 @@ public class ShipMasterService : ApplicationService
|
||||
private IShipBagItemRepository BagItemRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IShipBagItemRepository>();
|
||||
private IOrderRepository OrderRepository => LazyServiceProvider.GetRequiredService<IOrderRepository>();
|
||||
private ILabelTemplateRepository LabelTemplateRepository =>
|
||||
LazyServiceProvider.GetRequiredService<ILabelTemplateRepository>();
|
||||
private ILabelPdfRenderer LabelPdfRenderer => LazyServiceProvider.GetRequiredService<ILabelPdfRenderer>();
|
||||
private IObjectStorage FileStorage => LazyServiceProvider.GetRequiredService<IObjectStorage>();
|
||||
private IWarehouseAddressRepository WarehouseAddressRepository =>
|
||||
LazyServiceProvider.GetRequiredService<IWarehouseAddressRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// 创建内部主单(打板中)。
|
||||
@ -43,16 +56,54 @@ public class ShipMasterService : ApplicationService
|
||||
DestinationCountry = string.IsNullOrWhiteSpace(input.DestinationCountry)
|
||||
? null
|
||||
: input.DestinationCountry.Trim().ToUpperInvariant(),
|
||||
DestinationPort = string.IsNullOrWhiteSpace(input.DestinationPort)
|
||||
? null
|
||||
: input.DestinationPort.Trim(),
|
||||
FlightOrVoyage = string.IsNullOrWhiteSpace(input.FlightOrVoyage)
|
||||
? null
|
||||
: input.FlightOrVoyage.Trim(),
|
||||
ExternalMawb = string.IsNullOrWhiteSpace(input.ExternalMawb) ? null : input.ExternalMawb.Trim(),
|
||||
Length = input.Length,
|
||||
Width = input.Width,
|
||||
Height = input.Height,
|
||||
Weight = input.Weight,
|
||||
Remark = input.Remark?.Trim(),
|
||||
};
|
||||
var saved = await MasterRepository.InsertAsync(entity);
|
||||
return MapMaster(saved);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新主单件重尺、目的口岸等属性(已交运/作废不可改)。
|
||||
/// </summary>
|
||||
[HttpPost("/operation/master/update-meta")]
|
||||
[UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
|
||||
public async Task<ShipMasterOutput> UpdateMetaAsync(UpdateShipMasterMetaInput input)
|
||||
{
|
||||
var master = await RequireMasterAsync(input.MasterNo);
|
||||
if (master.Status is ShipMasterStatusCodes.Handed or ShipMasterStatusCodes.Voided)
|
||||
{
|
||||
throw new BusinessException("已交运或已作废的主单不可改属性");
|
||||
}
|
||||
|
||||
master.DestinationCountry = string.IsNullOrWhiteSpace(input.DestinationCountry)
|
||||
? null
|
||||
: input.DestinationCountry.Trim().ToUpperInvariant();
|
||||
master.DestinationPort = string.IsNullOrWhiteSpace(input.DestinationPort)
|
||||
? null
|
||||
: input.DestinationPort.Trim();
|
||||
master.FlightOrVoyage = string.IsNullOrWhiteSpace(input.FlightOrVoyage)
|
||||
? null
|
||||
: input.FlightOrVoyage.Trim();
|
||||
master.Length = input.Length;
|
||||
master.Width = input.Width;
|
||||
master.Height = input.Height;
|
||||
master.Weight = input.Weight;
|
||||
master.Remark = input.Remark?.Trim();
|
||||
await MasterRepository.UpdateAsync(master);
|
||||
return await GetDetailAsync(master.MasterNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扫已封/已出库大包上板。
|
||||
/// </summary>
|
||||
@ -369,6 +420,137 @@ public class ShipMasterService : ApplicationService
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量打印主单标签:按所选模板(类型 shipMaster)渲染 PDF,返回各主单可打印 URL。
|
||||
/// </summary>
|
||||
/// <param name="input">主单号列表与可选模板 ID。</param>
|
||||
/// <returns>模板名 + 各主单 printUrl。</returns>
|
||||
[HttpPost("/operation/master/print-labels")]
|
||||
public async Task<ShipMasterPrintLabelsOutput> PrintLabelsAsync(ShipMasterPrintLabelsInput input)
|
||||
{
|
||||
var masterNos = (input.MasterNos ?? [])
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Select(x => x.Trim())
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.ToList();
|
||||
if (masterNos.Count == 0)
|
||||
{
|
||||
throw new BusinessException("请选择要打印的主单");
|
||||
}
|
||||
|
||||
var template = await ResolveLabelTemplateAsync(LabelTemplateTypeCodes.ShipMaster, input.LabelTemplateId);
|
||||
var masters = await MasterRepository.GetListAsync(x => masterNos.Contains(x.MasterNo));
|
||||
if (masters.Count == 0)
|
||||
{
|
||||
throw new BusinessException("未找到可打印的主单");
|
||||
}
|
||||
|
||||
var masterMap = masters.ToDictionary(x => x.MasterNo, StringComparer.OrdinalIgnoreCase);
|
||||
var warehouseIds = masters.Where(x => x.WarehouseId is > 0).Select(x => x.WarehouseId!.Value).Distinct().ToArray();
|
||||
var warehouses = warehouseIds.Length == 0
|
||||
? []
|
||||
: await WarehouseAddressRepository.GetListAsync(x => warehouseIds.Contains(x.Id));
|
||||
var warehouseMap = warehouses.ToDictionary(x => x.Id);
|
||||
var operatorName = CurrentUser?.UserName;
|
||||
var printTime = DateTime.Now;
|
||||
var pageCount = masterNos.Count(x => masterMap.ContainsKey(x));
|
||||
var pageIndex = 0;
|
||||
var items = new List<ShipMasterPrintLabelItemOutput>();
|
||||
|
||||
foreach (var masterNo in masterNos)
|
||||
{
|
||||
if (!masterMap.TryGetValue(masterNo, out var master))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pageIndex++;
|
||||
string? warehouseName = null;
|
||||
if (master.WarehouseId is > 0 && warehouseMap.TryGetValue(master.WarehouseId.Value, out var wh))
|
||||
{
|
||||
warehouseName = wh.WarehouseName;
|
||||
}
|
||||
|
||||
var printData = ShipMasterLabelPrintDataBuilder.Build(
|
||||
master,
|
||||
warehouseName: warehouseName,
|
||||
operatorName: operatorName,
|
||||
printTime: printTime,
|
||||
pageIndex: pageIndex,
|
||||
pageCount: pageCount);
|
||||
var pdfBytes = await LabelPdfRenderer.RenderAsync(template.TemplateJson!, printData);
|
||||
var printUrl = await SaveMasterLabelPdfAsync(master.MasterNo, pdfBytes);
|
||||
items.Add(new ShipMasterPrintLabelItemOutput
|
||||
{
|
||||
MasterNo = master.MasterNo,
|
||||
PrintUrl = printUrl
|
||||
});
|
||||
}
|
||||
|
||||
if (items.Count == 0)
|
||||
{
|
||||
throw new BusinessException("未找到可打印的主单");
|
||||
}
|
||||
|
||||
return new ShipMasterPrintLabelsOutput
|
||||
{
|
||||
TemplateName = template.Name,
|
||||
Items = items
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<LabelTemplate> ResolveLabelTemplateAsync(string templateType, int? labelTemplateId)
|
||||
{
|
||||
if (labelTemplateId is > 0)
|
||||
{
|
||||
var specified = await LabelTemplateRepository.FirstOrDefaultAsync(x => x.Id == labelTemplateId.Value);
|
||||
if (specified == null)
|
||||
{
|
||||
throw new BusinessException("标签模板不存在");
|
||||
}
|
||||
|
||||
if (!string.Equals(specified.TemplateType, templateType, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new BusinessException($"请选择类型为 {templateType} 的标签模板");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(specified.TemplateJson))
|
||||
{
|
||||
throw new BusinessException("所选标签模板内容为空,请先在标签设计中保存");
|
||||
}
|
||||
|
||||
return specified;
|
||||
}
|
||||
|
||||
var templates = await LabelTemplateRepository.GetListAsync(x => x.TemplateType == templateType);
|
||||
var latest = templates
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x.TemplateJson))
|
||||
.OrderByDescending(x => x.UpdateTime)
|
||||
.ThenByDescending(x => x.Id)
|
||||
.FirstOrDefault();
|
||||
if (latest == null)
|
||||
{
|
||||
throw new BusinessException($"未配置主单标签模板(类型 {templateType}),请先在标签设计中创建");
|
||||
}
|
||||
|
||||
return latest;
|
||||
}
|
||||
|
||||
private async Task<string> SaveMasterLabelPdfAsync(string masterNo, byte[] pdfBytes)
|
||||
{
|
||||
var safeNo = string.IsNullOrWhiteSpace(masterNo) ? "master" : masterNo.Trim();
|
||||
foreach (var c in Path.GetInvalidFileNameChars())
|
||||
{
|
||||
safeNo = safeNo.Replace(c, '_');
|
||||
}
|
||||
|
||||
var fileName = $"{safeNo}-{DateTime.Now:yyyyMMddHHmmssfff}.pdf";
|
||||
var relativeKey = $"uploads/prints/ship-master-labels/{fileName}";
|
||||
await using var stream = new MemoryStream(pdfBytes);
|
||||
var key = await FileStorage.SaveObjectAsync(stream, relativeKey, "application/pdf");
|
||||
return FileStorage.GetPublicUrl(key);
|
||||
}
|
||||
|
||||
private async Task<ShipMaster> RequireMasterAsync(string masterNo)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(masterNo))
|
||||
@ -427,7 +609,12 @@ public class ShipMasterService : ApplicationService
|
||||
},
|
||||
WarehouseId = m.WarehouseId,
|
||||
DestinationCountry = m.DestinationCountry,
|
||||
DestinationPort = m.DestinationPort,
|
||||
FlightOrVoyage = m.FlightOrVoyage,
|
||||
Length = m.Length,
|
||||
Width = m.Width,
|
||||
Height = m.Height,
|
||||
Weight = m.Weight,
|
||||
BagCount = m.BagCount,
|
||||
ParcelCount = m.ParcelCount,
|
||||
SealTime = m.SealTime,
|
||||
|
||||
@ -22,4 +22,10 @@ public static class LabelTemplateTypeCodes
|
||||
|
||||
/// <summary>箱唛标签(入库预报按箱打印)。</summary>
|
||||
public const string Box = "box";
|
||||
|
||||
/// <summary>出库大包标签。</summary>
|
||||
public const string ShipBag = "shipBag";
|
||||
|
||||
/// <summary>内部主单标签。</summary>
|
||||
public const string ShipMaster = "shipMaster";
|
||||
}
|
||||
|
||||
@ -26,9 +26,29 @@ public class ShipBag : OmsAuditedAggregateRoot
|
||||
[SugarColumn(Length = 8, IsNullable = true)]
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? ChannelCode { get; set; }
|
||||
|
||||
/// <summary>长(cm)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
/// <summary>宽(cm)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
/// <summary>高(cm)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
/// <summary>重量(kg)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public int ParcelCount { get; set; }
|
||||
|
||||
public DateTime? SealTime { get; set; }
|
||||
|
||||
@ -26,9 +26,29 @@ public class ShipMaster : OmsAuditedAggregateRoot
|
||||
[SugarColumn(Length = 8, IsNullable = true)]
|
||||
public string? DestinationCountry { get; set; }
|
||||
|
||||
/// <summary>目的口岸。</summary>
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? DestinationPort { get; set; }
|
||||
|
||||
[SugarColumn(Length = 64, IsNullable = true)]
|
||||
public string? FlightOrVoyage { get; set; }
|
||||
|
||||
/// <summary>长(cm)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Length { get; set; }
|
||||
|
||||
/// <summary>宽(cm)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Width { get; set; }
|
||||
|
||||
/// <summary>高(cm)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Height { get; set; }
|
||||
|
||||
/// <summary>重量(kg)。</summary>
|
||||
[SugarColumn(DecimalDigits = 2, IsNullable = true)]
|
||||
public decimal? Weight { get; set; }
|
||||
|
||||
public int BagCount { get; set; }
|
||||
|
||||
public int ParcelCount { get; set; }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user