fix(expiry): 已过期资产不再从到期统计中消失,总览页改为到期日历
get_expiring/get_overview 去掉 expiry_date>=today 下界(仅排除已注销)并新增 overdue_count;renewal_service 续费提醒纳入已过期、文案区分已过期N天/今天到期/N天后;dashboard 用到期日历逐条显示具体到期日与倒计时;api.js 新增 Fmt.countdownText 统一文案。
This commit is contained in:
@@ -434,6 +434,7 @@ def get_overview(session: Session) -> dict:
|
||||
by_status: dict = {}
|
||||
abnormal = 0
|
||||
expiring_30 = 0
|
||||
overdue = 0
|
||||
year_cost = 0.0
|
||||
month_cost = 0.0
|
||||
|
||||
@@ -446,8 +447,13 @@ def get_overview(session: Session) -> dict:
|
||||
abnormal += 1
|
||||
if expiry_date:
|
||||
days = (expiry_date - today).days
|
||||
if 0 <= days <= 30:
|
||||
expiring_30 += 1
|
||||
if status_val != AssetStatus.CANCELLED:
|
||||
# 已过期单独计数:过了续费日却还没处理的资产,比 30 天内的更需要被看到,
|
||||
# 不能因为「不在未来窗口内」就从统计里消失
|
||||
if days < 0:
|
||||
overdue += 1
|
||||
elif days <= 30:
|
||||
expiring_30 += 1
|
||||
if expiry_date.year == today.year:
|
||||
year_cost += cost
|
||||
if expiry_date.month == today.month:
|
||||
@@ -459,23 +465,24 @@ def get_overview(session: Session) -> dict:
|
||||
"by_status": by_status,
|
||||
"abnormal_count": abnormal,
|
||||
"expiring_30": expiring_30,
|
||||
"overdue_count": overdue,
|
||||
"year_cost": round(year_cost, 2),
|
||||
"month_cost": round(month_cost, 2),
|
||||
}
|
||||
|
||||
|
||||
def get_expiring(session: Session, days: int = 30) -> List[AssetRead]:
|
||||
"""N 天内到期资产列表(按剩余天数升序)
|
||||
"""N 天内到期资产列表,含已过期未处理的(按剩余天数升序,最紧急在前)
|
||||
|
||||
性能优化:过滤条件下推到 SQL 层,仅查询 [today, today+days] 区间内的资产。
|
||||
过滤条件下推到 SQL 层:到期日上界取 today+days,但不设下界 —— 昨天到期的
|
||||
资产比 30 天后到期的更该出现在倒计时里;只排除已注销资产。
|
||||
"""
|
||||
today = date.today()
|
||||
deadline = today + timedelta(days=days)
|
||||
deadline = date.today() + timedelta(days=days)
|
||||
assets = session.exec(
|
||||
select(Asset).where(
|
||||
Asset.expiry_date.is_not(None),
|
||||
Asset.expiry_date >= today,
|
||||
Asset.expiry_date <= deadline,
|
||||
Asset.status.notin_([AssetStatus.CANCELLED]),
|
||||
)
|
||||
).all()
|
||||
batch = _get_details_batch(session, assets)
|
||||
|
||||
Reference in New Issue
Block a user