mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 07:09:20 +08:00
Compare commits
18
Commits
b8005db2dc
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e183ed7a6 | ||
|
|
2f60efb8ef | ||
|
|
fb05b47d46 | ||
|
|
abe75f87aa | ||
|
|
7781f53d8a | ||
|
|
5427b3830c | ||
|
|
f382ba9bd7 | ||
|
|
e47f76c22a | ||
|
|
b45729fa1a | ||
|
|
16933b38ff | ||
|
|
b06cdc0309 | ||
|
|
9fafe55c4e | ||
|
|
ee985e33a9 | ||
|
|
3f8f066a7c | ||
|
|
49bbaa7362 | ||
|
|
36884890af | ||
|
|
31cd151b12 | ||
|
|
9e4b92bd15 |
@@ -0,0 +1,5 @@
|
|||||||
|
# 根目录仅薄脚本入口;勿提交本地依赖与锁外产物
|
||||||
|
node_modules/
|
||||||
|
.DS_Store
|
||||||
|
*.log
|
||||||
|
.pnpm-store/
|
||||||
@@ -1,6 +1,22 @@
|
|||||||
# AGENTS.md
|
# AGENTS.md
|
||||||
|
|
||||||
电商 DMB / ECBI 系统。根目录**不是统一工作区**:各 app 各自构建、各自装依赖,根目录无 package.json。提交走 git(分支 `dev`),commit message 用中文 conventional 格式(`feat:`/`fix:`/`refactor:`/`sql:` 前缀)。
|
电商 DMB / ECBI 系统。根目录**不是业务 monorepo**:各 app 各自构建、各自装依赖;根 `package.json` 只做开发启动薄封装(仅 `concurrently`)。`pnpm-workspace.yaml` 的 `packages: []` 用于阻断向上解析到家目录 workspace,**不要**把 `apps/*` 写进去。提交走 git(分支 `dev`),commit message 用中文 conventional 格式(`feat:`/`fix:`/`refactor:`/`sql:` 前缀)。
|
||||||
|
|
||||||
|
## 本地一键启动(根目录)
|
||||||
|
|
||||||
|
先各自装好依赖(`apps/web` 的 `pnpm install`、`apps/agent` 的 venv、Server 环境变量等),再在仓库根:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install # 仅安装 concurrently
|
||||||
|
pnpm dev # 并行:web + server + agent
|
||||||
|
pnpm dev:web-server # 只要前后端
|
||||||
|
pnpm dev:web # 仅前端
|
||||||
|
pnpm dev:server # 仅 Java(./mvnw spring-boot:run)
|
||||||
|
pnpm dev:agent # 仅 Agent(需 apps/agent/.venv)
|
||||||
|
pnpm deploy:tui # 部署 TUI(需先 cd deploy && pnpm install;勿用 pnpm deploy,会撞内置命令)
|
||||||
|
```
|
||||||
|
|
||||||
|
Server 仍依赖本机 `DB_*` / Redis / `JWT_SECRET` 等;Agent 读 `apps/agent/.env.dev`。
|
||||||
|
|
||||||
## 目录一览
|
## 目录一览
|
||||||
|
|
||||||
@@ -53,7 +69,7 @@ deploy/ # 部署 TUI(原 ecom-deploy),流程见 deploy/MANU
|
|||||||
|
|
||||||
## 部署(deploy)
|
## 部署(deploy)
|
||||||
|
|
||||||
- TUI:`cd deploy && pnpm dev`,可选自动部署 / 仅编译 / 上传并重启
|
- TUI:根目录 `pnpm deploy:tui`(或 `cd deploy && pnpm dev`),可选自动部署 / 仅编译 / 上传并重启
|
||||||
- **`config.json` 含真实服务器地址与 SSH 私钥路径,切勿提交或打印**
|
- **`config.json` 含真实服务器地址与 SSH 私钥路径,切勿提交或打印**
|
||||||
- 部署模式:运行时镜像 + 挂载 `app/` 目录;更新 = 上传产物 + 重启容器,无需重建镜像
|
- 部署模式:运行时镜像 + 挂载 `app/` 目录;更新 = 上传产物 + 重启容器,无需重建镜像
|
||||||
- 编译产物统一放 `artifacts/`(已 gitignore):`backend/app.jar`、`frontend/` dist、`license/` 整目录
|
- 编译产物统一放 `artifacts/`(已 gitignore):`backend/app.jar`、`frontend/` dist、`license/` 整目录
|
||||||
|
|||||||
@@ -17,35 +17,26 @@ async def load_tools_for_turn(
|
|||||||
scene: str = SCENE_GENERAL,
|
scene: str = SCENE_GENERAL,
|
||||||
client_tools: list[Any] | None = None,
|
client_tools: list[Any] | None = None,
|
||||||
) -> list[Any]:
|
) -> list[Any]:
|
||||||
"""general:builtin + memory + 全部 MCP;发布场景:builtin + 目录/拼多多 MCP + 前端 ui_ 工具。"""
|
"""各场景均挂 memory_*;general 全量 MCP,发布场景仅目录/拼多多 + 前端 ui_。"""
|
||||||
from agent.tools.builtin import builtin_tools
|
from agent.tools.builtin import builtin_tools
|
||||||
from agent.tools.memory import memory_tools
|
from agent.tools.memory import memory_tools
|
||||||
from infrastructure.mcp.client import load_mcp_tools
|
from infrastructure.mcp.client import load_mcp_tools
|
||||||
|
|
||||||
scene_value = (scene or SCENE_GENERAL).strip() or SCENE_GENERAL
|
scene_value = (scene or SCENE_GENERAL).strip() or SCENE_GENERAL
|
||||||
tools: list[Any] = [*builtin_tools()]
|
tools: list[Any] = [*builtin_tools(), *memory_tools(memory, actor)]
|
||||||
|
|
||||||
|
mcp_tools = await load_mcp_tools(
|
||||||
|
settings,
|
||||||
|
company_id=actor.company_id,
|
||||||
|
user_id=actor.user_id,
|
||||||
|
)
|
||||||
if scene_value == SCENE_ECOM_GOODS_PUBLISH:
|
if scene_value == SCENE_ECOM_GOODS_PUBLISH:
|
||||||
mcp_tools = await load_mcp_tools(
|
|
||||||
settings,
|
|
||||||
company_id=actor.company_id,
|
|
||||||
user_id=actor.user_id,
|
|
||||||
)
|
|
||||||
# 发布场景:目录 + 拼多多渠道;不挂经营 BI
|
# 发布场景:目录 + 拼多多渠道;不挂经营 BI
|
||||||
mcp_tools = [
|
mcp_tools = [
|
||||||
t
|
t
|
||||||
for t in mcp_tools
|
for t in mcp_tools
|
||||||
if _tool_name(t).startswith(("catalog_", "pdd_")) or _tool_name(t) == "mcp_ping"
|
if _tool_name(t).startswith(("catalog_", "pdd_")) or _tool_name(t) == "mcp_ping"
|
||||||
]
|
]
|
||||||
tools.extend(mcp_tools)
|
|
||||||
if client_tools:
|
|
||||||
tools.extend(client_tools)
|
|
||||||
return tools
|
|
||||||
|
|
||||||
tools.extend(memory_tools(memory, actor))
|
|
||||||
mcp_tools = await load_mcp_tools(
|
|
||||||
settings, company_id=actor.company_id, user_id=actor.user_id
|
|
||||||
)
|
|
||||||
tools.extend(mcp_tools)
|
tools.extend(mcp_tools)
|
||||||
if client_tools:
|
if client_tools:
|
||||||
tools.extend(client_tools)
|
tools.extend(client_tools)
|
||||||
|
|||||||
@@ -87,13 +87,11 @@ class ChatService:
|
|||||||
session.llm_response_chain = None
|
session.llm_response_chain = None
|
||||||
await self._session_repo.update(session)
|
await self._session_repo.update(session)
|
||||||
|
|
||||||
just_saved = None
|
# 各 scene 均可按需 memory_*;显式「记住」也会 maybe_capture
|
||||||
memory_count = 0
|
just_saved = await self._memory.maybe_capture_from_user(
|
||||||
if scene == "general":
|
actor, thread_id=thread_id, text=text
|
||||||
just_saved = await self._memory.maybe_capture_from_user(
|
)
|
||||||
actor, thread_id=thread_id, text=text
|
memory_count = await self._memory.count_active(actor)
|
||||||
)
|
|
||||||
memory_count = await self._memory.count_active(actor)
|
|
||||||
|
|
||||||
system_prompt = build_system_prompt(
|
system_prompt = build_system_prompt(
|
||||||
memory_count=memory_count,
|
memory_count=memory_count,
|
||||||
|
|||||||
@@ -57,9 +57,28 @@ _PUBLISH_SYSTEM = (
|
|||||||
"不要复述工具名、回执原文、字数统计、查了几条、竞品标题全文或改写策略,除非用户问为什么这样改。"
|
"不要复述工具名、回执原文、字数统计、查了几条、竞品标题全文或改写策略,除非用户问为什么这样改。"
|
||||||
"不要主动列 SKU 编码表,不要给没问过的下一版备选,不要让用户刷新、核对,或说「如果还是旧的再告诉我」。"
|
"不要主动列 SKU 编码表,不要给没问过的下一版备选,不要让用户刷新、核对,或说「如果还是旧的再告诉我」。"
|
||||||
"禁止向用户索要或复述数字 ID。"
|
"禁止向用户索要或复述数字 ID。"
|
||||||
|
"【长期记忆】跨会话用户级记忆不自动注入;标题口径、常用规格写法、用户偏好等需要时:"
|
||||||
|
"先 memory_search,必要时 memory_load;用户要求记住用 memory_save。"
|
||||||
|
"改表仍以当前表单与用户本轮指令为准,记忆只作补充,勿用旧记忆覆盖用户刚说的写法。"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _append_memory_status(
|
||||||
|
system: str,
|
||||||
|
*,
|
||||||
|
memory_count: int,
|
||||||
|
memory_just_saved: str | None,
|
||||||
|
) -> str:
|
||||||
|
if memory_count > 0:
|
||||||
|
system += (
|
||||||
|
f"\n\n当前用户约有 {memory_count} 条长期记忆,"
|
||||||
|
"需要时用 memory_search / memory_load。"
|
||||||
|
)
|
||||||
|
if memory_just_saved:
|
||||||
|
system += f"\n\n【本轮已写入长期记忆】{memory_just_saved}"
|
||||||
|
return system
|
||||||
|
|
||||||
|
|
||||||
def build_system_prompt(
|
def build_system_prompt(
|
||||||
*,
|
*,
|
||||||
memory_count: int = 0,
|
memory_count: int = 0,
|
||||||
@@ -73,16 +92,15 @@ def build_system_prompt(
|
|||||||
# 控制体积,避免拖垮上下文
|
# 控制体积,避免拖垮上下文
|
||||||
if len(snap_text) > 12000:
|
if len(snap_text) > 12000:
|
||||||
snap_text = snap_text[:12000] + "…(截断)"
|
snap_text = snap_text[:12000] + "…(截断)"
|
||||||
return (
|
system = f"{_PUBLISH_SYSTEM}\n\n【当前发布表单】\n{snap_text}"
|
||||||
f"{_PUBLISH_SYSTEM}\n\n【当前发布表单】\n{snap_text}"
|
return _append_memory_status(
|
||||||
|
system,
|
||||||
|
memory_count=memory_count,
|
||||||
|
memory_just_saved=memory_just_saved,
|
||||||
)
|
)
|
||||||
|
|
||||||
system = _BASE_SYSTEM
|
return _append_memory_status(
|
||||||
if memory_count > 0:
|
_BASE_SYSTEM,
|
||||||
system += (
|
memory_count=memory_count,
|
||||||
f"\n\n当前用户约有 {memory_count} 条长期记忆,"
|
memory_just_saved=memory_just_saved,
|
||||||
"需要时用 memory_search / memory_load。"
|
)
|
||||||
)
|
|
||||||
if memory_just_saved:
|
|
||||||
system += f"\n\n【本轮已写入长期记忆】{memory_just_saved}"
|
|
||||||
return system
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ CREATE TABLE `ec_product` (
|
|||||||
-- 1. 挂在 ec_product 下:一商品多 SKU
|
-- 1. 挂在 ec_product 下:一商品多 SKU
|
||||||
-- 2. 公司内 sku_code 唯一,便于订单/导入匹配,以及映射平台 outer_id
|
-- 2. 公司内 sku_code 唯一,便于订单/导入匹配,以及映射平台 outer_id
|
||||||
-- 3. 成本不落本表,见 ec_product_sku_cost(按生效日历史)
|
-- 3. 成本不落本表,见 ec_product_sku_cost(按生效日历史)
|
||||||
|
-- 4. weight_g:单件实重(克,整数);NULL=未填;对齐拼多多 SKU weight;界面可按 kg 录入后换算
|
||||||
|
-- 5. warehouse_id:默认发货仓;体积尺寸供体积重;仓/报价见 ec_warehouse_express_design.sql
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
DROP TABLE IF EXISTS `ec_product_sku_cost`;
|
DROP TABLE IF EXISTS `ec_product_sku_cost`;
|
||||||
DROP TABLE IF EXISTS `ec_product_sku`;
|
DROP TABLE IF EXISTS `ec_product_sku`;
|
||||||
@@ -77,6 +79,11 @@ CREATE TABLE `ec_product_sku` (
|
|||||||
`name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'SKU 名称(如颜色/尺码组合展示名)',
|
`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 编码(公司内唯一,对应商家外部编码)',
|
`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 '条码(可选)',
|
`barcode` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '条码(可选)',
|
||||||
|
`weight_g` int UNSIGNED NULL DEFAULT NULL COMMENT '单件实重(克);NULL=未填;快递计费 / 平台同步用',
|
||||||
|
`length_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '长(mm);体积重用',
|
||||||
|
`width_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '宽(mm);体积重用',
|
||||||
|
`height_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '高(mm);体积重用',
|
||||||
|
`warehouse_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '默认发货仓(ec_warehouse.id)',
|
||||||
`attrs` json NULL COMMENT '规格属性 JSON,如 [{"name":"颜色","value":"红"}](冗余/过渡;结构化见 ec_product_spec*)',
|
`attrs` json NULL COMMENT '规格属性 JSON,如 [{"name":"颜色","value":"红"}](冗余/过渡;结构化见 ec_product_spec*)',
|
||||||
`spec_combination_key` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规格组合键(value_id 升序拼接;空=未结构化遗留)',
|
`spec_combination_key` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '规格组合键(value_id 升序拼接;空=未结构化遗留)',
|
||||||
`image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'SKU 图文件ID(系统文件,可选)',
|
`image_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT 'SKU 图文件ID(系统文件,可选)',
|
||||||
@@ -96,11 +103,13 @@ CREATE TABLE `ec_product_sku` (
|
|||||||
INDEX `idx_ec_product_sku_status`(`status` ASC) USING BTREE,
|
INDEX `idx_ec_product_sku_status`(`status` ASC) USING BTREE,
|
||||||
INDEX `idx_ec_product_sku_barcode`(`barcode` 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_image`(`image_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_product_sku_warehouse`(`warehouse_id` ASC) USING BTREE,
|
||||||
INDEX `fk_ec_product_sku_creator`(`create_by` ASC) USING BTREE,
|
INDEX `fk_ec_product_sku_creator`(`create_by` ASC) USING BTREE,
|
||||||
INDEX `fk_ec_product_sku_updater`(`update_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_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_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_image` FOREIGN KEY (`image_id`) REFERENCES `sys_file` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_product_sku_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
CONSTRAINT `fk_ec_product_sku_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
CONSTRAINT `fk_ec_product_sku_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
|
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表(内部可核算最小单位)' ;
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-商品SKU表(内部可核算最小单位)' ;
|
||||||
|
|||||||
@@ -0,0 +1,180 @@
|
|||||||
|
-- ========================================
|
||||||
|
-- 电商-仓库发货与快递报价(无进销存)
|
||||||
|
-- ec_warehouse / ec_express_quote(+version/region/band)
|
||||||
|
-- ec_warehouse_express_bind / ec_express_carrier_alias
|
||||||
|
-- SKU 默认仓、体积尺寸见 ec_product_design.sql(warehouse_id / length_mm…)
|
||||||
|
-- REGION_WEIGHT:目的分区 × 多重量带(元/票 或 首重+续重/kg),对齐承运商矩阵报价单
|
||||||
|
-- ========================================
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- 仓库主数据(无库存)
|
||||||
|
-- ----------------------------
|
||||||
|
DROP TABLE IF EXISTS `ec_warehouse_express_bind`;
|
||||||
|
DROP TABLE IF EXISTS `ec_express_quote_band`;
|
||||||
|
DROP TABLE IF EXISTS `ec_express_quote_tier`;
|
||||||
|
DROP TABLE IF EXISTS `ec_express_quote_region`;
|
||||||
|
DROP TABLE IF EXISTS `ec_express_quote_version`;
|
||||||
|
DROP TABLE IF EXISTS `ec_express_quote`;
|
||||||
|
DROP TABLE IF EXISTS `ec_express_carrier_alias`;
|
||||||
|
DROP TABLE IF EXISTS `ec_warehouse`;
|
||||||
|
|
||||||
|
CREATE TABLE `ec_warehouse` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '仓库ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库编码(公司内唯一)',
|
||||||
|
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库名称',
|
||||||
|
`province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货省',
|
||||||
|
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货市',
|
||||||
|
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货地址',
|
||||||
|
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_warehouse_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_company`(`company_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_status`(`status` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-发货仓库(无库存)';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- 快递报价单(公司级;不属单一仓)
|
||||||
|
-- billing_mode: FLAT / PER_KG / REGION_WEIGHT
|
||||||
|
-- ----------------------------
|
||||||
|
CREATE TABLE `ec_express_quote` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '报价单ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价编码(公司内唯一)',
|
||||||
|
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价名称',
|
||||||
|
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '承运商软编码:ZTO/YTO/STO/YD/SF/JT/EMS/OTHER',
|
||||||
|
`billing_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'FLAT/PER_KG/REGION_WEIGHT',
|
||||||
|
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_quote_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_company`(`company_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_carrier`(`carrier_code` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价单';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- 报价版本(as-of;调价追加)
|
||||||
|
-- unit_scope: ORDER|PIECE(仅 FLAT)
|
||||||
|
-- ----------------------------
|
||||||
|
CREATE TABLE `ec_express_quote_version` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '版本ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||||
|
`effective_from` date NOT NULL COMMENT '生效起始日(含)',
|
||||||
|
`flat_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FLAT 一口价',
|
||||||
|
`unit_scope` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'FLAT:ORDER|PIECE',
|
||||||
|
`price_per_kg` decimal(10, 4) NULL DEFAULT NULL COMMENT 'PER_KG 单价',
|
||||||
|
`min_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'PER_KG 最低消费',
|
||||||
|
`volume_divisor` int UNSIGNED NULL DEFAULT 6000 COMMENT '计泡除数(cm 公式):体积重克=ceil(长*宽*高mm / divisor),如 6000/8000',
|
||||||
|
`use_volumetric` tinyint NOT NULL DEFAULT 0 COMMENT '是否启用体积重:0否 1是(计费重=max实重,体积重)',
|
||||||
|
`weight_round` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'NONE' COMMENT '计费重取整:NONE/CEIL_KG',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '调价说明',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_quote_version_from`(`quote_id` ASC, `effective_from` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_version_company`(`company_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价版本';
|
||||||
|
|
||||||
|
CREATE TABLE `ec_express_quote_region` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '分区ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||||
|
`region_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分区名(如二类/江浙沪)',
|
||||||
|
`zone_label` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '价区标签:一类/二类…(展示用)',
|
||||||
|
`provinces_json` json NOT NULL COMMENT '目的地列表 JSON(省全称或市名,如深圳市)',
|
||||||
|
`is_default` tinyint NOT NULL DEFAULT 0 COMMENT '是否默认分区(未命中时回落)',
|
||||||
|
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_region_version`(`version_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_region_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_region_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价目的分区';
|
||||||
|
|
||||||
|
-- 重量带:一分区多行;FLAT_TICKET=元/票;FIRST_PLUS_KG=首重价+续重元/kg(续重按 kg 向上取整段)
|
||||||
|
CREATE TABLE `ec_express_quote_band` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '重量带ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||||
|
`region_id` bigint UNSIGNED NOT NULL COMMENT '分区ID',
|
||||||
|
`weight_from_g` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '计费重下限(克,含)',
|
||||||
|
`weight_to_g` int UNSIGNED NULL DEFAULT NULL COMMENT '计费重上限(克,含);NULL=无上限',
|
||||||
|
`price_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'FLAT_TICKET/FIRST_PLUS_KG',
|
||||||
|
`flat_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FLAT_TICKET 元/票',
|
||||||
|
`first_weight_g` int UNSIGNED NULL DEFAULT NULL COMMENT 'FIRST_PLUS_KG 首重克数(可为0)',
|
||||||
|
`first_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FIRST_PLUS_KG 首重价',
|
||||||
|
`continue_per_kg` decimal(10, 4) NULL DEFAULT NULL COMMENT 'FIRST_PLUS_KG 续重元/kg',
|
||||||
|
`sort_order` int NOT NULL DEFAULT 0 COMMENT '同区分带排序',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_band_region`(`region_id` ASC, `weight_from_g` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_band_version`(`version_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_band_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_band_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_band_region` FOREIGN KEY (`region_id`) REFERENCES `ec_express_quote_region` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价重量带';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- 仓 ↔ 报价多对多绑定
|
||||||
|
-- ----------------------------
|
||||||
|
CREATE TABLE `ec_warehouse_express_bind` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '绑定ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`warehouse_id` bigint UNSIGNED NOT NULL COMMENT '仓库ID',
|
||||||
|
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||||
|
`priority` int NOT NULL DEFAULT 100 COMMENT '仓内选价优先级(小优先)',
|
||||||
|
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_warehouse_express_bind`(`warehouse_id` ASC, `quote_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_express_bind_company`(`company_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_express_bind_priority`(`warehouse_id` ASC, `priority` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-仓库快递报价绑定';
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- 订单 logistics_id → carrier_code 映射(公司可覆盖;company_id NULL=全局)
|
||||||
|
-- ----------------------------
|
||||||
|
CREATE TABLE `ec_express_carrier_alias` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||||
|
`company_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '公司ID;空=全局默认',
|
||||||
|
`logistics_pattern` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '物流标识/名称(精确匹配,大小写不敏感)',
|
||||||
|
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '归一承运商编码',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_carrier_alias`(`company_id` ASC, `logistics_pattern` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_carrier_alias_carrier`(`carrier_code` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_carrier_alias_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-物流标识到承运商映射';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
-- SKU 单件实重(克):对齐拼多多 weight;为后续按重算快递费预留
|
||||||
|
|
||||||
|
ALTER TABLE `ec_product_sku`
|
||||||
|
ADD COLUMN `weight_g` int UNSIGNED NULL DEFAULT NULL COMMENT '单件实重(克);NULL=未填;快递计费 / 平台同步用'
|
||||||
|
AFTER `barcode`;
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
-- 仓库发货 + 快递报价(无进销存)+ SKU 默认仓/体积尺寸 + 菜单权限
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_warehouse` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '仓库ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库编码(公司内唯一)',
|
||||||
|
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '仓库名称',
|
||||||
|
`province` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货省',
|
||||||
|
`city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货市',
|
||||||
|
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '发货地址',
|
||||||
|
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_warehouse_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_company`(`company_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_status`(`status` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-发货仓库(无库存)';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_express_quote` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '报价单ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价编码(公司内唯一)',
|
||||||
|
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '报价名称',
|
||||||
|
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '承运商软编码',
|
||||||
|
`billing_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'FLAT/PER_KG/REGION_WEIGHT',
|
||||||
|
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_quote_company_code`(`company_id` ASC, `code` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_company`(`company_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_carrier`(`carrier_code` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价单';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_express_quote_version` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '版本ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||||
|
`effective_from` date NOT NULL COMMENT '生效起始日(含)',
|
||||||
|
`flat_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FLAT 一口价',
|
||||||
|
`unit_scope` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'FLAT:ORDER|PIECE',
|
||||||
|
`price_per_kg` decimal(10, 4) NULL DEFAULT NULL COMMENT 'PER_KG 单价',
|
||||||
|
`min_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'PER_KG 最低消费',
|
||||||
|
`volume_divisor` int UNSIGNED NULL DEFAULT 6000 COMMENT '体积重除数',
|
||||||
|
`use_volumetric` tinyint NOT NULL DEFAULT 0 COMMENT '是否启用体积重',
|
||||||
|
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '调价说明',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_quote_version_from`(`quote_id` ASC, `effective_from` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_version_company`(`company_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_version_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价版本';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_express_quote_region` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '分区ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||||
|
`region_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '分区名',
|
||||||
|
`provinces_json` json NOT NULL COMMENT '省份全称列表 JSON',
|
||||||
|
`is_default` tinyint NOT NULL DEFAULT 0 COMMENT '是否默认分区',
|
||||||
|
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_region_version`(`version_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_region_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_region_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价分区';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_express_quote_tier` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '阶梯ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||||
|
`region_id` bigint UNSIGNED NOT NULL COMMENT '分区ID',
|
||||||
|
`first_weight_g` int UNSIGNED NOT NULL DEFAULT 1000 COMMENT '首重(克)',
|
||||||
|
`first_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '首重价格',
|
||||||
|
`additional_weight_g` int UNSIGNED NOT NULL DEFAULT 1000 COMMENT '续重步进(克)',
|
||||||
|
`additional_amount` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '续重价格',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_quote_tier_region`(`region_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_tier_version`(`version_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_tier_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_tier_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_tier_region` FOREIGN KEY (`region_id`) REFERENCES `ec_express_quote_region` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价首重续重';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_warehouse_express_bind` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '绑定ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`warehouse_id` bigint UNSIGNED NOT NULL COMMENT '仓库ID',
|
||||||
|
`quote_id` bigint UNSIGNED NOT NULL COMMENT '报价单ID',
|
||||||
|
`priority` int NOT NULL DEFAULT 100 COMMENT '仓内选价优先级(小优先)',
|
||||||
|
`status` tinyint NOT NULL DEFAULT 1 COMMENT '状态:0停用 1启用',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
`create_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '创建人ID',
|
||||||
|
`update_by` bigint UNSIGNED NULL DEFAULT NULL COMMENT '更新人ID',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_warehouse_express_bind`(`warehouse_id` ASC, `quote_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_express_bind_company`(`company_id` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_warehouse_express_bind_priority`(`warehouse_id` ASC, `priority` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_wh` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_quote` FOREIGN KEY (`quote_id`) REFERENCES `ec_express_quote` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_warehouse_express_bind_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-仓库快递报价绑定';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_express_carrier_alias` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||||
|
`company_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '公司ID;空=全局默认',
|
||||||
|
`logistics_pattern` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '物流标识/名称',
|
||||||
|
`carrier_code` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '归一承运商编码',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
UNIQUE INDEX `uk_ec_express_carrier_alias`(`company_id` ASC, `logistics_pattern` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_carrier_alias_carrier`(`carrier_code` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_carrier_alias_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-物流标识到承运商映射';
|
||||||
|
|
||||||
|
-- 全局默认承运商别名(常见)
|
||||||
|
INSERT IGNORE INTO `ec_express_carrier_alias` (`company_id`, `logistics_pattern`, `carrier_code`) VALUES
|
||||||
|
(NULL, 'ZTO', 'ZTO'), (NULL, '中通', 'ZTO'), (NULL, '中通快递', 'ZTO'),
|
||||||
|
(NULL, 'YTO', 'YTO'), (NULL, '圆通', 'YTO'), (NULL, '圆通速递', 'YTO'),
|
||||||
|
(NULL, 'STO', 'STO'), (NULL, '申通', 'STO'), (NULL, '申通快递', 'STO'),
|
||||||
|
(NULL, 'YD', 'YD'), (NULL, '韵达', 'YD'), (NULL, '韵达快递', 'YD'),
|
||||||
|
(NULL, 'SF', 'SF'), (NULL, '顺丰', 'SF'), (NULL, '顺丰速运', 'SF'),
|
||||||
|
(NULL, 'JT', 'JT'), (NULL, '极兔', 'JT'), (NULL, '极兔速递', 'JT'),
|
||||||
|
(NULL, 'EMS', 'EMS'), (NULL, '邮政', 'EMS'), (NULL, '邮政快递', 'EMS');
|
||||||
|
|
||||||
|
-- SKU:默认仓 + 体积尺寸(weight_g 已在 V20261021)
|
||||||
|
ALTER TABLE `ec_product_sku`
|
||||||
|
ADD COLUMN `length_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '长(mm)' AFTER `weight_g`,
|
||||||
|
ADD COLUMN `width_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '宽(mm)' AFTER `length_mm`,
|
||||||
|
ADD COLUMN `height_mm` int UNSIGNED NULL DEFAULT NULL COMMENT '高(mm)' AFTER `width_mm`,
|
||||||
|
ADD COLUMN `warehouse_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '默认发货仓' AFTER `height_mm`,
|
||||||
|
ADD INDEX `idx_ec_product_sku_warehouse` (`warehouse_id`),
|
||||||
|
ADD CONSTRAINT `fk_ec_product_sku_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `ec_warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- 权限
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3390, (SELECT id FROM `sys_permission` WHERE `code` = 'ec' LIMIT 1), 'ec:warehouse', '发货仓库', 'module', 1, '', 46
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3390 OR `code` = 'ec:warehouse');
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3391, 3390, 'ec:warehouse:read', '查看', 'api', 1, '', 1
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3391 OR `code` = 'ec:warehouse:read');
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3392, 3390, 'ec:warehouse:create', '创建', 'api', 1, '', 2
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3392 OR `code` = 'ec:warehouse:create');
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3393, 3390, 'ec:warehouse:update', '更新', 'api', 1, '', 3
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3393 OR `code` = 'ec:warehouse:update');
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3394, 3390, 'ec:warehouse:delete', '删除', 'api', 1, '', 4
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3394 OR `code` = 'ec:warehouse:delete');
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3400, (SELECT id FROM `sys_permission` WHERE `code` = 'ec' LIMIT 1), 'ec:express-quote', '快递报价', 'module', 1, '', 47
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3400 OR `code` = 'ec:express-quote');
|
||||||
|
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3401, 3400, 'ec:express-quote:read', '查看', 'api', 1, '', 1
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3401 OR `code` = 'ec:express-quote:read');
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3402, 3400, 'ec:express-quote:create', '创建', 'api', 1, '', 2
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3402 OR `code` = 'ec:express-quote:create');
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3403, 3400, 'ec:express-quote:update', '更新', 'api', 1, '', 3
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3403 OR `code` = 'ec:express-quote:update');
|
||||||
|
INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`)
|
||||||
|
SELECT 3404, 3400, 'ec:express-quote:delete', '删除', 'api', 1, '', 4
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `id` = 3404 OR `code` = 'ec:express-quote:delete');
|
||||||
|
|
||||||
|
-- 菜单挂「经营店铺」
|
||||||
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
|
SELECT 14020, (SELECT id FROM `sys_menu` WHERE `id` = 7 OR `title` = '经营店铺' OR `route_name` = 'ShopCatalog' LIMIT 1), 0,
|
||||||
|
'WarehouseManagement', '发货仓库', '/ec/warehouse/list', '/ec/warehouse/list/index', '', 'lucide:warehouse', 'menu', 1, 1, 1, 6
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14020 OR `route_name` = 'WarehouseManagement');
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
|
SELECT 14021, (SELECT id FROM `sys_menu` WHERE `id` = 7 OR `title` = '经营店铺' OR `route_name` = 'ShopCatalog' LIMIT 1), 0,
|
||||||
|
'ExpressQuoteManagement', '快递报价', '/ec/warehouse/express-quote', '/ec/warehouse/express-quote/index', '', 'lucide:truck', 'menu', 1, 1, 1, 7
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14021 OR `route_name` = 'ExpressQuoteManagement');
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||||
|
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'ec:warehouse:%'
|
||||||
|
WHERE m.route_name = 'WarehouseManagement' OR m.id = 14020;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||||
|
SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'ec:express-quote:%'
|
||||||
|
WHERE m.route_name = 'ExpressQuoteManagement' OR m.id = 14021;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, 14020, 1 FROM `org_company_menu` cm WHERE cm.`menu_id` IN (7, 14010);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, 14021, 1 FROM `org_company_menu` cm WHERE cm.`menu_id` IN (7, 14010);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_company_permission` (`company_id`, `permission_id`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, p.`id`
|
||||||
|
FROM `org_company_menu` cm
|
||||||
|
JOIN `sys_permission` p ON p.`code` LIKE 'ec:warehouse:%' OR p.`code` LIKE 'ec:express-quote:%'
|
||||||
|
WHERE cm.`menu_id` IN (7, 14010, 14020, 14021);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||||
|
SELECT pm.`position_id`, 14020 FROM `org_position_menu` pm WHERE pm.`menu_id` = 14010;
|
||||||
|
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||||
|
SELECT pm.`position_id`, 14021 FROM `org_position_menu` pm WHERE pm.`menu_id` = 14010;
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_position_permission` (`position_id`, `permission_id`)
|
||||||
|
SELECT DISTINCT pp.`position_id`, p.`id`
|
||||||
|
FROM `org_position_permission` pp
|
||||||
|
JOIN `sys_permission` shop ON shop.`id` = pp.`permission_id` AND shop.`code` LIKE 'ec:shop:%'
|
||||||
|
JOIN `sys_permission` p ON p.`code` LIKE 'ec:warehouse:%' OR p.`code` LIKE 'ec:express-quote:%';
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
-- 报价:单区单条首重续重 → 目的分区 × 多重量带(对齐承运商矩阵报价单)
|
||||||
|
|
||||||
|
-- 1) version 增加计费重取整
|
||||||
|
ALTER TABLE `ec_express_quote_version`
|
||||||
|
ADD COLUMN `weight_round` varchar(16) NOT NULL DEFAULT 'NONE' COMMENT '计费重取整:NONE/CEIL_KG'
|
||||||
|
AFTER `use_volumetric`;
|
||||||
|
|
||||||
|
-- 2) region 增加价区标签
|
||||||
|
ALTER TABLE `ec_express_quote_region`
|
||||||
|
ADD COLUMN `zone_label` varchar(32) NULL DEFAULT NULL COMMENT '价区标签:一类/二类…'
|
||||||
|
AFTER `region_name`;
|
||||||
|
|
||||||
|
ALTER TABLE `ec_express_quote_region`
|
||||||
|
MODIFY COLUMN `provinces_json` json NOT NULL COMMENT '目的地列表 JSON(省全称或市名)';
|
||||||
|
|
||||||
|
-- 3) 新建重量带表
|
||||||
|
CREATE TABLE IF NOT EXISTS `ec_express_quote_band` (
|
||||||
|
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '重量带ID',
|
||||||
|
`company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID',
|
||||||
|
`version_id` bigint UNSIGNED NOT NULL COMMENT '报价版本ID',
|
||||||
|
`region_id` bigint UNSIGNED NOT NULL COMMENT '分区ID',
|
||||||
|
`weight_from_g` int UNSIGNED NOT NULL DEFAULT 0 COMMENT '计费重下限(克,含)',
|
||||||
|
`weight_to_g` int UNSIGNED NULL DEFAULT NULL COMMENT '计费重上限(克,含);NULL=无上限',
|
||||||
|
`price_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'FLAT_TICKET/FIRST_PLUS_KG',
|
||||||
|
`flat_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FLAT_TICKET 元/票',
|
||||||
|
`first_weight_g` int UNSIGNED NULL DEFAULT NULL COMMENT 'FIRST_PLUS_KG 首重克数',
|
||||||
|
`first_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT 'FIRST_PLUS_KG 首重价',
|
||||||
|
`continue_per_kg` decimal(10, 4) NULL DEFAULT NULL COMMENT 'FIRST_PLUS_KG 续重元/kg',
|
||||||
|
`sort_order` int NOT NULL DEFAULT 0 COMMENT '同区分带排序',
|
||||||
|
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||||
|
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_band_region`(`region_id` ASC, `weight_from_g` ASC) USING BTREE,
|
||||||
|
INDEX `idx_ec_express_quote_band_version`(`version_id` ASC) USING BTREE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_band_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_band_version` FOREIGN KEY (`version_id`) REFERENCES `ec_express_quote_version` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
|
CONSTRAINT `fk_ec_express_quote_band_region` FOREIGN KEY (`region_id`) REFERENCES `ec_express_quote_region` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '电商-快递报价重量带';
|
||||||
|
|
||||||
|
-- 4) 迁移旧 tier → 一条开区间 FIRST_PLUS_KG band
|
||||||
|
INSERT INTO `ec_express_quote_band` (
|
||||||
|
`company_id`, `version_id`, `region_id`,
|
||||||
|
`weight_from_g`, `weight_to_g`, `price_mode`,
|
||||||
|
`first_weight_g`, `first_amount`, `continue_per_kg`, `sort_order`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
t.`company_id`, t.`version_id`, t.`region_id`,
|
||||||
|
0, NULL, 'FIRST_PLUS_KG',
|
||||||
|
IFNULL(t.`first_weight_g`, 1000),
|
||||||
|
IFNULL(t.`first_amount`, 0),
|
||||||
|
CASE
|
||||||
|
WHEN IFNULL(t.`additional_weight_g`, 0) > 0
|
||||||
|
THEN ROUND(IFNULL(t.`additional_amount`, 0) * 1000 / t.`additional_weight_g`, 4)
|
||||||
|
ELSE IFNULL(t.`additional_amount`, 0)
|
||||||
|
END,
|
||||||
|
0
|
||||||
|
FROM `ec_express_quote_tier` t
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM `ec_express_quote_band` b WHERE b.`region_id` = t.`region_id`
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 5) 删除旧 tier
|
||||||
|
DROP TABLE IF EXISTS `ec_express_quote_tier`;
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
-- 快递报价编辑页:后端动态路由(embedded,不进侧栏)
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (
|
||||||
|
`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`,
|
||||||
|
`redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
14022,
|
||||||
|
(SELECT id FROM `sys_menu` WHERE `id` = 7 OR `title` = '经营店铺' OR `route_name` = 'ShopCatalog' LIMIT 1),
|
||||||
|
0,
|
||||||
|
'ExpressQuoteEdit',
|
||||||
|
'快递报价单编辑',
|
||||||
|
'/ec/warehouse/express-quote/edit/:id?',
|
||||||
|
'/ec/warehouse/express-quote/edit/index',
|
||||||
|
'',
|
||||||
|
'lucide:file-pen-line',
|
||||||
|
'embedded',
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
8
|
||||||
|
FROM DUAL
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM `sys_menu` WHERE `id` = 14022 OR `route_name` = 'ExpressQuoteEdit'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 菜单权限:读写创建更新(打开编辑页)
|
||||||
|
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||||
|
SELECT m.id, p.id
|
||||||
|
FROM `sys_menu` m
|
||||||
|
JOIN `sys_permission` p ON p.code IN (
|
||||||
|
'ec:express-quote:read',
|
||||||
|
'ec:express-quote:create',
|
||||||
|
'ec:express-quote:update'
|
||||||
|
)
|
||||||
|
WHERE m.route_name = 'ExpressQuoteEdit' OR m.id = 14022;
|
||||||
|
|
||||||
|
-- 已开通快递报价列表的公司同步开通编辑页
|
||||||
|
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, 14022, 1
|
||||||
|
FROM `org_company_menu` cm
|
||||||
|
WHERE cm.`menu_id` = 14021;
|
||||||
|
|
||||||
|
-- 已有快递报价菜单的岗位同步开通
|
||||||
|
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||||
|
SELECT pm.`position_id`, 14022
|
||||||
|
FROM `org_position_menu` pm
|
||||||
|
WHERE pm.`menu_id` = 14021;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
-- 发货仓库 / 快递报价从「经营店铺」拆到一级目录「发货物流」
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (
|
||||||
|
`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`,
|
||||||
|
`redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
14019,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
'FreightCatalog',
|
||||||
|
'发货物流',
|
||||||
|
'/freight',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'lucide:truck',
|
||||||
|
'catalog',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
6
|
||||||
|
FROM DUAL
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM `sys_menu` WHERE `id` = 14019 OR `route_name` = 'FreightCatalog'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 子菜单改挂到发货物流(含编辑页 embedded)
|
||||||
|
UPDATE `sys_menu`
|
||||||
|
SET `parent_id` = 14019
|
||||||
|
WHERE `id` IN (14020, 14021, 14022)
|
||||||
|
OR `route_name` IN (
|
||||||
|
'WarehouseManagement',
|
||||||
|
'ExpressQuoteManagement',
|
||||||
|
'ExpressQuoteEdit'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 已开通仓/报价子菜单的公司补挂父目录,避免侧栏断树
|
||||||
|
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, 14019, 1
|
||||||
|
FROM `org_company_menu` cm
|
||||||
|
WHERE cm.`menu_id` IN (14020, 14021, 14022);
|
||||||
|
|
||||||
|
-- 已有子菜单的岗位补挂父目录
|
||||||
|
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||||
|
SELECT DISTINCT pm.`position_id`, 14019
|
||||||
|
FROM `org_position_menu` pm
|
||||||
|
WHERE pm.`menu_id` IN (14020, 14021, 14022);
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
-- 发货物流:发货仓商品(仓×SKU 默认分配)
|
||||||
|
|
||||||
|
-- 侧栏顺序:发货仓库 → 发货仓商品 → 快递报价
|
||||||
|
UPDATE `sys_menu` SET `order` = 1 WHERE `id` = 14020 OR `route_name` = 'WarehouseManagement';
|
||||||
|
UPDATE `sys_menu` SET `order` = 3 WHERE `id` = 14021 OR `route_name` = 'ExpressQuoteManagement';
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (
|
||||||
|
`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`,
|
||||||
|
`redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
14023,
|
||||||
|
(SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `route_name` = 'FreightCatalog' LIMIT 1),
|
||||||
|
0,
|
||||||
|
'WarehouseSkuManagement',
|
||||||
|
'发货仓商品',
|
||||||
|
'/ec/warehouse/sku',
|
||||||
|
'/ec/warehouse/sku/index',
|
||||||
|
'',
|
||||||
|
'lucide:boxes',
|
||||||
|
'menu',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
2
|
||||||
|
FROM DUAL
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM `sys_menu` WHERE `id` = 14023 OR `route_name` = 'WarehouseSkuManagement'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 复用发货仓库读写权限
|
||||||
|
INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`)
|
||||||
|
SELECT m.id, p.id
|
||||||
|
FROM `sys_menu` m
|
||||||
|
JOIN `sys_permission` p ON p.code IN ('ec:warehouse:read', 'ec:warehouse:update')
|
||||||
|
WHERE m.route_name = 'WarehouseSkuManagement' OR m.id = 14023;
|
||||||
|
|
||||||
|
-- 已开通发货物流或发货仓库的公司同步开通
|
||||||
|
INSERT IGNORE INTO `org_company_menu` (`company_id`, `menu_id`, `status`)
|
||||||
|
SELECT DISTINCT cm.`company_id`, 14023, 1
|
||||||
|
FROM `org_company_menu` cm
|
||||||
|
WHERE cm.`menu_id` IN (14019, 14020);
|
||||||
|
|
||||||
|
INSERT IGNORE INTO `org_position_menu` (`position_id`, `menu_id`)
|
||||||
|
SELECT DISTINCT pm.`position_id`, 14023
|
||||||
|
FROM `org_position_menu` pm
|
||||||
|
WHERE pm.`menu_id` IN (14019, 14020);
|
||||||
+2
@@ -21,6 +21,8 @@ public class BiOrderStatDirtyDayPO {
|
|||||||
|
|
||||||
public static final String REASON_COST = "COST";
|
public static final String REASON_COST = "COST";
|
||||||
public static final String REASON_PRODUCT_DIM = "PRODUCT_DIM";
|
public static final String REASON_PRODUCT_DIM = "PRODUCT_DIM";
|
||||||
|
/** 仓库快递报价 / 默认仓 / 计费重变更 */
|
||||||
|
public static final String REASON_FREIGHT = "FREIGHT";
|
||||||
|
|
||||||
@TableId(value = "id", type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|||||||
+13
@@ -67,6 +67,19 @@ public class BiOrderStatDirtyDayService {
|
|||||||
Map.of("type", "COST_ADJUST", "skuId", skuId, "userId", userId != null ? userId : 0));
|
Map.of("type", "COST_ADJUST", "skuId", skuId, "userId", userId != null ? userId : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 快递报价/默认仓/计费重变更:effectiveFrom~today 涉及该 SKU 的 (shop, day)。 */
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void markAfterFreightQuoteChange(Long companyId, Long skuId, LocalDate effectiveFrom, Long userId) {
|
||||||
|
if (companyId == null || skuId == null || effectiveFrom == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LocalDate today = LocalDate.now(ZONE);
|
||||||
|
LocalDate dateFrom = effectiveFrom.isAfter(today) ? today : effectiveFrom;
|
||||||
|
markForSkuDateRange(companyId, skuId, dateFrom, today,
|
||||||
|
BiOrderStatDirtyDayPO.REASON_FREIGHT,
|
||||||
|
Map.of("type", "FREIGHT_QUOTE", "skuId", skuId, "userId", userId != null ? userId : 0));
|
||||||
|
}
|
||||||
|
|
||||||
/** SKU 迁品:effectiveFrom~today(最早下单日或 today)涉及该 SKU 的 (shop, day)。 */
|
/** SKU 迁品:effectiveFrom~today(最早下单日或 today)涉及该 SKU 的 (shop, day)。 */
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void markAfterSkuMigrate(Long companyId, Long skuId, Long userId) {
|
public void markAfterSkuMigrate(Long companyId, Long skuId, Long userId) {
|
||||||
|
|||||||
+4
-1
@@ -214,6 +214,7 @@ public class OrderDailyStatComputeService {
|
|||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Map<Long, BigDecimal> freightByItem = orderItemCostResolver.freightByItemForOrder(order, items, stat);
|
||||||
for (OrderItemPO item : items) {
|
for (OrderItemPO item : items) {
|
||||||
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||||
long productId = productBySku.getOrDefault(skuId, 0L);
|
long productId = productBySku.getOrDefault(skuId, 0L);
|
||||||
@@ -221,7 +222,9 @@ public class OrderDailyStatComputeService {
|
|||||||
BigDecimal lineReceived = allocateLine(received, item, items);
|
BigDecimal lineReceived = allocateLine(received, item, items);
|
||||||
BigDecimal lineFee = deal ? allocateLine(fee, item, items) : BigDecimal.ZERO;
|
BigDecimal lineFee = deal ? allocateLine(fee, item, items) : BigDecimal.ZERO;
|
||||||
BigDecimal linePc = lineProductCost(order, item, stat, unitCostBySku);
|
BigDecimal linePc = lineProductCost(order, item, stat, unitCostBySku);
|
||||||
BigDecimal lineFc = lineFreightCost(order, item, stat, unitCostBySku);
|
BigDecimal lineFc = item.getId() != null
|
||||||
|
? freightByItem.getOrDefault(item.getId(), BigDecimal.ZERO)
|
||||||
|
: lineFreightCost(order, item, stat, unitCostBySku);
|
||||||
BigDecimal lineOc = lineOtherCost(order, item, stat, unitCostBySku);
|
BigDecimal lineOc = lineOtherCost(order, item, stat, unitCostBySku);
|
||||||
|
|
||||||
String pk = companyId + ":" + shopId + ":" + productId;
|
String pk = companyId + ":" + shopId + ":" + productId;
|
||||||
|
|||||||
+22
-4
@@ -7,23 +7,26 @@ import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
|||||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusStatSets;
|
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusStatSets;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.model.po.ProductSkuCostPO;
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.model.po.ProductSkuCostPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.ProductSkuCostService;
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.ProductSkuCostService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.FreightCostCalculator;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订单明细成本:按 order_time 自然日从 SKU 成本主数据 as-of 解析,不读 ec_order_item 快照。
|
* 订单明细成本:商品/其他 as-of 读 SKU 成本;运费优先按仓报价整包分摊,失败回退 shipping_cost。
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OrderItemCostResolver {
|
public class OrderItemCostResolver {
|
||||||
|
|
||||||
private final ProductSkuCostService productSkuCostService;
|
private final ProductSkuCostService productSkuCostService;
|
||||||
|
private final FreightCostCalculator freightCostCalculator;
|
||||||
|
|
||||||
/** 单笔订单行:按订单日取 SKU 成本。 */
|
/** 单笔订单行:按订单日取 SKU 成本(不含算出运费)。 */
|
||||||
public UnitCosts resolveUnitCosts(OrderPO order, OrderItemPO item) {
|
public UnitCosts resolveUnitCosts(OrderPO order, OrderItemPO item) {
|
||||||
LocalDate orderDate = order != null && order.getOrderTime() != null
|
LocalDate orderDate = order != null && order.getOrderTime() != null
|
||||||
? order.getOrderTime().toLocalDate()
|
? order.getOrderTime().toLocalDate()
|
||||||
@@ -60,12 +63,27 @@ public class OrderItemCostResolver {
|
|||||||
return c.productCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
return c.productCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单行运费(会为整单再算一遍分摊;批算请用 {@link #freightByItemForOrder})。
|
||||||
|
*/
|
||||||
public BigDecimal freightCostForStats(OrderPO order, OrderItemPO item, OrderStatusStatSets stat) {
|
public BigDecimal freightCostForStats(OrderPO order, OrderItemPO item, OrderStatusStatSets stat) {
|
||||||
if (!stat.includesFreightCost(order.getStatus())) {
|
if (!stat.includesFreightCost(order.getStatus())) {
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
}
|
}
|
||||||
UnitCosts c = resolveUnitCosts(order, item);
|
if (item == null || item.getId() == null) {
|
||||||
return c.shippingCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
UnitCosts c = resolveUnitCosts(order, item);
|
||||||
|
return c.shippingCost().multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item)));
|
||||||
|
}
|
||||||
|
Map<Long, BigDecimal> map = freightCostCalculator.allocateFreight(order, List.of(item));
|
||||||
|
return map.getOrDefault(item.getId(), BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 整单运费分摊:itemId → 金额。 */
|
||||||
|
public Map<Long, BigDecimal> freightByItemForOrder(OrderPO order, List<OrderItemPO> items, OrderStatusStatSets stat) {
|
||||||
|
if (order == null || !stat.includesFreightCost(order.getStatus())) {
|
||||||
|
return Map.of();
|
||||||
|
}
|
||||||
|
return freightCostCalculator.allocateFreight(order, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal otherCostForStats(OrderPO order, OrderItemPO item, OrderStatusStatSets stat) {
|
public BigDecimal otherCostForStats(OrderPO order, OrderItemPO item, OrderStatusStatSets stat) {
|
||||||
|
|||||||
+4
-1
@@ -73,6 +73,7 @@ public class OrderStatContributionCalculator {
|
|||||||
Map<String, long[]> skuKeys = new HashMap<>();
|
Map<String, long[]> skuKeys = new HashMap<>();
|
||||||
|
|
||||||
Map<Long, Long> productBySku = loadProductBySku(safeItems);
|
Map<Long, Long> productBySku = loadProductBySku(safeItems);
|
||||||
|
Map<Long, BigDecimal> freightByItem = orderItemCostResolver.freightByItemForOrder(order, safeItems, stat);
|
||||||
|
|
||||||
for (OrderItemPO item : safeItems) {
|
for (OrderItemPO item : safeItems) {
|
||||||
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||||
@@ -94,7 +95,9 @@ public class OrderStatContributionCalculator {
|
|||||||
pm.setRefundQuantitySum(nzi(pm.getRefundQuantitySum()) + qty);
|
pm.setRefundQuantitySum(nzi(pm.getRefundQuantitySum()) + qty);
|
||||||
}
|
}
|
||||||
BigDecimal pc = orderItemCostResolver.productCostForStats(order, item, stat);
|
BigDecimal pc = orderItemCostResolver.productCostForStats(order, item, stat);
|
||||||
BigDecimal fc = orderItemCostResolver.freightCostForStats(order, item, stat);
|
BigDecimal fc = item.getId() != null
|
||||||
|
? freightByItem.getOrDefault(item.getId(), BigDecimal.ZERO)
|
||||||
|
: orderItemCostResolver.freightCostForStats(order, item, stat);
|
||||||
BigDecimal oc = orderItemCostResolver.otherCostForStats(order, item, stat);
|
BigDecimal oc = orderItemCostResolver.otherCostForStats(order, item, stat);
|
||||||
pm.setProductCost(nz(pm.getProductCost()).add(pc));
|
pm.setProductCost(nz(pm.getProductCost()).add(pc));
|
||||||
pm.setFreightCost(nz(pm.getFreightCost()).add(fc));
|
pm.setFreightCost(nz(pm.getFreightCost()).add(fc));
|
||||||
|
|||||||
+12
@@ -1,6 +1,8 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.product.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.ec.product.model.dto;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -41,6 +43,16 @@ public class CreateProductDTO {
|
|||||||
@NotBlank(message = "SKU编码不能为空")
|
@NotBlank(message = "SKU编码不能为空")
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
@Min(value = 1, message = "重量至少为 1 克")
|
||||||
|
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
|
private Integer lengthMm;
|
||||||
|
private Integer widthMm;
|
||||||
|
private Integer heightMm;
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
@NotNull(message = "商品成本不能为空")
|
@NotNull(message = "商品成本不能为空")
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
|
|||||||
+12
@@ -1,6 +1,8 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.product.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.ec.product.model.dto;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -49,6 +51,16 @@ public class UpdateProductDTO {
|
|||||||
@NotBlank(message = "SKU编码不能为空")
|
@NotBlank(message = "SKU编码不能为空")
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
@Min(value = 1, message = "重量至少为 1 克")
|
||||||
|
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
|
private Integer lengthMm;
|
||||||
|
private Integer widthMm;
|
||||||
|
private Integer heightMm;
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
@NotNull(message = "商品成本不能为空")
|
@NotNull(message = "商品成本不能为空")
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
|
|||||||
+20
@@ -137,6 +137,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
createDto.setProductId(product.getId());
|
createDto.setProductId(product.getId());
|
||||||
createDto.setName(specDTO.getName());
|
createDto.setName(specDTO.getName());
|
||||||
createDto.setSkuCode(specDTO.getSkuCode());
|
createDto.setSkuCode(specDTO.getSkuCode());
|
||||||
|
createDto.setWeightG(specDTO.getWeightG());
|
||||||
|
createDto.setLengthMm(specDTO.getLengthMm());
|
||||||
|
createDto.setWidthMm(specDTO.getWidthMm());
|
||||||
|
createDto.setHeightMm(specDTO.getHeightMm());
|
||||||
|
createDto.setWarehouseId(specDTO.getWarehouseId());
|
||||||
createDto.setProductCost(specDTO.getProductCost());
|
createDto.setProductCost(specDTO.getProductCost());
|
||||||
createDto.setShippingCost(specDTO.getShippingCost());
|
createDto.setShippingCost(specDTO.getShippingCost());
|
||||||
createDto.setOtherCost(specDTO.getOtherCost());
|
createDto.setOtherCost(specDTO.getOtherCost());
|
||||||
@@ -196,6 +201,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
createDto.setProductId(product.getId());
|
createDto.setProductId(product.getId());
|
||||||
createDto.setName(specDTO.getName());
|
createDto.setName(specDTO.getName());
|
||||||
createDto.setSkuCode(specDTO.getSkuCode());
|
createDto.setSkuCode(specDTO.getSkuCode());
|
||||||
|
createDto.setWeightG(specDTO.getWeightG());
|
||||||
|
createDto.setLengthMm(specDTO.getLengthMm());
|
||||||
|
createDto.setWidthMm(specDTO.getWidthMm());
|
||||||
|
createDto.setHeightMm(specDTO.getHeightMm());
|
||||||
|
createDto.setWarehouseId(specDTO.getWarehouseId());
|
||||||
createDto.setProductCost(specDTO.getProductCost() != null ? specDTO.getProductCost() : java.math.BigDecimal.ZERO);
|
createDto.setProductCost(specDTO.getProductCost() != null ? specDTO.getProductCost() : java.math.BigDecimal.ZERO);
|
||||||
createDto.setShippingCost(specDTO.getShippingCost());
|
createDto.setShippingCost(specDTO.getShippingCost());
|
||||||
createDto.setOtherCost(specDTO.getOtherCost());
|
createDto.setOtherCost(specDTO.getOtherCost());
|
||||||
@@ -327,6 +337,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
UpdateProductSkuDTO updateDto = new UpdateProductSkuDTO();
|
UpdateProductSkuDTO updateDto = new UpdateProductSkuDTO();
|
||||||
updateDto.setName(row.getName());
|
updateDto.setName(row.getName());
|
||||||
updateDto.setSkuCode(row.getSkuCode());
|
updateDto.setSkuCode(row.getSkuCode());
|
||||||
|
updateDto.setWeightG(row.getWeightG());
|
||||||
|
updateDto.setLengthMm(row.getLengthMm());
|
||||||
|
updateDto.setWidthMm(row.getWidthMm());
|
||||||
|
updateDto.setHeightMm(row.getHeightMm());
|
||||||
|
updateDto.setWarehouseId(row.getWarehouseId());
|
||||||
updateDto.setRemark(row.getRemark());
|
updateDto.setRemark(row.getRemark());
|
||||||
updateDto.setImageId(row.getImageId());
|
updateDto.setImageId(row.getImageId());
|
||||||
productSkuService.updateProductSku(updateDto, row.getId());
|
productSkuService.updateProductSku(updateDto, row.getId());
|
||||||
@@ -337,6 +352,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
createDto.setProductId(productId);
|
createDto.setProductId(productId);
|
||||||
createDto.setName(row.getName());
|
createDto.setName(row.getName());
|
||||||
createDto.setSkuCode(row.getSkuCode());
|
createDto.setSkuCode(row.getSkuCode());
|
||||||
|
createDto.setWeightG(row.getWeightG());
|
||||||
|
createDto.setLengthMm(row.getLengthMm());
|
||||||
|
createDto.setWidthMm(row.getWidthMm());
|
||||||
|
createDto.setHeightMm(row.getHeightMm());
|
||||||
|
createDto.setWarehouseId(row.getWarehouseId());
|
||||||
createDto.setProductCost(row.getProductCost());
|
createDto.setProductCost(row.getProductCost());
|
||||||
createDto.setShippingCost(row.getShippingCost());
|
createDto.setShippingCost(row.getShippingCost());
|
||||||
createDto.setOtherCost(row.getOtherCost());
|
createDto.setOtherCost(row.getOtherCost());
|
||||||
|
|||||||
+12
@@ -1,5 +1,7 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -20,6 +22,16 @@ public class CreateProductSkuDTO {
|
|||||||
|
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
@Min(value = 1, message = "重量至少为 1 克")
|
||||||
|
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
|
private Integer lengthMm;
|
||||||
|
private Integer widthMm;
|
||||||
|
private Integer heightMm;
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
@NotNull(message = "商品成本不能为空")
|
@NotNull(message = "商品成本不能为空")
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
|
|||||||
+6
@@ -21,4 +21,10 @@ public class ProductSkuFilterDTO {
|
|||||||
|
|
||||||
/** 模糊匹配:SKU 名称、SKU 编码、所属商品名称、商品编码 */
|
/** 模糊匹配:SKU 名称、SKU 编码、所属商品名称、商品编码 */
|
||||||
private String keywords;
|
private String keywords;
|
||||||
|
|
||||||
|
/** 默认发货仓;与 unassignedOnly 互斥(未分配优先) */
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
/** true = 仅未分配发货仓(warehouse_id IS NULL) */
|
||||||
|
private Boolean unassignedOnly;
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -1,5 +1,7 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -20,6 +22,16 @@ public class UpdateProductSkuDTO {
|
|||||||
|
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
|
/** 单件实重(克);空=未填/清空 */
|
||||||
|
@Min(value = 1, message = "重量至少为 1 克")
|
||||||
|
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
|
private Integer lengthMm;
|
||||||
|
private Integer widthMm;
|
||||||
|
private Integer heightMm;
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
private BigDecimal shippingCost;
|
private BigDecimal shippingCost;
|
||||||
|
|||||||
+17
@@ -32,6 +32,23 @@ public class ProductSkuPO {
|
|||||||
@TableField("barcode")
|
@TableField("barcode")
|
||||||
private String barcode;
|
private String barcode;
|
||||||
|
|
||||||
|
/** 单件实重(克);NULL=未填;更新时允许置空 */
|
||||||
|
@TableField(value = "weight_g", updateStrategy = FieldStrategy.ALWAYS)
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
|
@TableField(value = "length_mm", updateStrategy = FieldStrategy.ALWAYS)
|
||||||
|
private Integer lengthMm;
|
||||||
|
|
||||||
|
@TableField(value = "width_mm", updateStrategy = FieldStrategy.ALWAYS)
|
||||||
|
private Integer widthMm;
|
||||||
|
|
||||||
|
@TableField(value = "height_mm", updateStrategy = FieldStrategy.ALWAYS)
|
||||||
|
private Integer heightMm;
|
||||||
|
|
||||||
|
/** 默认发货仓;更新时允许置空 */
|
||||||
|
@TableField(value = "warehouse_id", updateStrategy = FieldStrategy.ALWAYS)
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
@TableField("attrs")
|
@TableField("attrs")
|
||||||
private String attrs;
|
private String attrs;
|
||||||
|
|
||||||
|
|||||||
+11
@@ -25,6 +25,17 @@ public class ProductSkuVO {
|
|||||||
|
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
|
private Integer lengthMm;
|
||||||
|
private Integer widthMm;
|
||||||
|
private Integer heightMm;
|
||||||
|
|
||||||
|
/** 默认发货仓 */
|
||||||
|
private Long warehouseId;
|
||||||
|
private String warehouseName;
|
||||||
|
|
||||||
/** 空=遗留无结构 SKU */
|
/** 空=遗留无结构 SKU */
|
||||||
private String specCombinationKey;
|
private String specCombinationKey;
|
||||||
|
|
||||||
|
|||||||
+28
-2
@@ -32,6 +32,8 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.impl.Produc
|
|||||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.service.ProductSkuService;
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.service.ProductSkuService;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.mapper.FakeOrdersFeeMapper;
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.mapper.FakeOrdersFeeMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.model.po.FakeOrdersFeePO;
|
import top.xyquan.ecomdmbbackend.modules.ec.shop.fakeordersfee.model.po.FakeOrdersFeePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
import top.xyquan.ecomdmbbackend.modules.sys.file.mapper.SysFileMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO;
|
||||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||||
@@ -60,13 +62,15 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
private final ProductSkuCostMapper productSkuCostMapper;
|
private final ProductSkuCostMapper productSkuCostMapper;
|
||||||
private final FakeOrdersFeeMapper fakeOrdersFeeMapper;
|
private final FakeOrdersFeeMapper fakeOrdersFeeMapper;
|
||||||
private final SysFileMapper sysFileMapper;
|
private final SysFileMapper sysFileMapper;
|
||||||
|
private final WarehouseMapper warehouseMapper;
|
||||||
|
|
||||||
public ProductSkuServiceImpl(CurrentUserContext currentUserContext, ProductService productService,
|
public ProductSkuServiceImpl(CurrentUserContext currentUserContext, ProductService productService,
|
||||||
ProductSkuCostService productSkuCostService, OrderMapper orderMapper,
|
ProductSkuCostService productSkuCostService, OrderMapper orderMapper,
|
||||||
OrderItemMapper orderItemMapper,
|
OrderItemMapper orderItemMapper,
|
||||||
ProductSkuCostMapper productSkuCostMapper,
|
ProductSkuCostMapper productSkuCostMapper,
|
||||||
FakeOrdersFeeMapper fakeOrdersFeeMapper,
|
FakeOrdersFeeMapper fakeOrdersFeeMapper,
|
||||||
SysFileMapper sysFileMapper) {
|
SysFileMapper sysFileMapper,
|
||||||
|
WarehouseMapper warehouseMapper) {
|
||||||
this.currentUserContext = currentUserContext;
|
this.currentUserContext = currentUserContext;
|
||||||
this.productService = productService;
|
this.productService = productService;
|
||||||
this.productSkuCostService = productSkuCostService;
|
this.productSkuCostService = productSkuCostService;
|
||||||
@@ -75,6 +79,7 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
this.productSkuCostMapper = productSkuCostMapper;
|
this.productSkuCostMapper = productSkuCostMapper;
|
||||||
this.fakeOrdersFeeMapper = fakeOrdersFeeMapper;
|
this.fakeOrdersFeeMapper = fakeOrdersFeeMapper;
|
||||||
this.sysFileMapper = sysFileMapper;
|
this.sysFileMapper = sysFileMapper;
|
||||||
|
this.warehouseMapper = warehouseMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SKU 落库后尝试挂 orphan 订单;订单表不存在时跳过 */
|
/** SKU 落库后尝试挂 orphan 订单;订单表不存在时跳过 */
|
||||||
@@ -132,13 +137,18 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调价走独立成本接口;此处只更新 SKU 基础字段
|
// 调价走独立成本接口;此处只更新 SKU 基础字段(含重量,允许置空)
|
||||||
ProductSkuPO sku = new ProductSkuPO();
|
ProductSkuPO sku = new ProductSkuPO();
|
||||||
sku.setId(id);
|
sku.setId(id);
|
||||||
sku.setCompanyId(companyId);
|
sku.setCompanyId(companyId);
|
||||||
sku.setProductId(existing.getProductId());
|
sku.setProductId(existing.getProductId());
|
||||||
sku.setName(dto.getName());
|
sku.setName(dto.getName());
|
||||||
sku.setSkuCode(dto.getSkuCode());
|
sku.setSkuCode(dto.getSkuCode());
|
||||||
|
sku.setWeightG(dto.getWeightG());
|
||||||
|
sku.setLengthMm(dto.getLengthMm());
|
||||||
|
sku.setWidthMm(dto.getWidthMm());
|
||||||
|
sku.setHeightMm(dto.getHeightMm());
|
||||||
|
sku.setWarehouseId(dto.getWarehouseId());
|
||||||
sku.setRemark(dto.getRemark());
|
sku.setRemark(dto.getRemark());
|
||||||
if (dto.getImageId() != null) {
|
if (dto.getImageId() != null) {
|
||||||
sku.setImageId(dto.getImageId());
|
sku.setImageId(dto.getImageId());
|
||||||
@@ -229,6 +239,11 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
if (filter.getExcludeProductId() != null) {
|
if (filter.getExcludeProductId() != null) {
|
||||||
wrapper.ne(ProductSkuPO::getProductId, filter.getExcludeProductId());
|
wrapper.ne(ProductSkuPO::getProductId, filter.getExcludeProductId());
|
||||||
}
|
}
|
||||||
|
if (Boolean.TRUE.equals(filter.getUnassignedOnly())) {
|
||||||
|
wrapper.isNull(ProductSkuPO::getWarehouseId);
|
||||||
|
} else if (filter.getWarehouseId() != null) {
|
||||||
|
wrapper.eq(ProductSkuPO::getWarehouseId, filter.getWarehouseId());
|
||||||
|
}
|
||||||
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
||||||
String keywords = filter.getKeywords().trim();
|
String keywords = filter.getKeywords().trim();
|
||||||
LambdaQueryWrapper<ProductPO> productKw = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<ProductPO> productKw = new LambdaQueryWrapper<>();
|
||||||
@@ -436,6 +451,11 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
byCode.setProductId(dto.getProductId());
|
byCode.setProductId(dto.getProductId());
|
||||||
byCode.setName(dto.getName());
|
byCode.setName(dto.getName());
|
||||||
byCode.setSkuCode(trimmedCode);
|
byCode.setSkuCode(trimmedCode);
|
||||||
|
byCode.setWeightG(dto.getWeightG());
|
||||||
|
byCode.setLengthMm(dto.getLengthMm());
|
||||||
|
byCode.setWidthMm(dto.getWidthMm());
|
||||||
|
byCode.setHeightMm(dto.getHeightMm());
|
||||||
|
byCode.setWarehouseId(dto.getWarehouseId());
|
||||||
byCode.setRemark(dto.getRemark());
|
byCode.setRemark(dto.getRemark());
|
||||||
if (dto.getImageId() != null) {
|
if (dto.getImageId() != null) {
|
||||||
byCode.setImageId(dto.getImageId());
|
byCode.setImageId(dto.getImageId());
|
||||||
@@ -591,6 +611,12 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
vo.setOtherCost(cost.getOtherCost());
|
vo.setOtherCost(cost.getOtherCost());
|
||||||
vo.setCostEffectiveFrom(cost.getEffectiveFrom());
|
vo.setCostEffectiveFrom(cost.getEffectiveFrom());
|
||||||
}
|
}
|
||||||
|
if (sku.getWarehouseId() != null) {
|
||||||
|
WarehousePO wh = warehouseMapper.selectById(sku.getWarehouseId());
|
||||||
|
if (wh != null) {
|
||||||
|
vo.setWarehouseName(wh.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
// 有系统图 id 则覆盖外链
|
// 有系统图 id 则覆盖外链
|
||||||
if (sku.getImageId() != null) {
|
if (sku.getImageId() != null) {
|
||||||
SysFilePO file = sysFileMapper.selectById(sku.getImageId());
|
SysFilePO file = sysFileMapper.selectById(sku.getImageId());
|
||||||
|
|||||||
+7
@@ -1,5 +1,7 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.ec.product.spec.model.dto;
|
package top.xyquan.ecomdmbbackend.modules.ec.product.spec.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Max;
|
||||||
|
import jakarta.validation.constraints.Min;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -23,6 +25,11 @@ public class CreateSkuFromSpecsDTO {
|
|||||||
/** 可选;空则用规格值名拼接 */
|
/** 可选;空则用规格值名拼接 */
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
@Min(value = 1, message = "重量至少为 1 克")
|
||||||
|
@Max(value = 500000, message = "重量不能超过 500kg")
|
||||||
|
private Integer weightG;
|
||||||
|
|
||||||
@NotNull(message = "商品成本不能为空")
|
@NotNull(message = "商品成本不能为空")
|
||||||
private BigDecimal productCost;
|
private BigDecimal productCost;
|
||||||
|
|
||||||
|
|||||||
+1
@@ -297,6 +297,7 @@ public class ProductSpecServiceImpl implements ProductSpecService {
|
|||||||
sku.setProductId(productId);
|
sku.setProductId(productId);
|
||||||
sku.setName(name);
|
sku.setName(name);
|
||||||
sku.setSkuCode(skuCode);
|
sku.setSkuCode(skuCode);
|
||||||
|
sku.setWeightG(dto.getWeightG());
|
||||||
sku.setSpecCombinationKey(key);
|
sku.setSpecCombinationKey(key);
|
||||||
sku.setRemark(dto.getRemark());
|
sku.setRemark(dto.getRemark());
|
||||||
sku.setStatus(1);
|
sku.setStatus(1);
|
||||||
|
|||||||
+156
@@ -0,0 +1,156 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.controller;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteImportDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteImportVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport.ExpressQuoteImportService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.ExpressQuoteService;
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** 快递报价单。 */
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/ec/express-quote")
|
||||||
|
public class ExpressQuoteController {
|
||||||
|
|
||||||
|
private final ExpressQuoteService expressQuoteService;
|
||||||
|
private final ExpressQuoteImportService expressQuoteImportService;
|
||||||
|
|
||||||
|
public ExpressQuoteController(ExpressQuoteService expressQuoteService,
|
||||||
|
ExpressQuoteImportService expressQuoteImportService) {
|
||||||
|
this.expressQuoteService = expressQuoteService;
|
||||||
|
this.expressQuoteImportService = expressQuoteImportService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@RequirePermission(value = "ec:express-quote:create", description = "创建报价", allowSuper = true)
|
||||||
|
public ApiResponse<ExpressQuoteVO> create(@Valid @RequestBody ExpressQuoteDtos.Create dto) {
|
||||||
|
return ApiResponse.success("创建成功", expressQuoteService.create(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/{id}")
|
||||||
|
@RequirePermission(value = "ec:express-quote:update", description = "更新报价", allowSuper = true)
|
||||||
|
public ApiResponse<ExpressQuoteVO> update(@Valid @RequestBody ExpressQuoteDtos.Update dto, @PathVariable Long id) {
|
||||||
|
return ApiResponse.success("更新成功", expressQuoteService.update(dto, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@RequirePermission(value = "ec:express-quote:delete", description = "删除报价", allowSuper = true)
|
||||||
|
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||||
|
expressQuoteService.delete(id);
|
||||||
|
return ApiResponse.success("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
@RequirePermission(value = "ec:express-quote:read", description = "查询报价", allowSuper = true)
|
||||||
|
public ApiResponse<PageResultVO<ExpressQuoteVO>> list(
|
||||||
|
@Valid @RequestBody PageQueryDTO<ExpressQuoteDtos.Filter> query) {
|
||||||
|
return ApiResponse.success("获取成功", expressQuoteService.page(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/enabled")
|
||||||
|
@RequirePermission(value = "ec:express-quote:read", description = "启用报价列表", allowSuper = true)
|
||||||
|
public ApiResponse<List<ExpressQuoteVO>> enabled() {
|
||||||
|
return ApiResponse.success("获取成功", expressQuoteService.listEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/detail/{id}")
|
||||||
|
@RequirePermission(value = "ec:express-quote:read", description = "报价详情", allowSuper = true)
|
||||||
|
public ApiResponse<ExpressQuoteVO> detail(
|
||||||
|
@PathVariable Long id,
|
||||||
|
@RequestParam(value = "withHistory", defaultValue = "false") boolean withHistory) {
|
||||||
|
return ApiResponse.success("获取成功", expressQuoteService.detail(id, withHistory));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{quoteId}/version")
|
||||||
|
@RequirePermission(value = "ec:express-quote:update", description = "追加报价版本", allowSuper = true)
|
||||||
|
public ApiResponse<ExpressQuoteVO.VersionVO> upsertVersion(
|
||||||
|
@PathVariable Long quoteId,
|
||||||
|
@Valid @RequestBody ExpressQuoteDtos.VersionUpsert dto) {
|
||||||
|
return ApiResponse.success("版本保存成功", expressQuoteService.upsertVersion(quoteId, dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/version/{versionId}")
|
||||||
|
@RequirePermission(value = "ec:express-quote:update", description = "删除报价版本", allowSuper = true)
|
||||||
|
public ApiResponse<Void> deleteVersion(@PathVariable Long versionId) {
|
||||||
|
expressQuoteService.deleteVersion(versionId);
|
||||||
|
return ApiResponse.success("版本已删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/import/template")
|
||||||
|
@RequirePermission(value = "ec:express-quote:read", description = "下载报价导入模板", allowSuper = true)
|
||||||
|
public void downloadImportTemplate(HttpServletResponse response) {
|
||||||
|
byte[] data = expressQuoteImportService.templateBytes();
|
||||||
|
String filename = URLEncoder.encode("快递报价导入模板.xlsx", StandardCharsets.UTF_8).replace("+", "%20");
|
||||||
|
try {
|
||||||
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||||
|
response.setHeader(HttpHeaders.CONTENT_DISPOSITION,
|
||||||
|
"attachment; filename=\"express-quote-template.xlsx\"; filename*=UTF-8''" + filename);
|
||||||
|
response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
|
||||||
|
response.getOutputStream().write(data);
|
||||||
|
response.getOutputStream().flush();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("下载模板失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/import/preview", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
@RequirePermission(value = "ec:express-quote:create", description = "预览报价导入", allowSuper = true)
|
||||||
|
public ApiResponse<ExpressQuoteImportVO> importPreview(@RequestPart("file") MultipartFile file) {
|
||||||
|
return ApiResponse.success("解析完成", expressQuoteImportService.preview(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/import/commit", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
@RequirePermission(value = "ec:express-quote:create", description = "确认导入报价", allowSuper = true)
|
||||||
|
public ApiResponse<ExpressQuoteVO> importCommit(
|
||||||
|
@RequestPart("file") MultipartFile file,
|
||||||
|
@Valid @RequestPart("params") ExpressQuoteImportDtos.Commit params) {
|
||||||
|
return ApiResponse.success("导入成功", expressQuoteImportService.commit(file, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/meta/carriers")
|
||||||
|
@RequirePermission(value = "ec:express-quote:read", description = "承运商字典", allowSuper = true)
|
||||||
|
public ApiResponse<List<Map<String, String>>> carriers() {
|
||||||
|
return ApiResponse.success("获取成功", ExpressCarrierCodes.all());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 标准省份全称列表(与 BiRegionNormalizer 对齐)。 */
|
||||||
|
@GetMapping("/meta/provinces")
|
||||||
|
@RequirePermission(value = "ec:express-quote:read", description = "省份字典", allowSuper = true)
|
||||||
|
public ApiResponse<List<Map<String, String>>> provinces() {
|
||||||
|
String[] fulls = {
|
||||||
|
"北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省", "黑龙江省",
|
||||||
|
"上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省",
|
||||||
|
"湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省",
|
||||||
|
"云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区",
|
||||||
|
"台湾省", "香港特别行政区", "澳门特别行政区"
|
||||||
|
};
|
||||||
|
List<Map<String, String>> list = new ArrayList<>();
|
||||||
|
for (String f : fulls) {
|
||||||
|
Map<String, String> m = new LinkedHashMap<>();
|
||||||
|
m.put("code", f);
|
||||||
|
m.put("name", f);
|
||||||
|
m.put("normalized", BiRegionNormalizer.normalize(f));
|
||||||
|
list.add(m);
|
||||||
|
}
|
||||||
|
return ApiResponse.success("获取成功", list);
|
||||||
|
}
|
||||||
|
}
|
||||||
+112
@@ -0,0 +1,112 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.controller;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.vo.ProductSkuVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.WarehouseService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** 发货仓库、报价绑定与仓商品。 */
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/ec/warehouse")
|
||||||
|
public class WarehouseController {
|
||||||
|
|
||||||
|
private final WarehouseService warehouseService;
|
||||||
|
|
||||||
|
public WarehouseController(WarehouseService warehouseService) {
|
||||||
|
this.warehouseService = warehouseService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@RequirePermission(value = "ec:warehouse:create", description = "创建仓库", allowSuper = true)
|
||||||
|
public ApiResponse<WarehouseVO> create(@Valid @RequestBody WarehouseDtos.Create dto) {
|
||||||
|
return ApiResponse.success("仓库创建成功", warehouseService.create(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/{id}")
|
||||||
|
@RequirePermission(value = "ec:warehouse:update", description = "更新仓库", allowSuper = true)
|
||||||
|
public ApiResponse<WarehouseVO> update(@Valid @RequestBody WarehouseDtos.Update dto, @PathVariable Long id) {
|
||||||
|
return ApiResponse.success("仓库更新成功", warehouseService.update(dto, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@RequirePermission(value = "ec:warehouse:delete", description = "删除仓库", allowSuper = true)
|
||||||
|
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||||
|
warehouseService.delete(id);
|
||||||
|
return ApiResponse.success("仓库删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/list")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "查询仓库", allowSuper = true)
|
||||||
|
public ApiResponse<PageResultVO<WarehouseVO>> list(@Valid @RequestBody PageQueryDTO<WarehouseDtos.Filter> query) {
|
||||||
|
return ApiResponse.success("获取成功", warehouseService.page(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/enabled")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "启用仓库列表", allowSuper = true)
|
||||||
|
public ApiResponse<List<WarehouseVO>> enabled() {
|
||||||
|
return ApiResponse.success("获取成功", warehouseService.listEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/detail/{id}")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "仓库详情", allowSuper = true)
|
||||||
|
public ApiResponse<WarehouseVO> detail(@PathVariable Long id) {
|
||||||
|
return ApiResponse.success("获取成功", warehouseService.detail(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/binds")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "仓库报价绑定", allowSuper = true)
|
||||||
|
public ApiResponse<List<WarehouseExpressBindVO>> binds(@PathVariable Long id) {
|
||||||
|
return ApiResponse.success("获取成功", warehouseService.listBinds(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/bind")
|
||||||
|
@RequirePermission(value = "ec:warehouse:update", description = "绑定报价", allowSuper = true)
|
||||||
|
public ApiResponse<WarehouseExpressBindVO> addBind(@Valid @RequestBody WarehouseDtos.BindCreate dto) {
|
||||||
|
return ApiResponse.success("绑定成功", warehouseService.addBind(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/bind/{bindId}")
|
||||||
|
@RequirePermission(value = "ec:warehouse:update", description = "更新绑定", allowSuper = true)
|
||||||
|
public ApiResponse<WarehouseExpressBindVO> updateBind(@Valid @RequestBody WarehouseDtos.BindUpdate dto,
|
||||||
|
@PathVariable Long bindId) {
|
||||||
|
return ApiResponse.success("更新成功", warehouseService.updateBind(dto, bindId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/bind/{bindId}")
|
||||||
|
@RequirePermission(value = "ec:warehouse:update", description = "解除绑定", allowSuper = true)
|
||||||
|
public ApiResponse<Void> removeBind(@PathVariable Long bindId) {
|
||||||
|
warehouseService.removeBind(bindId);
|
||||||
|
return ApiResponse.success("已解绑");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/skus/list")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "发货仓商品列表", allowSuper = true)
|
||||||
|
public ApiResponse<PageResultVO<ProductSkuVO>> skuList(
|
||||||
|
@Valid @RequestBody PageQueryDTO<WarehouseDtos.SkuFilter> query) {
|
||||||
|
return ApiResponse.success("获取成功", warehouseService.pageSkus(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/skus/unassigned-count")
|
||||||
|
@RequirePermission(value = "ec:warehouse:read", description = "未分配 SKU 数", allowSuper = true)
|
||||||
|
public ApiResponse<Map<String, Long>> unassignedSkuCount() {
|
||||||
|
return ApiResponse.success("获取成功", Map.of("count", warehouseService.countUnassignedSkus()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/skus/batch-assign")
|
||||||
|
@RequirePermission(value = "ec:warehouse:update", description = "批量分配发货仓", allowSuper = true)
|
||||||
|
public ApiResponse<Map<String, Integer>> batchAssignSkus(
|
||||||
|
@Valid @RequestBody WarehouseDtos.SkuBatchAssign dto) {
|
||||||
|
int updated = warehouseService.batchAssignSkus(dto);
|
||||||
|
return ApiResponse.success("分配成功", Map.of("updated", updated));
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** 承运商软编码字典(P2)。 */
|
||||||
|
public final class ExpressCarrierCodes {
|
||||||
|
|
||||||
|
public static final String OTHER = "OTHER";
|
||||||
|
|
||||||
|
private static final List<Map<String, String>> ALL = List.of(
|
||||||
|
Map.of("code", "ZTO", "name", "中通快递"),
|
||||||
|
Map.of("code", "YTO", "name", "圆通速递"),
|
||||||
|
Map.of("code", "STO", "name", "申通快递"),
|
||||||
|
Map.of("code", "YD", "name", "韵达快递"),
|
||||||
|
Map.of("code", "SF", "name", "顺丰速运"),
|
||||||
|
Map.of("code", "JT", "name", "极兔速递"),
|
||||||
|
Map.of("code", "EMS", "name", "邮政EMS"),
|
||||||
|
Map.of("code", OTHER, "name", "其他")
|
||||||
|
);
|
||||||
|
|
||||||
|
private ExpressCarrierCodes() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Map<String, String>> all() {
|
||||||
|
return ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isKnown(String code) {
|
||||||
|
if (code == null || code.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String c = code.trim().toUpperCase();
|
||||||
|
return ALL.stream().anyMatch(m -> c.equals(m.get("code")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String normalizeCode(String code) {
|
||||||
|
if (code == null || code.isBlank()) {
|
||||||
|
return OTHER;
|
||||||
|
}
|
||||||
|
String c = code.trim().toUpperCase();
|
||||||
|
return isKnown(c) ? c : OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressCarrierAliasMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressCarrierAliasPO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/** 将订单 logistics_id / 物流名归一为 carrier_code。 */
|
||||||
|
@Component
|
||||||
|
public class ExpressCarrierResolver {
|
||||||
|
|
||||||
|
private final ExpressCarrierAliasMapper aliasMapper;
|
||||||
|
|
||||||
|
public ExpressCarrierResolver(ExpressCarrierAliasMapper aliasMapper) {
|
||||||
|
this.aliasMapper = aliasMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 归一承运商编码;无法识别返回 null(走 priority)
|
||||||
|
*/
|
||||||
|
public String resolve(Long companyId, String logisticsIdOrName) {
|
||||||
|
if (!StringUtils.hasText(logisticsIdOrName)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String raw = logisticsIdOrName.trim();
|
||||||
|
String upper = raw.toUpperCase(Locale.ROOT);
|
||||||
|
if (ExpressCarrierCodes.isKnown(upper)) {
|
||||||
|
return upper;
|
||||||
|
}
|
||||||
|
// 公司覆盖优先,再全局
|
||||||
|
List<ExpressCarrierAliasPO> aliases = aliasMapper.selectList(new LambdaQueryWrapper<ExpressCarrierAliasPO>()
|
||||||
|
.and(w -> w.eq(ExpressCarrierAliasPO::getCompanyId, companyId)
|
||||||
|
.or().isNull(ExpressCarrierAliasPO::getCompanyId)));
|
||||||
|
ExpressCarrierAliasPO companyHit = null;
|
||||||
|
ExpressCarrierAliasPO globalHit = null;
|
||||||
|
for (ExpressCarrierAliasPO a : aliases) {
|
||||||
|
if (a.getLogisticsPattern() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!a.getLogisticsPattern().trim().equalsIgnoreCase(raw)
|
||||||
|
&& !a.getLogisticsPattern().trim().equalsIgnoreCase(upper)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (a.getCompanyId() != null) {
|
||||||
|
companyHit = a;
|
||||||
|
} else {
|
||||||
|
globalHit = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ExpressCarrierAliasPO hit = companyHit != null ? companyHit : globalHit;
|
||||||
|
return hit != null ? ExpressCarrierCodes.normalizeCode(hit.getCarrierCode()) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+210
@@ -0,0 +1,210 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderItemPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.order.model.po.OrderPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.order.status.support.OrderStatusStatSets;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.model.po.ProductSkuCostPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.cost.service.ProductSkuCostService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteVersionMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单运费:同仓整包计价后按行重量分摊;失败回退 SKU shipping_cost×qty。
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class FreightCostCalculator {
|
||||||
|
|
||||||
|
private final ProductSkuMapper productSkuMapper;
|
||||||
|
private final ProductSkuCostService productSkuCostService;
|
||||||
|
private final FreightQuoteResolver quoteResolver;
|
||||||
|
private final ExpressCarrierResolver carrierResolver;
|
||||||
|
private final WarehouseExpressBindMapper bindMapper;
|
||||||
|
private final ExpressQuoteVersionMapper versionMapper;
|
||||||
|
|
||||||
|
public FreightCostCalculator(ProductSkuMapper productSkuMapper,
|
||||||
|
ProductSkuCostService productSkuCostService,
|
||||||
|
FreightQuoteResolver quoteResolver,
|
||||||
|
ExpressCarrierResolver carrierResolver,
|
||||||
|
WarehouseExpressBindMapper bindMapper,
|
||||||
|
ExpressQuoteVersionMapper versionMapper) {
|
||||||
|
this.productSkuMapper = productSkuMapper;
|
||||||
|
this.productSkuCostService = productSkuCostService;
|
||||||
|
this.quoteResolver = quoteResolver;
|
||||||
|
this.carrierResolver = carrierResolver;
|
||||||
|
this.bindMapper = bindMapper;
|
||||||
|
this.versionMapper = versionMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return itemId → 行运费;无 itemId 的行用负数占位 key 不放入
|
||||||
|
*/
|
||||||
|
public Map<Long, BigDecimal> allocateFreight(OrderPO order, List<OrderItemPO> items) {
|
||||||
|
Map<Long, BigDecimal> result = new HashMap<>();
|
||||||
|
if (order == null || items == null || items.isEmpty()) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
LocalDate onDate = order.getOrderTime() != null ? order.getOrderTime().toLocalDate() : LocalDate.now();
|
||||||
|
String preferredCarrier = carrierResolver.resolve(order.getCompanyId(), order.getLogisticsId());
|
||||||
|
|
||||||
|
List<Long> skuIds = items.stream()
|
||||||
|
.map(OrderItemPO::getProductSkuId)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(id -> id > 0)
|
||||||
|
.distinct()
|
||||||
|
.toList();
|
||||||
|
Map<Long, ProductSkuPO> skuMap = new HashMap<>();
|
||||||
|
if (!skuIds.isEmpty()) {
|
||||||
|
for (ProductSkuPO sku : productSkuMapper.selectByIds(skuIds)) {
|
||||||
|
skuMap.put(sku.getId(), sku);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<Long, ProductSkuCostPO> costMap = productSkuCostService.getCostsAsOf(skuIds, onDate);
|
||||||
|
|
||||||
|
// warehouseId -> lines
|
||||||
|
Map<Long, List<OrderItemPO>> byWarehouse = new HashMap<>();
|
||||||
|
List<OrderItemPO> noWarehouse = new ArrayList<>();
|
||||||
|
for (OrderItemPO item : items) {
|
||||||
|
Long skuId = item.getProductSkuId();
|
||||||
|
ProductSkuPO sku = skuId != null ? skuMap.get(skuId) : null;
|
||||||
|
if (sku == null || sku.getWarehouseId() == null) {
|
||||||
|
noWarehouse.add(item);
|
||||||
|
} else {
|
||||||
|
byWarehouse.computeIfAbsent(sku.getWarehouseId(), k -> new ArrayList<>()).add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<Long, List<OrderItemPO>> e : byWarehouse.entrySet()) {
|
||||||
|
Long warehouseId = e.getKey();
|
||||||
|
List<OrderItemPO> group = e.getValue();
|
||||||
|
int pieceCount = 0;
|
||||||
|
int actualG = 0;
|
||||||
|
int volumetricG = 0;
|
||||||
|
Map<Long, Integer> lineWeight = new HashMap<>();
|
||||||
|
boolean useVolumetric = isUseVolumetric(warehouseId, onDate);
|
||||||
|
|
||||||
|
for (OrderItemPO item : group) {
|
||||||
|
int qty = OrderStatusStatSets.quantity(item);
|
||||||
|
pieceCount += qty;
|
||||||
|
ProductSkuPO sku = skuMap.get(item.getProductSkuId());
|
||||||
|
int unitActual = sku != null && sku.getWeightG() != null ? sku.getWeightG() : 0;
|
||||||
|
int unitVol = 0;
|
||||||
|
if (useVolumetric && sku != null) {
|
||||||
|
Integer divisor = resolveVolumeDivisor(warehouseId, onDate);
|
||||||
|
unitVol = FreightQuoteResolver.volumetricWeightG(
|
||||||
|
sku.getLengthMm(), sku.getWidthMm(), sku.getHeightMm(), divisor);
|
||||||
|
}
|
||||||
|
int unitCharge = FreightQuoteResolver.chargeableWeightG(unitActual, unitVol, useVolumetric);
|
||||||
|
int lineG = unitCharge * qty;
|
||||||
|
if (item.getId() != null) {
|
||||||
|
lineWeight.put(item.getId(), lineG);
|
||||||
|
}
|
||||||
|
actualG += unitActual * qty;
|
||||||
|
volumetricG += unitVol * qty;
|
||||||
|
}
|
||||||
|
int chargeG = FreightQuoteResolver.chargeableWeightG(actualG, volumetricG, useVolumetric);
|
||||||
|
Optional<BigDecimal> packageFreight = quoteResolver.resolveAmount(
|
||||||
|
warehouseId, onDate, order.getProvince(), order.getCity(),
|
||||||
|
chargeG, pieceCount, preferredCarrier);
|
||||||
|
|
||||||
|
if (packageFreight.isPresent() && chargeG > 0) {
|
||||||
|
allocateByWeight(result, group, lineWeight, packageFreight.get(), costMap, onDate);
|
||||||
|
} else {
|
||||||
|
fallbackManual(result, group, costMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fallbackManual(result, noWarehouse, costMap);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void allocateByWeight(Map<Long, BigDecimal> result, List<OrderItemPO> group,
|
||||||
|
Map<Long, Integer> lineWeight, BigDecimal packageFreight,
|
||||||
|
Map<Long, ProductSkuCostPO> costMap, LocalDate onDate) {
|
||||||
|
int totalW = lineWeight.values().stream().mapToInt(Integer::intValue).sum();
|
||||||
|
if (totalW <= 0) {
|
||||||
|
fallbackManual(result, group, costMap);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BigDecimal allocated = BigDecimal.ZERO;
|
||||||
|
for (int i = 0; i < group.size(); i++) {
|
||||||
|
OrderItemPO item = group.get(i);
|
||||||
|
if (item.getId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int w = lineWeight.getOrDefault(item.getId(), 0);
|
||||||
|
BigDecimal share;
|
||||||
|
if (i == group.size() - 1) {
|
||||||
|
share = packageFreight.subtract(allocated);
|
||||||
|
} else {
|
||||||
|
share = packageFreight.multiply(BigDecimal.valueOf(w))
|
||||||
|
.divide(BigDecimal.valueOf(totalW), 2, RoundingMode.HALF_UP);
|
||||||
|
allocated = allocated.add(share);
|
||||||
|
}
|
||||||
|
result.put(item.getId(), share.max(BigDecimal.ZERO));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fallbackManual(Map<Long, BigDecimal> result, List<OrderItemPO> items,
|
||||||
|
Map<Long, ProductSkuCostPO> costMap) {
|
||||||
|
for (OrderItemPO item : items) {
|
||||||
|
if (item.getId() == null || result.containsKey(item.getId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Long skuId = item.getProductSkuId();
|
||||||
|
ProductSkuCostPO cost = skuId != null ? costMap.get(skuId) : null;
|
||||||
|
BigDecimal unit = cost != null && cost.getShippingCost() != null
|
||||||
|
? cost.getShippingCost() : BigDecimal.ZERO;
|
||||||
|
result.put(item.getId(), unit.multiply(BigDecimal.valueOf(OrderStatusStatSets.quantity(item))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUseVolumetric(Long warehouseId, LocalDate onDate) {
|
||||||
|
WarehouseExpressBindPO first = firstBind(warehouseId);
|
||||||
|
if (first == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ExpressQuoteVersionPO v = versionAsOf(first.getQuoteId(), onDate);
|
||||||
|
return v != null && v.getUseVolumetric() != null && v.getUseVolumetric() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer resolveVolumeDivisor(Long warehouseId, LocalDate onDate) {
|
||||||
|
WarehouseExpressBindPO first = firstBind(warehouseId);
|
||||||
|
if (first == null) {
|
||||||
|
return 6000;
|
||||||
|
}
|
||||||
|
ExpressQuoteVersionPO v = versionAsOf(first.getQuoteId(), onDate);
|
||||||
|
return v != null && v.getVolumeDivisor() != null ? v.getVolumeDivisor() : 6000;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WarehouseExpressBindPO firstBind(Long warehouseId) {
|
||||||
|
return bindMapper.selectOne(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getWarehouseId, warehouseId)
|
||||||
|
.eq(WarehouseExpressBindPO::getStatus, 1)
|
||||||
|
.orderByAsc(WarehouseExpressBindPO::getPriority)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteVersionPO versionAsOf(Long quoteId, LocalDate onDate) {
|
||||||
|
return versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, quoteId)
|
||||||
|
.le(ExpressQuoteVersionPO::getEffectiveFrom, onDate)
|
||||||
|
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
}
|
||||||
|
}
|
||||||
+291
@@ -0,0 +1,291 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteBandMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteRegionMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteVersionMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteBandPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteRegionPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按仓 + 日期 + 目的地 + 计费重 + 可选承运商选价。
|
||||||
|
* 策略:PRIORITY;有 carrier 时将该 carrier 的 bind 提到最前。
|
||||||
|
* REGION_WEIGHT:目的地优先市名精确匹配,再省全称,再默认分区;命中后按重量带计价。
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class FreightQuoteResolver {
|
||||||
|
|
||||||
|
private final WarehouseExpressBindMapper bindMapper;
|
||||||
|
private final ExpressQuoteMapper quoteMapper;
|
||||||
|
private final ExpressQuoteVersionMapper versionMapper;
|
||||||
|
private final ExpressQuoteRegionMapper regionMapper;
|
||||||
|
private final ExpressQuoteBandMapper bandMapper;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public FreightQuoteResolver(WarehouseExpressBindMapper bindMapper,
|
||||||
|
ExpressQuoteMapper quoteMapper,
|
||||||
|
ExpressQuoteVersionMapper versionMapper,
|
||||||
|
ExpressQuoteRegionMapper regionMapper,
|
||||||
|
ExpressQuoteBandMapper bandMapper,
|
||||||
|
ObjectMapper objectMapper) {
|
||||||
|
this.bindMapper = bindMapper;
|
||||||
|
this.quoteMapper = quoteMapper;
|
||||||
|
this.versionMapper = versionMapper;
|
||||||
|
this.regionMapper = regionMapper;
|
||||||
|
this.bandMapper = bandMapper;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param chargeableWeightG 计费重(克,已含体积重取大)
|
||||||
|
* @param pieceCount 件数(FLAT/PIECE 用)
|
||||||
|
* @return 运费金额;无法计价返回 empty
|
||||||
|
*/
|
||||||
|
public Optional<BigDecimal> resolveAmount(Long warehouseId, LocalDate onDate,
|
||||||
|
String province, String city,
|
||||||
|
int chargeableWeightG, int pieceCount,
|
||||||
|
String preferredCarrier) {
|
||||||
|
if (warehouseId == null || onDate == null || chargeableWeightG <= 0) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getWarehouseId, warehouseId)
|
||||||
|
.eq(WarehouseExpressBindPO::getStatus, 1));
|
||||||
|
if (binds.isEmpty()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
binds.sort(Comparator
|
||||||
|
.comparing((WarehouseExpressBindPO b) -> b.getPriority() != null ? b.getPriority() : 100)
|
||||||
|
.thenComparing(WarehouseExpressBindPO::getId));
|
||||||
|
|
||||||
|
List<WarehouseExpressBindPO> ordered = new ArrayList<>(binds);
|
||||||
|
if (StringUtils.hasText(preferredCarrier)) {
|
||||||
|
String carrier = preferredCarrier.trim().toUpperCase();
|
||||||
|
List<WarehouseExpressBindPO> matched = new ArrayList<>();
|
||||||
|
List<WarehouseExpressBindPO> rest = new ArrayList<>();
|
||||||
|
for (WarehouseExpressBindPO b : ordered) {
|
||||||
|
ExpressQuotePO q = quoteMapper.selectById(b.getQuoteId());
|
||||||
|
if (q != null && q.getStatus() != null && q.getStatus() == 1
|
||||||
|
&& carrier.equalsIgnoreCase(q.getCarrierCode())) {
|
||||||
|
matched.add(b);
|
||||||
|
} else {
|
||||||
|
rest.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ordered = new ArrayList<>();
|
||||||
|
ordered.addAll(matched);
|
||||||
|
ordered.addAll(rest);
|
||||||
|
}
|
||||||
|
|
||||||
|
String provinceFull = BiRegionNormalizer.normalize(province);
|
||||||
|
String cityRaw = StringUtils.hasText(city) ? city.trim() : null;
|
||||||
|
for (WarehouseExpressBindPO bind : ordered) {
|
||||||
|
ExpressQuotePO quote = quoteMapper.selectById(bind.getQuoteId());
|
||||||
|
if (quote == null || quote.getStatus() == null || quote.getStatus() != 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ExpressQuoteVersionPO version = versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, quote.getId())
|
||||||
|
.le(ExpressQuoteVersionPO::getEffectiveFrom, onDate)
|
||||||
|
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
if (version == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int weightG = applyWeightRound(chargeableWeightG, version.getWeightRound());
|
||||||
|
Optional<BigDecimal> amount = price(quote, version, provinceFull, cityRaw, weightG, pieceCount);
|
||||||
|
if (amount.isPresent()) {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<BigDecimal> price(ExpressQuotePO quote, ExpressQuoteVersionPO version,
|
||||||
|
String provinceFull, String cityRaw, int weightG, int pieceCount) {
|
||||||
|
String mode = quote.getBillingMode();
|
||||||
|
if (ExpressQuotePO.MODE_FLAT.equals(mode)) {
|
||||||
|
if (version.getFlatAmount() == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
if (ExpressQuoteVersionPO.SCOPE_ORDER.equalsIgnoreCase(version.getUnitScope())) {
|
||||||
|
return Optional.of(version.getFlatAmount());
|
||||||
|
}
|
||||||
|
if (ExpressQuoteVersionPO.SCOPE_PIECE.equalsIgnoreCase(version.getUnitScope())) {
|
||||||
|
int pcs = Math.max(pieceCount, 1);
|
||||||
|
return Optional.of(version.getFlatAmount().multiply(BigDecimal.valueOf(pcs)));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
if (ExpressQuotePO.MODE_PER_KG.equals(mode)) {
|
||||||
|
if (version.getPricePerKg() == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
BigDecimal kg = BigDecimal.valueOf(weightG).divide(BigDecimal.valueOf(1000), 3, RoundingMode.CEILING);
|
||||||
|
BigDecimal amount = kg.multiply(version.getPricePerKg()).setScale(2, RoundingMode.HALF_UP);
|
||||||
|
if (version.getMinAmount() != null && amount.compareTo(version.getMinAmount()) < 0) {
|
||||||
|
amount = version.getMinAmount();
|
||||||
|
}
|
||||||
|
return Optional.of(amount);
|
||||||
|
}
|
||||||
|
if (ExpressQuotePO.MODE_REGION_WEIGHT.equals(mode)) {
|
||||||
|
return priceRegionWeight(version, provinceFull, cityRaw, weightG);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Optional<BigDecimal> priceRegionWeight(ExpressQuoteVersionPO version,
|
||||||
|
String provinceFull, String cityRaw, int weightG) {
|
||||||
|
List<ExpressQuoteRegionPO> regions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||||
|
.eq(ExpressQuoteRegionPO::getVersionId, version.getId())
|
||||||
|
.orderByAsc(ExpressQuoteRegionPO::getSortOrder));
|
||||||
|
ExpressQuoteRegionPO hit = matchRegion(regions, provinceFull, cityRaw);
|
||||||
|
if (hit == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
List<ExpressQuoteBandPO> bands = bandMapper.selectList(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||||
|
.eq(ExpressQuoteBandPO::getRegionId, hit.getId())
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getSortOrder)
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getWeightFromG));
|
||||||
|
ExpressQuoteBandPO band = matchBand(bands, weightG);
|
||||||
|
if (band == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return priceBand(band, weightG);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 市名精确优先,再省全称,再默认分区。 */
|
||||||
|
private ExpressQuoteRegionPO matchRegion(List<ExpressQuoteRegionPO> regions,
|
||||||
|
String provinceFull, String cityRaw) {
|
||||||
|
ExpressQuoteRegionPO defaultRegion = null;
|
||||||
|
ExpressQuoteRegionPO provinceHit = null;
|
||||||
|
for (ExpressQuoteRegionPO r : regions) {
|
||||||
|
if (r.getIsDefault() != null && r.getIsDefault() == 1) {
|
||||||
|
defaultRegion = r;
|
||||||
|
}
|
||||||
|
List<String> dests = parseDestinations(r.getProvincesJson());
|
||||||
|
if (cityRaw != null && dests.stream().anyMatch(d -> destinationEquals(d, cityRaw))) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if (provinceHit == null && !BiRegionNormalizer.isUnknown(provinceFull)
|
||||||
|
&& dests.stream().anyMatch(d -> destinationEquals(d, provinceFull))) {
|
||||||
|
provinceHit = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return provinceHit != null ? provinceHit : defaultRegion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExpressQuoteBandPO matchBand(List<ExpressQuoteBandPO> bands, int weightG) {
|
||||||
|
for (ExpressQuoteBandPO b : bands) {
|
||||||
|
int from = b.getWeightFromG() != null ? b.getWeightFromG() : 0;
|
||||||
|
Integer to = b.getWeightToG();
|
||||||
|
if (weightG >= from && (to == null || weightG <= to)) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<BigDecimal> priceBand(ExpressQuoteBandPO band, int weightG) {
|
||||||
|
if (ExpressQuoteBandPO.MODE_FLAT_TICKET.equals(band.getPriceMode())) {
|
||||||
|
if (band.getFlatAmount() == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(band.getFlatAmount().setScale(2, RoundingMode.HALF_UP));
|
||||||
|
}
|
||||||
|
if (ExpressQuoteBandPO.MODE_FIRST_PLUS_KG.equals(band.getPriceMode())) {
|
||||||
|
int firstG = band.getFirstWeightG() != null ? Math.max(band.getFirstWeightG(), 0) : 0;
|
||||||
|
BigDecimal firstAmt = nz(band.getFirstAmount());
|
||||||
|
BigDecimal continuePerKg = nz(band.getContinuePerKg());
|
||||||
|
if (weightG <= firstG) {
|
||||||
|
return Optional.of(firstAmt.setScale(2, RoundingMode.HALF_UP));
|
||||||
|
}
|
||||||
|
int remainG = weightG - firstG;
|
||||||
|
int continueKg = (remainG + 999) / 1000;
|
||||||
|
return Optional.of(firstAmt.add(continuePerKg.multiply(BigDecimal.valueOf(continueKg)))
|
||||||
|
.setScale(2, RoundingMode.HALF_UP));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 计费重取整:CEIL_KG 向上取整到整千克(克)。 */
|
||||||
|
static int applyWeightRound(int weightG, String round) {
|
||||||
|
if (weightG <= 0) {
|
||||||
|
return weightG;
|
||||||
|
}
|
||||||
|
if ("CEIL_KG".equalsIgnoreCase(round)) {
|
||||||
|
return ((weightG + 999) / 1000) * 1000;
|
||||||
|
}
|
||||||
|
return weightG;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> parseDestinations(String provincesJson) {
|
||||||
|
if (!StringUtils.hasText(provincesJson)) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(provincesJson, new TypeReference<>() {
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean destinationEquals(String configured, String actual) {
|
||||||
|
if (!StringUtils.hasText(configured) || !StringUtils.hasText(actual)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String a = configured.trim();
|
||||||
|
String b = actual.trim();
|
||||||
|
if (Objects.equals(a, b)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String na = BiRegionNormalizer.normalize(a);
|
||||||
|
String nb = BiRegionNormalizer.normalize(b);
|
||||||
|
return !BiRegionNormalizer.isUnknown(na) && Objects.equals(na, nb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal nz(BigDecimal v) {
|
||||||
|
return v != null ? v : BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 体积重(克):长宽高 mm,divisor 默认 6000(cm 公式)。
|
||||||
|
* 克 = ceil(Lmm * Wmm * Hmm / divisor)。
|
||||||
|
*/
|
||||||
|
public static int volumetricWeightG(Integer lengthMm, Integer widthMm, Integer heightMm, Integer divisor) {
|
||||||
|
if (lengthMm == null || widthMm == null || heightMm == null
|
||||||
|
|| lengthMm <= 0 || widthMm <= 0 || heightMm <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int d = divisor != null && divisor > 0 ? divisor : 6000;
|
||||||
|
long volume = (long) lengthMm * widthMm * heightMm;
|
||||||
|
return (int) Math.ceil(volume * 1.0 / d);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int chargeableWeightG(int actualG, int volumetricG, boolean useVolumetric) {
|
||||||
|
if (!useVolumetric || volumetricG <= 0) {
|
||||||
|
return Math.max(actualG, 0);
|
||||||
|
}
|
||||||
|
return Math.max(actualG, volumetricG);
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressCarrierAliasPO;
|
||||||
|
|
||||||
|
/** ExpressCarrierAlias Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface ExpressCarrierAliasMapper extends BaseMapper<ExpressCarrierAliasPO> {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteBandPO;
|
||||||
|
|
||||||
|
/** 快递报价重量带 Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface ExpressQuoteBandMapper extends BaseMapper<ExpressQuoteBandPO> {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||||
|
|
||||||
|
/** ExpressQuote Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface ExpressQuoteMapper extends BaseMapper<ExpressQuotePO> {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteRegionPO;
|
||||||
|
|
||||||
|
/** ExpressQuoteRegion Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface ExpressQuoteRegionMapper extends BaseMapper<ExpressQuoteRegionPO> {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||||
|
|
||||||
|
/** ExpressQuoteVersion Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface ExpressQuoteVersionMapper extends BaseMapper<ExpressQuoteVersionPO> {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||||
|
|
||||||
|
/** WarehouseExpressBind Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface WarehouseExpressBindMapper extends BaseMapper<WarehouseExpressBindPO> {
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||||
|
|
||||||
|
/** Warehouse Mapper */
|
||||||
|
@Mapper
|
||||||
|
public interface WarehouseMapper extends BaseMapper<WarehousePO> {
|
||||||
|
}
|
||||||
+99
@@ -0,0 +1,99 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 快递报价 DTO。 */
|
||||||
|
public final class ExpressQuoteDtos {
|
||||||
|
|
||||||
|
private ExpressQuoteDtos() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Create {
|
||||||
|
@NotBlank(message = "报价编码不能为空")
|
||||||
|
private String code;
|
||||||
|
@NotBlank(message = "报价名称不能为空")
|
||||||
|
private String name;
|
||||||
|
@NotBlank(message = "承运商不能为空")
|
||||||
|
private String carrierCode;
|
||||||
|
@NotBlank(message = "计费模式不能为空")
|
||||||
|
private String billingMode;
|
||||||
|
private Integer status;
|
||||||
|
private String remark;
|
||||||
|
@Valid
|
||||||
|
private VersionUpsert initialVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Update {
|
||||||
|
@NotBlank(message = "报价名称不能为空")
|
||||||
|
private String name;
|
||||||
|
@NotBlank(message = "承运商不能为空")
|
||||||
|
private String carrierCode;
|
||||||
|
private Integer status;
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Filter {
|
||||||
|
private String keywords;
|
||||||
|
private String carrierCode;
|
||||||
|
private String billingMode;
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class VersionUpsert {
|
||||||
|
@NotNull(message = "生效日不能为空")
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
private String unitScope;
|
||||||
|
private BigDecimal pricePerKg;
|
||||||
|
private BigDecimal minAmount;
|
||||||
|
private Integer volumeDivisor;
|
||||||
|
private Integer useVolumetric;
|
||||||
|
/** NONE / CEIL_KG */
|
||||||
|
private String weightRound;
|
||||||
|
private String remark;
|
||||||
|
@Valid
|
||||||
|
private List<RegionUpsert> regions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class RegionUpsert {
|
||||||
|
@NotBlank(message = "分区名不能为空")
|
||||||
|
private String regionName;
|
||||||
|
/** 一类/二类… */
|
||||||
|
private String zoneLabel;
|
||||||
|
/** 目的地:省全称或市名 */
|
||||||
|
private List<String> provinces;
|
||||||
|
private Integer isDefault;
|
||||||
|
private Integer sortOrder;
|
||||||
|
/** 重量带(REGION_WEIGHT 必填) */
|
||||||
|
@Valid
|
||||||
|
private List<BandUpsert> bands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BandUpsert {
|
||||||
|
/** 下限克(含),默认 0 */
|
||||||
|
private Integer weightFromG;
|
||||||
|
/** 上限克(含);空=无上限 */
|
||||||
|
private Integer weightToG;
|
||||||
|
/** FLAT_TICKET / FIRST_PLUS_KG */
|
||||||
|
@NotBlank(message = "计价方式不能为空")
|
||||||
|
private String priceMode;
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
private Integer firstWeightG;
|
||||||
|
private BigDecimal firstAmount;
|
||||||
|
private BigDecimal continuePerKg;
|
||||||
|
private Integer sortOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
/** 报价导入提交参数(与文件一并 multipart)。 */
|
||||||
|
public final class ExpressQuoteImportDtos {
|
||||||
|
|
||||||
|
private ExpressQuoteImportDtos() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Commit {
|
||||||
|
/** CREATE / APPEND_VERSION */
|
||||||
|
@NotBlank(message = "导入模式不能为空")
|
||||||
|
private String mode;
|
||||||
|
/** APPEND_VERSION 时必填 */
|
||||||
|
private Long quoteId;
|
||||||
|
private String carrierCode;
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private String weightRound;
|
||||||
|
private Integer useVolumetric;
|
||||||
|
private Integer volumeDivisor;
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
}
|
||||||
+79
@@ -0,0 +1,79 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 仓库相关 DTO。 */
|
||||||
|
public final class WarehouseDtos {
|
||||||
|
|
||||||
|
private WarehouseDtos() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Create {
|
||||||
|
@NotBlank(message = "仓库编码不能为空")
|
||||||
|
private String code;
|
||||||
|
@NotBlank(message = "仓库名称不能为空")
|
||||||
|
private String name;
|
||||||
|
private String province;
|
||||||
|
private String city;
|
||||||
|
private String address;
|
||||||
|
private Integer status;
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Update {
|
||||||
|
@NotBlank(message = "仓库名称不能为空")
|
||||||
|
private String name;
|
||||||
|
private String province;
|
||||||
|
private String city;
|
||||||
|
private String address;
|
||||||
|
private Integer status;
|
||||||
|
private String remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Filter {
|
||||||
|
private String keywords;
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BindCreate {
|
||||||
|
@NotNull(message = "仓库不能为空")
|
||||||
|
private Long warehouseId;
|
||||||
|
@NotNull(message = "报价单不能为空")
|
||||||
|
private Long quoteId;
|
||||||
|
private Integer priority;
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BindUpdate {
|
||||||
|
private Integer priority;
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 发货仓商品列表筛选(走仓权限,内部复用 SKU 查询) */
|
||||||
|
@Data
|
||||||
|
public static class SkuFilter {
|
||||||
|
private String keywords;
|
||||||
|
private Long warehouseId;
|
||||||
|
/** true = 仅未分配 */
|
||||||
|
private Boolean unassignedOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量设置 SKU 默认发货仓;warehouseId 空=取消分配 */
|
||||||
|
@Data
|
||||||
|
public static class SkuBatchAssign {
|
||||||
|
@NotEmpty(message = "请选择 SKU")
|
||||||
|
private List<Long> skuIds;
|
||||||
|
/** null = 取消分配 */
|
||||||
|
private Long warehouseId;
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 物流标识 → 承运商编码。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_express_carrier_alias")
|
||||||
|
public class ExpressCarrierAliasPO {
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("logistics_pattern")
|
||||||
|
private String logisticsPattern;
|
||||||
|
|
||||||
|
@TableField("carrier_code")
|
||||||
|
private String carrierCode;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 报价重量带(一分区多行)。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_express_quote_band")
|
||||||
|
public class ExpressQuoteBandPO {
|
||||||
|
|
||||||
|
public static final String MODE_FLAT_TICKET = "FLAT_TICKET";
|
||||||
|
public static final String MODE_FIRST_PLUS_KG = "FIRST_PLUS_KG";
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("version_id")
|
||||||
|
private Long versionId;
|
||||||
|
|
||||||
|
@TableField("region_id")
|
||||||
|
private Long regionId;
|
||||||
|
|
||||||
|
@TableField("weight_from_g")
|
||||||
|
private Integer weightFromG;
|
||||||
|
|
||||||
|
/** NULL=无上限 */
|
||||||
|
@TableField("weight_to_g")
|
||||||
|
private Integer weightToG;
|
||||||
|
|
||||||
|
@TableField("price_mode")
|
||||||
|
private String priceMode;
|
||||||
|
|
||||||
|
@TableField("flat_amount")
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
|
||||||
|
@TableField("first_weight_g")
|
||||||
|
private Integer firstWeightG;
|
||||||
|
|
||||||
|
@TableField("first_amount")
|
||||||
|
private BigDecimal firstAmount;
|
||||||
|
|
||||||
|
@TableField("continue_per_kg")
|
||||||
|
private BigDecimal continuePerKg;
|
||||||
|
|
||||||
|
@TableField("sort_order")
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 快递报价单(公司级)。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_express_quote")
|
||||||
|
public class ExpressQuotePO {
|
||||||
|
|
||||||
|
public static final String MODE_FLAT = "FLAT";
|
||||||
|
public static final String MODE_PER_KG = "PER_KG";
|
||||||
|
public static final String MODE_REGION_WEIGHT = "REGION_WEIGHT";
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("code")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("carrier_code")
|
||||||
|
private String carrierCode;
|
||||||
|
|
||||||
|
@TableField("billing_mode")
|
||||||
|
private String billingMode;
|
||||||
|
|
||||||
|
@TableField("status")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@TableField("remark")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@TableField("create_by")
|
||||||
|
private Long createBy;
|
||||||
|
|
||||||
|
@TableField("update_by")
|
||||||
|
private Long updateBy;
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 报价分区(省份列表 JSON)。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_express_quote_region")
|
||||||
|
public class ExpressQuoteRegionPO {
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("version_id")
|
||||||
|
private Long versionId;
|
||||||
|
|
||||||
|
@TableField("region_name")
|
||||||
|
private String regionName;
|
||||||
|
|
||||||
|
/** 一类/二类等展示标签 */
|
||||||
|
@TableField("zone_label")
|
||||||
|
private String zoneLabel;
|
||||||
|
|
||||||
|
/** 目的地 JSON(省全称或市名) */
|
||||||
|
@TableField("provinces_json")
|
||||||
|
private String provincesJson;
|
||||||
|
|
||||||
|
@TableField("is_default")
|
||||||
|
private Integer isDefault;
|
||||||
|
|
||||||
|
@TableField("sort_order")
|
||||||
|
private Integer sortOrder;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 报价版本(as-of)。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_express_quote_version")
|
||||||
|
public class ExpressQuoteVersionPO {
|
||||||
|
|
||||||
|
public static final String SCOPE_ORDER = "ORDER";
|
||||||
|
public static final String SCOPE_PIECE = "PIECE";
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("quote_id")
|
||||||
|
private Long quoteId;
|
||||||
|
|
||||||
|
@TableField("effective_from")
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
|
||||||
|
@TableField("flat_amount")
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
|
||||||
|
@TableField("unit_scope")
|
||||||
|
private String unitScope;
|
||||||
|
|
||||||
|
@TableField("price_per_kg")
|
||||||
|
private BigDecimal pricePerKg;
|
||||||
|
|
||||||
|
@TableField("min_amount")
|
||||||
|
private BigDecimal minAmount;
|
||||||
|
|
||||||
|
/** 体积重:mm³ / divisor → kg,再 ×1000 得克 */
|
||||||
|
@TableField("volume_divisor")
|
||||||
|
private Integer volumeDivisor;
|
||||||
|
|
||||||
|
@TableField("use_volumetric")
|
||||||
|
private Integer useVolumetric;
|
||||||
|
|
||||||
|
/** NONE / CEIL_KG */
|
||||||
|
@TableField("weight_round")
|
||||||
|
private String weightRound;
|
||||||
|
|
||||||
|
@TableField("remark")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@TableField("create_by")
|
||||||
|
private Long createBy;
|
||||||
|
|
||||||
|
@TableField("update_by")
|
||||||
|
private Long updateBy;
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 仓 ↔ 报价绑定。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_warehouse_express_bind")
|
||||||
|
public class WarehouseExpressBindPO {
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("warehouse_id")
|
||||||
|
private Long warehouseId;
|
||||||
|
|
||||||
|
@TableField("quote_id")
|
||||||
|
private Long quoteId;
|
||||||
|
|
||||||
|
@TableField("priority")
|
||||||
|
private Integer priority;
|
||||||
|
|
||||||
|
@TableField("status")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@TableField("create_by")
|
||||||
|
private Long createBy;
|
||||||
|
|
||||||
|
@TableField("update_by")
|
||||||
|
private Long updateBy;
|
||||||
|
}
|
||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 发货仓库(无库存)。 */
|
||||||
|
@Data
|
||||||
|
@TableName("ec_warehouse")
|
||||||
|
public class WarehousePO {
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField("company_id")
|
||||||
|
private Long companyId;
|
||||||
|
|
||||||
|
@TableField("code")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("province")
|
||||||
|
private String province;
|
||||||
|
|
||||||
|
@TableField("city")
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
@TableField("address")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
/** 0停用 1启用 */
|
||||||
|
@TableField("status")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@TableField("remark")
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
@TableField("create_by")
|
||||||
|
private Long createBy;
|
||||||
|
|
||||||
|
@TableField("update_by")
|
||||||
|
private Long updateBy;
|
||||||
|
}
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 快递报价导入预览。 */
|
||||||
|
@Data
|
||||||
|
public class ExpressQuoteImportVO {
|
||||||
|
|
||||||
|
/** STANDARD / CARRIER_MATRIX */
|
||||||
|
private String format;
|
||||||
|
private boolean success;
|
||||||
|
private String carrierCode;
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private String weightRound;
|
||||||
|
private Integer useVolumetric;
|
||||||
|
private Integer volumeDivisor;
|
||||||
|
private int regionCount;
|
||||||
|
private int destinationCount;
|
||||||
|
private int bandCount;
|
||||||
|
private List<String> warnings = new ArrayList<>();
|
||||||
|
private List<String> errors = new ArrayList<>();
|
||||||
|
private List<RegionPreview> regions = new ArrayList<>();
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class RegionPreview {
|
||||||
|
private String regionName;
|
||||||
|
private String zoneLabel;
|
||||||
|
private List<String> destinations;
|
||||||
|
private int bandCount;
|
||||||
|
private List<BandPreview> bands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BandPreview {
|
||||||
|
private Integer weightFromG;
|
||||||
|
private Integer weightToG;
|
||||||
|
private String priceMode;
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
private Integer firstWeightG;
|
||||||
|
private BigDecimal firstAmount;
|
||||||
|
private BigDecimal continuePerKg;
|
||||||
|
}
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 快递报价 VO。 */
|
||||||
|
@Data
|
||||||
|
public class ExpressQuoteVO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Long companyId;
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private String carrierCode;
|
||||||
|
private String billingMode;
|
||||||
|
private Integer status;
|
||||||
|
private String remark;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
private VersionVO currentVersion;
|
||||||
|
private List<VersionVO> versions;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class VersionVO {
|
||||||
|
private Long id;
|
||||||
|
private Long quoteId;
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
private String unitScope;
|
||||||
|
private BigDecimal pricePerKg;
|
||||||
|
private BigDecimal minAmount;
|
||||||
|
private Integer volumeDivisor;
|
||||||
|
private Integer useVolumetric;
|
||||||
|
private String weightRound;
|
||||||
|
private String remark;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private List<RegionVO> regions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class RegionVO {
|
||||||
|
private Long id;
|
||||||
|
private String regionName;
|
||||||
|
private String zoneLabel;
|
||||||
|
private List<String> provinces;
|
||||||
|
private Integer isDefault;
|
||||||
|
private Integer sortOrder;
|
||||||
|
private List<BandVO> bands;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BandVO {
|
||||||
|
private Long id;
|
||||||
|
private Integer weightFromG;
|
||||||
|
private Integer weightToG;
|
||||||
|
private String priceMode;
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
private Integer firstWeightG;
|
||||||
|
private BigDecimal firstAmount;
|
||||||
|
private BigDecimal continuePerKg;
|
||||||
|
private Integer sortOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/** 仓-报价绑定 VO。 */
|
||||||
|
@Data
|
||||||
|
public class WarehouseExpressBindVO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Long warehouseId;
|
||||||
|
private Long quoteId;
|
||||||
|
private String quoteName;
|
||||||
|
private String quoteCode;
|
||||||
|
private String carrierCode;
|
||||||
|
private String billingMode;
|
||||||
|
private Integer priority;
|
||||||
|
private Integer status;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 仓库 VO。 */
|
||||||
|
@Data
|
||||||
|
public class WarehouseVO {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private Long companyId;
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private String province;
|
||||||
|
private String city;
|
||||||
|
private String address;
|
||||||
|
private Integer status;
|
||||||
|
private String remark;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
/** 已绑定报价数 */
|
||||||
|
private Integer bindCount;
|
||||||
|
/** 默认发此仓的 SKU 数 */
|
||||||
|
private Integer skuCount;
|
||||||
|
private List<WarehouseExpressBindVO> binds;
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeParseException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/** 读取标准模板 Meta 页(key-value)。 */
|
||||||
|
public final class ExpressQuoteImportMetaReader {
|
||||||
|
|
||||||
|
private ExpressQuoteImportMetaReader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void apply(Workbook wb, ExpressQuoteImportModels.Draft draft) {
|
||||||
|
Sheet meta = wb.getSheet("Meta");
|
||||||
|
if (meta == null) {
|
||||||
|
meta = wb.getSheet("meta");
|
||||||
|
}
|
||||||
|
if (meta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
for (int r = 0; r <= meta.getLastRowNum(); r++) {
|
||||||
|
Row row = meta.getRow(r);
|
||||||
|
if (row == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String k = ExpressQuoteMatrixSheetParser.cellText(row, 0);
|
||||||
|
String v = ExpressQuoteMatrixSheetParser.cellText(row, 1);
|
||||||
|
if (StringUtils.hasText(k) && StringUtils.hasText(v)) {
|
||||||
|
map.put(k.trim().toLowerCase(Locale.ROOT), v.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
draft.setFormat("STANDARD");
|
||||||
|
if (map.containsKey("carriercode")) {
|
||||||
|
draft.setCarrierCode(map.get("carriercode"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("code")) {
|
||||||
|
draft.setCode(map.get("code"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("name")) {
|
||||||
|
draft.setName(map.get("name"));
|
||||||
|
}
|
||||||
|
if (map.containsKey("effectivefrom")) {
|
||||||
|
try {
|
||||||
|
draft.setEffectiveFrom(LocalDate.parse(map.get("effectivefrom")));
|
||||||
|
} catch (DateTimeParseException e) {
|
||||||
|
draft.getErrors().add("Meta.effectiveFrom 日期格式应为 yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (map.containsKey("weightround")) {
|
||||||
|
draft.setWeightRound(map.get("weightround").toUpperCase(Locale.ROOT));
|
||||||
|
}
|
||||||
|
if (map.containsKey("usevolumetric")) {
|
||||||
|
draft.setUseVolumetric("1".equals(map.get("usevolumetric")) ? 1 : 0);
|
||||||
|
}
|
||||||
|
if (map.containsKey("volumedivisor")) {
|
||||||
|
try {
|
||||||
|
draft.setVolumeDivisor(Integer.parseInt(map.get("volumedivisor")));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
draft.getErrors().add("Meta.volumeDivisor 须为整数");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (map.containsKey("remark")) {
|
||||||
|
draft.setRemark(map.get("remark"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 报价表格导入中间模型(解析 → 合并 → 落库)。 */
|
||||||
|
public final class ExpressQuoteImportModels {
|
||||||
|
|
||||||
|
private ExpressQuoteImportModels() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class Draft {
|
||||||
|
/** STANDARD / CARRIER_MATRIX */
|
||||||
|
private String format;
|
||||||
|
private String carrierCode;
|
||||||
|
private String code;
|
||||||
|
private String name;
|
||||||
|
private LocalDate effectiveFrom;
|
||||||
|
private String weightRound = "NONE";
|
||||||
|
private Integer useVolumetric = 0;
|
||||||
|
private Integer volumeDivisor = 6000;
|
||||||
|
private String remark;
|
||||||
|
private List<RegionDraft> regions = new ArrayList<>();
|
||||||
|
private List<String> warnings = new ArrayList<>();
|
||||||
|
private List<String> errors = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class RegionDraft {
|
||||||
|
private String regionName;
|
||||||
|
private String zoneLabel;
|
||||||
|
private List<String> destinations = new ArrayList<>();
|
||||||
|
private Integer isDefault = 0;
|
||||||
|
private List<BandDraft> bands = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class BandDraft {
|
||||||
|
private Integer weightFromG;
|
||||||
|
private Integer weightToG;
|
||||||
|
private String priceMode;
|
||||||
|
private BigDecimal flatAmount;
|
||||||
|
private Integer firstWeightG;
|
||||||
|
private BigDecimal firstAmount;
|
||||||
|
private BigDecimal continuePerKg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 矩阵列定义。 */
|
||||||
|
@Data
|
||||||
|
public static class ColumnDef {
|
||||||
|
private int colIndex;
|
||||||
|
private int weightFromG;
|
||||||
|
private Integer weightToG;
|
||||||
|
/** FLAT_TICKET / FIRST_PLUS_KG;空则按单元格推断 */
|
||||||
|
private String defaultPriceMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
+228
@@ -0,0 +1,228 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteImportDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteImportVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.ExpressQuoteService;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报价表格导入:解析(标准 Meta+矩阵 / 承运商多段矩阵)→ 合并 → 预览 / 落库。
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ExpressQuoteImportService {
|
||||||
|
|
||||||
|
private final ExpressQuoteService expressQuoteService;
|
||||||
|
|
||||||
|
public ExpressQuoteImportService(ExpressQuoteService expressQuoteService) {
|
||||||
|
this.expressQuoteService = expressQuoteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] templateBytes() {
|
||||||
|
return ExpressQuoteTemplateWriter.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExpressQuoteImportVO preview(MultipartFile file) {
|
||||||
|
ExpressQuoteImportModels.Draft draft = parseFile(file);
|
||||||
|
return toPreview(draft);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ExpressQuoteVO commit(MultipartFile file, ExpressQuoteImportDtos.Commit params) {
|
||||||
|
ExpressQuoteImportModels.Draft draft = parseFile(file);
|
||||||
|
applyOverrides(draft, params);
|
||||||
|
assertDraftReady(draft);
|
||||||
|
String mode = params.getMode().trim().toUpperCase();
|
||||||
|
if ("CREATE".equals(mode)) {
|
||||||
|
return expressQuoteService.create(toCreateDto(draft));
|
||||||
|
}
|
||||||
|
if ("APPEND_VERSION".equals(mode)) {
|
||||||
|
if (params.getQuoteId() == null) {
|
||||||
|
throw new BusinessException("追加版本须指定 quoteId");
|
||||||
|
}
|
||||||
|
expressQuoteService.requireCompanyQuote(params.getQuoteId());
|
||||||
|
expressQuoteService.upsertVersion(params.getQuoteId(), toVersionDto(draft));
|
||||||
|
return expressQuoteService.detail(params.getQuoteId(), false);
|
||||||
|
}
|
||||||
|
throw new BusinessException("不支持的导入模式: " + params.getMode());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteImportModels.Draft parseFile(MultipartFile file) {
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
throw new BusinessException("请上传 Excel 文件");
|
||||||
|
}
|
||||||
|
String name = file.getOriginalFilename() != null ? file.getOriginalFilename() : "";
|
||||||
|
if (!name.toLowerCase().endsWith(".xlsx") && !name.toLowerCase().endsWith(".xls")) {
|
||||||
|
throw new BusinessException("仅支持 .xlsx / .xls");
|
||||||
|
}
|
||||||
|
try (InputStream in = file.getInputStream(); Workbook wb = WorkbookFactory.create(in)) {
|
||||||
|
ExpressQuoteImportModels.Draft draft = new ExpressQuoteImportModels.Draft();
|
||||||
|
ExpressQuoteImportMetaReader.apply(wb, draft);
|
||||||
|
Sheet quoteSheet = wb.getSheet("报价");
|
||||||
|
if (quoteSheet == null) {
|
||||||
|
quoteSheet = wb.getSheetAt(0);
|
||||||
|
}
|
||||||
|
if (!StringUtils.hasText(draft.getFormat())) {
|
||||||
|
draft.setFormat("CARRIER_MATRIX");
|
||||||
|
}
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> raw =
|
||||||
|
ExpressQuoteMatrixSheetParser.parse(quoteSheet, draft.getErrors(), draft.getWarnings());
|
||||||
|
if (raw.isEmpty() && draft.getErrors().isEmpty()) {
|
||||||
|
draft.getErrors().add("未解析到任何目的地报价行(可解析行均为空或已跳过)");
|
||||||
|
}
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> merged = ExpressQuoteRegionMerger.merge(raw);
|
||||||
|
draft.setRegions(merged);
|
||||||
|
int before = raw.size();
|
||||||
|
int after = merged.size();
|
||||||
|
if (before > after) {
|
||||||
|
draft.getWarnings().add("已按价区+重量带合并分区:" + before + " 行 → " + after + " 个分区");
|
||||||
|
}
|
||||||
|
return draft;
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException("解析 Excel 失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyOverrides(ExpressQuoteImportModels.Draft draft, ExpressQuoteImportDtos.Commit params) {
|
||||||
|
if (params == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(params.getCarrierCode())) {
|
||||||
|
draft.setCarrierCode(params.getCarrierCode());
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(params.getCode())) {
|
||||||
|
draft.setCode(params.getCode());
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(params.getName())) {
|
||||||
|
draft.setName(params.getName());
|
||||||
|
}
|
||||||
|
if (params.getEffectiveFrom() != null) {
|
||||||
|
draft.setEffectiveFrom(params.getEffectiveFrom());
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(params.getWeightRound())) {
|
||||||
|
draft.setWeightRound(params.getWeightRound());
|
||||||
|
}
|
||||||
|
if (params.getUseVolumetric() != null) {
|
||||||
|
draft.setUseVolumetric(params.getUseVolumetric());
|
||||||
|
}
|
||||||
|
if (params.getVolumeDivisor() != null) {
|
||||||
|
draft.setVolumeDivisor(params.getVolumeDivisor());
|
||||||
|
}
|
||||||
|
if (params.getRemark() != null) {
|
||||||
|
draft.setRemark(params.getRemark());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertDraftReady(ExpressQuoteImportModels.Draft draft) {
|
||||||
|
if (draft.getErrors() != null && !draft.getErrors().isEmpty()) {
|
||||||
|
throw new BusinessException("导入失败:\n" + String.join("\n", draft.getErrors()));
|
||||||
|
}
|
||||||
|
if (draft.getRegions() == null || draft.getRegions().isEmpty()) {
|
||||||
|
throw new BusinessException("没有可导入的分区");
|
||||||
|
}
|
||||||
|
if (!StringUtils.hasText(draft.getCarrierCode())) {
|
||||||
|
throw new BusinessException("请填写承运商 carrierCode");
|
||||||
|
}
|
||||||
|
if (!StringUtils.hasText(draft.getCode())) {
|
||||||
|
throw new BusinessException("请填写报价编码 code");
|
||||||
|
}
|
||||||
|
if (!StringUtils.hasText(draft.getName())) {
|
||||||
|
throw new BusinessException("请填写报价名称 name");
|
||||||
|
}
|
||||||
|
if (draft.getEffectiveFrom() == null) {
|
||||||
|
draft.setEffectiveFrom(LocalDate.now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteDtos.Create toCreateDto(ExpressQuoteImportModels.Draft draft) {
|
||||||
|
ExpressQuoteDtos.Create create = new ExpressQuoteDtos.Create();
|
||||||
|
create.setCode(draft.getCode().trim());
|
||||||
|
create.setName(draft.getName().trim());
|
||||||
|
create.setCarrierCode(ExpressCarrierCodes.normalizeCode(draft.getCarrierCode()));
|
||||||
|
create.setBillingMode(ExpressQuotePO.MODE_REGION_WEIGHT);
|
||||||
|
create.setStatus(1);
|
||||||
|
create.setRemark(draft.getRemark());
|
||||||
|
create.setInitialVersion(toVersionDto(draft));
|
||||||
|
return create;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteDtos.VersionUpsert toVersionDto(ExpressQuoteImportModels.Draft draft) {
|
||||||
|
ExpressQuoteDtos.VersionUpsert v = new ExpressQuoteDtos.VersionUpsert();
|
||||||
|
v.setEffectiveFrom(draft.getEffectiveFrom());
|
||||||
|
v.setWeightRound(draft.getWeightRound());
|
||||||
|
v.setUseVolumetric(draft.getUseVolumetric());
|
||||||
|
v.setVolumeDivisor(draft.getVolumeDivisor());
|
||||||
|
v.setRemark(draft.getRemark());
|
||||||
|
v.setRegions(draft.getRegions().stream().map(r -> {
|
||||||
|
ExpressQuoteDtos.RegionUpsert ru = new ExpressQuoteDtos.RegionUpsert();
|
||||||
|
ru.setRegionName(r.getRegionName());
|
||||||
|
ru.setZoneLabel(r.getZoneLabel());
|
||||||
|
ru.setProvinces(r.getDestinations());
|
||||||
|
ru.setIsDefault(r.getIsDefault());
|
||||||
|
ru.setBands(r.getBands().stream().map(b -> {
|
||||||
|
ExpressQuoteDtos.BandUpsert bu = new ExpressQuoteDtos.BandUpsert();
|
||||||
|
BeanCopyUtils.copyProperties(b, bu);
|
||||||
|
return bu;
|
||||||
|
}).toList());
|
||||||
|
return ru;
|
||||||
|
}).toList());
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteImportVO toPreview(ExpressQuoteImportModels.Draft draft) {
|
||||||
|
ExpressQuoteImportVO vo = new ExpressQuoteImportVO();
|
||||||
|
vo.setFormat(draft.getFormat());
|
||||||
|
vo.setCarrierCode(draft.getCarrierCode());
|
||||||
|
vo.setCode(draft.getCode());
|
||||||
|
vo.setName(draft.getName());
|
||||||
|
vo.setEffectiveFrom(draft.getEffectiveFrom());
|
||||||
|
vo.setWeightRound(draft.getWeightRound());
|
||||||
|
vo.setUseVolumetric(draft.getUseVolumetric());
|
||||||
|
vo.setVolumeDivisor(draft.getVolumeDivisor());
|
||||||
|
vo.setWarnings(draft.getWarnings());
|
||||||
|
vo.setErrors(draft.getErrors());
|
||||||
|
vo.setSuccess(draft.getErrors() == null || draft.getErrors().isEmpty());
|
||||||
|
int dest = 0;
|
||||||
|
int bands = 0;
|
||||||
|
for (ExpressQuoteImportModels.RegionDraft r : draft.getRegions()) {
|
||||||
|
ExpressQuoteImportVO.RegionPreview rp = new ExpressQuoteImportVO.RegionPreview();
|
||||||
|
rp.setRegionName(r.getRegionName());
|
||||||
|
rp.setZoneLabel(r.getZoneLabel());
|
||||||
|
rp.setDestinations(r.getDestinations());
|
||||||
|
rp.setBandCount(r.getBands().size());
|
||||||
|
rp.setBands(r.getBands().stream().map(b -> {
|
||||||
|
ExpressQuoteImportVO.BandPreview bp = new ExpressQuoteImportVO.BandPreview();
|
||||||
|
BeanCopyUtils.copyProperties(b, bp);
|
||||||
|
return bp;
|
||||||
|
}).toList());
|
||||||
|
vo.getRegions().add(rp);
|
||||||
|
dest += r.getDestinations().size();
|
||||||
|
bands += r.getBands().size();
|
||||||
|
}
|
||||||
|
vo.setRegionCount(draft.getRegions().size());
|
||||||
|
vo.setDestinationCount(dest);
|
||||||
|
vo.setBandCount(bands);
|
||||||
|
if (vo.isSuccess() && draft.getRegions().isEmpty()) {
|
||||||
|
vo.setSuccess(false);
|
||||||
|
vo.getErrors().add("未解析到任何分区");
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
+239
@@ -0,0 +1,239 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
|
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析承运商矩阵 / 标准模板「报价」页:支持同 Sheet 多段表头。
|
||||||
|
* 空单元格 / 不可解析单元格 / 无有效带的行 → warning 并跳过,不拖垮整单。
|
||||||
|
*/
|
||||||
|
public final class ExpressQuoteMatrixSheetParser {
|
||||||
|
|
||||||
|
private static final DataFormatter FMT = new DataFormatter();
|
||||||
|
|
||||||
|
private ExpressQuoteMatrixSheetParser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ExpressQuoteImportModels.RegionDraft> parse(
|
||||||
|
Sheet sheet, List<String> errors, List<String> warnings) {
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> rows = new ArrayList<>();
|
||||||
|
if (sheet == null) {
|
||||||
|
errors.add("缺少报价工作表");
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
int last = sheet.getLastRowNum();
|
||||||
|
List<ExpressQuoteImportModels.ColumnDef> columns = null;
|
||||||
|
for (int r = 0; r <= last; r++) {
|
||||||
|
Row row = sheet.getRow(r);
|
||||||
|
if (row == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String c0 = cellText(row, 0);
|
||||||
|
|
||||||
|
// 偏远区域行:内嵌新重量表头
|
||||||
|
if (isSectionMarker(c0) && hasWeightHeaders(row, 2)) {
|
||||||
|
columns = readColumnsFromWeightRow(row, 2, null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标准表头行:目的省 | 重量/KG | ranges...
|
||||||
|
if (isDestinationHeader(c0)) {
|
||||||
|
if (hasWeightHeaders(row, 2)) {
|
||||||
|
columns = readColumnsFromWeightRow(row, 2, null);
|
||||||
|
// 下一行可能是模式行
|
||||||
|
Row next = sheet.getRow(r + 1);
|
||||||
|
if (next != null && isModeRow(next, columns)) {
|
||||||
|
applyModes(next, columns);
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 目的省行仅有模式标签,重量在上一偏远行已设
|
||||||
|
if (columns != null) {
|
||||||
|
applyModes(row, columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 独立模式行(上一行已设列)
|
||||||
|
if (columns != null && isModeRow(row, columns) && !looksLikeDestination(c0)) {
|
||||||
|
applyModes(row, columns);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (columns == null || columns.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!looksLikeDestination(c0)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExpressQuoteImportModels.RegionDraft region = parseDataRow(row, columns, warnings, r + 1);
|
||||||
|
if (region != null) {
|
||||||
|
rows.add(region);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExpressQuoteImportModels.RegionDraft parseDataRow(
|
||||||
|
Row row, List<ExpressQuoteImportModels.ColumnDef> columns,
|
||||||
|
List<String> warnings, int excelRow) {
|
||||||
|
String destRaw = cellText(row, 0);
|
||||||
|
if (!StringUtils.hasText(destRaw)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String zone = cellText(row, 1);
|
||||||
|
String dest = normalizeDestination(destRaw);
|
||||||
|
ExpressQuoteImportModels.RegionDraft region = new ExpressQuoteImportModels.RegionDraft();
|
||||||
|
region.setZoneLabel(StringUtils.hasText(zone) ? zone.trim() : null);
|
||||||
|
region.setRegionName(StringUtils.hasText(zone) ? zone.trim() : dest);
|
||||||
|
region.getDestinations().add(dest);
|
||||||
|
|
||||||
|
List<ExpressQuoteImportModels.BandDraft> bands = new ArrayList<>();
|
||||||
|
for (ExpressQuoteImportModels.ColumnDef col : columns) {
|
||||||
|
Object raw = cellValue(row, col.getColIndex());
|
||||||
|
if (raw == null || (raw instanceof String s && !StringUtils.hasText(s))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Optional<ExpressQuoteImportModels.BandDraft> band = PriceCellParser.parse(
|
||||||
|
raw, col.getDefaultPriceMode(), col.getWeightFromG(), col.getWeightToG());
|
||||||
|
band.ifPresent(bands::add);
|
||||||
|
} catch (PriceCellParser.UnparseablePriceException ex) {
|
||||||
|
warnings.add("第" + excelRow + "行「" + destRaw + "」列" + (col.getColIndex() + 1)
|
||||||
|
+ "已跳过(无法解析): " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bands.isEmpty()) {
|
||||||
|
warnings.add("第" + excelRow + "行「" + destRaw + "」无有效重量带,已跳过该目的地");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
region.setBands(bands);
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String normalizeDestination(String raw) {
|
||||||
|
String t = raw.trim();
|
||||||
|
String n = BiRegionNormalizer.normalize(t);
|
||||||
|
return BiRegionNormalizer.isUnknown(n) ? t : n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<ExpressQuoteImportModels.ColumnDef> readColumnsFromWeightRow(
|
||||||
|
Row row, int startCol, List<String> modeHints) {
|
||||||
|
List<ExpressQuoteImportModels.ColumnDef> cols = new ArrayList<>();
|
||||||
|
short last = row.getLastCellNum();
|
||||||
|
for (int c = startCol; c < last; c++) {
|
||||||
|
String text = cellText(row, c);
|
||||||
|
Optional<int[]> range = WeightBandHeaderParser.parseRangeGrams(text);
|
||||||
|
if (range.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ExpressQuoteImportModels.ColumnDef def = new ExpressQuoteImportModels.ColumnDef();
|
||||||
|
def.setColIndex(c);
|
||||||
|
def.setWeightFromG(range.get()[0]);
|
||||||
|
int to = range.get()[1];
|
||||||
|
def.setWeightToG(to < 0 ? null : to);
|
||||||
|
if (modeHints != null && c < modeHints.size()) {
|
||||||
|
def.setDefaultPriceMode(modeHints.get(c));
|
||||||
|
}
|
||||||
|
cols.add(def);
|
||||||
|
}
|
||||||
|
return cols;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyModes(Row row, List<ExpressQuoteImportModels.ColumnDef> columns) {
|
||||||
|
for (ExpressQuoteImportModels.ColumnDef col : columns) {
|
||||||
|
String mode = PriceCellParser.detectModeLabel(cellText(row, col.getColIndex()));
|
||||||
|
if (mode != null) {
|
||||||
|
col.setDefaultPriceMode(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasWeightHeaders(Row row, int startCol) {
|
||||||
|
short last = row.getLastCellNum();
|
||||||
|
for (int c = startCol; c < last; c++) {
|
||||||
|
if (WeightBandHeaderParser.looksLikeWeightHeader(cellText(row, c))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isModeRow(Row row, List<ExpressQuoteImportModels.ColumnDef> columns) {
|
||||||
|
int hit = 0;
|
||||||
|
for (ExpressQuoteImportModels.ColumnDef col : columns) {
|
||||||
|
if (PriceCellParser.detectModeLabel(cellText(row, col.getColIndex())) != null) {
|
||||||
|
hit++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hit >= Math.max(1, columns.size() / 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDestinationHeader(String c0) {
|
||||||
|
return StringUtils.hasText(c0) && (c0.contains("目的") || c0.contains("省份") || "目的省".equals(c0.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSectionMarker(String c0) {
|
||||||
|
return StringUtils.hasText(c0) && (c0.contains("偏远") || c0.contains("区域说明"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean looksLikeDestination(String c0) {
|
||||||
|
if (!StringUtils.hasText(c0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String t = c0.trim();
|
||||||
|
if (t.contains("快递报价") || isDestinationHeader(t) || isSectionMarker(t)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (WeightBandHeaderParser.looksLikeWeightHeader(t)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (PriceCellParser.detectModeLabel(t) != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return t.length() <= 40;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String cellText(Row row, int col) {
|
||||||
|
Cell cell = row.getCell(col);
|
||||||
|
if (cell == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return FMT.formatCellValue(cell).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object cellValue(Row row, int col) {
|
||||||
|
Cell cell = row.getCell(col);
|
||||||
|
if (cell == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CellType type = cell.getCellType();
|
||||||
|
if (type == CellType.FORMULA) {
|
||||||
|
type = cell.getCachedFormulaResultType();
|
||||||
|
}
|
||||||
|
return switch (type) {
|
||||||
|
case NUMERIC -> BigDecimal.valueOf(cell.getNumericCellValue());
|
||||||
|
case STRING -> {
|
||||||
|
String s = cell.getStringCellValue();
|
||||||
|
yield StringUtils.hasText(s) ? s.trim() : null;
|
||||||
|
}
|
||||||
|
case BOOLEAN -> cell.getBooleanCellValue();
|
||||||
|
default -> {
|
||||||
|
String t = FMT.formatCellValue(cell);
|
||||||
|
yield StringUtils.hasText(t) ? t.trim() : null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+100
@@ -0,0 +1,100 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/** 相同价区标签且重量带完全一致 → 合并为一个分区(目的地并集)。 */
|
||||||
|
public final class ExpressQuoteRegionMerger {
|
||||||
|
|
||||||
|
private ExpressQuoteRegionMerger() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ExpressQuoteImportModels.RegionDraft> merge(
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> rows) {
|
||||||
|
Map<String, ExpressQuoteImportModels.RegionDraft> merged = new LinkedHashMap<>();
|
||||||
|
for (ExpressQuoteImportModels.RegionDraft row : rows) {
|
||||||
|
String key = fingerprint(row);
|
||||||
|
ExpressQuoteImportModels.RegionDraft exist = merged.get(key);
|
||||||
|
if (exist == null) {
|
||||||
|
ExpressQuoteImportModels.RegionDraft copy = copyRegion(row);
|
||||||
|
merged.put(key, copy);
|
||||||
|
} else {
|
||||||
|
Set<String> dest = new LinkedHashSet<>(exist.getDestinations());
|
||||||
|
dest.addAll(row.getDestinations());
|
||||||
|
exist.setDestinations(new ArrayList<>(dest));
|
||||||
|
if (!StringUtils.hasText(exist.getZoneLabel()) && StringUtils.hasText(row.getZoneLabel())) {
|
||||||
|
exist.setZoneLabel(row.getZoneLabel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> result = new ArrayList<>(merged.values());
|
||||||
|
int i = 1;
|
||||||
|
for (ExpressQuoteImportModels.RegionDraft r : result) {
|
||||||
|
if (!StringUtils.hasText(r.getRegionName())) {
|
||||||
|
r.setRegionName(StringUtils.hasText(r.getZoneLabel())
|
||||||
|
? r.getZoneLabel()
|
||||||
|
: "分区" + i);
|
||||||
|
}
|
||||||
|
// 合并后名称:价区优先,否则取首个目的地概括
|
||||||
|
if (StringUtils.hasText(r.getZoneLabel())) {
|
||||||
|
r.setRegionName(r.getZoneLabel());
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String fingerprint(ExpressQuoteImportModels.RegionDraft r) {
|
||||||
|
String zone = r.getZoneLabel() != null ? r.getZoneLabel().trim() : "";
|
||||||
|
String bands = r.getBands().stream()
|
||||||
|
.sorted(Comparator
|
||||||
|
.comparing((ExpressQuoteImportModels.BandDraft b) -> b.getWeightFromG() != null ? b.getWeightFromG() : 0)
|
||||||
|
.thenComparing(b -> b.getWeightToG() != null ? b.getWeightToG() : Integer.MAX_VALUE))
|
||||||
|
.map(ExpressQuoteRegionMerger::bandKey)
|
||||||
|
.collect(Collectors.joining("|"));
|
||||||
|
return zone + "#" + bands;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String bandKey(ExpressQuoteImportModels.BandDraft b) {
|
||||||
|
return b.getWeightFromG() + "-" + b.getWeightToG() + ":" + b.getPriceMode()
|
||||||
|
+ ":" + dec(b.getFlatAmount())
|
||||||
|
+ ":" + b.getFirstWeightG()
|
||||||
|
+ ":" + dec(b.getFirstAmount())
|
||||||
|
+ ":" + dec(b.getContinuePerKg());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String dec(BigDecimal v) {
|
||||||
|
return v == null ? "" : v.stripTrailingZeros().toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExpressQuoteImportModels.RegionDraft copyRegion(ExpressQuoteImportModels.RegionDraft src) {
|
||||||
|
ExpressQuoteImportModels.RegionDraft r = new ExpressQuoteImportModels.RegionDraft();
|
||||||
|
r.setRegionName(src.getRegionName());
|
||||||
|
r.setZoneLabel(src.getZoneLabel());
|
||||||
|
r.setIsDefault(src.getIsDefault());
|
||||||
|
r.setDestinations(new ArrayList<>(src.getDestinations()));
|
||||||
|
List<ExpressQuoteImportModels.BandDraft> bands = new ArrayList<>();
|
||||||
|
for (ExpressQuoteImportModels.BandDraft b : src.getBands()) {
|
||||||
|
ExpressQuoteImportModels.BandDraft c = new ExpressQuoteImportModels.BandDraft();
|
||||||
|
c.setWeightFromG(b.getWeightFromG());
|
||||||
|
c.setWeightToG(b.getWeightToG());
|
||||||
|
c.setPriceMode(b.getPriceMode());
|
||||||
|
c.setFlatAmount(b.getFlatAmount());
|
||||||
|
c.setFirstWeightG(b.getFirstWeightG());
|
||||||
|
c.setFirstAmount(b.getFirstAmount());
|
||||||
|
c.setContinuePerKg(b.getContinuePerKg());
|
||||||
|
bands.add(c);
|
||||||
|
}
|
||||||
|
r.setBands(bands);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成标准报价导入模板(Meta + 报价矩阵,单段表头,可直接填数)。
|
||||||
|
*/
|
||||||
|
public final class ExpressQuoteTemplateWriter {
|
||||||
|
|
||||||
|
private ExpressQuoteTemplateWriter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] write() {
|
||||||
|
try (XSSFWorkbook wb = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||||
|
writeMeta(wb.createSheet("Meta"));
|
||||||
|
writeQuote(wb.createSheet("报价"));
|
||||||
|
writeReadme(wb.createSheet("说明"));
|
||||||
|
wb.write(out);
|
||||||
|
return out.toByteArray();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("生成报价模板失败: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeMeta(Sheet sheet) {
|
||||||
|
kv(sheet, 0, "carrierCode", "ZTO");
|
||||||
|
kv(sheet, 1, "code", "ZTO-DEMO");
|
||||||
|
kv(sheet, 2, "name", "中通示范报价");
|
||||||
|
kv(sheet, 3, "effectiveFrom", LocalDate.now().toString());
|
||||||
|
kv(sheet, 4, "weightRound", "NONE");
|
||||||
|
kv(sheet, 5, "useVolumetric", "0");
|
||||||
|
kv(sheet, 6, "volumeDivisor", "6000");
|
||||||
|
kv(sheet, 7, "remark", "");
|
||||||
|
sheet.setColumnWidth(0, 4000);
|
||||||
|
sheet.setColumnWidth(1, 6000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void kv(Sheet sheet, int row, String k, String v) {
|
||||||
|
Row r = sheet.createRow(row);
|
||||||
|
r.createCell(0).setCellValue(k);
|
||||||
|
r.createCell(1).setCellValue(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeQuote(Sheet sheet) {
|
||||||
|
Row title = sheet.createRow(0);
|
||||||
|
title.createCell(0).setCellValue("快递报价表(标准模板)");
|
||||||
|
|
||||||
|
String[] weights = {
|
||||||
|
"0-0.5kg", "0.51-1KG", "1.01-2KG", "2.01-3KG",
|
||||||
|
"3.01-5.5KG", "5.51-9KG", "9.01-10KG", "18.01-20KG"
|
||||||
|
};
|
||||||
|
Row header = sheet.createRow(1);
|
||||||
|
header.createCell(0).setCellValue("目的省");
|
||||||
|
header.createCell(1).setCellValue("重量/KG");
|
||||||
|
for (int i = 0; i < weights.length; i++) {
|
||||||
|
header.createCell(2 + i).setCellValue(weights[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Row mode = sheet.createRow(2);
|
||||||
|
mode.createCell(0).setCellValue("");
|
||||||
|
mode.createCell(1).setCellValue("");
|
||||||
|
for (int i = 0; i < weights.length - 1; i++) {
|
||||||
|
mode.createCell(2 + i).setCellValue("元/票");
|
||||||
|
}
|
||||||
|
mode.createCell(2 + weights.length - 1).setCellValue("首重0kg+续重/kg");
|
||||||
|
|
||||||
|
Object[][] samples = {
|
||||||
|
{"浙江省", "二类", 1.4, 1.6, 1.9, 2.3, 3.6, 5.5, 6, "2+0.7元/kg"},
|
||||||
|
{"北京市", "一类", 2.4, 2.6, 2.7, 3, 4.6, 6.5, 7, "3+0.7元/kg"},
|
||||||
|
{"深圳市", "一类", 2.4, 2.6, 2.7, 3, 4.6, 6.5, 7, "3+0.7元/kg"},
|
||||||
|
};
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
Row row = sheet.createRow(3 + i);
|
||||||
|
Object[] s = samples[i];
|
||||||
|
row.createCell(0).setCellValue(String.valueOf(s[0]));
|
||||||
|
row.createCell(1).setCellValue(String.valueOf(s[1]));
|
||||||
|
for (int c = 2; c < s.length; c++) {
|
||||||
|
Object v = s[c];
|
||||||
|
if (v instanceof Number n) {
|
||||||
|
row.createCell(c).setCellValue(n.doubleValue());
|
||||||
|
} else {
|
||||||
|
row.createCell(c).setCellValue(String.valueOf(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
sheet.setColumnWidth(i, 3500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeReadme(Sheet sheet) {
|
||||||
|
String[] lines = {
|
||||||
|
"1. 填写 Meta 页:carrierCode/code/name/effectiveFrom 必填。",
|
||||||
|
"2. 报价页为矩阵:目的省 + 价区 + 各重量列;同价区且价格相同会自动合并。",
|
||||||
|
"3. 重量表头按字面转克,如 0.51-1KG → 510–1000g。",
|
||||||
|
"4. 单元格支持数字(元/票)或「2+0.7元/kg」(首重+续重);空单元格表示该带无报价。",
|
||||||
|
"5. 「发极兔/转单」等分支文案、无价格的目的地行会跳过并给出警告,不拖垮整单。",
|
||||||
|
"6. 也可直接上传承运商多段矩阵表(无 Meta 时在提交时补全编码/名称/承运商/生效日)。",
|
||||||
|
};
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
sheet.createRow(i).createCell(0).setCellValue(lines[i]);
|
||||||
|
}
|
||||||
|
sheet.setColumnWidth(0, 20000);
|
||||||
|
}
|
||||||
|
}
|
||||||
+120
@@ -0,0 +1,120 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteBandPO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析价格单元格:数值 /「4.5元/票」/「2+0.7元/kg」。
|
||||||
|
* 含业务分支文案(发极兔、转单等)视为不可解析。
|
||||||
|
*/
|
||||||
|
public final class PriceCellParser {
|
||||||
|
|
||||||
|
private static final Pattern FLAT = Pattern.compile(
|
||||||
|
"^\\s*(\\d+(?:\\.\\d+)?)\\s*(?:元)?\\s*/?\\s*票?\\s*$");
|
||||||
|
private static final Pattern FIRST_PLUS = Pattern.compile(
|
||||||
|
"^\\s*(\\d+(?:\\.\\d+)?)\\s*\\+\\s*(\\d+(?:\\.\\d+)?)\\s*(?:元)?\\s*/?\\s*kg\\s*$",
|
||||||
|
Pattern.CASE_INSENSITIVE);
|
||||||
|
private static final Pattern REJECT = Pattern.compile("发|转单|其他快递|极兔|备注");
|
||||||
|
|
||||||
|
private PriceCellParser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<ExpressQuoteImportModels.BandDraft> parse(
|
||||||
|
Object cellValue, String defaultMode, int weightFromG, Integer weightToG) {
|
||||||
|
if (cellValue == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
if (cellValue instanceof Number n) {
|
||||||
|
return Optional.of(buildNumeric(n, defaultMode, weightFromG, weightToG));
|
||||||
|
}
|
||||||
|
String text = String.valueOf(cellValue).trim();
|
||||||
|
if (!StringUtils.hasText(text) || "-".equals(text) || "—".equals(text)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
if (REJECT.matcher(text).find()) {
|
||||||
|
throw new UnparseablePriceException(text);
|
||||||
|
}
|
||||||
|
Matcher fp = FIRST_PLUS.matcher(text.replace(" ", ""));
|
||||||
|
if (fp.matches()) {
|
||||||
|
ExpressQuoteImportModels.BandDraft b = base(weightFromG, weightToG);
|
||||||
|
b.setPriceMode(ExpressQuoteBandPO.MODE_FIRST_PLUS_KG);
|
||||||
|
b.setFirstWeightG(0);
|
||||||
|
b.setFirstAmount(new BigDecimal(fp.group(1)));
|
||||||
|
b.setContinuePerKg(new BigDecimal(fp.group(2)));
|
||||||
|
return Optional.of(b);
|
||||||
|
}
|
||||||
|
Matcher flat = FLAT.matcher(text.replace("元/票", "").replace("元", "").trim());
|
||||||
|
// 再试:完整「4.5元/票」
|
||||||
|
Matcher flat2 = Pattern.compile("^\\s*(\\d+(?:\\.\\d+)?)\\s*元\\s*/\\s*票\\s*$").matcher(text);
|
||||||
|
if (flat2.matches()) {
|
||||||
|
ExpressQuoteImportModels.BandDraft b = base(weightFromG, weightToG);
|
||||||
|
b.setPriceMode(ExpressQuoteBandPO.MODE_FLAT_TICKET);
|
||||||
|
b.setFlatAmount(new BigDecimal(flat2.group(1)));
|
||||||
|
return Optional.of(b);
|
||||||
|
}
|
||||||
|
if (flat.matches() && !text.contains("+")) {
|
||||||
|
ExpressQuoteImportModels.BandDraft b = base(weightFromG, weightToG);
|
||||||
|
String mode = StringUtils.hasText(defaultMode) ? defaultMode : ExpressQuoteBandPO.MODE_FLAT_TICKET;
|
||||||
|
if (ExpressQuoteBandPO.MODE_FIRST_PLUS_KG.equals(mode)) {
|
||||||
|
// 列声明为首重续重但单元格只有数字 → 不可靠,报错
|
||||||
|
throw new UnparseablePriceException(text + "(列为首重+续重,但单元格非 a+b 格式)");
|
||||||
|
}
|
||||||
|
b.setPriceMode(ExpressQuoteBandPO.MODE_FLAT_TICKET);
|
||||||
|
b.setFlatAmount(new BigDecimal(flat.group(1)));
|
||||||
|
return Optional.of(b);
|
||||||
|
}
|
||||||
|
// 纯数字字符串
|
||||||
|
try {
|
||||||
|
BigDecimal n = new BigDecimal(text);
|
||||||
|
return Optional.of(buildNumeric(n, defaultMode, weightFromG, weightToG));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new UnparseablePriceException(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExpressQuoteImportModels.BandDraft buildNumeric(
|
||||||
|
Number n, String defaultMode, int weightFromG, Integer weightToG) {
|
||||||
|
ExpressQuoteImportModels.BandDraft b = base(weightFromG, weightToG);
|
||||||
|
BigDecimal amount = n instanceof BigDecimal bd ? bd : BigDecimal.valueOf(n.doubleValue());
|
||||||
|
String mode = StringUtils.hasText(defaultMode) ? defaultMode : ExpressQuoteBandPO.MODE_FLAT_TICKET;
|
||||||
|
if (ExpressQuoteBandPO.MODE_FIRST_PLUS_KG.equals(mode)) {
|
||||||
|
throw new UnparseablePriceException(amount + "(列为首重+续重,需 a+b元/kg)");
|
||||||
|
}
|
||||||
|
b.setPriceMode(ExpressQuoteBandPO.MODE_FLAT_TICKET);
|
||||||
|
b.setFlatAmount(amount);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ExpressQuoteImportModels.BandDraft base(int from, Integer to) {
|
||||||
|
ExpressQuoteImportModels.BandDraft b = new ExpressQuoteImportModels.BandDraft();
|
||||||
|
b.setWeightFromG(from);
|
||||||
|
b.setWeightToG(to);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String detectModeLabel(String raw) {
|
||||||
|
if (!StringUtils.hasText(raw)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String s = raw.trim();
|
||||||
|
if (s.contains("续重") || s.contains("首重") || s.toLowerCase().contains("/kg")) {
|
||||||
|
return ExpressQuoteBandPO.MODE_FIRST_PLUS_KG;
|
||||||
|
}
|
||||||
|
if (s.contains("元/票") || s.contains("票")) {
|
||||||
|
return ExpressQuoteBandPO.MODE_FLAT_TICKET;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 不可解析价格。 */
|
||||||
|
public static class UnparseablePriceException extends RuntimeException {
|
||||||
|
public UnparseablePriceException(String cell) {
|
||||||
|
super(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析表头重量区间:按字面 kg→克(0.51-1KG → 510–1000g)。
|
||||||
|
*/
|
||||||
|
public final class WeightBandHeaderParser {
|
||||||
|
|
||||||
|
private static final Pattern RANGE = Pattern.compile(
|
||||||
|
"^\\s*(\\d+(?:\\.\\d+)?)\\s*[-~~到至]\\s*(\\d+(?:\\.\\d+)?)\\s*(?:kg|KG|Kg)?\\s*$");
|
||||||
|
private static final Pattern OPEN = Pattern.compile(
|
||||||
|
"^\\s*(\\d+(?:\\.\\d+)?)\\s*\\+\\s*(?:kg|KG|Kg)?\\s*$");
|
||||||
|
|
||||||
|
private WeightBandHeaderParser() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<int[]> parseRangeGrams(String raw) {
|
||||||
|
if (!StringUtils.hasText(raw)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
String s = raw.trim()
|
||||||
|
.replace("重量", "")
|
||||||
|
.replace("/KG", "")
|
||||||
|
.replace("/kg", "")
|
||||||
|
.trim();
|
||||||
|
Matcher m = RANGE.matcher(s);
|
||||||
|
if (m.matches()) {
|
||||||
|
int from = kgToGrams(m.group(1));
|
||||||
|
int to = kgToGrams(m.group(2));
|
||||||
|
if (from < 0 || to < from) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(new int[]{from, to});
|
||||||
|
}
|
||||||
|
Matcher open = OPEN.matcher(s);
|
||||||
|
if (open.matches()) {
|
||||||
|
int from = kgToGrams(open.group(1));
|
||||||
|
return Optional.of(new int[]{from, -1}); // -1 = 无上限
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** kg 字面转克:0.51 → 510。 */
|
||||||
|
public static int kgToGrams(String kgText) {
|
||||||
|
BigDecimal kg = new BigDecimal(kgText.trim());
|
||||||
|
return kg.multiply(BigDecimal.valueOf(1000)).setScale(0, RoundingMode.HALF_UP).intValueExact();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean looksLikeWeightHeader(String raw) {
|
||||||
|
return parseRangeGrams(raw).isPresent();
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service;
|
||||||
|
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 快递报价单与版本。 */
|
||||||
|
public interface ExpressQuoteService {
|
||||||
|
|
||||||
|
ExpressQuoteVO create(ExpressQuoteDtos.Create dto);
|
||||||
|
|
||||||
|
ExpressQuoteVO update(ExpressQuoteDtos.Update dto, Long id);
|
||||||
|
|
||||||
|
void delete(Long id);
|
||||||
|
|
||||||
|
PageResultVO<ExpressQuoteVO> page(PageQueryDTO<ExpressQuoteDtos.Filter> query);
|
||||||
|
|
||||||
|
List<ExpressQuoteVO> listEnabled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 报价详情。
|
||||||
|
*
|
||||||
|
* @param withHistory true=加载全部版本的分区/重量带(详情抽屉);false=仅当前版本明细(编辑页)
|
||||||
|
*/
|
||||||
|
ExpressQuoteVO detail(Long id, boolean withHistory);
|
||||||
|
|
||||||
|
ExpressQuotePO requireCompanyQuote(Long id);
|
||||||
|
|
||||||
|
/** 追加或覆盖同日版本(含分区阶梯)。 */
|
||||||
|
ExpressQuoteVO.VersionVO upsertVersion(Long quoteId, ExpressQuoteDtos.VersionUpsert dto);
|
||||||
|
|
||||||
|
void deleteVersion(Long versionId);
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service;
|
||||||
|
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.vo.ProductSkuVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** 发货仓库、报价绑定与仓商品分配。 */
|
||||||
|
public interface WarehouseService {
|
||||||
|
|
||||||
|
WarehouseVO create(WarehouseDtos.Create dto);
|
||||||
|
|
||||||
|
WarehouseVO update(WarehouseDtos.Update dto, Long id);
|
||||||
|
|
||||||
|
void delete(Long id);
|
||||||
|
|
||||||
|
PageResultVO<WarehouseVO> page(PageQueryDTO<WarehouseDtos.Filter> query);
|
||||||
|
|
||||||
|
List<WarehouseVO> listEnabled();
|
||||||
|
|
||||||
|
WarehouseVO detail(Long id);
|
||||||
|
|
||||||
|
WarehousePO requireCompanyWarehouse(Long id);
|
||||||
|
|
||||||
|
WarehouseExpressBindVO addBind(WarehouseDtos.BindCreate dto);
|
||||||
|
|
||||||
|
WarehouseExpressBindVO updateBind(WarehouseDtos.BindUpdate dto, Long bindId);
|
||||||
|
|
||||||
|
void removeBind(Long bindId);
|
||||||
|
|
||||||
|
List<WarehouseExpressBindVO> listBinds(Long warehouseId);
|
||||||
|
|
||||||
|
/** 按仓/未分配筛选 SKU(仓权限) */
|
||||||
|
PageResultVO<ProductSkuVO> pageSkus(PageQueryDTO<WarehouseDtos.SkuFilter> query);
|
||||||
|
|
||||||
|
/** 未分配默认仓的 SKU 数量 */
|
||||||
|
long countUnassignedSkus();
|
||||||
|
|
||||||
|
/** 批量设置/清空 SKU 默认发货仓 */
|
||||||
|
int batchAssignSkus(WarehouseDtos.SkuBatchAssign dto);
|
||||||
|
}
|
||||||
+555
@@ -0,0 +1,555 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatDirtyDayService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.support.BiRegionNormalizer;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteBandMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteRegionMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteVersionMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.ExpressQuoteDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteBandPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteRegionPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuoteVersionPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.ExpressQuoteVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.ExpressQuoteService;
|
||||||
|
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/** 快递报价单与版本编排。 */
|
||||||
|
@Service
|
||||||
|
public class ExpressQuoteServiceImpl extends ServiceImpl<ExpressQuoteMapper, ExpressQuotePO>
|
||||||
|
implements ExpressQuoteService {
|
||||||
|
|
||||||
|
private final CurrentUserContext currentUserContext;
|
||||||
|
private final ExpressQuoteVersionMapper versionMapper;
|
||||||
|
private final ExpressQuoteRegionMapper regionMapper;
|
||||||
|
private final ExpressQuoteBandMapper bandMapper;
|
||||||
|
private final WarehouseExpressBindMapper bindMapper;
|
||||||
|
private final ProductSkuMapper productSkuMapper;
|
||||||
|
private final BiOrderStatDirtyDayService dirtyDayService;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
public ExpressQuoteServiceImpl(CurrentUserContext currentUserContext,
|
||||||
|
ExpressQuoteVersionMapper versionMapper,
|
||||||
|
ExpressQuoteRegionMapper regionMapper,
|
||||||
|
ExpressQuoteBandMapper bandMapper,
|
||||||
|
WarehouseExpressBindMapper bindMapper,
|
||||||
|
ProductSkuMapper productSkuMapper,
|
||||||
|
BiOrderStatDirtyDayService dirtyDayService,
|
||||||
|
ObjectMapper objectMapper) {
|
||||||
|
this.currentUserContext = currentUserContext;
|
||||||
|
this.versionMapper = versionMapper;
|
||||||
|
this.regionMapper = regionMapper;
|
||||||
|
this.bandMapper = bandMapper;
|
||||||
|
this.bindMapper = bindMapper;
|
||||||
|
this.productSkuMapper = productSkuMapper;
|
||||||
|
this.dirtyDayService = dirtyDayService;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ExpressQuoteVO create(ExpressQuoteDtos.Create dto) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
assertCodeUnique(companyId, dto.getCode().trim(), null);
|
||||||
|
validateMode(dto.getBillingMode());
|
||||||
|
ExpressQuotePO po = new ExpressQuotePO();
|
||||||
|
po.setCompanyId(companyId);
|
||||||
|
po.setCode(dto.getCode().trim());
|
||||||
|
po.setName(dto.getName().trim());
|
||||||
|
po.setCarrierCode(ExpressCarrierCodes.normalizeCode(dto.getCarrierCode()));
|
||||||
|
po.setBillingMode(dto.getBillingMode().trim().toUpperCase());
|
||||||
|
po.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
|
||||||
|
po.setRemark(dto.getRemark());
|
||||||
|
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||||
|
save(po);
|
||||||
|
if (dto.getInitialVersion() != null) {
|
||||||
|
upsertVersionInternal(po, dto.getInitialVersion());
|
||||||
|
}
|
||||||
|
return detail(po.getId(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ExpressQuoteVO update(ExpressQuoteDtos.Update dto, Long id) {
|
||||||
|
ExpressQuotePO po = requireCompanyQuote(id);
|
||||||
|
po.setName(dto.getName().trim());
|
||||||
|
po.setCarrierCode(ExpressCarrierCodes.normalizeCode(dto.getCarrierCode()));
|
||||||
|
if (dto.getStatus() != null) {
|
||||||
|
po.setStatus(dto.getStatus());
|
||||||
|
}
|
||||||
|
po.setRemark(dto.getRemark());
|
||||||
|
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
|
updateById(po);
|
||||||
|
markDirtyForQuote(po.getId(), null);
|
||||||
|
return detail(id, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void delete(Long id) {
|
||||||
|
ExpressQuotePO po = requireCompanyQuote(id);
|
||||||
|
Long bindCount = bindMapper.selectCount(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getQuoteId, id));
|
||||||
|
if (bindCount != null && bindCount > 0) {
|
||||||
|
throw new BusinessException("仍有仓库绑定此报价,请先解绑");
|
||||||
|
}
|
||||||
|
List<ExpressQuoteVersionPO> versions = versionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, id));
|
||||||
|
for (ExpressQuoteVersionPO v : versions) {
|
||||||
|
deleteVersionCascade(v.getId());
|
||||||
|
}
|
||||||
|
removeById(po.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResultVO<ExpressQuoteVO> page(PageQueryDTO<ExpressQuoteDtos.Filter> query) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
LambdaQueryWrapper<ExpressQuotePO> w = new LambdaQueryWrapper<ExpressQuotePO>()
|
||||||
|
.eq(ExpressQuotePO::getCompanyId, companyId);
|
||||||
|
ExpressQuoteDtos.Filter f = query.getFilters();
|
||||||
|
if (f != null) {
|
||||||
|
if (StringUtils.hasText(f.getKeywords())) {
|
||||||
|
String kw = f.getKeywords().trim();
|
||||||
|
w.and(x -> x.like(ExpressQuotePO::getName, kw).or().like(ExpressQuotePO::getCode, kw));
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(f.getCarrierCode())) {
|
||||||
|
w.eq(ExpressQuotePO::getCarrierCode, f.getCarrierCode().trim().toUpperCase());
|
||||||
|
}
|
||||||
|
if (StringUtils.hasText(f.getBillingMode())) {
|
||||||
|
w.eq(ExpressQuotePO::getBillingMode, f.getBillingMode().trim().toUpperCase());
|
||||||
|
}
|
||||||
|
if (f.getStatus() != null) {
|
||||||
|
w.eq(ExpressQuotePO::getStatus, f.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.orderByDesc(ExpressQuotePO::getId);
|
||||||
|
Page<ExpressQuotePO> page = page(new Page<>(query.getPage(), query.getPageSize()), w);
|
||||||
|
List<ExpressQuoteVO> records = page.getRecords().stream().map(p -> toBriefVo(p)).toList();
|
||||||
|
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ExpressQuoteVO> listEnabled() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
return list(new LambdaQueryWrapper<ExpressQuotePO>()
|
||||||
|
.eq(ExpressQuotePO::getCompanyId, companyId)
|
||||||
|
.eq(ExpressQuotePO::getStatus, 1)
|
||||||
|
.orderByAsc(ExpressQuotePO::getCode)).stream()
|
||||||
|
.map(this::toBriefVo)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExpressQuoteVO detail(Long id, boolean withHistory) {
|
||||||
|
ExpressQuotePO po = requireCompanyQuote(id);
|
||||||
|
ExpressQuoteVO vo = new ExpressQuoteVO();
|
||||||
|
BeanCopyUtils.copyProperties(po, vo);
|
||||||
|
|
||||||
|
List<ExpressQuoteVersionPO> versions = versionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, id)
|
||||||
|
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||||
|
.orderByDesc(ExpressQuoteVersionPO::getId));
|
||||||
|
if (versions.isEmpty()) {
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 编辑页只要当前版本明细;详情抽屉再拉全历史分区(避免 N 版 × 2 次查询)
|
||||||
|
List<ExpressQuoteVersionPO> versionsToExpand = withHistory
|
||||||
|
? versions
|
||||||
|
: List.of(versions.get(0));
|
||||||
|
List<Long> expandIds = versionsToExpand.stream().map(ExpressQuoteVersionPO::getId).toList();
|
||||||
|
|
||||||
|
Map<Long, List<ExpressQuoteRegionPO>> regionsByVersion = Map.of();
|
||||||
|
Map<Long, List<ExpressQuoteBandPO>> bandsByRegion = Map.of();
|
||||||
|
if (!expandIds.isEmpty()) {
|
||||||
|
List<ExpressQuoteRegionPO> allRegions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||||
|
.in(ExpressQuoteRegionPO::getVersionId, expandIds)
|
||||||
|
.orderByAsc(ExpressQuoteRegionPO::getSortOrder)
|
||||||
|
.orderByAsc(ExpressQuoteRegionPO::getId));
|
||||||
|
regionsByVersion = allRegions.stream()
|
||||||
|
.collect(Collectors.groupingBy(ExpressQuoteRegionPO::getVersionId, LinkedHashMap::new, Collectors.toList()));
|
||||||
|
|
||||||
|
List<Long> regionIds = allRegions.stream().map(ExpressQuoteRegionPO::getId).toList();
|
||||||
|
if (!regionIds.isEmpty()) {
|
||||||
|
List<ExpressQuoteBandPO> allBands = bandMapper.selectList(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||||
|
.in(ExpressQuoteBandPO::getRegionId, regionIds)
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getSortOrder)
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getWeightFromG)
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getId));
|
||||||
|
bandsByRegion = allBands.stream()
|
||||||
|
.collect(Collectors.groupingBy(ExpressQuoteBandPO::getRegionId, LinkedHashMap::new, Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ExpressQuoteVO.VersionVO> versionVos = new ArrayList<>(versions.size());
|
||||||
|
for (ExpressQuoteVersionPO v : versions) {
|
||||||
|
boolean expand = expandIds.contains(v.getId());
|
||||||
|
versionVos.add(toVersionVo(
|
||||||
|
v,
|
||||||
|
expand,
|
||||||
|
expand ? regionsByVersion.getOrDefault(v.getId(), List.of()) : List.of(),
|
||||||
|
expand ? bandsByRegion : Map.of()));
|
||||||
|
}
|
||||||
|
vo.setVersions(versionVos);
|
||||||
|
vo.setCurrentVersion(versionVos.get(0));
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ExpressQuotePO requireCompanyQuote(Long id) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
ExpressQuotePO po = getById(id);
|
||||||
|
if (po == null || !Objects.equals(po.getCompanyId(), companyId)) {
|
||||||
|
throw new BusinessException("报价单不存在");
|
||||||
|
}
|
||||||
|
return po;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public ExpressQuoteVO.VersionVO upsertVersion(Long quoteId, ExpressQuoteDtos.VersionUpsert dto) {
|
||||||
|
ExpressQuotePO quote = requireCompanyQuote(quoteId);
|
||||||
|
ExpressQuoteVersionPO version = upsertVersionInternal(quote, dto);
|
||||||
|
markDirtyForQuote(quoteId, dto.getEffectiveFrom());
|
||||||
|
return toVersionVo(version, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void deleteVersion(Long versionId) {
|
||||||
|
ExpressQuoteVersionPO version = versionMapper.selectById(versionId);
|
||||||
|
if (version == null) {
|
||||||
|
throw new BusinessException("报价版本不存在");
|
||||||
|
}
|
||||||
|
requireCompanyQuote(version.getQuoteId());
|
||||||
|
Long remaining = versionMapper.selectCount(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, version.getQuoteId())
|
||||||
|
.ne(ExpressQuoteVersionPO::getId, versionId));
|
||||||
|
if (remaining == null || remaining == 0) {
|
||||||
|
throw new BusinessException("至少保留一个报价版本");
|
||||||
|
}
|
||||||
|
deleteVersionCascade(versionId);
|
||||||
|
markDirtyForQuote(version.getQuoteId(), version.getEffectiveFrom());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteVersionPO upsertVersionInternal(ExpressQuotePO quote, ExpressQuoteDtos.VersionUpsert dto) {
|
||||||
|
if (dto == null || dto.getEffectiveFrom() == null) {
|
||||||
|
throw new BusinessException("生效日不能为空");
|
||||||
|
}
|
||||||
|
validateVersionPayload(quote.getBillingMode(), dto);
|
||||||
|
ExpressQuoteVersionPO existing = versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, quote.getId())
|
||||||
|
.eq(ExpressQuoteVersionPO::getEffectiveFrom, dto.getEffectiveFrom())
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
ExpressQuoteVersionPO version;
|
||||||
|
if (existing != null) {
|
||||||
|
version = existing;
|
||||||
|
applyVersionFields(version, dto);
|
||||||
|
version.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
|
versionMapper.updateById(version);
|
||||||
|
clearRegionsAndBands(version.getId());
|
||||||
|
} else {
|
||||||
|
version = new ExpressQuoteVersionPO();
|
||||||
|
version.setCompanyId(quote.getCompanyId());
|
||||||
|
version.setQuoteId(quote.getId());
|
||||||
|
version.setEffectiveFrom(dto.getEffectiveFrom());
|
||||||
|
applyVersionFields(version, dto);
|
||||||
|
version.setCreateBy(currentUserContext.getCurrentUserId());
|
||||||
|
versionMapper.insert(version);
|
||||||
|
}
|
||||||
|
if (ExpressQuotePO.MODE_REGION_WEIGHT.equals(quote.getBillingMode())) {
|
||||||
|
saveRegions(quote.getCompanyId(), version.getId(), dto.getRegions());
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyVersionFields(ExpressQuoteVersionPO version, ExpressQuoteDtos.VersionUpsert dto) {
|
||||||
|
version.setFlatAmount(dto.getFlatAmount());
|
||||||
|
version.setUnitScope(dto.getUnitScope() != null ? dto.getUnitScope().trim().toUpperCase() : null);
|
||||||
|
version.setPricePerKg(dto.getPricePerKg());
|
||||||
|
version.setMinAmount(dto.getMinAmount());
|
||||||
|
version.setVolumeDivisor(dto.getVolumeDivisor() != null ? dto.getVolumeDivisor() : 6000);
|
||||||
|
version.setUseVolumetric(dto.getUseVolumetric() != null ? dto.getUseVolumetric() : 0);
|
||||||
|
String round = dto.getWeightRound() != null ? dto.getWeightRound().trim().toUpperCase() : "NONE";
|
||||||
|
if (!"CEIL_KG".equals(round)) {
|
||||||
|
round = "NONE";
|
||||||
|
}
|
||||||
|
version.setWeightRound(round);
|
||||||
|
version.setRemark(dto.getRemark());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveRegions(Long companyId, Long versionId, List<ExpressQuoteDtos.RegionUpsert> regions) {
|
||||||
|
if (regions == null || regions.isEmpty()) {
|
||||||
|
throw new BusinessException("分区重量模式至少配置一个分区");
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (ExpressQuoteDtos.RegionUpsert r : regions) {
|
||||||
|
if (r.getBands() == null || r.getBands().isEmpty()) {
|
||||||
|
throw new BusinessException("分区「" + r.getRegionName() + "」至少配置一条重量带");
|
||||||
|
}
|
||||||
|
ExpressQuoteRegionPO region = new ExpressQuoteRegionPO();
|
||||||
|
region.setCompanyId(companyId);
|
||||||
|
region.setVersionId(versionId);
|
||||||
|
region.setRegionName(r.getRegionName().trim());
|
||||||
|
region.setZoneLabel(StringUtils.hasText(r.getZoneLabel()) ? r.getZoneLabel().trim() : null);
|
||||||
|
region.setProvincesJson(toDestinationsJson(r.getProvinces()));
|
||||||
|
region.setIsDefault(r.getIsDefault() != null ? r.getIsDefault() : 0);
|
||||||
|
region.setSortOrder(r.getSortOrder() != null ? r.getSortOrder() : i++);
|
||||||
|
regionMapper.insert(region);
|
||||||
|
int bi = 0;
|
||||||
|
for (ExpressQuoteDtos.BandUpsert b : r.getBands()) {
|
||||||
|
saveBand(companyId, versionId, region.getId(), b, bi++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveBand(Long companyId, Long versionId, Long regionId,
|
||||||
|
ExpressQuoteDtos.BandUpsert b, int defaultOrder) {
|
||||||
|
String mode = b.getPriceMode().trim().toUpperCase();
|
||||||
|
if (!ExpressQuoteBandPO.MODE_FLAT_TICKET.equals(mode)
|
||||||
|
&& !ExpressQuoteBandPO.MODE_FIRST_PLUS_KG.equals(mode)) {
|
||||||
|
throw new BusinessException("不支持的重量带计价方式: " + b.getPriceMode());
|
||||||
|
}
|
||||||
|
int from = b.getWeightFromG() != null ? b.getWeightFromG() : 0;
|
||||||
|
Integer to = b.getWeightToG();
|
||||||
|
if (from < 0 || (to != null && to < from)) {
|
||||||
|
throw new BusinessException("重量带区间无效");
|
||||||
|
}
|
||||||
|
ExpressQuoteBandPO band = new ExpressQuoteBandPO();
|
||||||
|
band.setCompanyId(companyId);
|
||||||
|
band.setVersionId(versionId);
|
||||||
|
band.setRegionId(regionId);
|
||||||
|
band.setWeightFromG(from);
|
||||||
|
band.setWeightToG(to);
|
||||||
|
band.setPriceMode(mode);
|
||||||
|
band.setSortOrder(b.getSortOrder() != null ? b.getSortOrder() : defaultOrder);
|
||||||
|
if (ExpressQuoteBandPO.MODE_FLAT_TICKET.equals(mode)) {
|
||||||
|
if (b.getFlatAmount() == null) {
|
||||||
|
throw new BusinessException("元/票金额不能为空");
|
||||||
|
}
|
||||||
|
band.setFlatAmount(b.getFlatAmount());
|
||||||
|
} else {
|
||||||
|
if (b.getFirstAmount() == null || b.getContinuePerKg() == null) {
|
||||||
|
throw new BusinessException("首重价与续重元/kg 不能为空");
|
||||||
|
}
|
||||||
|
band.setFirstWeightG(b.getFirstWeightG() != null ? b.getFirstWeightG() : 0);
|
||||||
|
band.setFirstAmount(b.getFirstAmount());
|
||||||
|
band.setContinuePerKg(b.getContinuePerKg());
|
||||||
|
}
|
||||||
|
bandMapper.insert(band);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 目的地:能归一为省全称则用全称,否则保留原名(如深圳市)。 */
|
||||||
|
private String toDestinationsJson(List<String> destinations) {
|
||||||
|
try {
|
||||||
|
Set<String> normalized = new HashSet<>();
|
||||||
|
if (destinations != null) {
|
||||||
|
for (String p : destinations) {
|
||||||
|
if (!StringUtils.hasText(p)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String raw = p.trim();
|
||||||
|
String n = BiRegionNormalizer.normalize(raw);
|
||||||
|
normalized.add(BiRegionNormalizer.isUnknown(n) ? raw : n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return objectMapper.writeValueAsString(normalized.stream().sorted().toList());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException("目的地列表序列化失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> parseProvinces(String json) {
|
||||||
|
if (!StringUtils.hasText(json)) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return objectMapper.readValue(json, new TypeReference<List<String>>() {
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateMode(String mode) {
|
||||||
|
if (!StringUtils.hasText(mode)) {
|
||||||
|
throw new BusinessException("计费模式不能为空");
|
||||||
|
}
|
||||||
|
String m = mode.trim().toUpperCase();
|
||||||
|
if (!ExpressQuotePO.MODE_FLAT.equals(m)
|
||||||
|
&& !ExpressQuotePO.MODE_PER_KG.equals(m)
|
||||||
|
&& !ExpressQuotePO.MODE_REGION_WEIGHT.equals(m)) {
|
||||||
|
throw new BusinessException("不支持的计费模式: " + mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateVersionPayload(String billingMode, ExpressQuoteDtos.VersionUpsert dto) {
|
||||||
|
if (ExpressQuotePO.MODE_FLAT.equals(billingMode)) {
|
||||||
|
if (dto.getFlatAmount() == null) {
|
||||||
|
throw new BusinessException("一口价金额不能为空");
|
||||||
|
}
|
||||||
|
String scope = dto.getUnitScope() != null ? dto.getUnitScope().trim().toUpperCase() : "";
|
||||||
|
if (!ExpressQuoteVersionPO.SCOPE_ORDER.equals(scope)
|
||||||
|
&& !ExpressQuoteVersionPO.SCOPE_PIECE.equals(scope)) {
|
||||||
|
throw new BusinessException("一口价须指定 ORDER 或 PIECE");
|
||||||
|
}
|
||||||
|
} else if (ExpressQuotePO.MODE_PER_KG.equals(billingMode)) {
|
||||||
|
if (dto.getPricePerKg() == null) {
|
||||||
|
throw new BusinessException("每千克单价不能为空");
|
||||||
|
}
|
||||||
|
} else if (ExpressQuotePO.MODE_REGION_WEIGHT.equals(billingMode)) {
|
||||||
|
if (dto.getRegions() == null || dto.getRegions().isEmpty()) {
|
||||||
|
throw new BusinessException("请配置目的分区与重量带");
|
||||||
|
}
|
||||||
|
for (ExpressQuoteDtos.RegionUpsert r : dto.getRegions()) {
|
||||||
|
if (r.getBands() == null || r.getBands().isEmpty()) {
|
||||||
|
throw new BusinessException("分区「" + r.getRegionName() + "」至少一条重量带");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearRegionsAndBands(Long versionId) {
|
||||||
|
List<ExpressQuoteRegionPO> oldRegions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||||
|
.eq(ExpressQuoteRegionPO::getVersionId, versionId));
|
||||||
|
for (ExpressQuoteRegionPO r : oldRegions) {
|
||||||
|
bandMapper.delete(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||||
|
.eq(ExpressQuoteBandPO::getRegionId, r.getId()));
|
||||||
|
}
|
||||||
|
regionMapper.delete(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||||
|
.eq(ExpressQuoteRegionPO::getVersionId, versionId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteVersionCascade(Long versionId) {
|
||||||
|
clearRegionsAndBands(versionId);
|
||||||
|
versionMapper.deleteById(versionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markDirtyForQuote(Long quoteId, java.time.LocalDate effectiveFrom) {
|
||||||
|
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getQuoteId, quoteId)
|
||||||
|
.eq(WarehouseExpressBindPO::getStatus, 1));
|
||||||
|
if (binds.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Set<Long> warehouseIds = binds.stream().map(WarehouseExpressBindPO::getWarehouseId).collect(Collectors.toSet());
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Long userId = currentUserContext.getCurrentUserId();
|
||||||
|
java.time.LocalDate from = effectiveFrom != null ? effectiveFrom : java.time.LocalDate.now().minusYears(1);
|
||||||
|
List<ProductSkuPO> skus = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.in(ProductSkuPO::getWarehouseId, warehouseIds)
|
||||||
|
.select(ProductSkuPO::getId));
|
||||||
|
for (ProductSkuPO sku : skus) {
|
||||||
|
dirtyDayService.markAfterFreightQuoteChange(companyId, sku.getId(), from, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertCodeUnique(Long companyId, String code, Long excludeId) {
|
||||||
|
LambdaQueryWrapper<ExpressQuotePO> w = new LambdaQueryWrapper<ExpressQuotePO>()
|
||||||
|
.eq(ExpressQuotePO::getCompanyId, companyId)
|
||||||
|
.eq(ExpressQuotePO::getCode, code);
|
||||||
|
if (excludeId != null) {
|
||||||
|
w.ne(ExpressQuotePO::getId, excludeId);
|
||||||
|
}
|
||||||
|
if (count(w) > 0) {
|
||||||
|
throw new BusinessException("报价编码已存在: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteVO toBriefVo(ExpressQuotePO po) {
|
||||||
|
ExpressQuoteVO vo = new ExpressQuoteVO();
|
||||||
|
BeanCopyUtils.copyProperties(po, vo);
|
||||||
|
ExpressQuoteVersionPO current = versionMapper.selectOne(new LambdaQueryWrapper<ExpressQuoteVersionPO>()
|
||||||
|
.eq(ExpressQuoteVersionPO::getQuoteId, po.getId())
|
||||||
|
.orderByDesc(ExpressQuoteVersionPO::getEffectiveFrom)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
if (current != null) {
|
||||||
|
vo.setCurrentVersion(toVersionVo(current, false));
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ExpressQuoteVO.VersionVO toVersionVo(ExpressQuoteVersionPO v, boolean withRegions) {
|
||||||
|
if (!withRegions) {
|
||||||
|
ExpressQuoteVO.VersionVO vo = new ExpressQuoteVO.VersionVO();
|
||||||
|
BeanCopyUtils.copyProperties(v, vo);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
List<ExpressQuoteRegionPO> regions = regionMapper.selectList(new LambdaQueryWrapper<ExpressQuoteRegionPO>()
|
||||||
|
.eq(ExpressQuoteRegionPO::getVersionId, v.getId())
|
||||||
|
.orderByAsc(ExpressQuoteRegionPO::getSortOrder));
|
||||||
|
List<Long> regionIds = regions.stream().map(ExpressQuoteRegionPO::getId).toList();
|
||||||
|
Map<Long, List<ExpressQuoteBandPO>> bandsByRegion = Map.of();
|
||||||
|
if (!regionIds.isEmpty()) {
|
||||||
|
List<ExpressQuoteBandPO> bands = bandMapper.selectList(new LambdaQueryWrapper<ExpressQuoteBandPO>()
|
||||||
|
.in(ExpressQuoteBandPO::getRegionId, regionIds)
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getSortOrder)
|
||||||
|
.orderByAsc(ExpressQuoteBandPO::getWeightFromG));
|
||||||
|
bandsByRegion = bands.stream().collect(Collectors.groupingBy(ExpressQuoteBandPO::getRegionId));
|
||||||
|
}
|
||||||
|
return toVersionVo(v, true, regions, bandsByRegion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 用预取的分区/重量带组装,避免详情 N+1 */
|
||||||
|
private ExpressQuoteVO.VersionVO toVersionVo(
|
||||||
|
ExpressQuoteVersionPO v,
|
||||||
|
boolean withRegions,
|
||||||
|
List<ExpressQuoteRegionPO> regions,
|
||||||
|
Map<Long, List<ExpressQuoteBandPO>> bandsByRegion) {
|
||||||
|
ExpressQuoteVO.VersionVO vo = new ExpressQuoteVO.VersionVO();
|
||||||
|
BeanCopyUtils.copyProperties(v, vo);
|
||||||
|
if (!withRegions) {
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
List<ExpressQuoteVO.RegionVO> regionVos = new ArrayList<>(regions.size());
|
||||||
|
for (ExpressQuoteRegionPO r : regions) {
|
||||||
|
ExpressQuoteVO.RegionVO rv = new ExpressQuoteVO.RegionVO();
|
||||||
|
rv.setId(r.getId());
|
||||||
|
rv.setRegionName(r.getRegionName());
|
||||||
|
rv.setZoneLabel(r.getZoneLabel());
|
||||||
|
rv.setProvinces(parseProvinces(r.getProvincesJson()));
|
||||||
|
rv.setIsDefault(r.getIsDefault());
|
||||||
|
rv.setSortOrder(r.getSortOrder());
|
||||||
|
List<ExpressQuoteVO.BandVO> bandVos = new ArrayList<>();
|
||||||
|
for (ExpressQuoteBandPO b : bandsByRegion.getOrDefault(r.getId(), List.of())) {
|
||||||
|
ExpressQuoteVO.BandVO bv = new ExpressQuoteVO.BandVO();
|
||||||
|
BeanCopyUtils.copyProperties(b, bv);
|
||||||
|
bandVos.add(bv);
|
||||||
|
}
|
||||||
|
rv.setBands(bandVos);
|
||||||
|
regionVos.add(rv);
|
||||||
|
}
|
||||||
|
regionVos.sort(Comparator.comparing(r -> r.getSortOrder() != null ? r.getSortOrder() : 0));
|
||||||
|
vo.setRegions(regionVos);
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
+387
@@ -0,0 +1,387 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.bi.orderstat.service.BiOrderStatDirtyDayService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.mapper.ProductSkuMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.dto.ProductSkuFilterDTO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.vo.ProductSkuVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.service.ProductSkuService;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.freight.ExpressCarrierCodes;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.ExpressQuoteMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseExpressBindMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.mapper.WarehouseMapper;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.dto.WarehouseDtos;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.ExpressQuotePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehouseExpressBindPO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.po.WarehousePO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseExpressBindVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.model.vo.WarehouseVO;
|
||||||
|
import top.xyquan.ecomdmbbackend.modules.ec.warehouse.service.WarehouseService;
|
||||||
|
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/** 仓库 CRUD + 报价绑定。 */
|
||||||
|
@Service
|
||||||
|
public class WarehouseServiceImpl extends ServiceImpl<WarehouseMapper, WarehousePO> implements WarehouseService {
|
||||||
|
|
||||||
|
private final CurrentUserContext currentUserContext;
|
||||||
|
private final WarehouseExpressBindMapper bindMapper;
|
||||||
|
private final ExpressQuoteMapper quoteMapper;
|
||||||
|
private final ProductSkuMapper productSkuMapper;
|
||||||
|
private final ProductSkuService productSkuService;
|
||||||
|
private final BiOrderStatDirtyDayService dirtyDayService;
|
||||||
|
|
||||||
|
public WarehouseServiceImpl(CurrentUserContext currentUserContext,
|
||||||
|
WarehouseExpressBindMapper bindMapper,
|
||||||
|
ExpressQuoteMapper quoteMapper,
|
||||||
|
ProductSkuMapper productSkuMapper,
|
||||||
|
ProductSkuService productSkuService,
|
||||||
|
BiOrderStatDirtyDayService dirtyDayService) {
|
||||||
|
this.currentUserContext = currentUserContext;
|
||||||
|
this.bindMapper = bindMapper;
|
||||||
|
this.quoteMapper = quoteMapper;
|
||||||
|
this.productSkuMapper = productSkuMapper;
|
||||||
|
this.productSkuService = productSkuService;
|
||||||
|
this.dirtyDayService = dirtyDayService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public WarehouseVO create(WarehouseDtos.Create dto) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
assertCodeUnique(companyId, dto.getCode().trim(), null);
|
||||||
|
WarehousePO po = new WarehousePO();
|
||||||
|
BeanCopyUtils.copyProperties(dto, po);
|
||||||
|
po.setCode(dto.getCode().trim());
|
||||||
|
po.setCompanyId(companyId);
|
||||||
|
if (po.getStatus() == null) {
|
||||||
|
po.setStatus(1);
|
||||||
|
}
|
||||||
|
po.setCreateBy(currentUserContext.getCurrentUserId());
|
||||||
|
save(po);
|
||||||
|
return toVo(po, false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public WarehouseVO update(WarehouseDtos.Update dto, Long id) {
|
||||||
|
WarehousePO po = requireCompanyWarehouse(id);
|
||||||
|
po.setName(dto.getName());
|
||||||
|
po.setProvince(dto.getProvince());
|
||||||
|
po.setCity(dto.getCity());
|
||||||
|
po.setAddress(dto.getAddress());
|
||||||
|
po.setRemark(dto.getRemark());
|
||||||
|
if (dto.getStatus() != null) {
|
||||||
|
po.setStatus(dto.getStatus());
|
||||||
|
}
|
||||||
|
po.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
|
updateById(po);
|
||||||
|
Map<Long, Integer> skuCounts = loadSkuCounts(po.getCompanyId());
|
||||||
|
return toVo(po, true, skuCounts.getOrDefault(po.getId(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void delete(Long id) {
|
||||||
|
WarehousePO po = requireCompanyWarehouse(id);
|
||||||
|
Long skuCount = productSkuMapper.selectCount(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getWarehouseId, id));
|
||||||
|
if (skuCount != null && skuCount > 0) {
|
||||||
|
throw new BusinessException("仍有 " + skuCount + " 个 SKU 默认发此仓,请先解绑");
|
||||||
|
}
|
||||||
|
bindMapper.delete(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getWarehouseId, id));
|
||||||
|
removeById(po.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResultVO<WarehouseVO> page(PageQueryDTO<WarehouseDtos.Filter> query) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
LambdaQueryWrapper<WarehousePO> w = new LambdaQueryWrapper<WarehousePO>()
|
||||||
|
.eq(WarehousePO::getCompanyId, companyId);
|
||||||
|
WarehouseDtos.Filter f = query.getFilters();
|
||||||
|
if (f != null) {
|
||||||
|
if (StringUtils.hasText(f.getKeywords())) {
|
||||||
|
String kw = f.getKeywords().trim();
|
||||||
|
w.and(x -> x.like(WarehousePO::getName, kw).or().like(WarehousePO::getCode, kw));
|
||||||
|
}
|
||||||
|
if (f.getStatus() != null) {
|
||||||
|
w.eq(WarehousePO::getStatus, f.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.orderByDesc(WarehousePO::getId);
|
||||||
|
Page<WarehousePO> page = page(new Page<>(query.getPage(), query.getPageSize()), w);
|
||||||
|
Map<Long, Integer> skuCounts = loadSkuCounts(companyId);
|
||||||
|
List<WarehouseVO> records = page.getRecords().stream()
|
||||||
|
.map(p -> toVo(p, false, skuCounts.getOrDefault(p.getId(), 0)))
|
||||||
|
.toList();
|
||||||
|
return PageResultVO.create(records, page.getTotal(), query.getPage(), query.getPageSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WarehouseVO> listEnabled() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Map<Long, Integer> skuCounts = loadSkuCounts(companyId);
|
||||||
|
return list(new LambdaQueryWrapper<WarehousePO>()
|
||||||
|
.eq(WarehousePO::getCompanyId, companyId)
|
||||||
|
.eq(WarehousePO::getStatus, 1)
|
||||||
|
.orderByAsc(WarehousePO::getCode)).stream()
|
||||||
|
.map(p -> toVo(p, false, skuCounts.getOrDefault(p.getId(), 0)))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WarehouseVO detail(Long id) {
|
||||||
|
WarehousePO po = requireCompanyWarehouse(id);
|
||||||
|
Map<Long, Integer> skuCounts = loadSkuCounts(po.getCompanyId());
|
||||||
|
return toVo(po, true, skuCounts.getOrDefault(po.getId(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResultVO<ProductSkuVO> pageSkus(PageQueryDTO<WarehouseDtos.SkuFilter> query) {
|
||||||
|
ProductSkuFilterDTO skuFilter = new ProductSkuFilterDTO();
|
||||||
|
WarehouseDtos.SkuFilter f = query.getFilters();
|
||||||
|
if (f != null) {
|
||||||
|
skuFilter.setKeywords(f.getKeywords());
|
||||||
|
skuFilter.setWarehouseId(f.getWarehouseId());
|
||||||
|
skuFilter.setUnassignedOnly(f.getUnassignedOnly());
|
||||||
|
}
|
||||||
|
PageQueryDTO<ProductSkuFilterDTO> pageQuery = new PageQueryDTO<>();
|
||||||
|
pageQuery.setPage(query.getPage());
|
||||||
|
pageQuery.setPageSize(query.getPageSize());
|
||||||
|
pageQuery.setFilters(skuFilter);
|
||||||
|
return productSkuService.getProductSkuPage(pageQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long countUnassignedSkus() {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Long count = productSkuMapper.selectCount(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.isNull(ProductSkuPO::getWarehouseId));
|
||||||
|
return count == null ? 0L : count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public int batchAssignSkus(WarehouseDtos.SkuBatchAssign dto) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
Long userId = currentUserContext.getCurrentUserId();
|
||||||
|
Long targetWarehouseId = dto.getWarehouseId();
|
||||||
|
if (targetWarehouseId != null) {
|
||||||
|
requireCompanyWarehouse(targetWarehouseId);
|
||||||
|
}
|
||||||
|
List<Long> skuIds = dto.getSkuIds().stream().filter(Objects::nonNull).distinct().toList();
|
||||||
|
if (skuIds.isEmpty()) {
|
||||||
|
throw new BusinessException("请选择 SKU");
|
||||||
|
}
|
||||||
|
List<ProductSkuPO> skus = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.in(ProductSkuPO::getId, skuIds));
|
||||||
|
if (skus.size() != skuIds.size()) {
|
||||||
|
throw new BusinessException("部分 SKU 不存在或不属于本公司");
|
||||||
|
}
|
||||||
|
LocalDate from = LocalDate.now().minusYears(1);
|
||||||
|
int updated = 0;
|
||||||
|
for (ProductSkuPO sku : skus) {
|
||||||
|
if (Objects.equals(sku.getWarehouseId(), targetWarehouseId)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 允许 warehouseId 置空(取消分配)
|
||||||
|
productSkuMapper.update(null, new LambdaUpdateWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getId, sku.getId())
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.set(ProductSkuPO::getWarehouseId, targetWarehouseId)
|
||||||
|
.set(ProductSkuPO::getUpdateBy, userId));
|
||||||
|
dirtyDayService.markAfterFreightQuoteChange(companyId, sku.getId(), from, userId);
|
||||||
|
updated++;
|
||||||
|
}
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WarehousePO requireCompanyWarehouse(Long id) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
WarehousePO po = getById(id);
|
||||||
|
if (po == null || !Objects.equals(po.getCompanyId(), companyId)) {
|
||||||
|
throw new BusinessException("仓库不存在");
|
||||||
|
}
|
||||||
|
return po;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public WarehouseExpressBindVO addBind(WarehouseDtos.BindCreate dto) {
|
||||||
|
WarehousePO wh = requireCompanyWarehouse(dto.getWarehouseId());
|
||||||
|
ExpressQuotePO quote = quoteMapper.selectById(dto.getQuoteId());
|
||||||
|
if (quote == null || !Objects.equals(quote.getCompanyId(), wh.getCompanyId())) {
|
||||||
|
throw new BusinessException("报价单不存在");
|
||||||
|
}
|
||||||
|
Long exists = bindMapper.selectCount(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getWarehouseId, wh.getId())
|
||||||
|
.eq(WarehouseExpressBindPO::getQuoteId, quote.getId()));
|
||||||
|
if (exists != null && exists > 0) {
|
||||||
|
throw new BusinessException("该仓已绑定此报价单");
|
||||||
|
}
|
||||||
|
WarehouseExpressBindPO bind = new WarehouseExpressBindPO();
|
||||||
|
bind.setCompanyId(wh.getCompanyId());
|
||||||
|
bind.setWarehouseId(wh.getId());
|
||||||
|
bind.setQuoteId(quote.getId());
|
||||||
|
bind.setPriority(dto.getPriority() != null ? dto.getPriority() : 100);
|
||||||
|
bind.setStatus(dto.getStatus() != null ? dto.getStatus() : 1);
|
||||||
|
bind.setCreateBy(currentUserContext.getCurrentUserId());
|
||||||
|
bindMapper.insert(bind);
|
||||||
|
markFreightDirtyForWarehouse(wh.getCompanyId(), wh.getId());
|
||||||
|
return toBindVo(bind, quote);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public WarehouseExpressBindVO updateBind(WarehouseDtos.BindUpdate dto, Long bindId) {
|
||||||
|
WarehouseExpressBindPO bind = requireBind(bindId);
|
||||||
|
if (dto.getPriority() != null) {
|
||||||
|
bind.setPriority(dto.getPriority());
|
||||||
|
}
|
||||||
|
if (dto.getStatus() != null) {
|
||||||
|
bind.setStatus(dto.getStatus());
|
||||||
|
}
|
||||||
|
bind.setUpdateBy(currentUserContext.getCurrentUserId());
|
||||||
|
bindMapper.updateById(bind);
|
||||||
|
markFreightDirtyForWarehouse(bind.getCompanyId(), bind.getWarehouseId());
|
||||||
|
ExpressQuotePO quote = quoteMapper.selectById(bind.getQuoteId());
|
||||||
|
return toBindVo(bind, quote);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void removeBind(Long bindId) {
|
||||||
|
WarehouseExpressBindPO bind = requireBind(bindId);
|
||||||
|
bindMapper.deleteById(bindId);
|
||||||
|
markFreightDirtyForWarehouse(bind.getCompanyId(), bind.getWarehouseId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WarehouseExpressBindVO> listBinds(Long warehouseId) {
|
||||||
|
requireCompanyWarehouse(warehouseId);
|
||||||
|
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getWarehouseId, warehouseId)
|
||||||
|
.orderByAsc(WarehouseExpressBindPO::getPriority)
|
||||||
|
.orderByAsc(WarehouseExpressBindPO::getId));
|
||||||
|
return toBindVos(binds);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markFreightDirtyForWarehouse(Long companyId, Long warehouseId) {
|
||||||
|
List<ProductSkuPO> skus = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.eq(ProductSkuPO::getWarehouseId, warehouseId)
|
||||||
|
.select(ProductSkuPO::getId));
|
||||||
|
Long userId = currentUserContext.getCurrentUserId();
|
||||||
|
LocalDate from = LocalDate.now().minusYears(1);
|
||||||
|
for (ProductSkuPO sku : skus) {
|
||||||
|
dirtyDayService.markAfterFreightQuoteChange(companyId, sku.getId(), from, userId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private WarehouseExpressBindPO requireBind(Long bindId) {
|
||||||
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
WarehouseExpressBindPO bind = bindMapper.selectById(bindId);
|
||||||
|
if (bind == null || !Objects.equals(bind.getCompanyId(), companyId)) {
|
||||||
|
throw new BusinessException("绑定不存在");
|
||||||
|
}
|
||||||
|
return bind;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertCodeUnique(Long companyId, String code, Long excludeId) {
|
||||||
|
LambdaQueryWrapper<WarehousePO> w = new LambdaQueryWrapper<WarehousePO>()
|
||||||
|
.eq(WarehousePO::getCompanyId, companyId)
|
||||||
|
.eq(WarehousePO::getCode, code);
|
||||||
|
if (excludeId != null) {
|
||||||
|
w.ne(WarehousePO::getId, excludeId);
|
||||||
|
}
|
||||||
|
if (count(w) > 0) {
|
||||||
|
throw new BusinessException("仓库编码已存在: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 按仓汇总默认 SKU 数 */
|
||||||
|
private Map<Long, Integer> loadSkuCounts(Long companyId) {
|
||||||
|
List<ProductSkuPO> rows = productSkuMapper.selectList(new LambdaQueryWrapper<ProductSkuPO>()
|
||||||
|
.eq(ProductSkuPO::getCompanyId, companyId)
|
||||||
|
.isNotNull(ProductSkuPO::getWarehouseId)
|
||||||
|
.select(ProductSkuPO::getWarehouseId));
|
||||||
|
Map<Long, Integer> counts = new HashMap<>();
|
||||||
|
for (ProductSkuPO row : rows) {
|
||||||
|
if (row.getWarehouseId() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
counts.merge(row.getWarehouseId(), 1, Integer::sum);
|
||||||
|
}
|
||||||
|
return counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
private WarehouseVO toVo(WarehousePO po, boolean withBinds, int skuCount) {
|
||||||
|
WarehouseVO vo = new WarehouseVO();
|
||||||
|
BeanCopyUtils.copyProperties(po, vo);
|
||||||
|
List<WarehouseExpressBindPO> binds = bindMapper.selectList(new LambdaQueryWrapper<WarehouseExpressBindPO>()
|
||||||
|
.eq(WarehouseExpressBindPO::getWarehouseId, po.getId()));
|
||||||
|
vo.setBindCount(binds.size());
|
||||||
|
vo.setSkuCount(skuCount);
|
||||||
|
if (withBinds) {
|
||||||
|
vo.setBinds(toBindVos(binds));
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WarehouseExpressBindVO> toBindVos(List<WarehouseExpressBindPO> binds) {
|
||||||
|
if (binds == null || binds.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
List<Long> quoteIds = binds.stream().map(WarehouseExpressBindPO::getQuoteId).distinct().toList();
|
||||||
|
Map<Long, ExpressQuotePO> quoteMap = new HashMap<>();
|
||||||
|
if (!quoteIds.isEmpty()) {
|
||||||
|
for (ExpressQuotePO q : quoteMapper.selectByIds(quoteIds)) {
|
||||||
|
quoteMap.put(q.getId(), q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return binds.stream()
|
||||||
|
.sorted((a, b) -> {
|
||||||
|
int pa = a.getPriority() != null ? a.getPriority() : 100;
|
||||||
|
int pb = b.getPriority() != null ? b.getPriority() : 100;
|
||||||
|
if (pa != pb) {
|
||||||
|
return Integer.compare(pa, pb);
|
||||||
|
}
|
||||||
|
return Long.compare(a.getId(), b.getId());
|
||||||
|
})
|
||||||
|
.map(b -> toBindVo(b, quoteMap.get(b.getQuoteId())))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private WarehouseExpressBindVO toBindVo(WarehouseExpressBindPO bind, ExpressQuotePO quote) {
|
||||||
|
WarehouseExpressBindVO vo = new WarehouseExpressBindVO();
|
||||||
|
BeanCopyUtils.copyProperties(bind, vo);
|
||||||
|
if (quote != null) {
|
||||||
|
vo.setQuoteName(quote.getName());
|
||||||
|
vo.setQuoteCode(quote.getCode());
|
||||||
|
vo.setCarrierCode(ExpressCarrierCodes.normalizeCode(quote.getCarrierCode()));
|
||||||
|
vo.setBillingMode(quote.getBillingMode());
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-4
@@ -60,15 +60,17 @@ public class DepartmentController {
|
|||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@RequirePermission(value = "org:department:read", description = "查询全部部门", allowSuper = true)
|
@RequirePermission(value = "org:department:read", description = "查询全部部门", allowSuper = true)
|
||||||
public ApiResponse<List<DepartmentVO>> getAllDepartments() {
|
public ApiResponse<List<DepartmentVO>> getAllDepartments(
|
||||||
List<DepartmentVO> result = departmentService.getAllDepartments();
|
@RequestParam(required = false) Long companyId) {
|
||||||
|
List<DepartmentVO> result = departmentService.getAllDepartments(companyId);
|
||||||
return ApiResponse.success("获取全部部门成功", result);
|
return ApiResponse.success("获取全部部门成功", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tree")
|
@GetMapping("/tree")
|
||||||
@RequirePermission(value = "org:department:read", description = "查询部门树", allowSuper = true)
|
@RequirePermission(value = "org:department:read", description = "查询部门树", allowSuper = true)
|
||||||
public ApiResponse<List<DepartmentVO>> getDepartmentTree() {
|
public ApiResponse<List<DepartmentVO>> getDepartmentTree(
|
||||||
List<DepartmentVO> result = departmentService.getDepartmentTree();
|
@RequestParam(required = false) Long companyId) {
|
||||||
|
List<DepartmentVO> result = departmentService.getDepartmentTree(companyId);
|
||||||
return ApiResponse.success("获取部门树成功", result);
|
return ApiResponse.success("获取部门树成功", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -22,4 +22,9 @@ public class DepartmentFilterDTO {
|
|||||||
* 状态
|
* 状态
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司ID(仅超管可跨公司查询)
|
||||||
|
*/
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -55,6 +55,14 @@ public interface DepartmentService extends IService<DepartmentPO> {
|
|||||||
*/
|
*/
|
||||||
List<DepartmentVO> getAllDepartments();
|
List<DepartmentVO> getAllDepartments();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司全部部门(companyId 为空则取当前公司;跨公司仅超管)
|
||||||
|
*
|
||||||
|
* @param companyId 公司ID,可空
|
||||||
|
* @return 部门列表
|
||||||
|
*/
|
||||||
|
List<DepartmentVO> getAllDepartments(Long companyId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前公司部门树
|
* 获取当前公司部门树
|
||||||
*
|
*
|
||||||
@@ -62,6 +70,14 @@ public interface DepartmentService extends IService<DepartmentPO> {
|
|||||||
*/
|
*/
|
||||||
List<DepartmentVO> getDepartmentTree();
|
List<DepartmentVO> getDepartmentTree();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司部门树(companyId 为空则取当前公司;跨公司仅超管)
|
||||||
|
*
|
||||||
|
* @param companyId 公司ID,可空
|
||||||
|
* @return 部门树
|
||||||
|
*/
|
||||||
|
List<DepartmentVO> getDepartmentTree(Long companyId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为指定公司创建部门(用于初始化)
|
* 为指定公司创建部门(用于初始化)
|
||||||
*
|
*
|
||||||
|
|||||||
+35
-20
@@ -158,6 +158,19 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析查询用公司ID:超管可传 companyId 跨公司;否则强制当前公司。
|
||||||
|
*/
|
||||||
|
private Long resolveCompanyId(Long requestedCompanyId) {
|
||||||
|
if (requestedCompanyId == null) {
|
||||||
|
return currentUserContext.getCurrentCompanyId();
|
||||||
|
}
|
||||||
|
if (!currentUserContext.isCurrentUserSuper()) {
|
||||||
|
throw new BusinessException("无权跨公司查询部门");
|
||||||
|
}
|
||||||
|
return requestedCompanyId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门分页列表
|
* 获取部门分页列表
|
||||||
* @param pageQueryDTO 分页查询DTO
|
* @param pageQueryDTO 分页查询DTO
|
||||||
@@ -165,14 +178,11 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResultVO<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO) {
|
public PageResultVO<DepartmentVO> getDepartmentPage(PageQueryDTO<DepartmentFilterDTO> pageQueryDTO) {
|
||||||
// 从token中获取公司ID
|
DepartmentFilterDTO queryDTO = pageQueryDTO.getFilters();
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = resolveCompanyId(queryDTO != null ? queryDTO.getCompanyId() : null);
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
// 添加过滤条件
|
|
||||||
DepartmentFilterDTO queryDTO = pageQueryDTO.getFilters();
|
|
||||||
if (queryDTO != null) {
|
if (queryDTO != null) {
|
||||||
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
||||||
wrapper.like(DepartmentPO::getName, queryDTO.getName());
|
wrapper.like(DepartmentPO::getName, queryDTO.getName());
|
||||||
@@ -184,37 +194,36 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
wrapper.eq(DepartmentPO::getStatus, queryDTO.getStatus());
|
wrapper.eq(DepartmentPO::getStatus, queryDTO.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 强制添加公司ID过滤条件
|
|
||||||
wrapper.eq(DepartmentPO::getCompanyId, companyId);
|
wrapper.eq(DepartmentPO::getCompanyId, companyId);
|
||||||
|
|
||||||
// 排序
|
|
||||||
wrapper.orderByAsc(DepartmentPO::getCreateTime);
|
wrapper.orderByAsc(DepartmentPO::getCreateTime);
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
Page<DepartmentPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
Page<DepartmentPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||||
IPage<DepartmentPO> pageResult = this.page(page, wrapper);
|
IPage<DepartmentPO> pageResult = this.page(page, wrapper);
|
||||||
|
|
||||||
// 转换为VO
|
|
||||||
List<DepartmentVO> records = pageResult.getRecords().stream()
|
List<DepartmentVO> records = pageResult.getRecords().stream()
|
||||||
.map(this::convertToVO)
|
.map(this::convertToVO)
|
||||||
.toList();
|
.toList();
|
||||||
PageResultVO<DepartmentVO> result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
return PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
||||||
pageQueryDTO.getPageSize());
|
pageQueryDTO.getPageSize());
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前公司全部部门
|
* 获取当前公司全部部门
|
||||||
*
|
|
||||||
* @return 部门列表
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<DepartmentVO> getAllDepartments() {
|
public List<DepartmentVO> getAllDepartments() {
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
return getAllDepartments(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司全部部门
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DepartmentVO> getAllDepartments(Long companyId) {
|
||||||
|
Long resolvedCompanyId = resolveCompanyId(companyId);
|
||||||
|
|
||||||
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<DepartmentPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(DepartmentPO::getCompanyId, companyId)
|
wrapper.eq(DepartmentPO::getCompanyId, resolvedCompanyId)
|
||||||
.orderByAsc(DepartmentPO::getCreateTime);
|
.orderByAsc(DepartmentPO::getCreateTime);
|
||||||
|
|
||||||
return this.list(wrapper).stream()
|
return this.list(wrapper).stream()
|
||||||
@@ -224,12 +233,18 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前公司部门树
|
* 获取当前公司部门树
|
||||||
*
|
|
||||||
* @return 部门树
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<DepartmentVO> getDepartmentTree() {
|
public List<DepartmentVO> getDepartmentTree() {
|
||||||
List<DepartmentVO> allDepartments = getAllDepartments();
|
return getDepartmentTree(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定公司部门树
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<DepartmentVO> getDepartmentTree(Long companyId) {
|
||||||
|
List<DepartmentVO> allDepartments = getAllDepartments(companyId);
|
||||||
if (allDepartments.isEmpty()) {
|
if (allDepartments.isEmpty()) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -17,4 +17,9 @@ public class PositionFilterDTO {
|
|||||||
* 状态
|
* 状态
|
||||||
*/
|
*/
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公司ID(仅超管可跨公司查询)
|
||||||
|
*/
|
||||||
|
private Long companyId;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-13
@@ -147,6 +147,19 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
|||||||
this.removeById(id);
|
this.removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析查询用公司ID:超管可传 companyId 跨公司;否则强制当前公司。
|
||||||
|
*/
|
||||||
|
private Long resolveCompanyId(Long requestedCompanyId) {
|
||||||
|
if (requestedCompanyId == null) {
|
||||||
|
return currentUserContext.getCurrentCompanyId();
|
||||||
|
}
|
||||||
|
if (!currentUserContext.isCurrentUserSuper()) {
|
||||||
|
throw new BusinessException("无权跨公司查询岗位");
|
||||||
|
}
|
||||||
|
return requestedCompanyId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取岗位分页列表
|
* 获取岗位分页列表
|
||||||
* @param pageQueryDTO 分页查询DTO
|
* @param pageQueryDTO 分页查询DTO
|
||||||
@@ -154,14 +167,11 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResultVO<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO) {
|
public PageResultVO<PositionVO> getPositionPage(PageQueryDTO<PositionFilterDTO> pageQueryDTO) {
|
||||||
// 从token中获取公司ID
|
PositionFilterDTO queryDTO = pageQueryDTO.getFilters();
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = resolveCompanyId(queryDTO != null ? queryDTO.getCompanyId() : null);
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
LambdaQueryWrapper<PositionPO> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<PositionPO> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
// 添加过滤条件
|
|
||||||
PositionFilterDTO queryDTO = pageQueryDTO.getFilters();
|
|
||||||
if (queryDTO != null) {
|
if (queryDTO != null) {
|
||||||
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
if (queryDTO.getName() != null && StringUtils.hasText(queryDTO.getName())) {
|
||||||
wrapper.like(PositionPO::getName, queryDTO.getName());
|
wrapper.like(PositionPO::getName, queryDTO.getName());
|
||||||
@@ -170,24 +180,17 @@ public class PositionServiceImpl extends ServiceImpl<PositionMapper, PositionPO>
|
|||||||
wrapper.eq(PositionPO::getStatus, queryDTO.getStatus());
|
wrapper.eq(PositionPO::getStatus, queryDTO.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 强制添加公司ID过滤条件
|
|
||||||
wrapper.eq(PositionPO::getCompanyId, companyId);
|
wrapper.eq(PositionPO::getCompanyId, companyId);
|
||||||
|
|
||||||
// 排序
|
|
||||||
wrapper.orderByAsc(PositionPO::getCreateTime);
|
wrapper.orderByAsc(PositionPO::getCreateTime);
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
Page<PositionPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
Page<PositionPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||||
IPage<PositionPO> pageResult = this.page(page, wrapper);
|
IPage<PositionPO> pageResult = this.page(page, wrapper);
|
||||||
|
|
||||||
// 转换为VO
|
|
||||||
List<PositionVO> records = pageResult.getRecords().stream()
|
List<PositionVO> records = pageResult.getRecords().stream()
|
||||||
.map(this::convertToVO)
|
.map(this::convertToVO)
|
||||||
.toList();
|
.toList();
|
||||||
PageResultVO<PositionVO> result = PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
return PageResultVO.create(records, pageResult.getTotal(), pageQueryDTO.getPage(),
|
||||||
pageQueryDTO.getPageSize());
|
pageQueryDTO.getPageSize());
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ public class CreateSysAccountDTO {
|
|||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
@Size(min = 8, max = 20, message = "密码长度必须在8-20个字符之间")
|
@Size(min = 6, max = 20, message = "密码长度必须在6-20个字符之间")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
@NotBlank(message = "用户姓名不能为空")
|
@NotBlank(message = "用户姓名不能为空")
|
||||||
|
|||||||
@@ -727,6 +727,10 @@ INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path
|
|||||||
SELECT 14006, NULL, 0, 'ProductCatalog', '经营商品', '/product', '', '', 'icon-park-outline:ad-product', 'catalog', 1, 1, 0, 5
|
SELECT 14006, NULL, 0, 'ProductCatalog', '经营商品', '/product', '', '', 'icon-park-outline:ad-product', 'catalog', 1, 1, 0, 5
|
||||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14006 OR `route_name` = 'ProductCatalog');
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14006 OR `route_name` = 'ProductCatalog');
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
|
SELECT 14019, NULL, 0, 'FreightCatalog', '发货物流', '/freight', '', '', 'lucide:truck', 'catalog', 1, 1, 0, 6
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14019 OR `route_name` = 'FreightCatalog');
|
||||||
|
|
||||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
SELECT 2, (SELECT id FROM `sys_menu` WHERE `id` = 1 OR `title` = '系统设置' LIMIT 1), 1, 'MenuManagement', '系统菜单', '/sys/menu', '/sys/menu/index', '', 'lucide:menu', 'menu', 1, 1, 0, 1
|
SELECT 2, (SELECT id FROM `sys_menu` WHERE `id` = 1 OR `title` = '系统设置' LIMIT 1), 1, 'MenuManagement', '系统菜单', '/sys/menu', '/sys/menu/index', '', 'lucide:menu', 'menu', 1, 1, 0, 1
|
||||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 2 OR `route_name` = 'MenuManagement');
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 2 OR `route_name` = 'MenuManagement');
|
||||||
@@ -798,6 +802,16 @@ INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path
|
|||||||
SELECT 43, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `title` = '电商页面' LIMIT 1), 0, 'ProductOverview', '商品概览', '/ec/product/overview/:id', '/ec/product/overview/index', '', 'lets-icons:chart', 'embedded', 0, 1, 1, 2
|
SELECT 43, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `title` = '电商页面' LIMIT 1), 0, 'ProductOverview', '商品概览', '/ec/product/overview/:id', '/ec/product/overview/index', '', 'lets-icons:chart', 'embedded', 0, 1, 1, 2
|
||||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 43 OR `route_name` = 'ProductOverview');
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 43 OR `route_name` = 'ProductOverview');
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
|
SELECT 14023, (SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `title` = '发货物流' OR `route_name` = 'FreightCatalog' LIMIT 1), 0,
|
||||||
|
'WarehouseSkuManagement', '发货仓商品', '/ec/warehouse/sku', '/ec/warehouse/sku/index', '', 'lucide:boxes', 'menu', 1, 1, 1, 2
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14023 OR `route_name` = 'WarehouseSkuManagement');
|
||||||
|
|
||||||
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
|
SELECT 14022, (SELECT id FROM `sys_menu` WHERE `id` = 14019 OR `title` = '发货物流' OR `route_name` = 'FreightCatalog' LIMIT 1), 0,
|
||||||
|
'ExpressQuoteEdit', '快递报价单编辑', '/ec/warehouse/express-quote/edit/:id?', '/ec/warehouse/express-quote/edit/index', '', 'lucide:file-pen-line', 'embedded', 0, 1, 0, 8
|
||||||
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 14022 OR `route_name` = 'ExpressQuoteEdit');
|
||||||
|
|
||||||
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `route_name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`)
|
||||||
SELECT 53, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `title` = '电商页面' LIMIT 1), 0, 'PlatformOverview', '平台概览', '/ec/platform/overview/:code', '/ec/platform/overview/index', '', 'lucide:layers', 'embedded', 0, 1, 1, 4
|
SELECT 53, (SELECT id FROM `sys_menu` WHERE `id` = 6 OR `title` = '电商页面' LIMIT 1), 0, 'PlatformOverview', '平台概览', '/ec/platform/overview/:code', '/ec/platform/overview/index', '', 'lucide:layers', 'embedded', 0, 1, 1, 4
|
||||||
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 53 OR `route_name` = 'PlatformOverview');
|
FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `id` = 53 OR `route_name` = 'PlatformOverview');
|
||||||
|
|||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package top.xyquan.ecomdmbbackend.modules.ec.warehouse.quoteimport;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
/** 承运商样表解析冒烟(本地 temp 文件存在时才跑)。 */
|
||||||
|
class ExpressQuoteMatrixSheetParserTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parseSampleCarrierMatrix() throws Exception {
|
||||||
|
Path path = Path.of("temp/json/快递报价单.xlsx");
|
||||||
|
if (!Files.exists(path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try (InputStream in = Files.newInputStream(path); Workbook wb = WorkbookFactory.create(in)) {
|
||||||
|
Sheet sheet = wb.getSheetAt(0);
|
||||||
|
List<String> errors = new ArrayList<>();
|
||||||
|
List<String> warnings = new ArrayList<>();
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> raw =
|
||||||
|
ExpressQuoteMatrixSheetParser.parse(sheet, errors, warnings);
|
||||||
|
List<ExpressQuoteImportModels.RegionDraft> merged = ExpressQuoteRegionMerger.merge(raw);
|
||||||
|
assertFalse(merged.isEmpty(), "应解析到分区");
|
||||||
|
assertTrue(errors.isEmpty(), "跳过策略下不应产生硬错误: " + errors);
|
||||||
|
assertTrue(warnings.stream().anyMatch(w -> w.contains("跳过")),
|
||||||
|
"应对发极兔/空行给出跳过警告: " + warnings);
|
||||||
|
boolean hasNeimeng = merged.stream()
|
||||||
|
.flatMap(r -> r.getDestinations().stream())
|
||||||
|
.anyMatch(d -> d.contains("内蒙古"));
|
||||||
|
assertTrue(hasNeimeng, "内蒙古应保留可解析重量带");
|
||||||
|
boolean hasXizang = merged.stream()
|
||||||
|
.flatMap(r -> r.getDestinations().stream())
|
||||||
|
.anyMatch(d -> d.contains("西藏"));
|
||||||
|
assertFalse(hasXizang, "西藏无价格应整行跳过");
|
||||||
|
boolean has510 = merged.stream()
|
||||||
|
.flatMap(r -> r.getBands().stream())
|
||||||
|
.anyMatch(b -> Integer.valueOf(510).equals(b.getWeightFromG()));
|
||||||
|
assertTrue(has510, "重量带应从 0.51kg 得到 510g");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void templateRoundTripHasRegions() {
|
||||||
|
byte[] bytes = ExpressQuoteTemplateWriter.write();
|
||||||
|
assertTrue(bytes.length > 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import type {
|
||||||
|
ExpressQuoteDTO,
|
||||||
|
ExpressQuoteImportDTO,
|
||||||
|
ExpressQuoteImportVO,
|
||||||
|
ExpressQuoteVO,
|
||||||
|
} from './types';
|
||||||
|
|
||||||
|
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||||
|
|
||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
import { exportByGet } from '#/utils/export';
|
||||||
|
|
||||||
|
export async function getExpressQuotePageApi(
|
||||||
|
params: PageQueryDTO<ExpressQuoteDTO.Filters>,
|
||||||
|
) {
|
||||||
|
return requestClient.post<PageResultVO<ExpressQuoteVO.Info>>(
|
||||||
|
'/ec/express-quote/list',
|
||||||
|
params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEnabledExpressQuotesApi() {
|
||||||
|
return requestClient.get<ExpressQuoteVO.Info[]>('/ec/express-quote/enabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** withHistory:详情抽屉拉全版本分区;编辑页默认 false 仅当前版本明细 */
|
||||||
|
export async function getExpressQuoteDetailApi(
|
||||||
|
id: number,
|
||||||
|
withHistory = false,
|
||||||
|
) {
|
||||||
|
return requestClient.get<ExpressQuoteVO.Info>(
|
||||||
|
`/ec/express-quote/detail/${id}`,
|
||||||
|
{ params: { withHistory } },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createExpressQuoteApi(data: ExpressQuoteDTO.Create) {
|
||||||
|
return requestClient.post<ExpressQuoteVO.Info>(
|
||||||
|
'/ec/express-quote/create',
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateExpressQuoteApi(
|
||||||
|
id: number,
|
||||||
|
data: ExpressQuoteDTO.Update,
|
||||||
|
) {
|
||||||
|
return requestClient.put<ExpressQuoteVO.Info>(
|
||||||
|
`/ec/express-quote/update/${id}`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteExpressQuoteApi(id: number) {
|
||||||
|
return requestClient.delete(`/ec/express-quote/delete/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function upsertExpressQuoteVersionApi(
|
||||||
|
quoteId: number,
|
||||||
|
data: ExpressQuoteDTO.VersionUpsert,
|
||||||
|
) {
|
||||||
|
return requestClient.post<ExpressQuoteVO.Version>(
|
||||||
|
`/ec/express-quote/${quoteId}/version`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteExpressQuoteVersionApi(versionId: number) {
|
||||||
|
return requestClient.delete(`/ec/express-quote/version/${versionId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getExpressCarriersApi() {
|
||||||
|
return requestClient.get<ExpressQuoteVO.CarrierOption[]>(
|
||||||
|
'/ec/express-quote/meta/carriers',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getExpressProvincesApi() {
|
||||||
|
return requestClient.get<ExpressQuoteVO.ProvinceOption[]>(
|
||||||
|
'/ec/express-quote/meta/provinces',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function downloadExpressQuoteTemplateApi() {
|
||||||
|
return exportByGet(
|
||||||
|
'/ec/express-quote/import/template',
|
||||||
|
'快递报价导入模板.xlsx',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function previewExpressQuoteImportApi(file: File) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
return requestClient.post<ExpressQuoteImportVO.Preview>(
|
||||||
|
'/ec/express-quote/import/preview',
|
||||||
|
formData,
|
||||||
|
{
|
||||||
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function commitExpressQuoteImportApi(
|
||||||
|
file: File,
|
||||||
|
params: ExpressQuoteImportDTO.Commit,
|
||||||
|
) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
formData.append(
|
||||||
|
'params',
|
||||||
|
new Blob([JSON.stringify(params)], { type: 'application/json' }),
|
||||||
|
);
|
||||||
|
return requestClient.post<ExpressQuoteVO.Info>(
|
||||||
|
'/ec/express-quote/import/commit',
|
||||||
|
formData,
|
||||||
|
{
|
||||||
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './apis';
|
||||||
|
export * from './types';
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export * from './types.dto';
|
||||||
|
export * from './types.import';
|
||||||
|
export * from './types.vo';
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
export namespace ExpressQuoteDTO {
|
||||||
|
export interface Create {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
carrierCode: string;
|
||||||
|
billingMode: string;
|
||||||
|
status?: number;
|
||||||
|
remark?: string;
|
||||||
|
initialVersion?: VersionUpsert;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Update {
|
||||||
|
name: string;
|
||||||
|
carrierCode: string;
|
||||||
|
status?: number;
|
||||||
|
remark?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Filters {
|
||||||
|
keywords?: string;
|
||||||
|
carrierCode?: string;
|
||||||
|
billingMode?: string;
|
||||||
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VersionUpsert {
|
||||||
|
effectiveFrom: string;
|
||||||
|
flatAmount?: number;
|
||||||
|
unitScope?: string;
|
||||||
|
pricePerKg?: number;
|
||||||
|
minAmount?: number;
|
||||||
|
volumeDivisor?: number;
|
||||||
|
useVolumetric?: number;
|
||||||
|
/** NONE / CEIL_KG */
|
||||||
|
weightRound?: string;
|
||||||
|
remark?: string;
|
||||||
|
regions?: RegionUpsert[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RegionUpsert {
|
||||||
|
regionName: string;
|
||||||
|
zoneLabel?: string;
|
||||||
|
/** 目的地:省全称或市名 */
|
||||||
|
provinces?: string[];
|
||||||
|
isDefault?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
bands?: BandUpsert[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BandUpsert {
|
||||||
|
weightFromG?: number;
|
||||||
|
weightToG?: number | null;
|
||||||
|
/** FLAT_TICKET / FIRST_PLUS_KG */
|
||||||
|
priceMode: string;
|
||||||
|
flatAmount?: number;
|
||||||
|
firstWeightG?: number;
|
||||||
|
firstAmount?: number;
|
||||||
|
continuePerKg?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
export namespace ExpressQuoteImportVO {
|
||||||
|
export interface Preview {
|
||||||
|
format?: string;
|
||||||
|
success: boolean;
|
||||||
|
carrierCode?: string;
|
||||||
|
code?: string;
|
||||||
|
name?: string;
|
||||||
|
effectiveFrom?: string;
|
||||||
|
weightRound?: string;
|
||||||
|
useVolumetric?: number;
|
||||||
|
volumeDivisor?: number;
|
||||||
|
regionCount: number;
|
||||||
|
destinationCount: number;
|
||||||
|
bandCount: number;
|
||||||
|
warnings?: string[];
|
||||||
|
errors?: string[];
|
||||||
|
regions?: RegionPreview[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RegionPreview {
|
||||||
|
regionName: string;
|
||||||
|
zoneLabel?: string;
|
||||||
|
destinations?: string[];
|
||||||
|
bandCount: number;
|
||||||
|
bands?: BandPreview[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BandPreview {
|
||||||
|
weightFromG: number;
|
||||||
|
weightToG?: number | null;
|
||||||
|
priceMode: string;
|
||||||
|
flatAmount?: number;
|
||||||
|
firstWeightG?: number;
|
||||||
|
firstAmount?: number;
|
||||||
|
continuePerKg?: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export namespace ExpressQuoteImportDTO {
|
||||||
|
export interface Commit {
|
||||||
|
mode: 'CREATE' | 'APPEND_VERSION';
|
||||||
|
quoteId?: number;
|
||||||
|
carrierCode?: string;
|
||||||
|
code?: string;
|
||||||
|
name?: string;
|
||||||
|
effectiveFrom?: string;
|
||||||
|
weightRound?: string;
|
||||||
|
useVolumetric?: number;
|
||||||
|
volumeDivisor?: number;
|
||||||
|
remark?: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
export namespace ExpressQuoteVO {
|
||||||
|
export interface Info {
|
||||||
|
id: number;
|
||||||
|
companyId: number;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
carrierCode: string;
|
||||||
|
billingMode: string;
|
||||||
|
status: number;
|
||||||
|
remark?: string;
|
||||||
|
createTime?: string;
|
||||||
|
currentVersion?: Version;
|
||||||
|
versions?: Version[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Version {
|
||||||
|
id: number;
|
||||||
|
quoteId: number;
|
||||||
|
effectiveFrom: string;
|
||||||
|
flatAmount?: number;
|
||||||
|
unitScope?: string;
|
||||||
|
pricePerKg?: number;
|
||||||
|
minAmount?: number;
|
||||||
|
volumeDivisor?: number;
|
||||||
|
useVolumetric?: number;
|
||||||
|
/** NONE / CEIL_KG */
|
||||||
|
weightRound?: string;
|
||||||
|
remark?: string;
|
||||||
|
regions?: Region[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Region {
|
||||||
|
id?: number;
|
||||||
|
regionName: string;
|
||||||
|
zoneLabel?: string;
|
||||||
|
provinces?: string[];
|
||||||
|
isDefault?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
bands?: Band[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Band {
|
||||||
|
id?: number;
|
||||||
|
weightFromG: number;
|
||||||
|
weightToG?: number | null;
|
||||||
|
/** FLAT_TICKET / FIRST_PLUS_KG */
|
||||||
|
priceMode: string;
|
||||||
|
flatAmount?: number;
|
||||||
|
firstWeightG?: number;
|
||||||
|
firstAmount?: number;
|
||||||
|
continuePerKg?: number;
|
||||||
|
sortOrder?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CarrierOption {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProvinceOption {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
normalized: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ export namespace ProductSkuDTO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
weightG?: number | null;
|
||||||
/** 商品成本 */
|
/** 商品成本 */
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费成本 */
|
/** 运费成本 */
|
||||||
@@ -31,6 +33,8 @@ export namespace ProductSkuDTO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
weightG?: number | null;
|
||||||
/** 商品成本 */
|
/** 商品成本 */
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费成本 */
|
/** 运费成本 */
|
||||||
@@ -57,6 +61,8 @@ export namespace ProductSkuDTO {
|
|||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
/** 关键字(模糊查询 SKU 名称、SKU 编码) */
|
/** 关键字(模糊查询 SKU 名称、SKU 编码) */
|
||||||
keywords?: string;
|
keywords?: string;
|
||||||
|
warehouseId?: number;
|
||||||
|
unassignedOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 商品 SKU 查询 DTO(用于批量查询) */
|
/** 商品 SKU 查询 DTO(用于批量查询) */
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ export namespace ProductSkuVO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
weightG?: number | null;
|
||||||
|
lengthMm?: number | null;
|
||||||
|
widthMm?: number | null;
|
||||||
|
heightMm?: number | null;
|
||||||
|
warehouseId?: number | null;
|
||||||
|
warehouseName?: string;
|
||||||
/** 规格组合键;空=未结构化 */
|
/** 规格组合键;空=未结构化 */
|
||||||
specCombinationKey?: string;
|
specCombinationKey?: string;
|
||||||
/** 已绑规格值 */
|
/** 已绑规格值 */
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ export namespace ProductDTO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填;界面按 kg 录入后换算 */
|
||||||
|
weightG?: number | null;
|
||||||
|
lengthMm?: number | null;
|
||||||
|
widthMm?: number | null;
|
||||||
|
heightMm?: number | null;
|
||||||
|
warehouseId?: number | null;
|
||||||
/** 商品成本 */
|
/** 商品成本 */
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费成本 */
|
/** 运费成本 */
|
||||||
@@ -78,6 +84,12 @@ export namespace ProductDTO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
weightG?: number | null;
|
||||||
|
lengthMm?: number | null;
|
||||||
|
widthMm?: number | null;
|
||||||
|
heightMm?: number | null;
|
||||||
|
warehouseId?: number | null;
|
||||||
/** 商品成本 */
|
/** 商品成本 */
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费成本 */
|
/** 运费成本 */
|
||||||
@@ -98,6 +110,12 @@ export namespace ProductDTO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
weightG?: number | null;
|
||||||
|
lengthMm?: number | null;
|
||||||
|
widthMm?: number | null;
|
||||||
|
heightMm?: number | null;
|
||||||
|
warehouseId?: number | null;
|
||||||
/** 商品成本 */
|
/** 商品成本 */
|
||||||
productCost: number;
|
productCost: number;
|
||||||
/** 运费成本 */
|
/** 运费成本 */
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ export namespace ProductVO {
|
|||||||
name: string;
|
name: string;
|
||||||
/** SKU 编码 */
|
/** SKU 编码 */
|
||||||
skuCode?: string;
|
skuCode?: string;
|
||||||
|
/** 单件实重(克);空=未填 */
|
||||||
|
weightG?: number | null;
|
||||||
|
lengthMm?: number | null;
|
||||||
|
widthMm?: number | null;
|
||||||
|
heightMm?: number | null;
|
||||||
|
warehouseId?: number | null;
|
||||||
|
warehouseName?: string;
|
||||||
/** 规格组合键;空=未结构化 */
|
/** 规格组合键;空=未结构化 */
|
||||||
specCombinationKey?: string;
|
specCombinationKey?: string;
|
||||||
/** 已绑规格值 */
|
/** 已绑规格值 */
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
import type { WarehouseDTO, WarehouseVO } from './types';
|
||||||
|
|
||||||
|
import type { ProductSkuVO } from '#/api/ec/product/sku';
|
||||||
|
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||||
|
|
||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
|
export async function getWarehousePageApi(
|
||||||
|
params: PageQueryDTO<WarehouseDTO.Filters>,
|
||||||
|
) {
|
||||||
|
return requestClient.post<PageResultVO<WarehouseVO.Info>>(
|
||||||
|
'/ec/warehouse/list',
|
||||||
|
params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEnabledWarehousesApi() {
|
||||||
|
return requestClient.get<WarehouseVO.Info[]>('/ec/warehouse/enabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getWarehouseDetailApi(id: number) {
|
||||||
|
return requestClient.get<WarehouseVO.Info>(`/ec/warehouse/detail/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createWarehouseApi(data: WarehouseDTO.Create) {
|
||||||
|
return requestClient.post<WarehouseVO.Info>('/ec/warehouse/create', data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateWarehouseApi(
|
||||||
|
id: number,
|
||||||
|
data: WarehouseDTO.Update,
|
||||||
|
) {
|
||||||
|
return requestClient.put<WarehouseVO.Info>(`/ec/warehouse/update/${id}`, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteWarehouseApi(id: number) {
|
||||||
|
return requestClient.delete(`/ec/warehouse/delete/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getWarehouseBindsApi(warehouseId: number) {
|
||||||
|
return requestClient.get<WarehouseVO.Bind[]>(
|
||||||
|
`/ec/warehouse/${warehouseId}/binds`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addWarehouseBindApi(data: WarehouseDTO.BindCreate) {
|
||||||
|
return requestClient.post<WarehouseVO.Bind>('/ec/warehouse/bind', data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateWarehouseBindApi(
|
||||||
|
bindId: number,
|
||||||
|
data: WarehouseDTO.BindUpdate,
|
||||||
|
) {
|
||||||
|
return requestClient.put<WarehouseVO.Bind>(
|
||||||
|
`/ec/warehouse/bind/${bindId}`,
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeWarehouseBindApi(bindId: number) {
|
||||||
|
return requestClient.delete(`/ec/warehouse/bind/${bindId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 发货仓商品分页(仓权限) */
|
||||||
|
export async function getWarehouseSkuPageApi(
|
||||||
|
params: PageQueryDTO<WarehouseDTO.SkuFilters>,
|
||||||
|
) {
|
||||||
|
return requestClient.post<PageResultVO<ProductSkuVO.Info>>(
|
||||||
|
'/ec/warehouse/skus/list',
|
||||||
|
params,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUnassignedWarehouseSkuCountApi() {
|
||||||
|
return requestClient.get<{ count: number }>(
|
||||||
|
'/ec/warehouse/skus/unassigned-count',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function batchAssignWarehouseSkusApi(
|
||||||
|
data: WarehouseDTO.SkuBatchAssign,
|
||||||
|
) {
|
||||||
|
return requestClient.post<{ updated: number }>(
|
||||||
|
'/ec/warehouse/skus/batch-assign',
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './apis';
|
||||||
|
export * from './types';
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './types.dto';
|
||||||
|
export * from './types.vo';
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
export namespace WarehouseDTO {
|
||||||
|
export interface Create {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
province?: string;
|
||||||
|
city?: string;
|
||||||
|
address?: string;
|
||||||
|
status?: number;
|
||||||
|
remark?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Update {
|
||||||
|
name: string;
|
||||||
|
province?: string;
|
||||||
|
city?: string;
|
||||||
|
address?: string;
|
||||||
|
status?: number;
|
||||||
|
remark?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Filters {
|
||||||
|
keywords?: string;
|
||||||
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BindCreate {
|
||||||
|
warehouseId: number;
|
||||||
|
quoteId: number;
|
||||||
|
priority?: number;
|
||||||
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BindUpdate {
|
||||||
|
priority?: number;
|
||||||
|
status?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 发货仓商品筛选 */
|
||||||
|
export interface SkuFilters {
|
||||||
|
keywords?: string;
|
||||||
|
warehouseId?: number;
|
||||||
|
unassignedOnly?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 批量分配默认发货仓;warehouseId 空=取消分配 */
|
||||||
|
export interface SkuBatchAssign {
|
||||||
|
skuIds: number[];
|
||||||
|
warehouseId?: number | null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
export namespace WarehouseVO {
|
||||||
|
export interface Info {
|
||||||
|
id: number;
|
||||||
|
companyId: number;
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
province?: string;
|
||||||
|
city?: string;
|
||||||
|
address?: string;
|
||||||
|
status: number;
|
||||||
|
remark?: string;
|
||||||
|
createTime?: string;
|
||||||
|
updateTime?: string;
|
||||||
|
bindCount?: number;
|
||||||
|
/** 默认发此仓的 SKU 数 */
|
||||||
|
skuCount?: number;
|
||||||
|
binds?: Bind[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Bind {
|
||||||
|
id: number;
|
||||||
|
warehouseId: number;
|
||||||
|
quoteId: number;
|
||||||
|
quoteName?: string;
|
||||||
|
quoteCode?: string;
|
||||||
|
carrierCode?: string;
|
||||||
|
billingMode?: string;
|
||||||
|
priority: number;
|
||||||
|
status: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,15 +53,19 @@ export async function deleteDepartmentApi(id: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部部门
|
* 获取全部部门(超管可传 companyId 跨公司)
|
||||||
*/
|
*/
|
||||||
export async function getAllDepartmentsApi() {
|
export async function getAllDepartmentsApi(companyId?: number) {
|
||||||
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/all');
|
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/all', {
|
||||||
|
params: companyId == null ? undefined : { companyId },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取部门树
|
* 获取部门树(超管可传 companyId 跨公司)
|
||||||
*/
|
*/
|
||||||
export async function getDepartmentTreeApi() {
|
export async function getDepartmentTreeApi(companyId?: number) {
|
||||||
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/tree');
|
return requestClient.get<DepartmentVO.DepartmentInfoVO[]>('/department/tree', {
|
||||||
|
params: companyId == null ? undefined : { companyId },
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,5 +35,7 @@ export namespace DepartmentDTO {
|
|||||||
parentId?: number;
|
parentId?: number;
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
status?: number;
|
status?: number;
|
||||||
|
/** 公司ID(仅超管可跨公司) */
|
||||||
|
companyId?: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,5 +37,7 @@ export namespace PositionDTO {
|
|||||||
name?: string;
|
name?: string;
|
||||||
/** 状态 */
|
/** 状态 */
|
||||||
status?: number;
|
status?: number;
|
||||||
|
/** 公司ID(仅超管可跨公司) */
|
||||||
|
companyId?: number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,28 @@ import { $t } from '#/locales';
|
|||||||
|
|
||||||
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
||||||
|
|
||||||
|
/** 编辑类 embedded 路由:侧栏高亮回列表菜单 */
|
||||||
|
const ACTIVE_PATH_BY_ROUTE_NAME: Record<string, string> = {
|
||||||
|
ExpressQuoteEdit: '/ec/warehouse/express-quote',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** 就地写入 activePath,避免 mapTree 展开 meta 后 title 被推断成 string | undefined */
|
||||||
|
function enrichRouteMeta(
|
||||||
|
routes: RouteRecordStringComponent[],
|
||||||
|
): RouteRecordStringComponent[] {
|
||||||
|
for (const node of routes) {
|
||||||
|
const name = String(node.name ?? '');
|
||||||
|
const activePath = ACTIVE_PATH_BY_ROUTE_NAME[name];
|
||||||
|
if (activePath && node.meta) {
|
||||||
|
node.meta.activePath = activePath;
|
||||||
|
}
|
||||||
|
if (node.children?.length) {
|
||||||
|
enrichRouteMeta(node.children as RouteRecordStringComponent[]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
|
||||||
/** 将 glob key 规范成与后端 component 一致的 /xxx/index.vue */
|
/** 将 glob key 规范成与后端 component 一致的 /xxx/index.vue */
|
||||||
function normalizePageKey(path: string): string {
|
function normalizePageKey(path: string): string {
|
||||||
const normalized = path.replace(/^(\.\/|\.\.\/)+/, '');
|
const normalized = path.replace(/^(\.\/|\.\.\/)+/, '');
|
||||||
@@ -83,7 +105,9 @@ async function generateAccess(
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const routes = await getUserMenuApi();
|
const routes = await getUserMenuApi();
|
||||||
return filterMissingPageRoutes(routes || [], pageMap, layoutMap);
|
return enrichRouteMeta(
|
||||||
|
filterMissingPageRoutes(routes || [], pageMap, layoutMap),
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ 获取用户菜单路由失败:', error);
|
console.error('❌ 获取用户菜单路由失败:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { defineStore } from 'pinia';
|
|||||||
export type ColSidebarKind =
|
export type ColSidebarKind =
|
||||||
| 'company'
|
| 'company'
|
||||||
| 'ec-shop'
|
| 'ec-shop'
|
||||||
|
| 'ec-warehouse'
|
||||||
| 'pdd-shop'
|
| 'pdd-shop'
|
||||||
| 'pdd-publish-agent';
|
| 'pdd-publish-agent';
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ const AGENT_DEFAULT_LAYOUT: ColSidebarLayout = {
|
|||||||
function createDefaultLayouts(): Record<ColSidebarKind, ColSidebarLayout> {
|
function createDefaultLayouts(): Record<ColSidebarKind, ColSidebarLayout> {
|
||||||
return {
|
return {
|
||||||
'ec-shop': { ...DEFAULT_LAYOUT },
|
'ec-shop': { ...DEFAULT_LAYOUT },
|
||||||
|
'ec-warehouse': { ...DEFAULT_LAYOUT },
|
||||||
'pdd-shop': { ...DEFAULT_LAYOUT },
|
'pdd-shop': { ...DEFAULT_LAYOUT },
|
||||||
company: { ...DEFAULT_LAYOUT },
|
company: { ...DEFAULT_LAYOUT },
|
||||||
'pdd-publish-agent': { ...AGENT_DEFAULT_LAYOUT },
|
'pdd-publish-agent': { ...AGENT_DEFAULT_LAYOUT },
|
||||||
|
|||||||
@@ -964,7 +964,8 @@ void loadEnabledModels().then(() => refreshSessions());
|
|||||||
class="mt-24"
|
class="mt-24"
|
||||||
description="开始提问吧(需先在「模型管理」配置 API)"
|
description="开始提问吧(需先在「模型管理」配置 API)"
|
||||||
/>
|
/>
|
||||||
<div class="mx-auto max-w-[760px]">
|
<!-- w-full:避免仅 max-w 时在 flex 列里被内容撑成窄条,短气泡左右贴中间 -->
|
||||||
|
<div class="mx-auto w-full max-w-[760px]">
|
||||||
<ChatItem
|
<ChatItem
|
||||||
v-for="item in bubbleViews"
|
v-for="item in bubbleViews"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
@@ -1086,18 +1087,21 @@ html.dark .agent-session-item--active,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item {
|
.agent-td-item {
|
||||||
/* ChatItem 根节点即 .t-chat__inner,样式打在本类上 */
|
/* ChatItem 根节点即 .t-chat__inner;行必须拉满,短文案才能各贴左右 */
|
||||||
display: flex;
|
display: flex;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
padding-inline: 20px;
|
padding-inline: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 内容区占满行宽,气泡用 align-items 贴边;勿对 content 用 fit-content(会把左右挤到中间) */
|
||||||
.agent-td-item :deep(.t-chat__content) {
|
.agent-td-item :deep(.t-chat__content) {
|
||||||
flex: 0 1 auto !important;
|
flex: 1 1 auto !important;
|
||||||
width: fit-content !important;
|
width: 100% !important;
|
||||||
max-width: min(680px, 100%);
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
justify-content: flex-start !important;
|
justify-content: flex-start !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1106,30 +1110,31 @@ html.dark .agent-session-item--active,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item--assistant :deep(.t-chat__content) {
|
.agent-td-item--assistant :deep(.t-chat__content) {
|
||||||
align-self: flex-start;
|
|
||||||
align-items: flex-start !important;
|
align-items: flex-start !important;
|
||||||
margin-right: auto;
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item--user {
|
.agent-td-item--user {
|
||||||
|
/* 无头像时关掉 TDesign row-reverse,避免与左右对齐打架 */
|
||||||
|
flex-direction: row !important;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item--user :deep(.t-chat__content) {
|
.agent-td-item--user :deep(.t-chat__content) {
|
||||||
align-self: flex-end;
|
|
||||||
align-items: flex-end !important;
|
align-items: flex-end !important;
|
||||||
margin-left: auto;
|
|
||||||
margin-right: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.agent-td-item--user :deep(.t-chat__base) {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 只有气泡随文字收缩;行宽始终 100% */
|
||||||
.agent-td-item :deep(.t-chat__detail) {
|
.agent-td-item :deep(.t-chat__detail) {
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
max-width: 100%;
|
max-width: min(680px, 100%);
|
||||||
margin-inline: 0;
|
margin-inline: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.agent-td-item :deep(.t-chat__text__name) {
|
.agent-td-item :deep(.t-chat__name) {
|
||||||
opacity: 0.55;
|
opacity: 0.55;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* 发货仓双栏页:左栏 WarehouseSidebarList,宽度/收起走全局持久化。
|
||||||
|
*/
|
||||||
|
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||||
|
import type { WarehouseSidebarScope } from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { ColPage } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { useColSidebarLayout } from '#/store/col-sidebar-layout';
|
||||||
|
import WarehouseSidebarList from '#/views/ec/components/WarehouseSidebarList.vue';
|
||||||
|
|
||||||
|
defineOptions({ name: 'EcWarehouseColPage' });
|
||||||
|
|
||||||
|
withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
scope?: WarehouseSidebarScope;
|
||||||
|
selectedWarehouseId?: number;
|
||||||
|
autoContentHeight?: boolean;
|
||||||
|
leftMinWidth?: number;
|
||||||
|
leftMaxWidth?: number;
|
||||||
|
leftCollapsedWidth?: number;
|
||||||
|
leftCollapsible?: boolean;
|
||||||
|
resizable?: boolean;
|
||||||
|
splitHandle?: boolean;
|
||||||
|
splitLine?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
scope: 'all',
|
||||||
|
selectedWarehouseId: undefined,
|
||||||
|
autoContentHeight: true,
|
||||||
|
leftMinWidth: 16,
|
||||||
|
leftMaxWidth: 36,
|
||||||
|
leftCollapsedWidth: 3,
|
||||||
|
leftCollapsible: true,
|
||||||
|
resizable: true,
|
||||||
|
splitHandle: false,
|
||||||
|
splitLine: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:scope': [scope: WarehouseSidebarScope];
|
||||||
|
'update:selectedWarehouseId': [id: number | undefined];
|
||||||
|
select: [
|
||||||
|
payload: {
|
||||||
|
scope: WarehouseSidebarScope;
|
||||||
|
warehouse: WarehouseVO.Info | null;
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const { width: leftWidth, collapsed: leftCollapsed } =
|
||||||
|
useColSidebarLayout('ec-warehouse');
|
||||||
|
|
||||||
|
const listRef = ref<InstanceType<typeof WarehouseSidebarList> | null>(null);
|
||||||
|
|
||||||
|
function refreshSidebar() {
|
||||||
|
void listRef.value?.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ refreshSidebar });
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="ec-warehouse-col-page h-full min-h-0">
|
||||||
|
<ColPage
|
||||||
|
v-model:left-width="leftWidth"
|
||||||
|
v-model:left-collapsed="leftCollapsed"
|
||||||
|
:auto-content-height="autoContentHeight"
|
||||||
|
:left-min-width="leftMinWidth"
|
||||||
|
:left-max-width="leftMaxWidth"
|
||||||
|
:left-collapsed-width="leftCollapsedWidth"
|
||||||
|
:left-collapsible="leftCollapsible"
|
||||||
|
:right-width="100 - leftWidth"
|
||||||
|
:resizable="resizable"
|
||||||
|
:split-handle="splitHandle"
|
||||||
|
:split-line="splitLine"
|
||||||
|
content-class="!p-2 sm:!p-3"
|
||||||
|
>
|
||||||
|
<template #left="{ isCollapsed, expand, collapse }">
|
||||||
|
<div
|
||||||
|
class="flex h-full min-h-0 flex-col"
|
||||||
|
:class="
|
||||||
|
isCollapsed
|
||||||
|
? 'warehouse-sidebar-collapsed-mark min-w-[56px] overflow-visible'
|
||||||
|
: 'min-w-0 overflow-hidden'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<WarehouseSidebarList
|
||||||
|
ref="listRef"
|
||||||
|
fluid
|
||||||
|
:collapsed="!!isCollapsed"
|
||||||
|
show-collapse-action
|
||||||
|
:scope="scope"
|
||||||
|
:selected-warehouse-id="selectedWarehouseId"
|
||||||
|
@collapse="collapse"
|
||||||
|
@expand="expand"
|
||||||
|
@update:scope="emit('update:scope', $event)"
|
||||||
|
@update:selected-warehouse-id="
|
||||||
|
emit('update:selectedWarehouseId', $event)
|
||||||
|
"
|
||||||
|
@select="emit('select', $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<slot />
|
||||||
|
</ColPage>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.ec-warehouse-col-page :deep([data-panel]:has(.warehouse-sidebar-collapsed-mark)),
|
||||||
|
.ec-warehouse-col-page
|
||||||
|
:deep(
|
||||||
|
[data-panel-group-direction]
|
||||||
|
> *:first-child:has(.warehouse-sidebar-collapsed-mark)
|
||||||
|
) {
|
||||||
|
flex: 0 0 56px !important;
|
||||||
|
width: 56px !important;
|
||||||
|
min-width: 56px !important;
|
||||||
|
max-width: 56px !important;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,455 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
/**
|
||||||
|
* 发货仓侧栏:全部 / 未分配 / 指定仓;交互对齐 ShopSidebarList。
|
||||||
|
*/
|
||||||
|
import type { WarehouseVO } from '#/api/ec/warehouse';
|
||||||
|
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import { createIconifyIcon } from '@vben/icons';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
Empty,
|
||||||
|
Input,
|
||||||
|
message,
|
||||||
|
Spin,
|
||||||
|
Tag,
|
||||||
|
Tooltip,
|
||||||
|
} from 'ant-design-vue';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getUnassignedWarehouseSkuCountApi,
|
||||||
|
getWarehousePageApi,
|
||||||
|
} from '#/api/ec/warehouse';
|
||||||
|
|
||||||
|
defineOptions({ name: 'WarehouseSidebarList' });
|
||||||
|
|
||||||
|
export type WarehouseSidebarScope = 'all' | 'unassigned' | 'warehouse';
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
scope?: WarehouseSidebarScope;
|
||||||
|
/** scope=warehouse 时选中的仓 id */
|
||||||
|
selectedWarehouseId?: number;
|
||||||
|
fluid?: boolean;
|
||||||
|
showCollapseAction?: boolean;
|
||||||
|
collapsed?: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
scope: 'all',
|
||||||
|
selectedWarehouseId: undefined,
|
||||||
|
fluid: false,
|
||||||
|
showCollapseAction: false,
|
||||||
|
collapsed: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:scope': [scope: WarehouseSidebarScope];
|
||||||
|
'update:selectedWarehouseId': [id: number | undefined];
|
||||||
|
select: [
|
||||||
|
payload: {
|
||||||
|
scope: WarehouseSidebarScope;
|
||||||
|
warehouse: WarehouseVO.Info | null;
|
||||||
|
},
|
||||||
|
];
|
||||||
|
collapse: [];
|
||||||
|
expand: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const WarehouseIcon = createIconifyIcon('lucide:warehouse');
|
||||||
|
const BoxesIcon = createIconifyIcon('lucide:boxes');
|
||||||
|
const InboxIcon = createIconifyIcon('lucide:inbox');
|
||||||
|
const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||||
|
const PanelOpenIcon = createIconifyIcon('lucide:panel-left-open');
|
||||||
|
const ChevronUpIcon = createIconifyIcon('lucide:chevron-up');
|
||||||
|
const ChevronDownIcon = createIconifyIcon('lucide:chevron-down');
|
||||||
|
|
||||||
|
const keyword = ref('');
|
||||||
|
const warehouses = ref<WarehouseVO.Info[]>([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const unassignedCount = ref(0);
|
||||||
|
const pagination = ref({ current: 1, pageSize: 20, total: 0 });
|
||||||
|
|
||||||
|
const totalPages = computed(() => {
|
||||||
|
const { total, pageSize } = pagination.value;
|
||||||
|
return Math.max(1, Math.ceil(total / pageSize) || 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
const allSelected = computed(() => props.scope === 'all');
|
||||||
|
const unassignedSelected = computed(() => props.scope === 'unassigned');
|
||||||
|
|
||||||
|
async function loadUnassignedCount() {
|
||||||
|
try {
|
||||||
|
const res = await getUnassignedWarehouseSkuCountApi();
|
||||||
|
unassignedCount.value = Number(res?.count ?? 0);
|
||||||
|
} catch {
|
||||||
|
unassignedCount.value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function searchWarehouses(resetPage = false) {
|
||||||
|
if (resetPage) {
|
||||||
|
pagination.value.current = 1;
|
||||||
|
}
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const result = await getWarehousePageApi({
|
||||||
|
page: pagination.value.current,
|
||||||
|
pageSize: pagination.value.pageSize,
|
||||||
|
filters: {
|
||||||
|
keywords: keyword.value || undefined,
|
||||||
|
status: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
warehouses.value = result.records ?? [];
|
||||||
|
pagination.value.total = result.total ?? 0;
|
||||||
|
} catch (error: any) {
|
||||||
|
message.error(error?.message || '获取仓库列表失败');
|
||||||
|
warehouses.value = [];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetSearch() {
|
||||||
|
keyword.value = '';
|
||||||
|
void searchWarehouses(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function goPage(page: number) {
|
||||||
|
const next = Math.min(totalPages.value, Math.max(1, page));
|
||||||
|
if (next === pagination.value.current) return;
|
||||||
|
pagination.value.current = next;
|
||||||
|
void searchWarehouses();
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectAll() {
|
||||||
|
emit('update:scope', 'all');
|
||||||
|
emit('update:selectedWarehouseId', undefined);
|
||||||
|
emit('select', { scope: 'all', warehouse: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectUnassigned() {
|
||||||
|
emit('update:scope', 'unassigned');
|
||||||
|
emit('update:selectedWarehouseId', undefined);
|
||||||
|
emit('select', { scope: 'unassigned', warehouse: null });
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectWarehouse(wh: WarehouseVO.Info) {
|
||||||
|
emit('update:scope', 'warehouse');
|
||||||
|
emit('update:selectedWarehouseId', wh.id);
|
||||||
|
emit('select', { scope: 'warehouse', warehouse: wh });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refresh() {
|
||||||
|
await Promise.all([loadUnassignedCount(), searchWarehouses()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ refresh });
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
void refresh();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="collapsed"
|
||||||
|
class="flex h-full min-h-0 w-full flex-col items-center gap-1 pb-2 pt-3"
|
||||||
|
>
|
||||||
|
<Tooltip title="展开仓库列表">
|
||||||
|
<Button type="text" size="small" class="!px-1" @click="emit('expand')">
|
||||||
|
<PanelOpenIcon class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="flex min-h-0 w-full flex-1 flex-col items-center gap-1.5 overflow-y-auto px-1.5 pb-1 pt-2"
|
||||||
|
>
|
||||||
|
<Tooltip title="全部 SKU">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||||
|
:class="
|
||||||
|
allSelected
|
||||||
|
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectAll"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<BoxesIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="未分配">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||||
|
:class="
|
||||||
|
unassignedSelected
|
||||||
|
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectUnassigned"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Spin
|
||||||
|
:spinning="loading"
|
||||||
|
size="small"
|
||||||
|
wrapper-class-name="warehouse-sidebar-collapsed-spin"
|
||||||
|
>
|
||||||
|
<div class="flex w-full flex-col items-center gap-1.5">
|
||||||
|
<Tooltip
|
||||||
|
v-for="wh in warehouses"
|
||||||
|
:key="wh.id"
|
||||||
|
:title="`${wh.name}(${wh.skuCount ?? 0})`"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex shrink-0 rounded-md p-0.5 transition-colors hover:bg-accent"
|
||||||
|
:class="
|
||||||
|
scope === 'warehouse' && selectedWarehouseId === wh.id
|
||||||
|
? 'ring-2 ring-primary ring-offset-1 ring-offset-background'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectWarehouse(wh)"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 items-center justify-center rounded-md border border-border bg-card text-xs font-medium"
|
||||||
|
>
|
||||||
|
{{ (wh.name || wh.code || '?').slice(0, 1) }}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="totalPages > 1"
|
||||||
|
class="flex shrink-0 flex-col items-center gap-0.5"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
class="!h-6 !px-1"
|
||||||
|
:disabled="pagination.current <= 1 || loading"
|
||||||
|
@click="goPage(pagination.current - 1)"
|
||||||
|
>
|
||||||
|
<ChevronUpIcon class="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
<span class="text-[10px] leading-none text-muted-foreground">
|
||||||
|
{{ pagination.current }}/{{ totalPages }}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
class="!h-6 !px-1"
|
||||||
|
:disabled="pagination.current >= totalPages || loading"
|
||||||
|
@click="goPage(pagination.current + 1)"
|
||||||
|
>
|
||||||
|
<ChevronDownIcon class="h-3.5 w-3.5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
v-else
|
||||||
|
class="flex h-full flex-col overflow-hidden"
|
||||||
|
:class="fluid ? 'w-full min-w-0' : 'w-[320px] shrink-0'"
|
||||||
|
:body-style="{
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '8px',
|
||||||
|
minHeight: 0,
|
||||||
|
minWidth: 0,
|
||||||
|
overflow: 'hidden',
|
||||||
|
padding: '12px',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<template #title>
|
||||||
|
<span class="flex items-center gap-2 text-base font-semibold">
|
||||||
|
<WarehouseIcon class="h-4 w-4" />
|
||||||
|
发货仓
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="showCollapseAction" #extra>
|
||||||
|
<Tooltip title="收起仓库列表">
|
||||||
|
<Button type="text" size="small" class="!px-1" @click="emit('collapse')">
|
||||||
|
<PanelCloseIcon class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 shrink-0 items-center gap-2">
|
||||||
|
<Input
|
||||||
|
v-model:value="keyword"
|
||||||
|
placeholder="名称/编码"
|
||||||
|
allow-clear
|
||||||
|
class="min-w-0 flex-1"
|
||||||
|
@press-enter="searchWarehouses(true)"
|
||||||
|
/>
|
||||||
|
<Button type="primary" class="shrink-0" @click="searchWarehouses(true)">
|
||||||
|
搜索
|
||||||
|
</Button>
|
||||||
|
<Button class="shrink-0" @click="resetSearch">重置</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||||
|
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto">
|
||||||
|
<Card
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="cursor-pointer !shadow-none hover:border-primary"
|
||||||
|
:class="allSelected ? 'border-primary bg-primary/5' : undefined"
|
||||||
|
@click="selectAll"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<BoxesIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-medium">全部</span>
|
||||||
|
<span class="shrink-0 text-xs text-muted-foreground">全部 SKU</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="cursor-pointer !shadow-none hover:border-primary"
|
||||||
|
:class="unassignedSelected ? 'border-primary bg-primary/5' : undefined"
|
||||||
|
@click="selectUnassigned"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-dashed border-border bg-muted/50"
|
||||||
|
>
|
||||||
|
<InboxIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-medium">未分配</span>
|
||||||
|
<Tag class="m-0 shrink-0">{{ unassignedCount }}</Tag>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Spin
|
||||||
|
:spinning="loading"
|
||||||
|
wrapper-class-name="warehouse-sidebar-list-spin"
|
||||||
|
>
|
||||||
|
<Empty
|
||||||
|
v-if="!loading && warehouses.length === 0"
|
||||||
|
class="py-8"
|
||||||
|
description="暂无启用仓库"
|
||||||
|
/>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<Card
|
||||||
|
v-for="wh in warehouses"
|
||||||
|
:key="wh.id"
|
||||||
|
size="small"
|
||||||
|
:body-style="{ padding: '10px 12px' }"
|
||||||
|
class="cursor-pointer !shadow-none hover:border-primary"
|
||||||
|
:class="
|
||||||
|
scope === 'warehouse' && selectedWarehouseId === wh.id
|
||||||
|
? 'border-primary bg-primary/5'
|
||||||
|
: undefined
|
||||||
|
"
|
||||||
|
@click="selectWarehouse(wh)"
|
||||||
|
>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div
|
||||||
|
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-md border border-border bg-card"
|
||||||
|
>
|
||||||
|
<WarehouseIcon class="h-4 w-4 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<div class="flex items-center justify-between gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-medium">
|
||||||
|
{{ wh.name }}
|
||||||
|
</span>
|
||||||
|
<Tag class="m-0 shrink-0">{{ wh.skuCount ?? 0 }}</Tag>
|
||||||
|
</div>
|
||||||
|
<div class="truncate text-xs text-muted-foreground">
|
||||||
|
{{ wh.code }}
|
||||||
|
<template v-if="wh.province || wh.city">
|
||||||
|
· {{ [wh.province, wh.city].filter(Boolean).join(' ') }}
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="mt-2 flex w-full min-w-0 shrink-0 items-center justify-between gap-2"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="pagination.current <= 1 || loading"
|
||||||
|
@click="goPage(pagination.current - 1)"
|
||||||
|
>
|
||||||
|
上一页
|
||||||
|
</Button>
|
||||||
|
<span
|
||||||
|
class="min-w-0 flex-1 truncate text-center text-xs text-muted-foreground"
|
||||||
|
>
|
||||||
|
{{ pagination.current }} / {{ totalPages }}
|
||||||
|
<span class="ml-1 opacity-70">({{ pagination.total }})</span>
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
class="shrink-0"
|
||||||
|
:disabled="pagination.current >= totalPages || loading"
|
||||||
|
@click="goPage(pagination.current + 1)"
|
||||||
|
>
|
||||||
|
下一页
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
:deep(.warehouse-sidebar-collapsed-spin),
|
||||||
|
:deep(.warehouse-sidebar-collapsed-spin .ant-spin-container) {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
:deep(.warehouse-sidebar-list-spin),
|
||||||
|
:deep(.warehouse-sidebar-list-spin .ant-spin-container) {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user