基本完成

This commit is contained in:
2026-08-25 23:03:28 +08:00
parent 252d5b53ac
commit 20936d109f
3 changed files with 221 additions and 0 deletions
+9
View File
@@ -6,8 +6,10 @@
docker exec -i jianli-boss-mysql mysql -uroot -p<密码> < docs/schema.sql docker exec -i jianli-boss-mysql mysql -uroot -p<密码> < docs/schema.sql
""" """
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from loguru import logger from loguru import logger
from .config import settings from .config import settings
@@ -57,6 +59,13 @@ def health_check():
} }
@app.get("/view", include_in_schema=False)
def view_page():
"""独立展示前端:今日投递数据(需登录)"""
return FileResponse(Path(__file__).resolve().parent / "static" / "view.html",
media_type="text/html")
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run("server.main:app", host="0.0.0.0", port=8000, reload=True) uvicorn.run("server.main:app", host="0.0.0.0", port=8000, reload=True)
+34
View File
@@ -98,6 +98,40 @@ def today_count(
return {"count": count} return {"count": count}
@router.get("/today", response_model=dict)
def today_applications(
current_user: User = Depends(get_current_user),
db: Session = Depends(get_db),
):
"""当天(北京时间)全部投递/跳过记录,供独立展示前端使用"""
now_cn = datetime.utcnow() + timedelta(hours=8)
start_utc = now_cn.replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(hours=8)
rows = db.query(JobApplication).filter(
JobApplication.user_id == current_user.id,
JobApplication.applied_at >= start_utc,
).order_by(JobApplication.applied_at.desc()).all()
applied = skipped = 0
items = []
for r in rows:
if r.apply_type in ("chat", "deliver"):
applied += 1
elif r.apply_type == "skipped":
skipped += 1
items.append({
"job_title": r.job_title,
"company": r.company,
"salary": r.salary,
"location": r.location,
"apply_type": r.apply_type,
"ai_score": r.ai_score,
"ai_reason": r.ai_reason,
"skip_reason": r.skip_reason,
"applied_at": (r.applied_at + timedelta(hours=8)).strftime("%H:%M:%S"),
})
return {"applied": applied, "skipped": skipped, "total": len(rows), "items": items}
@router.get("/history", response_model=list[ApplicationOut]) @router.get("/history", response_model=list[ApplicationOut])
def list_applications( def list_applications(
apply_type: Optional[str] = Query(None, description="过滤投递类型"), apply_type: Optional[str] = Query(None, description="过滤投递类型"),
+178
View File
@@ -0,0 +1,178 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>今日投递数据</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: "Microsoft YaHei", sans-serif; background: #f0f4f8; color: #333; }
.hidden { display: none !important; }
/* 登录页 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: #fff; padding: 36px 40px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.08); width: 360px; }
.login-box h1 { font-size: 20px; text-align: center; margin-bottom: 24px; color: #1890ff; }
.login-box input { width: 100%; padding: 10px 12px; margin-bottom: 14px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; }
.login-box button { width: 100%; padding: 11px; background: #1890ff; color: #fff; border: none; border-radius: 6px; font-size: 15px; cursor: pointer; }
.login-box button:hover { background: #40a9ff; }
.login-err { color: #e64340; font-size: 13px; margin-bottom: 10px; min-height: 18px; }
/* 主页面 */
header { background: #fff; padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
header h1 { font-size: 18px; color: #1890ff; }
header .ops { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #666; }
header button { padding: 6px 14px; border: 1px solid #d9d9d9; background: #fff; border-radius: 6px; cursor: pointer; font-size: 13px; }
header button:hover { border-color: #1890ff; color: #1890ff; }
main { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: 10px; padding: 18px 22px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.stat-card .num { font-size: 30px; font-weight: 700; }
.stat-card .label { font-size: 13px; color: #888; margin-top: 4px; }
.num.green { color: #52c41a; } .num.orange { color: #faad14; } .num.blue { color: #1890ff; }
table { width: 100%; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.05); border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f0f0f0; }
th { background: #fafafa; color: #666; font-weight: 600; }
tr:hover td { background: #f7fbff; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: 12px; }
.badge.chat, .badge.deliver { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.badge.skipped { background: #fff7e6; color: #faad14; border: 1px solid #ffd591; }
.score-high { color: #52c41a; font-weight: 700; } .score-mid { color: #faad14; font-weight: 700; } .score-low { color: #e64340; font-weight: 700; }
.remark { color: #999; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; padding: 40px; color: #999; }
</style>
</head>
<body>
<!-- 登录 -->
<div class="login-wrap" id="loginView">
<div class="login-box">
<h1>今日投递数据 · 登录</h1>
<div class="login-err" id="loginErr"></div>
<input type="text" id="username" placeholder="用户名" autocomplete="username">
<input type="password" id="password" placeholder="密码" autocomplete="current-password">
<button id="btnLogin">登 录</button>
</div>
</div>
<!-- 数据 -->
<div id="dataView" class="hidden">
<header>
<h1>今日投递数据</h1>
<div class="ops">
<span id="who"></span>
<span id="updatedAt"></span>
<button id="btnRefresh">刷新</button>
<button id="btnLogout">退出</button>
</div>
</header>
<main>
<div class="stats">
<div class="stat-card"><div class="num green" id="stApplied">0</div><div class="label">今日已投递</div></div>
<div class="stat-card"><div class="num orange" id="stSkipped">0</div><div class="label">今日已跳过</div></div>
<div class="stat-card"><div class="num blue" id="stTotal">0</div><div class="label">今日处理总数</div></div>
</div>
<table>
<thead><tr>
<th>时间</th><th>职位</th><th>公司</th><th>薪资</th><th>结果</th><th>AI评分</th><th>备注</th>
</tr></thead>
<tbody id="tbody"></tbody>
</table>
<div class="empty hidden" id="empty">今天还没有投递记录</div>
</main>
</div>
<script>
const TOKEN_KEY = 'view_token';
const token = () => localStorage.getItem(TOKEN_KEY);
async function api(path, opts = {}) {
const resp = await fetch(path, {
...opts,
headers: { 'Content-Type': 'application/json',
...(token() ? { Authorization: 'Bearer ' + token() } : {}),
...(opts.headers || {}) },
});
if (resp.status === 401) { logout(); throw new Error('未登录'); }
if (!resp.ok) { const d = await resp.json().catch(() => ({})); throw new Error(d.detail || resp.status); }
return resp.json();
}
function showLogin() {
document.getElementById('loginView').classList.remove('hidden');
document.getElementById('dataView').classList.add('hidden');
}
function showData() {
document.getElementById('loginView').classList.add('hidden');
document.getElementById('dataView').classList.remove('hidden');
}
function logout() {
localStorage.removeItem(TOKEN_KEY);
showLogin();
}
async function login() {
const errEl = document.getElementById('loginErr');
errEl.textContent = '';
try {
const d = await api('/api/auth/login', {
method: 'POST',
body: JSON.stringify({
username: document.getElementById('username').value.trim(),
password: document.getElementById('password').value,
}),
});
localStorage.setItem(TOKEN_KEY, d.token);
enter();
} catch (e) { errEl.textContent = e.message || '登录失败'; }
}
function esc(s) {
const div = document.createElement('div');
div.textContent = s == null ? '' : String(s);
return div.innerHTML;
}
async function load() {
try {
const [me, d] = await Promise.all([api('/api/auth/me'), api('/api/jobs/today')]);
document.getElementById('who').textContent = me.nickname || me.username;
document.getElementById('stApplied').textContent = d.applied;
document.getElementById('stSkipped').textContent = d.skipped;
document.getElementById('stTotal').textContent = d.total;
document.getElementById('updatedAt').textContent =
'更新于 ' + new Date().toLocaleTimeString('zh-CN', { hour12: false });
const tbody = document.getElementById('tbody');
tbody.innerHTML = (d.items || []).map(r => {
const type = r.apply_type === 'skipped'
? '<span class="badge skipped">跳过</span>'
: '<span class="badge ' + r.apply_type + '">' + (r.apply_type === 'chat' ? '已沟通' : '已投递') + '</span>';
const score = r.ai_score == null || r.ai_score < 0 ? '-'
: '<span class="' + (r.ai_score >= 80 ? 'score-high' : r.ai_score >= 60 ? 'score-mid' : 'score-low') + '">' + r.ai_score + '</span>';
const remark = r.apply_type === 'skipped' ? (r.skip_reason || '') : (r.ai_reason || '');
return '<tr><td>' + esc(r.applied_at) + '</td><td>' + esc(r.job_title) + '</td><td>' + esc(r.company) +
'</td><td>' + esc(r.salary) + '</td><td>' + type + '</td><td>' + score +
'</td><td class="remark" title="' + esc(remark) + '">' + esc(remark) + '</td></tr>';
}).join('');
document.getElementById('empty').classList.toggle('hidden', (d.items || []).length > 0);
} catch (e) { /* 401 已在 api 内处理 */ }
}
async function enter() {
showData();
await load();
}
document.getElementById('btnLogin').onclick = login;
document.getElementById('password').addEventListener('keydown', e => { if (e.key === 'Enter') login(); });
document.getElementById('btnRefresh').onclick = load;
document.getElementById('btnLogout').onclick = logout;
if (token()) enter(); else showLogin();
setInterval(() => { if (token() && !document.getElementById('dataView').classList.contains('hidden')) load(); }, 30000);
</script>
</body>
</html>