- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。 - 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。 - 更新 ORM 模型,增加出站报表相关的持久化模型。 - 统一命名规范,确保在手、入站与出站的概念一致性。
127 lines
5.2 KiB
Python
127 lines
5.2 KiB
Python
"""
|
|
api/admin/shipping_notice_admin.py
|
|
|
|
用途:发货通知仍留在本蓝图的管理面——Excel 模板、临时在手会话。
|
|
依赖:admin blueprint、require_admin、excel_template、临时会话服务。
|
|
逻辑:货代 RPA 管理路由(含 movement-fields / 报表规则)已迁至
|
|
api/admin_freight_rpa.py 的 /api/admin/freight-rpa/;本文件不再注册那些路径。
|
|
临时会话只改路径段 temporary-onhand-sessions,仍挂在 /shipping-notice/。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from flask import g, request
|
|
|
|
from app.api.admin.blueprint import admin_bp
|
|
from app.core.decorators import require_admin
|
|
from app.core.response import ok
|
|
from app.services.shipping_notice import excel_template
|
|
|
|
|
|
def _actor_id() -> int | None:
|
|
"""取得 require_admin 已写入请求上下文的管理员 ID。"""
|
|
return getattr(getattr(g, 'current_user', None), 'id', None)
|
|
|
|
|
|
def _ok(data, *, status: int = 200):
|
|
"""按平台统一 envelope 返回管理 API 成功结果。"""
|
|
return ok(data, request_id=getattr(g, 'request_id', None), status=status)
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates', methods=['GET'])
|
|
@require_admin
|
|
def list_shipping_excel_templates():
|
|
"""列出版本化发货 Excel 模板。"""
|
|
return _ok(excel_template.list_templates())
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates', methods=['POST'])
|
|
@require_admin
|
|
def create_shipping_excel_template():
|
|
"""上传 xlsx 并创建模板草稿版本。"""
|
|
try:
|
|
definition = json.loads(request.form.get('definition') or '{}')
|
|
except json.JSONDecodeError as exc:
|
|
from app.core.errors import ValidationError
|
|
raise ValidationError('definition must be valid JSON', code='SHIPPING.EXCEL_TEMPLATE_INVALID') from exc
|
|
data = {
|
|
'template_code': request.form.get('template_code'),
|
|
'display_name': request.form.get('display_name'),
|
|
'definition': definition,
|
|
}
|
|
return _ok(excel_template.create_draft(request.files.get('file'), data, actor_id=_actor_id()), status=201)
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>', methods=['PUT'])
|
|
@require_admin
|
|
def update_shipping_excel_template(template_id: int):
|
|
"""更新 Excel 模板草稿定义。"""
|
|
return _ok(excel_template.update_draft(template_id, request.get_json(silent=True) or {}))
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>/layout', methods=['GET'])
|
|
@require_admin
|
|
def get_shipping_excel_template_layout(template_id: int):
|
|
"""读取已保存模板的工作表和栏位,编辑时无需重新上传 Excel。"""
|
|
return _ok(excel_template.get_layout(template_id))
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>/new-version', methods=['POST'])
|
|
@require_admin
|
|
def create_shipping_excel_template_version(template_id: int):
|
|
"""复制现有模板文件和映射定义,创建新的草稿版本。"""
|
|
return _ok(excel_template.create_draft_from_existing(template_id, actor_id=_actor_id()), status=201)
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>/clone', methods=['POST'])
|
|
@require_admin
|
|
def clone_shipping_excel_template(template_id: int):
|
|
"""复制已有模板为使用新编码的独立 v1 草稿。"""
|
|
return _ok(excel_template.clone_as_new_template(
|
|
template_id, request.get_json(silent=True) or {}, actor_id=_actor_id(),
|
|
), status=201)
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>/publish', methods=['POST'])
|
|
@require_admin
|
|
def publish_shipping_excel_template(template_id: int):
|
|
"""校验工作簿和字段映射后发布模板。"""
|
|
return _ok(excel_template.publish(template_id, actor_id=_actor_id()))
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>/retire', methods=['POST'])
|
|
@require_admin
|
|
def retire_shipping_excel_template(template_id: int):
|
|
"""退役没有启用库存源引用的模板。"""
|
|
return _ok(excel_template.retire(template_id))
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/excel-templates/<int:template_id>', methods=['DELETE'])
|
|
@require_admin
|
|
def delete_shipping_excel_template(template_id: int):
|
|
"""删除从未发布且未使用的模板草稿。"""
|
|
excel_template.delete_draft(template_id)
|
|
return '', 204
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/temporary-onhand-sessions', methods=['GET'])
|
|
@require_admin
|
|
def list_confirmed_shipping_temporary_inventory_sessions():
|
|
"""列出已通过质量校验、可供管理员沉淀为解析方案草稿的对话临时库存会话。"""
|
|
from app.services.shipping_notice import onhand_temporary_session
|
|
|
|
return _ok(onhand_temporary_session.list_confirmed_temporary_inventory_sessions())
|
|
|
|
|
|
@admin_bp.route('/shipping-notice/temporary-onhand-sessions/<string:session_no>/create-profile-draft', methods=['POST'])
|
|
@require_admin
|
|
def create_shipping_parsing_draft_from_temporary_inventory_session(session_no: str):
|
|
"""管理员将已确认临时会话锁定映射复制为解析方案草稿;发布仍走既有门禁。"""
|
|
from app.services.shipping_notice import onhand_temporary_session
|
|
|
|
return _ok(onhand_temporary_session.create_parsing_profile_draft_from_temporary_session(
|
|
session_no, request.get_json(silent=True) or {}, actor_id=_actor_id(),
|
|
), status=201)
|