From 2984b9c8857ca19abcfc4b61c4ac9007baedbc1d Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Sat, 7 Nov 2026 17:55:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=A7=E5=8C=85/=E4=B8=BB=E5=8D=95?= =?UTF-8?q?=E9=9D=A2=E5=8D=95=E6=89=93=E5=8D=B0=E4=B8=8E=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=20shipBag=E3=80=81shipMaster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 支持按模板批量出签,并补齐件重尺等字段与设计器预览字段。 Co-authored-by: Cursor --- sql/migrate_ship_bag_master_20261107.sql | 49 +++++ .../Dtos/Operations/ShipContainerDtos.cs | 158 +++++++++++++++ .../Labeling/LabelFieldDictionary.cs | 55 ++++++ .../Labeling/ShipBagLabelPrintDataBuilder.cs | 80 ++++++++ .../ShipMasterLabelPrintDataBuilder.cs | 85 ++++++++ .../Services/Channels/LabelTemplateService.cs | 8 + .../Services/Operations/ShipBagService.cs | 185 +++++++++++++++++ .../Services/Operations/ShipMasterService.cs | 187 ++++++++++++++++++ .../Consts/LabelTemplateTypeCodes.cs | 6 + .../OperationsAggregate/Entities/ShipBag.cs | 20 ++ .../Entities/ShipMaster.cs | 20 ++ 11 files changed, 853 insertions(+) create mode 100644 src/Oms.Application/Labeling/ShipBagLabelPrintDataBuilder.cs create mode 100644 src/Oms.Application/Labeling/ShipMasterLabelPrintDataBuilder.cs diff --git a/sql/migrate_ship_bag_master_20261107.sql b/sql/migrate_ship_bag_master_20261107.sql index 1ac6449..f42cfe7 100644 --- a/sql/migrate_ship_bag_master_20261107.sql +++ b/sql/migrate_ship_bag_master_20261107.sql @@ -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 diff --git a/src/Oms.Application/Dtos/Operations/ShipContainerDtos.cs b/src/Oms.Application/Dtos/Operations/ShipContainerDtos.cs index b5742f2..9c9622a 100644 --- a/src/Oms.Application/Dtos/Operations/ShipContainerDtos.cs +++ b/src/Oms.Application/Dtos/Operations/ShipContainerDtos.cs @@ -10,8 +10,46 @@ public class CreateShipBagInput public string? DestinationCountry { get; set; } + /// 目的口岸。 + public string? DestinationPort { get; set; } + public string? ChannelCode { get; set; } + /// 长(cm)。 + public decimal? Length { get; set; } + + /// 宽(cm)。 + public decimal? Width { get; set; } + + /// 高(cm)。 + public decimal? Height { get; set; } + + /// 重量(kg)。 + public decimal? Weight { get; set; } + + public string? Remark { get; set; } +} + +/// 更新大包件重尺 / 目的口岸等属性(交运前)。 +public class UpdateShipBagMetaInput +{ + public string BagNo { get; set; } = string.Empty; + + public string? DestinationCountry { get; set; } + + /// 目的口岸。 + 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; } + /// 目的口岸。 + public string? DestinationPort { get; set; } + public string? ChannelCode { get; set; } + /// 长(cm)。 + public decimal? Length { get; set; } + + /// 宽(cm)。 + public decimal? Width { get; set; } + + /// 高(cm)。 + public decimal? Height { get; set; } + + /// 重量(kg)。 + 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; } + /// 目的口岸。 + 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; } +} + +/// 更新主单件重尺 / 目的口岸等属性(交运前)。 +public class UpdateShipMasterMetaInput +{ + public string MasterNo { get; set; } = string.Empty; + + public string? DestinationCountry { get; set; } + + /// 目的口岸。 + 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; } + /// 目的口岸。 + public string? DestinationPort { get; set; } + public string? FlightOrVoyage { get; set; } + /// 长(cm)。 + public decimal? Length { get; set; } + + /// 宽(cm)。 + public decimal? Width { get; set; } + + /// 高(cm)。 + public decimal? Height { get; set; } + + /// 重量(kg)。 + 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; } } + +/// 批量打印大包标签入参。 +public class ShipBagPrintLabelsInput +{ + /// 大包号列表。 + public List BagNos { get; set; } = []; + + /// 标签模板 ID;不传则取类型 shipBag 最新模板。 + public int? LabelTemplateId { get; set; } +} + +/// 批量打印大包标签出参。 +public class ShipBagPrintLabelsOutput +{ + /// 使用的模板名称。 + public string? TemplateName { get; set; } + + /// 各包打印结果。 + public List Items { get; set; } = []; +} + +/// 单个大包打印结果。 +public class ShipBagPrintLabelItemOutput +{ + public string BagNo { get; set; } = string.Empty; + + public string PrintUrl { get; set; } = string.Empty; +} + +/// 批量打印主单标签入参。 +public class ShipMasterPrintLabelsInput +{ + /// 内部主单号列表。 + public List MasterNos { get; set; } = []; + + /// 标签模板 ID;不传则取类型 shipMaster 最新模板。 + public int? LabelTemplateId { get; set; } +} + +/// 批量打印主单标签出参。 +public class ShipMasterPrintLabelsOutput +{ + /// 使用的模板名称。 + public string? TemplateName { get; set; } + + /// 各主单打印结果。 + public List Items { get; set; } = []; +} + +/// 单个主单打印结果。 +public class ShipMasterPrintLabelItemOutput +{ + public string MasterNo { get; set; } = string.Empty; + + public string PrintUrl { get; set; } = string.Empty; +} diff --git a/src/Oms.Application/Labeling/LabelFieldDictionary.cs b/src/Oms.Application/Labeling/LabelFieldDictionary.cs index 58b9f1c..f037e5b 100644 --- a/src/Oms.Application/Labeling/LabelFieldDictionary.cs +++ b/src/Oms.Application/Labeling/LabelFieldDictionary.cs @@ -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 = "系统", diff --git a/src/Oms.Application/Labeling/ShipBagLabelPrintDataBuilder.cs b/src/Oms.Application/Labeling/ShipBagLabelPrintDataBuilder.cs new file mode 100644 index 0000000..7051d16 --- /dev/null +++ b/src/Oms.Application/Labeling/ShipBagLabelPrintDataBuilder.cs @@ -0,0 +1,80 @@ +using System.Globalization; +using Oms.Domain.OperationsAggregate.Entities; + +namespace Oms.Application.Labeling; + +/// +/// 出库大包标签 PrintData(camelCase,与 hiprint 字段对齐)。 +/// +public static class ShipBagLabelPrintDataBuilder +{ + public static IReadOnlyDictionary Build( + ShipBag bag, + string? warehouseName = null, + string? operatorName = null, + DateTime? printTime = null, + int pageIndex = 1, + int pageCount = 1) + { + return new Dictionary(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 BuildMock() => + new Dictionary(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}"; + } +} diff --git a/src/Oms.Application/Labeling/ShipMasterLabelPrintDataBuilder.cs b/src/Oms.Application/Labeling/ShipMasterLabelPrintDataBuilder.cs new file mode 100644 index 0000000..9c085f4 --- /dev/null +++ b/src/Oms.Application/Labeling/ShipMasterLabelPrintDataBuilder.cs @@ -0,0 +1,85 @@ +using System.Globalization; +using Oms.Domain.OperationsAggregate.Entities; + +namespace Oms.Application.Labeling; + +/// +/// 内部主单标签 PrintData(camelCase,与 hiprint 字段对齐)。 +/// +public static class ShipMasterLabelPrintDataBuilder +{ + public static IReadOnlyDictionary Build( + ShipMaster master, + string? warehouseName = null, + string? operatorName = null, + DateTime? printTime = null, + int pageIndex = 1, + int pageCount = 1) + { + return new Dictionary(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 BuildMock() => + new Dictionary(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)); +} diff --git a/src/Oms.Application/Services/Channels/LabelTemplateService.cs b/src/Oms.Application/Services/Channels/LabelTemplateService.cs index 93a1566..0f5d588 100644 --- a/src/Oms.Application/Services/Channels/LabelTemplateService.cs +++ b/src/Oms.Application/Services/Channels/LabelTemplateService.cs @@ -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") diff --git a/src/Oms.Application/Services/Operations/ShipBagService.cs b/src/Oms.Application/Services/Operations/ShipBagService.cs index 71e8c49..ec089ea 100644 --- a/src/Oms.Application/Services/Operations/ShipBagService.cs +++ b/src/Oms.Application/Services/Operations/ShipBagService.cs @@ -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(); private IOutboundRecordRepository OutboundRecordRepository => LazyServiceProvider.GetRequiredService(); + private ILabelTemplateRepository LabelTemplateRepository => + LazyServiceProvider.GetRequiredService(); + private ILabelPdfRenderer LabelPdfRenderer => LazyServiceProvider.GetRequiredService(); + private IObjectStorage FileStorage => LazyServiceProvider.GetRequiredService(); + private IWarehouseAddressRepository WarehouseAddressRepository => + LazyServiceProvider.GetRequiredService(); /// /// 创建空大包(装袋中)。 @@ -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); } + /// + /// 更新大包件重尺、目的口岸等属性(已出库/作废不可改)。 + /// + [HttpPost("/operation/bag/update-meta")] + [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)] + public async Task 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); + } + /// /// 扫小包入袋(仅待发货;可不使用大包出库路径)。 /// @@ -374,6 +423,137 @@ public class ShipBagService : ApplicationService return output; } + /// + /// 批量打印大包标签:按所选模板(类型 shipBag)渲染 PDF,返回各包可打印 URL。 + /// + /// 大包号列表与可选模板 ID。 + /// 模板名 + 各包 printUrl。 + [HttpPost("/operation/bag/print-labels")] + public async Task 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(); + + 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 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 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 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, diff --git a/src/Oms.Application/Services/Operations/ShipMasterService.cs b/src/Oms.Application/Services/Operations/ShipMasterService.cs index 9f48d67..55d73d0 100644 --- a/src/Oms.Application/Services/Operations/ShipMasterService.cs +++ b/src/Oms.Application/Services/Operations/ShipMasterService.cs @@ -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(); private IOrderRepository OrderRepository => LazyServiceProvider.GetRequiredService(); + private ILabelTemplateRepository LabelTemplateRepository => + LazyServiceProvider.GetRequiredService(); + private ILabelPdfRenderer LabelPdfRenderer => LazyServiceProvider.GetRequiredService(); + private IObjectStorage FileStorage => LazyServiceProvider.GetRequiredService(); + private IWarehouseAddressRepository WarehouseAddressRepository => + LazyServiceProvider.GetRequiredService(); /// /// 创建内部主单(打板中)。 @@ -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); } + /// + /// 更新主单件重尺、目的口岸等属性(已交运/作废不可改)。 + /// + [HttpPost("/operation/master/update-meta")] + [UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)] + public async Task 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); + } + /// /// 扫已封/已出库大包上板。 /// @@ -369,6 +420,137 @@ public class ShipMasterService : ApplicationService return output; } + /// + /// 批量打印主单标签:按所选模板(类型 shipMaster)渲染 PDF,返回各主单可打印 URL。 + /// + /// 主单号列表与可选模板 ID。 + /// 模板名 + 各主单 printUrl。 + [HttpPost("/operation/master/print-labels")] + public async Task 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(); + + 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 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 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 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, diff --git a/src/Oms.Domain/ChannelsAggregate/Consts/LabelTemplateTypeCodes.cs b/src/Oms.Domain/ChannelsAggregate/Consts/LabelTemplateTypeCodes.cs index 3c8abdf..4d76647 100644 --- a/src/Oms.Domain/ChannelsAggregate/Consts/LabelTemplateTypeCodes.cs +++ b/src/Oms.Domain/ChannelsAggregate/Consts/LabelTemplateTypeCodes.cs @@ -22,4 +22,10 @@ public static class LabelTemplateTypeCodes /// 箱唛标签(入库预报按箱打印)。 public const string Box = "box"; + + /// 出库大包标签。 + public const string ShipBag = "shipBag"; + + /// 内部主单标签。 + public const string ShipMaster = "shipMaster"; } diff --git a/src/Oms.Domain/OperationsAggregate/Entities/ShipBag.cs b/src/Oms.Domain/OperationsAggregate/Entities/ShipBag.cs index a4bc7e2..3f1df56 100644 --- a/src/Oms.Domain/OperationsAggregate/Entities/ShipBag.cs +++ b/src/Oms.Domain/OperationsAggregate/Entities/ShipBag.cs @@ -26,9 +26,29 @@ public class ShipBag : OmsAuditedAggregateRoot [SugarColumn(Length = 8, IsNullable = true)] public string? DestinationCountry { get; set; } + /// 目的口岸。 + [SugarColumn(Length = 64, IsNullable = true)] + public string? DestinationPort { get; set; } + [SugarColumn(Length = 64, IsNullable = true)] public string? ChannelCode { get; set; } + /// 长(cm)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Length { get; set; } + + /// 宽(cm)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Width { get; set; } + + /// 高(cm)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Height { get; set; } + + /// 重量(kg)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Weight { get; set; } + public int ParcelCount { get; set; } public DateTime? SealTime { get; set; } diff --git a/src/Oms.Domain/OperationsAggregate/Entities/ShipMaster.cs b/src/Oms.Domain/OperationsAggregate/Entities/ShipMaster.cs index d51bbd2..30504ab 100644 --- a/src/Oms.Domain/OperationsAggregate/Entities/ShipMaster.cs +++ b/src/Oms.Domain/OperationsAggregate/Entities/ShipMaster.cs @@ -26,9 +26,29 @@ public class ShipMaster : OmsAuditedAggregateRoot [SugarColumn(Length = 8, IsNullable = true)] public string? DestinationCountry { get; set; } + /// 目的口岸。 + [SugarColumn(Length = 64, IsNullable = true)] + public string? DestinationPort { get; set; } + [SugarColumn(Length = 64, IsNullable = true)] public string? FlightOrVoyage { get; set; } + /// 长(cm)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Length { get; set; } + + /// 宽(cm)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Width { get; set; } + + /// 高(cm)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Height { get; set; } + + /// 重量(kg)。 + [SugarColumn(DecimalDigits = 2, IsNullable = true)] + public decimal? Weight { get; set; } + public int BagCount { get; set; } public int ParcelCount { get; set; }