添加引导词和投递模板
This commit is contained in:
+2
-1
@@ -14,7 +14,7 @@ from loguru import logger
|
||||
|
||||
from .config import settings
|
||||
from .database import engine
|
||||
from .routers import register, resumes, sessions, jobs, blacklist, rpa
|
||||
from .routers import register, resumes, sessions, jobs, blacklist, rpa, templates
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
@@ -50,6 +50,7 @@ app.include_router(sessions.router)
|
||||
app.include_router(jobs.router)
|
||||
app.include_router(blacklist.router)
|
||||
app.include_router(rpa.router)
|
||||
app.include_router(templates.router)
|
||||
|
||||
|
||||
@app.get("/", tags=["健康检查"])
|
||||
|
||||
@@ -46,6 +46,7 @@ class User(Base):
|
||||
applications = relationship("JobApplication", back_populates="user", cascade="all, delete-orphan")
|
||||
sessions = relationship("ApplySession", back_populates="user", cascade="all, delete-orphan")
|
||||
blacklist = relationship("CompanyBlacklist", back_populates="user", cascade="all, delete-orphan")
|
||||
templates = relationship("ApplyTemplate", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class Resume(Base):
|
||||
@@ -91,6 +92,8 @@ class ApplySession(Base):
|
||||
# 薪资范围
|
||||
salary_min = Column(Integer, nullable=True)
|
||||
salary_max = Column(Integer, nullable=True)
|
||||
# AI 评分引导词(用户自定义补充偏好)
|
||||
prompt = Column(Text, nullable=True)
|
||||
# 本次会话投递数量统计
|
||||
applied_count = Column(Integer, default=0)
|
||||
skipped_count = Column(Integer, default=0)
|
||||
@@ -204,3 +207,38 @@ class RpaTask(Base):
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow, nullable=False)
|
||||
|
||||
user = relationship("User")
|
||||
|
||||
|
||||
class ApplyTemplate(Base):
|
||||
"""
|
||||
投递条件模板
|
||||
用户保存常用投递配置,支持在本地面板和远程控制面板套用。
|
||||
"""
|
||||
__tablename__ = "apply_templates"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id", ondelete="CASCADE"),
|
||||
nullable=False, index=True)
|
||||
# 模板名称(用户自定义)
|
||||
name = Column(String(128), nullable=False)
|
||||
# 搜索关键词(逗号分隔)
|
||||
keywords = Column(String(512), nullable=True)
|
||||
# 城市
|
||||
city = Column(String(20), nullable=True)
|
||||
# 薪资范围
|
||||
salary_min = Column(Integer, nullable=True)
|
||||
salary_max = Column(Integer, nullable=True)
|
||||
# AI 最低匹配分
|
||||
min_score = Column(Integer, default=65)
|
||||
# 每日投递上限(0=不限)
|
||||
daily_limit = Column(Integer, default=0)
|
||||
# 是否只投递 Boss 在线的职位
|
||||
boss_online_only = Column(Boolean, default=False, nullable=False)
|
||||
# 是否考虑猎头职位
|
||||
allow_headhunter = Column(Boolean, default=False, nullable=False)
|
||||
# AI 评分引导词
|
||||
prompt = Column(Text, nullable=True)
|
||||
created_at = Column(DateTime, default=utcnow, nullable=False)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow, nullable=False)
|
||||
|
||||
user = relationship("User", back_populates="templates")
|
||||
|
||||
@@ -37,6 +37,7 @@ def start_session(
|
||||
city=req.city,
|
||||
salary_min=req.salary_min,
|
||||
salary_max=req.salary_max,
|
||||
prompt=req.prompt,
|
||||
)
|
||||
db.add(session)
|
||||
db.commit()
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
"""
|
||||
投递条件模板路由:增删改查 + 套用
|
||||
"""
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from ..auth import get_current_user
|
||||
from ..database import get_db
|
||||
from ..models import ApplyTemplate, User
|
||||
from ..schemas import TemplateIn, TemplateOut
|
||||
|
||||
router = APIRouter(prefix="/api/templates", tags=["投递模板"])
|
||||
|
||||
|
||||
def _template_out(t: ApplyTemplate) -> dict:
|
||||
return {
|
||||
"id": t.id,
|
||||
"name": t.name,
|
||||
"keywords": t.keywords,
|
||||
"city": t.city,
|
||||
"salary_min": t.salary_min,
|
||||
"salary_max": t.salary_max,
|
||||
"min_score": t.min_score,
|
||||
"daily_limit": t.daily_limit,
|
||||
"boss_online_only": t.boss_online_only,
|
||||
"allow_headhunter": t.allow_headhunter,
|
||||
"prompt": t.prompt,
|
||||
"created_at": t.created_at,
|
||||
"updated_at": t.updated_at,
|
||||
}
|
||||
|
||||
|
||||
@router.get("", response_model=list[TemplateOut])
|
||||
def list_templates(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""获取当前用户的所有投递模板(按更新时间倒序)"""
|
||||
rows = db.query(ApplyTemplate).filter(
|
||||
ApplyTemplate.user_id == current_user.id
|
||||
).order_by(ApplyTemplate.updated_at.desc()).all()
|
||||
return rows
|
||||
|
||||
|
||||
@router.post("", response_model=TemplateOut)
|
||||
def create_template(
|
||||
req: TemplateIn,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""创建投递模板"""
|
||||
t = ApplyTemplate(
|
||||
user_id=current_user.id,
|
||||
name=req.name,
|
||||
keywords=req.keywords,
|
||||
city=req.city,
|
||||
salary_min=req.salary_min,
|
||||
salary_max=req.salary_max,
|
||||
min_score=req.min_score,
|
||||
daily_limit=req.daily_limit,
|
||||
boss_online_only=req.boss_online_only,
|
||||
allow_headhunter=req.allow_headhunter,
|
||||
prompt=req.prompt,
|
||||
)
|
||||
db.add(t)
|
||||
db.commit()
|
||||
db.refresh(t)
|
||||
return t
|
||||
|
||||
|
||||
@router.get("/{template_id}", response_model=TemplateOut)
|
||||
def get_template(
|
||||
template_id: int,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""获取单个模板详情"""
|
||||
t = db.query(ApplyTemplate).filter(
|
||||
ApplyTemplate.id == template_id,
|
||||
ApplyTemplate.user_id == current_user.id,
|
||||
).first()
|
||||
if not t:
|
||||
raise HTTPException(status_code=404, detail="模板不存在")
|
||||
return t
|
||||
|
||||
|
||||
@router.put("/{template_id}", response_model=TemplateOut)
|
||||
def update_template(
|
||||
template_id: int,
|
||||
req: TemplateIn,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""更新投递模板"""
|
||||
t = db.query(ApplyTemplate).filter(
|
||||
ApplyTemplate.id == template_id,
|
||||
ApplyTemplate.user_id == current_user.id,
|
||||
).first()
|
||||
if not t:
|
||||
raise HTTPException(status_code=404, detail="模板不存在")
|
||||
|
||||
t.name = req.name
|
||||
t.keywords = req.keywords
|
||||
t.city = req.city
|
||||
t.salary_min = req.salary_min
|
||||
t.salary_max = req.salary_max
|
||||
t.min_score = req.min_score
|
||||
t.daily_limit = req.daily_limit
|
||||
t.boss_online_only = req.boss_online_only
|
||||
t.allow_headhunter = req.allow_headhunter
|
||||
t.prompt = req.prompt
|
||||
|
||||
db.commit()
|
||||
db.refresh(t)
|
||||
return t
|
||||
|
||||
|
||||
@router.delete("/{template_id}")
|
||||
def delete_template(
|
||||
template_id: int,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""删除投递模板"""
|
||||
t = db.query(ApplyTemplate).filter(
|
||||
ApplyTemplate.id == template_id,
|
||||
ApplyTemplate.user_id == current_user.id,
|
||||
).first()
|
||||
if not t:
|
||||
raise HTTPException(status_code=404, detail="模板不存在")
|
||||
db.delete(t)
|
||||
db.commit()
|
||||
return {"ok": True}
|
||||
@@ -97,6 +97,7 @@ class SessionStartIn(BaseModel):
|
||||
city: str
|
||||
salary_min: Optional[int] = None
|
||||
salary_max: Optional[int] = None
|
||||
prompt: Optional[str] = None
|
||||
|
||||
|
||||
class SessionOut(BaseModel):
|
||||
@@ -106,6 +107,7 @@ class SessionOut(BaseModel):
|
||||
city: Optional[str]
|
||||
salary_min: Optional[int]
|
||||
salary_max: Optional[int]
|
||||
prompt: Optional[str]
|
||||
applied_count: int
|
||||
skipped_count: int
|
||||
started_at: datetime
|
||||
@@ -156,6 +158,41 @@ class ApplicationOut(BaseModel):
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# =======================================================
|
||||
# 投递条件模板
|
||||
# =======================================================
|
||||
class TemplateIn(BaseModel):
|
||||
name: str = Field(..., min_length=1, max_length=128, description="模板名称")
|
||||
keywords: Optional[str] = Field(None, max_length=512, description="搜索关键词(逗号分隔)")
|
||||
city: Optional[str] = Field(None, max_length=20, description="城市")
|
||||
salary_min: Optional[int] = None
|
||||
salary_max: Optional[int] = None
|
||||
min_score: int = Field(65, ge=0, le=100, description="AI 最低匹配分")
|
||||
daily_limit: int = Field(0, ge=0, description="每日投递上限(0=不限)")
|
||||
boss_online_only: bool = False
|
||||
allow_headhunter: bool = False
|
||||
prompt: Optional[str] = None
|
||||
|
||||
|
||||
class TemplateOut(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
keywords: Optional[str]
|
||||
city: Optional[str]
|
||||
salary_min: Optional[int]
|
||||
salary_max: Optional[int]
|
||||
min_score: int
|
||||
daily_limit: int
|
||||
boss_online_only: bool
|
||||
allow_headhunter: bool
|
||||
prompt: Optional[str]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# =======================================================
|
||||
# 公司黑名单
|
||||
# =======================================================
|
||||
|
||||
@@ -198,6 +198,17 @@
|
||||
</div>
|
||||
<div class="bl-tip" id="rsDetail">进度:- | 更新:-</div>
|
||||
|
||||
<div class="bl-add" style="flex-wrap:wrap;align-items:flex-end;">
|
||||
<div style="flex:2;min-width:220px;"><label style="font-size:12px;color:#666;">选择模板</label>
|
||||
<select id="rTemplate" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;">
|
||||
<option value="">-- 不使用模板 --</option>
|
||||
</select></div>
|
||||
<div style="display:flex;align-items:flex-end;gap:8px;padding-bottom:10px;">
|
||||
<button id="btnRefreshTemplates" type="button">刷新模板</button>
|
||||
<button id="btnSaveTemplateRemote" type="button">保存为模板</button>
|
||||
<button id="btnManageTemplatesRemote" type="button">管理模板</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bl-add" style="flex-wrap:wrap;align-items:flex-end;">
|
||||
<div style="flex:2;min-width:220px;"><label style="font-size:12px;color:#666;">搜索关键词(多个用逗号分隔)</label>
|
||||
<input type="text" id="rKeywords" placeholder="如:Python开发,后端工程师" value="Python开发"></div>
|
||||
@@ -221,6 +232,10 @@
|
||||
<button id="btnStartRemote" style="background:#1890ff;">开始投递</button>
|
||||
<button id="btnStopRemote">结束投递</button>
|
||||
</div>
|
||||
<div class="bl-add" style="flex-wrap:wrap;align-items:flex-end;">
|
||||
<div style="flex:1;min-width:300px;"><label style="font-size:12px;color:#666;">AI 引导词(可选)</label>
|
||||
<textarea id="rPrompt" rows="3" style="width:100%;padding:9px 10px;border:1px solid #d9d9d9;border-radius:6px;resize:vertical;" placeholder="例如:优先投递 Java 后端岗位,接受 10-15K,有 AI 项目经验优先"></textarea></div>
|
||||
</div>
|
||||
<div class="bl-tip">任务下发后客户端 5 秒内认领执行;同类型任务未结束前不能重复下发。</div>
|
||||
|
||||
<table>
|
||||
@@ -503,6 +518,7 @@ document.getElementById('btnStartRemote').onclick = () => {
|
||||
daily_limit: parseInt(document.getElementById('rLimit').value, 10) || 0,
|
||||
boss_online_only: document.getElementById('rOnlineOnly').checked,
|
||||
allow_headhunter: document.getElementById('rHunter').checked,
|
||||
prompt: document.getElementById('rPrompt').value.trim() || null,
|
||||
});
|
||||
};
|
||||
document.getElementById('btnStopRemote').onclick = () => {
|
||||
@@ -520,6 +536,99 @@ document.getElementById('tbody').addEventListener('click', e => {
|
||||
}
|
||||
});
|
||||
|
||||
// 远程模板管理
|
||||
let remoteTemplates = [];
|
||||
|
||||
async function loadRemoteTemplates() {
|
||||
try {
|
||||
remoteTemplates = await api('/api/templates') || [];
|
||||
const select = document.getElementById('rTemplate');
|
||||
select.innerHTML = '<option value="">-- 不使用模板 --</option>';
|
||||
remoteTemplates.forEach(t => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = t.id;
|
||||
opt.textContent = t.name;
|
||||
select.appendChild(opt);
|
||||
});
|
||||
} catch (e) { console.error('加载模板失败', e); }
|
||||
}
|
||||
|
||||
function fillRemoteForm(t) {
|
||||
document.getElementById('rKeywords').value = (t.keywords || '').replace(/,/g, ', ');
|
||||
document.getElementById('rCity').value = t.city || '北京';
|
||||
document.getElementById('rScore').value = t.min_score || 65;
|
||||
document.getElementById('rSalaryMin').value = t.salary_min || 0;
|
||||
document.getElementById('rSalaryMax').value = t.salary_max || 0;
|
||||
document.getElementById('rLimit').value = t.daily_limit || 0;
|
||||
document.getElementById('rOnlineOnly').checked = !!t.boss_online_only;
|
||||
document.getElementById('rHunter').checked = !!t.allow_headhunter;
|
||||
document.getElementById('rPrompt').value = t.prompt || '';
|
||||
}
|
||||
|
||||
function collectRemoteTemplate() {
|
||||
return {
|
||||
keywords: document.getElementById('rKeywords').value.split(/[,,\s]+/).filter(Boolean).join(','),
|
||||
city: document.getElementById('rCity').value,
|
||||
salary_min: parseInt(document.getElementById('rSalaryMin').value, 10) || null,
|
||||
salary_max: parseInt(document.getElementById('rSalaryMax').value, 10) || null,
|
||||
min_score: parseInt(document.getElementById('rScore').value, 10) || 65,
|
||||
daily_limit: parseInt(document.getElementById('rLimit').value, 10) || 0,
|
||||
boss_online_only: document.getElementById('rOnlineOnly').checked,
|
||||
allow_headhunter: document.getElementById('rHunter').checked,
|
||||
prompt: document.getElementById('rPrompt').value.trim() || null,
|
||||
};
|
||||
}
|
||||
|
||||
document.getElementById('rTemplate').addEventListener('change', () => {
|
||||
const id = document.getElementById('rTemplate').value;
|
||||
if (!id) return;
|
||||
const t = remoteTemplates.find(x => String(x.id) === id);
|
||||
if (t) fillRemoteForm(t);
|
||||
});
|
||||
|
||||
document.getElementById('btnRefreshTemplates').onclick = loadRemoteTemplates;
|
||||
|
||||
document.getElementById('btnSaveTemplateRemote').onclick = async () => {
|
||||
const name = prompt('请输入模板名称:');
|
||||
if (!name || !name.trim()) return;
|
||||
try {
|
||||
await api('/api/templates', { method: 'POST', body: JSON.stringify({ name: name.trim(), ...collectRemoteTemplate() }) });
|
||||
alert('模板已保存');
|
||||
await loadRemoteTemplates();
|
||||
} catch (e) { alert('保存失败:' + (e.message || '')); }
|
||||
};
|
||||
|
||||
async function renderRemoteTemplates() {
|
||||
await loadRemoteTemplates();
|
||||
const tbody = document.getElementById('tmplTbody');
|
||||
if (!remoteTemplates.length) {
|
||||
tbody.innerHTML = '<tr><td colspan="4" style="text-align:center;color:#999;padding:12px;">暂无模板</td></tr>';
|
||||
return;
|
||||
}
|
||||
tbody.innerHTML = remoteTemplates.map(t => '<tr><td style="padding:8px;border-bottom:1px solid #f0f0f0;">' + esc(t.name) + '</td><td style="padding:8px;border-bottom:1px solid #f0f0f0;">' + esc(t.keywords || '-') + '</td><td style="padding:8px;border-bottom:1px solid #f0f0f0;">' + esc(t.city || '-') + '</td><td style="padding:8px;border-bottom:1px solid #f0f0f0;"><button data-tid="' + t.id + '" class="tmpl-apply" style="margin-right:6px;">套用</button><button data-tid="' + t.id + '" class="tmpl-del" style="color:#d00;">删除</button></td></tr>').join('');
|
||||
}
|
||||
|
||||
document.getElementById('btnManageTemplatesRemote').onclick = () => {
|
||||
document.getElementById('tmplModal').classList.remove('hidden');
|
||||
renderRemoteTemplates();
|
||||
};
|
||||
|
||||
document.getElementById('tmplClose').onclick = () => {
|
||||
document.getElementById('tmplModal').classList.add('hidden');
|
||||
};
|
||||
|
||||
document.getElementById('tmplTbody').addEventListener('click', async e => {
|
||||
const tid = parseInt(e.target.dataset.tid);
|
||||
if (e.target.classList.contains('tmpl-apply')) {
|
||||
const t = remoteTemplates.find(x => x.id === tid);
|
||||
if (t) { fillRemoteForm(t); document.getElementById('rTemplate').value = tid; document.getElementById('tmplModal').classList.add('hidden'); }
|
||||
} else if (e.target.classList.contains('tmpl-del')) {
|
||||
if (!confirm('确定删除该模板?')) return;
|
||||
try { await api('/api/templates/' + tid, { method: 'DELETE' }); alert('已删除'); await renderRemoteTemplates(); }
|
||||
catch (e) { alert('删除失败:' + (e.message || '')); }
|
||||
}
|
||||
});
|
||||
|
||||
async function enter() {
|
||||
showData();
|
||||
// 自定义日期默认填入今天
|
||||
@@ -528,6 +637,7 @@ async function enter() {
|
||||
document.getElementById('dateEnd').value = today;
|
||||
await loadBlacklist();
|
||||
await load();
|
||||
await loadRemoteTemplates();
|
||||
}
|
||||
|
||||
if (token()) enter(); else showLogin();
|
||||
@@ -538,5 +648,19 @@ setInterval(() => {
|
||||
}
|
||||
}, 5000);
|
||||
</script>
|
||||
|
||||
<!-- 模板管理弹窗 -->
|
||||
<div id="tmplModal" class="hidden" style="position:fixed;inset:0;background:rgba(0,0,0,0.45);z-index:2000;display:flex;align-items:center;justify-content:center;">
|
||||
<div style="background:#fff;border-radius:8px;padding:24px;width:760px;max-width:95vw;max-height:85vh;overflow:auto;">
|
||||
<h3 style="margin:0 0 16px;">管理投递模板</h3>
|
||||
<table style="width:100%;border-collapse:collapse;">
|
||||
<thead><tr><th style="text-align:left;border-bottom:1px solid #eee;padding:8px;">名称</th><th style="text-align:left;border-bottom:1px solid #eee;padding:8px;">关键词</th><th style="text-align:left;border-bottom:1px solid #eee;padding:8px;">城市</th><th style="text-align:left;border-bottom:1px solid #eee;padding:8px;">操作</th></tr></thead>
|
||||
<tbody id="tmplTbody"></tbody>
|
||||
</table>
|
||||
<div style="margin-top:16px;text-align:right;">
|
||||
<button id="tmplClose" style="padding:6px 14px;border-radius:4px;border:1px solid #d9d9d9;background:#fff;cursor:pointer;">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user