mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 15:09:19 +08:00
feat: 发货仓与快递报价主数据及按仓选价算运费
This commit is contained in:
@@ -68,6 +68,7 @@ CREATE TABLE `ec_product` (
|
||||
-- 2. 公司内 sku_code 唯一,便于订单/导入匹配,以及映射平台 outer_id
|
||||
-- 3. 成本不落本表,见 ec_product_sku_cost(按生效日历史)
|
||||
-- 4. weight_g:单件实重(克,整数);NULL=未填;对齐拼多多 SKU weight;界面可按 kg 录入后换算
|
||||
-- 5. warehouse_id:默认发货仓;体积尺寸供体积重;仓/报价见 ec_warehouse_express_design.sql
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_product_sku_cost`;
|
||||
DROP TABLE IF EXISTS `ec_product_sku`;
|
||||
@@ -79,6 +80,10 @@ CREATE TABLE `ec_product_sku` (
|
||||
`sku_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'SKU 编码(公司内唯一,对应商家外部编码)',
|
||||
`barcode` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '条码(可选)',
|
||||
`weight_g` int UNSIGNED NULL DEFAULT NULL COMMENT '单件实重(克);NULL=未填;快递计费 / 平台同步用',
|
||||
`length_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '长(mm);体积重用',
|
||||
`width_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '宽(mm);体积重用',
|
||||
`height_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '高(mm);体积重用',
|
||||
`warehouse_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '默认发货仓(ec_warehouse.id)',
|
||||
`attrs` json NULL COMMENT '规格属性 JSON,如 [{"name":"颜色","value":"红"}](冗余/过渡;结构化见 ec_product_spec*)',
|
||||
`spec_combination_key` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规格组合键(value_id 升序拼接;空=未结构化遗留)',
|
||||
`image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'SKU 图文件ID(系统文件,可选)',
|
||||
@@ -98,11 +103,13 @@ CREATE TABLE `ec_product_sku` (
|
||||
INDEX `idx_ec_product_sku_status`(`status` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_barcode`(`barcode` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_image`(`image_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_warehouse`(`warehouse_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_product_sku_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_image` FOREIGN KEY (`image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-商品SKU表(内部可核算最小单位)' ;
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
-- ========================================
|
||||
-- 电商-仓库发货与快递报价(无进销存)
|
||||
-- ec_warehouse / ec_express_quote(+version/region/tier)
|
||||
-- ec_warehouse_express_bind / ec_express_carrier_alias
|
||||
-- SKU 默认仓、体积尺寸见 ec_product_design.sql(warehouse_id / length_mm…)
|
||||
-- ========================================
|
||||
|
||||
-- ----------------------------
|
||||
-- 仓库主数据(无库存)
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_warehouse_express_bind`;
|
||||
DROP TABLE IF EXISTS `ec_express_quote_tier`;
|
||||
DROP TABLE IF EXISTS `ec_express_quote_region`;
|
||||
DROP TABLE IF EXISTS `ec_express_quote_version`;
|
||||
DROP TABLE IF EXISTS `ec_express_quote`;
|
||||
DROP TABLE IF EXISTS `ec_express_carrier_alias`;
|
||||
DROP TABLE IF EXISTS `ec_warehouse`;
|
||||
|
||||
CREATE TABLE `ec_warehouse` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '仓库ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库编码(公司内唯一)',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库名称',
|
||||
`province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货省',
|
||||
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货市',
|
||||
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货地址',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_warehouse_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_status`(`status` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_warehouse_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-发货仓库(无库存)';
|
||||
|
||||
-- ----------------------------
|
||||
-- 快递报价单(公司级;不属单一仓)
|
||||
-- billing_mode: FLAT / PER_KG / REGION_WEIGHT
|
||||
-- ----------------------------
|
||||
CREATE TABLE `ec_express_quote` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '报价单ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价编码(公司内唯一)',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价名称',
|
||||
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '承运商软编码:ZTO/YTO/STO/YD/SF/JT/EMS/OTHER',
|
||||
`billing_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'FLAT/PER_KG/REGION_WEIGHT',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_quote_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_carrier`(`carrier_code` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价单';
|
||||
|
||||
-- ----------------------------
|
||||
-- 报价版本(as-of;调价追加)
|
||||
-- unit_scope: ORDER|PIECE(仅 FLAT)
|
||||
-- ----------------------------
|
||||
CREATE TABLE `ec_express_quote_version` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '版本ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||
`effective_from` date NOT NULL COMMENT '生效起始日(含)',
|
||||
`flat_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FLAT 一口价',
|
||||
`unit_scope` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'FLAT:ORDER|PIECE',
|
||||
`price_per_kg` decimal(10, 4) NULL DEFAULT NULL COMMENT 'PER_KG 单价',
|
||||
`min_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'PER_KG 最低消费',
|
||||
`volume_divisor` int UNSIGNED NULL DEFAULT 6000 COMMENT '体积重除数(长*宽*高mm / divisor = g 量级需再换算;约定:mm³/divisor→kg*1000=g)',
|
||||
`use_volumetric` tinyint NOT NULL DEFAULT 0 COMMENT '是否启用体积重:0否 1是(计费重=max实重,体积重)',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '调价说明',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_quote_version_from`(`quote_id` ASC, `effective_from` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_version_company`(`company_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价版本';
|
||||
|
||||
CREATE TABLE `ec_express_quote_region` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '分区ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||
`region_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分区名(如江浙沪)',
|
||||
`provinces_json` json NOT NULL COMMENT '省份全称列表 JSON,与 BiRegionNormalizer 对齐',
|
||||
`is_default` tinyint NOT NULL DEFAULT 0 COMMENT '是否默认分区(未命中省时回落)',
|
||||
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_region_version`(`version_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_region_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_region_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价分区';
|
||||
|
||||
CREATE TABLE `ec_express_quote_tier` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '阶梯ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||
`region_id` bigint UNSIGNED NOT NULL COMMENT '分区ID',
|
||||
`first_weight_g` int UNSIGNED NOT NULL DEFAULT 1000 COMMENT '首重(克)',
|
||||
`first_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '首重价格',
|
||||
`additional_weight_g` int UNSIGNED NOT NULL DEFAULT 1000 COMMENT '续重步进(克)',
|
||||
`additional_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '续重价格',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_quote_tier_region`(`region_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_tier_version`(`version_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_tier_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_tier_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_tier_region` FOREIGN KEY (`region_id`) REFERENCES `ec_express_quote_region` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价首重续重';
|
||||
|
||||
-- ----------------------------
|
||||
-- 仓 ↔ 报价多对多绑定
|
||||
-- ----------------------------
|
||||
CREATE TABLE `ec_warehouse_express_bind` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '绑定ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`warehouse_id` bigint UNSIGNED NOT NULL COMMENT '仓库ID',
|
||||
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||
`priority` int NOT NULL DEFAULT 100 COMMENT '仓内选价优先级(小优先)',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_warehouse_express_bind`(`warehouse_id` ASC, `quote_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_express_bind_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_express_bind_priority`(`warehouse_id` ASC, `priority` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-仓库快递报价绑定';
|
||||
|
||||
-- ----------------------------
|
||||
-- 订单 logistics_id → carrier_code 映射(公司可覆盖;company_id NULL=全局)
|
||||
-- ----------------------------
|
||||
CREATE TABLE `ec_express_carrier_alias` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '公司ID;空=全局默认',
|
||||
`logistics_pattern` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '物流标识/名称(精确匹配,大小写不敏感)',
|
||||
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '归一承运商编码',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_carrier_alias`(`company_id` ASC, `logistics_pattern` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_carrier_alias_carrier`(`carrier_code` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_carrier_alias_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-物流标识到承运商映射';
|
||||
@@ -0,0 +1,237 @@
|
||||
-- 仓库发货 + 快递报价(无进销存)+ SKU 默认仓/体积尺寸 + 菜单权限
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_warehouse` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '仓库ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库编码(公司内唯一)',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库名称',
|
||||
`province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货省',
|
||||
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货市',
|
||||
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货地址',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_warehouse_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_status`(`status` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_warehouse_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-发货仓库(无库存)';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_express_quote` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '报价单ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价编码(公司内唯一)',
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价名称',
|
||||
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '承运商软编码',
|
||||
`billing_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'FLAT/PER_KG/REGION_WEIGHT',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_quote_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_carrier`(`carrier_code` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价单';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_express_quote_version` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '版本ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||
`effective_from` date NOT NULL COMMENT '生效起始日(含)',
|
||||
`flat_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FLAT 一口价',
|
||||
`unit_scope` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'FLAT:ORDER|PIECE',
|
||||
`price_per_kg` decimal(10, 4) NULL DEFAULT NULL COMMENT 'PER_KG 单价',
|
||||
`min_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'PER_KG 最低消费',
|
||||
`volume_divisor` int UNSIGNED NULL DEFAULT 6000 COMMENT '体积重除数',
|
||||
`use_volumetric` tinyint NOT NULL DEFAULT 0 COMMENT '是否启用体积重',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '调价说明',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_quote_version_from`(`quote_id` ASC, `effective_from` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_version_company`(`company_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_version_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价版本';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_express_quote_region` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '分区ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||
`region_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分区名',
|
||||
`provinces_json` json NOT NULL COMMENT '省份全称列表 JSON',
|
||||
`is_default` tinyint NOT NULL DEFAULT 0 COMMENT '是否默认分区',
|
||||
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_region_version`(`version_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_region_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_region_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价分区';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_express_quote_tier` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '阶梯ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||
`region_id` bigint UNSIGNED NOT NULL COMMENT '分区ID',
|
||||
`first_weight_g` int UNSIGNED NOT NULL DEFAULT 1000 COMMENT '首重(克)',
|
||||
`first_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '首重价格',
|
||||
`additional_weight_g` int UNSIGNED NOT NULL DEFAULT 1000 COMMENT '续重步进(克)',
|
||||
`additional_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '续重价格',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_quote_tier_region`(`region_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_quote_tier_version`(`version_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_quote_tier_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_tier_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_express_quote_tier_region` FOREIGN KEY (`region_id`) REFERENCES `ec_express_quote_region` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价首重续重';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_warehouse_express_bind` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '绑定ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`warehouse_id` bigint UNSIGNED NOT NULL COMMENT '仓库ID',
|
||||
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||
`priority` int NOT NULL DEFAULT 100 COMMENT '仓内选价优先级(小优先)',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_warehouse_express_bind`(`warehouse_id` ASC, `quote_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_express_bind_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_warehouse_express_bind_priority`(`warehouse_id` ASC, `priority` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_warehouse_express_bind_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-仓库快递报价绑定';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_express_carrier_alias` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '公司ID;空=全局默认',
|
||||
`logistics_pattern` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '物流标识/名称',
|
||||
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '归一承运商编码',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_express_carrier_alias`(`company_id` ASC, `logistics_pattern` ASC) USING BTREE,
|
||||
INDEX `idx_ec_express_carrier_alias_carrier`(`carrier_code` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_express_carrier_alias_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-物流标识到承运商映射';
|
||||
|
||||
-- 全局默认承运商别名(常见)
|
||||
INSERT IGNORE INTO `ec_express_carrier_alias` (`company_id`, `logistics_pattern`, `carrier_code`) VALUES
|
||||
(NULL, 'ZTO', 'ZTO'), (NULL, '中通', 'ZTO'), (NULL, '中通快递', 'ZTO'),
|
||||
(NULL, 'YTO', 'YTO'), (NULL, '圆通', 'YTO'), (NULL, '圆通速递', 'YTO'),
|
||||
(NULL, 'STO', 'STO'), (NULL, '申通', 'STO'), (NULL, '申通快递', 'STO'),
|
||||
(NULL, 'YD', 'YD'), (NULL, '韵达', 'YD'), (NULL, '韵达快递', 'YD'),
|
||||
(NULL, 'SF', 'SF'), (NULL, '顺丰', 'SF'), (NULL, '顺丰速运', 'SF'),
|
||||
(NULL, 'JT', 'JT'), (NULL, '极兔', 'JT'), (NULL, '极兔速递', 'JT'),
|
||||
(NULL, 'EMS', 'EMS'), (NULL, '邮政', 'EMS'), (NULL, '邮政快递', 'EMS');
|
||||
|
||||
-- SKU:默认仓 + 体积尺寸(weight_g 已在 V20261021)
|
||||
ALTER TABLE `ec_product_sku`
|
||||
ADD COLUMN `length_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '长(mm)' AFTER `weight_g`,
|
||||
ADD COLUMN `width_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '宽(mm)' AFTER `length_mm`,
|
||||
ADD COLUMN `height_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '高(mm)' AFTER `width_mm`,
|
||||
ADD COLUMN `warehouse_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '默认发货仓' AFTER `height_mm`,
|
||||
ADD INDEX `idx_ec_product_sku_warehouse` (`warehouse_id`),
|
||||
ADD CONSTRAINT `fk_ec_product_sku_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- 权限
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3390, (SELECT id FROM `sys_permission` WHERE `code` = 'ec' LIMIT 1), 'ec:warehouse', '发货仓库', 'module', 1, '', 46
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3390 OR `code` = 'ec:warehouse');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3391, 3390, 'ec:warehouse:read', '查看', 'api', 1, '', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3391 OR `code` = 'ec:warehouse:read');
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3392, 3390, 'ec:warehouse:create', '创建', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3392 OR `code` = 'ec:warehouse:create');
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3393, 3390, 'ec:warehouse:update', '更新', 'api', 1, '', 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3393 OR `code` = 'ec:warehouse:update');
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3394, 3390, 'ec:warehouse:delete', '删除', 'api', 1, '', 4
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3394 OR `code` = 'ec:warehouse:delete');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3400, (SELECT id FROM `sys_permission` WHERE `code` = 'ec' LIMIT 1), 'ec:express-quote', '快递报价', 'module', 1, '', 47
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3400 OR `code` = 'ec:express-quote');
|
||||
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3401, 3400, 'ec:express-quote:read', '查看', 'api', 1, '', 1
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3401 OR `code` = 'ec:express-quote:read');
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3402, 3400, 'ec:express-quote:create', '创建', 'api', 1, '', 2
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3402 OR `code` = 'ec:express-quote:create');
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3403, 3400, 'ec:express-quote:update', '更新', 'api', 1, '', 3
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3403 OR `code` = 'ec:express-quote:update');
|
||||
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||
SELECT 3404, 3400, 'ec:express-quote:delete', '删除', 'api', 1, '', 4
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3404 OR `code` = 'ec:express-quote:delete');
|
||||
|
||||
-- 菜单挂「经营店铺」
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14020, (SELECT id FROM `sys_menu` WHERE `id` = 7 OR `title` = '经营店铺' OR `route_name` = 'ShopCatalog' LIMIT 1), 0,
|
||||
'WarehouseManagement', '发货仓库', '/ec/warehouse/list', '/ec/warehouse/list/index', '', 'lucide:warehouse', 'menu', 1, 1, 1, 6
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14020 OR `route_name` = 'WarehouseManagement');
|
||||
|
||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||
SELECT 14021, (SELECT id FROM `sys_menu` WHERE `id` = 7 OR `title` = '经营店铺' OR `route_name` = 'ShopCatalog' LIMIT 1), 0,
|
||||
'ExpressQuoteManagement', '快递报价', '/ec/warehouse/express-quote', '/ec/warehouse/express-quote/index', '', 'lucide:truck', 'menu', 1, 1, 1, 7
|
||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14021 OR `route_name` = 'ExpressQuoteManagement');
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'ec:warehouse:%'
|
||||
WHERE m.route_name = 'WarehouseManagement' OR m.id = 14020;
|
||||
|
||||
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'ec:express-quote:%'
|
||||
WHERE m.route_name = 'ExpressQuoteManagement' OR m.id = 14021;
|
||||
|
||||
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||
SELECT DISTINCT cm.`company_id`, 14020, 1 FROM `org_company_menu` cm WHERE cm.`menu_id` IN (7, 14010);
|
||||
|
||||
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||
SELECT DISTINCT cm.`company_id`, 14021, 1 FROM `org_company_menu` cm WHERE cm.`menu_id` IN (7, 14010);
|
||||
|
||||
INSERT IGNORE INTO `org_company_permission` (`company_id`, `permission_id`)
|
||||
SELECT DISTINCT cm.`company_id`, p.`id`
|
||||
FROM `org_company_menu` cm
|
||||
JOIN `sys_permission` p ON p.`code` LIKE 'ec:warehouse:%' OR p.`code` LIKE 'ec:express-quote:%'
|
||||
WHERE cm.`menu_id` IN (7, 14010, 14020, 14021);
|
||||
|
||||
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||
SELECT pm.`position_id`, 14020 FROM `org_position_menu` pm WHERE pm.`menu_id` = 14010;
|
||||
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||
SELECT pm.`position_id`, 14021 FROM `org_position_menu` pm WHERE pm.`menu_id` = 14010;
|
||||
|
||||
INSERT IGNORE INTO `org_position_permission` (`position_id`, `permission_id`)
|
||||
SELECT DISTINCT pp.`position_id`, p.`id`
|
||||
FROM `org_position_permission` pp
|
||||
JOIN `sys_permission` shop ON shop.`id` = pp.`permission_id` AND shop.`code` LIKE 'ec:shop:%'
|
||||
JOIN `sys_permission` p ON p.`code` LIKE 'ec:warehouse:%' OR p.`code` LIKE 'ec:express-quote:%';
|
||||
+2
@@ -21,6 +21,8 @@ public class BiOrderStatDirtyDayPO {
|
||||
|
||||
public static final String REASON_COST = "COST";
|
||||
public static final String REASON_PRODUCT_DIM = "PRODUCT_DIM";
|
||||
/** 仓库快递报价 / 默认仓 / 计费重变更 */
|
||||
public static final String REASON_FREIGHT = "FREIGHT";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
+13
@@ -67,6 +67,19 @@ public class BiOrderStatDirtyDayService {
|
||||
Map.of("type", "COST_ADJUST", "skuId", skuId, "userId", userId != null ? userId : 0));
|
||||
}
|
||||
|
||||
/** 快递报价/默认仓/计费重变更:effectiveFrom~today 涉及该 SKU 的 (shop, day)。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markAfterFreightQuoteChange(Long companyId, Long skuId, LocalDate effectiveFrom, Long userId) {
|
||||
if (companyId == null || skuId == null || effectiveFrom == null) {
|
||||
return;
|
||||
}
|
||||
LocalDate today = LocalDate.now(ZONE);
|
||||
LocalDate dateFrom = effectiveFrom.isAfter(today) ? today : effectiveFrom;
|
||||
markForSkuDateRange(companyId, skuId, dateFrom, today,
|
||||
BiOrderStatDirtyDayPO.REASON_FREIGHT,
|
||||
Map.of("type", "FREIGHT_QUOTE", "skuId", skuId, "userId", userId != null ? userId : 0));
|
||||
}
|
||||
|
||||
/** SKU 迁品:effectiveFrom~today(最早下单日或 today)涉及该 SKU 的 (shop, day)。 */
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markAfterSkuMigrate(Long companyId, Long skuId, Long userId) {
|
||||
|
||||
+4
-1
@@ -214,6 +214,7 @@ public class OrderDailyStatComputeService {
|
||||
if (items.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
Map<Long, BigDecimal> freightByItem = orderItemCostResolver.freightByItemForOrder(order, items, stat);
|
||||
for (OrderItemPO item : items) {
|
||||
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||
long productId = productBySku.getOrDefault(skuId, 0L);
|
||||
@@ -221,7 +222,9 @@ public class OrderDailyStatComputeService {
|
||||
BigDecimal lineReceived = allocateLine(received, item, items);
|
||||
BigDecimal lineFee = deal ? allocateLine(fee, item, items) : BigDecimal.ZERO;
|
||||
BigDecimal linePc = lineProductCost(order, item, stat, unitCostBySku);
|
||||
BigDecimal lineFc = lineFreightCost(order, item, stat, unitCostBySku);
|
||||
BigDecimal lineFc = item.getId() != null
|
||||
? freightByItem.getOrDefault(item.getId(), BigDecimal.ZERO)
|
||||
: lineFreightCost(order, item, stat, unitCostBySku);
|
||||
BigDecimal lineOc = lineOtherCost(order, item, stat, unitCostBySku);
|
||||
|
||||
String pk = companyId + ":" + shopId + ":" + productId;
|
||||
|
||||
+22
-4
@@ -7,23 +7,26 @@ import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusStatSets;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.model.po.ProductSkuCostPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.FreightCostCalculator;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 订单明细成本:按 order_time 自然日从 SKU 成本主数据 as-of 解析,不读 ec_order_item 快照。
|
||||
* 订单明细成本:商品/其他 as-of 读 SKU 成本;运费优先按仓报价整包分摊,失败回退 shipping_cost。
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class OrderItemCostResolver {
|
||||
|
||||
private final ProductSkuCostService productSkuCostService;
|
||||
private final FreightCostCalculator freightCostCalculator;
|
||||
|
||||
/** 单笔订单行:按订单日取 SKU 成本。 */
|
||||
/** 单笔订单行:按订单日取 SKU 成本(不含算出运费)。 */
|
||||
public UnitCosts resolveUnitCosts(OrderPO order, OrderItemPO item) {
|
||||
LocalDate orderDate = order != null && order.getOrderTime() != null
|
||||
? order.getOrderTime().toLocalDate()
|
||||
@@ -60,12 +63,27 @@ public class OrderItemCostResolver {
|
||||
return c.productCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单行运费(会为整单再算一遍分摊;批算请用 {@link #freightByItemForOrder})。
|
||||
*/
|
||||
public BigDecimal freightCostForStats(OrderPO order, OrderItemPO item, OrderStatusStatSets stat) {
|
||||
if (!stat.includesFreightCost(order.getStatus())) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
UnitCosts c = resolveUnitCosts(order, item);
|
||||
return c.shippingCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
||||
if (item == null || item.getId() == null) {
|
||||
UnitCosts c = resolveUnitCosts(order, item);
|
||||
return c.shippingCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
||||
}
|
||||
Map<Long, BigDecimal> map = freightCostCalculator.allocateFreight(order, List.of(item));
|
||||
return map.getOrDefault(item.getId(), BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
/** 整单运费分摊:itemId → 金额。 */
|
||||
public Map<Long, BigDecimal> freightByItemForOrder(OrderPO order, List<OrderItemPO> items, OrderStatusStatSets stat) {
|
||||
if (order == null || !stat.includesFreightCost(order.getStatus())) {
|
||||
return Map.of();
|
||||
}
|
||||
return freightCostCalculator.allocateFreight(order, items);
|
||||
}
|
||||
|
||||
public BigDecimal otherCostForStats(OrderPO order, OrderItemPO item, OrderStatusStatSets stat) {
|
||||
|
||||
+4
-1
@@ -73,6 +73,7 @@ public class OrderStatContributionCalculator {
|
||||
Map<String, long[]> skuKeys = new HashMap<>();
|
||||
|
||||
Map<Long, Long> productBySku = loadProductBySku(safeItems);
|
||||
Map<Long, BigDecimal> freightByItem = orderItemCostResolver.freightByItemForOrder(order, safeItems, stat);
|
||||
|
||||
for (OrderItemPO item : safeItems) {
|
||||
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||
@@ -94,7 +95,9 @@ public class OrderStatContributionCalculator {
|
||||
pm.setRefundQuantitySum(nzi(pm.getRefundQuantitySum()) + qty);
|
||||
}
|
||||
BigDecimal pc = orderItemCostResolver.productCostForStats(order, item, stat);
|
||||
BigDecimal fc = orderItemCostResolver.freightCostForStats(order, item, stat);
|
||||
BigDecimal fc = item.getId() != null
|
||||
? freightByItem.getOrDefault(item.getId(), BigDecimal.ZERO)
|
||||
: orderItemCostResolver.freightCostForStats(order, item, stat);
|
||||
BigDecimal oc = orderItemCostResolver.otherCostForStats(order, item, stat);
|
||||
pm.setProductCost(nz(pm.getProductCost()).add(pc));
|
||||
pm.setFreightCost(nz(pm.getFreightCost()).add(fc));
|
||||
|
||||
+5
@@ -48,6 +48,11 @@ public class CreateProductDTO {
|
||||
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||
private Integer weightG;
|
||||
|
||||
private Integer lengthMm;
|
||||
private Integer widthMm;
|
||||
private Integer heightMm;
|
||||
private Long warehouseId;
|
||||
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
|
||||
+5
@@ -56,6 +56,11 @@ public class UpdateProductDTO {
|
||||
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||
private Integer weightG;
|
||||
|
||||
private Integer lengthMm;
|
||||
private Integer widthMm;
|
||||
private Integer heightMm;
|
||||
private Long warehouseId;
|
||||
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
|
||||
+16
@@ -138,6 +138,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
createDto.setName(specDTO.getName());
|
||||
createDto.setSkuCode(specDTO.getSkuCode());
|
||||
createDto.setWeightG(specDTO.getWeightG());
|
||||
createDto.setLengthMm(specDTO.getLengthMm());
|
||||
createDto.setWidthMm(specDTO.getWidthMm());
|
||||
createDto.setHeightMm(specDTO.getHeightMm());
|
||||
createDto.setWarehouseId(specDTO.getWarehouseId());
|
||||
createDto.setProductCost(specDTO.getProductCost());
|
||||
createDto.setShippingCost(specDTO.getShippingCost());
|
||||
createDto.setOtherCost(specDTO.getOtherCost());
|
||||
@@ -198,6 +202,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
createDto.setName(specDTO.getName());
|
||||
createDto.setSkuCode(specDTO.getSkuCode());
|
||||
createDto.setWeightG(specDTO.getWeightG());
|
||||
createDto.setLengthMm(specDTO.getLengthMm());
|
||||
createDto.setWidthMm(specDTO.getWidthMm());
|
||||
createDto.setHeightMm(specDTO.getHeightMm());
|
||||
createDto.setWarehouseId(specDTO.getWarehouseId());
|
||||
createDto.setProductCost(specDTO.getProductCost() != null ? specDTO.getProductCost() : java.math.BigDecimal.ZERO);
|
||||
createDto.setShippingCost(specDTO.getShippingCost());
|
||||
createDto.setOtherCost(specDTO.getOtherCost());
|
||||
@@ -330,6 +338,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
updateDto.setName(row.getName());
|
||||
updateDto.setSkuCode(row.getSkuCode());
|
||||
updateDto.setWeightG(row.getWeightG());
|
||||
updateDto.setLengthMm(row.getLengthMm());
|
||||
updateDto.setWidthMm(row.getWidthMm());
|
||||
updateDto.setHeightMm(row.getHeightMm());
|
||||
updateDto.setWarehouseId(row.getWarehouseId());
|
||||
updateDto.setRemark(row.getRemark());
|
||||
updateDto.setImageId(row.getImageId());
|
||||
productSkuService.updateProductSku(updateDto, row.getId());
|
||||
@@ -341,6 +353,10 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
createDto.setName(row.getName());
|
||||
createDto.setSkuCode(row.getSkuCode());
|
||||
createDto.setWeightG(row.getWeightG());
|
||||
createDto.setLengthMm(row.getLengthMm());
|
||||
createDto.setWidthMm(row.getWidthMm());
|
||||
createDto.setHeightMm(row.getHeightMm());
|
||||
createDto.setWarehouseId(row.getWarehouseId());
|
||||
createDto.setProductCost(row.getProductCost());
|
||||
createDto.setShippingCost(row.getShippingCost());
|
||||
createDto.setOtherCost(row.getOtherCost());
|
||||
|
||||
+5
@@ -27,6 +27,11 @@ public class CreateProductSkuDTO {
|
||||
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||
private Integer weightG;
|
||||
|
||||
private Integer lengthMm;
|
||||
private Integer widthMm;
|
||||
private Integer heightMm;
|
||||
private Long warehouseId;
|
||||
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
|
||||
+5
@@ -27,6 +27,11 @@ public class UpdateProductSkuDTO {
|
||||
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||
private Integer weightG;
|
||||
|
||||
private Integer lengthMm;
|
||||
private Integer widthMm;
|
||||
private Integer heightMm;
|
||||
private Long warehouseId;
|
||||
|
||||
private BigDecimal productCost;
|
||||
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
+13
@@ -36,6 +36,19 @@ public class ProductSkuPO {
|
||||
@TableField(value = "weight_g", updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Integer weightG;
|
||||
|
||||
@TableField(value = "length_mm", updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Integer lengthMm;
|
||||
|
||||
@TableField(value = "width_mm", updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Integer widthMm;
|
||||
|
||||
@TableField(value = "height_mm", updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Integer heightMm;
|
||||
|
||||
/** 默认发货仓;更新时允许置空 */
|
||||
@TableField(value = "warehouse_id", updateStrategy = FieldStrategy.ALWAYS)
|
||||
private Long warehouseId;
|
||||
|
||||
@TableField("attrs")
|
||||
private String attrs;
|
||||
|
||||
|
||||
+8
@@ -28,6 +28,14 @@ public class ProductSkuVO {
|
||||
/** 单件实重(克);空=未填 */
|
||||
private Integer weightG;
|
||||
|
||||
private Integer lengthMm;
|
||||
private Integer widthMm;
|
||||
private Integer heightMm;
|
||||
|
||||
/** 默认发货仓 */
|
||||
private Long warehouseId;
|
||||
private String warehouseName;
|
||||
|
||||
/** 空=遗留无结构 SKU */
|
||||
private String specCombinationKey;
|
||||
|
||||
|
||||
+20
-1
@@ -32,6 +32,8 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.impl.Produc
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.mapper.FakeOrdersFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.model.po.FakeOrdersFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
@@ -60,13 +62,15 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
private final ProductSkuCostMapper productSkuCostMapper;
|
||||
private final FakeOrdersFeeMapper fakeOrdersFeeMapper;
|
||||
private final SysFileMapper sysFileMapper;
|
||||
private final WarehouseMapper warehouseMapper;
|
||||
|
||||
public ProductSkuServiceImpl(CurrentUserContext currentUserContext, ProductService productService,
|
||||
ProductSkuCostService productSkuCostService, OrderMapper orderMapper,
|
||||
OrderItemMapper orderItemMapper,
|
||||
ProductSkuCostMapper productSkuCostMapper,
|
||||
FakeOrdersFeeMapper fakeOrdersFeeMapper,
|
||||
SysFileMapper sysFileMapper) {
|
||||
SysFileMapper sysFileMapper,
|
||||
WarehouseMapper warehouseMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.productService = productService;
|
||||
this.productSkuCostService = productSkuCostService;
|
||||
@@ -75,6 +79,7 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
this.productSkuCostMapper = productSkuCostMapper;
|
||||
this.fakeOrdersFeeMapper = fakeOrdersFeeMapper;
|
||||
this.sysFileMapper = sysFileMapper;
|
||||
this.warehouseMapper = warehouseMapper;
|
||||
}
|
||||
|
||||
/** SKU 落库后尝试挂 orphan 订单;订单表不存在时跳过 */
|
||||
@@ -140,6 +145,10 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
sku.setName(dto.getName());
|
||||
sku.setSkuCode(dto.getSkuCode());
|
||||
sku.setWeightG(dto.getWeightG());
|
||||
sku.setLengthMm(dto.getLengthMm());
|
||||
sku.setWidthMm(dto.getWidthMm());
|
||||
sku.setHeightMm(dto.getHeightMm());
|
||||
sku.setWarehouseId(dto.getWarehouseId());
|
||||
sku.setRemark(dto.getRemark());
|
||||
if (dto.getImageId() != null) {
|
||||
sku.setImageId(dto.getImageId());
|
||||
@@ -438,6 +447,10 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
byCode.setName(dto.getName());
|
||||
byCode.setSkuCode(trimmedCode);
|
||||
byCode.setWeightG(dto.getWeightG());
|
||||
byCode.setLengthMm(dto.getLengthMm());
|
||||
byCode.setWidthMm(dto.getWidthMm());
|
||||
byCode.setHeightMm(dto.getHeightMm());
|
||||
byCode.setWarehouseId(dto.getWarehouseId());
|
||||
byCode.setRemark(dto.getRemark());
|
||||
if (dto.getImageId() != null) {
|
||||
byCode.setImageId(dto.getImageId());
|
||||
@@ -593,6 +606,12 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
vo.setOtherCost(cost.getOtherCost());
|
||||
vo.setCostEffectiveFrom(cost.getEffectiveFrom());
|
||||
}
|
||||
if (sku.getWarehouseId() != null) {
|
||||
WarehousePO wh = warehouseMapper.selectById(sku.getWarehouseId());
|
||||
if (wh != null) {
|
||||
vo.setWarehouseName(wh.getName());
|
||||
}
|
||||
}
|
||||
// 有系统图 id 则覆盖外链
|
||||
if (sku.getImageId() != null) {
|
||||
SysFilePO file = sysFileMapper.selectById(sku.getImageId());
|
||||
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.ExpressQuoteService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** 快递报价单。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/express-quote")
|
||||
public class ExpressQuoteController {
|
||||
|
||||
private final ExpressQuoteService expressQuoteService;
|
||||
|
||||
public ExpressQuoteController(ExpressQuoteService expressQuoteService) {
|
||||
this.expressQuoteService = expressQuoteService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ec:express-quote:create", description = "创建报价", allowSuper = true)
|
||||
public ApiResponse<ExpressQuoteVO> create(@Valid @RequestBody ExpressQuoteDtos.Create dto) {
|
||||
return ApiResponse.success("创建成功", expressQuoteService.create(dto));
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ec:express-quote:update", description = "更新报价", allowSuper = true)
|
||||
public ApiResponse<ExpressQuoteVO> update(@Valid @RequestBody ExpressQuoteDtos.Update dto, @PathVariable Long id) {
|
||||
return ApiResponse.success("更新成功", expressQuoteService.update(dto, id));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ec:express-quote:delete", description = "删除报价", allowSuper = true)
|
||||
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||
expressQuoteService.delete(id);
|
||||
return ApiResponse.success("删除成功");
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ec:express-quote:read", description = "查询报价", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ExpressQuoteVO>> list(
|
||||
@Valid @RequestBody PageQueryDTO<ExpressQuoteDtos.Filter> query) {
|
||||
return ApiResponse.success("获取成功", expressQuoteService.page(query));
|
||||
}
|
||||
|
||||
@GetMapping("/enabled")
|
||||
@RequirePermission(value = "ec:express-quote:read", description = "启用报价列表", allowSuper = true)
|
||||
public ApiResponse<List<ExpressQuoteVO>> enabled() {
|
||||
return ApiResponse.success("获取成功", expressQuoteService.listEnabled());
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission(value = "ec:express-quote:read", description = "报价详情", allowSuper = true)
|
||||
public ApiResponse<ExpressQuoteVO> detail(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", expressQuoteService.detail(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{quoteId}/version")
|
||||
@RequirePermission(value = "ec:express-quote:update", description = "追加报价版本", allowSuper = true)
|
||||
public ApiResponse<ExpressQuoteVO.VersionVO> upsertVersion(
|
||||
@PathVariable Long quoteId,
|
||||
@Valid @RequestBody ExpressQuoteDtos.VersionUpsert dto) {
|
||||
return ApiResponse.success("版本保存成功", expressQuoteService.upsertVersion(quoteId, dto));
|
||||
}
|
||||
|
||||
@DeleteMapping("/version/{versionId}")
|
||||
@RequirePermission(value = "ec:express-quote:update", description = "删除报价版本", allowSuper = true)
|
||||
public ApiResponse<Void> deleteVersion(@PathVariable Long versionId) {
|
||||
expressQuoteService.deleteVersion(versionId);
|
||||
return ApiResponse.success("版本已删除");
|
||||
}
|
||||
|
||||
@GetMapping("/meta/carriers")
|
||||
@RequirePermission(value = "ec:express-quote:read", description = "承运商字典", allowSuper = true)
|
||||
public ApiResponse<List<Map<String, String>>> carriers() {
|
||||
return ApiResponse.success("获取成功", ExpressCarrierCodes.all());
|
||||
}
|
||||
|
||||
/** 标准省份全称列表(与 BiRegionNormalizer 对齐)。 */
|
||||
@GetMapping("/meta/provinces")
|
||||
@RequirePermission(value = "ec:express-quote:read", description = "省份字典", allowSuper = true)
|
||||
public ApiResponse<List<Map<String, String>>> provinces() {
|
||||
String[] fulls = {
|
||||
"北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省", "黑龙江省",
|
||||
"上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省",
|
||||
"湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省",
|
||||
"云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区",
|
||||
"台湾省", "香港特别行政区", "澳门特别行政区"
|
||||
};
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
for (String f : fulls) {
|
||||
Map<String, String> m = new LinkedHashMap<>();
|
||||
m.put("code", f);
|
||||
m.put("name", f);
|
||||
m.put("normalized", BiRegionNormalizer.normalize(f));
|
||||
list.add(m);
|
||||
}
|
||||
return ApiResponse.success("获取成功", list);
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.WarehouseService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 发货仓库与报价绑定。 */
|
||||
@RestController
|
||||
@RequestMapping("/api/ec/warehouse")
|
||||
public class WarehouseController {
|
||||
|
||||
private final WarehouseService warehouseService;
|
||||
|
||||
public WarehouseController(WarehouseService warehouseService) {
|
||||
this.warehouseService = warehouseService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ec:warehouse:create", description = "创建仓库", allowSuper = true)
|
||||
public ApiResponse<WarehouseVO> create(@Valid @RequestBody WarehouseDtos.Create dto) {
|
||||
return ApiResponse.success("仓库创建成功", warehouseService.create(dto));
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ec:warehouse:update", description = "更新仓库", allowSuper = true)
|
||||
public ApiResponse<WarehouseVO> update(@Valid @RequestBody WarehouseDtos.Update dto, @PathVariable Long id) {
|
||||
return ApiResponse.success("仓库更新成功", warehouseService.update(dto, id));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ec:warehouse:delete", description = "删除仓库", allowSuper = true)
|
||||
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||
warehouseService.delete(id);
|
||||
return ApiResponse.success("仓库删除成功");
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ec:warehouse:read", description = "查询仓库", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<WarehouseVO>> list(@Valid @RequestBody PageQueryDTO<WarehouseDtos.Filter> query) {
|
||||
return ApiResponse.success("获取成功", warehouseService.page(query));
|
||||
}
|
||||
|
||||
@GetMapping("/enabled")
|
||||
@RequirePermission(value = "ec:warehouse:read", description = "启用仓库列表", allowSuper = true)
|
||||
public ApiResponse<List<WarehouseVO>> enabled() {
|
||||
return ApiResponse.success("获取成功", warehouseService.listEnabled());
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission(value = "ec:warehouse:read", description = "仓库详情", allowSuper = true)
|
||||
public ApiResponse<WarehouseVO> detail(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", warehouseService.detail(id));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/binds")
|
||||
@RequirePermission(value = "ec:warehouse:read", description = "仓库报价绑定", allowSuper = true)
|
||||
public ApiResponse<List<WarehouseExpressBindVO>> binds(@PathVariable Long id) {
|
||||
return ApiResponse.success("获取成功", warehouseService.listBinds(id));
|
||||
}
|
||||
|
||||
@PostMapping("/bind")
|
||||
@RequirePermission(value = "ec:warehouse:update", description = "绑定报价", allowSuper = true)
|
||||
public ApiResponse<WarehouseExpressBindVO> addBind(@Valid @RequestBody WarehouseDtos.BindCreate dto) {
|
||||
return ApiResponse.success("绑定成功", warehouseService.addBind(dto));
|
||||
}
|
||||
|
||||
@PutMapping("/bind/{bindId}")
|
||||
@RequirePermission(value = "ec:warehouse:update", description = "更新绑定", allowSuper = true)
|
||||
public ApiResponse<WarehouseExpressBindVO> updateBind(@Valid @RequestBody WarehouseDtos.BindUpdate dto,
|
||||
@PathVariable Long bindId) {
|
||||
return ApiResponse.success("更新成功", warehouseService.updateBind(dto, bindId));
|
||||
}
|
||||
|
||||
@DeleteMapping("/bind/{bindId}")
|
||||
@RequirePermission(value = "ec:warehouse:update", description = "解除绑定", allowSuper = true)
|
||||
public ApiResponse<Void> removeBind(@PathVariable Long bindId) {
|
||||
warehouseService.removeBind(bindId);
|
||||
return ApiResponse.success("已解绑");
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** 承运商软编码字典(P2)。 */
|
||||
public final class ExpressCarrierCodes {
|
||||
|
||||
public static final String OTHER = "OTHER";
|
||||
|
||||
private static final List<Map<String, String>> ALL = List.of(
|
||||
Map.of("code", "ZTO", "name", "中通快递"),
|
||||
Map.of("code", "YTO", "name", "圆通速递"),
|
||||
Map.of("code", "STO", "name", "申通快递"),
|
||||
Map.of("code", "YD", "name", "韵达快递"),
|
||||
Map.of("code", "SF", "name", "顺丰速运"),
|
||||
Map.of("code", "JT", "name", "极兔速递"),
|
||||
Map.of("code", "EMS", "name", "邮政EMS"),
|
||||
Map.of("code", OTHER, "name", "其他")
|
||||
);
|
||||
|
||||
private ExpressCarrierCodes() {
|
||||
}
|
||||
|
||||
public static List<Map<String, String>> all() {
|
||||
return ALL;
|
||||
}
|
||||
|
||||
public static boolean isKnown(String code) {
|
||||
if (code == null || code.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
String c = code.trim().toUpperCase();
|
||||
return ALL.stream().anyMatch(m -> c.equals(m.get("code")));
|
||||
}
|
||||
|
||||
public static String normalizeCode(String code) {
|
||||
if (code == null || code.isBlank()) {
|
||||
return OTHER;
|
||||
}
|
||||
String c = code.trim().toUpperCase();
|
||||
return isKnown(c) ? c : OTHER;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressCarrierAliasMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressCarrierAliasPO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/** 将订单 logistics_id / 物流名归一为 carrier_code。 */
|
||||
@Component
|
||||
public class ExpressCarrierResolver {
|
||||
|
||||
private final ExpressCarrierAliasMapper aliasMapper;
|
||||
|
||||
public ExpressCarrierResolver(ExpressCarrierAliasMapper aliasMapper) {
|
||||
this.aliasMapper = aliasMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 归一承运商编码;无法识别返回 null(走 priority)
|
||||
*/
|
||||
public String resolve(Long companyId, String logisticsIdOrName) {
|
||||
if (!StringUtils.hasText(logisticsIdOrName)) {
|
||||
return null;
|
||||
}
|
||||
String raw = logisticsIdOrName.trim();
|
||||
String upper = raw.toUpperCase(Locale.ROOT);
|
||||
if (ExpressCarrierCodes.isKnown(upper)) {
|
||||
return upper;
|
||||
}
|
||||
// 公司覆盖优先,再全局
|
||||
List<ExpressCarrierAliasPO> aliases = aliasMapper.selectList(new LambdaQueryWrapper<ExpressCarrierAliasPO>()
|
||||
.and(w -> w.eq(ExpressCarrierAliasPO::getCompanyId, companyId)
|
||||
.or().isNull(ExpressCarrierAliasPO::getCompanyId)));
|
||||
ExpressCarrierAliasPO companyHit = null;
|
||||
ExpressCarrierAliasPO globalHit = null;
|
||||
for (ExpressCarrierAliasPO a : aliases) {
|
||||
if (a.getLogisticsPattern() == null) {
|
||||
continue;
|
||||
}
|
||||
if (!a.getLogisticsPattern().trim().equalsIgnoreCase(raw)
|
||||
&& !a.getLogisticsPattern().trim().equalsIgnoreCase(upper)) {
|
||||
continue;
|
||||
}
|
||||
if (a.getCompanyId() != null) {
|
||||
companyHit = a;
|
||||
} else {
|
||||
globalHit = a;
|
||||
}
|
||||
}
|
||||
ExpressCarrierAliasPO hit = companyHit != null ? companyHit : globalHit;
|
||||
return hit != null ? ExpressCarrierCodes.normalizeCode(hit.getCarrierCode()) : null;
|
||||
}
|
||||
}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusStatSets;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.model.po.ProductSkuCostPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteVersionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 订单运费:同仓整包计价后按行重量分摊;失败回退 SKU shipping_cost×qty。
|
||||
*/
|
||||
@Component
|
||||
public class FreightCostCalculator {
|
||||
|
||||
private final ProductSkuMapper productSkuMapper;
|
||||
private final ProductSkuCostService productSkuCostService;
|
||||
private final FreightQuoteResolver quoteResolver;
|
||||
private final ExpressCarrierResolver carrierResolver;
|
||||
private final WarehouseExpressBindMapper bindMapper;
|
||||
private final ExpressQuoteVersionMapper versionMapper;
|
||||
|
||||
public FreightCostCalculator(ProductSkuMapper productSkuMapper,
|
||||
ProductSkuCostService productSkuCostService,
|
||||
FreightQuoteResolver quoteResolver,
|
||||
ExpressCarrierResolver carrierResolver,
|
||||
WarehouseExpressBindMapper bindMapper,
|
||||
ExpressQuoteVersionMapper versionMapper) {
|
||||
this.productSkuMapper = productSkuMapper;
|
||||
this.productSkuCostService = productSkuCostService;
|
||||
this.quoteResolver = quoteResolver;
|
||||
this.carrierResolver = carrierResolver;
|
||||
this.bindMapper = bindMapper;
|
||||
this.versionMapper = versionMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return itemId → 行运费;无 itemId 的行用负数占位 key 不放入
|
||||
*/
|
||||
public Map<Long, BigDecimal> allocateFreight(OrderPO order, List<OrderItemPO> items) {
|
||||
Map<Long, BigDecimal> result = new HashMap<>();
|
||||
if (order == null || items == null || items.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
LocalDate onDate = order.getOrderTime() != null ? order.getOrderTime().toLocalDate() : LocalDate.now();
|
||||
String preferredCarrier = carrierResolver.resolve(order.getCompanyId(), order.getLogisticsId());
|
||||
|
||||
List<Long> skuIds = items.stream()
|
||||
.map(OrderItemPO::getProductSkuId)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(id -> id > 0)
|
||||
.distinct()
|
||||
.toList();
|
||||
Map<Long, ProductSkuPO> skuMap = new HashMap<>();
|
||||
if (!skuIds.isEmpty()) {
|
||||
for (ProductSkuPO sku : productSkuMapper.selectBatchIds(skuIds)) {
|
||||
skuMap.put(sku.getId(), sku);
|
||||
}
|
||||
}
|
||||
Map<Long, ProductSkuCostPO> costMap = productSkuCostService.getCostsAsOf(skuIds, onDate);
|
||||
|
||||
// warehouseId -> lines
|
||||
Map<Long, List<OrderItemPO>> byWarehouse = new HashMap<>();
|
||||
List<OrderItemPO> noWarehouse = new ArrayList<>();
|
||||
for (OrderItemPO item : items) {
|
||||
Long skuId = item.getProductSkuId();
|
||||
ProductSkuPO sku = skuId != null ? skuMap.get(skuId) : null;
|
||||
if (sku == null || sku.getWarehouseId() == null) {
|
||||
noWarehouse.add(item);
|
||||
} else {
|
||||
byWarehouse.computeIfAbsent(sku.getWarehouseId(), k -> new ArrayList<>()).add(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Long, List<OrderItemPO>> e : byWarehouse.entrySet()) {
|
||||
Long warehouseId = e.getKey();
|
||||
List<OrderItemPO> group = e.getValue();
|
||||
int pieceCount = 0;
|
||||
int actualG = 0;
|
||||
int volumetricG = 0;
|
||||
Map<Long, Integer> lineWeight = new HashMap<>();
|
||||
boolean useVolumetric = isUseVolumetric(warehouseId, onDate);
|
||||
|
||||
for (OrderItemPO item : group) {
|
||||
int qty = OrderStatusStatSets.quantity(item);
|
||||
pieceCount += qty;
|
||||
ProductSkuPO sku = skuMap.get(item.getProductSkuId());
|
||||
int unitActual = sku != null && sku.getWeightG() != null ? sku.getWeightG() : 0;
|
||||
int unitVol = 0;
|
||||
if (useVolumetric && sku != null) {
|
||||
Integer divisor = resolveVolumeDivisor(warehouseId, onDate);
|
||||
unitVol = FreightQuoteResolver.volumetricWeightG(
|
||||
sku.getLengthMm(), sku.getWidthMm(), sku.getHeightMm(), divisor);
|
||||
}
|
||||
int unitCharge = FreightQuoteResolver.chargeableWeightG(unitActual, unitVol, useVolumetric);
|
||||
int lineG = unitCharge * qty;
|
||||
if (item.getId() != null) {
|
||||
lineWeight.put(item.getId(), lineG);
|
||||
}
|
||||
actualG += unitActual * qty;
|
||||
volumetricG += unitVol * qty;
|
||||
}
|
||||
int chargeG = FreightQuoteResolver.chargeableWeightG(actualG, volumetricG, useVolumetric);
|
||||
Optional<BigDecimal> packageFreight = quoteResolver.resolveAmount(
|
||||
warehouseId, onDate, order.getProvince(), chargeG, pieceCount, preferredCarrier);
|
||||
|
||||
if (packageFreight.isPresent() && chargeG > 0) {
|
||||
allocateByWeight(result, group, lineWeight, packageFreight.get(), costMap, onDate);
|
||||
} else {
|
||||
fallbackManual(result, group, costMap);
|
||||
}
|
||||
}
|
||||
|
||||
fallbackManual(result, noWarehouse, costMap);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void allocateByWeight(Map<Long, BigDecimal> result, List<OrderItemPO> group,
|
||||
Map<Long, Integer> lineWeight, BigDecimal packageFreight,
|
||||
Map<Long, ProductSkuCostPO> costMap, LocalDate onDate) {
|
||||
int totalW = lineWeight.values().stream().mapToInt(Integer::intValue).sum();
|
||||
if (totalW <= 0) {
|
||||
fallbackManual(result, group, costMap);
|
||||
return;
|
||||
}
|
||||
BigDecimal allocated = BigDecimal.ZERO;
|
||||
for (int i = 0; i < group.size(); i++) {
|
||||
OrderItemPO item = group.get(i);
|
||||
if (item.getId() == null) {
|
||||
continue;
|
||||
}
|
||||
int w = lineWeight.getOrDefault(item.getId(), 0);
|
||||
BigDecimal share;
|
||||
if (i == group.size() - 1) {
|
||||
share = packageFreight.subtract(allocated);
|
||||
} else {
|
||||
share = packageFreight.multiply(BigDecimal.valueOf(w))
|
||||
.divide(BigDecimal.valueOf(totalW), 2, RoundingMode.HALF_UP);
|
||||
allocated = allocated.add(share);
|
||||
}
|
||||
result.put(item.getId(), share.max(BigDecimal.ZERO));
|
||||
}
|
||||
}
|
||||
|
||||
private void fallbackManual(Map<Long, BigDecimal> result, List<OrderItemPO> items,
|
||||
Map<Long, ProductSkuCostPO> costMap) {
|
||||
for (OrderItemPO item : items) {
|
||||
if (item.getId() == null || result.containsKey(item.getId())) {
|
||||
continue;
|
||||
}
|
||||
Long skuId = item.getProductSkuId();
|
||||
ProductSkuCostPO cost = skuId != null ? costMap.get(skuId) : null;
|
||||
BigDecimal unit = cost != null && cost.getShippingCost() != null
|
||||
? cost.getShippingCost() : BigDecimal.ZERO;
|
||||
result.put(item.getId(), unit.multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item))));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUseVolumetric(Long warehouseId, LocalDate onDate) {
|
||||
WarehouseExpressBindPO first = firstBind(warehouseId);
|
||||
if (first == null) {
|
||||
return false;
|
||||
}
|
||||
ExpressQuoteVersionPO v = versionAsOf(first.getQuoteId(), onDate);
|
||||
return v != null && v.getUseVolumetric() != null && v.getUseVolumetric() == 1;
|
||||
}
|
||||
|
||||
private Integer resolveVolumeDivisor(Long warehouseId, LocalDate onDate) {
|
||||
WarehouseExpressBindPO first = firstBind(warehouseId);
|
||||
if (first == null) {
|
||||
return 6000;
|
||||
}
|
||||
ExpressQuoteVersionPO v = versionAsOf(first.getQuoteId(), onDate);
|
||||
return v != null && v.getVolumeDivisor() != null ? v.getVolumeDivisor() : 6000;
|
||||
}
|
||||
|
||||
private WarehouseExpressBindPO firstBind(Long warehouseId) {
|
||||
return bindMapper.selectOne(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseExpressBindPO::getStatus, 1)
|
||||
.orderByAsc(WarehouseExpressBindPO::getPriority)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
private ExpressQuoteVersionPO versionAsOf(Long quoteId, LocalDate onDate) {
|
||||
return versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, quoteId)
|
||||
.le(ExpressQuoteVersionPO::getEffectiveFrom, onDate)
|
||||
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteRegionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteTierMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteVersionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteRegionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteTierPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 按仓 + 日期 + 省 + 计费重 + 可选承运商选价。
|
||||
* 策略:PRIORITY;有 carrier 时将该 carrier 的 bind 提到最前。
|
||||
*/
|
||||
@Component
|
||||
public class FreightQuoteResolver {
|
||||
|
||||
private final WarehouseExpressBindMapper bindMapper;
|
||||
private final ExpressQuoteMapper quoteMapper;
|
||||
private final ExpressQuoteVersionMapper versionMapper;
|
||||
private final ExpressQuoteRegionMapper regionMapper;
|
||||
private final ExpressQuoteTierMapper tierMapper;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public FreightQuoteResolver(WarehouseExpressBindMapper bindMapper,
|
||||
ExpressQuoteMapper quoteMapper,
|
||||
ExpressQuoteVersionMapper versionMapper,
|
||||
ExpressQuoteRegionMapper regionMapper,
|
||||
ExpressQuoteTierMapper tierMapper,
|
||||
ObjectMapper objectMapper) {
|
||||
this.bindMapper = bindMapper;
|
||||
this.quoteMapper = quoteMapper;
|
||||
this.versionMapper = versionMapper;
|
||||
this.regionMapper = regionMapper;
|
||||
this.tierMapper = tierMapper;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param chargeableWeightG 计费重(克,已含体积重取大)
|
||||
* @param pieceCount 件数(FLAT/PIECE 用)
|
||||
* @return 运费金额;无法计价返回 empty
|
||||
*/
|
||||
public Optional<BigDecimal> resolveAmount(Long warehouseId, LocalDate onDate, String province,
|
||||
int chargeableWeightG, int pieceCount, String preferredCarrier) {
|
||||
if (warehouseId == null || onDate == null || chargeableWeightG <= 0) {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getWarehouseId, warehouseId)
|
||||
.eq(WarehouseExpressBindPO::getStatus, 1));
|
||||
if (binds.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
binds.sort(Comparator
|
||||
.comparing((WarehouseExpressBindPO b) -> b.getPriority() != null ? b.getPriority() : 100)
|
||||
.thenComparing(WarehouseExpressBindPO::getId));
|
||||
|
||||
List<WarehouseExpressBindPO> ordered = new ArrayList<>(binds);
|
||||
if (StringUtils.hasText(preferredCarrier)) {
|
||||
String carrier = preferredCarrier.trim().toUpperCase();
|
||||
List<WarehouseExpressBindPO> matched = new ArrayList<>();
|
||||
List<WarehouseExpressBindPO> rest = new ArrayList<>();
|
||||
for (WarehouseExpressBindPO b : ordered) {
|
||||
ExpressQuotePO q = quoteMapper.selectById(b.getQuoteId());
|
||||
if (q != null && q.getStatus() != null && q.getStatus() == 1
|
||||
&& carrier.equalsIgnoreCase(q.getCarrierCode())) {
|
||||
matched.add(b);
|
||||
} else {
|
||||
rest.add(b);
|
||||
}
|
||||
}
|
||||
ordered = new ArrayList<>();
|
||||
ordered.addAll(matched);
|
||||
ordered.addAll(rest);
|
||||
}
|
||||
|
||||
String provinceFull = BiRegionNormalizer.normalize(province);
|
||||
for (WarehouseExpressBindPO bind : ordered) {
|
||||
ExpressQuotePO quote = quoteMapper.selectById(bind.getQuoteId());
|
||||
if (quote == null || quote.getStatus() == null || quote.getStatus() != 1) {
|
||||
continue;
|
||||
}
|
||||
ExpressQuoteVersionPO version = versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, quote.getId())
|
||||
.le(ExpressQuoteVersionPO::getEffectiveFrom, onDate)
|
||||
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||
.last("LIMIT 1"));
|
||||
if (version == null) {
|
||||
continue;
|
||||
}
|
||||
Optional<BigDecimal> amount = price(quote, version, provinceFull, chargeableWeightG, pieceCount);
|
||||
if (amount.isPresent()) {
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<BigDecimal> price(ExpressQuotePO quote, ExpressQuoteVersionPO version,
|
||||
String provinceFull, int weightG, int pieceCount) {
|
||||
String mode = quote.getBillingMode();
|
||||
if (ExpressQuotePO.MODE_FLAT.equals(mode)) {
|
||||
if (version.getFlatAmount() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
if (ExpressQuoteVersionPO.SCOPE_ORDER.equalsIgnoreCase(version.getUnitScope())) {
|
||||
return Optional.of(version.getFlatAmount());
|
||||
}
|
||||
if (ExpressQuoteVersionPO.SCOPE_PIECE.equalsIgnoreCase(version.getUnitScope())) {
|
||||
int pcs = Math.max(pieceCount, 1);
|
||||
return Optional.of(version.getFlatAmount().multiply(BigDecimal.valueOf(pcs)));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
if (ExpressQuotePO.MODE_PER_KG.equals(mode)) {
|
||||
if (version.getPricePerKg() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
BigDecimal kg = BigDecimal.valueOf(weightG).divide(BigDecimal.valueOf(1000), 3, RoundingMode.CEILING);
|
||||
BigDecimal amount = kg.multiply(version.getPricePerKg()).setScale(2, RoundingMode.HALF_UP);
|
||||
if (version.getMinAmount() != null && amount.compareTo(version.getMinAmount()) < 0) {
|
||||
amount = version.getMinAmount();
|
||||
}
|
||||
return Optional.of(amount);
|
||||
}
|
||||
if (ExpressQuotePO.MODE_REGION_WEIGHT.equals(mode)) {
|
||||
return priceRegionWeight(version, provinceFull, weightG);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<BigDecimal> priceRegionWeight(ExpressQuoteVersionPO version, String provinceFull, int weightG) {
|
||||
List<ExpressQuoteRegionPO> regions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, version.getId())
|
||||
.orderByAsc(ExpressQuoteRegionPO::getSortOrder));
|
||||
ExpressQuoteRegionPO hit = null;
|
||||
ExpressQuoteRegionPO defaultRegion = null;
|
||||
for (ExpressQuoteRegionPO r : regions) {
|
||||
if (r.getIsDefault() != null && r.getIsDefault() == 1) {
|
||||
defaultRegion = r;
|
||||
}
|
||||
if (provinceContains(r.getProvincesJson(), provinceFull)) {
|
||||
hit = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hit == null) {
|
||||
hit = defaultRegion;
|
||||
}
|
||||
if (hit == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ExpressQuoteTierPO tier = tierMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteTierPO>()
|
||||
.eq(ExpressQuoteTierPO::getRegionId, hit.getId())
|
||||
.last("LIMIT 1"));
|
||||
if (tier == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
int firstG = tier.getFirstWeightG() != null && tier.getFirstWeightG() > 0 ? tier.getFirstWeightG() : 1000;
|
||||
int addG = tier.getAdditionalWeightG() != null && tier.getAdditionalWeightG() > 0
|
||||
? tier.getAdditionalWeightG() : 1000;
|
||||
BigDecimal firstAmt = nz(tier.getFirstAmount());
|
||||
BigDecimal addAmt = nz(tier.getAdditionalAmount());
|
||||
if (weightG <= firstG) {
|
||||
return Optional.of(firstAmt);
|
||||
}
|
||||
int remain = weightG - firstG;
|
||||
int steps = (remain + addG - 1) / addG;
|
||||
return Optional.of(firstAmt.add(addAmt.multiply(BigDecimal.valueOf(steps))).setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
|
||||
private boolean provinceContains(String provincesJson, String provinceFull) {
|
||||
if (!StringUtils.hasText(provincesJson) || BiRegionNormalizer.isUnknown(provinceFull)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
List<String> list = objectMapper.readValue(provincesJson, new TypeReference<>() {
|
||||
});
|
||||
return list.stream().anyMatch(p -> Objects.equals(p, provinceFull));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 体积重(克):长宽高 mm,divisor 默认 6000 → kg = L*W*H/divisor,再 ×1000。
|
||||
*/
|
||||
public static int volumetricWeightG(Integer lengthMm, Integer widthMm, Integer heightMm, Integer divisor) {
|
||||
if (lengthMm == null || widthMm == null || heightMm == null
|
||||
|| lengthMm <= 0 || widthMm <= 0 || heightMm <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int d = divisor != null && divisor > 0 ? divisor : 6000;
|
||||
long volume = (long) lengthMm * widthMm * heightMm;
|
||||
// kg = volume / d;g = kg * 1000 = volume * 1000 / d
|
||||
return (int) Math.ceil(volume * 1000.0 / d);
|
||||
}
|
||||
|
||||
public static int chargeableWeightG(int actualG, int volumetricG, boolean useVolumetric) {
|
||||
if (!useVolumetric || volumetricG <= 0) {
|
||||
return Math.max(actualG, 0);
|
||||
}
|
||||
return Math.max(actualG, volumetricG);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressCarrierAliasPO;
|
||||
|
||||
/** ExpressCarrierAlias Mapper */
|
||||
@Mapper
|
||||
public interface ExpressCarrierAliasMapper extends BaseMapper<ExpressCarrierAliasPO> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||
|
||||
/** ExpressQuote Mapper */
|
||||
@Mapper
|
||||
public interface ExpressQuoteMapper extends BaseMapper<ExpressQuotePO> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteRegionPO;
|
||||
|
||||
/** ExpressQuoteRegion Mapper */
|
||||
@Mapper
|
||||
public interface ExpressQuoteRegionMapper extends BaseMapper<ExpressQuoteRegionPO> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteTierPO;
|
||||
|
||||
/** ExpressQuoteTier Mapper */
|
||||
@Mapper
|
||||
public interface ExpressQuoteTierMapper extends BaseMapper<ExpressQuoteTierPO> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||
|
||||
/** ExpressQuoteVersion Mapper */
|
||||
@Mapper
|
||||
public interface ExpressQuoteVersionMapper extends BaseMapper<ExpressQuoteVersionPO> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||
|
||||
/** WarehouseExpressBind Mapper */
|
||||
@Mapper
|
||||
public interface WarehouseExpressBindMapper extends BaseMapper<WarehouseExpressBindPO> {
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||
|
||||
/** Warehouse Mapper */
|
||||
@Mapper
|
||||
public interface WarehouseMapper extends BaseMapper<WarehousePO> {
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/** 快递报价 DTO。 */
|
||||
public final class ExpressQuoteDtos {
|
||||
|
||||
private ExpressQuoteDtos() {
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Create {
|
||||
@NotBlank(message = "报价编码不能为空")
|
||||
private String code;
|
||||
@NotBlank(message = "报价名称不能为空")
|
||||
private String name;
|
||||
@NotBlank(message = "承运商不能为空")
|
||||
private String carrierCode;
|
||||
@NotBlank(message = "计费模式不能为空")
|
||||
private String billingMode;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
/** 创建时可顺带写入首个版本 */
|
||||
@Valid
|
||||
private VersionUpsert initialVersion;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Update {
|
||||
@NotBlank(message = "报价名称不能为空")
|
||||
private String name;
|
||||
@NotBlank(message = "承运商不能为空")
|
||||
private String carrierCode;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Filter {
|
||||
private String keywords;
|
||||
private String carrierCode;
|
||||
private String billingMode;
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class VersionUpsert {
|
||||
@NotNull(message = "生效日不能为空")
|
||||
private LocalDate effectiveFrom;
|
||||
private BigDecimal flatAmount;
|
||||
private String unitScope;
|
||||
private BigDecimal pricePerKg;
|
||||
private BigDecimal minAmount;
|
||||
private Integer volumeDivisor;
|
||||
private Integer useVolumetric;
|
||||
private String remark;
|
||||
@Valid
|
||||
private List<RegionUpsert> regions;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class RegionUpsert {
|
||||
@NotBlank(message = "分区名不能为空")
|
||||
private String regionName;
|
||||
/** 省份全称列表 */
|
||||
private List<String> provinces;
|
||||
private Integer isDefault;
|
||||
private Integer sortOrder;
|
||||
private Integer firstWeightG;
|
||||
private BigDecimal firstAmount;
|
||||
private Integer additionalWeightG;
|
||||
private BigDecimal additionalAmount;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/** 仓库相关 DTO。 */
|
||||
public final class WarehouseDtos {
|
||||
|
||||
private WarehouseDtos() {
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Create {
|
||||
@NotBlank(message = "仓库编码不能为空")
|
||||
private String code;
|
||||
@NotBlank(message = "仓库名称不能为空")
|
||||
private String name;
|
||||
private String province;
|
||||
private String city;
|
||||
private String address;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Update {
|
||||
@NotBlank(message = "仓库名称不能为空")
|
||||
private String name;
|
||||
private String province;
|
||||
private String city;
|
||||
private String address;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Filter {
|
||||
private String keywords;
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class BindCreate {
|
||||
@NotNull(message = "仓库不能为空")
|
||||
private Long warehouseId;
|
||||
@NotNull(message = "报价单不能为空")
|
||||
private Long quoteId;
|
||||
private Integer priority;
|
||||
private Integer status;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class BindUpdate {
|
||||
private Integer priority;
|
||||
private Integer status;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 物流标识 → 承运商编码。 */
|
||||
@Data
|
||||
@TableName("ec_express_carrier_alias")
|
||||
public class ExpressCarrierAliasPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("logistics_pattern")
|
||||
private String logisticsPattern;
|
||||
|
||||
@TableField("carrier_code")
|
||||
private String carrierCode;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 快递报价单(公司级)。 */
|
||||
@Data
|
||||
@TableName("ec_express_quote")
|
||||
public class ExpressQuotePO {
|
||||
|
||||
public static final String MODE_FLAT = "FLAT";
|
||||
public static final String MODE_PER_KG = "PER_KG";
|
||||
public static final String MODE_REGION_WEIGHT = "REGION_WEIGHT";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("code")
|
||||
private String code;
|
||||
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField("carrier_code")
|
||||
private String carrierCode;
|
||||
|
||||
@TableField("billing_mode")
|
||||
private String billingMode;
|
||||
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 报价分区(省份列表 JSON)。 */
|
||||
@Data
|
||||
@TableName("ec_express_quote_region")
|
||||
public class ExpressQuoteRegionPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("version_id")
|
||||
private Long versionId;
|
||||
|
||||
@TableField("region_name")
|
||||
private String regionName;
|
||||
|
||||
/** JSON 数组字符串 */
|
||||
@TableField("provinces_json")
|
||||
private String provincesJson;
|
||||
|
||||
@TableField("is_default")
|
||||
private Integer isDefault;
|
||||
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 分区首重/续重。 */
|
||||
@Data
|
||||
@TableName("ec_express_quote_tier")
|
||||
public class ExpressQuoteTierPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("version_id")
|
||||
private Long versionId;
|
||||
|
||||
@TableField("region_id")
|
||||
private Long regionId;
|
||||
|
||||
@TableField("first_weight_g")
|
||||
private Integer firstWeightG;
|
||||
|
||||
@TableField("first_amount")
|
||||
private BigDecimal firstAmount;
|
||||
|
||||
@TableField("additional_weight_g")
|
||||
private Integer additionalWeightG;
|
||||
|
||||
@TableField("additional_amount")
|
||||
private BigDecimal additionalAmount;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 报价版本(as-of)。 */
|
||||
@Data
|
||||
@TableName("ec_express_quote_version")
|
||||
public class ExpressQuoteVersionPO {
|
||||
|
||||
public static final String SCOPE_ORDER = "ORDER";
|
||||
public static final String SCOPE_PIECE = "PIECE";
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("quote_id")
|
||||
private Long quoteId;
|
||||
|
||||
@TableField("effective_from")
|
||||
private LocalDate effectiveFrom;
|
||||
|
||||
@TableField("flat_amount")
|
||||
private BigDecimal flatAmount;
|
||||
|
||||
@TableField("unit_scope")
|
||||
private String unitScope;
|
||||
|
||||
@TableField("price_per_kg")
|
||||
private BigDecimal pricePerKg;
|
||||
|
||||
@TableField("min_amount")
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 体积重:mm³ / divisor → kg,再 ×1000 得克 */
|
||||
@TableField("volume_divisor")
|
||||
private Integer volumeDivisor;
|
||||
|
||||
@TableField("use_volumetric")
|
||||
private Integer useVolumetric;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 仓 ↔ 报价绑定。 */
|
||||
@Data
|
||||
@TableName("ec_warehouse_express_bind")
|
||||
public class WarehouseExpressBindPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("warehouse_id")
|
||||
private Long warehouseId;
|
||||
|
||||
@TableField("quote_id")
|
||||
private Long quoteId;
|
||||
|
||||
@TableField("priority")
|
||||
private Integer priority;
|
||||
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 发货仓库(无库存)。 */
|
||||
@Data
|
||||
@TableName("ec_warehouse")
|
||||
public class WarehousePO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("code")
|
||||
private String code;
|
||||
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@TableField("province")
|
||||
private String province;
|
||||
|
||||
@TableField("city")
|
||||
private String city;
|
||||
|
||||
@TableField("address")
|
||||
private String address;
|
||||
|
||||
/** 0停用 1启用 */
|
||||
@TableField("status")
|
||||
private Integer status;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** 快递报价 VO。 */
|
||||
@Data
|
||||
public class ExpressQuoteVO {
|
||||
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private String code;
|
||||
private String name;
|
||||
private String carrierCode;
|
||||
private String billingMode;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
/** 当前生效版本(最大 effective_from)摘要 */
|
||||
private VersionVO currentVersion;
|
||||
private List<VersionVO> versions;
|
||||
|
||||
@Data
|
||||
public static class VersionVO {
|
||||
private Long id;
|
||||
private Long quoteId;
|
||||
private LocalDate effectiveFrom;
|
||||
private BigDecimal flatAmount;
|
||||
private String unitScope;
|
||||
private BigDecimal pricePerKg;
|
||||
private BigDecimal minAmount;
|
||||
private Integer volumeDivisor;
|
||||
private Integer useVolumetric;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private List<RegionVO> regions;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class RegionVO {
|
||||
private Long id;
|
||||
private String regionName;
|
||||
private List<String> provinces;
|
||||
private Integer isDefault;
|
||||
private Integer sortOrder;
|
||||
private Integer firstWeightG;
|
||||
private BigDecimal firstAmount;
|
||||
private Integer additionalWeightG;
|
||||
private BigDecimal additionalAmount;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/** 仓-报价绑定 VO。 */
|
||||
@Data
|
||||
public class WarehouseExpressBindVO {
|
||||
|
||||
private Long id;
|
||||
private Long warehouseId;
|
||||
private Long quoteId;
|
||||
private String quoteName;
|
||||
private String quoteCode;
|
||||
private String carrierCode;
|
||||
private String billingMode;
|
||||
private Integer priority;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/** 仓库 VO。 */
|
||||
@Data
|
||||
public class WarehouseVO {
|
||||
|
||||
private Long id;
|
||||
private Long companyId;
|
||||
private String code;
|
||||
private String name;
|
||||
private String province;
|
||||
private String city;
|
||||
private String address;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
/** 已绑定报价数 */
|
||||
private Integer bindCount;
|
||||
private List<WarehouseExpressBindVO> binds;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 快递报价单与版本。 */
|
||||
public interface ExpressQuoteService {
|
||||
|
||||
ExpressQuoteVO create(ExpressQuoteDtos.Create dto);
|
||||
|
||||
ExpressQuoteVO update(ExpressQuoteDtos.Update dto, Long id);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
PageResultVO<ExpressQuoteVO> page(PageQueryDTO<ExpressQuoteDtos.Filter> query);
|
||||
|
||||
List<ExpressQuoteVO> listEnabled();
|
||||
|
||||
ExpressQuoteVO detail(Long id);
|
||||
|
||||
ExpressQuotePO requireCompanyQuote(Long id);
|
||||
|
||||
/** 追加或覆盖同日版本(含分区阶梯)。 */
|
||||
ExpressQuoteVO.VersionVO upsertVersion(Long quoteId, ExpressQuoteDtos.VersionUpsert dto);
|
||||
|
||||
void deleteVersion(Long versionId);
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** 发货仓库与报价绑定。 */
|
||||
public interface WarehouseService {
|
||||
|
||||
WarehouseVO create(WarehouseDtos.Create dto);
|
||||
|
||||
WarehouseVO update(WarehouseDtos.Update dto, Long id);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
PageResultVO<WarehouseVO> page(PageQueryDTO<WarehouseDtos.Filter> query);
|
||||
|
||||
List<WarehouseVO> listEnabled();
|
||||
|
||||
WarehouseVO detail(Long id);
|
||||
|
||||
WarehousePO requireCompanyWarehouse(Long id);
|
||||
|
||||
WarehouseExpressBindVO addBind(WarehouseDtos.BindCreate dto);
|
||||
|
||||
WarehouseExpressBindVO updateBind(WarehouseDtos.BindUpdate dto, Long bindId);
|
||||
|
||||
void removeBind(Long bindId);
|
||||
|
||||
List<WarehouseExpressBindVO> listBinds(Long warehouseId);
|
||||
}
|
||||
+454
@@ -0,0 +1,454 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatDirtyDayService;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteRegionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteTierMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteVersionMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteRegionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteTierPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.ExpressQuoteService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** 快递报价单与版本编排。 */
|
||||
@Service
|
||||
public class ExpressQuoteServiceImpl extends ServiceImpl<ExpressQuoteMapper, ExpressQuotePO>
|
||||
implements ExpressQuoteService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ExpressQuoteVersionMapper versionMapper;
|
||||
private final ExpressQuoteRegionMapper regionMapper;
|
||||
private final ExpressQuoteTierMapper tierMapper;
|
||||
private final WarehouseExpressBindMapper bindMapper;
|
||||
private final ProductSkuMapper productSkuMapper;
|
||||
private final BiOrderStatDirtyDayService dirtyDayService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public ExpressQuoteServiceImpl(CurrentUserContext currentUserContext,
|
||||
ExpressQuoteVersionMapper versionMapper,
|
||||
ExpressQuoteRegionMapper regionMapper,
|
||||
ExpressQuoteTierMapper tierMapper,
|
||||
WarehouseExpressBindMapper bindMapper,
|
||||
ProductSkuMapper productSkuMapper,
|
||||
BiOrderStatDirtyDayService dirtyDayService,
|
||||
ObjectMapper objectMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.versionMapper = versionMapper;
|
||||
this.regionMapper = regionMapper;
|
||||
this.tierMapper = tierMapper;
|
||||
this.bindMapper = bindMapper;
|
||||
this.productSkuMapper = productSkuMapper;
|
||||
this.dirtyDayService = dirtyDayService;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExpressQuoteVO create(ExpressQuoteDtos.Create dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
assertCodeUnique(companyId, dto.getCode().trim(), null);
|
||||
validateMode(dto.getBillingMode());
|
||||
ExpressQuotePO po = new ExpressQuotePO();
|
||||
po.setCompanyId(companyId);
|
||||
po.setCode(dto.getCode().trim());
|
||||
po.setName(dto.getName().trim());
|
||||
po.setCarrierCode(ExpressCarrierCodes.normalizeCode(dto.getCarrierCode()));
|
||||
po.setBillingMode(dto.getBillingMode().trim().toUpperCase());
|
||||
po.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
|
||||
po.setRemark(dto.getRemark());
|
||||
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
save(po);
|
||||
if (dto.getInitialVersion() != null) {
|
||||
upsertVersionInternal(po, dto.getInitialVersion());
|
||||
}
|
||||
return detail(po.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExpressQuoteVO update(ExpressQuoteDtos.Update dto, Long id) {
|
||||
ExpressQuotePO po = requireCompanyQuote(id);
|
||||
po.setName(dto.getName().trim());
|
||||
po.setCarrierCode(ExpressCarrierCodes.normalizeCode(dto.getCarrierCode()));
|
||||
if (dto.getStatus() != null) {
|
||||
po.setStatus(dto.getStatus());
|
||||
}
|
||||
po.setRemark(dto.getRemark());
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
updateById(po);
|
||||
markDirtyForQuote(po.getId(), null);
|
||||
return detail(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
ExpressQuotePO po = requireCompanyQuote(id);
|
||||
Long bindCount = bindMapper.selectCount(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getQuoteId, id));
|
||||
if (bindCount != null && bindCount > 0) {
|
||||
throw new BusinessException("仍有仓库绑定此报价,请先解绑");
|
||||
}
|
||||
List<ExpressQuoteVersionPO> versions = versionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, id));
|
||||
for (ExpressQuoteVersionPO v : versions) {
|
||||
deleteVersionCascade(v.getId());
|
||||
}
|
||||
removeById(po.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<ExpressQuoteVO> page(PageQueryDTO<ExpressQuoteDtos.Filter> query) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<ExpressQuotePO> w = new LambdaQueryWrapper<ExpressQuotePO>()
|
||||
.eq(ExpressQuotePO::getCompanyId, companyId);
|
||||
ExpressQuoteDtos.Filter f = query.getFilters();
|
||||
if (f != null) {
|
||||
if (StringUtils.hasText(f.getKeywords())) {
|
||||
String kw = f.getKeywords().trim();
|
||||
w.and(x -> x.like(ExpressQuotePO::getName, kw).or().like(ExpressQuotePO::getCode, kw));
|
||||
}
|
||||
if (StringUtils.hasText(f.getCarrierCode())) {
|
||||
w.eq(ExpressQuotePO::getCarrierCode, f.getCarrierCode().trim().toUpperCase());
|
||||
}
|
||||
if (StringUtils.hasText(f.getBillingMode())) {
|
||||
w.eq(ExpressQuotePO::getBillingMode, f.getBillingMode().trim().toUpperCase());
|
||||
}
|
||||
if (f.getStatus() != null) {
|
||||
w.eq(ExpressQuotePO::getStatus, f.getStatus());
|
||||
}
|
||||
}
|
||||
w.orderByDesc(ExpressQuotePO::getId);
|
||||
Page<ExpressQuotePO> page = page(new Page<>(query.getPage(), query.getPageSize()), w);
|
||||
List<ExpressQuoteVO> records = page.getRecords().stream().map(p -> toBriefVo(p)).toList();
|
||||
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExpressQuoteVO> listEnabled() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
return list(new LambdaQueryWrapper<ExpressQuotePO>()
|
||||
.eq(ExpressQuotePO::getCompanyId, companyId)
|
||||
.eq(ExpressQuotePO::getStatus, 1)
|
||||
.orderByAsc(ExpressQuotePO::getCode)).stream()
|
||||
.map(this::toBriefVo)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressQuoteVO detail(Long id) {
|
||||
ExpressQuotePO po = requireCompanyQuote(id);
|
||||
ExpressQuoteVO vo = toBriefVo(po);
|
||||
List<ExpressQuoteVersionPO> versions = versionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, id)
|
||||
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom));
|
||||
List<ExpressQuoteVO.VersionVO> versionVos = new ArrayList<>();
|
||||
for (ExpressQuoteVersionPO v : versions) {
|
||||
versionVos.add(toVersionVo(v, true));
|
||||
}
|
||||
vo.setVersions(versionVos);
|
||||
if (!versionVos.isEmpty()) {
|
||||
vo.setCurrentVersion(versionVos.get(0));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressQuotePO requireCompanyQuote(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ExpressQuotePO po = getById(id);
|
||||
if (po == null || !Objects.equals(po.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("报价单不存在");
|
||||
}
|
||||
return po;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ExpressQuoteVO.VersionVO upsertVersion(Long quoteId, ExpressQuoteDtos.VersionUpsert dto) {
|
||||
ExpressQuotePO quote = requireCompanyQuote(quoteId);
|
||||
ExpressQuoteVersionPO version = upsertVersionInternal(quote, dto);
|
||||
markDirtyForQuote(quoteId, dto.getEffectiveFrom());
|
||||
return toVersionVo(version, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteVersion(Long versionId) {
|
||||
ExpressQuoteVersionPO version = versionMapper.selectById(versionId);
|
||||
if (version == null) {
|
||||
throw new BusinessException("报价版本不存在");
|
||||
}
|
||||
requireCompanyQuote(version.getQuoteId());
|
||||
Long remaining = versionMapper.selectCount(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, version.getQuoteId())
|
||||
.ne(ExpressQuoteVersionPO::getId, versionId));
|
||||
if (remaining == null || remaining == 0) {
|
||||
throw new BusinessException("至少保留一个报价版本");
|
||||
}
|
||||
deleteVersionCascade(versionId);
|
||||
markDirtyForQuote(version.getQuoteId(), version.getEffectiveFrom());
|
||||
}
|
||||
|
||||
private ExpressQuoteVersionPO upsertVersionInternal(ExpressQuotePO quote, ExpressQuoteDtos.VersionUpsert dto) {
|
||||
if (dto == null || dto.getEffectiveFrom() == null) {
|
||||
throw new BusinessException("生效日不能为空");
|
||||
}
|
||||
validateVersionPayload(quote.getBillingMode(), dto);
|
||||
ExpressQuoteVersionPO existing = versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, quote.getId())
|
||||
.eq(ExpressQuoteVersionPO::getEffectiveFrom, dto.getEffectiveFrom())
|
||||
.last("LIMIT 1"));
|
||||
ExpressQuoteVersionPO version;
|
||||
if (existing != null) {
|
||||
version = existing;
|
||||
applyVersionFields(version, dto);
|
||||
version.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
versionMapper.updateById(version);
|
||||
// 重建分区
|
||||
List<ExpressQuoteRegionPO> oldRegions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, version.getId()));
|
||||
for (ExpressQuoteRegionPO r : oldRegions) {
|
||||
tierMapper.delete(new LambdaQueryWrapper<ExpressQuoteTierPO>()
|
||||
.eq(ExpressQuoteTierPO::getRegionId, r.getId()));
|
||||
}
|
||||
regionMapper.delete(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, version.getId()));
|
||||
} else {
|
||||
version = new ExpressQuoteVersionPO();
|
||||
version.setCompanyId(quote.getCompanyId());
|
||||
version.setQuoteId(quote.getId());
|
||||
version.setEffectiveFrom(dto.getEffectiveFrom());
|
||||
applyVersionFields(version, dto);
|
||||
version.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
versionMapper.insert(version);
|
||||
}
|
||||
if (ExpressQuotePO.MODE_REGION_WEIGHT.equals(quote.getBillingMode())) {
|
||||
saveRegions(quote.getCompanyId(), version.getId(), dto.getRegions());
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private void applyVersionFields(ExpressQuoteVersionPO version, ExpressQuoteDtos.VersionUpsert dto) {
|
||||
version.setFlatAmount(dto.getFlatAmount());
|
||||
version.setUnitScope(dto.getUnitScope() != null ? dto.getUnitScope().trim().toUpperCase() : null);
|
||||
version.setPricePerKg(dto.getPricePerKg());
|
||||
version.setMinAmount(dto.getMinAmount());
|
||||
version.setVolumeDivisor(dto.getVolumeDivisor() != null ? dto.getVolumeDivisor() : 6000);
|
||||
version.setUseVolumetric(dto.getUseVolumetric() != null ? dto.getUseVolumetric() : 0);
|
||||
version.setRemark(dto.getRemark());
|
||||
}
|
||||
|
||||
private void saveRegions(Long companyId, Long versionId, List<ExpressQuoteDtos.RegionUpsert> regions) {
|
||||
if (regions == null || regions.isEmpty()) {
|
||||
throw new BusinessException("分区重量模式至少配置一个分区");
|
||||
}
|
||||
int i = 0;
|
||||
for (ExpressQuoteDtos.RegionUpsert r : regions) {
|
||||
ExpressQuoteRegionPO region = new ExpressQuoteRegionPO();
|
||||
region.setCompanyId(companyId);
|
||||
region.setVersionId(versionId);
|
||||
region.setRegionName(r.getRegionName().trim());
|
||||
region.setProvincesJson(toProvincesJson(r.getProvinces()));
|
||||
region.setIsDefault(r.getIsDefault() != null ? r.getIsDefault() : 0);
|
||||
region.setSortOrder(r.getSortOrder() != null ? r.getSortOrder() : i++);
|
||||
regionMapper.insert(region);
|
||||
|
||||
ExpressQuoteTierPO tier = new ExpressQuoteTierPO();
|
||||
tier.setCompanyId(companyId);
|
||||
tier.setVersionId(versionId);
|
||||
tier.setRegionId(region.getId());
|
||||
tier.setFirstWeightG(r.getFirstWeightG() != null ? r.getFirstWeightG() : 1000);
|
||||
tier.setFirstAmount(r.getFirstAmount() != null ? r.getFirstAmount() : java.math.BigDecimal.ZERO);
|
||||
tier.setAdditionalWeightG(r.getAdditionalWeightG() != null ? r.getAdditionalWeightG() : 1000);
|
||||
tier.setAdditionalAmount(r.getAdditionalAmount() != null ? r.getAdditionalAmount() : java.math.BigDecimal.ZERO);
|
||||
tierMapper.insert(tier);
|
||||
}
|
||||
}
|
||||
|
||||
private String toProvincesJson(List<String> provinces) {
|
||||
try {
|
||||
Set<String> normalized = new HashSet<>();
|
||||
if (provinces != null) {
|
||||
for (String p : provinces) {
|
||||
if (!StringUtils.hasText(p)) {
|
||||
continue;
|
||||
}
|
||||
String n = BiRegionNormalizer.normalize(p);
|
||||
if (!BiRegionNormalizer.isUnknown(n)) {
|
||||
normalized.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
return objectMapper.writeValueAsString(normalized.stream().sorted().toList());
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException("省份列表序列化失败");
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> parseProvinces(String json) {
|
||||
if (!StringUtils.hasText(json)) {
|
||||
return List.of();
|
||||
}
|
||||
try {
|
||||
return objectMapper.readValue(json, new TypeReference<List<String>>() {
|
||||
});
|
||||
} catch (Exception e) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateMode(String mode) {
|
||||
if (!StringUtils.hasText(mode)) {
|
||||
throw new BusinessException("计费模式不能为空");
|
||||
}
|
||||
String m = mode.trim().toUpperCase();
|
||||
if (!ExpressQuotePO.MODE_FLAT.equals(m)
|
||||
&& !ExpressQuotePO.MODE_PER_KG.equals(m)
|
||||
&& !ExpressQuotePO.MODE_REGION_WEIGHT.equals(m)) {
|
||||
throw new BusinessException("不支持的计费模式: " + mode);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateVersionPayload(String billingMode, ExpressQuoteDtos.VersionUpsert dto) {
|
||||
if (ExpressQuotePO.MODE_FLAT.equals(billingMode)) {
|
||||
if (dto.getFlatAmount() == null) {
|
||||
throw new BusinessException("一口价金额不能为空");
|
||||
}
|
||||
String scope = dto.getUnitScope() != null ? dto.getUnitScope().trim().toUpperCase() : "";
|
||||
if (!ExpressQuoteVersionPO.SCOPE_ORDER.equals(scope)
|
||||
&& !ExpressQuoteVersionPO.SCOPE_PIECE.equals(scope)) {
|
||||
throw new BusinessException("一口价须指定 ORDER 或 PIECE");
|
||||
}
|
||||
} else if (ExpressQuotePO.MODE_PER_KG.equals(billingMode)) {
|
||||
if (dto.getPricePerKg() == null) {
|
||||
throw new BusinessException("每千克单价不能为空");
|
||||
}
|
||||
} else if (ExpressQuotePO.MODE_REGION_WEIGHT.equals(billingMode)) {
|
||||
if (dto.getRegions() == null || dto.getRegions().isEmpty()) {
|
||||
throw new BusinessException("请配置分区与首重续重");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteVersionCascade(Long versionId) {
|
||||
List<ExpressQuoteRegionPO> regions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, versionId));
|
||||
for (ExpressQuoteRegionPO r : regions) {
|
||||
tierMapper.delete(new LambdaQueryWrapper<ExpressQuoteTierPO>()
|
||||
.eq(ExpressQuoteTierPO::getRegionId, r.getId()));
|
||||
}
|
||||
regionMapper.delete(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, versionId));
|
||||
versionMapper.deleteById(versionId);
|
||||
}
|
||||
|
||||
private void markDirtyForQuote(Long quoteId, java.time.LocalDate effectiveFrom) {
|
||||
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getQuoteId, quoteId)
|
||||
.eq(WarehouseExpressBindPO::getStatus, 1));
|
||||
if (binds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Long> warehouseIds = binds.stream().map(WarehouseExpressBindPO::getWarehouseId).collect(Collectors.toSet());
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
java.time.LocalDate from = effectiveFrom != null ? effectiveFrom : java.time.LocalDate.now().minusYears(1);
|
||||
List<ProductSkuPO> skus = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||
.in(ProductSkuPO::getWarehouseId, warehouseIds)
|
||||
.select(ProductSkuPO::getId));
|
||||
for (ProductSkuPO sku : skus) {
|
||||
dirtyDayService.markAfterFreightQuoteChange(companyId, sku.getId(), from, userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertCodeUnique(Long companyId, String code, Long excludeId) {
|
||||
LambdaQueryWrapper<ExpressQuotePO> w = new LambdaQueryWrapper<ExpressQuotePO>()
|
||||
.eq(ExpressQuotePO::getCompanyId, companyId)
|
||||
.eq(ExpressQuotePO::getCode, code);
|
||||
if (excludeId != null) {
|
||||
w.ne(ExpressQuotePO::getId, excludeId);
|
||||
}
|
||||
if (count(w) > 0) {
|
||||
throw new BusinessException("报价编码已存在: " + code);
|
||||
}
|
||||
}
|
||||
|
||||
private ExpressQuoteVO toBriefVo(ExpressQuotePO po) {
|
||||
ExpressQuoteVO vo = new ExpressQuoteVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
ExpressQuoteVersionPO current = versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||
.eq(ExpressQuoteVersionPO::getQuoteId, po.getId())
|
||||
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||
.last("LIMIT 1"));
|
||||
if (current != null) {
|
||||
vo.setCurrentVersion(toVersionVo(current, false));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private ExpressQuoteVO.VersionVO toVersionVo(ExpressQuoteVersionPO v, boolean withRegions) {
|
||||
ExpressQuoteVO.VersionVO vo = new ExpressQuoteVO.VersionVO();
|
||||
BeanCopyUtils.copyProperties(v, vo);
|
||||
if (!withRegions) {
|
||||
return vo;
|
||||
}
|
||||
List<ExpressQuoteRegionPO> regions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||
.eq(ExpressQuoteRegionPO::getVersionId, v.getId())
|
||||
.orderByAsc(ExpressQuoteRegionPO::getSortOrder));
|
||||
List<ExpressQuoteTierPO> tiers = tierMapper.selectList(new LambdaQueryWrapper<ExpressQuoteTierPO>()
|
||||
.eq(ExpressQuoteTierPO::getVersionId, v.getId()));
|
||||
var tierByRegion = tiers.stream().collect(Collectors.toMap(ExpressQuoteTierPO::getRegionId, t -> t, (a, b) -> a));
|
||||
List<ExpressQuoteVO.RegionVO> regionVos = new ArrayList<>();
|
||||
for (ExpressQuoteRegionPO r : regions) {
|
||||
ExpressQuoteVO.RegionVO rv = new ExpressQuoteVO.RegionVO();
|
||||
rv.setId(r.getId());
|
||||
rv.setRegionName(r.getRegionName());
|
||||
rv.setProvinces(parseProvinces(r.getProvincesJson()));
|
||||
rv.setIsDefault(r.getIsDefault());
|
||||
rv.setSortOrder(r.getSortOrder());
|
||||
ExpressQuoteTierPO tier = tierByRegion.get(r.getId());
|
||||
if (tier != null) {
|
||||
rv.setFirstWeightG(tier.getFirstWeightG());
|
||||
rv.setFirstAmount(tier.getFirstAmount());
|
||||
rv.setAdditionalWeightG(tier.getAdditionalWeightG());
|
||||
rv.setAdditionalAmount(tier.getAdditionalAmount());
|
||||
}
|
||||
regionVos.add(rv);
|
||||
}
|
||||
regionVos.sort(Comparator.comparing(r -> r.getSortOrder() != null ? r.getSortOrder() : 0));
|
||||
vo.setRegions(regionVos);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+294
@@ -0,0 +1,294 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatDirtyDayService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.WarehouseService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** 仓库 CRUD + 报价绑定。 */
|
||||
@Service
|
||||
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, WarehousePO> implements WarehouseService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final WarehouseExpressBindMapper bindMapper;
|
||||
private final ExpressQuoteMapper quoteMapper;
|
||||
private final ProductSkuMapper productSkuMapper;
|
||||
private final BiOrderStatDirtyDayService dirtyDayService;
|
||||
|
||||
public WarehouseServiceImpl(CurrentUserContext currentUserContext,
|
||||
WarehouseExpressBindMapper bindMapper,
|
||||
ExpressQuoteMapper quoteMapper,
|
||||
ProductSkuMapper productSkuMapper,
|
||||
BiOrderStatDirtyDayService dirtyDayService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.bindMapper = bindMapper;
|
||||
this.quoteMapper = quoteMapper;
|
||||
this.productSkuMapper = productSkuMapper;
|
||||
this.dirtyDayService = dirtyDayService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public WarehouseVO create(WarehouseDtos.Create dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
assertCodeUnique(companyId, dto.getCode().trim(), null);
|
||||
WarehousePO po = new WarehousePO();
|
||||
BeanCopyUtils.copyProperties(dto, po);
|
||||
po.setCode(dto.getCode().trim());
|
||||
po.setCompanyId(companyId);
|
||||
if (po.getStatus() == null) {
|
||||
po.setStatus(1);
|
||||
}
|
||||
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
save(po);
|
||||
return toVo(po, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public WarehouseVO update(WarehouseDtos.Update dto, Long id) {
|
||||
WarehousePO po = requireCompanyWarehouse(id);
|
||||
po.setName(dto.getName());
|
||||
po.setProvince(dto.getProvince());
|
||||
po.setCity(dto.getCity());
|
||||
po.setAddress(dto.getAddress());
|
||||
po.setRemark(dto.getRemark());
|
||||
if (dto.getStatus() != null) {
|
||||
po.setStatus(dto.getStatus());
|
||||
}
|
||||
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
updateById(po);
|
||||
return toVo(po, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Long id) {
|
||||
WarehousePO po = requireCompanyWarehouse(id);
|
||||
Long skuCount = productSkuMapper.selectCount(new LambdaQueryWrapper<ProductSkuPO>()
|
||||
.eq(ProductSkuPO::getWarehouseId, id));
|
||||
if (skuCount != null && skuCount > 0) {
|
||||
throw new BusinessException("仍有 " + skuCount + " 个 SKU 默认发此仓,请先解绑");
|
||||
}
|
||||
bindMapper.delete(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getWarehouseId, id));
|
||||
removeById(po.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<WarehouseVO> page(PageQueryDTO<WarehouseDtos.Filter> query) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<WarehousePO> w = new LambdaQueryWrapper<WarehousePO>()
|
||||
.eq(WarehousePO::getCompanyId, companyId);
|
||||
WarehouseDtos.Filter f = query.getFilters();
|
||||
if (f != null) {
|
||||
if (StringUtils.hasText(f.getKeywords())) {
|
||||
String kw = f.getKeywords().trim();
|
||||
w.and(x -> x.like(WarehousePO::getName, kw).or().like(WarehousePO::getCode, kw));
|
||||
}
|
||||
if (f.getStatus() != null) {
|
||||
w.eq(WarehousePO::getStatus, f.getStatus());
|
||||
}
|
||||
}
|
||||
w.orderByDesc(WarehousePO::getId);
|
||||
Page<WarehousePO> page = page(new Page<>(query.getPage(), query.getPageSize()), w);
|
||||
List<WarehouseVO> records = page.getRecords().stream().map(p -> toVo(p, false)).toList();
|
||||
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WarehouseVO> listEnabled() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
return list(new LambdaQueryWrapper<WarehousePO>()
|
||||
.eq(WarehousePO::getCompanyId, companyId)
|
||||
.eq(WarehousePO::getStatus, 1)
|
||||
.orderByAsc(WarehousePO::getCode)).stream()
|
||||
.map(p -> toVo(p, false))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WarehouseVO detail(Long id) {
|
||||
return toVo(requireCompanyWarehouse(id), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WarehousePO requireCompanyWarehouse(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
WarehousePO po = getById(id);
|
||||
if (po == null || !Objects.equals(po.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("仓库不存在");
|
||||
}
|
||||
return po;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public WarehouseExpressBindVO addBind(WarehouseDtos.BindCreate dto) {
|
||||
WarehousePO wh = requireCompanyWarehouse(dto.getWarehouseId());
|
||||
ExpressQuotePO quote = quoteMapper.selectById(dto.getQuoteId());
|
||||
if (quote == null || !Objects.equals(quote.getCompanyId(), wh.getCompanyId())) {
|
||||
throw new BusinessException("报价单不存在");
|
||||
}
|
||||
Long exists = bindMapper.selectCount(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getWarehouseId, wh.getId())
|
||||
.eq(WarehouseExpressBindPO::getQuoteId, quote.getId()));
|
||||
if (exists != null && exists > 0) {
|
||||
throw new BusinessException("该仓已绑定此报价单");
|
||||
}
|
||||
WarehouseExpressBindPO bind = new WarehouseExpressBindPO();
|
||||
bind.setCompanyId(wh.getCompanyId());
|
||||
bind.setWarehouseId(wh.getId());
|
||||
bind.setQuoteId(quote.getId());
|
||||
bind.setPriority(dto.getPriority() != null ? dto.getPriority() : 100);
|
||||
bind.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
|
||||
bind.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
bindMapper.insert(bind);
|
||||
markFreightDirtyForWarehouse(wh.getCompanyId(), wh.getId());
|
||||
return toBindVo(bind, quote);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public WarehouseExpressBindVO updateBind(WarehouseDtos.BindUpdate dto, Long bindId) {
|
||||
WarehouseExpressBindPO bind = requireBind(bindId);
|
||||
if (dto.getPriority() != null) {
|
||||
bind.setPriority(dto.getPriority());
|
||||
}
|
||||
if (dto.getStatus() != null) {
|
||||
bind.setStatus(dto.getStatus());
|
||||
}
|
||||
bind.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
bindMapper.updateById(bind);
|
||||
markFreightDirtyForWarehouse(bind.getCompanyId(), bind.getWarehouseId());
|
||||
ExpressQuotePO quote = quoteMapper.selectById(bind.getQuoteId());
|
||||
return toBindVo(bind, quote);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void removeBind(Long bindId) {
|
||||
WarehouseExpressBindPO bind = requireBind(bindId);
|
||||
bindMapper.deleteById(bindId);
|
||||
markFreightDirtyForWarehouse(bind.getCompanyId(), bind.getWarehouseId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WarehouseExpressBindVO> listBinds(Long warehouseId) {
|
||||
requireCompanyWarehouse(warehouseId);
|
||||
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getWarehouseId, warehouseId)
|
||||
.orderByAsc(WarehouseExpressBindPO::getPriority)
|
||||
.orderByAsc(WarehouseExpressBindPO::getId));
|
||||
return toBindVos(binds);
|
||||
}
|
||||
|
||||
private void markFreightDirtyForWarehouse(Long companyId, Long warehouseId) {
|
||||
List<ProductSkuPO> skus = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||
.eq(ProductSkuPO::getWarehouseId, warehouseId)
|
||||
.select(ProductSkuPO::getId));
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
LocalDate from = LocalDate.now().minusYears(1);
|
||||
for (ProductSkuPO sku : skus) {
|
||||
dirtyDayService.markAfterFreightQuoteChange(companyId, sku.getId(), from, userId);
|
||||
}
|
||||
}
|
||||
|
||||
private WarehouseExpressBindPO requireBind(Long bindId) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
WarehouseExpressBindPO bind = bindMapper.selectById(bindId);
|
||||
if (bind == null || !Objects.equals(bind.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("绑定不存在");
|
||||
}
|
||||
return bind;
|
||||
}
|
||||
|
||||
private void assertCodeUnique(Long companyId, String code, Long excludeId) {
|
||||
LambdaQueryWrapper<WarehousePO> w = new LambdaQueryWrapper<WarehousePO>()
|
||||
.eq(WarehousePO::getCompanyId, companyId)
|
||||
.eq(WarehousePO::getCode, code);
|
||||
if (excludeId != null) {
|
||||
w.ne(WarehousePO::getId, excludeId);
|
||||
}
|
||||
if (count(w) > 0) {
|
||||
throw new BusinessException("仓库编码已存在: " + code);
|
||||
}
|
||||
}
|
||||
|
||||
private WarehouseVO toVo(WarehousePO po, boolean withBinds) {
|
||||
WarehouseVO vo = new WarehouseVO();
|
||||
BeanCopyUtils.copyProperties(po, vo);
|
||||
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||
.eq(WarehouseExpressBindPO::getWarehouseId, po.getId()));
|
||||
vo.setBindCount(binds.size());
|
||||
if (withBinds) {
|
||||
vo.setBinds(toBindVos(binds));
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private List<WarehouseExpressBindVO> toBindVos(List<WarehouseExpressBindPO> binds) {
|
||||
if (binds == null || binds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<Long> quoteIds = binds.stream().map(WarehouseExpressBindPO::getQuoteId).distinct().toList();
|
||||
Map<Long, ExpressQuotePO> quoteMap = new HashMap<>();
|
||||
if (!quoteIds.isEmpty()) {
|
||||
for (ExpressQuotePO q : quoteMapper.selectBatchIds(quoteIds)) {
|
||||
quoteMap.put(q.getId(), q);
|
||||
}
|
||||
}
|
||||
return binds.stream()
|
||||
.sorted((a, b) -> {
|
||||
int pa = a.getPriority() != null ? a.getPriority() : 100;
|
||||
int pb = b.getPriority() != null ? b.getPriority() : 100;
|
||||
if (pa != pb) {
|
||||
return Integer.compare(pa, pb);
|
||||
}
|
||||
return Long.compare(a.getId(), b.getId());
|
||||
})
|
||||
.map(b -> toBindVo(b, quoteMap.get(b.getQuoteId())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private WarehouseExpressBindVO toBindVo(WarehouseExpressBindPO bind, ExpressQuotePO quote) {
|
||||
WarehouseExpressBindVO vo = new WarehouseExpressBindVO();
|
||||
BeanCopyUtils.copyProperties(bind, vo);
|
||||
if (quote != null) {
|
||||
vo.setQuoteName(quote.getName());
|
||||
vo.setQuoteCode(quote.getCode());
|
||||
vo.setCarrierCode(ExpressCarrierCodes.normalizeCode(quote.getCarrierCode()));
|
||||
vo.setBillingMode(quote.getBillingMode());
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user