34 KiB
车辆 ETC/加油充值 — Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: 在运输管理下新增「ETC加油申请」「ETC加油发放登记」两个独立菜单,支持申请提交(无审批)、发放登记、申请-发放关联与单号自动生成。
Architecture: 两张业务表 pl_vehicle_recharge_apply / pl_vehicle_recharge_record;业务逻辑集中在 pl_vehicle_recharge_service.py(单号生成、状态联动、校验);vehicle_recharge.py 薄路由;前端两页 P01 标准列表 + 弹窗,复用 AttachmentUploadField 与 SystemViewDialog。
Tech Stack: FastAPI + SQLAlchemy + Pydantic v2;Vue 3 + Element Plus + web-admin/src/api/pl/index.ts
Spec: docs/superpowers/specs/2026-06-29-pl-vehicle-recharge-design.md
文件结构
| 文件 | 职责 |
|---|---|
docs/sql/migrations/2026-06-29-pl-vehicle-recharge.sql |
DDL + 字典 + 菜单 + 按钮权限 |
docs/sql/pl_tables.sql |
同步两张新表定义 |
backend/app/models/pl_models.py |
PlVehicleRechargeApply / PlVehicleRechargeRecord |
backend/app/schemas/pl/vehicle_recharge.py |
Create/Update/Read/ListResponse |
backend/app/services/pl_vehicle_recharge_service.py |
单号、校验、CRUD、状态联动 |
backend/app/api/pl/vehicle_recharge.py |
REST 路由 |
backend/app/api/pl/__init__.py |
注册 router |
web-admin/src/api/pl/index.ts |
TS 类型 + API 方法 |
web-admin/src/utils/pl-display.ts |
充值类型/申请状态 Tag 映射 |
web-admin/src/views/pl/vehicle-recharge-apply/index.vue |
申请列表页 |
web-admin/src/views/pl/vehicle-recharge-record/index.vue |
发放登记页 |
web-admin/src/App.vue |
panelTitleBarTextRules 注册标题竖条 |
API 前缀(与现有 PL 一致): /api/transport/vehicle-recharge-apply/*、/api/transport/vehicle-recharge-record/*
Task 1: DDL + 字典 + 菜单权限
Files:
-
Create:
docs/sql/migrations/2026-06-29-pl-vehicle-recharge.sql -
Modify:
docs/sql/pl_tables.sql(追加两表 CREATE) -
Step 1: 创建迁移脚本,含两张表(内容见 spec §数据模型):
-- docs/sql/migrations/2026-06-29-pl-vehicle-recharge.sql
SET NAMES utf8mb4;
CREATE TABLE IF NOT EXISTS `pl_vehicle_recharge_apply` (
`id` varchar(64) NOT NULL COMMENT '主键ID',
`apply_no` varchar(32) NOT NULL COMMENT '申请单号 SXSQ+YYYYMMDD+6位',
`license_plate` varchar(20) NOT NULL COMMENT '车牌号',
`recharge_type` varchar(20) NOT NULL COMMENT '充值类型 etc-ETC fuel-加油',
`apply_date` date NOT NULL COMMENT '申请日期',
`odometer_km` decimal(10,1) DEFAULT NULL COMMENT '期初公里数',
`attachment_urls` varchar(2000) DEFAULT NULL COMMENT '附件URL,逗号分隔',
`applicant_id` varchar(64) NOT NULL COMMENT '申请人用户ID',
`status` varchar(20) NOT NULL DEFAULT 'pending' COMMENT 'pending-待发放 disbursed-已发放 cancelled-已作废',
`tenant_no` varchar(64) NOT NULL DEFAULT 'shanxia2.0',
`order_num` int(11) DEFAULT NULL,
`remark` varchar(512) DEFAULT NULL,
`create_by` varchar(64) DEFAULT NULL,
`create_dept_id` varchar(64) NOT NULL DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_by` varchar(64) DEFAULT NULL,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`del_flag` smallint(6) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_apply_no` (`apply_no`),
KEY `idx_tenant` (`tenant_no`),
KEY `idx_license_plate` (`license_plate`),
KEY `idx_status` (`status`),
KEY `idx_apply_date` (`apply_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='车辆ETC/加油充值申请';
CREATE TABLE IF NOT EXISTS `pl_vehicle_recharge_record` (
`id` varchar(64) NOT NULL COMMENT '主键ID',
`recharge_order_no` varchar(32) NOT NULL COMMENT '充值订单号 SXCL+YYYYMMDD+6位',
`recharge_date` date NOT NULL COMMENT '充值日期',
`recharge_type` varchar(20) NOT NULL COMMENT '充值类型 etc-ETC fuel-加油',
`card_no` varchar(64) DEFAULT NULL COMMENT '卡号',
`gas_station` varchar(200) DEFAULT NULL COMMENT '加油站/充值渠道',
`amount` decimal(10,2) NOT NULL COMMENT '充值金额(元)',
`attachment_urls` varchar(2000) DEFAULT NULL COMMENT '附件URL,逗号分隔',
`apply_id` varchar(64) DEFAULT NULL COMMENT '关联申请单ID',
`license_plate` varchar(20) DEFAULT NULL COMMENT '车牌号冗余',
`tenant_no` varchar(64) NOT NULL DEFAULT 'shanxia2.0',
`order_num` int(11) DEFAULT NULL,
`remark` varchar(512) DEFAULT NULL,
`create_by` varchar(64) DEFAULT NULL,
`create_dept_id` varchar(64) NOT NULL DEFAULT '',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_by` varchar(64) DEFAULT NULL,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`del_flag` smallint(6) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_recharge_order_no` (`recharge_order_no`),
UNIQUE KEY `uk_apply_id` (`apply_id`),
KEY `idx_tenant` (`tenant_no`),
KEY `idx_recharge_date` (`recharge_date`),
KEY `idx_license_plate` (`license_plate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='车辆ETC/加油充值发放登记';
- Step 2: 同一脚本插入字典类型与字典项:
INSERT INTO `sys_dict_type` (`id`, `dict_name`, `dict_type`, `tenant_no`, `order_num`, `remark`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag`) VALUES
('PL_RECHARGE_TYPE', '充值类型', 'pl_recharge_type', 'shanxia2.0', 10, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_RECHARGE_APPLY_STATUS', '充值申请状态', 'pl_recharge_apply_status', 'shanxia2.0', 11, NULL, 'system', '', NOW(), NULL, NOW(), 0)
ON DUPLICATE KEY UPDATE `dict_name` = VALUES(`dict_name`), `update_time` = NOW(), `del_flag` = 0;
INSERT INTO `sys_dict_data` (`id`, `dict_label`, `dict_value`, `tag_type`, `dict_type`, `tenant_no`, `order_num`, `remark`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag`) VALUES
('PL_RECHARGE_TYPE_ETC', 'ETC', 'etc', 'primary', 'pl_recharge_type', 'shanxia2.0', 1, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_RECHARGE_TYPE_FUEL', '加油', 'fuel', 'success', 'pl_recharge_type', 'shanxia2.0', 2, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_RECHARGE_APPLY_PENDING', '待发放', 'pending', 'warning', 'pl_recharge_apply_status', 'shanxia2.0', 1, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_RECHARGE_APPLY_DISBURSED', '已发放', 'disbursed', 'success', 'pl_recharge_apply_status', 'shanxia2.0', 2, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_RECHARGE_APPLY_CANCELLED', '已作废', 'cancelled', 'info', 'pl_recharge_apply_status', 'shanxia2.0', 3, NULL, 'system', '', NOW(), NULL, NOW(), 0)
ON DUPLICATE KEY UPDATE `dict_label` = VALUES(`dict_label`), `tag_type` = VALUES(`tag_type`), `update_time` = NOW(), `del_flag` = 0;
- Step 3: 菜单与按钮权限(parent
PL_MENU_ROOT,order_num 31/32):
INSERT INTO `sys_menu` (`id`, `menu_name`, `parent_id`, `menu_type`, `path`, `component`, `perms`, `is_frame`, `visible`, `status`, `tenant_no`, `order_num`, `remark`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag`) VALUES
('PL_VEH_RECHARGE_APPLY', 'ETC加油申请', 'PL_MENU_ROOT', 'C', 'vehicle-recharge-apply', 'pl/vehicle-recharge-apply/index', 'pl:vehicle-recharge-apply:list', 1, '1', '1', 'shanxia2.0', 31, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VEH_RECHARGE_RECORD', 'ETC加油发放登记', 'PL_MENU_ROOT', 'C', 'vehicle-recharge-record', 'pl/vehicle-recharge-record/index', 'pl:vehicle-recharge-record:list', 1, '1', '1', 'shanxia2.0', 32, NULL, 'system', '', NOW(), NULL, NOW(), 0)
ON DUPLICATE KEY UPDATE `menu_name` = VALUES(`menu_name`), `component` = VALUES(`component`), `perms` = VALUES(`perms`), `update_time` = NOW(), `del_flag` = 0;
-- 申请按钮
INSERT INTO `sys_menu` (`id`, `menu_name`, `parent_id`, `menu_type`, `path`, `component`, `perms`, `is_frame`, `visible`, `status`, `tenant_no`, `order_num`, `remark`, `create_by`, `create_dept_id`, `create_time`, `update_by`, `update_time`, `del_flag`) VALUES
('PL_VRA_Q', '查询', 'PL_VEH_RECHARGE_APPLY', 'F', '', '', 'pl:vehicle-recharge-apply:query', 1, '1', '1', 'shanxia2.0', 1, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRA_A', '新增', 'PL_VEH_RECHARGE_APPLY', 'F', '', '', 'pl:vehicle-recharge-apply:add', 1, '1', '1', 'shanxia2.0', 2, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRA_E', '编辑', 'PL_VEH_RECHARGE_APPLY', 'F', '', '', 'pl:vehicle-recharge-apply:edit', 1, '1', '1', 'shanxia2.0', 3, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRA_R', '删除', 'PL_VEH_RECHARGE_APPLY', 'F', '', '', 'pl:vehicle-recharge-apply:remove', 1, '1', '1', 'shanxia2.0', 4, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRA_C', '作废', 'PL_VEH_RECHARGE_APPLY', 'F', '', '', 'pl:vehicle-recharge-apply:cancel', 1, '1', '1', 'shanxia2.0', 5, NULL, 'system', '', NOW(), NULL, NOW(), 0),
-- 发放按钮
('PL_VRR_Q', '查询', 'PL_VEH_RECHARGE_RECORD', 'F', '', '', 'pl:vehicle-recharge-record:query', 1, '1', '1', 'shanxia2.0', 1, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRR_A', '新增', 'PL_VEH_RECHARGE_RECORD', 'F', '', '', 'pl:vehicle-recharge-record:add', 1, '1', '1', 'shanxia2.0', 2, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRR_E', '编辑', 'PL_VEH_RECHARGE_RECORD', 'F', '', '', 'pl:vehicle-recharge-record:edit', 1, '1', '1', 'shanxia2.0', 3, NULL, 'system', '', NOW(), NULL, NOW(), 0),
('PL_VRR_R', '删除', 'PL_VEH_RECHARGE_RECORD', 'F', '', '', 'pl:vehicle-recharge-record:remove', 1, '1', '1', 'shanxia2.0', 4, NULL, 'system', '', NOW(), NULL, NOW(), 0)
ON DUPLICATE KEY UPDATE `perms` = VALUES(`perms`), `update_time` = NOW(), `del_flag` = 0;
-
Step 4: 将两表 DDL 追加到
docs/sql/pl_tables.sql末尾(与 migration 一致) -
Step 5: 在目标库执行迁移并验证
Run: mysql -u... -p... shanxia -e "SHOW TABLES LIKE 'pl_vehicle_recharge%';"
Expected: 2 rows
- Step 6: Commit
git add docs/sql/migrations/2026-06-29-pl-vehicle-recharge.sql docs/sql/pl_tables.sql
git commit -m "feat(pl): add vehicle recharge apply/record DDL and menus"
Task 2: ORM 模型
Files:
-
Modify:
backend/app/models/pl_models.py -
Step 1: 在
PlDocumentReminder类之后追加两个模型(import 已有Date,DECIMAL,datetime):
class PlVehicleRechargeApply(Base):
"""车辆ETC/加油充值申请 pl_vehicle_recharge_apply"""
__tablename__ = "pl_vehicle_recharge_apply"
id = Column(String(64), primary_key=True, comment="主键ID")
apply_no = Column(String(32), nullable=False, unique=True, comment="申请单号")
license_plate = Column(String(20), nullable=False, comment="车牌号")
recharge_type = Column(String(20), nullable=False, comment="充值类型 etc/fuel")
apply_date = Column(Date, nullable=False, comment="申请日期")
odometer_km = Column(DECIMAL(10, 1), nullable=True, comment="期初公里数")
attachment_urls = Column(String(2000), nullable=True, comment="附件URL")
applicant_id = Column(String(64), nullable=False, comment="申请人ID")
status = Column(String(20), nullable=False, default="pending", comment="申请状态")
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
order_num = Column(Integer, nullable=True, comment="排序号")
remark = Column(String(512), nullable=True, comment="备注")
create_by = Column(String(64), nullable=True, comment="创建人id")
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
update_by = Column(String(64), nullable=True, comment="更新人id")
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
class PlVehicleRechargeRecord(Base):
"""车辆ETC/加油充值发放登记 pl_vehicle_recharge_record"""
__tablename__ = "pl_vehicle_recharge_record"
id = Column(String(64), primary_key=True, comment="主键ID")
recharge_order_no = Column(String(32), nullable=False, unique=True, comment="充值订单号")
recharge_date = Column(Date, nullable=False, comment="充值日期")
recharge_type = Column(String(20), nullable=False, comment="充值类型")
card_no = Column(String(64), nullable=True, comment="卡号")
gas_station = Column(String(200), nullable=True, comment="加油站/渠道")
amount = Column(DECIMAL(10, 2), nullable=False, comment="充值金额")
attachment_urls = Column(String(2000), nullable=True, comment="附件URL")
apply_id = Column(String(64), nullable=True, unique=True, comment="关联申请单ID")
license_plate = Column(String(20), nullable=True, comment="车牌号冗余")
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
order_num = Column(Integer, nullable=True, comment="排序号")
remark = Column(String(512), nullable=True, comment="备注")
create_by = Column(String(64), nullable=True, comment="创建人id")
create_dept_id = Column(String(64), nullable=False, default="", comment="创建人部门ID")
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
update_by = Column(String(64), nullable=True, comment="更新人id")
update_time = Column(DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间")
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
- Step 2: 验证 import
Run: cd backend && python3 -c "from app.models.pl_models import PlVehicleRechargeApply, PlVehicleRechargeRecord; print('ok')"
Expected: ok
- Step 3: Commit
git add backend/app/models/pl_models.py
git commit -m "feat(pl): add vehicle recharge ORM models"
Task 3: Pydantic Schema
Files:
-
Create:
backend/app/schemas/pl/vehicle_recharge.py -
Modify:
backend/app/schemas/pl/__init__.py -
Step 1: 新建 schema 文件:
"""车辆 ETC/加油充值 Schema"""
from datetime import date, datetime
from decimal import Decimal
from typing import Optional
from pydantic import BaseModel, Field, field_validator
RECHARGE_TYPES = {"etc", "fuel"}
APPLY_STATUSES = {"pending", "disbursed", "cancelled"}
class VehicleRechargeApplyCreate(BaseModel):
license_plate: str = Field(..., alias="licensePlate")
recharge_type: str = Field(..., alias="rechargeType")
apply_date: date = Field(..., alias="applyDate")
odometer_km: Optional[Decimal] = Field(default=None, alias="odometerKm")
attachment_urls: Optional[str] = Field(default=None, alias="attachmentUrls")
remark: Optional[str] = None
model_config = {"populate_by_name": True}
@field_validator("recharge_type")
@classmethod
def validate_recharge_type(cls, v: str) -> str:
if v not in RECHARGE_TYPES:
raise ValueError("充值类型无效")
return v
class VehicleRechargeApplyUpdate(VehicleRechargeApplyCreate):
pass
class VehicleRechargeApplyRead(BaseModel):
id: str
apply_no: str = Field(..., alias="applyNo")
license_plate: str = Field(..., alias="licensePlate")
recharge_type: str = Field(..., alias="rechargeType")
apply_date: date = Field(..., alias="applyDate")
odometer_km: Optional[Decimal] = Field(default=None, alias="odometerKm")
attachment_urls: Optional[str] = Field(default=None, alias="attachmentUrls")
applicant_id: str = Field(..., alias="applicantId")
applicant_name: Optional[str] = Field(default=None, alias="applicantName")
status: str
remark: Optional[str] = None
create_time: Optional[datetime] = Field(default=None, alias="createTime")
update_time: Optional[datetime] = Field(default=None, alias="updateTime")
model_config = {"populate_by_name": True, "from_attributes": True}
class VehicleRechargeApplyListResponse(BaseModel):
items: list[VehicleRechargeApplyRead]
total: int
page: int
page_size: int = Field(..., alias="pageSize")
model_config = {"populate_by_name": True}
class VehicleRechargeApplyOption(BaseModel):
id: str
apply_no: str = Field(..., alias="applyNo")
license_plate: str = Field(..., alias="licensePlate")
recharge_type: str = Field(..., alias="rechargeType")
model_config = {"populate_by_name": True}
class VehicleRechargeRecordCreate(BaseModel):
recharge_date: date = Field(..., alias="rechargeDate")
recharge_type: str = Field(..., alias="rechargeType")
card_no: Optional[str] = Field(default=None, alias="cardNo")
gas_station: Optional[str] = Field(default=None, alias="gasStation")
amount: Decimal
attachment_urls: Optional[str] = Field(default=None, alias="attachmentUrls")
apply_id: Optional[str] = Field(default=None, alias="applyId")
license_plate: Optional[str] = Field(default=None, alias="licensePlate")
remark: Optional[str] = None
model_config = {"populate_by_name": True}
@field_validator("recharge_type")
@classmethod
def validate_recharge_type(cls, v: str) -> str:
if v not in RECHARGE_TYPES:
raise ValueError("充值类型无效")
return v
@field_validator("amount")
@classmethod
def validate_amount(cls, v: Decimal) -> Decimal:
if v is None or v <= 0:
raise ValueError("充值金额须大于 0")
return v
class VehicleRechargeRecordUpdate(VehicleRechargeRecordCreate):
pass
class VehicleRechargeRecordRead(BaseModel):
id: str
recharge_order_no: str = Field(..., alias="rechargeOrderNo")
recharge_date: date = Field(..., alias="rechargeDate")
recharge_type: str = Field(..., alias="rechargeType")
card_no: Optional[str] = Field(default=None, alias="cardNo")
gas_station: Optional[str] = Field(default=None, alias="gasStation")
amount: Decimal
attachment_urls: Optional[str] = Field(default=None, alias="attachmentUrls")
apply_id: Optional[str] = Field(default=None, alias="applyId")
apply_no: Optional[str] = Field(default=None, alias="applyNo")
license_plate: Optional[str] = Field(default=None, alias="licensePlate")
remark: Optional[str] = None
create_by: Optional[str] = Field(default=None, alias="createBy")
create_by_name: Optional[str] = Field(default=None, alias="createByName")
create_time: Optional[datetime] = Field(default=None, alias="createTime")
update_time: Optional[datetime] = Field(default=None, alias="updateTime")
model_config = {"populate_by_name": True, "from_attributes": True}
class VehicleRechargeRecordListResponse(BaseModel):
items: list[VehicleRechargeRecordRead]
total: int
page: int
page_size: int = Field(..., alias="pageSize")
model_config = {"populate_by_name": True}
-
Step 2: 在
schemas/pl/__init__.py导出上述类型并加入__all__ -
Step 3: Commit
git add backend/app/schemas/pl/vehicle_recharge.py backend/app/schemas/pl/__init__.py
git commit -m "feat(pl): add vehicle recharge pydantic schemas"
Task 4: Service 层(单号 + 业务逻辑)
Files:
-
Create:
backend/app/services/pl_vehicle_recharge_service.py -
Step 1: 实现核心 service(节选关键函数):
"""车辆 ETC/加油充值业务逻辑"""
from datetime import date, datetime
from decimal import Decimal
from typing import Optional
from fastapi import HTTPException
from sqlalchemy import func, or_
from sqlalchemy.orm import Session
from app.core.utils import generate_uuid
from app.models.pl_models import (
PlVehicle,
PlVehicleRechargeApply,
PlVehicleRechargeRecord,
)
from app.models.models import SysUser
from app.schemas.pl.vehicle_recharge import (
VehicleRechargeApplyCreate,
VehicleRechargeApplyUpdate,
VehicleRechargeRecordCreate,
VehicleRechargeRecordUpdate,
)
from app.services.pl_data_scope import apply_pl_scope, assert_pl_row_in_scope
def _generate_seq_no(db: Session, model, column, prefix: str) -> str:
last = (
db.query(model)
.filter(getattr(model, column.name).like(f"{prefix}%"))
.order_by(getattr(model, column.name).desc())
.first()
)
seq = int(getattr(last, column.key)[-6:]) + 1 if last else 1
return f"{prefix}{seq:06d}"
def generate_apply_no(db: Session) -> str:
prefix = f"SXSQ{date.today():%Y%m%d}"
return _generate_seq_no(db, PlVehicleRechargeApply, PlVehicleRechargeApply.apply_no, prefix)
def generate_recharge_order_no(db: Session) -> str:
prefix = f"SXCL{date.today():%Y%m%d}"
return _generate_seq_no(db, PlVehicleRechargeRecord, PlVehicleRechargeRecord.recharge_order_no, prefix)
def _resolve_user_name(db: Session, user_id: Optional[str]) -> Optional[str]:
if not user_id:
return None
row = db.query(SysUser).filter(SysUser.id == user_id, SysUser.del_flag == 0).first()
return row.nick_name or row.user_name if row else None
def _assert_vehicle_exists(db: Session, tenant_no: str, license_plate: str) -> None:
exists = (
db.query(PlVehicle.id)
.filter(
PlVehicle.tenant_no == tenant_no,
PlVehicle.license_plate == license_plate,
PlVehicle.del_flag == 0,
)
.first()
)
if not exists:
raise HTTPException(status_code=400, detail="车牌号不存在")
def apply_to_dict(row: PlVehicleRechargeApply, db: Session) -> dict:
return {
"id": row.id,
"applyNo": row.apply_no,
"licensePlate": row.license_plate,
"rechargeType": row.recharge_type,
"applyDate": row.apply_date,
"odometerKm": row.odometer_km,
"attachmentUrls": row.attachment_urls,
"applicantId": row.applicant_id,
"applicantName": _resolve_user_name(db, row.applicant_id),
"status": row.status,
"remark": row.remark,
"createTime": row.create_time,
"updateTime": row.update_time,
}
def record_to_dict(row: PlVehicleRechargeRecord, db: Session, apply_no: Optional[str] = None) -> dict:
return {
"id": row.id,
"rechargeOrderNo": row.recharge_order_no,
"rechargeDate": row.recharge_date,
"rechargeType": row.recharge_type,
"cardNo": row.card_no,
"gasStation": row.gas_station,
"amount": row.amount,
"attachmentUrls": row.attachment_urls,
"applyId": row.apply_id,
"applyNo": apply_no,
"licensePlate": row.license_plate,
"remark": row.remark,
"createBy": row.create_by,
"createByName": _resolve_user_name(db, row.create_by),
"createTime": row.create_time,
"updateTime": row.update_time,
}
-
Step 2: 在同一文件实现
list_applies/create_apply/update_apply/cancel_apply/delete_apply/list_pending_apply_options/list_records/create_record/update_record/delete_records,规则:- 创建申请:
status='pending',applicant_id=create_by=user_id - 更新申请:仅
pending - 作废:仅
pending→cancelled - 删除申请:仅
pending且无关联 record(查pl_vehicle_recharge_record.apply_id) - 创建 record:生成
recharge_order_no;若apply_id有值则校验申请pending、类型一致,写入license_plate,申请改disbursed;无apply_id则license_plate必填 - 删除 record:软删;若有关联申请则回退
pending - 所有 list/get 走
apply_pl_scope+assert_pl_row_in_scope
- 创建申请:
-
Step 3: 验证 import
Run: cd backend && python3 -c "from app.services.pl_vehicle_recharge_service import generate_apply_no; print('ok')"
Expected: ok
- Step 4: Commit
git add backend/app/services/pl_vehicle_recharge_service.py
git commit -m "feat(pl): add vehicle recharge service with status linkage"
Task 5: API 路由 + 注册
Files:
-
Create:
backend/app/api/pl/vehicle_recharge.py -
Modify:
backend/app/api/pl/__init__.py -
Step 1: 创建两个
APIRouter:
apply_router = APIRouter(prefix="/vehicle-recharge-apply", tags=["运输计划-ETC加油申请"])
record_router = APIRouter(prefix="/vehicle-recharge-record", tags=["运输计划-ETC加油发放"])
@apply_router.get("/", response_model=VehicleRechargeApplyListResponse)
def list_applies(...): ...
@apply_router.get("/pending-options", response_model=list[VehicleRechargeApplyOption])
def pending_options(...): ...
@apply_router.get("/{id}", response_model=VehicleRechargeApplyRead)
def get_apply(...): ...
@apply_router.post("/", response_model=VehicleRechargeApplyRead, status_code=201)
def create_apply(...): ...
@apply_router.put("/{id}", response_model=VehicleRechargeApplyRead)
def update_apply(...): ...
@apply_router.post("/{id}/cancel", response_model=VehicleRechargeApplyRead)
def cancel_apply(...): ...
@apply_router.delete("/{ids}")
def delete_applies(...): ...
# record_router 同理:GET /, GET /{id}, POST /, PUT /{id}, DELETE /{ids}
- Step 2: 在
backend/app/api/pl/__init__.py注册:
from app.api.pl import vehicle_recharge
pl_router.include_router(vehicle_recharge.apply_router)
pl_router.include_router(vehicle_recharge.record_router)
- Step 3: 启动后端 smoke test(需本地 DB)
Run: curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8000/docs
Expected: 200(服务已运行时)
- Step 4: Commit
git add backend/app/api/pl/vehicle_recharge.py backend/app/api/pl/__init__.py
git commit -m "feat(pl): expose vehicle recharge apply and record APIs"
Task 6: 前端 API 与 display 工具
Files:
-
Modify:
web-admin/src/api/pl/index.ts -
Modify:
web-admin/src/utils/pl-display.ts -
Step 1: 在
api/pl/index.ts追加类型与方法:
export interface VehicleRechargeApply {
id: string
applyNo: string
licensePlate: string
rechargeType: 'etc' | 'fuel'
applyDate: string
odometerKm?: number | null
attachmentUrls?: string
applicantId: string
applicantName?: string
status: 'pending' | 'disbursed' | 'cancelled'
remark?: string
createTime?: string
updateTime?: string
}
export interface VehicleRechargeApplyListResponse {
items: VehicleRechargeApply[]
total: number
page: number
pageSize: number
}
export interface VehicleRechargeRecord {
id: string
rechargeOrderNo: string
rechargeDate: string
rechargeType: 'etc' | 'fuel'
cardNo?: string
gasStation?: string
amount: number
attachmentUrls?: string
applyId?: string
applyNo?: string
licensePlate?: string
remark?: string
createBy?: string
createByName?: string
createTime?: string
updateTime?: string
}
export const vehicleRechargeApplyApi = {
list: (params?: Record<string, unknown>) =>
request.get<VehicleRechargeApplyListResponse>('/transport/vehicle-recharge-apply/', { params }),
get: (id: string) => request.get<VehicleRechargeApply>(`/transport/vehicle-recharge-apply/${id}`),
create: (data: Partial<VehicleRechargeApply>) =>
request.post<VehicleRechargeApply>('/transport/vehicle-recharge-apply/', data),
update: (id: string, data: Partial<VehicleRechargeApply>) =>
request.put<VehicleRechargeApply>(`/transport/vehicle-recharge-apply/${id}`, data),
cancel: (id: string) => request.post<VehicleRechargeApply>(`/transport/vehicle-recharge-apply/${id}/cancel`),
delete: (ids: string) => request.delete(`/transport/vehicle-recharge-apply/${ids}`),
pendingOptions: () =>
request.get<Array<{ id: string; applyNo: string; licensePlate: string; rechargeType: string }>>(
'/transport/vehicle-recharge-apply/pending-options'
)
}
export const vehicleRechargeRecordApi = {
list: (params?: Record<string, unknown>) =>
request.get<{ items: VehicleRechargeRecord[]; total: number; page: number; pageSize: number }>(
'/transport/vehicle-recharge-record/',
{ params }
),
get: (id: string) => request.get<VehicleRechargeRecord>(`/transport/vehicle-recharge-record/${id}`),
create: (data: Partial<VehicleRechargeRecord>) =>
request.post<VehicleRechargeRecord>('/transport/vehicle-recharge-record/', data),
update: (id: string, data: Partial<VehicleRechargeRecord>) =>
request.put<VehicleRechargeRecord>(`/transport/vehicle-recharge-record/${id}`, data),
delete: (ids: string) => request.delete(`/transport/vehicle-recharge-record/${ids}`)
}
- Step 2: 在
pl-display.ts追加:
export function getPlRechargeTypeLabel(type: string) {
return type === 'etc' ? 'ETC' : type === 'fuel' ? '加油' : type
}
export function getPlRechargeTypeTagType(type: string) {
return type === 'etc' ? 'primary' : type === 'fuel' ? 'success' : 'info'
}
export function getPlRechargeApplyStatusLabel(status: string) {
const map: Record<string, string> = {
pending: '待发放',
disbursed: '已发放',
cancelled: '已作废'
}
return map[status] || status
}
export function getPlRechargeApplyStatusTagType(status: string) {
const map: Record<string, string> = {
pending: 'warning',
disbursed: 'success',
cancelled: 'info'
}
return map[status] || 'info'
}
export const PL_GAS_STATION_PRESETS = ['中石化', '线上etc-app', '百链']
- Step 3: Commit
git add web-admin/src/api/pl/index.ts web-admin/src/utils/pl-display.ts
git commit -m "feat(pl): add vehicle recharge frontend API and display helpers"
Task 7: ETC加油申请页面
Files:
-
Create:
web-admin/src/views/pl/vehicle-recharge-apply/index.vue -
Step 1: 以
web-admin/src/views/pl/plan/index.vue为骨架,实现 P01 列表页:- 筛选:关键词(申请单号/车牌)、充值类型、状态、申请日期范围
- 表格列 + 分页(
page/pageSize) - 工具栏:已选 N 项 → 新增申请(primary)
- 行操作(
fixed="right"min-width 280):pending:查看、编辑、作废、删除- 其他:查看
- 弹窗
dialog-form-layoutwidth 720px,form-grid-2,字段见 spec - 车牌:
vehicleApi.list()加载 options - 附件:
AttachmentUploadFieldfolder="pl/vehicle-recharge/apply"limit=5accept="image/*,.pdf" - 申请人:
useUserStore()当前用户昵称只读 - 查看:
SystemViewDialog+ attachment 区块
-
Step 2: 在
web-admin/src/App.vue的panelTitleBarTextRules追加:
'ETC加油申请',
- Step 3: 本地验证页面
Run: cd web-admin && pnpm dev
手动:登录 → 运输管理 → ETC加油申请 → 新增一条 → 列表可见、单号生成
- Step 4: Commit
git add web-admin/src/views/pl/vehicle-recharge-apply/index.vue web-admin/src/App.vue
git commit -m "feat(pl): add ETC fuel recharge apply list page"
Task 8: ETC加油发放登记页面
Files:
-
Create:
web-admin/src/views/pl/vehicle-recharge-record/index.vue -
Step 1: 同样 P01 骨架,实现发放页:
- 筛选:关键词(订单号/车牌/卡号)、充值类型、充值日期范围、加油站、关联申请单号
- 表格列:订单号、充值日期、类型(Tag)、车牌、卡号、加油站、金额、关联申请单号、创建人
- 新增/编辑弹窗:
- 充值订单号只读(新建 placeholder「保存后自动生成」)
- 关联申请:
vehicleRechargeApplyApi.pendingOptions(),@change带出licensePlate+rechargeType只读 - 无关联时车牌、类型可编辑且必填
- 加油站:
el-selectfilterableallow-create+PL_GAS_STATION_PRESETS - 金额:
el-input-numberprecision=2 min=0.01 - 附件 folder=
pl/vehicle-recharge/record - 创建人只读
-
Step 2:
App.vue追加'ETC加油发放登记' -
Step 3: 联调完整流程
- 申请页新建待发放申请
- 发放页关联该申请并保存 → 申请状态变已发放
- 发放页无关联补录一条
- 删除发放 → 申请回退待发放
-
Step 4: Commit
git add web-admin/src/views/pl/vehicle-recharge-record/index.vue web-admin/src/App.vue
git commit -m "feat(pl): add ETC fuel recharge disbursement record page"
Task 9: 字段一致性 + 图谱 + 设计文档状态
Files:
-
Modify:
docs/superpowers/specs/2026-06-29-pl-vehicle-recharge-design.md(状态 → 已批准) -
Step 1: 运行字段一致性检查(若脚本已配置新模块则补充映射后执行)
Run: cd backend && python scripts/check_field_consistency.py 2>/dev/null || echo "skip if module not registered yet"
- Step 2: 更新知识图谱
Run: ./scripts/update-graph.sh all
-
Step 3: 更新 spec 状态为「已批准」
-
Step 4: Commit
git add docs/superpowers/specs/2026-06-29-pl-vehicle-recharge-design.md
git commit -m "docs(pl): mark vehicle recharge design approved after plan"
验收清单(Task 9 后逐项勾选)
- 新建申请 →
SXSQ单号 + 待发放 + 当前用户为申请人 - 待发放申请可编辑/作废/删除;已发放仅查看
- 发放关联申请 →
SXCL订单号 + 申请变已发放 - 无关联发放补录成功(手填车牌/类型)
- 删除发放 → 申请回退待发放
- 附件上传/预览正常
- 菜单权限按钮可见(有权限角色)
- 租户隔离有效
Spec 覆盖自检
| Spec 要求 | 对应 Task |
|---|---|
| D1 无审批 | Task 4 create_apply 直接 pending |
| D2 双菜单 | Task 1 菜单 + Task 7/8 页面 |
| D3 1:1 关联 | Task 1 uk_apply_id + Task 4 状态联动 |
| D4 无申请补录 | Task 4 create_record apply_id 可空 |
| D9/D10 单号规则 | Task 4 generate_* |
| D11 加油站下拉+自由填 | Task 6 presets + Task 8 el-select allow-create |
| 附件规范 | Task 7/8 AttachmentUploadField |
| 数据权限 | Task 4 apply_pl_scope |
工作量
约 3~4 人日(与 spec 估算一致)