mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
refactor: 重构订单,店铺,商品
This commit is contained in:
@@ -12,7 +12,7 @@ CREATE TABLE `ec_brush_order` (
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品ID(可选)',
|
||||
`product_spec_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品规格ID(可选)',
|
||||
`product_sku_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品SKU ID(可选)',
|
||||
`brush_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '刷单金额',
|
||||
`brush_time` timestamp NOT NULL COMMENT '刷单时间',
|
||||
`quantity` int NULL DEFAULT 1 COMMENT '刷单数量',
|
||||
@@ -25,7 +25,7 @@ CREATE TABLE `ec_brush_order` (
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_shop_id`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_id`(`product_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_spec_id`(`product_spec_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_sku_id`(`product_sku_id` ASC) USING BTREE,
|
||||
INDEX `idx_brush_time`(`brush_time` ASC) USING BTREE,
|
||||
INDEX `idx_company_shop_time`(`company_id` ASC, `shop_id` ASC, `brush_time` ASC) USING BTREE,
|
||||
INDEX `fk_ec_brush_order_creator`(`create_by` ASC) USING BTREE,
|
||||
@@ -33,7 +33,7 @@ CREATE TABLE `ec_brush_order` (
|
||||
CONSTRAINT `fk_ec_brush_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_product_sku` FOREIGN KEY (`product_sku_id`) REFERENCES `ec_product_sku` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_brush_order_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 = '电商-刷单记录表' ROW_FORMAT = Dynamic;
|
||||
@@ -123,88 +123,115 @@ CREATE TABLE `ec_import_tasks` (
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-导入任务表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 订单表
|
||||
-- 内部订单主表 + 明细表(多平台统一经营分析模型)
|
||||
-- 数据链路:
|
||||
-- 各平台镜像(如 ec_pdd_order)--映射/转换--> ec_order + ec_order_item
|
||||
-- 也可经导入(import)或手工录入,不强制经过平台镜像
|
||||
-- 设计原则:
|
||||
-- 1. 主表一单一行;明细一行一 SKU;与具体平台表解耦,不写平台专属 FK
|
||||
-- 2. 幂等:uk(company_id, shop_id, platform_order_no)(店内平台单号唯一)
|
||||
-- 3. 追溯:source + source_order_id(镜像表主键);用 shop.platform_code 判定读哪张镜像表
|
||||
-- 4. 明细优先绑 ec_product_sku;成本快照落明细,不随历史成本表回写
|
||||
-- 5. 平台差异字段不进主表;扩展信息留在各平台镜像 raw,转换时归一化
|
||||
-- 6. status / platform_code 均为软约定枚举(代码字典),不建状态表/平台表
|
||||
-- 7. FK 收敛:只保留 company/shop;import_task/审计人仅索引
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_order_item`;
|
||||
DROP TABLE IF EXISTS `ec_order`;
|
||||
CREATE TABLE `ec_order` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`product_spec_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品规格ID',
|
||||
`spec_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规格编码(冗余,便于查询)',
|
||||
`status_id` bigint UNSIGNED NOT NULL COMMENT '订单状态ID',
|
||||
`platform_order_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台订单号',
|
||||
`link_product_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '链接商品名称',
|
||||
`link_spec_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '链接规格名称',
|
||||
`received_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '商家实收金额',
|
||||
`quantity` int NOT NULL DEFAULT 1 COMMENT '数量',
|
||||
`unit_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '销售单价',
|
||||
`product_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '单件商品成本(下单时快照)',
|
||||
`shipping_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '单件运费成本(下单时快照)',
|
||||
`other_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '单件其他成本(下单时快照)',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
`import_task_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '导入任务ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID(隐含所属平台)',
|
||||
`platform_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台代码(冗余自 ec_shop.platform_code:pdd/taobao/jd…)',
|
||||
`status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '内部订单状态码:PENDING_SHIPMENT/SHIPPED/COMPLETED/CANCELLED/REFUNDING/REFUNDED/UNKNOWN',
|
||||
`platform_order_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台订单号',
|
||||
`source` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'import' COMMENT '来源:import-导入 sync-平台镜像转换 manual-手工',
|
||||
`source_order_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '来源平台镜像订单主键(如 ec_pdd_order.id;无跨表 FK,结合 platform 解析)',
|
||||
`pay_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '实付/商家实收金额(订单合计)',
|
||||
`goods_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '商品金额合计',
|
||||
`discount_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '折扣金额合计',
|
||||
`postage` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '邮费',
|
||||
`platform_discount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '平台优惠',
|
||||
`seller_discount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '商家优惠',
|
||||
`logistics_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '快递公司编码/标识',
|
||||
`tracking_number` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '快递运单号',
|
||||
`order_time` datetime NOT NULL COMMENT '下单时间',
|
||||
`pay_time` datetime NULL DEFAULT NULL COMMENT '支付时间',
|
||||
`confirm_time` datetime NULL DEFAULT NULL COMMENT '成交时间',
|
||||
`shipping_time` datetime NULL DEFAULT NULL COMMENT '发货时间',
|
||||
`receive_time` datetime NULL DEFAULT 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 '城市',
|
||||
`town` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '区县',
|
||||
`receiver_name_mask` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '收件人姓名脱敏',
|
||||
`receiver_phone_mask` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '收件人手机脱敏',
|
||||
`receiver_address_mask` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '收件地址脱敏',
|
||||
`buyer_memo` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '买家留言',
|
||||
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商家备注',
|
||||
`import_task_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '导入任务ID(source=import 时;弱关联,无 FK)',
|
||||
`confirm` tinyint NOT NULL DEFAULT 1 COMMENT '确认(0-否 1-是)',
|
||||
`order_time` timestamp NOT NULL COMMENT '下单时间',
|
||||
`last_mapped_time` datetime 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',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID(审计,无 FK)',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID(审计,无 FK)',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
INDEX `idx_company_shop_time`(`company_id` ASC, `shop_id` ASC, `order_time` ASC) USING BTREE,
|
||||
INDEX `idx_company_order_time`(`company_id` ASC, `order_time` ASC) USING BTREE COMMENT '覆盖概览/工作台按公司+时间范围查询',
|
||||
INDEX `idx_company_order_time_status`(`company_id` ASC, `order_time` ASC, `status_id` ASC) USING BTREE COMMENT '覆盖概览/工作台按公司+时间范围+状态查询',
|
||||
INDEX `idx_status_id`(`status_id` ASC) USING BTREE,
|
||||
INDEX `idx_platform_order_no`(`platform_order_no` ASC) USING BTREE,
|
||||
INDEX `idx_product_spec_id`(`product_spec_id` ASC) USING BTREE,
|
||||
INDEX `idx_spec_code`(`spec_code` ASC) USING BTREE,
|
||||
INDEX `idx_import_task_id`(`import_task_id` ASC) USING BTREE,
|
||||
INDEX `idx_confirm`(`confirm` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_updater`(`update_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_shop`(`shop_id` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_platform`(`company_id` ASC, `platform_order_no` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_ec_order_shop_platform_no`(`company_id` ASC, `shop_id` ASC, `platform_order_no` ASC) USING BTREE COMMENT '幂等:同店平台单号唯一',
|
||||
INDEX `idx_ec_order_company_shop_time`(`company_id` ASC, `shop_id` ASC, `order_time` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_company_order_time`(`company_id` ASC, `order_time` ASC) USING BTREE COMMENT '概览/工作台按公司+时间',
|
||||
INDEX `idx_ec_order_company_time_status`(`company_id` ASC, `order_time` ASC, `status` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_platform`(`platform_code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_status`(`status` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_pay_time`(`pay_time` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_confirm_time`(`confirm_time` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_import_task`(`import_task_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_source`(`source` ASC, `source_order_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_confirm`(`confirm` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_order_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_import_task` FOREIGN KEY (`import_task_id`) REFERENCES `ec_import_tasks` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_product_spec` FOREIGN KEY (`product_spec_id`) REFERENCES `ec_product_spec` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status` FOREIGN KEY (`status_id`) REFERENCES `ec_order_status` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_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 = '电商-订单表(含商品明细)' ;
|
||||
CONSTRAINT `fk_ec_order_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-内部订单主表(多平台统一)' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 订单状态表
|
||||
-- 说明:各统计维度独立开关(0否 1是),替代原 auto_statistics / is_refund。
|
||||
-- 概览、导出等按维度筛选订单状态时分别读取对应字段;任一为 1 的状态会进入「待拉取订单」并集。
|
||||
-- 内部订单明细表(一行一 SKU)
|
||||
-- FK:仅 order_id;company/shop 冗余无 FK;product/sku 暂留 FK(可空绑定),审计人无 FK
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_order_status`;
|
||||
CREATE TABLE `ec_order_status` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '订单状态ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`status_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '状态名称(中文)',
|
||||
`description` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '状态描述',
|
||||
`color` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '状态颜色(十六进制)',
|
||||
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`include_sales_amount` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入销售额/单量等统计 0否 1是',
|
||||
`include_product_cost` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入商品成本统计 0否 1是',
|
||||
`include_freight_cost` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入运费成本统计 0否 1是',
|
||||
`include_other_cost` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入其他成本统计 0否 1是',
|
||||
`include_refund` tinyint NOT NULL DEFAULT 0 COMMENT '是否计入退款金额统计 0否 1是',
|
||||
CREATE TABLE `ec_order_item` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '明细ID',
|
||||
`order_id` bigint UNSIGNED NOT NULL COMMENT '订单ID(ec_order.id)',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID(冗余,无 FK)',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID(冗余,无 FK)',
|
||||
`line_no` int NOT NULL DEFAULT 1 COMMENT '行号(同单内从 1 递增)',
|
||||
`product_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '内部商品ID(ec_product.id)',
|
||||
`product_sku_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '内部SKU ID(ec_product_sku.id)',
|
||||
`sku_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'SKU编码(冗余,匹配用)',
|
||||
`platform_goods_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台商品ID',
|
||||
`platform_sku_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台SKU ID',
|
||||
`link_product_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '链接/平台商品名称',
|
||||
`link_sku_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '链接/平台规格名称',
|
||||
`goods_img` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '商品图片URL',
|
||||
`quantity` int NOT NULL DEFAULT 1 COMMENT '数量',
|
||||
`unit_price` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '销售单价',
|
||||
`line_amount` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '行实收/行销售额(可选汇总)',
|
||||
`product_cost` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '单件商品成本快照',
|
||||
`shipping_cost` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '单件运费成本快照',
|
||||
`other_cost` decimal(12, 2) NOT NULL DEFAULT 0.00 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',
|
||||
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID(审计,无 FK)',
|
||||
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID(审计,无 FK)',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_status_name`(`company_id` ASC, `status_name` ASC) USING BTREE,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_status_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_order_status_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_order_status_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_status_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 = '电商-订单状态表' ;
|
||||
UNIQUE INDEX `uk_ec_order_item_line`(`order_id` ASC, `line_no` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_item_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_item_shop`(`shop_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_item_product`(`product_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_item_sku`(`product_sku_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_item_sku_code`(`sku_code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_order_item_platform_sku`(`platform_sku_id` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_order_item_order` FOREIGN KEY (`order_id`) REFERENCES `ec_order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_item_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_order_item_sku` FOREIGN KEY (`product_sku_id`) REFERENCES `ec_product_sku` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-内部订单明细表(多平台归一后的行项目)' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 商品类目表
|
||||
@@ -262,34 +289,78 @@ CREATE TABLE `ec_product` (
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-商品表(含成本价)' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 商品规格表
|
||||
-- 商品 SKU 表(内部可售/可核算最小单位;由原 ec_product_spec 迁入)
|
||||
-- 设计要点:
|
||||
-- 1. 挂在 ec_product 下:一商品多 SKU
|
||||
-- 2. 公司内 sku_code 唯一,便于订单/导入匹配,以及映射平台 outer_id
|
||||
-- 3. 成本不落本表,见 ec_product_sku_cost(按生效日历史)
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_product_spec`;
|
||||
CREATE TABLE `ec_product_spec` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '规格ID',
|
||||
DROP TABLE IF EXISTS `ec_product_sku_cost`;
|
||||
DROP TABLE IF EXISTS `ec_product_sku`;
|
||||
CREATE TABLE `ec_product_sku` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'SKU ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '规格名称',
|
||||
`spec_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '规格编码',
|
||||
`product_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`shipping_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '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 '条码(可选)',
|
||||
`attrs` json NULL COMMENT '规格属性 JSON,如 [{"name":"颜色","value":"红"}]',
|
||||
`image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'SKU 图文件ID(可选)',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`sort_order` int 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,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_product_id`(`product_id` ASC) USING BTREE,
|
||||
UNIQUE INDEX `uk_company_spec_code`(`company_id` ASC, `spec_code` ASC) USING BTREE,
|
||||
INDEX `fk_ec_spec_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_spec_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_spec_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_spec_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 = '电商-规格表' ;
|
||||
UNIQUE INDEX `uk_ec_product_sku_company_code`(`company_id` ASC, `sku_code` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_product`(`product_id` ASC) USING BTREE,
|
||||
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 `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_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表(内部可核算最小单位)' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 商品 SKU 历史成本表(追加写;按生效日起算)
|
||||
-- 取某日成本:同一 sku 下 effective_from <= 业务日 且最大的一条;当前成本 = 最大 effective_from
|
||||
-- 调价:插入新行,勿改历史行金额
|
||||
-- ----------------------------
|
||||
CREATE TABLE `ec_product_sku_cost` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL COMMENT '商品ID(冗余,便于按商品查)',
|
||||
`sku_id` bigint UNSIGNED NOT NULL COMMENT 'SKU ID',
|
||||
`product_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`shipping_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
`effective_from` date NOT NULL 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_product_sku_cost_sku_from`(`sku_id` ASC, `effective_from` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_cost_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_cost_product`(`product_id` ASC) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_cost_from`(`effective_from` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_cost_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_cost_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_sku` FOREIGN KEY (`sku_id`) REFERENCES `ec_product_sku` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_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历史成本表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 推广费记录表
|
||||
@@ -357,49 +428,7 @@ CREATE TABLE `ec_promotion_fee_type` (
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-推广费类型表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 平台表
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_platform`;
|
||||
CREATE TABLE `ec_platform` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '平台ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`platform_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台名称(如淘宝、京东、拼多多、抖音)',
|
||||
`platform_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '平台代码(如 taobao、jd、pdd、douyin)',
|
||||
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`is_active` 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,
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_sort_order`(`sort_order` ASC) USING BTREE,
|
||||
INDEX `idx_is_active`(`is_active` ASC) USING BTREE,
|
||||
INDEX `fk_ec_platform_company`(`company_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_platform_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_platform_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_platform_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_platform_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_platform_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 = '电商-平台表' ;
|
||||
|
||||
-- ----------------------------
|
||||
-- 平台数据初始化
|
||||
-- ----------------------------
|
||||
INSERT INTO `ec_platform` (`platform_name`, `platform_code`, `sort_order`, `is_active`) VALUES
|
||||
('淘宝', 'taobao', 1, 1),
|
||||
('京东', 'jd', 2, 1),
|
||||
('拼多多', 'pdd', 3, 1),
|
||||
('抖音', 'douyin', 4, 1),
|
||||
('快手', 'kuaishou', 5, 1),
|
||||
('小红书', 'xiaohongshu', 6, 1),
|
||||
('天猫', 'tmall', 7, 1),
|
||||
('唯品会', 'vip', 8, 1),
|
||||
('苏宁', 'suning', 9, 1),
|
||||
('1688', '1688', 10, 1);
|
||||
|
||||
-- ----------------------------
|
||||
-- 店铺表
|
||||
-- 店铺表(platform_code 软约定:taobao/jd/pdd/douyin/kuaishou/xiaohongshu/tmall/vip/suning/1688)
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ec_shop`;
|
||||
CREATE TABLE `ec_shop` (
|
||||
@@ -407,23 +436,22 @@ CREATE TABLE `ec_shop` (
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '所属公司ID',
|
||||
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '店铺名称',
|
||||
`logo_image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'logo图片ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID',
|
||||
`external_shop_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '外部店铺ID(如拼多多 mall_id;与 platform_id 组合关联平台店铺)',
|
||||
`platform_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '平台代码(软约定枚举,无平台表)',
|
||||
`external_shop_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '外部店铺ID(如拼多多 mall_id;与 platform_code 组合关联平台店铺)',
|
||||
`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_shop_company_platform_external`(`company_id` ASC, `platform_id` ASC, `external_shop_id` ASC) USING BTREE COMMENT '同一公司同一平台下外部店铺ID唯一(NULL 可重复,手工店)',
|
||||
UNIQUE INDEX `uk_ec_shop_company_platform_external`(`company_id` ASC, `platform_code` ASC, `external_shop_id` ASC) USING BTREE COMMENT '同一公司同一平台下外部店铺ID唯一(NULL 可重复,手工店)',
|
||||
INDEX `idx_company_id`(`company_id` ASC) USING BTREE,
|
||||
INDEX `idx_platform_id`(`platform_id` ASC) USING BTREE,
|
||||
INDEX `idx_platform_code`(`platform_code` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_logo_image`(`logo_image_id` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_creator`(`create_by` ASC) USING BTREE,
|
||||
INDEX `fk_ec_shop_updater`(`update_by` ASC) USING BTREE,
|
||||
CONSTRAINT `fk_ec_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_logo_image` FOREIGN KEY (`logo_image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_platform` FOREIGN KEY (`platform_id`) REFERENCES `ec_platform` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_shop_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 = '电商-店铺表' ;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ CREATE TABLE `ec_order_stat_daily_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID(写入时快照 ec_shop.platform_id)',
|
||||
`platform_code` varchar(32) NULL DEFAULT NULL COMMENT '平台代码(写入时快照 ec_shop.platform_code)',
|
||||
`stat_date` date NOT NULL COMMENT '自然日(Asia/Shanghai,与 order_time 的 DATE 一致)',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
@@ -80,7 +80,7 @@ CREATE TABLE `ec_order_stat_daily_shop` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_date` (`company_id`, `shop_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_date` (`company_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_platform_date` (`company_id`, `platform_id`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_company_platform_date` (`company_id`, `platform_code`, `stat_date`) USING BTREE,
|
||||
INDEX `idx_shop_date` (`shop_id`, `stat_date`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_daily_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_daily_shop_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
@@ -92,7 +92,7 @@ CREATE TABLE `ec_order_stat_monthly_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID(月 rollup 时取当月最后写入快照)',
|
||||
`platform_code` varchar(32) NULL DEFAULT NULL COMMENT '平台代码(月 rollup 时取当月最后写入快照)',
|
||||
`stat_month` date NOT NULL COMMENT '自然月首日,如 2024-03-01',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
@@ -113,7 +113,7 @@ CREATE TABLE `ec_order_stat_monthly_shop` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_month` (`company_id`, `shop_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_month` (`company_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_platform_month` (`company_id`, `platform_id`, `stat_month`) USING BTREE,
|
||||
INDEX `idx_company_platform_month` (`company_id`, `platform_code`, `stat_month`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_monthly_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_monthly_shop_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-店铺-月汇总(由日表 SUM 或订单直算)';
|
||||
@@ -124,7 +124,7 @@ CREATE TABLE `ec_order_stat_yearly_shop` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID',
|
||||
`platform_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '平台ID',
|
||||
`platform_code` varchar(32) NULL DEFAULT NULL COMMENT '平台代码',
|
||||
`stat_year` smallint NOT NULL COMMENT '自然年,如 2024',
|
||||
|
||||
`sales_amount` decimal(16, 2) NOT NULL DEFAULT 0.00 COMMENT '实际销售额',
|
||||
@@ -145,7 +145,7 @@ CREATE TABLE `ec_order_stat_yearly_shop` (
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
UNIQUE KEY `uk_company_shop_year` (`company_id`, `shop_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_year` (`company_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_platform_year` (`company_id`, `platform_id`, `stat_year`) USING BTREE,
|
||||
INDEX `idx_company_platform_year` (`company_id`, `platform_code`, `stat_year`) USING BTREE,
|
||||
CONSTRAINT `fk_oss_yearly_shop_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_oss_yearly_shop_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '订单统计-店铺-年汇总(3~5 年 KPI / 平台占比主读表)';
|
||||
@@ -541,7 +541,7 @@ CREATE TABLE `ec_order_stat_refresh_queue` (
|
||||
--
|
||||
-- 月表 ← 日表(店铺):
|
||||
-- INSERT INTO ec_order_stat_monthly_shop (...)
|
||||
-- SELECT company_id, shop_id, MAX(platform_id),
|
||||
-- SELECT company_id, shop_id, MAX(platform_code),
|
||||
-- DATE_FORMAT(stat_date, '%Y-%m-01'),
|
||||
-- SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum),
|
||||
-- SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum),
|
||||
@@ -553,7 +553,7 @@ CREATE TABLE `ec_order_stat_refresh_queue` (
|
||||
--
|
||||
-- 年表 ← 月表(店铺):
|
||||
-- INSERT INTO ec_order_stat_yearly_shop (...)
|
||||
-- SELECT company_id, shop_id, MAX(platform_id), YEAR(stat_month),
|
||||
-- SELECT company_id, shop_id, MAX(platform_code), YEAR(stat_month),
|
||||
-- SUM(sales_amount), ...
|
||||
-- FROM ec_order_stat_monthly_shop
|
||||
-- WHERE company_id=? AND stat_year BETWEEN ? AND ?
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
-- 3. 漏单补拉:pdd.order.information.get(按 order_sn)
|
||||
--
|
||||
-- 设计原则:
|
||||
-- 1. 与 ec_order(内部经营分析订单)分离,本模块只存平台原始同步数据;映射到 ec_order 另期
|
||||
-- 1. 与 ec_order(内部经营分析订单)分离,本模块只存平台原始同步数据;
|
||||
-- 映射路径:ec_pdd_order(+item) → 转换器 → ec_order(+item);其他平台同理各建镜像表再统一转入
|
||||
-- 2. 主表 + 明细表覆盖列表查询、对账、物流、状态同步;gift_list / promotion_detail_list /
|
||||
-- order_tag_list 等嵌套结构写入 raw_response
|
||||
-- 3. 幂等键 uk(company_id, order_sn);同步进度按店存在 ec_pdd_order_sync_cursor,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
-- 数据来源:pdd.mall.info.get → mall_info_get_response
|
||||
-- 设计原则:
|
||||
-- 1. 与 ec_shop(内部店铺)分离,本表只存拼多多平台店铺镜像
|
||||
-- 2. 不主动 FK 关联 ec_shop;绑定由 ec_shop.platform_id + external_shop_id(= mall_id)维护
|
||||
-- 2. 不主动 FK 关联 ec_shop;绑定由 ec_shop.platform_code + external_shop_id(= mall_id)维护
|
||||
-- 3. 授权后拉取写入本表,再按公司 + 拼多多平台 + mall_id upsert ec_shop
|
||||
-- ========================================
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
-- 去掉 ec_platform / ec_order_status:店铺改存 platform_code;订单表/统计表已删,不做变更
|
||||
|
||||
-- ========== 1. ec_shop:platform_id → platform_code ==========
|
||||
ALTER TABLE `ec_shop`
|
||||
ADD COLUMN `platform_code` varchar(32) NULL DEFAULT NULL COMMENT '平台代码(软约定)' AFTER `logo_image_id`;
|
||||
|
||||
UPDATE `ec_shop` s
|
||||
LEFT JOIN `ec_platform` p ON p.id = s.platform_id
|
||||
SET s.platform_code = p.platform_code
|
||||
WHERE s.platform_id IS NOT NULL;
|
||||
|
||||
ALTER TABLE `ec_shop` DROP FOREIGN KEY `fk_ec_shop_platform`;
|
||||
ALTER TABLE `ec_shop` DROP INDEX `uk_ec_shop_company_platform_external`;
|
||||
ALTER TABLE `ec_shop` DROP INDEX `idx_platform_id`;
|
||||
ALTER TABLE `ec_shop` DROP COLUMN `platform_id`;
|
||||
|
||||
ALTER TABLE `ec_shop`
|
||||
ADD UNIQUE INDEX `uk_ec_shop_company_platform_external`(`company_id`, `platform_code`, `external_shop_id`),
|
||||
ADD INDEX `idx_platform_code`(`platform_code`);
|
||||
|
||||
-- ========== 2. 删除字典表 ==========
|
||||
DROP TABLE IF EXISTS `ec_order_status`;
|
||||
DROP TABLE IF EXISTS `ec_platform`;
|
||||
|
||||
-- ========== 3. 清理菜单与权限(平台管理 / 订单状态配置) ==========
|
||||
DELETE mp FROM `sys_menu_permission` mp
|
||||
INNER JOIN `sys_menu` m ON m.id = mp.menu_id
|
||||
WHERE m.name IN ('平台管理', '订单状态');
|
||||
|
||||
-- org_company_menu / org_position_menu 对 sys_menu 为 ON DELETE CASCADE
|
||||
DELETE FROM `sys_menu` WHERE `name` IN ('平台管理', '订单状态');
|
||||
|
||||
DELETE ocp FROM `org_company_permission` ocp
|
||||
INNER JOIN `sys_permission` p ON p.id = ocp.permission_id
|
||||
WHERE p.code LIKE 'ecom:platform%';
|
||||
|
||||
DELETE opp FROM `org_position_permission` opp
|
||||
INNER JOIN `sys_permission` p ON p.id = opp.permission_id
|
||||
WHERE p.code LIKE 'ecom:platform%';
|
||||
|
||||
DELETE FROM `sys_permission` WHERE `code` LIKE 'ecom:platform%';
|
||||
@@ -0,0 +1,164 @@
|
||||
-- 规格 → SKU / SKU 成本迁移
|
||||
-- 1) 建 ec_product_sku、ec_product_sku_cost(若不存在)
|
||||
-- 2) 按原 spec.id 灌入 SKU(id 保持一致,便于刷单等引用对齐)
|
||||
-- 3) 成本写入历史成本表(effective_from = 规格创建日)
|
||||
-- 4) 刷单表 product_spec_id → product_sku_id
|
||||
-- 5) 删除 ec_product_spec
|
||||
|
||||
-- ========== 1. 建表 ==========
|
||||
CREATE TABLE IF NOT EXISTS `ec_product_sku` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'SKU ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '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 '条码(可选)',
|
||||
`attrs` json NULL COMMENT '规格属性 JSON',
|
||||
`image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'SKU 图文件ID',
|
||||
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||
`sort_order` int 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_product_sku_company_code`(`company_id`, `sku_code`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_company`(`company_id`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_product`(`product_id`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_status`(`status`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_barcode`(`barcode`) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_image`(`image_id`) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_creator`(`create_by`) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_updater`(`update_by`) 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_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表';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ec_product_sku_cost` (
|
||||
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`product_id` bigint UNSIGNED NOT NULL COMMENT '商品ID',
|
||||
`sku_id` bigint UNSIGNED NOT NULL COMMENT 'SKU ID',
|
||||
`product_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '商品成本',
|
||||
`shipping_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '运费成本',
|
||||
`other_cost` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '其他成本',
|
||||
`effective_from` date NOT NULL 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_product_sku_cost_sku_from`(`sku_id`, `effective_from`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_cost_company`(`company_id`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_cost_product`(`product_id`) USING BTREE,
|
||||
INDEX `idx_ec_product_sku_cost_from`(`effective_from`) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_cost_creator`(`create_by`) USING BTREE,
|
||||
INDEX `fk_ec_product_sku_cost_updater`(`update_by`) USING BTREE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_product` FOREIGN KEY (`product_id`) REFERENCES `ec_product` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_sku` FOREIGN KEY (`sku_id`) REFERENCES `ec_product_sku` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_product_sku_cost_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历史成本表';
|
||||
|
||||
-- ========== 2. 规格 → SKU(保留原 id) ==========
|
||||
INSERT INTO `ec_product_sku` (
|
||||
`id`, `company_id`, `product_id`, `name`, `sku_code`,
|
||||
`status`, `sort_order`, `remark`,
|
||||
`create_time`, `update_time`, `create_by`, `update_by`
|
||||
)
|
||||
SELECT
|
||||
s.`id`,
|
||||
s.`company_id`,
|
||||
s.`product_id`,
|
||||
s.`name`,
|
||||
s.`spec_code`,
|
||||
1,
|
||||
0,
|
||||
s.`remark`,
|
||||
s.`create_time`,
|
||||
s.`update_time`,
|
||||
s.`create_by`,
|
||||
s.`update_by`
|
||||
FROM `ec_product_spec` s
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `ec_product_sku` k WHERE k.`id` = s.`id`
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `ec_product_sku` k
|
||||
WHERE k.`company_id` = s.`company_id` AND k.`sku_code` = s.`spec_code`
|
||||
);
|
||||
|
||||
-- 若同公司已有同 code 的 SKU(非同 id),按 code 对齐:不插入,刷单后续用 code 映射不到 id——尽量避免;
|
||||
-- 正常存量应是 1:1 空表迁移。
|
||||
|
||||
-- 校正自增
|
||||
SET @sku_ai := (SELECT IFNULL(MAX(`id`), 0) + 1 FROM `ec_product_sku`);
|
||||
SET @sql := CONCAT('ALTER TABLE `ec_product_sku` AUTO_INCREMENT = ', @sku_ai);
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ========== 3. 规格成本 → SKU 成本(effective_from = 创建日) ==========
|
||||
INSERT INTO `ec_product_sku_cost` (
|
||||
`company_id`, `product_id`, `sku_id`,
|
||||
`product_cost`, `shipping_cost`, `other_cost`,
|
||||
`effective_from`, `remark`,
|
||||
`create_time`, `update_time`, `create_by`, `update_by`
|
||||
)
|
||||
SELECT
|
||||
s.`company_id`,
|
||||
s.`product_id`,
|
||||
k.`id`,
|
||||
IFNULL(s.`product_cost`, 0.00),
|
||||
IFNULL(s.`shipping_cost`, 0.00),
|
||||
IFNULL(s.`other_cost`, 0.00),
|
||||
COALESCE(DATE(s.`create_time`), '2000-01-01'),
|
||||
CONCAT('migrated from ec_product_spec.id=', s.`id`),
|
||||
s.`create_time`,
|
||||
s.`update_time`,
|
||||
s.`create_by`,
|
||||
s.`update_by`
|
||||
FROM `ec_product_spec` s
|
||||
INNER JOIN `ec_product_sku` k
|
||||
ON k.`company_id` = s.`company_id`
|
||||
AND k.`sku_code` = s.`spec_code`
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `ec_product_sku_cost` c
|
||||
WHERE c.`sku_id` = k.`id`
|
||||
AND c.`effective_from` = COALESCE(DATE(s.`create_time`), '2000-01-01')
|
||||
);
|
||||
|
||||
-- ========== 4. 刷单:product_spec_id → product_sku_id ==========
|
||||
ALTER TABLE `ec_brush_order`
|
||||
ADD COLUMN `product_sku_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '商品SKU ID' AFTER `product_id`;
|
||||
|
||||
UPDATE `ec_brush_order` b
|
||||
LEFT JOIN `ec_product_spec` s ON s.`id` = b.`product_spec_id`
|
||||
LEFT JOIN `ec_product_sku` k
|
||||
ON k.`company_id` = s.`company_id` AND k.`sku_code` = s.`spec_code`
|
||||
SET b.`product_sku_id` = k.`id`
|
||||
WHERE b.`product_spec_id` IS NOT NULL;
|
||||
|
||||
-- 若 id 一致且未改 code,兜底按原 id 对齐
|
||||
UPDATE `ec_brush_order` b
|
||||
INNER JOIN `ec_product_sku` k ON k.`id` = b.`product_spec_id`
|
||||
SET b.`product_sku_id` = k.`id`
|
||||
WHERE b.`product_sku_id` IS NULL AND b.`product_spec_id` IS NOT NULL;
|
||||
|
||||
ALTER TABLE `ec_brush_order` DROP FOREIGN KEY `fk_ec_brush_order_product_spec`;
|
||||
ALTER TABLE `ec_brush_order` DROP INDEX `idx_product_spec_id`;
|
||||
ALTER TABLE `ec_brush_order` DROP COLUMN `product_spec_id`;
|
||||
|
||||
ALTER TABLE `ec_brush_order`
|
||||
ADD INDEX `idx_product_sku_id`(`product_sku_id`),
|
||||
ADD CONSTRAINT `fk_ec_brush_order_product_sku`
|
||||
FOREIGN KEY (`product_sku_id`) REFERENCES `ec_product_sku` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- ========== 5. 删除规格表 ==========
|
||||
DROP TABLE IF EXISTS `ec_product_spec`;
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class CreateBrushOrderDTO {
|
||||
* 商品规格ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
private Long productSkuId;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ public class UpdateBrushOrderDTO {
|
||||
* 商品规格ID(可选)
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
private Long productSkuId;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
|
||||
+2
-2
@@ -42,8 +42,8 @@ public class BrushOrderPO {
|
||||
/**
|
||||
* 商品规格ID(可选)
|
||||
*/
|
||||
@TableField("product_spec_id")
|
||||
private Long productSpecId;
|
||||
@TableField("product_sku_id")
|
||||
private Long productSkuId;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
|
||||
+2
-2
@@ -53,13 +53,13 @@ public class BrushOrderVO {
|
||||
* 商品规格ID
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
private Long productSkuId;
|
||||
|
||||
/**
|
||||
* 商品规格名称
|
||||
*/
|
||||
@Schema(description = "商品规格名称", example = "256GB 深空黑色")
|
||||
private String productSpecName;
|
||||
private String productSkuName;
|
||||
|
||||
/**
|
||||
* 刷单金额
|
||||
|
||||
+19
-19
@@ -16,13 +16,13 @@ import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.dto.CreateBrushOr
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.dto.UpdateBrushOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.vo.BrushOrderVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.service.BrushOrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.FeeStatCrudCoordinator;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
@@ -38,16 +38,16 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final ProductService productService;
|
||||
private final ProductSpecService productSpecService;
|
||||
private final ProductSkuService productSkuService;
|
||||
private final FeeStatCrudCoordinator feeStatCrudCoordinator;
|
||||
|
||||
public BrushOrderServiceImpl(CurrentUserContext currentUserContext, ShopService shopService,
|
||||
ProductService productService, ProductSpecService productSpecService,
|
||||
ProductService productService, ProductSkuService productSkuService,
|
||||
FeeStatCrudCoordinator feeStatCrudCoordinator) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.productService = productService;
|
||||
this.productSpecService = productSpecService;
|
||||
this.productSkuService = productSkuService;
|
||||
this.feeStatCrudCoordinator = feeStatCrudCoordinator;
|
||||
}
|
||||
|
||||
@@ -77,10 +77,10 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
|
||||
}
|
||||
|
||||
// 验证商品规格是否存在且属于当前公司(如果提供了规格ID)
|
||||
if (createBrushOrderDTO.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = productSpecService.getById(createBrushOrderDTO.getProductSpecId());
|
||||
if (productSpec == null || !productSpec.getCompanyId().equals(companyId) ||
|
||||
!productSpec.getProductId().equals(createBrushOrderDTO.getProductId())) {
|
||||
if (createBrushOrderDTO.getProductSkuId() != null) {
|
||||
ProductSkuPO productSku = productSkuService.getById(createBrushOrderDTO.getProductSkuId());
|
||||
if (productSku == null || !productSku.getCompanyId().equals(companyId) ||
|
||||
!productSku.getProductId().equals(createBrushOrderDTO.getProductId())) {
|
||||
throw new BusinessException("商品规格不存在或不属于该商品");
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
|
||||
brushOrder.setCompanyId(companyId);
|
||||
brushOrder.setShopId(createBrushOrderDTO.getShopId());
|
||||
brushOrder.setProductId(createBrushOrderDTO.getProductId());
|
||||
brushOrder.setProductSpecId(createBrushOrderDTO.getProductSpecId());
|
||||
brushOrder.setProductSkuId(createBrushOrderDTO.getProductSkuId());
|
||||
brushOrder.setBrushAmount(createBrushOrderDTO.getBrushAmount());
|
||||
brushOrder.setBrushTime(createBrushOrderDTO.getBrushTime());
|
||||
brushOrder.setQuantity(createBrushOrderDTO.getQuantity() != null ? createBrushOrderDTO.getQuantity() : 1);
|
||||
@@ -139,10 +139,10 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
|
||||
}
|
||||
|
||||
// 验证商品规格是否存在且属于当前公司(如果提供了规格ID)
|
||||
if (updateBrushOrderDTO.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = productSpecService.getById(updateBrushOrderDTO.getProductSpecId());
|
||||
if (productSpec == null || !productSpec.getCompanyId().equals(companyId) ||
|
||||
!productSpec.getProductId().equals(updateBrushOrderDTO.getProductId())) {
|
||||
if (updateBrushOrderDTO.getProductSkuId() != null) {
|
||||
ProductSkuPO productSku = productSkuService.getById(updateBrushOrderDTO.getProductSkuId());
|
||||
if (productSku == null || !productSku.getCompanyId().equals(companyId) ||
|
||||
!productSku.getProductId().equals(updateBrushOrderDTO.getProductId())) {
|
||||
throw new BusinessException("商品规格不存在或不属于该商品");
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
|
||||
BeanCopyUtils.copyProperties(existingBrushOrder, before);
|
||||
existingBrushOrder.setShopId(updateBrushOrderDTO.getShopId());
|
||||
existingBrushOrder.setProductId(updateBrushOrderDTO.getProductId());
|
||||
existingBrushOrder.setProductSpecId(updateBrushOrderDTO.getProductSpecId());
|
||||
existingBrushOrder.setProductSkuId(updateBrushOrderDTO.getProductSkuId());
|
||||
existingBrushOrder.setBrushAmount(updateBrushOrderDTO.getBrushAmount());
|
||||
existingBrushOrder.setBrushTime(updateBrushOrderDTO.getBrushTime());
|
||||
if (updateBrushOrderDTO.getQuantity() != null) {
|
||||
@@ -290,10 +290,10 @@ public class BrushOrderServiceImpl extends ServiceImpl<BrushOrderMapper, BrushOr
|
||||
brushOrderVO.setProductName(product.getName());
|
||||
}
|
||||
|
||||
if (brushOrder.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = productSpecService.getById(brushOrder.getProductSpecId());
|
||||
if (productSpec != null) {
|
||||
brushOrderVO.setProductSpecName(productSpec.getName());
|
||||
if (brushOrder.getProductSkuId() != null) {
|
||||
ProductSkuPO productSku = productSkuService.getById(brushOrder.getProductSkuId());
|
||||
if (productSku != null) {
|
||||
brushOrderVO.setProductSkuName(productSku.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -18,7 +18,7 @@ public class OrderImportMappingConfig {
|
||||
private List<FieldMappingItem> fieldMapping;
|
||||
|
||||
/**
|
||||
* 状态映射:CSV 状态文案 -> 订单状态ID
|
||||
* 状态映射:CSV 状态文案 -> 订单状态码
|
||||
*/
|
||||
@JsonProperty("statusMapping")
|
||||
private List<StatusMappingItem> statusMapping;
|
||||
@@ -26,7 +26,7 @@ public class OrderImportMappingConfig {
|
||||
@Data
|
||||
public static class FieldMappingItem {
|
||||
private Boolean required;
|
||||
/** 订单/实体字段名,如 spec_code, link_product_name */
|
||||
/** 订单/实体字段名,如 sku_code, link_product_name */
|
||||
private String fieldName;
|
||||
private String fieldLabel;
|
||||
/** CSV 表头名称,如 商品、订单号 */
|
||||
@@ -37,7 +37,7 @@ public class OrderImportMappingConfig {
|
||||
public static class StatusMappingItem {
|
||||
/** CSV 中的状态文案,如 已发货,待收货 */
|
||||
private String csvStatus;
|
||||
/** 系统订单状态ID */
|
||||
private Long mappedStatusId;
|
||||
/** 系统订单状态码 */
|
||||
private String mappedStatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-6
@@ -30,8 +30,9 @@ public class OrderImportRow {
|
||||
return values == null ? null : values.get(fieldName);
|
||||
}
|
||||
|
||||
public String getSpecCode() {
|
||||
return get("spec_code");
|
||||
public String getSkuCode() {
|
||||
String v = get("sku_code");
|
||||
return v != null ? v : get("spec_code");
|
||||
}
|
||||
|
||||
public String getLinkProductName() {
|
||||
@@ -46,7 +47,7 @@ public class OrderImportRow {
|
||||
return get("platform_order_no");
|
||||
}
|
||||
|
||||
public String getLinkSpecName() {
|
||||
public String getLinkSkuName() {
|
||||
return get("link_spec_name");
|
||||
}
|
||||
|
||||
@@ -54,8 +55,8 @@ public class OrderImportRow {
|
||||
return get("status");
|
||||
}
|
||||
|
||||
/** 根据 statusMapping 将 CSV 状态文案解析为订单状态ID */
|
||||
public Long getMappedStatusId(List<OrderImportMappingConfig.StatusMappingItem> statusMapping) {
|
||||
/** 根据 statusMapping 将 CSV 状态文案解析为订单状态码 */
|
||||
public String getMappedStatusCode(List<OrderImportMappingConfig.StatusMappingItem> statusMapping) {
|
||||
String text = getStatusText();
|
||||
if (text == null || text.isBlank() || statusMapping == null) {
|
||||
return null;
|
||||
@@ -63,7 +64,7 @@ public class OrderImportRow {
|
||||
String trimmed = text.trim();
|
||||
for (OrderImportMappingConfig.StatusMappingItem item : statusMapping) {
|
||||
if (trimmed.equals(item.getCsvStatus() != null ? item.getCsvStatus().trim() : null)) {
|
||||
return item.getMappedStatusId();
|
||||
return item.getMappedStatusCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+16
-12
@@ -1,8 +1,9 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopProductRelationPO;
|
||||
|
||||
import java.time.LocalDate;
|
||||
@@ -53,14 +54,14 @@ public class ImportRuntimeContext {
|
||||
*/
|
||||
public static class StatusMapping {
|
||||
private String csvStatus;
|
||||
private Long mappedStatusId;
|
||||
private String mappedStatusCode;
|
||||
|
||||
public StatusMapping() {}
|
||||
|
||||
public String getCsvStatus() { return csvStatus; }
|
||||
public void setCsvStatus(String csvStatus) { this.csvStatus = csvStatus; }
|
||||
public Long getMappedStatusId() { return mappedStatusId; }
|
||||
public void setMappedStatusId(Long mappedStatusId) { this.mappedStatusId = mappedStatusId; }
|
||||
public String getMappedStatusCode() { return mappedStatusCode; }
|
||||
public void setMappedStatusCode(String mappedStatusCode) { this.mappedStatusCode = mappedStatusCode; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +86,7 @@ public class ImportRuntimeContext {
|
||||
public int rowNumber;
|
||||
public String platformOrderNo;
|
||||
public OrderPO order;
|
||||
public OrderItemPO item;
|
||||
/**
|
||||
* 该导入行输入的 order_time 是否为空(仅用于更新跳过策略)。
|
||||
* <p>
|
||||
@@ -94,21 +96,23 @@ public class ImportRuntimeContext {
|
||||
public Long existingOrderId; // 不为空表示是更新操作
|
||||
public StringBuilder updateMessages;
|
||||
|
||||
public PendingOrderInsert(int rowNumber, String platformOrderNo, OrderPO order,
|
||||
public PendingOrderInsert(int rowNumber, String platformOrderNo, OrderPO order, OrderItemPO item,
|
||||
Long existingOrderId, StringBuilder updateMessages,
|
||||
boolean orderTimeEmptyInInput) {
|
||||
this.rowNumber = rowNumber;
|
||||
this.platformOrderNo = platformOrderNo;
|
||||
this.order = order;
|
||||
this.item = item;
|
||||
this.orderTimeEmptyInInput = orderTimeEmptyInInput;
|
||||
this.existingOrderId = existingOrderId;
|
||||
this.updateMessages = updateMessages;
|
||||
}
|
||||
|
||||
public void updateData(OrderPO newOrder, Long newExistingOrderId,
|
||||
public void updateData(OrderPO newOrder, OrderItemPO newItem, Long newExistingOrderId,
|
||||
StringBuilder newUpdateMsg, int newRowNumber,
|
||||
boolean newOrderTimeEmptyInInput) {
|
||||
this.order = newOrder;
|
||||
this.item = newItem;
|
||||
this.rowNumber = newRowNumber;
|
||||
if (newExistingOrderId != null) this.existingOrderId = newExistingOrderId;
|
||||
if (newUpdateMsg != null && newUpdateMsg.length() > 0) this.updateMessages = newUpdateMsg;
|
||||
@@ -160,19 +164,19 @@ public class ImportRuntimeContext {
|
||||
private DateTimeFormatPattern detectedDatePattern;
|
||||
|
||||
// 缓存:只读(预加载后不再写入),使用 ConcurrentHashMap 确保 workers 并行读取安全
|
||||
final ConcurrentHashMap<String, ProductSpecPO> specByCodeCache = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, ProductSkuPO> skuByCodeCache = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, ProductPO> productByCodeCache = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, ProductPO> productByNameCache = new ConcurrentHashMap<>();
|
||||
/** 与 uk_company_code_name 对齐:规范化编码与名称用 U+0001 拼接作为键 */
|
||||
final ConcurrentHashMap<String, ProductPO> productByCodeAndNameCache = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<Long, ProductPO> productByIdCache = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, Long> statusIdByNameCache = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, String> statusCodeByNameCache = new ConcurrentHashMap<>();
|
||||
|
||||
// 已存在于 DB 的数据:预加载时填充(只写一次),后续只读
|
||||
final Set<String> existingPlatformOrderNos = ConcurrentHashMap.newKeySet();
|
||||
final Map<String, Long> existingOrderIdByPlatformNo = new ConcurrentHashMap<>();
|
||||
/** 平台订单号(规范化) → 库中订单业务字段快照;成功 UPDATE 后由主线程替换为新快照 */
|
||||
final ConcurrentHashMap<String, OrderPO> existingOrderSnapshotByPlatformNo = new ConcurrentHashMap<>();
|
||||
final ConcurrentHashMap<String, OrderImportSnapshot> existingOrderSnapshotByPlatformNo = new ConcurrentHashMap<>();
|
||||
final Set<String> existingRelationKeys = ConcurrentHashMap.newKeySet();
|
||||
|
||||
// pendingOrders:由 workers 并发添加(CopyOnWriteArrayList 读多写少场景高效)
|
||||
@@ -234,15 +238,15 @@ public class ImportRuntimeContext {
|
||||
public Map<String, MappingField> getOrderImportFieldMapping() {
|
||||
return orderImportFieldMapping != null ? orderImportFieldMapping : Collections.emptyMap();
|
||||
}
|
||||
public Map<String, ProductSpecPO> getSpecByCodeCache() { return specByCodeCache; }
|
||||
public Map<String, ProductSkuPO> getSpecByCodeCache() { return skuByCodeCache; }
|
||||
public Map<String, ProductPO> getProductByCodeCache() { return productByCodeCache; }
|
||||
public Map<String, ProductPO> getProductByNameCache() { return productByNameCache; }
|
||||
public Map<String, ProductPO> getProductByCodeAndNameCache() { return productByCodeAndNameCache; }
|
||||
public Map<Long, ProductPO> getProductByIdCache() { return productByIdCache; }
|
||||
public Map<String, Long> getStatusIdByNameCache() { return statusIdByNameCache; }
|
||||
public Map<String, String> getStatusCodeByNameCache() { return statusCodeByNameCache; }
|
||||
public Set<String> getExistingPlatformOrderNos() { return existingPlatformOrderNos; }
|
||||
public Map<String, Long> getExistingOrderIdByPlatformNo() { return existingOrderIdByPlatformNo; }
|
||||
public Map<String, OrderPO> getExistingOrderSnapshotByPlatformNo() { return existingOrderSnapshotByPlatformNo; }
|
||||
public Map<String, OrderImportSnapshot> getExistingOrderSnapshotByPlatformNo() { return existingOrderSnapshotByPlatformNo; }
|
||||
public Set<String> getExistingRelationKeys() { return existingRelationKeys; }
|
||||
public List<PendingOrderInsert> getPendingOrders() { return pendingOrders; }
|
||||
public Map<String, PendingOrderInsert> getPendingOrderByPlatformNo() { return pendingOrderByPlatformNo; }
|
||||
|
||||
+17
-11
@@ -13,13 +13,14 @@ import top.xyquan.ecomdmbbackend.modules.ecom.importtask.model.vo.ImportTaskVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.ImportTaskProcessorService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.ImportTaskService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.SseNotificationService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.FeeStatRefreshService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatRefreshCoordinator;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.support.RefreshSource;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.service.impl.PromotionFeeImportProcessor;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.OssService;
|
||||
@@ -69,13 +70,14 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
private final LicenseFeatureGuard licenseFeatureGuard;
|
||||
|
||||
public ImportTaskProcessorServiceImpl(ImportTaskService importTaskService,
|
||||
ProductSpecService productSpecService,
|
||||
ProductSkuService productSkuService,
|
||||
ProductSkuCostService productSkuCostService,
|
||||
OrderMapper orderMapper,
|
||||
OrderItemMapper orderItemMapper,
|
||||
ProductMapper productMapper,
|
||||
ShopProductRelationMapper shopProductRelationMapper,
|
||||
SseNotificationService sseNotificationService,
|
||||
ObjectMapper objectMapper,
|
||||
OrderStatusService orderStatusService,
|
||||
SqlSessionFactory sqlSessionFactory,
|
||||
OssService ossService,
|
||||
SysFileService sysFileService,
|
||||
@@ -94,10 +96,10 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
this.orderStatRefreshCoordinator = orderStatRefreshCoordinator;
|
||||
this.feeStatRefreshService = feeStatRefreshService;
|
||||
|
||||
ProductSpecImportHelper productSpecImportHelper = new ProductSpecImportHelper(
|
||||
productMapper, productSpecService, orderStatusService, shopProductRelationMapper);
|
||||
ProductSkuImportHelper productSkuImportHelper = new ProductSkuImportHelper(
|
||||
productMapper, productSkuService, productSkuCostService, shopProductRelationMapper);
|
||||
this.orderImportProcessor = new OrderImportProcessor(
|
||||
productSpecImportHelper, orderMapper, shopProductRelationMapper, sqlSessionFactory);
|
||||
productSkuImportHelper, orderMapper, orderItemMapper, shopProductRelationMapper, sqlSessionFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -145,12 +147,12 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
.collect(Collectors.toMap(
|
||||
ImportRuntimeContext.MappingField::getFieldName,
|
||||
field -> field, (v1, v2) -> v1));
|
||||
Map<String, Long> statusMapping = mappingConfig.getStatusMapping() != null
|
||||
Map<String, String> statusMapping = mappingConfig.getStatusMapping() != null
|
||||
? mappingConfig.getStatusMapping().stream()
|
||||
.filter(sm -> sm.getCsvStatus() != null && sm.getMappedStatusId() != null)
|
||||
.filter(sm -> sm.getCsvStatus() != null && sm.getMappedStatusCode() != null)
|
||||
.collect(Collectors.toMap(
|
||||
sm -> sm.getCsvStatus().trim(),
|
||||
ImportRuntimeContext.StatusMapping::getMappedStatusId,
|
||||
ImportRuntimeContext.StatusMapping::getMappedStatusCode,
|
||||
(v1, v2) -> v1))
|
||||
: java.util.Collections.emptyMap();
|
||||
|
||||
@@ -383,7 +385,11 @@ public class ImportTaskProcessorServiceImpl implements ImportTaskProcessorServic
|
||||
if (!statusNode.isObject()) continue;
|
||||
ImportRuntimeContext.StatusMapping sm = new ImportRuntimeContext.StatusMapping();
|
||||
if (statusNode.has("csvStatus")) sm.setCsvStatus(statusNode.get("csvStatus").asText());
|
||||
if (statusNode.has("mappedStatusId")) sm.setMappedStatusId(statusNode.get("mappedStatusId").asLong());
|
||||
if (statusNode.has("mappedStatusCode")) {
|
||||
sm.setMappedStatusCode(statusNode.get("mappedStatusCode").asText());
|
||||
} else if (statusNode.has("mappedStatusId")) {
|
||||
sm.setMappedStatusCode(statusNode.get("mappedStatusId").asText());
|
||||
}
|
||||
statusMappings.add(sm);
|
||||
}
|
||||
config.setStatusMapping(statusMappings);
|
||||
|
||||
+230
-184
@@ -7,10 +7,12 @@ import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.CreateOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopProductRelationPO;
|
||||
|
||||
@@ -46,17 +48,20 @@ public class OrderImportProcessor {
|
||||
private static final int PARALLELISM = 4; // Worker 线程数
|
||||
private static final int WORKER_TERMINATE_TIMEOUT_SEC = 60; // awaitTermination 超时
|
||||
|
||||
private final ProductSpecImportHelper specHelper;
|
||||
private final ProductSkuImportHelper skuHelper;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final ShopProductRelationMapper shopProductRelationMapper;
|
||||
private final SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public OrderImportProcessor(ProductSpecImportHelper specHelper,
|
||||
public OrderImportProcessor(ProductSkuImportHelper skuHelper,
|
||||
OrderMapper orderMapper,
|
||||
OrderItemMapper orderItemMapper,
|
||||
ShopProductRelationMapper shopProductRelationMapper,
|
||||
SqlSessionFactory sqlSessionFactory) {
|
||||
this.specHelper = specHelper;
|
||||
this.skuHelper = skuHelper;
|
||||
this.orderMapper = orderMapper;
|
||||
this.orderItemMapper = orderItemMapper;
|
||||
this.shopProductRelationMapper = shopProductRelationMapper;
|
||||
this.sqlSessionFactory = sqlSessionFactory;
|
||||
}
|
||||
@@ -72,7 +77,7 @@ public class OrderImportProcessor {
|
||||
public final Map<String, String> rowData;
|
||||
public final CreateOrderDTO dto;
|
||||
public final Map<String, ImportRuntimeContext.MappingField> fieldMapping;
|
||||
public final Map<String, Long> statusMapping;
|
||||
public final Map<String, String> statusMapping;
|
||||
public final Long shopId;
|
||||
public final Long companyId;
|
||||
public final Long createBy;
|
||||
@@ -91,7 +96,7 @@ public class OrderImportProcessor {
|
||||
|
||||
public PendingRow(int rowNumber, Map<String, String> rowData, CreateOrderDTO dto,
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping,
|
||||
Map<String, Long> statusMapping,
|
||||
Map<String, String> statusMapping,
|
||||
Long shopId, Long companyId, Long createBy) {
|
||||
this.rowNumber = rowNumber;
|
||||
this.rowData = rowData;
|
||||
@@ -111,35 +116,37 @@ public class OrderImportProcessor {
|
||||
public final int rowNumber;
|
||||
public final CreateOrderDTO dto;
|
||||
public final OrderPO order;
|
||||
public final OrderItemPO item;
|
||||
public final String platformOrderNo;
|
||||
public final StringBuilder updateMsg;
|
||||
public final boolean isUpdate;
|
||||
public final Exception parseException;
|
||||
|
||||
private OrderParseResult(int rowNumber, CreateOrderDTO dto, OrderPO order,
|
||||
private OrderParseResult(int rowNumber, CreateOrderDTO dto, OrderPO order, OrderItemPO item,
|
||||
String platformOrderNo, StringBuilder updateMsg,
|
||||
boolean isUpdate, Exception parseException) {
|
||||
this.rowNumber = rowNumber;
|
||||
this.dto = dto;
|
||||
this.order = order;
|
||||
this.item = item;
|
||||
this.platformOrderNo = platformOrderNo;
|
||||
this.updateMsg = updateMsg;
|
||||
this.isUpdate = isUpdate;
|
||||
this.parseException = parseException;
|
||||
}
|
||||
|
||||
public static OrderParseResult success(int rowNumber, CreateOrderDTO dto, OrderPO order,
|
||||
public static OrderParseResult success(int rowNumber, CreateOrderDTO dto, OrderPO order, OrderItemPO item,
|
||||
String platformOrderNo, boolean isUpdate) {
|
||||
return new OrderParseResult(rowNumber, dto, order, platformOrderNo, null, isUpdate, null);
|
||||
return new OrderParseResult(rowNumber, dto, order, item, platformOrderNo, null, isUpdate, null);
|
||||
}
|
||||
|
||||
public static OrderParseResult error(int rowNumber, Exception e) {
|
||||
return new OrderParseResult(rowNumber, null, null, null, null, false, e);
|
||||
return new OrderParseResult(rowNumber, null, null, null, null, null, false, e);
|
||||
}
|
||||
|
||||
public static OrderParseResult error(int rowNumber, String platformOrderNo,
|
||||
StringBuilder updateMsg, boolean isUpdate) {
|
||||
return new OrderParseResult(rowNumber, null, null, platformOrderNo, updateMsg, isUpdate, null);
|
||||
return new OrderParseResult(rowNumber, null, null, null, platformOrderNo, updateMsg, isUpdate, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +160,7 @@ public class OrderImportProcessor {
|
||||
File csvFile,
|
||||
Charset charset,
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping,
|
||||
Map<String, Long> statusMapping,
|
||||
Map<String, String> statusMapping,
|
||||
ImportRuntimeContext context,
|
||||
BiConsumer<Integer, Integer> progressCallback) {
|
||||
|
||||
@@ -170,14 +177,14 @@ public class OrderImportProcessor {
|
||||
.build())) {
|
||||
|
||||
// 收集预加载数据(主线程,单例执行)
|
||||
ImportRuntimeContext.MappingField specCodeField = fieldMapping.get("spec_code");
|
||||
ImportRuntimeContext.MappingField skuCodeField = skuCodeFieldOf(fieldMapping);
|
||||
ImportRuntimeContext.MappingField productCodeField = fieldMapping.get("product_code");
|
||||
ImportRuntimeContext.MappingField linkProductNameField = fieldMapping.get("link_product_name");
|
||||
ImportRuntimeContext.MappingField orderStatusField = fieldMapping.get("status");
|
||||
ImportRuntimeContext.MappingField platformOrderNoField = fieldMapping.get("platform_order_no");
|
||||
ImportRuntimeContext.MappingField orderDateField = fieldMapping.get("order_time");
|
||||
|
||||
Set<String> specCodes = new HashSet<>();
|
||||
Set<String> skuCodes = new HashSet<>();
|
||||
Set<String> productCodes = new HashSet<>();
|
||||
Set<String> productNames = new HashSet<>();
|
||||
Set<String> platformOrderNos = new HashSet<>();
|
||||
@@ -186,7 +193,7 @@ public class OrderImportProcessor {
|
||||
|
||||
for (CSVRecord record : csvParser) {
|
||||
records.add(record);
|
||||
context.addNormalizedValue(specCodes, getValue(record, specCodeField));
|
||||
context.addNormalizedValue(skuCodes, getValue(record, skuCodeField));
|
||||
context.addNormalizedValue(productCodes, getValue(record, productCodeField));
|
||||
context.addNormalizedValue(productNames, getValue(record, linkProductNameField));
|
||||
context.addNormalizedValue(platformOrderNos, getValue(record, platformOrderNoField));
|
||||
@@ -208,12 +215,12 @@ public class OrderImportProcessor {
|
||||
context.setOrderImportFieldMapping(fieldMapping);
|
||||
|
||||
// 预加载(主线程)
|
||||
specHelper.preloadProductSpecs(context, specCodes);
|
||||
specHelper.preloadProductsByCode(context, productCodes);
|
||||
specHelper.preloadProductsByName(context, productNames);
|
||||
specHelper.preloadPlatformOrderNos(context, platformOrderNos, orderMapper);
|
||||
specHelper.preloadStatuses(context, statusNames, statusMapping);
|
||||
specHelper.preloadShopProductRelations(context, shopProductRelationMapper);
|
||||
skuHelper.preloadProductSkus(context, skuCodes);
|
||||
skuHelper.preloadProductsByCode(context, productCodes);
|
||||
skuHelper.preloadProductsByName(context, productNames);
|
||||
skuHelper.preloadPlatformOrderNos(context, platformOrderNos, orderMapper, orderItemMapper);
|
||||
skuHelper.preloadStatuses(context, statusNames, statusMapping);
|
||||
skuHelper.preloadShopProductRelations(context, shopProductRelationMapper);
|
||||
|
||||
List<LocalDateTime> neighborOrderTimesByRow = buildNeighborOrderTimesForRows(
|
||||
records, orderDateField, r -> getValue(r, orderDateField), context);
|
||||
@@ -335,7 +342,7 @@ public class OrderImportProcessor {
|
||||
top.xyquan.ecomdmbbackend.modules.ecom.importtask.model.po.ImportTaskPO task,
|
||||
File excelFile,
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping,
|
||||
Map<String, Long> statusMapping,
|
||||
Map<String, String> statusMapping,
|
||||
ImportRuntimeContext context,
|
||||
BiConsumer<Integer, Integer> progressCallback) {
|
||||
|
||||
@@ -396,21 +403,21 @@ public class OrderImportProcessor {
|
||||
context.setOrderImportFieldMapping(fieldMapping);
|
||||
|
||||
// 预加载数据
|
||||
ImportRuntimeContext.MappingField specCodeField = fieldMapping.get("spec_code");
|
||||
ImportRuntimeContext.MappingField skuCodeField = skuCodeFieldOf(fieldMapping);
|
||||
ImportRuntimeContext.MappingField productCodeField = fieldMapping.get("product_code");
|
||||
ImportRuntimeContext.MappingField linkProductNameField = fieldMapping.get("link_product_name");
|
||||
ImportRuntimeContext.MappingField orderStatusField = fieldMapping.get("status");
|
||||
ImportRuntimeContext.MappingField platformOrderNoField = fieldMapping.get("platform_order_no");
|
||||
ImportRuntimeContext.MappingField orderDateField = fieldMapping.get("order_time");
|
||||
|
||||
Set<String> specCodes = new HashSet<>();
|
||||
Set<String> skuCodes = new HashSet<>();
|
||||
Set<String> productCodes = new HashSet<>();
|
||||
Set<String> productNames = new HashSet<>();
|
||||
Set<String> platformOrderNos = new HashSet<>();
|
||||
Set<String> statusNames = new HashSet<>();
|
||||
|
||||
for (Map<String, String> rowMap : rowDataList) {
|
||||
context.addNormalizedValue(specCodes, getValue(rowMap, specCodeField));
|
||||
context.addNormalizedValue(skuCodes, getValue(rowMap, skuCodeField));
|
||||
context.addNormalizedValue(productCodes, getValue(rowMap, productCodeField));
|
||||
context.addNormalizedValue(productNames, getValue(rowMap, linkProductNameField));
|
||||
context.addNormalizedValue(platformOrderNos, getValue(rowMap, platformOrderNoField));
|
||||
@@ -423,12 +430,12 @@ public class OrderImportProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
specHelper.preloadProductSpecs(context, specCodes);
|
||||
specHelper.preloadProductsByCode(context, productCodes);
|
||||
specHelper.preloadProductsByName(context, productNames);
|
||||
specHelper.preloadPlatformOrderNos(context, platformOrderNos, orderMapper);
|
||||
specHelper.preloadStatuses(context, statusNames, statusMapping);
|
||||
specHelper.preloadShopProductRelations(context, shopProductRelationMapper);
|
||||
skuHelper.preloadProductSkus(context, skuCodes);
|
||||
skuHelper.preloadProductsByCode(context, productCodes);
|
||||
skuHelper.preloadProductsByName(context, productNames);
|
||||
skuHelper.preloadPlatformOrderNos(context, platformOrderNos, orderMapper, orderItemMapper);
|
||||
skuHelper.preloadStatuses(context, statusNames, statusMapping);
|
||||
skuHelper.preloadShopProductRelations(context, shopProductRelationMapper);
|
||||
|
||||
List<LocalDateTime> neighborOrderTimesByRow = buildNeighborOrderTimesForRows(
|
||||
rowDataList, orderDateField, rowMap -> getValue(rowMap, orderDateField), context);
|
||||
@@ -545,8 +552,9 @@ public class OrderImportProcessor {
|
||||
|
||||
try {
|
||||
CreateOrderDTO dto = resolveProductAndSpec(row, context);
|
||||
OrderPO orderPO = buildOrderPO(dto, context.getCompanyId(),
|
||||
OrderPO orderPO = buildOrderHeader(dto, context.getCompanyId(),
|
||||
context.getCreateBy(), context.getTaskId(), context);
|
||||
OrderItemPO itemPO = buildOrderItem(dto, orderPO, context.getCompanyId(), context.getCreateBy());
|
||||
|
||||
String platformOrderNo = dto.getPlatformOrderNo();
|
||||
boolean isUpdate = false;
|
||||
@@ -560,7 +568,7 @@ public class OrderImportProcessor {
|
||||
}
|
||||
|
||||
synchronized (results) {
|
||||
results.add(OrderParseResult.success(row.rowNumber, dto, orderPO, platformOrderNo, isUpdate));
|
||||
results.add(OrderParseResult.success(row.rowNumber, dto, orderPO, itemPO, platformOrderNo, isUpdate));
|
||||
}
|
||||
context.processedCount.incrementAndGet();
|
||||
|
||||
@@ -623,11 +631,18 @@ public class OrderImportProcessor {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 导入映射:优先 sku_code,兼容旧 spec_code */
|
||||
private static ImportRuntimeContext.MappingField skuCodeFieldOf(
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping) {
|
||||
ImportRuntimeContext.MappingField f = fieldMapping.get("sku_code");
|
||||
return f != null ? f : fieldMapping.get("spec_code");
|
||||
}
|
||||
|
||||
// ==================== Map 版本的订单解析 ====================
|
||||
|
||||
CreateOrderDTO parseOrderFromMap(Map<String, String> rowData,
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping,
|
||||
Map<String, Long> statusMapping,
|
||||
Map<String, String> statusMapping,
|
||||
Long shopId, Long companyId, Long createBy,
|
||||
ImportRuntimeContext context,
|
||||
LocalDateTime neighborRowOrderTime) {
|
||||
@@ -646,24 +661,19 @@ public class OrderImportProcessor {
|
||||
if (statusField != null) {
|
||||
String statusStr = getValue(rowData, statusField);
|
||||
if (statusStr != null && !statusStr.trim().isEmpty()) {
|
||||
Long statusId = statusMapping.get(statusStr.trim());
|
||||
if (statusId != null) {
|
||||
dto.setStatusId(statusId);
|
||||
String statusCode = statusMapping.get(statusStr.trim());
|
||||
if (statusCode != null) {
|
||||
dto.setStatus(statusCode);
|
||||
} else {
|
||||
Long id = specHelper.findOrderStatusIdByName(
|
||||
context.getCompanyId(), statusStr, context);
|
||||
if (id != null) {
|
||||
dto.setStatusId(id);
|
||||
} else {
|
||||
id = specHelper.createOrderStatusIfNotExists(
|
||||
context.getCompanyId(), statusStr, createBy, context);
|
||||
dto.setStatusId(id);
|
||||
String code = skuHelper.resolveOrderStatusCode(statusStr, context);
|
||||
if (code != null) {
|
||||
dto.setStatus(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImportRuntimeContext.MappingField specCodeField = fieldMapping.get("spec_code");
|
||||
ImportRuntimeContext.MappingField skuCodeField = skuCodeFieldOf(fieldMapping);
|
||||
ImportRuntimeContext.MappingField productCodeField = fieldMapping.get("product_code");
|
||||
ImportRuntimeContext.MappingField linkProductNameField = fieldMapping.get("link_product_name");
|
||||
ImportRuntimeContext.MappingField quantityField = fieldMapping.get("product_quantity");
|
||||
@@ -674,10 +684,10 @@ public class OrderImportProcessor {
|
||||
ImportRuntimeContext.MappingField receivedAmountField = fieldMapping.get("received_amount");
|
||||
ImportRuntimeContext.MappingField orderDateField = fieldMapping.get("order_time");
|
||||
|
||||
String specCode = getValue(rowData, specCodeField);
|
||||
if (specCode == null || specCode.trim().isEmpty()) {
|
||||
if (specCodeField == null
|
||||
|| (specCodeField.getRequired() != null && specCodeField.getRequired())) {
|
||||
String skuCode = getValue(rowData, skuCodeField);
|
||||
if (skuCode == null || skuCode.trim().isEmpty()) {
|
||||
if (skuCodeField == null
|
||||
|| (skuCodeField.getRequired() != null && skuCodeField.getRequired())) {
|
||||
throw new BusinessException("规格编码不能为空");
|
||||
}
|
||||
}
|
||||
@@ -724,14 +734,14 @@ public class OrderImportProcessor {
|
||||
linkProductName = linkProductName.trim();
|
||||
if (linkProductName.isEmpty()) linkProductName = null;
|
||||
}
|
||||
String linkSpecName = getValue(rowData, fieldMapping.get("link_spec_name"));
|
||||
if (linkSpecName != null) {
|
||||
linkSpecName = linkSpecName.trim();
|
||||
if (linkSpecName.isEmpty()) linkSpecName = null;
|
||||
String linkSkuName = getValue(rowData, fieldMapping.get("link_spec_name"));
|
||||
if (linkSkuName != null) {
|
||||
linkSkuName = linkSkuName.trim();
|
||||
if (linkSkuName.isEmpty()) linkSkuName = null;
|
||||
}
|
||||
|
||||
dto.setLinkProductName(linkProductName);
|
||||
dto.setLinkSpecName(linkSpecName);
|
||||
dto.setLinkSkuName(linkSkuName);
|
||||
|
||||
if (quantityField != null) {
|
||||
String qtyStr = getValue(rowData, quantityField);
|
||||
@@ -851,9 +861,10 @@ public class OrderImportProcessor {
|
||||
// 执行商品/规格解析(Worker 线程)
|
||||
CreateOrderDTO dto = resolveProductAndSpec(row, context);
|
||||
|
||||
// 构建 OrderPO
|
||||
OrderPO orderPO = buildOrderPO(dto, context.getCompanyId(),
|
||||
// 构建主表 + 明细
|
||||
OrderPO orderPO = buildOrderHeader(dto, context.getCompanyId(),
|
||||
context.getCreateBy(), context.getTaskId(), context);
|
||||
OrderItemPO itemPO = buildOrderItem(dto, orderPO, context.getCompanyId(), context.getCreateBy());
|
||||
|
||||
// 检查是否为更新
|
||||
String platformOrderNo = dto.getPlatformOrderNo();
|
||||
@@ -868,7 +879,7 @@ public class OrderImportProcessor {
|
||||
}
|
||||
|
||||
synchronized (results) {
|
||||
results.add(OrderParseResult.success(row.rowNumber, dto, orderPO,
|
||||
results.add(OrderParseResult.success(row.rowNumber, dto, orderPO, itemPO,
|
||||
platformOrderNo, isUpdate));
|
||||
}
|
||||
context.processedCount.incrementAndGet();
|
||||
@@ -892,22 +903,22 @@ public class OrderImportProcessor {
|
||||
CreateOrderDTO dto = row.dto;
|
||||
Long companyId = row.companyId;
|
||||
|
||||
if (dto.getProductSpecId() == null) {
|
||||
if (dto.getProductSkuId() == null) {
|
||||
// 重新获取关键字段
|
||||
String specCodeRaw = getValue(row.rowData, row.fieldMapping.get("spec_code"));
|
||||
String skuCodeRaw = getValue(row.rowData, skuCodeFieldOf(row.fieldMapping));
|
||||
String productCode = getValue(row.rowData, row.fieldMapping.get("product_code"));
|
||||
String linkProductName = getValue(row.rowData, row.fieldMapping.get("link_product_name"));
|
||||
String linkSpecName = getValue(row.rowData, row.fieldMapping.get("link_spec_name"));
|
||||
String linkSkuName = getValue(row.rowData, row.fieldMapping.get("link_spec_name"));
|
||||
|
||||
if (specCodeRaw != null) specCodeRaw = specCodeRaw.trim();
|
||||
if (skuCodeRaw != null) skuCodeRaw = skuCodeRaw.trim();
|
||||
if (productCode != null) productCode = productCode.trim().isEmpty() ? null : productCode.trim();
|
||||
if (linkProductName != null) {
|
||||
linkProductName = linkProductName.trim();
|
||||
if (linkProductName.isEmpty()) linkProductName = null;
|
||||
}
|
||||
if (linkSpecName != null) {
|
||||
linkSpecName = linkSpecName.trim();
|
||||
if (linkSpecName.isEmpty()) linkSpecName = null;
|
||||
if (linkSkuName != null) {
|
||||
linkSkuName = linkSkuName.trim();
|
||||
if (linkSkuName.isEmpty()) linkSkuName = null;
|
||||
}
|
||||
// 二次从 CSV 读取失败时,回退到主线程 parseOrderFromCSV 已解析的 DTO 值。
|
||||
if ((linkProductName == null || linkProductName.isEmpty())
|
||||
@@ -915,30 +926,30 @@ public class OrderImportProcessor {
|
||||
&& !dto.getLinkProductName().trim().isEmpty()) {
|
||||
linkProductName = dto.getLinkProductName().trim();
|
||||
}
|
||||
if ((linkSpecName == null || linkSpecName.isEmpty())
|
||||
&& dto.getLinkSpecName() != null
|
||||
&& !dto.getLinkSpecName().trim().isEmpty()) {
|
||||
linkSpecName = dto.getLinkSpecName().trim();
|
||||
if ((linkSkuName == null || linkSkuName.isEmpty())
|
||||
&& dto.getLinkSkuName() != null
|
||||
&& !dto.getLinkSkuName().trim().isEmpty()) {
|
||||
linkSkuName = dto.getLinkSkuName().trim();
|
||||
}
|
||||
|
||||
if (specCodeRaw == null && productCode == null && linkProductName == null) {
|
||||
if (skuCodeRaw == null && productCode == null && linkProductName == null) {
|
||||
throw new BusinessException("商品信息为空");
|
||||
}
|
||||
|
||||
ProductSpecPO productSpec = null;
|
||||
ProductSkuPO productSku = null;
|
||||
boolean isNewSpecCreated = false;
|
||||
if (specCodeRaw != null && !specCodeRaw.isEmpty()) {
|
||||
productSpec = specHelper.findProductSpecBySpecCode(specCodeRaw, companyId, context);
|
||||
if (skuCodeRaw != null && !skuCodeRaw.isEmpty()) {
|
||||
productSku = skuHelper.findProductSkuBySkuCode(skuCodeRaw, companyId, context);
|
||||
}
|
||||
|
||||
if (productSpec == null) {
|
||||
if (productSku == null) {
|
||||
top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO product =
|
||||
specHelper.findProductForOrderImport(companyId, productCode, linkProductName, context);
|
||||
skuHelper.findProductForOrderImport(companyId, productCode, linkProductName, context);
|
||||
if (product != null) {
|
||||
String finalSpecName = (linkSpecName != null) ? linkSpecName : "未知规格";
|
||||
productSpec = specHelper.createSpecForProduct(
|
||||
companyId, product.getId(), finalSpecName,
|
||||
specCodeRaw != null ? specCodeRaw : null,
|
||||
String finalSkuName = (linkSkuName != null) ? linkSkuName : "未知规格";
|
||||
productSku = skuHelper.createSkuForProduct(
|
||||
companyId, product.getId(), finalSkuName,
|
||||
skuCodeRaw != null ? skuCodeRaw : null,
|
||||
row.createBy, context);
|
||||
isNewSpecCreated = true;
|
||||
} else {
|
||||
@@ -946,38 +957,36 @@ public class OrderImportProcessor {
|
||||
(linkProductName != null && !linkProductName.isEmpty()) ? linkProductName
|
||||
: (productCode != null && !productCode.isEmpty()) ? productCode
|
||||
: "未知商品";
|
||||
String finalSpecName = (linkSpecName != null) ? linkSpecName : "未知规格";
|
||||
productSpec = specHelper.createProductAndSpecIfNotExists(
|
||||
String finalSkuName = (linkSkuName != null) ? linkSkuName : "未知规格";
|
||||
productSku = skuHelper.createProductAndSkuIfNotExists(
|
||||
companyId, finalProductName, productCode,
|
||||
finalSpecName, specCodeRaw,
|
||||
finalSkuName, skuCodeRaw,
|
||||
row.createBy, context);
|
||||
isNewSpecCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (productSpec == null) {
|
||||
if (productSku == null) {
|
||||
throw new BusinessException("无法创建商品规格");
|
||||
}
|
||||
|
||||
dto.setShopRelationProductId(productSpec.getProductId());
|
||||
dto.setProductSpecId(productSpec.getId());
|
||||
dto.setSpecCode(productSpec.getSpecCode());
|
||||
dto.setShopRelationProductId(productSku.getProductId());
|
||||
dto.setProductSkuId(productSku.getId());
|
||||
dto.setSkuCode(productSku.getSkuCode());
|
||||
dto.setConfirm(isNewSpecCreated ? 0 : 1);
|
||||
|
||||
// linkProductName / linkSpecName fallback
|
||||
// linkProductName / linkSkuName fallback
|
||||
if (dto.getLinkProductName() == null || dto.getLinkProductName().isEmpty()) {
|
||||
top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO product =
|
||||
specHelper.getProductById(productSpec.getProductId(), context);
|
||||
skuHelper.getProductById(productSku.getProductId(), context);
|
||||
dto.setLinkProductName(product != null ? product.getName() : "未知商品");
|
||||
}
|
||||
if (dto.getLinkSpecName() == null || dto.getLinkSpecName().isEmpty()) {
|
||||
dto.setLinkSpecName(productSpec.getName());
|
||||
if (dto.getLinkSkuName() == null || dto.getLinkSkuName().isEmpty()) {
|
||||
dto.setLinkSkuName(productSku.getName());
|
||||
}
|
||||
|
||||
// 成本快照
|
||||
dto.setProductCost(productSpec.getProductCost() != null ? productSpec.getProductCost() : BigDecimal.ZERO);
|
||||
dto.setShippingCost(productSpec.getShippingCost() != null ? productSpec.getShippingCost() : BigDecimal.ZERO);
|
||||
dto.setOtherCost(productSpec.getOtherCost() != null ? productSpec.getOtherCost() : BigDecimal.ZERO);
|
||||
// 成本快照(从 SKU 成本表读当前生效值)
|
||||
skuHelper.fillSkuCostSnapshot(productSku.getId(), dto::setProductCost, dto::setShippingCost, dto::setOtherCost);
|
||||
}
|
||||
|
||||
return dto;
|
||||
@@ -1024,6 +1033,7 @@ public class OrderImportProcessor {
|
||||
r.platformOrderNo,
|
||||
context,
|
||||
r.order,
|
||||
r.item,
|
||||
r.rowNumber,
|
||||
r.order != null ? r.order.getId() : null,
|
||||
updateMsg,
|
||||
@@ -1034,15 +1044,15 @@ public class OrderImportProcessor {
|
||||
|
||||
ImportRuntimeContext.PendingOrderInsert pending =
|
||||
new ImportRuntimeContext.PendingOrderInsert(
|
||||
r.rowNumber, r.platformOrderNo, r.order,
|
||||
r.rowNumber, r.platformOrderNo, r.order, r.item,
|
||||
r.order.getId(), updateMsg,
|
||||
r.dto != null && Boolean.TRUE.equals(r.dto.getOrderTimeEmptyInInput()));
|
||||
if (r.order != null && r.order.getOrderTime() != null) {
|
||||
context.markOrderStatDirty(r.order.getShopId(), r.order.getOrderTime());
|
||||
}
|
||||
if (r.platformOrderNo != null && !r.platformOrderNo.trim().isEmpty()) {
|
||||
OrderPO snap = context.existingOrderSnapshotByPlatformNo.get(r.platformOrderNo.trim());
|
||||
context.markOrderStatDirtyFromSnapshot(snap);
|
||||
OrderImportSnapshot snap = context.existingOrderSnapshotByPlatformNo.get(r.platformOrderNo.trim());
|
||||
context.markOrderStatDirtyFromSnapshot(snap != null ? snap.getOrder() : null);
|
||||
}
|
||||
context.pendingOrders.add(pending);
|
||||
if (r.platformOrderNo != null && !r.platformOrderNo.trim().isEmpty()) {
|
||||
@@ -1093,12 +1103,12 @@ public class OrderImportProcessor {
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping = context.getOrderImportFieldMapping();
|
||||
for (ImportRuntimeContext.PendingOrderInsert p : updates) {
|
||||
String normalized = p.platformOrderNo != null ? p.platformOrderNo.trim() : null;
|
||||
OrderPO dbSnap = normalized != null ? context.existingOrderSnapshotByPlatformNo.get(normalized) : null;
|
||||
// 下单时间为空:仅当「除下单时间外」与库中一致时才跳过整单 UPDATE;若有其它字段变更则照常更新,并保留库中原下单时间
|
||||
OrderImportSnapshot dbSnap = normalized != null ? context.existingOrderSnapshotByPlatformNo.get(normalized) : null;
|
||||
// 下单时间为空:仅当「除下单时间外」与库中一致时才跳过整单 UPDATE
|
||||
if (p.orderTimeEmptyInInput
|
||||
&& fieldMapping.containsKey("order_time")
|
||||
&& dbSnap != null
|
||||
&& isOrderImportContentUnchanged(dbSnap, p.order, fieldMapping, true)) {
|
||||
&& isOrderImportContentUnchanged(dbSnap, p.order, p.item, fieldMapping, true)) {
|
||||
updateSkippedUnchanged++;
|
||||
if (p.platformOrderNo != null && !p.platformOrderNo.trim().isEmpty()) {
|
||||
context.pendingPlatformOrderNos.remove(normalized);
|
||||
@@ -1107,9 +1117,9 @@ public class OrderImportProcessor {
|
||||
continue;
|
||||
}
|
||||
if (p.orderTimeEmptyInInput && fieldMapping.containsKey("order_time") && dbSnap != null) {
|
||||
p.order.setOrderTime(dbSnap.getOrderTime());
|
||||
p.order.setOrderTime(dbSnap.getOrder().getOrderTime());
|
||||
}
|
||||
boolean unchanged = dbSnap != null && isOrderImportContentUnchanged(dbSnap, p.order, fieldMapping, false);
|
||||
boolean unchanged = dbSnap != null && isOrderImportContentUnchanged(dbSnap, p.order, p.item, fieldMapping, false);
|
||||
if (unchanged) {
|
||||
updateSkippedUnchanged++;
|
||||
if (p.platformOrderNo != null && !p.platformOrderNo.trim().isEmpty()) {
|
||||
@@ -1120,6 +1130,7 @@ public class OrderImportProcessor {
|
||||
}
|
||||
try {
|
||||
orderMapper.updateById(p.order);
|
||||
replaceImportItem(p.order.getId(), p.item);
|
||||
updateChanged++;
|
||||
if (p.updateMessages != null && p.updateMessages.length() > 0) {
|
||||
errorMessages.append(String.format("[更新] 第%d行:%s",
|
||||
@@ -1129,7 +1140,7 @@ public class OrderImportProcessor {
|
||||
if (normalized != null) {
|
||||
context.pendingPlatformOrderNos.remove(normalized);
|
||||
context.existingPlatformOrderNos.add(normalized);
|
||||
context.existingOrderSnapshotByPlatformNo.put(normalized, copyOrderImportSnapshot(p.order));
|
||||
context.existingOrderSnapshotByPlatformNo.put(normalized, copyOrderImportSnapshot(p.order, p.item));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
updateFail++;
|
||||
@@ -1155,46 +1166,55 @@ public class OrderImportProcessor {
|
||||
*
|
||||
* @param ignoreOrderTimeWhenComparing 为 true 时不比较 {@code order_time}(用于「输入下单时间为空且仅判断是否还有其它变更」)
|
||||
*/
|
||||
private static boolean isOrderImportContentUnchanged(OrderPO db, OrderPO incoming,
|
||||
private static boolean isOrderImportContentUnchanged(OrderImportSnapshot dbSnap, OrderPO incoming,
|
||||
OrderItemPO incomingItem,
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping,
|
||||
boolean ignoreOrderTimeWhenComparing) {
|
||||
if (fieldMapping == null) {
|
||||
fieldMapping = Collections.emptyMap();
|
||||
}
|
||||
OrderPO db = dbSnap.getOrder();
|
||||
OrderItemPO dbItem = dbSnap.getItem();
|
||||
if (db == null || incoming == null) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(db.getCompanyId(), incoming.getCompanyId())) return false;
|
||||
if (!Objects.equals(db.getShopId(), incoming.getShopId())) return false;
|
||||
if (!Objects.equals(db.getStatusId(), incoming.getStatusId())) return false;
|
||||
if (!Objects.equals(db.getStatus(), incoming.getStatus())) return false;
|
||||
|
||||
boolean compareProductBlock = fieldMapping.containsKey("spec_code")
|
||||
boolean compareProductBlock = fieldMapping.containsKey("sku_code")
|
||||
|| fieldMapping.containsKey("spec_code")
|
||||
|| fieldMapping.containsKey("product_code")
|
||||
|| fieldMapping.containsKey("link_product_name")
|
||||
|| fieldMapping.containsKey("link_spec_name");
|
||||
if (compareProductBlock) {
|
||||
if (!Objects.equals(db.getProductSpecId(), incoming.getProductSpecId())) return false;
|
||||
if (!normStrEq(db.getSpecCode(), incoming.getSpecCode())) return false;
|
||||
if (!normStrEq(db.getLinkProductName(), incoming.getLinkProductName())) return false;
|
||||
if (!normStrEq(db.getLinkSpecName(), incoming.getLinkSpecName())) return false;
|
||||
if (compareProductBlock && incomingItem != null) {
|
||||
if (dbItem != null) {
|
||||
if (!Objects.equals(dbItem.getProductSkuId(), incomingItem.getProductSkuId())) return false;
|
||||
if (!normStrEq(dbItem.getSkuCode(), incomingItem.getSkuCode())) return false;
|
||||
if (!normStrEq(dbItem.getLinkProductName(), incomingItem.getLinkProductName())) return false;
|
||||
if (!normStrEq(dbItem.getLinkSkuName(), incomingItem.getLinkSkuName())) return false;
|
||||
}
|
||||
}
|
||||
if (fieldMapping.containsKey("platform_order_no")) {
|
||||
if (!normStrEq(db.getPlatformOrderNo(), incoming.getPlatformOrderNo())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("product_quantity")) {
|
||||
if (!Objects.equals(db.getQuantity(), incoming.getQuantity())) return false;
|
||||
if (fieldMapping.containsKey("product_quantity") && incomingItem != null && dbItem != null) {
|
||||
if (!Objects.equals(dbItem.getQuantity(), incomingItem.getQuantity())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("unit_price")) {
|
||||
if (!decimalEq(db.getUnitPrice(), incoming.getUnitPrice())) return false;
|
||||
if (fieldMapping.containsKey("unit_price") && incomingItem != null && dbItem != null) {
|
||||
if (!decimalEq(dbItem.getUnitPrice(), incomingItem.getUnitPrice())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("product_cost")) {
|
||||
if (!decimalEq(db.getProductCost(), incoming.getProductCost())) return false;
|
||||
if (fieldMapping.containsKey("product_cost") && incomingItem != null && dbItem != null) {
|
||||
if (!decimalEq(dbItem.getProductCost(), incomingItem.getProductCost())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("shipping_cost")) {
|
||||
if (!decimalEq(db.getShippingCost(), incoming.getShippingCost())) return false;
|
||||
if (fieldMapping.containsKey("shipping_cost") && incomingItem != null && dbItem != null) {
|
||||
if (!decimalEq(dbItem.getShippingCost(), incomingItem.getShippingCost())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("other_cost")) {
|
||||
if (!decimalEq(db.getOtherCost(), incoming.getOtherCost())) return false;
|
||||
if (fieldMapping.containsKey("other_cost") && incomingItem != null && dbItem != null) {
|
||||
if (!decimalEq(dbItem.getOtherCost(), incomingItem.getOtherCost())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("received_amount")) {
|
||||
if (!decimalEq(db.getReceivedAmount(), incoming.getReceivedAmount())) return false;
|
||||
if (!decimalEq(db.getPayAmount(), incoming.getPayAmount())) return false;
|
||||
}
|
||||
if (fieldMapping.containsKey("order_time") && !ignoreOrderTimeWhenComparing) {
|
||||
if (!orderTimeEqualsForImport(db.getOrderTime(), incoming.getOrderTime())) return false;
|
||||
@@ -1232,35 +1252,52 @@ public class OrderImportProcessor {
|
||||
}
|
||||
|
||||
/** 写入内存快照,避免后续同单号批次仍用旧快照比较 */
|
||||
private static OrderPO copyOrderImportSnapshot(OrderPO o) {
|
||||
OrderPO c = new OrderPO();
|
||||
c.setId(o.getId());
|
||||
c.setCompanyId(o.getCompanyId());
|
||||
c.setShopId(o.getShopId());
|
||||
c.setPlatformOrderNo(o.getPlatformOrderNo());
|
||||
c.setStatusId(o.getStatusId());
|
||||
c.setProductSpecId(o.getProductSpecId());
|
||||
c.setSpecCode(o.getSpecCode());
|
||||
c.setLinkProductName(o.getLinkProductName());
|
||||
c.setLinkSpecName(o.getLinkSpecName());
|
||||
c.setQuantity(o.getQuantity());
|
||||
c.setUnitPrice(o.getUnitPrice());
|
||||
c.setProductCost(o.getProductCost());
|
||||
c.setShippingCost(o.getShippingCost());
|
||||
c.setOtherCost(o.getOtherCost());
|
||||
c.setReceivedAmount(o.getReceivedAmount());
|
||||
c.setOrderTime(o.getOrderTime());
|
||||
c.setConfirm(o.getConfirm());
|
||||
return c;
|
||||
private static OrderImportSnapshot copyOrderImportSnapshot(OrderPO o, OrderItemPO item) {
|
||||
OrderPO header = new OrderPO();
|
||||
header.setId(o.getId());
|
||||
header.setCompanyId(o.getCompanyId());
|
||||
header.setShopId(o.getShopId());
|
||||
header.setPlatformOrderNo(o.getPlatformOrderNo());
|
||||
header.setStatus(o.getStatus());
|
||||
header.setPayAmount(o.getPayAmount());
|
||||
header.setOrderTime(o.getOrderTime());
|
||||
header.setConfirm(o.getConfirm());
|
||||
OrderItemPO itemCopy = null;
|
||||
if (item != null) {
|
||||
itemCopy = new OrderItemPO();
|
||||
itemCopy.setProductSkuId(item.getProductSkuId());
|
||||
itemCopy.setSkuCode(item.getSkuCode());
|
||||
itemCopy.setLinkProductName(item.getLinkProductName());
|
||||
itemCopy.setLinkSkuName(item.getLinkSkuName());
|
||||
itemCopy.setQuantity(item.getQuantity());
|
||||
itemCopy.setUnitPrice(item.getUnitPrice());
|
||||
itemCopy.setProductCost(item.getProductCost());
|
||||
itemCopy.setShippingCost(item.getShippingCost());
|
||||
itemCopy.setOtherCost(item.getOtherCost());
|
||||
}
|
||||
return new OrderImportSnapshot(header, itemCopy);
|
||||
}
|
||||
|
||||
private void replaceImportItem(Long orderId, OrderItemPO item) {
|
||||
if (orderId == null || item == null) {
|
||||
return;
|
||||
}
|
||||
orderItemMapper.delete(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getOrderId, orderId));
|
||||
item.setOrderId(orderId);
|
||||
orderItemMapper.insert(item);
|
||||
}
|
||||
|
||||
private int[] doBatchInsert(List<ImportRuntimeContext.PendingOrderInsert> inserts,
|
||||
ImportRuntimeContext context, StringBuilder errorMessages) {
|
||||
int success = 0, fail = 0;
|
||||
try (SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH, false)) {
|
||||
OrderMapper batchMapper = session.getMapper(OrderMapper.class);
|
||||
OrderMapper batchOrderMapper = session.getMapper(OrderMapper.class);
|
||||
OrderItemMapper batchItemMapper = session.getMapper(OrderItemMapper.class);
|
||||
for (ImportRuntimeContext.PendingOrderInsert p : inserts) {
|
||||
batchMapper.insert(p.order);
|
||||
batchOrderMapper.insert(p.order);
|
||||
p.item.setOrderId(p.order.getId());
|
||||
batchItemMapper.insert(p.item);
|
||||
}
|
||||
session.flushStatements();
|
||||
session.commit();
|
||||
@@ -1276,6 +1313,8 @@ public class OrderImportProcessor {
|
||||
for (ImportRuntimeContext.PendingOrderInsert p : inserts) {
|
||||
try {
|
||||
orderMapper.insert(p.order);
|
||||
p.item.setOrderId(p.order.getId());
|
||||
orderItemMapper.insert(p.item);
|
||||
success++;
|
||||
if (p.platformOrderNo != null && !p.platformOrderNo.trim().isEmpty()) {
|
||||
String normalized = p.platformOrderNo.trim();
|
||||
@@ -1335,7 +1374,7 @@ public class OrderImportProcessor {
|
||||
*/
|
||||
CreateOrderDTO parseOrderFromCSV(CSVRecord record,
|
||||
Map<String, ImportRuntimeContext.MappingField> fieldMapping,
|
||||
Map<String, Long> statusMapping,
|
||||
Map<String, String> statusMapping,
|
||||
Long shopId, Long companyId, Long createBy,
|
||||
ImportRuntimeContext context,
|
||||
LocalDateTime neighborRowOrderTime) {
|
||||
@@ -1354,24 +1393,19 @@ public class OrderImportProcessor {
|
||||
if (statusField != null) {
|
||||
String statusStr = getValue(record, statusField);
|
||||
if (statusStr != null && !statusStr.trim().isEmpty()) {
|
||||
Long statusId = statusMapping.get(statusStr.trim());
|
||||
if (statusId != null) {
|
||||
dto.setStatusId(statusId);
|
||||
String statusCode = statusMapping.get(statusStr.trim());
|
||||
if (statusCode != null) {
|
||||
dto.setStatus(statusCode);
|
||||
} else {
|
||||
Long id = specHelper.findOrderStatusIdByName(
|
||||
context.getCompanyId(), statusStr, context);
|
||||
if (id != null) {
|
||||
dto.setStatusId(id);
|
||||
} else {
|
||||
id = specHelper.createOrderStatusIfNotExists(
|
||||
context.getCompanyId(), statusStr, createBy, context);
|
||||
dto.setStatusId(id);
|
||||
String code = skuHelper.resolveOrderStatusCode(statusStr, context);
|
||||
if (code != null) {
|
||||
dto.setStatus(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImportRuntimeContext.MappingField specCodeField = fieldMapping.get("spec_code");
|
||||
ImportRuntimeContext.MappingField skuCodeField = skuCodeFieldOf(fieldMapping);
|
||||
ImportRuntimeContext.MappingField productCodeField = fieldMapping.get("product_code");
|
||||
ImportRuntimeContext.MappingField linkProductNameField = fieldMapping.get("link_product_name");
|
||||
ImportRuntimeContext.MappingField quantityField = fieldMapping.get("product_quantity");
|
||||
@@ -1382,11 +1416,11 @@ public class OrderImportProcessor {
|
||||
ImportRuntimeContext.MappingField receivedAmountField = fieldMapping.get("received_amount");
|
||||
ImportRuntimeContext.MappingField orderDateField = fieldMapping.get("order_time");
|
||||
|
||||
String specCode = getValue(record, specCodeField);
|
||||
if (specCode == null || specCode.trim().isEmpty()) {
|
||||
String skuCode = getValue(record, skuCodeField);
|
||||
if (skuCode == null || skuCode.trim().isEmpty()) {
|
||||
// 必填但未填,或未配置映射:任务消息仅提示简短文案
|
||||
if (specCodeField == null
|
||||
|| (specCodeField.getRequired() != null && specCodeField.getRequired())) {
|
||||
if (skuCodeField == null
|
||||
|| (skuCodeField.getRequired() != null && skuCodeField.getRequired())) {
|
||||
throw new BusinessException("规格编码不能为空");
|
||||
}
|
||||
}
|
||||
@@ -1435,14 +1469,14 @@ public class OrderImportProcessor {
|
||||
linkProductName = linkProductName.trim();
|
||||
if (linkProductName.isEmpty()) linkProductName = null;
|
||||
}
|
||||
String linkSpecName = getValue(record, fieldMapping.get("link_spec_name"));
|
||||
if (linkSpecName != null) {
|
||||
linkSpecName = linkSpecName.trim();
|
||||
if (linkSpecName.isEmpty()) linkSpecName = null;
|
||||
String linkSkuName = getValue(record, fieldMapping.get("link_spec_name"));
|
||||
if (linkSkuName != null) {
|
||||
linkSkuName = linkSkuName.trim();
|
||||
if (linkSkuName.isEmpty()) linkSkuName = null;
|
||||
}
|
||||
|
||||
dto.setLinkProductName(linkProductName);
|
||||
dto.setLinkSpecName(linkSpecName);
|
||||
dto.setLinkSkuName(linkSkuName);
|
||||
|
||||
// 数量(可能已在上面解析过,但这里也会重复解析,取后者)
|
||||
if (quantityField != null) {
|
||||
@@ -1504,26 +1538,18 @@ public class OrderImportProcessor {
|
||||
// ==================== 订单构建 ====================
|
||||
|
||||
/**
|
||||
* 构建 OrderPO(Worker 线程调用)
|
||||
* 构建订单主表(Worker 线程调用)
|
||||
*/
|
||||
private OrderPO buildOrderPO(CreateOrderDTO dto, Long companyId, Long createBy,
|
||||
Long importTaskId, ImportRuntimeContext context) {
|
||||
private OrderPO buildOrderHeader(CreateOrderDTO dto, Long companyId, Long createBy,
|
||||
Long importTaskId, ImportRuntimeContext context) {
|
||||
OrderPO order = new OrderPO();
|
||||
order.setCompanyId(companyId);
|
||||
order.setShopId(dto.getShopId());
|
||||
order.setPlatformOrderNo(dto.getPlatformOrderNo());
|
||||
order.setStatusId(dto.getStatusId());
|
||||
order.setProductSpecId(dto.getProductSpecId());
|
||||
order.setSpecCode(dto.getSpecCode());
|
||||
order.setLinkProductName(dto.getLinkProductName());
|
||||
order.setLinkSpecName(dto.getLinkSpecName());
|
||||
order.setQuantity(dto.getQuantity());
|
||||
order.setUnitPrice(dto.getUnitPrice());
|
||||
order.setProductCost(dto.getProductCost());
|
||||
order.setShippingCost(dto.getShippingCost());
|
||||
order.setOtherCost(dto.getOtherCost());
|
||||
order.setReceivedAmount(dto.getReceivedAmount());
|
||||
order.setStatus(dto.getStatus());
|
||||
order.setPayAmount(dto.getPayAmount());
|
||||
order.setOrderTime(dto.getOrderTime());
|
||||
order.setSource("import");
|
||||
order.setCreateBy(createBy);
|
||||
order.setImportTaskId(importTaskId);
|
||||
order.setConfirm(dto.getConfirm() != null ? dto.getConfirm() : 1);
|
||||
@@ -1536,13 +1562,33 @@ public class OrderImportProcessor {
|
||||
return order;
|
||||
}
|
||||
|
||||
/** 构建首行明细(当前一行一单,line_no=1) */
|
||||
private OrderItemPO buildOrderItem(CreateOrderDTO dto, OrderPO order, Long companyId, Long createBy) {
|
||||
OrderItemPO item = new OrderItemPO();
|
||||
item.setCompanyId(companyId);
|
||||
item.setShopId(order.getShopId());
|
||||
item.setLineNo(1);
|
||||
item.setProductSkuId(dto.getProductSkuId());
|
||||
item.setProductId(dto.getShopRelationProductId());
|
||||
item.setSkuCode(dto.getSkuCode());
|
||||
item.setLinkProductName(dto.getLinkProductName());
|
||||
item.setLinkSkuName(dto.getLinkSkuName());
|
||||
item.setQuantity(dto.getQuantity());
|
||||
item.setUnitPrice(dto.getUnitPrice());
|
||||
item.setProductCost(dto.getProductCost() != null ? dto.getProductCost() : BigDecimal.ZERO);
|
||||
item.setShippingCost(dto.getShippingCost() != null ? dto.getShippingCost() : BigDecimal.ZERO);
|
||||
item.setOtherCost(dto.getOtherCost() != null ? dto.getOtherCost() : BigDecimal.ZERO);
|
||||
item.setCreateBy(createBy);
|
||||
return item;
|
||||
}
|
||||
|
||||
// ==================== 平台订单号校验 ====================
|
||||
|
||||
/**
|
||||
* 校验平台订单号是否重复(主线程 flush 时调用,每次处理批量结果)
|
||||
*/
|
||||
private boolean validatePlatformOrderNo(String platformOrderNo, ImportRuntimeContext context,
|
||||
OrderPO newOrderPO, int newRowNumber,
|
||||
OrderPO newOrderPO, OrderItemPO newItemPO, int newRowNumber,
|
||||
Long newExistingOrderId, StringBuilder newUpdateMsg,
|
||||
boolean newOrderTimeEmptyInInput) {
|
||||
if (platformOrderNo == null || platformOrderNo.trim().isEmpty()) return false;
|
||||
@@ -1558,13 +1604,13 @@ public class OrderImportProcessor {
|
||||
ImportRuntimeContext.PendingOrderInsert existing =
|
||||
context.pendingOrderByPlatformNo.get(normalized);
|
||||
if (existing != null) {
|
||||
existing.updateData(newOrderPO, existingId, newUpdateMsg, newRowNumber,
|
||||
existing.updateData(newOrderPO, newItemPO, existingId, newUpdateMsg, newRowNumber,
|
||||
newOrderTimeEmptyInInput);
|
||||
if (newOrderPO != null && newOrderPO.getOrderTime() != null) {
|
||||
context.markOrderStatDirty(newOrderPO.getShopId(), newOrderPO.getOrderTime());
|
||||
}
|
||||
OrderPO snap = context.existingOrderSnapshotByPlatformNo.get(normalized);
|
||||
context.markOrderStatDirtyFromSnapshot(snap);
|
||||
OrderImportSnapshot snap = context.existingOrderSnapshotByPlatformNo.get(normalized);
|
||||
context.markOrderStatDirtyFromSnapshot(snap != null ? snap.getOrder() : null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importtask.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
|
||||
/**
|
||||
* 导入场景订单快照(主表 + 首行明细,当前一行一单)
|
||||
*/
|
||||
public class OrderImportSnapshot {
|
||||
|
||||
private OrderPO order;
|
||||
private OrderItemPO item;
|
||||
|
||||
public OrderImportSnapshot() {
|
||||
}
|
||||
|
||||
public OrderImportSnapshot(OrderPO order, OrderItemPO item) {
|
||||
this.order = order;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public OrderPO getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(OrderPO order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public OrderItemPO getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(OrderItemPO item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
+154
-157
@@ -5,14 +5,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.enums.OrderStatus;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductSpecDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopProductRelationMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopProductRelationPO;
|
||||
|
||||
@@ -25,40 +28,50 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 商品/规格查找与创建辅助类
|
||||
* 商品/SKU查找与创建辅助类
|
||||
* <p>
|
||||
* 职责:
|
||||
* - 商品/规格/状态缓存查找
|
||||
* - 商品/规格/状态创建
|
||||
* - 商品/SKU/状态缓存查找
|
||||
* - 商品/SKU/状态创建
|
||||
* - 预加载(填充 ImportRuntimeContext)
|
||||
*/
|
||||
public class ProductSpecImportHelper {
|
||||
public class ProductSkuImportHelper {
|
||||
|
||||
private static final int IN_QUERY_BATCH_SIZE = 1000;
|
||||
/** 与 {@link ImportRuntimeContext#productByCodeAndNameCache} 键拼接,避免与名称字符冲突 */
|
||||
private static final char PRODUCT_CODE_NAME_SEP = '\u0001';
|
||||
|
||||
private final ProductMapper productMapper;
|
||||
private final ProductSpecService productSpecService;
|
||||
private final OrderStatusService orderStatusService;
|
||||
private final ProductSkuService productSkuService;
|
||||
private final ProductSkuCostService productSkuCostService;
|
||||
private final ShopProductRelationMapper shopProductRelationMapper;
|
||||
|
||||
public ProductSpecImportHelper(ProductMapper productMapper,
|
||||
ProductSpecService productSpecService,
|
||||
OrderStatusService orderStatusService,
|
||||
public ProductSkuImportHelper(ProductMapper productMapper,
|
||||
ProductSkuService productSkuService,
|
||||
ProductSkuCostService productSkuCostService,
|
||||
ShopProductRelationMapper shopProductRelationMapper) {
|
||||
this.productMapper = productMapper;
|
||||
this.productSpecService = productSpecService;
|
||||
this.orderStatusService = orderStatusService;
|
||||
this.productSkuService = productSkuService;
|
||||
this.productSkuCostService = productSkuCostService;
|
||||
this.shopProductRelationMapper = shopProductRelationMapper;
|
||||
}
|
||||
|
||||
/** 将 SKU 当前生效成本写入订单 DTO 快照字段 */
|
||||
public void fillSkuCostSnapshot(Long skuId, java.util.function.Consumer<java.math.BigDecimal> productCostSetter,
|
||||
java.util.function.Consumer<java.math.BigDecimal> shippingCostSetter,
|
||||
java.util.function.Consumer<java.math.BigDecimal> otherCostSetter) {
|
||||
var cost = productSkuCostService.getCurrentCost(skuId);
|
||||
productCostSetter.accept(cost != null && cost.getProductCost() != null ? cost.getProductCost() : BigDecimal.ZERO);
|
||||
shippingCostSetter.accept(cost != null && cost.getShippingCost() != null ? cost.getShippingCost() : BigDecimal.ZERO);
|
||||
otherCostSetter.accept(cost != null && cost.getOtherCost() != null ? cost.getOtherCost() : BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
// ==================== 缓存查找 ====================
|
||||
|
||||
public ProductSpecPO findProductSpecBySpecCode(String specCode, Long companyId,
|
||||
public ProductSkuPO findProductSkuBySkuCode(String skuCode, Long companyId,
|
||||
ImportRuntimeContext context) {
|
||||
if (specCode == null || specCode.trim().isEmpty()) return null;
|
||||
return context.specByCodeCache.get(specCode.trim());
|
||||
if (skuCode == null || skuCode.trim().isEmpty()) return null;
|
||||
return context.skuByCodeCache.get(skuCode.trim());
|
||||
}
|
||||
|
||||
public ProductPO findProductByProductCode(String productCode, Long companyId,
|
||||
@@ -193,42 +206,43 @@ public class ProductSpecImportHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
private ProductSpecPO selectSpecByCompanyAndSpecCodeFromDb(Long companyId, String specCode) {
|
||||
if (specCode == null || specCode.isEmpty()) {
|
||||
private ProductSkuPO selectSkuByCompanyAndSkuCodeFromDb(Long companyId, String skuCode) {
|
||||
if (skuCode == null || skuCode.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
LambdaQueryWrapper<ProductSpecPO> w = new LambdaQueryWrapper<>();
|
||||
w.eq(ProductSpecPO::getCompanyId, companyId).eq(ProductSpecPO::getSpecCode, specCode);
|
||||
return productSpecService.getOne(w);
|
||||
LambdaQueryWrapper<ProductSkuPO> w = new LambdaQueryWrapper<>();
|
||||
w.eq(ProductSkuPO::getCompanyId, companyId).eq(ProductSkuPO::getSkuCode, skuCode);
|
||||
return productSkuService.getOne(w);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单导入插入规格:同公司已存在该规格编码时<strong>不更新</strong>已有行,直接复用;
|
||||
* 不存在则新建(走 {@link ProductSpecService#createProductSpecForImport},与其它入口一致)。
|
||||
* 订单导入插入SKU:同公司已存在该SKU编码时<strong>不更新</strong>已有行,直接复用;
|
||||
* 不存在则新建(走 {@link ProductSkuService#createProductSkuForImport},与其它入口一致)。
|
||||
* 并发下仍可能触发唯一约束,则回查已存在行。
|
||||
*/
|
||||
private ProductSpecPO insertSpecOrFetchExisting(ProductSpecPO draft, Long companyId,
|
||||
ImportRuntimeContext context) {
|
||||
String rawCode = draft.getSpecCode();
|
||||
private ProductSkuPO insertSkuOrFetchExisting(ProductSkuPO draft, BigDecimal productCost,
|
||||
BigDecimal shippingCost, BigDecimal otherCost,
|
||||
Long companyId, ImportRuntimeContext context) {
|
||||
String rawCode = draft.getSkuCode();
|
||||
if (rawCode != null && !rawCode.trim().isEmpty()) {
|
||||
ProductSpecPO existing = selectSpecByCompanyAndSpecCodeFromDb(companyId, rawCode.trim());
|
||||
ProductSkuPO existing = selectSkuByCompanyAndSkuCodeFromDb(companyId, rawCode.trim());
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
CreateProductSpecDTO dto = new CreateProductSpecDTO();
|
||||
CreateProductSkuDTO dto = new CreateProductSkuDTO();
|
||||
dto.setProductId(draft.getProductId());
|
||||
dto.setName(draft.getName());
|
||||
dto.setSpecCode(draft.getSpecCode());
|
||||
dto.setProductCost(draft.getProductCost());
|
||||
dto.setShippingCost(draft.getShippingCost());
|
||||
dto.setOtherCost(draft.getOtherCost());
|
||||
dto.setSkuCode(draft.getSkuCode());
|
||||
dto.setProductCost(productCost != null ? productCost : BigDecimal.ZERO);
|
||||
dto.setShippingCost(shippingCost);
|
||||
dto.setOtherCost(otherCost);
|
||||
dto.setRemark(draft.getRemark());
|
||||
Long createBy = draft.getCreateBy();
|
||||
try {
|
||||
return productSpecService.getById(
|
||||
productSpecService.createProductSpecForImport(dto, companyId, createBy).getId());
|
||||
return productSkuService.getById(
|
||||
productSkuService.createProductSkuForImport(dto, companyId, createBy).getId());
|
||||
} catch (Exception ex) {
|
||||
if (!isDuplicateKeyException(ex)) {
|
||||
if (ex instanceof RuntimeException re) {
|
||||
@@ -236,66 +250,63 @@ public class ProductSpecImportHelper {
|
||||
}
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
String code = draft.getSpecCode();
|
||||
String code = draft.getSkuCode();
|
||||
if (code == null || code.trim().isEmpty()) {
|
||||
throw new BusinessException(
|
||||
"规格因唯一约束已存在但规格编码为空,无法回查已存在记录");
|
||||
"SKU因唯一约束已存在但SKU编码为空,无法回查已存在记录");
|
||||
}
|
||||
ProductSpecPO existing = selectSpecByCompanyAndSpecCodeFromDb(companyId, code.trim());
|
||||
ProductSkuPO existing = selectSkuByCompanyAndSkuCodeFromDb(companyId, code.trim());
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
throw new BusinessException(
|
||||
"规格因唯一约束已存在但重新查询失败,请稍后重试导入");
|
||||
"SKU因唯一约束已存在但重新查询失败,请稍后重试导入");
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 商品/规格创建 ====================
|
||||
// ==================== 商品/SKU创建 ====================
|
||||
|
||||
/**
|
||||
* 根据已知商品创建规格(跳过 selectById)
|
||||
* 根据已知商品创建SKU(跳过 selectById)
|
||||
*/
|
||||
public ProductSpecPO createSpecForProduct(ProductPO product, String specCode, String specName,
|
||||
public ProductSkuPO createSkuForProduct(ProductPO product, String skuCode, String skuName,
|
||||
BigDecimal productCost, Long companyId,
|
||||
Long createBy, ImportRuntimeContext context) {
|
||||
if (product == null) {
|
||||
throw new BusinessException("商品不能为空");
|
||||
}
|
||||
|
||||
String trimmedCode = specCode != null ? specCode.trim() : null;
|
||||
String trimmedName = specName != null ? specName.trim() : null;
|
||||
String trimmedCode = skuCode != null ? skuCode.trim() : null;
|
||||
String trimmedName = skuName != null ? skuName.trim() : null;
|
||||
|
||||
// 检查缓存(插入前再读一次,减少并行线程重复 insert)
|
||||
if (trimmedCode != null) {
|
||||
ProductSpecPO existing = context.specByCodeCache.get(trimmedCode);
|
||||
ProductSkuPO existing = context.skuByCodeCache.get(trimmedCode);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
}
|
||||
|
||||
// 创建规格
|
||||
ProductSpecPO spec = new ProductSpecPO();
|
||||
spec.setProductId(product.getId());
|
||||
spec.setCompanyId(companyId);
|
||||
spec.setSpecCode(trimmedCode);
|
||||
String finalSpecName = trimmedName != null ? trimmedName : (trimmedCode != null ? trimmedCode : "未知规格");
|
||||
spec.setName(finalSpecName);
|
||||
spec.setProductCost(productCost != null ? productCost : BigDecimal.ZERO);
|
||||
spec.setCreateBy(createBy);
|
||||
spec = insertSpecOrFetchExisting(spec, companyId, context);
|
||||
ProductSkuPO sku = new ProductSkuPO();
|
||||
sku.setProductId(product.getId());
|
||||
sku.setCompanyId(companyId);
|
||||
sku.setSkuCode(trimmedCode);
|
||||
String finalSkuName = trimmedName != null ? trimmedName : (trimmedCode != null ? trimmedCode : "未知SKU");
|
||||
sku.setName(finalSkuName);
|
||||
sku.setCreateBy(createBy);
|
||||
sku = insertSkuOrFetchExisting(sku, productCost, null, null, companyId, context);
|
||||
|
||||
// 写入缓存(有编码时以编码为键;并发冲突回查得到的行也写入)
|
||||
if (trimmedCode != null) {
|
||||
context.specByCodeCache.put(trimmedCode, spec);
|
||||
context.skuByCodeCache.put(trimmedCode, sku);
|
||||
}
|
||||
return spec;
|
||||
return sku;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找或创建商品,再查找或创建规格
|
||||
* 查找或创建商品,再查找或创建SKU
|
||||
*/
|
||||
public ProductSpecPO createProductAndSpecIfNotExists(String productCode, String productName,
|
||||
String specCode, String specName,
|
||||
public ProductSkuPO createProductAndSkuIfNotExists(String productCode, String productName,
|
||||
String skuCode, String skuName,
|
||||
BigDecimal productCost, Long companyId,
|
||||
Long createBy, ImportRuntimeContext context) {
|
||||
String trimmedCode = productCode != null ? productCode.trim() : null;
|
||||
@@ -321,64 +332,64 @@ public class ProductSpecImportHelper {
|
||||
cacheProduct(context, product);
|
||||
}
|
||||
|
||||
return createSpecForProduct(product, specCode, specName, productCost, companyId, createBy, context);
|
||||
return createSkuForProduct(product, skuCode, skuName, productCost, companyId, createBy, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据规格编码查找规格,找不到则按"编码创建规格/无编码返回空"逻辑处理
|
||||
* 根据SKU编码查找SKU,找不到则按"编码创建SKU/无编码返回空"逻辑处理
|
||||
*/
|
||||
public ProductSpecPO createSpecForProduct(String productCode, String productName,
|
||||
String specCode, String specName,
|
||||
public ProductSkuPO createSkuForProduct(String productCode, String productName,
|
||||
String skuCode, String skuName,
|
||||
BigDecimal productCost, Long companyId,
|
||||
Long createBy, ImportRuntimeContext context) {
|
||||
String trimmedSpecCode = specCode != null ? specCode.trim() : null;
|
||||
if (trimmedSpecCode != null && !trimmedSpecCode.isEmpty()) {
|
||||
ProductSpecPO existing = findProductSpecBySpecCode(trimmedSpecCode, companyId, context);
|
||||
String trimmedSkuCode = skuCode != null ? skuCode.trim() : null;
|
||||
if (trimmedSkuCode != null && !trimmedSkuCode.isEmpty()) {
|
||||
ProductSkuPO existing = findProductSkuBySkuCode(trimmedSkuCode, companyId, context);
|
||||
if (existing != null) return existing;
|
||||
return createProductAndSpecIfNotExists(productCode, productName, specCode, specName,
|
||||
return createProductAndSkuIfNotExists(productCode, productName, skuCode, skuName,
|
||||
productCost, companyId, createBy, context);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProductSpecPO createSpecForProductWithValidation(String productCode, String productName,
|
||||
String specCode, String specName,
|
||||
public ProductSkuPO createSkuForProductWithValidation(String productCode, String productName,
|
||||
String skuCode, String skuName,
|
||||
BigDecimal productCost, Long companyId,
|
||||
Long createBy, ImportRuntimeContext context) {
|
||||
String trimmedSpecCode = specCode != null ? specCode.trim() : null;
|
||||
String trimmedSpecName = specName != null ? specName.trim() : null;
|
||||
String trimmedSkuCode = skuCode != null ? skuCode.trim() : null;
|
||||
String trimmedSkuName = skuName != null ? skuName.trim() : null;
|
||||
|
||||
if (trimmedSpecCode == null || trimmedSpecCode.isEmpty()) {
|
||||
throw new BusinessException("规格编码不能为空");
|
||||
if (trimmedSkuCode == null || trimmedSkuCode.isEmpty()) {
|
||||
throw new BusinessException("SKU编码不能为空");
|
||||
}
|
||||
if (trimmedSpecName == null || trimmedSpecName.isEmpty()) {
|
||||
throw new BusinessException("规格名称不能为空");
|
||||
if (trimmedSkuName == null || trimmedSkuName.isEmpty()) {
|
||||
throw new BusinessException("SKU名称不能为空");
|
||||
}
|
||||
|
||||
ProductSpecPO existing = findProductSpecBySpecCode(trimmedSpecCode, companyId, context);
|
||||
ProductSkuPO existing = findProductSkuBySkuCode(trimmedSkuCode, companyId, context);
|
||||
if (existing != null) return existing;
|
||||
|
||||
return createProductAndSpecIfNotExists(productCode, productName, specCode, specName,
|
||||
return createProductAndSkuIfNotExists(productCode, productName, skuCode, skuName,
|
||||
productCost, companyId, createBy, context);
|
||||
}
|
||||
|
||||
/** 旧签名(兼容旧版调用) */
|
||||
public ProductSpecPO createSpecForProduct(Long companyId, Long productId, String specName,
|
||||
String specCode, Long createBy,
|
||||
public ProductSkuPO createSkuForProduct(Long companyId, Long productId, String skuName,
|
||||
String skuCode, Long createBy,
|
||||
ImportRuntimeContext context) {
|
||||
ProductPO product = getProductById(productId, context);
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
// 已知 productId 时应直接基于该商品创建规格,不能再走“按商品编码/名称查商品”的路径,
|
||||
// 已知 productId 时应直接基于该商品创建SKU,不能再走“按商品编码/名称查商品”的路径,
|
||||
// 否则会在 productCode/productName 为空时误报“商品编码和商品名称不能同时为空”。
|
||||
return createSpecForProduct(product, specCode, specName, null, companyId, createBy, context);
|
||||
return createSkuForProduct(product, skuCode, skuName, null, companyId, createBy, context);
|
||||
}
|
||||
|
||||
/** 旧签名(兼容旧版调用):参数顺序 companyId, productName, productCode, specName, specCode */
|
||||
public ProductSpecPO createProductAndSpecIfNotExists(Long companyId, String productName,
|
||||
String productCode, String specName,
|
||||
String specCode, Long createBy,
|
||||
/** 旧签名(兼容旧版调用):参数顺序 companyId, productName, productCode, skuName, skuCode */
|
||||
public ProductSkuPO createProductAndSkuIfNotExists(Long companyId, String productName,
|
||||
String productCode, String skuName,
|
||||
String skuCode, Long createBy,
|
||||
ImportRuntimeContext context) {
|
||||
if (productName == null || productName.trim().isEmpty()) {
|
||||
throw new BusinessException("商品名称不能为空");
|
||||
@@ -398,7 +409,7 @@ public class ProductSpecImportHelper {
|
||||
}
|
||||
|
||||
cacheProduct(context, product);
|
||||
return createSpecForProduct(product, specCode, specName, null, companyId, createBy, context);
|
||||
return createSkuForProduct(product, skuCode, skuName, null, companyId, createBy, context);
|
||||
}
|
||||
|
||||
public ProductPO getProductById(Long productId, ImportRuntimeContext context) {
|
||||
@@ -424,63 +435,44 @@ public class ProductSpecImportHelper {
|
||||
|
||||
// ==================== 订单状态 ====================
|
||||
|
||||
public Long findOrderStatusIdByName(Long companyId, String statusName,
|
||||
ImportRuntimeContext context) {
|
||||
if (statusName == null || statusName.trim().isEmpty()) return null;
|
||||
/** 按名称或 code 解析状态码,结果写入缓存。 */
|
||||
public String resolveOrderStatusCode(String statusName, ImportRuntimeContext context) {
|
||||
if (statusName == null || statusName.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String trimmed = statusName.trim();
|
||||
if (context.statusIdByNameCache.containsKey(trimmed)) {
|
||||
return context.statusIdByNameCache.get(trimmed);
|
||||
if (context.statusCodeByNameCache.containsKey(trimmed)) {
|
||||
return context.statusCodeByNameCache.get(trimmed);
|
||||
}
|
||||
LambdaQueryWrapper<top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO> wrapper =
|
||||
new LambdaQueryWrapper<>();
|
||||
wrapper.eq(top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO::getStatusName, trimmed);
|
||||
top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO status =
|
||||
orderStatusService.getOne(wrapper);
|
||||
if (status != null) {
|
||||
context.statusIdByNameCache.put(trimmed, status.getId());
|
||||
return status.getId();
|
||||
}
|
||||
return null;
|
||||
String code = OrderStatus.fromName(trimmed).getCode();
|
||||
context.statusCodeByNameCache.put(trimmed, code);
|
||||
return code;
|
||||
}
|
||||
|
||||
public Long createOrderStatusIfNotExists(Long companyId, String statusName,
|
||||
Long createBy, ImportRuntimeContext context) {
|
||||
if (statusName == null || statusName.trim().isEmpty()) {
|
||||
throw new BusinessException("订单状态名称不能为空");
|
||||
public void preloadStatuses(ImportRuntimeContext context, Set<String> statusNames,
|
||||
Map<String, String> statusMapping) {
|
||||
if (statusMapping != null) {
|
||||
context.statusCodeByNameCache.putAll(statusMapping);
|
||||
}
|
||||
if (statusNames == null) {
|
||||
return;
|
||||
}
|
||||
for (String name : statusNames) {
|
||||
if (name != null && !name.isBlank()) {
|
||||
resolveOrderStatusCode(name, context);
|
||||
}
|
||||
}
|
||||
String trimmed = statusName.trim();
|
||||
|
||||
Long existingId = findOrderStatusIdByName(companyId, trimmed, context);
|
||||
if (existingId != null) return existingId;
|
||||
|
||||
top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO orderStatus =
|
||||
new top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO();
|
||||
orderStatus.setCompanyId(companyId);
|
||||
orderStatus.setStatusName(trimmed);
|
||||
orderStatus.setDescription("自动创建的状态");
|
||||
orderStatus.setSortOrder(0);
|
||||
orderStatus.setIncludeSalesAmount(1);
|
||||
orderStatus.setIncludeProductCost(1);
|
||||
orderStatus.setIncludeFreightCost(1);
|
||||
orderStatus.setIncludeOtherCost(1);
|
||||
orderStatus.setIncludeRefund(0);
|
||||
orderStatus.setCreateBy(createBy);
|
||||
orderStatusService.save(orderStatus);
|
||||
|
||||
context.statusIdByNameCache.put(trimmed, orderStatus.getId());
|
||||
return orderStatus.getId();
|
||||
}
|
||||
|
||||
// ==================== 预加载 ====================
|
||||
|
||||
public void preloadProductSpecs(ImportRuntimeContext context, Set<String> specCodes) {
|
||||
for (List<String> chunk : ImportRuntimeContext.splitToChunks(specCodes, IN_QUERY_BATCH_SIZE)) {
|
||||
LambdaQueryWrapper<ProductSpecPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ProductSpecPO::getCompanyId, context.getCompanyId())
|
||||
.in(ProductSpecPO::getSpecCode, chunk);
|
||||
for (ProductSpecPO spec : productSpecService.list(wrapper)) {
|
||||
context.specByCodeCache.put(spec.getSpecCode(), spec);
|
||||
public void preloadProductSkus(ImportRuntimeContext context, Set<String> skuCodes) {
|
||||
for (List<String> chunk : ImportRuntimeContext.splitToChunks(skuCodes, IN_QUERY_BATCH_SIZE)) {
|
||||
LambdaQueryWrapper<ProductSkuPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ProductSkuPO::getCompanyId, context.getCompanyId())
|
||||
.in(ProductSkuPO::getSkuCode, chunk);
|
||||
for (ProductSkuPO sku : productSkuService.list(wrapper)) {
|
||||
context.skuByCodeCache.put(sku.getSkuCode(), sku);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -507,31 +499,13 @@ public class ProductSpecImportHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public void preloadStatuses(ImportRuntimeContext context, Set<String> statusNames,
|
||||
Map<String, Long> statusMapping) {
|
||||
if (statusMapping != null) {
|
||||
context.statusIdByNameCache.putAll(statusMapping);
|
||||
}
|
||||
for (List<String> chunk : ImportRuntimeContext.splitToChunks(statusNames, IN_QUERY_BATCH_SIZE)) {
|
||||
LambdaQueryWrapper<top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO> wrapper =
|
||||
new LambdaQueryWrapper<>();
|
||||
wrapper.eq(top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO::getCompanyId,
|
||||
context.getCompanyId())
|
||||
.in(top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO::getStatusName, chunk);
|
||||
for (top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO status :
|
||||
orderStatusService.list(wrapper)) {
|
||||
context.statusIdByNameCache.put(status.getStatusName(), status.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按公司 + 平台订单号预加载已存在订单,不按店铺过滤,以便导入任务 {@code shop_id} 变更后仍能命中并更新 {@code shop_id}。
|
||||
* 库表唯一键为 {@code uk_company_platform(company_id, platform_order_no)} 时,同号非空至多一行;若仍出现多行(未迁完库等),
|
||||
* 见 {@link #pickExistingOrderForPlatformNo} 的兜底选择。
|
||||
*/
|
||||
public void preloadPlatformOrderNos(ImportRuntimeContext context, Set<String> platformOrderNos,
|
||||
OrderMapper orderMapper) {
|
||||
OrderMapper orderMapper, OrderItemMapper orderItemMapper) {
|
||||
for (List<String> chunk : ImportRuntimeContext.splitToChunks(platformOrderNos, IN_QUERY_BATCH_SIZE)) {
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getCompanyId, context.getCompanyId())
|
||||
@@ -545,19 +519,42 @@ public class ProductSpecImportHelper {
|
||||
String normalized = order.getPlatformOrderNo().trim();
|
||||
byNormalized.computeIfAbsent(normalized, k -> new ArrayList<>()).add(order);
|
||||
}
|
||||
List<Long> chosenOrderIds = new ArrayList<>();
|
||||
Map<String, OrderPO> chosenByNormalized = new HashMap<>();
|
||||
for (Map.Entry<String, List<OrderPO>> e : byNormalized.entrySet()) {
|
||||
OrderPO chosen = pickExistingOrderForPlatformNo(context, e.getValue());
|
||||
if (chosen == null) {
|
||||
continue;
|
||||
}
|
||||
chosenByNormalized.put(e.getKey(), chosen);
|
||||
chosenOrderIds.add(chosen.getId());
|
||||
}
|
||||
Map<Long, OrderItemPO> firstItemByOrderId = loadFirstItemsByOrderIds(orderItemMapper, chosenOrderIds);
|
||||
for (Map.Entry<String, OrderPO> e : chosenByNormalized.entrySet()) {
|
||||
String normalized = e.getKey();
|
||||
OrderPO chosen = e.getValue();
|
||||
context.existingPlatformOrderNos.add(normalized);
|
||||
context.existingOrderIdByPlatformNo.put(normalized, chosen.getId());
|
||||
context.existingOrderSnapshotByPlatformNo.put(normalized, chosen);
|
||||
context.existingOrderSnapshotByPlatformNo.put(normalized,
|
||||
new OrderImportSnapshot(chosen, firstItemByOrderId.get(chosen.getId())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Long, OrderItemPO> loadFirstItemsByOrderIds(OrderItemMapper orderItemMapper,
|
||||
List<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
LambdaQueryWrapper<OrderItemPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(OrderItemPO::getOrderId, orderIds).orderByAsc(OrderItemPO::getLineNo);
|
||||
Map<Long, OrderItemPO> map = new HashMap<>();
|
||||
for (OrderItemPO item : orderItemMapper.selectList(wrapper)) {
|
||||
map.putIfAbsent(item.getOrderId(), item);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 正常库结构下同一 {@code (company_id, platform_order_no)}(非空)仅一行。
|
||||
* 若多行:优先与当前导入任务 {@code shop_id} 一致的一条;否则取 {@code id} 最大(兼容迁移前重复数据)。
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
|
||||
/**
|
||||
* 订单明细 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderItemMapper extends BaseMapper<OrderItemPO> {
|
||||
}
|
||||
+29
-38
@@ -15,41 +15,37 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单Mapper接口
|
||||
* 订单主表 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderMapper extends BaseMapper<OrderPO> {
|
||||
|
||||
/**
|
||||
* 批量更新订单的成本字段
|
||||
* @param productCost 商品成本
|
||||
* @param shippingCost 运费成本
|
||||
* @param otherCost 其他成本
|
||||
* @param productSpecId 规格ID
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return 更新行数
|
||||
*/
|
||||
@Update("UPDATE ec_order SET product_cost = #{productCost}, shipping_cost = #{shippingCost}, " +
|
||||
"other_cost = #{otherCost}, update_time = NOW() " +
|
||||
"WHERE product_spec_id = #{productSpecId} AND order_time >= #{startTime} AND order_time <= #{endTime}")
|
||||
/** 批量更新明细成本(JOIN 主表按下单时间过滤) */
|
||||
@Update("""
|
||||
UPDATE ec_order_item i
|
||||
INNER JOIN ec_order o ON o.id = i.order_id
|
||||
SET i.product_cost = #{productCost}, i.shipping_cost = #{shippingCost},
|
||||
i.other_cost = #{otherCost}, i.update_time = NOW()
|
||||
WHERE i.product_sku_id = #{productSkuId}
|
||||
AND o.order_time >= #{startTime} AND o.order_time <= #{endTime}
|
||||
""")
|
||||
int updateCostFields(@Param("productCost") BigDecimal productCost,
|
||||
@Param("shippingCost") BigDecimal shippingCost,
|
||||
@Param("otherCost") BigDecimal otherCost,
|
||||
@Param("productSpecId") Long productSpecId,
|
||||
@Param("productSkuId") Long productSkuId,
|
||||
@Param("startTime") LocalDateTime startTime,
|
||||
@Param("endTime") LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 新建规格后:将同公司、规格编码一致且未绑定规格的订单挂到该规格。
|
||||
*/
|
||||
@Update("UPDATE ec_order SET product_spec_id = #{productSpecId}, update_time = NOW() " +
|
||||
"WHERE company_id = #{companyId} AND spec_code = #{specCode} AND product_spec_id IS NULL")
|
||||
int linkOrdersBySpecCodeWhenSpecIdNull(@Param("companyId") Long companyId,
|
||||
@Param("specCode") String specCode,
|
||||
@Param("productSpecId") Long productSpecId);
|
||||
/** 新建 SKU 后挂 orphan 明细 */
|
||||
@Update("""
|
||||
UPDATE ec_order_item i
|
||||
SET i.product_sku_id = #{productSkuId}, i.update_time = NOW()
|
||||
WHERE i.company_id = #{companyId} AND i.sku_code = #{skuCode} AND i.product_sku_id IS NULL
|
||||
""")
|
||||
int linkOrdersBySkuCodeWhenSkuIdNull(@Param("companyId") Long companyId,
|
||||
@Param("skuCode") String skuCode,
|
||||
@Param("productSkuId") Long productSkuId);
|
||||
|
||||
/** 导入任务完成后兜底:该任务写入订单涉及的自然日 */
|
||||
@Select("SELECT DISTINCT DATE(order_time) FROM ec_order WHERE import_task_id = #{importTaskId}")
|
||||
List<LocalDate> selectDistinctOrderDatesByImportTaskId(@Param("importTaskId") Long importTaskId);
|
||||
|
||||
@@ -65,29 +61,24 @@ public interface OrderMapper extends BaseMapper<OrderPO> {
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate);
|
||||
|
||||
/** 公司订单日期范围(rebuild 用) */
|
||||
@Select("""
|
||||
SELECT MIN(DATE(order_time)) FROM ec_order WHERE company_id = #{companyId}
|
||||
""")
|
||||
@Select("SELECT MIN(DATE(order_time)) FROM ec_order WHERE company_id = #{companyId}")
|
||||
LocalDate selectMinOrderDateByCompany(@Param("companyId") Long companyId);
|
||||
|
||||
@Select("""
|
||||
SELECT MAX(DATE(order_time)) FROM ec_order WHERE company_id = #{companyId}
|
||||
""")
|
||||
@Select("SELECT MAX(DATE(order_time)) FROM ec_order WHERE company_id = #{companyId}")
|
||||
LocalDate selectMaxOrderDateByCompany(@Param("companyId") Long companyId);
|
||||
|
||||
@Select("""
|
||||
SELECT shop_id AS shopId, DATE(order_time) AS statDate FROM ec_order
|
||||
WHERE company_id = #{companyId} AND spec_code = #{specCode} AND product_spec_id IS NULL
|
||||
GROUP BY shop_id, DATE(order_time)
|
||||
SELECT i.shop_id AS shopId, DATE(o.order_time) AS statDate
|
||||
FROM ec_order_item i
|
||||
INNER JOIN ec_order o ON o.id = i.order_id
|
||||
WHERE i.company_id = #{companyId} AND i.sku_code = #{skuCode} AND i.product_sku_id IS NULL
|
||||
GROUP BY i.shop_id, DATE(o.order_time)
|
||||
""")
|
||||
List<OrderShopStatDateRow> selectOrphanOrderStatDatesBySpecCode(
|
||||
List<OrderShopStatDateRow> selectOrphanOrderStatDatesBySkuCode(
|
||||
@Param("companyId") Long companyId,
|
||||
@Param("specCode") String specCode);
|
||||
@Param("skuCode") String skuCode);
|
||||
|
||||
/** 列表分页:走时间索引的 COUNT */
|
||||
long countOrderList(OrderListQueryParam param);
|
||||
|
||||
/** 列表分页:先查 id 再回表,避免大结果集 filesort */
|
||||
List<Long> selectOrderListIds(OrderListQueryParam param);
|
||||
}
|
||||
|
||||
+19
-19
@@ -23,12 +23,12 @@ public interface OrderStatAggMapper {
|
||||
@Param("shopIds") List<Long> shopIds,
|
||||
@Param("start") LocalDateTime start,
|
||||
@Param("end") LocalDateTime end,
|
||||
@Param("unionStatusIds") List<Long> unionStatusIds,
|
||||
@Param("salesStatusIds") List<Long> salesStatusIds,
|
||||
@Param("refundStatusIds") List<Long> refundStatusIds,
|
||||
@Param("productCostStatusIds") List<Long> productCostStatusIds,
|
||||
@Param("freightCostStatusIds") List<Long> freightCostStatusIds,
|
||||
@Param("otherCostStatusIds") List<Long> otherCostStatusIds);
|
||||
@Param("unionStatusCodes") List<String> unionStatusCodes,
|
||||
@Param("salesStatusCodes") List<String> salesStatusCodes,
|
||||
@Param("refundStatusCodes") List<String> refundStatusCodes,
|
||||
@Param("productCostStatusCodes") List<String> productCostStatusCodes,
|
||||
@Param("freightCostStatusCodes") List<String> freightCostStatusCodes,
|
||||
@Param("otherCostStatusCodes") List<String> otherCostStatusCodes);
|
||||
|
||||
/** SQL-2:日趋势 */
|
||||
List<DailyRow> aggregateDaily(
|
||||
@@ -36,12 +36,12 @@ public interface OrderStatAggMapper {
|
||||
@Param("shopIds") List<Long> shopIds,
|
||||
@Param("start") LocalDateTime start,
|
||||
@Param("end") LocalDateTime end,
|
||||
@Param("unionStatusIds") List<Long> unionStatusIds,
|
||||
@Param("salesStatusIds") List<Long> salesStatusIds,
|
||||
@Param("refundStatusIds") List<Long> refundStatusIds,
|
||||
@Param("productCostStatusIds") List<Long> productCostStatusIds,
|
||||
@Param("freightCostStatusIds") List<Long> freightCostStatusIds,
|
||||
@Param("otherCostStatusIds") List<Long> otherCostStatusIds);
|
||||
@Param("unionStatusCodes") List<String> unionStatusCodes,
|
||||
@Param("salesStatusCodes") List<String> salesStatusCodes,
|
||||
@Param("refundStatusCodes") List<String> refundStatusCodes,
|
||||
@Param("productCostStatusCodes") List<String> productCostStatusCodes,
|
||||
@Param("freightCostStatusCodes") List<String> freightCostStatusCodes,
|
||||
@Param("otherCostStatusCodes") List<String> otherCostStatusCodes);
|
||||
|
||||
/** SQL-3:三段时间 KPI(一次扫描) */
|
||||
PeriodKpiRow aggregatePeriodKpi(
|
||||
@@ -55,12 +55,12 @@ public interface OrderStatAggMapper {
|
||||
@Param("prevEnd") LocalDateTime prevEnd,
|
||||
@Param("yoyStart") LocalDateTime yoyStart,
|
||||
@Param("yoyEnd") LocalDateTime yoyEnd,
|
||||
@Param("unionStatusIds") List<Long> unionStatusIds,
|
||||
@Param("salesStatusIds") List<Long> salesStatusIds,
|
||||
@Param("refundStatusIds") List<Long> refundStatusIds,
|
||||
@Param("productCostStatusIds") List<Long> productCostStatusIds,
|
||||
@Param("freightCostStatusIds") List<Long> freightCostStatusIds,
|
||||
@Param("otherCostStatusIds") List<Long> otherCostStatusIds);
|
||||
@Param("unionStatusCodes") List<String> unionStatusCodes,
|
||||
@Param("salesStatusCodes") List<String> salesStatusCodes,
|
||||
@Param("refundStatusCodes") List<String> refundStatusCodes,
|
||||
@Param("productCostStatusCodes") List<String> productCostStatusCodes,
|
||||
@Param("freightCostStatusCodes") List<String> freightCostStatusCodes,
|
||||
@Param("otherCostStatusCodes") List<String> otherCostStatusCodes);
|
||||
|
||||
/** 推广费三段时间 KPI */
|
||||
FeeKpiRow aggregatePromotionPeriodKpi(
|
||||
@@ -105,7 +105,7 @@ public interface OrderStatAggMapper {
|
||||
@Data
|
||||
class ShopProductRow {
|
||||
private Long shopId;
|
||||
private Long platformId;
|
||||
private String platformCode;
|
||||
private Long productId;
|
||||
private Long categoryId;
|
||||
private BigDecimal salesAmount;
|
||||
|
||||
+65
-95
@@ -1,153 +1,123 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建订单DTO
|
||||
* 创建订单 DTO(主表 + 明细;导入可仍用扁平单行字段)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建订单DTO")
|
||||
public class CreateOrderDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "店铺ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 平台订单号
|
||||
*/
|
||||
@Schema(description = "平台订单号", example = "TB202401010001")
|
||||
@Schema(description = "平台订单号")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@Schema(description = "订单状态ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "订单状态ID不能为空")
|
||||
private Long statusId;
|
||||
@Schema(description = "订单状态码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "订单状态不能为空")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 商家实收金额
|
||||
*/
|
||||
@Schema(description = "商家实收金额", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商家实收金额不能为空")
|
||||
private BigDecimal receivedAmount;
|
||||
@Schema(description = "实付/商家实收金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "实付金额不能为空")
|
||||
@JsonAlias("receivedAmount")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
/**
|
||||
* 下单时间
|
||||
*/
|
||||
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "下单时间不能为空")
|
||||
private LocalDateTime orderTime;
|
||||
|
||||
/**
|
||||
* 导入时输入的下单时间是否为空(仅用于「更新时跳过」的业务决策)。
|
||||
* <p>
|
||||
* 注意:即便输入为空,orderTime 在解析阶段仍可能被填充为邻近行的下单时间;
|
||||
* 该字段用于区分「输入是否为空」而不是区分 orderTime 是否为空。
|
||||
*/
|
||||
@Schema(description = "导入时下单时间是否为空(仅用于更新跳过逻辑)")
|
||||
private Boolean orderTimeEmptyInInput;
|
||||
|
||||
/**
|
||||
* 商品规格ID(下单必选,商品由规格关联)
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品规格ID不能为空")
|
||||
private Long productSpecId;
|
||||
@Schema(description = "平台代码(未传时从店铺补全)")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 规格编码(可选;未传时服务端按规格ID补全写入订单)
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "SKU001")
|
||||
private String specCode;
|
||||
@Schema(description = "来源:import/sync/manual")
|
||||
private String source;
|
||||
|
||||
@Schema(description = "商品金额合计")
|
||||
private BigDecimal goodsAmount;
|
||||
|
||||
@Schema(description = "折扣金额合计")
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
@Schema(description = "邮费")
|
||||
private BigDecimal postage;
|
||||
|
||||
@Schema(description = "平台优惠")
|
||||
private BigDecimal platformDiscount;
|
||||
|
||||
@Schema(description = "商家优惠")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@Schema(description = "订单明细(至少 1 条;未传时 Service 用下方扁平字段合成一行)")
|
||||
@Valid
|
||||
private List<CreateOrderItemDTO> items;
|
||||
|
||||
/** 导入兼容:扁平单行字段 */
|
||||
@Schema(description = "商品规格ID(扁平导入)")
|
||||
private Long productSkuId;
|
||||
|
||||
@Schema(description = "规格编码(扁平导入)")
|
||||
private String skuCode;
|
||||
|
||||
/**
|
||||
* 导入流程用:店铺-商品关联所需商品ID,不入库,不对外序列化。
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Schema(hidden = true)
|
||||
private Long shopRelationProductId;
|
||||
|
||||
/**
|
||||
* 链接商品名称(冗余存储)
|
||||
*/
|
||||
@Schema(description = "链接商品名称", example = "iPhone 15 Pro", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "链接商品名称不能为空")
|
||||
@Schema(description = "链接商品名称(扁平导入)")
|
||||
private String linkProductName;
|
||||
|
||||
/**
|
||||
* 链接规格名称(冗余存储)
|
||||
*/
|
||||
@Schema(description = "链接规格名称", example = "256GB 深空黑色")
|
||||
private String linkSpecName;
|
||||
@Schema(description = "链接规格名称(扁平导入)")
|
||||
private String linkSkuName;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@Schema(description = "数量", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "数量不能为空")
|
||||
@Schema(description = "数量(扁平导入)")
|
||||
@Positive(message = "数量必须大于0")
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 销售单价
|
||||
*/
|
||||
@Schema(description = "销售单价", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "销售单价不能为空")
|
||||
@Schema(description = "销售单价(扁平导入)")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "单件商品成本不能为空")
|
||||
@Schema(description = "单件商品成本(扁平导入)")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件运费成本", example = "10.00")
|
||||
@Schema(description = "单件运费成本(扁平导入)")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件其他成本", example = "5.00")
|
||||
@Schema(description = "单件其他成本(扁平导入)")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@Schema(description = "导入任务ID", example = "1")
|
||||
@Schema(description = "导入任务ID")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
@Schema(description = "确认(0-否 1-是)")
|
||||
private Integer confirm;
|
||||
|
||||
/**
|
||||
* 已存在的订单ID(用于导入时更新重复订单)
|
||||
* 不为空表示是更新操作
|
||||
*/
|
||||
@Schema(description = "已存在的订单ID(导入时用于更新)", example = "1")
|
||||
@Schema(description = "已存在的订单ID(导入时用于更新)")
|
||||
private Long existingOrderId;
|
||||
|
||||
/** 兼容旧字段名:写入 payAmount */
|
||||
public void setReceivedAmount(BigDecimal receivedAmount) {
|
||||
this.payAmount = receivedAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getReceivedAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
}
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 创建/导入订单明细 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建订单明细 DTO")
|
||||
public class CreateOrderItemDTO {
|
||||
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSkuId;
|
||||
|
||||
@Schema(description = "规格编码", example = "SKU001")
|
||||
private String skuCode;
|
||||
|
||||
@Schema(description = "链接商品名称", example = "iPhone 15 Pro")
|
||||
@NotNull(message = "链接商品名称不能为空")
|
||||
private String linkProductName;
|
||||
|
||||
@Schema(description = "链接规格名称", example = "256GB")
|
||||
private String linkSkuName;
|
||||
|
||||
@Schema(description = "数量", example = "1")
|
||||
@NotNull(message = "数量不能为空")
|
||||
@Positive(message = "数量必须大于0")
|
||||
private Integer quantity;
|
||||
|
||||
@Schema(description = "销售单价", example = "9999.00")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
@Schema(description = "行实收/行销售额")
|
||||
private BigDecimal lineAmount;
|
||||
|
||||
@Schema(description = "单件商品成本快照")
|
||||
private BigDecimal productCost;
|
||||
|
||||
@Schema(description = "单件运费成本快照")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@Schema(description = "单件其他成本快照")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
@Schema(description = "明细备注")
|
||||
private String remark;
|
||||
}
|
||||
+33
-44
@@ -1,5 +1,6 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -8,71 +9,59 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单分页查询过滤DTO
|
||||
* 订单分页查询过滤 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "订单分页查询过滤DTO")
|
||||
public class OrderFilterDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
@Schema(description = "店铺ID")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 平台订单号:无 %/_ 时按前缀匹配(可走索引);含通配符时全模糊
|
||||
*/
|
||||
@Schema(description = "平台订单号(默认前缀匹配;含%/_ 时全模糊)", example = "TB2024")
|
||||
@Schema(description = "平台订单号(默认前缀匹配;含%/_ 时全模糊)")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@Schema(description = "订单状态ID", example = "1")
|
||||
private Long statusId;
|
||||
@Schema(description = "订单状态码")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 实收金额范围-最小值
|
||||
*/
|
||||
@Schema(description = "实收金额范围-最小值", example = "100.00")
|
||||
private BigDecimal minReceivedAmount;
|
||||
@Schema(description = "实付金额范围-最小值")
|
||||
@JsonAlias("minReceivedAmount")
|
||||
private BigDecimal minPayAmount;
|
||||
|
||||
/**
|
||||
* 实收金额范围-最大值
|
||||
*/
|
||||
@Schema(description = "实收金额范围-最大值", example = "10000.00")
|
||||
private BigDecimal maxReceivedAmount;
|
||||
@Schema(description = "实付金额范围-最大值")
|
||||
@JsonAlias("maxReceivedAmount")
|
||||
private BigDecimal maxPayAmount;
|
||||
|
||||
/**
|
||||
* 下单时间范围-开始时间
|
||||
*/
|
||||
@Schema(description = "下单时间范围-开始时间", example = "2024-01-01 00:00:00")
|
||||
@Schema(description = "下单时间范围-开始时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime startOrderTime;
|
||||
|
||||
/**
|
||||
* 下单时间范围-结束时间
|
||||
*/
|
||||
@Schema(description = "下单时间范围-结束时间", example = "2024-12-31 23:59:59")
|
||||
@Schema(description = "下单时间范围-结束时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endOrderTime;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@Schema(description = "导入任务ID", example = "1")
|
||||
@Schema(description = "导入任务ID")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
@Schema(description = "确认(0-否 1-是)")
|
||||
private Integer confirm;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
@Schema(description = "商品ID(走明细 EXISTS)")
|
||||
private Long productId;
|
||||
|
||||
public BigDecimal getMinReceivedAmount() {
|
||||
return minPayAmount;
|
||||
}
|
||||
|
||||
public void setMinReceivedAmount(BigDecimal v) {
|
||||
this.minPayAmount = v;
|
||||
}
|
||||
|
||||
public BigDecimal getMaxReceivedAmount() {
|
||||
return maxPayAmount;
|
||||
}
|
||||
|
||||
public void setMaxReceivedAmount(BigDecimal v) {
|
||||
this.maxPayAmount = v;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-9
@@ -6,31 +6,26 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单列表分页查询参数(Mapper 动态 SQL,含 FORCE INDEX 提示)。
|
||||
* 订单列表分页查询参数(Mapper 动态 SQL)
|
||||
*/
|
||||
@Data
|
||||
public class OrderListQueryParam {
|
||||
|
||||
private Long companyId;
|
||||
private Long shopId;
|
||||
/** 平台单号:前缀匹配(无 %/_ 时) */
|
||||
private String platformOrderNo;
|
||||
private Boolean platformOrderNoPrefix;
|
||||
private Long statusId;
|
||||
private BigDecimal minReceivedAmount;
|
||||
private BigDecimal maxReceivedAmount;
|
||||
private String status;
|
||||
private BigDecimal minPayAmount;
|
||||
private BigDecimal maxPayAmount;
|
||||
private LocalDateTime startOrderTime;
|
||||
private LocalDateTime endOrderTime;
|
||||
private Long importTaskId;
|
||||
private Integer confirm;
|
||||
private Long productId;
|
||||
|
||||
/** true → FORCE INDEX(idx_company_shop_time),否则 idx_company_order_time */
|
||||
private boolean useShopTimeIndex;
|
||||
|
||||
/** 白名单排序片段,如 order_time DESC, id DESC */
|
||||
private String orderByClause;
|
||||
|
||||
private long offset;
|
||||
private long limit;
|
||||
}
|
||||
|
||||
+48
-79
@@ -1,115 +1,84 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 更新订单DTO
|
||||
* 更新订单 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新订单DTO")
|
||||
public class UpdateOrderDTO {
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "店铺ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 平台订单号
|
||||
*/
|
||||
@Schema(description = "平台订单号", example = "TB202401010001")
|
||||
@Schema(description = "平台订单号")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@Schema(description = "订单状态ID", example = "1")
|
||||
private Long statusId;
|
||||
@Schema(description = "订单状态码")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 商家实收金额
|
||||
*/
|
||||
@Schema(description = "商家实收金额", example = "9999.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商家实收金额不能为空")
|
||||
private BigDecimal receivedAmount;
|
||||
@Schema(description = "实付/商家实收金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "实付金额不能为空")
|
||||
@JsonAlias("receivedAmount")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
/**
|
||||
* 下单时间
|
||||
*/
|
||||
@Schema(description = "下单时间", example = "2024-01-01T10:00:00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "下单时间不能为空")
|
||||
private LocalDateTime orderTime;
|
||||
|
||||
/**
|
||||
* 商品规格ID
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
@Schema(description = "平台代码")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "SKU001")
|
||||
private String specCode;
|
||||
@Schema(description = "来源")
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 链接商品名称(冗余存储)
|
||||
*/
|
||||
@Schema(description = "链接商品名称", example = "iPhone 15 Pro")
|
||||
@Schema(description = "商品金额合计")
|
||||
private BigDecimal goodsAmount;
|
||||
|
||||
@Schema(description = "折扣金额合计")
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
@Schema(description = "邮费")
|
||||
private BigDecimal postage;
|
||||
|
||||
@Schema(description = "平台优惠")
|
||||
private BigDecimal platformDiscount;
|
||||
|
||||
@Schema(description = "商家优惠")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@Schema(description = "订单明细(全量替换)")
|
||||
@Valid
|
||||
private List<CreateOrderItemDTO> items;
|
||||
|
||||
/** 扁平字段(未传 items 时合成一行) */
|
||||
private Long productSkuId;
|
||||
private String skuCode;
|
||||
private String linkProductName;
|
||||
|
||||
/**
|
||||
* 链接规格名称(冗余存储)
|
||||
*/
|
||||
@Schema(description = "链接规格名称", example = "256GB 深空黑色")
|
||||
private String linkSpecName;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@Schema(description = "数量", example = "1")
|
||||
private String linkSkuName;
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 销售单价
|
||||
*/
|
||||
@Schema(description = "销售单价", example = "9999.00")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件商品成本", example = "8000.00")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
private Integer confirm;
|
||||
|
||||
public void setReceivedAmount(BigDecimal receivedAmount) {
|
||||
this.payAmount = receivedAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getReceivedAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
}
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-内部订单明细(一行一 SKU)
|
||||
*/
|
||||
@Data
|
||||
@TableName("ec_order_item")
|
||||
public class OrderItemPO {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("order_id")
|
||||
private Long orderId;
|
||||
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
|
||||
@TableField("line_no")
|
||||
private Integer lineNo;
|
||||
|
||||
@TableField("product_id")
|
||||
private Long productId;
|
||||
|
||||
@TableField("product_sku_id")
|
||||
private Long productSkuId;
|
||||
|
||||
@TableField("sku_code")
|
||||
private String skuCode;
|
||||
|
||||
@TableField("platform_goods_id")
|
||||
private String platformGoodsId;
|
||||
|
||||
@TableField("platform_sku_id")
|
||||
private String platformSkuId;
|
||||
|
||||
@TableField("link_product_name")
|
||||
private String linkProductName;
|
||||
|
||||
@TableField("link_sku_name")
|
||||
private String linkSkuName;
|
||||
|
||||
@TableField("goods_img")
|
||||
private String goodsImg;
|
||||
|
||||
@TableField("quantity")
|
||||
private Integer quantity;
|
||||
|
||||
@TableField("unit_price")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
@TableField("line_amount")
|
||||
private BigDecimal lineAmount;
|
||||
|
||||
@TableField("product_cost")
|
||||
private BigDecimal productCost;
|
||||
|
||||
@TableField("shipping_cost")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@TableField("other_cost")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
@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;
|
||||
}
|
||||
+72
-102
@@ -8,148 +8,118 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-订单实体(含商品明细)
|
||||
* 电商-内部订单主表(一单一行)
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_order")
|
||||
public class OrderPO {
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 平台订单号
|
||||
*/
|
||||
@TableField("platform_code")
|
||||
private String platformCode;
|
||||
|
||||
@TableField("status")
|
||||
private String status;
|
||||
|
||||
@TableField("platform_order_no")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@TableField("status_id")
|
||||
private Long statusId;
|
||||
@TableField("source")
|
||||
private String source;
|
||||
|
||||
/**
|
||||
* 商品规格ID
|
||||
*/
|
||||
@TableField("product_spec_id")
|
||||
private Long productSpecId;
|
||||
@TableField("source_order_id")
|
||||
private Long sourceOrderId;
|
||||
|
||||
/**
|
||||
* 规格编码(冗余,与 ec_product_spec.spec_code 一致)
|
||||
*/
|
||||
@TableField("spec_code")
|
||||
private String specCode;
|
||||
@TableField("pay_amount")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
/**
|
||||
* 链接商品名称(冗余存储)
|
||||
*/
|
||||
@TableField("link_product_name")
|
||||
private String linkProductName;
|
||||
@TableField("goods_amount")
|
||||
private BigDecimal goodsAmount;
|
||||
|
||||
/**
|
||||
* 链接规格名称(冗余存储)
|
||||
*/
|
||||
@TableField("link_spec_name")
|
||||
private String linkSpecName;
|
||||
@TableField("discount_amount")
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@TableField("quantity")
|
||||
private Integer quantity;
|
||||
@TableField("postage")
|
||||
private BigDecimal postage;
|
||||
|
||||
/**
|
||||
* 销售单价
|
||||
*/
|
||||
@TableField("unit_price")
|
||||
private BigDecimal unitPrice;
|
||||
@TableField("platform_discount")
|
||||
private BigDecimal platformDiscount;
|
||||
|
||||
/**
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@TableField("product_cost")
|
||||
private BigDecimal productCost;
|
||||
@TableField("seller_discount")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@TableField("shipping_cost")
|
||||
private BigDecimal shippingCost;
|
||||
@TableField("logistics_id")
|
||||
private String logisticsId;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@TableField("other_cost")
|
||||
private BigDecimal otherCost;
|
||||
@TableField("tracking_number")
|
||||
private String trackingNumber;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@TableField("import_task_id")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@TableField("confirm")
|
||||
private Integer confirm;
|
||||
|
||||
/**
|
||||
* 商家实收金额
|
||||
*/
|
||||
@TableField("received_amount")
|
||||
private BigDecimal receivedAmount;
|
||||
|
||||
/**
|
||||
* 下单时间
|
||||
*/
|
||||
@TableField("order_time")
|
||||
private LocalDateTime orderTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("pay_time")
|
||||
private LocalDateTime payTime;
|
||||
|
||||
@TableField("confirm_time")
|
||||
private LocalDateTime confirmTime;
|
||||
|
||||
@TableField("shipping_time")
|
||||
private LocalDateTime shippingTime;
|
||||
|
||||
@TableField("receive_time")
|
||||
private LocalDateTime receiveTime;
|
||||
|
||||
@TableField("province")
|
||||
private String province;
|
||||
|
||||
@TableField("city")
|
||||
private String city;
|
||||
|
||||
@TableField("town")
|
||||
private String town;
|
||||
|
||||
@TableField("receiver_name_mask")
|
||||
private String receiverNameMask;
|
||||
|
||||
@TableField("receiver_phone_mask")
|
||||
private String receiverPhoneMask;
|
||||
|
||||
@TableField("receiver_address_mask")
|
||||
private String receiverAddressMask;
|
||||
|
||||
@TableField("buyer_memo")
|
||||
private String buyerMemo;
|
||||
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@TableField("import_task_id")
|
||||
private Long importTaskId;
|
||||
|
||||
@TableField("confirm")
|
||||
private Integer confirm;
|
||||
|
||||
@TableField("last_mapped_time")
|
||||
private LocalDateTime lastMappedTime;
|
||||
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
public class OrderFieldConstants {
|
||||
|
||||
public static final List<OrderFieldVO> FIELDS = Arrays.asList(
|
||||
create("spec_code", "规格编码", "商家编码-规格维度", true, 1, "string"),
|
||||
create("sku_code", "规格编码", "商家编码-规格维度", true, 1, "string"),
|
||||
create("received_amount", "商家实收金额", "商家实收金额(元)", true, 2, "string"),
|
||||
create("product_quantity", "商品数量", "商品数量(件)", true, 3, "number"),
|
||||
create("order_time", "下单时间", "下单时间", true, 4, "string"),
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单明细 VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "订单明细 VO")
|
||||
public class OrderItemVO {
|
||||
|
||||
@Schema(description = "明细ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "行号")
|
||||
private Integer lineNo;
|
||||
|
||||
@Schema(description = "商品ID")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "商品规格ID")
|
||||
private Long productSkuId;
|
||||
|
||||
@Schema(description = "规格编码")
|
||||
private String skuCode;
|
||||
|
||||
@Schema(description = "链接商品名称")
|
||||
private String linkProductName;
|
||||
|
||||
@Schema(description = "链接规格名称")
|
||||
private String linkSkuName;
|
||||
|
||||
@Schema(description = "商品图片URL")
|
||||
private String goodsImg;
|
||||
|
||||
@Schema(description = "数量")
|
||||
private Integer quantity;
|
||||
|
||||
@Schema(description = "销售单价")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
@Schema(description = "行实收/行销售额")
|
||||
private BigDecimal lineAmount;
|
||||
|
||||
@Schema(description = "单件商品成本快照")
|
||||
private BigDecimal productCost;
|
||||
|
||||
@Schema(description = "单件运费成本快照")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@Schema(description = "单件其他成本快照")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
@Schema(description = "明细备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "关联商品")
|
||||
private ProductVO product;
|
||||
|
||||
@Schema(description = "关联规格")
|
||||
private ProductSkuVO productSku;
|
||||
}
|
||||
+53
-144
@@ -1,193 +1,102 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单VO
|
||||
* 订单 VO(主表 + 明细列表)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "订单VO")
|
||||
public class OrderVO {
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
@Schema(description = "订单ID", example = "1")
|
||||
@Schema(description = "订单ID")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@Schema(description = "公司ID", example = "1")
|
||||
@Schema(description = "公司ID")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
@Schema(description = "店铺ID", example = "1")
|
||||
@Schema(description = "店铺ID")
|
||||
private Long shopId;
|
||||
|
||||
/**
|
||||
* 店铺名称
|
||||
*/
|
||||
@Schema(description = "店铺名称", example = "旗舰店")
|
||||
@Schema(description = "店铺名称")
|
||||
private String shopName;
|
||||
|
||||
/**
|
||||
* 平台订单号
|
||||
*/
|
||||
@Schema(description = "平台订单号", example = "TB202401010001")
|
||||
@Schema(description = "平台代码")
|
||||
private String platformCode;
|
||||
|
||||
@Schema(description = "平台订单号")
|
||||
private String platformOrderNo;
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@Schema(description = "订单状态ID", example = "1")
|
||||
private Long statusId;
|
||||
@Schema(description = "订单状态码")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 订单状态名称(中文)
|
||||
*/
|
||||
@Schema(description = "订单状态名称", example = "待发货")
|
||||
private String statusName;
|
||||
@Schema(description = "订单状态名称")
|
||||
private String statusLabel;
|
||||
|
||||
/**
|
||||
* 商家实收金额
|
||||
*/
|
||||
@Schema(description = "商家实收金额", example = "9999.00")
|
||||
private BigDecimal receivedAmount;
|
||||
@Schema(description = "订单状态颜色")
|
||||
private String statusColor;
|
||||
|
||||
/**
|
||||
* 下单时间
|
||||
*/
|
||||
@Schema(description = "下单时间", example = "2024-01-01T10:00:00")
|
||||
@Schema(description = "来源")
|
||||
private String source;
|
||||
|
||||
@Schema(description = "实付/商家实收金额")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
@Schema(description = "商品金额合计")
|
||||
private BigDecimal goodsAmount;
|
||||
|
||||
@Schema(description = "折扣金额合计")
|
||||
private BigDecimal discountAmount;
|
||||
|
||||
@Schema(description = "邮费")
|
||||
private BigDecimal postage;
|
||||
|
||||
@Schema(description = "下单时间")
|
||||
private LocalDateTime orderTime;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Schema(description = "创建人ID", example = "1")
|
||||
@Schema(description = "创建人ID")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Schema(description = "更新人ID", example = "1")
|
||||
@Schema(description = "更新人ID")
|
||||
private Long updateBy;
|
||||
|
||||
/**
|
||||
* 商品规格ID
|
||||
*/
|
||||
@Schema(description = "商品规格ID", example = "1")
|
||||
private Long productSpecId;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "SKU001")
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 链接商品名称(冗余存储)
|
||||
*/
|
||||
@Schema(description = "链接商品名称", example = "iPhone 15 Pro")
|
||||
private String linkProductName;
|
||||
|
||||
/**
|
||||
* 链接规格名称(冗余存储)
|
||||
*/
|
||||
@Schema(description = "链接规格名称", example = "256GB 深空黑色")
|
||||
private String linkSpecName;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
@Schema(description = "数量", example = "1")
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 销售单价
|
||||
*/
|
||||
@Schema(description = "销售单价", example = "9999.00")
|
||||
private BigDecimal unitPrice;
|
||||
|
||||
/**
|
||||
* 单件商品成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件商品成本", example = "8000.00")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 单件运费成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 单件其他成本(下单时快照)
|
||||
*/
|
||||
@Schema(description = "单件其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 导入任务ID
|
||||
*/
|
||||
@Schema(description = "导入任务ID", example = "1")
|
||||
@Schema(description = "导入任务ID")
|
||||
private Long importTaskId;
|
||||
|
||||
/**
|
||||
* 确认(0-否 1-是)
|
||||
*/
|
||||
@Schema(description = "确认", example = "1")
|
||||
@Schema(description = "确认(0-否 1-是)")
|
||||
private Integer confirm;
|
||||
|
||||
/**
|
||||
* 关联商品信息
|
||||
*/
|
||||
@Schema(description = "关联商品信息")
|
||||
private ProductVO product;
|
||||
@Schema(description = "明细行数(列表汇总)")
|
||||
private Integer itemCount;
|
||||
|
||||
/**
|
||||
* 关联商品规格信息
|
||||
*/
|
||||
@Schema(description = "关联商品规格信息")
|
||||
private ProductSpecVO productSpec;
|
||||
@Schema(description = "首行链接商品名(列表汇总)")
|
||||
private String firstLinkProductName;
|
||||
|
||||
/**
|
||||
* 关联订单状态信息
|
||||
*/
|
||||
@Schema(description = "关联订单状态信息")
|
||||
private OrderStatusVO orderStatus;
|
||||
@Schema(description = "订单明细")
|
||||
private List<OrderItemVO> items;
|
||||
|
||||
/**
|
||||
* 关联店铺信息
|
||||
*/
|
||||
@Schema(description = "关联店铺信息")
|
||||
@Schema(description = "关联店铺")
|
||||
private ShopVO shop;
|
||||
|
||||
/** 兼容旧前端字段名 */
|
||||
@JsonProperty("receivedAmount")
|
||||
public BigDecimal getReceivedAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -85,7 +85,7 @@ public interface OrderService extends IService<OrderPO> {
|
||||
|
||||
/**
|
||||
* 同步规格成本到历史订单
|
||||
* @param specId 规格ID
|
||||
* @param skuId 规格ID
|
||||
* @param productCost 商品成本
|
||||
* @param shippingCost 运费成本
|
||||
* @param otherCost 其他成本
|
||||
@@ -93,7 +93,7 @@ public interface OrderService extends IService<OrderPO> {
|
||||
* @param endTime 结束时间
|
||||
* @return 更新行数
|
||||
*/
|
||||
int syncCostsToOrders(Long specId, java.math.BigDecimal productCost,
|
||||
int syncCostsToOrders(Long skuId, java.math.BigDecimal productCost,
|
||||
java.math.BigDecimal shippingCost, java.math.BigDecimal otherCost,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime);
|
||||
|
||||
@@ -101,25 +101,25 @@ public interface OrderService extends IService<OrderPO> {
|
||||
* 统计在指定时间范围内、且商品规格在列表中的订单数量(与成本同步 UPDATE 条件一致,用于同步前预览)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param specIds 规格ID列表
|
||||
* @param skuIds 规格ID列表
|
||||
* @param startTime 订单时间起(含)
|
||||
* @param endTime 订单时间止(含)
|
||||
* @return 订单条数
|
||||
*/
|
||||
long countOrdersForCostSync(Long companyId, java.util.List<Long> specIds,
|
||||
long countOrdersForCostSync(Long companyId, java.util.List<Long> skuIds,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 在指定公司下,返回传入规格 ID 中存在至少一条订单的子集(无顺序保证,调用方可再与期望顺序求交)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param specIds 待检测的规格ID列表
|
||||
* @param skuIds 待检测的规格ID列表
|
||||
* @return 存在关联订单的规格ID列表(去重)
|
||||
*/
|
||||
java.util.List<Long> specIdsHavingOrders(Long companyId, java.util.List<Long> specIds);
|
||||
java.util.List<Long> skuIdsHavingOrders(Long companyId, java.util.List<Long> skuIds);
|
||||
|
||||
/**
|
||||
* 当前公司在库中是否存在至少一条订单关联该规格
|
||||
*/
|
||||
boolean companyHasOrdersForSpec(Long companyId, Long specId);
|
||||
boolean companyHasOrdersForSku(Long companyId, Long skuId);
|
||||
}
|
||||
|
||||
+300
-344
@@ -8,38 +8,44 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
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.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.BatchImportOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.CreateOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.CreateOrderItemDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.OrderFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.OrderListQueryParam;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.UpdateOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.support.OrderDtoSupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.support.OrderPageQuerySupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.vo.BatchImportResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.vo.OrderItemVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.vo.OrderVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.enums.OrderStatus;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatCrudCoordinator;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.support.StatDirtyKey;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.license.LicenseFeature;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.license.LicenseFeatureGuard;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -49,250 +55,126 @@ import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单服务实现类
|
||||
* 订单服务实现(主表 + 明细)
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implements OrderService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(OrderServiceImpl.class);
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopService shopService;
|
||||
private final ProductService productService;
|
||||
private final ProductSpecService productSpecService;
|
||||
private final OrderStatusService orderStatusService;
|
||||
private final ProductSkuService productSkuService;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final OrderStatCrudCoordinator orderStatCrudCoordinator;
|
||||
private final LicenseFeatureGuard licenseFeatureGuard;
|
||||
|
||||
public OrderServiceImpl(CurrentUserContext currentUserContext, ShopService shopService,
|
||||
ProductService productService, ProductSpecService productSpecService,
|
||||
OrderStatusService orderStatusService,
|
||||
public OrderServiceImpl(CurrentUserContext currentUserContext, ShopService shopService,
|
||||
ProductService productService, ProductSkuService productSkuService,
|
||||
OrderItemMapper orderItemMapper,
|
||||
OrderStatCrudCoordinator orderStatCrudCoordinator,
|
||||
LicenseFeatureGuard licenseFeatureGuard) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopService = shopService;
|
||||
this.productService = productService;
|
||||
this.productSpecService = productSpecService;
|
||||
this.orderStatusService = orderStatusService;
|
||||
this.productSkuService = productSkuService;
|
||||
this.orderItemMapper = orderItemMapper;
|
||||
this.orderStatCrudCoordinator = orderStatCrudCoordinator;
|
||||
this.licenseFeatureGuard = licenseFeatureGuard;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param createOrderDTO 创建订单DTO
|
||||
* @return 订单VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO createOrder(CreateOrderDTO createOrderDTO) {
|
||||
licenseFeatureGuard.require(LicenseFeature.ORDER_CREATE);
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
ShopPO shop = requireShop(createOrderDTO.getShopId(), companyId);
|
||||
List<CreateOrderItemDTO> itemDtos = OrderDtoSupport.resolveItems(createOrderDTO);
|
||||
validateItems(itemDtos, companyId);
|
||||
validateOrderStatus(createOrderDTO.getStatus());
|
||||
assertPlatformOrderNoUnique(createOrderDTO.getPlatformOrderNo(), companyId,
|
||||
createOrderDTO.getShopId(), null);
|
||||
|
||||
// 验证店铺是否存在且属于当前公司
|
||||
ShopPO shop = shopService.getById(createOrderDTO.getShopId());
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
|
||||
ProductSpecPO productSpec = productSpecService.getById(createOrderDTO.getProductSpecId());
|
||||
if (productSpec == null || !productSpec.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品规格不存在");
|
||||
}
|
||||
ProductPO product = productService.getById(productSpec.getProductId());
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
|
||||
// 验证订单状态是否存在且属于当前公司
|
||||
OrderStatusPO orderStatus = orderStatusService.getById(createOrderDTO.getStatusId());
|
||||
if (orderStatus == null || !orderStatus.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单状态不存在");
|
||||
}
|
||||
|
||||
// 验证平台订单号是否重复(如果提供了的话)
|
||||
if (createOrderDTO.getPlatformOrderNo() != null && !createOrderDTO.getPlatformOrderNo().trim().isEmpty()) {
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getPlatformOrderNo, createOrderDTO.getPlatformOrderNo())
|
||||
.eq(OrderPO::getCompanyId, companyId);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台订单号已存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 创建订单(包含商品明细)
|
||||
OrderPO order = new OrderPO();
|
||||
order.setCompanyId(companyId);
|
||||
order.setShopId(createOrderDTO.getShopId());
|
||||
order.setPlatformOrderNo(createOrderDTO.getPlatformOrderNo());
|
||||
order.setStatusId(createOrderDTO.getStatusId());
|
||||
order.setProductSpecId(createOrderDTO.getProductSpecId());
|
||||
String specCodeIn = createOrderDTO.getSpecCode();
|
||||
order.setSpecCode(specCodeIn != null && !specCodeIn.trim().isEmpty()
|
||||
? specCodeIn.trim() : productSpec.getSpecCode());
|
||||
order.setLinkProductName(createOrderDTO.getLinkProductName());
|
||||
order.setLinkSpecName(createOrderDTO.getLinkSpecName());
|
||||
order.setQuantity(createOrderDTO.getQuantity());
|
||||
order.setUnitPrice(createOrderDTO.getUnitPrice());
|
||||
order.setProductCost(createOrderDTO.getProductCost());
|
||||
order.setShippingCost(createOrderDTO.getShippingCost());
|
||||
order.setOtherCost(createOrderDTO.getOtherCost());
|
||||
order.setRemark(createOrderDTO.getRemark());
|
||||
order.setReceivedAmount(createOrderDTO.getReceivedAmount());
|
||||
order.setOrderTime(createOrderDTO.getOrderTime());
|
||||
order.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
// 设置导入任务ID和确认状态(默认已确认)
|
||||
order.setImportTaskId(createOrderDTO.getImportTaskId());
|
||||
order.setConfirm(createOrderDTO.getConfirm() != null ? createOrderDTO.getConfirm() : 1);
|
||||
|
||||
// 保存订单
|
||||
OrderDtoSupport.applyHeaderFromCreate(createOrderDTO, order, shop.getPlatformCode());
|
||||
order.setCreateBy(userId);
|
||||
this.save(order);
|
||||
saveItems(order, itemDtos, companyId, userId);
|
||||
orderStatCrudCoordinator.afterOrderSaved(null, order);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO createOrderForImport(CreateOrderDTO createOrderDTO, Long companyId, Long userId) {
|
||||
ShopPO shop = shopService.getById(createOrderDTO.getShopId());
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
ProductSpecPO productSpec = productSpecService.getById(createOrderDTO.getProductSpecId());
|
||||
if (productSpec == null || !productSpec.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品规格不存在");
|
||||
}
|
||||
ProductPO product = productService.getById(productSpec.getProductId());
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
OrderStatusPO orderStatus = orderStatusService.getById(createOrderDTO.getStatusId());
|
||||
if (orderStatus == null || !orderStatus.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单状态不存在");
|
||||
}
|
||||
if (createOrderDTO.getPlatformOrderNo() != null && !createOrderDTO.getPlatformOrderNo().trim().isEmpty()) {
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getPlatformOrderNo, createOrderDTO.getPlatformOrderNo())
|
||||
.eq(OrderPO::getCompanyId, companyId);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台订单号已存在");
|
||||
}
|
||||
}
|
||||
ShopPO shop = requireShop(createOrderDTO.getShopId(), companyId);
|
||||
List<CreateOrderItemDTO> itemDtos = OrderDtoSupport.resolveItems(createOrderDTO);
|
||||
validateItems(itemDtos, companyId);
|
||||
validateOrderStatus(createOrderDTO.getStatus());
|
||||
assertPlatformOrderNoUnique(createOrderDTO.getPlatformOrderNo(), companyId,
|
||||
createOrderDTO.getShopId(), null);
|
||||
|
||||
OrderPO order = new OrderPO();
|
||||
order.setCompanyId(companyId);
|
||||
order.setShopId(createOrderDTO.getShopId());
|
||||
order.setPlatformOrderNo(createOrderDTO.getPlatformOrderNo());
|
||||
order.setStatusId(createOrderDTO.getStatusId());
|
||||
order.setProductSpecId(createOrderDTO.getProductSpecId());
|
||||
String specCodeImp = createOrderDTO.getSpecCode();
|
||||
order.setSpecCode(specCodeImp != null && !specCodeImp.trim().isEmpty()
|
||||
? specCodeImp.trim() : productSpec.getSpecCode());
|
||||
order.setLinkProductName(createOrderDTO.getLinkProductName());
|
||||
order.setLinkSpecName(createOrderDTO.getLinkSpecName());
|
||||
order.setQuantity(createOrderDTO.getQuantity());
|
||||
order.setUnitPrice(createOrderDTO.getUnitPrice());
|
||||
order.setProductCost(createOrderDTO.getProductCost());
|
||||
order.setShippingCost(createOrderDTO.getShippingCost());
|
||||
order.setOtherCost(createOrderDTO.getOtherCost());
|
||||
order.setRemark(createOrderDTO.getRemark());
|
||||
order.setReceivedAmount(createOrderDTO.getReceivedAmount());
|
||||
order.setOrderTime(createOrderDTO.getOrderTime());
|
||||
OrderDtoSupport.applyHeaderFromCreate(createOrderDTO, order, shop.getPlatformCode());
|
||||
order.setCreateBy(userId);
|
||||
order.setImportTaskId(createOrderDTO.getImportTaskId());
|
||||
order.setConfirm(createOrderDTO.getConfirm() != null ? createOrderDTO.getConfirm() : 1);
|
||||
this.save(order);
|
||||
saveItems(order, itemDtos, companyId, userId);
|
||||
return convertToVO(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单
|
||||
* @param updateOrderDTO 更新订单DTO
|
||||
* @param id 订单ID
|
||||
* @return 订单VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO updateOrder(UpdateOrderDTO updateOrderDTO, Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
OrderPO existingOrder = requireOrder(id, companyId);
|
||||
requireShop(updateOrderDTO.getShopId(), companyId);
|
||||
assertPlatformOrderNoUnique(updateOrderDTO.getPlatformOrderNo(), companyId,
|
||||
updateOrderDTO.getShopId(), id);
|
||||
|
||||
// 验证订单是否存在
|
||||
OrderPO existingOrder = this.getById(id);
|
||||
if (existingOrder == null || !existingOrder.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单不存在");
|
||||
if (updateOrderDTO.getStatus() != null && !updateOrderDTO.getStatus().isBlank()) {
|
||||
validateOrderStatus(updateOrderDTO.getStatus());
|
||||
}
|
||||
|
||||
// 验证店铺是否存在且属于当前公司
|
||||
ShopPO shop = shopService.getById(updateOrderDTO.getShopId());
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
|
||||
// 验证平台订单号是否重复(排除当前订单)
|
||||
if (updateOrderDTO.getPlatformOrderNo() != null && !updateOrderDTO.getPlatformOrderNo().trim().isEmpty()) {
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getPlatformOrderNo, updateOrderDTO.getPlatformOrderNo())
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.ne(OrderPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台订单号已存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 更新订单
|
||||
OrderPO order = new OrderPO();
|
||||
BeanCopyUtils.copyProperties(updateOrderDTO, order);
|
||||
order.setId(id);
|
||||
order.setCompanyId(companyId);
|
||||
|
||||
// 设置更新人ID
|
||||
order.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 更新订单
|
||||
order.setUpdateBy(userId);
|
||||
this.updateById(order);
|
||||
|
||||
List<CreateOrderItemDTO> itemDtos = OrderDtoSupport.resolveItems(updateOrderDTO);
|
||||
if (itemDtos != null && !itemDtos.isEmpty()) {
|
||||
validateItems(itemDtos, companyId);
|
||||
replaceItems(existingOrder, itemDtos, userId);
|
||||
}
|
||||
|
||||
OrderPO after = this.getById(id);
|
||||
orderStatCrudCoordinator.afterOrderSaved(existingOrder, after);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(after != null ? after : order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单
|
||||
* @param id 订单ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteOrder(Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证订单是否存在
|
||||
OrderPO existingOrder = this.getById(id);
|
||||
if (existingOrder == null || !existingOrder.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
// 硬删除订单(外键约束会自动处理相关数据)
|
||||
OrderPO existingOrder = requireOrder(id, companyId);
|
||||
orderStatCrudCoordinator.afterOrderDeleted(existingOrder);
|
||||
orderItemMapper.delete(new LambdaQueryWrapper<OrderItemPO>().eq(OrderItemPO::getOrderId, id));
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除订单
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteOrders(List<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
throw new BusinessException("请选择要删除的订单");
|
||||
}
|
||||
List<Long> uniqueIds = orderIds.stream()
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
List<Long> uniqueIds = orderIds.stream().filter(Objects::nonNull).distinct().toList();
|
||||
if (uniqueIds.isEmpty()) {
|
||||
throw new BusinessException("请选择要删除的订单");
|
||||
}
|
||||
@@ -301,22 +183,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
}
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.in(OrderPO::getId, uniqueIds);
|
||||
wrapper.eq(OrderPO::getCompanyId, companyId).in(OrderPO::getId, uniqueIds);
|
||||
List<OrderPO> toRemove = this.list(wrapper);
|
||||
long matched = toRemove.size();
|
||||
if (matched != uniqueIds.size()) {
|
||||
if (toRemove.size() != uniqueIds.size()) {
|
||||
throw new BusinessException("存在无效订单或无权删除的订单");
|
||||
}
|
||||
orderStatCrudCoordinator.afterOrdersDeletedBatch(toRemove);
|
||||
orderItemMapper.delete(new LambdaQueryWrapper<OrderItemPO>().in(OrderItemPO::getOrderId, uniqueIds));
|
||||
this.remove(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单分页列表
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果VO
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<OrderVO> getOrderPage(PageQueryDTO<OrderFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
@@ -324,10 +200,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
if (filter == null) {
|
||||
filter = new OrderFilterDTO();
|
||||
}
|
||||
|
||||
int page = pageQueryDTO.getPage() != null ? pageQueryDTO.getPage() : 1;
|
||||
int pageSize = pageQueryDTO.getPageSize() != null ? pageQueryDTO.getPageSize() : 20;
|
||||
|
||||
OrderListQueryParam query = OrderPageQuerySupport.toQueryParam(
|
||||
companyId, filter, pageQueryDTO.getSorts(), page, pageSize);
|
||||
|
||||
@@ -335,49 +209,24 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
if (total == 0) {
|
||||
return PageResultVO.create(Collections.emptyList(), 0L, page, pageSize);
|
||||
}
|
||||
|
||||
List<Long> ids = baseMapper.selectOrderListIds(query);
|
||||
if (ids.isEmpty()) {
|
||||
return PageResultVO.create(Collections.emptyList(), total, page, pageSize);
|
||||
}
|
||||
|
||||
List<OrderPO> rows = listByIds(ids);
|
||||
Map<Long, OrderPO> rowMap = rows.stream()
|
||||
.collect(Collectors.toMap(OrderPO::getId, Function.identity(), (a, b) -> a));
|
||||
List<OrderPO> ordered = ids.stream()
|
||||
.map(rowMap::get)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<OrderVO> voList = convertToVOBatch(ordered);
|
||||
return PageResultVO.create(voList, total, page, pageSize);
|
||||
List<OrderPO> ordered = ids.stream().map(rowMap::get).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
return PageResultVO.create(convertToVOBatch(ordered), total, page, pageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询订单
|
||||
* @param id 订单ID
|
||||
* @return 订单VO
|
||||
*/
|
||||
@Override
|
||||
public OrderVO getOrderById(Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证订单是否存在
|
||||
OrderPO order = this.getById(id);
|
||||
if (order == null || !order.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
OrderPO order = requireOrder(id, companyId);
|
||||
return convertToVO(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量导入订单
|
||||
* @param batchImportOrderDTO 批量导入订单DTO
|
||||
* @return 批量导入结果VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public BatchImportResultVO batchImportOrders(BatchImportOrderDTO batchImportOrderDTO) {
|
||||
@@ -385,8 +234,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
List<CreateOrderDTO> orders = batchImportOrderDTO.getOrders();
|
||||
List<OrderVO> successOrders = new ArrayList<>();
|
||||
List<BatchImportResultVO.ImportFailureRecord> failureRecords = new ArrayList<>();
|
||||
|
||||
int totalCount = orders.size();
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
Long importCompanyId = currentUserContext.getCurrentCompanyId();
|
||||
@@ -394,15 +241,12 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
|
||||
for (int i = 0; i < orders.size(); i++) {
|
||||
CreateOrderDTO rowOrder = orders.get(i);
|
||||
int rowNumber = i + 1; // 行号从1开始
|
||||
|
||||
int rowNumber = i + 1;
|
||||
try {
|
||||
// 批量导入走专用写入路径,授权已在方法入口校验 ORDER_IMPORT
|
||||
OrderVO orderVO = this.createOrderForImport(rowOrder, importCompanyId, importUserId);
|
||||
successOrders.add(orderVO);
|
||||
successCount++;
|
||||
} catch (Exception e) {
|
||||
// 记录失败信息
|
||||
BatchImportResultVO.ImportFailureRecord failureRecord = new BatchImportResultVO.ImportFailureRecord();
|
||||
failureRecord.setRowNumber(rowNumber);
|
||||
failureRecord.setPlatformOrderNo(rowOrder.getPlatformOrderNo());
|
||||
@@ -411,181 +255,293 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
failureCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建返回结果
|
||||
|
||||
BatchImportResultVO result = new BatchImportResultVO();
|
||||
result.setTotalCount(totalCount);
|
||||
result.setTotalCount(orders.size());
|
||||
result.setSuccessCount(successCount);
|
||||
result.setFailureCount(failureCount);
|
||||
result.setSuccessOrders(successOrders);
|
||||
result.setFailureRecords(failureRecords);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO(单条详情等仍用逐条加载)
|
||||
*/
|
||||
@Override
|
||||
public int syncCostsToOrders(Long skuId, java.math.BigDecimal productCost,
|
||||
java.math.BigDecimal shippingCost, java.math.BigDecimal otherCost,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) {
|
||||
try {
|
||||
ProductSkuPO sku = productSkuService.getById(skuId);
|
||||
int n = baseMapper.updateCostFields(productCost, shippingCost, otherCost, skuId, startTime, endTime);
|
||||
if (n > 0 && sku != null && sku.getCompanyId() != null) {
|
||||
List<OrderItemPO> affected = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getCompanyId, sku.getCompanyId())
|
||||
.eq(OrderItemPO::getProductSkuId, skuId));
|
||||
Set<Long> orderIds = affected.stream().map(OrderItemPO::getOrderId).filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
if (!orderIds.isEmpty()) {
|
||||
List<OrderPO> orders = list(new LambdaQueryWrapper<OrderPO>()
|
||||
.in(OrderPO::getId, orderIds)
|
||||
.ge(OrderPO::getOrderTime, startTime)
|
||||
.le(OrderPO::getOrderTime, endTime)
|
||||
.select(OrderPO::getCompanyId, OrderPO::getShopId, OrderPO::getOrderTime));
|
||||
Set<StatDirtyKey> keys = new HashSet<>();
|
||||
ZoneId zone = ZoneId.of("Asia/Shanghai");
|
||||
for (OrderPO o : orders) {
|
||||
if (o.getShopId() != null && o.getOrderTime() != null) {
|
||||
keys.add(new StatDirtyKey(o.getCompanyId(), o.getShopId(),
|
||||
o.getOrderTime().atZone(zone).toLocalDate()));
|
||||
}
|
||||
}
|
||||
orderStatCrudCoordinator.enqueueDirtyKeys(keys);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
} catch (Exception ex) {
|
||||
log.warn("同步成本到订单跳过(订单表可能不存在): {}", ex.getMessage());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countOrdersForCostSync(Long companyId, List<Long> skuIds,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) {
|
||||
if (skuIds == null || skuIds.isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
try {
|
||||
List<OrderItemPO> items = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getCompanyId, companyId)
|
||||
.in(OrderItemPO::getProductSkuId, skuIds)
|
||||
.select(OrderItemPO::getOrderId));
|
||||
Set<Long> orderIds = items.stream().map(OrderItemPO::getOrderId)
|
||||
.filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
if (orderIds.isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
Long cnt = baseMapper.selectCount(new LambdaQueryWrapper<OrderPO>()
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.in(OrderPO::getId, orderIds)
|
||||
.ge(OrderPO::getOrderTime, startTime)
|
||||
.le(OrderPO::getOrderTime, endTime));
|
||||
return cnt == null ? 0L : cnt;
|
||||
} catch (Exception ex) {
|
||||
log.warn("统计成本同步订单数跳过: {}", ex.getMessage());
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> skuIdsHavingOrders(Long companyId, List<Long> skuIds) {
|
||||
if (skuIds == null || skuIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<OrderItemPO> rows = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getCompanyId, companyId)
|
||||
.in(OrderItemPO::getProductSkuId, skuIds)
|
||||
.select(OrderItemPO::getProductSkuId));
|
||||
return rows.stream().map(OrderItemPO::getProductSkuId).filter(Objects::nonNull).distinct().toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean companyHasOrdersForSku(Long companyId, Long skuId) {
|
||||
if (companyId == null || skuId == null) {
|
||||
return false;
|
||||
}
|
||||
Long c = orderItemMapper.selectCount(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.eq(OrderItemPO::getCompanyId, companyId)
|
||||
.eq(OrderItemPO::getProductSkuId, skuId));
|
||||
return c != null && c > 0;
|
||||
}
|
||||
|
||||
private void saveItems(OrderPO order, List<CreateOrderItemDTO> itemDtos, Long companyId, Long userId) {
|
||||
int lineNo = 1;
|
||||
for (CreateOrderItemDTO dto : itemDtos) {
|
||||
ProductSkuPO sku = dto.getProductSkuId() != null
|
||||
? requireSku(dto.getProductSkuId(), companyId) : null;
|
||||
ProductPO product = sku != null ? requireProduct(sku.getProductId(), companyId) : null;
|
||||
OrderItemPO item = OrderDtoSupport.toItemPO(dto, order, sku, product, lineNo++, userId);
|
||||
orderItemMapper.insert(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceItems(OrderPO order, List<CreateOrderItemDTO> itemDtos, Long userId) {
|
||||
orderItemMapper.delete(new LambdaQueryWrapper<OrderItemPO>().eq(OrderItemPO::getOrderId, order.getId()));
|
||||
saveItems(order, itemDtos, order.getCompanyId(), userId);
|
||||
}
|
||||
|
||||
private Map<Long, List<OrderItemPO>> loadItemsByOrderIds(List<Long> orderIds) {
|
||||
if (orderIds == null || orderIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<OrderItemPO> items = orderItemMapper.selectList(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.in(OrderItemPO::getOrderId, orderIds)
|
||||
.orderByAsc(OrderItemPO::getLineNo));
|
||||
return items.stream().collect(Collectors.groupingBy(OrderItemPO::getOrderId));
|
||||
}
|
||||
|
||||
private OrderVO convertToVO(OrderPO order) {
|
||||
return convertToVOBatch(List.of(order)).get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量转换为 VO,关联数据一次查出,避免 N+1。
|
||||
*/
|
||||
private List<OrderVO> convertToVOBatch(List<OrderPO> orders) {
|
||||
if (orders == null || orders.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Long> orderIds = orders.stream().map(OrderPO::getId).filter(Objects::nonNull).toList();
|
||||
Map<Long, List<OrderItemPO>> itemsByOrder = loadItemsByOrderIds(orderIds);
|
||||
|
||||
Set<Long> statusIds = new HashSet<>();
|
||||
Set<Long> shopIds = new HashSet<>();
|
||||
Set<Long> specIds = new HashSet<>();
|
||||
Set<Long> skuIds = new HashSet<>();
|
||||
for (OrderPO o : orders) {
|
||||
if (o.getStatusId() != null) {
|
||||
statusIds.add(o.getStatusId());
|
||||
}
|
||||
if (o.getShopId() != null) {
|
||||
shopIds.add(o.getShopId());
|
||||
}
|
||||
if (o.getProductSpecId() != null) {
|
||||
specIds.add(o.getProductSpecId());
|
||||
if (o.getShopId() != null) shopIds.add(o.getShopId());
|
||||
}
|
||||
for (List<OrderItemPO> items : itemsByOrder.values()) {
|
||||
for (OrderItemPO item : items) {
|
||||
if (item.getProductSkuId() != null) skuIds.add(item.getProductSkuId());
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, OrderStatusPO> statusMap = statusIds.isEmpty()
|
||||
? Map.of()
|
||||
: orderStatusService.listByIds(statusIds).stream()
|
||||
.collect(Collectors.toMap(OrderStatusPO::getId, Function.identity(), (a, b) -> a));
|
||||
Map<Long, ShopPO> shopMap = shopIds.isEmpty()
|
||||
? Map.of()
|
||||
Map<Long, ShopPO> shopMap = shopIds.isEmpty() ? Map.of()
|
||||
: shopService.listByIds(shopIds).stream()
|
||||
.collect(Collectors.toMap(ShopPO::getId, Function.identity(), (a, b) -> a));
|
||||
Map<Long, ProductSpecPO> specMap = specIds.isEmpty()
|
||||
? Map.of()
|
||||
: productSpecService.listByIds(specIds).stream()
|
||||
.collect(Collectors.toMap(ProductSpecPO::getId, Function.identity(), (a, b) -> a));
|
||||
|
||||
Set<Long> productIds = specMap.values().stream()
|
||||
.map(ProductSpecPO::getProductId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, ProductPO> productMap = productIds.isEmpty()
|
||||
? Map.of()
|
||||
Map<Long, ProductSkuPO> skuMap = skuIds.isEmpty() ? Map.of()
|
||||
: productSkuService.listByIds(skuIds).stream()
|
||||
.collect(Collectors.toMap(ProductSkuPO::getId, Function.identity(), (a, b) -> a));
|
||||
Set<Long> productIds = skuMap.values().stream().map(ProductSkuPO::getProductId)
|
||||
.filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
Map<Long, ProductPO> productMap = productIds.isEmpty() ? Map.of()
|
||||
: productService.listByIds(productIds).stream()
|
||||
.collect(Collectors.toMap(ProductPO::getId, Function.identity(), (a, b) -> a));
|
||||
|
||||
List<OrderVO> result = new ArrayList<>(orders.size());
|
||||
for (OrderPO order : orders) {
|
||||
OrderVO orderVO = new OrderVO();
|
||||
BeanCopyUtils.copyProperties(order, orderVO);
|
||||
|
||||
if (order.getStatusId() != null) {
|
||||
OrderStatusPO orderStatus = statusMap.get(order.getStatusId());
|
||||
if (orderStatus != null) {
|
||||
orderVO.setStatusName(orderStatus.getStatusName());
|
||||
OrderStatusVO orderStatusVO = new OrderStatusVO();
|
||||
BeanCopyUtils.copyProperties(orderStatus, orderStatusVO);
|
||||
orderVO.setOrderStatus(orderStatusVO);
|
||||
}
|
||||
}
|
||||
OrderVO vo = new OrderVO();
|
||||
BeanCopyUtils.copyProperties(order, vo);
|
||||
fillStatusMeta(vo, order.getStatus());
|
||||
|
||||
if (order.getShopId() != null) {
|
||||
ShopPO shop = shopMap.get(order.getShopId());
|
||||
if (shop != null) {
|
||||
orderVO.setShopName(shop.getName());
|
||||
vo.setShopName(shop.getName());
|
||||
ShopVO shopVO = new ShopVO();
|
||||
BeanCopyUtils.copyProperties(shop, shopVO);
|
||||
orderVO.setShop(shopVO);
|
||||
vo.setShop(shopVO);
|
||||
}
|
||||
}
|
||||
|
||||
if (order.getProductSpecId() != null) {
|
||||
ProductSpecPO productSpec = specMap.get(order.getProductSpecId());
|
||||
if (productSpec != null) {
|
||||
ProductSpecVO productSpecVO = new ProductSpecVO();
|
||||
BeanCopyUtils.copyProperties(productSpec, productSpecVO);
|
||||
orderVO.setProductSpec(productSpecVO);
|
||||
if (productSpec.getProductId() != null) {
|
||||
ProductPO product = productMap.get(productSpec.getProductId());
|
||||
if (product != null) {
|
||||
ProductVO productVO = new ProductVO();
|
||||
BeanCopyUtils.copyProperties(product, productVO);
|
||||
orderVO.setProduct(productVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<OrderItemPO> itemRows = itemsByOrder.getOrDefault(order.getId(), List.of());
|
||||
vo.setItemCount(itemRows.size());
|
||||
if (!itemRows.isEmpty()) {
|
||||
vo.setFirstLinkProductName(itemRows.get(0).getLinkProductName());
|
||||
}
|
||||
result.add(orderVO);
|
||||
vo.setItems(toItemVoList(itemRows, skuMap, productMap));
|
||||
result.add(vo);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int syncCostsToOrders(Long specId, java.math.BigDecimal productCost,
|
||||
java.math.BigDecimal shippingCost, java.math.BigDecimal otherCost,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) {
|
||||
ProductSpecPO spec = productSpecService.getById(specId);
|
||||
int n = baseMapper.updateCostFields(productCost, shippingCost, otherCost, specId, startTime, endTime);
|
||||
if (n > 0 && spec != null && spec.getCompanyId() != null) {
|
||||
List<OrderPO> affected = list(new LambdaQueryWrapper<OrderPO>()
|
||||
.eq(OrderPO::getCompanyId, spec.getCompanyId())
|
||||
.eq(OrderPO::getProductSpecId, specId)
|
||||
.ge(OrderPO::getOrderTime, startTime)
|
||||
.le(OrderPO::getOrderTime, endTime)
|
||||
.select(OrderPO::getCompanyId, OrderPO::getShopId, OrderPO::getOrderTime));
|
||||
Set<StatDirtyKey> keys = new HashSet<>();
|
||||
ZoneId zone = ZoneId.of("Asia/Shanghai");
|
||||
for (OrderPO o : affected) {
|
||||
if (o.getShopId() != null && o.getOrderTime() != null) {
|
||||
keys.add(new StatDirtyKey(o.getCompanyId(), o.getShopId(),
|
||||
o.getOrderTime().atZone(zone).toLocalDate()));
|
||||
private List<OrderItemVO> toItemVoList(List<OrderItemPO> items,
|
||||
Map<Long, ProductSkuPO> skuMap,
|
||||
Map<Long, ProductPO> productMap) {
|
||||
List<OrderItemVO> list = new ArrayList<>(items.size());
|
||||
for (OrderItemPO item : items) {
|
||||
OrderItemVO vo = new OrderItemVO();
|
||||
BeanCopyUtils.copyProperties(item, vo);
|
||||
if (item.getProductSkuId() != null) {
|
||||
ProductSkuPO sku = skuMap.get(item.getProductSkuId());
|
||||
if (sku != null) {
|
||||
vo.setProductSku(productSkuService.toVo(sku));
|
||||
if (sku.getProductId() != null) {
|
||||
ProductPO product = productMap.get(sku.getProductId());
|
||||
if (product != null) {
|
||||
ProductVO productVO = new ProductVO();
|
||||
BeanCopyUtils.copyProperties(product, productVO);
|
||||
vo.setProduct(productVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
orderStatCrudCoordinator.enqueueDirtyKeys(keys);
|
||||
list.add(vo);
|
||||
}
|
||||
return n;
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countOrdersForCostSync(Long companyId, List<Long> specIds,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) {
|
||||
if (specIds == null || specIds.isEmpty()) {
|
||||
return 0L;
|
||||
private void validateItems(List<CreateOrderItemDTO> items, Long companyId) {
|
||||
if (items == null || items.isEmpty()) {
|
||||
throw new BusinessException("订单明细不能为空");
|
||||
}
|
||||
Long cnt = baseMapper.selectCount(new LambdaQueryWrapper<OrderPO>()
|
||||
for (CreateOrderItemDTO dto : items) {
|
||||
if (dto.getProductSkuId() != null) {
|
||||
requireSku(dto.getProductSkuId(), companyId);
|
||||
}
|
||||
if (dto.getLinkProductName() == null || dto.getLinkProductName().isBlank()) {
|
||||
throw new BusinessException("链接商品名称不能为空");
|
||||
}
|
||||
if (dto.getQuantity() == null || dto.getQuantity() <= 0) {
|
||||
throw new BusinessException("数量必须大于0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ShopPO requireShop(Long shopId, Long companyId) {
|
||||
ShopPO shop = shopService.getById(shopId);
|
||||
if (shop == null || !shop.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("店铺不存在");
|
||||
}
|
||||
return shop;
|
||||
}
|
||||
|
||||
private OrderPO requireOrder(Long id, Long companyId) {
|
||||
OrderPO order = this.getById(id);
|
||||
if (order == null || !order.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
return order;
|
||||
}
|
||||
|
||||
private ProductSkuPO requireSku(Long skuId, Long companyId) {
|
||||
ProductSkuPO sku = productSkuService.getById(skuId);
|
||||
if (sku == null || !sku.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品规格不存在");
|
||||
}
|
||||
return sku;
|
||||
}
|
||||
|
||||
private ProductPO requireProduct(Long productId, Long companyId) {
|
||||
ProductPO product = productService.getById(productId);
|
||||
if (product == null || !product.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
private void assertPlatformOrderNoUnique(String platformOrderNo, Long companyId, Long shopId, Long excludeId) {
|
||||
if (platformOrderNo == null || platformOrderNo.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
LambdaQueryWrapper<OrderPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderPO::getPlatformOrderNo, platformOrderNo.trim())
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.in(OrderPO::getProductSpecId, specIds)
|
||||
.ge(OrderPO::getOrderTime, startTime)
|
||||
.le(OrderPO::getOrderTime, endTime));
|
||||
return cnt == null ? 0L : cnt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> specIdsHavingOrders(Long companyId, List<Long> specIds) {
|
||||
if (specIds == null || specIds.isEmpty()) {
|
||||
return List.of();
|
||||
.eq(OrderPO::getShopId, shopId);
|
||||
if (excludeId != null) {
|
||||
wrapper.ne(OrderPO::getId, excludeId);
|
||||
}
|
||||
List<OrderPO> rows = list(new LambdaQueryWrapper<OrderPO>()
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.in(OrderPO::getProductSpecId, specIds)
|
||||
.select(OrderPO::getProductSpecId));
|
||||
return rows.stream()
|
||||
.map(OrderPO::getProductSpecId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean companyHasOrdersForSpec(Long companyId, Long specId) {
|
||||
if (companyId == null || specId == null) {
|
||||
return false;
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台订单号已存在");
|
||||
}
|
||||
Long c = baseMapper.selectCount(new LambdaQueryWrapper<OrderPO>()
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.eq(OrderPO::getProductSpecId, specId));
|
||||
return c != null && c > 0;
|
||||
}
|
||||
|
||||
private static void validateOrderStatus(String status) {
|
||||
if (!OrderStatus.isValid(status)) {
|
||||
throw new BusinessException("订单状态无效");
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillStatusMeta(OrderVO orderVO, String statusCode) {
|
||||
if (statusCode == null || statusCode.isBlank()) {
|
||||
return;
|
||||
}
|
||||
OrderStatus status = OrderStatus.fromCode(statusCode);
|
||||
orderVO.setStatusLabel(status.getLabel());
|
||||
orderVO.setStatusColor(status.getColor());
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -38,17 +38,17 @@ public interface OrderStatRefreshMapper extends BaseMapper<OrderStatRefreshQueue
|
||||
@Param("shopId") Long shopId,
|
||||
@Param("start") LocalDateTime start,
|
||||
@Param("end") LocalDateTime end,
|
||||
@Param("unionStatusIds") List<Long> unionStatusIds,
|
||||
@Param("salesStatusIds") List<Long> salesStatusIds,
|
||||
@Param("refundStatusIds") List<Long> refundStatusIds,
|
||||
@Param("productCostStatusIds") List<Long> productCostStatusIds,
|
||||
@Param("freightCostStatusIds") List<Long> freightCostStatusIds,
|
||||
@Param("otherCostStatusIds") List<Long> otherCostStatusIds);
|
||||
@Param("unionStatusCodes") List<String> unionStatusCodes,
|
||||
@Param("salesStatusCodes") List<String> salesStatusCodes,
|
||||
@Param("refundStatusCodes") List<String> refundStatusCodes,
|
||||
@Param("productCostStatusCodes") List<String> productCostStatusCodes,
|
||||
@Param("freightCostStatusCodes") List<String> freightCostStatusCodes,
|
||||
@Param("otherCostStatusCodes") List<String> otherCostStatusCodes);
|
||||
|
||||
@Data
|
||||
class SpecDayRow {
|
||||
private Long productId;
|
||||
private Long productSpecId;
|
||||
private Long productSkuId;
|
||||
private BigDecimal salesAmount;
|
||||
private Long orderCount;
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
+2
-2
@@ -13,10 +13,10 @@ public class OrderStatMetricsDTO {
|
||||
|
||||
private LocalDate statDate;
|
||||
private Long shopId;
|
||||
private Long platformId;
|
||||
private String platformCode;
|
||||
private Long productId;
|
||||
private Long categoryId;
|
||||
private Long productSpecId;
|
||||
private Long productSkuId;
|
||||
|
||||
private BigDecimal salesAmount = BigDecimal.ZERO;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ public class OrderStatDailyShopPO {
|
||||
@TableField("shop_id")
|
||||
private Long shopId;
|
||||
|
||||
@TableField("platform_id")
|
||||
private Long platformId;
|
||||
@TableField("platform_code")
|
||||
private String platformCode;
|
||||
|
||||
@TableField("stat_date")
|
||||
private LocalDate statDate;
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ public class OrderStatDailySpecPO {
|
||||
@TableField("product_id")
|
||||
private Long productId;
|
||||
|
||||
@TableField("product_spec_id")
|
||||
private Long productSpecId;
|
||||
@TableField("product_sku_id")
|
||||
private Long productSkuId;
|
||||
|
||||
@TableField("stat_date")
|
||||
private LocalDate statDate;
|
||||
|
||||
+4
-4
@@ -63,7 +63,7 @@ public class OrderStatReadFacade {
|
||||
OrderStatParamHelper.freightCostList(stat), OrderStatParamHelper.otherCostList(stat));
|
||||
}
|
||||
orderStatQueryService.ensureStatReady(companyId, shopIds, startDate, endDate);
|
||||
Map<Long, Long> platformByShop = platformByShop(shopIds);
|
||||
Map<Long, String> platformByShop = platformByShop(shopIds);
|
||||
List<OrderStatMetricsDTO> rows = orderStatQueryMapper.sumDailyProductByShopProduct(
|
||||
companyId, shopIds, startDate, endDate);
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
@@ -73,7 +73,7 @@ public class OrderStatReadFacade {
|
||||
for (OrderStatMetricsDTO m : rows) {
|
||||
OrderStatAggMapper.ShopProductRow r = new OrderStatAggMapper.ShopProductRow();
|
||||
r.setShopId(m.getShopId());
|
||||
r.setPlatformId(platformByShop.get(m.getShopId()));
|
||||
r.setPlatformCode(platformByShop.get(m.getShopId()));
|
||||
r.setProductId(m.getProductId());
|
||||
r.setCategoryId(m.getCategoryId());
|
||||
r.setSalesAmount(m.getSalesAmount());
|
||||
@@ -271,12 +271,12 @@ public class OrderStatReadFacade {
|
||||
return row != null ? row : new OrderStatAggMapper.FeeKpiRow();
|
||||
}
|
||||
|
||||
private Map<Long, Long> platformByShop(List<Long> shopIds) {
|
||||
private Map<Long, String> platformByShop(List<Long> shopIds) {
|
||||
if (shopIds == null || shopIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return shopService.listByIds(shopIds).stream()
|
||||
.collect(Collectors.toMap(ShopPO::getId, s -> s.getPlatformId() != null ? s.getPlatformId() : 0L, (a, b) -> a));
|
||||
.collect(Collectors.toMap(ShopPO::getId, s -> s.getPlatformCode(), (a, b) -> a));
|
||||
}
|
||||
|
||||
private enum Period { CUR, PREV, YOY }
|
||||
|
||||
+4
-6
@@ -6,6 +6,7 @@ import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.model.dto.OrderStatMetricsDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.support.OrderStatParamHelper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatResolver;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
@@ -79,8 +80,9 @@ public class OrderStatReconcileService {
|
||||
OrderStatMetricsDTO daily = orderStatReadFacade.sumShopMetrics(companyId, List.of(shopId), d, d);
|
||||
List<OrderStatAggMapper.ShopProductRow> rows = orderStatAggMapper.aggregateByShopProduct(
|
||||
companyId, List.of(shopId), d.atStartOfDay(), d.atTime(23, 59, 59),
|
||||
stat.getUnionStatusIds(), list(stat.getSalesIds()), list(stat.getRefundIds()),
|
||||
list(stat.getProductCostIds()), list(stat.getFreightCostIds()), list(stat.getOtherCostIds()));
|
||||
OrderStatParamHelper.unionList(stat), OrderStatParamHelper.salesList(stat),
|
||||
OrderStatParamHelper.refundList(stat), OrderStatParamHelper.productCostList(stat),
|
||||
OrderStatParamHelper.freightCostList(stat), OrderStatParamHelper.otherCostList(stat));
|
||||
BigDecimal aggSales = BigDecimal.ZERO;
|
||||
for (OrderStatAggMapper.ShopProductRow r : rows) {
|
||||
aggSales = aggSales.add(nz(r.getSalesAmount()));
|
||||
@@ -115,10 +117,6 @@ public class OrderStatReconcileService {
|
||||
return pool.subList(0, Math.min(sampleSize, pool.size()));
|
||||
}
|
||||
|
||||
private static List<Long> list(java.util.Set<Long> ids) {
|
||||
return ids == null ? List.of() : new ArrayList<>(ids);
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
+10
-10
@@ -74,10 +74,10 @@ public class OrderStatRefreshService {
|
||||
OrderStatParamHelper.freightCostList(stat),
|
||||
OrderStatParamHelper.otherCostList(stat));
|
||||
|
||||
Long platformId = resolvePlatformId(shopId);
|
||||
String platformCode = resolvePlatformCode(shopId);
|
||||
Integer gmvOrderCount = orderStatRefreshMapper.countGmvOrdersByShopDay(
|
||||
companyId, shopId, start, end);
|
||||
OrderStatDailyShopPO shopRow = buildShopRow(companyId, shopId, platformId, statDate, productRows,
|
||||
OrderStatDailyShopPO shopRow = buildShopRow(companyId, shopId, platformCode, statDate, productRows,
|
||||
gmvOrderCount != null ? gmvOrderCount : 0);
|
||||
orderStatDailyMapper.upsertDailyShop(shopRow);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class OrderStatRefreshService {
|
||||
}
|
||||
|
||||
orderStatDailyMapper.deleteDailySpec(companyId, shopId, statDate);
|
||||
List<OrderStatRefreshMapper.SpecDayRow> specRows = orderStatRefreshMapper.aggregateSpecByShopDay(
|
||||
List<OrderStatRefreshMapper.SpecDayRow> skuRows = orderStatRefreshMapper.aggregateSpecByShopDay(
|
||||
companyId, shopId, start, end,
|
||||
OrderStatParamHelper.unionList(stat),
|
||||
OrderStatParamHelper.salesList(stat),
|
||||
@@ -96,7 +96,7 @@ public class OrderStatRefreshService {
|
||||
OrderStatParamHelper.productCostList(stat),
|
||||
OrderStatParamHelper.freightCostList(stat),
|
||||
OrderStatParamHelper.otherCostList(stat));
|
||||
List<OrderStatDailySpecPO> dailySpecs = buildSpecRows(companyId, shopId, statDate, specRows);
|
||||
List<OrderStatDailySpecPO> dailySpecs = buildSpecRows(companyId, shopId, statDate, skuRows);
|
||||
if (!dailySpecs.isEmpty()) {
|
||||
orderStatDailyMapper.batchInsertDailySpec(dailySpecs);
|
||||
}
|
||||
@@ -104,16 +104,16 @@ public class OrderStatRefreshService {
|
||||
orderStatRollupService.rollupAfterDailyChange(companyId, shopId, statDate);
|
||||
}
|
||||
|
||||
private Long resolvePlatformId(Long shopId) {
|
||||
private String resolvePlatformCode(Long shopId) {
|
||||
ShopPO shop = shopMapper.selectById(shopId);
|
||||
return shop != null ? shop.getPlatformId() : null;
|
||||
return shop != null ? shop.getPlatformCode() : null;
|
||||
}
|
||||
|
||||
private void writeEmptyShopDay(Long companyId, Long shopId, LocalDate statDate) {
|
||||
OrderStatDailyShopPO row = new OrderStatDailyShopPO();
|
||||
row.setCompanyId(companyId);
|
||||
row.setShopId(shopId);
|
||||
row.setPlatformId(resolvePlatformId(shopId));
|
||||
row.setPlatformCode(resolvePlatformCode(shopId));
|
||||
row.setStatDate(statDate);
|
||||
row.setSalesAmount(BigDecimal.ZERO);
|
||||
row.setRefundAmount(BigDecimal.ZERO);
|
||||
@@ -129,7 +129,7 @@ public class OrderStatRefreshService {
|
||||
orderStatDailyMapper.upsertDailyShop(row);
|
||||
}
|
||||
|
||||
private static OrderStatDailyShopPO buildShopRow(Long companyId, Long shopId, Long platformId,
|
||||
private static OrderStatDailyShopPO buildShopRow(Long companyId, Long shopId, String platformCode,
|
||||
LocalDate statDate,
|
||||
List<OrderStatAggMapper.ShopProductRow> rows,
|
||||
int gmvOrderCount) {
|
||||
@@ -156,7 +156,7 @@ public class OrderStatRefreshService {
|
||||
OrderStatDailyShopPO row = new OrderStatDailyShopPO();
|
||||
row.setCompanyId(companyId);
|
||||
row.setShopId(shopId);
|
||||
row.setPlatformId(platformId);
|
||||
row.setPlatformCode(platformCode);
|
||||
row.setStatDate(statDate);
|
||||
row.setSalesAmount(sales);
|
||||
row.setRefundAmount(refund);
|
||||
@@ -212,7 +212,7 @@ public class OrderStatRefreshService {
|
||||
s.setCompanyId(companyId);
|
||||
s.setShopId(shopId);
|
||||
s.setProductId(r.getProductId() != null ? r.getProductId() : 0L);
|
||||
s.setProductSpecId(r.getProductSpecId() != null ? r.getProductSpecId() : 0L);
|
||||
s.setProductSkuId(r.getProductSkuId() != null ? r.getProductSkuId() : 0L);
|
||||
s.setStatDate(statDate);
|
||||
s.setSalesAmount(nz(r.getSalesAmount()));
|
||||
s.setRefundAmount(nz(r.getRefundAmount()));
|
||||
|
||||
+17
-17
@@ -6,42 +6,42 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** 将 OrderStatusStatSets 转为 MyBatis IN 列表参数。 */
|
||||
/** 将 OrderStatusStatSets 转为 MyBatis IN 列表参数(状态码)。 */
|
||||
public final class OrderStatParamHelper {
|
||||
|
||||
private OrderStatParamHelper() {
|
||||
}
|
||||
|
||||
public static List<Long> statusList(java.util.Collection<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return List.of(-1L);
|
||||
public static List<String> statusList(java.util.Collection<String> codes) {
|
||||
if (codes == null || codes.isEmpty()) {
|
||||
return List.of("__NONE__");
|
||||
}
|
||||
List<Long> list = new ArrayList<>(ids);
|
||||
List<String> list = new ArrayList<>(codes);
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Long> unionList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getUnionStatusIds());
|
||||
public static List<String> unionList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getUnionStatusCodes());
|
||||
}
|
||||
|
||||
public static List<Long> salesList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getSalesIds());
|
||||
public static List<String> salesList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getSalesCodes());
|
||||
}
|
||||
|
||||
public static List<Long> refundList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getRefundIds());
|
||||
public static List<String> refundList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getRefundCodes());
|
||||
}
|
||||
|
||||
public static List<Long> productCostList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getProductCostIds());
|
||||
public static List<String> productCostList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getProductCostCodes());
|
||||
}
|
||||
|
||||
public static List<Long> freightCostList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getFreightCostIds());
|
||||
public static List<String> freightCostList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getFreightCostCodes());
|
||||
}
|
||||
|
||||
public static List<Long> otherCostList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getOtherCostIds());
|
||||
public static List<String> otherCostList(OrderStatusStatSets stat) {
|
||||
return statusList(stat.getOtherCostCodes());
|
||||
}
|
||||
}
|
||||
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.PatchOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单状态管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-订单状态管理", description = "订单状态的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/order-status")
|
||||
public class OrderStatusController {
|
||||
|
||||
private final OrderStatusService orderStatusService;
|
||||
|
||||
public OrderStatusController(OrderStatusService orderStatusService) {
|
||||
this.orderStatusService = orderStatusService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建订单状态", description = "创建新的订单状态")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ecom:order:manage", description = "创建订单状态", allowSuper = true)
|
||||
public ApiResponse<OrderStatusVO> createOrderStatus(@Valid @RequestBody CreateOrderStatusDTO createOrderStatusDTO) {
|
||||
OrderStatusVO orderStatusVO = orderStatusService.createOrderStatus(createOrderStatusDTO);
|
||||
return ApiResponse.success("订单状态创建成功", orderStatusVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单状态", description = "更新现有订单状态信息")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:order:manage", description = "更新订单状态", allowSuper = true)
|
||||
public ApiResponse<OrderStatusVO> updateOrderStatus(@Valid @RequestBody UpdateOrderStatusDTO updateOrderStatusDTO,
|
||||
@Parameter(description = "订单状态ID") @PathVariable Long id) {
|
||||
OrderStatusVO orderStatusVO = orderStatusService.updateOrderStatus(updateOrderStatusDTO, id);
|
||||
return ApiResponse.success("订单状态更新成功", orderStatusVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "部分更新订单状态", description = "仅更新自动统计和退款状态字段")
|
||||
@PatchMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:order:manage", description = "部分更新订单状态", allowSuper = true)
|
||||
public ApiResponse<OrderStatusVO> patchOrderStatus(@Valid @RequestBody PatchOrderStatusDTO patchDTO,
|
||||
@Parameter(description = "订单状态ID") @PathVariable Long id) {
|
||||
OrderStatusVO orderStatusVO = orderStatusService.patchOrderStatus(patchDTO, id);
|
||||
return ApiResponse.success("订单状态更新成功", orderStatusVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除订单状态", description = "删除指定订单状态")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ecom:order:manage", description = "删除订单状态", allowSuper = true)
|
||||
public ApiResponse<Void> deleteOrderStatus(
|
||||
@Parameter(description = "订单状态ID") @PathVariable Long id) {
|
||||
orderStatusService.deleteOrderStatus(id);
|
||||
return ApiResponse.success("订单状态删除成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有订单状态", description = "获取当前公司的所有订单状态列表")
|
||||
@GetMapping("/list")
|
||||
@RequirePermission(value = "ecom:order:read", description = "查询订单状态列表", allowSuper = true)
|
||||
public ApiResponse<List<OrderStatusVO>> getAllOrderStatuses() {
|
||||
List<OrderStatusVO> result = orderStatusService.getAllOrderStatuses();
|
||||
return ApiResponse.success("获取订单状态列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取订单状态详情", description = "根据ID获取订单状态详情")
|
||||
@GetMapping("/detail/{id}")
|
||||
@RequirePermission(value = "ecom:order:read", description = "查询订单状态详情", allowSuper = true)
|
||||
public ApiResponse<OrderStatusVO> getOrderStatusById(
|
||||
@Parameter(description = "订单状态ID") @PathVariable Long id) {
|
||||
OrderStatusVO orderStatusVO = orderStatusService.getOrderStatusById(id);
|
||||
return ApiResponse.success("获取订单状态详情成功", orderStatusVO);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusMetaVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusMetaSupport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单状态静态字典(无 CRUD)。
|
||||
*/
|
||||
@Tag(name = "电商-订单状态字典", description = "订单状态枚举元数据")
|
||||
@RestController
|
||||
@RequestMapping("/ec/order-status")
|
||||
public class OrderStatusDictController {
|
||||
|
||||
@Operation(summary = "获取订单状态列表", description = "返回全局固定枚举元数据")
|
||||
@GetMapping("/list")
|
||||
@RequirePermission(value = "ecom:order:read", description = "查询订单状态列表", allowSuper = true)
|
||||
public ApiResponse<List<OrderStatusMetaVO>> listOrderStatuses() {
|
||||
return ApiResponse.success("获取订单状态列表成功", OrderStatusMetaSupport.allMeta());
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 订单状态Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderStatusMapper extends BaseMapper<OrderStatusPO> {
|
||||
}
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建订单状态DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建订单状态DTO")
|
||||
public class CreateOrderStatusDTO {
|
||||
|
||||
/**
|
||||
* 状态名称(中文)
|
||||
*/
|
||||
@Schema(description = "状态名称", example = "待发货", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "状态名称不能为空")
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
@Schema(description = "状态描述", example = "订单已创建,等待商家发货")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态颜色(十六进制,如 #1890ff)
|
||||
*/
|
||||
@Schema(description = "状态颜色", example = "#1890ff")
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "是否计入销售额/单量等统计 0否 1是", example = "1")
|
||||
private Integer includeSalesAmount;
|
||||
|
||||
@Schema(description = "是否计入商品成本统计 0否 1是", example = "1")
|
||||
private Integer includeProductCost;
|
||||
|
||||
@Schema(description = "是否计入运费成本统计 0否 1是", example = "1")
|
||||
private Integer includeFreightCost;
|
||||
|
||||
@Schema(description = "是否计入其他成本统计 0否 1是", example = "1")
|
||||
private Integer includeOtherCost;
|
||||
|
||||
@Schema(description = "是否计入退款金额统计 0否 1是", example = "0")
|
||||
private Integer includeRefund;
|
||||
}
|
||||
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 部分更新订单状态DTO(仅用于PATCH)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "部分更新订单状态DTO")
|
||||
public class PatchOrderStatusDTO {
|
||||
|
||||
@Schema(description = "是否计入销售额/单量等统计 0否 1是", example = "1")
|
||||
private Integer includeSalesAmount;
|
||||
|
||||
@Schema(description = "是否计入商品成本统计 0否 1是", example = "1")
|
||||
private Integer includeProductCost;
|
||||
|
||||
@Schema(description = "是否计入运费成本统计 0否 1是", example = "1")
|
||||
private Integer includeFreightCost;
|
||||
|
||||
@Schema(description = "是否计入其他成本统计 0否 1是", example = "1")
|
||||
private Integer includeOtherCost;
|
||||
|
||||
@Schema(description = "是否计入退款金额统计 0否 1是", example = "0")
|
||||
private Integer includeRefund;
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新订单状态DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新订单状态DTO")
|
||||
public class UpdateOrderStatusDTO {
|
||||
|
||||
/**
|
||||
* 状态名称(中文)
|
||||
*/
|
||||
@Schema(description = "状态名称", example = "待发货", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "状态名称不能为空")
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
@Schema(description = "状态描述", example = "订单已创建,等待商家发货")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态颜色(十六进制,如 #1890ff)
|
||||
*/
|
||||
@Schema(description = "状态颜色", example = "#1890ff")
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "是否计入销售额/单量等统计 0否 1是", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "includeSalesAmount 不能为空")
|
||||
private Integer includeSalesAmount;
|
||||
|
||||
@Schema(description = "是否计入商品成本统计 0否 1是", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "includeProductCost 不能为空")
|
||||
private Integer includeProductCost;
|
||||
|
||||
@Schema(description = "是否计入运费成本统计 0否 1是", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "includeFreightCost 不能为空")
|
||||
private Integer includeFreightCost;
|
||||
|
||||
@Schema(description = "是否计入其他成本统计 0否 1是", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "includeOtherCost 不能为空")
|
||||
private Integer includeOtherCost;
|
||||
|
||||
@Schema(description = "是否计入退款金额统计 0否 1是", example = "0", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "includeRefund 不能为空")
|
||||
private Integer includeRefund;
|
||||
}
|
||||
|
||||
+74
-49
@@ -2,70 +2,95 @@ package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 订单状态枚举
|
||||
* 内部订单状态(软约定,无状态表)。
|
||||
* 统计五维开关写死在枚举元数据上。
|
||||
*/
|
||||
@Getter
|
||||
public enum OrderStatus {
|
||||
/**
|
||||
* 未知状态
|
||||
*/
|
||||
UNKNOWN("未知状态"),
|
||||
UNKNOWN("UNKNOWN", "未知状态", "#8c8c8c", 0,
|
||||
false, false, false, false, false),
|
||||
PENDING_SHIPMENT("PENDING_SHIPMENT", "待发货", "#1677ff", 10,
|
||||
true, true, true, true, false),
|
||||
SHIPPED("SHIPPED", "已发货", "#13c2c2", 20,
|
||||
true, true, true, true, false),
|
||||
COMPLETED("COMPLETED", "已完成", "#52c41a", 30,
|
||||
true, true, true, true, false),
|
||||
CANCELLED("CANCELLED", "已取消", "#bfbfbf", 40,
|
||||
false, false, false, false, false),
|
||||
REFUNDING("REFUNDING", "退款中", "#fa8c16", 50,
|
||||
false, false, false, false, true),
|
||||
REFUNDED("REFUNDED", "已退款", "#f5222d", 60,
|
||||
false, false, false, false, true);
|
||||
|
||||
/**
|
||||
* 待发货
|
||||
*/
|
||||
PENDING_SHIPMENT("待发货"),
|
||||
private final String code;
|
||||
private final String label;
|
||||
private final String color;
|
||||
private final int sortOrder;
|
||||
private final boolean includeSalesAmount;
|
||||
private final boolean includeProductCost;
|
||||
private final boolean includeFreightCost;
|
||||
private final boolean includeOtherCost;
|
||||
private final boolean includeRefund;
|
||||
|
||||
/**
|
||||
* 已发货
|
||||
*/
|
||||
SHIPPED("已发货"),
|
||||
|
||||
/**
|
||||
* 已完成
|
||||
*/
|
||||
COMPLETED("已完成"),
|
||||
|
||||
/**
|
||||
* 已取消
|
||||
*/
|
||||
CANCELLED("已取消"),
|
||||
|
||||
/**
|
||||
* 退款中
|
||||
*/
|
||||
REFUNDING("退款中"),
|
||||
|
||||
/**
|
||||
* 已退款
|
||||
*/
|
||||
REFUNDED("已退款");
|
||||
|
||||
/**
|
||||
* 状态名称(中文)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
OrderStatus(String name) {
|
||||
this.name = name;
|
||||
OrderStatus(String code, String label, String color, int sortOrder,
|
||||
boolean includeSalesAmount, boolean includeProductCost,
|
||||
boolean includeFreightCost, boolean includeOtherCost,
|
||||
boolean includeRefund) {
|
||||
this.code = code;
|
||||
this.label = label;
|
||||
this.color = color;
|
||||
this.sortOrder = sortOrder;
|
||||
this.includeSalesAmount = includeSalesAmount;
|
||||
this.includeProductCost = includeProductCost;
|
||||
this.includeFreightCost = includeFreightCost;
|
||||
this.includeOtherCost = includeOtherCost;
|
||||
this.includeRefund = includeRefund;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据中文名称获取枚举
|
||||
* @param name 中文名称
|
||||
* @return 订单状态枚举,如果未找到则返回 UNKNOWN
|
||||
*/
|
||||
/** @deprecated 使用 {@link #getLabel()} */
|
||||
@Deprecated
|
||||
public String getName() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public static Optional<OrderStatus> ofCode(String code) {
|
||||
if (code == null || code.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String normalized = code.trim();
|
||||
return Arrays.stream(values())
|
||||
.filter(s -> s.code.equalsIgnoreCase(normalized))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public static OrderStatus fromCode(String code) {
|
||||
return ofCode(code).orElse(UNKNOWN);
|
||||
}
|
||||
|
||||
/** 按中文名解析(导入兼容);未命中返回 UNKNOWN */
|
||||
public static OrderStatus fromName(String name) {
|
||||
if (name == null || name.trim().isEmpty()) {
|
||||
if (name == null || name.isBlank()) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
String trimmed = name.trim();
|
||||
for (OrderStatus status : values()) {
|
||||
if (status.getName().equals(name.trim())) {
|
||||
if (status.label.equals(trimmed) || status.code.equalsIgnoreCase(trimmed)) {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValid(String code) {
|
||||
return ofCode(code).isPresent();
|
||||
}
|
||||
|
||||
public static List<OrderStatus> all() {
|
||||
return Arrays.asList(values());
|
||||
}
|
||||
}
|
||||
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-订单状态实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_order_status")
|
||||
public class OrderStatusPO {
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 状态名称(中文)
|
||||
*/
|
||||
@TableField("status_name")
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态颜色(十六进制,如 #1890ff)
|
||||
*/
|
||||
@TableField("color")
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否计入销售额/单量等统计 0否 1是
|
||||
*/
|
||||
@TableField("include_sales_amount")
|
||||
private Integer includeSalesAmount;
|
||||
|
||||
/**
|
||||
* 是否计入商品成本统计 0否 1是
|
||||
*/
|
||||
@TableField("include_product_cost")
|
||||
private Integer includeProductCost;
|
||||
|
||||
/**
|
||||
* 是否计入运费成本统计 0否 1是
|
||||
*/
|
||||
@TableField("include_freight_cost")
|
||||
private Integer includeFreightCost;
|
||||
|
||||
/**
|
||||
* 是否计入其他成本统计 0否 1是
|
||||
*/
|
||||
@TableField("include_other_cost")
|
||||
private Integer includeOtherCost;
|
||||
|
||||
/**
|
||||
* 是否计入退款金额统计 0否 1是
|
||||
*/
|
||||
@TableField("include_refund")
|
||||
private Integer includeRefund;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 订单状态枚举元数据(静态字典,无 DB 主键)。
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "订单状态元数据")
|
||||
public class OrderStatusMetaVO {
|
||||
|
||||
@Schema(description = "状态码", example = "PENDING_SHIPMENT")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "状态名称", example = "待发货")
|
||||
private String label;
|
||||
|
||||
@Schema(description = "展示颜色", example = "#1677ff")
|
||||
private String color;
|
||||
|
||||
@Schema(description = "排序", example = "10")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "是否计入销售额/单量")
|
||||
private boolean includeSalesAmount;
|
||||
|
||||
@Schema(description = "是否计入商品成本")
|
||||
private boolean includeProductCost;
|
||||
|
||||
@Schema(description = "是否计入运费成本")
|
||||
private boolean includeFreightCost;
|
||||
|
||||
@Schema(description = "是否计入其他成本")
|
||||
private boolean includeOtherCost;
|
||||
|
||||
@Schema(description = "是否计入退款")
|
||||
private boolean includeRefund;
|
||||
}
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单状态VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "订单状态VO")
|
||||
public class OrderStatusVO {
|
||||
|
||||
/**
|
||||
* 订单状态ID
|
||||
*/
|
||||
@Schema(description = "订单状态ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@Schema(description = "公司ID", example = "1")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 状态名称(中文)
|
||||
*/
|
||||
@Schema(description = "状态名称", example = "待发货")
|
||||
private String statusName;
|
||||
|
||||
/**
|
||||
* 状态描述
|
||||
*/
|
||||
@Schema(description = "状态描述", example = "订单已创建,等待商家发货")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 状态颜色(十六进制,如 #1890ff)
|
||||
*/
|
||||
@Schema(description = "状态颜色", example = "#1890ff")
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
@Schema(description = "是否计入销售额/单量等统计 0否 1是", example = "1")
|
||||
private Integer includeSalesAmount;
|
||||
|
||||
@Schema(description = "是否计入商品成本统计 0否 1是", example = "1")
|
||||
private Integer includeProductCost;
|
||||
|
||||
@Schema(description = "是否计入运费成本统计 0否 1是", example = "1")
|
||||
private Integer includeFreightCost;
|
||||
|
||||
@Schema(description = "是否计入其他成本统计 0否 1是", example = "1")
|
||||
private Integer includeOtherCost;
|
||||
|
||||
@Schema(description = "是否计入退款金额统计 0否 1是", example = "0")
|
||||
private Integer includeRefund;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Schema(description = "创建人ID", example = "1")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Schema(description = "更新人ID", example = "1")
|
||||
private Long updateBy;
|
||||
}
|
||||
|
||||
-66
@@ -1,66 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.PatchOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单状态服务接口
|
||||
*/
|
||||
public interface OrderStatusService extends IService<OrderStatusPO> {
|
||||
|
||||
/**
|
||||
* 创建订单状态
|
||||
*
|
||||
* @param createOrderStatusDTO 创建订单状态DTO
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
OrderStatusVO createOrderStatus(CreateOrderStatusDTO createOrderStatusDTO);
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*
|
||||
* @param updateOrderStatusDTO 更新订单状态DTO
|
||||
* @param id 订单状态ID
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
OrderStatusVO updateOrderStatus(UpdateOrderStatusDTO updateOrderStatusDTO, Long id);
|
||||
|
||||
/**
|
||||
* 部分更新订单状态(仅更新各统计维度开关)
|
||||
*
|
||||
* @param patchDTO 部分更新DTO
|
||||
* @param id 订单状态ID
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
OrderStatusVO patchOrderStatus(PatchOrderStatusDTO patchDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除订单状态
|
||||
*
|
||||
* @param id 订单状态ID
|
||||
*/
|
||||
void deleteOrderStatus(Long id);
|
||||
|
||||
/**
|
||||
* 获取所有订单状态(当前公司)
|
||||
*
|
||||
* @return 订单状态列表
|
||||
*/
|
||||
List<OrderStatusVO> getAllOrderStatuses();
|
||||
|
||||
/**
|
||||
* 根据ID获取订单状态
|
||||
*
|
||||
* @param id 订单状态ID
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
OrderStatusVO getOrderStatusById(Long id);
|
||||
}
|
||||
|
||||
-315
@@ -1,315 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatRebuildService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.mapper.OrderStatusMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.CreateOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.PatchOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.dto.UpdateOrderStatusDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单状态服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class OrderStatusServiceImpl extends ServiceImpl<OrderStatusMapper, OrderStatusPO> implements OrderStatusService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final OrderStatRebuildService orderStatRebuildService;
|
||||
private final OrderMapper orderMapper;
|
||||
|
||||
public OrderStatusServiceImpl(CurrentUserContext currentUserContext,
|
||||
@Lazy OrderStatRebuildService orderStatRebuildService,
|
||||
OrderMapper orderMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderStatRebuildService = orderStatRebuildService;
|
||||
this.orderMapper = orderMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单状态
|
||||
*
|
||||
* @param createOrderStatusDTO 创建订单状态DTO
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderStatusVO createOrderStatus(CreateOrderStatusDTO createOrderStatusDTO) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证状态名称是否重复(同一公司内)
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(OrderStatusPO::getStatusName, createOrderStatusDTO.getStatusName());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("状态名称已存在");
|
||||
}
|
||||
|
||||
// 创建订单状态
|
||||
OrderStatusPO orderStatus = new OrderStatusPO();
|
||||
BeanCopyUtils.copyProperties(createOrderStatusDTO, orderStatus);
|
||||
orderStatus.setCompanyId(companyId);
|
||||
|
||||
// 设置默认值
|
||||
if (orderStatus.getSortOrder() == null) {
|
||||
orderStatus.setSortOrder(0);
|
||||
}
|
||||
applyStatDefaultsForCreate(orderStatus);
|
||||
|
||||
// 设置创建人ID
|
||||
orderStatus.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存订单状态
|
||||
this.save(orderStatus);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(orderStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单状态
|
||||
*
|
||||
* @param updateOrderStatusDTO 更新订单状态DTO
|
||||
* @param id 订单状态ID
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderStatusVO updateOrderStatus(UpdateOrderStatusDTO updateOrderStatusDTO, Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证订单状态是否存在
|
||||
OrderStatusPO existingStatus = this.getById(id);
|
||||
if (existingStatus == null || !existingStatus.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单状态不存在");
|
||||
}
|
||||
|
||||
// 验证状态名称是否重复(排除当前记录)
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.eq(OrderStatusPO::getStatusName, updateOrderStatusDTO.getStatusName())
|
||||
.ne(OrderStatusPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("状态名称已存在");
|
||||
}
|
||||
|
||||
// 更新前快照五维开关,用于检测是否需全公司 rebuild
|
||||
OrderStatusPO beforeStat = snapshotStatDimensions(existingStatus);
|
||||
|
||||
// 更新订单状态
|
||||
OrderStatusPO orderStatus = new OrderStatusPO();
|
||||
BeanCopyUtils.copyProperties(updateOrderStatusDTO, orderStatus);
|
||||
orderStatus.setId(id);
|
||||
orderStatus.setCompanyId(companyId);
|
||||
|
||||
// 设置更新人ID
|
||||
orderStatus.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 更新订单状态
|
||||
this.updateById(orderStatus);
|
||||
|
||||
maybeScheduleCompanyRebuild(companyId, beforeStat, snapshotStatDimensions(orderStatus));
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(orderStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 部分更新订单状态(仅更新各统计维度开关)
|
||||
*
|
||||
* @param patchDTO 部分更新DTO
|
||||
* @param id 订单状态ID
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderStatusVO patchOrderStatus(PatchOrderStatusDTO patchDTO, Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证订单状态是否存在
|
||||
OrderStatusPO existingStatus = this.getById(id);
|
||||
if (existingStatus == null || !existingStatus.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单状态不存在");
|
||||
}
|
||||
|
||||
OrderStatusPO beforeStat = snapshotStatDimensions(existingStatus);
|
||||
|
||||
if (patchDTO.getIncludeSalesAmount() != null) {
|
||||
existingStatus.setIncludeSalesAmount(patchDTO.getIncludeSalesAmount());
|
||||
}
|
||||
if (patchDTO.getIncludeProductCost() != null) {
|
||||
existingStatus.setIncludeProductCost(patchDTO.getIncludeProductCost());
|
||||
}
|
||||
if (patchDTO.getIncludeFreightCost() != null) {
|
||||
existingStatus.setIncludeFreightCost(patchDTO.getIncludeFreightCost());
|
||||
}
|
||||
if (patchDTO.getIncludeOtherCost() != null) {
|
||||
existingStatus.setIncludeOtherCost(patchDTO.getIncludeOtherCost());
|
||||
}
|
||||
if (patchDTO.getIncludeRefund() != null) {
|
||||
existingStatus.setIncludeRefund(patchDTO.getIncludeRefund());
|
||||
}
|
||||
existingStatus.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
this.updateById(existingStatus);
|
||||
maybeScheduleCompanyRebuild(companyId, beforeStat, snapshotStatDimensions(existingStatus));
|
||||
return convertToVO(existingStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单状态
|
||||
*
|
||||
* @param id 订单状态ID
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteOrderStatus(Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证订单状态是否存在
|
||||
OrderStatusPO existingStatus = this.getById(id);
|
||||
if (existingStatus == null || !existingStatus.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单状态不存在");
|
||||
}
|
||||
|
||||
// 检查是否有订单使用此状态
|
||||
// TODO: 这里可以添加检查逻辑,如果有订单使用此状态,可以阻止删除或提示
|
||||
|
||||
// 删除后统计口径集合变化,需全公司 rebuild
|
||||
scheduleCompanyRebuild(companyId);
|
||||
|
||||
// 删除订单状态
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有订单状态(当前公司)
|
||||
*
|
||||
* @return 订单状态列表
|
||||
*/
|
||||
@Override
|
||||
public List<OrderStatusVO> getAllOrderStatuses() {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 查询当前公司的所有订单状态
|
||||
LambdaQueryWrapper<OrderStatusPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(OrderStatusPO::getCompanyId, companyId)
|
||||
.orderByAsc(OrderStatusPO::getSortOrder)
|
||||
.orderByDesc(OrderStatusPO::getCreateTime);
|
||||
|
||||
List<OrderStatusPO> statusList = this.list(wrapper);
|
||||
|
||||
// 转换为VO列表
|
||||
return statusList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取订单状态
|
||||
*
|
||||
* @param id 订单状态ID
|
||||
* @return 订单状态VO
|
||||
*/
|
||||
@Override
|
||||
public OrderStatusVO getOrderStatusById(Long id) {
|
||||
// 从token中获取公司ID
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证订单状态是否存在
|
||||
OrderStatusPO orderStatus = this.getById(id);
|
||||
if (orderStatus == null || !orderStatus.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("订单状态不存在");
|
||||
}
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(orderStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private OrderStatusVO convertToVO(OrderStatusPO orderStatus) {
|
||||
OrderStatusVO vo = new OrderStatusVO();
|
||||
BeanCopyUtils.copyProperties(orderStatus, vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 五维统计开关是否变化(影响历史汇总列含义) */
|
||||
private static boolean statDimensionsChanged(OrderStatusPO before, OrderStatusPO after) {
|
||||
if (before == null || after == null) {
|
||||
return false;
|
||||
}
|
||||
return !Objects.equals(before.getIncludeSalesAmount(), after.getIncludeSalesAmount())
|
||||
|| !Objects.equals(before.getIncludeProductCost(), after.getIncludeProductCost())
|
||||
|| !Objects.equals(before.getIncludeFreightCost(), after.getIncludeFreightCost())
|
||||
|| !Objects.equals(before.getIncludeOtherCost(), after.getIncludeOtherCost())
|
||||
|| !Objects.equals(before.getIncludeRefund(), after.getIncludeRefund());
|
||||
}
|
||||
|
||||
private static OrderStatusPO snapshotStatDimensions(OrderStatusPO src) {
|
||||
OrderStatusPO copy = new OrderStatusPO();
|
||||
copy.setIncludeSalesAmount(src.getIncludeSalesAmount());
|
||||
copy.setIncludeProductCost(src.getIncludeProductCost());
|
||||
copy.setIncludeFreightCost(src.getIncludeFreightCost());
|
||||
copy.setIncludeOtherCost(src.getIncludeOtherCost());
|
||||
copy.setIncludeRefund(src.getIncludeRefund());
|
||||
return copy;
|
||||
}
|
||||
|
||||
private void maybeScheduleCompanyRebuild(Long companyId, OrderStatusPO before, OrderStatusPO after) {
|
||||
if (!statDimensionsChanged(before, after)) {
|
||||
return;
|
||||
}
|
||||
scheduleCompanyRebuild(companyId);
|
||||
}
|
||||
|
||||
/** 状态配置变更后异步全公司 backfill */
|
||||
private void scheduleCompanyRebuild(Long companyId) {
|
||||
LocalDate start = orderMapper.selectMinOrderDateByCompany(companyId);
|
||||
LocalDate end = orderMapper.selectMaxOrderDateByCompany(companyId);
|
||||
if (start == null || end == null) {
|
||||
return;
|
||||
}
|
||||
orderStatRebuildService.scheduleRebuild(companyId, null, start, end);
|
||||
}
|
||||
|
||||
/** 创建时未传的统计开关默认:前四项参与(等同原 auto_statistics=1),退款不参与 */
|
||||
private void applyStatDefaultsForCreate(OrderStatusPO p) {
|
||||
if (p.getIncludeSalesAmount() == null) {
|
||||
p.setIncludeSalesAmount(1);
|
||||
}
|
||||
if (p.getIncludeProductCost() == null) {
|
||||
p.setIncludeProductCost(1);
|
||||
}
|
||||
if (p.getIncludeFreightCost() == null) {
|
||||
p.setIncludeFreightCost(1);
|
||||
}
|
||||
if (p.getIncludeOtherCost() == null) {
|
||||
p.setIncludeOtherCost(1);
|
||||
}
|
||||
if (p.getIncludeRefund() == null) {
|
||||
p.setIncludeRefund(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.support;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.enums.OrderStatus;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.vo.OrderStatusMetaVO;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/** 枚举 → 字典 VO 转换。 */
|
||||
public final class OrderStatusMetaSupport {
|
||||
|
||||
private OrderStatusMetaSupport() {
|
||||
}
|
||||
|
||||
public static List<OrderStatusMetaVO> allMeta() {
|
||||
return OrderStatus.all().stream()
|
||||
.sorted(Comparator.comparingInt(OrderStatus::getSortOrder))
|
||||
.map(OrderStatusMetaSupport::toMeta)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static OrderStatusMetaVO toMeta(OrderStatus status) {
|
||||
OrderStatusMetaVO vo = new OrderStatusMetaVO();
|
||||
vo.setCode(status.getCode());
|
||||
vo.setLabel(status.getLabel());
|
||||
vo.setColor(status.getColor());
|
||||
vo.setSortOrder(status.getSortOrder());
|
||||
vo.setIncludeSalesAmount(status.isIncludeSalesAmount());
|
||||
vo.setIncludeProductCost(status.isIncludeProductCost());
|
||||
vo.setIncludeFreightCost(status.isIncludeFreightCost());
|
||||
vo.setIncludeOtherCost(status.isIncludeOtherCost());
|
||||
vo.setIncludeRefund(status.isIncludeRefund());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+6
-19
@@ -1,32 +1,19 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.service.OrderStatusService;
|
||||
|
||||
import java.util.List;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.enums.OrderStatus;
|
||||
|
||||
/**
|
||||
* 加载当前公司的订单状态并解析为 {@link OrderStatusStatSets}。
|
||||
* 解析订单统计状态集合。去表后全局固定,忽略 companyId。
|
||||
*/
|
||||
@Component
|
||||
public class OrderStatusStatResolver {
|
||||
|
||||
private final OrderStatusService orderStatusService;
|
||||
|
||||
public OrderStatusStatResolver(@Lazy OrderStatusService orderStatusService) {
|
||||
this.orderStatusService = orderStatusService;
|
||||
public OrderStatusStatSets resolve(Long companyId) {
|
||||
return OrderStatusStatSets.global();
|
||||
}
|
||||
|
||||
public OrderStatusStatSets resolve(Long companyId) {
|
||||
if (companyId == null) {
|
||||
return OrderStatusStatSets.from(List.of());
|
||||
}
|
||||
List<OrderStatusPO> list = orderStatusService.list(
|
||||
new LambdaQueryWrapper<OrderStatusPO>()
|
||||
.eq(OrderStatusPO::getCompanyId, companyId));
|
||||
return OrderStatusStatSets.from(list);
|
||||
public OrderStatusStatSets resolve() {
|
||||
return OrderStatusStatSets.global();
|
||||
}
|
||||
}
|
||||
|
||||
+122
-109
@@ -1,83 +1,68 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.status.support;
|
||||
|
||||
import lombok.Getter;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.po.OrderStatusPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.model.enums.OrderStatus;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 订单状态在各统计维度上的生效集合(由 {@link OrderStatusPO} 列表解析)。
|
||||
* 订单状态各统计维度的生效集合(由 {@link OrderStatus} 枚举元数据解析,全局固定)。
|
||||
*/
|
||||
@Getter
|
||||
public final class OrderStatusStatSets {
|
||||
|
||||
private final List<Long> unionStatusIds;
|
||||
private final Set<Long> salesIds;
|
||||
private final Set<Long> productCostIds;
|
||||
private final Set<Long> freightCostIds;
|
||||
private final Set<Long> otherCostIds;
|
||||
private final Set<Long> refundIds;
|
||||
private static final OrderStatusStatSets GLOBAL = fromEnum();
|
||||
|
||||
private OrderStatusStatSets(List<Long> unionStatusIds,
|
||||
Set<Long> salesIds,
|
||||
Set<Long> productCostIds,
|
||||
Set<Long> freightCostIds,
|
||||
Set<Long> otherCostIds,
|
||||
Set<Long> refundIds) {
|
||||
this.unionStatusIds = unionStatusIds;
|
||||
this.salesIds = salesIds;
|
||||
this.productCostIds = productCostIds;
|
||||
this.freightCostIds = freightCostIds;
|
||||
this.otherCostIds = otherCostIds;
|
||||
this.refundIds = refundIds;
|
||||
private final List<String> unionStatusCodes;
|
||||
private final Set<String> salesCodes;
|
||||
private final Set<String> productCostCodes;
|
||||
private final Set<String> freightCostCodes;
|
||||
private final Set<String> otherCostCodes;
|
||||
private final Set<String> refundCodes;
|
||||
|
||||
private OrderStatusStatSets(List<String> unionStatusCodes,
|
||||
Set<String> salesCodes,
|
||||
Set<String> productCostCodes,
|
||||
Set<String> freightCostCodes,
|
||||
Set<String> otherCostCodes,
|
||||
Set<String> refundCodes) {
|
||||
this.unionStatusCodes = unionStatusCodes;
|
||||
this.salesCodes = salesCodes;
|
||||
this.productCostCodes = productCostCodes;
|
||||
this.freightCostCodes = freightCostCodes;
|
||||
this.otherCostCodes = otherCostCodes;
|
||||
this.refundCodes = refundCodes;
|
||||
}
|
||||
|
||||
public static OrderStatusStatSets from(List<OrderStatusPO> statuses) {
|
||||
Set<Long> union = new HashSet<>();
|
||||
Set<Long> sales = new HashSet<>();
|
||||
Set<Long> productCost = new HashSet<>();
|
||||
Set<Long> freightCost = new HashSet<>();
|
||||
Set<Long> otherCost = new HashSet<>();
|
||||
Set<Long> refund = new HashSet<>();
|
||||
for (OrderStatusPO s : statuses) {
|
||||
Long id = s.getId();
|
||||
if (id == null) {
|
||||
continue;
|
||||
}
|
||||
public static OrderStatusStatSets global() {
|
||||
return GLOBAL;
|
||||
}
|
||||
|
||||
private static OrderStatusStatSets fromEnum() {
|
||||
Set<String> sales = new HashSet<>();
|
||||
Set<String> productCost = new HashSet<>();
|
||||
Set<String> freightCost = new HashSet<>();
|
||||
Set<String> otherCost = new HashSet<>();
|
||||
Set<String> refund = new HashSet<>();
|
||||
Set<String> union = new HashSet<>();
|
||||
for (OrderStatus s : OrderStatus.values()) {
|
||||
boolean any = false;
|
||||
if (isOn(s.getIncludeSalesAmount())) {
|
||||
sales.add(id);
|
||||
any = true;
|
||||
}
|
||||
if (isOn(s.getIncludeProductCost())) {
|
||||
productCost.add(id);
|
||||
any = true;
|
||||
}
|
||||
if (isOn(s.getIncludeFreightCost())) {
|
||||
freightCost.add(id);
|
||||
any = true;
|
||||
}
|
||||
if (isOn(s.getIncludeOtherCost())) {
|
||||
otherCost.add(id);
|
||||
any = true;
|
||||
}
|
||||
if (isOn(s.getIncludeRefund())) {
|
||||
refund.add(id);
|
||||
any = true;
|
||||
}
|
||||
if (any) {
|
||||
union.add(id);
|
||||
}
|
||||
if (s.isIncludeSalesAmount()) { sales.add(s.getCode()); any = true; }
|
||||
if (s.isIncludeProductCost()) { productCost.add(s.getCode()); any = true; }
|
||||
if (s.isIncludeFreightCost()) { freightCost.add(s.getCode()); any = true; }
|
||||
if (s.isIncludeOtherCost()) { otherCost.add(s.getCode()); any = true; }
|
||||
if (s.isIncludeRefund()) { refund.add(s.getCode()); any = true; }
|
||||
if (any) union.add(s.getCode());
|
||||
}
|
||||
List<Long> unionList = new ArrayList<>(union);
|
||||
List<String> unionList = new ArrayList<>(union);
|
||||
Collections.sort(unionList);
|
||||
return new OrderStatusStatSets(
|
||||
Collections.unmodifiableList(unionList),
|
||||
@@ -88,83 +73,111 @@ public final class OrderStatusStatSets {
|
||||
Collections.unmodifiableSet(refund));
|
||||
}
|
||||
|
||||
private static boolean isOn(Integer v) {
|
||||
return Objects.equals(v, 1);
|
||||
}
|
||||
|
||||
public boolean isUnionEmpty() {
|
||||
return unionStatusIds.isEmpty();
|
||||
return unionStatusCodes.isEmpty();
|
||||
}
|
||||
|
||||
public boolean includesSales(Long statusId) {
|
||||
return statusId != null && salesIds.contains(statusId);
|
||||
public boolean includesSales(String status) {
|
||||
return status != null && salesCodes.contains(status);
|
||||
}
|
||||
|
||||
public boolean includesProductCost(Long statusId) {
|
||||
return statusId != null && productCostIds.contains(statusId);
|
||||
public boolean includesProductCost(String status) {
|
||||
return status != null && productCostCodes.contains(status);
|
||||
}
|
||||
|
||||
public boolean includesFreightCost(Long statusId) {
|
||||
return statusId != null && freightCostIds.contains(statusId);
|
||||
public boolean includesFreightCost(String status) {
|
||||
return status != null && freightCostCodes.contains(status);
|
||||
}
|
||||
|
||||
public boolean includesOtherCost(Long statusId) {
|
||||
return statusId != null && otherCostIds.contains(statusId);
|
||||
public boolean includesOtherCost(String status) {
|
||||
return status != null && otherCostCodes.contains(status);
|
||||
}
|
||||
|
||||
public boolean includesRefund(Long statusId) {
|
||||
return statusId != null && refundIds.contains(statusId);
|
||||
public boolean includesRefund(String status) {
|
||||
return status != null && refundCodes.contains(status);
|
||||
}
|
||||
|
||||
public List<Long> getRefundStatusIds() {
|
||||
return refundIds.stream().sorted().collect(Collectors.toList());
|
||||
public List<String> getRefundStatusCodes() {
|
||||
return refundCodes.stream().sorted().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static int quantity(OrderPO order) {
|
||||
Integer q = order.getQuantity();
|
||||
public static int quantity(OrderItemPO item) {
|
||||
if (item == null) return 1;
|
||||
Integer q = item.getQuantity();
|
||||
return q != null && q > 0 ? q : 1;
|
||||
}
|
||||
|
||||
public static int totalQuantity(List<OrderItemPO> items) {
|
||||
if (items == null || items.isEmpty()) return 0;
|
||||
int sum = 0;
|
||||
for (OrderItemPO item : items) {
|
||||
sum += quantity(item);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public BigDecimal receivedForSales(OrderPO order) {
|
||||
return includesSales(order.getStatusId())
|
||||
? nz(order.getReceivedAmount())
|
||||
: BigDecimal.ZERO;
|
||||
return includesSales(order.getStatus()) ? nz(order.getPayAmount()) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public BigDecimal productCostForStats(OrderPO order) {
|
||||
if (!includesProductCost(order.getStatusId())) {
|
||||
return BigDecimal.ZERO;
|
||||
public BigDecimal productCostForStats(OrderPO order, OrderItemPO item) {
|
||||
if (!includesProductCost(order.getStatus())) return BigDecimal.ZERO;
|
||||
return nz(item.getProductCost()).multiply(BigDecimal.valueOf(quantity(item)));
|
||||
}
|
||||
|
||||
public BigDecimal freightCostForStats(OrderPO order, OrderItemPO item) {
|
||||
if (!includesFreightCost(order.getStatus())) return BigDecimal.ZERO;
|
||||
return nz(item.getShippingCost()).multiply(BigDecimal.valueOf(quantity(item)));
|
||||
}
|
||||
|
||||
public BigDecimal otherCostForStats(OrderPO order, OrderItemPO item) {
|
||||
if (!includesOtherCost(order.getStatus())) return BigDecimal.ZERO;
|
||||
return nz(item.getOtherCost()).multiply(BigDecimal.valueOf(quantity(item)));
|
||||
}
|
||||
|
||||
public BigDecimal totalCostForStats(OrderPO order, List<OrderItemPO> items) {
|
||||
if (items == null || items.isEmpty()) return BigDecimal.ZERO;
|
||||
BigDecimal sum = BigDecimal.ZERO;
|
||||
for (OrderItemPO item : items) {
|
||||
sum = sum.add(productCostForStats(order, item))
|
||||
.add(freightCostForStats(order, item))
|
||||
.add(otherCostForStats(order, item));
|
||||
}
|
||||
BigDecimal c = nz(order.getProductCost());
|
||||
return c.multiply(BigDecimal.valueOf(quantity(order)));
|
||||
}
|
||||
|
||||
public BigDecimal freightCostForStats(OrderPO order) {
|
||||
if (!includesFreightCost(order.getStatusId())) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal c = nz(order.getShippingCost());
|
||||
return c.multiply(BigDecimal.valueOf(quantity(order)));
|
||||
}
|
||||
|
||||
public BigDecimal otherCostForStats(OrderPO order) {
|
||||
if (!includesOtherCost(order.getStatusId())) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal c = nz(order.getOtherCost());
|
||||
return c.multiply(BigDecimal.valueOf(quantity(order)));
|
||||
}
|
||||
|
||||
public BigDecimal totalCostForStats(OrderPO order) {
|
||||
return productCostForStats(order)
|
||||
.add(freightCostForStats(order))
|
||||
.add(otherCostForStats(order));
|
||||
return sum;
|
||||
}
|
||||
|
||||
public BigDecimal receivedForRefund(OrderPO order) {
|
||||
return includesRefund(order.getStatusId())
|
||||
? nz(order.getReceivedAmount())
|
||||
: BigDecimal.ZERO;
|
||||
return includesRefund(order.getStatus()) ? nz(order.getPayAmount()) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/** @deprecated 使用 {@link #quantity(OrderItemPO)} */
|
||||
@Deprecated
|
||||
public static int quantity(OrderPO order) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** @deprecated 明细成本请用 {@link #productCostForStats(OrderPO, OrderItemPO)} */
|
||||
@Deprecated
|
||||
public BigDecimal productCostForStats(OrderPO order) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public BigDecimal freightCostForStats(OrderPO order) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public BigDecimal otherCostForStats(OrderPO order) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
@Deprecated
|
||||
public BigDecimal totalCostForStats(OrderPO order) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.support;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.CreateOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.CreateOrderItemDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.dto.UpdateOrderDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单 DTO ↔ PO 转换辅助
|
||||
*/
|
||||
public final class OrderDtoSupport {
|
||||
|
||||
private OrderDtoSupport() {
|
||||
}
|
||||
|
||||
public static List<CreateOrderItemDTO> resolveItems(CreateOrderDTO dto) {
|
||||
if (dto.getItems() != null && !dto.getItems().isEmpty()) {
|
||||
return dto.getItems();
|
||||
}
|
||||
if (dto.getProductSkuId() == null && (dto.getLinkProductName() == null || dto.getLinkProductName().isBlank())) {
|
||||
throw new BusinessException("订单明细不能为空");
|
||||
}
|
||||
CreateOrderItemDTO item = new CreateOrderItemDTO();
|
||||
item.setProductSkuId(dto.getProductSkuId());
|
||||
item.setSkuCode(dto.getSkuCode());
|
||||
item.setLinkProductName(dto.getLinkProductName());
|
||||
item.setLinkSkuName(dto.getLinkSkuName());
|
||||
item.setQuantity(dto.getQuantity());
|
||||
item.setUnitPrice(dto.getUnitPrice());
|
||||
item.setProductCost(dto.getProductCost());
|
||||
item.setShippingCost(dto.getShippingCost());
|
||||
item.setOtherCost(dto.getOtherCost());
|
||||
item.setRemark(dto.getRemark());
|
||||
return List.of(item);
|
||||
}
|
||||
|
||||
public static List<CreateOrderItemDTO> resolveItems(UpdateOrderDTO dto) {
|
||||
if (dto.getItems() != null && !dto.getItems().isEmpty()) {
|
||||
return dto.getItems();
|
||||
}
|
||||
if (dto.getProductSkuId() == null && (dto.getLinkProductName() == null || dto.getLinkProductName().isBlank())) {
|
||||
return null;
|
||||
}
|
||||
CreateOrderItemDTO item = new CreateOrderItemDTO();
|
||||
item.setProductSkuId(dto.getProductSkuId());
|
||||
item.setSkuCode(dto.getSkuCode());
|
||||
item.setLinkProductName(dto.getLinkProductName());
|
||||
item.setLinkSkuName(dto.getLinkSkuName());
|
||||
item.setQuantity(dto.getQuantity());
|
||||
item.setUnitPrice(dto.getUnitPrice());
|
||||
item.setProductCost(dto.getProductCost());
|
||||
item.setShippingCost(dto.getShippingCost());
|
||||
item.setOtherCost(dto.getOtherCost());
|
||||
item.setRemark(dto.getRemark());
|
||||
return List.of(item);
|
||||
}
|
||||
|
||||
public static OrderItemPO toItemPO(CreateOrderItemDTO dto, OrderPO order, ProductSkuPO sku,
|
||||
ProductPO product, int lineNo, Long userId) {
|
||||
OrderItemPO item = new OrderItemPO();
|
||||
item.setOrderId(order.getId());
|
||||
item.setCompanyId(order.getCompanyId());
|
||||
item.setShopId(order.getShopId());
|
||||
item.setLineNo(lineNo);
|
||||
if (sku != null) {
|
||||
item.setProductSkuId(sku.getId());
|
||||
item.setProductId(sku.getProductId());
|
||||
String code = dto.getSkuCode();
|
||||
item.setSkuCode(code != null && !code.isBlank() ? code.trim() : sku.getSkuCode());
|
||||
} else {
|
||||
item.setProductSkuId(dto.getProductSkuId());
|
||||
item.setSkuCode(dto.getSkuCode());
|
||||
if (product != null) {
|
||||
item.setProductId(product.getId());
|
||||
}
|
||||
}
|
||||
item.setLinkProductName(dto.getLinkProductName());
|
||||
item.setLinkSkuName(dto.getLinkSkuName());
|
||||
item.setQuantity(dto.getQuantity() != null ? dto.getQuantity() : 1);
|
||||
item.setUnitPrice(nz(dto.getUnitPrice()));
|
||||
item.setLineAmount(dto.getLineAmount() != null ? dto.getLineAmount()
|
||||
: nz(dto.getUnitPrice()).multiply(BigDecimal.valueOf(item.getQuantity())));
|
||||
item.setProductCost(nz(dto.getProductCost()));
|
||||
item.setShippingCost(nz(dto.getShippingCost()));
|
||||
item.setOtherCost(nz(dto.getOtherCost()));
|
||||
item.setRemark(dto.getRemark());
|
||||
item.setCreateBy(userId);
|
||||
item.setUpdateBy(userId);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static void applyHeaderFromCreate(CreateOrderDTO dto, OrderPO order, String platformCode) {
|
||||
order.setShopId(dto.getShopId());
|
||||
order.setPlatformOrderNo(dto.getPlatformOrderNo());
|
||||
order.setStatus(dto.getStatus());
|
||||
order.setPayAmount(dto.getPayAmount());
|
||||
order.setGoodsAmount(dto.getGoodsAmount());
|
||||
order.setDiscountAmount(dto.getDiscountAmount());
|
||||
order.setPostage(dto.getPostage());
|
||||
order.setPlatformDiscount(dto.getPlatformDiscount());
|
||||
order.setSellerDiscount(dto.getSellerDiscount());
|
||||
order.setOrderTime(dto.getOrderTime());
|
||||
order.setPlatformCode(platformCode != null ? platformCode : dto.getPlatformCode());
|
||||
order.setSource(dto.getSource() != null ? dto.getSource() : "import");
|
||||
order.setRemark(dto.getRemark());
|
||||
order.setImportTaskId(dto.getImportTaskId());
|
||||
order.setConfirm(dto.getConfirm() != null ? dto.getConfirm() : 1);
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.order.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 概览/统计侧订单+明细加载辅助(兼容原扁平 OrderPO 用法)
|
||||
*/
|
||||
public final class OrderOverviewSupport {
|
||||
|
||||
private OrderOverviewSupport() {
|
||||
}
|
||||
|
||||
public static Map<Long, List<OrderItemPO>> loadItemsByOrderIds(OrderItemMapper mapper, Collection<Long> orderIds) {
|
||||
if (mapper == null || orderIds == null || orderIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<OrderItemPO> items = mapper.selectList(new LambdaQueryWrapper<OrderItemPO>()
|
||||
.in(OrderItemPO::getOrderId, orderIds)
|
||||
.orderByAsc(OrderItemPO::getLineNo));
|
||||
return items.stream().collect(Collectors.groupingBy(OrderItemPO::getOrderId));
|
||||
}
|
||||
|
||||
/** 每单取首行明细(当前导入/手工多为单行) */
|
||||
public static Map<Long, OrderItemPO> firstItemByOrderId(OrderItemMapper mapper, Collection<Long> orderIds) {
|
||||
Map<Long, List<OrderItemPO>> grouped = loadItemsByOrderIds(mapper, orderIds);
|
||||
Map<Long, OrderItemPO> result = new HashMap<>();
|
||||
for (Map.Entry<Long, List<OrderItemPO>> e : grouped.entrySet()) {
|
||||
if (!e.getValue().isEmpty()) {
|
||||
result.put(e.getKey(), e.getValue().get(0));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<Long, OrderItemPO> firstItemsForOrders(OrderItemMapper mapper, List<OrderPO> orders) {
|
||||
if (orders == null || orders.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<Long> ids = orders.stream().map(OrderPO::getId).filter(Objects::nonNull).toList();
|
||||
return firstItemByOrderId(mapper, ids);
|
||||
}
|
||||
|
||||
public static Map<Long, Long> skuToProductMap(ProductSkuMapper skuMapper, Collection<Long> skuIds) {
|
||||
if (skuMapper == null || skuIds == null || skuIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
List<ProductSkuPO> specs = skuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||
.in(ProductSkuPO::getId, skuIds)
|
||||
.select(ProductSkuPO::getId, ProductSkuPO::getProductId));
|
||||
Map<Long, Long> map = new HashMap<>();
|
||||
for (ProductSkuPO s : specs) {
|
||||
map.put(s.getId(), s.getProductId());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Map<Long, Long> orderSpecIdToProductIdMap(ProductSkuMapper skuMapper,
|
||||
OrderItemMapper itemMapper,
|
||||
List<OrderPO> orders) {
|
||||
Map<Long, OrderItemPO> items = firstItemsForOrders(itemMapper, orders);
|
||||
List<Long> skuIds = items.values().stream()
|
||||
.map(OrderItemPO::getProductSkuId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
return skuToProductMap(skuMapper, skuIds);
|
||||
}
|
||||
|
||||
public static Long productIdOfOrder(OrderPO order, Map<Long, OrderItemPO> firstItems,
|
||||
Map<Long, Long> skuToProduct) {
|
||||
if (order == null || firstItems == null || skuToProduct == null) {
|
||||
return -1L;
|
||||
}
|
||||
OrderItemPO item = firstItems.get(order.getId());
|
||||
if (item == null || item.getProductSkuId() == null) {
|
||||
return -1L;
|
||||
}
|
||||
return skuToProduct.getOrDefault(item.getProductSkuId(), -1L);
|
||||
}
|
||||
|
||||
public static List<Long> skuIdsFromOrderItems(Map<Long, OrderItemPO> firstItems) {
|
||||
if (firstItems == null || firstItems.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return firstItems.values().stream()
|
||||
.map(OrderItemPO::getProductSkuId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
+7
-6
@@ -22,15 +22,16 @@ public final class OrderPageQuerySupport {
|
||||
public static final int MAX_LIST_DAYS = 366;
|
||||
|
||||
private static final Set<String> ALLOWED_SORT_COLUMNS = Set.of(
|
||||
"order_time", "id", "received_amount", "shop_id", "status_id", "create_time"
|
||||
"order_time", "id", "pay_amount", "shop_id", "status", "create_time"
|
||||
);
|
||||
|
||||
private static final Map<String, String> SORT_FIELD_TO_COLUMN = Map.of(
|
||||
"orderTime", "order_time",
|
||||
"id", "id",
|
||||
"receivedAmount", "received_amount",
|
||||
"payAmount", "pay_amount",
|
||||
"receivedAmount", "pay_amount",
|
||||
"shopId", "shop_id",
|
||||
"statusId", "status_id",
|
||||
"status", "status",
|
||||
"createTime", "create_time"
|
||||
);
|
||||
|
||||
@@ -78,9 +79,9 @@ public final class OrderPageQuerySupport {
|
||||
p.setPlatformOrderNo(raw);
|
||||
p.setPlatformOrderNoPrefix(!raw.contains("%") && !raw.contains("_"));
|
||||
}
|
||||
p.setStatusId(filter.getStatusId());
|
||||
p.setMinReceivedAmount(filter.getMinReceivedAmount());
|
||||
p.setMaxReceivedAmount(filter.getMaxReceivedAmount());
|
||||
p.setStatus(filter.getStatus());
|
||||
p.setMinPayAmount(filter.getMinPayAmount());
|
||||
p.setMaxPayAmount(filter.getMaxPayAmount());
|
||||
p.setStartOrderTime(filter.getStartOrderTime());
|
||||
p.setEndOrderTime(filter.getEndOrderTime());
|
||||
p.setImportTaskId(filter.getImportTaskId());
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ public class PlatformExportDTO {
|
||||
@Size(min = 1, max = 2, message = "日期范围数组必须包含1-2个日期")
|
||||
private List<LocalDate> dateRange;
|
||||
|
||||
@Schema(description = "平台ID列表,不传则导出全部平台", example = "[1, 2]")
|
||||
private List<Long> platformIds;
|
||||
@Schema(description = "平台代码列表,不传则导出全部平台", example = "[\"pdd\", \"taobao\"]")
|
||||
private List<String> platformCodes;
|
||||
|
||||
@Schema(description = "税率,默认 0.04", example = "0.04")
|
||||
private BigDecimal taxRate = new BigDecimal("0.04");
|
||||
|
||||
+2
-2
@@ -405,8 +405,8 @@ public class CompanyOverviewVO {
|
||||
@Data
|
||||
@Schema(description = "平台维度汇总")
|
||||
public static class PlatformSummary {
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long platformId;
|
||||
@Schema(description = "平台代码", example = "pdd")
|
||||
private String platformCode;
|
||||
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
+81
-113
@@ -8,12 +8,14 @@ import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderStatAggMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatOverviewAssembler;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.stat.service.OrderStatReadFacade;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.CompanyOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.support.OrderOverviewSupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatResolver;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
|
||||
@@ -26,9 +28,9 @@ import top.xyquan.ecomdmbbackend.modules.ecom.shop.service.ShopService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.category.model.po.CategoryPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.category.service.CategoryService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSpecMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -57,42 +59,42 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
|
||||
private final ShopService shopService;
|
||||
private final OrderStatusStatResolver orderStatusStatResolver;
|
||||
private final ProductMapper productMapper;
|
||||
private final ProductSpecMapper productSpecMapper;
|
||||
private final ProductSkuMapper productSkuMapper;
|
||||
private final CategoryService categoryService;
|
||||
private final PlatformMapper platformMapper;
|
||||
private final OrderStatReadFacade orderStatReadFacade;
|
||||
private final OrderStatOverviewAssembler orderStatOverviewAssembler;
|
||||
|
||||
public CompanyOverviewServiceImpl(CurrentUserContext currentUserContext,
|
||||
OrderMapper orderMapper,
|
||||
OrderItemMapper orderItemMapper,
|
||||
PromotionFeeMapper promotionFeeMapper,
|
||||
BrushOrderMapper brushOrderMapper,
|
||||
ShopMonthlyTargetMapper shopMonthlyTargetMapper,
|
||||
ShopService shopService,
|
||||
OrderStatusStatResolver orderStatusStatResolver,
|
||||
ProductMapper productMapper,
|
||||
ProductSpecMapper productSpecMapper,
|
||||
ProductSkuMapper productSkuMapper,
|
||||
CategoryService categoryService,
|
||||
PlatformMapper platformMapper,
|
||||
OrderStatReadFacade orderStatReadFacade,
|
||||
OrderStatOverviewAssembler orderStatOverviewAssembler) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderMapper = orderMapper;
|
||||
this.orderItemMapper = orderItemMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
this.brushOrderMapper = brushOrderMapper;
|
||||
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
|
||||
this.shopService = shopService;
|
||||
this.orderStatusStatResolver = orderStatusStatResolver;
|
||||
this.productMapper = productMapper;
|
||||
this.productSpecMapper = productSpecMapper;
|
||||
this.productSkuMapper = productSkuMapper;
|
||||
this.categoryService = categoryService;
|
||||
this.platformMapper = platformMapper;
|
||||
this.orderStatReadFacade = orderStatReadFacade;
|
||||
this.orderStatOverviewAssembler = orderStatOverviewAssembler;
|
||||
}
|
||||
@@ -148,7 +150,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
|
||||
OrderStatusStatSets stat = orderStatusStatResolver.resolve(companyId);
|
||||
List<Long> unionStatusIds = stat.getUnionStatusIds();
|
||||
List<String> unionStatusCodes = stat.getUnionStatusCodes();
|
||||
|
||||
// 查询所有店铺
|
||||
LambdaQueryWrapper<ShopPO> shopWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -172,8 +174,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
orderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.ge(OrderPO::getOrderTime, startDateTime)
|
||||
.le(OrderPO::getOrderTime, endDateTime);
|
||||
if (!unionStatusIds.isEmpty()) {
|
||||
orderWrapper.in(OrderPO::getStatusId, unionStatusIds);
|
||||
if (!unionStatusCodes.isEmpty()) {
|
||||
orderWrapper.in(OrderPO::getStatus, unionStatusCodes);
|
||||
} else {
|
||||
orderWrapper.isNull(OrderPO::getId);
|
||||
}
|
||||
@@ -203,8 +205,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
lastMonthOrderWrapper.eq(OrderPO::getCompanyId, companyId)
|
||||
.ge(OrderPO::getOrderTime, lastMonthStartDateTime)
|
||||
.le(OrderPO::getOrderTime, lastMonthEndDateTime);
|
||||
if (!unionStatusIds.isEmpty()) {
|
||||
lastMonthOrderWrapper.in(OrderPO::getStatusId, unionStatusIds);
|
||||
if (!unionStatusCodes.isEmpty()) {
|
||||
lastMonthOrderWrapper.in(OrderPO::getStatus, unionStatusCodes);
|
||||
} else {
|
||||
lastMonthOrderWrapper.isNull(OrderPO::getId);
|
||||
}
|
||||
@@ -238,7 +240,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
overviewVO.setMonthOverMonthGrowth(monthOverMonthGrowth);
|
||||
|
||||
// 3. 计算全店总单量(按状态「计入销售额」维度计单)
|
||||
int totalOrderCount = (int) orders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int totalOrderCount = (int) orders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
overviewVO.setTotalOrderCount(totalOrderCount);
|
||||
|
||||
// 4. 计算总推广费支出
|
||||
@@ -566,7 +568,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
.map(stat::receivedForSales)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
int orderCount = (int) shopOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int orderCount = (int) shopOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
|
||||
BigDecimal refundAmount = shopOrders.stream()
|
||||
.map(stat::receivedForRefund)
|
||||
@@ -646,7 +648,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
CompanyOverviewVO.ShopSummary summary = new CompanyOverviewVO.ShopSummary();
|
||||
summary.setShopId(shop.getId());
|
||||
summary.setShopName(shop.getName());
|
||||
summary.setPlatform(shop.getPlatformId() != null ? getPlatformNameById(shop.getPlatformId()) : null);
|
||||
summary.setPlatform(shop.getPlatformCode() != null ? PlatformCode.labelOf(shop.getPlatformCode()) : null);
|
||||
summary.setTargetOrderCount(targetOrderCount);
|
||||
summary.setOrderCountAchievementRate(orderCountAchievementRate);
|
||||
summary.setTargetAmount(targetAmount);
|
||||
@@ -814,24 +816,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
return calculateSalesROI(netSales, totalPromotionFee);
|
||||
}
|
||||
|
||||
/** 订单行上的 product_spec_id → 商品 id */
|
||||
/** 订单明细 product_sku_id → 商品 id */
|
||||
private Map<Long, Long> orderSpecIdToProductIdMap(List<OrderPO> orders) {
|
||||
List<Long> specIds = orders.stream()
|
||||
.map(OrderPO::getProductSpecId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (specIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<ProductSpecPO> specs = productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpecPO>()
|
||||
.in(ProductSpecPO::getId, specIds)
|
||||
.select(ProductSpecPO::getId, ProductSpecPO::getProductId));
|
||||
Map<Long, Long> map = new java.util.HashMap<>();
|
||||
for (ProductSpecPO s : specs) {
|
||||
map.put(s.getId(), s.getProductId());
|
||||
}
|
||||
return map;
|
||||
return OrderOverviewSupport.orderSpecIdToProductIdMap(productSkuMapper, orderItemMapper, orders);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -849,8 +836,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
Map<Long, String> categoryNameMap = allCategories.stream()
|
||||
.collect(Collectors.toMap(CategoryPO::getId, CategoryPO::getName));
|
||||
|
||||
Map<Long, Long> specIdToProductId = orderSpecIdToProductIdMap(orders);
|
||||
List<Long> productIds = specIdToProductId.values().stream().filter(Objects::nonNull).distinct()
|
||||
Map<Long, Long> skuIdToProductId = orderSpecIdToProductIdMap(orders);
|
||||
List<Long> productIds = skuIdToProductId.values().stream().filter(Objects::nonNull).distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<Long, Long> productCategoryMap = new java.util.HashMap<>();
|
||||
@@ -864,10 +851,12 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
|
||||
// Group orders by category
|
||||
Map<Long, OrderItemPO> firstItems = OrderOverviewSupport.firstItemsForOrders(orderItemMapper, orders);
|
||||
Map<Long, List<OrderPO>> ordersByCategory = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> {
|
||||
Long specId = order.getProductSpecId();
|
||||
Long productId = specId != null ? specIdToProductId.get(specId) : null;
|
||||
OrderItemPO item = firstItems.get(order.getId());
|
||||
Long skuId = item != null ? item.getProductSkuId() : null;
|
||||
Long productId = skuId != null ? skuIdToProductId.get(skuId) : null;
|
||||
if (productId == null) {
|
||||
return -1L;
|
||||
}
|
||||
@@ -918,7 +907,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
.map(stat::receivedForSales)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
int orderCount = (int) categoryOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int orderCount = (int) categoryOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
|
||||
BigDecimal refundAmount = categoryOrders.stream()
|
||||
.map(stat::receivedForRefund)
|
||||
@@ -946,8 +935,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
Set<Long> catProductIds = new HashSet<>();
|
||||
for (OrderPO order : categoryOrders) {
|
||||
Long specId = order.getProductSpecId();
|
||||
Long productId = specId != null ? specIdToProductId.get(specId) : null;
|
||||
OrderItemPO item = firstItems.get(order.getId());
|
||||
Long skuId = item != null ? item.getProductSkuId() : null;
|
||||
Long productId = skuId != null ? skuIdToProductId.get(skuId) : null;
|
||||
if (productId != null) {
|
||||
catProductIds.add(productId);
|
||||
}
|
||||
@@ -1112,21 +1102,14 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
List<CompanyOverviewVO.PlatformSummary> platformSummaries = new ArrayList<>();
|
||||
|
||||
// 获取当前公司的所有平台
|
||||
LambdaQueryWrapper<PlatformPO> platformWrapper = new LambdaQueryWrapper<>();
|
||||
platformWrapper.eq(PlatformPO::getCompanyId, companyId);
|
||||
List<PlatformPO> allPlatforms = platformMapper.selectList(platformWrapper);
|
||||
Map<Long, PlatformPO> platformMap = allPlatforms.stream()
|
||||
.collect(Collectors.toMap(PlatformPO::getId, p -> p));
|
||||
// 按平台代码分组店铺
|
||||
Map<String, List<ShopPO>> shopsByPlatform = shops.stream()
|
||||
.filter(shop -> shop.getPlatformCode() != null && !shop.getPlatformCode().isBlank())
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformCode));
|
||||
|
||||
// 按平台分组店铺(有platformId的)
|
||||
Map<Long, List<ShopPO>> shopsByPlatform = shops.stream()
|
||||
.filter(shop -> shop.getPlatformId() != null)
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformId));
|
||||
|
||||
// 没有platformId的店铺,汇总为"其他平台"
|
||||
// 没有 platformCode 的店铺,汇总为"其他平台"
|
||||
List<ShopPO> shopsWithoutPlatform = shops.stream()
|
||||
.filter(shop -> shop.getPlatformId() == null)
|
||||
.filter(shop -> shop.getPlatformCode() == null || shop.getPlatformCode().isBlank())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 生成目标月份列表
|
||||
@@ -1155,12 +1138,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
.collect(Collectors.groupingBy(BrushOrderPO::getShopId));
|
||||
|
||||
// 计算每个平台的数据
|
||||
for (Map.Entry<Long, List<ShopPO>> entry : shopsByPlatform.entrySet()) {
|
||||
Long platformId = entry.getKey();
|
||||
for (Map.Entry<String, List<ShopPO>> entry : shopsByPlatform.entrySet()) {
|
||||
String platformCode = entry.getKey();
|
||||
List<ShopPO> platformShops = entry.getValue();
|
||||
PlatformPO platform = platformMap.get(platformId);
|
||||
|
||||
if (platform == null) continue;
|
||||
|
||||
// 汇总该平台下所有店铺的数据
|
||||
BigDecimal totalSalesAmount = BigDecimal.ZERO;
|
||||
@@ -1188,7 +1168,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
totalSalesAmount = totalSalesAmount.add(shopSales);
|
||||
|
||||
// 订单数(按状态「计入销售额」计单)
|
||||
totalOrderCount += (int) shopOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
totalOrderCount += (int) shopOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
|
||||
// 退款金额(按状态「计入退款」)
|
||||
BigDecimal shopRefund = shopOrders.stream()
|
||||
@@ -1281,8 +1261,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
|
||||
CompanyOverviewVO.PlatformSummary platformSummary = new CompanyOverviewVO.PlatformSummary();
|
||||
platformSummary.setPlatformId(platformId);
|
||||
platformSummary.setPlatformName(platform.getPlatformName());
|
||||
platformSummary.setPlatformCode(platformCode);
|
||||
platformSummary.setPlatformName(PlatformCode.labelOf(platformCode));
|
||||
platformSummary.setTargetOrderCount(totalTargetOrderCount);
|
||||
platformSummary.setOrderCountAchievementRate(orderCountAchievementRate);
|
||||
platformSummary.setTargetAmount(totalTargetAmount);
|
||||
@@ -1387,7 +1367,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
: totalOrderCount > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.PlatformSummary total = new CompanyOverviewVO.PlatformSummary();
|
||||
total.setPlatformId(0L);
|
||||
total.setPlatformCode(null);
|
||||
total.setPlatformName("合计");
|
||||
total.setSalesAmount(totalSalesAmount);
|
||||
total.setGmv(totalGmv);
|
||||
@@ -1448,7 +1428,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
.map(stat::receivedForSales)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
totalSalesAmount = totalSalesAmount.add(shopSales);
|
||||
totalOrderCount += (int) shopOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
totalOrderCount += (int) shopOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
|
||||
BigDecimal shopRefund = shopOrders.stream()
|
||||
.map(stat::receivedForRefund)
|
||||
@@ -1515,7 +1495,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
: totalOrderCount > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.PlatformSummary summary = new CompanyOverviewVO.PlatformSummary();
|
||||
summary.setPlatformId(0L); // 0表示"其他平台"
|
||||
summary.setPlatformCode(null);
|
||||
summary.setPlatformName("其他平台");
|
||||
summary.setTargetOrderCount(totalTargetOrderCount);
|
||||
summary.setOrderCountAchievementRate(orderAchievementRate);
|
||||
@@ -1543,16 +1523,6 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
return summary;
|
||||
}
|
||||
|
||||
private String getPlatformNameById(Long platformId) {
|
||||
if (platformId == null) return null;
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getId, platformId)
|
||||
.eq(PlatformPO::getCompanyId, companyId);
|
||||
PlatformPO platform = platformMapper.selectOne(wrapper);
|
||||
return platform != null ? platform.getPlatformName() : null;
|
||||
}
|
||||
|
||||
private CompanyOverviewVO.TrendData calculateSalesAmountTrend(List<OrderPO> orders, LocalDate startDate,
|
||||
LocalDate endDate, OrderStatusStatSets stat) {
|
||||
CompanyOverviewVO.TrendData trendData = new CompanyOverviewVO.TrendData();
|
||||
@@ -1590,7 +1560,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
CompanyOverviewVO.TrendData trendData = new CompanyOverviewVO.TrendData();
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
|
||||
int total = (int) orders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int total = (int) orders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
trendData.setTotal(new BigDecimal(total));
|
||||
List<LocalDate> dateList = new ArrayList<>();
|
||||
LocalDate currentDate = startDate;
|
||||
@@ -1603,7 +1573,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
CompanyOverviewVO.TrendDataItem item = new CompanyOverviewVO.TrendDataItem();
|
||||
item.setDate(date);
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, List.of());
|
||||
int dayCount = (int) dayOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int dayCount = (int) dayOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
item.setValue(new BigDecimal(dayCount));
|
||||
return item;
|
||||
})
|
||||
@@ -1650,8 +1620,8 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
List<BrushOrderPO> brushOrders, OrderStatusStatSets stat, Long companyId,
|
||||
LocalDate startDate, LocalDate endDate, GmvDimensionMaps gmvMaps) {
|
||||
|
||||
Map<Long, Long> specIdToProductId = orderSpecIdToProductIdMap(orders);
|
||||
List<Long> productIds = specIdToProductId.values().stream().filter(Objects::nonNull).distinct()
|
||||
Map<Long, Long> skuIdToProductId = orderSpecIdToProductIdMap(orders);
|
||||
List<Long> productIds = skuIdToProductId.values().stream().filter(Objects::nonNull).distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Map<Long, Long> productCategoryMap = new java.util.HashMap<>();
|
||||
@@ -1666,10 +1636,12 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, OrderItemPO> firstItems = OrderOverviewSupport.firstItemsForOrders(orderItemMapper, orders);
|
||||
Map<Long, List<OrderPO>> ordersByProduct = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> {
|
||||
Long specId = order.getProductSpecId();
|
||||
Long productId = specId != null ? specIdToProductId.get(specId) : null;
|
||||
OrderItemPO item = firstItems.get(order.getId());
|
||||
Long skuId = item != null ? item.getProductSkuId() : null;
|
||||
Long productId = skuId != null ? skuIdToProductId.get(skuId) : null;
|
||||
return productId != null ? productId : -1L;
|
||||
}));
|
||||
|
||||
@@ -1700,8 +1672,9 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
Map<Long, BigDecimal> salesByCategory = new java.util.HashMap<>();
|
||||
for (OrderPO o : orders) {
|
||||
Long specId = o.getProductSpecId();
|
||||
Long pid = specId != null ? specIdToProductId.get(specId) : null;
|
||||
OrderItemPO item = firstItems.get(o.getId());
|
||||
Long skuId = item != null ? item.getProductSkuId() : null;
|
||||
Long pid = skuId != null ? skuIdToProductId.get(skuId) : null;
|
||||
if (pid == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -1727,7 +1700,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
BigDecimal salesAmount = productOrders.stream()
|
||||
.map(stat::receivedForSales)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
int orderCount = (int) productOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int orderCount = (int) productOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
BigDecimal refundAmount = productOrders.stream()
|
||||
.map(stat::receivedForRefund)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
@@ -1911,12 +1884,11 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
BigDecimal totalSalesPool = orderRows.stream().map(r -> nz(r.getSalesAmount())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
Map<Long, String> platformNames = loadPlatformNameMap(companyId);
|
||||
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop = loadTargetsByShop(companyId, startDate, endDate);
|
||||
|
||||
CompanyOverviewVO.WorkbenchTableBundle bundle = new CompanyOverviewVO.WorkbenchTableBundle();
|
||||
bundle.setShopTable(buildShopOverviewFromAgg(shops, byShop, promoByShop, brushByShop, targetsByShop, platformNames));
|
||||
bundle.setPlatformTable(buildPlatformOverviewFromAgg(shops, byShop, promoByShop, brushByShop, targetsByShop, platformNames));
|
||||
bundle.setShopTable(buildShopOverviewFromAgg(shops, byShop, promoByShop, brushByShop, targetsByShop));
|
||||
bundle.setPlatformTable(buildPlatformOverviewFromAgg(shops, byShop, promoByShop, brushByShop, targetsByShop));
|
||||
bundle.setCategoryTable(buildCategoryOverviewFromAgg(byCategory, categorySalesByShop, brushByShop,
|
||||
directPromoByProduct, directPromoByCategory, ratioPool, totalSalesPool, productCategoryMap, companyId));
|
||||
bundle.setProductTable(buildProductOverviewFromAgg(byProduct, productSalesByShop, brushByShop,
|
||||
@@ -1926,14 +1898,13 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
private CompanyOverviewVO.ShopOverview buildShopOverviewFromAgg(
|
||||
List<ShopPO> shops, Map<Long, AggMetrics> byShop, Map<Long, BigDecimal> promoByShop,
|
||||
Map<Long, BigDecimal> brushByShop, Map<Long, List<ShopMonthlyTargetPO>> targetsByShop,
|
||||
Map<Long, String> platformNames) {
|
||||
Map<Long, BigDecimal> brushByShop, Map<Long, List<ShopMonthlyTargetPO>> targetsByShop) {
|
||||
List<CompanyOverviewVO.ShopSummary> list = new ArrayList<>();
|
||||
for (ShopPO shop : shops) {
|
||||
AggMetrics m = byShop.getOrDefault(shop.getId(), AggMetrics.EMPTY);
|
||||
list.add(toShopSummaryFromAgg(shop, m, promoByShop.getOrDefault(shop.getId(), BigDecimal.ZERO),
|
||||
brushByShop.getOrDefault(shop.getId(), BigDecimal.ZERO),
|
||||
targetsByShop.getOrDefault(shop.getId(), List.of()), platformNames));
|
||||
targetsByShop.getOrDefault(shop.getId(), List.of())));
|
||||
}
|
||||
list.sort(Comparator.comparing(CompanyOverviewVO.ShopSummary::getSalesAmount,
|
||||
Comparator.nullsFirst(BigDecimal::compareTo)).reversed());
|
||||
@@ -1945,13 +1916,13 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
|
||||
private CompanyOverviewVO.PlatformOverview buildPlatformOverviewFromAgg(
|
||||
List<ShopPO> shops, Map<Long, AggMetrics> byShop, Map<Long, BigDecimal> promoByShop,
|
||||
Map<Long, BigDecimal> brushByShop, Map<Long, List<ShopMonthlyTargetPO>> targetsByShop,
|
||||
Map<Long, String> platformNames) {
|
||||
Map<Long, List<ShopPO>> byPlatform = shops.stream().filter(s -> s.getPlatformId() != null)
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformId));
|
||||
Map<Long, BigDecimal> brushByShop, Map<Long, List<ShopMonthlyTargetPO>> targetsByShop) {
|
||||
Map<String, List<ShopPO>> byPlatform = shops.stream()
|
||||
.filter(s -> s.getPlatformCode() != null && !s.getPlatformCode().isBlank())
|
||||
.collect(Collectors.groupingBy(ShopPO::getPlatformCode));
|
||||
List<CompanyOverviewVO.PlatformSummary> list = new ArrayList<>();
|
||||
for (Map.Entry<Long, List<ShopPO>> e : byPlatform.entrySet()) {
|
||||
list.add(rollupPlatformFromAgg(e.getKey(), platformNames.getOrDefault(e.getKey(), "未知平台"),
|
||||
for (Map.Entry<String, List<ShopPO>> e : byPlatform.entrySet()) {
|
||||
list.add(rollupPlatformFromAgg(e.getKey(), PlatformCode.labelOf(e.getKey()),
|
||||
e.getValue(), byShop, promoByShop, brushByShop, targetsByShop));
|
||||
}
|
||||
list.sort(Comparator.comparing(CompanyOverviewVO.PlatformSummary::getSalesAmount,
|
||||
@@ -2021,7 +1992,7 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
}
|
||||
|
||||
private CompanyOverviewVO.PlatformSummary rollupPlatformFromAgg(
|
||||
Long platformId, String platformName, List<ShopPO> platformShops,
|
||||
String platformCode, String platformName, List<ShopPO> platformShops,
|
||||
Map<Long, AggMetrics> byShop, Map<Long, BigDecimal> promoByShop, Map<Long, BigDecimal> brushByShop,
|
||||
Map<Long, List<ShopMonthlyTargetPO>> targetsByShop) {
|
||||
AggMetrics merged = AggMetrics.EMPTY;
|
||||
@@ -2038,27 +2009,27 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
targetOrders += t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0;
|
||||
}
|
||||
}
|
||||
return toPlatformSummaryFromAgg(platformId, platformName, merged, promo, brush, targetAmt, targetOrders);
|
||||
return toPlatformSummaryFromAgg(platformCode, platformName, merged, promo, brush, targetAmt, targetOrders);
|
||||
}
|
||||
|
||||
private CompanyOverviewVO.ShopSummary toShopSummaryFromAgg(
|
||||
ShopPO shop, AggMetrics m, BigDecimal promo, BigDecimal brush,
|
||||
List<ShopMonthlyTargetPO> targets, Map<Long, String> platformNames) {
|
||||
List<ShopMonthlyTargetPO> targets) {
|
||||
BigDecimal targetAmt = targets.stream().map(t -> nz(t.getTargetAmount())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
int targetOrders = targets.stream().mapToInt(t -> t.getTargetOrderCount() != null ? t.getTargetOrderCount() : 0).sum();
|
||||
CompanyOverviewVO.ShopSummary s = new CompanyOverviewVO.ShopSummary();
|
||||
s.setShopId(shop.getId());
|
||||
s.setShopName(shop.getName());
|
||||
s.setPlatform(shop.getPlatformId() != null ? platformNames.get(shop.getPlatformId()) : null);
|
||||
s.setPlatform(shop.getPlatformCode() != null ? PlatformCode.labelOf(shop.getPlatformCode()) : null);
|
||||
fillSummaryMetrics(s, m, promo, brush, targetAmt, targetOrders);
|
||||
return s;
|
||||
}
|
||||
|
||||
private CompanyOverviewVO.PlatformSummary toPlatformSummaryFromAgg(
|
||||
Long platformId, String name, AggMetrics m, BigDecimal promo, BigDecimal brush,
|
||||
String platformCode, String name, AggMetrics m, BigDecimal promo, BigDecimal brush,
|
||||
BigDecimal targetAmt, int targetOrders) {
|
||||
CompanyOverviewVO.PlatformSummary s = new CompanyOverviewVO.PlatformSummary();
|
||||
s.setPlatformId(platformId > 0 ? platformId : null);
|
||||
s.setPlatformCode(platformCode != null && !platformCode.isBlank() ? platformCode : null);
|
||||
s.setPlatformName(name);
|
||||
fillPlatformLikeMetrics(s, m, promo, brush, targetAmt, targetOrders);
|
||||
return s;
|
||||
@@ -2218,11 +2189,6 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
return brush;
|
||||
}
|
||||
|
||||
private Map<Long, String> loadPlatformNameMap(Long companyId) {
|
||||
return platformMapper.selectList(new LambdaQueryWrapper<PlatformPO>().eq(PlatformPO::getCompanyId, companyId))
|
||||
.stream().collect(Collectors.toMap(PlatformPO::getId, PlatformPO::getPlatformName, (a, b) -> a));
|
||||
}
|
||||
|
||||
private Map<Long, String> loadCategoryNameMap(Long companyId) {
|
||||
return categoryService.list(new LambdaQueryWrapper<CategoryPO>().eq(CategoryPO::getCompanyId, companyId))
|
||||
.stream().collect(Collectors.toMap(CategoryPO::getId, CategoryPO::getName, (a, b) -> a));
|
||||
@@ -2302,23 +2268,25 @@ public class CompanyOverviewServiceImpl implements CompanyOverviewService {
|
||||
.ge(OrderPO::getOrderTime, startDate.atStartOfDay())
|
||||
.le(OrderPO::getOrderTime, endDate.atTime(23, 59, 59));
|
||||
List<OrderPO> allOrders = orderMapper.selectList(w);
|
||||
Map<Long, Long> specToProduct = orderSpecIdToProductIdMap(allOrders);
|
||||
Map<Long, Long> skuToProduct = orderSpecIdToProductIdMap(allOrders);
|
||||
Map<Long, Long> productCategoryMap = new HashMap<>();
|
||||
List<Long> productIds = specToProduct.values().stream().filter(Objects::nonNull).distinct().toList();
|
||||
List<Long> productIds = skuToProduct.values().stream().filter(Objects::nonNull).distinct().toList();
|
||||
if (!productIds.isEmpty()) {
|
||||
productMapper.selectList(new LambdaQueryWrapper<ProductPO>().in(ProductPO::getId, productIds))
|
||||
.forEach(p -> productCategoryMap.put(p.getId(), p.getCategoryId()));
|
||||
}
|
||||
Map<Long, OrderItemPO> firstItems = OrderOverviewSupport.firstItemsForOrders(orderItemMapper, allOrders);
|
||||
Map<Long, BigDecimal> byShop = new HashMap<>();
|
||||
Map<Long, BigDecimal> byCategoryKey = new HashMap<>();
|
||||
Map<Long, BigDecimal> byProductKey = new HashMap<>();
|
||||
for (OrderPO o : allOrders) {
|
||||
BigDecimal amt = nz(o.getReceivedAmount());
|
||||
BigDecimal amt = nz(o.getPayAmount());
|
||||
if (o.getShopId() != null) {
|
||||
byShop.merge(o.getShopId(), amt, BigDecimal::add);
|
||||
}
|
||||
long productId = o.getProductSpecId() != null
|
||||
? specToProduct.getOrDefault(o.getProductSpecId(), -1L) : -1L;
|
||||
OrderItemPO item = firstItems.get(o.getId());
|
||||
Long skuId = item != null ? item.getProductSkuId() : null;
|
||||
long productId = skuId != null ? skuToProduct.getOrDefault(skuId, -1L) : -1L;
|
||||
byProductKey.merge(productId, amt, BigDecimal::add);
|
||||
long categoryKey;
|
||||
if (productId <= 0) {
|
||||
|
||||
+5
-5
@@ -443,7 +443,7 @@ public class ExportServiceImpl implements ExportService {
|
||||
: totalOrders > 0 ? new BigDecimal("100") : BigDecimal.ZERO;
|
||||
|
||||
CompanyOverviewVO.PlatformSummary total = new CompanyOverviewVO.PlatformSummary();
|
||||
total.setPlatformId(0L);
|
||||
total.setPlatformCode(null);
|
||||
total.setPlatformName("合计");
|
||||
total.setSalesAmount(totalSales);
|
||||
total.setOrderCount(totalOrders);
|
||||
@@ -636,17 +636,17 @@ public class ExportServiceImpl implements ExportService {
|
||||
List<CompanyOverviewVO.PlatformSummary> platforms = (platformOv != null && platformOv.getPlatforms() != null)
|
||||
? new ArrayList<>(platformOv.getPlatforms())
|
||||
: new ArrayList<>();
|
||||
if (dto.getPlatformIds() != null && !dto.getPlatformIds().isEmpty()) {
|
||||
Set<Long> allowed = new HashSet<>(dto.getPlatformIds());
|
||||
if (dto.getPlatformCodes() != null && !dto.getPlatformCodes().isEmpty()) {
|
||||
Set<String> allowed = new HashSet<>(dto.getPlatformCodes());
|
||||
platforms = platforms.stream()
|
||||
.filter(p -> p.getPlatformId() != null && allowed.contains(p.getPlatformId()))
|
||||
.filter(p -> p.getPlatformCode() != null && allowed.contains(p.getPlatformCode()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
List<Map<String, Object>> platformRows = platforms.stream()
|
||||
.map(this::platformSummaryToRowMap)
|
||||
.collect(Collectors.toList());
|
||||
boolean platformFiltered = dto.getPlatformIds() != null && !dto.getPlatformIds().isEmpty();
|
||||
boolean platformFiltered = dto.getPlatformCodes() != null && !dto.getPlatformCodes().isEmpty();
|
||||
CompanyOverviewVO.PlatformSummary totalPlatform = platformFiltered
|
||||
? aggregatePlatformSummariesForExport(platforms, taxRate)
|
||||
: (platformOv != null && platformOv.getTotal() != null
|
||||
|
||||
+5
-5
@@ -33,14 +33,14 @@ public class ExportStatusRangeHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* 任一会参与统计的维度为 1 的订单状态 ID(用于拉取订单并集)
|
||||
* 任一会参与统计的订单状态码(用于拉取订单并集)
|
||||
*/
|
||||
public List<Long> getAutoStatusIds(Long companyId) {
|
||||
return orderStatusStatResolver.resolve(companyId).getUnionStatusIds();
|
||||
public List<String> getAutoStatusCodes(Long companyId) {
|
||||
return orderStatusStatResolver.resolve(companyId).getUnionStatusCodes();
|
||||
}
|
||||
|
||||
public List<Long> getRefundStatusIds(Long companyId) {
|
||||
return orderStatusStatResolver.resolve(companyId).getRefundStatusIds();
|
||||
public List<String> getRefundStatusCodes(Long companyId) {
|
||||
return orderStatusStatResolver.resolve(companyId).getRefundStatusCodes();
|
||||
}
|
||||
|
||||
public OrderStatusStatSets resolveStat(Long companyId) {
|
||||
|
||||
+34
-40
@@ -15,11 +15,14 @@ import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMappe
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.overview.model.dto.ShopOverviewQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.brushorder.model.po.BrushOrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.mapper.OrderItemMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.model.po.OrderItemPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.support.OrderOverviewSupport;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatResolver;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.status.support.OrderStatusStatSets;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSpecMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductSkuMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.model.po.PromotionFeePO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.monthlytarget.mapper.ShopMonthlyTargetMapper;
|
||||
@@ -57,12 +60,13 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final OrderMapper orderMapper;
|
||||
private final OrderItemMapper orderItemMapper;
|
||||
private final PromotionFeeMapper promotionFeeMapper;
|
||||
private final BrushOrderMapper brushOrderMapper;
|
||||
private final ShopMonthlyTargetMapper shopMonthlyTargetMapper;
|
||||
private final ShopService shopService;
|
||||
private final ProductService productService;
|
||||
private final ProductSpecMapper productSpecMapper;
|
||||
private final ProductSkuMapper productSkuMapper;
|
||||
private final OrderStatusStatResolver orderStatusStatResolver;
|
||||
private final CategoryService categoryService;
|
||||
private final OrderStatReadFacade orderStatReadFacade;
|
||||
@@ -70,24 +74,26 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
|
||||
public ShopOverviewStatisticsServiceImpl(CurrentUserContext currentUserContext,
|
||||
OrderMapper orderMapper,
|
||||
OrderItemMapper orderItemMapper,
|
||||
PromotionFeeMapper promotionFeeMapper,
|
||||
BrushOrderMapper brushOrderMapper,
|
||||
ShopMonthlyTargetMapper shopMonthlyTargetMapper,
|
||||
ShopService shopService,
|
||||
ProductService productService,
|
||||
ProductSpecMapper productSpecMapper,
|
||||
ProductSkuMapper productSkuMapper,
|
||||
OrderStatusStatResolver orderStatusStatResolver,
|
||||
CategoryService categoryService,
|
||||
OrderStatReadFacade orderStatReadFacade,
|
||||
CompanyOverviewService companyOverviewService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.orderMapper = orderMapper;
|
||||
this.orderItemMapper = orderItemMapper;
|
||||
this.promotionFeeMapper = promotionFeeMapper;
|
||||
this.brushOrderMapper = brushOrderMapper;
|
||||
this.shopMonthlyTargetMapper = shopMonthlyTargetMapper;
|
||||
this.shopService = shopService;
|
||||
this.productService = productService;
|
||||
this.productSpecMapper = productSpecMapper;
|
||||
this.productSkuMapper = productSkuMapper;
|
||||
this.orderStatusStatResolver = orderStatusStatResolver;
|
||||
this.categoryService = categoryService;
|
||||
this.orderStatReadFacade = orderStatReadFacade;
|
||||
@@ -131,7 +137,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
LocalDateTime startDateTime = startDate.atStartOfDay();
|
||||
LocalDateTime endDateTime = endDate.atTime(23, 59, 59);
|
||||
OrderStatusStatSets stat = orderStatusStatResolver.resolve(companyId);
|
||||
List<Long> unionStatusIds = stat.getUnionStatusIds();
|
||||
List<String> unionStatusCodes = stat.getUnionStatusCodes();
|
||||
|
||||
// 验证店铺是否存在
|
||||
ShopPO shop = shopService.getById(queryDTO.getShopId());
|
||||
@@ -149,8 +155,8 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
.eq(OrderPO::getShopId, queryDTO.getShopId())
|
||||
.ge(OrderPO::getOrderTime, startDateTime)
|
||||
.le(OrderPO::getOrderTime, endDateTime);
|
||||
if (!unionStatusIds.isEmpty()) {
|
||||
orderWrapper.in(OrderPO::getStatusId, unionStatusIds);
|
||||
if (!unionStatusCodes.isEmpty()) {
|
||||
orderWrapper.in(OrderPO::getStatus, unionStatusCodes);
|
||||
} else {
|
||||
orderWrapper.isNull(OrderPO::getId);
|
||||
}
|
||||
@@ -183,8 +189,8 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
.eq(OrderPO::getShopId, queryDTO.getShopId())
|
||||
.ge(OrderPO::getOrderTime, lastMonthStartDateTime)
|
||||
.le(OrderPO::getOrderTime, lastMonthEndDateTime);
|
||||
if (!unionStatusIds.isEmpty()) {
|
||||
lastMonthOrderWrapper.in(OrderPO::getStatusId, unionStatusIds);
|
||||
if (!unionStatusCodes.isEmpty()) {
|
||||
lastMonthOrderWrapper.in(OrderPO::getStatus, unionStatusCodes);
|
||||
} else {
|
||||
lastMonthOrderWrapper.isNull(OrderPO::getId);
|
||||
}
|
||||
@@ -220,7 +226,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
overviewVO.setMonthOverMonthGrowth(monthOverMonthGrowth);
|
||||
|
||||
// 3. 计算店铺总单量(按状态「计入销售额」维度计单)
|
||||
int totalOrderCount = (int) orders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int totalOrderCount = (int) orders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
overviewVO.setTotalOrderCount(totalOrderCount);
|
||||
|
||||
// 3.1 退款金额、客单价(按状态「计入退款」维度)
|
||||
@@ -411,22 +417,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
}
|
||||
|
||||
private Map<Long, Long> orderSpecIdToProductIdMap(List<OrderPO> orders) {
|
||||
List<Long> specIds = orders.stream()
|
||||
.map(OrderPO::getProductSpecId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
if (specIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
List<ProductSpecPO> specs = productSpecMapper.selectList(new LambdaQueryWrapper<ProductSpecPO>()
|
||||
.in(ProductSpecPO::getId, specIds)
|
||||
.select(ProductSpecPO::getId, ProductSpecPO::getProductId));
|
||||
Map<Long, Long> map = new HashMap<>();
|
||||
for (ProductSpecPO s : specs) {
|
||||
map.put(s.getId(), s.getProductId());
|
||||
}
|
||||
return map;
|
||||
return OrderOverviewSupport.orderSpecIdToProductIdMap(productSkuMapper, orderItemMapper, orders);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -437,12 +428,11 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
List<BrushOrderPO> brushOrders, OrderStatusStatSets stat) {
|
||||
List<ShopOverviewStatisticsVO.ProductSummary> summaries = new ArrayList<>();
|
||||
|
||||
Map<Long, Long> specToProduct = orderSpecIdToProductIdMap(orders);
|
||||
Map<Long, Long> skuToProduct = orderSpecIdToProductIdMap(orders);
|
||||
Map<Long, OrderItemPO> firstItems = OrderOverviewSupport.firstItemsForOrders(orderItemMapper, orders);
|
||||
Map<Long, List<OrderPO>> ordersByProduct = orders.stream()
|
||||
.collect(Collectors.groupingBy(o -> {
|
||||
Long sid = o.getProductSpecId();
|
||||
return sid != null ? specToProduct.getOrDefault(sid, -1L) : -1L;
|
||||
}));
|
||||
.collect(Collectors.groupingBy(o ->
|
||||
OrderOverviewSupport.productIdOfOrder(o, firstItems, skuToProduct)));
|
||||
|
||||
// 按商品分组刷单费数据(如果有商品ID)
|
||||
Map<Long, List<BrushOrderPO>> brushOrdersByProduct = brushOrders.stream()
|
||||
@@ -541,7 +531,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
int orderCount = (int) productOrders.stream()
|
||||
.filter(o -> stat.includesSales(o.getStatusId()))
|
||||
.filter(o -> stat.includesSales(o.getStatus()))
|
||||
.count();
|
||||
|
||||
BigDecimal refundAmount = productOrders.stream()
|
||||
@@ -755,7 +745,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
Map<LocalDate, List<OrderPO>> ordersByDate = orders.stream()
|
||||
.collect(Collectors.groupingBy(order -> order.getOrderTime().toLocalDate()));
|
||||
|
||||
int totalCount = (int) orders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int totalCount = (int) orders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
trendData.setTotal(new BigDecimal(totalCount));
|
||||
|
||||
// 生成日期范围内的所有日期列表
|
||||
@@ -772,7 +762,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
ShopOverviewStatisticsVO.TrendDataItem item = new ShopOverviewStatisticsVO.TrendDataItem();
|
||||
item.setDate(date);
|
||||
List<OrderPO> dayOrders = ordersByDate.getOrDefault(date, new ArrayList<>());
|
||||
int dayCount = (int) dayOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int dayCount = (int) dayOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
item.setValue(new BigDecimal(dayCount));
|
||||
return item;
|
||||
})
|
||||
@@ -808,12 +798,14 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
categoryMap.put(c.getId(), c);
|
||||
}
|
||||
|
||||
Map<Long, Long> specToProduct = orderSpecIdToProductIdMap(orders);
|
||||
Map<Long, Long> skuToProduct = orderSpecIdToProductIdMap(orders);
|
||||
Map<Long, OrderItemPO> firstItems = OrderOverviewSupport.firstItemsForOrders(orderItemMapper, orders);
|
||||
// 按品类分组订单
|
||||
Map<Long, List<OrderPO>> ordersByCategory = new HashMap<>();
|
||||
for (OrderPO order : orders) {
|
||||
Long sid = order.getProductSpecId();
|
||||
Long pid = sid != null ? specToProduct.get(sid) : null;
|
||||
OrderItemPO item = firstItems.get(order.getId());
|
||||
Long sid = item != null ? item.getProductSkuId() : null;
|
||||
Long pid = sid != null ? skuToProduct.get(sid) : null;
|
||||
Long categoryId = pid != null ? productCategoryMap.get(pid) : null;
|
||||
if (categoryId == null) {
|
||||
categoryId = 0L; // 未分类
|
||||
@@ -867,7 +859,7 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
.map(stat::receivedForSales)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
int orderCount = (int) catOrders.stream().filter(o -> stat.includesSales(o.getStatusId())).count();
|
||||
int orderCount = (int) catOrders.stream().filter(o -> stat.includesSales(o.getStatus())).count();
|
||||
|
||||
BigDecimal refundAmount = catOrders.stream()
|
||||
.map(stat::receivedForRefund)
|
||||
@@ -876,7 +868,9 @@ public class ShopOverviewStatisticsServiceImpl implements ShopOverviewStatistics
|
||||
// 推广费:先汇总品类内各商品的直接归属推广费,再按品类销售额比例分配比例池
|
||||
Set<Long> catProductIds = new HashSet<>();
|
||||
for (OrderPO order : catOrders) {
|
||||
Long pid = specToProduct.get(order.getProductSpecId());
|
||||
OrderItemPO item = firstItems.get(order.getId());
|
||||
Long sid = item != null ? item.getProductSkuId() : null;
|
||||
Long pid = sid != null ? skuToProduct.get(sid) : null;
|
||||
if (pid != null) catProductIds.add(pid);
|
||||
}
|
||||
BigDecimal directCatPromotion = catProductIds.stream()
|
||||
|
||||
+5
-11
@@ -24,8 +24,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.pdd.pop.mall.PddMallApiSnapshot;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.pop.mall.PddMallPopApiClient;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.mapper.PddShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.po.PddShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
@@ -46,7 +45,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class PddAuthServiceImpl implements PddAuthService {
|
||||
|
||||
private static final String STATE_KEY_PREFIX = "pdd:oauth:state:";
|
||||
private static final String PLATFORM_CODE_PDD = "pdd";
|
||||
private static final String PLATFORM_CODE_PDD = PlatformCode.PDD.getCode();
|
||||
|
||||
private final PddOAuthProperties properties;
|
||||
private final PddPopClientFactory popClientFactory;
|
||||
@@ -56,7 +55,6 @@ public class PddAuthServiceImpl implements PddAuthService {
|
||||
private final PddAuthMapper pddAuthMapper;
|
||||
private final PddShopMapper pddShopMapper;
|
||||
private final ShopMapper shopMapper;
|
||||
private final PlatformMapper platformMapper;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public PddAuthServiceImpl(PddOAuthProperties properties,
|
||||
@@ -67,7 +65,6 @@ public class PddAuthServiceImpl implements PddAuthService {
|
||||
PddAuthMapper pddAuthMapper,
|
||||
PddShopMapper pddShopMapper,
|
||||
ShopMapper shopMapper,
|
||||
PlatformMapper platformMapper,
|
||||
ObjectMapper objectMapper) {
|
||||
this.properties = properties;
|
||||
this.popClientFactory = popClientFactory;
|
||||
@@ -77,7 +74,6 @@ public class PddAuthServiceImpl implements PddAuthService {
|
||||
this.pddAuthMapper = pddAuthMapper;
|
||||
this.pddShopMapper = pddShopMapper;
|
||||
this.shopMapper = shopMapper;
|
||||
this.platformMapper = platformMapper;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@@ -209,8 +205,7 @@ public class PddAuthServiceImpl implements PddAuthService {
|
||||
if (shop == null || !companyId.equals(shop.getCompanyId())) {
|
||||
throw new BusinessException("内部店铺不存在或不属于当前公司");
|
||||
}
|
||||
PlatformPO platform = platformMapper.selectById(shop.getPlatformId());
|
||||
if (platform == null || !PLATFORM_CODE_PDD.equals(platform.getPlatformCode())) {
|
||||
if (!PLATFORM_CODE_PDD.equals(shop.getPlatformCode())) {
|
||||
throw new BusinessException("仅支持对拼多多平台的内部店铺发起授权");
|
||||
}
|
||||
}
|
||||
@@ -344,8 +339,7 @@ public class PddAuthServiceImpl implements PddAuthService {
|
||||
throw new BusinessException("授权关联的内部店铺不存在或不属于当前公司");
|
||||
}
|
||||
|
||||
PlatformPO platform = platformMapper.selectById(shop.getPlatformId());
|
||||
if (platform == null || !PLATFORM_CODE_PDD.equals(platform.getPlatformCode())) {
|
||||
if (!PLATFORM_CODE_PDD.equals(shop.getPlatformCode())) {
|
||||
throw new BusinessException("内部店铺不是拼多多平台,无法绑定");
|
||||
}
|
||||
|
||||
@@ -354,7 +348,7 @@ public class PddAuthServiceImpl implements PddAuthService {
|
||||
// 同一公司+平台下外部店 ID 唯一:若已被其他内部店占用则解绑
|
||||
ShopPO occupied = shopMapper.selectOne(new LambdaQueryWrapper<ShopPO>()
|
||||
.eq(ShopPO::getCompanyId, companyId)
|
||||
.eq(ShopPO::getPlatformId, shop.getPlatformId())
|
||||
.eq(ShopPO::getPlatformCode, shop.getPlatformCode())
|
||||
.eq(ShopPO::getExternalShopId, externalShopId)
|
||||
.ne(ShopPO::getId, shopId)
|
||||
.last("LIMIT 1"));
|
||||
|
||||
+2
-13
@@ -8,15 +8,13 @@ import org.springframework.stereotype.Component;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.sync.mapper.PddOrderSyncCursorMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.sync.model.po.PddOrderSyncCursorPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.sync.service.PddOrderSyncService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 定时增量同步已绑定外部店的拼多多店铺;跳过增量游标 status=2(出错暂停)。
|
||||
@@ -27,30 +25,21 @@ import java.util.stream.Collectors;
|
||||
public class PddOrderIncrementalSyncJob {
|
||||
|
||||
private final ShopMapper shopMapper;
|
||||
private final PlatformMapper platformMapper;
|
||||
private final PddOrderSyncCursorMapper cursorMapper;
|
||||
private final PddOrderSyncService pddOrderSyncService;
|
||||
|
||||
public PddOrderIncrementalSyncJob(ShopMapper shopMapper,
|
||||
PlatformMapper platformMapper,
|
||||
PddOrderSyncCursorMapper cursorMapper,
|
||||
PddOrderSyncService pddOrderSyncService) {
|
||||
this.shopMapper = shopMapper;
|
||||
this.platformMapper = platformMapper;
|
||||
this.cursorMapper = cursorMapper;
|
||||
this.pddOrderSyncService = pddOrderSyncService;
|
||||
}
|
||||
|
||||
@Scheduled(cron = "${pdd.order-sync.incremental-cron:0 */5 * * * ?}")
|
||||
public void run() {
|
||||
List<PlatformPO> pddPlatforms = platformMapper.selectList(new LambdaQueryWrapper<PlatformPO>()
|
||||
.eq(PlatformPO::getPlatformCode, "pdd"));
|
||||
if (pddPlatforms.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<Long> platformIds = pddPlatforms.stream().map(PlatformPO::getId).collect(Collectors.toSet());
|
||||
List<ShopPO> shops = shopMapper.selectList(new LambdaQueryWrapper<ShopPO>()
|
||||
.in(ShopPO::getPlatformId, platformIds)
|
||||
.eq(ShopPO::getPlatformCode, PlatformCode.PDD.getCode())
|
||||
.isNotNull(ShopPO::getExternalShopId)
|
||||
.ne(ShopPO::getExternalShopId, ""));
|
||||
Set<Long> done = new HashSet<>();
|
||||
|
||||
+2
-9
@@ -9,8 +9,7 @@ import top.xyquan.ecomdmbbackend.modules.ecom.pdd.auth.model.po.PddAuthPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.order.sync.model.PddOrderSyncShopContext;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.mapper.PddShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.pdd.shop.model.po.PddShopPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.mapper.ShopMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.shop.model.po.ShopPO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
@@ -18,22 +17,17 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
@Service
|
||||
public class PddOrderSyncContextResolver {
|
||||
|
||||
private static final String PLATFORM_CODE_PDD = "pdd";
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final ShopMapper shopMapper;
|
||||
private final PlatformMapper platformMapper;
|
||||
private final PddShopMapper pddShopMapper;
|
||||
private final PddAuthMapper pddAuthMapper;
|
||||
|
||||
public PddOrderSyncContextResolver(CurrentUserContext currentUserContext,
|
||||
ShopMapper shopMapper,
|
||||
PlatformMapper platformMapper,
|
||||
PddShopMapper pddShopMapper,
|
||||
PddAuthMapper pddAuthMapper) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.shopMapper = shopMapper;
|
||||
this.platformMapper = platformMapper;
|
||||
this.pddShopMapper = pddShopMapper;
|
||||
this.pddAuthMapper = pddAuthMapper;
|
||||
}
|
||||
@@ -51,8 +45,7 @@ public class PddOrderSyncContextResolver {
|
||||
if (shop == null || !companyId.equals(shop.getCompanyId())) {
|
||||
throw new BusinessException("内部店铺不存在或不属于当前公司");
|
||||
}
|
||||
PlatformPO platform = platformMapper.selectById(shop.getPlatformId());
|
||||
if (platform == null || !PLATFORM_CODE_PDD.equals(platform.getPlatformCode())) {
|
||||
if (!PlatformCode.PDD.getCode().equals(shop.getPlatformCode())) {
|
||||
throw new BusinessException("仅支持拼多多平台店铺同步订单");
|
||||
}
|
||||
if (!StringUtils.hasText(shop.getExternalShopId())) {
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.ecom.platform.model.dto.CreatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.PlatformFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.UpdatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.service.PlatformService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 平台管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-平台管理", description = "平台的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/platform")
|
||||
public class PlatformController {
|
||||
|
||||
private final PlatformService platformService;
|
||||
|
||||
public PlatformController(PlatformService platformService) {
|
||||
this.platformService = platformService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建平台", description = "创建新的平台")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ecom:platform:manage", description = "创建平台", allowSuper = true)
|
||||
public ApiResponse<PlatformVO> createPlatform(@Valid @RequestBody CreatePlatformDTO createPlatformDTO) {
|
||||
PlatformVO platformVO = platformService.createPlatform(createPlatformDTO);
|
||||
return ApiResponse.success("平台创建成功", platformVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新平台", description = "更新现有平台信息")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:platform:manage", description = "更新平台", allowSuper = true)
|
||||
public ApiResponse<PlatformVO> updatePlatform(@Valid @RequestBody UpdatePlatformDTO updatePlatformDTO,
|
||||
@Parameter(description = "平台ID") @PathVariable Long id) {
|
||||
PlatformVO platformVO = platformService.updatePlatform(updatePlatformDTO, id);
|
||||
return ApiResponse.success("平台更新成功", platformVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除平台", description = "删除指定平台")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ecom:platform:manage", description = "删除平台", allowSuper = true)
|
||||
public ApiResponse<Void> deletePlatform(@Parameter(description = "平台ID") @PathVariable Long id) {
|
||||
platformService.deletePlatform(id);
|
||||
return ApiResponse.success("平台删除成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取平台列表", description = "分页获取平台列表,支持条件过滤")
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ecom:platform:read", description = "查询平台列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<PlatformVO>> getPlatformPage(
|
||||
@Valid @RequestBody PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<PlatformVO> result = platformService.getPlatformPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取平台列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有启用的平台", description = "获取所有已启用的平台列表,供下拉选择")
|
||||
@GetMapping("/active")
|
||||
@RequirePermission(value = "ecom:platform:read", description = "查询平台列表", allowSuper = true)
|
||||
public ApiResponse<List<PlatformVO>> getActivePlatforms() {
|
||||
List<PlatformVO> result = platformService.getActivePlatforms();
|
||||
return ApiResponse.success("获取启用的平台列表成功", result);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformDictVO;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 电商平台字典:返回静态 code/label/sortOrder,供下拉选择。
|
||||
*/
|
||||
@Tag(name = "电商-平台字典", description = "电商平台静态字典")
|
||||
@RestController
|
||||
@RequestMapping("/ec/platform")
|
||||
public class PlatformDictController {
|
||||
|
||||
@Operation(summary = "获取平台列表", description = "返回全部预置电商平台(code/label/sortOrder)")
|
||||
@GetMapping("/list")
|
||||
@RequirePermission(value = "ecom:shop:read", description = "查询平台字典", allowSuper = true)
|
||||
public ApiResponse<List<PlatformDictVO>> listPlatforms() {
|
||||
List<PlatformDictVO> list = PlatformCode.all().stream()
|
||||
.sorted(Comparator.comparingInt(PlatformCode::getSortOrder))
|
||||
.map(p -> new PlatformDictVO(p.getCode(), p.getLabel(), p.getSortOrder()))
|
||||
.toList();
|
||||
return ApiResponse.success("获取平台列表成功", list);
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
|
||||
/**
|
||||
* 平台Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface PlatformMapper extends BaseMapper<PlatformPO> {
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建平台DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建平台DTO")
|
||||
public class CreatePlatformDTO {
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台名称不能为空")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台代码不能为空")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 所属公司ID
|
||||
*/
|
||||
@Schema(description = "所属公司ID", example = "1")
|
||||
private Long companyId;
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 平台过滤DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "平台过滤DTO")
|
||||
public class PlatformFilterDTO {
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 所属公司ID
|
||||
*/
|
||||
@Schema(description = "所属公司ID", example = "1")
|
||||
private Long companyId;
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更新平台DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新平台DTO")
|
||||
public class UpdatePlatformDTO {
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台名称不能为空")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "平台代码不能为空")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
@NotNull(message = "是否启用不能为空")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 所属公司ID
|
||||
*/
|
||||
@Schema(description = "所属公司ID", example = "1")
|
||||
private Long companyId;
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 电商平台代码(软约定,无平台表)。
|
||||
*/
|
||||
@Getter
|
||||
public enum PlatformCode {
|
||||
TAOBAO("taobao", "淘宝", 1),
|
||||
JD("jd", "京东", 2),
|
||||
PDD("pdd", "拼多多", 3),
|
||||
DOUYIN("douyin", "抖音", 4),
|
||||
KUAISHOU("kuaishou", "快手", 5),
|
||||
XIAOHONGSHU("xiaohongshu", "小红书", 6),
|
||||
TMALL("tmall", "天猫", 7),
|
||||
VIP("vip", "唯品会", 8),
|
||||
SUNING("suning", "苏宁", 9),
|
||||
ALIBABA_1688("1688", "1688", 10);
|
||||
|
||||
private final String code;
|
||||
private final String label;
|
||||
private final int sortOrder;
|
||||
|
||||
PlatformCode(String code, String label, int sortOrder) {
|
||||
this.code = code;
|
||||
this.label = label;
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
|
||||
public static Optional<PlatformCode> ofCode(String code) {
|
||||
if (code == null || code.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String normalized = code.trim();
|
||||
return Arrays.stream(values())
|
||||
.filter(p -> p.code.equalsIgnoreCase(normalized))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public static String labelOf(String code) {
|
||||
return ofCode(code).map(PlatformCode::getLabel).orElse(code);
|
||||
}
|
||||
|
||||
public static boolean isValid(String code) {
|
||||
return ofCode(code).isPresent();
|
||||
}
|
||||
|
||||
public static List<PlatformCode> all() {
|
||||
return Arrays.asList(values());
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-平台实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_platform")
|
||||
public class PlatformPO {
|
||||
|
||||
/**
|
||||
* 平台ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 所属公司ID
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 平台名称(如淘宝、京东、拼多多、抖音)
|
||||
*/
|
||||
@TableField("platform_name")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码(如 taobao、jd、pdd、douyin)
|
||||
*/
|
||||
@TableField("platform_code")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort_order")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用 0禁用 1启用
|
||||
*/
|
||||
@TableField("is_active")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 电商平台字典项(静态枚举,无平台表)。
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "电商平台字典项")
|
||||
public class PlatformDictVO {
|
||||
|
||||
@Schema(description = "平台代码", example = "pdd")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "平台名称", example = "拼多多")
|
||||
private String label;
|
||||
|
||||
@Schema(description = "排序", example = "3")
|
||||
private int sortOrder;
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 平台VO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "平台VO")
|
||||
public class PlatformVO {
|
||||
|
||||
/**
|
||||
* 平台ID
|
||||
*/
|
||||
@Schema(description = "平台ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 所属公司ID
|
||||
*/
|
||||
@Schema(description = "所属公司ID", example = "1")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 平台名称
|
||||
*/
|
||||
@Schema(description = "平台名称", example = "淘宝")
|
||||
private String platformName;
|
||||
|
||||
/**
|
||||
* 平台代码
|
||||
*/
|
||||
@Schema(description = "平台代码", example = "taobao")
|
||||
private String platformCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
@Schema(description = "是否启用 0禁用 1启用", example = "1")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Schema(description = "更新时间", example = "2024-01-01T10:00:00")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.CreatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.PlatformFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.UpdatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 平台服务接口
|
||||
*/
|
||||
public interface PlatformService extends IService<PlatformPO> {
|
||||
|
||||
/**
|
||||
* 创建平台
|
||||
*
|
||||
* @param createPlatformDTO 创建平台DTO
|
||||
* @return 平台VO
|
||||
*/
|
||||
PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO);
|
||||
|
||||
/**
|
||||
* 更新平台
|
||||
*
|
||||
* @param updatePlatformDTO 更新平台DTO
|
||||
* @param id 平台ID
|
||||
* @return 平台VO
|
||||
*/
|
||||
PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id);
|
||||
|
||||
/**
|
||||
* 删除平台
|
||||
*
|
||||
* @param id 平台ID
|
||||
*/
|
||||
void deletePlatform(Long id);
|
||||
|
||||
/**
|
||||
* 分页获取平台列表
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 获取所有启用的平台列表
|
||||
*
|
||||
* @return 平台列表
|
||||
*/
|
||||
List<PlatformVO> getActivePlatforms();
|
||||
|
||||
/**
|
||||
* 为新公司初始化平台数据(从平台公共数据复制)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param creatorId 创建人ID
|
||||
*/
|
||||
void initPlatformsForCompany(Long companyId, Long creatorId);
|
||||
}
|
||||
-229
@@ -1,229 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.platform.service.impl;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
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 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.modules.ecom.platform.mapper.PlatformMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.CreatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.PlatformFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.dto.UpdatePlatformDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.po.PlatformPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.model.vo.PlatformVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.platform.service.PlatformService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 平台服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class PlatformServiceImpl extends ServiceImpl<PlatformMapper, PlatformPO> implements PlatformService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public PlatformServiceImpl(CurrentUserContext currentUserContext) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlatformVO createPlatform(CreatePlatformDTO createPlatformDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证平台名称是否重复(同一公司下)
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||
.eq(PlatformPO::getPlatformName, createPlatformDTO.getPlatformName());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台名称已存在");
|
||||
}
|
||||
|
||||
// 验证平台代码是否重复(同一公司下)
|
||||
wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||
.eq(PlatformPO::getPlatformCode, createPlatformDTO.getPlatformCode());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台代码已存在");
|
||||
}
|
||||
|
||||
// 创建平台
|
||||
PlatformPO platform = new PlatformPO();
|
||||
BeanCopyUtils.copyProperties(createPlatformDTO, platform);
|
||||
platform.setCompanyId(companyId);
|
||||
|
||||
// 设置默认值
|
||||
if (platform.getSortOrder() == null) {
|
||||
platform.setSortOrder(0);
|
||||
}
|
||||
if (platform.getIsActive() == null) {
|
||||
platform.setIsActive(1);
|
||||
}
|
||||
|
||||
// 设置创建人ID
|
||||
platform.setCreateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 保存平台
|
||||
this.save(platform);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PlatformVO updatePlatform(UpdatePlatformDTO updatePlatformDTO, Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
// 验证平台是否存在
|
||||
PlatformPO existingPlatform = this.getById(id);
|
||||
if (existingPlatform == null) {
|
||||
throw new BusinessException("平台不存在");
|
||||
}
|
||||
|
||||
// 验证平台名称是否重复(排除当前平台,同一公司下)
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||
.eq(PlatformPO::getPlatformName, updatePlatformDTO.getPlatformName())
|
||||
.ne(PlatformPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台名称已存在");
|
||||
}
|
||||
|
||||
// 验证平台代码是否重复(排除当前平台,同一公司下)
|
||||
wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||
.eq(PlatformPO::getPlatformCode, updatePlatformDTO.getPlatformCode())
|
||||
.ne(PlatformPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("平台代码已存在");
|
||||
}
|
||||
|
||||
// 更新平台
|
||||
PlatformPO platform = new PlatformPO();
|
||||
BeanCopyUtils.copyProperties(updatePlatformDTO, platform);
|
||||
platform.setId(id);
|
||||
platform.setCompanyId(companyId);
|
||||
|
||||
// 设置更新人ID
|
||||
platform.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||
|
||||
// 更新平台
|
||||
this.updateById(platform);
|
||||
|
||||
// 转换为VO并返回
|
||||
return convertToVO(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deletePlatform(Long id) {
|
||||
// 验证平台是否存在
|
||||
PlatformPO existingPlatform = this.getById(id);
|
||||
if (existingPlatform == null) {
|
||||
throw new BusinessException("平台不存在");
|
||||
}
|
||||
|
||||
// 删除平台
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<PlatformVO> getPlatformPage(PageQueryDTO<PlatformFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PlatformFilterDTO filter = pageQueryDTO.getFilters() != null ? pageQueryDTO.getFilters() : new PlatformFilterDTO();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getCompanyId, companyId);
|
||||
if (filter.getPlatformName() != null && !filter.getPlatformName().isEmpty()) {
|
||||
wrapper.like(PlatformPO::getPlatformName, filter.getPlatformName());
|
||||
}
|
||||
if (filter.getPlatformCode() != null && !filter.getPlatformCode().isEmpty()) {
|
||||
wrapper.eq(PlatformPO::getPlatformCode, filter.getPlatformCode());
|
||||
}
|
||||
if (filter.getIsActive() != null) {
|
||||
wrapper.eq(PlatformPO::getIsActive, filter.getIsActive());
|
||||
}
|
||||
|
||||
// 按排序字段升序
|
||||
wrapper.orderByAsc(PlatformPO::getSortOrder)
|
||||
.orderByDesc(PlatformPO::getCreateTime);
|
||||
|
||||
// 分页查询
|
||||
IPage<PlatformPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<PlatformPO> result = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<PlatformVO> voList = result.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(voList, result.getTotal(), (int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlatformVO> getActivePlatforms() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
LambdaQueryWrapper<PlatformPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PlatformPO::getCompanyId, companyId)
|
||||
.eq(PlatformPO::getIsActive, 1)
|
||||
.orderByAsc(PlatformPO::getSortOrder);
|
||||
|
||||
return this.list(wrapper).stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initPlatformsForCompany(Long companyId, Long creatorId) {
|
||||
// 检查该公司是否已有平台数据
|
||||
LambdaQueryWrapper<PlatformPO> checkWrapper = new LambdaQueryWrapper<>();
|
||||
checkWrapper.eq(PlatformPO::getCompanyId, companyId);
|
||||
if (this.count(checkWrapper) > 0) {
|
||||
return; // 已有平台数据,无需初始化
|
||||
}
|
||||
|
||||
// 插入初始平台数据(绑定到公司)
|
||||
List<PlatformPO> initialPlatforms = List.of(
|
||||
createPlatform(companyId, "淘宝", "taobao", 1, creatorId),
|
||||
createPlatform(companyId, "京东", "jd", 2, creatorId),
|
||||
createPlatform(companyId, "拼多多", "pdd", 3, creatorId),
|
||||
createPlatform(companyId, "抖音", "douyin", 4, creatorId),
|
||||
createPlatform(companyId, "快手", "kuaishou", 5, creatorId),
|
||||
createPlatform(companyId, "小红书", "xiaohongshu", 6, creatorId),
|
||||
createPlatform(companyId, "天猫", "tmall", 7, creatorId),
|
||||
createPlatform(companyId, "唯品会", "vip", 8, creatorId),
|
||||
createPlatform(companyId, "苏宁", "suning", 9, creatorId),
|
||||
createPlatform(companyId, "1688", "1688", 10, creatorId)
|
||||
);
|
||||
|
||||
this.saveBatch(initialPlatforms);
|
||||
}
|
||||
|
||||
private PlatformPO createPlatform(Long companyId, String name, String code, int sortOrder, Long creatorId) {
|
||||
PlatformPO platform = new PlatformPO();
|
||||
platform.setCompanyId(companyId);
|
||||
platform.setPlatformName(name);
|
||||
platform.setPlatformCode(code);
|
||||
platform.setSortOrder(sortOrder);
|
||||
platform.setIsActive(1);
|
||||
platform.setCreateBy(creatorId);
|
||||
platform.setUpdateBy(creatorId);
|
||||
return platform;
|
||||
}
|
||||
|
||||
private PlatformVO convertToVO(PlatformPO platform) {
|
||||
PlatformVO vo = new PlatformVO();
|
||||
BeanCopyUtils.copyProperties(platform, vo);
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -31,7 +31,7 @@ public class ProductController {
|
||||
this.productService = productService;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建商品", description = "创建新的商品;响应含 specIdsCostChangedWithLinkedOrders:新增规格且规格编码非空、商品/运费/其他成本至少一项大于 0、且本公司在库中存在关联订单的规格ID(如同编码合并),用于提示同步成本")
|
||||
@Operation(summary = "创建商品", description = "创建新的商品;响应含 skuIdsCostChangedWithLinkedOrders:新增规格且规格编码非空、商品/运费/其他成本至少一项大于 0、且本公司在库中存在关联订单的规格ID(如同编码合并),用于提示同步成本")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ecom:product:create", description = "创建商品", allowSuper = true)
|
||||
public ApiResponse<CreateProductResultDTO> createProduct(@Valid @RequestBody CreateProductDTO createProductDTO) {
|
||||
@@ -39,7 +39,7 @@ public class ProductController {
|
||||
return ApiResponse.success("商品创建成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新商品", description = "更新现有商品信息;响应中的 specIdsCostChangedWithLinkedOrders 为「成本已变更且存在关联订单」的规格ID,用于提示同步成本")
|
||||
@Operation(summary = "更新商品", description = "更新现有商品信息;响应中的 skuIdsCostChangedWithLinkedOrders 为「成本已变更且存在关联订单」的规格ID,用于提示同步成本")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:product:update", description = "更新商品", allowSuper = true)
|
||||
public ApiResponse<UpdateProductResultDTO> updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO,
|
||||
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.controller;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.BatchSyncCostDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductSkuFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.SyncCostDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuCostService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSkuService.ProductSkuQueryDTO;
|
||||
|
||||
/**
|
||||
* 商品 SKU 管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-商品SKU管理", description = "商品SKU的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/product-sku")
|
||||
public class ProductSkuController {
|
||||
|
||||
private final ProductSkuService productSkuService;
|
||||
private final ProductSkuCostService productSkuCostService;
|
||||
private final OrderService orderService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public ProductSkuController(ProductSkuService productSkuService,
|
||||
ProductSkuCostService productSkuCostService,
|
||||
OrderService orderService,
|
||||
CurrentUserContext currentUserContext) {
|
||||
this.productSkuService = productSkuService;
|
||||
this.productSkuCostService = productSkuCostService;
|
||||
this.orderService = orderService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建商品SKU")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ecom:product:create", description = "创建商品SKU", allowSuper = true)
|
||||
public ApiResponse<ProductSkuVO> createProductSku(@Valid @RequestBody CreateProductSkuDTO dto) {
|
||||
ProductSkuVO vo = productSkuService.createProductSku(dto);
|
||||
return ApiResponse.success("SKU创建成功", vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新商品SKU")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:product:update", description = "更新商品SKU", allowSuper = true)
|
||||
public ApiResponse<ProductSkuVO> updateProductSku(@Valid @RequestBody UpdateProductSkuDTO dto,
|
||||
@Parameter(description = "商品SKU ID") @PathVariable Long id) {
|
||||
ProductSkuVO vo = productSkuService.updateProductSku(dto, id);
|
||||
return ApiResponse.success("SKU更新成功", vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除商品SKU")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ecom:product:delete", description = "删除商品SKU", allowSuper = true)
|
||||
public ApiResponse<Void> deleteProductSku(@Parameter(description = "商品SKU ID") @PathVariable Long id) {
|
||||
productSkuService.deleteProductSku(id);
|
||||
return ApiResponse.<Void>success("SKU删除成功", null);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取商品SKU列表")
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ecom:product:read", description = "查询商品SKU列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ProductSkuVO>> getProductSkuPage(
|
||||
@Valid @RequestBody PageQueryDTO<ProductSkuFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ProductSkuVO> result = productSkuService.getProductSkuPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取商品SKU列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID列表批量查询商品SKU")
|
||||
@PostMapping("/batch-get-by-ids")
|
||||
@RequirePermission(value = "ecom:product:read", description = "批量查询商品SKU", allowSuper = true)
|
||||
public ApiResponse<List<ProductSkuVO>> batchGetByIds(@RequestBody List<Long> skuIds) {
|
||||
List<ProductSkuPO> skus = productSkuService.getByIds(skuIds);
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
List<ProductSkuVO> result = skus.stream()
|
||||
.filter(sku -> sku.getCompanyId().equals(companyId))
|
||||
.map(productSkuService::toVo)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
return ApiResponse.success("批量获取商品SKU成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据商品名称和SKU编码精准查询")
|
||||
@GetMapping("/find-by-product-and-sku/{productName}/{skuCode}")
|
||||
@RequirePermission(value = "ecom:product:read", description = "根据商品名称和SKU编码查询", allowSuper = true)
|
||||
public ApiResponse<ProductSkuVO> getProductSkuByProductAndSku(
|
||||
@Parameter(description = "商品名称") @PathVariable String productName,
|
||||
@Parameter(description = "SKU编码") @PathVariable String skuCode) {
|
||||
ProductSkuVO vo = productSkuService.getProductSkuByProductAndSku(productName, skuCode);
|
||||
return ApiResponse.success("查询SKU成功", vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量根据商品名称和SKU编码查询")
|
||||
@PostMapping("/find-by-product-and-skus")
|
||||
@RequirePermission(value = "ecom:product:read", description = "批量根据商品名称和SKU编码查询", allowSuper = true)
|
||||
public ApiResponse<List<ProductVO>> getProductSkusByProductAndSkus(@RequestBody List<ProductSkuQueryDTO> queries) {
|
||||
List<ProductVO> productVOs = productSkuService.getProductSkusByProductAndSkus(queries);
|
||||
return ApiResponse.success("批量查询SKU成功", productVOs);
|
||||
}
|
||||
|
||||
@Operation(summary = "同步SKU成本到历史订单")
|
||||
@PostMapping("/sync-costs-to-orders")
|
||||
@RequirePermission(value = "ecom:product:update", description = "同步成本到订单", allowSuper = true)
|
||||
public ApiResponse<Integer> syncCostsToOrders(@Valid @RequestBody SyncCostDTO syncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ProductSkuPO sku = productSkuService.getById(syncCostDTO.getSkuId());
|
||||
if (sku == null || !sku.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("SKU不存在");
|
||||
}
|
||||
int updatedCount = orderService.syncCostsToOrders(
|
||||
syncCostDTO.getSkuId(),
|
||||
syncCostDTO.getProductCost(),
|
||||
syncCostDTO.getShippingCost(),
|
||||
syncCostDTO.getOtherCost(),
|
||||
syncCostDTO.getStartTime(),
|
||||
syncCostDTO.getEndTime());
|
||||
return ApiResponse.success("成本同步成功,共更新" + updatedCount + "条订单", updatedCount);
|
||||
}
|
||||
|
||||
@Operation(summary = "统计成本同步将影响的订单数量")
|
||||
@PostMapping("/count-orders-for-cost-sync")
|
||||
@RequirePermission(value = "ecom:product:read", description = "统计成本同步订单数", allowSuper = true)
|
||||
public ApiResponse<Long> countOrdersForCostSync(@Valid @RequestBody BatchSyncCostDTO batchSyncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
List<ProductSkuPO> skus = productSkuService.getByIds(batchSyncCostDTO.getSkuIds());
|
||||
if (skus.isEmpty()) {
|
||||
return ApiResponse.success("统计成功", 0L);
|
||||
}
|
||||
for (ProductSkuPO sku : skus) {
|
||||
if (!sku.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("SKU不存在,SKU ID: " + sku.getId());
|
||||
}
|
||||
}
|
||||
long count = orderService.countOrdersForCostSync(
|
||||
companyId,
|
||||
batchSyncCostDTO.getSkuIds(),
|
||||
batchSyncCostDTO.getStartTime(),
|
||||
batchSyncCostDTO.getEndTime());
|
||||
return ApiResponse.success("统计成功", count);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量同步SKU成本到历史订单")
|
||||
@PostMapping("/batch-sync-costs-to-orders")
|
||||
@RequirePermission(value = "ecom:product:update", description = "批量同步成本到订单", allowSuper = true)
|
||||
public ApiResponse<Integer> batchSyncCostsToOrders(@Valid @RequestBody BatchSyncCostDTO batchSyncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
List<ProductSkuPO> skus = productSkuService.getByIds(batchSyncCostDTO.getSkuIds());
|
||||
if (skus.isEmpty()) {
|
||||
return ApiResponse.success("没有找到需要同步的SKU", 0);
|
||||
}
|
||||
for (ProductSkuPO sku : skus) {
|
||||
if (!sku.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("SKU不存在,SKU ID: " + sku.getId());
|
||||
}
|
||||
}
|
||||
int totalUpdated = 0;
|
||||
for (ProductSkuPO sku : skus) {
|
||||
var cost = productSkuCostService.getCurrentCost(sku.getId());
|
||||
int updated = orderService.syncCostsToOrders(
|
||||
sku.getId(),
|
||||
cost != null ? cost.getProductCost() : null,
|
||||
cost != null ? cost.getShippingCost() : null,
|
||||
cost != null ? cost.getOtherCost() : null,
|
||||
batchSyncCostDTO.getStartTime(),
|
||||
batchSyncCostDTO.getEndTime());
|
||||
totalUpdated += updated;
|
||||
}
|
||||
return ApiResponse.success("批量成本同步成功,共更新" + totalUpdated + "条订单", totalUpdated);
|
||||
}
|
||||
}
|
||||
-194
@@ -1,194 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.controller;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.BatchSyncCostDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductSpecDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductSpecFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.SyncCostDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductSpecDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService.ProductSpecQueryDTO;
|
||||
|
||||
/**
|
||||
* 商品规格管理控制器
|
||||
*/
|
||||
@Tag(name = "电商-商品规格管理", description = "商品规格的增删改查接口")
|
||||
@RestController
|
||||
@RequestMapping("/ec/product-spec")
|
||||
public class ProductSpecController {
|
||||
|
||||
private final ProductSpecService productSpecService;
|
||||
private final OrderService orderService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public ProductSpecController(ProductSpecService productSpecService, OrderService orderService,
|
||||
CurrentUserContext currentUserContext) {
|
||||
this.productSpecService = productSpecService;
|
||||
this.orderService = orderService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建商品规格", description = "创建新的商品规格")
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "ecom:product:create", description = "创建商品规格", allowSuper = true)
|
||||
public ApiResponse<ProductSpecVO> createProductSpec(@Valid @RequestBody CreateProductSpecDTO createProductSpecDTO) {
|
||||
ProductSpecVO productSpecVO = productSpecService.createProductSpec(createProductSpecDTO);
|
||||
return ApiResponse.success("规格创建成功", productSpecVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新商品规格", description = "更新现有商品规格信息")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:product:update", description = "更新商品规格", allowSuper = true)
|
||||
public ApiResponse<ProductSpecVO> updateProductSpec(@Valid @RequestBody UpdateProductSpecDTO updateProductSpecDTO,
|
||||
@Parameter(description = "商品规格ID") @PathVariable Long id) {
|
||||
ProductSpecVO productSpecVO = productSpecService.updateProductSpec(updateProductSpecDTO, id);
|
||||
return ApiResponse.success("规格更新成功", productSpecVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除商品规格", description = "删除指定商品规格")
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "ecom:product:delete", description = "删除商品规格", allowSuper = true)
|
||||
public ApiResponse<Void> deleteProductSpec(
|
||||
@Parameter(description = "商品规格ID") @PathVariable Long id) {
|
||||
productSpecService.deleteProductSpec(id);
|
||||
return ApiResponse.<Void>success("规格删除成功", null);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页获取商品规格列表", description = "分页获取商品规格列表,支持条件过滤")
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "ecom:product:read", description = "查询商品规格列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ProductSpecVO>> getProductSpecPage(
|
||||
@Valid @RequestBody PageQueryDTO<ProductSpecFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ProductSpecVO> result = productSpecService.getProductSpecPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取商品规格列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ID列表批量查询商品规格", description = "根据规格ID列表批量查询规格详情,用于同步确认")
|
||||
@PostMapping("/batch-get-by-ids")
|
||||
@RequirePermission(value = "ecom:product:read", description = "批量查询商品规格", allowSuper = true)
|
||||
public ApiResponse<List<ProductSpecVO>> batchGetByIds(@RequestBody List<Long> specIds) {
|
||||
List<ProductSpecPO> specs = productSpecService.getByIds(specIds);
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
// 只返回属于该公司的规格
|
||||
List<ProductSpecVO> result = specs.stream()
|
||||
.filter(spec -> spec.getCompanyId().equals(companyId))
|
||||
.map(spec -> {
|
||||
ProductSpecVO vo = new ProductSpecVO();
|
||||
BeanCopyUtils.copyProperties(spec, vo);
|
||||
return vo;
|
||||
})
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
return ApiResponse.success("批量获取商品规格成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据商品名称和规格编码精准查询商品规格", description = "根据商品名称和规格编码精准查询商品规格信息,用于数据导入")
|
||||
@GetMapping("/find-by-product-and-spec/{productName}/{specCode}")
|
||||
@RequirePermission(value = "ecom:product:read", description = "根据商品名称和规格编码查询商品规格", allowSuper = true)
|
||||
public ApiResponse<ProductSpecVO> getProductSpecByProductAndSpec(
|
||||
@Parameter(description = "商品名称") @PathVariable String productName,
|
||||
@Parameter(description = "规格编码") @PathVariable String specCode) {
|
||||
ProductSpecVO productSpecVO = productSpecService.getProductSpecByProductAndSpec(productName, specCode);
|
||||
return ApiResponse.success("根据商品名称和规格编码查询规格成功", productSpecVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量根据商品名称和规格编码查询商品规格", description = "批量根据商品名称和规格编码精准查询商品规格信息,用于数据导入")
|
||||
@PostMapping("/find-by-product-and-specs")
|
||||
@RequirePermission(value = "ecom:product:read", description = "批量根据商品名称和规格编码查询商品规格", allowSuper = true)
|
||||
public ApiResponse<List<ProductVO>> getProductSpecsByProductAndSpecs(@RequestBody List<ProductSpecQueryDTO> queries) {
|
||||
List<ProductVO> productVOs = productSpecService.getProductSpecsByProductAndSpecs(queries);
|
||||
return ApiResponse.success("批量查询规格成功", productVOs);
|
||||
}
|
||||
|
||||
@Operation(summary = "同步规格成本到历史订单", description = "将指定规格的成本批量更新到符合时间范围的订单")
|
||||
@PostMapping("/sync-costs-to-orders")
|
||||
@RequirePermission(value = "ecom:product:update", description = "同步成本到订单", allowSuper = true)
|
||||
public ApiResponse<Integer> syncCostsToOrders(@Valid @RequestBody SyncCostDTO syncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
// 验证规格是否存在且属于该公司
|
||||
ProductSpecPO spec = productSpecService.getById(syncCostDTO.getSpecId());
|
||||
if (spec == null || !spec.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("规格不存在");
|
||||
}
|
||||
int updatedCount = orderService.syncCostsToOrders(
|
||||
syncCostDTO.getSpecId(),
|
||||
syncCostDTO.getProductCost(),
|
||||
syncCostDTO.getShippingCost(),
|
||||
syncCostDTO.getOtherCost(),
|
||||
syncCostDTO.getStartTime(),
|
||||
syncCostDTO.getEndTime()
|
||||
);
|
||||
return ApiResponse.success("成本同步成功,共更新" + updatedCount + "条订单", updatedCount);
|
||||
}
|
||||
|
||||
@Operation(summary = "统计成本同步将影响的订单数量", description = "根据已选规格与订单时间范围,统计当前公司将更新的订单条数,条件与批量同步一致")
|
||||
@PostMapping("/count-orders-for-cost-sync")
|
||||
@RequirePermission(value = "ecom:product:read", description = "统计成本同步订单数", allowSuper = true)
|
||||
public ApiResponse<Long> countOrdersForCostSync(@Valid @RequestBody BatchSyncCostDTO batchSyncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
List<ProductSpecPO> specs = productSpecService.getByIds(batchSyncCostDTO.getSpecIds());
|
||||
if (specs.isEmpty()) {
|
||||
return ApiResponse.success("统计成功", 0L);
|
||||
}
|
||||
for (ProductSpecPO spec : specs) {
|
||||
if (!spec.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("规格不存在,规格ID: " + spec.getId());
|
||||
}
|
||||
}
|
||||
long count = orderService.countOrdersForCostSync(
|
||||
companyId,
|
||||
batchSyncCostDTO.getSpecIds(),
|
||||
batchSyncCostDTO.getStartTime(),
|
||||
batchSyncCostDTO.getEndTime());
|
||||
return ApiResponse.success("统计成功", count);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量同步规格成本到历史订单", description = "批量将多个规格的成本同步到符合时间范围的订单")
|
||||
@PostMapping("/batch-sync-costs-to-orders")
|
||||
@RequirePermission(value = "ecom:product:update", description = "批量同步成本到订单", allowSuper = true)
|
||||
public ApiResponse<Integer> batchSyncCostsToOrders(@Valid @RequestBody BatchSyncCostDTO batchSyncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
// 批量查询规格信息
|
||||
List<ProductSpecPO> specs = productSpecService.getByIds(batchSyncCostDTO.getSpecIds());
|
||||
if (specs.isEmpty()) {
|
||||
return ApiResponse.success("没有找到需要同步的规格", 0);
|
||||
}
|
||||
// 校验所有规格都属于该公司
|
||||
for (ProductSpecPO spec : specs) {
|
||||
if (!spec.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("规格不存在,规格ID: " + spec.getId());
|
||||
}
|
||||
}
|
||||
// 逐个规格同步成本到订单,累加更新数量
|
||||
int totalUpdated = 0;
|
||||
for (ProductSpecPO spec : specs) {
|
||||
int updated = orderService.syncCostsToOrders(
|
||||
spec.getId(),
|
||||
spec.getProductCost(),
|
||||
spec.getShippingCost(),
|
||||
spec.getOtherCost(),
|
||||
batchSyncCostDTO.getStartTime(),
|
||||
batchSyncCostDTO.getEndTime()
|
||||
);
|
||||
totalUpdated += updated;
|
||||
}
|
||||
return ApiResponse.success("批量成本同步成功,共更新" + totalUpdated + "条订单", totalUpdated);
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuCostPO;
|
||||
|
||||
/**
|
||||
* 商品 SKU 成本 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductSkuCostMapper extends BaseMapper<ProductSkuCostPO> {
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSkuPO;
|
||||
|
||||
/**
|
||||
* 商品 SKU Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductSkuMapper extends BaseMapper<ProductSkuPO> {
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductSpecFilterDTO;
|
||||
|
||||
/**
|
||||
* 商品规格Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface ProductSpecMapper extends BaseMapper<ProductSpecPO> {
|
||||
|
||||
/**
|
||||
* 分页查询商品规格
|
||||
*/
|
||||
IPage<ProductSpecPO> selectPageWithFilter(Page<ProductSpecPO> page, @Param("filter") ProductSpecFilterDTO filter);
|
||||
}
|
||||
+6
-6
@@ -9,18 +9,18 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量同步规格成本到订单的请求DTO
|
||||
* 批量同步 SKU 成本到订单的请求 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "批量同步规格成本到订单的请求DTO")
|
||||
@Schema(description = "批量同步SKU成本到订单的请求DTO")
|
||||
public class BatchSyncCostDTO {
|
||||
|
||||
/**
|
||||
* 规格ID列表
|
||||
* SKU ID 列表
|
||||
*/
|
||||
@Schema(description = "规格ID列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "规格ID列表不能为空")
|
||||
private List<Long> specIds;
|
||||
@Schema(description = "SKU ID列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "SKU ID列表不能为空")
|
||||
private List<Long> skuIds;
|
||||
|
||||
/**
|
||||
* 订单开始时间(包含),格式 yyyy-MM-dd HH:mm:ss;按自然日筛选时一般为起日 00:00:00
|
||||
|
||||
+14
-50
@@ -10,88 +10,52 @@ import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建商品DTO
|
||||
* 创建商品 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建商品DTO")
|
||||
public class CreateProductDTO {
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
@Schema(description = "商品名称", example = "iPhone 15 Pro", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "商品名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商品编码
|
||||
*/
|
||||
@Schema(description = "商品编码", example = "IPHONE15PRO001")
|
||||
private String productCode;
|
||||
|
||||
/**
|
||||
* 类目ID
|
||||
*/
|
||||
@Schema(description = "类目ID", example = "1")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 主图图片ID
|
||||
*/
|
||||
@Schema(description = "主图图片ID", example = "1")
|
||||
private Long mainImageId;
|
||||
|
||||
/**
|
||||
* 商品规格列表(可选)
|
||||
*/
|
||||
@Schema(description = "商品规格列表")
|
||||
@Schema(description = "商品SKU列表")
|
||||
@Valid
|
||||
private List<ProductSpecDTO> specs;
|
||||
private List<ProductSkuDTO> skus;
|
||||
|
||||
/**
|
||||
* 商品规格DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商品规格DTO")
|
||||
public static class ProductSpecDTO {
|
||||
@Schema(description = "商品SKU DTO")
|
||||
public static class ProductSkuDTO {
|
||||
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "规格名称不能为空")
|
||||
@Schema(description = "SKU名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "SKU名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "IPHONE15PRO-128G-BLACK", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "规格编码不能为空")
|
||||
private String specCode;
|
||||
@Schema(description = "SKU编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "SKU编码不能为空")
|
||||
private String skuCode;
|
||||
|
||||
/**
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "商品成本", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
@Schema(description = "运费成本")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
@Schema(description = "其他成本")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,8 +17,8 @@ public class CreateProductResultDTO {
|
||||
private ProductVO product;
|
||||
|
||||
/**
|
||||
* 新增规格中:规格编码非空、商品/运费/其他成本至少一项大于 0、且本公司在库中存在关联订单的规格ID(通常为同编码合并后的已有规格)
|
||||
* 新增 SKU 中:skuCode 非空、成本至少一项大于 0、且本公司在库中存在关联订单的 SKU ID
|
||||
*/
|
||||
@Schema(description = "新增规格(有成本且有关联订单)的规格ID列表,用于同步成本提示")
|
||||
private List<Long> specIdsCostChangedWithLinkedOrders;
|
||||
@Schema(description = "新增SKU(有成本且有关联订单)的SKU ID列表,用于同步成本提示")
|
||||
private List<Long> skuIdsCostChangedWithLinkedOrders;
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 创建商品 SKU DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建商品SKU DTO")
|
||||
public class CreateProductSkuDTO {
|
||||
|
||||
@Schema(description = "商品ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品ID不能为空")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "SKU名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "SKU名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "SKU编码")
|
||||
private String skuCode;
|
||||
|
||||
@Schema(description = "商品成本", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
@Schema(description = "运费成本")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@Schema(description = "其他成本")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 创建商品规格DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "创建商品规格DTO")
|
||||
public class CreateProductSpecDTO {
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品ID不能为空")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "规格名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "IPHONE15PRO-128G-BLACK")
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
+8
-8
@@ -28,20 +28,20 @@ public class ProductFilterDTO {
|
||||
private String productCode;
|
||||
|
||||
/**
|
||||
* 规格编码(精准查询)
|
||||
* SKU 编码(精准查询)
|
||||
*/
|
||||
@Schema(description = "规格编码(精准查询)", example = "SKU001")
|
||||
private String specCode;
|
||||
@Schema(description = "SKU编码(精准查询)", example = "SKU001")
|
||||
private String skuCode;
|
||||
|
||||
/**
|
||||
* 规格名称(模糊查询)
|
||||
* SKU 名称(模糊查询)
|
||||
*/
|
||||
@Schema(description = "规格名称(模糊查询)", example = "256GB")
|
||||
private String specName;
|
||||
@Schema(description = "SKU名称(模糊查询)", example = "256GB")
|
||||
private String skuName;
|
||||
|
||||
/**
|
||||
* 关键字(模糊查询商品名称、商品编码、规格名称、规格编码)
|
||||
* 关键字(模糊查询商品名称、商品编码、SKU名称、SKU编码)
|
||||
*/
|
||||
@Schema(description = "关键字(模糊查询商品名称、商品编码、规格名称、规格编码)", example = "iPhone 256")
|
||||
@Schema(description = "关键字(模糊查询商品名称、商品编码、SKU名称、SKU编码)", example = "iPhone 256")
|
||||
private String keywords;
|
||||
}
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 商品 SKU 筛选 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商品SKU筛选DTO")
|
||||
public class ProductSkuFilterDTO {
|
||||
|
||||
@Schema(description = "商品ID")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "SKU ID")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "SKU名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "SKU编码")
|
||||
private String skuCode;
|
||||
|
||||
@Schema(description = "关键字(模糊查询SKU名称、SKU编码)")
|
||||
private String keywords;
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 商品规格筛选DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商品规格筛选DTO")
|
||||
public class ProductSpecFilterDTO {
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@Schema(description = "商品ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 规格ID
|
||||
*/
|
||||
@Schema(description = "规格ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
@Schema(description = "规格名称", example = "128GB")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "IPHONE15PRO-128G")
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 关键字(模糊查询规格名称、规格编码)
|
||||
*/
|
||||
@Schema(description = "关键字(模糊查询规格名称、规格编码)", example = "256GB")
|
||||
private String keywords;
|
||||
}
|
||||
+6
-6
@@ -8,18 +8,18 @@ import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 同步规格成本到订单的请求DTO
|
||||
* 同步 SKU 成本到订单的请求 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "同步规格成本到订单的请求DTO")
|
||||
@Schema(description = "同步SKU成本到订单的请求DTO")
|
||||
public class SyncCostDTO {
|
||||
|
||||
/**
|
||||
* 规格ID
|
||||
* SKU ID
|
||||
*/
|
||||
@Schema(description = "规格ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "规格ID不能为空")
|
||||
private Long specId;
|
||||
@Schema(description = "SKU ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "SKU ID不能为空")
|
||||
private Long skuId;
|
||||
|
||||
/**
|
||||
* 商品成本
|
||||
|
||||
+18
-60
@@ -10,100 +10,58 @@ import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 更新商品DTO
|
||||
* 更新商品 DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新商品DTO")
|
||||
public class UpdateProductDTO {
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
@Schema(description = "商品名称", example = "iPhone 15 Pro", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "商品名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 商品编码
|
||||
*/
|
||||
@Schema(description = "商品编码", example = "IPHONE15PRO001")
|
||||
private String productCode;
|
||||
|
||||
/**
|
||||
* 类目ID
|
||||
*/
|
||||
@Schema(description = "类目ID", example = "1")
|
||||
private Long categoryId;
|
||||
|
||||
/**
|
||||
* 主图图片ID
|
||||
*/
|
||||
@Schema(description = "主图图片ID", example = "1")
|
||||
private Long mainImageId;
|
||||
|
||||
/**
|
||||
* 商品规格列表(可选):有 id 的项为更新,无 id 的项为在该商品下新增规格。
|
||||
*/
|
||||
@Schema(description = "商品规格列表:含 id 为更新,不含 id 为新增")
|
||||
@Schema(description = "商品SKU列表:含 id 为更新,不含 id 为新增")
|
||||
@Valid
|
||||
private List<ProductSpecUpdateDTO> specs;
|
||||
private List<ProductSkuUpdateDTO> skus;
|
||||
|
||||
/**
|
||||
* 编辑商品时需删除的规格 ID(与 specs 组合使用:先删再改后增)。
|
||||
*/
|
||||
@Schema(description = "本次需删除的规格 ID 列表(须属于当前商品)")
|
||||
private List<Long> removedSpecIds;
|
||||
@Schema(description = "本次需删除的 SKU ID 列表(须属于当前商品)")
|
||||
private List<Long> removedSkuIds;
|
||||
|
||||
/**
|
||||
* 商品规格更新DTO(内部类)
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "商品规格更新DTO")
|
||||
public static class ProductSpecUpdateDTO {
|
||||
@Schema(description = "商品SKU更新DTO")
|
||||
public static class ProductSkuUpdateDTO {
|
||||
|
||||
/**
|
||||
* 规格ID(更新时必填;为空表示在该商品下新增一条规格)
|
||||
*/
|
||||
@Schema(description = "规格ID:有值则更新该规格,为空则新增", example = "1")
|
||||
@Schema(description = "SKU ID:有值则更新,为空则新增", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "规格名称不能为空")
|
||||
@Schema(description = "SKU名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "SKU名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "IPHONE15PRO-128G-BLACK", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "规格编码不能为空")
|
||||
private String specCode;
|
||||
@Schema(description = "SKU编码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "SKU编码不能为空")
|
||||
private String skuCode;
|
||||
|
||||
/**
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "商品成本", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
@Schema(description = "运费成本")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
@Schema(description = "其他成本")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -14,10 +14,10 @@ import java.util.List;
|
||||
public class UpdateProductResultDTO {
|
||||
|
||||
/**
|
||||
* 需提示同步成本的规格:成本已变更且有关联订单;或本次新增规格(规格编码非空、三项成本至少一项大于 0)且有关联订单
|
||||
* 需提示同步成本的 SKU:成本已变更且有关联订单;或本次新增 SKU 且有关联订单
|
||||
*/
|
||||
@Schema(description = "成本变更或新增规格(有成本且有关联订单)的规格ID列表,用于同步成本提示")
|
||||
private List<Long> specIdsCostChangedWithLinkedOrders;
|
||||
@Schema(description = "成本变更或新增SKU(有成本且有关联订单)的SKU ID列表,用于同步成本提示")
|
||||
private List<Long> skuIdsCostChangedWithLinkedOrders;
|
||||
|
||||
/**
|
||||
* 更新后的商品完整信息
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 更新商品 SKU DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新商品SKU DTO")
|
||||
public class UpdateProductSkuDTO {
|
||||
|
||||
@Schema(description = "SKU ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "SKU ID不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "SKU名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "SKU名称不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "SKU编码")
|
||||
private String skuCode;
|
||||
|
||||
@Schema(description = "商品成本", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
@Schema(description = "运费成本")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
@Schema(description = "其他成本")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
}
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 更新商品规格DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "更新商品规格DTO")
|
||||
public class UpdateProductSpecDTO {
|
||||
|
||||
/**
|
||||
* 规格ID
|
||||
*/
|
||||
@Schema(description = "规格ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "规格ID不能为空")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
@Schema(description = "规格名称", example = "128GB 深空黑色", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "规格名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@Schema(description = "规格编码", example = "IPHONE15PRO-128G-BLACK")
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 商品成本
|
||||
*/
|
||||
@Schema(description = "商品成本", example = "8000.00", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "商品成本不能为空")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@Schema(description = "运费成本", example = "10.00")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@Schema(description = "其他成本", example = "5.00")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注", example = "备注信息")
|
||||
private String remark;
|
||||
}
|
||||
+9
-47
@@ -5,91 +5,53 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 电商-商品规格实体
|
||||
* 电商-商品 SKU 历史成本(按 effective_from 分段)
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("ec_product_spec")
|
||||
public class ProductSpecPO {
|
||||
@TableName("ec_product_sku_cost")
|
||||
public class ProductSkuCostPO {
|
||||
|
||||
/**
|
||||
* 规格ID
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@TableField("company_id")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
@TableField("product_id")
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 规格名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
@TableField("sku_id")
|
||||
private Long skuId;
|
||||
|
||||
/**
|
||||
* 规格编码
|
||||
*/
|
||||
@TableField("spec_code")
|
||||
private String specCode;
|
||||
|
||||
/**
|
||||
* 商品成本
|
||||
*/
|
||||
@TableField("product_cost")
|
||||
private BigDecimal productCost;
|
||||
|
||||
/**
|
||||
* 运费成本
|
||||
*/
|
||||
@TableField("shipping_cost")
|
||||
private BigDecimal shippingCost;
|
||||
|
||||
/**
|
||||
* 其他成本
|
||||
*/
|
||||
@TableField("other_cost")
|
||||
private BigDecimal otherCost;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("effective_from")
|
||||
private LocalDate effectiveFrom;
|
||||
|
||||
@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;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@TableField("create_by")
|
||||
private Long createBy;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@TableField("update_by")
|
||||
private Long updateBy;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user