Merge branch 'dev' into picture-feedback

This commit is contained in:
HTEWJ\26070045 committed 2026-10-29 11:04:59 +08:00
commit 34ad40778b
180 files changed
+13262 -5333

No files matched your search

@@ -1102,6 +1102,47 @@ def workspace_confirm_shipping_notice_uploaded(business_no: str):
))
@workspace_shipping_notice_bp.route('/shipping-notices/<business_no>/refresh-crane-upload', methods=['POST'])
def workspace_refresh_crane_upload_status(business_no: str):
"""手动刷新一张仍在分配中的 Crane 发货单。
核心逻辑:校验当前用户可见的通知单,读取最近一次上传尝试,写入一条只查状态的 trigger。
不改 10 分钟定时回查的到期时间,也不重新上传 Excel。
Args:
business_no: 对外发货通知单号,同时是 Crane 的 Pull Request #。
Returns:
JSON: business_no 与 trigger_queued。
Raises:
ValidationError: 没有可刷新的上传尝试或来源连接。
ConflictError: 当前不是分配中,或上一次手动刷新还在排队。
"""
user = _require_user()
task = _load_business_notice_for_user(business_no=business_no, user_id=int(user.id))
from app.services.freight_rpa.upload.crane_recheck import request_manual_crane_refresh
from app.services.shipping_notice.onhand_source_rules import task_rpa_inventory_source
from app.services.shipping_notice.onhand_source_repository import get_rpa_trigger_inventory_source
from app.services.shipping_notice.upload_attempt_service import latest_upload_attempt
attempt = latest_upload_attempt(task)
from app.models import ShippingExportArtifact
artifact = db.session.get(ShippingExportArtifact, attempt.artifact_id) if attempt is not None else None
snapshot = task_rpa_inventory_source(task) or {}
upload_source = get_rpa_trigger_inventory_source(str(snapshot.get('source_code') or '')) if snapshot.get('source_code') else None
if attempt is None or artifact is None or not isinstance(upload_source, dict):
raise ValidationError('Crane upload status cannot be refreshed', code='SHIPPING.UPLOAD_CRANE_ALLOCATING')
trigger_path = request_manual_crane_refresh(
attempt,
upload_source,
task_no=str(task.task_no),
export_file_path=str(artifact.file_path or ''),
)
db.session.commit()
return _ok({'business_no': str(task.business_no), 'trigger_queued': bool(trigger_path)})
@workspace_shipping_notice_bp.route('/shipping-notices/<business_no>/rpa-upload', methods=['POST'])
def workspace_start_shipping_notice_rpa_upload(business_no: str):
"""按发货通知单号发起 RPA 上传;RPA 成功事实仍由受信回调裁决。"""
+35 -4
View File
@@ -4,17 +4,20 @@ backend/app/api/workspace/voucher_check.py
用途:立账凭证检核查询、强制重检与通知配置 API(任务列表 / 最近一次检核 / 批次明细 / 企微发送记录 / 按类型接收人)。
依赖:auth.jwt、response_utils envelope、Agent 授权、voucher_check.query_service、notify_config_service。
逻辑:Chat Agent 与旧工作台查询共用;GET runs/latest 不跟筛选;GET notifications 为企微发送记录;
批次明细可按 result 与 invoice_no 筛选。企微记录里的 Excel 走本模块下载,不走排程通知人权限。
查询要求 is_platform_admin 或持有 `agent_code=voucher_check` 的 Agent 授权;POST runs 与通知配置仅平台管理员。
"""
from __future__ import annotations
from flask import Blueprint, request
from io import BytesIO
from flask import Blueprint, request, send_file
from app.core.auth.jwt import get_current_user
from app.core.errors import ForbiddenError, UnauthorizedError, ValidationError
from app.core.errors import ForbiddenError, NotFoundError, UnauthorizedError, ValidationError
from app.core.response import ok
from app.models import Agent
from app.models import Agent, ScheduleRun, VoucherCheckRun
from app.services.voucher_check import notify_config_service, query_service
workspace_voucher_check_bp = Blueprint("workspace_voucher_check", __name__)
@@ -149,12 +152,13 @@ def workspace_voucher_latest_run():
def workspace_voucher_run_items(run_id: int):
"""
分页查看批次明细。
核心逻辑:委托 query_service.list_run_items,可按 result 过滤,并返回 by_file_type。
核心逻辑:委托 query_service.list_run_items,可按 result 与 invoice_no 过滤,并返回 by_file_type。
"""
_require_voucher_check_access()
data = query_service.list_run_items(
run_id=run_id,
result=request.args.get("result"),
invoice_no=request.args.get("invoice_no"),
page=request.args.get("page", default=1, type=int) or 1,
page_size=request.args.get("page_size", default=50, type=int) or 50,
)
@@ -177,6 +181,33 @@ def workspace_voucher_notifications():
return ok(data)
@workspace_voucher_check_bp.route(
"/accounting-voucher-check/schedule-runs/<int:schedule_run_id>/excel",
methods=["GET"],
)
def workspace_voucher_schedule_excel(schedule_run_id: int):
"""
下载企微发送记录对应的检核结果 Excel。
核心逻辑:能看发送记录的人即可下载。只放行已挂到立账凭证批次上的 ScheduleRun,不按排程负责人或通知人拦截。
Raises:
NotFoundError: 该排程记录不是立账凭证批次,或还没有生成 Excel。
"""
_require_voucher_check_access()
engine = VoucherCheckRun.query.filter_by(schedule_run_id=schedule_run_id).first()
if engine is None:
raise NotFoundError("立账凭证检核批次不存在", code="VOUCHER_CHECK.RUN_NOT_FOUND")
run = ScheduleRun.query.get(schedule_run_id)
if run is None or not run.excel_file_data:
raise NotFoundError("检核结果 Excel 不存在", code="VOUCHER_CHECK.EXCEL_NOT_FOUND")
return send_file(
BytesIO(run.excel_file_data),
as_attachment=True,
download_name=run.excel_file_name or "voucher_check.xlsx",
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
@workspace_voucher_check_bp.route("/accounting-voucher-check/notify-config", methods=["GET"])
def workspace_voucher_notify_config_get():
"""