Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59177155e9 | ||
|
|
ebd27ccfa7 | ||
|
|
aed076046a | ||
|
|
d004a141f2 | ||
|
|
425ed43649 |
No files matched your search
@@ -25,11 +25,15 @@ HXOPS_PUBLIC_BASE_URL=https://ai.well-trust.com
|
||||
AUTH_LOGIN_MODE=casdoor
|
||||
# 如果需要用户密码登录,修改该值为password
|
||||
# AUTH_LOGIN_MODE=password
|
||||
|
||||
# 是否启用 JWT 认证
|
||||
AUTH_JWT_REQUIRED=true
|
||||
# 令牌 iss 仍是公网域名,不能改成 IP。证书恢复后把下面两个 HTTP 地址改回 https://auth.well-trust.com。
|
||||
AUTH_JWT_ISSUER=https://auth.well-trust.com
|
||||
AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4
|
||||
AUTH_JWT_JWKS_URL=https://auth.well-trust.com/.well-known/jwks
|
||||
# Casdoor OIDC 服务入口
|
||||
CASDOOR_BASE_URL=https://auth.well-trust.com
|
||||
AUTH_JWT_JWKS_URL=http://192.168.100.230:8870/.well-known/jwks
|
||||
# 临时绕开 auth.well-trust.com 过期证书。Casdoor 直连 8870,不经过 443。
|
||||
CASDOOR_BASE_URL=http://192.168.100.230:8870
|
||||
# 与 Casdoor 里 Application「hxops-prod」(或你当前生产应用)的 Client ID 一致
|
||||
CASDOOR_CLIENT_ID=758be5fcba2df784fdb4
|
||||
CASDOOR_CLIENT_SECRET=522161bea5bb4f90b63f77c41dc26d223f1244ab
|
||||
|
||||
@@ -25,12 +25,12 @@ HXOPS_PUBLIC_BASE_URL=https://ait.well-trust.com
|
||||
#AUTH_LOGIN_MODE=casdoor
|
||||
AUTH_LOGIN_MODE=casdoor
|
||||
|
||||
# 必须与 CASDOOR_BASE_URL discovery 返回的 issuer 完全一致,不能填写 HXOPS 地址。
|
||||
# 令牌 iss 仍是公网域名,不能改成 IP。证书恢复后把 CASDOOR_BASE_URL 改回 https://autht.well-trust.com。
|
||||
AUTH_JWT_ISSUER=https://autht.well-trust.com
|
||||
AUTH_JWT_AUDIENCE=758be5fcba2df784fdb4
|
||||
AUTH_JWT_JWKS_URL=http://192.168.100.192:8870/.well-known/jwks
|
||||
# Casdoor
|
||||
CASDOOR_BASE_URL=https://autht.well-trust.com
|
||||
# 临时绕开 autht.well-trust.com 过期证书。Casdoor 直连 8870,不经过 443。
|
||||
CASDOOR_BASE_URL=http://192.168.100.192:8870
|
||||
# 与 Casdoor 里 Application「hxops-prod」(或你当前生产应用)的 Client ID 一致
|
||||
CASDOOR_CLIENT_ID=758be5fcba2df784fdb4
|
||||
CASDOOR_CLIENT_SECRET=522161bea5bb4f90b63f77c41dc26d223f1244ab
|
||||
|
||||
@@ -4,6 +4,7 @@ backend/app/services/auth/casdoor/client.py
|
||||
用途:封装 Casdoor OAuth/OIDC HTTP 通信,供 HXOPS 与平级服务复制复用。
|
||||
依赖:requests、CasdoorConfig、Casdoor 错误映射。
|
||||
逻辑:所有 grant 和 userinfo 请求集中在此;模块不依赖 HXOPS User、数据库或业务权限。
|
||||
discovery 仍可能广告 HTTPS 域名,服务端换票和 userinfo 会改写到 CASDOOR_BASE_URL。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -40,6 +41,15 @@ class CasdoorTokenResult:
|
||||
return dict(self.raw)
|
||||
|
||||
|
||||
# 仅改写后端自己调用的端点。authorization_endpoint 留给浏览器,避免把用户重定向到内网地址。
|
||||
_SERVER_ENDPOINT_KEYS = (
|
||||
'token_endpoint',
|
||||
'userinfo_endpoint',
|
||||
'jwks_uri',
|
||||
'introspection_endpoint',
|
||||
)
|
||||
|
||||
|
||||
class CasdoorClient:
|
||||
"""无业务模型依赖的 Casdoor OAuth/OIDC 客户端。"""
|
||||
|
||||
@@ -58,7 +68,13 @@ class CasdoorClient:
|
||||
self._metadata_lock = Lock()
|
||||
|
||||
def oidc_metadata(self) -> dict[str, Any]:
|
||||
"""读取并缓存 OIDC discovery 文档 10 分钟。"""
|
||||
"""
|
||||
读取并缓存 OIDC discovery 文档 10 分钟。
|
||||
|
||||
核心逻辑:先请求 CASDOOR_BASE_URL 上的 discovery。若换票、userinfo、JWKS
|
||||
仍指向 AUTH_JWT_ISSUER 的 HTTPS 源,改写到 CASDOOR_BASE_URL,避开过期证书。
|
||||
浏览器使用的 authorization_endpoint 保持 discovery 原值。
|
||||
"""
|
||||
now = datetime.now(timezone.utc)
|
||||
if self._metadata and self._metadata_expires_at and self._metadata_expires_at > now:
|
||||
return dict(self._metadata)
|
||||
@@ -74,10 +90,35 @@ class CasdoorClient:
|
||||
data = response.json() or {}
|
||||
if not isinstance(data, dict):
|
||||
raise RuntimeError('Casdoor OIDC metadata is invalid')
|
||||
# [STEP 1] 公网证书过期时,Casdoor 仍在 discovery 里广告 HTTPS 域名。
|
||||
# 后端改走已配置的 HTTP 入口,令牌 iss 仍按 AUTH_JWT_ISSUER 校验。
|
||||
data = self._rewrite_server_endpoints(data)
|
||||
self._metadata = data
|
||||
self._metadata_expires_at = now + timedelta(minutes=10)
|
||||
return dict(data)
|
||||
|
||||
def _rewrite_server_endpoints(self, data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
把 discovery 中指向签发方源站的服务端地址改写到 CASDOOR_BASE_URL。
|
||||
|
||||
Args:
|
||||
data: Casdoor openid-configuration JSON。
|
||||
|
||||
Returns:
|
||||
改写 token、userinfo、jwks 后的文档。签发方与 base URL 相同时原样返回。
|
||||
"""
|
||||
issuer = self.config.issuer.rstrip('/')
|
||||
base_url = self.config.base_url.rstrip('/')
|
||||
if not issuer or not base_url or issuer == base_url:
|
||||
return data
|
||||
prefix = f'{issuer}/'
|
||||
rewritten = dict(data)
|
||||
for key in _SERVER_ENDPOINT_KEYS:
|
||||
value = str(rewritten.get(key) or '').strip()
|
||||
if value == issuer or value.startswith(prefix):
|
||||
rewritten[key] = f'{base_url}{value[len(issuer):]}'
|
||||
return rewritten
|
||||
|
||||
def _token_endpoint(self) -> str:
|
||||
"""从 discovery 文档读取 token endpoint,缺失时安全失败。"""
|
||||
endpoint = str(self.oidc_metadata().get('token_endpoint') or '').strip()
|
||||
|
||||
@@ -4,11 +4,13 @@ backend/app/services/voucher_check/notification.py
|
||||
用途:立账凭证检核缺件通知、以及检核 / PO 生成排程的技术失败告警。
|
||||
依赖:wecom_notify、notify_config_service、ScheduleTask.notify_user_ids_json、engine_persistence。
|
||||
逻辑:缺件按文件类型接收人拆成每人一封,正文只含该人负责且本批缺失的类型;
|
||||
卡片标题为「销售开票附件缺件」,不写业务方代号和批次号;
|
||||
排程「启用通知」为总开关;技术失败仍走排程通知人;domain_notification_managed 避免通用排程重复通知。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
@@ -23,6 +25,46 @@ from app.services.voucher_check.engine_persistence import persist_notification
|
||||
_TZ = ZoneInfo("Asia/Shanghai")
|
||||
|
||||
|
||||
def _friendly_period_label(period_month: str) -> str:
|
||||
"""
|
||||
把 YYYY-MM 收成企微卡片上的中文年月。
|
||||
核心逻辑:收件人看「2026年8月」,不看 2026-08;解析失败时保留原文。
|
||||
"""
|
||||
text = str(period_month or "").strip()
|
||||
match = re.fullmatch(r"(\d{4})-(\d{2})", text)
|
||||
if not match:
|
||||
return text or "-"
|
||||
return f"{int(match.group(1))}年{int(match.group(2))}月"
|
||||
|
||||
|
||||
def _missing_type_line(item: dict[str, Any]) -> str:
|
||||
"""一条缺件类型:名称、缺件份数、涉及发票张数。"""
|
||||
name = str(item.get("name") or item.get("code") or "")
|
||||
files = int(item.get("missing_file_count") or 0)
|
||||
invoices = int(item.get("missing_invoice_count") or 0)
|
||||
return f"{name}:缺 {files} 份,涉及 {invoices} 张发票"
|
||||
|
||||
|
||||
def _missing_textcard(period_month: str, items: list[dict[str, Any]]) -> tuple[str, str]:
|
||||
"""
|
||||
组装销售开票附件缺件 textcard。
|
||||
核心逻辑:用纯文本而不是 div 着色。企微 description 约 512 字节,
|
||||
颜色标签会挤掉后面的缺件类型。
|
||||
|
||||
Returns:
|
||||
(title, description)
|
||||
"""
|
||||
body = "\n".join(
|
||||
[
|
||||
_friendly_period_label(period_month),
|
||||
"销售开票附件已检核,你负责的类型还有缺件:",
|
||||
*[_missing_type_line(item) for item in items],
|
||||
"请尽快补齐。完整清单见详情里的 Excel。",
|
||||
]
|
||||
)
|
||||
return "销售开票附件缺件", body
|
||||
|
||||
|
||||
def _users_by_ids(user_ids: list[int]) -> list[User]:
|
||||
"""按 id 取出已绑定企微的用户,保持传入顺序。"""
|
||||
if not user_ids:
|
||||
@@ -84,7 +126,7 @@ def send_batch_missing_summary(
|
||||
) -> str:
|
||||
"""
|
||||
按文件类型接收人发送缺件 textcard。
|
||||
核心逻辑:每人一封,只列出该人负责且本批缺失的类型;无缺件或无人可发则写审计不发空消息。
|
||||
核心逻辑:每人一封,只列出该人负责且本批缺失的类型;标题写明销售开票附件,不写业务方代号和批次号。无缺件或无人可发则写审计不发空消息。
|
||||
|
||||
Returns:
|
||||
send_status:sent / skipped_no_missing / skipped_no_recipients / skipped_disabled / failed
|
||||
@@ -177,19 +219,7 @@ def send_batch_missing_summary(
|
||||
sent_ids: list[int] = []
|
||||
for user in users:
|
||||
items = plan["user_rules"].get(int(user.id)) or []
|
||||
type_lines = [
|
||||
f"{item['name']} {item['missing_file_count']} 份 / {item['missing_invoice_count']} 张 invoice"
|
||||
for item in items
|
||||
]
|
||||
title = f"立账凭证缺件: {task.name}"
|
||||
description = (
|
||||
f"业务方 {profile_code}\n"
|
||||
f"资料所属期间 {period_month}\n"
|
||||
f"批次 {schedule_run.run_no}\n"
|
||||
f"你负责的缺件:\n"
|
||||
+ "\n".join(type_lines)
|
||||
+ "\n明细以工作台 Excel 为准。"
|
||||
)
|
||||
title, description = _missing_textcard(period_month, items)
|
||||
trace_id = uuid.uuid4().hex
|
||||
jump_url = _build_jump_url(
|
||||
"/workspace/accounting-voucher-check",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
flask
|
||||
flask-sqlalchemy
|
||||
# 2.1 起 postgresql:// 默认改用 psycopg(v3);本仓库只安装 psycopg2-binary。
|
||||
sqlalchemy>=2.0.16,<2.1
|
||||
flask-migrate
|
||||
flask-cors
|
||||
psycopg2-binary
|
||||
|
||||
@@ -135,6 +135,33 @@ def test_casdoor_config_repr_does_not_expose_secret(app):
|
||||
assert 'top-secret-value' not in repr(config)
|
||||
|
||||
|
||||
def test_casdoor_server_endpoints_follow_base_url_when_issuer_uses_expired_https():
|
||||
"""公网 HTTPS 证书不可用时,换票和 userinfo 改走 CASDOOR_BASE_URL,浏览器授权地址保持原域名。"""
|
||||
http = FakeHttp()
|
||||
http.get = lambda url, **kwargs: FakeResponse({
|
||||
'issuer': 'https://auth.example.com',
|
||||
'authorization_endpoint': 'https://auth.example.com/login/oauth/authorize',
|
||||
'token_endpoint': 'https://auth.example.com/api/login/oauth/access_token',
|
||||
'userinfo_endpoint': 'https://auth.example.com/api/userinfo',
|
||||
'jwks_uri': 'https://auth.example.com/.well-known/jwks',
|
||||
}) if url.endswith('/.well-known/openid-configuration') else FakeResponse({})
|
||||
client = CasdoorClient(CasdoorConfig(
|
||||
base_url='http://192.168.100.230:8870',
|
||||
client_id='peer-client',
|
||||
client_secret='peer-secret',
|
||||
issuer='https://auth.example.com',
|
||||
), http_session=http)
|
||||
metadata = client.oidc_metadata()
|
||||
# 后端换票不能再访问过期证书上的 HTTPS 域名。
|
||||
assert metadata['token_endpoint'] == 'http://192.168.100.230:8870/api/login/oauth/access_token'
|
||||
assert metadata['userinfo_endpoint'] == 'http://192.168.100.230:8870/api/userinfo'
|
||||
assert metadata['jwks_uri'] == 'http://192.168.100.230:8870/.well-known/jwks'
|
||||
# 浏览器授权仍使用 discovery 原地址。
|
||||
assert metadata['authorization_endpoint'] == 'https://auth.example.com/login/oauth/authorize'
|
||||
client.password_login('alice', 'user-password')
|
||||
assert http.posts[0][0] == 'http://192.168.100.230:8870/api/login/oauth/access_token'
|
||||
|
||||
|
||||
def test_casdoor_password_client_request_is_framework_independent():
|
||||
"""公共客户端按配置发送 password grant,不依赖 HXOPS User 或数据库。"""
|
||||
http = FakeHttp()
|
||||
|
||||
@@ -291,10 +291,18 @@ def test_send_batch_splits_one_card_per_user(app, monkeypatch):
|
||||
|
||||
wecom_ids = {item[0] for item in sent}
|
||||
assert wecom_ids == {"wx-po-recv", "wx-bl-recv"}
|
||||
po_body = next(item[2] for item in sent if item[0] == "wx-po-recv")
|
||||
po_title, po_body = next((item[1], item[2]) for item in sent if item[0] == "wx-po-recv")
|
||||
bl_body = next(item[2] for item in sent if item[0] == "wx-bl-recv")
|
||||
# 关键断言:卡片面向销售开票附件,不暴露业务方代号和批次号。
|
||||
assert po_title == "销售开票附件缺件"
|
||||
assert "2026年8月" in po_body
|
||||
assert "缺 2 份,涉及 1 张发票" in po_body
|
||||
assert "业务方" not in po_body
|
||||
assert "sales" not in po_body
|
||||
assert "RUN-VC-NOTIFY-SPLIT" not in po_body
|
||||
assert "PO订单" in po_body
|
||||
assert "提单" not in po_body
|
||||
assert "发票" not in po_body
|
||||
# 关键断言:「张发票」是计量用语,类型是否出现要看「发票:缺」。
|
||||
assert "提单:缺" not in po_body
|
||||
assert "发票:缺" not in po_body
|
||||
assert "提单" in bl_body
|
||||
assert "PO订单" not in bl_body
|
||||
assert "PO订单:缺" not in bl_body
|
||||
+13
-9
@@ -120,6 +120,7 @@
|
||||
.latest.compact .metric b { font-size: 18px; }
|
||||
.latest.compact .step-line { margin-top: 8px; }
|
||||
.latest-hd h2 { margin: 0; font-size: 15px; }
|
||||
.latest-title { display: flex; align-items: center; gap: 8px; }
|
||||
.latest-meta { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
|
||||
.latest-meta span { margin-right: 12px; }
|
||||
.badge {
|
||||
@@ -228,7 +229,6 @@
|
||||
<th>缺件文件数</th>
|
||||
<th>状态</th>
|
||||
<th>执行时间</th>
|
||||
<th>失败原因</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -241,7 +241,6 @@
|
||||
<td>11</td>
|
||||
<td><span class="pill miss">缺件</span></td>
|
||||
<td>2026-09-08 09:50:19</td>
|
||||
<td>—</td>
|
||||
<td><button class="link" type="button">查看详情</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -250,9 +249,8 @@
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td>0</td>
|
||||
<td><span class="pill fail">技术失败</span></td>
|
||||
<td><span class="pill fail" title="未配置销售开票附件文档库根目录">技术失败</span></td>
|
||||
<td>2026-09-07 16:32:10</td>
|
||||
<td class="err">未配置销售开票附件文档库根目录</td>
|
||||
<td><button class="link" type="button">查看详情</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -332,6 +330,12 @@
|
||||
setTimeout(() => toastEl.classList.remove("show"), 2200);
|
||||
}
|
||||
|
||||
function friendlyPeriod(period) {
|
||||
const match = /^(\d{4})-(\d{2})$/.exec(period || "");
|
||||
if (!match) return period || "-";
|
||||
return match[1] + "年" + Number(match[2]) + "月";
|
||||
}
|
||||
|
||||
function render(data) {
|
||||
const warn = data.metrics[2] > 0 || data.metrics[3] > 0;
|
||||
const labels = ["invoice总数", "已归档文件", "缺件文件数", "缺件 invoice 数"];
|
||||
@@ -339,14 +343,14 @@
|
||||
latestEl.className = "latest" + (isMonitor ? "" : " compact") + (data.statusClass === "fail" ? " fail" : "");
|
||||
latestEl.innerHTML =
|
||||
'<div class="latest-hd">' +
|
||||
"<div><h2>" + data.title + "</h2>" +
|
||||
'<p class="latest-meta"><span>批次 ' + data.runNo + "</span><span>期间 " + data.period + "</span><span>" + data.mode + "</span></p></div>" +
|
||||
"<div><div class=\"latest-title\"><h2>" + data.title + "</h2>" +
|
||||
'<span class="badge ' + data.statusClass + '">' + data.status + "</span></div>" +
|
||||
'<p class="latest-meta">' + friendlyPeriod(data.period) + "</p></div>" +
|
||||
'<div class="latest-actions">' +
|
||||
(data.percent === 100 && data.statusClass !== "fail"
|
||||
? '<button class="link" type="button">查看本批详情</button>'
|
||||
? '<button class="btn" type="button">查看本批详情</button>'
|
||||
: "") +
|
||||
'<span class="badge ' + data.statusClass + '">' + data.status + "</span>" +
|
||||
'<button class="btn warn" type="button" data-force="1"' + (busy ? " disabled" : "") + ">强制重检上月</button>" +
|
||||
'<button class="btn" type="button" data-force="1"' + (busy ? " disabled" : "") + ">强制重检上月</button>" +
|
||||
"</div>" +
|
||||
"</div>" +
|
||||
'<div class="latest-bd">' +
|
||||
|
||||
@@ -61,13 +61,13 @@
|
||||
|
||||
检核任务列表是用户查看历史批次和进入详情的主入口。默认展示**上一个自然月**的批次,支持把月份改为「全部」查看该年全部批次,再进入对应的执行明细、企业微信通知附件 Excel 和通知记录。
|
||||
|
||||
「最近一次检核」卡片放在 Tab 下方、筛选栏上方,只出现在「检核任务」Tab:展示**最近一批**(按执行时间,不跟年/月/状态筛选)。终态用矮指标格(批次号、期间、模式、状态、四格数字、强制重检),不展示进度条和完成说明;排队/执行中才展开进度条、开始/完成时间和当前步骤。强制重检上月(仅管理员)放在这张卡片上,入队后进度在本卡更新。
|
||||
「最近一次检核」卡片放在 Tab 下方、筛选栏上方,只出现在「检核任务」Tab:展示**最近一批**(按执行时间,不跟年/月/状态筛选)。终态用矮指标格(资料所属年月、状态、四格数字、强制重检;不展示批次号与增量/全量模式),不展示进度条和完成说明;排队/执行中才展开进度条、开始/完成时间和当前步骤。强制重检上月(仅管理员)放在这张卡片上,入队后进度在本卡更新。
|
||||
|
||||
| 区域 | 内容 |
|
||||
| ------------ | ------------------------------------------------------------------------------------------------- |
|
||||
| 最近一次检核 | 终态矮指标格(批次/状态/四格数字,无进度条);执行中展开进度;强制重检上月(全量 `force_all`,期间固定上一个自然月,不用筛选栏期间) |
|
||||
| 最近一次检核 | 终态矮指标格(资料所属年月/状态/四格数字,无进度条,不展示批次号与执行模式);执行中展开进度;强制重检上月(全量 `force_all`,期间固定上一个自然月,不用筛选栏期间) |
|
||||
| 筛选条件 | 资料所属期间(年必选、月可选「全部」;进页默认上一个自然月)、任务状态 |
|
||||
| 任务列表字段 | 批次号、资料所属期间、执行时间、主体总数、缺件文件数、缺件 `invoice` 数、状态、失败原因 |
|
||||
| 任务列表字段 | 批次号、资料所属期间、执行时间、主体总数、缺件文件数、缺件 `invoice` 数、状态。失败原因不单独成列;仅技术失败且有原因时,在状态旁以提示展示 |
|
||||
| 状态 | 排队中、执行中、缺件、完整、技术失败 |
|
||||
| 操作 | 查看详情;进入该批次的执行记录,并可查看企业微信通知附件 Excel |
|
||||
|
||||
@@ -78,7 +78,7 @@ Chat 同一入口用 Tab 切换「检核任务」与「企微发送记录」。
|
||||
| 区域 | 内容 |
|
||||
| -------- | --------------------------------------------------------------------------------------------- |
|
||||
| 筛选条件 | 资料所属期间(与检核任务同一套年/月口径)、发送状态 |
|
||||
| 列表字段 | 批次号、资料所属期间、invoice 总数、invoice 缺件数、缺件文件数、发送状态、未发送原因、接收人、发送时间、Excel |
|
||||
| 列表字段 | 批次号、资料所属期间、invoice 总数、invoice 缺件数、缺件文件数、发送状态、接收人、发送时间、Excel。未发送原因不单独成列;有原因时挂在发送状态旁的提示上 |
|
||||
| 操作 | 有附件时可下载该批 Excel;查看详情进入对应批次明细 |
|
||||
|
||||
### 3.6 通知配置(仅平台管理员)
|
||||
@@ -244,7 +244,7 @@ flowchart TD
|
||||
| -------- | ------------------------------------------------------------------------------------------------------- |
|
||||
| 触发 | 本批存在必检文件缺件 |
|
||||
| 聚合 | 审计仍是一个检核批次一条;企微按接收人拆信,不在正文逐票展开缺失明细 |
|
||||
| 内容 | 业务方、检核月份、批次号,以及该人负责且本批缺失的文件类型(缺件文件数 / 缺件 invoice 数);完整明细以 Excel 为准 |
|
||||
| 内容 | 标题为「销售开票附件缺件」。正文为中文年月、该人负责且本批缺失的文件类型(缺多少份、涉及多少张发票),并提示到详情 Excel 补齐。不写业务方代号和批次号 |
|
||||
| 明细查看 | 全部缺件 `invoice`、缺失文件列表和处理状态以 Excel 与执行记录为准 |
|
||||
| 接收人 | 平台管理员在 Chat「通知配置」按文件类型从系统用户多选。未配置任何接收人时不发送空通知,并在发送记录标记未发送原因 |
|
||||
| 技术失败 | 不作为缺件通知;按排程通知人单独告警 |
|
||||
|
||||
@@ -331,7 +331,7 @@ ERP/OA 打印或目录扫描的成功文件先写入类型存放目录;完成
|
||||
| 最近一次检核卡片 | `GET .../runs/latest`;终态矮指标格,排队/执行中展开进度;强制重检仅 admin,入队后前端轮询本接口 |
|
||||
| 批次号、业务方、资料所属期间、执行时间 | `voucher_check_runs` |
|
||||
| 主体总数、已归档数、缺件文件数、缺件 `invoice` 数 | 批次结束时固化的统计快照;执行中可来自 `response_summary_json.voucher_check` |
|
||||
| 状态 | 列表:`completed`、`missing`、`technical_failed`;卡片另含 `queued`、`running` |
|
||||
| 状态 | 列表:`completed`、`missing`、`technical_failed`;卡片另含 `queued`、`running`。技术失败且有 `error_message` 时,原因挂在状态旁提示,不单独成列 |
|
||||
| 查看详情 | 携带 `schedule_run_id` 跳转执行记录;详情读取 `voucher_check_file_results` |
|
||||
| 通知附件 | 通过该批次的 Excel 文件标识进入企业微信通知附件 Excel 预览或下载 |
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/workspace/utils/voucherCheck.display.ts
|
||||
* 用途:立账凭证检核列表、最近一次检核卡片与明细页共用的状态/模式/步骤文案。
|
||||
* 用途:立账凭证检核列表、最近一次检核卡片与明细页共用的状态、期间、模式与步骤文案。
|
||||
* 依赖:vue-i18n 的 t()。
|
||||
* 逻辑:AccountingVoucherCheckView / AccountingVoucherCheckDetailView 调用。
|
||||
*/
|
||||
@@ -23,6 +23,25 @@ export function voucherCheckStatusLabel(t: (key: string) => string, value: strin
|
||||
return value || '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* 把资料所属期间 YYYY-MM 格式成当前语言的年月。
|
||||
* 核心逻辑:卡片不展示原始 2026-08;中文为「2026年8月」,英文与泰文用月份名。
|
||||
* @param period - 期间,例如 2026-08
|
||||
* @param locale - 当前 vue-i18n locale
|
||||
* @returns 友好年月;无法解析时回退原文本或 '-'
|
||||
*/
|
||||
export function voucherCheckPeriodLabel(period: string | null | undefined, locale: string): string {
|
||||
const match = /^(\d{4})-(\d{2})$/.exec(String(period || '').trim());
|
||||
if (!match) return period || '-';
|
||||
const year = Number(match[1]);
|
||||
const month = Number(match[2]);
|
||||
if (month < 1 || month > 12) return period || '-';
|
||||
const tag = locale === 'zh-TW' ? 'zh-Hant' : locale === 'zh-CN' ? 'zh-Hans' : locale;
|
||||
return new Intl.DateTimeFormat(tag, { year: 'numeric', month: 'long', calendar: 'gregory' }).format(
|
||||
new Date(year, month - 1, 1),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将批次执行模式映射为工作台文案。
|
||||
* @param t - i18n 翻译函数
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
* 依赖:voucherCheck.api、vue-i18n、useMessage、DeleteConfirmDialog、PaginationBar、formatLocalDateTime、voucherCheck.display、auth。
|
||||
* Chat 嵌入时由 VoucherCheckChatPanel 传入 embedded / activeTab。
|
||||
* 逻辑:独立路由或 Chat 嵌入;进页默认上一个自然月;「最近一次检核」不跟筛选;强制重检仅 is_platform_admin,进度在本卡轮询。
|
||||
* 终态用矮指标格;排队/执行中才展开进度条与当前步骤。Chat 嵌入时隐藏页头与内层 Tab。
|
||||
* 终态用矮指标格;排队/执行中才展开进度条与当前步骤。技术失败原因与企微未发送原因都挂在状态旁的提示上,不单独成列。Chat 嵌入时隐藏页头与内层 Tab。
|
||||
*/
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ChevronDown, Download, Loader2, RotateCcw, Search } from 'lucide-vue-next';
|
||||
import { ChevronDown, CircleAlert, Download, Eye, Loader2, RotateCcw, Search } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
@@ -28,8 +28,8 @@ import {
|
||||
type VoucherCheckRunItem,
|
||||
} from '../api/voucherCheck.api';
|
||||
import {
|
||||
voucherCheckModeLabel,
|
||||
voucherCheckNotifyStatusLabel,
|
||||
voucherCheckPeriodLabel,
|
||||
voucherCheckStatusLabel,
|
||||
voucherCheckStepLabel,
|
||||
} from '../utils/voucherCheck.display';
|
||||
@@ -46,7 +46,7 @@ const emit = defineEmits<{
|
||||
'open-detail': [payload: { runId: number; runNo?: string | null }];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const { t, locale } = useI18n();
|
||||
const msg = useMessage();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -115,6 +115,42 @@ const latestShowFailureHint = computed(() => {
|
||||
|
||||
const MONTH_VALUES = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] as const;
|
||||
|
||||
const failureTip = ref<{ text: string; left: number; top: number } | null>(null);
|
||||
|
||||
/**
|
||||
* 技术失败且带有批次失败原因时,才在状态旁挂提示。
|
||||
* 核心逻辑:缺件、完整没有批次级失败原因;没有 error_message 的技术失败不挂空图标。
|
||||
* @param row - 检核任务列表行
|
||||
*/
|
||||
function showRunFailureReason(row: VoucherCheckRunItem): boolean {
|
||||
return row.status === 'technical_failed' && Boolean(row.error_message?.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 在失败图标下方打开失败原因提示,避免表格滚动容器把提示裁掉。
|
||||
* @param event - 悬停或聚焦事件
|
||||
* @param message - 批次失败原因
|
||||
*/
|
||||
function openFailureTip(event: Event, message: string): void {
|
||||
const target = event.currentTarget;
|
||||
if (!(target instanceof HTMLElement)) return;
|
||||
const rect = target.getBoundingClientRect();
|
||||
const width = 280;
|
||||
const left = Math.max(8, Math.min(rect.left, window.innerWidth - width - 8));
|
||||
failureTip.value = {
|
||||
text: message,
|
||||
left,
|
||||
top: rect.bottom + 6,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭状态旁的失败原因提示。
|
||||
*/
|
||||
function closeFailureTip(): void {
|
||||
failureTip.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 进页默认资料所属期间为上一个自然月。
|
||||
*/
|
||||
@@ -248,6 +284,15 @@ function notifyBadgeClass(value: string): string {
|
||||
return 'bg-surface-soft text-secondary';
|
||||
}
|
||||
|
||||
/**
|
||||
* 有未发送原因时才在发送状态旁挂提示。
|
||||
* 核心逻辑:已发送且无 skip_reason 不占列、不挂空图标。
|
||||
* @param row - 企微发送记录
|
||||
*/
|
||||
function showNotifySkipReason(row: VoucherCheckNotificationItem): boolean {
|
||||
return Boolean(row.skip_reason?.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将接收人姓名拼成展示文本。
|
||||
* @param names - 系统用户姓名
|
||||
@@ -532,33 +577,34 @@ onUnmounted(() => {
|
||||
:class="latestInProgress ? 'bg-blue-50' : ''"
|
||||
>
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold text-primary">{{ $t('workspace.voucherCheck.latestTitle') }}</h2>
|
||||
<div class="flex items-center gap-2">
|
||||
<h2 class="text-sm font-semibold text-primary">{{ $t('workspace.voucherCheck.latestTitle') }}</h2>
|
||||
<span
|
||||
v-if="latestRun"
|
||||
class="inline-flex rounded-full px-2.5 py-0.5 text-xs font-semibold"
|
||||
:class="latestBadgeClass(latestRun.status)"
|
||||
>
|
||||
{{ voucherCheckStatusLabel(t, latestRun.status) }}
|
||||
</span>
|
||||
</div>
|
||||
<p v-if="latestRun" class="mt-0.5 text-xs text-muted">
|
||||
<span class="mr-3">{{ $t('workspace.voucherCheck.latestBatch', { runNo: latestRun.run_no }) }}</span>
|
||||
<span class="mr-3">{{ $t('workspace.voucherCheck.latestPeriod', { period: latestRun.period_month || '-' }) }}</span>
|
||||
<span>{{ voucherCheckModeLabel(t, latestRun.mode) }}</span>
|
||||
{{ voucherCheckPeriodLabel(latestRun.period_month, locale) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
<button
|
||||
v-if="latestCanOpenDetail"
|
||||
type="button"
|
||||
class="text-sm font-semibold text-brand-700 hover:underline"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-default bg-surface px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="openLatestDetail"
|
||||
>
|
||||
<Eye class="h-3.5 w-3.5" />
|
||||
{{ $t('workspace.voucherCheck.viewLatestDetail') }}
|
||||
</button>
|
||||
<span
|
||||
v-if="latestRun"
|
||||
class="inline-flex rounded-full px-2.5 py-0.5 text-xs font-semibold"
|
||||
:class="latestBadgeClass(latestRun.status)"
|
||||
>
|
||||
{{ voucherCheckStatusLabel(t, latestRun.status) }}
|
||||
</span>
|
||||
<button
|
||||
v-if="isAdmin"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-amber-300 bg-amber-50 px-3 py-1.5 text-sm font-medium text-amber-900 transition-colors hover:bg-amber-100 disabled:opacity-50"
|
||||
class="inline-flex items-center gap-1 rounded-xl border border-default bg-surface px-3 py-1.5 text-sm font-medium text-secondary transition-colors hover:bg-surface-soft disabled:opacity-50"
|
||||
:disabled="forcing || latestInProgress"
|
||||
@click="openForceRecheck()"
|
||||
>
|
||||
@@ -683,7 +729,6 @@ onUnmounted(() => {
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingFiles') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.status') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.checkedAt') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.failureReason') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -695,15 +740,28 @@ onUnmounted(() => {
|
||||
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_invoice_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_file_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3">
|
||||
<span
|
||||
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="row.status === 'missing' ? 'bg-rose-50 text-rose-700' : row.status === 'completed' ? 'bg-emerald-50 text-emerald-700' : 'bg-surface-soft text-secondary'"
|
||||
>
|
||||
{{ voucherCheckStatusLabel(t, row.status) }}
|
||||
<span class="inline-flex items-center gap-1.5">
|
||||
<span
|
||||
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="latestBadgeClass(row.status)"
|
||||
>
|
||||
{{ voucherCheckStatusLabel(t, row.status) }}
|
||||
</span>
|
||||
<button
|
||||
v-if="showRunFailureReason(row)"
|
||||
type="button"
|
||||
class="inline-flex h-[22px] w-[22px] cursor-help items-center justify-center rounded-full text-rose-600 hover:bg-rose-50"
|
||||
:aria-label="row.error_message || $t('workspace.voucherCheck.failureReason')"
|
||||
@mouseenter="openFailureTip($event, row.error_message || '')"
|
||||
@mouseleave="closeFailureTip"
|
||||
@focus="openFailureTip($event, row.error_message || '')"
|
||||
@blur="closeFailureTip"
|
||||
>
|
||||
<CircleAlert class="h-4 w-4" />
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ formatLocalDateTime(row.finished_at) }}</td>
|
||||
<td class="max-w-64 truncate px-4 py-3 text-rose-700" :title="row.error_message || ''">{{ row.error_message || '-' }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3">
|
||||
<button
|
||||
type="button"
|
||||
@@ -737,7 +795,6 @@ onUnmounted(() => {
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingInvoices') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.missingFiles') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifyStatus') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifySkipReason') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifyRecipients') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifySentAt') }}</th>
|
||||
<th class="whitespace-nowrap bg-surface-soft px-4 py-3">{{ $t('workspace.voucherCheck.notifyExcel') }}</th>
|
||||
@@ -752,14 +809,27 @@ onUnmounted(() => {
|
||||
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_invoice_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ row.missing_file_count }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3">
|
||||
<span
|
||||
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="notifyBadgeClass(row.send_status)"
|
||||
>
|
||||
{{ voucherCheckNotifyStatusLabel(t, row.send_status) }}
|
||||
<span class="inline-flex items-center gap-1.5">
|
||||
<span
|
||||
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="notifyBadgeClass(row.send_status)"
|
||||
>
|
||||
{{ voucherCheckNotifyStatusLabel(t, row.send_status) }}
|
||||
</span>
|
||||
<button
|
||||
v-if="showNotifySkipReason(row)"
|
||||
type="button"
|
||||
class="inline-flex h-[22px] w-[22px] cursor-help items-center justify-center rounded-full text-rose-600 hover:bg-rose-50"
|
||||
:aria-label="row.skip_reason || $t('workspace.voucherCheck.notifySkipReason')"
|
||||
@mouseenter="openFailureTip($event, row.skip_reason || '')"
|
||||
@mouseleave="closeFailureTip"
|
||||
@focus="openFailureTip($event, row.skip_reason || '')"
|
||||
@blur="closeFailureTip"
|
||||
>
|
||||
<CircleAlert class="h-4 w-4" />
|
||||
</button>
|
||||
</span>
|
||||
</td>
|
||||
<td class="max-w-56 truncate px-4 py-3 text-muted" :title="row.skip_reason || ''">{{ row.skip_reason || '-' }}</td>
|
||||
<td class="max-w-48 truncate px-4 py-3 text-muted" :title="formatRecipientNames(row.recipient_names)">{{ formatRecipientNames(row.recipient_names) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3 text-muted">{{ formatLocalDateTime(row.sent_at || row.created_at) }}</td>
|
||||
<td class="whitespace-nowrap px-4 py-3">
|
||||
@@ -819,6 +889,17 @@ onUnmounted(() => {
|
||||
confirm-tone="primary"
|
||||
@confirm="forceRecheck"
|
||||
/>
|
||||
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="failureTip"
|
||||
class="pointer-events-none fixed z-[80] max-w-[280px] whitespace-normal break-words rounded-lg bg-slate-900 px-2.5 py-1.5 text-xs leading-relaxed text-white shadow-lg"
|
||||
role="tooltip"
|
||||
:style="{ left: `${failureTip.left}px`, top: `${failureTip.top}px` }"
|
||||
>
|
||||
{{ failureTip.text }}
|
||||
</div>
|
||||
</Teleport>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in new issue
Block a user